# Autogenerated from a Treetop grammar. Edits may be lost.


module Numerals
  include Treetop::Runtime

  def root
    @root ||= :percentage
  end

  module Percentage0
    def decimal
      elements[0]
    end

  end

  module Percentage1
    def to_f
      decimal.to_f / 100
    end
  end

  def _nt_percentage
    start_index = index
    if node_cache[:percentage].has_key?(index)
      cached = node_cache[:percentage][index]
      if cached
        node_cache[:percentage][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
        @index = cached.interval.end
      end
      return cached
    end

    i0, s0 = index, []
    r1 = _nt_decimal
    s0 << r1
    if r1
      if (match_len = has_terminal?("%", false, index))
        r2 = true
        @index += match_len
      else
        terminal_parse_failure('"%"')
        r2 = nil
      end
      s0 << r2
    end
    if s0.last
      r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
      r0.extend(Percentage0)
      r0.extend(Percentage1)
    else
      @index = i0
      r0 = nil
    end

    node_cache[:percentage][start_index] = r0

    r0
  end

  module Decimal0
    def sign
      elements[0]
    end

  end

  module Decimal1
    def to_f
      text_value.to_f
    end
  end

  def _nt_decimal
    start_index = index
    if node_cache[:decimal].has_key?(index)
      cached = node_cache[:decimal][index]
      if cached
        node_cache[:decimal][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
        @index = cached.interval.end
      end
      return cached
    end

    i0, s0 = index, []
    r1 = _nt_sign
    s0 << r1
    if r1
      s2, i2 = [], index
      loop do
        if has_terminal?(@regexps[gr = '\A[0-9]'] ||= Regexp.new(gr), :regexp, index)
          r3 = true
          @index += 1
        else
          terminal_parse_failure('[0-9]')
          r3 = nil
        end
        if r3
          s2 << r3
        else
          break
        end
      end
      if s2.empty?
        @index = i2
        r2 = nil
      else
        r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
      end
      s0 << r2
      if r2
        if (match_len = has_terminal?('.', false, index))
          r4 = true
          @index += match_len
        else
          terminal_parse_failure('\'.\'')
          r4 = nil
        end
        s0 << r4
        if r4
          s5, i5 = [], index
          loop do
            if has_terminal?(@regexps[gr = '\A[0-9]'] ||= Regexp.new(gr), :regexp, index)
              r6 = true
              @index += 1
            else
              terminal_parse_failure('[0-9]')
              r6 = nil
            end
            if r6
              s5 << r6
            else
              break
            end
          end
          r5 = instantiate_node(SyntaxNode,input, i5...index, s5)
          s0 << r5
        end
      end
    end
    if s0.last
      r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
      r0.extend(Decimal0)
      r0.extend(Decimal1)
    else
      @index = i0
      r0 = nil
    end

    node_cache[:decimal][start_index] = r0

    r0
  end

  def _nt_sign
    start_index = index
    if node_cache[:sign].has_key?(index)
      cached = node_cache[:sign][index]
      if cached
        node_cache[:sign][index] = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
        @index = cached.interval.end
      end
      return cached
    end

    i1 = index
    if (match_len = has_terminal?('+', false, index))
      r2 = true
      @index += match_len
    else
      terminal_parse_failure('\'+\'')
      r2 = nil
    end
    if r2
      r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
      r1 = r2
    else
      if (match_len = has_terminal?('-', false, index))
        r3 = true
        @index += match_len
      else
        terminal_parse_failure('\'-\'')
        r3 = nil
      end
      if r3
        r3 = SyntaxNode.new(input, (index-1)...index) if r3 == true
        r1 = r3
      else
        @index = i1
        r1 = nil
      end
    end
    if r1
      r0 = r1
    else
      r0 = instantiate_node(SyntaxNode,input, index...index)
    end

    node_cache[:sign][start_index] = r0

    r0
  end

end

class NumeralsParser < Treetop::Runtime::CompiledParser
  include Numerals
end

