Skip to content

Commit

Permalink
The any type is now recognized as a type properly
Browse files Browse the repository at this point in the history
  • Loading branch information
Ratstail91 committed Jun 19, 2023
1 parent 2157b2f commit f6ec6a8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
10 changes: 9 additions & 1 deletion source/toy_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions test/scripts/types.toy
Original file line number Diff line number Diff line change
Expand Up @@ -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";

0 comments on commit f6ec6a8

Please sign in to comment.