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

lexer.cpp doesn't recognize #define without trailing newline #450

Open
dargueta opened this issue Apr 6, 2023 · 2 comments
Open

lexer.cpp doesn't recognize #define without trailing newline #450

dargueta opened this issue Apr 6, 2023 · 2 comments

Comments

@dargueta
Copy link
Contributor

dargueta commented Apr 6, 2023

Preprocessor statements, at least #define, must have a trailing newline to be recognized.

No trailing newline means it gets expanded into separate tokens:

> s = "#define ASDF"
> for t, v in lexer.cpp(s) do  print(t .. " -> " .. tostring(v))  end
# -> #
iden -> define
iden -> ASDF

With a newline, it's recognized as a preprocessor statement.

> s = "#define ASDF\n"
> for t, v in lexer.cpp(s) do  print(t .. " -> " .. tostring(v))  end
prepro -> #define ASDF

Ideally the behavior would be consistent for both cases. I need to be able to process third-party headers that may or may not end in a newline.

Environment:

  • OS: Ubuntu 22.04
  • Lua: 5.4.4
  • Penlight: 1.13.1
@dargueta
Copy link
Contributor Author

This is still happening on Penlight 1.14.0:

  • OS: Ubuntu 23.10
  • Lua: 5.4.6
  • Penlight: 1.14.0

@alerque
Copy link
Member

alerque commented May 14, 2024

Contributions welcome. ;-)

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

No branches or pull requests

2 participants