-
It seems that the example XML parser does not take into account if a start and end tag have matching tag names. When running the spec with the below input text the parser treats it as syntactically correct. const inputText =
'<?xml version="1.0"?>\n' +
"<foo>\n" +
"</bar>" I want to fix this (check that the tag names match). I am a complete newbie using chevrotain, but from looking at the docs it seems look ahead parsing is not enough here as the content of that element is unknown. So I guess I have to use backtracking somehow, maybe together with a parameterized rule. But I don't see how to check this in the subrule then. Is there an example of how to accomplish something like that? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
@medihack The XML Parser extends CSTParser, so it includes all the parsed tokens in the output and a check whether start and end tags match could be implemented as a second pass. If you want to check immediately, you could assign the two consumed if (openName.image !== closeName.image) throw new Error("unexpected closing tag") |
Beta Was this translation helpful? Give feedback.
-
Hi @medihack As a generalization of what @NaridaL wrote above: For example have a look at an XML Language Service:
|
Beta Was this translation helpful? Give feedback.
@medihack The XML Parser extends CSTParser, so it includes all the parsed tokens in the output and a check whether start and end tags match could be implemented as a second pass.
If you want to check immediately, you could assign the two consumed
Name
tokens to variables and then check if they match.