eatkins / tree-sitter-ebnf-generator

Convert an EBNF grammar to the tree-sitter dsl
GNU General Public License v3.0
24 stars 2 forks source link

Some fixes to problems detected trying to use this project #2

Open mingodad opened 3 years ago

mingodad commented 3 years ago

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 using lua2ljs and it points out redeclarations/shadowing variables.

mingodad commented 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.

eatkins commented 3 years ago

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.

mingodad commented 3 years ago

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))
eatkins commented 3 years ago

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?

mingodad commented 3 years ago

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.