summaryrefslogtreecommitdiff
path: root/parse.y
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-07-17 04:30:38 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-07-17 04:30:38 +0000
commit27e1b2477601804e56f256bbd3b12b887c2bea9a (patch)
treecf16fd325143470fd80a2ad0eec7c53c5ada1ae6 /parse.y
parentdb155640b7cad2752863acc75c8ed231a2c6f271 (diff)
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
Diffstat (limited to 'parse.y')
-rw-r--r--parse.y46
1 files changed, 29 insertions, 17 deletions
diff --git a/parse.y b/parse.y
index dbfb9b34d4..ec9114c427 100644
--- a/parse.y
+++ b/parse.y
@@ -7461,6 +7461,32 @@ parse_gvar(struct parser_params *parser, const enum lex_state_e last_state)
}
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)
{
int result = 0;
@@ -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 '_':