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
(comment)
(comment)
(comment))
(root
(item
(comment))
(item
(comment))
(item
(comment)))
==================
Partial Line Comments
@ -23,13 +26,18 @@ Partial Line Comments
---
(source
(comment)
(item
(comment))
(item
(statement
(closed_statement
(value
(integer))))
(comment)
(integer)))))
(item
(comment))
(item
(statement
(open_statement
(value
(string)))))
(string))))))

View File

@ -6,20 +6,22 @@ if true then "True";
---
(source
(statement
(closed_statement
(expression
(control_flow
(expression
(value
(boolean)))
(statement
(open_statement
(expression
(value
(string)))))))
(close))))
(root
(item
(statement
(closed_statement
(expression
(control_flow
(expression
(value
(boolean)))
(statement
(open_statement
(expression
(value
(string)))))))
(close)))))
==================
If/Then Assignment
@ -29,22 +31,24 @@ x = if true then 1;
---
(source
(statement
(closed_statement
(expression
(operation
(expression
(identifier))
(operator)
(expression
(control_flow
(expression
(value
(boolean)))
(statement
(open_statement
(expression
(value
(integer)))))))))
(close))))
(root
(item
(statement
(closed_statement
(expression
(operation
(expression
(identifier))
(operator)
(expression
(control_flow
(expression
(value
(boolean)))
(statement
(open_statement
(expression
(value
(integer)))))))))
(close)))))

View File

@ -8,24 +8,27 @@ x;
---
(source
(statement
(closed_statement
(expression
(value
(integer)))
(close)))
(statement
(closed_statement
(expression
(value
(string)))
(close)))
(statement
(closed_statement
(expression
(identifier))
(close))))
(root
(item
(statement
(closed_statement
(expression
(value
(integer)))
(close))))
(item
(statement
(closed_statement
(expression
(value
(string)))
(close))))
(item
(statement
(closed_statement
(expression
(identifier))
(close)))))
==================
Simple Assignment
@ -36,30 +39,31 @@ y = "one";
---
(source
(statement
(closed_statement
(expression
(operation
(expression
(identifier))
(operator)
(expression
(value
(integer)))))
(close)))
(statement
(closed_statement
(expression
(operation
(expression
(identifier))
(operator)
(expression
(value
(string)))))
(close))))
(root
(item
(statement
(closed_statement
(expression
(operation
(expression
(identifier))
(operator)
(expression
(value
(integer)))))
(close))))
(item
(statement
(closed_statement
(expression
(operation
(expression
(identifier))
(operator)
(expression
(value
(string)))))
(close)))))
==================
Complex Assignment
@ -69,23 +73,22 @@ x = 1 + 1;
---
(source
(statement
(closed_statement
(expression
(operation
(expression
(operation
(expression
(identifier))
(operator)
(expression
(value
(integer)))))
(operator)
(expression
(value
(integer)))))
(close))))
(root
(item
(statement
(closed_statement
(expression
(operation
(expression
(operation
(expression
(identifier))
(operator)
(expression
(value
(integer)))))
(operator)
(expression
(value
(integer)))))
(close)))))

View File

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

View File

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

View File

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

View File

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