aboutsummaryrefslogtreecommitdiff
path: root/neb/structs.py
diff options
context:
space:
mode:
authormryouse2022-07-27 00:43:17 +0000
committermryouse2022-07-27 00:43:17 +0000
commitaa52ae991cd7bfaebd358f7d1a9482613b82396c (patch)
treeddfe4fe51bc5280a59df970f2b13d75cf5215128 /neb/structs.py
parentf2125f46a689abd037b081a17c112ec3170ee0e4 (diff)
implement {} syntax for non-empty lists
Diffstat (limited to 'neb/structs.py')
-rw-r--r--neb/structs.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/neb/structs.py b/neb/structs.py
index 51cdb34..8c643b5 100644
--- a/neb/structs.py
+++ b/neb/structs.py
@@ -13,6 +13,8 @@ class TokenType(Enum):
CLOSE_PAREN = auto()
OPEN_BRACKET = auto()
CLOSE_BRACKET = auto()
+ OPEN_BRACE = auto()
+ CLOSE_BRACE = auto()
EOF = auto()
@@ -111,10 +113,15 @@ class Type:
return f":[:any]"
else:
return f":[{self.inner}]"
+ elif self.name == ":{}":
+ if self.inner is None:
+ return ":{:any}"
+ else:
+ return ":{" + f"{self.inner}" + "}"
else:
return self.name
-_native_types = ":any :literal :string :bool :number :int :float :[] :handle :type"
+_native_types = ":any :literal :string :bool :number :int :float :[] :{} :handle :type"
ALL_TYPES = {x: Type(x) for x in _native_types.split(" ")}
class Symbol:
@@ -151,7 +158,7 @@ class NebFuncDef:
class Expr:
def __init__(self, args):
self.args = args
- self.type_ = ALL_TYPES[":[]"] # TODO no it's not
+ self.type_ = ALL_TYPES[":{}"] # TODO no it's not
def __str__(self):
return "(" + " ".join(f"{arg}" for arg in self.args) + ")"