parse.y: fix state after ivar/cvar
* parse.y (parse_atmark): return EXPR_END or EXPR_ENDFN, depending on the previous state, even incomplete names consistently.
This commit is contained in:
parent
83e905eb4e
commit
1da5c73932
5
parse.y
5
parse.y
@ -8396,6 +8396,7 @@ parse_atmark(struct parser_params *p, const enum lex_state_e last_state)
|
|||||||
tokadd(p, '@');
|
tokadd(p, '@');
|
||||||
c = nextc(p);
|
c = nextc(p);
|
||||||
}
|
}
|
||||||
|
SET_LEX_STATE(IS_lex_state_for(last_state, EXPR_FNAME) ? EXPR_ENDFN : EXPR_END);
|
||||||
if (c == -1 || !parser_is_identchar(p)) {
|
if (c == -1 || !parser_is_identchar(p)) {
|
||||||
pushback(p, c);
|
pushback(p, c);
|
||||||
RUBY_SET_YYLLOC(loc);
|
RUBY_SET_YYLLOC(loc);
|
||||||
@ -8407,6 +8408,7 @@ parse_atmark(struct parser_params *p, const enum lex_state_e last_state)
|
|||||||
}
|
}
|
||||||
parser_show_error_line(p, &loc);
|
parser_show_error_line(p, &loc);
|
||||||
set_yylval_noname();
|
set_yylval_noname();
|
||||||
|
SET_LEX_STATE(EXPR_END);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
else if (ISDIGIT(c)) {
|
else if (ISDIGIT(c)) {
|
||||||
@ -8417,7 +8419,7 @@ parse_atmark(struct parser_params *p, const enum lex_state_e last_state)
|
|||||||
p->lex.pcur = ptr + len;
|
p->lex.pcur = ptr + len;
|
||||||
RUBY_SET_YYLLOC(loc);
|
RUBY_SET_YYLLOC(loc);
|
||||||
if (result == tIVAR) {
|
if (result == tIVAR) {
|
||||||
if (IS_lex_state(EXPR_FNAME)) {
|
if (IS_lex_state_for(last_state, EXPR_FNAME)) {
|
||||||
compile_error(p, "`@%c' is not allowed as an instance variable name", c);
|
compile_error(p, "`@%c' is not allowed as an instance variable name", c);
|
||||||
}
|
}
|
||||||
else if (ptr[0] == '0') {
|
else if (ptr[0] == '0') {
|
||||||
@ -8439,7 +8441,6 @@ parse_atmark(struct parser_params *p, const enum lex_state_e last_state)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (tokadd_ident(p, c)) return 0;
|
if (tokadd_ident(p, c)) return 0;
|
||||||
SET_LEX_STATE(EXPR_END);
|
|
||||||
tokenize_ident(p, last_state);
|
tokenize_ident(p, last_state);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -95,4 +95,22 @@ class TestRipper::Lexer < Test::Unit::TestCase
|
|||||||
assert_equal "string\#{nil}\n",
|
assert_equal "string\#{nil}\n",
|
||||||
Ripper.slice(%(<<HERE\nstring\#{nil}\nHERE), "heredoc_beg .*? nl $(.*?) heredoc_end", 1)
|
Ripper.slice(%(<<HERE\nstring\#{nil}\nHERE), "heredoc_beg .*? nl $(.*?) heredoc_end", 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def state(name)
|
||||||
|
Ripper::Lexer::State.new(Ripper.const_get(name))
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_state_after_ivar
|
||||||
|
assert_equal [[1,0],:on_ivar,"@a",state(:EXPR_END)], Ripper.lex("@a").last
|
||||||
|
assert_equal [[1,1],:on_ivar,"@a",state(:EXPR_ENDFN)], Ripper.lex(":@a").last
|
||||||
|
assert_equal [[1,0],:on_ivar,"@1",state(:EXPR_END)], Ripper.lex("@1").last
|
||||||
|
assert_equal [[1,1],:on_ivar,"@1",state(:EXPR_ENDFN)], Ripper.lex(":@1").last
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_state_after_cvar
|
||||||
|
assert_equal [[1,0],:on_cvar,"@@a",state(:EXPR_END)], Ripper.lex("@@a").last
|
||||||
|
assert_equal [[1,1],:on_cvar,"@@a",state(:EXPR_ENDFN)], Ripper.lex(":@@a").last
|
||||||
|
assert_equal [[1,0],:on_cvar,"@@1",state(:EXPR_END)], Ripper.lex("@@1").last
|
||||||
|
assert_equal [[1,1],:on_cvar,"@@1",state(:EXPR_ENDFN)], Ripper.lex(":@@1").last
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user