Closed pragdave closed 3 years ago
Interesting, thanks for reporting. Seems like it's related to this: https://v8.dev/features/subsume-json.
I am curious why there is a difference between JS and TS here. Can you let me know which version of TypeScript you're using? It seems to work for me under 4.4.3:
[ohm-scratch] cat jq.ohm
JQ {
lineTerminator
= "\n" | "\r" | "\u2028" | "\u2029"
}
[ohm-scratch] npx ohm generateRecipes jq.ohm && npx ts-node jq.ohm-recipe.js
jq.ohm-recipe.js
[ohm-scratch] grep typescript package.json
"typescript": "^4.4.3"
A possible fix would be to modify Terminal.outputRecipe
so that it always emits the escaped version of those characters.
Hmm, here was my first attempt at a fix: https://github.com/harc/ohm/compare/issue-322?expand=1 but it seems it's a bit more complicated than I thought. Will try to tackle it tomorrow.
Thanks @pragdave for taking the new stuff for a spin!
I am curious why there is a difference between JS and TS here. Can you let me know which version of TypeScript you're using? It seems to work for me under 4.4.3
{ "name": "my-jq", "version": "1.0.0", "main": "cli.js", "license": "MIT", "devDependencies": { ***@***.***/cli": "^0.1.0", ***@***.***/jest": "^27.0.1", ***@***.***/node": "^16.9.1", "fast-glob": "^3.2.7", "jest": "^27.0.6", "ts-jest": "^27.0.4", "ts-node": "^10.2.1", "typescript": "^4.4.3" }, "dependencies": { "ohm-js": "^16.0.0-pre.2" }, "scripts": { "test": "jest", "testw": "jest --watch" } }
Ok, turns out it was simpler than I thought — I was totally overthinking it, due to the multiple levels of escaping.
Thanks again for the bug report!
The following source
Generates a recipe file that compiles fine under node, but fails to compile with ts-node. If I remove the two Unicode escapes, it compiles fine under both.