(20 lines)
1 # Syntax definitions for some Python-specific patterns2 #3 # NOTE: this is *NOT* intended to be a complete definition of the language's4 # syntax! Providing a full language grammar is overkill, because the intended5 # use case is finding/replacing string patterns. This task does not require a6 # 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 $