1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use crate::errors::parser_error::ParserError;
use crate::parser::parser_config::ParserConfig;
use crate::parser::utils::parse_span::{LineSpan, ParseSpan};
pub struct ParsingContext<'c, 'p, 'a, 's, 'f> {
pub config: &'c ParserConfig,
pub span: &'p ParseSpan<'a, 's, 'f>,
}
pub struct LineParsingContext<'c, 'p, 's, 'f> {
pub config: &'c ParserConfig,
pub line: &'p LineSpan<'s, 'f>,
}
impl<'c, 'p, 'a, 's, 'f> ParsingContext<'c, 'p, 'a, 's, 'f> {
pub fn with_different_span(
&self,
new_span: &'p ParseSpan<'a, 's, 'f>,
) -> Self {
Self {
config: self.config,
span: new_span,
}
}
pub fn get_line_context_with_span(
&self,
line: &'p LineSpan<'s, 'f>,
) -> LineParsingContext<'c, 'p, 's, 'f> {
LineParsingContext {
config: self.config,
line,
}
}
}
pub trait Parseable
where Self: Sized + 'static
{
fn parse(context: &ParsingContext) -> Result<Self, ParserError>;
}
pub trait ParseableFromLine
where Self: Sized + 'static
{
fn parse_from_line(context: &LineParsingContext) -> Result<Self, ParserError>;
}
pub trait ParseableWithUnknownSpan
where Self: Sized + 'static
{
fn parse_with_unknown_span<'c, 'p, 'a, 's, 'f>(context: &ParsingContext<'c, 'p, 'a, 's, 'f>) -> Result<(Self, ParseSpan<'a, 's, 'f>), ParserError>;
}