def get_on_indentation_handler(Mode): # 'on_dedent' and 'on_n_dedent cannot be defined at the same time. assert not ( Mode.has_code_fragment_list("on_dedent") \ and Mode.has_code_fragment_list("on_n_dedent")) # A mode that deals only with the default indentation handler relies # on what is defined in '$QUEX_PATH/analayzer/member/on_indentation.i' if Mode.default_indentation_handler_sufficient(): return " return;" if Mode.has_code_fragment_list("on_indent"): on_indent_str, eol_f = action_code_formatter.get_code(Mode.get_code_fragment_list("on_indent")) else: on_indent_str = "self_send(__QUEX_SETTING_TOKEN_ID_INDENT);" if Mode.has_code_fragment_list("on_nodent"): on_nodent_str, eol_f = action_code_formatter.get_code(Mode.get_code_fragment_list("on_nodent")) else: on_nodent_str = "self_send(__QUEX_SETTING_TOKEN_ID_NODENT);" if Mode.has_code_fragment_list("on_dedent"): assert not Mode.has_code_fragment_list("on_n_dedent") on_dedent_str, eol_f = action_code_formatter.get_code(Mode.get_code_fragment_list("on_dedent")) on_n_dedent_str = "" elif Mode.has_code_fragment_list("on_n_dedent"): assert not Mode.has_code_fragment_list("on_dedent") on_n_dedent_str, eol_f = action_code_formatter.get_code(Mode.get_code_fragment_list("on_n_dedent")) on_dedent_str = "" else: # If no 'on_dedent' and no 'on_n_dedent' is defined ... on_dedent_str = "" on_n_dedent_str = "#if defined(QUEX_OPTION_TOKEN_REPETITION_SUPPORT)\n" on_n_dedent_str += " self_send_n(ClosedN, __QUEX_SETTING_TOKEN_ID_DEDENT);\n" on_n_dedent_str += "#else\n" on_n_dedent_str += " while( start-- != stack->back ) self_send(__QUEX_SETTING_TOKEN_ID_DEDENT);\n" on_n_dedent_str += "#endif\n" if not Mode.has_code_fragment_list("on_indentation_error"): # Default: Blow the program if there is an indentation error. on_indentation_error = 'QUEX_ERROR_EXIT("Lexical analyzer mode \'%s\': indentation error detected!\\n"' \ % Mode.name + \ ' "No \'on_indentation_error\' handler has been specified.\\n");' else: on_indentation_error, eol_f = action_code_formatter.get_code(Mode.get_code_fragment_list("on_indentation_error")) # Note: 'on_indentation_bad' is applied in code generation for # indentation counter in 'indentation_counter.py'. txt = blue_print(on_indentation_str, [["$$INDENT-PROCEDURE$$", on_indent_str], ["$$NODENT-PROCEDURE$$", on_nodent_str], ["$$DEDENT-PROCEDURE$$", on_dedent_str], ["$$N-DEDENT-PROCEDURE$$", on_n_dedent_str], ["$$INDENTATION-ERROR-PROCEDURE$$", on_indentation_error]]) return txt
def get_on_skip_range_open(Mode, CloserSequence): """For unit tests 'Mode' may actually be a string, so that we do not have to generate a whole mode just to get the 'on_skip_range_open' code fragment. """ if Mode == None: return "" txt = "" if type(Mode) in [str, unicode]: txt += Mode elif not Mode.has_code_fragment_list("on_skip_range_open"): txt += 'QUEX_ERROR_EXIT("\\nLexical analyzer mode \'%s\':\\n"\n' % Mode.name + \ ' "End of file occured before closing skip range delimiter!\\n"' + \ ' "The \'on_skip_range_open\' handler has not been specified.");' else: closer_string = "" for letter in CloserSequence: closer_string += utf8.unicode_to_pretty_utf8(letter).replace( "'", "") code, eol_f = action_code_formatter.get_code( Mode.get_code_fragment_list("on_skip_range_open")) txt += "#define Closer \"%s\"\n" % closer_string txt += code txt += "#undef Closer\n" txt += "RETURN;\n" return txt
def get_on_skip_range_open(Mode, CloserSequence): """For unit tests 'Mode' may actually be a string, so that we do not have to generate a whole mode just to get the 'on_skip_range_open' code fragment. """ if Mode == None: return "" txt = "" if type(Mode) in [str, unicode]: txt += Mode elif not Mode.has_code_fragment_list("on_skip_range_open"): txt += 'QUEX_ERROR_EXIT("\\nLexical analyzer mode \'%s\':\\n"\n' % Mode.name + \ ' "End of file occured before closing skip range delimiter!\\n"' + \ ' "The \'on_skip_range_open\' handler has not been specified.");' else: closer_string = "" for letter in CloserSequence: closer_string += utf8.unicode_to_pretty_utf8(letter).replace("'", "") code, eol_f = action_code_formatter.get_code(Mode.get_code_fragment_list("on_skip_range_open")) txt += "#define Closer \"%s\"\n" % closer_string txt += code txt += "#undef Closer\n" txt += "RETURN;\n" return txt
def get_bad_character_handler(Mode, IndentationSetup, CounterIdx): if Mode == None: return "" if IndentationSetup.bad_character_set.get().is_empty(): return "" txt = "INDENTATION_COUNTER_%i_BAD_CHARACTER:\n" % CounterIdx if not Mode.has_code_fragment_list("on_indentation_bad"): txt += 'QUEX_ERROR_EXIT("Lexical analyzer mode \'%s\': bad indentation character detected!\\n"' \ % Mode.name + \ ' "No \'on_indentation_bad\' handler has been specified.\\n");' else: code, eol_f = action_code_formatter.get_code(Mode.get_code_fragment_list("on_indentation_bad")) txt += "#define BadCharacter ((QUEX_TYPE_CHARACTER)*(me->buffer._input_p))\n" txt += code txt += "#undef BadCharacter\n" return txt
def get_on_indentation_handler(Mode): # 'on_dedent' and 'on_n_dedent cannot be defined at the same time. assert not ( Mode.has_code_fragment_list("on_dedent") \ and Mode.has_code_fragment_list("on_n_dedent")) # A mode that deals only with the default indentation handler relies # on what is defined in '$QUEX_PATH/analayzer/member/on_indentation.i' if Mode.default_indentation_handler_sufficient(): return " return;" if Mode.has_code_fragment_list("on_indent"): on_indent_str, eol_f = action_code_formatter.get_code( Mode.get_code_fragment_list("on_indent")) else: on_indent_str = "self_send(__QUEX_SETTING_TOKEN_ID_INDENT);" if Mode.has_code_fragment_list("on_nodent"): on_nodent_str, eol_f = action_code_formatter.get_code( Mode.get_code_fragment_list("on_nodent")) else: on_nodent_str = "self_send(__QUEX_SETTING_TOKEN_ID_NODENT);" if Mode.has_code_fragment_list("on_dedent"): assert not Mode.has_code_fragment_list("on_n_dedent") on_dedent_str, eol_f = action_code_formatter.get_code( Mode.get_code_fragment_list("on_dedent")) on_n_dedent_str = "" elif Mode.has_code_fragment_list("on_n_dedent"): assert not Mode.has_code_fragment_list("on_dedent") on_n_dedent_str, eol_f = action_code_formatter.get_code( Mode.get_code_fragment_list("on_n_dedent")) on_dedent_str = "" else: # If no 'on_dedent' and no 'on_n_dedent' is defined ... on_dedent_str = "" on_n_dedent_str = "#if defined(QUEX_OPTION_TOKEN_REPETITION_SUPPORT)\n" on_n_dedent_str += " self_send_n(ClosedN, __QUEX_SETTING_TOKEN_ID_DEDENT);\n" on_n_dedent_str += "#else\n" on_n_dedent_str += " while( start-- != stack->back ) self_send(__QUEX_SETTING_TOKEN_ID_DEDENT);\n" on_n_dedent_str += "#endif\n" if not Mode.has_code_fragment_list("on_indentation_error"): # Default: Blow the program if there is an indentation error. on_indentation_error = 'QUEX_ERROR_EXIT("Lexical analyzer mode \'%s\': indentation error detected!\\n"' \ % Mode.name + \ ' "No \'on_indentation_error\' handler has been specified.\\n");' else: on_indentation_error, eol_f = action_code_formatter.get_code( Mode.get_code_fragment_list("on_indentation_error")) # Note: 'on_indentation_bad' is applied in code generation for # indentation counter in 'indentation_counter.py'. txt = blue_print( on_indentation_str, [["$$INDENT-PROCEDURE$$", on_indent_str], ["$$NODENT-PROCEDURE$$", on_nodent_str], ["$$DEDENT-PROCEDURE$$", on_dedent_str], ["$$N-DEDENT-PROCEDURE$$", on_n_dedent_str], ["$$INDENTATION-ERROR-PROCEDURE$$", on_indentation_error]]) return txt