Skip to content

Commit 38bbb1f

Browse files
committedApr 24, 2016
re jython#10 Ellipsis (...) should be expr
1 parent 0b33367 commit 38bbb1f

File tree

6 files changed

+65
-21
lines changed

6 files changed

+65
-21
lines changed
 

‎ast/Python.asdl

+2-1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ module Python version "$Revision$"
8080
| Num(object n) -- a number as a PyObject.
8181
| Str(string s) -- need to specify raw, unicode, etc?
8282
-- other literals? bools?
83+
| Ellipsis
8384

8485
-- the following expression can appear in assignment context
8586
| Attribute(expr value, identifier attr, expr_context ctx)
@@ -94,7 +95,7 @@ module Python version "$Revision$"
9495

9596
expr_context = Load | Store | Del | AugLoad | AugStore | Param
9697

97-
slice = Ellipsis | Slice(expr? lower, expr? upper, expr? step)
98+
slice = Slice(expr? lower, expr? upper, expr? step)
9899
| ExtSlice(slice* dims)
99100
| Index(expr value)
100101

‎grammar/Python.g

+8-6
Original file line numberDiff line numberDiff line change
@@ -1928,6 +1928,10 @@ atom
19281928
{
19291929
etype = new Num($COMPLEX, actions.makeComplex($COMPLEX));
19301930
}
1931+
| ELLIPSIS
1932+
{
1933+
etype = new Ellipsis($ELLIPSIS);
1934+
}
19311935
| (S+=STRING)+
19321936
{
19331937
etype = new Str(actions.extractStringToken($S), actions.extractStrings($S, encoding, unicodeLiterals));
@@ -2054,17 +2058,13 @@ subscriptlist[Token begin]
20542058
}
20552059
;
20562060
2057-
//subscript: '.' '.' '.' | test | [test] ':' [test] [sliceop]
2061+
//subscript: test | [test] ':' [test] [sliceop]
20582062
subscript
20592063
returns [slice sltype]
20602064
@after {
20612065
$subscript.tree = $sltype;
20622066
}
2063-
: d1=DOT DOT DOT
2064-
{
2065-
$sltype = new Ellipsis($d1);
2066-
}
2067-
| (test[null] COLON)
2067+
: (test[null] COLON)
20682068
=> lower=test[expr_contextType.Load] (c1=COLON (upper1=test[expr_contextType.Load])? (sliceop)?)?
20692069
{
20702070
$sltype = actions.makeSubscript($lower.tree, $c1, $upper1.tree, $sliceop.tree);
@@ -2504,6 +2504,8 @@ ARROW : '->' ;
25042504

25052505
DOT : '.' ;
25062506

2507+
ELLIPSIS : '...' ;
2508+
25072509
AT : '@' ;
25082510

25092511
AND : 'and' ;

‎grammar/PythonPartial.g

+5-3
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,7 @@ atom
735735
| LONGINT
736736
| FLOAT
737737
| COMPLEX
738+
| ELLIPSIS
738739
| (STRING)+
739740
| TRISTRINGPART
740741
| STRINGPART TRAILBACKSLASH
@@ -779,10 +780,9 @@ subscriptlist
779780
: subscript (options {greedy=true;}:COMMA subscript)* (COMMA)?
780781
;
781782
782-
//subscript: '.' '.' '.' | test | [test] ':' [test] [sliceop]
783+
//subscript: test | [test] ':' [test] [sliceop]
783784
subscript
784-
: DOT DOT DOT
785-
| (test COLON)
785+
: (test COLON)
786786
=> test (COLON (test)? (sliceop)?)?
787787
| (COLON)
788788
=> COLON (test)? (sliceop)?
@@ -1014,6 +1014,8 @@ DOUBLESLASHEQUAL : '//=' ;
10141014

10151015
DOT : '.' ;
10161016

1017+
ELLIPSIS : '...' ;
1018+
10171019
AT : '@' ;
10181020

10191021
AND : 'and' ;

‎src/org/python/antlr/ast/Ellipsis.java

+43-4
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,16 @@
2727
import java.io.IOException;
2828
import java.util.ArrayList;
2929

30-
@ExposedType(name = "_ast.Ellipsis", base = slice.class)
31-
public class Ellipsis extends slice {
30+
@ExposedType(name = "_ast.Ellipsis", base = expr.class)
31+
public class Ellipsis extends expr {
3232
public static final PyType TYPE = PyType.fromClass(Ellipsis.class);
3333

3434
private final static PyString[] fields = new PyString[0];
3535
@ExposedGet(name = "_fields")
3636
public PyString[] get_fields() { return fields; }
3737

38-
private final static PyString[] attributes = new PyString[0];
38+
private final static PyString[] attributes =
39+
new PyString[] {new PyString("lineno"), new PyString("col_offset")};
3940
@ExposedGet(name = "_attributes")
4041
public PyString[] get_attributes() { return attributes; }
4142

@@ -46,7 +47,17 @@ public Ellipsis(PyType subType) {
4647
@ExposedMethod
4748
public void Ellipsis___init__(PyObject[] args, String[] keywords) {
4849
ArgParser ap = new ArgParser("Ellipsis", args, keywords, new String[]
49-
{}, 0, true);
50+
{"lineno", "col_offset"}, 0, true);
51+
int lin = ap.getInt(0, -1);
52+
if (lin != -1) {
53+
setLineno(lin);
54+
}
55+
56+
int col = ap.getInt(1, -1);
57+
if (col != -1) {
58+
setLineno(col);
59+
}
60+
5061
}
5162

5263
public Ellipsis() {
@@ -101,4 +112,32 @@ private void ensureDict() {
101112
}
102113
}
103114

115+
private int lineno = -1;
116+
@ExposedGet(name = "lineno")
117+
public int getLineno() {
118+
if (lineno != -1) {
119+
return lineno;
120+
}
121+
return getLine();
122+
}
123+
124+
@ExposedSet(name = "lineno")
125+
public void setLineno(int num) {
126+
lineno = num;
127+
}
128+
129+
private int col_offset = -1;
130+
@ExposedGet(name = "col_offset")
131+
public int getCol_offset() {
132+
if (col_offset != -1) {
133+
return col_offset;
134+
}
135+
return getCharPositionInLine();
136+
}
137+
138+
@ExposedSet(name = "col_offset")
139+
public void setCol_offset(int num) {
140+
col_offset = num;
141+
}
142+
104143
}

‎src/org/python/antlr/ast/VisitorBase.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,12 @@ public R visitStr(Str node) throws Exception {
301301
return ret;
302302
}
303303

304+
public R visitEllipsis(Ellipsis node) throws Exception {
305+
R ret = unhandled_node(node);
306+
traverse(node);
307+
return ret;
308+
}
309+
304310
public R visitAttribute(Attribute node) throws Exception {
305311
R ret = unhandled_node(node);
306312
traverse(node);
@@ -337,12 +343,6 @@ public R visitTuple(Tuple node) throws Exception {
337343
return ret;
338344
}
339345

340-
public R visitEllipsis(Ellipsis node) throws Exception {
341-
R ret = unhandled_node(node);
342-
traverse(node);
343-
return ret;
344-
}
345-
346346
public R visitSlice(Slice node) throws Exception {
347347
R ret = unhandled_node(node);
348348
traverse(node);

‎src/org/python/antlr/ast/VisitorIF.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ public interface VisitorIF<R> {
4848
public R visitRepr(Repr node) throws Exception;
4949
public R visitNum(Num node) throws Exception;
5050
public R visitStr(Str node) throws Exception;
51+
public R visitEllipsis(Ellipsis node) throws Exception;
5152
public R visitAttribute(Attribute node) throws Exception;
5253
public R visitSubscript(Subscript node) throws Exception;
5354
public R visitStarred(Starred node) throws Exception;
5455
public R visitName(Name node) throws Exception;
5556
public R visitList(List node) throws Exception;
5657
public R visitTuple(Tuple node) throws Exception;
57-
public R visitEllipsis(Ellipsis node) throws Exception;
5858
public R visitSlice(Slice node) throws Exception;
5959
public R visitExtSlice(ExtSlice node) throws Exception;
6060
public R visitIndex(Index node) throws Exception;

0 commit comments

Comments
 (0)
Please sign in to comment.