Class ClaferParser
java.lang.Object
org.clafer.frontend.ClaferParser
Parses a model in the full Clafer language into its
Syntax tree, as
the compiler parses it (clafer.cf, generated by BNFC and Happy, and
Language.Clafer.parse).
It is a recursive descent over the grammar, one method per level of expression, which takes the choices that Happy takes:
- an expression goes on as long as it can, so that in
[a -b]the-is a subtraction, anda notmust go on within; a list of expressions has no separator; - a quantifier starts a declaration,
some x; y : X | e, whendisj, or a name and;or:, follow it; - a cardinality is taken whenever one can start, e.g., the
2..3ofa 2..3 bis the card ofa; - a clafer must start on a new line, after its previous sibling clafer.
Layout), so the parser reads blocks
as braces, and lines of siblings with a separator between them.
The parser does not stop at an error: it reports it, skips to the next line at the same or a lower indentation, and goes on, so that a model with errors on several lines reports all of them, and the tree has the rest.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordThe tree of a model and its errors. -
Method Summary
-
Method Details
-
parse
Parses a model.- Parameters:
source- the text of the model- Returns:
- its tree, comments and errors
-