Skip to content

Commit

Permalink
fix(xml): don't advance after char data end
Browse files Browse the repository at this point in the history
  • Loading branch information
ObserverOfTime committed Jun 30, 2024
1 parent 648183d commit 809266e
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "tree-sitter-xml"
description = "XML & DTD grammars for tree-sitter"
version = "0.6.3"
version = "0.6.4"
license = "MIT"
readme = "README.md"
keywords = ["incremental", "parsing", "tree-sitter", "dtd", "xml"]
Expand Down
2 changes: 1 addition & 1 deletion common/common.mak
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION := 0.6.3
VERSION := 0.6.4

# repository
SRC_DIR := src
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tree-sitter-grammars/tree-sitter-xml",
"version": "0.6.3",
"version": "0.6.4",
"license": "MIT",
"description": "XML & DTD grammars for tree-sitter",
"repository": "tree-sitter-grammars/tree-sitter-xml",
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "tree-sitter-xml"
description = "XML & DTD grammars for tree-sitter"
version = "0.6.3"
version = "0.6.4"
keywords = ["incremental", "parsing", "tree-sitter", "xml"]
classifiers = [
"Intended Audience :: Developers",
Expand Down
19 changes: 19 additions & 0 deletions test/corpus/issues.txt
Original file line number Diff line number Diff line change
Expand Up @@ -283,3 +283,22 @@ Parameter-entity references (#10)
(DefaultDecl))
(PEReference
(Name))))

================================================================================
Closing bracket in CharData (#22)

:language(xml)
================================================================================

<test>]</test>

--------------------------------------------------------------------------------

(document
(element
(STag
(Name))
(content
(CharData))
(ETag
(Name))))
11 changes: 9 additions & 2 deletions xml/src/scanner.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,16 @@ static inline bool in_error_recovery(const bool *valid_symbols) {
valid_symbols[CHAR_DATA] && valid_symbols[CDATA];
}

/// Check if the lexer is in a char data node
static inline bool in_char_data(TSLexer *lexer) {
return !lexer->eof(lexer) && lexer->lookahead != '<' && lexer->lookahead != '&';
}

/// Scan for a CharData node
static bool scan_char_data(TSLexer *lexer) {
bool advanced_once = false;

while (!lexer->eof(lexer) && lexer->lookahead != '<' && lexer->lookahead != '&') {
while (in_char_data(lexer)) {
if (lexer->lookahead == ']') {
lexer->mark_end(lexer);
advance(lexer);
Expand All @@ -92,7 +97,9 @@ static bool scan_char_data(TSLexer *lexer) {
}
}
advanced_once = true;
advance(lexer);
if (in_char_data(lexer)) {
advance(lexer);
}
}

if (advanced_once) {
Expand Down

0 comments on commit 809266e

Please sign in to comment.