def expand_to_subword(string, start, end): # if it is an upper case word search for upper case chars # else search for lower case chars if (_is_inside_upper(string, start, end)): regex = re.compile(r"[A-Z]") else: regex = re.compile(r"[a-z]") result = expand_to_regex_set._expand_to_regex_rule(string, start, end, regex, "subword") if result is None: return None # check if it is prefixed by an upper char # expand from camelC|ase| to camel|Case| upper = re.compile(r"[A-Z]") if upper.match(string[result["start"] - 1:result["start"]]): result["start"] -= 1 # check that it is a "true" subword, i.e. inside a word if not _is_true_subword(string, result): return None return result
def expand_to_subword(string, start, end): # if it is an upper case word search for upper case chars # else search for lower case chars if(_is_inside_upper(string, start, end)): regex = re.compile(r"[A-Z]") else: regex = re.compile(r"[a-z]") result = expand_to_regex_set._expand_to_regex_rule( string, start, end, regex, "subword") if result is None: return None # check if it is prefixed by an upper char # expand from camelC|ase| to camel|Case| upper = re.compile(r"[A-Z]") if upper.match(string[result["start"]-1:result["start"]]): result["start"] -= 1 # check that it is a "true" subword, i.e. inside a word if not _is_true_subword(string, result): return None return result
def expand_to_word(string, startIndex, endIndex): regex = re.compile(r"[\w$]", re.UNICODE) return expand_to_regex_set._expand_to_regex_rule(string, startIndex, endIndex, regex, "word")
def expand_to_word(string, startIndex, endIndex): regex = re.compile("[a-zA-Z0-9$]"); return expand_to_regex_set._expand_to_regex_rule(string, startIndex, endIndex, regex, "word")
def expand_to_word_with_dots(string, startIndex, endIndex): regex = re.compile("[a-zA-Z0-9_$.]") return expand_to_regex_set._expand_to_regex_rule(string, startIndex, endIndex, regex, "word_with_dots")
def expand_to_tex_word(string, start, end): """Expand to a valid latex word.""" regex = re.compile(r"[a-zA-Z@]", re.UNICODE) return expand_to_regex_set._expand_to_regex_rule(string, start, end, regex, "tex_word")
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_to_word_with_dots(string, startIndex, endIndex): regex = re.compile("[a-zA-Z0-9_$.]"); return expand_to_regex_set._expand_to_regex_rule(string, startIndex, endIndex, regex, "word_with_dots")
def expand_to_tex_word(string, start, end): """Expand to a valid latex word.""" regex = re.compile(r"[a-zA-Z@]", re.UNICODE) return expand_to_regex_set._expand_to_regex_rule( string, start, end, regex, "tex_word")
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