Skip to content

Instantly share code, notes, and snippets.

@kschiess
Created May 22, 2013 15:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kschiess/5628463 to your computer and use it in GitHub Desktop.
Save kschiess/5628463 to your computer and use it in GitHub Desktop.
diff --git a/lib/rip/compiler/parser.rb b/lib/rip/compiler/parser.rb
index eb60b43..2416e3d 100644
--- a/lib/rip/compiler/parser.rb
+++ b/lib/rip/compiler/parser.rb
@@ -261,11 +261,13 @@ module Rip::Compiler
rule(:heredoc_start) { angled_open.repeat(2, 2) >> heredoc_label >> line_break }
rule(:heredoc_label) { match['A-Z_'].repeat(1).capture(:heredoc_label) }
- rule(:heredoc_content) { (heredoc_end.absent? >> heredoc_content_any >> (line_break.absent? >> heredoc_content_any).repeat >> heredoc_content_any).repeat(1) }
+ # rule(:heredoc_content) { (heredoc_end.absent? >> heredoc_content_any >> (line_break.absent? >> heredoc_content_any).repeat >> heredoc_content_any).repeat(1) }
+ rule(:heredoc_content) { (heredoc_end.absent? >> heredoc_content_line).repeat }
+ rule(:heredoc_content_line) { (line_break.absent? >> heredoc_content_any).repeat >> line_break.as(:character) }
rule(:heredoc_content_any) { escape_advanced.as(:character) | interpolation | any.as(:character) }
rule(:heredoc_end) do
- dynamic { |source, context| str(context.captures[:heredoc_label]) >> (eof.absent? >> line_break) }
+ dynamic { |source, context| spaces? >> str(context.captures[:heredoc_label]) >> (eof.absent? >> line_break | eof) }
end
diff --git a/spec/unit/rip/compiler/parser_spec.rb b/spec/unit/rip/compiler/parser_spec.rb
index 162949d..c72493f 100644
--- a/spec/unit/rip/compiler/parser_spec.rb
+++ b/spec/unit/rip/compiler/parser_spec.rb
@@ -1445,12 +1445,31 @@ describe Rip::Compiler::Parser do
}
end
end
+ describe "HEREDOCs", :focus, :broken do
+ let(:parser) { described_class.new(nil, nil) }
+ let(:heredoc) { parser.heredoc }
+
+ subject { heredoc }
+
+ it { should parse("<<HERE_DOC\nHERE_DOC") }
+ it { should parse("<<HERE_DOC\n\n\nHERE_DOC\n") }
+ it { should parse("<<HERE_DOC\n\t\n\t\n\tHERE_DOC\n") }
+ it { should parse(%q(<<HERE_DOC
+ i'm a HERE_DOC
+ HERE_DOC are multi-line strings
+ HERE_DOC).strip, trace: true) }
+ it { should parse(%q(<<HERE_DOC
+ here docs are good for
+ strings that \#{need} multiple lines
+ advantageous, eh?
+ HERE_DOC).strip, trace: true) }
+ end
recognizes_as_expected 'empty heredoc', :focus, :broken do
let(:rip) { "<<HERE_DOC\nHERE_DOC" }
let(:expected_raw) do
{
- :module => [
+ :module => [
{
:string => rip_string('')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment