Commit aaf5f3a0 authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto

Merge pull request #753 from masamitsu-murase/modify_handling_of_quoted_string_literal

Modify handling of quoted non-expanded string literal
parents ebdb8e98 f04d9b1c
...@@ -3434,36 +3434,39 @@ parse_string(parser_state *p, int term) ...@@ -3434,36 +3434,39 @@ parse_string(parser_state *p, int term)
} }
static node* static node*
qstring_node(parser_state *p, int term) qstring_node(parser_state *p, int beg, int end)
{ {
int c; int c;
int nest_level = 0;
newtok(p); newtok(p);
while ((c = nextc(p)) != term) { while ((c = nextc(p)) != end || nest_level != 0) {
if (c == -1) { if (c == -1) {
yyerror(p, "unterminated string meets end of file"); yyerror(p, "unterminated string meets end of file");
return 0; return 0;
} }
if (c == '\\') { else if (c == beg) {
nest_level++;
}
else if (c == end) {
nest_level--;
}
else if (c == '\\') {
c = nextc(p); c = nextc(p);
switch (c) { if (c != beg && c != end) {
case '\n': switch (c) {
p->lineno++; case '\n':
p->column = 0; p->lineno++;
continue; p->column = 0;
continue;
case '\\':
c = '\\'; case '\\':
break; c = '\\';
break;
case '\'':
if (term == '\'') { default:
c = '\''; tokadd(p, '\\');
break; }
}
/* fall through */
default:
tokadd(p, '\\');
} }
} }
tokadd(p, c); tokadd(p, c);
...@@ -3475,12 +3478,12 @@ qstring_node(parser_state *p, int term) ...@@ -3475,12 +3478,12 @@ qstring_node(parser_state *p, int term)
} }
static int static int
parse_qstring(parser_state *p, int term) parse_qstring(parser_state *p, int beg, int end)
{ {
node *nd = qstring_node(p, term); node *nd = qstring_node(p, beg, end);
if (nd) { if (nd) {
yylval.nd = new_str(p, tok(p), toklen(p)); yylval.nd = nd;
return tSTRING; return tSTRING;
} }
return 0; return 0;
...@@ -3714,7 +3717,7 @@ parser_yylex(parser_state *p) ...@@ -3714,7 +3717,7 @@ parser_yylex(parser_state *p)
return tSTRING_BEG; return tSTRING_BEG;
case '\'': case '\'':
return parse_qstring(p, c); return parse_qstring(p, '\'', '\'');
case '?': case '?':
if (IS_END()) { if (IS_END()) {
...@@ -4317,7 +4320,7 @@ parser_yylex(parser_state *p) ...@@ -4317,7 +4320,7 @@ parser_yylex(parser_state *p)
case '%': case '%':
if (IS_BEG()) { if (IS_BEG()) {
int term; int beg = 0, term;
#if 0 #if 0
int paren; int paren;
#endif #endif
...@@ -4329,7 +4332,7 @@ parser_yylex(parser_state *p) ...@@ -4329,7 +4332,7 @@ parser_yylex(parser_state *p)
c = 'Q'; c = 'Q';
} }
else { else {
term = nextc(p); beg = term = nextc(p);
if (isalnum(term)) { if (isalnum(term)) {
yyerror(p, "unknown type of %string"); yyerror(p, "unknown type of %string");
return 0; return 0;
...@@ -4362,7 +4365,8 @@ parser_yylex(parser_state *p) ...@@ -4362,7 +4365,8 @@ parser_yylex(parser_state *p)
#if 0 #if 0
p->lex_strterm = new_strterm(p, str_squote, term, paren); p->lex_strterm = new_strterm(p, str_squote, term, paren);
#endif #endif
return tSTRING_BEG; p->sterm = 0;
return parse_qstring(p, beg, term);
case 'W': case 'W':
#if 0 #if 0
......
...@@ -40,9 +40,10 @@ assert('Literals Strings Quoted Non-Expanded', '8.7.6.3.4') do ...@@ -40,9 +40,10 @@ assert('Literals Strings Quoted Non-Expanded', '8.7.6.3.4') do
d = %q<abc> d = %q<abc>
e = %q/abc/ e = %q/abc/
f = %q/ab\/c/ f = %q/ab\/c/
g = %q{#{a}}
a == 'abc' and b == 'abc' and c == 'abc' and d == 'abc' and a == 'abc' and b == 'abc' and c == 'abc' and d == 'abc' and
e == 'abc' and f == 'ab/c' e == 'abc' and f == 'ab/c' and g == '#{a}'
end end
assert('Literals Strings Quoted Expanded', '8.7.6.3.5') do assert('Literals Strings Quoted Expanded', '8.7.6.3.5') do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment