aboutsummaryrefslogtreecommitdiff
path: root/bpeg.bpeg
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2020-09-10 02:02:40 -0700
committerBruce Hill <bruce@bruce-hill.com>2020-09-10 02:02:40 -0700
commit8126489f81c37d6a8961f0f0e4f6193da38a4dc0 (patch)
tree5865e590cd2830bd3b2521d2950a5db387ee21cb /bpeg.bpeg
parent384fb6293a85502bbc9423b8b098337e77bb3738 (diff)
Some bug fixes, syntax tweaks, added ^^/$$/__, and bpeg meta grammar.
Diffstat (limited to 'bpeg.bpeg')
-rw-r--r--bpeg.bpeg59
1 files changed, 59 insertions, 0 deletions
diff --git a/bpeg.bpeg b/bpeg.bpeg
new file mode 100644
index 0000000..b90f7d0
--- /dev/null
+++ b/bpeg.bpeg
@@ -0,0 +1,59 @@
+# This is a file defining the BPEG grammar using BPEG syntax
+
+grammar;
+grammar = __ @[mainPattern]extendedPat __ (*def % (__`;__)) ?(__ `;) __;
+def = @[name]ref __ `= __ @[definition]extendedPat;
+
+# This is used for command line arguments:
+stringGrammar = *(`\ pat ?`; / .);
+
+pat = empty / dot / string / charRange / char / escape / no / anythingBut
+ / uptoAnd / repeat / after / before / capture / replace / ref / parens;
+
+empty = `/ >(__ (`}/`}));
+dot = `.;
+string = (
+ `" @[s]*(escape / ~`") `"
+ / `' @[s]*(escape / ~`') `'
+ );
+charRange = `` @[low]. `- @[high].;
+char = `` @[s].;
+escape = `\ @[s](
+ 1-3 `0-7
+ / `x 2 (`0-9/`a-f/`A-F)
+ /`a/`b/`e/`n/`r/`t/`v / . / \n
+ );
+no = `! _ @pat;
+anythingBut = `~ _ @pat;
+uptoAnd = `& _ @pat;
+repeat = (
+ @[min]int _ `- _ @[max]int
+ / @[min]{->"0"} @[max]int _ `-
+ / @[min]int _ `+ @[max](/)
+ / @[min] @[max]int
+ / `+ @[min]{->"1"} @[max](/)
+ / `* @[min]{->"0"} @[max](/)
+ / `? @[min]{->"0"} @[max]{->"1"}
+ ) _ @[repeatPat]pat ?( __ `% __ @[sep]pat);
+after = `< _ pat;
+before = `> _ pat;
+capture = `@ ?(_ `[ @[captureName]ref `]) _ @[capture]pat;
+replace = `{ __ (
+ ?(@[replacePat]extendedPat __) "=>" ?(__ @[replacement]string)
+ ) __ `};
+ref = @[name](
+ "^^" / "^" / "__" / "_" / "$$" / "$" /
+ (`a-z/`A-Z) *(`a-z/`A-Z/`0-9));
+
+parens = `( __ extendedPat __ `);
+
+chain = +@pat % (__);
+otherwise = +@(chain/pat) % (__`/__);
+extendedPat = otherwise / chain / pat;
+
+_ = *(` / \t);
+__ = *(` / \t / \r / \n / comment);
+hashComment = `# *.;
+
+# Note: comments are undefined by default in regular BPEG
+comment = hashComment;