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)
}
static node*
qstring_node(parser_state *p, int term)
qstring_node(parser_state *p, int beg, int end)
{
int c;
int nest_level = 0;
newtok(p);
while ((c = nextc(p)) != term) {
while ((c = nextc(p)) != end || nest_level != 0) {
if (c == -1) {
yyerror(p, "unterminated string meets end of file");
return 0;
}
if (c == '\\') {
else if (c == beg) {
nest_level++;
}
else if (c == end) {
nest_level--;
}
else if (c == '\\') {
c = nextc(p);
switch (c) {
case '\n':
p->lineno++;
p->column = 0;
continue;
case '\\':
c = '\\';
break;
case '\'':
if (term == '\'') {
c = '\'';
break;
}
/* fall through */
default:
tokadd(p, '\\');
if (c != beg && c != end) {
switch (c) {
case '\n':
p->lineno++;
p->column = 0;
continue;
case '\\':
c = '\\';
break;
default:
tokadd(p, '\\');
}
}
}
tokadd(p, c);
......@@ -3475,12 +3478,12 @@ qstring_node(parser_state *p, int term)
}
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) {
yylval.nd = new_str(p, tok(p), toklen(p));
yylval.nd = nd;
return tSTRING;
}
return 0;
......@@ -3714,7 +3717,7 @@ parser_yylex(parser_state *p)
return tSTRING_BEG;
case '\'':
return parse_qstring(p, c);
return parse_qstring(p, '\'', '\'');
case '?':
if (IS_END()) {
......@@ -4317,7 +4320,7 @@ parser_yylex(parser_state *p)
case '%':
if (IS_BEG()) {
int term;
int beg = 0, term;
#if 0
int paren;
#endif
......@@ -4329,7 +4332,7 @@ parser_yylex(parser_state *p)
c = 'Q';
}
else {
term = nextc(p);
beg = term = nextc(p);
if (isalnum(term)) {
yyerror(p, "unknown type of %string");
return 0;
......@@ -4362,7 +4365,8 @@ parser_yylex(parser_state *p)
#if 0
p->lex_strterm = new_strterm(p, str_squote, term, paren);
#endif
return tSTRING_BEG;
p->sterm = 0;
return parse_qstring(p, beg, term);
case 'W':
#if 0
......
......@@ -40,9 +40,10 @@ assert('Literals Strings Quoted Non-Expanded', '8.7.6.3.4') do
d = %q<abc>
e = %q/abc/
f = %q/ab\/c/
g = %q{#{a}}
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
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