Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Locations of long string literals #36

Closed
paulcuth opened this issue Sep 26, 2016 · 1 comment
Closed

Locations of long string literals #36

paulcuth opened this issue Sep 26, 2016 · 1 comment
Labels
incorrect parsing Valid Lua code fails to parse, is parsed incorrectly, or invalid Lua code is accepted

Comments

@paulcuth
Copy link

Hi,

Thanks for the great library, I've depended on this a few times and it has always worked superbly well.

However, I've come across an issue in the locations with long string literals. It seems that when the input expression spans many lines, the resulting column value for that expression is negative. For example:

const parser = require('luaparse');
const lua = 'local a = [[hello\nworld]]';
const ast = parser.parse(lua, { locations: true });

console.log(JSON.stringify(ast));

Results in:

{"type":"Chunk","body":[{"type":"LocalStatement","variables":[{"type":"Identifier","name":"a","loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":7}}}],"init":[{"type":"StringLiteral","value":"hello\nworld","raw":"[[hello\nworld]]","loc":{"start":{"line":2,"column":-8},"end":{"line":2,"column":7}}}],"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":7}}}],"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":7}},"comments":[]}

Note the "column":-8 in the middle.

I'll look into this sometime this week and open a PR if I can. However, if a possible cause pops into your head or you can give me any pointers in the meantime, that'd be great.

Cheers.

@fstirlitz
Copy link
Owner

Fixed in 4b56017.

@fstirlitz fstirlitz added the incorrect parsing Valid Lua code fails to parse, is parsed incorrectly, or invalid Lua code is accepted label Aug 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
incorrect parsing Valid Lua code fails to parse, is parsed incorrectly, or invalid Lua code is accepted
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants