Skip to content

Commit

Permalink
fixup! scanner cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ObserverOfTime committed Feb 20, 2024
1 parent e70146b commit 58c4722
Show file tree
Hide file tree
Showing 13 changed files with 365 additions and 485 deletions.
1 change: 1 addition & 0 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"-std=c99",
"-Wno-misleading-indentation",
"-Wno-unused-parameter",
"-Wno-unused-but-set-variable"
],
"cflags_cc": [
"-Wno-cast-function-type",
Expand Down
3 changes: 2 additions & 1 deletion bindings/rust/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ fn main() {
config.include(&xml_dir);
config
.flag_if_supported("-Wno-misleading-indentation")
.flag_if_supported("-Wno-unused-parameter");
.flag_if_supported("-Wno-unused-parameter")
.flag_if_supported("-Wno-unused-but-set-variable");

for path in &[
xml_dir.join("parser.c"),
Expand Down
26 changes: 3 additions & 23 deletions common/scanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ enum TokenType {
END_TAG_NAME,
ERRONEOUS_END_NAME,
SELF_CLOSING_TAG_DELIMITER,
IMPLICIT_END_TAG,
};

// BUG: see cursorless-dev/vscode-parse-tree#74
Expand All @@ -26,17 +25,12 @@ enum TokenType {
#define isalnum(chr) (isalpha(chr) || ((chr) >= '0' && (chr) <= '9'))

/// Advance the lexer if the next token doesn't match the given character
#define advance_if_not(lexer, chr) \
if ((lexer)->lookahead != (chr)) \
return false; \
advance((lexer))
#define advance_if_not(lexer, chr) \
if ((lexer)->lookahead != (chr)) return false; advance((lexer))

/// Advance the lexer to the next token
static inline void advance(TSLexer *lexer) { lexer->advance(lexer, false); }

/// Skip the current token
static inline void skip(TSLexer *lexer) { lexer->advance(lexer, true); }

/// Check if the character is valid in PITarget
/// @private
static inline bool is_valid_pi_char(int32_t chr) {
Expand Down Expand Up @@ -122,11 +116,7 @@ static bool scan_pi_content(TSLexer *lexer) {
}

/// Scan for a Comment node
static bool scan_comment(TSLexer *lexer, bool xml) {
if (!xml) {
advance_if_not(lexer, '<');
advance_if_not(lexer, '!');
}
static bool scan_comment(TSLexer *lexer) {
advance_if_not(lexer, '-');
advance_if_not(lexer, '-');

Expand All @@ -151,13 +141,3 @@ static bool scan_comment(TSLexer *lexer, bool xml) {

return false;
}

/// Define the boilerplate functions of the scanner
#define SCANNER_BOILERPLATE(name) \
void *tree_sitter_##name##_external_scanner_create() { return NULL; } \
\
void tree_sitter_##name##_external_scanner_destroy(void *payload) {} \
\
unsigned tree_sitter_##name##_external_scanner_serialize(void *payload, char *buffer) { return 0; } \
\
void tree_sitter_##name##_external_scanner_deserialize(void *payload, const char *buffer, unsigned length) {}
64 changes: 32 additions & 32 deletions dtd/src/parser.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 12 additions & 2 deletions dtd/src/scanner.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,19 @@ bool tree_sitter_dtd_external_scanner_scan(void *payload, TSLexer *lexer, const

if (valid_symbols[PI_CONTENT]) return scan_pi_content(lexer);

if (valid_symbols[COMMENT]) return scan_comment(lexer, false);
if (valid_symbols[COMMENT]) {
advance_if_not(lexer, '<');
advance_if_not(lexer, '!');
return scan_comment(lexer);
}

return false;
}

SCANNER_BOILERPLATE(dtd)
void *tree_sitter_dtd_external_scanner_create() { return NULL; }

void tree_sitter_dtd_external_scanner_destroy(void *payload) {}

unsigned tree_sitter_dtd_external_scanner_serialize(void *payload, char *buffer) { return 0; }

void tree_sitter_dtd_external_scanner_deserialize(void *payload, const char *buffer, unsigned length) {}
16 changes: 5 additions & 11 deletions dtd/src/tree_sitter/parser.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions xml/grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ module.exports = grammar(DTD, {
$._end_tag_name,
$._erroneous_end_name,
'/>',
$._implicit_end_tag,
],

inline: $ => [
Expand Down Expand Up @@ -131,9 +130,9 @@ module.exports = grammar(DTD, {

ETag: $ => seq('</', alias($._end_tag_name, $.Name), O($._S), '>'),

ErroneousETag: $ => seq(
_ErroneousETag: $ => seq(
'</',
alias($._erroneous_end_name, $.ErroneousName),
$._erroneous_end_name,
O($._S),
'>',
),
Expand Down
16 changes: 4 additions & 12 deletions xml/src/grammar.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions xml/src/node-types.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 58c4722

Please sign in to comment.