code / bp

Lines4.3K C3.3K Markdown541 YAML273 make110 Shell77 Lua54
(20 lines)
1 # Syntax definitions for some Python-specific patterns
2 #
3 # NOTE: this is *NOT* intended to be a complete definition of the language's
4 # syntax! Providing a full language grammar is overkill, because the intended
5 # use case is finding/replacing string patterns. This task does not require a
6 # full parse tree, and having one makes the task considerably more complicated.
7 # See the accompanying README.md for more info.
9 comment: `# ..$
10 string: "'''" ..%\n "'''" / '"""' ..%\n '"""' / `" ..%string-escape `" / `' ..%string-escape `'
11 keyword: ("and" / "as" / "assert" / "break" / "class" / "continue" / "def" /
12 "del" / "elif" / "else" / "except" / "finally" / "for" / "from" /
13 "global" / "if" / "import" / "in" / "is" / "lambda" / "None" / "nonlocal" /
14 "not" / "or" / "pass" / "raise" / "return" / "try" / "while" /
15 "with" / "yield")
16 class: class-def +(\N ..$)
17 class-def: ^_"class"|_id[_parens]_`:
18 function: function-def +(\N ..$)
19 function-def: ^_"def"|_id parens `:
20 import: ^_["from"| ..%parens >(|"import"|)] |"import"| ..%parens $