I am trying to make a parser for these tokens. I find it intuitive to consider the entire text a "document," and the body of the if statement to be a document in its own right. The concrete syntax tree should resemble this pseudocode: doc(if(expression(product.type == "Shirt" or product.type == "Shoes"), doc("This is a shirt or a pair of shoes."))).
Looking at the JSON examples in this repository, it seems to be that recursive parsing should be possible (I can see object -> objectItem -> value -> object). When I run my parser, however, I get the following:
NoViableAltException: Expecting: one of these possible Token sequences:
1. [Text]
2. [TagStart, ControlIf]
but found: '{%'
It seems to me like chevrotain is getting into the sub document (the body of the if statement), and then not exiting back up to consume the TagStart, ControlEndIf, and TagEnd tokens for the controlIf rule.
I've tried making a sub document rule, but it doesn't work and even if it did I think I would have to create as many sub document rules as levels of nesting I plan to support.
Am I doing something wrong? Are there any tips or tricks I can use to debug or fix this?
EDIT: It's probably worth noting that I'm calling the doc method on the parser and passing in the aforementioned tokens.
Continuing #2017: I'm working on a parser for liquid templates. Given the following template:
I get the following tokens:
I am trying to make a parser for these tokens. I find it intuitive to consider the entire text a "document," and the body of the
if
statement to be a document in its own right. The concrete syntax tree should resemble this pseudocode:doc(if(expression(product.type == "Shirt" or product.type == "Shoes"), doc("This is a shirt or a pair of shoes.")))
.So far I've put the following together:
Looking at the JSON examples in this repository, it seems to be that recursive parsing should be possible (I can see
object -> objectItem -> value -> object
). When I run my parser, however, I get the following:It seems to me like chevrotain is getting into the sub document (the body of the if statement), and then not exiting back up to consume the
TagStart
,ControlEndIf
, andTagEnd
tokens for thecontrolIf
rule.I've tried making a sub document rule, but it doesn't work and even if it did I think I would have to create as many sub document rules as levels of nesting I plan to support.
Am I doing something wrong? Are there any tips or tricks I can use to debug or fix this?
EDIT: It's probably worth noting that I'm calling the
doc
method on the parser and passing in the aforementioned tokens.