1 /* 2 * Copyright (c) 2016, Masatake YAMATO 3 * Copyright (c) 2016, Red Hat, Inc. 4 * 5 * This source code is released for free distribution under the terms of the 6 * GNU General Public License version 2 or (at your option) any later version. 7 * 8 * Xpath based parer API 9 */ 10 #ifndef CTAGS_LXPATH_PARSE_H 11 #define CTAGS_LXPATH_PARSE_H 12 13 /* 14 * INCLUDE FILES 15 */ 16 17 #include "general.h" /* must always come first */ 18 #include "types.h" 19 20 #ifdef HAVE_LIBXML 21 #include <libxml/xpath.h> 22 #include <libxml/tree.h> 23 #else 24 #define xmlNode void 25 #define xmlXPathCompExpr void 26 #define xmlXPathContext void 27 #endif 28 29 30 /* 31 * DATA DECLARATIONS 32 */ 33 34 typedef struct sTagXpathMakeTagSpec { 35 /* Kind used in making a tag. 36 If kind is KIND_GHOST_INDEX, a function 37 specified with decideKind is called to decide 38 the kind for the tag. */ 39 int kind; 40 int role; 41 /* If make is NULL, just makeTagEntry is used instead. */ 42 void (*make) (xmlNode *node, 43 const char *xpath, 44 const struct sTagXpathMakeTagSpec *spec, 45 tagEntryInfo *tag, 46 void *userData); 47 int (*decideKind) (xmlNode *node, 48 const char *xpath, 49 const struct sTagXpathMakeTagSpec *spec, 50 void *userData); 51 /* TODO: decideRole */ 52 } tagXpathMakeTagSpec; 53 54 typedef struct sTagXpathRecurSpec { 55 void (*enter) (xmlNode *node, 56 const char *xpath, 57 const struct sTagXpathRecurSpec *spec, 58 xmlXPathContext *ctx, 59 void *userData); 60 61 int nextTable; /* A parser can use this field any purpose. 62 main/lxpath part doesn't touch this. */ 63 64 } tagXpathRecurSpec; 65 66 typedef struct sTagXpathTable 67 { 68 const char *const xpath; 69 enum { LXPATH_TABLE_DO_MAKE, LXPATH_TABLE_DO_RECUR } specType; 70 union { 71 tagXpathMakeTagSpec makeTagSpec; 72 tagXpathRecurSpec recurSpec; 73 } spec; 74 xmlXPathCompExpr* xpathCompiled; 75 } tagXpathTable; 76 77 typedef struct sTagXpathTableTable { 78 tagXpathTable *table; 79 unsigned int count; 80 } tagXpathTableTable; 81 82 typedef struct sXpathFileSpec { 83 /* 84 NULL represents the associated field in DTD is not examined. 85 "" (an empty string) represents the associated field in DTD 86 (and root element) must not exist. */ 87 const char *rootElementName; 88 const char *nameInDTD; 89 const char *externalID; 90 const char *systemID; 91 const char *rootNSPrefix; 92 const char *rootNSHref; 93 } xpathFileSpec; 94 95 96 /* 97 * FUNCTION PROTOTYPES 98 */ 99 100 /* Xpath interface */ 101 extern void findXMLTagsFull (xmlXPathContext *ctx, xmlNode *root, 102 int tableTableIndex, 103 void (* runAfter) (xmlXPathContext *, xmlNode *, void *), 104 void *userData); 105 106 extern void findXMLTags (xmlXPathContext *ctx, xmlNode *root, 107 int tableTableIndex, 108 void *userData); 109 110 #endif /* CTAGS_LXPATH_PARSE_H */ 111