@@ -15,8 +15,8 @@ use annotations::*;
1515pub use error:: FznParseError ;
1616use primitives:: * ;
1717use winnow:: {
18- combinator:: { alt, delimited, opt, preceded, separated, separated_pair} ,
1918 Parser , Result , Stateful ,
19+ combinator:: { alt, delimited, opt, preceded, separated, separated_pair} ,
2020} ;
2121
2222use crate :: {
@@ -35,18 +35,28 @@ enum Declaration<Identifier> {
3535}
3636
3737#[ derive( Clone , Copy , Debug , Eq , Ord , PartialEq , PartialOrd ) ]
38+ /// Represents the current parsing phase.
3839enum ParsePhase {
40+ /// Accepting all items, possibly already parsed a predicate declaration.
3941 Predicates ,
42+ /// Parsed a array/variable declaration item, no longer accepting predicate
43+ /// declarations.
4044 Declarations ,
45+ /// Parsed a constraint item, no longer accepting predicate or
46+ /// array/variable declarations.
4147 Constraints ,
48+ /// Parsed a solve item, no longer accepting any items.
4249 Solve ,
4350}
4451
4552#[ derive( Debug , PartialEq ) ]
53+ /// State used during parsing.
4654struct ParseState < ' s , Identifier > {
55+ /// Collection of parsed parameters to be replaced in constraint arguments.
4756 parameters : & ' s mut HashMap < String , Literal < Identifier > > ,
4857}
4958
59+ /// Type used for the parser input and state.
5060type Stream < ' source , ' state , Identifier > = Stateful < & ' source str , ParseState < ' state , Identifier > > ;
5161
5262/// Parses a constraint argument.
@@ -127,8 +137,8 @@ where
127137
128138/// Parses the domain in a variable declaration.
129139///
130- /// Has no direct analogue in the grammar. However, it is essentially the `<basic-var-type>`
131- /// without the "var" token preceding it:
140+ /// Has no direct analogue in the grammar. However, it is essentially the
141+ /// `<basic-var-type>` without the "var" token preceding it:
132142///
133143/// ```bnf
134144/// <basic-var-type> ::= "var" <basic-par-type>
@@ -197,6 +207,7 @@ where
197207 . parse_next ( input)
198208}
199209
210+ /// Parse a parameter declaration item.
200211fn parameter_item < Identifier > (
201212 input : & mut Stream < ' _ , ' _ , Identifier > ,
202213) -> Result < ( String , Literal < Identifier > ) >
@@ -537,7 +548,7 @@ where
537548 . parse_next ( input)
538549}
539550
540- /// Parse a variable model item.
551+ /// Parse a variable declaration item.
541552fn variable < Identifier > (
542553 input : & mut Stream < ' _ , ' _ , Identifier > ,
543554) -> Result < ( Identifier , Variable < Identifier > , bool ) >
@@ -583,15 +594,15 @@ mod tests {
583594
584595 use rangelist:: RangeList ;
585596 use ustr:: Ustr ;
586- use winnow:: { error :: ParserError , Parser , Stateful } ;
597+ use winnow:: { Parser , Stateful , error :: ParserError } ;
587598
588599 use crate :: {
589- fzn:: {
590- array_item, constraint, parameter_item, predicate_item, solve_objective, variable,
591- ParseState , Stream ,
592- } ,
593600 Annotation , AnnotationArgument , AnnotationCall , AnnotationLiteral , Argument , Array ,
594601 Constraint , FlatZinc , FznParseError , Literal , Method , SolveObjective , Type , Variable ,
602+ fzn:: {
603+ ParseState , Stream , array_item, constraint, parameter_item, predicate_item,
604+ solve_objective, variable,
605+ } ,
595606 } ;
596607
597608 #[ test]
0 commit comments