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

Strange restriction on newlines in macro definitions #560

Open
dscorbett opened this issue Apr 3, 2019 · 2 comments
Open

Strange restriction on newlines in macro definitions #560

dscorbett opened this issue Apr 3, 2019 · 2 comments
Assignees
Labels
enhancement Feature requests

Comments

@dscorbett
Copy link

A newline is only allowed after the equals sign in a macro definition if the next token is not an identifier. I find this unintuitive.

$ cat <<EOF >test1.flex
%%
x =
    "x"
%%
{x} {}
EOF
$ cat <<EOF >test2.flex
%%
x0 = x
x =
    {x0}
%%
{x} {}
EOF
$ cat <<EOF >test3.flex
%%
x =
    x
%%
{x} {}
EOF
$ jflex -q test1.flex
$ jflex -q test2.flex
$ jflex -q test3.flex

Error in file "test3.flex" (line 2): 
Syntax error.
x =
   ^

Error in file "test3.flex" (line 5): 
Macro has not been declared.
{x} {}
^
2 errors, 0 warnings.
@lsf37
Copy link
Member

lsf37 commented Dec 6, 2019

Sorry, for some reason I only saw this one now.

The reason for this restriction is that an identifier can be the start of the next macro definition, but non-identifiers can't be. You'd have to look ahead several tokens to figure out what it is (x happens to be only one token here, but if it was abcd, these would be 4 tokens for a regexp, but only 1 token if it was the left-hand side of a macro definition, i.e. the lexer has to make this decision, it's too late in the parser).

With the more flexible lookahead expressions JFlex has now (this was all written long before that), it might be possible to do that these days, but it would at least require a deeper investigation.

@lsf37 lsf37 added the enhancement Feature requests label Dec 6, 2019
@lsf37
Copy link
Member

lsf37 commented Dec 6, 2019

I'll keep this open until I've figure out how hard it would be to lift the restriction, i.e. whether it can be done with reasonable effort.

@lsf37 lsf37 self-assigned this Dec 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature requests
Projects
None yet
Development

No branches or pull requests

2 participants