aboutsummaryrefslogtreecommitdiff
path: root/src/parser.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2021-10-19 11:31:11 +0100
committergingerBill <bill@gingerbill.org>2021-10-19 11:31:11 +0100
commit1556fad65a52af7683d5c80f2f724ef252525163 (patch)
tree565b7327f9ae66e692641c2ef5659d11f9e091fc /src/parser.cpp
parent243e2e2b8a7566087375178a66b25b5d9ac9a356 (diff)
Change syntax for matrices to `matrix[R, C]T`
Diffstat (limited to 'src/parser.cpp')
-rw-r--r--src/parser.cpp37
1 files changed, 19 insertions, 18 deletions
diff --git a/src/parser.cpp b/src/parser.cpp
index 499bd337b..c29cf70d9 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -2241,18 +2241,6 @@ Ast *parse_operand(AstFile *f, bool lhs) {
count_expr = parse_expr(f, false);
f->expr_level--;
}
- if (allow_token(f, Token_Semicolon)) {
- Ast *row_count = count_expr;
- Ast *column_count = nullptr;
-
- f->expr_level++;
- column_count = parse_expr(f, false);
- f->expr_level--;
-
- expect_token(f, Token_CloseBracket);
-
- return ast_matrix_type(f, token, row_count, column_count, parse_type(f));
- }
expect_token(f, Token_CloseBracket);
return ast_array_type(f, token, count_expr, parse_type(f));
@@ -2271,6 +2259,23 @@ Ast *parse_operand(AstFile *f, bool lhs) {
return ast_map_type(f, token, key, value);
} break;
+
+ case Token_matrix: {
+ Token token = expect_token(f, Token_matrix);
+ Ast *row_count = nullptr;
+ Ast *column_count = nullptr;
+ Ast *type = nullptr;
+ Token open, close;
+
+ open = expect_token_after(f, Token_OpenBracket, "matrix");
+ row_count = parse_expr(f, true);
+ expect_token(f, Token_Comma);
+ column_count = parse_expr(f, true);
+ close = expect_token(f, Token_CloseBracket);
+ type = parse_type(f);
+
+ return ast_matrix_type(f, token, row_count, column_count, type);
+ } break;
case Token_struct: {
Token token = expect_token(f, Token_struct);
@@ -2716,11 +2721,7 @@ Ast *parse_atom_expr(AstFile *f, Ast *operand, bool lhs) {
case Token_RangeHalf:
syntax_error(f->curr_token, "Expected a colon, not a range");
/* fallthrough */
- case Token_Semicolon: // matrix index
- if (f->curr_token.kind == Token_Semicolon && f->curr_token.string == "\n") {
- syntax_error(f->curr_token, "Expected a ';', not a newline");
- }
- /* fallthrough */
+ case Token_Comma: // matrix index
case Token_Colon:
interval = advance_token(f);
is_interval = true;
@@ -2736,7 +2737,7 @@ Ast *parse_atom_expr(AstFile *f, Ast *operand, bool lhs) {
close = expect_token(f, Token_CloseBracket);
if (is_interval) {
- if (interval.kind == Token_Semicolon) {
+ if (interval.kind == Token_Comma) {
if (indices[0] == nullptr || indices[1] == nullptr) {
syntax_error(open, "Matrix index expressions require both row and column indices");
}