# ex: set ro:
# DO NOT EDIT.
# generated by smc (http://smc.sourceforge.net/)
# from file : Detector.sm

import statemap


class DetectorState(statemap.State):

    def Entry(self, fsm):
        pass

    def Exit(self, fsm):
        pass

    def EOS(self, fsm):
        self.Default(fsm)

    def cbracket(self, fsm):
        self.Default(fsm)

    def comma(self, fsm):
        self.Default(fsm)

    def digit(self, fsm):
        self.Default(fsm)

    def digit(self, fsm, lt):
        self.Default(fsm)

    def letter(self, fsm, lt):
        self.Default(fsm)

    def obracket(self, fsm):
        self.Default(fsm)

    def space(self, fsm):
        self.Default(fsm)

    def Default(self, fsm):
        msg = "\n\tState: %s\n\tTransition: %s" % (
            fsm.getState().getName(), fsm.getTransition())
        raise statemap.TransitionUndefinedException(msg)

class MainMap_Default(DetectorState):
    pass

class MainMap_Gnd(MainMap_Default):

    def Default(self, fsm):
        fsm.getState().Exit(fsm)
        fsm.setState(MainMap.Error)
        fsm.getState().Entry(fsm)

    def EOS(self, fsm):
        ctxt = fsm.getOwner()
        if ctxt.counter() :
            fsm.getState().Exit(fsm)
            fsm.clearState()
            try:
                ctxt.set_out_flag()
            finally:
                fsm.setState(MainMap.Acceptable)
                fsm.getState().Entry(fsm)
        else:
            MainMap_Default.EOS(self, fsm)
        
    def digit(self, fsm, lt):
        ctxt = fsm.getOwner()
        if ctxt.counter() :
            endState = fsm.getState()
            fsm.clearState()
            try:
                ctxt.inc_counter()
                ctxt.cmd_update(lt)
            finally:
                fsm.setState(endState)
        else:
            MainMap_Default.digit(self, fsm, lt)
        
    def letter(self, fsm, lt):
        ctxt = fsm.getOwner()
        endState = fsm.getState()
        fsm.clearState()
        try:
            ctxt.inc_counter()
            ctxt.cmd_update(lt)
        finally:
            fsm.setState(endState)

    def space(self, fsm):
        ctxt = fsm.getOwner()
        if ctxt.cmd_is_create() :
            # No actions.
            pass
            fsm.pushState(CreateMap.Gnd)
            fsm.getState().Entry(fsm)
        elif ctxt.counter() :
            # No actions.
            pass
            fsm.pushState(JoinMap.Gnd)
            fsm.getState().Entry(fsm)
        else:
            MainMap_Default.space(self, fsm)
        
class MainMap_Error(MainMap_Default):

    def Entry(self, fsm):
        ctxt = fsm.getOwner()
        ctxt.reset_out_flag()
        ctxt.unacceptable()

    def Default(self, fsm):
        # No actions.
        pass

class MainMap_Acceptable(MainMap_Default):

    def Default(self, fsm):
        fsm.getState().Exit(fsm)
        fsm.setState(MainMap.Error)
        fsm.getState().Entry(fsm)

class MainMap(object):

    Gnd = MainMap_Gnd('MainMap.Gnd', 0)
    Error = MainMap_Error('MainMap.Error', 1)
    Acceptable = MainMap_Acceptable('MainMap.Acceptable', 2)
    Default = MainMap_Default('MainMap.Default', -1)

class CreateMap_Default(DetectorState):
    pass

class CreateMap_Gnd(CreateMap_Default):

    def Entry(self, fsm):
        ctxt = fsm.getOwner()
        ctxt.set_create_flag()
        ctxt.reset_counter()

    def Exit(self, fsm):
        ctxt = fsm.getOwner()
        ctxt.reset_create_flag()

    def Default(self, fsm):
        fsm.getState().Exit(fsm)
        fsm.setState(CreateMap.Error)
        fsm.getState().Entry(fsm)

    def digit(self, fsm):
        fsm.getState().Exit(fsm)
        fsm.setState(CreateMap.Error)
        fsm.getState().Entry(fsm)

    def digit(self, fsm, lt):
        ctxt = fsm.getOwner()
        if ctxt.counter() :
            endState = fsm.getState()
            fsm.clearState()
            try:
                ctxt.var_update(lt)
                ctxt.inc_counter()
            finally:
                fsm.setState(endState)
        else:
            CreateMap_Default.digit(self, fsm, lt)
        
    def letter(self, fsm, lt):
        ctxt = fsm.getOwner()
        endState = fsm.getState()
        fsm.clearState()
        try:
            ctxt.var_update(lt)
            ctxt.inc_counter()
        finally:
            fsm.setState(endState)

    def obracket(self, fsm):
        ctxt = fsm.getOwner()
        if ctxt.counter() :
            fsm.getState().Exit(fsm)
            fsm.clearState()
            try:
                ctxt.reset_counter()
            finally:
                fsm.setState(CreateMap.Args)
                fsm.getState().Entry(fsm)
        else:
            CreateMap_Default.obracket(self, fsm)
        
    def space(self, fsm):
        ctxt = fsm.getOwner()
        if ctxt.var_is_join() :
            # No actions.
            pass
            fsm.pushState(JoinMap.OtherVar)
            fsm.getState().Entry(fsm)
        else:
            CreateMap_Default.space(self, fsm)
        
class CreateMap_Args(CreateMap_Default):

    def Entry(self, fsm):
        ctxt = fsm.getOwner()
        ctxt.set_create_flag()

    def Default(self, fsm):
        fsm.getState().Exit(fsm)
        fsm.setState(CreateMap.Error)
        fsm.getState().Entry(fsm)

    def cbracket(self, fsm):
        ctxt = fsm.getOwner()
        if ctxt.args() or ctxt.counter() :
            fsm.getState().Exit(fsm)
            fsm.clearState()
            try:
                ctxt.arg_append()
            finally:
                fsm.setState(CreateMap.Acceptable)
                fsm.getState().Entry(fsm)
        else:
            fsm.getState().Exit(fsm)
            # No actions.
            pass
            fsm.setState(CreateMap.Error)
            fsm.getState().Entry(fsm)


    def comma(self, fsm):
        ctxt = fsm.getOwner()
        if ctxt.counter() :
            endState = fsm.getState()
            fsm.clearState()
            try:
                ctxt.arg_append()
                ctxt.reset_counter()
            finally:
                fsm.setState(endState)
        else:
            CreateMap_Default.comma(self, fsm)
        
    def digit(self, fsm):
        fsm.getState().Exit(fsm)
        fsm.setState(CreateMap.Error)
        fsm.getState().Entry(fsm)

    def digit(self, fsm, lt):
        ctxt = fsm.getOwner()
        if ctxt.counter() :
            endState = fsm.getState()
            fsm.clearState()
            try:
                ctxt.arg_update(lt)
                ctxt.inc_counter()
            finally:
                fsm.setState(endState)
        else:
            CreateMap_Default.digit(self, fsm, lt)
        
    def letter(self, fsm, lt):
        ctxt = fsm.getOwner()
        endState = fsm.getState()
        fsm.clearState()
        try:
            ctxt.arg_update(lt)
            ctxt.inc_counter()
        finally:
            fsm.setState(endState)

    def space(self, fsm):
        fsm.getState().Exit(fsm)
        fsm.setState(CreateMap.Error)
        fsm.getState().Entry(fsm)

class CreateMap_Acceptable(CreateMap_Default):

    def Default(self, fsm):
        fsm.getState().Exit(fsm)
        fsm.setState(CreateMap.Error)
        fsm.getState().Entry(fsm)

    def EOS(self, fsm):
        # No actions.
        pass

class CreateMap_Error(CreateMap_Default):

    def Entry(self, fsm):
        ctxt = fsm.getOwner()
        ctxt.reset_create_flag()
        ctxt.unacceptable()

    def Default(self, fsm):
        # No actions.
        pass

class CreateMap(object):

    Gnd = CreateMap_Gnd('CreateMap.Gnd', 3)
    Args = CreateMap_Args('CreateMap.Args', 4)
    Acceptable = CreateMap_Acceptable('CreateMap.Acceptable', 5)
    Error = CreateMap_Error('CreateMap.Error', 6)
    Default = CreateMap_Default('CreateMap.Default', -1)

class JoinMap_Default(DetectorState):
    pass

class JoinMap_Gnd(JoinMap_Default):

    def Entry(self, fsm):
        ctxt = fsm.getOwner()
        ctxt.set_join_flag()

    def Default(self, fsm):
        fsm.getState().Exit(fsm)
        fsm.setState(JoinMap.Error)
        fsm.getState().Entry(fsm)

    def letter(self, fsm, lt):
        ctxt = fsm.getOwner()
        endState = fsm.getState()
        fsm.clearState()
        try:
            ctxt.join_update(lt)
        finally:
            fsm.setState(endState)

    def space(self, fsm):
        ctxt = fsm.getOwner()
        if ctxt.join_is_join() :
            fsm.getState().Exit(fsm)
            fsm.clearState()
            try:
                ctxt.reset_counter()
            finally:
                fsm.setState(JoinMap.OtherVar)
                fsm.getState().Entry(fsm)
        else:
            JoinMap_Default.space(self, fsm)
        
class JoinMap_OtherVar(JoinMap_Default):

    def Entry(self, fsm):
        ctxt = fsm.getOwner()
        ctxt.set_join_flag()

    def Default(self, fsm):
        fsm.getState().Exit(fsm)
        fsm.setState(JoinMap.Error)
        fsm.getState().Entry(fsm)

    def EOS(self, fsm):
        ctxt = fsm.getOwner()
        if ctxt.counter() :
            fsm.getState().Exit(fsm)
            fsm.clearState()
            try:
                ctxt.reset_counter()
            finally:
                fsm.setState(JoinMap.Acceptable)
                fsm.getState().Entry(fsm)
        else:
            JoinMap_Default.EOS(self, fsm)
        
    def digit(self, fsm, lt):
        ctxt = fsm.getOwner()
        if ctxt.counter() :
            endState = fsm.getState()
            fsm.clearState()
            try:
                ctxt.other_var_update(lt)
                ctxt.inc_counter()
            finally:
                fsm.setState(endState)
        else:
            JoinMap_Default.digit(self, fsm, lt)
        
    def letter(self, fsm, lt):
        ctxt = fsm.getOwner()
        endState = fsm.getState()
        fsm.clearState()
        try:
            ctxt.other_var_update(lt)
            ctxt.inc_counter()
        finally:
            fsm.setState(endState)

class JoinMap_Error(JoinMap_Default):

    def Entry(self, fsm):
        ctxt = fsm.getOwner()
        ctxt.reset_join_flag()
        ctxt.unacceptable()

    def Default(self, fsm):
        # No actions.
        pass

class JoinMap_Acceptable(JoinMap_Default):

    def Default(self, fsm):
        fsm.getState().Exit(fsm)
        fsm.setState(JoinMap.Error)
        fsm.getState().Entry(fsm)

class JoinMap(object):

    Gnd = JoinMap_Gnd('JoinMap.Gnd', 7)
    OtherVar = JoinMap_OtherVar('JoinMap.OtherVar', 8)
    Error = JoinMap_Error('JoinMap.Error', 9)
    Acceptable = JoinMap_Acceptable('JoinMap.Acceptable', 10)
    Default = JoinMap_Default('JoinMap.Default', -1)

class Detector_sm(statemap.FSMContext):

    def __init__(self, owner):
        statemap.FSMContext.__init__(self, MainMap.Gnd)
        self._owner = owner

    def __getattr__(self, attrib):
        def trans_sm(*arglist):
            self._transition = attrib
            getattr(self.getState(), attrib)(self, *arglist)
            self._transition = None
        return trans_sm

    def enterStartState(self):
        self._state.Entry(self)

    def getOwner(self):
        return self._owner

# Local variables:
#  buffer-read-only: t
# End:
