From: <fwi...@us...> - 2009-07-05 22:34:45
|
Revision: 6510 http://jython.svn.sourceforge.net/jython/?rev=6510&view=rev Author: fwierzbicki Date: 2009-07-05 22:34:44 +0000 (Sun, 05 Jul 2009) Log Message: ----------- Whitespace fixes for easier diffs. Modified Paths: -------------- trunk/jython/grammar/Python.g trunk/jython/grammar/PythonPartial.g Modified: trunk/jython/grammar/Python.g =================================================================== --- trunk/jython/grammar/Python.g 2009-07-05 18:07:53 UTC (rev 6509) +++ trunk/jython/grammar/Python.g 2009-07-05 22:34:44 UTC (rev 6510) @@ -156,7 +156,7 @@ import java.util.Collections; import java.util.Iterator; import java.util.ListIterator; -} +} @members { private ErrorHandler errorHandler; @@ -195,7 +195,7 @@ } } -@lexer::header { +@lexer::header { package org.python.antlr; } @@ -221,7 +221,7 @@ this.errorHandler = eh; } - /** + /** * Taken directly from antlr's Lexer.java -- needs to be re-integrated every time * we upgrade from Antlr (need to consider a Lexer subclass, though the issue would * remain). @@ -401,7 +401,7 @@ @after { $decorator.tree = $etype; } - : AT dotted_attr + : AT dotted_attr ( LPAREN ( arglist { @@ -443,8 +443,10 @@ //parameters: '(' [varargslist] ')' parameters returns [arguments args] - : LPAREN - (varargslist {$args = $varargslist.args;} + : LPAREN + (varargslist + {$args = $varargslist.args; + } | { $args = new arguments($parameters.start, new ArrayList<expr>(), null, null, new ArrayList<expr>()); } ) @@ -498,7 +500,7 @@ @after { actions.checkAssign(actions.castExpr($fpdef.tree)); } - : NAME + : NAME -> ^(NAME<Name>[$NAME, $NAME.text, ctype]) | (LPAREN fpdef[null] COMMA) => LPAREN fplist RPAREN -> ^(LPAREN<Tuple>[$fplist.start, actions.castExprs($fplist.etypes), expr_contextType.Store]) @@ -551,7 +553,7 @@ //expr_stmt: testlist (augassign (yield_expr|testlist) | // ('=' (yield_expr|testlist))*) -expr_stmt +expr_stmt @init { stmt stype = null; } @@ -561,7 +563,7 @@ } } : ((testlist[null] augassign) => lhs=testlist[expr_contextType.AugStore] - ( (aay=augassign y1=yield_expr + ( (aay=augassign y1=yield_expr { actions.checkAssign(actions.castExpr($lhs.tree)); stype = new AugAssign($lhs.tree, actions.castExpr($lhs.tree), $aay.op, actions.castExpr($y1.tree)); @@ -612,7 +614,7 @@ //print_stmt: 'print' ( [ test (',' test)* [','] ] | // '>>' test [ (',' test)+ [','] ] ) print_stmt - : PRINT + : PRINT (t1=printlist -> ^(PRINT<Print>[$PRINT, null, actions.castExprs($t1.elts), $t1.newline]) | RIGHTSHIFT t2=printlist2 @@ -702,7 +704,7 @@ //return_stmt: 'return' [testlist] return_stmt - : RETURN + : RETURN (testlist[expr_contextType.Load] -> ^(RETURN<Return>[$RETURN, actions.castExpr($testlist.tree)]) | @@ -737,7 +739,7 @@ //import_from: ('from' ('.'* dotted_name | '.'+) // 'import' ('*' | '(' import_as_names ')' | import_as_names)) import_from - : FROM (d+=DOT* dotted_name | d+=DOT+) IMPORT + : FROM (d+=DOT* dotted_name | d+=DOT+) IMPORT (STAR -> ^(FROM<ImportFrom>[$FROM, actions.makeFromText($d, $dotted_name.name), actions.makeStarAlias($STAR), actions.makeLevel($d)]) @@ -1001,7 +1003,7 @@ and_test[expr_contextType ctype] @after { if ($and != null) { - $and_test.tree = actions.makeBoolOp($left.tree, boolopType.And, $right); + $and_test.tree = actions.makeBoolOp($left.tree, boolopType.And, $right); } } : left=not_test[ctype] @@ -1064,7 +1066,7 @@ } @after { if ($op != null) { - $expr.tree = actions.makeBinOp($left.tree, operatorType.BitOr, $right); + $expr.tree = actions.makeBinOp($left.tree, operatorType.BitOr, $right); } } : left=xor_expr @@ -1080,7 +1082,7 @@ xor_expr @after { if ($op != null) { - $xor_expr.tree = actions.makeBinOp($left.tree, operatorType.BitXor, $right); + $xor_expr.tree = actions.makeBinOp($left.tree, operatorType.BitXor, $right); } } : left=and_expr @@ -1095,7 +1097,7 @@ and_expr @after { if ($op != null) { - $and_expr.tree = actions.makeBinOp($left.tree, operatorType.BitAnd, $right); + $and_expr.tree = actions.makeBinOp($left.tree, operatorType.BitAnd, $right); } } : left=shift_expr @@ -1113,7 +1115,7 @@ } @after { if (!ops.isEmpty()) { - $shift_expr.tree = actions.makeBinOp($left.tree, ops, $right); + $shift_expr.tree = actions.makeBinOp($left.tree, ops, $right); } } : left=arith_expr @@ -1240,7 +1242,7 @@ // '`' testlist1 '`' | // NAME | NUMBER | STRING+) atom - : LPAREN + : LPAREN ( yield_expr -> yield_expr | testlist_gexp @@ -1256,7 +1258,7 @@ -> ^(LBRACK<org.python.antlr.ast.List>[$LBRACK, new ArrayList<expr>(), $expr::ctype]) ) RBRACK - | LCURLY + | LCURLY (dictmaker -> ^(LCURLY<Dict>[$LCURLY, actions.castExprs($dictmaker.keys), actions.castExprs($dictmaker.values)]) @@ -1276,7 +1278,7 @@ -> ^(FLOAT<Num>[$FLOAT, actions.makeFloat($FLOAT)]) | COMPLEX -> ^(COMPLEX<Num>[$COMPLEX, actions.makeComplex($COMPLEX)]) - | (S+=STRING)+ + | (S+=STRING)+ -> ^(STRING<Str>[actions.extractStringToken($S), actions.extractStrings($S, encoding)]) ; @@ -1289,7 +1291,7 @@ @after { $listmaker.tree = etype; } - : t+=test[$expr::ctype] + : t+=test[$expr::ctype] (list_for[gens] { Collections.reverse(gens); @@ -1301,7 +1303,7 @@ etype = new org.python.antlr.ast.List($lbrack, actions.castExprs($t), $expr::ctype); } ) (COMMA)? - ; + ; //testlist_gexp: test ( gen_for | (',' test)* [','] ) testlist_gexp @@ -1354,7 +1356,7 @@ //trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME trailer [Token begin, PythonTree tree] - : LPAREN + : LPAREN (arglist -> ^(LPAREN<Call>[$begin, actions.castExpr($tree), actions.castExprs($arglist.args), actions.makeKeywords($arglist.keywords), $arglist.starargs, $arglist.kwargs]) @@ -1836,7 +1838,7 @@ WS : {startPos>0}?=> (' '|'\t'|'\u000C')+ {$channel=HIDDEN;} ; - + /** Grab everything before a real symbol. Then if newline, kill it * as this is a blank line. If whitespace followed by comment, kill it * as it's a comment on a line by itself. @@ -1906,7 +1908,7 @@ Only match \n here if we didn't start on left edge; let NEWLINE return that. Kill if newlines if we live on a line by ourselves - + Consume any leading whitespace if it starts on left edge. */ COMMENT Modified: trunk/jython/grammar/PythonPartial.g =================================================================== --- trunk/jython/grammar/PythonPartial.g 2009-07-05 18:07:53 UTC (rev 6509) +++ trunk/jython/grammar/PythonPartial.g 2009-07-05 22:34:44 UTC (rev 6510) @@ -60,14 +60,13 @@ */ grammar PythonPartial; - options { tokenVocab=Python; } -@header { +@header { package org.python.antlr; -} +} @members { private ErrorHandler errorHandler = new FailFastHandler(); @@ -90,7 +89,7 @@ } } -@lexer::header { +@lexer::header { package org.python.antlr; } @@ -116,7 +115,7 @@ this.errorHandler = eh; } - /** + /** * Taken directly from antlr's Lexer.java -- needs to be re-integrated every time * we upgrade from Antlr (need to consider a Lexer subclass, though the issue would * remain). @@ -172,15 +171,14 @@ //eval_input: testlist NEWLINE* ENDMARKER eval_input - : LEADING_WS? (NEWLINE)* testlist? (NEWLINE)* EOF ; //not in CPython's Grammar file -dotted_attr +dotted_attr : NAME - ( (DOT NAME)+ - | + ( (DOT NAME)+ + | ) ; @@ -223,95 +221,77 @@ ; //decorator: '@' dotted_name [ '(' [arglist] ')' ] NEWLINE -decorator - - : AT dotted_attr +decorator + : AT dotted_attr ( LPAREN ( arglist - - | + | ) RPAREN - | + | ) NEWLINE ; //decorators: decorator+ -decorators +decorators : decorator+ - ; //funcdef: [decorators] 'def' NAME parameters ':' suite funcdef - : decorators? DEF NAME parameters COLON suite - ; //parameters: '(' [varargslist] ')' -parameters - : LPAREN - (varargslist - | +parameters + : LPAREN + (varargslist + | ) RPAREN ; //not in CPython's Grammar file -defparameter - +defparameter : fpdef (ASSIGN test)? - ; //varargslist: ((fpdef ['=' test] ',')* // ('*' NAME [',' '**' NAME] | '**' NAME) | // fpdef ['=' test] (',' fpdef ['=' test])* [',']) -varargslist - +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 - + : NAME | (LPAREN fpdef COMMA) => LPAREN fplist RPAREN - | LPAREN fplist RPAREN - ; //fplist: fpdef (',' fpdef)* [','] -fplist +fplist : fpdef (options {greedy=true;}:COMMA fpdef)* (COMMA)? - ; //stmt: simple_stmt | compound_stmt -stmt +stmt : simple_stmt - | compound_stmt - ; //simple_stmt: small_stmt (';' small_stmt)* [';'] NEWLINE -simple_stmt +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 | @@ -327,57 +307,48 @@ | assert_stmt ; -expr_stmt - +expr_stmt : ((testlist augassign) => testlist - ( (augassign yield_expr - + ( (augassign yield_expr ) | (augassign testlist - ) ) | (testlist ASSIGN) => testlist ( | ((ASSIGN testlist)+ - ) | ((ASSIGN yield_expr)+ - ) ) | testlist - ) ; //augassign: ('+=' | '-=' | '*=' | '/=' | '%=' | '&=' | '|=' | '^=' | // '<<=' | '>>=' | '**=' | '//=') -augassign - : PLUSEQUAL - | MINUSEQUAL - | STAREQUAL - | SLASHEQUAL - | PERCENTEQUAL - | AMPEREQUAL - | VBAREQUAL - | CIRCUMFLEXEQUAL - | LEFTSHIFTEQUAL - | RIGHTSHIFTEQUAL - | DOUBLESTAREQUAL - | DOUBLESLASHEQUAL +augassign + : PLUSEQUAL + | MINUSEQUAL + | STAREQUAL + | SLASHEQUAL + | PERCENTEQUAL + | AMPEREQUAL + | VBAREQUAL + | CIRCUMFLEXEQUAL + | LEFTSHIFTEQUAL + | RIGHTSHIFTEQUAL + | DOUBLESTAREQUAL + | DOUBLESLASHEQUAL ; //print_stmt: 'print' ( [ test (',' test)* [','] ] | // '>>' test [ (',' test)+ [','] ] ) print_stmt - : PRINT + : PRINT (printlist - | RIGHTSHIFT printlist - | - ) ; @@ -389,13 +360,11 @@ //del_stmt: 'del' exprlist del_stmt : DELETE exprlist - ; //pass_stmt: 'pass' pass_stmt : PASS - ; //flow_stmt: break_stmt | continue_stmt | return_stmt | raise_stmt | yield_stmt @@ -410,35 +379,30 @@ //break_stmt: 'break' break_stmt : BREAK - ; //continue_stmt: 'continue' continue_stmt - : CONTINUE - + : CONTINUE ; //return_stmt: 'return' [testlist] return_stmt - : RETURN + : RETURN (testlist - | - ) ; //yield_stmt: yield_expr yield_stmt - : yield_expr + : yield_expr ; //raise_stmt: 'raise' [test [',' test [',' test]]] raise_stmt : RAISE (test (COMMA test (COMMA test)?)?)? - ; //import_stmt: import_name | import_from @@ -450,73 +414,58 @@ //import_name: 'import' dotted_as_names import_name : IMPORT dotted_as_names - ; //import_from: ('from' ('.'* dotted_name | '.'+) // 'import' ('*' | '(' import_as_names ')' | import_as_names)) import_from - : FROM (DOT* dotted_name | DOT+) IMPORT + : FROM (DOT* dotted_name | DOT+) IMPORT (STAR - | import_as_names - | LPAREN import_as_names COMMA? RPAREN - ) ; //import_as_names: import_as_name (',' import_as_name)* [','] -import_as_names +import_as_names : import_as_name (COMMA import_as_name)* - ; //import_as_name: NAME [('as' | NAME) NAME] -import_as_name - +import_as_name : NAME (AS NAME)? - ; //XXX: when does CPython Grammar match "dotted_name NAME NAME"? //dotted_as_name: dotted_name [('as' | NAME) NAME] -dotted_as_name - - +dotted_as_name : dotted_name (AS NAME)? - ; //dotted_as_names: dotted_as_name (',' dotted_as_name)* -dotted_as_names +dotted_as_names : dotted_as_name (COMMA dotted_as_name)* - ; //dotted_name: NAME ('.' NAME)* -dotted_name - : NAME (DOT attr)* +dotted_name + : NAME (DOT attr)* ; //global_stmt: 'global' NAME (',' NAME)* global_stmt : GLOBAL NAME (COMMA NAME)* - ; //exec_stmt: 'exec' expr ['in' test [',' test]] exec_stmt - : EXEC expr (IN test (COMMA test)?)? - ; //assert_stmt: 'assert' test [',' test] assert_stmt : ASSERT test (COMMA test)? - ; //compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | funcdef | classdef @@ -533,38 +482,31 @@ //if_stmt: 'if' test ':' suite ('elif' test ':' suite)* ['else' ':' suite] if_stmt : IF test COLON suite elif_clause? - ; //not in CPython's Grammar file -elif_clause - : else_clause +elif_clause + : else_clause | ELIF test COLON suite (elif_clause - | - ) ; //not in CPython's Grammar file -else_clause - : ORELSE COLON suite +else_clause + : ORELSE COLON suite ; //while_stmt: 'while' test ':' suite ['else' ':' suite] while_stmt - : WHILE test COLON suite (ORELSE COLON suite)? - ; //for_stmt: 'for' exprlist 'in' testlist ':' suite ['else' ':' suite] for_stmt - : FOR exprlist IN testlist COLON suite (ORELSE COLON suite)? - ; //try_stmt: ('try' ':' suite @@ -573,39 +515,30 @@ // ['finally' ':' suite] | // 'finally' ':' suite)) try_stmt - : TRY COLON suite ( except_clause+ (ORELSE COLON suite)? (FINALLY COLON suite)? - | FINALLY COLON suite - ) ; //with_stmt: 'with' test [ with_var ] ':' suite with_stmt - : WITH test (with_var)? COLON suite - ; //with_var: ('as' | NAME) expr -with_var +with_var : (AS | NAME) expr - ; //except_clause: 'except' [test [',' test]] except_clause : EXCEPT (test (COMMA test)?)? COLON suite - ; //suite: simple_stmt | NEWLINE INDENT stmt+ DEDENT -suite - +suite : simple_stmt - | NEWLINE (EOF | (DEDENT)+ EOF |INDENT (stmt)+ (DEDENT @@ -618,9 +551,7 @@ test :or_test ( (IF or_test ORELSE) => IF or_test ORELSE test - | - ) | lambdef ; @@ -631,7 +562,6 @@ ( (OR and_test )+ | - ) ; @@ -641,141 +571,122 @@ ( (AND not_test )+ | - ) ; //not_test: 'not' not_test | comparison not_test : NOT not_test - | comparison ; //comparison: expr (comp_op expr)* comparison : expr - ( ( comp_op expr + ( ( comp_op expr )+ | - ) ; //comp_op: '<'|'>'|'=='|'>='|'<='|'<>'|'!='|'in'|'not' 'in'|'is'|'is' 'not' -comp_op - : LESS - | GREATER - | EQUAL - | GREATEREQUAL - | LESSEQUAL - | ALT_NOTEQUAL - | NOTEQUAL - | IN - | NOT IN - | IS - | IS NOT +comp_op + : LESS + | GREATER + | EQUAL + | GREATEREQUAL + | LESSEQUAL + | ALT_NOTEQUAL + | NOTEQUAL + | IN + | NOT IN + | IS + | IS NOT ; - //expr: xor_expr ('|' xor_expr)* expr : xor_expr ( (VBAR xor_expr )+ | - ) ; - //xor_expr: and_expr ('^' and_expr)* xor_expr - : and_expr ( (CIRCUMFLEX and_expr )+ | - ) ; //and_expr: shift_expr ('&' shift_expr)* and_expr - : shift_expr ( (AMPER shift_expr )+ | - ) ; //shift_expr: arith_expr (('<<'|'>>') arith_expr)* shift_expr - : arith_expr - ( ( shift_op arith_expr + ( ( shift_op arith_expr )+ | - ) ; -shift_op - : LEFTSHIFT - | RIGHTSHIFT +shift_op + : LEFTSHIFT + | RIGHTSHIFT ; //arith_expr: term (('+'|'-') term)* arith_expr - : term - ( (arith_op term + ( (arith_op term )+ | - ) ; -arith_op - : PLUS - | MINUS +arith_op + : PLUS + | MINUS ; //term: factor (('*'|'/'|'%'|'//') factor)* term - : factor - ( (term_op factor + ( (term_op factor )+ | - ) ; -term_op - :STAR - |SLASH - |PERCENT - |DOUBLESLASH +term_op + :STAR + |SLASH + |PERCENT + |DOUBLESLASH ; //factor: ('+'|'-'|'~') factor | power -factor - - : PLUS factor - | MINUS factor - | TILDE factor - | power +factor + : PLUS factor + | MINUS factor + | TILDE factor + | power | TRAILBACKSLASH ; //power: atom trailer* ['**' factor] -power - +power : atom (trailer)* (options {greedy=true;}:DOUBLESTAR factor)? - ; //atom: ('(' [yield_expr|testlist_gexp] ')' | @@ -784,226 +695,176 @@ // '`' testlist1 '`' | // NAME | NUMBER | STRING+) atom - : LPAREN + : LPAREN ( yield_expr - | testlist_gexp - | - ) RPAREN | LBRACK (listmaker - | - ) RBRACK - | LCURLY + | LCURLY (dictmaker - | - ) RCURLY | BACKQUOTE testlist BACKQUOTE - | NAME - | INT - | LONGINT - | FLOAT - | COMPLEX - - | (STRING)+ - + | (STRING)+ | STRINGPART ; //listmaker: test ( list_for | (',' test)* [','] ) listmaker - : test + : test (list_for - | (options {greedy=true;}:COMMA test)* - ) (COMMA)? - ; + ; //testlist_gexp: test ( gen_for | (',' test)* [','] ) testlist_gexp - : test ( ((options {k=2;}: COMMA test)* (COMMA)? - - ) | (gen_for - ) ) ; //lambdef: 'lambda' [varargslist] ':' test lambdef - : LAMBDA (varargslist)? COLON test - ; //trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME -trailer - : LPAREN +trailer + : LPAREN (arglist - | - ) RPAREN | LBRACK subscriptlist RBRACK - | DOT attr - ; //subscriptlist: subscript (',' subscript)* [','] subscriptlist : subscript (options {greedy=true;}:COMMA subscript)* (COMMA)? - ; //subscript: '.' '.' '.' | test | [test] ':' [test] [sliceop] -subscript - +subscript : DOT DOT DOT - | (test COLON) => test (COLON (test)? (sliceop)?)? - | (COLON) => COLON (test)? (sliceop)? - | test - ; //sliceop: ':' [test] sliceop : COLON - (test + (test | ) ; //exprlist: expr (',' expr)* [','] -exprlist +exprlist : (expr COMMA) => expr (options {k=2;}: COMMA expr)* (COMMA)? - | expr - ; //not in CPython's Grammar file //Needed as an exprlist that does not produce tuples for del_stmt. -del_list +del_list : expr (options {k=2;}: COMMA expr)* (COMMA)? - ; //testlist: test (',' test)* [','] testlist : (test COMMA) => test (options {k=2;}: COMMA test)* (COMMA)? - | test ; //dictmaker: test ':' test (',' test ':' test)* [','] -dictmaker +dictmaker : test COLON test (options {k=2;}:COMMA test COLON test)* (COMMA)? - ; //classdef: 'class' NAME ['(' [testlist] ')'] ':' suite classdef - : decorators? CLASS NAME (LPAREN testlist? RPAREN)? COLON suite - ; //arglist: (argument ',')* (argument [',']| '*' test [',' '**' test] | '**' test) -arglist - +arglist : argument (COMMA argument)* (COMMA ( STAR test (COMMA DOUBLESTAR test)? | DOUBLESTAR test )? )? - | STAR test (COMMA DOUBLESTAR test)? - | DOUBLESTAR test - ; //argument: test [gen_for] | test '=' test # Really [keyword '='] test -argument +argument : test ((ASSIGN test) - | gen_for - - | + | ) ; //list_iter: list_for | list_if -list_iter +list_iter : list_for | list_if ; //list_for: 'for' exprlist 'in' testlist_safe [list_iter] -list_for +list_for : FOR exprlist IN testlist (list_iter)? - ; //list_if: 'if' test [list_iter] list_if : IF test (list_iter)? - ; //gen_iter: gen_for | gen_if -gen_iter +gen_iter : gen_for | gen_if ; //gen_for: 'for' exprlist 'in' or_test [gen_iter] -gen_for +gen_for : FOR exprlist IN or_test gen_iter? - ; //gen_if: 'if' old_test [gen_iter] gen_if : IF test gen_iter? - ; //yield_expr: 'yield' [testlist] yield_expr : YIELD testlist? - ; AS : 'as' ; @@ -1240,7 +1101,7 @@ WS : {startPos>0}?=> (' '|'\t'|'\u000C')+ {$channel=HIDDEN;} ; - + /** Grab everything before a real symbol. Then if newline, kill it * as this is a blank line. If whitespace followed by comment, kill it * as it's a comment on a line by itself. @@ -1310,7 +1171,7 @@ Only match \n here if we didn't start on left edge; let NEWLINE return that. Kill if newlines if we live on a line by ourselves - + Consume any leading whitespace if it starts on left edge. */ COMMENT This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |