bp/grammars/python.bp

21 lines
1.0 KiB
Plaintext
Raw Normal View History

2021-01-17 19:42:11 -08:00
# 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 '"""' / `" ..%string-escape `" / `' ..%string-escape `'
2021-08-01 12:40:27 -07:00
keyword: ("and" / "as" / "assert" / "break" / "class" / "continue" / "def" /
2021-01-17 19:42:11 -08:00
"del" / "elif" / "else" / "except" / "finally" / "for" / "from" /
"global" / "if" / "import" / "in" / "is" / "lambda" / "None" / "nonlocal" /
"not" / "or" / "pass" / "raise" / "return" / "try" / "while" /
2021-08-01 12:40:27 -07:00
"with" / "yield")
2021-01-17 20:05:19 -08:00
class: class-def +(\N ..$)
2021-07-30 20:23:18 -07:00
class-def: ^_"class"|_id[_parens]_`:
2021-01-17 19:42:11 -08:00
function: function-def +(\N ..$)
2021-07-30 20:23:18 -07:00
function-def: ^_"def"|_id parens `:
import: ^_["from"| ..%parens >(|"import"|)] |"import"| ..%parens $