### re: Parser Combinators are Easy VIEW POST

Nice grammar you got there.
So... regular.
Would be a shame if something...

``````const ＨａｐｐｅｎｅｄＴｏＩｔ = input => {
const re = /\d+|\)\]\[\(|\]\[/g
const out = [[[]]]
let set = out
let point = set
let match
while ((match = re.exec(input))) {
const [m] = match
switch (m) {
case ")][(":
out.push((set = []))
case "][":
set.push((point = []))
continue
}
point.push(parseInt(m, 10))
}
return out
}
console.log(
JSON.stringify(
ＨａｐｐｅｎｅｄＴｏＩｔ(".:{([2 3]][[6 2]][[1 2])][([1 4]][[2 1])][([6 9])}:.")
)
)
``````

Point Guru wasn't so bonkers after all ;)

Perhaps a more interesting input would have been warranted

At least for paired tokens, I probably would have used a pushdown automata.

I only looked at the separators, not the paired wrappers.
Furthermore I didn't rely on the knowledge that the points are 2-dimensional.

You could say I have a stack of stacks of stacks :v

Points could just be space separated, the sepBy() combinator would address that restriction

`````` 2      number
3      number
][     new point
6      number
2      number
][     new point
1      number
2      number
)][(    new set
][     new point
1      number
4      number
][     new point
2      number
1      number
)][(    new set
][     new point
6      number
9      number
``````
code of conduct - report abuse  