13b13813cSMasatake YAMATO /* 23b13813cSMasatake YAMATO * Copyright (c) 2020, Masatake YAMATO 33b13813cSMasatake YAMATO * 43b13813cSMasatake YAMATO * This source code is released for free distribution under the terms of the 53b13813cSMasatake YAMATO * GNU General Public License version 2 or (at your option) any later version. 63b13813cSMasatake YAMATO * 73b13813cSMasatake YAMATO * Tex base parser interface exported to subparsers 83b13813cSMasatake YAMATO */ 93b13813cSMasatake YAMATO 103b13813cSMasatake YAMATO #ifndef CTAGS_PARSER_TEX_H 113b13813cSMasatake YAMATO #define CTAGS_PARSER_TEX_H 123b13813cSMasatake YAMATO 133b13813cSMasatake YAMATO /* 143b13813cSMasatake YAMATO * INCLUDE FILES 153b13813cSMasatake YAMATO */ 163b13813cSMasatake YAMATO 173b13813cSMasatake YAMATO #include "general.h" /* must always come first */ 183b13813cSMasatake YAMATO 193b13813cSMasatake YAMATO #include "subparser.h" 203b13813cSMasatake YAMATO #include "vstring.h" 213b13813cSMasatake YAMATO 223b13813cSMasatake YAMATO 233b13813cSMasatake YAMATO /* 243b13813cSMasatake YAMATO * DATA DEFINITIONS 253b13813cSMasatake YAMATO */ 263b13813cSMasatake YAMATO 273b13813cSMasatake YAMATO /* Parsing strategy */ 283b13813cSMasatake YAMATO 293b13813cSMasatake YAMATO enum TexNameFlag { 303b13813cSMasatake YAMATO /* Allow that the type of input token doesn't match 313b13813cSMasatake YAMATO * the type of strategy. In stread of aborting, 323b13813cSMasatake YAMATO * apply the next strategy to the same token. */ 333b13813cSMasatake YAMATO TEX_NAME_FLAG_OPTIONAL = (1 << 0), 343b13813cSMasatake YAMATO 353b13813cSMasatake YAMATO /* When reading tokens inside pair, 363b13813cSMasatake YAMATO * whitespaces are considered as parts of a token or not. */ 373b13813cSMasatake YAMATO TEX_NAME_FLAG_INCLUDING_WHITESPACE = (1 << 1), 383b13813cSMasatake YAMATO 393b13813cSMasatake YAMATO /* If a tag is created with this strategy, don't 403b13813cSMasatake YAMATO * create a tag in its successor strategies. */ 413b13813cSMasatake YAMATO TEX_NAME_FLAG_EXCLUSIVE = (1 << 2), 423b13813cSMasatake YAMATO }; 433b13813cSMasatake YAMATO 443b13813cSMasatake YAMATO struct TexParseStrategy { 45*c6cbaf9cSJiří Techet /* Expected token type '<', '[', '*', '{', and '\\' are supported. 46*c6cbaf9cSJiří Techet * 0 means the end of strategies. '\\' means {} pair may be omitted. 473b13813cSMasatake YAMATO * 483b13813cSMasatake YAMATO * A string between <>, [], or {} (pairs) can be tagged or store to 493b13813cSMasatake YAMATO * a vString. See kindIndex and name field of this structure. 503b13813cSMasatake YAMATO */ 513b13813cSMasatake YAMATO int type; 523b13813cSMasatake YAMATO 533b13813cSMasatake YAMATO /* Bits combination of enum TexNameFlag */ 543b13813cSMasatake YAMATO unsigned int flags; 553b13813cSMasatake YAMATO 56f7be3a35SMasatake YAMATO /* Kind and role for making a tag for the string surrounded by one of pairs. 573b13813cSMasatake YAMATO * If you don't need to make a tag for the string, 583b13813cSMasatake YAMATO * specify KIND_GHOST_INDEX. */ 593b13813cSMasatake YAMATO int kindIndex; 60993d4289SMasatake YAMATO int roleIndex; 613b13813cSMasatake YAMATO 623b13813cSMasatake YAMATO /* If a tag is made, Tex parser stores its cork index here. */ 633b13813cSMasatake YAMATO int corkIndex; 643b13813cSMasatake YAMATO 653b13813cSMasatake YAMATO /* Store the string surrounded by one of paris. 663b13813cSMasatake YAMATO * If you don't need to store the string, set NULL here. */ 673b13813cSMasatake YAMATO vString *name; 68f67e271cSMasatake YAMATO 69f67e271cSMasatake YAMATO /* If true, make at most one tag for the name in the scope specified 70f67e271cSMasatake YAMATO * with scopeIndex. When making a tag, scopeIndex is set to 71f67e271cSMasatake YAMATO * extensionFields.scopeIndex only if unique is true. 72f67e271cSMasatake YAMATO * scopeIndex is never referred if unique if false. */ 73f67e271cSMasatake YAMATO bool unique; 74f67e271cSMasatake YAMATO int scopeIndex; 753b13813cSMasatake YAMATO }; 763b13813cSMasatake YAMATO 773b13813cSMasatake YAMATO typedef struct sTexSubparser texSubparser; 783b13813cSMasatake YAMATO struct sTexSubparser { 793b13813cSMasatake YAMATO subparser subparser; 803b13813cSMasatake YAMATO 811cfa869bSMasatake YAMATO /* When Tex parser reads an \begin{foo}, it calls 821cfa869bSMasatake YAMATO * this method. 831cfa869bSMasatake YAMATO * 841cfa869bSMasatake YAMATO * A subparser having interests in successor tokens may return strategies. 851cfa869bSMasatake YAMATO * If it doesn't, just return NULL; Tex base parser may call the next subparser. 861cfa869bSMasatake YAMATO */ 871cfa869bSMasatake YAMATO struct TexParseStrategy * (* readEnviromentBeginNotify) (texSubparser *s, 881cfa869bSMasatake YAMATO vString *env); 891cfa869bSMasatake YAMATO /* When Tex parser reads an \end{foo}, it calls 901cfa869bSMasatake YAMATO * this method. 911cfa869bSMasatake YAMATO * 921cfa869bSMasatake YAMATO * If this method returns true, Tex base parser may call the next subparser. 931cfa869bSMasatake YAMATO * If it returns false, Tex base parser stops calling the rest of subparsers. 941cfa869bSMasatake YAMATO */ 951cfa869bSMasatake YAMATO bool (* readEnviromentEndNotify) (texSubparser *s, vString *env); 961cfa869bSMasatake YAMATO 973b13813cSMasatake YAMATO /* When Tex parser reads an \identifier, it calls 983b13813cSMasatake YAMATO * this method. 993b13813cSMasatake YAMATO * 1003b13813cSMasatake YAMATO * A subparser having interests in successor tokens may return strategies. 1013b13813cSMasatake YAMATO * If it has no interest, just return NULL; Tex base parser may call next subparser. 1023b13813cSMasatake YAMATO */ 1033b13813cSMasatake YAMATO struct TexParseStrategy *(* readIdentifierNotify) (texSubparser *s, 1043b13813cSMasatake YAMATO vString *identifier); 105f03d2abaSMasatake YAMATO 106f03d2abaSMasatake YAMATO /* After Tex parser runs the strategies returned from readIdentifierNotify 107f03d2abaSMasatake YAMATO * method, Tex parser calls this method to notify the subparser the result 108f03d2abaSMasatake YAMATO * of running the strategies; corkIndex and/or name fields of strategies 109f03d2abaSMasatake YAMATO * may be filled. */ 110f03d2abaSMasatake YAMATO void (* reportStrategicParsing) (texSubparser *s, 111f03d2abaSMasatake YAMATO const struct TexParseStrategy *strategy); 1123b13813cSMasatake YAMATO }; 1133b13813cSMasatake YAMATO 1143b13813cSMasatake YAMATO #endif /* CTAGS_PARSER_TEX_H */ 115