package parsekit // routeAction is a struct that is used for building On() method chains. type routeAction struct { chainAction } // RouteRepeat indicates that on the next parsing cycle, // the current StateHandler must be reinvoked. func (a *routeAction) RouteRepeat() *chainAction { if a.ok { return a.p.RouteRepeat() } return &chainAction{nil, false} } // RouteTo tells the parser what StateHandler function to invoke // in the next parsing cycle. func (a *routeAction) RouteTo(state StateHandler) *routeFollowupAction { if a.ok { return a.p.RouteTo(state) } return &routeFollowupAction{chainAction: chainAction{nil, false}} } // RouteReturn tells the parser that on the next cycle the next scheduled // route must be invoked. func (a *routeAction) RouteReturn() *chainAction { if a.ok { return a.p.RouteReturn() } return &chainAction{nil, false} } // routeFollowupAction chains parsing routes. // It allows for routing code like p.RouteTo(handlerA).ThenTo(handlerB). type routeFollowupAction struct { chainAction } // ThenTo schedules a StateHandler that must be invoked after the RouteTo // StateHandler has been completed. // For example: p.RouteTo(handlerA).ThenTo(handlerB) func (a *routeFollowupAction) ThenTo(state StateHandler) *chainAction { if a.ok { a.p.pushRoute(state) } return &chainAction{nil, a.ok} } // ThenReturnHere schedules the current StateHandler to be invoked after // the RouteTo StateHandler has been completed. // For example: p.RouteTo(handlerA).ThenReturnHere() func (a *routeFollowupAction) ThenReturnHere() *chainAction { if a.ok { a.p.pushRoute(a.p.state) } return &chainAction{nil, a.ok} }