/** * This Python 2.7 grammar was copied from the PyDev Project. (http://www.pydev.org/) * * Original source file: * https://github.com/aptana/Pydev/blob/development/plugins/org.python.pydev.parser/src/org/python/pydev/parser/grammar27/python.jjt (commit 32950d534139f286e03d34795aec99edab09c04c) */ options { BUILD_PARSER=false; CACHE_TOKENS=true; STATIC=false; UNICODE_INPUT = true; USER_CHAR_STREAM=true; } PARSER_BEGIN(PythonParser) package net.sourceforge.pmd.lang.python.ast; import net.sourceforge.pmd.lang.ast.CharStream; import net.sourceforge.pmd.lang.ast.TokenMgrError; public class PythonParser { } PARSER_END(PythonParser) SKIP : { | "\t" | "\014" | | } SPECIAL_TOKEN : { } TOKEN : /* SEPARATORS */ { < LPAREN: "(" > | < RPAREN: ")" > | < LBRACE: "{" > | < RBRACE: "}" > | < LBRACKET: "[" > | < RBRACKET: "]" > | < SEMICOLON: ";" > | < COMMA: "," > | < DOT: "." > | < COLON: ":" > | < BACKTICK: "`" > } TOKEN : /* OPERATORS */ { < PLUS: "+" > | < MINUS: "-" > | < MULTIPLY: "*" > | < DIVIDE: "/" > | < FLOORDIVIDE: "//" > | < POWER: "**" > | < LSHIFT: "<<" > | < RSHIFT: ">>" > | < MODULO: "%" > | < NOT: "~" > | < XOR: "^" > | < OR: "|" > | < AND: "&" > | < EQUAL: "=" > | < GREATER: ">" > | < LESS: "<" > | < EQEQUAL: "==" > | < EQLESS: "<=" > | < EQGREATER: ">=" > | < LESSGREATER: "<>" > | < NOTEQUAL: "!=" > | < PLUSEQ: "+=" > | < MINUSEQ: "-=" > | < MULTIPLYEQ: "*=" > | < DIVIDEEQ: "/=" > | < FLOORDIVIDEEQ: "//=" > | < MODULOEQ: "%=" > | < ANDEQ: "&=" > | < OREQ: "|=" > | < XOREQ: "^=" > | < LSHIFTEQ: "<<=" > | < RSHIFTEQ: ">>=" > | < POWEREQ: "**=" > } TOKEN : /* KEYWORDS */ { < OR_BOOL: "or" > | < AND_BOOL: "and" > | < NOT_BOOL: "not" > | < IS: "is" > | < IN: "in" > | < LAMBDA: "lambda" > | < IF: "if" > | < ELSE: "else" > | < ELIF: "elif" > | < WHILE: "while" > | < FOR: "for" > | < TRY: "try" > | < EXCEPT: "except" > | < DEF: "def" > | < CLASS: "class" > | < FINALLY: "finally" > | < PRINT: "print" > | < PASS: "pass" > | < BREAK: "break" > | < CONTINUE: "continue" > | < RETURN: "return" > | < YIELD: "yield" > | < IMPORT: "import" > | < FROM: "from" > | < DEL: "del" > | < RAISE: "raise" > | < GLOBAL: "global" > | < EXEC: "exec" > | < ASSERT: "assert" > | < AS: "as" > | | < AT: "@" > } TOKEN : /* Python identifiers */ { < NAME: ( | )* > | < #LETTER: ["_","a"-"z","A"-"Z"] > } TOKEN : /* Numeric literals */ { < DECNUMBER: ["1"-"9"] (["0"-"9"])* (["l", "L"])? | "0" > | < HEXNUMBER: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ (["l","L"])? > | < OCTNUMBER: "0" (["o","O"])? (["0"-"7"])* (["l","L"])? > | < BINNUMBER: "0" (["b","B"])? (["0"-"1"])* (["l","L"])? > | < FLOAT: (["0"-"9"])+ "." (["0"-"9"])* ()? | "." (["0"-"9"])+ ()? | (["0"-"9"])+ > | < COMPLEX: ( | | "0" ) ["j", "J"]> | < #EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ > | < #DIGIT: ["0" - "9"] > } MORE : /* Strings */ { < (["u", "U"]) (["r", "R"])? "'" > : IN_USTRING11 | < (["u", "U"]) (["r", "R"])? "\"" > : IN_USTRING21 | < (["u", "U"]) (["r", "R"])? "'''" > : IN_USTRING13 | < (["u", "U"]) (["r", "R"])? "\"\"\"" > : IN_USTRING23 | < (["b", "B"]) (["r", "R"])? "'" > : IN_BSTRING11 | < (["b", "B"]) (["r", "R"])? "\"" > : IN_BSTRING21 | < (["b", "B"]) (["r", "R"])? "'''" > : IN_BSTRING13 | < (["b", "B"]) (["r", "R"])? "\"\"\"" > : IN_BSTRING23 | < (["r", "R"])? "'" > : IN_STRING11 | < (["r", "R"])? "\"" > : IN_STRING21 | < (["r", "R"])? "'''" > : IN_STRING13 | < (["r", "R"])? "\"\"\"" > : IN_STRING23 } TOKEN : { { matchedToken.image = image.toString(); } : DEFAULT} TOKEN : { { matchedToken.image = image.toString(); } : DEFAULT} TOKEN : { { matchedToken.image = image.toString(); } : DEFAULT} TOKEN : { { matchedToken.image = image.toString(); } : DEFAULT} TOKEN : { { matchedToken.image = image.toString(); } : DEFAULT} TOKEN : { { matchedToken.image = image.toString(); } : DEFAULT} TOKEN : { { matchedToken.image = image.toString(); } : DEFAULT} TOKEN : { { matchedToken.image = image.toString(); } : DEFAULT} TOKEN : { { matchedToken.image = image.toString(); } : DEFAULT} TOKEN : { { matchedToken.image = image.toString(); } : DEFAULT} TOKEN : { { matchedToken.image = image.toString(); } : DEFAULT} TOKEN : { { matchedToken.image = image.toString(); } : DEFAULT} MORE: { <"\\\r\n"> { image.setLength(image.length()-3); } : IN_STRING1NLC | <("\\" ("\n"|"\r"))> { image.setLength(image.length()-2); } : IN_STRING1NLC } MORE: { <"\\\r\n"> { image.setLength(image.length()-3); } : IN_STRING2NLC | <("\\" ("\n"|"\r"))> { image.setLength(image.length()-2); } : IN_STRING2NLC } MORE: { <"\\\r\n"> { image.setLength(image.length()-3); } : IN_USTRING1NLC | <("\\" ("\n"|"\r"))> { image.setLength(image.length()-2); } : IN_USTRING1NLC } MORE: { <"\\\r\n"> { image.setLength(image.length()-3); } : IN_USTRING2NLC | <("\\" ("\n"|"\r"))> { image.setLength(image.length()-2); } : IN_USTRING2NLC } MORE: { <"\\\r\n"> { image.setLength(image.length()-3); } : IN_BSTRING1NLC | <("\\" ("\n"|"\r"))> { image.setLength(image.length()-2); } : IN_BSTRING1NLC } MORE: { <"\\\r\n"> { image.setLength(image.length()-3); } : IN_BSTRING2NLC | <("\\" ("\n"|"\r"))> { image.setLength(image.length()-2); } : IN_BSTRING2NLC } MORE: { <""> : IN_STRING11 } MORE: { <""> : IN_STRING21 } MORE: { <""> : IN_USTRING11 } MORE: { <""> : IN_USTRING21 } MORE: { <""> : IN_BSTRING11 } MORE: { <""> : IN_BSTRING21 } MORE: { <("\\" ("\\"|"'")) | ~["\n","\r"]> } MORE: { <("\\" ("\\"|"\"")) | ~["\n","\r"]> } MORE: { <"\r\n"> { int l = image.length(); image.setLength(l-1); image.setCharAt(l-2, '\n'); } | <"\n"> | <"\r"> { image.setCharAt(image.length()-1, '\n'); } | <~["\n","\r"]> | <"\\" ~["\n","\r"]> }