rhue-parser 2.1.0

Parser and syntax tree for the Rhue scripting language
Documentation

This is part of Rhue's insides. If you just want to run scripts from Rust, use rhue, it's the only crate whose API is meant to stay stable. Everything else (this one included) can change between minor versions.

use rhue_parser::parse_chunk;

let chunk = parse_chunk("local function sq(x: number) return x * x end").unwrap();
assert_eq!(chunk.body.stmts.len(), 1);

let errors = parse_chunk("local = 1\nlocal y = )").unwrap_err();
assert_eq!(errors.len(), 2); // it recovers and keeps going

It takes all of Luau's type syntax (annotations, aliases with generics and defaults, type packs, read/write properties, typeof, ::) and keeps it in the AST for rhue-types. The compiler just ignores it.

A few things worth knowing:

  • every name occurrence gets a dense NameId, so later passes keep side tables in a Vec instead of hashing nodes
  • nesting is capped at MAX_DEPTH, including long 1 + 1 + 1 ... chains, so hostile input can't build a tree deep enough to blow the stack
  • it stops collecting after MAX_ERRORS, the rest are usually cascades anyway
  • parse_expr and parse_type parse just an expression or just a type (the REPL and host declarations use those)

License

MIT or Apache-2.0, same as the rest of Rhue.