[][src]Crate wast

A crate for low-level parsing of the WebAssembly text formats: WAT and WAST.

This crate is intended to be a low-level detail of the wat crate, providing a low-level parsing API for parsing WebAssembly text format structures. The API provided by this crate is very similar to syn and provides the ability to write customized parsers which may be an extension to the core WebAssembly text format. For more documentation see the parser module.

High-level Overview

This crate provides a few major pieces of functionality

  • lexer - this is a raw lexer for the wasm text format. This is not customizable, but if you'd like to iterate over raw tokens this is the module for you. You likely won't use this much.

  • parser - this is the workhorse of this crate. The parser module provides the Parse trait primarily and utilities around working with a Parser to parse streams of tokens.

  • Module - this contains an Abstract Syntax Tree (AST) of the WebAssembly Text format (WAT) as well as the unofficial WAST format. This also has a Module::encode method to emit a module in its binary form.

Stability and WebAssembly Features

This crate provides support for many in-progress WebAssembly features such as reference types, multi-value, etc. Be sure to check out the documentation of the wast crate for policy information on crate stability vs WebAssembly Features. The tl;dr; version is that this crate will issue semver-non-breaking releases which will break the parsing of the text format. This crate, unlike wast, is expected to have numerous Rust public API changes, all of which will be accompanied with a semver-breaking release.

Compile-time Cargo features

This crate has a wasm-module feature which is turned on by default which includes all necessary support to parse full WebAssembly modules. If you don't need this (for example you're parsing your own s-expression format) then this feature can be disabled.

Modules

kw

Common keyword used to parse WebAssembly text files.

lexer

Definition of a lexer for the WebAssembly text format.

parser

Traits for parsing the WebAssembly Text format

Macros

custom_keyword

A macro to create a custom keyword parser.

Structs

BlockType

Extra information associated with block-related instructions.

BrTableIndices

Extra information associated with the br_table instruction.

CallIndirect

Extra data associated with the call_indirect instruction.

Data

A data directive in a WebAssembly module.

Elem

An elem segment in a WebAssembly module.

Error

A convenience error type to tie together all the detailed errors produced by this crate.

Export

A entry in a WebAssembly module's export section.

Expression

An expression, or a list of instructions, in the WebAssembly text format.

Float32

A parsed floating-point type

Float64

A parsed floating-point type

Func

A WebAssembly function to be inserted into a module.

FunctionType

A function type with parameters and results.

Global

A WebAssembly global in a module

GlobalType

Type for a global in a wasm module

Id

An identifier in a WebAssembly module, prefixed by $ in the textual format.

Import

An import statement and entry in a WebAssembly module.

InlineExport

A listing of inline (export "foo") statements on a WebAssembly item in its textual format.

LParen

A convenience type to use with Parser::peek to see if the next token is an s-expression.

Limits

Min/max limits used for tables/memories.

MemArg

Payload for memory-related instructions indicating offset/alignment of memory accesses.

Memory

A defined WebAssembly memory instance inside of a module.

MemoryInit

Extra data associated with the memory.init instruction

MemoryType

Configuration for a memory of a wasm module

Module

A parsed WebAssembly module.

Names

Representation of the results of name resolution for a module.

SelectTypes

Payload of the select instructions

Span

A position in the original source stream, used to render errors.

Table

A WebAssembly table directive in a module.

TableCopy

Extra data associated with the table.copy instruction.

TableInit

Extra data associated with the table.init instruction

TableType

Configuration for a table of a wasm mdoule

Type

A type declaration in a module

TypeUse

A reference to a type defined in this module.

V8x16Shuffle

Lanes being shuffled in the v8x16.shuffle instruction

Wast

A parsed representation of a *.wast file.

WastInvoke
Wat

A *.wat file parser, or a parser for one parenthesized module.

Enums

AssertExpression

An expression that is valid inside an assert_return directive.

DataKind

Different kinds of data segments, either passive or active.

ElemKind

Different ways to define an element segment in an mdoule.

ElemPayload

Different ways to define the element segment payload in a module.

ExportKind

Different kinds of elements that can be exported from a WebAssembly module, contained in an Export.

FuncKind

Possible ways to define a function in the text format.

GlobalKind

Different kinds of globals that can be defined in a module.

ImportKind

All possible types of items that can be imported into a wasm module.

Index

A reference to another item in a wasm module.

Instruction

A listing of all WebAssembly instructions that can be in a module that this crate currently parses.

MemoryKind

Different syntactical ways a memory can be defined in a module.

ModuleField

A listing of all possible fields that can make up a WebAssembly module.

ModuleKind

The different kinds of ways to define a module.

NanPattern

Either a NaN pattern (nan:canonical, nan:arithmetic) or a value of type T.

QuoteModule
TableElemType

List of different kinds of table types we can have.

TableKind

Different ways to textually define a table.

V128Pattern

A version of V128Const that allows NanPatterns.

V128Const

Different ways to specify a v128.const instruction

ValType

The value types for a wasm module.

WastDirective

The different kinds of directives found in a *.wast file.

WastExecute