wain-syntax-text
wain-syntax-text
is a crate to parse WebAssembly text format files.
This crate is part of larger wain project.
Installation
[]
= "0"
Usage
Using wain_syntax_text::parse()
is the easiest way.
extern crate wain_syntax_text;
use parse;
let source = "(module
(memory 0 2)
(table 0 1 1 funcref)
(export "_start" (func $_start))
(func $_start)
)";
match parse
For the syntax tree structure parsed by this library, please see wain-ast crate.
wain_syntax_text::lexer::Lexer
lexes a text format source.
extern crate wain_syntax_text;
use Lexer;
let source = "(module
(memory 0 2)
(table 0 1 1 funcref)
(export "_start" (func $_start))
(func $_start)
)";
// Lexer implements Iterator which traverses tokens in the given source
let mut lexer = new;
for lexed in lexer
APIs are provided for each logic:
- Lexer and parser for WAT syntax tree
- WAT to WASM translation
- Composing multiple WASM modules into single WASM module
Working examples can be seen at examples/api/ directory
Please read documentation (not yet) for details.
Implementation
- Lex and parse
.wat
file into WAT sytnax tree which is dedicated for text format resolving many syntax sugars. Since multiple modules can be put in.wat
file, it can be parsed into multiple trees - Translate the WAT syntax trees into common Wasm syntax trees (
wain_ast::Root
) resolving identifiers. Identifiers may refer things not defined yet (forward references) so.wat
file cannot be parsed into common Wasm syntax trees directly - Compose a single module from the multiple Wasm syntax trees following spec