From f6ec6a8c731e45a8045d508d282d39bd166b291d Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Mon, 19 Jun 2023 23:16:46 +1000 Subject: [PATCH] The any type is now recognized as a type properly --- source/toy_parser.c | 10 +++++++++- test/scripts/types.toy | 5 +++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/source/toy_parser.c b/source/toy_parser.c index c25b29f..a06052f 100644 --- a/source/toy_parser.c +++ b/source/toy_parser.c @@ -628,6 +628,14 @@ static Toy_Opcode castingPrefix(Toy_Parser* parser, Toy_ASTNode** nodeHandle) { } break; + //BUGFIX: handle this here, and not in castingPrefix, so "any" can be recognized as a type properly + case TOY_TOKEN_ANY: { + Toy_Literal literal = TOY_TO_TYPE_LITERAL(TOY_LITERAL_ANY, false); + Toy_emitASTNodeLiteral(nodeHandle, literal); + Toy_freeLiteral(literal); + } + break; + default: error(parser, parser->previous, "Unexpected token passed to casting precedence rule"); return TOY_OP_EOF; @@ -940,7 +948,7 @@ ParseRule parseRules[] = { //must match the token types {NULL, NULL, PREC_NONE},// TOKEN_DICTIONARY, {NULL, NULL, PREC_NONE},// TOKEN_FUNCTION, {NULL, NULL, PREC_NONE},// TOKEN_OPAQUE, - {NULL, NULL, PREC_NONE},// TOKEN_ANY, + {castingPrefix, NULL, PREC_CALL},// TOKEN_ANY, //keywords and reserved words {NULL, NULL, PREC_NONE},// TOKEN_AS, diff --git a/test/scripts/types.toy b/test/scripts/types.toy index 3f7b281..b742102 100644 --- a/test/scripts/types.toy +++ b/test/scripts/types.toy @@ -22,4 +22,9 @@ var dict: complex = [ "third array": [7, 8, 9] ]; + +//check the any type is recognized as a type within an array +var a: [type] = [int, bool, any]; + + print "All good";