package parsekit func (p *P) QueueStates(states ...StateFn) StateFn { first, followup := states[0], states[1:] for reverse := range followup { p.PushState(followup[len(followup)-reverse-1]) } return first } func (p *P) ToChildState(state StateFn) StateFn { p.PushState(p.state) return state } func (p *P) ToParentState() StateFn { state := p.PopState() return state } // PushState adds the state function to the state stack. // This is used for implementing nested parsing. func (p *P) PushState(state StateFn) { p.stack = append(p.stack, state) } // PopState pops the last pushed state from the state stack. func (p *P) PopState() StateFn { last := len(p.stack) - 1 head, tail := p.stack[:last], p.stack[last] p.stack = head return tail }