Example #1
0
def _add_newline(psml, SmNewlineOriginal):
    """Add a pair (newline state machine, terminal on newline) to 'psml'.

    When a newline occurs, the column count can be set to 1 and the line number
    is incremented. Then the indentation counting restarts.
    """
    assert SmNewlineOriginal is not None

    # Disconnect from machines being used elsewhere.
    SmNewline = SmNewlineOriginal.clone()
    SmNewline.set_id(dial_db.new_incidence_id())

    # The SmNewline has been used before in the main state machine with a
    # different incidence id. It is essential to clone!

    cl = [
        Op.LineCountAdd(1),
        Op.AssignConstant(E_R.Column, 1),
        Op.GotoDoorId(DoorID.incidence(E_IncidenceIDs.INDENTATION_HANDLER))
    ]
    terminal = Terminal(CodeTerminal(Lng.COMMAND_LIST(cl)),
                        "<INDENTATION NEWLINE>")
    terminal.set_incidence_id(SmNewline.get_id())

    psml.append((SmNewline, terminal))
Example #2
0
def _add_suppressed_newline(psml, SmSuppressedNewlineOriginal):
    """Add a pair (suppressed newline, terminal on suppressed newline to 'psml'.

    A suppresed newline is not like a newline--the next line is considered as 
    being appended to the current line. Nevertheless the line number needs to
    incremented, just the column number is not reset to 1. Then, it continues
    with indentation counting.
    """
    if SmSuppressedNewlineOriginal is None:
        return

    # Disconnect from machines being used elsewhere.
    SmSuppressedNewline = SmSuppressedNewlineOriginal.clone()
    SmSuppressedNewline.set_id(dial_db.new_incidence_id())

    # The parser MUST ensure that if there is a newline suppressor, there MUST
    # be a newline being defined.

    cl = [
        Op.LineCountAdd(1),
        Op.AssignConstant(E_R.Column, 1),
        Op.GotoDoorId(DoorID.incidence(E_IncidenceIDs.INDENTATION_HANDLER)),
    ]
    terminal = Terminal(CodeTerminal(Lng.COMMAND_LIST(cl)),
                        "<INDENTATION SUPPRESSED NEWLINE>")
    terminal.set_incidence_id(SmSuppressedNewline.get_id())

    psml.append((SmSuppressedNewline, terminal))
Example #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)
                ]
Example #4
0
}

cc_type_name_db = dict((value, key) for key, value in cc_type_db.iteritems())

count_operation_db_without_reference = {
    E_CharacterCountType.BAD:    lambda Parameter, Dummy=None, Dummy2=None: [ 
        Op.GotoDoorId(Parameter)
    ],
    E_CharacterCountType.COLUMN: lambda Parameter, Dummy=None, Dummy2=None: [
        Op.ColumnCountAdd(Parameter)
    ],
    E_CharacterCountType.GRID:   lambda Parameter, Dummy=None, Dummy2=None: [
        Op.ColumnCountGridAdd(Parameter)
    ],
    E_CharacterCountType.LINE:   lambda Parameter, Dummy=None, Dummy2=None: [
        Op.LineCountAdd(Parameter),
        Op.AssignConstant(E_R.Column, 1),
    ],
    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: [ 
    ],
}
Example #5
0
    def get_OpList(cls, LCCI, ModeName):
        """RETURN: [0] Verdict
                   [1] CounterCode

        Verdict == True  --> Run-time counter implementation required!!
                             Pattern's length cannot be determined beforehand.
                             
                   False --> No run-time counting is necessary!!
                             It was possible to determine the increments
                             based on the pattern's structure. 
                                 
        Default Character Counter is used when the increments and/or setting 
        cannot be derived from the pattern itself. 
        """
        if not (Setup.count_line_number_f or Setup.count_column_number_f):
            return False, []
        elif LCCI is None:
            return True, [Op.PasspartoutCounterCall(ModeName)]
        elif LCCI.run_time_counter_required_f:
            return True, [Op.PasspartoutCounterCall(ModeName)]

        # (*) Determine Line and Column Number Count ______________________________
        #
        #     Both, for line and column number considerations the same rules hold.
        #     Those rules are defined in 'get_offset()' as shown below.
        #
        def get_offset(Increment, IncrementByLexemeLength):
            if IncrementByLexemeLength == 0 or Increment == 0:
                return None, None
            elif Increment != E_Count.VOID:
                return Increment, 1
            else:
                return Lng.LEXEME_LENGTH(), IncrementByLexemeLength

        # Column and line counts must be shifted (begin=end) even if only
        # columns are counted. For example, even if only columns are modified
        # the old line_number_at_begin must be adapted to the current.
        cmd_list = [Op.ColumnCountShift(), Op.LineCountShift()]

        # -- Line Number Count
        offset, factor = get_offset(LCCI.line_n_increment,
                                    LCCI.line_n_increment_by_lexeme_length)
        if offset is not None:
            cmd_list.append(Op.LineCountAdd(offset, factor))

        # -- Column Number Count
        if LCCI.column_index != E_Count.VOID:
            cmd_list.append(Op.ColumnCountSet(LCCI.column_index + 1))

        elif LCCI.column_n_increment_by_lexeme_length != E_Count.VOID:
            offset, factor = get_offset(
                LCCI.column_n_increment,
                LCCI.column_n_increment_by_lexeme_length)
            if offset is not None:
                cmd_list.append(Op.ColumnCountAdd(offset, factor))

        else:
            # Following assert results from entry check against 'VOID'
            assert LCCI.grid_step_size_by_lexeme_length != E_Count.VOID

            if LCCI.grid_step_n == E_Count.VOID:
                grid_step_n = Lng.LEXEME_LENGTH()
            elif LCCI.grid_step_n != 0:
                grid_step_n = LCCI.grid_step_n
            else:
                grid_step_n = None

            if grid_step_n is not None:
                cmd_list.append(
                    Op.ColumnCountGridAdd(LCCI.grid_step_size_by_lexeme_length,
                                          grid_step_n))

        return False, cmd_list