rustre_parser

Function parse

Source
pub fn parse(source: &str) -> (Root, Vec<ParserError>)
Expand description

Parse a Lustre file’s source code into a syntax tree and a list of parsing errors

The syntax tree elements correspond to structs in the ast module.

§Errors

Thanks to the design of the parser, errors don’t cause the entire parser to fail, but are rather accumulated in the list while the parser continues its jobs, doing the best it can to land back on its feet. For this reason, errors are returned in a tuple rather than with the usual Result.

§Parsing individual grammar elements

This function parses an entire Lustre program, that is, an entire file. If you want to parse a specific syntax element (say, just a node), you’ll have to find the specific parser in the parser module and build one of ast’s structs from its result.

While — as explained above — parsing an entire program isn’t supposed to make the actual parser fail, if you go about parsing individual syntax elements, their parsers may fail, typically if the first (few) token(s) are/is unexpected.