[ruby/prism] Fix .. and ... to be non-associative

(https://github.com/ruby/prism/pull/1837)

Fix https://github.com/ruby/prism/pull/1829

90b0b1974c

Co-authored-by: Kevin Newton <kddnewton@gmail.com>
This commit is contained in:
Hiroya Fujinami 2023-11-22 02:03:29 +09:00 committed by git
parent 0aafd040c3
commit ad25313ca8
2 changed files with 12 additions and 6 deletions

View file

@ -10141,10 +10141,8 @@ typedef struct {
bool binary; bool binary;
/** /**
* Whether or not this token can be used as non associative binary operator. * Whether or not this token can be used as non-associative binary operator.
* Usually, non associative operator can be handled by using the above left * Non-associative operators (e.g. in and =>) need special treatment in parse_expression.
* and right binding powers, but some operators (e.g. in and =>) need special
* treatment since they do not call parse_expression recursively.
*/ */
bool nonassoc; bool nonassoc;
} pm_binding_powers_t; } pm_binding_powers_t;
@ -10193,8 +10191,8 @@ pm_binding_powers_t pm_binding_powers[PM_TOKEN_MAXIMUM] = {
[PM_TOKEN_QUESTION_MARK] = RIGHT_ASSOCIATIVE(PM_BINDING_POWER_TERNARY), [PM_TOKEN_QUESTION_MARK] = RIGHT_ASSOCIATIVE(PM_BINDING_POWER_TERNARY),
// .. ... // .. ...
[PM_TOKEN_DOT_DOT] = LEFT_ASSOCIATIVE(PM_BINDING_POWER_RANGE), [PM_TOKEN_DOT_DOT] = NON_ASSOCIATIVE(PM_BINDING_POWER_RANGE),
[PM_TOKEN_DOT_DOT_DOT] = LEFT_ASSOCIATIVE(PM_BINDING_POWER_RANGE), [PM_TOKEN_DOT_DOT_DOT] = NON_ASSOCIATIVE(PM_BINDING_POWER_RANGE),
// || // ||
[PM_TOKEN_PIPE_PIPE] = LEFT_ASSOCIATIVE(PM_BINDING_POWER_LOGICAL_OR), [PM_TOKEN_PIPE_PIPE] = LEFT_ASSOCIATIVE(PM_BINDING_POWER_LOGICAL_OR),

View file

@ -1708,6 +1708,14 @@ module Prism
] ]
end end
def test_non_assoc_range
source = '1....2'
assert_errors expression(source), source, [
['Expected a newline or semicolon after the statement', 4..4],
['Cannot parse the expression', 4..4],
]
end
def test_upcase_end_in_def def test_upcase_end_in_def
assert_warning_messages "def foo; END { }; end", [ assert_warning_messages "def foo; END { }; end", [
"END in method; use at_exit" "END in method; use at_exit"