mirror of https://github.com/Wilfred/difftastic/
Fix for comment-in-string bug (#27)
Nodes defined in `extras` can be expected before an node. Thus, `comment` could be expected before `escape_sequence` or `quoted_content`; aka inside of a string. Naturally, this makes no sense.
I tried wrapping `escape_sequence` and `quoted_content` in `token.immediate` to resolve the issue, but it had no effect (maybe is specific to whitespace?). Instead, I found success in largely copying [`tree-sitter-rust`'s solution of using an external scanner for string content](9a6d980afb/src/scanner.c (L27-L40)).
pull/315/head
parent
ec0286fd84
commit
17ed183fc8
@ -1,2 +1,3 @@
|
||||
src/** linguist-generated
|
||||
src/scanner.c -linguist-generated
|
||||
test/** linguist-documentation
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,28 @@
|
||||
#include <tree_sitter/parser.h>
|
||||
|
||||
enum TokenType {
|
||||
QUOTED_CONTENT
|
||||
};
|
||||
|
||||
void * tree_sitter_gleam_external_scanner_create() {return NULL;}
|
||||
void tree_sitter_gleam_external_scanner_destroy(void * payload) {}
|
||||
unsigned tree_sitter_gleam_external_scanner_serialize(void * payload, char * buffer) {return 0;}
|
||||
void tree_sitter_gleam_external_scanner_deserialize(void * payload, const char * buffer, unsigned length) {}
|
||||
|
||||
bool tree_sitter_gleam_external_scanner_scan(void * payload, TSLexer *lexer, const bool * valid_symbols) {
|
||||
if (valid_symbols[QUOTED_CONTENT]) {
|
||||
bool has_content = false;
|
||||
|
||||
while (true) {
|
||||
if (lexer->lookahead == '\"' || lexer->lookahead == '\\') {
|
||||
break;
|
||||
} else if (lexer->lookahead == 0) {
|
||||
return false;
|
||||
}
|
||||
has_content = true;
|
||||
lexer->advance(lexer, false);
|
||||
}
|
||||
lexer->result_symbol = QUOTED_CONTENT;
|
||||
return has_content;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue