-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.md.template
88 lines (60 loc) · 2.09 KB
/
README.md.template
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# syntaks [![Crystal CI](https://github.com/Ragmaanir/syntaks/actions/workflows/crystal.yml/badge.svg)](https://github.com/Ragmaanir/syntaks/actions/workflows/crystal.yml)
### Version <%= Syntaks::VERSION %>
A parser combinator framework.
## Usage
```crystal
require "syntaks"
```
## Example
```crystal
<%= File.read("spec/examples/list/parser.cr") %>
<%= File.read("spec/examples/list/example.cr") %>
```
## Usage
Rules are specified in a format similar to EBNF:
```crystal
# literals/tokens
ignored(:space, /\s+/) # generates nil as AST-node
rule(:int, String, /[1-9][0-9]*/) { |m| m.content } # generates String as AST-node
# sequence
rule(:root, String, "var " >> id) { |m| m[1] } # use the second match (id) as AST-node
# sequence with backtracking disabled
rule(:root, String, "var " & id) { |m| m[1] }
# alternatives
rule(:root, String, a | b)
# repetition
rule(:root, Array(Int32), {"," >> int}) { |m| m.map(&.[1]) }
```
When backtracking is disabled an parsing fails, a syntax error is produced:
```crystal
<%= File.read("spec/examples/error/parser.cr") %>
<%= File.read("spec/examples/error/example.cr") %>
```
A parse log can be printed to inspect the parsing process:
```crystal
<%= File.read("spec/examples/log/example.cr") %>
```
## TODO
- simple token macro
- rules that do not generate ast nodes
- error-recovery productions / synchronization tokens
- optional whitespace skippers
- Simple lexer?
- Packrat parsing / memoization
- remember longest parsed prefix when parsing fails
## DONE
- Use ameba
- Generated `README.md` with examples
- LoggingContext with a ParseLog
- ProfilingContext
- EBNF DSL
- Selectively disable backtracking
- Detailed syntax errors: display production that failed and the location where exactly it failed
## Contributing
1. Fork it ( https://github.com/ragmaanir/syntaks/fork )
2. Create your feature branch (git checkout -b my-new-feature)
3. Commit your changes (git commit -am 'Add some feature')
4. Push to the branch (git push origin my-new-feature)
5. Create a new Pull Request
## Contributors
- [Ragmaanir](https://github.com/ragmaanir) - creator, maintainer