File src/ts/bash/TSBashLanguage.cpp changed (mode: 100644) (index e63dea4..93f6613) |
... |
... |
TsBashLanguage::TsBashLanguage() : tsLanguage(*tree_sitter_bash()) |
36 |
36 |
{ "comment", +TSBashSType::Comment }, |
{ "comment", +TSBashSType::Comment }, |
37 |
37 |
|
|
38 |
38 |
{ "program", +TSBashSType::Program }, |
{ "program", +TSBashSType::Program }, |
|
39 |
|
|
|
40 |
|
{ "command", +TSBashSType::Command }, |
|
41 |
|
{ "declaration_command", +TSBashSType::DeclarationCommand }, |
|
42 |
|
{ "negated_command", +TSBashSType::NegatedCommand }, |
|
43 |
|
{ "test_command", +TSBashSType::TestCommand }, |
|
44 |
|
{ "unset_command", +TSBashSType::UnsetCommand }, |
|
45 |
|
|
|
46 |
|
{ "_statement", +TSBashSType::Statement }, |
|
47 |
|
{ "c_style_for_statement", +TSBashSType::CStyleForStatement }, |
|
48 |
|
{ "case_statement", +TSBashSType::CaseStatement }, |
|
49 |
|
{ "compound_statement", +TSBashSType::CompoundStatement }, |
|
50 |
|
{ "for_statement", +TSBashSType::ForStatement }, |
|
51 |
|
{ "if_statement", +TSBashSType::IfStatement }, |
|
52 |
|
{ "while_statement", +TSBashSType::WhileStatement }, |
|
53 |
|
|
|
54 |
|
{ "variable_assignment", +TSBashSType::VariableAssignment }, |
|
55 |
|
|
|
56 |
|
{ "_expression", +TSBashSType::Expression }, |
|
57 |
|
{ "_primary_expression", +TSBashSType::PrimaryExpression }, |
|
58 |
|
{ "array", +TSBashSType::Array }, |
|
59 |
|
{ "binary_expression", +TSBashSType::BinaryExpression }, |
|
60 |
|
{ "case_item", +TSBashSType::CaseItem }, |
|
61 |
|
{ "command_name", +TSBashSType::CommandName }, |
|
62 |
|
{ "command_substitution", +TSBashSType::CommandSubstitution }, |
|
63 |
|
{ "concatenation", +TSBashSType::Concatenation }, |
|
64 |
|
{ "do_group", +TSBashSType::DoGroup }, |
|
65 |
|
{ "elif_clause", +TSBashSType::ElifClause }, |
|
66 |
|
{ "else_clause", +TSBashSType::ElseClause }, |
|
67 |
|
{ "expansion", +TSBashSType::Expansion }, |
|
68 |
|
{ "expansion_flags", +TSBashSType::ExpansionFlags }, |
|
69 |
|
{ "file_redirect", +TSBashSType::FileRedirect }, |
|
70 |
|
{ "function_definition", +TSBashSType::FunctionDefinition }, |
|
71 |
|
{ "heredoc_body", +TSBashSType::HeredocBody }, |
|
72 |
|
{ "heredoc_redirect", +TSBashSType::HeredocRedirect }, |
|
73 |
|
{ "herestring_redirect", +TSBashSType::HerestringRedirect }, |
|
74 |
|
{ "list", +TSBashSType::List }, |
|
75 |
|
{ "line_continuation", +TSBashSType::LineContinuation }, |
|
76 |
|
{ "parenthesized_expression", +TSBashSType::ParenthesizedExpression }, |
|
77 |
|
{ "pipeline", +TSBashSType::Pipeline }, |
|
78 |
|
{ "postfix_expression", +TSBashSType::PostfixExpression }, |
|
79 |
|
{ "process_substitution", +TSBashSType::ProcessSubstitution }, |
|
80 |
|
{ "redirected_statement", +TSBashSType::RedirectedStatement }, |
|
81 |
|
{ "simple_expansion", +TSBashSType::SimpleExpansion }, |
|
82 |
|
{ "string", +TSBashSType::String }, |
|
83 |
|
{ "string_content", +TSBashSType::StringContent }, |
|
84 |
|
{ "string_expansion", +TSBashSType::StringExpansion }, |
|
85 |
|
{ "subscript", +TSBashSType::Subscript }, |
|
86 |
|
{ "subshell", +TSBashSType::Subshell }, |
|
87 |
|
{ "ternary_expression", +TSBashSType::TernaryExpression }, |
|
88 |
|
{ "unary_expression", +TSBashSType::UnaryExpression }, |
|
89 |
|
{ "word", +TSBashSType::Word }, |
|
90 |
|
{ "ansii_c_string", +TSBashSType::AnsiiCString }, |
|
91 |
|
{ "comment", +TSBashSType::Comment }, |
|
92 |
|
{ "file_descriptor", +TSBashSType::FileDescriptor }, |
|
93 |
|
{ "heredoc_start", +TSBashSType::HeredocStart }, |
|
94 |
|
{ "raw_string", +TSBashSType::RawString }, |
|
95 |
|
{ "regex", +TSBashSType::Regex }, |
|
96 |
|
{ "special_variable_name", +TSBashSType::SpecialVariableName }, |
|
97 |
|
{ "test_operator", +TSBashSType::TestOperator }, |
|
98 |
|
{ "variable_name", +TSBashSType::VariableName }, |
39 |
99 |
}; |
}; |
40 |
100 |
|
|
41 |
101 |
types = { |
types = { |
|
102 |
|
{ "comment", Type::Comments }, |
|
103 |
|
{ "command_name", Type::Directives }, |
|
104 |
|
|
|
105 |
|
{ "special_variable_name", Type::UserTypes }, |
|
106 |
|
{ "variable_name", Type::UserTypes }, |
|
107 |
|
{ "$", Type::UserTypes }, |
|
108 |
|
|
|
109 |
|
{ "ansii_c_string", Type::StrConstants }, |
|
110 |
|
{ "raw_string", Type::StrConstants }, |
|
111 |
|
{ "string_content", Type::StrConstants }, |
|
112 |
|
{ "\"", Type::StrConstants }, |
|
113 |
|
|
|
114 |
|
{ "test_operator", Type::Operators }, |
|
115 |
|
|
|
116 |
|
{ "case", Type::Keywords }, |
|
117 |
|
{ "declare", Type::Keywords }, |
|
118 |
|
{ "do", Type::Keywords }, |
|
119 |
|
{ "done", Type::Keywords }, |
|
120 |
|
{ "elif", Type::Keywords }, |
|
121 |
|
{ "else", Type::Keywords }, |
|
122 |
|
{ "esac", Type::Keywords }, |
|
123 |
|
{ "export", Type::Keywords }, |
|
124 |
|
{ "fi", Type::Keywords }, |
|
125 |
|
{ "for", Type::Keywords }, |
|
126 |
|
{ "function", Type::Keywords }, |
|
127 |
|
{ "if", Type::Keywords }, |
|
128 |
|
{ "in", Type::Keywords }, |
|
129 |
|
{ "local", Type::Keywords }, |
|
130 |
|
{ "readonly", Type::Keywords }, |
|
131 |
|
{ "select", Type::Keywords }, |
|
132 |
|
{ "then", Type::Keywords }, |
|
133 |
|
{ "typeset", Type::Keywords }, |
|
134 |
|
{ "unset", Type::Keywords }, |
|
135 |
|
{ "unsetenv", Type::Keywords }, |
|
136 |
|
{ "until", Type::Keywords }, |
|
137 |
|
{ "while", Type::Keywords }, |
|
138 |
|
|
|
139 |
|
{ "&>", Type::Specifiers }, |
|
140 |
|
{ "&>>", Type::Specifiers }, |
|
141 |
|
{ ">", Type::Specifiers }, |
|
142 |
|
{ ">&", Type::Specifiers }, |
|
143 |
|
{ ">(", Type::Specifiers }, |
|
144 |
|
{ ">>", Type::Specifiers }, |
|
145 |
|
{ ">|", Type::Specifiers }, |
|
146 |
|
|
|
147 |
|
{ "==", Type::Comparisons }, |
|
148 |
|
{ "!=", Type::Comparisons }, |
|
149 |
|
{ "=~", Type::Comparisons }, |
|
150 |
|
{ "<=", Type::Comparisons }, |
|
151 |
|
{ ">=", Type::Comparisons }, |
|
152 |
|
|
|
153 |
|
{ "|", Type::Operators }, |
|
154 |
|
{ "|&", Type::Operators }, |
|
155 |
|
{ "||", Type::Operators }, |
|
156 |
|
{ "&&", Type::Operators }, |
|
157 |
|
{ "+", Type::Operators }, |
|
158 |
|
{ "++", Type::Operators }, |
|
159 |
|
{ "-", Type::Operators }, |
|
160 |
|
{ "--", Type::Operators }, |
|
161 |
|
|
|
162 |
|
{ "[", Type::LeftBrackets }, |
|
163 |
|
{ "]", Type::RightBrackets }, |
|
164 |
|
|
|
165 |
|
{ "[[", Type::LeftBrackets }, |
|
166 |
|
{ "]]", Type::RightBrackets }, |
|
167 |
|
|
|
168 |
|
{ "<(", Type::LeftBrackets }, |
|
169 |
|
{ "$(", Type::LeftBrackets }, |
|
170 |
|
{ "${", Type::LeftBrackets }, |
|
171 |
|
{ "(", Type::LeftBrackets }, |
|
172 |
|
{ ")", Type::RightBrackets }, |
|
173 |
|
|
|
174 |
|
{ "((", Type::LeftBrackets }, |
|
175 |
|
{ "))", Type::RightBrackets }, |
|
176 |
|
|
|
177 |
|
{ "{", Type::LeftBrackets }, |
|
178 |
|
{ "}", Type::RightBrackets }, |
|
179 |
|
|
|
180 |
|
{ "=", Type::Assignments }, |
|
181 |
|
{ "+=", Type::Assignments }, |
|
182 |
|
{ "-=", Type::Assignments }, |
42 |
183 |
}; |
}; |
|
184 |
|
|
|
185 |
|
// Unused: "!", "#", "%", "&", "/", ":", ":-", ":?", ";", ";&", ";;", ";;&", |
|
186 |
|
// "<", "<&", "<<", "<<-", "<<<", "?", "`" |
|
187 |
|
|
|
188 |
|
badNodes = { "\n" }; |
43 |
189 |
} |
} |
44 |
190 |
|
|
45 |
191 |
Type |
Type |
|
... |
... |
TsBashLanguage::isDiffable(const Node *x) const |
86 |
232 |
|
|
87 |
233 |
bool |
bool |
88 |
234 |
TsBashLanguage::isStructural(const Node *x) const |
TsBashLanguage::isStructural(const Node *x) const |
89 |
|
{ return Language::isStructural(x); } |
|
|
235 |
|
{ |
|
236 |
|
return Language::isStructural(x) |
|
237 |
|
|| -x->stype == TSBashSType::LineContinuation; |
|
238 |
|
} |
90 |
239 |
|
|
91 |
240 |
bool |
bool |
92 |
|
TsBashLanguage::isEolContinuation(const Node */*x*/) const |
|
93 |
|
{ return false; } |
|
|
241 |
|
TsBashLanguage::isEolContinuation(const Node *x) const |
|
242 |
|
{ return (-x->stype == TSBashSType::LineContinuation); } |
94 |
243 |
|
|
95 |
244 |
bool |
bool |
96 |
245 |
TsBashLanguage::alwaysMatches(const Node *x) const |
TsBashLanguage::alwaysMatches(const Node *x) const |
|
... |
... |
TsBashLanguage::isPseudoParameter(const Node */*x*/) const |
101 |
250 |
{ return false; } |
{ return false; } |
102 |
251 |
|
|
103 |
252 |
bool |
bool |
104 |
|
TsBashLanguage::shouldSplice(SType /*parent*/, const Node */*childNode*/) const |
|
105 |
|
{ return false; } |
|
|
253 |
|
TsBashLanguage::shouldSplice(SType parent, const Node *childNode) const |
|
254 |
|
{ |
|
255 |
|
return -parent == TSBashSType::FunctionDefinition |
|
256 |
|
&& -childNode->stype == TSBashSType::CompoundStatement; |
|
257 |
|
} |
106 |
258 |
|
|
107 |
259 |
bool |
bool |
108 |
260 |
TsBashLanguage::isValueNode(SType /*stype*/) const |
TsBashLanguage::isValueNode(SType /*stype*/) const |
|
... |
... |
TsBashLanguage::isValueNode(SType /*stype*/) const |
110 |
262 |
|
|
111 |
263 |
bool |
bool |
112 |
264 |
TsBashLanguage::isLayerBreak(SType /*parent*/, SType stype) const |
TsBashLanguage::isLayerBreak(SType /*parent*/, SType stype) const |
113 |
|
{ return isValueNode(stype); } |
|
|
265 |
|
{ |
|
266 |
|
return isValueNode(stype) |
|
267 |
|
|| -stype == TSBashSType::Command |
|
268 |
|
|| -stype == TSBashSType::DeclarationCommand |
|
269 |
|
|| -stype == TSBashSType::NegatedCommand |
|
270 |
|
|| -stype == TSBashSType::TestCommand |
|
271 |
|
|| -stype == TSBashSType::UnsetCommand |
|
272 |
|
|| -stype == TSBashSType::Statement |
|
273 |
|
|| -stype == TSBashSType::CStyleForStatement |
|
274 |
|
|| -stype == TSBashSType::CaseStatement |
|
275 |
|
|| -stype == TSBashSType::CompoundStatement |
|
276 |
|
|| -stype == TSBashSType::ForStatement |
|
277 |
|
|| -stype == TSBashSType::IfStatement |
|
278 |
|
|| -stype == TSBashSType::WhileStatement |
|
279 |
|
|| -stype == TSBashSType::VariableAssignment |
|
280 |
|
|| -stype == TSBashSType::FunctionDefinition; |
|
281 |
|
} |
114 |
282 |
|
|
115 |
283 |
bool |
bool |
116 |
284 |
TsBashLanguage::shouldDropLeadingWS(SType /*stype*/) const |
TsBashLanguage::shouldDropLeadingWS(SType /*stype*/) const |
|
... |
... |
TsBashLanguage::classify(SType stype) const |
127 |
295 |
case TSBashSType::Comment: |
case TSBashSType::Comment: |
128 |
296 |
return MType::Comment; |
return MType::Comment; |
129 |
297 |
|
|
|
298 |
|
case TSBashSType::DeclarationCommand: |
|
299 |
|
return MType::Declaration; |
|
300 |
|
|
|
301 |
|
case TSBashSType::Statement: |
|
302 |
|
case TSBashSType::CStyleForStatement: |
|
303 |
|
case TSBashSType::CaseStatement: |
|
304 |
|
case TSBashSType::CompoundStatement: |
|
305 |
|
case TSBashSType::ForStatement: |
|
306 |
|
case TSBashSType::IfStatement: |
|
307 |
|
case TSBashSType::WhileStatement: |
|
308 |
|
return MType::Statement; |
|
309 |
|
|
|
310 |
|
case TSBashSType::FunctionDefinition: |
|
311 |
|
return MType::Function; |
|
312 |
|
|
130 |
313 |
default: |
default: |
131 |
314 |
return MType::Other; |
return MType::Other; |
132 |
315 |
} |
} |
|
... |
... |
TsBashLanguage::classify(SType stype) const |
135 |
318 |
const char * |
const char * |
136 |
319 |
TsBashLanguage::toString(SType stype) const |
TsBashLanguage::toString(SType stype) const |
137 |
320 |
{ |
{ |
138 |
|
switch (-stype) { |
|
139 |
|
case TSBashSType::None: return "TSBashSType::None"; |
|
140 |
|
|
|
141 |
|
case TSBashSType::Separator: return "TSBashSType::Separator"; |
|
142 |
|
case TSBashSType::Comment: return "TSBashSType::Comment"; |
|
|
321 |
|
#define CASE(item) case TSBashSType::item: return "TSBashSType::" #item |
143 |
322 |
|
|
144 |
|
case TSBashSType::Program: return "TSBashSType::Program"; |
|
|
323 |
|
switch (-stype) { |
|
324 |
|
CASE(None); |
|
325 |
|
|
|
326 |
|
CASE(Separator); |
|
327 |
|
CASE(Comment); |
|
328 |
|
|
|
329 |
|
CASE(Program); |
|
330 |
|
|
|
331 |
|
CASE(Command); |
|
332 |
|
CASE(DeclarationCommand); |
|
333 |
|
CASE(NegatedCommand); |
|
334 |
|
CASE(TestCommand); |
|
335 |
|
CASE(UnsetCommand); |
|
336 |
|
|
|
337 |
|
CASE(Statement); |
|
338 |
|
CASE(CStyleForStatement); |
|
339 |
|
CASE(CaseStatement); |
|
340 |
|
CASE(CompoundStatement); |
|
341 |
|
CASE(ForStatement); |
|
342 |
|
CASE(IfStatement); |
|
343 |
|
CASE(WhileStatement); |
|
344 |
|
|
|
345 |
|
CASE(VariableAssignment); |
|
346 |
|
|
|
347 |
|
CASE(Expression); |
|
348 |
|
CASE(PrimaryExpression); |
|
349 |
|
CASE(Array); |
|
350 |
|
CASE(BinaryExpression); |
|
351 |
|
CASE(CaseItem); |
|
352 |
|
CASE(CommandName); |
|
353 |
|
CASE(CommandSubstitution); |
|
354 |
|
CASE(Concatenation); |
|
355 |
|
CASE(DoGroup); |
|
356 |
|
CASE(ElifClause); |
|
357 |
|
CASE(ElseClause); |
|
358 |
|
CASE(Expansion); |
|
359 |
|
CASE(ExpansionFlags); |
|
360 |
|
CASE(FileRedirect); |
|
361 |
|
CASE(FunctionDefinition); |
|
362 |
|
CASE(HeredocBody); |
|
363 |
|
CASE(HeredocRedirect); |
|
364 |
|
CASE(HerestringRedirect); |
|
365 |
|
CASE(List); |
|
366 |
|
CASE(LineContinuation); |
|
367 |
|
CASE(ParenthesizedExpression); |
|
368 |
|
CASE(Pipeline); |
|
369 |
|
CASE(PostfixExpression); |
|
370 |
|
CASE(ProcessSubstitution); |
|
371 |
|
CASE(RedirectedStatement); |
|
372 |
|
CASE(SimpleExpansion); |
|
373 |
|
CASE(String); |
|
374 |
|
CASE(StringContent); |
|
375 |
|
CASE(StringExpansion); |
|
376 |
|
CASE(Subscript); |
|
377 |
|
CASE(Subshell); |
|
378 |
|
CASE(TernaryExpression); |
|
379 |
|
CASE(UnaryExpression); |
|
380 |
|
CASE(Word); |
|
381 |
|
CASE(AnsiiCString); |
|
382 |
|
CASE(FileDescriptor); |
|
383 |
|
CASE(HeredocStart); |
|
384 |
|
CASE(RawString); |
|
385 |
|
CASE(Regex); |
|
386 |
|
CASE(SpecialVariableName); |
|
387 |
|
CASE(TestOperator); |
|
388 |
|
CASE(VariableName); |
145 |
389 |
} |
} |
146 |
390 |
|
|
147 |
391 |
assert(false && "Unhandled enumeration item"); |
assert(false && "Unhandled enumeration item"); |
148 |
392 |
return "<UNKNOWN>"; |
return "<UNKNOWN>"; |
|
393 |
|
|
|
394 |
|
#undef CASE |
149 |
395 |
} |
} |