示例#1
0
def _terminator(ast, scene, parent, states):
    ''' Create a TERMINATOR symbol '''
    if ast.label:
        # pylint: disable=E1111
        parent = render(ast.label, scene=scene, parent=parent, states=states)
    if ast.kind == 'next_state':
        LOG.debug('ADDING NEXT_STATE ' + ast.inputString)
        # Create a new state symbol
        symbol = sdlSymbols.State(parent=parent, ast=ast)
        # If the terminator is also a new state, render the inputs below
        LOG.debug('STATELIST:' + str([st.inputString for st in states]))
        for state_ast in states:
            if (state_ast.inputString == ast.inputString
                    and state_ast.pos_x == ast.pos_x
                    and state_ast.pos_y == ast.pos_y):
                LOG.debug('MERGING TERMINATOR "' + ast.inputString + '"')
                symbol.nested_scene = state_ast.composite or \
                                      ogAST.CompositeState()
                for each in chain(state_ast.inputs, state_ast.connects):
                    render(each, scene=scene, parent=symbol, states=states)
                break
        symbol.nested_scene = ast.composite or ogAST.CompositeState()
    elif ast.kind == 'join':
        symbol = sdlSymbols.Join(parent, ast)
    elif ast.kind in ('return', 'stop'):
        symbol = sdlSymbols.ProcedureStop(parent, ast)
    else:
        raise TypeError('Unsupported terminator: ' + repr(ast))
    return symbol
示例#2
0
def _state(ast, scene, states, terminators, parent=None):
    ''' Render a floating state and its inputs '''
    _ = parent
    # Discard the state if it is a terminator too as it is not a floating
    # state in that case: it will be rendered together with all its (possible)
    # INPUT children in the render_terminator function.
    for term in terminators:
        if (term.kind == 'next_state' and term.pos_x == ast.pos_x
                and term.pos_y == ast.pos_y
                and term.inputString == ast.inputString):
            raise TypeError('This state is a terminator')
    new_state = sdlSymbols.State(parent=None, ast=ast)
    if new_state not in scene.items():
        add_to_scene(new_state, scene)

    for exit in chain(ast.inputs, ast.connects):
        render(exit, scene=scene, parent=new_state, states=states)

    new_state.nested_scene = ast.composite or ogAST.CompositeState()

    return new_state