Skip to content

Commit 04d9590

Browse files
committed
Added method to enable TigerPython-specific modifications
1 parent 62ece19 commit 04d9590

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

tpParser/js/src/main/scala/tigerpython/parser/TPyParser.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,15 @@ object TPyParser {
130130
}
131131
}
132132

133+
/**
134+
* TigerPython comes with some small modifications to the Python defaults, which are enabled by this method. Note
135+
* that this cannot be undone; the modifications to the types and built-in dictionary are persistent.
136+
*/
137+
@JSExport
138+
def enableTigerPythonModifications(): Unit = {
139+
tigerpython.utilities.types.BuiltinTypes.appyTigerPythonModifications()
140+
}
141+
133142
/**
134143
* Checks the syntax of the given source code and returns a list with all errors detected in the code.
135144
*

tpParser/shared/src/main/scala/tigerpython/utilities/types/BuiltinTypes.scala

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ object BuiltinTypes {
106106
val TUPLE_TYPE = PrimitiveType("tuple", SEQ_TYPE)
107107
val BYTEARRAY_TYPE = PrimitiveType("bytearray", SEQ_TYPE)
108108
val BUFFER_TYPE = PrimitiveType("buffer", SEQ_TYPE)
109-
val XRANGE_TYPE = PrimitiveType("xrange", SEQ_TYPE)
109+
// val XRANGE_TYPE = PrimitiveType("xrange", SEQ_TYPE)
110110
val UNICODE_TYPE: PrimitiveType = new PrimitiveType("unicode", SEQ_TYPE, Map()) {
111111
override def getItemType: DataType = this
112112
}
@@ -293,4 +293,13 @@ object BuiltinTypes {
293293
val SET = new Instance(SET_TYPE)
294294
val STRING = new Instance(STRING_TYPE)
295295
val TUPLE = new Instance(TUPLE_TYPE)
296+
297+
def appyTigerPythonModifications(): Unit = {
298+
LIST_TYPE.addFields(
299+
PrimitiveType("first"),
300+
PrimitiveType("head"),
301+
PrimitiveType("last"),
302+
PrimitiveType("tail", LIST_TYPE)
303+
)
304+
}
296305
}

0 commit comments

Comments
 (0)