aboutsummaryrefslogtreecommitdiff
path: root/grammars/python.bp
blob: 13c9251cd52d48941c4d3e6de2f7d118ff943a7f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 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: "'''" ..%\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")|
class: class-def +(\N ..$)
class-def: ^_|"class"|_id[_parens]_`:
function: function-def +(\N ..$)
function-def: ^_|"def"|_id parens `:
import: ^_["from"| ..%parens >(|"import"|)] |"import"| ..%parens $