From: <fwi...@us...> - 2009-06-23 02:20:08
|
Revision: 6495 http://jython.svn.sourceforge.net/jython/?rev=6495&view=rev Author: fwierzbicki Date: 2009-06-23 02:20:07 +0000 (Tue, 23 Jun 2009) Log Message: ----------- Part 1 of making PythonPartial.g diffable from Python.g. Modified Paths: -------------- trunk/jython/grammar/PythonPartial.g Modified: trunk/jython/grammar/PythonPartial.g =================================================================== --- trunk/jython/grammar/PythonPartial.g 2009-06-22 16:38:12 UTC (rev 6494) +++ trunk/jython/grammar/PythonPartial.g 2009-06-23 02:20:07 UTC (rev 6495) @@ -52,14 +52,11 @@ * * I (Terence) tested this by running it on the jython-2.1/Lib * directory of 40k lines of Python. - * + * + * REQUIRES ANTLR v3 + * * Updated to Python 2.5 by Frank Wierzbicki. * - * This particular version has some changes to allow "partial" parsing - * So that an interactive session can tell if it should wait for more - * input or not. For example, this grammar will allow a String that - * starts with """ but has no ending """ and will allow a Suite to have - * an indent but no dedent. */ parser grammar PythonPartial; @@ -93,58 +90,160 @@ } } -single_input : NEWLINE - | simple_stmt - | compound_stmt NEWLINE? - ; +//single_input: NEWLINE | simple_stmt | compound_stmt NEWLINE +single_input + : NEWLINE + | simple_stmt + | compound_stmt NEWLINE? + ; + //eval_input: testlist NEWLINE* ENDMARKER -eval_input : LEADING_WS? (NEWLINE)* testlist? (NEWLINE)* EOF - ; +eval_input -decorators: decorator+ - ; + : LEADING_WS? (NEWLINE)* testlist? (NEWLINE)* EOF + ; -decorator: AT dotted_attr (LPAREN arglist? RPAREN)? NEWLINE - ; +//not in CPython's Grammar file +dotted_attr + : NAME + ( (DOT NAME)+ + | + ) + ; -dotted_attr - : NAME (DOT NAME)* +//attr is here for Java compatibility. A Java foo.getIf() can be called from Jython as foo.if +// so we need to support any keyword as an attribute. + +attr + : NAME + | AND + | AS + | ASSERT + | BREAK + | CLASS + | CONTINUE + | DEF + | DELETE + | ELIF + | EXCEPT + | EXEC + | FINALLY + | FROM + | FOR + | GLOBAL + | IF + | IMPORT + | IN + | IS + | LAMBDA + | NOT + | OR + | ORELSE + | PASS + | PRINT + | RAISE + | RETURN + | TRY + | WHILE + | WITH + | YIELD ; -funcdef : decorators? DEF NAME parameters COLON suite - ; +//decorator: '@' dotted_name [ '(' [arglist] ')' ] NEWLINE +decorator -parameters : LPAREN (varargslist)? RPAREN - ; + : AT dotted_attr + ( LPAREN + ( arglist + + | + ) + RPAREN + | + ) NEWLINE + ; -varargslist : defparameter (options {greedy=true;}:COMMA defparameter)* - (COMMA - ( STAR NAME (COMMA DOUBLESTAR NAME)? - | DOUBLESTAR NAME - )? - )? - | STAR NAME (COMMA DOUBLESTAR NAME)? - | DOUBLESTAR NAME - ; +//decorators: decorator+ +decorators + : decorator+ + + ; -defparameter : fpdef (ASSIGN test)? - ; +//funcdef: [decorators] 'def' NAME parameters ':' suite +funcdef -fpdef : NAME - | LPAREN fplist RPAREN - ; + : decorators? DEF NAME parameters COLON suite + + ; -fplist : fpdef (options {greedy=true;}:COMMA fpdef)* (COMMA)? - ; +//parameters: '(' [varargslist] ')' +parameters + : LPAREN + (varargslist + | + ) + RPAREN + ; -stmt : simple_stmt - | compound_stmt - ; +//not in CPython's Grammar file +defparameter -simple_stmt : small_stmt (options {greedy=true;}:SEMI small_stmt)* (SEMI)? (NEWLINE|EOF) - ; + : fpdef (ASSIGN test)? + + ; +//varargslist: ((fpdef ['=' test] ',')* +// ('*' NAME [',' '**' NAME] | '**' NAME) | +// fpdef ['=' test] (',' fpdef ['=' test])* [',']) +varargslist + + : defparameter (options {greedy=true;}:COMMA defparameter)* + (COMMA + (STAR NAME (COMMA DOUBLESTAR NAME)? + | DOUBLESTAR NAME + )? + )? + + | STAR NAME (COMMA DOUBLESTAR NAME)? + + | DOUBLESTAR NAME + + ; + +//fpdef: NAME | '(' fplist ')' +fpdef + : NAME + + | (LPAREN fpdef COMMA) => LPAREN fplist RPAREN + + | LPAREN fplist RPAREN + + ; + +//fplist: fpdef (',' fpdef)* [','] +fplist + : fpdef + (options {greedy=true;}:COMMA fpdef)* (COMMA)? + + ; + +//stmt: simple_stmt | compound_stmt +stmt + : simple_stmt + + | compound_stmt + + ; + +//simple_stmt: small_stmt (';' small_stmt)* [';'] NEWLINE +simple_stmt + : small_stmt (options {greedy=true;}:SEMI small_stmt)* (SEMI)? (NEWLINE|EOF) + + ; + +//small_stmt: (expr_stmt | print_stmt | del_stmt | pass_stmt | flow_stmt | +// import_stmt | global_stmt | exec_stmt | assert_stmt) small_stmt : expr_stmt | print_stmt | del_stmt This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |