harttle/liquidjs

All end/begin positions of IdentifierTokens start at 0 inside IfTag

blidblid opened this issue · 1 comments

I am trying to build a Liquid code editor using liquidjs.

When creating an AST of this code

{% if customer.name == "kevin" %}
  Hey Kevin!
{% elsif customer.name == "anonymous" %}
  Hey Anonymous!
{% else %}
  Hi Stranger!
{% endif %}

All identifier tokens inside branches[0].value.initial.postfix[0] begin at index 0. It seems all tokens inside IfTag have indexes in relation to the IfTag itself. Is this by design? If so, is there any way to use the AST to find the position of child tokens inside IfTag in relation to the whole input text?

The parsed templates returned by .parse() cannot be serialized back to liquid template, that means it's not a AST can be used for code editors.

I'm still not sure should we provide parser inside LiquidJS project. But https://codemirror.net/ supports Liquid language and there's a liquid parser implemented in BNF style: https://github.com/codemirror/lang-liquid