Allow lexical debug mode to be enabled on documents

- `ts_document_set_debug(doc, 1)` implies parse debug mode
- `ts_document_set_debug(doc, > 1)` implies parse and lex debug mode
This commit is contained in:
Max Brunsfeld 2014-09-11 13:12:06 -07:00
parent 68d6e242ee
commit e23f11b7c4
4 changed files with 21 additions and 11 deletions

View file

@ -35,13 +35,17 @@ static void reparse(TSDocument *document, TSInputEdit *edit) {
void ts_document_set_language(TSDocument *document, const TSLanguage *language) {
ts_parser_destroy(&document->parser);
document->parser = ts_parser_make(language);
document->parser.debug = document->debug;
ts_document_set_debug(document, document->debug);
reparse(document, NULL);
}
void ts_document_set_debug(TSDocument *document, int debug) {
document->debug = debug;
document->parser.debug = debug;
if (debug > 1)
document->parser.lexer.debug = 1;
else
document->parser.lexer.debug = 0;
}
void ts_document_set_input(TSDocument *document, TSInput input) {

View file

@ -37,13 +37,18 @@ static TSTree *accept(TSLexer *lexer, TSSymbol symbol, int is_hidden) {
* this library.
*/
TSLexer ts_lexer_make() {
return (TSLexer) { .chunk = NULL,
.debug = 0,
.chunk_start = 0,
.chunk_size = 0,
.position_in_chunk = 0,
.token_start_position = 0,
.token_end_position = 0,
.advance_fn = advance,
.accept_fn = accept, };
TSLexer result = (TSLexer) { .debug = 0,
.advance_fn = advance,
.accept_fn = accept, };
ts_lexer_reset(&result);
return result;
}
void ts_lexer_reset(TSLexer *lexer) {
lexer->chunk = NULL;
lexer->chunk_start = 0;
lexer->chunk_size = 0;
lexer->position_in_chunk = 0;
lexer->token_start_position = 0;
lexer->token_end_position = 0;
}

View file

@ -8,6 +8,7 @@ extern "C" {
#include "tree_sitter/parser.h"
TSLexer ts_lexer_make();
void ts_lexer_reset(TSLexer *);
#ifdef __cplusplus
}

View file

@ -216,7 +216,7 @@ const TSTree *ts_parser_parse(TSParser *parser, TSInput input,
TSInputEdit *edit) {
parser->lookahead = NULL;
parser->next_lookahead = NULL;
parser->lexer = ts_lexer_make();
ts_lexer_reset(&parser->lexer);
parser->lexer.input = input;
input.seek_fn(input.data, breakdown_stack(parser, edit));