Dynamic Parser with extensible PEG grammar. Reads as deep
- Single unnamed pattern is passed as is:
X: x
~X: <value: x> => value
- Sequence without named arguments results in
{}
:X: x y
~X: x y => {}
- Sequence with named arguments is wrapped with rule's name
X: <value: x> y
~X: <value: x> y => X { value }
You may override rules:
X: a
X: b
Y: X // Same as Y: b
Parsing in Repl starts from Statement
rule.
If you want to extend parser's syntax, you must override it
>>> EmptyTuple: '(' ')' => "EmptyTuple"
>>> Statement: Rule | EmptyTuple
// >>> Statement: Statement.clone() | EmptyTuple // TODO: copy rule
>>> ()
"EmptyTuple"
Parsing in files starts from Root
rule.
If you want to extend parser's syntax, you must override it
Override Whitespace
rule to change skipped characters
Whitespace: /[ ]*/ // Skip only spaces without tabs and newlines
There is context.skip_whitespace
special variable that must be set to true
for automatic whitespace skipping
Parser first tries to parse without ignoring whitespaces. This allows you to parse whitespaces, where needed.
BinaryOrPrefix
: '+' /[ ]+/ 'x' => "binary"
| '+' 'x' => "prefix"
Create error rules for better errors description. By convention, they should start with Invalid
.
@
means at current location,
@lparen
means at location of lparen
.
Note that invalid syntax is still parsed and is accepted as valid alternative.
Tuple: '(' ')' | InvalidTuple
InvalidTuple: <lparen: '('> =>
throw ExpectedMatching {
expected: ')',
at: @,
to_match: '(',
unmatched_at: @lparen,
}
To debug library itself call with env RUST_LOG=debug
or RUST_LOG=trace
- Remove
on_parse
function from rule - Move logic to syntax
- Export/Import rules
- Rule copy
- Use special rules for whitespace skip
- Add syntax highlighting
* [x] Text as keywords
* [x] Regex
* [x] Strings
* [x] Numbers
* [x] Special symbols as operators or punctuators
* [x] Variables as identifiers (parameter)
* [x] RuleName as types
* [ ] Make syntax highlighting smarter
* [ ] More token subkinds like
keyword.text
,operator.lparent
, etc. * [ ] Syntax highlight shouldn't be affected by errors - Add documentation
- Simplify separated patterns
- Add
#[derive(Rule)]
* [ ] Add#[rule]
attribute * [ ] AddSelf::rule()
method * [ ] AddSelf::parse(str: &str)
method * [ ] Implement deserialize * [ ] On enums every variant is alternative - Simplify rules
- Remove ';' at end of rules
- Use
xxx#tag
to add tags like token kinds to values - Fix left recursion
- Make adding rules to context automatic
- Support code blocks in actions