Skip to content

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

Open
@dargueta

Description

@dargueta

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions