-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(scanner): drop unnecessary struct
- Loading branch information
1 parent
189b3cc
commit ce2f4f6
Showing
1 changed file
with
8 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,22 @@ | ||
#include "tree_sitter/parser.h" | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
enum TokenType { FAKE_EOL }; | ||
|
||
typedef struct { | ||
bool reached_eof; | ||
} Scanner; | ||
|
||
void *tree_sitter_properties_external_scanner_create() { | ||
Scanner *scanner = malloc(sizeof(Scanner)); | ||
scanner->reached_eof = false; | ||
return scanner; | ||
} | ||
static bool reached_eof = false; | ||
|
||
bool tree_sitter_properties_external_scanner_scan(void *payload, TSLexer *lexer, const bool *valid_symbols) { | ||
Scanner *scanner = (Scanner *) payload; | ||
|
||
if (valid_symbols[FAKE_EOL] && !scanner->reached_eof && lexer->eof(lexer)) { | ||
lexer->result_symbol = FAKE_EOL; | ||
return scanner->reached_eof = true; | ||
} | ||
|
||
return false; | ||
lexer->result_symbol = FAKE_EOL; | ||
return reached_eof = !reached_eof && valid_symbols[FAKE_EOL] && lexer->eof(lexer); | ||
} | ||
|
||
unsigned tree_sitter_properties_external_scanner_serialize(void *payload, char *buffer) { | ||
Scanner *scanner = (Scanner *) payload; | ||
return scanner->reached_eof ? 1 : 0; | ||
return reached_eof; | ||
} | ||
|
||
void tree_sitter_properties_external_scanner_deserialize(void *payload, const char *buffer, unsigned length) { | ||
Scanner *scanner = (Scanner *) payload; | ||
scanner->reached_eof = length == 1; | ||
reached_eof = length; | ||
} | ||
|
||
void tree_sitter_properties_external_scanner_destroy(void *payload) { | ||
free(payload); | ||
} | ||
void *tree_sitter_properties_external_scanner_create() { return NULL; } | ||
|
||
void tree_sitter_properties_external_scanner_destroy(void *payload) { } |