Skip to main content

Module parser

Module parser 

Source
Expand description

Recursive-descent parser producing the AST, modelled on rustc_parse.

  • The parser walks the token list keeping token (current) and prev_token; a node’s span is lo.to(self.prev_token.span).
  • check, eat and expect record what would have been accepted at the current position, so errors read “expected one of , or ), found ;”.
  • Parsing functions return PResult. Recovery points (items and statements) report the error, skip ahead and carry on, leaving an Err node in the tree.

Structs§

Parser

Enums§

PathStyle
Where a path appears, which decides how generic arguments are written (rustc’s PathStyle).

Functions§

parse_file
Lexes and parses a whole source file, returning the module (complete even if there were errors, with Err nodes where parsing failed) and every diagnostic. Node ids are taken from ids.
parse_items
Parses source as module-level items. A synthetic file is added to source_map so that diagnostics can point into the generated code.

Type Aliases§

PResult
The result of a parsing function. The error has not been reported yet: the caller either reports it or propagates it to a recovery point.