aboutsummaryrefslogtreecommitdiff
path: root/grammars
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2021-01-17 20:05:19 -0800
committerBruce Hill <bruce@bruce-hill.com>2021-01-17 20:05:19 -0800
commit008db802298d688067ed9615079be28978e60e28 (patch)
treeeb1a4e080aad6356852b4712b5bdc1901e817697 /grammars
parentfdc91544b7c7a57243e5504c29dab68e45cc79cc (diff)
Adding and improving grammars.
Diffstat (limited to 'grammars')
-rw-r--r--grammars/c.bp4
-rw-r--r--grammars/go.bp18
-rw-r--r--grammars/python.bp20
-rw-r--r--grammars/rust.bp19
4 files changed, 43 insertions, 18 deletions
diff --git a/grammars/c.bp b/grammars/c.bp
index 2b2e1d9..e7c4d22 100644
--- a/grammars/c.bp
+++ b/grammars/c.bp
@@ -8,9 +8,6 @@
comment: "//" .. $ / "/*" .. "*/" % \n
string: `"..`" % (`\.)
-char: `' [`\] . `'
-array: `{..`} % (array/comment/\n)
-struct: array
keyword: |(
"auto" / "break" / "case" / "char" / "const" / "continue" / "default" / "do" /
"double" / "else" / "enum" / "extern" / "float" / "for" / "goto" / "if" /
@@ -21,3 +18,4 @@ keyword: |(
function-def: ^_ 2+(keyword / id / `*) % __ parens (__`; / >(__`{))
function: function-def __ braces
macro: ^"#define " ..$ *(<`\ \n..$)
+import: |"#include"| __ (string / `<..`>)
diff --git a/grammars/go.bp b/grammars/go.bp
new file mode 100644
index 0000000..52abd64
--- /dev/null
+++ b/grammars/go.bp
@@ -0,0 +1,18 @@
+# Syntax definitions for some Go-specific patterns
+#
+# NOTE: this is *NOT* intended to be a complete definition of the language's
+# syntax! Providing a full language grammar is overkill, because the intended
+# use case is finding/replacing string patterns. This task does not require a
+# full parse tree, and having one makes the task considerably more complicated.
+# See the accompanying README.md for more info.
+
+comment: "//" .. $ / "/*" .. "*/" % \n
+string: `"..`" % (`\.)
+keyword: |(
+ "break" / "default" / "func" / "interface" / "select" / "case" / "defer" / "go" /
+ "map" / "struct" / "chan" / "else" / "goto" / "package" / "switch" / "const" /
+ "fallthrough" / "if" / "range" / "type" / "continue" / "for" / "import" / "return" / "var"
+)|
+function-def: |"func"| __ id __ parens __ [id / parens] >(__`{)
+function: function-def __ braces
+import: |"import"| __ (parens / string)
diff --git a/grammars/python.bp b/grammars/python.bp
index 0683c0a..6928580 100644
--- a/grammars/python.bp
+++ b/grammars/python.bp
@@ -7,24 +7,14 @@
# See the accompanying README.md for more info.
comment: `# ..$
-string: quoted-string / `b quoted-string / `f quoted-string
-quoted-string: "'''".."'''" % \n / '"""'..'"""' % \n / `"..`" % (`\.) / `'..`' % (`\.)
-dict: `{__`} / `{ __ +(expr__`:__expr) % (__`,__) __ `}
-set: `{ __ +expr % (__`,__) __ `}
-list: `[ __ +expr % (__`,__) __ `]
+string: "'''".."'''" % \n / '"""'..'"""' % \n / `"..`" % (`\.) / `'..`' % (`\.)
keyword: |("and" / "as" / "assert" / "break" / "class" / "continue" / "def" /
"del" / "elif" / "else" / "except" / "finally" / "for" / "from" /
"global" / "if" / "import" / "in" / "is" / "lambda" / "None" / "nonlocal" /
"not" / "or" / "pass" / "raise" / "return" / "try" / "while" /
"with" / "yield")|
-expr: (function-call / lambda / string / dict / set / list / id / number / `(__expr__`)) *(method/attr/index)
-method: `. function-call
-attr: `. id
-index: `[__expr[__`:__expr [__`:__expr]]__`]
-tuple: `(__`) / +(__expr__`,) [__expr]
-empty-tuple: `(__`)
-class: |"class"|_id`: +(\N ..$)
+class: class-def +(\N ..$)
+class-def: ^_|"class"|_id[_parens]_`:
function: function-def +(\N ..$)
-function-def: |"def"|_id parens `:
-function-call: !<"def " id parens
-lambda: |"lambda"| .. `:__expr
+function-def: ^_|"def"|_id parens `:
+import: |"import"| _ (parens / *id%(_`,__)) [_ |"as"| (parens / *id%(_`,__))]
diff --git a/grammars/rust.bp b/grammars/rust.bp
new file mode 100644
index 0000000..003427a
--- /dev/null
+++ b/grammars/rust.bp
@@ -0,0 +1,19 @@
+# Syntax definitions for some Rust-specific patterns
+#
+# NOTE: this is *NOT* intended to be a complete definition of the language's
+# syntax! Providing a full language grammar is overkill, because the intended
+# use case is finding/replacing string patterns. This task does not require a
+# full parse tree, and having one makes the task considerably more complicated.
+# See the accompanying README.md for more info.
+
+comment: "//" .. $ / "/*" .. "*/" % (comment / \n)
+string: `"..`" % (`\.)
+keyword: |(
+ "as" / "break" / "const" / "continue" / "crate" / "else" / "enum" / "extern" /
+ "false" / "fn" / "for" / "if" / "impl" / "in" / "let" / "loop" / "match" /
+ "mod" / "move" / "mut" / "pub" / "ref" / "return" / "self" / "Self" / "static" /
+ "struct" / "super" / "trait" / "true" / "type" / "unsafe" / "use" / "where" / "while"
+)|
+function-def: |"fn"| __ id __ parens __ ["->"__(id / parens)] >(__`{)
+function: function-def __ braces
+import: |"use"| _ *(id / braces) % "::" _ `;