Closed FranciscoG closed 3 years ago
think i figured it out
Main -> answers {% id %}
answers -> answerText ("~" answerText {% d => d[1] %}):* {% flatten %}
answerText
-> answerChar {% id %}
| answerChar answerText {% d => d[0] + d[1] %}
answerChar
-> [^\~\\] {% id %}
| "\\" escape {% d => d[0] + d[1] %}
escape
-> "~"
| "\\" {% () => "\\" %}
| "#" {% () => "#" %}
@{%
const flatten = d => {
return d.reduce(
(a, b) => {
return a.concat(b);
},
[]
);
};
%}
test\~next~blablabla~last\~test
Testing it out in this playground I am seeing this
["test\~next", "blablabla", "last\~test"]
This video really helped me out: https://www.youtube.com/watch?v=a2mZTBI1ZxU&t=620s
I need to run it through a few more test cases but I'm pretty this is it.
Given one string like this
I would like the parser to match groups of text that are separated by a
~
but ignore escaped tildes\~
Here's what I want my result to look like
I've tried doing this with a regex using a negative lookbehind but that is not 100% supported yet in Safari and I need to support Safari unfortunately so I am hoping to figure out a way to do this using Nearley's grammar