Parser function declarations
Quick examples:
parser parse :: Root {
grammar:one;
grammar:two;
some:other:grammar;
}
Parser declarations have three parts: a name for the newly created parse function, the starting nonterminal, and a list of grammar to include in what’s sent to the parser generator.
parser name :: start nonterminal { grammars...; }
The resulting parse function has type (ParseResult<StartNT> ::= String String)
.
For example, the example parser at the top of this page has type (ParseResult<Root> ::= String String)
.
The two parameters are (1) the string to actually parse and (2) the name of the “file” being parsed.
(e.g. This will appear in the filename
attribute of terminal locations.)
ParseResult
is a standary library data structure indicating either parseSuccess
or parseFailure
along with the errors or syntax tree result.
All concrete syntax in the listed grammars in included in what’s sent to the parser generator, including those grammars they export. Silver will use Copper to construct an LALR(1) parser.
Not yet.
Silver currently just makes all “ignore terminals” be the global layout that’s expected before/after the starting nonterminal. Eventually there will be syntax to control this for a parser, just like there is on productions. But for now, that’s the only option.