Skip to content

Commit b358539

Browse files
committed
feat(builtin): Ellipsis (ast syntax ... is sup too)
1 parent 511e0f2 commit b358539

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

Objects/pyobjectBase.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ type
1010
NULL,
1111
Object,
1212
None,
13-
NotImplemented,
13+
Ellipsis,
1414
BaseError, # exception
1515
Int,
1616
Float,

Objects/sliceobject.nim

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,18 @@ proc getSliceItems*(slice: PySliceObject, src, dest: ptr seq[PyObject]): PyObjec
7070
dest[].add(src[][start])
7171
start += step
7272
pyNone
73+
74+
declarePyType Ellipsis(tpToken):
75+
discard
76+
77+
let pyEllipsis* = newPyEllipsisSimple()
78+
79+
proc dollar(self: PyEllipsisObject): string = "Ellipsis"
80+
method `$`*(self: PyEllipsisObject): string =
81+
self.dollar
82+
83+
implEllipsisMagic repr:
84+
newPyString self.dollar
85+
86+
implEllipsisMagic New(tp: PyObject):
87+
return pyEllipsis

Python/ast.nim

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ import strformat
77

88
import asdl
99
import ../Parser/[token, parser]
10-
import ../Objects/[pyobject, noneobject, numobjects, boolobjectImpl, stringobjectImpl]
10+
import ../Objects/[pyobject, noneobject,
11+
numobjects, boolobjectImpl, stringobjectImpl,
12+
sliceobject # pyEllipsis
13+
]
1114
import ../Utils/[utils, compat]
1215

1316

@@ -1053,8 +1056,10 @@ ast atom, [AsdlExpr]:
10531056
of Token.None:
10541057
result = newAstConstant(pyNone)
10551058

1059+
of Token.Ellipsis:
1060+
result = newAstConstant(pyEllipsis)
10561061
else:
1057-
raiseSyntaxError("ellipsis not implemented")
1062+
unreachable()
10581063

10591064
assert result != nil
10601065
setNo(result, parseNode.children[0])

Python/bltinmodule.nim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ implBltinFunc buildClass(funcObj: PyFunctionObject, name: PyStrObject), "__build
107107

108108

109109
registerBltinObject("NotImplemented", pyNotImplemented)
110+
registerBltinObject("Ellipsis", pyEllipsis)
110111
registerBltinObject("None", pyNone)
111112
registerBltinObject("type", pyTypeObjectType)
112113
registerBltinObject("range", pyRangeObjectType)

0 commit comments

Comments
 (0)