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

ruby-changes:49406

From: nobu <ko1@a...>
Date: Sun, 31 Dec 2017 15:53:11 +0900 (JST)
Subject: [ruby-changes:49406] nobu:r61522 (trunk): parse.y: yylloc at yyerror

nobu	2017-12-31 15:53:04 +0900 (Sun, 31 Dec 2017)

  New Revision: 61522

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

  Log:
    parse.y: yylloc at yyerror
    
    * parse.y (parser_yyerror): utilize the location given by bison.

  Modified files:
    trunk/parse.y
Index: parse.y
===================================================================
--- parse.y	(revision 61521)
+++ parse.y	(revision 61522)
@@ -290,9 +290,9 @@ struct parser_params { https://github.com/ruby/ruby/blob/trunk/parse.y#L290
 #define STR_NEW3(p,n,e,func) parser_str_new((p),(n),(e),(func),current_enc)
 #define TOK_INTERN() intern_cstr(tok(), toklen(), current_enc)
 
-static int parser_yyerror(struct parser_params*, const char*);
-#define yyerror0(msg) parser_yyerror(parser, (msg))
-#define yyerror(yylloc, parser, msg) yyerror0(msg)
+static int parser_yyerror(struct parser_params*, const YYLTYPE *yylloc, const char*);
+#define yyerror0(msg) parser_yyerror(parser, NULL, (msg))
+#define yyerror(yylloc, parser, msg) parser_yyerror(parser, yylloc, msg)
 #define token_flush(p) ((p)->lex.ptok = (p)->lex.pcur)
 
 #define lex_strterm		(parser->lex.strterm)
@@ -5346,7 +5346,7 @@ parser_precise_mbclen(struct parser_para https://github.com/ruby/ruby/blob/trunk/parse.y#L5346
 }
 
 static int
-parser_yyerror(struct parser_params *parser, const char *msg)
+parser_yyerror(struct parser_params *parser, const YYLTYPE *yylloc, const char *msg)
 {
 #ifndef RIPPER
     const int max_line_margin = 30;
@@ -5357,6 +5357,19 @@ parser_yyerror(struct parser_params *par https://github.com/ruby/ruby/blob/trunk/parse.y#L5357
     char *buf;
     long len;
     int i;
+    YYLTYPE current;
+
+    if (!yylloc) {
+	RUBY_SET_YYLLOC(current);
+	yylloc = &current;
+    }
+    else if ((ruby_sourceline != yylloc->first_loc.lineno &&
+	 ruby_sourceline != yylloc->last_loc.lineno) ||
+	(yylloc->first_loc.lineno == yylloc->last_loc.lineno &&
+	 yylloc->first_loc.column == yylloc->last_loc.column)) {
+	compile_error(PARSER_ARG "%s", msg);
+	return 0;
+    }
 
     pend = lex_pend;
     if (pend > lex_pbeg && pend[-1] == '\n') {
@@ -6723,8 +6736,8 @@ parser_heredoc_identifier(struct parser_ https://github.com/ruby/ruby/blob/trunk/parse.y#L6736
 	    else if (newline) newline = 2;
 	}
 	if (c == -1) {
-	    compile_error(PARSER_ARG "unterminated here document identifier");
-	    return 0;
+	    yyerror(NULL, parser, "unterminated here document identifier");
+	    return -1;
 	}
 	switch (newline) {
 	  case 1:
@@ -9893,7 +9906,7 @@ rb_parser_fatal(struct parser_params *pa https://github.com/ruby/ruby/blob/trunk/parse.y#L9906
     rb_str_vcatf(mesg, fmt, ap);
     va_end(ap);
 #ifndef RIPPER
-    parser_yyerror(parser, RSTRING_PTR(mesg));
+    parser_yyerror(parser, NULL, RSTRING_PTR(mesg));
     RB_GC_GUARD(mesg);
 #else
     dispatch1(parse_error, mesg);
@@ -9967,7 +9980,7 @@ assignable_gen(struct parser_params *par https://github.com/ruby/ruby/blob/trunk/parse.y#L9980
 #ifdef RIPPER
     ID id = get_id(lhs);
 # define assignable_result(x) (lhs)
-# define parser_yyerror(parser, x) (lhs = assign_error_gen(parser, lhs))
+# define parser_yyerror(parser, loc, x) (lhs = assign_error_gen(parser, lhs))
 #else
 # define assignable_result(x) assignable_result0(x, location)
 #endif

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

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