Fix tests

This commit is contained in:
Jeff 2023-09-29 09:53:53 -04:00
parent b4a114108b
commit 424b1a42ef
7 changed files with 175 additions and 150 deletions

View File

@ -8,10 +8,13 @@ Full Line Comments
--- ---
(source (root
(comment) (item
(comment)
(comment)) (comment))
(item
(comment))
(item
(comment)))
================== ==================
Partial Line Comments Partial Line Comments
@ -23,13 +26,18 @@ Partial Line Comments
--- ---
(source (source
(comment) (item
(comment))
(item
(statement (statement
(closed_statement (closed_statement
(value (value
(integer)))) (integer)))))
(comment)
(item
(comment))
(item
(statement (statement
(open_statement (open_statement
(value (value
(string))))) (string))))))

View File

@ -6,7 +6,8 @@ if true then "True";
--- ---
(source (root
(item
(statement (statement
(closed_statement (closed_statement
(expression (expression
@ -19,7 +20,8 @@ if true then "True";
(expression (expression
(value (value
(string))))))) (string)))))))
(close)))) (close)))))
================== ==================
If/Then Assignment If/Then Assignment
@ -29,7 +31,8 @@ x = if true then 1;
--- ---
(source (root
(item
(statement (statement
(closed_statement (closed_statement
(expression (expression
@ -47,4 +50,5 @@ x = if true then 1;
(expression (expression
(value (value
(integer))))))))) (integer)))))))))
(close)))) (close)))))

View File

@ -8,24 +8,27 @@ x;
--- ---
(source (root
(item
(statement (statement
(closed_statement (closed_statement
(expression (expression
(value (value
(integer))) (integer)))
(close))) (close))))
(item
(statement (statement
(closed_statement (closed_statement
(expression (expression
(value (value
(string))) (string)))
(close))) (close))))
(item
(statement (statement
(closed_statement (closed_statement
(expression (expression
(identifier)) (identifier))
(close)))) (close)))))
================== ==================
Simple Assignment Simple Assignment
@ -36,7 +39,8 @@ y = "one";
--- ---
(source (root
(item
(statement (statement
(closed_statement (closed_statement
(expression (expression
@ -47,7 +51,8 @@ y = "one";
(expression (expression
(value (value
(integer))))) (integer)))))
(close))) (close))))
(item
(statement (statement
(closed_statement (closed_statement
(expression (expression
@ -58,8 +63,7 @@ y = "one";
(expression (expression
(value (value
(string))))) (string)))))
(close)))) (close)))))
================== ==================
Complex Assignment Complex Assignment
@ -69,7 +73,8 @@ x = 1 + 1;
--- ---
(source (root
(item
(statement (statement
(closed_statement (closed_statement
(expression (expression
@ -86,6 +91,4 @@ x = 1 + 1;
(expression (expression
(value (value
(integer))))) (integer)))))
(close)))) (close)))))

View File

@ -31,7 +31,7 @@ module.exports = grammar({
close: $ => ";", close: $ => ";",
identifier: $ => /[a-zA-Z|_|.]+(_[a-zA-Z]+)*/, identifier: $ => /[a-z|_|.]+/,
value: $ => choice( value: $ => choice(
$.integer, $.integer,
@ -84,5 +84,11 @@ module.exports = grammar({
$.statement, $.statement,
optional(seq('else', $.statement)) optional(seq('else', $.statement))
)), )),
_keywords: $ => choice(
'if',
'then',
'else',
),
} }
}); });

View File

@ -2,10 +2,6 @@
"name": "tree-sitter-dust", "name": "tree-sitter-dust",
"version": "1.0.0", "version": "1.0.0",
"description": "Tree Sitter grammar for the Dust programming language", "description": "Tree Sitter grammar for the Dust programming language",
"main": "bindings/node",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Jeff Anderson", "author": "Jeff Anderson",
"license": "ISC", "license": "ISC",
"tree-sitter": [ "tree-sitter": [
@ -23,5 +19,6 @@
}, },
"devDependencies": { "devDependencies": {
"tree-sitter-cli": "^0.20.8" "tree-sitter-cli": "^0.20.8"
} },
"main": "bindings/node"
} }

View File

@ -108,7 +108,7 @@
}, },
"identifier": { "identifier": {
"type": "PATTERN", "type": "PATTERN",
"value": "[a-zA-Z|_|.]+(_[a-zA-Z]+)*" "value": "[a-z|_|.]+"
}, },
"value": { "value": {
"type": "CHOICE", "type": "CHOICE",
@ -300,6 +300,23 @@
} }
] ]
} }
},
"_keywords": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "if"
},
{
"type": "STRING",
"value": "then"
},
{
"type": "STRING",
"value": "else"
}
]
} }
}, },
"extras": [ "extras": [

View File

@ -345,32 +345,31 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) {
lookahead == '\'' || lookahead == '\'' ||
lookahead == '`') ADVANCE(2); lookahead == '`') ADVANCE(2);
if (lookahead == '#') ADVANCE(4); if (lookahead == '#') ADVANCE(4);
if (lookahead == '(') ADVANCE(15); if (lookahead == '(') ADVANCE(14);
if (lookahead == ')') ADVANCE(17); if (lookahead == ')') ADVANCE(16);
if (lookahead == '+') ADVANCE(18); if (lookahead == '+') ADVANCE(17);
if (lookahead == ',') ADVANCE(16); if (lookahead == ',') ADVANCE(15);
if (lookahead == '-') ADVANCE(19); if (lookahead == '-') ADVANCE(18);
if (lookahead == ';') ADVANCE(7); if (lookahead == ';') ADVANCE(7);
if (lookahead == '=') ADVANCE(20); if (lookahead == '=') ADVANCE(19);
if (lookahead == '{') ADVANCE(1); if (lookahead == '{') ADVANCE(1);
if (lookahead == '\t' || if (lookahead == '\t' ||
lookahead == '\n' || lookahead == '\n' ||
lookahead == '\r' || lookahead == '\r' ||
lookahead == ' ') SKIP(0) lookahead == ' ') SKIP(0)
if (('0' <= lookahead && lookahead <= '9')) ADVANCE(11); if (('0' <= lookahead && lookahead <= '9')) ADVANCE(10);
if (lookahead == '.' || if (lookahead == '.' ||
('A' <= lookahead && lookahead <= 'Z') || ('_' <= lookahead && lookahead <= '|')) ADVANCE(8);
('_' <= lookahead && lookahead <= '|')) ADVANCE(9);
END_STATE(); END_STATE();
case 1: case 1:
if (lookahead == '}') ADVANCE(13); if (lookahead == '}') ADVANCE(12);
if (lookahead != 0 && if (lookahead != 0 &&
lookahead != '\n') ADVANCE(1); lookahead != '\n') ADVANCE(1);
END_STATE(); END_STATE();
case 2: case 2:
if (lookahead == '"' || if (lookahead == '"' ||
lookahead == '\'' || lookahead == '\'' ||
lookahead == '`') ADVANCE(12); lookahead == '`') ADVANCE(11);
if (lookahead != 0 && if (lookahead != 0 &&
lookahead != '\n') ADVANCE(2); lookahead != '\n') ADVANCE(2);
END_STATE(); END_STATE();
@ -398,67 +397,58 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) {
END_STATE(); END_STATE();
case 8: case 8:
ACCEPT_TOKEN(sym_identifier); ACCEPT_TOKEN(sym_identifier);
if (lookahead == '_') ADVANCE(8);
if (lookahead == '.' || if (lookahead == '.' ||
lookahead == '|') ADVANCE(9); lookahead == '_' ||
if (('A' <= lookahead && lookahead <= 'Z') || ('a' <= lookahead && lookahead <= 'z') ||
('a' <= lookahead && lookahead <= 'z')) ADVANCE(8); lookahead == '|') ADVANCE(8);
END_STATE(); END_STATE();
case 9: case 9:
ACCEPT_TOKEN(sym_identifier); ACCEPT_TOKEN(sym_float);
if (lookahead == '_') ADVANCE(8); if (('0' <= lookahead && lookahead <= '9')) ADVANCE(9);
if (lookahead == '.' ||
('A' <= lookahead && lookahead <= 'Z') ||
('a' <= lookahead && lookahead <= 'z') ||
lookahead == '|') ADVANCE(9);
END_STATE(); END_STATE();
case 10: case 10:
ACCEPT_TOKEN(sym_float); ACCEPT_TOKEN(sym_integer);
if (lookahead == '.') ADVANCE(9);
if (('0' <= lookahead && lookahead <= '9')) ADVANCE(10); if (('0' <= lookahead && lookahead <= '9')) ADVANCE(10);
END_STATE(); END_STATE();
case 11: case 11:
ACCEPT_TOKEN(sym_integer);
if (lookahead == '.') ADVANCE(10);
if (('0' <= lookahead && lookahead <= '9')) ADVANCE(11);
END_STATE();
case 12:
ACCEPT_TOKEN(sym_string); ACCEPT_TOKEN(sym_string);
if (lookahead == '"' || if (lookahead == '"' ||
lookahead == '\'' || lookahead == '\'' ||
lookahead == '`') ADVANCE(12); lookahead == '`') ADVANCE(11);
if (lookahead != 0 && if (lookahead != 0 &&
lookahead != '\n') ADVANCE(2); lookahead != '\n') ADVANCE(2);
END_STATE(); END_STATE();
case 13: case 12:
ACCEPT_TOKEN(sym_function); ACCEPT_TOKEN(sym_function);
if (lookahead == '}') ADVANCE(13); if (lookahead == '}') ADVANCE(12);
if (lookahead != 0 && if (lookahead != 0 &&
lookahead != '\n') ADVANCE(1); lookahead != '\n') ADVANCE(1);
END_STATE(); END_STATE();
case 14: case 13:
ACCEPT_TOKEN(sym_empty); ACCEPT_TOKEN(sym_empty);
END_STATE(); END_STATE();
case 15: case 14:
ACCEPT_TOKEN(anon_sym_LPAREN); ACCEPT_TOKEN(anon_sym_LPAREN);
if (lookahead == ')') ADVANCE(14); if (lookahead == ')') ADVANCE(13);
END_STATE(); END_STATE();
case 16: case 15:
ACCEPT_TOKEN(anon_sym_COMMA); ACCEPT_TOKEN(anon_sym_COMMA);
END_STATE(); END_STATE();
case 17: case 16:
ACCEPT_TOKEN(anon_sym_RPAREN); ACCEPT_TOKEN(anon_sym_RPAREN);
END_STATE(); END_STATE();
case 18: case 17:
ACCEPT_TOKEN(anon_sym_PLUS); ACCEPT_TOKEN(anon_sym_PLUS);
END_STATE(); END_STATE();
case 19: case 18:
ACCEPT_TOKEN(anon_sym_DASH); ACCEPT_TOKEN(anon_sym_DASH);
END_STATE(); END_STATE();
case 20: case 19:
ACCEPT_TOKEN(anon_sym_EQ); ACCEPT_TOKEN(anon_sym_EQ);
if (lookahead == '=') ADVANCE(21); if (lookahead == '=') ADVANCE(20);
END_STATE(); END_STATE();
case 21: case 20:
ACCEPT_TOKEN(anon_sym_EQ_EQ); ACCEPT_TOKEN(anon_sym_EQ_EQ);
END_STATE(); END_STATE();
default: default: