Skip to content

Commit 814bf32

Browse files
committed
Fix text tokens
1 parent 4a47080 commit 814bf32

File tree

5 files changed

+22
-17
lines changed

5 files changed

+22
-17
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules/
22
/log.html
3+
/target
34
build/

grammar.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
const WHITE_SPACE = choice(' ', '\t', '\v', '\f');
1+
const WHITE_SPACE = choice(" ", "\t", "\v", "\f");
22
const NEWLINE = /\r?\n/;
33

44
module.exports = grammar({
5-
name: 'comment',
5+
name: "comment",
66

77
externals: $ => [
88
$.name,
@@ -18,7 +18,7 @@ module.exports = grammar({
1818
source: $ => repeat(
1919
choice(
2020
$.tag,
21-
alias($._text, 'text'),
21+
alias($._text, "text"),
2222
),
2323
),
2424

package-lock.json

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

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@
2626
"nan": "^2.14.2"
2727
},
2828
"devDependencies": {
29-
"tree-sitter-cli": "^0.19.3"
29+
"tree-sitter-cli": "^0.19.4"
3030
}
3131
}

src/tree_sitter_comment/parser.c

+10-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include "tree_sitter_comment/chars.c"
44
#include "tree_sitter_comment/tokens.h"
55

6-
/// Parse a the name of the tag.
6+
/// Parse the name of the tag.
77
///
88
/// They can be of the form:
99
/// - TODO:
@@ -43,12 +43,12 @@ bool parse_tagname(TSLexer* lexer, const bool* valid_symbols)
4343
}
4444
// Checking aperture.
4545
if (lexer->lookahead != '(') {
46-
return parse_text(lexer, valid_symbols, true);
46+
return parse_text(lexer, valid_symbols, false);
4747
}
4848
// Checking closure.
4949
while (lexer->lookahead != ')') {
5050
if (is_newline(lexer->lookahead)) {
51-
return parse_text(lexer, valid_symbols, true);
51+
return parse_text(lexer, valid_symbols, false);
5252
}
5353
lexer->advance(lexer, false);
5454
}
@@ -72,11 +72,15 @@ bool parse_tagname(TSLexer* lexer, const bool* valid_symbols)
7272

7373
/// Parse normal text.
7474
///
75-
/// Text nodes are september by white spaces or an start char like `(`
75+
/// Text nodes are separated by white spaces or an start char like `(`
7676
bool parse_text(TSLexer* lexer, const bool* valid_symbols, bool end)
7777
{
78-
if (is_space(lexer->lookahead) || !valid_symbols[T_TEXT]) {
79-
if (!end && valid_symbols[T_TEXT]) {
78+
if (!valid_symbols[T_TEXT]) {
79+
return false;
80+
}
81+
82+
if (is_space(lexer->lookahead)) {
83+
if (!end) {
8084
lexer->result_symbol = T_TEXT;
8185
return true;
8286
}

0 commit comments

Comments
 (0)