Crystal: Parse error with escape quote inside heredoc

Created on 18 Feb 2019  路  4Comments  路  Source: crystal-lang/crystal

lines 5 and 12 conflicting between themselves
https://play.crystal-lang.org/#/r/6ae2

module M1
  macro included
    def self.amberDestroyMethod : String
      <<-AMBER_DESTROY
        redirect_to action: :index, flash: {\"success\" => \"Deleted  successfully.\"}
      AMBER_DESTROY
    end

    def self.testMethod : String
      required = [] of String
      [{"1", "2", "3", "4"}].each do |name, t|
        required << "output = #{t}::None"
      end  
      required.join "\n      "
    end
  end
end   

module M2
  include M1
end
bug topicparser

Most helpful comment

reducing incorrect, because removing line 12 or remove #{t} from 12th line - changes error message - two lines together reproducing original bug.
in real program, i moved self.amberDestroyMethod upper in code and bug dissapear.
and, yes - removing backslash also solves problem

why i do that - probably some kind of insanity.

All 4 comments

Reduced:

macro foo
  <<-X
  a \"
  X
end

But I don't understand what you are trying to do. Why do you use \" instead of "?

It doesn't really matter why one would write \" instead of ", it shouldn't really matter, because in the context of a heredoc neither of them should have any specific meaning, thus both should be equivalent. This seems to be a parser bug.

reducing incorrect, because removing line 12 or remove #{t} from 12th line - changes error message - two lines together reproducing original bug.
in real program, i moved self.amberDestroyMethod upper in code and bug dissapear.
and, yes - removing backslash also solves problem

why i do that - probably some kind of insanity.

Even this fails:

macro foo # syntax error: unterminated macro
  <<-X
  "
  X
end
Was this page helpful?
0 / 5 - 0 ratings

Related issues

asterite picture asterite  路  3Comments

asterite picture asterite  路  3Comments

TechMagister picture TechMagister  路  3Comments

costajob picture costajob  路  3Comments

grosser picture grosser  路  3Comments