summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/parse.y60
-rw-r--r--test/t/literals.rb3
2 files changed, 34 insertions, 29 deletions
diff --git a/src/parse.y b/src/parse.y
index a9201a79b..1cb8741f2 100644
--- a/src/parse.y
+++ b/src/parse.y
@@ -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
diff --git a/test/t/literals.rb b/test/t/literals.rb
index 700c4c846..c996af3f3 100644
--- a/test/t/literals.rb
+++ b/test/t/literals.rb
@@ -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