xref: /Universal-ctags/parsers/glade.c (revision 20c8252b10749d3e8e3ff6662378276290650ced)
1 /*
2 *
3 *   Copyright (c) 2015, Masatake YAMATO
4 *   Copyright (c) 2015, Red Hat, K.K.
5 *
6 *   This source code is released for free distribution under the terms of the
7 *   GNU General Public License version 2 or (at your option) any later version.
8 *
9 *   This module contains functions for generating tags for diff files (based on Sh parser).
10 */
11 
12 #include "general.h"	/* must always come first */
13 #include "entry.h"
14 #include "debug.h"
15 #include "parse.h"
16 #include "read.h"
17 #include "routines.h"
18 #include "xml.h"
19 
20 
21 typedef enum {
22 	R_CLASS_WIDGET,
23 } gladeClassRole;
24 
25 typedef enum {
26 	R_HANDLER_HANDLER,
27 } gladeHandleRoler;
28 
29 static roleDefinition GladeClassRoles [] = {
30 	{ true, "widget", "specified as a widget constructor" },
31 };
32 
33 static roleDefinition GladeHandlerRoles [] = {
34 	{ true, "handler", "specified as a callback for signal emission" },
35 };
36 
37 typedef enum {
38 	K_CLASS, K_HANDLER,
39 } gladeKind;
40 
41 static kindDefinition GladeKinds [] = {
42 	/* These two are appeared on names in C source code. */
43 	{ true,  'c', "class",	  "classes",
44 	  .referenceOnly = true, ATTACH_ROLES (GladeClassRoles) },
45 	{ true,  'h', "handler",  "handlers",
46 	  .referenceOnly = true, ATTACH_ROLES (GladeHandlerRoles) },
47 };
48 
49 static tagXpathTable gladeXpathMainTable[] = {
50 	{ "///glade-interface//widget//@class",
51 	  LXPATH_TABLE_DO_MAKE,
52 	  { .makeTagSpec = { K_CLASS, R_CLASS_WIDGET } }
53 	},
54 	{ "///glade-interface//signal//@handler",
55 	  LXPATH_TABLE_DO_MAKE,
56 	  { .makeTagSpec = { K_HANDLER, R_HANDLER_HANDLER }}
57 	},
58 };
59 
60 enum gladeXpathTable {
61 	TABLE_MAIN
62 };
63 
64 static tagXpathTableTable gladeXpathTableTable[] = {
65 	[TABLE_MAIN] = { ARRAY_AND_SIZE(gladeXpathMainTable) },
66 };
67 
68 static void
findGladeTags(void)69 findGladeTags (void)
70 {
71 	scheduleRunningBaseparser (RUN_DEFAULT_SUBPARSERS);
72 }
73 
74 
75 static void
runXPathEngine(xmlSubparser * s,xmlXPathContext * ctx,xmlNode * root)76 runXPathEngine(xmlSubparser *s,
77 			   xmlXPathContext *ctx, xmlNode *root)
78 {
79 	findXMLTags (ctx, root, TABLE_MAIN, NULL);
80 }
81 
82 static xmlSubparser gladeSubparser = {
83 	.subparser = {
84 		.direction = SUBPARSER_BI_DIRECTION,
85 	},
86 	.runXPathEngine = runXPathEngine,
87 };
88 
89 extern parserDefinition*
GladeParser(void)90 GladeParser (void)
91 {
92 	static const char *const extensions [] = { "glade", NULL };
93 	parserDefinition* const def = parserNew ("Glade");
94 	static parserDependency dependencies [] = {
95 		[0] = { DEPTYPE_SUBPARSER, "XML", &gladeSubparser },
96 	};
97 
98 	def->kindTable         = GladeKinds;
99 	def->kindCount     = ARRAY_SIZE (GladeKinds);
100 	def->extensions    = extensions;
101 	def->parser        = findGladeTags;
102 	def->tagXpathTableTable  = gladeXpathTableTable;
103 	def->tagXpathTableCount  = ARRAY_SIZE (gladeXpathTableTable);
104 	def->dependencies = dependencies;
105 	def->dependencyCount = ARRAY_SIZE (dependencies);
106 	return def;
107 }
108