From c1bd83cef742b7ff68d02cc490d018c6ac4d8c13 Mon Sep 17 00:00:00 2001 From: yui-knk Date: Wed, 6 Dec 2017 03:09:55 +0000 Subject: parse.y: Fix the first location of heredoc identifier * parse.y (parser_heredoc_identifier): Put length of term at the head of rb_strterm_heredoc_struct.term. * parse.y (rb_parser_set_location_from_strterm_heredoc): Use length of term to calculate first_loc.column. e.g. The locations of the NODE_DSTR is fixed: ``` a <term); - len = RSTRING_LEN(here->term) - 1; + len = RSTRING_LEN(here->term) - 2; /* here->term includes term_len and func */ + eos++; /* skip term_len */ indent = (func = *eos++) & STR_FUNC_INDENT; if ((c = nextc()) == -1) { @@ -9841,8 +9851,11 @@ rb_parser_fatal(struct parser_params *parser, const char *fmt, ...) void rb_parser_set_location_from_strterm_heredoc(struct parser_params *parser, rb_strterm_heredoc_t *here, YYLTYPE *yylloc) { + const char *eos = RSTRING_PTR(here->term); + int term_len = (int)eos[0]; + yylloc->first_loc.lineno = (int)here->sourceline; - yylloc->first_loc.column = (int)(here->u3.lastidx - RSTRING_LEN(here->term)); + yylloc->first_loc.column = (int)(here->u3.lastidx - term_len); yylloc->last_loc.lineno = (int)here->sourceline; yylloc->last_loc.column = (int)(here->u3.lastidx); } -- cgit v1.2.3