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

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.

Functions

Returns an implementation of std::fmt::Display that can pretty-print the location of an error in a source string.
Parses an input token list into a syntax tree.
Parses an input string into a list of tokens.