Пример #1
0
 def get_LexemeEndCheck_appendix(ccfactory, CC_Type):
     if not LexemeEndCheckF:
         return [Op.GotoDoorId(door_id_loop)]
     #
     #       .---------------.        ,----------.   no
     #   --->| Count Op |-------< LexemeEnd? >------> DoorIdOk
     #       '---------------'        '----+-----'
     #                                     | yes
     #                              .---------------.
     #                              |  Lexeme End   |
     #                              | Count Op |----> DoorIdOnLexemeEnd
     #                              '---------------'
     #
     elif ccfactory.requires_reference_p(
     ) and CC_Type == E_CharacterCountType.COLUMN:
         return [
             Op.GotoDoorIdIfInputPNotEqualPointer(door_id_loop,
                                                  E_R.LexemeEnd),
             Op.ColumnCountReferencePDeltaAdd(
                 E_R.InputP, ccfactory.column_count_per_chunk, False),
         ] + AfterBeyond
     else:
         return [
             Op.GotoDoorIdIfInputPNotEqualPointer(door_id_loop,
                                                  E_R.LexemeEnd),
         ] + AfterBeyond
Пример #2
0
    def __prepare(ColumnNPerChunk):
        """BEFORE RELOAD:
                                                           input_p
                                                           |
                [ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
                                            |
                                            reference_p
             
                     column_n += (input_p - reference_p) * C

              where C = ColumnNPerChunk

           AFTER RELOAD:

                 input_p
                 |
                [ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
                 |
                 reference_p
        """
        if ColumnNPerChunk is None:
            return [], [], [], []

        # When there is more than one chunk possibly involved, then it is
        # possible that reload happens in between one character. I such cases
        # the 'input_p' cannot be used as reference for delta-add. Here,
        # we must rely on the 'character begin_p'.
        if Setup.buffer_codec.variable_character_sizes_f():
            pointer = E_R.CharacterBeginP
        else:
            pointer = E_R.InputP

        on_begin = [Op.ColumnCountReferencePSet(pointer)]
        on_after_reload = [Op.ColumnCountReferencePSet(pointer)]
        on_end = [
            Op.ColumnCountReferencePDeltaAdd(pointer, ColumnNPerChunk, False)
        ]
        on_before_reload = [
            Op.ColumnCountReferencePDeltaAdd(pointer, ColumnNPerChunk, False)
        ]

        return on_begin, on_end, on_before_reload, on_after_reload
Пример #3
0
    def _command(self, CC_Type, Parameter):
        if self.column_count_per_chunk is None:

            if CC_Type == E_CharacterCountType.BAD:
                return [Op.GotoDoorId(self.door_id_on_bad_indentation)]
            elif CC_Type == E_CharacterCountType.COLUMN:
                return [
                    Op.ColumnCountAdd(Parameter),
                ]
            elif CC_Type == E_CharacterCountType.GRID:
                return [
                    Op.ColumnCountGridAdd(Parameter),
                ]
            elif CC_Type == E_CharacterCountType.LINE:
                return [
                    Op.LineCountAdd(Parameter),
                    Op.AssignConstant(E_R.Column, 1),
                ]
        else:

            if CC_Type == E_CharacterCountType.BAD:
                return [
                    Op.ColumnCountReferencePDeltaAdd(
                        E_R.InputP, self.column_count_per_chunk, False),
                    Op.ColumnCountReferencePSet(E_R.InputP),
                    Op.GotoDoorId(self.door_id_on_bad_indentation)
                ]
            elif CC_Type == E_CharacterCountType.COLUMN:
                return []
            elif CC_Type == E_CharacterCountType.GRID:
                return [
                    Op.ColumnCountReferencePDeltaAdd(
                        E_R.InputP, self.column_count_per_chunk, True),
                    Op.ColumnCountGridAdd(Parameter),
                    Op.ColumnCountReferencePSet(E_R.InputP)
                ]
            elif CC_Type == E_CharacterCountType.LINE:
                return [
                    Op.LineCountAdd(Parameter),
                    Op.AssignConstant(E_R.Column, 1),
                    Op.ColumnCountReferencePSet(E_R.InputP)
                ]
Пример #4
0
    def get_loop_terminal_code(self, TheLoopMapEntry, DoorIdLoop,
                               DoorIdLoopExit):
        """RETURNS: A loop terminal. 

        A terminal: (i)    Counts,
                    (ii)   checks possibly for the lexeme end, and
                    (iii)a either re-enters the loop, or
                    (iii)b transits to an appendix state machine (couple terminal).
        """
        IncidenceId = TheLoopMapEntry.incidence_id
        AppendixSmId = TheLoopMapEntry.appendix_sm_id
        TheCountAction = TheLoopMapEntry.count_action

        code = []
        if TheCountAction is not None:
            code.extend(
                TheCountAction.get_OpList(self.column_number_per_code_unit))

        if AppendixSmId is not None:
            if not lei.appendix_sm_has_transitions_f:
                # If there is no appendix, directly goto to the terminal.
                code.extend([Op.GotoDoorId(DoorID.incidence_id(AppendixSmId))])
            else:
                assert not self.lexeme_end_check_f
                # Couple Terminal: transit to appendix state machine.
                code.extend([
                    Op.Assign(E_R.ReferenceP, E_R.InputP),
                    Op.GotoDoorId(DoorID.state_machine_entry(AppendixSmId))
                ])
        elif not self.lexeme_end_check_f:
            # Loop Terminal: directly re-enter loop.
            code.append(Op.GotoDoorId(DoorIdLoop))
        else:
            # Check Terminal: check against lexeme end before re-entering loop.
            code.append(
                Op.GotoDoorIdIfInputPNotEqualPointer(DoorIdLoop,
                                                     E_R.LexemeEnd))
            if     self.column_number_per_code_unit is not None \
               and TheCountAction is not None \
               and TheCountAction.cc_type == E_CharacterCountType.COLUMN:
                # With reference counting, no column counting while looping.
                # => Do it now, before leaving.
                code.append(
                    Op.ColumnCountReferencePDeltaAdd(
                        E_R.InputP, self.column_number_per_code_unit, False))
            code.append(Op.GotoDoorId(DoorIdLoopExit))

        return Terminal(CodeTerminal(Lng.COMMAND_LIST(code)),
                        "<LOOP TERMINAL %i>" % IncidenceId, IncidenceId)
Пример #5
0
 def _cmd_list_CA_LexemeEndCheck_GotoLoopEntry(self, CA):
     # Check Terminal: check against lexeme end before re-entering loop.
     cmd_list = [
         Op.GotoDoorIdIfInputPNotEqualPointer(self.Lazy_DoorIdLoop,
                                              E_R.LexemeEnd)
     ]
     if     self.column_number_per_code_unit is not None \
        and CA is not None and CA.cc_type == E_CharacterCountType.COLUMN:
         # With reference counting, no column counting while looping.
         # => Do it now, before leaving.
         cmd_list.append(
             Op.ColumnCountReferencePDeltaAdd(
                 E_R.InputP, self.column_number_per_code_unit, False))
     target_door_id = self.door_id_on_loop_exit_user_code
     return self._cmd_list_Frame(CA, cmd_list, target_door_id)
Пример #6
0
    E_CharacterCountType.LOOP_ENTRY: lambda Parameter, Dummy=None, Dummy2=None: [ 
    ],
    E_CharacterCountType.LOOP_EXIT: lambda Parameter, Dummy=None, Dummy2=None: [ 
    ],
    E_CharacterCountType.COLUMN_BEFORE_APPENDIX_SM: lambda Parameter, ColumnNPerCodeUnit, ColumnAdd: [
        Op.ColumnCountAdd(ColumnAdd)
    ],
    E_CharacterCountType.BEFORE_RELOAD: lambda Parameter, Dummy=None, Dummy2=None: [ 
    ],
    E_CharacterCountType.AFTER_RELOAD: lambda Parameter, Dummy=None, Dummy2=None: [ 
    ],
}

count_operation_db_with_reference = {
    E_CharacterCountType.BAD:    lambda Parameter, ColumnNPerCodeUnit, Dummy=None: [
        Op.ColumnCountReferencePDeltaAdd(E_R.InputP, ColumnNPerCodeUnit, False),
        Op.ColumnCountReferencePSet(E_R.InputP),
        Op.GotoDoorId(Parameter) 
    ],
    E_CharacterCountType.COLUMN: lambda Parameter, ColumnNPerCodeUnit, Dummy=None: [
    ],
    E_CharacterCountType.GRID:   lambda Parameter, ColumnNPerCodeUnit, Dummy=None: [
        Op.ColumnCountReferencePDeltaAdd(E_R.InputP, ColumnNPerCodeUnit, True),
        Op.ColumnCountGridAdd(Parameter),
        Op.ColumnCountReferencePSet(E_R.InputP)
    ],
    E_CharacterCountType.LINE:   lambda Parameter, ColumnNPerCodeUnit, Dummy=None: [
        Op.LineCountAdd(Parameter),
        Op.AssignConstant(E_R.Column, 1),
        Op.ColumnCountReferencePSet(E_R.InputP)
    ],