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


module Normalizer
  include Treetop::Runtime

  def root
    @root ||= :text
  end

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

    s0, i0 = [], index
    loop do
      i1 = index
      r2 = _nt_directive
      if r2
        r2 = SyntaxNode.new(input, (index-1)...index) if r2 == true
        r1 = r2
      else
        r3 = _nt_comment
        if r3
          r3 = SyntaxNode.new(input, (index-1)...index) if r3 == true
          r1 = r3
        else
          r4 = _nt_quoted
          if r4
            r4 = SyntaxNode.new(input, (index-1)...index) if r4 == true
            r1 = r4
          else
            r5 = _nt_unquoted
            if r5
              r5 = SyntaxNode.new(input, (index-1)...index) if r5 == true
              r1 = r5
            else
              @index = i1
              r1 = nil
            end
          end
        end
      end
      if r1
        s0 << r1
      else
        break
      end
    end
    r0 = instantiate_node(Text,input, i0...index, s0)

    node_cache[:text][start_index] = r0

    r0
  end

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

    if (match_len = has_terminal?(@regexps['__ir__'+(gr = "\\A(![^\n]*\n)+")] ||= Regexp.new(gr, Regexp::IGNORECASE), :regexp, index))
      r0 = instantiate_node(Comment,input, index...(index + match_len))
      @index += match_len
    else
      terminal_parse_failure('"(![^\\n]*\\n)+"')
      r0 = nil
    end

    node_cache[:comment][start_index] = r0

    r0
  end

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

    if (match_len = has_terminal?(@regexps['__ir__'+(gr = "\\A@[^\n]+\n")] ||= Regexp.new(gr, Regexp::IGNORECASE), :regexp, index))
      r0 = instantiate_node(Directive,input, index...(index + match_len))
      @index += match_len
    else
      terminal_parse_failure('"@[^\\n]+\\n"')
      r0 = nil
    end

    node_cache[:directive][start_index] = r0

    r0
  end

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

    if (match_len = has_terminal?(@regexps['__ir__'+(gr = "\\A((\"[^\"]*\")|('[^']*'))+")] ||= Regexp.new(gr, Regexp::IGNORECASE), :regexp, index))
      r0 = instantiate_node(Quoted,input, index...(index + match_len))
      @index += match_len
    else
      terminal_parse_failure('"((\\"[^\\"]*\\")|(\\\'[^\\\']*\\\'))+"')
      r0 = nil
    end

    node_cache[:quoted][start_index] = r0

    r0
  end

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

    if (match_len = has_terminal?(@regexps['__ir__'+(gr = "\\A[^'\"!@]+")] ||= Regexp.new(gr, Regexp::IGNORECASE), :regexp, index))
      r0 = instantiate_node(Unquoted,input, index...(index + match_len))
      @index += match_len
    else
      terminal_parse_failure('"[^\\\'\\"!@]+"')
      r0 = nil
    end

    node_cache[:unquoted][start_index] = r0

    r0
  end

end

class NormalizerParser < Treetop::Runtime::CompiledParser
  include Normalizer
end

