Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix grammar.y bug for heredocs

  • Loading branch information...
commit 1566cad6dbad86ec3cdcb7fa1cec6d6e99e9eaa3 1 parent 1baa946
@evanphx evanphx authored
Showing with 20 additions and 9 deletions.
  1. +1 −1  Rakefile
  2. +1 −1  lib/compiler/compiler.rb
  3. +18 −7 shotgun/lib/grammar.y
View
2  Rakefile
@@ -453,7 +453,7 @@ namespace :build do
c_source = FileList[
"shotgun/config.h",
- "shotgun/lib/*.[ch]",
+ "shotgun/lib/*.[chy]",
"shotgun/lib/*.rb",
"shotgun/lib/subtend/*.[chS]",
"shotgun/main.c",
View
2  lib/compiler/compiler.rb
@@ -21,7 +21,7 @@ def self.compile_string(string, flags=nil, filename="(eval)", line=1)
else
binding = nil
end
-
+
comp = new(Compiler::Generator, binding)
node = comp.convert_sexp([:eval_expression, sexp])
cm = node.to_description(:__eval_script__).to_cmethod
View
25 shotgun/lib/grammar.y
@@ -2881,14 +2881,20 @@ ps_nextc(rb_parse_state *parse_state)
heredoc_end = 0;
}
ruby_sourceline++;
- parse_state->lex_pbeg = parse_state->lex_p = bdata(v);
- parse_state->lex_pend = parse_state->lex_p + blength(v);
-
+
+ /* This code is setup so that lex_pend can be compared to
+ the data in lex_lastline. Thats important, otherwise
+ the heredoc code breaks. */
if(parse_state->lex_lastline) {
bassign(parse_state->lex_lastline, v);
} else {
parse_state->lex_lastline = bstrcpy(v);
}
+
+ v = parse_state->lex_lastline;
+
+ parse_state->lex_pbeg = parse_state->lex_p = bdata(v);
+ parse_state->lex_pend = parse_state->lex_p + blength(v);
}
c = (unsigned char)*(parse_state->lex_p++);
if (c == '\r' && parse_state->lex_p < parse_state->lex_pend && *(parse_state->lex_p) == '\n') {
@@ -3362,7 +3368,7 @@ heredoc_identifier(rb_parse_state *parse_state)
/* The heredoc indent is quoted, so its easy to find, we just
continue to consume characters into the token buffer until
we hit the terminating character. */
-
+
newtok(parse_state);
tokadd((char)func, parse_state);
term = c;
@@ -3370,13 +3376,16 @@ heredoc_identifier(rb_parse_state *parse_state)
/* Where of where has the term gone.. */
while ((c = nextc()) != -1 && c != term) {
len = mbclen(c);
- do { tokadd((char)c, parse_state); } while (--len > 0 && (c = nextc()) != -1);
+ do {
+ tokadd((char)c, parse_state);
+ } while (--len > 0 && (c = nextc()) != -1);
}
/* Ack! end of file or end of string. */
if (c == -1) {
rb_compile_error("unterminated here document identifier");
return 0;
}
+
break;
default:
@@ -3407,6 +3416,7 @@ heredoc_identifier(rb_parse_state *parse_state)
pushback(c, parse_state);
break;
}
+
/* Fixup the token buffer, ie set the last character to null. */
tokfix();
@@ -3517,10 +3527,11 @@ here_document(here, parse_state)
--pend;
}
}
- if (str)
+ if (str) {
bcatblk(str, p, pend - p);
- else
+ } else {
str = blk2bstr(p, pend - p);
+ }
if (pend < parse_state->lex_pend) bcatblk(str, "\n", 1);
parse_state->lex_p = parse_state->lex_pend;
if (nextc() == -1) {
Please sign in to comment.
Something went wrong with that request. Please try again.