Crate wat_parser

Source
Expand description

The parser for WebAssembly Text Format.

This parser is error-tolerant, which means it can parse even even if the input contains syntax errors.

This parser will produce concrete syntax tree (CST), but you can build AST from it with a bunch of helpers from wat_syntax::ast module.

§Usage

Use the main parse function:

use wat_syntax::SyntaxKind;

let input = "(module)";
let (tree, errors) = wat_parser::parse(input);
assert_eq!(tree.kind(), SyntaxKind::ROOT);

Any syntax errors won’t prevent the parser from parsing the rest of the input, so the parse function returns a tuple which contains the CST and syntax errors. You can access syntax errors like this:

use wat_syntax::SyntaxKind;

let input = "(module";
let (tree, errors) = wat_parser::parse(input);
assert_eq!(errors[0].start, 7);
assert!(errors[0].message.to_string().contains("expected `)`"));

Structs§

SyntaxError
The syntax error comes with location and message.

Enums§

Message
Syntax error message.

Functions§

is_id_char
Checks if a character is a valid identifier character.
parse
Parse the code into a rowan syntax node.
parse_to_green
Parse the code into a rowan green node.