diff options
| author | mryouse | 2022-06-30 03:40:39 +0000 |
|---|---|---|
| committer | mryouse | 2022-06-30 03:40:39 +0000 |
| commit | bf8900200c25d383c883501446a8048ad8966d94 (patch) | |
| tree | c9c5fbd4563b2edc066339f0933d9b225bb5bdd6 /neb/parser.py | |
| parent | 5274edb5484f75266304d21840f8e854f2a1d3c5 (diff) | |
initial commit of multi-type support (only list of strings for now)
Diffstat (limited to 'neb/parser.py')
| -rw-r--r-- | neb/parser.py | 13 |
1 files changed, 12 insertions, 1 deletions
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: + # [ <type> ] + 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 |
