1d4c6f1e6SMasatake YAMATO /* 2d4c6f1e6SMasatake YAMATO * Copyright (c) 1998-2003, Darren Hiebert 3d4c6f1e6SMasatake YAMATO * 4d4c6f1e6SMasatake YAMATO * This source code is released for free distribution under the terms of the 50ce38835Sviccuad * GNU General Public License version 2 or (at your option) any later version. 6d4c6f1e6SMasatake YAMATO * 7d4c6f1e6SMasatake YAMATO * Private definitions for parsing support. 8d4c6f1e6SMasatake YAMATO */ 95474c2e5SMasatake YAMATO #ifndef CTAGS_MAIN_PARSE_H 105474c2e5SMasatake YAMATO #define CTAGS_MAIN_PARSE_H 11d4c6f1e6SMasatake YAMATO 12d4c6f1e6SMasatake YAMATO /* 13d4c6f1e6SMasatake YAMATO * INCLUDE FILES 14d4c6f1e6SMasatake YAMATO */ 15d4c6f1e6SMasatake YAMATO #include "general.h" /* must always come first */ 16c645eb4cSMasatake YAMATO #include "types.h" 17c645eb4cSMasatake YAMATO 18d548ab51SMasatake YAMATO #include "kind.h" 19bce55cc7SMasatake YAMATO #include "lregex.h" 200061bd0aSMasatake YAMATO #include "lxpath.h" 21934a26beSMasatake YAMATO #include "vstring.h" 22d4c6f1e6SMasatake YAMATO 23d4c6f1e6SMasatake YAMATO /* 24d4c6f1e6SMasatake YAMATO * MACROS 25d4c6f1e6SMasatake YAMATO */ 26d4c6f1e6SMasatake YAMATO #define LANG_AUTO (-1) 27d4c6f1e6SMasatake YAMATO #define LANG_IGNORE (-2) 28d4c6f1e6SMasatake YAMATO 29d4c6f1e6SMasatake YAMATO /* 30d4c6f1e6SMasatake YAMATO * DATA DECLARATIONS 31d4c6f1e6SMasatake YAMATO */ 32d4c6f1e6SMasatake YAMATO typedef enum { 33d4c6f1e6SMasatake YAMATO RESCAN_NONE, /* No rescan needed */ 34d4c6f1e6SMasatake YAMATO RESCAN_FAILED, /* Scan failed, clear out tags added, rescan */ 35d4c6f1e6SMasatake YAMATO RESCAN_APPEND /* Scan succeeded, rescan */ 36d4c6f1e6SMasatake YAMATO } rescanReason; 37d4c6f1e6SMasatake YAMATO 38d4c6f1e6SMasatake YAMATO typedef void (*createRegexTag) (const vString* const name); 39d4c6f1e6SMasatake YAMATO typedef void (*simpleParser) (void); 40d4c6f1e6SMasatake YAMATO typedef rescanReason (*rescanParser) (const unsigned int passCount); 41d4c6f1e6SMasatake YAMATO typedef void (*parserInitialize) (langType language); 42a9c91f4dSMasatake YAMATO typedef void (*initStatistics) (langType language); 43a9c91f4dSMasatake YAMATO typedef void (*printStatistics) (langType langType); 4419e4de57SMasatake YAMATO 4519e4de57SMasatake YAMATO /* Per language finalizer is called anytime when ctags exits. 4619e4de57SMasatake YAMATO (Exceptions are a kind of options are given when invoked. Here 4719e4de57SMasatake YAMATO options are: --version, --help, --list-*, and so on.) 4819e4de57SMasatake YAMATO 4919e4de57SMasatake YAMATO The finalizer is called even when the initializer of the 5019e4de57SMasatake YAMATO same parser is called or not. However, the finalizer can know 51759d281dSK.Takata whether the associated initializer is invoked or not with the 5219e4de57SMasatake YAMATO second parameter: INITIALIZED. If it is true, the initializer 5319e4de57SMasatake YAMATO is called. */ 54ce990805SThomas Braun typedef void (*parserFinalize) (langType language, bool initialized); 5519e4de57SMasatake YAMATO 56d4c6f1e6SMasatake YAMATO typedef enum { 57d4c6f1e6SMasatake YAMATO METHOD_NOT_CRAFTED = 1 << 0, 58d4c6f1e6SMasatake YAMATO METHOD_REGEX = 1 << 1, 593e7e9e07SMasatake YAMATO METHOD_XPATH = 1 << 2, 60d4c6f1e6SMasatake YAMATO } parsingMethod; 61d4c6f1e6SMasatake YAMATO 62d4c6f1e6SMasatake YAMATO typedef struct { 63c379c5d2SMasatake YAMATO const char *name; 64ed9f06eaSMasatake YAMATO const int id; 65c379c5d2SMasatake YAMATO } keywordTable; 66c379c5d2SMasatake YAMATO 676b1a862eSMasatake YAMATO typedef enum { 686b1a862eSMasatake YAMATO CORK_NO_USE, 696b1a862eSMasatake YAMATO CORK_QUEUE = (1 << 0), 70363a6369SMasatake YAMATO CORK_SYMTAB = (1 << 1), 716b1a862eSMasatake YAMATO } corkUsage; 726b1a862eSMasatake YAMATO 73b6124a60SMasatake YAMATO /* optlib2c requires the declaration here. */ 74b6124a60SMasatake YAMATO enum scriptHook { 75b6124a60SMasatake YAMATO SCRIPT_HOOK_PRELUDE, 76b6124a60SMasatake YAMATO SCRIPT_HOOK_SEQUEL, 77b6124a60SMasatake YAMATO SCRIPT_HOOK_MAX, 78b6124a60SMasatake YAMATO }; 79b6124a60SMasatake YAMATO 80135b4bc5SMasatake YAMATO struct sParserDefinition { 81d4c6f1e6SMasatake YAMATO /* defined by parser */ 82d4c6f1e6SMasatake YAMATO char* name; /* name of language */ 8309ae690fSMasatake YAMATO kindDefinition* kindTable; /* tag kinds handled by parser */ 84d4c6f1e6SMasatake YAMATO unsigned int kindCount; /* size of `kinds' list */ 85d4c6f1e6SMasatake YAMATO const char *const *extensions; /* list of default extensions */ 86d4c6f1e6SMasatake YAMATO const char *const *patterns; /* list of default file name patterns */ 87d4c6f1e6SMasatake YAMATO const char *const *aliases; /* list of default aliases (alternative names) */ 88d4c6f1e6SMasatake YAMATO parserInitialize initialize; /* initialization routine, if needed */ 89d4c6f1e6SMasatake YAMATO parserFinalize finalize; /* finalize routine, if needed */ 90d4c6f1e6SMasatake YAMATO simpleParser parser; /* simple parser (common case) */ 91d4c6f1e6SMasatake YAMATO rescanParser parser2; /* rescanning parser (unusual case) */ 925a38b5ceSMasatake YAMATO selectLanguage* selectLanguage; /* may be used to resolve conflicts */ 933a66a4ecSMasatake YAMATO unsigned int method; /* See METHOD_ definitions above */ 944af999f5SMasatake YAMATO unsigned int useCork; /* bit fields of corkUsage */ 95e535639cSMasatake YAMATO bool useMemoryStreamInput; 96ce990805SThomas Braun bool allowNullTag; 97ce990805SThomas Braun bool requestAutomaticFQTag; 985654c1fbSMasatake YAMATO tagRegexTable *tagRegexTable; 99dc0f490fSMasatake YAMATO unsigned int tagRegexCount; 100ed9f06eaSMasatake YAMATO const keywordTable *keywordTable; 101c379c5d2SMasatake YAMATO unsigned int keywordCount; 102a086aff1SMasatake YAMATO tagXpathTableTable *tagXpathTableTable; 103a086aff1SMasatake YAMATO unsigned int tagXpathTableCount; 104ce990805SThomas Braun bool invisible; 105a739fa5fSMasatake YAMATO fieldDefinition *fieldTable; 106a739fa5fSMasatake YAMATO unsigned int fieldCount; 107a02a9600SMasatake YAMATO xtagDefinition *xtagTable; 108a02a9600SMasatake YAMATO unsigned int xtagCount; 109d4c6f1e6SMasatake YAMATO 11078143775SMasatake YAMATO parserDependency * dependencies; 11178143775SMasatake YAMATO unsigned int dependencyCount; 1124d6cdcecSMasatake YAMATO 1134d6cdcecSMasatake YAMATO parameterHandlerTable *parameterHandlerTable; 1144d6cdcecSMasatake YAMATO unsigned int parameterHandlerCount; 1154d6cdcecSMasatake YAMATO 116d5e6de9cSMasatake YAMATO xpathFileSpec *xpathFileSpecs; 117d5e6de9cSMasatake YAMATO unsigned int xpathFileSpecCount; 118d5e6de9cSMasatake YAMATO 1195535211dSMasatake YAMATO /* Following two fields are used in a parser using cork. */ 1205535211dSMasatake YAMATO const char *defaultScopeSeparator; 1215535211dSMasatake YAMATO const char *defaultRootScopeSeparator; 1225535211dSMasatake YAMATO 123a9c91f4dSMasatake YAMATO initStatistics initStats; 124a9c91f4dSMasatake YAMATO printStatistics printStats; 125a9c91f4dSMasatake YAMATO 126d4c6f1e6SMasatake YAMATO /* used internally */ 127c645eb4cSMasatake YAMATO langType id; /* id assigned to language */ 12819e4de57SMasatake YAMATO unsigned int enabled:1; /* currently enabled? */ 129782707aeSMasatake YAMATO unsigned int traced:1; 130135b4bc5SMasatake YAMATO }; 131d4c6f1e6SMasatake YAMATO 132d4c6f1e6SMasatake YAMATO typedef parserDefinition* (parserDefinitionFunc) (void); 133d4c6f1e6SMasatake YAMATO 134d4c6f1e6SMasatake YAMATO /* 135d4c6f1e6SMasatake YAMATO * FUNCTION PROTOTYPES 136d4c6f1e6SMasatake YAMATO */ 137d4c6f1e6SMasatake YAMATO 138d4c6f1e6SMasatake YAMATO /* Language processing and parsing */ 13916a2541cSMasatake YAMATO extern int makeSimpleTag (const vString* const name, const int kindIndex); 14016a2541cSMasatake YAMATO extern int makeSimpleRefTag (const vString* const name, const int kindIndex, 1417868fb2eSMasatake YAMATO int roleIndex); 142a7c2b428SMasatake YAMATO extern int makeSimplePlaceholder(const vString* const name); 143d4c6f1e6SMasatake YAMATO extern parserDefinition* parserNew (const char* name); 1440d502ef0SMasatake YAMATO 145d4c6f1e6SMasatake YAMATO extern const char *getLanguageName (const langType language); 146bea76990SMasatake YAMATO extern const char *getLanguageKindName (const langType language, const int kindIndex); 1470d502ef0SMasatake YAMATO 1485a55f03bSMasatake YAMATO extern langType getNamedLanguage (const char *const name, size_t len); 1499a391711SMasatake YAMATO extern langType getNamedLanguageOrAlias (const char *const name, size_t len); 1505329ae51SMasatake YAMATO extern langType getLanguageForFilenameAndContents (const char *const fileName); 151334e072fSMasatake YAMATO extern langType getLanguageForCommand (const char *const command, langType startFrom); 152416c5e6bSMasatake YAMATO extern langType getLanguageForFilename (const char *const filename, langType startFrom); 153ce990805SThomas Braun extern bool isLanguageEnabled (const langType language); 1545c56d939SMasatake YAMATO extern bool isLanguageKindEnabled (const langType language, int kindIndex); 155320b1e8bSMasatake YAMATO extern bool isLanguageRoleEnabled (const langType language, int kindIndex, int roleIndex); 156ebd6043dSMasatake YAMATO 1570d502ef0SMasatake YAMATO extern kindDefinition* getLanguageKindForLetter (const langType language, char kindLetter); 15883f24c3bSMasatake YAMATO 159ad1a3891SMasatake YAMATO extern void initializeParser (langType language); 160a64816f9SMasatake YAMATO extern unsigned int getLanguageCorkUsage (langType language); 161d4c6f1e6SMasatake YAMATO 1622acdcfa1SYasuhiro Matsumoto #ifdef HAVE_ICONV 163bde9f60aSColomban Wendling extern const char *getLanguageEncoding (const langType language); 1642acdcfa1SYasuhiro Matsumoto #endif 1652acdcfa1SYasuhiro Matsumoto 166c379c5d2SMasatake YAMATO 167d4c6f1e6SMasatake YAMATO /* Regex interface */ 16853dda59eSMasatake YAMATO extern void addLanguageCallbackRegex (const langType language, const char *const regex, const char *const flags, 169ce990805SThomas Braun const regexCallback callback, bool *disabled, void *userData); 1700d502ef0SMasatake YAMATO extern void findRegexTagsMainloop (int (* driver)(void)); 1710d502ef0SMasatake YAMATO extern void findRegexTags (void); 172d4c6f1e6SMasatake YAMATO 1734e0c6ed6SMasatake YAMATO /* Multiline Regex Interface */ 17489c588f7SMasatake YAMATO extern void addLanguageRegexTable (const langType language, const char *name); 17589c588f7SMasatake YAMATO extern void addLanguageTagMultiTableRegex(const langType language, 17689c588f7SMasatake YAMATO const char* const table_name, 17789c588f7SMasatake YAMATO const char* const regex, 17889c588f7SMasatake YAMATO const char* const name, const char* const kinds, const char* const flags, 17989c588f7SMasatake YAMATO bool *disabled); 180bf809d1aSMasatake YAMATO 181b6124a60SMasatake YAMATO extern void addLanguageOptscriptToHook (langType language, enum scriptHook hook, const char *const src); 1825c872341SMasatake YAMATO 183d1437c58SMasatake YAMATO extern void anonGenerate (vString *buffer, const char *prefix, int kind); 184*a13d8d73SMasatake YAMATO extern void anonConcat (vString *buffer, int kind); 18522f2e7c1SMasatake YAMATO extern vString *anonGenerateNew (const char *prefix, int kind); 1862b15528aSMasatake YAMATO extern void anonHashString (const char *filename, char buf[9]); 187d1437c58SMasatake YAMATO 1885474c2e5SMasatake YAMATO #endif /* CTAGS_MAIN_PARSE_H */ 189