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

Fix Lua keywords #9

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

E-Fir
Copy link

@E-Fir E-Fir commented Nov 7, 2022

Problem: Lua keywords don't have recognized properly. They are treated as identifiers.
Example:
Source to parse:

if true and not false or nil then
  repeat
    break
  until true
elseif 1 then
  local a = 1
else
  for k, v in pairs(_G) do
    local f = function()  end
  end
end

while true do end

return 1

Parsing:

for kind, text in lxsh.lexers.lua.gmatch(source) do
  if kind ~= 'whitespace' then
    print(kind, text)
  end
end

Result:

keyword if
constant true
operator and
operator not
constant false
operator or
constant nil
identifier then
identifier repeat
identifier break
identifier until
constant true
identifier elseif
number 1
identifier then
identifier local
identifier a
operator =
number 1
identifier else
identifier for
identifier k
operator ,
identifier v
identifier in
identifier pairs
operator (
identifier _G
operator )
identifier do
identifier local
identifier f
operator =
identifier function
operator (
operator )
identifier end
identifier end
identifier end
identifier while
constant true
identifier do
identifier end
identifier return
number 1

Only the first if is recognized properly.

Solution: fix the keyword pattern.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant