[Jython-checkins] jython: A little less noise from ANTLR during the build.

jeff.allen jython-checkins at python.org
Fri Dec 28 10:42:05 EST 2018


https://hg.python.org/jython/rev/828c41688a52
changeset:   8210:828c41688a52
user:        Jeff Allen <ja.py at farowl.co.uk>
date:        Fri Dec 28 14:25:56 2018 +0000
summary:
  A little less noise from ANTLR during the build.

Introduces testlist1, as in the Python grammar, and answers a
long-standing question in the lexer.

files:
  grammar/Python.g        |  30 +++++++++++++++++++++++-----
  grammar/PythonPartial.g |  16 ++++++++++----
  2 files changed, 35 insertions(+), 11 deletions(-)


diff --git a/grammar/Python.g b/grammar/Python.g
--- a/grammar/Python.g
+++ b/grammar/Python.g
@@ -1770,9 +1770,9 @@
         }
        )
        RCURLY
-     | lb=BACKQUOTE testlist[expr_contextType.Load] rb=BACKQUOTE
+     | lb=BACKQUOTE testlist1[expr_contextType.Load] rb=BACKQUOTE
        {
-           etype = new Repr($lb, actions.castExpr($testlist.tree));
+           etype = new Repr($lb, actions.castExpr($testlist1.tree));
        }
      | name_or_print
        {
@@ -2206,6 +2206,26 @@
       }
     ;
 
+// Variant of testlist used between BACKQUOTEs (the deprecated back-tick repr()) only
+//testlist1: test (',' test)*
+testlist1[expr_contextType ctype]
+ at init {
+    expr etype = null;
+}
+ at after {
+    if (etype != null) {
+        $testlist1.tree = etype;
+    }
+}
+    : t+=test[ctype]
+      (
+        COMMA t+=test[ctype]
+        {
+            etype = new Tuple($testlist1.start, actions.castExprs($t), ctype);
+        }
+      )*
+    ;
+
 //yield_expr: 'yield' [testlist]
 yield_expr
     returns [expr etype]
@@ -2400,16 +2420,14 @@
         }
     ;
 
-/** the two '"'? cause a warning -- is there a way to avoid that? */
 fragment
 TRIQUOTE
-    : '"'? '"'? (ESC|~('\\'|'"'))+
+    : ('"' '"'?)? (ESC|~('\\'|'"'))+
     ;
 
-/** the two '\''? cause a warning -- is there a way to avoid that? */
 fragment
 TRIAPOS
-    : '\''? '\''? (ESC|~('\\'|'\''))+
+    : ('\'' '\''?)? (ESC|~('\\'|'\''))+
     ;
 
 fragment
diff --git a/grammar/PythonPartial.g b/grammar/PythonPartial.g
--- a/grammar/PythonPartial.g
+++ b/grammar/PythonPartial.g
@@ -187,7 +187,7 @@
 
 //eval_input: testlist NEWLINE* ENDMARKER
 eval_input
-    : LEADING_WS? (NEWLINE)* testlist? (NEWLINE)* EOF
+    : LEADING_WS? (NEWLINE)* (testlist (NEWLINE)*)? EOF
     ;
 
 //not in CPython's Grammar file
@@ -744,7 +744,7 @@
        |
        )
        RCURLY
-     | BACKQUOTE testlist BACKQUOTE
+     | BACKQUOTE testlist1 BACKQUOTE
      | NAME
      | INT
      | LONGINT
@@ -907,6 +907,12 @@
     : IF test comp_iter?
     ;
 
+// Variant of testlist used between BACKQUOTEs (the deprecated back-tick repr()) only
+//testlist1: test (',' test)*
+testlist1
+    : test (COMMA test)*
+    ;
+
 //yield_expr: 'yield' [testlist]
 yield_expr
     : YIELD testlist?
@@ -1106,13 +1112,13 @@
 /** the two '"'? cause a warning -- is there a way to avoid that? */
 fragment
 TRIQUOTE
-    : '"'? '"'? (ESC|~('\\'|'"'))+
+    : ('"' '"'?)? (ESC|~('\\'|'"'))+
     ;
 
 /** the two '\''? cause a warning -- is there a way to avoid that? */
 fragment
 TRIAPOS
-    : '\''? '\''? (ESC|~('\\'|'\''))+
+    : ('\'' '\''?)? (ESC|~('\\'|'\''))+
     ;
 
 fragment
@@ -1133,7 +1139,7 @@
          | nl=NEWLINE
            {
                extraNewlines = true;
-           }        
+           }
          |
          ) {
                if (input.LA(1) == -1) {

-- 
Repository URL: https://hg.python.org/jython


More information about the Jython-checkins mailing list