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

Unify coding style of if-statements.

Remove redundant "then"-s.
parent 8420f73f
Loading
Loading
Loading
Loading
+23 −23
Original line number Diff line number Diff line
@@ -48,7 +48,7 @@ module JsDuck
      # - and those without it
      input.each_line do |line|
        line.chomp!
        if line =~ /\A\s*\*\s?(.*)\Z/ then
        if line =~ /\A\s*\*\s?(.*)\Z/
          result << $1
        else
          result << line
@@ -64,39 +64,39 @@ module JsDuck
    def parse_loop
      add_tag(:default)
      while !@input.eos? do
        if look(/@class\b/) then
        if look(/@class\b/)
          at_class
        elsif look(/@extends\b/) then
        elsif look(/@extends\b/)
          at_extends
        elsif look(/@singleton\b/) then
        elsif look(/@singleton\b/)
          boolean_at_tag(/@singleton/, :singleton)
        elsif look(/@event\b/) then
        elsif look(/@event\b/)
          at_event
        elsif look(/@method\b/) then
        elsif look(/@method\b/)
          at_method
        elsif look(/@constructor\b/) then
        elsif look(/@constructor\b/)
          boolean_at_tag(/@constructor/, :constructor)
        elsif look(/@param\b/) then
        elsif look(/@param\b/)
          at_param
        elsif look(/@returns?\b/) then
        elsif look(/@returns?\b/)
          at_return
        elsif look(/@cfg\b/) then
        elsif look(/@cfg\b/)
          at_cfg
        elsif look(/@property\b/) then
        elsif look(/@property\b/)
          at_property
        elsif look(/@type\b/) then
        elsif look(/@type\b/)
          at_type
        elsif look(/@xtype\b/) then
        elsif look(/@xtype\b/)
          at_xtype
        elsif look(/@member\b/) then
        elsif look(/@member\b/)
          at_member
        elsif look(/@static\b/) then
        elsif look(/@static\b/)
          boolean_at_tag(/@static/, :static)
        elsif look(/@(private|ignore|hide|protected)\b/) then
        elsif look(/@(private|ignore|hide|protected)\b/)
          boolean_at_tag(/@(private|ignore|hide|protected)/, :private)
        elsif look(/@/) then
        elsif look(/@/)
          @current_tag[:doc] += @input.scan(/@/)
        elsif look(/[^@]/) then
        elsif look(/[^@]/)
          @current_tag[:doc] += @input.scan(/[^@]+/)
        end
      end
@@ -183,9 +183,9 @@ module JsDuck
      match(/@type/)
      add_tag(:type)
      skip_horiz_white
      if look(/\{/) then
      if look(/\{/)
        @current_tag[:type] = typedef
      elsif look(/\S/) then
      elsif look(/\S/)
        @current_tag[:type] = @input.scan(/\S+/)
      end
      skip_white
@@ -217,7 +217,7 @@ module JsDuck
    # matches {type} if possible and sets it on @current_tag
    def maybe_type
      skip_horiz_white
      if look(/\{/) then
      if look(/\{/)
        @current_tag[:type] = typedef
      end
    end
@@ -225,7 +225,7 @@ module JsDuck
    # matches identifier name if possible and sets it on @current_tag
    def maybe_name
      skip_horiz_white
      if look(/\w/) then
      if look(/\w/)
        @current_tag[:name] = ident
      end
    end
@@ -233,7 +233,7 @@ module JsDuck
    # matches ident.chain if possible and sets it on @current_tag
    def maybe_ident_chain(propname)
      skip_horiz_white
      if look(/\w/) then
      if look(/\w/)
        @current_tag[propname] = ident_chain
      end
    end
+12 −12
Original line number Diff line number Diff line
@@ -38,7 +38,7 @@ module JsDuck
        tok = @tokens[i]
        i += 1
        return false if tok == nil
        if t.instance_of?(Symbol) then
        if t.instance_of?(Symbol)
          tok[:type] == t
        else
          tok[:value] == t
@@ -71,36 +71,36 @@ module JsDuck
      @tokens = []
      while !@input.eos? do
        skip_white_and_comments
        if @input.check(/[0-9]+/) then
        if @input.check(/[0-9]+/)
          @tokens << {
            :type => :number,
            :value => eval(@input.scan(/[0-9]+(\.[0-9]*)?/))
          }
        elsif @input.check(/\w+/) then
        elsif @input.check(/\w+/)
          value = @input.scan(/\w+/)
          @tokens << {
            :type => KEYWORDS[value] ? :keyword : :ident,
            :value => value
          }
        elsif @input.check(/\/\*\*/) then
        elsif @input.check(/\/\*\*/)
          @tokens << {
            :type => :doc_comment,
            # Calculate current line number, starting with 1
            :linenr => @input.string[0...@input.pos].count("\n") + 1,
            :value => @input.scan_until(/\*\/|\Z/)
          }
        elsif @input.check(/"/) then
        elsif @input.check(/"/)
          @tokens << {
            :type => :string,
            :value => eval(@input.scan(/"([^"\\]|\\.)*"/))
          }
        elsif @input.check(/'/) then
        elsif @input.check(/'/)
          @tokens << {
            :type => :string,
            :value => eval(@input.scan(/'([^'\\]|\\.)*'/))
          }
        elsif @input.check(/\//) then
          if regex? then
        elsif @input.check(/\//)
          if regex?
            @tokens << {
              :type => :regex,
              :value => @input.scan(/\/([^\/\\]|\\.)*\/[gim]*/)
@@ -111,7 +111,7 @@ module JsDuck
              :value => @input.scan(/\//)
            }
          end
        elsif @input.check(/./) then
        elsif @input.check(/./)
          @tokens << {
            :type => :operator,
            :value => @input.scan(/./)
@@ -128,7 +128,7 @@ module JsDuck
    # - closing square-bracket ]
    # Otherwise it's a beginning of regex
    def regex?
      if @tokens.last then
      if @tokens.last
        type = @tokens.last[:type]
        value = @tokens.last[:value]
        if type == :ident || type == :number
@@ -145,9 +145,9 @@ module JsDuck
    def skip_white_and_comments
      skip_white
      while multiline_comment? || line_comment? do
        if multiline_comment? then
        if multiline_comment?
          @input.scan_until(/\*\/|\Z/)
        elsif line_comment? then
        elsif line_comment?
          @input.scan_until(/\n|\Z/)
        end
        skip_white
+15 −15
Original line number Diff line number Diff line
@@ -45,7 +45,7 @@ module JsDuck
    #
    def parse
      while !@lex.empty? do
        if look(:doc_comment) then
        if look(:doc_comment)
          comment = @lex.next(true)
          @docs << {
            :comment => comment[:value],
@@ -64,18 +64,18 @@ module JsDuck

    # <code-block> := <function> | <var-declaration> | <assignment> | <property-literal>
    def code_block
      if look("function") then
      if look("function")
        function
      elsif look("var") then
      elsif look("var")
        var_declaration
      elsif look(:ident, ":") || look(:string, ":") then
      elsif look(:ident, ":") || look(:string, ":")
        property_literal
      elsif look(",", :ident, ":") || look(",", :string, ":")  then
      elsif look(",", :ident, ":") || look(",", :string, ":")
        match(",")
        property_literal
      elsif look(:ident) || look("this") then
      elsif look(:ident) || look("this")
        maybe_assignment
      elsif look(:string) then
      elsif look(:string)
        {:type => :assignment, :left => [match(:string)]}
      else
        {:type => :nop}
@@ -118,7 +118,7 @@ module JsDuck
    # <maybe-assignment> := <ident-chain> [ "=" <expression> ]
    def maybe_assignment
      left = ident_chain
      if look("=") then
      if look("=")
        match("=")
        right = expression
      end
@@ -146,17 +146,17 @@ module JsDuck
    # <expression> := <function> | <ext-extend> | <literal>
    # <literal> := <string> | <boolean> | <number> | <regex>
    def expression
      if look("function") then
      if look("function")
        function
      elsif look("Ext", ".", "extend") then
      elsif look("Ext", ".", "extend")
        ext_extend
      elsif look(:string) then
      elsif look(:string)
        {:type => :literal, :class => "String"}
      elsif look("true") || look("false") then
      elsif look("true") || look("false")
        {:type => :literal, :class => "Boolean"}
      elsif look(:number) then
      elsif look(:number)
        {:type => :literal, :class => "Number"}
      elsif look(:regex) then
      elsif look(:regex)
        {:type => :literal, :class => "RegExp"}
      end
    end
@@ -185,7 +185,7 @@ module JsDuck
    # Matches all arguments, returns the value of last match
    # When the whole sequence doesn't match, throws exception
    def match(*args)
      if look(*args) then
      if look(*args)
        last = nil
        args.length.times { last = @lex.next }
        last