From bf8900200c25d383c883501446a8048ad8966d94 Mon Sep 17 00:00:00 2001 From: mryouse Date: Thu, 30 Jun 2022 03:40:39 +0000 Subject: initial commit of multi-type support (only list of strings for now) --- neb/parser.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'neb/parser.py') diff --git a/neb/parser.py b/neb/parser.py index bbaf7a8..10c6633 100644 --- a/neb/parser.py +++ b/neb/parser.py @@ -45,8 +45,19 @@ def parseLiteral(token, prev, tokens): def parseType(token, prev, tokens): # if the next token is a symbol, combine for a type - if len(tokens) > 0 and tokens[0].type_ == TokenType.SYMBOL: + if tokens[0].type_ == TokenType.SYMBOL: return Type(f":{tokens[0].text}"), 2 + elif tokens[0].type_ == TokenType.OPEN_BRACKET: + # only format currently supported: + # [ ] + if tokens[1].type_ != TokenType.COLON: + raise ParseError("invalid type definition (expecting colon)", tokens[1].line) + typ, counter = parseType(tokens[1], tokens[0], tokens[2:]) + if tokens[1+counter].type_ != TokenType.CLOSE_BRACKET: + raise ParseError("invalid type definition (expecting close bracket)", tokens[1+counter].line) + return MultiType(f":[{typ.name}]", typ), counter + 3 + else: + raise ParseError("invalid type definition!", tokens[0].line) def parse(tokens): idx = 0 -- cgit v1.2.3