pub struct Parser { /* private fields */ }Expand description
Parser state: a cursor over a token stream.
Implementations§
Source§impl Parser
impl Parser
Sourcepub fn new(tokens: Vec<Token>) -> Self
pub fn new(tokens: Vec<Token>) -> Self
Create a new parser from a token stream, starting at position 0.
Sourcepub fn from_tokens_at(tokens: Vec<Token>, pos: usize) -> Self
pub fn from_tokens_at(tokens: Vec<Token>, pos: usize) -> Self
Create a parser starting at a specific position in the token stream.
Use this to resume parsing after handing the token stream to another parser (e.g., a downstream DSL parser that calls fabula’s parser for pattern sections).
Sourcepub fn into_inner(self) -> (Vec<Token>, usize)
pub fn into_inner(self) -> (Vec<Token>, usize)
Consume the parser, returning the token stream and cursor position.
Use this to recover the tokens after parsing a section, so a downstream DSL can continue parsing from where fabula left off.
Sourcepub fn parse_document(&mut self) -> Result<Document, ParseError>
pub fn parse_document(&mut self) -> Result<Document, ParseError>
Parse a complete document (patterns, graphs, and compose directives).
Sourcepub fn parse_pattern_only(&mut self) -> Result<PatternAst, ParseError>
pub fn parse_pattern_only(&mut self) -> Result<PatternAst, ParseError>
Parse a single pattern declaration, then assert EOF.
Sourcepub fn parse_graph_only(&mut self) -> Result<GraphAst, ParseError>
pub fn parse_graph_only(&mut self) -> Result<GraphAst, ParseError>
Parse a single graph declaration, then assert EOF.
Sourcepub fn parse_pattern(&mut self) -> Result<PatternAst, ParseError>
pub fn parse_pattern(&mut self) -> Result<PatternAst, ParseError>
Parse a full pattern name { ... } declaration.
Sourcepub fn parse_pattern_body(&mut self) -> Result<PatternBody, ParseError>
pub fn parse_pattern_body(&mut self) -> Result<PatternBody, ParseError>
Parse the body of a pattern — stages, negations, and temporal
constraints — without the pattern name { } wrapper.
Stops when it sees } or EOF but does not consume the closing
brace. The caller owns the block structure and is responsible for
consuming the delimiter.
This is the primary composability entry point for downstream DSLs that embed fabula pattern syntax in their own blocks:
// salience-dsl example
parser.expect_ident()?; // "precondition"
parser.expect(TokenKind::LBrace)?; // {
let body = parser.parse_pattern_body()?;
parser.expect(TokenKind::RBrace)?; // }
let pattern = compile_pattern_body_with("name", &body, &mapper)?;Sourcepub fn parse_stage(&mut self) -> Result<StageAst, ParseError>
pub fn parse_stage(&mut self) -> Result<StageAst, ParseError>
Parse a stage anchor { clauses... } block.
Sourcepub fn parse_negation(&mut self) -> Result<NegationAst, ParseError>
pub fn parse_negation(&mut self) -> Result<NegationAst, ParseError>
Parse an unless [between|after] ... { clauses } negation block.
Sourcepub fn parse_temporal(&mut self) -> Result<TemporalAst, ParseError>
pub fn parse_temporal(&mut self) -> Result<TemporalAst, ParseError>
Parse a temporal left relation right [gap range] constraint.
Sourcepub fn parse_compose(&mut self) -> Result<ComposeAst, ParseError>
pub fn parse_compose(&mut self) -> Result<ComposeAst, ParseError>
Parse a compose name = ... directive.
Sourcepub fn parse_clause(&mut self) -> Result<ClauseAst, ParseError>
pub fn parse_clause(&mut self) -> Result<ClauseAst, ParseError>
Parse a single clause: [!] [?]source.label = | -> | < | > | <= | >= target.
Sourcepub fn parse_graph(&mut self) -> Result<GraphAst, ParseError>
pub fn parse_graph(&mut self) -> Result<GraphAst, ParseError>
Parse a graph { ... } declaration.
Sourcepub fn check(&self, kind: TokenKind) -> bool
pub fn check(&self, kind: TokenKind) -> bool
Check if the current token matches the given kind (by discriminant).
Sourcepub fn expect(&mut self, expected: TokenKind) -> Result<&Token, ParseError>
pub fn expect(&mut self, expected: TokenKind) -> Result<&Token, ParseError>
Expect the current token to be of the given kind, advance, and return it.
Sourcepub fn expect_ident(&mut self) -> Result<String, ParseError>
pub fn expect_ident(&mut self) -> Result<String, ParseError>
Expect and consume an identifier token. Some keywords are allowed as identifiers in certain positions (between, after, compose, sharing).
Sourcepub fn expect_ident_or_string(&mut self) -> Result<String, ParseError>
pub fn expect_ident_or_string(&mut self) -> Result<String, ParseError>
Expect and consume an identifier or string literal token.
Sourcepub fn expect_number(&mut self) -> Result<f64, ParseError>
pub fn expect_number(&mut self) -> Result<f64, ParseError>
Expect and consume a number literal token, with optional leading -.
Sourcepub fn error(&self, msg: &str) -> ParseError
pub fn error(&self, msg: &str) -> ParseError
Create a parse error at the current token position.