Skip to content

Commit

Permalink
Fix parsing keyword args starting with plus and minus
Browse files Browse the repository at this point in the history
  • Loading branch information
haldun committed Sep 28, 2023
1 parent 62469a5 commit 95913a4
Show file tree
Hide file tree
Showing 3 changed files with 158 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/prism.c
Original file line number Diff line number Diff line change
Expand Up @@ -6912,7 +6912,7 @@ parser_lex(pm_parser_t *parser) {
);
}

if (lex_state_beg_p(parser) || spcarg) {
if (lex_state_beg_p(parser) || spcarg || parser->in_keyword_arg) {
lex_state_set(parser, PM_LEX_STATE_BEG);

if (pm_char_is_decimal_digit(peek(parser))) {
Expand Down Expand Up @@ -6961,7 +6961,7 @@ parser_lex(pm_parser_t *parser) {
);
}

if (lex_state_beg_p(parser) || spcarg) {
if (lex_state_beg_p(parser) || spcarg || parser->in_keyword_arg) {
lex_state_set(parser, PM_LEX_STATE_BEG);
LEX(pm_char_is_decimal_digit(peek(parser)) ? PM_TOKEN_UMINUS_NUM : PM_TOKEN_UMINUS);
}
Expand Down
6 changes: 6 additions & 0 deletions test/prism/fixtures/methods.txt
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,9 @@ end

foo = 1
def foo.bar; end

def f x:-a; end

def f x:+a; end

def f x:!a; end
165 changes: 150 additions & 15 deletions test/prism/snapshots/methods.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 95913a4

Please sign in to comment.