aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2020-09-17 01:00:44 -0700
committerBruce Hill <bruce@bruce-hill.com>2020-09-17 01:00:44 -0700
commit4cfcdae3a1d6ec4963af436318907483e87c0a5b (patch)
tree32db30f0f8a6ec1083c0b3930cd57cd59d97d0cf
parent742d83684ef593ff0e428ae444ef97bb76a94cd9 (diff)
Updates to the grammar
-rw-r--r--grammars/bpeg.bpeg30
1 files changed, 17 insertions, 13 deletions
diff --git a/grammars/bpeg.bpeg b/grammars/bpeg.bpeg
index 5570ecb..43d6834 100644
--- a/grammars/bpeg.bpeg
+++ b/grammars/bpeg.bpeg
@@ -1,9 +1,10 @@
# This is a file defining the BPEG grammar using BPEG syntax
Grammar: __ 0+(Def 0-1(__`;))%__ __ ($$ / @[!]{... => "Could not parse this code"})
-Def: @[name]id __ `: __ (@[definition]extended-pat
+Def: @[name]id _ `: __ (
+ @[definition]extended-pat
/ $$ @[!]{=>"No definition for rule"}
- / @[!]{...>(`;/id__`:/$) => "Invalid definition: @0"})
+ / @[!]{...>(`;/id_`:/$) => "Invalid definition: @0"})
# This is used for command line arguments:
String-pattern: 0+(`\ pat 0-1`; / .)
@@ -12,10 +13,10 @@ pat: suffixed-pat / simple-pat
simple-pat: Upto-and / Dot / String / Char-range / Char / Escape-range / Escape / No
/ Nodent / Repeat / After / Before / Capture / Replace / Ref / parens
-suffixed-pat: Eq-pat / simple-pat (
+suffixed-pat: Eq-pat / simple-pat 0-1(
@[!]{`* => "'*' is not a BPEG operator. Use 0+<pat> instead of <pat>*"}
/ @[!]{`+ => "'+' is not a BPEG operator. Use 1+<pat> instead of <pat>+"}
- / @[!]{`? => "'?' is not a BPEG operator. Use 0-1<pat> or 1-<pat> instead of <pat>?"}
+ / @[!]{`? => "'?' is not a BPEG operator. Use 0-1<pat> instead of <pat>?"}
/ @[!]{`= => "'=' is not valid here. Perhaps you meant '==' or ':'"}
)
@@ -26,34 +27,37 @@ String: (
`" @[s]0+(Escape / !`".) (`" / @[!]{=> "Expected closing quote here"})
/ `' @[s]0+(Escape / !`'.) (`' / @[!]{=> "Expected closing quote here"})
)
-Char-range: `` @[low]. `- @[high].
-Char: `` @[s].
+Char-range: `` @[low]. `- (@[high]. / @[!]{=> "Expected a second character to form a character range"})
+Char: `` (@[s]. / @[!]{=> "Expected a character following the '`'"})
Escape-range: `\ @[low]escape-sequence `- @[high]escape-sequence
-Escape: `\ @[s]escape-sequence
+Escape: `\ (@[s]escape-sequence
+ / $ @[!]{=>"Backslashes are used for escape sequences, not splitting lines"}
+ / @[!]{. 0+(Abc/`0-9) => "Invalid escape sequence: '@0'"}
+)
escape-sequence: (
- 1-3 `0-7
+ `n/`t/`r/`e/`b/`a/`v
+ / 1-3 `0-7
/ `x 2 (`0-9/`a-f/`A-F)
- /`a/`b/`e/`n/`r/`t/`v / . / \n
)
-No: `! _ @pat
+No: `! (_@pat / @[!]{=>"Expected a pattern after the exclamation mark"})
Nodent: `|
Upto-and: 2-3`. 0-1(_@pat)
Repeat: (
@[min]int _ `- _ @[max]int
/ @[min]int _ `+ @[max]''
/ @[min]@[max]int
- ) _ @[repeat-pat]pat 0-1( __ `% __ @[sep]pat)
+ ) _ @[repeat-pat]pat 0-1( _ `% _ @[sep]pat)
After: `< _ pat
Before: `> _ pat
Capture: `@ 0-1(_ `[ @[capture-name](...>(`]/$$)) (`] / @[!]{=>"Expected closing bracket here"})) _ @[capture]pat
Replace: `{ __ (
0-1(@[replace-pat]extended-pat __) "=>" 0-1(__ @[replacement]String)
) __ (`} / @[!]{=> "Expected closing brace here"})
-Ref: @[name]id !>(__`:)
+Ref: @[name]id !>(_`:)
parens: `( __ extended-pat (__ `) / @[!]{=> "Expected closing parenthesis here"})
-Chain: 2+@pat % (__)
+Chain: 2+@pat % __
Otherwise: 2+@(Chain/pat) % (__`/__)
extended-pat: Otherwise / Chain / pat