1 /* 2 * Copyright (c) 1998-2003, Darren Hiebert 3 * 4 * This source code is released for free distribution under the terms of the 5 * GNU General Public License version 2 or (at your option) any later version. 6 * 7 * Private definitions for parsing support. 8 */ 9 #ifndef CTAGS_MAIN_PARSE_H 10 #define CTAGS_MAIN_PARSE_H 11 12 /* 13 * INCLUDE FILES 14 */ 15 #include "general.h" /* must always come first */ 16 #include "types.h" 17 18 #include "kind.h" 19 #include "lregex.h" 20 #include "lxpath.h" 21 #include "vstring.h" 22 23 /* 24 * MACROS 25 */ 26 #define LANG_AUTO (-1) 27 #define LANG_IGNORE (-2) 28 29 /* 30 * DATA DECLARATIONS 31 */ 32 typedef enum { 33 RESCAN_NONE, /* No rescan needed */ 34 RESCAN_FAILED, /* Scan failed, clear out tags added, rescan */ 35 RESCAN_APPEND /* Scan succeeded, rescan */ 36 } rescanReason; 37 38 typedef void (*createRegexTag) (const vString* const name); 39 typedef void (*simpleParser) (void); 40 typedef rescanReason (*rescanParser) (const unsigned int passCount); 41 typedef void (*parserInitialize) (langType language); 42 typedef void (*initStatistics) (langType language); 43 typedef void (*printStatistics) (langType langType); 44 45 /* Per language finalizer is called anytime when ctags exits. 46 (Exceptions are a kind of options are given when invoked. Here 47 options are: --version, --help, --list-*, and so on.) 48 49 The finalizer is called even when the initializer of the 50 same parser is called or not. However, the finalizer can know 51 whether the associated initializer is invoked or not with the 52 second parameter: INITIALIZED. If it is true, the initializer 53 is called. */ 54 typedef void (*parserFinalize) (langType language, bool initialized); 55 56 typedef enum { 57 METHOD_NOT_CRAFTED = 1 << 0, 58 METHOD_REGEX = 1 << 1, 59 METHOD_XPATH = 1 << 2, 60 } parsingMethod; 61 62 typedef struct { 63 const char *name; 64 const int id; 65 } keywordTable; 66 67 typedef enum { 68 CORK_NO_USE, 69 CORK_QUEUE = (1 << 0), 70 CORK_SYMTAB = (1 << 1), 71 } corkUsage; 72 73 /* optlib2c requires the declaration here. */ 74 enum scriptHook { 75 SCRIPT_HOOK_PRELUDE, 76 SCRIPT_HOOK_SEQUEL, 77 SCRIPT_HOOK_MAX, 78 }; 79 80 struct sParserDefinition { 81 /* defined by parser */ 82 char* name; /* name of language */ 83 kindDefinition* kindTable; /* tag kinds handled by parser */ 84 unsigned int kindCount; /* size of `kinds' list */ 85 const char *const *extensions; /* list of default extensions */ 86 const char *const *patterns; /* list of default file name patterns */ 87 const char *const *aliases; /* list of default aliases (alternative names) */ 88 parserInitialize initialize; /* initialization routine, if needed */ 89 parserFinalize finalize; /* finalize routine, if needed */ 90 simpleParser parser; /* simple parser (common case) */ 91 rescanParser parser2; /* rescanning parser (unusual case) */ 92 selectLanguage* selectLanguage; /* may be used to resolve conflicts */ 93 unsigned int method; /* See METHOD_ definitions above */ 94 unsigned int useCork; /* bit fields of corkUsage */ 95 bool useMemoryStreamInput; 96 bool allowNullTag; 97 bool requestAutomaticFQTag; 98 tagRegexTable *tagRegexTable; 99 unsigned int tagRegexCount; 100 const keywordTable *keywordTable; 101 unsigned int keywordCount; 102 tagXpathTableTable *tagXpathTableTable; 103 unsigned int tagXpathTableCount; 104 bool invisible; 105 fieldDefinition *fieldTable; 106 unsigned int fieldCount; 107 xtagDefinition *xtagTable; 108 unsigned int xtagCount; 109 110 parserDependency * dependencies; 111 unsigned int dependencyCount; 112 113 parameterHandlerTable *parameterHandlerTable; 114 unsigned int parameterHandlerCount; 115 116 xpathFileSpec *xpathFileSpecs; 117 unsigned int xpathFileSpecCount; 118 119 /* Following two fields are used in a parser using cork. */ 120 const char *defaultScopeSeparator; 121 const char *defaultRootScopeSeparator; 122 123 initStatistics initStats; 124 printStatistics printStats; 125 126 /* used internally */ 127 langType id; /* id assigned to language */ 128 unsigned int enabled:1; /* currently enabled? */ 129 unsigned int traced:1; 130 }; 131 132 typedef parserDefinition* (parserDefinitionFunc) (void); 133 134 /* 135 * FUNCTION PROTOTYPES 136 */ 137 138 /* Language processing and parsing */ 139 extern int makeSimpleTag (const vString* const name, const int kindIndex); 140 extern int makeSimpleRefTag (const vString* const name, const int kindIndex, 141 int roleIndex); 142 extern int makeSimplePlaceholder(const vString* const name); 143 extern parserDefinition* parserNew (const char* name); 144 145 extern const char *getLanguageName (const langType language); 146 extern const char *getLanguageKindName (const langType language, const int kindIndex); 147 148 extern langType getNamedLanguage (const char *const name, size_t len); 149 extern langType getNamedLanguageOrAlias (const char *const name, size_t len); 150 extern langType getLanguageForFilenameAndContents (const char *const fileName); 151 extern langType getLanguageForCommand (const char *const command, langType startFrom); 152 extern langType getLanguageForFilename (const char *const filename, langType startFrom); 153 extern bool isLanguageEnabled (const langType language); 154 extern bool isLanguageKindEnabled (const langType language, int kindIndex); 155 extern bool isLanguageRoleEnabled (const langType language, int kindIndex, int roleIndex); 156 157 extern kindDefinition* getLanguageKindForLetter (const langType language, char kindLetter); 158 159 extern void initializeParser (langType language); 160 extern unsigned int getLanguageCorkUsage (langType language); 161 162 #ifdef HAVE_ICONV 163 extern const char *getLanguageEncoding (const langType language); 164 #endif 165 166 167 /* Regex interface */ 168 extern void addLanguageCallbackRegex (const langType language, const char *const regex, const char *const flags, 169 const regexCallback callback, bool *disabled, void *userData); 170 extern void findRegexTagsMainloop (int (* driver)(void)); 171 extern void findRegexTags (void); 172 173 /* Multiline Regex Interface */ 174 extern void addLanguageRegexTable (const langType language, const char *name); 175 extern void addLanguageTagMultiTableRegex(const langType language, 176 const char* const table_name, 177 const char* const regex, 178 const char* const name, const char* const kinds, const char* const flags, 179 bool *disabled); 180 181 extern void addLanguageOptscriptToHook (langType language, enum scriptHook hook, const char *const src); 182 183 extern void anonGenerate (vString *buffer, const char *prefix, int kind); 184 extern void anonConcat (vString *buffer, int kind); 185 extern vString *anonGenerateNew (const char *prefix, int kind); 186 extern void anonHashString (const char *filename, char buf[9]); 187 188 #endif /* CTAGS_MAIN_PARSE_H */ 189