Commit 795de083 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Support for multiline strings in lexer.

Stuff like: "Some string\
continues here".

It's rarely used, but I encountered it in some Jasmine tests.
parent 4f8cc451
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -127,12 +127,12 @@ module JsDuck
        elsif @input.check(/'/)
          return {
            :type => :string,
            :value => @input.scan(/'([^'\\]|\\.)*'/).sub(/^'(.*)'$/, "\\1")
            :value => @input.scan(/'([^'\\]|\\.)*'/m).sub(/^'(.*)'$/m, "\\1")
          }
        elsif @input.check(/"/)
          return {
            :type => :string,
            :value => @input.scan(/"([^"\\]|\\.)*"/).sub(/^"(.*)"$/, "\\1")
            :value => @input.scan(/"([^"\\]|\\.)*"/m).sub(/^"(.*)"$/m, "\\1")
          }
        elsif @input.check(/\//)
          # Several things begin with dash:
+8 −0
Original line number Diff line number Diff line
@@ -89,6 +89,14 @@ describe JsDuck::Lexer do
    it "when escaped single-quote inside single-quoted string" do
      lex(@s+@b+@s+@s   + ' "blah"').should == [[:string, @b+@s], [:string, "blah"]]
    end

    it "when newlines escaped inside double-quoted string" do
      lex(@d+"A\\\nB"+@d).should == [[:string, "A\\\nB"]]
    end

    it "when newlines escaped inside single-quoted string" do
      lex(@s+"A\\\nB"+@s).should == [[:string, "A\\\nB"]]
    end
  end

  it "identifies $ as beginning of identifier" do