| Crates.io | wat_parser |
| lib.rs | wat_parser |
| version | 0.5.0 |
| created_at | 2024-11-30 04:17:25.046248+00 |
| updated_at | 2025-05-14 07:23:52.252009+00 |
| description | WebAssembly Text Format concrete syntax tree parser. |
| homepage | |
| repository | https://github.com/g-plane/wasm-language-tools |
| max_upload_size | |
| id | 1466289 |
| size | 94,317 |
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.
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 `)`"));