1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* parse.y (tokadd_string, parse_string, yylex): escaped terminator

is now interpreted as is.  [ruby-talk:82206]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4565 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2003-09-17 11:34:02 +00:00
parent 577fa4c6a8
commit d3b780b1cf
2 changed files with 16 additions and 49 deletions

View file

@ -1,3 +1,8 @@
Wed Sep 17 20:34:00 2003 Nobuyoshi Nakada <nobu@ruby-lang.org>
* parse.y (tokadd_string, parse_string, yylex): escaped terminator
is now interpreted as is. [ruby-talk:82206]
Wed Sep 17 18:52:36 2003 Minero Aoki <aamine@loveruby.net> Wed Sep 17 18:52:36 2003 Minero Aoki <aamine@loveruby.net>
* test/fileutils/fileassertions.rb: new file. * test/fileutils/fileassertions.rb: new file.
@ -73,7 +78,7 @@ Mon Sep 15 19:02:52 2003 NAKAMURA, Hiroshi <nahi@ruby-lang.org>
* lib/csv.rb: add extra pamameter to specify row(record) separater * lib/csv.rb: add extra pamameter to specify row(record) separater
character. To parse Mac's CR separated CSV, do like this. character. To parse Mac's CR separated CSV, do like this.
CSV.open("mac.csv", "r", ?,, ?\r) { |row| p row.to_a } CSV.open("mac.csv", "r", ?,, ?\r) { |row| p row.to_a }
The 3rd parameter in this example ?, is for column separater and the The 3rd parameter in this example ?, is for column separater and the
4th ?\r is for row separater. Row separater is nil by default. Nil 4th ?\r is for row separater. Row separater is nil by default. Nil
separater means "\r\n" or "\n". separater means "\r\n" or "\n".

54
parse.y
View file

@ -108,10 +108,6 @@ static int in_single = 0;
static int in_def = 0; static int in_def = 0;
static int compile_for_eval = 0; static int compile_for_eval = 0;
static ID cur_mid = 0; static ID cur_mid = 0;
static int quoted_term;
#define quoted_term_char ((unsigned char)quoted_term)
#define WHEN_QUOTED_TERM(x) ((quoted_term >= 0) && (x))
#define QUOTED_TERM_P(c) WHEN_QUOTED_TERM((c) == quoted_term_char)
static NODE *cond(); static NODE *cond();
static NODE *logop(); static NODE *logop();
@ -174,7 +170,6 @@ static void top_local_setup();
#define NODE_STRTERM NODE_ZARRAY /* nothing to gc */ #define NODE_STRTERM NODE_ZARRAY /* nothing to gc */
#define NODE_HEREDOC NODE_ARRAY /* 1, 3 to gc */ #define NODE_HEREDOC NODE_ARRAY /* 1, 3 to gc */
#define ESCAPED_TERM (1 << CHAR_BIT)
#define SIGN_EXTEND(x,n) (((1<<(n))-1-((x)&~(~0<<(n))))^~(~0<<(n))) #define SIGN_EXTEND(x,n) (((1<<(n))-1-((x)&~(~0<<(n))))^~(~0<<(n)))
#define nd_func u1.id #define nd_func u1.id
#if SIZEOF_SHORT == 2 #if SIZEOF_SHORT == 2
@ -263,7 +258,7 @@ static void top_local_setup();
%type <node> mlhs mlhs_head mlhs_basic mlhs_entry mlhs_item mlhs_node %type <node> mlhs mlhs_head mlhs_basic mlhs_entry mlhs_item mlhs_node
%type <id> fitem variable sym symbol operation operation2 operation3 %type <id> fitem variable sym symbol operation operation2 operation3
%type <id> cname fname op f_rest_arg %type <id> cname fname op f_rest_arg
%type <num> f_norm_arg f_arg term_push %type <num> f_norm_arg f_arg
%token tUPLUS /* unary+ */ %token tUPLUS /* unary+ */
%token tUMINUS /* unary- */ %token tUMINUS /* unary- */
%token tPOW /* ** */ %token tPOW /* ** */
@ -2050,7 +2045,7 @@ string_content : tSTRING_CONTENT
lex_strterm = $<node>2; lex_strterm = $<node>2;
$$ = NEW_EVSTR($3); $$ = NEW_EVSTR($3);
} }
| tSTRING_DBEG term_push | tSTRING_DBEG
{ {
$<node>$ = lex_strterm; $<node>$ = lex_strterm;
lex_strterm = 0; lex_strterm = 0;
@ -2058,11 +2053,10 @@ string_content : tSTRING_CONTENT
} }
compstmt '}' compstmt '}'
{ {
quoted_term = $2; lex_strterm = $<node>2;
lex_strterm = $<node>3; if (($$ = $3) && nd_type($$) == NODE_NEWLINE) {
if (($$ = $4) && nd_type($$) == NODE_NEWLINE) {
$$ = $$->nd_next; $$ = $$->nd_next;
rb_gc_force_recycle((VALUE)$4); rb_gc_force_recycle((VALUE)$3);
} }
$$ = new_evstr($$); $$ = new_evstr($$);
} }
@ -2074,16 +2068,6 @@ string_dvar : tGVAR {$$ = NEW_GVAR($1);}
| backref | backref
; ;
term_push : /* none */
{
if (($$ = quoted_term) == -1 &&
nd_type(lex_strterm) == NODE_STRTERM &&
!nd_paren(lex_strterm)) {
quoted_term = nd_term(lex_strterm);
}
}
;
symbol : tSYMBEG sym symbol : tSYMBEG sym
{ {
lex_state = EXPR_END; lex_state = EXPR_END;
@ -2450,7 +2434,7 @@ static char *lex_pend;
static int static int
yyerror(msg) yyerror(msg)
char *msg; const char *msg;
{ {
char *p, *pe, *buf; char *p, *pe, *buf;
int len, i; int len, i;
@ -2535,7 +2519,6 @@ yycompile(f, line)
ruby_eval_tree = 0; ruby_eval_tree = 0;
heredoc_end = 0; heredoc_end = 0;
lex_strterm = 0; lex_strterm = 0;
quoted_term = -1;
ruby_current_node = 0; ruby_current_node = 0;
ruby_sourcefile = rb_source_filename(f); ruby_sourcefile = rb_source_filename(f);
n = yyparse(); n = yyparse();
@ -2993,10 +2976,6 @@ tokadd_string(func, term, paren, nest)
} }
else if (c == '\\') { else if (c == '\\') {
c = nextc(); c = nextc();
if (QUOTED_TERM_P(c)) {
pushback(c);
return c;
}
switch (c) { switch (c) {
case '\n': case '\n':
if (func & STR_FUNC_QWORDS) break; if (func & STR_FUNC_QWORDS) break;
@ -3068,9 +3047,7 @@ parse_string(quote)
do {c = nextc();} while (ISSPACE(c)); do {c = nextc();} while (ISSPACE(c));
space = 1; space = 1;
} }
if ((c == term && !quote->nd_nest) || if (c == term && !quote->nd_nest) {
(c == '\\' && WHEN_QUOTED_TERM(peek(quoted_term_char)) &&
(c = nextc()) == term)) {
if (func & STR_FUNC_QWORDS) { if (func & STR_FUNC_QWORDS) {
quote->nd_func = -1; quote->nd_func = -1;
return ' '; return ' ';
@ -4095,13 +4072,6 @@ yylex()
goto retry; /* skip \\n */ goto retry; /* skip \\n */
} }
pushback(c); pushback(c);
if (QUOTED_TERM_P(c)) {
if (!(quoted_term & ESCAPED_TERM)) {
rb_warn("escaped terminator '%c' inside string interpolation", c);
quoted_term |= ESCAPED_TERM;
}
goto retry;
}
return '\\'; return '\\';
case '%': case '%':
@ -4111,14 +4081,6 @@ yylex()
c = nextc(); c = nextc();
quotation: quotation:
if (c == '\\' && WHEN_QUOTED_TERM(peek(quoted_term_char))) {
c = nextc();
if (!(quoted_term & ESCAPED_TERM)) {
rb_warn("escaped terminator '%s%c' inside string interpolation",
(c == '\'' ? "\\" : ""), c);
quoted_term |= ESCAPED_TERM;
}
}
if (!ISALNUM(c)) { if (!ISALNUM(c)) {
term = c; term = c;
c = 'Q'; c = 'Q';
@ -4856,7 +4818,7 @@ assignable(id, val)
return NEW_CVDECL(id, val); return NEW_CVDECL(id, val);
} }
else { else {
rb_compile_error("identifier %s is not valid", rb_id2name(id)); rb_compile_error("identifier %s is not valid", rb_id2name(id));
} }
return 0; return 0;
} }