Ignore external tokens that are zero-length and extra (#4213)

Co-authored-by: Anthony <anthony@zed.dev>
This commit is contained in:
Max Brunsfeld 2025-02-17 15:07:44 -08:00 committed by GitHub
parent 14b8ead412
commit dedcc5255a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 71 additions and 16 deletions

View file

@ -0,0 +1,9 @@
==========================
A document
==========================
a b
---
(document)

View file

@ -0,0 +1,11 @@
module.exports = grammar({
name: 'epsilon_external_extra_tokens',
extras: $ => [/\s/, $.comment],
externals: $ => [$.comment],
rules: {
document: $ => seq('a', 'b'),
}
});

View file

@ -0,0 +1,33 @@
#include "tree_sitter/parser.h"
enum TokenType {
COMMENT
};
void *tree_sitter_epsilon_external_extra_tokens_external_scanner_create(void) {
return NULL;
}
bool tree_sitter_epsilon_external_extra_tokens_external_scanner_scan(
void *payload,
TSLexer *lexer,
const bool *valid_symbols
) {
lexer->result_symbol = COMMENT;
return true;
}
unsigned tree_sitter_epsilon_external_extra_tokens_external_scanner_serialize(
void *payload,
char *buffer
) {
return 0;
}
void tree_sitter_epsilon_external_extra_tokens_external_scanner_deserialize(
void *payload,
const char *buffer,
unsigned length
) {}
void tree_sitter_epsilon_external_extra_tokens_external_scanner_destroy(void *payload) {}