5 unstable releases

0.3.2 Feb 7, 2025
0.3.1 Feb 6, 2025
0.3.0 Feb 5, 2025
0.2.0 Jan 5, 2025
0.1.0 Nov 30, 2024

#1835 in Parser implementations

Download history 125/week @ 2024-11-27 43/week @ 2024-12-04 16/week @ 2024-12-11 1/week @ 2024-12-18 140/week @ 2025-01-01 25/week @ 2025-01-08 6/week @ 2025-01-15 419/week @ 2025-02-05

428 downloads per month
Used in 3 crates (2 directly)

MIT license

150KB
5K SLoC

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 `)`"));

Dependencies

~2MB
~40K SLoC