-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathjavascript.py
122 lines (91 loc) · 3.49 KB
/
javascript.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
try:
import expand_to_word
import expand_to_subword
import expand_to_word_with_dots
import expand_to_symbols
import expand_to_quotes
import expand_to_semantic_unit
import utils
except:
from . import expand_to_word
from . import expand_to_subword
from . import expand_to_word_with_dots
from . import expand_to_symbols
from . import expand_to_quotes
from . import expand_to_semantic_unit
from . import utils
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
if utils.is_debug_enabled:
print("ExpandRegion, javascript.py, None")
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
# expand_stack.append("line")
# result = expand_to_line.expand_to_line(string, start, end)
# if result:
# result["expand_stack"] = expand_stack
# return result
# return 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