teal-language / teal-playground

teal-language/tl playground
https://teal-playground.netlify.app/
19 stars 1 forks source link

Brackets [ ] cause a JavaScript error? #3

Closed pdesaulniers closed 4 years ago

pdesaulniers commented 4 years ago

If I type brackets [ ] into the editor, I get a JavaScript error in the inspector console:

SyntaxError: "[string "?"]:7: ')' expected near ']'"
    D fengari-web.bundle.js:8
    handler Playground.vue:87
    VueJS 4
        run
        $n
        pt
        lt
Playground.vue:106:18
darrenjennings commented 4 years ago

Yea there's an issue with brackets because of how the string is passed to tl.gen

https://github.com/teal-language/teal-playground/blob/e1cecd5d4f5e3b63fe2d38f0b1340118b89f30a9/src/components/Playground.vue#L87

where %input% is replaced with whatever you type. so t.gen([[print([[hey]])]]) needs to be escaped?

I tried

const fengariInput = tl.replace('%input%', newValue.replace(/\[/g, '%[').replace(/\]/g, '%]'))
const out: LuaTableJs = fengari.load(fengariInput)()

But getting tl syntax errors.