Minimal Parsing Language (MPL)
This is minimal parser combinator of Minimal Parsing Language (MPL) like Top-Down Parsing Language (TDPL). It creates a abstract syntax tree (AST) for each input.
Getting Started
- implement
Variable
- insert each rule into
HashMap
minimal_parse()
- Optional
- implement
Input
- supports
[T]
andstr
by default - implement
Position
- supports
u*
,i*
, andf*
by default - implement
Span
- supports
StartAndLenSpan
by default - implement
Terminal
- supports
SliceTerminal
,StrTerminal
, andU8SliceTerminal
by default - implement
Output
- supports
()
by default - implement
Rules
- supports
HashMap
by default - implement
Parse
- supports
[T]
,str
, and[u8]
by default
Example
use crate*;
use Parser;
use ;
use ;
use Output;
use ;
use AST;
use HashMap;
;
/// ```
/// Open = '(' Parentheses / ()
/// Parentheses = Open Close / f
/// Close = ")" Open / f
/// ```
Test Examples
Parsers written with MPL
- WAV AST : RIFF waveform Audio Format
MPL
Definition of MPL grammar
A MPL grammar G
is a tuple G = (V, Σ, R, S)
in which:
V
is a finite set of variables.Σ
is a finite set of original terminal symbols.T
is an union ofΣ
orM
(Σ ∪ M) (M
(= {(), f}) is a finite set of metasymbols).R
is a finite set of rules of the formA = B C / D
A in V (A ∈ V),
B, C, D in E (E = T ∪ V) (T ∩ V = ∅) (B, C, D ∈ E).
For any variable A there is exactly one rule with A to the left of=
.- S in V (S ∈ V) is the start variable.
Empty
()
is a metasymbol that always succeeds without consuming input.
Empty = /
Failure
f
is a metasymbol that always fails without consuming input.
Failure = f f / f
Extended MPL
Since one of the goals of MPL is to create an AST, it also supports two features in terms of ease of use and speed.
Any
?
is a metasymbol representing any single input like wildcard character. This succeeds if there is any input left, and fails if there is no input left.
Any = ? / f
To extend the difinition of MPL grammar, let ? ∈ M.
All
*
is a metasymbol representing All remaining input like wildcard character. This will succeed even if the remaining inputs are zero.
All = * / f
Same as All = ? All / ()
.
To extend the difinition of MPL grammar, let * ∈ M.