Skip to content

Commit 961e0f2

Browse files
committed
Init
0 parents  commit 961e0f2

11 files changed

+571
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules/
2+
/log.html
3+
build/

binding.gyp

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"targets": [
3+
{
4+
"target_name": "tree_sitter_codetags_binding",
5+
"include_dirs": [
6+
"<!(node -e \"require('nan')\")",
7+
"src"
8+
],
9+
"sources": [
10+
"src/parser.c",
11+
"src/binding.cc"
12+
],
13+
"cflags_c": [
14+
"-std=c99",
15+
]
16+
}
17+
]
18+
}

grammar.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = grammar({
2+
name: 'codetags',
3+
4+
rules: {
5+
source: $ => 'TODO'
6+
}
7+
});

index.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
try {
2+
module.exports = require("./build/Release/tree_sitter_codetags_binding");
3+
} catch (error) {
4+
try {
5+
module.exports = require("./build/Debug/tree_sitter_codetags_binding");
6+
} catch (_) {
7+
throw error
8+
}
9+
}
10+
11+
try {
12+
module.exports.nodeTypeInfo = require("./src/node-types.json");
13+
} catch (_) {}

package-lock.json

+46
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "tree-sitter-codetags",
3+
"version": "0.0.1",
4+
"description": "Grammar for code tags like TODO:, FiXME(stsewd):, etc.",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "tree-sitter test",
8+
"build": "tree-sitter generate",
9+
"wasm": "tree-sitter build-wasm",
10+
"web": "tree-sitter web-ui"
11+
},
12+
"repository": {
13+
"type": "git",
14+
"url": "https://gihub.com/stsewd/tree-sitter-code-tags"
15+
},
16+
"keywords": [
17+
"tree-sitter",
18+
"gramar",
19+
"code-tags"
20+
],
21+
"author": "Santos Gallegos",
22+
"license": "MIT",
23+
"dependencies": {
24+
"nan": "^2.14.2"
25+
},
26+
"devDependencies": {
27+
"tree-sitter-cli": "^0.16.9"
28+
}
29+
}

src/binding.cc

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include "tree_sitter/parser.h"
2+
#include <node.h>
3+
#include "nan.h"
4+
5+
using namespace v8;
6+
7+
extern "C" TSLanguage * tree_sitter_code_tags();
8+
9+
namespace {
10+
11+
NAN_METHOD(New) {}
12+
13+
void Init(Local<Object> exports, Local<Object> module) {
14+
Local<FunctionTemplate> tpl = Nan::New<FunctionTemplate>(New);
15+
tpl->SetClassName(Nan::New("Language").ToLocalChecked());
16+
tpl->InstanceTemplate()->SetInternalFieldCount(1);
17+
18+
Local<Function> constructor = Nan::GetFunction(tpl).ToLocalChecked();
19+
Local<Object> instance = constructor->NewInstance(Nan::GetCurrentContext()).ToLocalChecked();
20+
Nan::SetInternalFieldPointer(instance, 0, tree_sitter_code_tags());
21+
22+
Nan::Set(instance, Nan::New("name").ToLocalChecked(), Nan::New("code_tags").ToLocalChecked());
23+
Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance);
24+
}
25+
26+
NODE_MODULE(tree_sitter_code_tags_binding, Init)
27+
28+
} // namespace

src/grammar.json

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "codetags",
3+
"rules": {
4+
"source": {
5+
"type": "STRING",
6+
"value": "hello"
7+
}
8+
},
9+
"extras": [
10+
{
11+
"type": "PATTERN",
12+
"value": "\\s"
13+
}
14+
],
15+
"conflicts": [],
16+
"externals": [],
17+
"inline": [],
18+
"supertypes": []
19+
}
20+

src/node-types.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[
2+
{
3+
"type": "source",
4+
"named": true,
5+
"fields": {}
6+
},
7+
{
8+
"type": "hello",
9+
"named": false
10+
}
11+
]

src/parser.c

+161
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
#include <tree_sitter/parser.h>
2+
3+
#if defined(__GNUC__) || defined(__clang__)
4+
#pragma GCC diagnostic push
5+
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
6+
#endif
7+
8+
#define LANGUAGE_VERSION 11
9+
#define STATE_COUNT 4
10+
#define LARGE_STATE_COUNT 2
11+
#define SYMBOL_COUNT 3
12+
#define ALIAS_COUNT 0
13+
#define TOKEN_COUNT 2
14+
#define EXTERNAL_TOKEN_COUNT 0
15+
#define FIELD_COUNT 0
16+
#define MAX_ALIAS_SEQUENCE_LENGTH 1
17+
18+
enum {
19+
anon_sym_hello = 1,
20+
sym_source = 2,
21+
};
22+
23+
static const char *ts_symbol_names[] = {
24+
[ts_builtin_sym_end] = "end",
25+
[anon_sym_hello] = "hello",
26+
[sym_source] = "source",
27+
};
28+
29+
static TSSymbol ts_symbol_map[] = {
30+
[ts_builtin_sym_end] = ts_builtin_sym_end,
31+
[anon_sym_hello] = anon_sym_hello,
32+
[sym_source] = sym_source,
33+
};
34+
35+
static const TSSymbolMetadata ts_symbol_metadata[] = {
36+
[ts_builtin_sym_end] = {
37+
.visible = false,
38+
.named = true,
39+
},
40+
[anon_sym_hello] = {
41+
.visible = true,
42+
.named = false,
43+
},
44+
[sym_source] = {
45+
.visible = true,
46+
.named = true,
47+
},
48+
};
49+
50+
static TSSymbol ts_alias_sequences[1][MAX_ALIAS_SEQUENCE_LENGTH] = {
51+
[0] = {0},
52+
};
53+
54+
static bool ts_lex(TSLexer *lexer, TSStateId state) {
55+
START_LEXER();
56+
eof = lexer->eof(lexer);
57+
switch (state) {
58+
case 0:
59+
if (eof) ADVANCE(5);
60+
if (lookahead == 'h') ADVANCE(1);
61+
if (lookahead == '\t' ||
62+
lookahead == '\n' ||
63+
lookahead == '\r' ||
64+
lookahead == ' ') SKIP(0)
65+
END_STATE();
66+
case 1:
67+
if (lookahead == 'e') ADVANCE(3);
68+
END_STATE();
69+
case 2:
70+
if (lookahead == 'l') ADVANCE(4);
71+
END_STATE();
72+
case 3:
73+
if (lookahead == 'l') ADVANCE(2);
74+
END_STATE();
75+
case 4:
76+
if (lookahead == 'o') ADVANCE(6);
77+
END_STATE();
78+
case 5:
79+
ACCEPT_TOKEN(ts_builtin_sym_end);
80+
END_STATE();
81+
case 6:
82+
ACCEPT_TOKEN(anon_sym_hello);
83+
END_STATE();
84+
default:
85+
return false;
86+
}
87+
}
88+
89+
static TSLexMode ts_lex_modes[STATE_COUNT] = {
90+
[0] = {.lex_state = 0},
91+
[1] = {.lex_state = 0},
92+
[2] = {.lex_state = 0},
93+
[3] = {.lex_state = 0},
94+
};
95+
96+
static uint16_t ts_parse_table[LARGE_STATE_COUNT][SYMBOL_COUNT] = {
97+
[0] = {
98+
[ts_builtin_sym_end] = ACTIONS(1),
99+
[anon_sym_hello] = ACTIONS(1),
100+
},
101+
[1] = {
102+
[sym_source] = STATE(3),
103+
[anon_sym_hello] = ACTIONS(3),
104+
},
105+
};
106+
107+
static uint16_t ts_small_parse_table[] = {
108+
[0] = 1,
109+
ACTIONS(5), 1,
110+
ts_builtin_sym_end,
111+
[4] = 1,
112+
ACTIONS(7), 1,
113+
ts_builtin_sym_end,
114+
};
115+
116+
static uint32_t ts_small_parse_table_map[] = {
117+
[SMALL_STATE(2)] = 0,
118+
[SMALL_STATE(3)] = 4,
119+
};
120+
121+
static TSParseActionEntry ts_parse_actions[] = {
122+
[0] = {.entry = {.count = 0, .reusable = false}},
123+
[1] = {.entry = {.count = 1, .reusable = false}}, RECOVER(),
124+
[3] = {.entry = {.count = 1, .reusable = true}}, SHIFT(2),
125+
[5] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_source, 1),
126+
[7] = {.entry = {.count = 1, .reusable = true}}, ACCEPT_INPUT(),
127+
};
128+
129+
#ifdef __cplusplus
130+
extern "C" {
131+
#endif
132+
#ifdef _WIN32
133+
#define extern __declspec(dllexport)
134+
#endif
135+
136+
extern const TSLanguage *tree_sitter_codetags(void) {
137+
static TSLanguage language = {
138+
.version = LANGUAGE_VERSION,
139+
.symbol_count = SYMBOL_COUNT,
140+
.alias_count = ALIAS_COUNT,
141+
.token_count = TOKEN_COUNT,
142+
.large_state_count = LARGE_STATE_COUNT,
143+
.symbol_metadata = ts_symbol_metadata,
144+
.parse_table = (const unsigned short *)ts_parse_table,
145+
.small_parse_table = (const uint16_t *)ts_small_parse_table,
146+
.small_parse_table_map = (const uint32_t *)ts_small_parse_table_map,
147+
.parse_actions = ts_parse_actions,
148+
.lex_modes = ts_lex_modes,
149+
.symbol_names = ts_symbol_names,
150+
.public_symbol_map = ts_symbol_map,
151+
.alias_sequences = (const TSSymbol *)ts_alias_sequences,
152+
.field_count = FIELD_COUNT,
153+
.max_alias_sequence_length = MAX_ALIAS_SEQUENCE_LENGTH,
154+
.lex_fn = ts_lex,
155+
.external_token_count = EXTERNAL_TOKEN_COUNT,
156+
};
157+
return &language;
158+
}
159+
#ifdef __cplusplus
160+
}
161+
#endif

0 commit comments

Comments
 (0)