Commit 42e8e00d authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

A more complete regex to match a regex in lexer.

parent 8a24f366
Loading
Loading
Loading
Loading
+15 −1
Original line number Diff line number Diff line
@@ -153,7 +153,7 @@ module JsDuck
          elsif regex?
            return {
              :type => :regex,
              :value => @input.scan(/\/([^\/\\]|\\.)*(\/[gim]*|\Z)/)
              :value => @input.scan(META_REGEX)
            }
          else
            return {
@@ -202,6 +202,20 @@ module JsDuck
      @input.scan(/\s+/)
    end

    # A regex to match a regex
    META_REGEX = %r{
      /               (?# beginning    )
      (
        [^/\[\\]      (?# any character except \ / [    )
        |
        \\.           (?# an escaping \ followed by any character    )
        |
        \[ ([^\]\\]|\\.)* \]    (?# [...] containing any characters including /    )
                                (?# except \ ] which have to be escaped    )
      )*
      (/[gim]*|\Z)   (?# ending + modifiers    )
    }x

    KEYWORDS = {
      "break" => true,
      "case" => true,
+4 −0
Original line number Diff line number Diff line
@@ -74,6 +74,10 @@ describe JsDuck::Lexer do
    end
  end

  it "allows [/] inside regex" do
    lex("/ [/] /").should == [[:regex, "/ [/] /"]]
  end

  describe "identifies strings" do

    before do