Giter Site home page Giter Site logo

Comments (6)

lezgomatt avatar lezgomatt commented on June 27, 2024 1

@andremm It took a while, but I've figured it out. There is no bug πŸ˜„

For bug1.lua, $ lua t.lua "x = '\\'" fails because the shell escapes characters on double quoted strings, turning the two backslashes into just a single backslash when passed to Lua.

$ echo '\\'
> \\
$ echo "\\"
> \

Similarly, for bug2.lua, the characters are being escaped, but this time by Lua. So again, there is only one backslash which is followed by the quote, making the string unclosed just as the error reports. If we change the \\ into \\\\, or use long strings instead, no error will be reported.

This bug was definitely confusing, but I think we can mark it as resolved now πŸ˜„

from lua-parser.

andremm avatar andremm commented on June 27, 2024

Can you please check whether this issue persists after latest changes?

from lua-parser.

andremm avatar andremm commented on June 27, 2024

After latest changes, this bug still persists.
In fact, now even the following correct program does not parse:

x = "\\"

Parsing this program throws the following error message:

bug.lua:1:7: syntax error, unclosed string

@undecidabot, do you have any thoughts on this?

from lua-parser.

lezgomatt avatar lezgomatt commented on June 27, 2024

@andremm Hm, I can't seem to reproduce this bug (on latest commit of master). I'm pretty sure this case is already handled by https://github.com/andremm/lua-parser/blob/master/lua-parser/parser.lua#L415.

I could reproduce the exact error message if there's only one backslash as in

x = "\"

but that wouldn't be a bug then. Are any of the other escape characters also having this issue?

from lua-parser.

andremm avatar andremm commented on June 27, 2024

Are any of the other escape characters also having this issue?

@undecidabot, this bug is a bit tricky. :)
And yes, I noticed it with other escape characters (I'm using Lua 5.3.3).

For instance, using the following test file (which I will call bug1.lua):

local parser = require "lua-parser.parser"
local pp = require "lua-parser.pp"

if #arg ~= 1 then
    print("Usage: parse.lua <string>")
    os.exit(1)
end

local ast, error_msg = parser.parse(arg[1], "example.lua")
if not ast then
    print(error_msg)
    os.exit(1)
end

pp.print(ast)
os.exit(0)

Running $ lua bug1.lua 'x = "\\"' works, but running $ lua t.lua "x = '\\'" does not work.

As another example, using the following test file (which I will call bug2.lua):

local parser = require "lua-parser.parser"
local pp = require "lua-parser.pp"

local ast, error_msg = parser.parse('x = "\\"', "example.lua")
if not ast then
    print(error_msg)
else
    pp.print(ast)
end

local ast, error_msg = parser.parse("x = '\\'", "example.lua")
if not ast then
    print(error_msg)
else
    pp.print(ast)
end

os.exit(0)

Both examples don't work when running $ lua bug2.lua.

However, both examples should work, as we can see in the following Lua test:

Lua 5.3.3  Copyright (C) 1994-2016 Lua.org, PUC-Rio
> x = '\\'
> print(x)
\
> x = "\\"
> print(x)
\
>

from lua-parser.

andremm avatar andremm commented on June 27, 2024

This bug was definitely confusing, but I think we can mark it as resolved now πŸ˜„

You're right @undecidabot. I'm sorry I took too long to reply, but that's great that @bbblitz already closed the issue. Thanks for your feedback!

from lua-parser.

Related Issues (12)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.