xref: /Universal-ctags/parsers/tex.h (revision c6cbaf9cc4b7fccde7384e99bcb8b042e03021ff)
1 /*
2 *   Copyright (c) 2020, Masatake YAMATO
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 *   Tex base parser interface exported to subparsers
8 */
9 
10 #ifndef CTAGS_PARSER_TEX_H
11 #define CTAGS_PARSER_TEX_H
12 
13 /*
14 *	 INCLUDE FILES
15 */
16 
17 #include "general.h"  /* must always come first */
18 
19 #include "subparser.h"
20 #include "vstring.h"
21 
22 
23 /*
24 *	 DATA DEFINITIONS
25 */
26 
27 /* Parsing strategy */
28 
29 enum TexNameFlag {
30 	/* Allow that the type of input token doesn't match
31 	 * the type of strategy. In stread of aborting,
32 	 * apply the next strategy to the same token. */
33 	TEX_NAME_FLAG_OPTIONAL             = (1 << 0),
34 
35 	/* When reading tokens inside pair,
36 	 * whitespaces are considered as parts of a token or not. */
37 	TEX_NAME_FLAG_INCLUDING_WHITESPACE = (1 << 1),
38 
39 	/* If a tag is created with this strategy, don't
40 	 * create a tag in its successor strategies. */
41 	TEX_NAME_FLAG_EXCLUSIVE            = (1 << 2),
42 };
43 
44 struct TexParseStrategy {
45 	/* Expected token type '<', '[', '*', '{', and '\\' are supported.
46 	 * 0 means the end of strategies. '\\' means {} pair may be omitted.
47 	 *
48 	 * A string between <>, [], or {} (pairs) can be tagged or store to
49 	 * a vString. See kindIndex and name field of this structure.
50 	 */
51 	int type;
52 
53 	/* Bits combination of enum TexNameFlag */
54 	unsigned int flags;
55 
56 	/* Kind and role for making a tag for the string surrounded by one of pairs.
57 	 * If you don't need to make a tag for the string,
58 	 * specify KIND_GHOST_INDEX. */
59 	int kindIndex;
60 	int roleIndex;
61 
62 	/* If a tag is made, Tex parser stores its cork index here. */
63 	int corkIndex;
64 
65 	/* Store the string surrounded by one of paris.
66 	 * If you don't need to store the string, set NULL here. */
67 	vString *name;
68 
69 	/* If true, make at most one tag for the name in the scope specified
70 	 * with scopeIndex. When making a tag, scopeIndex is set to
71 	 * extensionFields.scopeIndex only if unique is true.
72 	 * scopeIndex is never referred if unique if false. */
73 	bool unique;
74 	int scopeIndex;
75 };
76 
77 typedef struct sTexSubparser texSubparser;
78 struct sTexSubparser {
79 	subparser subparser;
80 
81 	/* When Tex parser reads an \begin{foo}, it calls
82 	 * this method.
83 	 *
84 	 * A subparser having interests in successor tokens may return strategies.
85 	 * If it doesn't, just return NULL; Tex base parser may call the next subparser.
86 	 */
87 	struct TexParseStrategy * (* readEnviromentBeginNotify) (texSubparser *s,
88 															 vString *env);
89 	/* When Tex parser reads an \end{foo}, it calls
90 	 * this method.
91 	 *
92 	 * If this method returns true, Tex base parser may call the next subparser.
93 	 * If it returns false, Tex base parser stops calling the rest of subparsers.
94 	 */
95 	bool (* readEnviromentEndNotify) (texSubparser *s, vString *env);
96 
97 	/* When Tex parser reads an \identifier, it calls
98 	 * this method.
99 	 *
100 	 * A subparser having interests in successor tokens may return strategies.
101 	 * If it has no interest, just return NULL; Tex base parser may call next subparser.
102 	 */
103 	struct TexParseStrategy *(* readIdentifierNotify) (texSubparser *s,
104 													   vString *identifier);
105 
106 	/* After Tex parser runs the strategies returned from readIdentifierNotify
107 	 * method, Tex parser calls this method to notify the subparser the result
108 	 * of running the strategies; corkIndex and/or name fields of strategies
109 	 * may be filled. */
110 	void (* reportStrategicParsing) (texSubparser *s,
111 									 const struct TexParseStrategy *strategy);
112 };
113 
114 #endif	/* CTAGS_PARSER_TEX_H */
115