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§
- annotation
- A utility for pretty-printing source code annotations, warnings and errors.
- ast
- Abstract syntax tree definitions outputted by the parser.
- token
- Token types emitted by the lexer.
Structs§
- Lexer
Error - An error emitted while trying to tokenize an input string.
- Parse
Error - An error emitted while trying to parse a token list.
- Parse
Error Context - Context attached to a
ParseError
. - Token
Item - A token with attached metadata.
Enums§
- Context
Type - Context information that can be attached to a
ParseError
. - Flavor
- A flavor of Squirrel to parse.
- Lexer
Error Type - Type of
LexerError
. - Parse
Error Type - Type of
ParseError
.