def cut_greater_or_equal(self, End): """Cuts out any range that is above or equal 'End'.""" for i, x in r_enumerate(self.__intervals): if x.begin < End: break else: del self.__intervals[:] return # HERE: '__intervals[i]' is the first interval that # intersects with 'End-oo' if x.end > End: x.end = End if i == len(self.__intervals): return # Delete all intervals that where skipped. del self.__intervals[i+1:]
def prune(TriggerMap, Begin, End): """Cut out any element in the trigger map which lies beyong [Begin:End) """ L = len(TriggerMap) # Iterate from 'low' to 'high' begin_i = None for i, info in enumerate(TriggerMap): interval, target = info if interval.end <= Begin: continue # Found an interval that intersects with 'Begin' line if interval.begin < Begin: interval.begin = Begin begin_i = i break if begin_i is None: del TriggerMap[:] # No element is in range elif begin_i != 0: del TriggerMap[:begin_i] # Iterate from 'high' to 'low' end_i = None for i, info in r_enumerate(TriggerMap): interval, target = info if interval.begin >= End: continue # Found an interval that intersects with 'End' line if interval.end > End: interval.end = End end_i = i break if end_i is None: del TriggerMap[:] # No element in range elif end_i != L - 1: del TriggerMap[end_i + 1:] # Delete all intervals which have become empty i = 0 size = len(TriggerMap) while i < size: if TriggerMap[i][0].begin == TriggerMap[i][0].end: del TriggerMap[i] size -= 1 else: i += 1 return
def prune(TriggerMap, Begin, End): """Cut out any element in the trigger map which lies beyong [Begin:End) """ L = len(TriggerMap) # Iterate from 'low' to 'high' begin_i = None for i, info in enumerate(TriggerMap): interval, target = info if interval.end <= Begin: continue # Found an interval that intersects with 'Begin' line if interval.begin < Begin: interval.begin = Begin begin_i = i break if begin_i is None: del TriggerMap[:] # No element is in range elif begin_i != 0: del TriggerMap[:begin_i] # Iterate from 'high' to 'low' end_i = None for i, info in r_enumerate(TriggerMap): interval, target = info if interval.begin >= End: continue # Found an interval that intersects with 'End' line if interval.end > End: interval.end = End end_i = i break if end_i is None: del TriggerMap[:] # No element in range elif end_i != L-1: del TriggerMap[end_i+1:] # Delete all intervals which have become empty i = 0 size = len(TriggerMap) while i < size: if TriggerMap[i][0].begin == TriggerMap[i][0].end: del TriggerMap[i] size -= 1 else: i += 1 return
def integrate_path_in_result(self): #print "#integrate_path_in_result:" #for i, x in enumerate(self.path): # try: #print "# [%i] %s, %s, %s" % (i, x[0], x[1], x[2].get_string(Option="utf8")) # except: #print "# [%i] %s" % (i, x) for k, info in r_enumerate(self.path): dummy, bi, dummy = info if bi != self.operation_index and self.admissible.states[ bi].is_acceptance(): first_remainder_k = k + 1 # (ai, bi) is cut; next state is good break else: first_remainder_k = 1 if first_remainder_k == len(self.path): # The last element of the path is an acceptance in SM_B, thus it is cut too. return # Nothing left. #print "#first_remainder_k:", first_remainder_k ai, bi, trigger_set = self.path[first_remainder_k] #print "#ai, bi:", ai, bi state_index, state = self.get_state(ai, bi) if state_index != self.result.init_state_index: ##print "#(%s, %s) %s -- epsilon --> %s" % (ai, bi, self.result.init_state_index, state_index) self.result.get_init_state().target_map.add_transition( trigger_set, state_index) #print "#state.target_map:", state.target_map.get_map() #old_ti = state_index for ai, bi, trigger_set in islice(self.path, first_remainder_k + 1, None): target_index, target_state = self.get_state(ai, bi) state.add_transition(trigger_set, target_index) #print "# %i -- %s --> %s" % (old_ti, trigger_set.get_utf8_string(), target_index) state = target_state #old_ti = target_index return
def integrate_path_in_result(self): #print "#integrate_path_in_result:" #for i, x in enumerate(self.path): # try: #print "# [%i] %s, %s, %s" % (i, x[0], x[1], x[2].get_string(Option="utf8")) # except: #print "# [%i] %s" % (i, x) for k, info in r_enumerate(self.path): dummy, bi, dummy = info if bi != self.operation_index and self.admissible.states[bi].is_acceptance(): first_remainder_k = k + 1 # (ai, bi) is cut; next state is good break else: first_remainder_k = 1 if first_remainder_k == len(self.path): # The last element of the path is an acceptance in SM_B, thus it is cut too. return # Nothing left. #print "#first_remainder_k:", first_remainder_k ai, bi, trigger_set = self.path[first_remainder_k] #print "#ai, bi:", ai, bi state_index, state = self.get_state(ai, bi) if state_index != self.result.init_state_index: ##print "#(%s, %s) %s -- epsilon --> %s" % (ai, bi, self.result.init_state_index, state_index) self.result.get_init_state().target_map.add_transition(trigger_set, state_index) #print "#state.target_map:", state.target_map.get_map() #old_ti = state_index for ai, bi, trigger_set in islice(self.path, first_remainder_k+1, None): target_index, target_state = self.get_state(ai, bi) state.add_transition(trigger_set, target_index) #print "# %i -- %s --> %s" % (old_ti, trigger_set.get_utf8_string(), target_index) state = target_state #old_ti = target_index return
def TRY_terminal_delimiter_sequence(Mode, UnicodeSequence, UnicodeEndSequencePattern, UponReloadDoneAdr): UnicodeEndSequencePattern.prepare_count_info(Mode.counter_db, Setup.buffer_codec) # Trasform letter by letter. sequence = flatten_list_of_lists( transformation.do_character(x, Setup.buffer_codec) for x in UnicodeSequence) EndSequenceChunkN = len(sequence) # Column and line number count for closing delimiter run_time_counting_required_f, counter_txt = \ counter_for_pattern.get(UnicodeEndSequencePattern, ShiftF=False) # The Closer Delimiter must be a string. As such it has a pre-determined size. assert not run_time_counting_required_f # Column and line number count for 'normal' character. tm, column_counter_per_chunk = \ counter.get_XXX_counter_map(Mode.counter_db, "me->buffer._input_p", Trafo=Setup.buffer_codec) dummy, character_count_txt, dummy = \ counter.get_core_step(tm, "me->buffer._input_p") txt = [] for i, x in enumerate(sequence): txt.append(i) txt.append(Lng.IF_INPUT("==", "0x%X" % x, FirstF=True)) # Opening the 'if' txt.append(i + 1) txt.append("%s\n" % Lng.INPUT_P_INCREMENT()) Lng.INDENT(counter_txt, i + 1) if column_counter_per_chunk: txt.append(i + 1) if column_counter_per_chunk == UnicodeEndSequencePattern.count_info( ).column_n_increment_by_lexeme_length: txt += Lng.REEFERENCE_P_COLUMN_ADD("me->buffer._input_p", column_counter_per_chunk) else: txt += Lng.REEFERENCE_P_COLUMN_ADD( "(me->buffer._input_p - %i)" % EndSequenceChunkN, column_counter_per_chunk) txt.append(i + 1) txt.extend(counter_txt) txt.append(i + 1) txt.append("break;\n") for i, x in r_enumerate(sequence): txt.append(i) txt.append("%s" % Lng.IF_INPUT( "==", "0x%X" % Setup.buffer_limit_code, FirstF=False)) # Check BLC txt.append(i + 1) txt.append("%s\n" % Lng.LEXEME_START_SET("me->buffer._input_p - %i" % i)) txt.append(i + 1) txt.append( "%s\n" % Lng.GOTO_RELOAD(UponReloadDoneAdr, True, engine.FORWARD)) # Reload if i == 0: break txt.append(i) txt.append("%s" % Lng.ELSE) txt.append(i + 1) txt.append("%s\n" % Lng.INPUT_P_ADD(-i)) txt.append(i) txt.append("%s\n" % Lng.END_IF()) txt.append(i) txt.append("%s\n" % Lng.END_IF()) txt.extend(character_count_txt) # print "##DEBUG:\n%s" % "".join(Lng.GET_PLAIN_STRINGS(txt)) return txt
def TRY_terminal_delimiter_sequence(Mode, UnicodeSequence, UnicodeEndSequencePattern, UponReloadDoneAdr): UnicodeEndSequencePattern.prepare_count_info(Mode.counter_db, Setup.buffer_codec) # Trasform letter by letter. sequence = flatten_list_of_lists( transformation.do_character(x, Setup.buffer_codec) for x in UnicodeSequence ) EndSequenceChunkN = len(sequence) # Column and line number count for closing delimiter run_time_counting_required_f, counter_txt = \ counter_for_pattern.get(UnicodeEndSequencePattern, ShiftF=False) # The Closer Delimiter must be a string. As such it has a pre-determined size. assert not run_time_counting_required_f # Column and line number count for 'normal' character. tm, column_counter_per_chunk = \ counter.get_XXX_counter_map(Mode.counter_db, "me->buffer._input_p", Trafo=Setup.buffer_codec) dummy, character_count_txt, dummy = \ counter.get_core_step(tm, "me->buffer._input_p") txt = [] for i, x in enumerate(sequence): txt.append(i) txt.append(Lng.IF_INPUT("==", "0x%X" % x, FirstF=True)) # Opening the 'if' txt.append(i+1) txt.append("%s\n" % Lng.INPUT_P_INCREMENT()) Lng.INDENT(counter_txt, i+1) if column_counter_per_chunk: txt.append(i+1) if column_counter_per_chunk == UnicodeEndSequencePattern.count_info().column_n_increment_by_lexeme_length: txt += Lng.REEFERENCE_P_COLUMN_ADD("me->buffer._input_p", column_counter_per_chunk) else: txt += Lng.REEFERENCE_P_COLUMN_ADD("(me->buffer._input_p - %i)" % EndSequenceChunkN, column_counter_per_chunk) txt.append(i+1) txt.extend(counter_txt) txt.append(i+1) txt.append("break;\n") for i, x in r_enumerate(sequence): txt.append(i) txt.append("%s" % Lng.IF_INPUT("==", "0x%X" % Setup.buffer_limit_code, FirstF=False)) # Check BLC txt.append(i+1) txt.append("%s\n" % Lng.LEXEME_START_SET("me->buffer._input_p - %i" % i)) txt.append(i+1) txt.append("%s\n" % Lng.GOTO_RELOAD(UponReloadDoneAdr, True, engine.FORWARD)) # Reload if i == 0: break txt.append(i) txt.append("%s" % Lng.ELSE) txt.append(i+1) txt.append("%s\n" % Lng.INPUT_P_ADD(- i)) txt.append(i) txt.append("%s\n" % Lng.END_IF()) txt.append(i) txt.append("%s\n" % Lng.END_IF()) txt.extend(character_count_txt) # print "##DEBUG:\n%s" % "".join(Lng.GET_PLAIN_STRINGS(txt)) return txt