Open mingodad opened 3 years ago
About escaping single character strings there is an (let's call it) ambiguity between Javascript/EBNF* for example the backslash need be escaped in Javascript '\\'
but doesn't in the EBNF accepted by https://www.bottlecaps.de/rr/ui '\'
, and probably others like it.
I reworked the lua script so that hopefully it doesn't emit warnings anymore with lua2ljs. I tried lua2ljs myself and it didn't emit any warnings with the old code or the new code so I'm not completely sure if it fixed the problem. Let me know if you still see shadows or duplicate definitions.
I forgot to mention that I also did a change to Lua 5.3.5 with the warnings here https://github.com/mingodad/lua-5.3.5-shadow-warnings , lua2ljs
do not issue any warnings, the ljs
interpreter does it on the converted files that match the original line numbers in Lua
.
There is still this shadow variables:
@@ -934,13 +934,13 @@ for _, v in ipairs(tokens) do
for line in parsed:gmatch("([^\n]*)") do table.insert(tree_sitter_body, line) end
if #tree_sitter_body == 1 then
table.insert(def, table.remove(tree_sitter_body))
else
local indent = def[1]:gsub(".", " ")
- for i, v in ipairs(tree_sitter_body) do
- local indent = i > 1 and indent or ""
- table.insert(def, indent .. v)
+ for i, v2 in ipairs(tree_sitter_body) do
+ local indent2 = i > 1 and indent or ""
+ table.insert(def, indent2 .. v2)
if i < #tree_sitter_body then table.insert(def, "\n") end
end
end
local full_body, start_line, end_line = unpack(tokenmap[id])
local line_num = start_line .. ((start_line == end_line and "") or ("-" .. end_line))
Cool. Thanks! I changed the shadowed variable names.
Do the changes you made to the js script fix it for most or all of the test grammars you tried?
It solves some small problems but not most of then you can see the output on the wary zip file attached here https://github.com/eatkins/tree-sitter-ebnf-generator/issues/3.
It seems that the nodejs version to run
tree-sitter-to-ebnf.js
is 15.* and also the argument to it in the readme seems to be wrong. For the Lua script I usually test Lua with https://github.com/mingodad/ljs usinglua2ljs
and it points out redeclarations/shadowing variables.