Commit df7953c6 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Slash after this is division not regex.

Another regex v/s division tokenization enhancement.
parent 36506ebb
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -84,7 +84,8 @@ module JsDuck
    end

    # A slash "/" is a division operator if it follows:
    # - identifier (but not a keyword)
    # - identifier
    # - the "this" keyword
    # - number
    # - closing bracket )
    # - closing square-bracket ]
@@ -93,7 +94,11 @@ module JsDuck
      if @tokens.last then
        type = @tokens.last[:type]
        value = @tokens.last[:value]
        if type == :ident || type == :number || value == ")" || value == "]" then
        if type == :ident || type == :number
          return false
        elsif type == :keyword && value == "this"
          return false
        elsif type == :operator && (value == ")" || value == "]")
          return false
        end
      end
+9 −0
Original line number Diff line number Diff line
@@ -55,6 +55,15 @@ class TestLexer < Test::Unit::TestCase
                  ])
  end

  def test_division_after_this
    assert_tokens("this / 3",
                  [
                   [:keyword, "this"],
                   [:operator, "/"],
                   [:number, 3]
                  ])
  end

  def test_strings
    d = '"' # double-quote
    s = "'" # single-quote