Available on crate feature
parser only.Expand description
Wright’s parser, which turns source code into an abstract syntax tree.
Parsing happens in three stages:
- The lexer splits the source into tokens (see
lexer.rsin this module). - A resilient LL(1) parser generated by lelwel from the grammar in
src/parser/wright.llwbuilds a lossless concrete syntax tree from the tokens. - The concrete syntax tree is lowered into the AST (see
lower.rs).
Parsing never fails outright. Syntax errors are reported as Diagnostics, and the parser recovers and keeps going, so a single parse reports as many problems as possible and still produces an AST for the parts of the source that make sense. See crate::ast for how errors show up in the AST.
use wright::parser::parse_source_file;
let source = Arc::new(Source::new_from_static_str(FileName::None, "func main() { println(\"hi\"); }"));
let parsed = parse_source_file(source);
assert!(!parsed.has_errors());
assert_eq!(parsed.ast.items.len(), 1);Modules§
- cst
- The concrete syntax tree (CST) and the parser that produces it.
Structs§
- Parsed
- The result of parsing some source code: an AST, the syntax tree it was lowered from, and any diagnostics.
Constants§
- MAX_
NESTING_ DEPTH - The maximum nesting depth the parser supports.
Functions§
- parse_
expr - Parse a source containing a single expression (such as input to a REPL).
- parse_
source_ file - Parse an entire source file.
- parse_
type - Parse a source containing a single type signature.