From ce89936e799b7ea5d657d5fa9371cf13e00614ba Mon Sep 17 00:00:00 2001 From: Ian Boll Date: Wed, 31 Jan 2024 20:23:57 -0500 Subject: [PATCH] number fixes - number is now a supertype of float and decimal - decimals can now include a leading negative sign --- grammar.js | 3 +- src/grammar.json | 5 +- src/node-types.json | 33 +- src/parser.c | 37 +- test/corpus/items.txt | 191 +++++----- test/corpus/literals.txt | 706 +++++++++++++++++-------------------- test/corpus/operators.txt | 515 +++++++++++++-------------- test/corpus/statements.txt | 376 +++++++++----------- 8 files changed, 860 insertions(+), 1006 deletions(-) diff --git a/grammar.js b/grammar.js index d84c0b8..d88473d 100644 --- a/grammar.js +++ b/grammar.js @@ -140,6 +140,7 @@ module.exports = grammar({ supertypes: $ => [ $.literal, $.expression, + $.number, ], word: $ => $.identifier, @@ -378,7 +379,7 @@ module.exports = grammar({ string: _ => token(seq('"', repeat(choice(/[^"]/, '\\"')), '"')), number: $ => choice($.decimal, $.float), - decimal: _ => token(/\d+/), + decimal: _ => token(/-?\d+/), float: _ => token(/-?(\d+(\.\d+)?|\.\d+)(e-?\d+)?/), boolean: _ => choice('true', 'false'), undef: _ => 'undef', diff --git a/src/grammar.json b/src/grammar.json index 8db2d41..bab011c 100644 --- a/src/grammar.json +++ b/src/grammar.json @@ -2038,7 +2038,7 @@ "type": "TOKEN", "content": { "type": "PATTERN", - "value": "\\d+" + "value": "-?\\d+" } }, "float": { @@ -2120,7 +2120,8 @@ "inline": [], "supertypes": [ "literal", - "expression" + "expression", + "number" ] } diff --git a/src/node-types.json b/src/node-types.json index 3fb064e..c01c9f7 100644 --- a/src/node-types.json +++ b/src/node-types.json @@ -87,6 +87,20 @@ } ] }, + { + "type": "number", + "named": true, + "subtypes": [ + { + "type": "decimal", + "named": true + }, + { + "type": "float", + "named": true + } + ] + }, { "type": "arguments", "named": true, @@ -1234,25 +1248,6 @@ } } }, - { - "type": "number", - "named": true, - "fields": {}, - "children": { - "multiple": false, - "required": true, - "types": [ - { - "type": "decimal", - "named": true - }, - { - "type": "float", - "named": true - } - ] - } - }, { "type": "parameter", "named": true, diff --git a/src/parser.c b/src/parser.c index ca764f8..6dedbed 100644 --- a/src/parser.c +++ b/src/parser.c @@ -747,8 +747,9 @@ static const TSSymbolMetadata ts_symbol_metadata[] = { .named = true, }, [sym_number] = { - .visible = true, + .visible = false, .named = true, + .supertype = true, }, [sym_boolean] = { .visible = true, @@ -1360,11 +1361,11 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { END_STATE(); case 5: if (lookahead == '*') ADVANCE(7); - if (lookahead == '/') ADVANCE(56); + if (lookahead == '/') ADVANCE(55); END_STATE(); case 6: if (lookahead == '*') ADVANCE(6); - if (lookahead == '/') ADVANCE(55); + if (lookahead == '/') ADVANCE(54); if (lookahead != 0) ADVANCE(7); END_STATE(); case 7: @@ -1373,7 +1374,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { END_STATE(); case 8: if (lookahead == '-') ADVANCE(13); - if (('0' <= lookahead && lookahead <= '9')) ADVANCE(54); + if (('0' <= lookahead && lookahead <= '9')) ADVANCE(53); END_STATE(); case 9: if (lookahead == '/') ADVANCE(5); @@ -1391,15 +1392,15 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { if (lookahead == '|') ADVANCE(36); END_STATE(); case 12: - if (('0' <= lookahead && lookahead <= '9')) ADVANCE(53); + if (('0' <= lookahead && lookahead <= '9')) ADVANCE(52); END_STATE(); case 13: - if (('0' <= lookahead && lookahead <= '9')) ADVANCE(54); + if (('0' <= lookahead && lookahead <= '9')) ADVANCE(53); END_STATE(); case 14: if (lookahead != 0 && - lookahead != '\r') ADVANCE(56); - if (lookahead == '\r') ADVANCE(57); + lookahead != '\r') ADVANCE(55); + if (lookahead == '\r') ADVANCE(56); END_STATE(); case 15: ACCEPT_TOKEN(ts_builtin_sym_end); @@ -1456,7 +1457,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { END_STATE(); case 32: ACCEPT_TOKEN(anon_sym_DOT); - if (('0' <= lookahead && lookahead <= '9')) ADVANCE(53); + if (('0' <= lookahead && lookahead <= '9')) ADVANCE(52); END_STATE(); case 33: ACCEPT_TOKEN(anon_sym_DASH); @@ -1464,7 +1465,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { case 34: ACCEPT_TOKEN(anon_sym_DASH); if (lookahead == '.') ADVANCE(12); - if (('0' <= lookahead && lookahead <= '9')) ADVANCE(52); + if (('0' <= lookahead && lookahead <= '9')) ADVANCE(51); END_STATE(); case 35: ACCEPT_TOKEN(anon_sym_PLUS); @@ -1498,7 +1499,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { case 44: ACCEPT_TOKEN(anon_sym_SLASH); if (lookahead == '*') ADVANCE(7); - if (lookahead == '/') ADVANCE(56); + if (lookahead == '/') ADVANCE(55); END_STATE(); case 45: ACCEPT_TOKEN(anon_sym_CARET); @@ -1533,32 +1534,26 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { END_STATE(); case 52: ACCEPT_TOKEN(sym_float); - if (lookahead == '.') ADVANCE(12); if (lookahead == 'e') ADVANCE(8); if (('0' <= lookahead && lookahead <= '9')) ADVANCE(52); END_STATE(); case 53: ACCEPT_TOKEN(sym_float); - if (lookahead == 'e') ADVANCE(8); if (('0' <= lookahead && lookahead <= '9')) ADVANCE(53); END_STATE(); case 54: - ACCEPT_TOKEN(sym_float); - if (('0' <= lookahead && lookahead <= '9')) ADVANCE(54); - END_STATE(); - case 55: ACCEPT_TOKEN(sym_comment); END_STATE(); - case 56: + case 55: ACCEPT_TOKEN(sym_comment); if (lookahead == '\\') ADVANCE(14); if (lookahead != 0 && - lookahead != '\n') ADVANCE(56); + lookahead != '\n') ADVANCE(55); END_STATE(); - case 57: + case 56: ACCEPT_TOKEN(sym_comment); if (lookahead != 0 && - lookahead != '\\') ADVANCE(56); + lookahead != '\\') ADVANCE(55); if (lookahead == '\\') ADVANCE(14); END_STATE(); default: diff --git a/test/corpus/items.txt b/test/corpus/items.txt index 85b1820..7d76ef8 100644 --- a/test/corpus/items.txt +++ b/test/corpus/items.txt @@ -28,86 +28,81 @@ module comma1(x,) {} -------------------------------------------------------------------------------- (source_file - (use_statement - (include_path)) - (include_statement - (include_path)) - (use_statement - (include_path)) - (include_statement - (include_path)) - (use_statement - (include_path)) - (comment) - (assignment - (identifier) - (number - (decimal))) - (comment) + (use_statement + (include_path)) + (include_statement + (include_path)) + (use_statement + (include_path)) + (include_statement + (include_path)) + (use_statement + (include_path)) + (comment) + (assignment + (identifier) + (decimal)) + (comment) + (assignment + (identifier) + (boolean)) + (function_declaration + (identifier) + (parameters_declaration + (parameter + (identifier))) + (binary_expression + (identifier) + (identifier))) + (module_declaration + (identifier) + (parameters_declaration + (parameter + (identifier)) (assignment (identifier) - (boolean)) - (function_declaration - (identifier) - (parameters_declaration - (parameter - (identifier))) - (binary_expression + (function_call (identifier) - (identifier))) - (module_declaration + (arguments + (decimal)))) + (assignment + (special_variable + (identifier)) + (decimal))) + (transform_chain + (module_call (identifier) - (parameters_declaration - (parameter - (identifier)) + (arguments (assignment (identifier) - (function_call - (identifier) - (arguments - (number - (decimal))))) + (identifier)) (assignment - (special_variable - (identifier)) - (number - (decimal)))) - (transform_chain - (module_call (identifier) - (arguments - (assignment - (identifier) - (identifier)) - (assignment - (identifier) - (identifier)))))) - (module_declaration - (identifier) - (parameters_declaration) - (union_block)) - (function_declaration - (identifier) - (parameters_declaration) - (number - (decimal))) - (function_declaration - (identifier) - (parameters_declaration - (parameter - (identifier))) - (number - (decimal))) - (module_declaration - (identifier) - (parameters_declaration) - (union_block)) - (module_declaration - (identifier) - (parameters_declaration - (parameter - (identifier))) - (union_block))) + (identifier)))))) + (module_declaration + (identifier) + (parameters_declaration) + (union_block)) + (function_declaration + (identifier) + (parameters_declaration) + (decimal)) + (function_declaration + (identifier) + (parameters_declaration + (parameter + (identifier))) + (decimal)) + (module_declaration + (identifier) + (parameters_declaration) + (union_block)) + (module_declaration + (identifier) + (parameters_declaration + (parameter + (identifier))) + (union_block))) ================================================================================ Nested Items @@ -160,33 +155,31 @@ module my_cylinder() { -------------------------------------------------------------------------------- (source_file + (comment) + (assignment + (identifier) + (decimal)) + (function_declaration + (identifier) + (parameters_declaration + (parameter + (identifier))) + (comment) + (binary_expression + (identifier) + (decimal))) + (comment) + (module_declaration + (identifier) + (parameters_declaration) + (union_block (comment) - (assignment - (identifier) - (number - (decimal))) - (function_declaration - (identifier) - (parameters_declaration - (parameter - (identifier))) - (comment) - (binary_expression + (transform_chain + (module_call (identifier) - (number - (decimal)))) + (arguments))) (comment) - (module_declaration - (identifier) - (parameters_declaration) - (union_block - (comment) - (transform_chain - (module_call - (identifier) - (arguments))) - (comment) - (transform_chain - (module_call - (identifier) - (arguments)))))) + (transform_chain + (module_call + (identifier) + (arguments)))))) diff --git a/test/corpus/literals.txt b/test/corpus/literals.txt index 3418729..fd19f62 100644 --- a/test/corpus/literals.txt +++ b/test/corpus/literals.txt @@ -12,83 +12,68 @@ comprehension = [for (x = 0; x < 5; x = x + 2) 12]; -------------------------------------------------------------------------------- (source_file - (assignment - (identifier) - (number - (float))) - (assignment - (identifier) - (string)) - (assignment - (identifier) - (boolean)) - (assignment - (identifier) + (assignment + (identifier) + (float)) + (assignment + (identifier) + (string)) + (assignment + (identifier) + (boolean)) + (assignment + (identifier) + (list + (decimal) + (decimal) + (each (list - (number - (decimal)) - (number - (decimal)) - (each - (list - (number - (decimal)) - (number - (decimal)))) - (list - (number - (decimal)) - (number - (decimal))))) - (assignment + (decimal) + (decimal))) + (list + (decimal) + (decimal)))) + (assignment + (identifier) + (list + (list + (decimal) + (decimal)))) + (assignment + (identifier) + (range + (decimal) + (identifier) + (decimal))) + (assignment + (identifier) + (function + (parameters_declaration + (parameter + (identifier)) + (parameter + (identifier))) + (binary_expression (identifier) - (list - (list - (number + (identifier)))) + (assignment + (identifier) + (list + (list_comprehension + (for_clause + (condition_update_clause + (assignment + (identifier) (decimal)) - (number - (decimal))))) - (assignment - (identifier) - (range - (number - (decimal)) - (identifier) - (number - (float)))) - (assignment - (identifier) - (function - (parameters_declaration - (parameter - (identifier)) - (parameter - (identifier))) - (binary_expression - (identifier) - (identifier)))) - (assignment - (identifier) - (list - (list_comprehension - (for_clause - (condition_update_clause - (assignment - (identifier) - (number - (decimal))) - (binary_expression - (identifier) - (number - (decimal))) - (assignment - (identifier) - (binary_expression - (identifier) - (number - (decimal))))) - (number - (decimal))))))) + (binary_expression + (identifier) + (decimal)) + (assignment + (identifier) + (binary_expression + (identifier) + (decimal)))) + (decimal)))))) ================================================================================ Comprehensions @@ -106,242 +91,206 @@ grouped = [if (x < 7) (for (y = [1:10]) if (y > x) y) else x]; -------------------------------------------------------------------------------- (source_file - (assignment - (identifier) - (list - (list_comprehension - (for_clause - (parenthesized_assignments - (assignment - (identifier) - (range - (number - (decimal)) - (number - (decimal))))) - (identifier))))) - (assignment - (identifier) - (list + (assignment + (identifier) + (list + (list_comprehension + (for_clause + (parenthesized_assignments + (assignment + (identifier) + (range + (decimal) + (decimal)))) + (identifier))))) + (assignment + (identifier) + (list + (list_comprehension + (for_clause + (parenthesized_assignments + (assignment + (identifier) + (range + (decimal) + (decimal)))) (list_comprehension - (for_clause - (parenthesized_assignments - (assignment - (identifier) - (range - (number - (decimal)) - (number - (decimal))))) - (list_comprehension - (if_clause - (parenthesized_expression - (special_variable - (identifier))) - (identifier))))))) - (assignment - (identifier) - (list + (if_clause + (parenthesized_expression + (special_variable + (identifier))) + (identifier))))))) + (assignment + (identifier) + (list + (list_comprehension + (for_clause + (parenthesized_assignments + (assignment + (identifier) + (range + (decimal) + (decimal)))) (list_comprehension - (for_clause - (parenthesized_assignments - (assignment - (identifier) - (range - (number - (decimal)) - (number - (decimal))))) - (list_comprehension - (if_clause - (parenthesized_expression - (special_variable - (identifier))) - (identifier) - (function_call - (identifier) - (arguments - (identifier))))))))) - (assignment - (identifier) - (list + (if_clause + (parenthesized_expression + (special_variable + (identifier))) + (identifier) + (function_call + (identifier) + (arguments + (identifier))))))))) + (assignment + (identifier) + (list + (list_comprehension + (for_clause + (parenthesized_assignments + (assignment + (identifier) + (decimal))) (list_comprehension - (for_clause - (parenthesized_assignments - (assignment + (if_clause + (parenthesized_expression + (binary_expression (identifier) - (number - (decimal)))) + (decimal))) (list_comprehension - (if_clause - (parenthesized_expression - (binary_expression + (for_clause + (parenthesized_assignments + (assignment (identifier) - (number - (decimal)))) - (list_comprehension - (for_clause - (parenthesized_assignments - (assignment - (identifier) - (number - (decimal)))) - (list_comprehension - (if_clause - (parenthesized_expression - (binary_expression - (identifier) - (number - (decimal)))) - (identifier) - (identifier))))))))))) - (assignment - (identifier) - (list - (list_comprehension - (for_clause - (parenthesized_assignments - (assignment - (identifier) - (range - (number - (decimal)) - (number - (decimal))))) - (list_comprehension - (if_clause - (parenthesized_expression - (binary_expression - (binary_expression - (identifier) - (number - (decimal))) - (number - (decimal)))) - (identifier) + (decimal))) (list_comprehension (if_clause (parenthesized_expression (binary_expression (identifier) - (number - (decimal)))) - (binary_expression - (identifier) - (number (decimal))) - (number - (decimal)))))))))) - (assignment - (identifier) - (list - (list_comprehension - (for_clause - (parenthesized_assignments - (assignment - (identifier) - (range - (number - (decimal)) - (number - (decimal))))) - (identifier))) + (identifier) + (identifier))))))))))) + (assignment + (identifier) + (list + (list_comprehension + (for_clause + (parenthesized_assignments + (assignment + (identifier) + (range + (decimal) + (decimal)))) (list_comprehension - (for_clause - (parenthesized_assignments - (assignment - (identifier) - (list - (number - (decimal)) - (number - (decimal)) - (number - (decimal))))) - (identifier))) + (if_clause + (parenthesized_expression + (binary_expression + (binary_expression + (identifier) + (decimal)) + (decimal))) + (identifier) + (list_comprehension + (if_clause + (parenthesized_expression + (binary_expression + (identifier) + (decimal))) + (binary_expression + (identifier) + (decimal)) + (decimal))))))))) + (assignment + (identifier) + (list + (list_comprehension + (for_clause + (parenthesized_assignments + (assignment + (identifier) + (range + (decimal) + (decimal)))) + (identifier))) + (list_comprehension + (for_clause + (parenthesized_assignments + (assignment + (identifier) + (list + (decimal) + (decimal) + (decimal)))) + (identifier))) + (list_comprehension + (for_clause + (parenthesized_assignments + (assignment + (identifier) + (list + (decimal) + (decimal) + (decimal)))) + (identifier))))) + (assignment + (identifier) + (list + (list_comprehension + (for_clause + (parenthesized_assignments + (assignment + (identifier) + (range + (decimal) + (decimal)))) (list_comprehension (for_clause (parenthesized_assignments (assignment (identifier) (list - (number - (decimal)) - (number - (decimal)) - (number - (decimal))))) - (identifier))))) - (assignment - (identifier) - (list - (list_comprehension - (for_clause - (parenthesized_assignments - (assignment - (identifier) - (range - (number - (decimal)) - (number - (decimal))))) + (decimal) + (decimal) + (decimal)))) (list_comprehension (for_clause (parenthesized_assignments (assignment (identifier) (list - (number - (decimal)) - (number - (decimal)) - (number - (decimal))))) - (list_comprehension - (for_clause - (parenthesized_assignments - (assignment - (identifier) - (list - (number - (decimal)) - (number - (decimal)) - (number - (decimal))))) - (binary_expression - (binary_expression - (identifier) - (identifier)) - (identifier)))))))))) - (assignment - (identifier) - (list + (decimal) + (decimal) + (decimal)))) + (binary_expression + (binary_expression + (identifier) + (identifier)) + (identifier)))))))))) + (assignment + (identifier) + (list + (list_comprehension + (if_clause + (parenthesized_expression + (binary_expression + (identifier) + (decimal))) (list_comprehension - (if_clause - (parenthesized_expression - (binary_expression + (for_clause + (parenthesized_assignments + (assignment (identifier) - (number + (range + (decimal) (decimal)))) (list_comprehension - (for_clause - (parenthesized_assignments - (assignment + (if_clause + (parenthesized_expression + (binary_expression (identifier) - (range - (number - (decimal)) - (number - (decimal))))) - (list_comprehension - (if_clause - (parenthesized_expression - (binary_expression - (identifier) - (identifier))) - (identifier))))) - (identifier)))))) + (identifier))) + (identifier))))) + (identifier)))))) ================================================================================ Numbers @@ -350,25 +299,25 @@ i = 5; f = -0.0; ie = 10e10; full = -2.3e-4; +negative_int = -6; -------------------------------------------------------------------------------- (source_file - (assignment - (identifier) - (number - (decimal))) - (assignment - (identifier) - (number - (float))) - (assignment - (identifier) - (number - (float))) - (assignment - (identifier) - (number - (float)))) + (assignment + (identifier) + (decimal)) + (assignment + (identifier) + (float)) + (assignment + (identifier) + (float)) + (assignment + (identifier) + (float)) + (assignment + (identifier) + (decimal))) ================================================================================ Each Expansion @@ -381,96 +330,79 @@ each_if = [each if (len(a) < 5) 10 else 15, each if (len(str_list) < 5) true]; -------------------------------------------------------------------------------- (source_file - (assignment - (identifier) - (list - (number - (decimal)) - (number - (decimal)) - (number + (assignment + (identifier) + (list + (decimal) + (decimal) + (decimal))) + (assignment + (identifier) + (list + (decimal) + (decimal) + (each + (identifier)) + (each + (parenthesized_expression + (list + (decimal) (decimal)))) - (assignment - (identifier) - (list - (number - (decimal)) - (number - (decimal)) - (each - (identifier)) - (each + (each + (decimal)) + (each + (list_comprehension + (for_clause + (parenthesized_assignments + (assignment + (identifier) + (range + (decimal) + (decimal)))) + (identifier)))))) + (assignment + (identifier) + (list + (each + (boolean)) + (each + (range + (decimal) + (decimal))) + (each + (undef)) + (each + (string)))) + (assignment + (identifier) + (list + (each + (function + (parameters_declaration) + (decimal))))) + (assignment + (identifier) + (list + (each + (list_comprehension + (if_clause (parenthesized_expression - (list - (number - (decimal)) - (number - (decimal))))) - (each - (number - (decimal))) - (each - (list_comprehension - (for_clause - (parenthesized_assignments - (assignment - (identifier) - (range - (number - (decimal)) - (number - (decimal))))) - (identifier)))))) - (assignment - (identifier) - (list - (each - (boolean)) - (each - (range - (number - (decimal)) - (number - (decimal)))) - (each - (undef)) - (each - (string)))) - (assignment - (identifier) - (list - (each - (function - (parameters_declaration) - (number - (decimal)))))) - (assignment - (identifier) - (list - (each - (list_comprehension - (if_clause - (parenthesized_expression - (binary_expression - (function_call - (identifier) - (arguments - (identifier))) - (number - (decimal)))) - (number - (decimal)) - (number - (decimal))))) - (each - (list_comprehension - (if_clause - (parenthesized_expression - (binary_expression - (function_call - (identifier) - (arguments - (identifier))) - (number - (decimal)))) - (boolean))))))) + (binary_expression + (function_call + (identifier) + (arguments + (identifier))) + (decimal))) + (decimal) + (decimal)))) + (each + (list_comprehension + (if_clause + (parenthesized_expression + (binary_expression + (function_call + (identifier) + (arguments + (identifier))) + (decimal))) + (boolean))))))) diff --git a/test/corpus/operators.txt b/test/corpus/operators.txt index c42c194..fa40bd0 100644 --- a/test/corpus/operators.txt +++ b/test/corpus/operators.txt @@ -7,70 +7,58 @@ result = call(); math = 8 % 3 * 5 % 7 / 2 % 1; number_index = [1, 2, 3, 4][3]; named_index = [1, 2, 3, 4].x; +spaced_negation = - 7; -------------------------------------------------------------------------------- (source_file - (assignment - (identifier) - (binary_expression - (number - (decimal)) - (number - (decimal)))) - (assignment - (identifier) - (string)) - (assignment - (identifier) - (function_call - (identifier) - (arguments))) - (assignment - (identifier) + (assignment + (identifier) + (binary_expression + (decimal) + (decimal))) + (assignment + (identifier) + (string)) + (assignment + (identifier) + (function_call + (identifier) + (arguments))) + (assignment + (identifier) + (binary_expression + (binary_expression (binary_expression (binary_expression (binary_expression - (binary_expression - (binary_expression - (number - (decimal)) - (number - (decimal))) - (number - (decimal))) - (number - (decimal))) - (number - (decimal))) - (number - (decimal)))) - (assignment - (identifier) - (index_expression - (list - (number - (decimal)) - (number - (decimal)) - (number - (decimal)) - (number - (decimal))) - (number - (decimal)))) - (assignment - (identifier) - (dot_index_expression - (list - (number - (decimal)) - (number - (decimal)) - (number + (decimal) (decimal)) - (number - (decimal))) - (identifier)))) + (decimal)) + (decimal)) + (decimal)) + (decimal))) + (assignment + (identifier) + (index_expression + (list + (decimal) + (decimal) + (decimal) + (decimal)) + (decimal))) + (assignment + (identifier) + (dot_index_expression + (list + (decimal) + (decimal) + (decimal) + (decimal)) + (identifier))) + (assignment + (identifier) + (unary_expression + (decimal)))) ================================================================================ Logical Precedence @@ -92,123 +80,111 @@ echo(true && 4 == 4); -------------------------------------------------------------------------------- (source_file - (function_declaration - (identifier) - (parameters_declaration - (parameter - (identifier))) + (function_declaration + (identifier) + (parameters_declaration + (parameter + (identifier))) + (function_call + (identifier) + (arguments (function_call (identifier) (arguments + (string) + (identifier)))))) + (function_declaration + (identifier) + (parameters_declaration + (parameter + (identifier))) + (binary_expression + (function_call + (identifier) + (arguments + (identifier))) + (undef))) + (assignment + (identifier) + (boolean)) + (assignment + (identifier) + (decimal)) + (assignment + (identifier) + (decimal)) + (transform_chain + (module_call + (identifier) + (arguments + (binary_expression + (binary_expression + (identifier) + (identifier)) + (identifier))))) + (transform_chain + (module_call + (identifier) + (arguments + (binary_expression + (identifier) + (binary_expression + (identifier) + (identifier)))))) + (transform_chain + (module_call + (identifier) + (arguments + (binary_expression + (binary_expression (function_call (identifier) (arguments - (string) - (identifier)))))) - (function_declaration - (identifier) - (parameters_declaration - (parameter - (identifier))) + (decimal))) + (function_call + (identifier) + (arguments + (decimal)))) + (function_call + (identifier) + (arguments + (decimal))))))) + (transform_chain + (module_call + (identifier) + (arguments (binary_expression (function_call (identifier) (arguments - (identifier))) - (undef))) - (assignment - (identifier) - (boolean)) - (assignment - (identifier) - (number - (decimal))) - (assignment - (identifier) - (number - (decimal))) - (transform_chain - (module_call - (identifier) - (arguments - (binary_expression - (binary_expression - (identifier) - (identifier)) - (identifier))))) - (transform_chain - (module_call - (identifier) - (arguments - (binary_expression + (decimal))) + (binary_expression + (function_call (identifier) - (binary_expression - (identifier) - (identifier)))))) - (transform_chain - (module_call - (identifier) - (arguments - (binary_expression - (binary_expression - (function_call - (identifier) - (arguments - (number - (decimal)))) - (function_call - (identifier) - (arguments - (number - (decimal))))) - (function_call - (identifier) - (arguments - (number - (decimal)))))))) - (transform_chain - (module_call - (identifier) - (arguments - (binary_expression - (function_call - (identifier) - (arguments - (number - (decimal)))) - (binary_expression - (function_call - (identifier) - (arguments - (number - (decimal)))) - (function_call - (identifier) - (arguments - (number - (decimal))))))))) - (transform_chain - (module_call - (identifier) - (arguments - (binary_expression - (binary_expression - (number - (decimal)) - (number - (decimal))) - (boolean))))) - (transform_chain - (module_call - (identifier) - (arguments - (binary_expression - (boolean) - (binary_expression - (number - (decimal)) - (number - (decimal)))))))) + (arguments + (decimal))) + (function_call + (identifier) + (arguments + (decimal)))))))) + (transform_chain + (module_call + (identifier) + (arguments + (binary_expression + (binary_expression + (decimal) + (decimal)) + (boolean))))) + (transform_chain + (module_call + (identifier) + (arguments + (binary_expression + (boolean) + (binary_expression + (decimal) + (decimal))))))) ================================================================================ Mathematical Precedence @@ -217,19 +193,15 @@ num = 5 + 4 * 3 ^ 2; -------------------------------------------------------------------------------- (source_file - (assignment - (identifier) + (assignment + (identifier) + (binary_expression + (decimal) + (binary_expression + (decimal) (binary_expression - (number - (decimal)) - (binary_expression - (number - (decimal)) - (binary_expression - (number - (decimal)) - (number - (decimal))))))) + (decimal) + (decimal)))))) ================================================================================ Function Precedence @@ -243,67 +215,65 @@ indexer = function(v) v[0]; -------------------------------------------------------------------------------- (source_file - (assignment - (identifier) - (function - (parameters_declaration - (parameter - (identifier))) + (assignment + (identifier) + (function + (parameters_declaration + (parameter (identifier))) - (assignment + (identifier))) + (assignment + (identifier) + (function + (parameters_declaration + (parameter + (identifier))) + (function_call (identifier) + (arguments + (identifier))))) + (assignment + (identifier) + (function_call + (parenthesized_expression (function (parameters_declaration (parameter (identifier))) - (function_call - (identifier) - (arguments - (identifier))))) - (assignment - (identifier) - (function_call - (parenthesized_expression - (function - (parameters_declaration - (parameter - (identifier))) - (identifier))) - (arguments - (number - (decimal))))) - (assignment + (identifier))) + (arguments + (decimal)))) + (assignment + (identifier) + (function + (parameters_declaration + (parameter + (identifier)) + (parameter + (identifier))) + (binary_expression (identifier) - (function - (parameters_declaration - (parameter - (identifier)) - (parameter - (identifier))) - (binary_expression - (identifier) - (identifier)))) - (assignment + (identifier)))) + (assignment + (identifier) + (function + (parameters_declaration + (parameter + (identifier)) + (parameter + (identifier))) + (binary_expression (identifier) - (function - (parameters_declaration - (parameter - (identifier)) - (parameter - (identifier))) - (binary_expression - (identifier) - (identifier)))) - (assignment + (identifier)))) + (assignment + (identifier) + (function + (parameters_declaration + (parameter + (identifier))) + (index_expression (identifier) - (function - (parameters_declaration - (parameter - (identifier))) - (index_expression - (identifier) - (number - (decimal)))))) + (decimal))))) ================================================================================ Functions and Ternaries @@ -314,33 +284,33 @@ echo(function(y) y ? "first" : "second"); -------------------------------------------------------------------------------- (source_file - (assignment - (identifier) + (assignment + (identifier) + (function + (parameters_declaration + (parameter + (identifier))) + (identifier))) + (transform_chain + (module_call + (identifier) + (arguments + (ternary_expression + (identifier) + (string) + (string))))) + (transform_chain + (module_call + (identifier) + (arguments (function (parameters_declaration (parameter (identifier))) - (identifier))) - (transform_chain - (module_call - (identifier) - (arguments - (ternary_expression - (identifier) - (string) - (string))))) - (transform_chain - (module_call - (identifier) - (arguments - (function - (parameters_declaration - (parameter - (identifier))) - (ternary_expression - (identifier) - (string) - (string))))))) + (ternary_expression + (identifier) + (string) + (string))))))) ================================================================================ Assertions @@ -351,30 +321,29 @@ echo(assert(true) assert(false) true); -------------------------------------------------------------------------------- (source_file - (assignment + (assignment + (identifier) + (assert_expression + (boolean) + (boolean) + (string) + (string) + (decimal))) + (assignment + (identifier) + (function + (parameters_declaration + (parameter + (identifier))) + (assert_expression (identifier) + (identifier)))) + (transform_chain + (module_call + (identifier) + (arguments (assert_expression (boolean) - (boolean) - (string) - (string) - (number - (decimal)))) - (assignment - (identifier) - (function - (parameters_declaration - (parameter - (identifier))) (assert_expression - (identifier) - (identifier)))) - (transform_chain - (module_call - (identifier) - (arguments - (assert_expression - (boolean) - (assert_expression - (boolean) - (boolean))))))) + (boolean) + (boolean))))))) diff --git a/test/corpus/statements.txt b/test/corpus/statements.txt index 906b3db..9988174 100644 --- a/test/corpus/statements.txt +++ b/test/corpus/statements.txt @@ -12,61 +12,52 @@ translate([1, 0, 0]) { -------------------------------------------------------------------------------- (source_file + (transform_chain + (module_call + (identifier) + (arguments))) + (transform_chain + (module_call + (identifier) + (arguments + (list + (decimal) + (decimal) + (decimal)))) + (transform_chain + (module_call + (identifier) + (arguments)))) + (transform_chain + (module_call + (identifier) + (arguments + (list + (decimal) + (decimal) + (decimal)))) + (union_block (transform_chain (module_call (identifier) - (arguments))) - (transform_chain - (module_call - (identifier) - (arguments - (list - (number - (decimal)) - (number - (decimal)) - (number - (decimal))))) - (transform_chain - (module_call - (identifier) - (arguments)))) - (transform_chain - (module_call - (identifier) - (arguments - (list - (number - (decimal)) - (number - (decimal)) - (number - (decimal))))) + (arguments)) (union_block (transform_chain (module_call (identifier) - (arguments)) - (union_block - (transform_chain - (module_call - (identifier) - (arguments - (list - (number - (decimal)) - (number - (decimal)) - (number - (decimal))))) - (transform_chain - (module_call - (identifier) - (arguments)))) - (transform_chain - (module_call - (identifier) - (arguments)))))))) + (arguments + (list + (decimal) + (decimal) + (decimal)))) + (transform_chain + (module_call + (identifier) + (arguments)))) + (transform_chain + (module_call + (identifier) + (arguments)))))))) ================================================================================ Control Flow @@ -91,108 +82,93 @@ intersection_for (i = [1, 2, 3]) { -------------------------------------------------------------------------------- (source_file - (if_block - (parenthesized_expression - (special_variable - (identifier))) - (if_block - (parenthesized_expression - (boolean)) - (transform_chain - (module_call + (if_block + (parenthesized_expression + (special_variable + (identifier))) + (if_block + (parenthesized_expression + (boolean)) + (transform_chain + (module_call + (identifier) + (arguments))) + (transform_chain + (module_call + (identifier) + (arguments + (list + (decimal) + (decimal) + (decimal)))) + (transform_chain + (module_call + (identifier) + (arguments)))))) + (for_block + (parenthesized_assignments + (assignment + (identifier) + (range + (decimal) + (decimal) + (decimal)))) + (union_block + (let_block + (parenthesized_assignments + (assignment + (identifier) + (binary_expression (identifier) - (arguments))) + (decimal))) + (assignment + (identifier) + (binary_expression + (identifier) + (decimal)))) + (union_block (transform_chain (module_call (identifier) (arguments (list - (number - (decimal)) - (number - (decimal)) - (number - (decimal))))) + (identifier) + (identifier) + (decimal)))) (transform_chain (module_call (identifier) - (arguments)))))) - (for_block - (parenthesized_assignments - (assignment - (identifier) - (range - (number - (decimal)) - (number - (decimal)) - (number - (decimal))))) - (union_block - (let_block - (parenthesized_assignments - (assignment - (identifier) - (binary_expression - (identifier) - (number - (decimal)))) - (assignment - (identifier) - (binary_expression - (identifier) - (number - (decimal))))) - (union_block - (transform_chain - (module_call - (identifier) - (arguments - (list - (identifier) - (identifier) - (number - (decimal))))) - (transform_chain - (module_call + (arguments + (assignment (identifier) - (arguments - (assignment - (identifier) - (identifier)))))))))) - (intersection_for_block - (parenthesized_assignments - (assignment + (identifier)))))))))) + (intersection_for_block + (parenthesized_assignments + (assignment + (identifier) + (list + (decimal) + (decimal) + (decimal)))) + (union_block + (if_block + (parenthesized_expression + (binary_expression (identifier) - (list - (number - (decimal)) - (number - (decimal)) - (number - (decimal))))) + (decimal))) (union_block - (if_block - (parenthesized_expression - (binary_expression - (identifier) - (number - (decimal)))) - (union_block - (transform_chain - (module_call + (transform_chain + (module_call + (identifier) + (arguments + (list + (decimal) (identifier) - (arguments - (list - (number - (decimal)) - (identifier) - (number - (decimal))))) - (transform_chain - (module_call - (identifier) - (arguments))))))))) + (decimal)))) + (transform_chain + (module_call + (identifier) + (arguments))))))))) ================================================================================ Modifiers @@ -203,50 +179,46 @@ rotate([0, 90, 0]) # cylinder(); % cube(); -------------------------------------------------------------------------------- - (source_file - (modifier_chain - (modifier) - (transform_chain - (module_call - (identifier) - (arguments)))) - (modifier_chain - (modifier) - (transform_chain - (module_call - (identifier) - (arguments - (number - (decimal)))) - (transform_chain - (module_call - (identifier) - (arguments - (string)))))) + (modifier_chain + (modifier) + (transform_chain + (module_call + (identifier) + (arguments)))) + (modifier_chain + (modifier) + (transform_chain + (module_call + (identifier) + (arguments + (decimal))) (transform_chain (module_call (identifier) (arguments - (list - (number - (decimal)) - (number - (decimal)) - (number - (decimal))))) - (modifier_chain - (modifier) - (transform_chain - (module_call - (identifier) - (arguments))))) - (modifier_chain - (modifier) - (transform_chain - (module_call - (identifier) - (arguments))))) + (string)))))) + (transform_chain + (module_call + (identifier) + (arguments + (list + (decimal) + (decimal) + (decimal)))) + (modifier_chain + (modifier) + (transform_chain + (module_call + (identifier) + (arguments))))) + (modifier_chain + (modifier) + (transform_chain + (module_call + (identifier) + (arguments))))) + ================================================================================ Assertions ================================================================================ @@ -258,35 +230,31 @@ for (y = [3:5]) -------------------------------------------------------------------------------- (source_file + (assignment + (identifier) + (decimal)) + (assert_statement + (binary_expression + (identifier) + (decimal)) + (transform_chain + (module_call + (identifier) + (arguments)))) + (for_block + (parenthesized_assignments (assignment (identifier) - (number - (decimal))) - (assert_statement + (range + (decimal) + (decimal)))) + (assert_statement + (assert_expression (binary_expression (identifier) - (number - (decimal))) - (transform_chain - (module_call - (identifier) - (arguments)))) - (for_block - (parenthesized_assignments - (assignment - (identifier) - (range - (number - (decimal)) - (number - (decimal))))) - (assert_statement - (assert_expression - (binary_expression - (identifier) - (identifier))) - (string) - (transform_chain - (module_call - (identifier) - (arguments)))))) + (identifier))) + (string) + (transform_chain + (module_call + (identifier) + (arguments))))))