[前][次][番号順一覧][スレッド一覧]

ruby-changes:47342

From: nobu <ko1@a...>
Date: Tue, 1 Aug 2017 17:32:24 +0900 (JST)
Subject: [ruby-changes:47342] nobu:r59458 (trunk): parse.y: simplify parse_ident

nobu	2017-08-01 17:32:18 +0900 (Tue, 01 Aug 2017)

  New Revision: 59458

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59458

  Log:
    parse.y: simplify parse_ident
    
    * parse.y (parse_ident): simplified selecting identifier types by
      the suffix.

  Modified files:
    trunk/parse.y
Index: parse.y
===================================================================
--- parse.y	(revision 59457)
+++ parse.y	(revision 59458)
@@ -7793,7 +7793,7 @@ parse_atmark(struct parser_params *parse https://github.com/ruby/ruby/blob/trunk/parse.y#L7793
 static enum yytokentype
 parse_ident(struct parser_params *parser, int c, int cmd_state)
 {
-    enum yytokentype result = 0;
+    enum yytokentype result;
     int mb = ENC_CODERANGE_7BIT;
     const enum lex_state_e last_state = lex_state;
     ID ident;
@@ -7804,37 +7804,20 @@ parse_ident(struct parser_params *parser https://github.com/ruby/ruby/blob/trunk/parse.y#L7804
 	c = nextc();
     } while (parser_is_identchar());
     if ((c == '!' || c == '?') && !peek('=')) {
+	result = tFID;
+	tokadd(c);
+    }
+    else if (c == '=' && IS_lex_state(EXPR_FNAME) &&
+	     (!peek('~') && !peek('>') && (!peek('=') || (peek_n('>', 1))))) {
+	result = tIDENTIFIER;
 	tokadd(c);
     }
     else {
+	result = ISUPPER(tok()[0]) ? tCONSTANT : tIDENTIFIER;
 	pushback(c);
     }
     tokfix();
 
-    if (toklast() == '!' || toklast() == '?') {
-	result = tFID;
-    }
-    else {
-	if (IS_lex_state(EXPR_FNAME)) {
-	    register int c = nextc();
-	    if (c == '=' && !peek('~') && !peek('>') &&
-		(!peek('=') || (peek_n('>', 1)))) {
-		result = tIDENTIFIER;
-		tokadd(c);
-		tokfix();
-	    }
-	    else {
-		pushback(c);
-	    }
-	}
-	if (result == 0 && ISUPPER(tok()[0])) {
-	    result = tCONSTANT;
-	}
-	else {
-	    result = tIDENTIFIER;
-	}
-    }
-
     if (IS_LABEL_POSSIBLE()) {
 	if (IS_LABEL_SUFFIX(0)) {
 	    SET_LEX_STATE(EXPR_ARG|EXPR_LABELED);

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]