Open zeertzjq opened 2 years ago
Could you provide a minimal source code example as plain text?
return function()
local a = [=[]]=]
local b = [=[]=]
return a, b
end
The reason for this is probably that the parsing for [[ ]]
[= =]
is mixed so =]
can close [[
if (lexer->lookahead == '[' || lexer->lookahead == '=') {
// further down
if (lexer->lookahead == ']' || lexer->lookahead == '=') {
It's probably good to start with #6 which already cleaned up the parser code.
We could also switch to https://github.com/MunifTanjim/tree-sitter-lua. It has the string start/end as separated nodes, which makes it easier for injections :)
Looks like the project took some inspiration from the original repo that was forked.
@MunifTanjim what's the status of your parser? I think it's more complete than this one :D
And it doesn't have this issue
return function()
local a = [=[]]=]
local b = [=[]=]
return a, b
end
is parsed as
(chunk [0, 0] - [5, 0]
(return_statement [0, 0] - [4, 3]
(function_definition [0, 7] - [4, 3]
parameters: (parameters [0, 15] - [0, 17])
body: (block [1, 2] - [3, 13]
local_declaration: (variable_declaration [1, 2] - [1, 19]
(assignment_statement [1, 8] - [1, 19]
(variable_list [1, 8] - [1, 9]
name: (identifier [1, 8] - [1, 9]))
(expression_list [1, 12] - [1, 19]
value: (string [1, 12] - [1, 19]))))
local_declaration: (variable_declaration [2, 2] - [2, 18]
(assignment_statement [2, 8] - [2, 18]
(variable_list [2, 8] - [2, 9]
name: (identifier [2, 8] - [2, 9]))
(expression_list [2, 12] - [2, 18]
value: (string [2, 12] - [2, 18]))))
(return_statement [3, 2] - [3, 13]
(identifier [3, 9] - [3, 10])
(identifier [3, 12] - [3, 13]))))))
@MunifTanjim what's the status of your parser?
It's complete as far as I know. It has corpus tests for all the possbile cases and can parse the whole luvit/luvit
repo without any errors.
I've been using it since August 2021 using this https://github.com/MunifTanjim/nvim-treesitter-lua/pull/2 . Haven't face any issues in my daily usage yet.
In case you wanna try it, the queries are available in this repo: https://github.com/MunifTanjim/nvim-treesitter-lua
The only reason I haven't shared it anywhere yet is because it's not easily usable without building neovim
yourself from this branch https://github.com/neovim/neovim/pull/15260 (it's necessary to ignore the queries for lua parser that comes with nvim-treesitter
).
That sounds great! Any thoughts about switching to that parser? @theHamsta @vigoux
Describe the bug
Lua parser fails to find ending of string enclosed by level 1 Lua long brackets if the last character of the string is a square bracket.
To Reproduce
Expected behavior
Lines 35 to 874 are highlighted correctly.
Output of
:checkhealth nvim-treesitter
Output of
nvim --version
Additional context
Screenshot: