Crate sqparse

Source
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§

LexerError
An error emitted while trying to tokenize an input string.
ParseError
An error emitted while trying to parse a token list.
ParseErrorContext
Context attached to a ParseError.
TokenItem
A token with attached metadata.

Enums§

ContextType
Context information that can be attached to a ParseError.
Flavor
A flavor of Squirrel to parse.
LexerErrorType
Type of LexerError.
ParseErrorType
Type of ParseError.

Functions§

parse
Parses an input token list into a syntax tree.
tokenize
Parses an input string into a list of tokens.