Merge pull request #3163 from techee/ocaml_parser
[geany-mirror.git] / src / tagmanager / tm_parser.c
blob7ab7411b382466380a67b27942a104afc9a29967
1 /*
2 * tm_parser.c - this file is part of Geany, a fast and lightweight IDE
4 * Copyright 2016 The Geany contributors
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "tm_parser.h"
22 #include "tm_ctags.h"
24 #include <string.h>
26 #include "config.h"
29 #ifdef GETTEXT_PACKAGE
30 # include <glib/gi18n-lib.h>
31 #else
32 # define _(String) String
33 # define N_(String) String
34 #endif
36 typedef struct
38 const gchar kind;
39 TMTagType type;
40 } TMParserMapEntry;
42 /* Allows remapping a subparser tag type to another type if there's a clash with
43 * the master parser tag type. Only subparser tag types explicitly listed within
44 * TMSubparserMapEntry maps are added to tag manager - tags with types not listed
45 * are discarded to prevent uncontrolled merging of tags from master parser and
46 * subparsers. */
47 typedef struct
49 TMTagType orig_type;
50 TMTagType new_type;
51 } TMSubparserMapEntry;
53 typedef struct
55 const gchar *name;
56 guint icon;
57 TMTagType types;
58 } TMParserMapGroup;
60 static GHashTable *subparser_map = NULL;
63 #define COMMON_C \
64 {'d', tm_tag_macro_t}, /* macro */ \
65 {'e', tm_tag_enumerator_t}, /* enumerator */ \
66 {'f', tm_tag_function_t}, /* function */ \
67 {'g', tm_tag_enum_t}, /* enum */ \
68 {'m', tm_tag_member_t}, /* member */ \
69 {'p', tm_tag_prototype_t}, /* prototype */ \
70 {'s', tm_tag_struct_t}, /* struct */ \
71 {'t', tm_tag_typedef_t}, /* typedef */ \
72 {'u', tm_tag_union_t}, /* union */ \
73 {'v', tm_tag_variable_t}, /* variable */ \
74 {'x', tm_tag_externvar_t}, /* externvar */ \
75 {'h', tm_tag_include_t}, /* header */ \
76 {'l', tm_tag_local_var_t}, /* local */ \
77 {'z', tm_tag_local_var_t}, /* parameter */ \
78 {'L', tm_tag_undef_t}, /* label */ \
79 {'D', tm_tag_undef_t}, /* macroparam */
81 static TMParserMapEntry map_C[] = {
82 COMMON_C
84 /* Used also by other languages than C - keep all the tm_tag_* here even though
85 * they aren't used by C as they might be used by some other language */
86 static TMParserMapGroup group_C[] = {
87 {N_("Namespaces"), TM_ICON_NAMESPACE, tm_tag_namespace_t | tm_tag_package_t | tm_tag_include_t},
88 {N_("Classes"), TM_ICON_CLASS, tm_tag_class_t},
89 {N_("Interfaces"), TM_ICON_STRUCT, tm_tag_interface_t},
90 {N_("Functions"), TM_ICON_METHOD, tm_tag_prototype_t | tm_tag_method_t | tm_tag_function_t},
91 {N_("Members"), TM_ICON_MEMBER, tm_tag_member_t | tm_tag_field_t},
92 {N_("Structs"), TM_ICON_STRUCT, tm_tag_union_t | tm_tag_struct_t},
93 {N_("Typedefs / Enums"), TM_ICON_STRUCT, tm_tag_typedef_t | tm_tag_enum_t},
94 {N_("Macros"), TM_ICON_MACRO, tm_tag_macro_t | tm_tag_macro_with_arg_t},
95 {N_("Variables"), TM_ICON_VAR, tm_tag_variable_t | tm_tag_enumerator_t | tm_tag_local_var_t},
96 {N_("Extern Variables"), TM_ICON_VAR, tm_tag_externvar_t},
97 {N_("Other"), TM_ICON_OTHER, tm_tag_other_t},
100 static TMParserMapEntry map_CPP[] = {
101 COMMON_C
102 {'c', tm_tag_class_t}, // class
103 {'n', tm_tag_namespace_t}, // namespace
104 {'A', tm_tag_undef_t}, // alias
105 {'N', tm_tag_undef_t}, // name
106 {'U', tm_tag_undef_t}, // using
107 {'Z', tm_tag_undef_t}, // tparam
109 #define group_CPP group_C
111 static TMParserMapEntry map_JAVA[] = {
112 {'c', tm_tag_class_t}, // class
113 {'f', tm_tag_field_t}, // field
114 {'i', tm_tag_interface_t}, // interface
115 {'m', tm_tag_method_t}, // method
116 {'p', tm_tag_package_t}, // package
117 {'e', tm_tag_enumerator_t}, // enumConstant
118 {'g', tm_tag_enum_t}, // enum
120 static TMParserMapGroup group_JAVA[] = {
121 {N_("Package"), TM_ICON_NAMESPACE, tm_tag_package_t},
122 {N_("Interfaces"), TM_ICON_STRUCT, tm_tag_interface_t},
123 {N_("Classes"), TM_ICON_CLASS, tm_tag_class_t},
124 {N_("Methods"), TM_ICON_METHOD, tm_tag_method_t},
125 {N_("Members"), TM_ICON_MEMBER, tm_tag_field_t},
126 {N_("Enums"), TM_ICON_STRUCT, tm_tag_enum_t},
127 {N_("Other"), TM_ICON_VAR, tm_tag_enumerator_t},
130 // no scope information
131 static TMParserMapEntry map_MAKEFILE[] = {
132 {'m', tm_tag_macro_t}, // macro
133 {'t', tm_tag_function_t}, // target
134 {'I', tm_tag_undef_t}, // makefile
136 static TMParserMapGroup group_MAKEFILE[] = {
137 {N_("Targets"), TM_ICON_METHOD, tm_tag_function_t},
138 {N_("Macros"), TM_ICON_MACRO, tm_tag_macro_t},
141 static TMParserMapEntry map_PASCAL[] = {
142 {'f', tm_tag_function_t}, // function
143 {'p', tm_tag_function_t}, // procedure
145 static TMParserMapGroup group_PASCAL[] = {
146 {N_("Functions"), TM_ICON_METHOD, tm_tag_function_t},
149 // no scope information
150 static TMParserMapEntry map_PERL[] = {
151 {'c', tm_tag_enum_t}, // constant
152 {'f', tm_tag_other_t}, // format
153 {'l', tm_tag_macro_t}, // label
154 {'p', tm_tag_package_t}, // package
155 {'s', tm_tag_function_t}, // subroutine
156 {'d', tm_tag_prototype_t}, // subroutineDeclaration
157 {'M', tm_tag_undef_t}, // module
159 static TMParserMapGroup group_PERL[] = {
160 {N_("Package"), TM_ICON_NAMESPACE, tm_tag_package_t},
161 {N_("Functions"), TM_ICON_METHOD, tm_tag_function_t | tm_tag_prototype_t},
162 {N_("Labels"), TM_ICON_NONE, tm_tag_macro_t},
163 {N_("Constants"), TM_ICON_NONE, tm_tag_enum_t},
164 {N_("Other"), TM_ICON_OTHER, tm_tag_other_t},
167 static TMParserMapEntry map_PHP[] = {
168 {'c', tm_tag_class_t}, // class
169 {'d', tm_tag_macro_t}, // define
170 {'f', tm_tag_function_t}, // function
171 {'i', tm_tag_interface_t}, // interface
172 {'l', tm_tag_local_var_t}, // local
173 {'n', tm_tag_namespace_t}, // namespace
174 {'t', tm_tag_struct_t}, // trait
175 {'v', tm_tag_variable_t}, // variable
176 {'a', tm_tag_undef_t}, // alias
178 static TMParserMapGroup group_PHP[] = {
179 {N_("Namespaces"), TM_ICON_NAMESPACE, tm_tag_namespace_t},
180 {N_("Interfaces"), TM_ICON_STRUCT, tm_tag_interface_t},
181 {N_("Classes"), TM_ICON_CLASS, tm_tag_class_t},
182 {N_("Functions"), TM_ICON_METHOD, tm_tag_function_t},
183 {N_("Constants"), TM_ICON_MACRO, tm_tag_macro_t},
184 {N_("Variables"), TM_ICON_VAR, tm_tag_variable_t | tm_tag_local_var_t},
185 {N_("Traits"), TM_ICON_STRUCT, tm_tag_struct_t},
188 static TMParserMapEntry map_PYTHON[] = {
189 {'c', tm_tag_class_t}, // class
190 {'f', tm_tag_function_t}, // function
191 {'m', tm_tag_method_t}, // member
192 {'v', tm_tag_variable_t}, // variable
193 {'I', tm_tag_externvar_t}, // namespace
194 {'i', tm_tag_externvar_t}, // module
195 /* defined as externvar to get those excluded as forward type in symbols.c:goto_tag()
196 * so we can jump to the real implementation (if known) instead of to the import statement */
197 {'x', tm_tag_externvar_t}, // unknown
198 {'z', tm_tag_local_var_t}, // parameter
199 {'l', tm_tag_local_var_t}, // local
201 static TMParserMapGroup group_PYTHON[] = {
202 {N_("Classes"), TM_ICON_CLASS, tm_tag_class_t},
203 {N_("Methods"), TM_ICON_MACRO, tm_tag_method_t},
204 {N_("Functions"), TM_ICON_METHOD, tm_tag_function_t},
205 {N_("Variables"), TM_ICON_VAR, tm_tag_variable_t | tm_tag_local_var_t},
206 {N_("Imports"), TM_ICON_NAMESPACE, tm_tag_externvar_t},
209 static TMParserMapEntry map_LATEX[] = {
210 {'p', tm_tag_enum_t}, // part
211 {'c', tm_tag_namespace_t}, // chapter
212 {'s', tm_tag_member_t}, // section
213 {'u', tm_tag_macro_t}, // subsection
214 {'b', tm_tag_variable_t}, // subsubsection
215 {'P', tm_tag_undef_t}, // paragraph
216 {'G', tm_tag_undef_t}, // subparagraph
217 {'l', tm_tag_struct_t}, // label
218 {'i', tm_tag_undef_t}, // xinput
219 {'B', tm_tag_field_t}, // bibitem
220 {'C', tm_tag_function_t}, // command
221 {'o', tm_tag_function_t}, // operator
222 {'e', tm_tag_class_t}, // environment
223 {'t', tm_tag_class_t}, // theorem
224 {'N', tm_tag_undef_t}, // counter
226 static TMParserMapGroup group_LATEX[] = {
227 {N_("Command"), TM_ICON_NONE, tm_tag_function_t},
228 {N_("Environment"), TM_ICON_NONE, tm_tag_class_t},
229 {N_("Part"), TM_ICON_NONE, tm_tag_enum_t},
230 {N_("Chapter"), TM_ICON_NONE, tm_tag_namespace_t},
231 {N_("Section"), TM_ICON_NONE, tm_tag_member_t},
232 {N_("Subsection"), TM_ICON_NONE, tm_tag_macro_t},
233 {N_("Subsubsection"), TM_ICON_NONE, tm_tag_variable_t},
234 {N_("Bibitem"), TM_ICON_NONE, tm_tag_field_t},
235 {N_("Label"), TM_ICON_NONE, tm_tag_struct_t},
238 // no scope information
239 static TMParserMapEntry map_BIBTEX[] = {
240 {'a', tm_tag_function_t}, // article
241 {'b', tm_tag_class_t}, // book
242 {'B', tm_tag_class_t}, // booklet
243 {'c', tm_tag_member_t}, // conference
244 {'i', tm_tag_macro_t}, // inbook
245 {'I', tm_tag_macro_t}, // incollection
246 {'j', tm_tag_member_t}, // inproceedings
247 {'m', tm_tag_other_t}, // manual
248 {'M', tm_tag_variable_t}, // mastersthesis
249 {'n', tm_tag_other_t}, // misc
250 {'p', tm_tag_variable_t}, // phdthesis
251 {'P', tm_tag_class_t}, // proceedings
252 {'s', tm_tag_namespace_t}, // string
253 {'t', tm_tag_other_t}, // techreport
254 {'u', tm_tag_externvar_t}, // unpublished
256 static TMParserMapGroup group_BIBTEX[] = {
257 {N_("Articles"), TM_ICON_NONE, tm_tag_function_t},
258 {N_("Book Chapters"), TM_ICON_NONE, tm_tag_macro_t},
259 {N_("Books & Conference Proceedings"), TM_ICON_NONE, tm_tag_class_t},
260 {N_("Conference Papers"), TM_ICON_NONE, tm_tag_member_t},
261 {N_("Theses"), TM_ICON_NONE, tm_tag_variable_t},
262 {N_("Strings"), TM_ICON_NONE, tm_tag_namespace_t},
263 {N_("Unpublished"), TM_ICON_NONE, tm_tag_externvar_t},
264 {N_("Other"), TM_ICON_NONE, tm_tag_other_t},
267 static TMParserMapEntry map_ASM[] = {
268 {'d', tm_tag_macro_t}, // define
269 {'l', tm_tag_namespace_t}, // label
270 {'m', tm_tag_function_t}, // macro
271 {'t', tm_tag_struct_t}, // type
272 {'s', tm_tag_undef_t}, // section
274 static TMParserMapGroup group_ASM[] = {
275 {N_("Labels"), TM_ICON_NAMESPACE, tm_tag_namespace_t},
276 {N_("Macros"), TM_ICON_METHOD, tm_tag_function_t},
277 {N_("Defines"), TM_ICON_MACRO, tm_tag_macro_t},
278 {N_("Types"), TM_ICON_STRUCT, tm_tag_struct_t},
281 static TMParserMapEntry map_CONF[] = {
282 {'s', tm_tag_namespace_t}, // section
283 {'k', tm_tag_macro_t}, // key
285 static TMParserMapGroup group_CONF[] = {
286 {N_("Sections"), TM_ICON_OTHER, tm_tag_namespace_t},
287 {N_("Keys"), TM_ICON_VAR, tm_tag_macro_t},
290 static TMParserMapEntry map_SQL[] = {
291 {'c', tm_tag_undef_t}, // cursor
292 {'d', tm_tag_prototype_t}, // prototype
293 {'f', tm_tag_function_t}, // function
294 {'E', tm_tag_field_t}, // field
295 {'l', tm_tag_undef_t}, // local
296 {'L', tm_tag_undef_t}, // label
297 {'P', tm_tag_package_t}, // package
298 {'p', tm_tag_namespace_t}, // procedure
299 {'r', tm_tag_undef_t}, // record
300 {'s', tm_tag_undef_t}, // subtype
301 {'t', tm_tag_class_t}, // table
302 {'T', tm_tag_macro_t}, // trigger
303 {'v', tm_tag_variable_t}, // variable
304 {'i', tm_tag_struct_t}, // index
305 {'e', tm_tag_undef_t}, // event
306 {'U', tm_tag_undef_t}, // publication
307 {'R', tm_tag_undef_t}, // service
308 {'D', tm_tag_undef_t}, // domain
309 {'V', tm_tag_member_t}, // view
310 {'n', tm_tag_undef_t}, // synonym
311 {'x', tm_tag_undef_t}, // mltable
312 {'y', tm_tag_undef_t}, // mlconn
313 {'z', tm_tag_undef_t}, // mlprop
314 {'C', tm_tag_undef_t}, // ccflag
316 static TMParserMapGroup group_SQL[] = {
317 {N_("Functions"), TM_ICON_METHOD, tm_tag_function_t | tm_tag_prototype_t},
318 {N_("Procedures"), TM_ICON_NAMESPACE, tm_tag_namespace_t | tm_tag_package_t},
319 {N_("Indexes"), TM_ICON_STRUCT, tm_tag_struct_t},
320 {N_("Tables"), TM_ICON_CLASS, tm_tag_class_t},
321 {N_("Triggers"), TM_ICON_MACRO, tm_tag_macro_t},
322 {N_("Views"), TM_ICON_VAR, tm_tag_field_t | tm_tag_member_t},
323 {N_("Variables"), TM_ICON_VAR, tm_tag_variable_t},
326 static TMParserMapEntry map_DOCBOOK[] = {
327 {'f', tm_tag_function_t},
328 {'c', tm_tag_class_t},
329 {'m', tm_tag_member_t},
330 {'d', tm_tag_macro_t},
331 {'v', tm_tag_variable_t},
332 {'s', tm_tag_struct_t},
334 static TMParserMapGroup group_DOCBOOK[] = {
335 {N_("Chapter"), TM_ICON_NONE, tm_tag_function_t},
336 {N_("Section"), TM_ICON_NONE, tm_tag_class_t},
337 {N_("Sect1"), TM_ICON_NONE, tm_tag_member_t},
338 {N_("Sect2"), TM_ICON_NONE, tm_tag_macro_t},
339 {N_("Sect3"), TM_ICON_NONE, tm_tag_variable_t},
340 {N_("Appendix"), TM_ICON_NONE, tm_tag_struct_t},
343 // no scope information
344 static TMParserMapEntry map_ERLANG[] = {
345 {'d', tm_tag_macro_t}, // macro
346 {'f', tm_tag_function_t}, // function
347 {'m', tm_tag_namespace_t}, // module
348 {'r', tm_tag_struct_t}, // record
349 {'t', tm_tag_typedef_t}, // type
351 static TMParserMapGroup group_ERLANG[] = {
352 {N_("Functions"), TM_ICON_METHOD, tm_tag_function_t},
353 {N_("Structs"), TM_ICON_STRUCT, tm_tag_struct_t},
354 {N_("Typedefs / Enums"), TM_ICON_STRUCT, tm_tag_typedef_t},
355 {N_("Macros"), TM_ICON_MACRO, tm_tag_macro_t},
356 {N_("Module"), TM_ICON_NAMESPACE, tm_tag_namespace_t},
359 // no scope information
360 static TMParserMapEntry map_CSS[] = {
361 {'c', tm_tag_class_t}, // class
362 {'s', tm_tag_struct_t}, // selector
363 {'i', tm_tag_variable_t}, // id
365 static TMParserMapGroup group_CSS[] = {
366 {N_("Classes"), TM_ICON_CLASS, tm_tag_class_t},
367 {N_("ID Selectors"), TM_ICON_VAR, tm_tag_variable_t},
368 {N_("Type Selectors"), TM_ICON_STRUCT, tm_tag_struct_t},
371 static TMParserMapEntry map_RUBY[] = {
372 {'c', tm_tag_class_t}, // class
373 {'f', tm_tag_method_t}, // method
374 {'m', tm_tag_namespace_t}, // module
375 {'S', tm_tag_member_t}, // singletonMethod
376 {'C', tm_tag_undef_t}, // constant
377 {'A', tm_tag_undef_t}, // accessor
378 {'a', tm_tag_undef_t}, // alias
379 {'L', tm_tag_undef_t}, // library
381 static TMParserMapGroup group_RUBY[] = {
382 {N_("Modules"), TM_ICON_NAMESPACE, tm_tag_namespace_t},
383 {N_("Classes"), TM_ICON_CLASS, tm_tag_class_t},
384 {N_("Singletons"), TM_ICON_STRUCT, tm_tag_member_t},
385 {N_("Methods"), TM_ICON_METHOD, tm_tag_method_t},
388 static TMParserMapEntry map_TCL[] = {
389 {'p', tm_tag_function_t}, // procedure
390 {'n', tm_tag_namespace_t}, // namespace
391 {'z', tm_tag_undef_t}, // parameter
393 static TMParserMapGroup group_TCL[] = {
394 {N_("Namespaces"), TM_ICON_NAMESPACE, tm_tag_namespace_t},
395 {N_("Classes"), TM_ICON_CLASS, tm_tag_class_t},
396 {N_("Methods"), TM_ICON_METHOD, tm_tag_member_t},
397 {N_("Procedures"), TM_ICON_OTHER, tm_tag_function_t},
400 static TMParserMapEntry map_TCLOO[] = {
401 {'c', tm_tag_class_t}, // class
402 {'m', tm_tag_member_t}, // method
404 #define group_TCLOO group_TCL
406 static TMSubparserMapEntry subparser_TCLOO_TCL_map[] = {
407 {tm_tag_namespace_t, tm_tag_namespace_t},
408 {tm_tag_class_t, tm_tag_class_t},
409 {tm_tag_member_t, tm_tag_member_t},
410 {tm_tag_function_t, tm_tag_function_t},
413 static TMParserMapEntry map_SH[] = {
414 {'a', tm_tag_undef_t}, // alias
415 {'f', tm_tag_function_t}, // function
416 {'s', tm_tag_undef_t}, // script
417 {'h', tm_tag_undef_t}, // heredoc
419 static TMParserMapGroup group_SH[] = {
420 {N_("Functions"), TM_ICON_METHOD, tm_tag_function_t},
423 static TMParserMapEntry map_D[] = {
424 {'c', tm_tag_class_t}, // class
425 {'e', tm_tag_enumerator_t}, // enumerator
426 {'f', tm_tag_function_t}, // function
427 {'g', tm_tag_enum_t}, // enum
428 {'i', tm_tag_interface_t}, // interface
429 {'m', tm_tag_member_t}, // member
430 {'n', tm_tag_namespace_t}, // namespace
431 {'p', tm_tag_prototype_t}, // prototype
432 {'s', tm_tag_struct_t}, // struct
433 {'t', tm_tag_typedef_t}, // typedef
434 {'u', tm_tag_union_t}, // union
435 {'v', tm_tag_variable_t}, // variable
436 {'x', tm_tag_externvar_t}, // externvar
438 static TMParserMapGroup group_D[] = {
439 {N_("Module"), TM_ICON_NONE, tm_tag_namespace_t},
440 {N_("Classes"), TM_ICON_CLASS, tm_tag_class_t},
441 {N_("Interfaces"), TM_ICON_STRUCT, tm_tag_interface_t},
442 {N_("Functions"), TM_ICON_METHOD, tm_tag_function_t | tm_tag_prototype_t},
443 {N_("Members"), TM_ICON_MEMBER, tm_tag_member_t},
444 {N_("Structs"), TM_ICON_STRUCT, tm_tag_struct_t | tm_tag_union_t},
445 {N_("Typedefs / Enums"), TM_ICON_STRUCT, tm_tag_typedef_t | tm_tag_enum_t},
446 {N_("Variables"), TM_ICON_VAR, tm_tag_variable_t | tm_tag_enumerator_t},
447 {N_("Extern Variables"), TM_ICON_VAR, tm_tag_externvar_t},
450 static TMParserMapEntry map_DIFF[] = {
451 {'m', tm_tag_function_t}, // modifiedFile
452 {'n', tm_tag_function_t}, // newFile
453 {'d', tm_tag_function_t}, // deletedFile
454 {'h', tm_tag_undef_t}, // hunk
456 static TMParserMapGroup group_DIFF[] = {
457 {N_("Files"), TM_ICON_NONE, tm_tag_function_t},
460 static TMParserMapEntry map_VHDL[] = {
461 {'c', tm_tag_variable_t}, // constant
462 {'t', tm_tag_typedef_t}, // type
463 {'T', tm_tag_typedef_t}, // subtype
464 {'r', tm_tag_undef_t}, // record
465 {'e', tm_tag_class_t}, // entity
466 {'C', tm_tag_member_t}, // component
467 {'d', tm_tag_undef_t}, // prototype
468 {'f', tm_tag_function_t}, // function
469 {'p', tm_tag_function_t}, // procedure
470 {'P', tm_tag_namespace_t}, // package
471 {'l', tm_tag_variable_t}, // local
472 {'a', tm_tag_struct_t}, // architecture
473 {'q', tm_tag_variable_t}, // port
474 {'g', tm_tag_undef_t}, // generic
475 {'s', tm_tag_variable_t}, // signal
476 {'Q', tm_tag_member_t}, // process
477 {'v', tm_tag_variable_t}, // variable
478 {'A', tm_tag_typedef_t}, // alias
480 static TMParserMapGroup group_VHDL[] = {
481 {N_("Package"), TM_ICON_NAMESPACE, tm_tag_namespace_t},
482 {N_("Entities"), TM_ICON_CLASS, tm_tag_class_t},
483 {N_("Architectures"), TM_ICON_STRUCT, tm_tag_struct_t},
484 {N_("Types"), TM_ICON_OTHER, tm_tag_typedef_t},
485 {N_("Functions / Procedures"), TM_ICON_METHOD, tm_tag_function_t},
486 {N_("Variables / Signals / Ports"), TM_ICON_VAR, tm_tag_variable_t},
487 {N_("Processes / Blocks / Components"), TM_ICON_MEMBER, tm_tag_member_t},
490 static TMParserMapEntry map_LUA[] = {
491 {'f', tm_tag_function_t}, // function
492 {'X', tm_tag_undef_t}, // unknown
494 static TMParserMapGroup group_LUA[] = {
495 {N_("Functions"), TM_ICON_METHOD, tm_tag_function_t},
498 static TMParserMapEntry map_JAVASCRIPT[] = {
499 {'f', tm_tag_function_t}, // function
500 {'c', tm_tag_class_t}, // class
501 {'m', tm_tag_method_t}, // method
502 {'p', tm_tag_member_t}, // property
503 {'C', tm_tag_macro_t}, // constant
504 {'v', tm_tag_variable_t}, // variable
505 {'g', tm_tag_function_t}, // generator
506 {'G', tm_tag_undef_t}, // getter
507 {'S', tm_tag_undef_t}, // setter
508 {'M', tm_tag_undef_t}, // field
510 static TMParserMapGroup group_JAVASCRIPT[] = {
511 {N_("Classes"), TM_ICON_CLASS, tm_tag_class_t},
512 {N_("Functions"), TM_ICON_METHOD, tm_tag_function_t | tm_tag_method_t},
513 {N_("Members"), TM_ICON_MEMBER, tm_tag_member_t},
514 {N_("Macros"), TM_ICON_MACRO, tm_tag_macro_t},
515 {N_("Variables"), TM_ICON_VAR, tm_tag_variable_t},
518 // no scope information
519 static TMParserMapEntry map_HASKELL[] = {
520 {'t', tm_tag_typedef_t}, // type
521 {'c', tm_tag_macro_t}, // constructor
522 {'f', tm_tag_function_t}, // function
523 {'m', tm_tag_namespace_t}, // module
525 static TMParserMapGroup group_HASKELL[] = {
526 {N_("Module"), TM_ICON_NONE, tm_tag_namespace_t},
527 {N_("Types"), TM_ICON_NONE, tm_tag_typedef_t},
528 {N_("Type constructors"), TM_ICON_NONE, tm_tag_macro_t},
529 {N_("Functions"), TM_ICON_METHOD, tm_tag_function_t},
532 #define map_UNUSED1 map_HASKELL
533 #define group_UNUSED1 group_HASKELL
535 static TMParserMapEntry map_CSHARP[] = {
536 {'c', tm_tag_class_t}, // class
537 {'d', tm_tag_macro_t}, // macro
538 {'e', tm_tag_enumerator_t}, // enumerator
539 {'E', tm_tag_undef_t}, // event
540 {'f', tm_tag_field_t}, // field
541 {'g', tm_tag_enum_t}, // enum
542 {'i', tm_tag_interface_t}, // interface
543 {'l', tm_tag_undef_t}, // local
544 {'m', tm_tag_method_t}, // method
545 {'n', tm_tag_namespace_t}, // namespace
546 {'p', tm_tag_undef_t}, // property
547 {'s', tm_tag_struct_t}, // struct
548 {'t', tm_tag_typedef_t}, // typedef
550 #define group_CSHARP group_C
552 // no scope information
553 static TMParserMapEntry map_FREEBASIC[] = {
554 {'c', tm_tag_macro_t}, // constant
555 {'f', tm_tag_function_t}, // function
556 {'l', tm_tag_namespace_t}, // label
557 {'t', tm_tag_struct_t}, // type
558 {'v', tm_tag_variable_t}, // variable
559 {'g', tm_tag_externvar_t}, // enum
561 static TMParserMapGroup group_FREEBASIC[] = {
562 {N_("Functions"), TM_ICON_METHOD, tm_tag_function_t},
563 {N_("Variables"), TM_ICON_VAR, tm_tag_variable_t | tm_tag_externvar_t},
564 {N_("Constants"), TM_ICON_MACRO, tm_tag_macro_t},
565 {N_("Types"), TM_ICON_NAMESPACE, tm_tag_struct_t},
566 {N_("Labels"), TM_ICON_MEMBER, tm_tag_namespace_t},
569 // no scope information
570 static TMParserMapEntry map_HAXE[] = {
571 {'m', tm_tag_method_t}, // method
572 {'c', tm_tag_class_t}, // class
573 {'e', tm_tag_enum_t}, // enum
574 {'v', tm_tag_variable_t}, // variable
575 {'i', tm_tag_interface_t}, // interface
576 {'t', tm_tag_typedef_t}, // typedef
578 static TMParserMapGroup group_HAXE[] = {
579 {N_("Interfaces"), TM_ICON_STRUCT, tm_tag_interface_t},
580 {N_("Classes"), TM_ICON_CLASS, tm_tag_class_t},
581 {N_("Methods"), TM_ICON_METHOD, tm_tag_method_t},
582 {N_("Types"), TM_ICON_MACRO, tm_tag_typedef_t | tm_tag_enum_t},
583 {N_("Variables"), TM_ICON_VAR, tm_tag_variable_t},
586 static TMParserMapEntry map_REST[] = {
587 {'c', tm_tag_namespace_t}, // chapter
588 {'s', tm_tag_member_t}, // section
589 {'S', tm_tag_macro_t}, // subsection
590 {'t', tm_tag_variable_t}, // subsubsection
591 {'C', tm_tag_undef_t}, // citation
592 {'T', tm_tag_undef_t}, // target
593 {'d', tm_tag_undef_t}, // substdef
595 static TMParserMapGroup group_REST[] = {
596 {N_("Chapter"), TM_ICON_NONE, tm_tag_namespace_t},
597 {N_("Section"), TM_ICON_NONE, tm_tag_member_t},
598 {N_("Subsection"), TM_ICON_NONE, tm_tag_macro_t},
599 {N_("Subsubsection"), TM_ICON_NONE, tm_tag_variable_t},
602 // no scope information
603 static TMParserMapEntry map_HTML[] = {
604 {'a', tm_tag_member_t}, // anchor
605 {'c', tm_tag_undef_t}, // class
606 {'h', tm_tag_namespace_t}, // heading1
607 {'i', tm_tag_class_t}, // heading2
608 {'j', tm_tag_variable_t}, // heading3
609 {'C', tm_tag_undef_t}, // stylesheet
610 {'I', tm_tag_undef_t}, // id
611 {'J', tm_tag_undef_t}, // script
613 static TMParserMapGroup group_HTML[] = {
614 {N_("Functions"), TM_ICON_NONE, tm_tag_function_t}, // javascript functions from subparser
615 {N_("Anchors"), TM_ICON_NONE, tm_tag_member_t},
616 {N_("H1 Headings"), TM_ICON_NONE, tm_tag_namespace_t},
617 {N_("H2 Headings"), TM_ICON_NONE, tm_tag_class_t},
618 {N_("H3 Headings"), TM_ICON_NONE, tm_tag_variable_t},
621 static TMSubparserMapEntry subparser_HTML_javascript_map[] = {
622 {tm_tag_function_t, tm_tag_function_t},
625 static TMParserMapEntry map_FORTRAN[] = {
626 {'b', tm_tag_undef_t}, // blockData
627 {'c', tm_tag_macro_t}, // common
628 {'e', tm_tag_undef_t}, // entry
629 {'E', tm_tag_enum_t}, // enum
630 {'f', tm_tag_function_t}, // function
631 {'i', tm_tag_interface_t}, // interface
632 {'k', tm_tag_member_t}, // component
633 {'l', tm_tag_undef_t}, // label
634 {'L', tm_tag_undef_t}, // local
635 {'m', tm_tag_namespace_t}, // module
636 {'M', tm_tag_member_t}, // method
637 {'n', tm_tag_undef_t}, // namelist
638 {'N', tm_tag_enumerator_t}, // enumerator
639 {'p', tm_tag_struct_t}, // program
640 {'P', tm_tag_undef_t}, // prototype
641 {'s', tm_tag_method_t}, // subroutine
642 {'t', tm_tag_class_t}, // type
643 {'v', tm_tag_variable_t}, // variable
644 {'S', tm_tag_undef_t}, // submodule
646 static TMParserMapGroup group_FORTRAN[] = {
647 {N_("Module"), TM_ICON_CLASS, tm_tag_namespace_t},
648 {N_("Programs"), TM_ICON_CLASS, tm_tag_struct_t},
649 {N_("Interfaces"), TM_ICON_STRUCT, tm_tag_interface_t},
650 {N_("Functions / Subroutines"), TM_ICON_METHOD, tm_tag_function_t | tm_tag_method_t},
651 {N_("Variables"), TM_ICON_VAR, tm_tag_variable_t | tm_tag_enumerator_t},
652 {N_("Types"), TM_ICON_CLASS, tm_tag_class_t},
653 {N_("Components"), TM_ICON_MEMBER, tm_tag_member_t},
654 {N_("Blocks"), TM_ICON_MEMBER, tm_tag_macro_t},
655 {N_("Enums"), TM_ICON_STRUCT, tm_tag_enum_t},
658 static TMParserMapEntry map_MATLAB[] = {
659 {'f', tm_tag_function_t}, // function
660 {'s', tm_tag_struct_t}, // struct
662 static TMParserMapGroup group_MATLAB[] = {
663 {N_("Functions"), TM_ICON_METHOD, tm_tag_function_t},
664 {N_("Structures"), TM_ICON_STRUCT, tm_tag_struct_t},
667 #define map_CUDA map_C
668 #define group_CUDA group_C
670 static TMParserMapEntry map_VALA[] = {
671 {'c', tm_tag_class_t}, // class
672 {'d', tm_tag_macro_t}, // macro
673 {'e', tm_tag_enumerator_t}, // enumerator
674 {'f', tm_tag_field_t}, // field
675 {'g', tm_tag_enum_t}, // enum
676 {'i', tm_tag_interface_t}, // interface
677 {'l', tm_tag_undef_t}, // local
678 {'m', tm_tag_method_t}, // method
679 {'n', tm_tag_namespace_t}, // namespace
680 {'p', tm_tag_undef_t}, // property
681 {'S', tm_tag_undef_t}, // signal
682 {'s', tm_tag_struct_t}, // struct
684 #define group_VALA group_C
686 static TMParserMapEntry map_ACTIONSCRIPT[] = {
687 {'f', tm_tag_function_t}, // function
688 {'c', tm_tag_class_t}, // class
689 {'i', tm_tag_interface_t}, // interface
690 {'P', tm_tag_package_t}, // package
691 {'m', tm_tag_method_t}, // method
692 {'p', tm_tag_member_t}, // property
693 {'v', tm_tag_variable_t}, // variable
694 {'l', tm_tag_variable_t}, // localvar
695 {'C', tm_tag_macro_t}, // constant
696 {'I', tm_tag_externvar_t}, // import
697 {'x', tm_tag_other_t}, // mxtag
699 static TMParserMapGroup group_ACTIONSCRIPT[] = {
700 {N_("Imports"), TM_ICON_NAMESPACE, tm_tag_externvar_t},
701 {N_("Package"), TM_ICON_NAMESPACE, tm_tag_package_t},
702 {N_("Interfaces"), TM_ICON_STRUCT, tm_tag_interface_t},
703 {N_("Classes"), TM_ICON_CLASS, tm_tag_class_t},
704 {N_("Functions"), TM_ICON_METHOD, tm_tag_function_t| tm_tag_method_t},
705 {N_("Properties"), TM_ICON_MEMBER, tm_tag_member_t},
706 {N_("Variables"), TM_ICON_VAR, tm_tag_variable_t},
707 {N_("Constants"), TM_ICON_MACRO, tm_tag_macro_t},
708 {N_("Other"), TM_ICON_OTHER, tm_tag_other_t},
711 static TMParserMapEntry map_NSIS[] = {
712 {'s', tm_tag_namespace_t}, // section
713 {'f', tm_tag_function_t}, // function
714 {'v', tm_tag_variable_t}, // variable
715 {'d', tm_tag_undef_t}, // definition
716 {'m', tm_tag_undef_t}, // macro
717 {'S', tm_tag_undef_t}, // sectionGroup
718 {'p', tm_tag_undef_t}, // macroparam
719 {'l', tm_tag_undef_t}, // langstr
720 {'i', tm_tag_undef_t}, // script
722 static TMParserMapGroup group_NSIS[] = {
723 {N_("Sections"), TM_ICON_OTHER, tm_tag_namespace_t},
724 {N_("Functions"), TM_ICON_METHOD, tm_tag_function_t},
725 {N_("Variables"), TM_ICON_VAR, tm_tag_variable_t},
728 static TMParserMapEntry map_MARKDOWN[] = {
729 {'c', tm_tag_namespace_t}, //chapter
730 {'s', tm_tag_member_t}, //section
731 {'S', tm_tag_macro_t}, //subsection
732 {'t', tm_tag_variable_t}, //subsubsection
733 {'T', tm_tag_struct_t}, //l4subsection
734 {'u', tm_tag_union_t}, //l5subsection
735 {'n', tm_tag_undef_t}, //footnote
737 static TMParserMapGroup group_MARKDOWN[] = {
738 {N_("Chapters"), TM_ICON_NONE, tm_tag_namespace_t},
739 {N_("Sections"), TM_ICON_NONE, tm_tag_member_t},
740 {N_("Subsections"), TM_ICON_NONE, tm_tag_macro_t},
741 {N_("Subsubsections"), TM_ICON_NONE, tm_tag_variable_t},
742 {N_("Level 4 sections"), TM_ICON_NONE, tm_tag_struct_t},
743 {N_("Level 5 sections"), TM_ICON_NONE, tm_tag_union_t},
746 static TMParserMapEntry map_TXT2TAGS[] = {
747 {'s', tm_tag_member_t}, // section
749 #define group_TXT2TAGS group_REST
751 // no scope information
752 static TMParserMapEntry map_ABC[] = {
753 {'s', tm_tag_member_t}, // section
755 #define group_ABC group_REST
757 static TMParserMapEntry map_VERILOG[] = {
758 {'c', tm_tag_variable_t}, // constant
759 {'e', tm_tag_typedef_t}, // event
760 {'f', tm_tag_function_t}, // function
761 {'m', tm_tag_class_t}, // module
762 {'n', tm_tag_variable_t}, // net
763 {'p', tm_tag_variable_t}, // port
764 {'r', tm_tag_variable_t}, // register
765 {'t', tm_tag_function_t}, // task
766 {'b', tm_tag_undef_t}, // block
767 {'i', tm_tag_undef_t}, // instance
769 static TMParserMapGroup group_VERILOG[] = {
770 {N_("Events"), TM_ICON_MACRO, tm_tag_typedef_t},
771 {N_("Modules"), TM_ICON_CLASS, tm_tag_class_t},
772 {N_("Functions / Tasks"), TM_ICON_METHOD, tm_tag_function_t},
773 {N_("Variables"), TM_ICON_VAR, tm_tag_variable_t},
776 static TMParserMapEntry map_R[] = {
777 {'f', tm_tag_function_t}, // function
778 {'l', tm_tag_other_t}, // library
779 {'s', tm_tag_other_t}, // source
780 {'g', tm_tag_undef_t}, // globalVar
781 {'v', tm_tag_undef_t}, // functionVar
782 {'z', tm_tag_undef_t}, // parameter
783 {'c', tm_tag_undef_t}, // vector
784 {'L', tm_tag_undef_t}, // list
785 {'d', tm_tag_undef_t}, // dataframe
786 {'n', tm_tag_undef_t}, // nameattr
788 static TMParserMapGroup group_R[] = {
789 {N_("Functions"), TM_ICON_METHOD, tm_tag_function_t},
790 {N_("Other"), TM_ICON_NONE, tm_tag_other_t},
793 static TMParserMapEntry map_COBOL[] = {
794 {'f', tm_tag_function_t}, // fd
795 {'g', tm_tag_struct_t}, // group
796 {'P', tm_tag_class_t}, // program
797 {'s', tm_tag_namespace_t}, // section
798 {'D', tm_tag_interface_t}, // division
799 {'p', tm_tag_macro_t}, // paragraph
800 {'d', tm_tag_variable_t}, // data
801 {'S', tm_tag_externvar_t}, // sourcefile
803 static TMParserMapGroup group_COBOL[] = {
804 {N_("Program"), TM_ICON_CLASS, tm_tag_class_t},
805 {N_("File"), TM_ICON_METHOD, tm_tag_function_t},
806 {N_("Divisions"), TM_ICON_NAMESPACE, tm_tag_interface_t},
807 {N_("Sections"), TM_ICON_NAMESPACE, tm_tag_namespace_t},
808 {N_("Paragraph"), TM_ICON_OTHER, tm_tag_macro_t},
809 {N_("Group"), TM_ICON_STRUCT, tm_tag_struct_t},
810 {N_("Data"), TM_ICON_VAR, tm_tag_variable_t},
811 {N_("Copies"), TM_ICON_NAMESPACE, tm_tag_externvar_t},
814 static TMParserMapEntry map_OBJC[] = {
815 {'i', tm_tag_interface_t}, // interface
816 {'I', tm_tag_undef_t}, // implementation
817 {'P', tm_tag_undef_t}, // protocol
818 {'m', tm_tag_method_t}, // method
819 {'c', tm_tag_class_t}, // class
820 {'v', tm_tag_variable_t}, // var
821 {'E', tm_tag_field_t}, // field
822 {'f', tm_tag_function_t}, // function
823 {'p', tm_tag_undef_t}, // property
824 {'t', tm_tag_typedef_t}, // typedef
825 {'s', tm_tag_struct_t}, // struct
826 {'e', tm_tag_enum_t}, // enum
827 {'M', tm_tag_macro_t}, // macro
828 {'C', tm_tag_undef_t}, // category
830 #define group_OBJC group_C
832 static TMParserMapEntry map_ASCIIDOC[] = {
833 {'c', tm_tag_namespace_t}, //chapter
834 {'s', tm_tag_member_t}, //section
835 {'S', tm_tag_macro_t}, //subsection
836 {'t', tm_tag_variable_t}, //subsubsection
837 {'T', tm_tag_struct_t}, //l4subsection
838 {'u', tm_tag_enumerator_t}, //l5subsection
839 {'a', tm_tag_undef_t}, //anchor
841 static TMParserMapGroup group_ASCIIDOC[] = {
842 {N_("Document"), TM_ICON_NONE, tm_tag_namespace_t},
843 {N_("Section Level 1"), TM_ICON_NONE, tm_tag_member_t},
844 {N_("Section Level 2"), TM_ICON_NONE, tm_tag_macro_t},
845 {N_("Section Level 3"), TM_ICON_NONE, tm_tag_variable_t},
846 {N_("Section Level 4"), TM_ICON_NONE, tm_tag_struct_t},
847 {N_("Section Level 5"), TM_ICON_NONE, tm_tag_enumerator_t},
850 // no scope information
851 static TMParserMapEntry map_ABAQUS[] = {
852 {'p', tm_tag_class_t}, // part
853 {'a', tm_tag_member_t}, // assembly
854 {'s', tm_tag_interface_t}, // step
856 static TMParserMapGroup group_ABAQUS[] = {
857 {N_("Parts"), TM_ICON_NONE, tm_tag_class_t},
858 {N_("Assembly"), TM_ICON_NONE, tm_tag_member_t},
859 {N_("Steps"), TM_ICON_NONE, tm_tag_interface_t},
862 static TMParserMapEntry map_RUST[] = {
863 {'n', tm_tag_namespace_t}, // module
864 {'s', tm_tag_struct_t}, // struct
865 {'i', tm_tag_interface_t}, // interface
866 {'c', tm_tag_class_t}, // implementation
867 {'f', tm_tag_function_t}, // function
868 {'g', tm_tag_enum_t}, // enum
869 {'t', tm_tag_typedef_t}, // typedef
870 {'v', tm_tag_variable_t}, // variable
871 {'M', tm_tag_macro_t}, // macro
872 {'m', tm_tag_field_t}, // field
873 {'e', tm_tag_enumerator_t}, // enumerator
874 {'P', tm_tag_method_t}, // method
876 static TMParserMapGroup group_RUST[] = {
877 {N_("Modules"), TM_ICON_NAMESPACE, tm_tag_namespace_t},
878 {N_("Structures"), TM_ICON_STRUCT, tm_tag_struct_t},
879 {N_("Traits"), TM_ICON_CLASS, tm_tag_interface_t},
880 {N_("Implementations"), TM_ICON_CLASS, tm_tag_class_t},
881 {N_("Functions"), TM_ICON_METHOD, tm_tag_function_t | tm_tag_method_t},
882 {N_("Typedefs / Enums"), TM_ICON_STRUCT, tm_tag_typedef_t | tm_tag_enum_t},
883 {N_("Variables"), TM_ICON_VAR, tm_tag_variable_t | tm_tag_enumerator_t},
884 {N_("Macros"), TM_ICON_MACRO, tm_tag_macro_t},
885 {N_("Methods"), TM_ICON_MEMBER, tm_tag_field_t},
888 static TMParserMapEntry map_GO[] = {
889 {'p', tm_tag_namespace_t}, // package
890 {'f', tm_tag_function_t}, // func
891 {'c', tm_tag_macro_t}, // const
892 {'t', tm_tag_typedef_t}, // type
893 {'v', tm_tag_variable_t}, // var
894 {'s', tm_tag_struct_t}, // struct
895 {'i', tm_tag_interface_t}, // interface
896 {'m', tm_tag_member_t}, // member
897 {'M', tm_tag_undef_t}, // anonMember
898 {'n', tm_tag_undef_t}, // methodSpec
899 {'u', tm_tag_undef_t}, // unknown
900 {'P', tm_tag_undef_t}, // packageName
901 {'a', tm_tag_undef_t}, // talias
902 {'R', tm_tag_undef_t}, // receiver
904 static TMParserMapGroup group_GO[] = {
905 {N_("Package"), TM_ICON_NAMESPACE, tm_tag_namespace_t},
906 {N_("Functions"), TM_ICON_METHOD, tm_tag_function_t},
907 {N_("Interfaces"), TM_ICON_STRUCT, tm_tag_interface_t},
908 {N_("Structs"), TM_ICON_STRUCT, tm_tag_struct_t},
909 {N_("Types"), TM_ICON_STRUCT, tm_tag_typedef_t},
910 {N_("Constants"), TM_ICON_MACRO, tm_tag_macro_t},
911 {N_("Variables"), TM_ICON_VAR, tm_tag_variable_t},
912 {N_("Members"), TM_ICON_MEMBER, tm_tag_member_t},
915 static TMParserMapEntry map_JSON[] = {
916 {'o', tm_tag_member_t}, // object
917 {'a', tm_tag_member_t}, // array
918 {'n', tm_tag_member_t}, // number
919 {'s', tm_tag_member_t}, // string
920 {'b', tm_tag_member_t}, // boolean
921 {'z', tm_tag_member_t}, // null
923 static TMParserMapGroup group_JSON[] = {
924 {N_("Members"), TM_ICON_MEMBER, tm_tag_member_t},
927 /* Zephir, same as PHP */
928 #define map_ZEPHIR map_PHP
929 #define group_ZEPHIR group_PHP
931 static TMParserMapEntry map_POWERSHELL[] = {
932 {'f', tm_tag_function_t}, // function
933 {'v', tm_tag_variable_t}, // variable
935 static TMParserMapGroup group_POWERSHELL[] = {
936 {N_("Functions"), TM_ICON_METHOD, tm_tag_function_t},
937 {N_("Variables"), TM_ICON_VAR, tm_tag_variable_t},
940 static TMParserMapEntry map_JULIA[] = {
941 {'c', tm_tag_variable_t}, // constant
942 {'f', tm_tag_function_t}, // function
943 {'g', tm_tag_member_t}, // field
944 {'m', tm_tag_macro_t}, // macro
945 {'n', tm_tag_namespace_t}, // module
946 {'s', tm_tag_struct_t}, // struct
947 {'t', tm_tag_typedef_t}, // type
948 /* defined as externvar to get those excluded as forward type in symbols.c:goto_tag()
949 * so we can jump to the real implementation (if known) instead of to the import statement */
950 {'x', tm_tag_externvar_t}, // unknown
952 static TMParserMapGroup group_JULIA[] = {
953 {N_("Constants"), TM_ICON_VAR, tm_tag_variable_t},
954 {N_("Modules"), TM_ICON_NAMESPACE, tm_tag_namespace_t},
955 {N_("Functions"), TM_ICON_METHOD, tm_tag_function_t},
956 {N_("Fields"), TM_ICON_MEMBER, tm_tag_member_t},
957 {N_("Macros"), TM_ICON_MACRO, tm_tag_macro_t},
958 {N_("Structures"), TM_ICON_STRUCT, tm_tag_struct_t},
959 {N_("Types"), TM_ICON_CLASS, tm_tag_typedef_t},
960 {N_("Unknowns"), TM_ICON_OTHER, tm_tag_externvar_t},
963 static TMParserMapEntry map_CPREPROCESSOR[] = {
964 {'d', tm_tag_undef_t}, // macro
965 {'h', tm_tag_undef_t}, // header
966 {'D', tm_tag_undef_t}, // parameter
968 #define group_CPREPROCESSOR group_C
970 static TMParserMapEntry map_GDSCRIPT[] = {
971 {'c', tm_tag_class_t}, // class
972 {'m', tm_tag_method_t}, // method
973 {'v', tm_tag_variable_t}, // variable
974 {'C', tm_tag_variable_t}, // const
975 {'g', tm_tag_enum_t}, // enum
976 {'e', tm_tag_variable_t}, // enumerator
977 {'z', tm_tag_local_var_t}, // parameter
978 {'l', tm_tag_local_var_t}, // local
979 {'s', tm_tag_variable_t}, // signal
981 static TMParserMapGroup group_GDSCRIPT[] = {
982 {N_("Classes"), TM_ICON_CLASS, tm_tag_class_t},
983 {N_("Methods"), TM_ICON_MACRO, tm_tag_method_t},
984 {N_("Variables"), TM_ICON_VAR, tm_tag_variable_t | tm_tag_local_var_t},
985 {N_("Enums"), TM_ICON_STRUCT, tm_tag_enum_t},
988 static TMParserMapEntry map_CLOJURE[] = {
989 {'f', tm_tag_function_t}, // function
990 {'n', tm_tag_namespace_t}, // namespace
992 static TMParserMapGroup group_CLOJURE[] = {
993 {N_("Namespaces"), TM_ICON_NAMESPACE, tm_tag_namespace_t},
994 {N_("Functions"), TM_ICON_METHOD, tm_tag_function_t},
997 static TMParserMapEntry map_LISP[] = {
998 {'u', tm_tag_undef_t}, // unknown
999 {'f', tm_tag_function_t}, // function
1000 {'v', tm_tag_variable_t}, // variable
1001 {'m', tm_tag_macro_t}, // macro
1002 {'c', tm_tag_field_t}, // const
1004 static TMParserMapGroup group_LISP[] = {
1005 {N_("Functions"), TM_ICON_METHOD, tm_tag_function_t},
1006 {N_("Macros"), TM_ICON_MACRO, tm_tag_macro_t},
1007 {N_("Variables"), TM_ICON_VAR, tm_tag_variable_t},
1008 {N_("Constants"), TM_ICON_VAR, tm_tag_field_t},
1011 static TMParserMapEntry map_TYPESCRIPT[] = {
1012 {'f', tm_tag_function_t}, // function
1013 {'c', tm_tag_class_t}, // class
1014 {'i', tm_tag_interface_t}, // interface
1015 {'g', tm_tag_enum_t}, // enum
1016 {'e', tm_tag_enumerator_t}, // enumerator
1017 {'m', tm_tag_method_t}, // method
1018 {'n', tm_tag_namespace_t}, // namespace
1019 {'z', tm_tag_local_var_t}, // parameter
1020 {'p', tm_tag_member_t}, // property
1021 {'v', tm_tag_variable_t}, // variable
1022 {'l', tm_tag_local_var_t}, // local
1023 {'C', tm_tag_macro_t}, // constant
1024 {'G', tm_tag_undef_t}, // generator
1025 {'a', tm_tag_undef_t}, // alias
1027 static TMParserMapGroup group_TYPESCRIPT[] = {
1028 {N_("Namespaces"), TM_ICON_NAMESPACE, tm_tag_namespace_t},
1029 {N_("Classes"), TM_ICON_CLASS, tm_tag_class_t},
1030 {N_("Interfaces"), TM_ICON_STRUCT, tm_tag_interface_t},
1031 {N_("Functions"), TM_ICON_METHOD, tm_tag_function_t | tm_tag_method_t},
1032 {N_("Enums"), TM_ICON_STRUCT, tm_tag_enum_t},
1033 {N_("Variables"), TM_ICON_VAR, tm_tag_variable_t | tm_tag_local_var_t},
1034 {N_("Constants"), TM_ICON_MACRO, tm_tag_macro_t},
1035 {N_("Other"), TM_ICON_MEMBER, tm_tag_member_t | tm_tag_enumerator_t},
1038 static TMParserMapEntry map_ADA[] = {
1039 {'P', tm_tag_package_t}, // packspec
1040 {'p', tm_tag_package_t}, // package
1041 {'T', tm_tag_typedef_t}, // typespec
1042 {'t', tm_tag_typedef_t}, // type
1043 {'U', tm_tag_undef_t}, // subspec
1044 {'u', tm_tag_typedef_t}, // subtype
1045 {'c', tm_tag_member_t}, // component
1046 {'l', tm_tag_enumerator_t}, // literal
1047 {'V', tm_tag_undef_t}, // varspec
1048 {'v', tm_tag_variable_t}, // variable
1049 {'f', tm_tag_undef_t}, // formal
1050 {'n', tm_tag_macro_t}, // constant
1051 {'x', tm_tag_undef_t}, // exception
1052 {'R', tm_tag_prototype_t}, // subprogspec
1053 {'r', tm_tag_function_t}, // subprogram
1054 {'K', tm_tag_prototype_t}, // taskspec
1055 {'k', tm_tag_method_t}, // task
1056 {'O', tm_tag_undef_t}, // protectspec
1057 {'o', tm_tag_undef_t}, // protected
1058 {'E', tm_tag_undef_t}, // entryspec
1059 {'e', tm_tag_undef_t}, // entry
1060 {'b', tm_tag_undef_t}, // label
1061 {'i', tm_tag_undef_t}, // identifier
1062 {'a', tm_tag_undef_t}, // autovar
1063 {'y', tm_tag_undef_t}, // anon
1065 static TMParserMapGroup group_ADA[] = {
1066 {N_("Packages"), TM_ICON_NAMESPACE, tm_tag_package_t},
1067 {N_("Types"), TM_ICON_STRUCT, tm_tag_typedef_t},
1068 {N_("Functions"), TM_ICON_METHOD, tm_tag_function_t | tm_tag_prototype_t},
1069 {N_("Tasks"), TM_ICON_METHOD, tm_tag_method_t},
1070 {N_("Variables"), TM_ICON_VAR, tm_tag_variable_t},
1071 {N_("Constants"), TM_ICON_MACRO, tm_tag_macro_t},
1072 {N_("Other"), TM_ICON_MEMBER, tm_tag_member_t | tm_tag_enumerator_t},
1075 static TMParserMapEntry map_BATCH[] = {
1076 {'l', tm_tag_other_t}, // label
1077 {'v', tm_tag_variable_t}, // variable
1079 static TMParserMapGroup group_BATCH[] = {
1080 {N_("Labels"), TM_ICON_OTHER, tm_tag_other_t},
1081 {N_("Variables"), TM_ICON_VAR, tm_tag_variable_t},
1084 static TMParserMapEntry map_AUTOIT[] = {
1085 {'f', tm_tag_function_t},
1086 {'r', tm_tag_other_t},
1087 {'g', tm_tag_variable_t},
1088 {'l', tm_tag_variable_t},
1089 {'S', tm_tag_undef_t},
1091 static TMParserMapGroup group_AUTOIT[] = {
1092 {N_("Functions"), TM_ICON_METHOD, tm_tag_function_t},
1093 {N_("Regions"), TM_ICON_OTHER, tm_tag_other_t},
1094 {N_("Variables"), TM_ICON_VAR, tm_tag_variable_t},
1097 static TMParserMapEntry map_RAKU[] = {
1098 {'c', tm_tag_class_t}, // class
1099 {'g', tm_tag_struct_t}, // grammar
1100 {'m', tm_tag_method_t}, // method
1101 {'o', tm_tag_namespace_t}, // module
1102 {'p', tm_tag_package_t}, // package
1103 {'r', tm_tag_class_t}, // role
1104 {'u', tm_tag_variable_t}, // rule
1105 {'b', tm_tag_method_t}, // submethod
1106 {'s', tm_tag_function_t}, // subroutine
1107 {'t', tm_tag_variable_t}, // token
1109 static TMParserMapGroup group_RAKU[] = {
1110 {N_("Packages / Modules"), TM_ICON_NAMESPACE, tm_tag_package_t | tm_tag_namespace_t},
1111 {N_("Classes / Roles"), TM_ICON_CLASS, tm_tag_class_t},
1112 {N_("Grammars"), TM_ICON_STRUCT, tm_tag_struct_t},
1113 {N_("Methods"), TM_ICON_METHOD, tm_tag_method_t},
1114 {N_("Subroutines"), TM_ICON_METHOD, tm_tag_function_t},
1115 {N_("Rules / Tokens"), TM_ICON_VAR, tm_tag_variable_t},
1118 static TMParserMapEntry map_OCAML[] = {
1119 {'c', tm_tag_class_t}, // class
1120 {'m', tm_tag_method_t}, // method
1121 {'M', tm_tag_package_t}, // module
1122 {'v', tm_tag_variable_t}, // var
1123 {'p', tm_tag_undef_t}, // val
1124 {'t', tm_tag_typedef_t}, // type
1125 {'f', tm_tag_function_t}, // function
1126 {'C', tm_tag_undef_t}, // Constructor
1127 {'r', tm_tag_undef_t}, // RecordField
1128 {'e', tm_tag_undef_t}, // Exception
1130 static TMParserMapGroup group_OCAML[] = {
1131 {N_("Modules"), TM_ICON_NAMESPACE, tm_tag_package_t},
1132 {N_("Classes"), TM_ICON_CLASS, tm_tag_class_t},
1133 {N_("Types"), TM_ICON_STRUCT, tm_tag_typedef_t},
1134 {N_("Functions"), TM_ICON_METHOD, tm_tag_method_t | tm_tag_function_t},
1135 {N_("Variables"), TM_ICON_VAR, tm_tag_variable_t},
1138 typedef struct
1140 TMParserMapEntry *entries;
1141 guint size;
1142 TMParserMapGroup *groups;
1143 guint group_num;
1144 } TMParserMap;
1146 #define MAP_ENTRY(lang) [TM_PARSER_##lang] = {map_##lang, G_N_ELEMENTS(map_##lang), group_##lang, G_N_ELEMENTS(group_##lang)}
1148 /* keep in sync with TM_PARSER_* definitions in the header */
1149 static TMParserMap parser_map[] = {
1150 MAP_ENTRY(C),
1151 MAP_ENTRY(CPP),
1152 MAP_ENTRY(JAVA),
1153 MAP_ENTRY(MAKEFILE),
1154 MAP_ENTRY(PASCAL),
1155 MAP_ENTRY(PERL),
1156 MAP_ENTRY(PHP),
1157 MAP_ENTRY(PYTHON),
1158 MAP_ENTRY(LATEX),
1159 MAP_ENTRY(BIBTEX),
1160 MAP_ENTRY(ASM),
1161 MAP_ENTRY(CONF),
1162 MAP_ENTRY(SQL),
1163 MAP_ENTRY(DOCBOOK),
1164 MAP_ENTRY(ERLANG),
1165 MAP_ENTRY(CSS),
1166 MAP_ENTRY(RUBY),
1167 MAP_ENTRY(TCL),
1168 MAP_ENTRY(SH),
1169 MAP_ENTRY(D),
1170 MAP_ENTRY(FORTRAN),
1171 MAP_ENTRY(GDSCRIPT),
1172 MAP_ENTRY(DIFF),
1173 MAP_ENTRY(VHDL),
1174 MAP_ENTRY(LUA),
1175 MAP_ENTRY(JAVASCRIPT),
1176 MAP_ENTRY(HASKELL),
1177 MAP_ENTRY(CSHARP),
1178 MAP_ENTRY(FREEBASIC),
1179 MAP_ENTRY(HAXE),
1180 MAP_ENTRY(REST),
1181 MAP_ENTRY(HTML),
1182 MAP_ENTRY(ADA),
1183 MAP_ENTRY(CUDA),
1184 MAP_ENTRY(MATLAB),
1185 MAP_ENTRY(VALA),
1186 MAP_ENTRY(ACTIONSCRIPT),
1187 MAP_ENTRY(NSIS),
1188 MAP_ENTRY(MARKDOWN),
1189 MAP_ENTRY(TXT2TAGS),
1190 MAP_ENTRY(ABC),
1191 MAP_ENTRY(VERILOG),
1192 MAP_ENTRY(R),
1193 MAP_ENTRY(COBOL),
1194 MAP_ENTRY(OBJC),
1195 MAP_ENTRY(ASCIIDOC),
1196 MAP_ENTRY(ABAQUS),
1197 MAP_ENTRY(RUST),
1198 MAP_ENTRY(GO),
1199 MAP_ENTRY(JSON),
1200 MAP_ENTRY(ZEPHIR),
1201 MAP_ENTRY(POWERSHELL),
1202 MAP_ENTRY(JULIA),
1203 MAP_ENTRY(CPREPROCESSOR),
1204 MAP_ENTRY(TCLOO),
1205 MAP_ENTRY(CLOJURE),
1206 MAP_ENTRY(LISP),
1207 MAP_ENTRY(TYPESCRIPT),
1208 MAP_ENTRY(BATCH),
1209 MAP_ENTRY(AUTOIT),
1210 MAP_ENTRY(RAKU),
1211 MAP_ENTRY(OCAML),
1213 /* make sure the parser map is consistent and complete */
1214 G_STATIC_ASSERT(G_N_ELEMENTS(parser_map) == TM_PARSER_COUNT);
1217 TMTagType tm_parser_get_tag_type(gchar kind, TMParserType lang)
1219 TMParserMap *map = &parser_map[lang];
1220 guint i;
1222 for (i = 0; i < map->size; i++)
1224 TMParserMapEntry *entry = &map->entries[i];
1226 if (entry->kind == kind)
1227 return entry->type;
1229 return tm_tag_undef_t;
1233 gchar tm_parser_get_tag_kind(TMTagType type, TMParserType lang)
1235 TMParserMap *map = &parser_map[lang];
1236 guint i;
1238 for (i = 0; i < map->size; i++)
1240 TMParserMapEntry *entry = &map->entries[i];
1242 if (entry->type == type)
1243 return entry->kind;
1245 return '\0';
1249 gint tm_parser_get_sidebar_group(TMParserType lang, TMTagType type)
1251 TMParserMap *map;
1252 guint i;
1254 if (lang >= TM_PARSER_COUNT)
1255 return -1;
1257 map = &parser_map[lang];
1258 for (i = 0; i < map->group_num; i++)
1260 if (map->groups[i].types & type)
1261 return i + 1; // "Symbols" group is always first
1263 return -1;
1267 const gchar *tm_parser_get_sidebar_info(TMParserType lang, gint group, guint *icon)
1269 const gchar *name;
1270 TMParserMap *map;
1271 TMParserMapGroup *grp;
1273 if (lang >= TM_PARSER_COUNT)
1274 return NULL;
1276 if (group == 0)
1278 name = _("Symbols");
1279 *icon = TM_ICON_NAMESPACE;
1281 else
1283 map = &parser_map[lang];
1284 if (group > (gint)map->group_num)
1285 return NULL;
1287 grp = &map->groups[group - 1];
1288 name = _(grp->name);
1289 *icon = grp->icon;
1292 return name;
1296 static void add_subparser(TMParserType lang, TMParserType sublang, TMSubparserMapEntry *map, guint map_size)
1298 guint i;
1299 GPtrArray *mapping;
1300 GHashTable *lang_map = g_hash_table_lookup(subparser_map, GINT_TO_POINTER(lang));
1302 if (!lang_map)
1304 lang_map = g_hash_table_new(g_direct_hash, g_direct_equal);
1305 g_hash_table_insert(subparser_map, GINT_TO_POINTER(lang), lang_map);
1308 mapping = g_ptr_array_new();
1309 for (i = 0; i < map_size; i++)
1310 g_ptr_array_add(mapping, &map[i]);
1312 g_hash_table_insert(lang_map, GINT_TO_POINTER(sublang), mapping);
1316 #define SUBPARSER_MAP_ENTRY(lang, sublang, map) add_subparser(TM_PARSER_##lang, TM_PARSER_##sublang, map, G_N_ELEMENTS(map))
1318 static void init_subparser_map(void)
1320 SUBPARSER_MAP_ENTRY(HTML, JAVASCRIPT, subparser_HTML_javascript_map);
1321 SUBPARSER_MAP_ENTRY(TCLOO, TCL, subparser_TCLOO_TCL_map);
1325 TMTagType tm_parser_get_subparser_type(TMParserType lang, TMParserType sublang, TMTagType type)
1327 guint i;
1328 GHashTable *lang_map;
1329 GPtrArray *mapping;
1331 if (!subparser_map)
1333 subparser_map = g_hash_table_new(g_direct_hash, g_direct_equal);
1334 init_subparser_map();
1337 lang_map = g_hash_table_lookup(subparser_map, GINT_TO_POINTER(lang));
1338 if (!lang_map)
1339 return tm_tag_undef_t;
1341 mapping = g_hash_table_lookup(lang_map, GINT_TO_POINTER(sublang));
1342 if (!mapping)
1343 return tm_tag_undef_t;
1345 for (i = 0; i < mapping->len; i++)
1347 TMSubparserMapEntry *entry = mapping->pdata[i];
1348 if (entry->orig_type == type)
1349 return entry->new_type;
1352 return tm_tag_undef_t;
1356 void tm_parser_verify_type_mappings(void)
1358 TMParserType lang;
1360 if (TM_PARSER_COUNT > tm_ctags_get_lang_count())
1361 g_error("More parsers defined in Geany than in ctags");
1363 for (lang = 0; lang < TM_PARSER_COUNT; lang++)
1365 const gchar *kinds = tm_ctags_get_lang_kinds(lang);
1366 TMParserMap *map = &parser_map[lang];
1367 gchar presence_map[256];
1368 TMTagType lang_types = 0;
1369 TMTagType group_types = 0;
1370 guint i;
1372 if (! map->entries || map->size < 1)
1373 g_error("No tag types in TM for %s, is the language listed in parser_map?",
1374 tm_ctags_get_lang_name(lang));
1376 if (map->size != strlen(kinds))
1377 g_error("Different number of tag types in TM (%d) and ctags (%d) for %s",
1378 map->size, (int)strlen(kinds), tm_ctags_get_lang_name(lang));
1380 memset(presence_map, 0, sizeof(presence_map));
1381 for (i = 0; i < map->size; i++)
1383 gboolean ctags_found = FALSE;
1384 gboolean tm_found = FALSE;
1385 guint j;
1387 for (j = 0; j < map->size; j++)
1389 /* check that for every type in TM there's a type in ctags */
1390 if (map->entries[i].kind == kinds[j])
1391 ctags_found = TRUE;
1392 /* check that for every type in ctags there's a type in TM */
1393 if (map->entries[j].kind == kinds[i])
1394 tm_found = TRUE;
1395 if (ctags_found && tm_found)
1396 break;
1398 if (!ctags_found)
1399 g_error("Tag type '%c' found in TM but not in ctags for %s",
1400 map->entries[i].kind, tm_ctags_get_lang_name(lang));
1401 if (!tm_found)
1402 g_error("Tag type '%c' found in ctags but not in TM for %s",
1403 kinds[i], tm_ctags_get_lang_name(lang));
1405 presence_map[(unsigned char) map->entries[i].kind]++;
1406 lang_types |= map->entries[i].type;
1409 for (i = 0; i < sizeof(presence_map); i++)
1411 if (presence_map[i] > 1)
1412 g_error("Duplicate tag type '%c' found for %s",
1413 (gchar)i, tm_ctags_get_lang_name(lang));
1416 for (i = 0; i < map->group_num; i++)
1417 group_types |= map->groups[i].types;
1419 if ((group_types & lang_types) != lang_types)
1420 g_warning("Not all tag types mapped to symbol tree groups for %s",
1421 tm_ctags_get_lang_name(lang));
1426 /* When the suffix of 'str' is an operator that should trigger scope
1427 * autocompletion, this function should return the length of the operator,
1428 * zero otherwise. */
1429 gint tm_parser_scope_autocomplete_suffix(TMParserType lang, const gchar *str)
1431 const gchar *sep = tm_parser_scope_separator(lang);
1433 if (g_str_has_suffix(str, sep))
1434 return strlen(sep);
1436 switch (lang)
1438 case TM_PARSER_C:
1439 case TM_PARSER_CPP:
1440 if (g_str_has_suffix(str, "."))
1441 return 1;
1442 else if (g_str_has_suffix(str, "->"))
1443 return 2;
1444 else if (lang == TM_PARSER_CPP && g_str_has_suffix(str, "->*"))
1445 return 3;
1446 default:
1447 break;
1449 return 0;
1453 /* Get the name of constructor method. Arguments of this method will be used
1454 * for calltips when creating an object using the class name
1455 * (e.g. after the opening brace in 'c = MyClass()' in Python) */
1456 const gchar *tm_parser_get_constructor_method(TMParserType lang)
1458 switch (lang)
1460 case TM_PARSER_D:
1461 return "this";
1462 case TM_PARSER_PYTHON:
1463 return "__init__";
1464 default:
1465 return NULL;
1470 /* determine anonymous tags from tag names only when corresponding
1471 * ctags information is not available */
1472 gboolean tm_parser_is_anon_name(TMParserType lang, const gchar *name)
1474 guint i;
1475 char dummy;
1477 if (sscanf(name, "__anon%u%c", &i, &dummy) == 1) /* uctags tags files */
1478 return TRUE;
1479 else if (lang == TM_PARSER_C || lang == TM_PARSER_CPP) /* legacy Geany tags files */
1480 return sscanf(name, "anon_%*[a-z]_%u%c", &i, &dummy) == 1;
1481 else if (lang == TM_PARSER_FORTRAN) /* legacy Geany tags files */
1483 return sscanf(name, "Structure#%u%c", &i, &dummy) == 1 ||
1484 sscanf(name, "Interface#%u%c", &i, &dummy) == 1 ||
1485 sscanf(name, "Enum#%u%c", &i, &dummy) == 1;
1487 return FALSE;
1491 static gchar *replace_string_if_present(gchar *haystack, const gchar *needle, const gchar *subst)
1493 if (strstr(haystack, needle))
1495 gchar **split = g_strsplit(haystack, needle, -1);
1496 gchar *ret = g_strjoinv(subst, split);
1497 g_strfreev(split);
1498 return ret;
1500 return haystack;
1504 /* return updated scope or original scope if no change needed */
1505 gchar *tm_parser_update_scope(TMParserType lang, gchar *scope)
1507 switch (lang)
1509 case TM_PARSER_PHP:
1510 case TM_PARSER_ZEPHIR:
1511 /* PHP parser uses two different scope separators but this would
1512 * complicate things in Geany so make sure there's just one type */
1513 return replace_string_if_present(scope, "\\", "::");
1514 case TM_PARSER_TCL:
1515 case TM_PARSER_TCLOO:
1516 /* The TCL(OO) parser returns scope prefixed with :: which we don't
1517 * want. */
1518 if (g_str_has_prefix(scope, "::"))
1519 return g_strdup(scope + 2);
1520 break;
1522 return scope;
1526 /* whether or not to enable ctags roles for the given language and kind */
1527 gboolean tm_parser_enable_role(TMParserType lang, gchar kind)
1529 switch (lang)
1531 case TM_PARSER_GDSCRIPT:
1532 return kind == 'c' ? FALSE : TRUE;
1533 case TM_PARSER_GO:
1534 /* 'p' is used both for package definition tags and imported package
1535 * tags and we can't tell which is which just by kind. By disabling
1536 * roles for this kind, we only get package definition tags. */
1537 return kind == 'p' ? FALSE : TRUE;
1539 return TRUE;
1543 /* whether or not to enable ctags kinds for the given language */
1544 gboolean tm_parser_enable_kind(TMParserType lang, gchar kind)
1546 TMParserMap *map;
1547 guint i;
1549 if (lang >= TM_PARSER_COUNT)
1550 /* Fatal error but tm_parser_verify_type_mappings() will provide
1551 * better message later */
1552 return FALSE;
1554 map = &parser_map[lang];
1555 for (i = 0; i < map->size; i++)
1557 if (map->entries[i].kind == kind)
1558 return map->entries[i].type != tm_tag_undef_t;
1560 return FALSE;
1564 gchar *tm_parser_format_variable(TMParserType lang, const gchar *name, const gchar *type,
1565 const gchar *scope)
1567 gchar *ret, *name_full;
1569 if (!type)
1570 return NULL;
1572 if (scope)
1573 name_full = g_strconcat(scope, tm_parser_scope_separator_printable(lang),
1574 name, NULL);
1575 else
1576 name_full = g_strdup(name);
1578 switch (lang)
1580 case TM_PARSER_GO:
1581 ret = g_strconcat(name_full, " ", type, NULL);
1582 break;
1583 case TM_PARSER_PASCAL:
1584 case TM_PARSER_PYTHON:
1585 ret = g_strconcat(name_full, ": ", type, NULL);
1586 break;
1587 default:
1588 ret = g_strconcat(type, " ", name_full, NULL);
1589 break;
1592 g_free(name_full);
1593 return ret;
1597 gchar *tm_parser_format_function(TMParserType lang, const gchar *fname, const gchar *args,
1598 const gchar *retval, const gchar *scope)
1600 GString *str;
1602 if (!args) /* not a function */
1603 return NULL;
1605 str = g_string_new(NULL);
1607 if (scope)
1609 g_string_append(str, scope);
1610 g_string_append(str, tm_parser_scope_separator_printable(lang));
1612 g_string_append(str, fname);
1613 g_string_append_c(str, ' ');
1614 g_string_append(str, args);
1616 if (retval)
1618 const gchar *sep = NULL;
1620 switch (lang)
1622 /* retval after function */
1623 case TM_PARSER_PASCAL:
1624 sep = ": ";
1625 break;
1626 case TM_PARSER_GDSCRIPT:
1627 case TM_PARSER_PYTHON:
1628 sep = " -> ";
1629 break;
1630 case TM_PARSER_GO:
1631 sep = " ";
1632 break;
1633 default:
1634 break;
1637 if (sep)
1639 /* retval after function */
1640 g_string_append(str, sep);
1641 g_string_append(str, retval);
1643 else
1645 /* retval before function */
1646 g_string_prepend_c(str, ' ');
1647 g_string_prepend(str, retval);
1651 return g_string_free(str, FALSE);
1655 const gchar *tm_parser_scope_separator(TMParserType lang)
1657 switch (lang)
1659 case TM_PARSER_C: /* for C++ .h headers or C structs */
1660 case TM_PARSER_CPP:
1661 case TM_PARSER_CUDA:
1662 case TM_PARSER_PHP:
1663 case TM_PARSER_POWERSHELL:
1664 case TM_PARSER_RUST:
1665 case TM_PARSER_TCL:
1666 case TM_PARSER_TCLOO:
1667 case TM_PARSER_ZEPHIR:
1668 return "::";
1670 case TM_PARSER_LATEX:
1671 case TM_PARSER_MARKDOWN:
1672 case TM_PARSER_TXT2TAGS:
1673 return "\"\"";
1675 /* these parsers don't report nested scopes but default "." for scope separator
1676 * might appear in the text so use something more improbable */
1677 case TM_PARSER_ASCIIDOC:
1678 case TM_PARSER_CONF:
1679 case TM_PARSER_REST:
1680 return "\x3";
1682 default:
1683 return ".";
1688 const gchar *tm_parser_scope_separator_printable(TMParserType lang)
1690 switch (lang)
1692 case TM_PARSER_ASCIIDOC:
1693 case TM_PARSER_CONF:
1694 case TM_PARSER_LATEX:
1695 case TM_PARSER_MARKDOWN:
1696 case TM_PARSER_REST:
1697 case TM_PARSER_TXT2TAGS:
1698 return " > ";
1700 default:
1701 return tm_parser_scope_separator(lang);
1706 gboolean tm_parser_has_full_scope(TMParserType lang)
1708 switch (lang)
1710 /* These parsers include full hierarchy in the tag scope, separated by tm_parser_scope_separator() */
1711 case TM_PARSER_ACTIONSCRIPT:
1712 case TM_PARSER_C:
1713 case TM_PARSER_CPP:
1714 case TM_PARSER_CUDA:
1715 case TM_PARSER_CSHARP:
1716 case TM_PARSER_COBOL:
1717 case TM_PARSER_D:
1718 case TM_PARSER_GDSCRIPT:
1719 case TM_PARSER_GO:
1720 case TM_PARSER_JAVA:
1721 case TM_PARSER_JAVASCRIPT:
1722 case TM_PARSER_JSON:
1723 case TM_PARSER_LATEX:
1724 case TM_PARSER_LUA:
1725 case TM_PARSER_MARKDOWN:
1726 case TM_PARSER_PHP:
1727 case TM_PARSER_POWERSHELL:
1728 case TM_PARSER_PYTHON:
1729 case TM_PARSER_R:
1730 case TM_PARSER_RUBY:
1731 case TM_PARSER_RUST:
1732 case TM_PARSER_SQL:
1733 case TM_PARSER_TCL:
1734 case TM_PARSER_TCLOO:
1735 case TM_PARSER_TXT2TAGS:
1736 case TM_PARSER_TYPESCRIPT:
1737 case TM_PARSER_VALA:
1738 case TM_PARSER_VHDL:
1739 case TM_PARSER_VERILOG:
1740 case TM_PARSER_ZEPHIR:
1741 case TM_PARSER_AUTOIT:
1742 return TRUE;
1744 /* These make use of the scope, but don't include nested hierarchy
1745 * (either as a parser limitation or a language semantic) */
1746 case TM_PARSER_ADA:
1747 case TM_PARSER_ASCIIDOC:
1748 case TM_PARSER_CLOJURE:
1749 case TM_PARSER_CONF:
1750 case TM_PARSER_ERLANG:
1751 case TM_PARSER_FORTRAN:
1752 case TM_PARSER_OBJC:
1753 case TM_PARSER_OCAML:
1754 case TM_PARSER_REST:
1755 /* Other parsers don't use scope at all (or should be somewhere above) */
1756 default:
1757 return FALSE;
1762 gboolean tm_parser_langs_compatible(TMParserType lang, TMParserType other)
1764 if (lang == TM_PARSER_NONE || other == TM_PARSER_NONE)
1765 return FALSE;
1766 if (lang == other)
1767 return TRUE;
1768 /* Accept CPP tags for C lang and vice versa */
1769 else if (lang == TM_PARSER_C && other == TM_PARSER_CPP)
1770 return TRUE;
1771 else if (lang == TM_PARSER_CPP && other == TM_PARSER_C)
1772 return TRUE;
1774 return FALSE;