Skip to content

Option to allow Commas in Parse Parameters Tokenizer #724

Answered by harttle
zachleat asked this question in Q&A
Discussion options

You must be logged in to vote

.peek(). .advance() can be used for such cases. Feel free to open another issue if this doesn't resolve the problem. I guess it hangs because .readValue() keep returns null and the while loop won't exit. The following snippet resolves the issue.

const { Liquid, Tokenizer, evalToken } = require('liquidjs')
const liquid = new Liquid()

liquid.registerTag('random', {
  parse(tagToken) {
    const tokenizer = new Tokenizer(tagToken.args)
    this.items = []
    let value
    while (value = tokenizer.readValue()) {
      this.items.push(value)
      tokenizer.skipBlank()
      while (tokenizer.peek() === ',') tokenizer.advance()
    }
    assert(tokenizer.end(), 'invalid chars')
  },
  * render(

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@zachleat
Comment options

Answer selected by zachleat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
2 participants
Converted from issue

This discussion was converted from issue #722 on July 21, 2024 16:32.