summaryrefslogtreecommitdiffstats
path: root/third_party/rust/jsparagus/pgen.pgen
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /third_party/rust/jsparagus/pgen.pgen
parentInitial commit. (diff)
downloadfirefox-esr-upstream.tar.xz
firefox-esr-upstream.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/jsparagus/pgen.pgen')
-rw-r--r--third_party/rust/jsparagus/pgen.pgen89
1 files changed, 89 insertions, 0 deletions
diff --git a/third_party/rust/jsparagus/pgen.pgen b/third_party/rust/jsparagus/pgen.pgen
new file mode 100644
index 0000000000..36b7483bb0
--- /dev/null
+++ b/third_party/rust/jsparagus/pgen.pgen
@@ -0,0 +1,89 @@
+# Grammar for the pgen parser specification language
+#
+# This was used to bootstrap the parser for the emu-grammar parser
+# specification language, and it's not clear why we should have two things.
+# Ignore this for now.
+
+var token IDENT;
+var token STR;
+var token MATCH;
+var token COMMENT;
+token Eq = "=";
+token Arrow = "=>";
+token Semi = ";";
+token Token = "token";
+token Var = "var";
+token Nt = "nt";
+token Goal = "goal";
+token Some = "Some";
+token None = "None";
+token OpenBrace = "{";
+token CloseBrace = "}";
+token OpenParen = "(";
+token CloseParen = ")";
+token Comma = ",";
+token QuestionMark = "?";
+
+goal nt grammar {
+ token_defs? nt_defs => grammar($0, $1);
+}
+
+nt token_defs {
+ token_def => single($0);
+ token_defs token_def => append($0, $1);
+}
+
+nt token_def {
+ "token" IDENT "=" STR ";" => const_token($1, $3);
+ "var" "token" IDENT ";" => var_token($2);
+}
+
+nt nt_defs {
+ nt_def => nt_defs_single($0);
+ nt_defs nt_def => nt_defs_append($0, $1);
+}
+
+nt nt_def {
+ COMMENT? "goal"? "nt" IDENT "{" prods? "}" => nt_def($0, $1, $3, $5);
+}
+
+nt prods {
+ prod => single($0);
+ prods prod => append($0, $1);
+ COMMENT => empty($0);
+}
+
+nt prod {
+ terms reducer? ";" => prod($0, $1);
+}
+
+nt terms {
+ term => single($0);
+ terms term => append($0, $1);
+}
+
+nt term {
+ symbol;
+ symbol "?" => optional($0);
+}
+
+nt symbol {
+ IDENT => ident($0);
+ STR => str($0);
+}
+
+nt reducer {
+ "=>" expr => $1;
+}
+
+nt expr {
+ MATCH => expr_match($0);
+ IDENT "(" expr_args? ")" => expr_call($0, $2);
+ "Some" "(" expr ")" => expr_some($2);
+ "None" => expr_none();
+}
+
+nt expr_args {
+ expr => args_single($0);
+ expr_args "," expr => args_append($0, $2);
+}