add support for import statements

This commit is contained in:
Peter Hart 2022-09-03 00:05:26 -04:00
parent 51def200ab
commit bd6ecaee2c
5 changed files with 45 additions and 18 deletions

View File

@ -20,9 +20,10 @@ module.exports = grammar({
),
optional($.script_part)
),
static_modifier: $ => 'static',
import_statement: $ => seq(
'import',
optional('static'),
optional($.static_modifier),
field('name',
seq(
$.identifier,

View File

@ -94,6 +94,10 @@
}
]
},
"static_modifier": {
"type": "STRING",
"value": "static"
},
"import_statement": {
"type": "SEQ",
"members": [
@ -105,8 +109,8 @@
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "static"
"type": "SYMBOL",
"name": "static_modifier"
},
{
"type": "BLANK"

View File

@ -36,6 +36,16 @@
}
]
}
},
"children": {
"multiple": false,
"required": false,
"types": [
{
"type": "static_modifier",
"named": true
}
]
}
},
{
@ -179,7 +189,7 @@
"named": false
},
{
"type": "static",
"named": false
"type": "static_modifier",
"named": true
}
]

View File

@ -17,8 +17,8 @@
#define PRODUCTION_ID_COUNT 9
enum {
anon_sym_import = 1,
anon_sym_static = 2,
sym_static_modifier = 1,
anon_sym_import = 2,
anon_sym_DOT = 3,
anon_sym_STAR = 4,
sym__shebang_comment = 5,
@ -44,8 +44,8 @@ enum {
static const char * const ts_symbol_names[] = {
[ts_builtin_sym_end] = "end",
[sym_static_modifier] = "static_modifier",
[anon_sym_import] = "import",
[anon_sym_static] = "static",
[anon_sym_DOT] = ".",
[anon_sym_STAR] = "*",
[sym__shebang_comment] = "_shebang_comment",
@ -71,8 +71,8 @@ static const char * const ts_symbol_names[] = {
static const TSSymbol ts_symbol_map[] = {
[ts_builtin_sym_end] = ts_builtin_sym_end,
[sym_static_modifier] = sym_static_modifier,
[anon_sym_import] = anon_sym_import,
[anon_sym_static] = anon_sym_static,
[anon_sym_DOT] = anon_sym_DOT,
[anon_sym_STAR] = anon_sym_STAR,
[sym__shebang_comment] = sym__shebang_comment,
@ -101,11 +101,11 @@ static const TSSymbolMetadata ts_symbol_metadata[] = {
.visible = false,
.named = true,
},
[anon_sym_import] = {
[sym_static_modifier] = {
.visible = true,
.named = false,
.named = true,
},
[anon_sym_static] = {
[anon_sym_import] = {
.visible = true,
.named = false,
},
@ -432,14 +432,14 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) {
ACCEPT_TOKEN(ts_builtin_sym_end);
END_STATE();
case 11:
ACCEPT_TOKEN(anon_sym_import);
ACCEPT_TOKEN(sym_static_modifier);
if (('0' <= lookahead && lookahead <= '9') ||
('A' <= lookahead && lookahead <= 'Z') ||
lookahead == '_' ||
('a' <= lookahead && lookahead <= 'z')) ADVANCE(35);
END_STATE();
case 12:
ACCEPT_TOKEN(anon_sym_static);
ACCEPT_TOKEN(anon_sym_import);
if (('0' <= lookahead && lookahead <= '9') ||
('A' <= lookahead && lookahead <= 'Z') ||
lookahead == '_' ||
@ -495,7 +495,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) {
END_STATE();
case 21:
ACCEPT_TOKEN(sym_identifier);
if (lookahead == 'c') ADVANCE(12);
if (lookahead == 'c') ADVANCE(11);
if (('0' <= lookahead && lookahead <= '9') ||
('A' <= lookahead && lookahead <= 'Z') ||
lookahead == '_' ||
@ -591,7 +591,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) {
END_STATE();
case 33:
ACCEPT_TOKEN(sym_identifier);
if (lookahead == 't') ADVANCE(11);
if (lookahead == 't') ADVANCE(12);
if (('0' <= lookahead && lookahead <= '9') ||
('A' <= lookahead && lookahead <= 'Z') ||
lookahead == '_' ||
@ -689,8 +689,8 @@ static const TSLexMode ts_lex_modes[STATE_COUNT] = {
static const uint16_t ts_parse_table[LARGE_STATE_COUNT][SYMBOL_COUNT] = {
[0] = {
[ts_builtin_sym_end] = ACTIONS(1),
[sym_static_modifier] = ACTIONS(1),
[anon_sym_import] = ACTIONS(1),
[anon_sym_static] = ACTIONS(1),
[anon_sym_DOT] = ACTIONS(1),
[anon_sym_STAR] = ACTIONS(1),
[sym__shebang_comment] = ACTIONS(1),
@ -1150,7 +1150,7 @@ static const uint16_t ts_small_parse_table[] = {
sym_identifier,
[475] = 2,
ACTIONS(139), 1,
anon_sym_static,
sym_static_modifier,
ACTIONS(141), 1,
sym_identifier,
[482] = 2,

View File

@ -45,3 +45,15 @@ import qq.ss; import flobble.*;
(identifier))
(import_statement
(identifier)))
================================================================================
static import
================================================================================
import static qq.q.*;
--------------------------------------------------------------------------------
(source_file
(import_statement
(static_modifier)
(identifier)
(identifier)))