aboutsummaryrefslogtreecommitdiff
path: root/grammars/bpeg.bpeg
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2020-09-16 17:57:56 -0700
committerBruce Hill <bruce@bruce-hill.com>2020-09-16 17:57:56 -0700
commit21807a663d0ab1fc934e1bb3ad485fe1c3e9c821 (patch)
tree618f998a8073b0adce37cb0947718945dedf775d /grammars/bpeg.bpeg
parent79efa8bf5efed69fafc558968d51da4dbdd9cfd1 (diff)
Consolidated repetition ops (instead of '+', '*', '?', etc. now it's all
number based: '1+', '0+', '0-1') and reverted to UPTO_AND behavior instead of UPTO
Diffstat (limited to 'grammars/bpeg.bpeg')
-rw-r--r--grammars/bpeg.bpeg66
1 files changed, 66 insertions, 0 deletions
diff --git a/grammars/bpeg.bpeg b/grammars/bpeg.bpeg
new file mode 100644
index 0000000..dd3a3b4
--- /dev/null
+++ b/grammars/bpeg.bpeg
@@ -0,0 +1,66 @@
+# This is a file defining the BPEG grammar using BPEG syntax
+
+Grammar = __ 0+Def%(__`;__) 0-1(`;__);
+Def = @[name]Ref __ `= __ @[definition]extended-pat;
+
+# This is used for command line arguments:
+String-pattern = 0+(`\ pat 0-1`; / .);
+
+pat = suffixed-pat / simple-pat;
+simple-pat = Empty / Upto-and / Dot / String / Char-range / Char / Escape-range / Escape / No
+ / Nodent / Repeat / After / Before / Capture / Replace / Ref / parens;
+suffixed-pat = Eq-pat;
+
+Eq-pat = @[first]simple-pat "==" @[second]pat;
+
+Empty = `/ >(__ (`)/`}));
+Dot = `. !`.;
+String = (
+ `" @[s]0+(Escape / !`"$.) `"
+ / `' @[s]0+(Escape / !`'$.) `'
+ );
+Char-range = `` @[low]. `- @[high].;
+Char = `` @[s].;
+Escape-range = `\ @[low]escape-sequence `- @[high]escape-sequence;
+Escape = `\ @[s]escape-sequence;
+escape-sequence = (
+ 1-3 `0-7
+ / `x 2 (`0-9/`a-f/`A-F)
+ /`a/`b/`e/`n/`r/`t/`v / . / \n
+ );
+No = `! _ @pat;
+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);
+After = `< _ pat;
+Before = `> _ pat;
+Capture = `@ 0-1(_ `[ @[capture-name]Ref `]) _ @[capture]pat;
+Replace = `{ __ (
+ 0-1(@[replace-pat]extended-pat __) "=>" 0-1(__ @[replacement]String)
+ ) __ `};
+Ref = @[name](
+ "^^" / "^" / "__" / "_" / "$$" / "$" /
+ (`a-z/`A-Z) 0+(`a-z/`A-Z/`0-9/`-));
+
+parens = `( __ extended-pat __ `);
+
+Chain = 2+@pat % (__);
+Otherwise = 2+@(Chain/pat) % (__`/__);
+extended-pat = Otherwise / Chain / pat;
+
+# Special-symbol rules:
+_ = 0+(` / \t);
+__ = 0+(` / \t / \r / \n / comment);
+$$ = !$.;
+$ = !.;
+^^ = !<$.;
+^ = !<.;
+
+hash-comment = `# .. $;
+
+# Note: comments are undefined by default in regular BPEG
+comment = hash-comment;