-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
35 additions
and
33 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,46 +1,48 @@ | ||
#include "tree_sitter/parser.h" | ||
|
||
enum TokenType { | ||
TYPE_TOKEN | ||
}; | ||
enum TokenType { TYPE_TOKEN }; | ||
|
||
void *tree_sitter_jsdoc_external_scanner_create() { return NULL; } | ||
void tree_sitter_jsdoc_external_scanner_destroy(void *p) {} | ||
void tree_sitter_jsdoc_external_scanner_reset(void *p) {} | ||
unsigned tree_sitter_jsdoc_external_scanner_serialize(void *p, char *buffer) { return 0; } | ||
void tree_sitter_jsdoc_external_scanner_deserialize(void *p, const char *b, unsigned n) {} | ||
|
||
void tree_sitter_jsdoc_external_scanner_destroy(void *payload) {} | ||
|
||
unsigned tree_sitter_jsdoc_external_scanner_serialize(void *payload, char *buffer) { return 0; } | ||
|
||
void tree_sitter_jsdoc_external_scanner_deserialize(void *payload, const char *buffer, unsigned length) {} | ||
|
||
// Scan to the next balanced `}` character. | ||
static bool scan_for_type(TSLexer *lexer) { | ||
int stack = 0; | ||
while (true) { | ||
if (lexer->eof(lexer)) { | ||
return false; | ||
int stack = 0; | ||
while (true) { | ||
if (lexer->eof(lexer)) { | ||
return false; | ||
} | ||
switch (lexer->lookahead) { | ||
case '{': | ||
stack++; | ||
break; | ||
case '}': | ||
stack--; | ||
if (stack == -1) { | ||
return true; | ||
} | ||
break; | ||
case '\n': | ||
case '\0': // fallthrough | ||
// Something's gone wrong. | ||
return false; | ||
default:; | ||
} | ||
lexer->advance(lexer, false); | ||
} | ||
switch (lexer->lookahead) { | ||
case '{': | ||
stack++; | ||
break; | ||
case '}': | ||
stack--; | ||
if (stack == -1) { return true; } | ||
break; | ||
case '\n': | ||
case '\0': // fallthrough | ||
// Something's gone wrong. | ||
return false; | ||
default:; | ||
} | ||
lexer->advance(lexer, false); | ||
} | ||
} | ||
|
||
bool tree_sitter_jsdoc_external_scanner_scan(void *payload, TSLexer *lexer, const bool *valid_symbols) { | ||
if (valid_symbols[TYPE_TOKEN] && scan_for_type(lexer)) { | ||
lexer->result_symbol = TYPE_TOKEN; | ||
lexer->mark_end(lexer); | ||
return true; | ||
} | ||
if (valid_symbols[TYPE_TOKEN] && scan_for_type(lexer)) { | ||
lexer->result_symbol = TYPE_TOKEN; | ||
lexer->mark_end(lexer); | ||
return true; | ||
} | ||
|
||
return false; | ||
return false; | ||
} |