Last active
September 16, 2016 20:59
-
-
Save yhirose/1291a8ebc4da1d3858b67f980089b1a4 to your computer and use it in GitHub Desktop.
PEG Linter ー peglint ref: http://qiita.com/yhirose/items/322d5e81d98de7e7df9e
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Expr ← Sum | |
Sum ← Product (('+' / '-') Product)* | |
Product ← Value (('*' / '/') Value)* | |
Value ← [0-9]+ / '(' Expr ')' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ peglint calc2.peg | |
1:17 'Hello' is not defined. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 構文ルール | |
Expr ← Sum | |
Sum ← Product (SumOpe Product)* | |
Product ← Value (ProOpe Value)* | |
Value ← Number / '(' Expr ')' | |
# 字句ルール | |
SumOpe ← ('+' / '-') | |
ProOpe ← ('*' / '/') | |
Number ← [0-9]+ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ go get github.com/yhirose/go-peg/cmd/peglint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ peglint -s "2*(3+5)/4" -trace calc3.peg | |
pos:lev rule/ope | |
------- -------- | |
0:0 [Expr] | |
0:1 reference | |
0:2 [Sum] | |
0:3 sequence | |
0:4 reference | |
0:5 [Product] | |
0:6 sequence | |
0:7 reference | |
0:8 [Value] | |
0:9 prioritizedChoice | |
0:10 reference | |
0:11 [Number] | |
0:12 oneOrMore | |
0:13 characterClass | |
1:13 characterClass | |
1:7 zeroOrMore | |
1:8 sequence | |
1:9 reference | |
1:10 [ProOpe] | |
1:11 prioritizedChoice | |
1:12 literalString | |
2:9 reference | |
2:10 [Value] | |
2:11 prioritizedChoice | |
[以下に続く...] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ peglint calc.peg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Expr ← Sum Hello | |
Sum ← Product (('+' / '-') Product)* | |
Product ← Value (('*' / '/') Value)* | |
Value ← [0-9]+ / '(' Expr ')' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ peglint -s "2*(3+5)/4" calc.peg | |
$ peglint -s "(hello world)" calc.peg | |
1:2 syntax error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ peglint -s "2*(3+5)/4" -ast calc.peg | |
+ Expr | |
+ Sum | |
+ Product | |
+ Value | |
+ Value | |
+ Expr | |
+ Sum | |
+ Product | |
+ Value | |
+ Product | |
+ Value | |
+ Value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ peglint -s "2*(3+5)/4" -ast -opt calc.peg | |
+ Product | |
+ Value | |
+ Sum | |
+ Value | |
+ Value | |
+ Value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
~/Dropbox/Projects/go-peg-tutorial$ peglint -s "2*(3+5)/4" -ast -opt calc3.peg | |
+ Product | |
- Number ("2") | |
- ProOpe ("*") | |
+ Sum | |
- Number ("3") | |
- SumOpe ("+") | |
- Number ("5") | |
- ProOpe ("/") | |
- Number ("4") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment