// evalApplyRule consume the inTok in some way or error, returns  done, consumed, err
evalApplyRule consume the inTok in some way or error, returns  done, consumed, err
// evalApplyRule consume the inTok in some way or error returns done consumed err
func (g *Grammer) evalApplyRule(current *capture, inTok cmdlang.TokInfo, evRule rule) (bool, bool, error) {
	consumed := false
	consumeInput := func() (*cmdlang.TokInfo, bool) {
		if !consumed {
			consumed = true
			return &inTok, true
		}
		return nil, false
	}
	for {
		done, ruleEv, ruleState, _ := restoreRuleState(current, evRule)
		if done {
			return true, consumed, nil
		}
		ruleTok := ruleEv.getTok(ruleState.get())
		if ruleState.Parent == nil && bytes.Compare(inTok.Literal, ruleTok.Literal) == 0 {
			var ok bool
			if _, ok = consumeInput(); !ok {
				return false, consumed, nil 
			}
			ruleState.inc()
			continue
		}
		if ruleState.Process != nil {
			fnProcess := ruleState.Process
			ruleState.Process = nil
			wanted := false
			got := false
			cInput := func() (*cmdlang.TokInfo, bool) {
				wanted = true
				if tok, ok := consumeInput(); ok {
					got = true
					return tok, ok
				}
				return nil, false
			}
			err := fnProcess(current, *ruleTok, cInput, ruleState)
			if err != nil {
				return false, consumed, err
			}
			if wanted && !got {
				ruleState.Process = fnProcess 
				return false, consumed, nil   
			}
			continue
		}
		cmd := string(ruleTok.Literal)
		switch cmd {
		case "!cap":
			ruleState.inc()
			ruleState.Process = setCapture
		case "!rcap":
			ruleState.inc()
			ruleState.Process = checkCapture
		case "!set":
			ruleState.inc()
			ruleState.Process = setNameCapture
		default:
			return false, consumed, newTErr(inTok, "Unknown rule token %v", ruleTok)
		}
	}
	return false, consumed, nil
}
func ( g * Grammer ) evalApplyRule ( current * capture , inTok cmdlang . TokInfo , evRule rule ) ( bool , bool , error ) { consumed := false consumeInput := func ( ) ( * cmdlang . TokInfo , bool ) { if ! consumed { consumed = true return & inTok , true } return nil , false } for { done , ruleEv , ruleState , _ := restoreRuleState ( current , evRule ) if done { return true , consumed , nil } ruleTok := ruleEv . getTok ( ruleState . get ( ) ) if ruleState . Parent == nil && bytes . Compare ( inTok . Literal , ruleTok . Literal ) == 0 { var ok bool if _ , ok = consumeInput ( ) ; ! ok { return false , consumed , nil } ruleState . inc ( ) continue } if ruleState . Process != nil { fnProcess := ruleState . Process ruleState . Process = nil wanted := false got := false cInput := func ( ) ( * cmdlang . TokInfo , bool ) { wanted = true if tok , ok := consumeInput ( ) ; ok { got = true return tok , ok } return nil , false } err := fnProcess ( current , * ruleTok , cInput , ruleState ) if err != nil { return false , consumed , err } if wanted && ! got { ruleState . Process = fnProcess return false , consumed , nil } continue } cmd := string ( ruleTok . Literal ) switch cmd { case " " : ruleState . inc ( ) ruleState . Process = setCapture case " " : ruleState . inc ( ) ruleState . Process = checkCapture case " " : ruleState . inc ( ) ruleState . Process = setNameCapture default : return false , consumed , newTErr ( inTok , " " , ruleTok ) } } return false , consumed , nil }
evalApplyRule consume the inTok in some way or error, returns  done, consumed, err
evalApplyRule consume the inTok in some way or error returns done consumed err
// ask for more input //current.Type = ruleTok // try again after input // ask for more input // effectivly default processors