feat: add integer
This commit is contained in:
@@ -11,7 +11,6 @@ module.exports = grammar({
|
||||
name: "emm",
|
||||
|
||||
rules: {
|
||||
// TODO: add the actual grammar rules
|
||||
source_file: $ => "hello"
|
||||
}
|
||||
integer: ($) => /0|[1-9]\d*/,
|
||||
},
|
||||
});
|
||||
|
||||
6
src/grammar.json
generated
6
src/grammar.json
generated
@@ -2,9 +2,9 @@
|
||||
"$schema": "https://tree-sitter.github.io/tree-sitter/assets/schemas/grammar.schema.json",
|
||||
"name": "emm",
|
||||
"rules": {
|
||||
"source_file": {
|
||||
"type": "STRING",
|
||||
"value": "hello"
|
||||
"integer": {
|
||||
"type": "PATTERN",
|
||||
"value": "0|[1-9]\\d*"
|
||||
}
|
||||
},
|
||||
"extras": [
|
||||
|
||||
6
src/node-types.json
generated
6
src/node-types.json
generated
@@ -1,12 +1,8 @@
|
||||
[
|
||||
{
|
||||
"type": "source_file",
|
||||
"type": "integer",
|
||||
"named": true,
|
||||
"root": true,
|
||||
"fields": {}
|
||||
},
|
||||
{
|
||||
"type": "hello",
|
||||
"named": false
|
||||
}
|
||||
]
|
||||
51
src/parser.c
generated
51
src/parser.c
generated
@@ -20,20 +20,20 @@
|
||||
#define SUPERTYPE_COUNT 0
|
||||
|
||||
enum ts_symbol_identifiers {
|
||||
anon_sym_hello = 1,
|
||||
sym_source_file = 2,
|
||||
aux_sym_integer_token1 = 1,
|
||||
sym_integer = 2,
|
||||
};
|
||||
|
||||
static const char * const ts_symbol_names[] = {
|
||||
[ts_builtin_sym_end] = "end",
|
||||
[anon_sym_hello] = "hello",
|
||||
[sym_source_file] = "source_file",
|
||||
[aux_sym_integer_token1] = "integer_token1",
|
||||
[sym_integer] = "integer",
|
||||
};
|
||||
|
||||
static const TSSymbol ts_symbol_map[] = {
|
||||
[ts_builtin_sym_end] = ts_builtin_sym_end,
|
||||
[anon_sym_hello] = anon_sym_hello,
|
||||
[sym_source_file] = sym_source_file,
|
||||
[aux_sym_integer_token1] = aux_sym_integer_token1,
|
||||
[sym_integer] = sym_integer,
|
||||
};
|
||||
|
||||
static const TSSymbolMetadata ts_symbol_metadata[] = {
|
||||
@@ -41,11 +41,11 @@ static const TSSymbolMetadata ts_symbol_metadata[] = {
|
||||
.visible = false,
|
||||
.named = true,
|
||||
},
|
||||
[anon_sym_hello] = {
|
||||
.visible = true,
|
||||
[aux_sym_integer_token1] = {
|
||||
.visible = false,
|
||||
.named = false,
|
||||
},
|
||||
[sym_source_file] = {
|
||||
[sym_integer] = {
|
||||
.visible = true,
|
||||
.named = true,
|
||||
},
|
||||
@@ -71,28 +71,21 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) {
|
||||
eof = lexer->eof(lexer);
|
||||
switch (state) {
|
||||
case 0:
|
||||
if (eof) ADVANCE(5);
|
||||
if (lookahead == 'h') ADVANCE(1);
|
||||
if (eof) ADVANCE(1);
|
||||
if (lookahead == '0') ADVANCE(2);
|
||||
if (('\t' <= lookahead && lookahead <= '\r') ||
|
||||
lookahead == ' ') SKIP(0);
|
||||
if (('1' <= lookahead && lookahead <= '9')) ADVANCE(3);
|
||||
END_STATE();
|
||||
case 1:
|
||||
if (lookahead == 'e') ADVANCE(3);
|
||||
END_STATE();
|
||||
case 2:
|
||||
if (lookahead == 'l') ADVANCE(4);
|
||||
END_STATE();
|
||||
case 3:
|
||||
if (lookahead == 'l') ADVANCE(2);
|
||||
END_STATE();
|
||||
case 4:
|
||||
if (lookahead == 'o') ADVANCE(6);
|
||||
END_STATE();
|
||||
case 5:
|
||||
ACCEPT_TOKEN(ts_builtin_sym_end);
|
||||
END_STATE();
|
||||
case 6:
|
||||
ACCEPT_TOKEN(anon_sym_hello);
|
||||
case 2:
|
||||
ACCEPT_TOKEN(aux_sym_integer_token1);
|
||||
END_STATE();
|
||||
case 3:
|
||||
ACCEPT_TOKEN(aux_sym_integer_token1);
|
||||
if (('0' <= lookahead && lookahead <= '9')) ADVANCE(3);
|
||||
END_STATE();
|
||||
default:
|
||||
return false;
|
||||
@@ -109,11 +102,11 @@ static const TSLexerMode ts_lex_modes[STATE_COUNT] = {
|
||||
static const uint16_t ts_parse_table[LARGE_STATE_COUNT][SYMBOL_COUNT] = {
|
||||
[STATE(0)] = {
|
||||
[ts_builtin_sym_end] = ACTIONS(1),
|
||||
[anon_sym_hello] = ACTIONS(1),
|
||||
[aux_sym_integer_token1] = ACTIONS(1),
|
||||
},
|
||||
[STATE(1)] = {
|
||||
[sym_source_file] = STATE(3),
|
||||
[anon_sym_hello] = ACTIONS(3),
|
||||
[sym_integer] = STATE(3),
|
||||
[aux_sym_integer_token1] = ACTIONS(3),
|
||||
},
|
||||
};
|
||||
|
||||
@@ -135,7 +128,7 @@ static const TSParseActionEntry ts_parse_actions[] = {
|
||||
[0] = {.entry = {.count = 0, .reusable = false}},
|
||||
[1] = {.entry = {.count = 1, .reusable = false}}, RECOVER(),
|
||||
[3] = {.entry = {.count = 1, .reusable = true}}, SHIFT(2),
|
||||
[5] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_source_file, 1, 0, 0),
|
||||
[5] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_integer, 1, 0, 0),
|
||||
[7] = {.entry = {.count = 1, .reusable = true}}, ACCEPT_INPUT(),
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user