mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
parse.y: parse_atmark
* parse.y (parse_atmark): extract from parser_yylex(). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46849 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
db155640b7
commit
27e1b24776
1 changed files with 29 additions and 17 deletions
46
parse.y
46
parse.y
|
@ -7460,6 +7460,32 @@ parse_gvar(struct parser_params *parser, const enum lex_state_e last_state)
|
|||
return -c;
|
||||
}
|
||||
|
||||
static int
|
||||
parse_atmark(struct parser_params *parser, const enum lex_state_e last_state)
|
||||
{
|
||||
int result = tIVAR;
|
||||
register int c = nextc();
|
||||
|
||||
newtok();
|
||||
tokadd('@');
|
||||
if (c == '@') {
|
||||
result = tCVAR;
|
||||
tokadd('@');
|
||||
c = nextc();
|
||||
}
|
||||
if (c != -1 && (ISDIGIT(c) || !parser_is_identchar())) {
|
||||
pushback(c);
|
||||
if (tokidx == 1) {
|
||||
compile_error(PARSER_ARG "`@%c' is not allowed as an instance variable name", c);
|
||||
}
|
||||
else {
|
||||
compile_error(PARSER_ARG "`@@%c' is not allowed as a class variable name", c);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return -c;
|
||||
}
|
||||
|
||||
static int
|
||||
parse_ident(struct parser_params *parser, int c, int cmd_state)
|
||||
{
|
||||
|
@ -8224,23 +8250,9 @@ parser_yylex(struct parser_params *parser)
|
|||
break;
|
||||
|
||||
case '@':
|
||||
c = nextc();
|
||||
newtok();
|
||||
tokadd('@');
|
||||
if (c == '@') {
|
||||
tokadd('@');
|
||||
c = nextc();
|
||||
}
|
||||
if (c != -1 && (ISDIGIT(c) || !parser_is_identchar())) {
|
||||
pushback(c);
|
||||
if (tokidx == 1) {
|
||||
compile_error(PARSER_ARG "`@%c' is not allowed as an instance variable name", c);
|
||||
}
|
||||
else {
|
||||
compile_error(PARSER_ARG "`@@%c' is not allowed as a class variable name", c);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
c = parse_atmark(parser, last_state);
|
||||
if (c >= 0) return c;
|
||||
c = -c;
|
||||
break;
|
||||
|
||||
case '_':
|
||||
|
|
Loading…
Add table
Reference in a new issue