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 incorrect keyword lexing #122

Merged
merged 1 commit into from
Jan 4, 2022
Merged

Fix incorrect keyword lexing #122

merged 1 commit into from
Jan 4, 2022

Conversation

schneems
Copy link
Collaborator

@schneems schneems commented Jan 4, 2022

For some weird reason this line is detected as a keyword line:

            type: :module,

Though it clearly isn't. Ripper:

require 'ripper'

pp Ripper.lex(<<~'EOM')
  {
    type: :module,
  }
EOM

Produces:

[[[1, 0], :on_lbrace, "{", BEG|LABEL],
 [[1, 1], :on_ignored_nl, "\n", BEG|LABEL],
 [[2, 0], :on_sp, "  ", BEG|LABEL],
 [[2, 2], :on_label, "type:", ARG|LABELED],
 [[2, 7], :on_sp, " ", ARG|LABELED],
 [[2, 8], :on_symbeg, ":", FNAME],
 [[2, 9], :on_kw, "module", ENDFN],
 [[2, 15], :on_comma, ",", BEG|LABEL],
 [[2, 16], :on_ignored_nl, "\n", BEG|LABEL],
 [[3, 0], :on_rbrace, "}", END],
 [[3, 1], :on_nl, "\n", BEG],
 [[4, 0], :on_const, "EOM", CMDARG]]

This is the problem line:

 [[2, 9], :on_kw, "module", ENDFN],

Digging into the IRB source code they handled this case here ruby/ruby@776759e. Based on the description I believe this may be a bug in the lexer, but I'm not sure how to validate it.

For some weird reason this line is detected as a keyword line:

```
            type: :module,
```

Though it clearly isn't. Ripper:

```
require 'ripper'

pp Ripper.lex(<<~'EOM')
  {
    type: :module,
  }
EOM
```

Produces:

```
[[[1, 0], :on_lbrace, "{", BEG|LABEL],
 [[1, 1], :on_ignored_nl, "\n", BEG|LABEL],
 [[2, 0], :on_sp, "  ", BEG|LABEL],
 [[2, 2], :on_label, "type:", ARG|LABELED],
 [[2, 7], :on_sp, " ", ARG|LABELED],
 [[2, 8], :on_symbeg, ":", FNAME],
 [[2, 9], :on_kw, "module", ENDFN],
 [[2, 15], :on_comma, ",", BEG|LABEL],
 [[2, 16], :on_ignored_nl, "\n", BEG|LABEL],
 [[3, 0], :on_rbrace, "}", END],
 [[3, 1], :on_nl, "\n", BEG],
 [[4, 0], :on_const, "EOM", CMDARG]]
```

This is the problem line:

```
 [[2, 9], :on_kw, "module", ENDFN],
```

Digging into the IRB source code they handled this case here ruby/ruby@776759e. Based on the description I believe this may be a bug in the lexer, but I'm not sure how to validate it.
@schneems schneems marked this pull request as ready for review January 4, 2022 22:30
@schneems schneems merged commit 10232e4 into main Jan 4, 2022
@schneems schneems deleted the schneems/keyword-wat-fix branch January 4, 2022 22:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant