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


module Mail
  module EnvelopeFrom
    include Treetop::Runtime

    def root
      @root ||= :primary
    end

    include RFC2822

    module Primary0
      def addr_spec
        elements[0]
      end

      def ctime_date
        elements[1]
      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_addr_spec
      s0 << r1
      if r1
        r2 = _nt_ctime_date
        s0 << r2
      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

    module CtimeDate0
      def day_name
        elements[0]
      end

      def month_name
        elements[2]
      end

      def day
        elements[4]
      end

      def time_of_day
        elements[6]
      end

      def year
        elements[8]
      end
    end

    def _nt_ctime_date
      start_index = index
      if node_cache[:ctime_date].has_key?(index)
        cached = node_cache[:ctime_date][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_day_name
      s0 << r1
      if r1
        s2, i2 = [], index
        loop do
          if has_terminal?(" ", false, index)
            r3 = instantiate_node(SyntaxNode,input, index...(index + 1))
            @index += 1
          else
            terminal_parse_failure(" ")
            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
          r4 = _nt_month_name
          s0 << r4
          if r4
            s5, i5 = [], index
            loop do
              if has_terminal?(" ", false, index)
                r6 = instantiate_node(SyntaxNode,input, index...(index + 1))
                @index += 1
              else
                terminal_parse_failure(" ")
                r6 = nil
              end
              if r6
                s5 << r6
              else
                break
              end
            end
            if s5.empty?
              @index = i5
              r5 = nil
            else
              r5 = instantiate_node(SyntaxNode,input, i5...index, s5)
            end
            s0 << r5
            if r5
              r7 = _nt_day
              s0 << r7
              if r7
                if has_terminal?(" ", false, index)
                  r8 = instantiate_node(SyntaxNode,input, index...(index + 1))
                  @index += 1
                else
                  terminal_parse_failure(" ")
                  r8 = nil
                end
                s0 << r8
                if r8
                  r9 = _nt_time_of_day
                  s0 << r9
                  if r9
                    if has_terminal?(" ", false, index)
                      r10 = instantiate_node(SyntaxNode,input, index...(index + 1))
                      @index += 1
                    else
                      terminal_parse_failure(" ")
                      r10 = nil
                    end
                    s0 << r10
                    if r10
                      r11 = _nt_year
                      s0 << r11
                    end
                  end
                end
              end
            end
          end
        end
      end
      if s0.last
        r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
        r0.extend(CtimeDate0)
      else
        @index = i0
        r0 = nil
      end

      node_cache[:ctime_date][start_index] = r0

      r0
    end

  end

  class EnvelopeFromParser < Treetop::Runtime::CompiledParser
    include EnvelopeFrom
  end

end