Comments (6)
@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.
Can you please check whether this issue persists after latest changes?
from lua-parser.
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.
@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.
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.
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)
- can't parse goto HOT 4
- Problem may in lua-parser/parser.lua:binaryOp HOT 7
- help HOT 2
- "attempt to get length of a number value (local 'sfail')" when parsing wrong syntax HOT 2
- parsing error are not properly reported HOT 5
- All tests pass, but fail sometimes ! HOT 2
- [Proposal] Unify tags 'True' and 'False' into 'Boolean' HOT 4
- <= and >= are scanned as the same token HOT 2
- Optional code context linked with ast node HOT 3
- How to generate lua code according to astοΌ HOT 15
- Problem in pp.dump HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lua-parser.