Expand description
This is a parser for the Squirrel language, written in Rust. It is primarily designed to parse Respawn’s custom Squirrel dialect, but should be able to handle Squirrel 2 and 3 code as well.
Features:
- Completely source-preserving: all tokens and comments in the input string are included in the AST. This makes it perfect for source modification operations like code formatting.
- Friendly error messages: in general, the parser aims to show nice syntax error messages with useful contextual information. Unfortunately this isn’t always possible due to syntax ambiguities, especially where Respawn’s type system is involved.
- Parses all Northstar scripts and R5Reloaded scripts successfully. The resulting ASTs have not been verified.
Example
use sqparse::{Flavor, parse, tokenize};
let source = r#"
global function MyFunction
struct {
int a
} file
string function MyFunction( List<number> values ) {
values.push(1 + 2)
}
"#;
let tokens = tokenize(source, Flavor::SquirrelRespawn).unwrap();
let program = parse(&tokens).unwrap();
println!("Program: {:#?}", program);Modules
A utility for pretty-printing source code annotations, warnings and errors.
Abstract syntax tree definitions outputted by the parser.
Token types emitted by the lexer.
Structs
An error emitted while trying to tokenize an input string.
An error emitted while trying to parse a token list.
Context attached to a
ParseError.A token with attached metadata.
Enums
Context information that can be attached to a
ParseError.A flavor of Squirrel to parse.
Type of
LexerError.Type of
ParseError.