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


module Mail
  module ContentTransferEncoding
    include Treetop::Runtime

    def root
      @root ||= :primary
    end

    include RFC2822

    include RFC2045

    module Primary0
      def CFWS1
        elements[0]
      end

      def encoding
        elements[1]
      end

      def CFWS2
        elements[2]
      end

      def CFWS3
        elements[4]
      end
    end

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

      i0, s0 = index, []
      r1 = _nt_CFWS
      s0 << r1
      if r1
        r2 = _nt_encoding
        s0 << r2
        if r2
          r3 = _nt_CFWS
          s0 << r3
          if r3
            if has_terminal?(";", false, index)
              r5 = instantiate_node(SyntaxNode,input, index...(index + 1))
              @index += 1
            else
              terminal_parse_failure(";")
              r5 = nil
            end
            if r5
              r4 = r5
            else
              r4 = instantiate_node(SyntaxNode,input, index...index)
            end
            s0 << r4
            if r4
              r6 = _nt_CFWS
              s0 << r6
            end
          end
        end
      end
      if s0.last
        r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
        r0.extend(Primary0)
      else
        @index = i0
        r0 = nil
      end

      node_cache[:primary][start_index] = r0

      r0
    end

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

      i0 = index
      if has_terminal?("7bits", false, index)
        r1 = instantiate_node(SyntaxNode,input, index...(index + 5))
        @index += 5
      else
        terminal_parse_failure("7bits")
        r1 = nil
      end
      if r1
        r0 = r1
      else
        if has_terminal?("8bits", false, index)
          r2 = instantiate_node(SyntaxNode,input, index...(index + 5))
          @index += 5
        else
          terminal_parse_failure("8bits")
          r2 = nil
        end
        if r2
          r0 = r2
        else
          if has_terminal?("7bit", false, index)
            r3 = instantiate_node(SyntaxNode,input, index...(index + 4))
            @index += 4
          else
            terminal_parse_failure("7bit")
            r3 = nil
          end
          if r3
            r0 = r3
          else
            if has_terminal?("8bit", false, index)
              r4 = instantiate_node(SyntaxNode,input, index...(index + 4))
              @index += 4
            else
              terminal_parse_failure("8bit")
              r4 = nil
            end
            if r4
              r0 = r4
            else
              if has_terminal?("binary", false, index)
                r5 = instantiate_node(SyntaxNode,input, index...(index + 6))
                @index += 6
              else
                terminal_parse_failure("binary")
                r5 = nil
              end
              if r5
                r0 = r5
              else
                if has_terminal?("quoted-printable", false, index)
                  r6 = instantiate_node(SyntaxNode,input, index...(index + 16))
                  @index += 16
                else
                  terminal_parse_failure("quoted-printable")
                  r6 = nil
                end
                if r6
                  r0 = r6
                else
                  if has_terminal?("base64", false, index)
                    r7 = instantiate_node(SyntaxNode,input, index...(index + 6))
                    @index += 6
                  else
                    terminal_parse_failure("base64")
                    r7 = nil
                  end
                  if r7
                    r0 = r7
                  else
                    r8 = _nt_ietf_token
                    if r8
                      r0 = r8
                    else
                      r9 = _nt_custom_x_token
                      if r9
                        r0 = r9
                      else
                        @index = i0
                        r0 = nil
                      end
                    end
                  end
                end
              end
            end
          end
        end
      end

      node_cache[:encoding][start_index] = r0

      r0
    end

  end

  class ContentTransferEncodingParser < Treetop::Runtime::CompiledParser
    include ContentTransferEncoding
  end

end
