aboutsummaryrefslogtreecommitdiff
path: root/grammars/python.bp
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2021-01-17 19:42:11 -0800
committerBruce Hill <bruce@bruce-hill.com>2021-01-17 19:42:11 -0800
commit51313c4773f0af62121b2192ff0cca9560b7ab44 (patch)
tree5873f54aafe2cd537e286a88b368ba0315d3e15d /grammars/python.bp
parent23f9b7ade9eccc6aee2e6c2a6737630a9d0cc77d (diff)
Adding more language grammars
Diffstat (limited to 'grammars/python.bp')
-rw-r--r--grammars/python.bp30
1 files changed, 30 insertions, 0 deletions
diff --git a/grammars/python.bp b/grammars/python.bp
new file mode 100644
index 0000000..0683c0a
--- /dev/null
+++ b/grammars/python.bp
@@ -0,0 +1,30 @@
+# Syntax definitions for some Python-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: `# ..$
+string: quoted-string / `b quoted-string / `f quoted-string
+quoted-string: "'''".."'''" % \n / '"""'..'"""' % \n / `"..`" % (`\.) / `'..`' % (`\.)
+dict: `{__`} / `{ __ +(expr__`:__expr) % (__`,__) __ `}
+set: `{ __ +expr % (__`,__) __ `}
+list: `[ __ +expr % (__`,__) __ `]
+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 ..$)
+function: function-def +(\N ..$)
+function-def: |"def"|_id parens `:
+function-call: !<"def " id parens
+lambda: |"lambda"| .. `:__expr