|
dvander@345
|
1 |
#if defined _textparse_included |
|
dvander@345
|
2 |
#endinput |
|
dvander@345
|
3 |
#endif |
|
dvander@345
|
4 |
#define _textparse_included |
|
dvander@345
|
5 |
|
|
dvander@345
|
6 |
|
|
dvander@345
|
7 |
/******************************** |
|
dvander@345
|
8 |
* Everything below describes the SMC Parse, or "SourceMod Configuration" format. |
|
dvander@345
|
9 |
* This parser is entirely event based. You must hook events to receive data. |
|
dvander@345
|
10 |
* The file format itself is nearly identical to Valve's KeyValues format. |
|
dvander@345
|
11 |
********************************/ |
|
dvander@345
|
12 |
|
|
dvander@345
|
13 |
enum SMCResult |
|
dvander@345
|
14 |
{ |
|
dvander@345
|
15 |
SMCParse_Continue, //continue parsing |
|
dvander@345
|
16 |
SMCParse_Halt, //stop parsing here |
|
dvander@345
|
17 |
SMCParse_HaltFail //stop parsing and return failure |
|
dvander@345
|
18 |
}; |
|
dvander@345
|
19 |
|
|
dvander@345
|
20 |
enum SMCError |
|
dvander@345
|
21 |
{ |
|
dvander@345
|
22 |
SMCError_Okay = 0, //no error |
|
dvander@345
|
23 |
SMCError_StreamOpen, //stream failed to open |
|
dvander@345
|
24 |
SMCError_StreamError, //the stream died... somehow |
|
dvander@345
|
25 |
SMCError_Custom, //a custom handler threw an error |
|
dvander@345
|
26 |
SMCError_InvalidSection1, //a section was declared without quotes, and had extra tokens |
|
dvander@345
|
27 |
SMCError_InvalidSection2, //a section was declared without any header |
|
dvander@345
|
28 |
SMCError_InvalidSection3, //a section ending was declared with too many unknown tokens |
|
dvander@345
|
29 |
SMCError_InvalidSection4, //a section ending has no matching beginning |
|
dvander@345
|
30 |
SMCError_InvalidSection5, //a section beginning has no matching ending |
|
dvander@345
|
31 |
SMCError_InvalidTokens, //there were too many unidentifiable strings on one line |
|
dvander@345
|
32 |
SMCError_TokenOverflow, //the token buffer overflowed |
|
dvander@345
|
33 |
SMCError_InvalidProperty1, //a property was declared outside of any section |
|
dvander@345
|
34 |
}; |
|
dvander@345
|
35 |
|
|
dvander@345
|
36 |
/** |
|
dvander@345
|
37 |
* Creates a new SMC file format parser. This is used to set parse hooks. |
|
dvander@345
|
38 |
* |
|
dvander@345
|
39 |
* @return A new Handle to an SMC Parse structure. |
|
dvander@345
|
40 |
*/ |
|
dvander@345
|
41 |
native Handle:SMC_CreateParse(); |
|
dvander@345
|
42 |
|
|
dvander@345
|
43 |
/** |
|
dvander@345
|
44 |
* Parses an SMC file. |
|
dvander@345
|
45 |
* |
|
dvander@345
|
46 |
* @param smc A Handle to an SMC Parse structure. |
|
dvander@345
|
47 |
* @param file A string containing the file path. |
|
dvander@345
|
48 |
* @param line An optional by reference cell to store the last line number read. |
|
dvander@345
|
49 |
* @param col An optional by reference cell to store the last column number read. |
|
dvander@345
|
50 |
* @return An SMCParseError result. |
|
dvander@345
|
51 |
* @error Invalid or corrupt Handle. |
|
dvander@345
|
52 |
*/ |
|
dvander@345
|
53 |
native SMCError:SMC_ParseFile(Handle:smc, const String:file[], &line=0, &col=0); |
|
dvander@345
|
54 |
|
|
dvander@345
|
55 |
/** |
|
dvander@345
|
56 |
* Gets an error string for an SMCError code. |
|
dvander@345
|
57 |
* @note SMCError_Okay returns false. |
|
dvander@345
|
58 |
* @note SMCError_Custom (which is thrown on SMCParse_HaltFail) returns false. |
|
dvander@345
|
59 |
* |
|
dvander@345
|
60 |
* @param error The SMCParseError code. |
|
dvander@345
|
61 |
* @param buffer A string buffer for the error (contents undefined on failure). |
|
dvander@345
|
62 |
* @param buf_max The maximum size of the buffer. |
|
dvander@345
|
63 |
* @return True on success, false otherwise. |
|
dvander@345
|
64 |
*/ |
|
dvander@345
|
65 |
native bool:SMC_GetErrorString(SMCError:error, String:buffer[], buf_max); |
|
dvander@345
|
66 |
|
|
dvander@345
|
67 |
/** |
|
dvander@345
|
68 |
* Called when parsing is started. |
|
dvander@345
|
69 |
* |
|
dvander@345
|
70 |
* @param smc The SMC Parse Handle. |
|
dvander@345
|
71 |
* @noreturn |
|
dvander@345
|
72 |
*/ |
|
dvander@345
|
73 |
functag SMC_ParseStart public(Handle:smc); |
|
dvander@345
|
74 |
|
|
dvander@345
|
75 |
/** |
|
dvander@345
|
76 |
* Sets the SMC_ParseStart function of a parse Handle. |
|
dvander@345
|
77 |
* |
|
dvander@345
|
78 |
* @param smc Handle to an SMC Parse. |
|
dvander@345
|
79 |
* @param func SMC_ParseStart function. |
|
dvander@345
|
80 |
* @noreturn |
|
dvander@345
|
81 |
* @error Invalid or corrupt Handle. |
|
dvander@345
|
82 |
*/ |
|
dvander@345
|
83 |
native SMC_SetParseStart(Handle:smc, SMC_ParseStart:func); |
|
dvander@345
|
84 |
|
|
dvander@345
|
85 |
/** |
|
dvander@345
|
86 |
* Called when parsing is halted. |
|
dvander@345
|
87 |
* |
|
dvander@345
|
88 |
* @param smc The SMC Parse Handle. |
|
dvander@345
|
89 |
* @param halted True if abnormally halted, false otherwise. |
|
dvander@345
|
90 |
* @param failed True if parsing failed, false otherwise. |
|
dvander@345
|
91 |
* @noreturn |
|
dvander@345
|
92 |
*/ |
|
dvander@345
|
93 |
functag SMC_ParseEnd public(Handle:smc, bool:halted, bool:failed); |
|
dvander@345
|
94 |
|
|
dvander@345
|
95 |
/** |
|
dvander@345
|
96 |
* Sets the SMC_ParseEnd of a parse handle. |
|
dvander@345
|
97 |
* |
|
dvander@345
|
98 |
* @param smc Handle to an SMC Parse. |
|
dvander@345
|
99 |
* @param func SMC_ParseEnd function. |
|
dvander@345
|
100 |
* @noreturn |
|
dvander@345
|
101 |
* @error Invalid or corrupt Handle. |
|
dvander@345
|
102 |
*/ |
|
dvander@345
|
103 |
native SMC_SetParseEnd(Handle:smc, SMC_ParseEnd:func); |
|
dvander@345
|
104 |
|
|
dvander@345
|
105 |
/** |
|
dvander@345
|
106 |
* Called when the parser is entering a new section or sub-section. |
|
dvander@345
|
107 |
* @note Enclosing quotes are always stripped. |
|
dvander@345
|
108 |
* |
|
dvander@345
|
109 |
* @param smc The SMC Parse Handle. |
|
dvander@345
|
110 |
* @param name String containing section name. |
|
dvander@345
|
111 |
* @param opt_quotes True if the section name was quote-enclosed in the file. |
|
dvander@345
|
112 |
* @return An SMCResult action to take. |
|
dvander@345
|
113 |
*/ |
|
dvander@345
|
114 |
functag SMC_NewSection SMCResult:public(Handle:smc, const String:name[], bool:opt_quotes); |
|
dvander@345
|
115 |
|
|
dvander@345
|
116 |
/** |
|
dvander@345
|
117 |
* Called when the parser finds a new key/value pair. |
|
dvander@345
|
118 |
* @note Enclosing quotes are always stripped. |
|
dvander@345
|
119 |
* |
|
dvander@345
|
120 |
* @param smc The SMC Parse Handle. |
|
dvander@345
|
121 |
* @param key String containing key name. |
|
dvander@345
|
122 |
* @param value String containing value name. |
|
dvander@345
|
123 |
* @param key_quotes Whether or not the key was enclosed in quotes. |
|
dvander@345
|
124 |
* @param value_quotes Whether or not the value was enclosed in quotes. |
|
dvander@345
|
125 |
* @return An SMCResult action to take. |
|
dvander@345
|
126 |
*/ |
|
dvander@345
|
127 |
functag SMC_KeyValue SMCResult:public(Handle:smc, const String:key[], const String:value[], bool:key_quotes, bool:value_quotes); |
|
dvander@345
|
128 |
|
|
dvander@345
|
129 |
/** |
|
dvander@345
|
130 |
* Called when the parser finds the end of the current section. |
|
dvander@345
|
131 |
* |
|
dvander@345
|
132 |
* @param smc The SMC Parse Handle. |
|
dvander@345
|
133 |
* @return An SMCResult action to take. |
|
dvander@345
|
134 |
*/ |
|
dvander@345
|
135 |
functag SMC_EndSection SMCResult:public(Handle:smc); |
|
dvander@345
|
136 |
|
|
dvander@345
|
137 |
/** |
|
dvander@345
|
138 |
* Sets the three main reader functions. |
|
dvander@345
|
139 |
* |
|
dvander@345
|
140 |
* @param smc An SMC parse Handle. |
|
dvander@345
|
141 |
* @param ns An SMC_NewSection function pointer. |
|
dvander@345
|
142 |
* @param kv An SMC_KeyValue function pointer. |
|
dvander@345
|
143 |
* @param es An SMC_EndSection function pointer. |
|
dvander@345
|
144 |
* @noreturn |
|
dvander@345
|
145 |
*/ |
|
dvander@345
|
146 |
native SMC_SetReaders(Handle:smc, SMC_NewSection:ns, SMC_KeyValue:kv, SMC_EndSection:es); |
|
dvander@345
|
147 |
|
|
dvander@345
|
148 |
/** |
|
dvander@345
|
149 |
* Called whenever a raw line is read. |
|
dvander@345
|
150 |
* |
|
dvander@345
|
151 |
* @param smc The SMC Parse Handle. |
|
dvander@345
|
152 |
* @param line A string containing the raw line from the file. |
|
dvander@345
|
153 |
* @param lineno The line number it occurs on. |
|
dvander@345
|
154 |
* @return An SMCResult action to take. |
|
dvander@345
|
155 |
*/ |
|
dvander@345
|
156 |
functag SMC_RawLine SMCResult:public(Handle:smc, const String:line[], lineno); |
|
dvander@345
|
157 |
|
|
dvander@345
|
158 |
/** |
|
dvander@345
|
159 |
* Sets a raw line reader on an SMC parser Handle. |
|
dvander@345
|
160 |
* |
|
dvander@345
|
161 |
* @param smc Handle to an SMC Parse. |
|
dvander@345
|
162 |
* @param func SMC_RawLine function. |
|
dvander@345
|
163 |
* @noreturn |
|
dvander@345
|
164 |
*/ |
|
dvander@345
|
165 |
native SMC_SetRawLine(Handle:smc, SMC_Rawline:func); |