def expand_agains_line(string, start, end): expand_stack = [] expand_stack.append("word") result = expand_to_word.expand_to_word(string, start, end) if result: result["expand_stack"] = expand_stack return result expand_stack.append("quotes") result = expand_to_quotes.expand_to_quotes(string, start, end) if result: result["expand_stack"] = expand_stack return result expand_stack.append("semantic_unit") result = expand_to_semantic_unit.expand_to_semantic_unit( string, start, end) if result: result["expand_stack"] = expand_stack return result expand_stack.append("symbols") result = expand_to_symbols.expand_to_symbols(string, start, end) if result: result["expand_stack"] = expand_stack return result
def _stretch_over_previous_semantic_unit(string, start): start -= 1 while chart_at(string, start) == " ": start -= 1 if chart_at(string, start) in ["]", "}"]: r = expand_to_symbols.expand_to_symbols(string, start, start) if r is not None: return r["start"] - 1 raise NoSemanticUnit()
def _stretch_over_previous_semantic_unit(string, start): start -= 1 while chart_at(string, start) == " ": start -= 1 if chart_at(string, start) in ["]", "}"]: r = expand_to_symbols.expand_to_symbols(string, start, start) if r is not None: return r["start"] - 1 raise NoSemanticUnit()
def _stretch_over_next_semantic_unit(string, end): while chart_at(string, end) == " ": end += 1 if chart_at(string, end) in ["[", "{"]: end += 1 r = expand_to_symbols.expand_to_symbols(string, end, end) if r is not None: end = r["end"] # special case: '{}' (no content) if end == r["start"] + 2: return end return end + 1 raise NoSemanticUnit()
def _stretch_over_next_semantic_unit(string, end): while chart_at(string, end) == " ": end += 1 if chart_at(string, end) in ["[", "{"]: end += 1 r = expand_to_symbols.expand_to_symbols(string, end, end) if r is not None: end = r["end"] # special case: '{}' (no content) if end == r["start"] + 2: return end return end + 1 raise NoSemanticUnit()
def expand(string, start, end): expand_stack = [] expand_stack.append("word") result = expand_to_word.expand_to_word(string, start, end) if result: result["expand_stack"] = expand_stack return result expand_stack.append("latex_command_base") result = expand_agains_base_command(string, start, end) if result: result["expand_stack"] = expand_stack return result expand_stack = ["latex_command_arg"] result = expand_against_command_args(string, start, end) if result: result["expand_stack"] = expand_stack return result expand_stack.append("latex_command_surround") result = expand_against_surrounding_command(string, start, end) if result: result["expand_stack"] = expand_stack return result expand_stack.append("latex_environment_matching") result = expand_against_matching_env(string, start, end) if result: result["expand_stack"] = expand_stack return result env_result = expand_against_env(string, start, end) # there might be a {} inside the environment sym_result = expand_to_symbols.expand_to_symbols(string, start, end) result = _closest_result(env_result, sym_result) if result == env_result: expand_stack.append("latex_environment") else: expand_stack.append("symbols") if result: result["expand_stack"] = expand_stack return result
def expand(string, start, end): selection_is_in_string = expand_to_quotes.expand_to_quotes( string, start, end) if selection_is_in_string: string_result = expand_agains_string( selection_is_in_string["string"], start - selection_is_in_string["start"], end - selection_is_in_string["start"]) if string_result: string_result["start"] = string_result[ "start"] + selection_is_in_string["start"] string_result[ "end"] = string_result["end"] + selection_is_in_string["start"] string_result[string] = string[ string_result["start"]:string_result["end"]] return string_result if utils.selection_contain_linebreaks(string, start, end) == False: line = utils.get_line(string, start, end) line_string = string[line["start"]:line["end"]] line_result = expand_agains_line(line_string, start - line["start"], end - line["start"]) if line_result: line_result["start"] = line_result["start"] + line["start"] line_result["end"] = line_result["end"] + line["start"] line_result[string] = string[ line_result["start"]:line_result["end"]] return line_result expand_stack = ["semantic_unit"] result = expand_to_semantic_unit.expand_to_semantic_unit( string, start, end) if result: result["expand_stack"] = expand_stack return result expand_stack.append("symbols") result = expand_to_symbols.expand_to_symbols(string, start, end) if result: result["expand_stack"] = expand_stack return result print(None)
def expand(string, start, end): selection_is_in_string = expand_to_quotes.expand_to_quotes( string, start, end) if selection_is_in_string: string_result = expand_agains_string( selection_is_in_string["string"], start - selection_is_in_string["start"], end - selection_is_in_string["start"]) if string_result: string_result["start"] = string_result[ "start"] + selection_is_in_string["start"] string_result[ "end"] = string_result["end"] + selection_is_in_string["start"] string_result[string] = string[string_result["start"]: string_result["end"]] return string_result if utils.selection_contain_linebreaks(string, start, end) == False: line = utils.get_line(string, start, end) line_string = string[line["start"]:line["end"]] line_result = expand_agains_line(line_string, start - line["start"], end - line["start"]) if line_result: line_result["start"] = line_result["start"] + line["start"] line_result["end"] = line_result["end"] + line["start"] line_result[string] = string[line_result["start"]: line_result["end"]] return line_result expand_stack = ["semantic_unit"] result = expand_to_semantic_unit.expand_to_semantic_unit( string, start, end) if result: result["expand_stack"] = expand_stack return result expand_stack.append("symbols") result = expand_to_symbols.expand_to_symbols(string, start, end) if result: result["expand_stack"] = expand_stack return result print(None)
def expand_agains_string(string, start, end): expand_stack = [] expand_stack.append("semantic_unit") result = expand_to_semantic_unit.expand_to_semantic_unit(string, start, end) if result: result["expand_stack"] = expand_stack return result expand_stack.append("symbols") result = expand_to_symbols.expand_to_symbols(string, start, end) if result: result["expand_stack"] = expand_stack return result
def expand_agains_string(string, start, end): expand_stack = [] expand_stack.append("semantic_unit") result = expand_to_semantic_unit.expand_to_semantic_unit(string, start, end) if result: result["expand_stack"] = expand_stack return result expand_stack.append("symbols") result = expand_to_symbols.expand_to_symbols(string, start, end) if result: result["expand_stack"] = expand_stack return result
def expand_agains_line(string, start, end): expand_stack = [] expand_stack.append("subword") result = expand_to_subword.expand_to_subword(string, start, end) if result: result["expand_stack"] = expand_stack return result expand_stack.append("word") result = expand_to_word.expand_to_word(string, start, end) if result: result["expand_stack"] = expand_stack return result expand_stack.append("quotes") result = expand_to_quotes.expand_to_quotes(string, start, end) if result: result["expand_stack"] = expand_stack return result expand_stack.append("semantic_unit") result = expand_to_semantic_unit.expand_to_semantic_unit( string, start, end) if result: result["expand_stack"] = expand_stack return result expand_stack.append("symbols") result = expand_to_symbols.expand_to_symbols(string, start, end) if result: result["expand_stack"] = expand_stack return result
def expand(string, start, end): expand_stack = [] expand_stack.append("tex_word") result = expand_to_tex_word(string, start, end) if result: result["expand_stack"] = expand_stack return result expand_stack.append("latex_command_base") result = expand_agains_base_command(string, start, end) if result: result["expand_stack"] = expand_stack return result expand_stack.append("tex_math_command") # expand to math commands, e.g. \phi_x^2 regex = re.compile(r"[\w\\@^]", re.UNICODE) result = expand_to_regex_set._expand_to_regex_rule(string, start, end, regex, "tex_math_command") if result: result["expand_stack"] = expand_stack return result expand_stack = ["latex_command_arg"] result = expand_against_command_args(string, start, end) if result: result["expand_stack"] = expand_stack return result expand_stack.append("latex_command_surround") result = expand_against_surrounding_command(string, start, end) if result: result["expand_stack"] = expand_stack return result expand_stack.append("latex_inline_math") result = expand_to_inline_math(string, start, end) if result: result["expand_stack"] = expand_stack return result expand_stack.append("latex_environment_matching") result = expand_against_matching_env(string, start, end) if result: result["expand_stack"] = expand_stack return result env_result = expand_against_env(string, start, end) # there might be a {} inside the environment sym_result = expand_to_symbols.expand_to_symbols(string, start, end) result = _closest_result(env_result, sym_result) if result == env_result: expand_stack.append("latex_environment") else: expand_stack.append("symbols") if result: result["expand_stack"] = expand_stack return result
def expand(string, start, end): expand_stack = [] expand_stack.append("tex_word") result = expand_to_tex_word(string, start, end) if result: result["expand_stack"] = expand_stack return result expand_stack.append("latex_command_base") result = expand_agains_base_command(string, start, end) if result: result["expand_stack"] = expand_stack return result expand_stack.append("tex_math_command") # expand to math commands, e.g. \phi_x^2 regex = re.compile(r"[\w\\@^]", re.UNICODE) result = expand_to_regex_set._expand_to_regex_rule( string, start, end, regex, "tex_math_command") if result: result["expand_stack"] = expand_stack return result expand_stack = ["latex_command_arg"] result = expand_against_command_args(string, start, end) if result: result["expand_stack"] = expand_stack return result expand_stack.append("latex_command_surround") result = expand_against_surrounding_command(string, start, end) if result: result["expand_stack"] = expand_stack return result expand_stack.append("latex_inline_math") result = expand_to_inline_math(string, start, end) if result: result["expand_stack"] = expand_stack return result expand_stack.append("latex_environment_matching") result = expand_against_matching_env(string, start, end) if result: result["expand_stack"] = expand_stack return result env_result = expand_against_env(string, start, end) # there might be a {} inside the environment sym_result = expand_to_symbols.expand_to_symbols(string, start, end) result = _closest_result(env_result, sym_result) if result == env_result: expand_stack.append("latex_environment") else: expand_stack.append("symbols") if result: result["expand_stack"] = expand_stack return result