rmultimarkdown 6.4.0.4 → 6.7.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. checksums.yaml +5 -5
  2. data/Rakefile +7 -13
  3. data/ext/Makefile +67 -55
  4. data/ext/extconf.rb +7 -5
  5. data/ext/mmd/aho-corasick.c +8 -8
  6. data/ext/mmd/aho-corasick.h +3 -3
  7. data/ext/mmd/argtable3.c +6537 -0
  8. data/ext/mmd/argtable3.h +273 -0
  9. data/ext/mmd/beamer.c +12 -1
  10. data/ext/mmd/char.c +120 -27
  11. data/ext/mmd/char.h +23 -23
  12. data/ext/mmd/critic_markup.c +7 -6
  13. data/ext/mmd/d_string.c +88 -32
  14. data/ext/mmd/{include/d_string.h → d_string.h} +50 -38
  15. data/ext/mmd/epub.c +36 -12
  16. data/ext/mmd/epub.h +2 -2
  17. data/ext/mmd/file.c +50 -40
  18. data/ext/mmd/file.h +2 -2
  19. data/ext/mmd/html.c +164 -99
  20. data/ext/mmd/html.h +3 -2
  21. data/ext/mmd/i18n.h +15 -11
  22. data/ext/mmd/itmz-lexer.c +16978 -0
  23. data/ext/mmd/itmz-lexer.h +132 -0
  24. data/ext/mmd/itmz-parser.c +1189 -0
  25. data/ext/mmd/itmz-parser.h +11 -0
  26. data/ext/mmd/itmz-reader.c +388 -0
  27. data/ext/mmd/itmz-reader.h +111 -0
  28. data/ext/mmd/itmz.c +567 -0
  29. data/ext/mmd/itmz.h +117 -0
  30. data/ext/mmd/latex.c +93 -41
  31. data/ext/mmd/lexer.c +3506 -2774
  32. data/ext/mmd/{include/libMultiMarkdown.h → libMultiMarkdown.h} +49 -2
  33. data/ext/mmd/main.c +612 -0
  34. data/ext/mmd/memoir.c +4 -1
  35. data/ext/mmd/miniz.c +6905 -6680
  36. data/ext/mmd/miniz.h +456 -476
  37. data/ext/mmd/mmd.c +399 -94
  38. data/ext/mmd/mmd.h +25 -25
  39. data/ext/mmd/object_pool.h +3 -3
  40. data/ext/mmd/opendocument-content.c +137 -69
  41. data/ext/mmd/opendocument-content.h +2 -2
  42. data/ext/mmd/opendocument.c +35 -14
  43. data/ext/mmd/opendocument.h +2 -2
  44. data/ext/mmd/opml-lexer.c +259 -637
  45. data/ext/mmd/opml-lexer.h +1 -17
  46. data/ext/mmd/opml-parser.c +194 -188
  47. data/ext/mmd/opml-reader.c +72 -142
  48. data/ext/mmd/opml-reader.h +1 -1
  49. data/ext/mmd/opml.c +13 -13
  50. data/ext/mmd/opml.h +1 -1
  51. data/ext/mmd/parser.c +1623 -1244
  52. data/ext/mmd/rng.c +8 -3
  53. data/ext/mmd/scanners.c +66625 -103198
  54. data/ext/mmd/scanners.h +1 -0
  55. data/ext/mmd/stack.c +62 -20
  56. data/ext/mmd/stack.h +10 -21
  57. data/ext/mmd/textbundle.c +23 -7
  58. data/ext/mmd/textbundle.h +2 -2
  59. data/ext/mmd/token.c +42 -16
  60. data/ext/mmd/{include/token.h → token.h} +22 -8
  61. data/ext/mmd/token_pairs.c +0 -16
  62. data/ext/mmd/transclude.c +6 -2
  63. data/ext/mmd/uthash.h +745 -745
  64. data/ext/mmd/version.h +8 -8
  65. data/ext/mmd/writer.c +225 -63
  66. data/ext/mmd/writer.h +50 -36
  67. data/ext/mmd/xml.c +855 -0
  68. data/ext/mmd/xml.h +134 -0
  69. data/ext/mmd/zip.c +71 -4
  70. data/ext/mmd/zip.h +7 -1
  71. data/ext/ruby_multi_markdown.c +9 -18
  72. data/lib/multi_markdown/version.rb +1 -1
  73. data/lib/multi_markdown.bundle +0 -0
  74. data/rmultimarkdown.gemspec +0 -2
  75. metadata +22 -28
  76. data/ext/mmd/char_lookup.c +0 -212
@@ -0,0 +1,1189 @@
1
+ /*
2
+ ** 2000-05-29
3
+ **
4
+ ** The author disclaims copyright to this source code. In place of
5
+ ** a legal notice, here is a blessing:
6
+ **
7
+ ** May you do good and not evil.
8
+ ** May you find forgiveness for yourself and forgive others.
9
+ ** May you share freely, never taking more than you give.
10
+ **
11
+ *************************************************************************
12
+ ** Driver template for the LEMON parser generator.
13
+ **
14
+ ** The "lemon" program processes an LALR(1) input grammar file, then uses
15
+ ** this template to construct a parser. The "lemon" program inserts text
16
+ ** at each "%%" line. Also, any "P-a-r-s-e" identifer prefix (without the
17
+ ** interstitial "-" characters) contained in this template is changed into
18
+ ** the value of the %name directive from the grammar. Otherwise, the content
19
+ ** of this template is copied straight through into the generate parser
20
+ ** source file.
21
+ **
22
+ ** The following is the concatenation of all %include directives from the
23
+ ** input grammar file:
24
+ */
25
+ #include <stdio.h>
26
+ /************ Begin %include sections from the grammar ************************/
27
+
28
+ #include <assert.h>
29
+ #include <stdio.h>
30
+ #include <stdlib.h>
31
+
32
+ #include "libMultiMarkdown.h"
33
+ #include "mmd.h"
34
+ #include "parser.h"
35
+ #include "token.h"
36
+ /**************** End of %include directives **********************************/
37
+ /* These constants specify the various numeric values for terminal symbols
38
+ ** in a format understandable to "makeheaders". This section is blank unless
39
+ ** "lemon" is run with the "-m" command-line option.
40
+ ***************** Begin makeheaders token definitions *************************/
41
+ /**************** End makeheaders token definitions ***************************/
42
+
43
+ /* The next sections is a series of control #defines.
44
+ ** various aspects of the generated parser.
45
+ ** YYCODETYPE is the data type used to store the integer codes
46
+ ** that represent terminal and non-terminal symbols.
47
+ ** "unsigned char" is used if there are fewer than
48
+ ** 256 symbols. Larger types otherwise.
49
+ ** YYNOCODE is a number of type YYCODETYPE that is not used for
50
+ ** any terminal or nonterminal symbol.
51
+ ** YYFALLBACK If defined, this indicates that one or more tokens
52
+ ** (also known as: "terminal symbols") have fall-back
53
+ ** values which should be used if the original symbol
54
+ ** would not parse. This permits keywords to sometimes
55
+ ** be used as identifiers, for example.
56
+ ** YYACTIONTYPE is the data type used for "action codes" - numbers
57
+ ** that indicate what to do in response to the next
58
+ ** token.
59
+ ** ITMZTOKENTYPE is the data type used for minor type for terminal
60
+ ** symbols. Background: A "minor type" is a semantic
61
+ ** value associated with a terminal or non-terminal
62
+ ** symbols. For example, for an "ID" terminal symbol,
63
+ ** the minor type might be the name of the identifier.
64
+ ** Each non-terminal can have a different minor type.
65
+ ** Terminal symbols all have the same minor type, though.
66
+ ** This macros defines the minor type for terminal
67
+ ** symbols.
68
+ ** YYMINORTYPE is the data type used for all minor types.
69
+ ** This is typically a union of many types, one of
70
+ ** which is ITMZTOKENTYPE. The entry in the union
71
+ ** for terminal symbols is called "yy0".
72
+ ** YYSTACKDEPTH is the maximum depth of the parser's stack. If
73
+ ** zero the stack is dynamically sized using realloc()
74
+ ** ITMZARG_SDECL A static variable declaration for the %extra_argument
75
+ ** ITMZARG_PDECL A parameter declaration for the %extra_argument
76
+ ** ITMZARG_STORE Code to store %extra_argument into yypParser
77
+ ** ITMZARG_FETCH Code to extract %extra_argument from yypParser
78
+ ** YYERRORSYMBOL is the code number of the error symbol. If not
79
+ ** defined, then do no error processing.
80
+ ** YYNSTATE the combined number of states.
81
+ ** YYNRULE the number of rules in the grammar
82
+ ** YY_MAX_SHIFT Maximum value for shift actions
83
+ ** YY_MIN_SHIFTREDUCE Minimum value for shift-reduce actions
84
+ ** YY_MAX_SHIFTREDUCE Maximum value for shift-reduce actions
85
+ ** YY_MIN_REDUCE Maximum value for reduce actions
86
+ ** YY_ERROR_ACTION The yy_action[] code for syntax error
87
+ ** YY_ACCEPT_ACTION The yy_action[] code for accept
88
+ ** YY_NO_ACTION The yy_action[] code for no-op
89
+ */
90
+ #ifndef INTERFACE
91
+ #define INTERFACE 1
92
+ #endif
93
+ /************* Begin control #defines *****************************************/
94
+ #define YYCODETYPE unsigned char
95
+ #define YYNOCODE 20
96
+ #define YYACTIONTYPE unsigned char
97
+ #define ITMZTOKENTYPE token *
98
+ typedef union {
99
+ int yyinit;
100
+ ITMZTOKENTYPE yy0;
101
+ } YYMINORTYPE;
102
+ #ifndef YYSTACKDEPTH
103
+ #define YYSTACKDEPTH 100
104
+ #endif
105
+ #define ITMZARG_SDECL mmd_engine * engine ;
106
+ #define ITMZARG_PDECL , mmd_engine * engine
107
+ #define ITMZARG_FETCH mmd_engine * engine = yypParser->engine
108
+ #define ITMZARG_STORE yypParser->engine = engine
109
+ #define YYNSTATE 15
110
+ #define YYNRULE 16
111
+ #define YY_MAX_SHIFT 14
112
+ #define YY_MIN_SHIFTREDUCE 28
113
+ #define YY_MAX_SHIFTREDUCE 43
114
+ #define YY_MIN_REDUCE 44
115
+ #define YY_MAX_REDUCE 59
116
+ #define YY_ERROR_ACTION 60
117
+ #define YY_ACCEPT_ACTION 61
118
+ #define YY_NO_ACTION 62
119
+ /************* End control #defines *******************************************/
120
+
121
+ /* Define the yytestcase() macro to be a no-op if is not already defined
122
+ ** otherwise.
123
+ **
124
+ ** Applications can choose to define yytestcase() in the %include section
125
+ ** to a macro that can assist in verifying code coverage. For production
126
+ ** code the yytestcase() macro should be turned off. But it is useful
127
+ ** for testing.
128
+ */
129
+ #ifndef yytestcase
130
+ #define yytestcase(X)
131
+ #endif
132
+
133
+
134
+ /* Next are the tables used to determine what action to take based on the
135
+ ** current state and lookahead token. These tables are used to implement
136
+ ** functions that take a state number and lookahead value and return an
137
+ ** action integer.
138
+ **
139
+ ** Suppose the action integer is N. Then the action is determined as
140
+ ** follows
141
+ **
142
+ ** 0 <= N <= YY_MAX_SHIFT Shift N. That is, push the lookahead
143
+ ** token onto the stack and goto state N.
144
+ **
145
+ ** N between YY_MIN_SHIFTREDUCE Shift to an arbitrary state then
146
+ ** and YY_MAX_SHIFTREDUCE reduce by rule N-YY_MIN_SHIFTREDUCE.
147
+ **
148
+ ** N between YY_MIN_REDUCE Reduce by rule N-YY_MIN_REDUCE
149
+ ** and YY_MAX_REDUCE
150
+ **
151
+ ** N == YY_ERROR_ACTION A syntax error has occurred.
152
+ **
153
+ ** N == YY_ACCEPT_ACTION The parser accepts its input.
154
+ **
155
+ ** N == YY_NO_ACTION No such action. Denotes unused
156
+ ** slots in the yy_action[] table.
157
+ **
158
+ ** The action table is constructed as a single large table named yy_action[].
159
+ ** Given state S and lookahead X, the action is computed as either:
160
+ **
161
+ ** (A) N = yy_action[ yy_shift_ofst[S] + X ]
162
+ ** (B) N = yy_default[S]
163
+ **
164
+ ** The (A) formula is preferred. The B formula is used instead if:
165
+ ** (1) The yy_shift_ofst[S]+X value is out of range, or
166
+ ** (2) yy_lookahead[yy_shift_ofst[S]+X] is not equal to X, or
167
+ ** (3) yy_shift_ofst[S] equal YY_SHIFT_USE_DFLT.
168
+ ** (Implementation note: YY_SHIFT_USE_DFLT is chosen so that
169
+ ** YY_SHIFT_USE_DFLT+X will be out of range for all possible lookaheads X.
170
+ ** Hence only tests (1) and (2) need to be evaluated.)
171
+ **
172
+ ** The formulas above are for computing the action when the lookahead is
173
+ ** a terminal symbol. If the lookahead is a non-terminal (as occurs after
174
+ ** a reduce action) then the yy_reduce_ofst[] array is used in place of
175
+ ** the yy_shift_ofst[] array and YY_REDUCE_USE_DFLT is used in place of
176
+ ** YY_SHIFT_USE_DFLT.
177
+ **
178
+ ** The following are the tables generated in this section:
179
+ **
180
+ ** yy_action[] A single table containing all actions.
181
+ ** yy_lookahead[] A table containing the lookahead for each entry in
182
+ ** yy_action. Used to detect hash collisions.
183
+ ** yy_shift_ofst[] For each state, the offset into yy_action for
184
+ ** shifting terminals.
185
+ ** yy_reduce_ofst[] For each state, the offset into yy_action for
186
+ ** shifting non-terminals after a reduce.
187
+ ** yy_default[] Default action for each state.
188
+ **
189
+ *********** Begin parsing tables **********************************************/
190
+ #define YY_ACTTAB_COUNT (61)
191
+ static const YYACTIONTYPE yy_action[] = {
192
+ /* 0 */ 4, 1, 3, 34, 10, 2, 41, 12, 3, 40,
193
+ /* 10 */ 10, 2, 41, 3, 36, 10, 2, 41, 32, 3,
194
+ /* 20 */ 12, 10, 2, 41, 3, 39, 10, 2, 41, 3,
195
+ /* 30 */ 38, 10, 2, 41, 31, 3, 13, 10, 2, 41,
196
+ /* 40 */ 9, 11, 8, 8, 3, 30, 10, 2, 41, 61,
197
+ /* 50 */ 14, 5, 5, 37, 29, 6, 6, 7, 7, 42,
198
+ /* 60 */ 44,
199
+ };
200
+ static const YYCODETYPE yy_lookahead[] = {
201
+ /* 0 */ 3, 1, 5, 18, 7, 8, 9, 10, 5, 6,
202
+ /* 10 */ 7, 8, 9, 5, 6, 7, 8, 9, 4, 5,
203
+ /* 20 */ 10, 7, 8, 9, 5, 6, 7, 8, 9, 5,
204
+ /* 30 */ 6, 7, 8, 9, 4, 5, 16, 7, 8, 9,
205
+ /* 40 */ 15, 16, 17, 18, 5, 2, 7, 8, 9, 13,
206
+ /* 50 */ 14, 17, 18, 6, 2, 17, 18, 17, 18, 11,
207
+ /* 60 */ 0,
208
+ };
209
+ #define YY_SHIFT_USE_DFLT (61)
210
+ #define YY_SHIFT_COUNT (14)
211
+ #define YY_SHIFT_MIN (-3)
212
+ #define YY_SHIFT_MAX (60)
213
+ static const signed char yy_shift_ofst[] = {
214
+ /* 0 */ 0, -3, 3, 8, 14, 19, 24, 30, 39, 10,
215
+ /* 10 */ 47, 43, 48, 52, 60,
216
+ };
217
+ #define YY_REDUCE_USE_DFLT (-16)
218
+ #define YY_REDUCE_COUNT (9)
219
+ #define YY_REDUCE_MIN (-15)
220
+ #define YY_REDUCE_MAX (40)
221
+ static const signed char yy_reduce_ofst[] = {
222
+ /* 0 */ 36, 25, 34, 38, 40, -15, -15, -15, -15, 20,
223
+ };
224
+ static const YYACTIONTYPE yy_default[] = {
225
+ /* 0 */ 60, 59, 60, 60, 60, 60, 60, 60, 49, 59,
226
+ /* 10 */ 60, 60, 60, 60, 60,
227
+ };
228
+ /********** End of lemon-generated parsing tables *****************************/
229
+
230
+ /* The next table maps tokens (terminal symbols) into fallback tokens.
231
+ ** If a construct like the following:
232
+ **
233
+ ** %fallback ID X Y Z.
234
+ **
235
+ ** appears in the grammar, then ID becomes a fallback token for X, Y,
236
+ ** and Z. Whenever one of the tokens X, Y, or Z is input to the parser
237
+ ** but it does not parse, the type of the token is changed to ID and
238
+ ** the parse is retried before an error is thrown.
239
+ **
240
+ ** This feature can be used, for example, to cause some keywords in a language
241
+ ** to revert to identifiers if they keyword does not apply in the context where
242
+ ** it appears.
243
+ */
244
+ #ifdef YYFALLBACK
245
+ static const YYCODETYPE yyFallback[] = {
246
+ };
247
+ #endif /* YYFALLBACK */
248
+
249
+ /* The following structure represents a single element of the
250
+ ** parser's stack. Information stored includes:
251
+ **
252
+ ** + The state number for the parser at this level of the stack.
253
+ **
254
+ ** + The value of the token stored at this level of the stack.
255
+ ** (In other words, the "major" token.)
256
+ **
257
+ ** + The semantic value stored at this level of the stack. This is
258
+ ** the information used by the action routines in the grammar.
259
+ ** It is sometimes called the "minor" token.
260
+ **
261
+ ** After the "shift" half of a SHIFTREDUCE action, the stateno field
262
+ ** actually contains the reduce action for the second half of the
263
+ ** SHIFTREDUCE.
264
+ */
265
+ struct yyStackEntry {
266
+ YYACTIONTYPE stateno; /* The state-number, or reduce action in SHIFTREDUCE */
267
+ YYCODETYPE major; /* The major token value. This is the code
268
+ ** number for the token at this stack level */
269
+ YYMINORTYPE minor; /* The user-supplied minor token value. This
270
+ ** is the value of the token */
271
+ };
272
+ typedef struct yyStackEntry yyStackEntry;
273
+
274
+ /* The state of the parser is completely contained in an instance of
275
+ ** the following structure */
276
+ struct yyParser {
277
+ yyStackEntry * yytos; /* Pointer to top element of the stack */
278
+ #ifdef YYTRACKMAXSTACKDEPTH
279
+ int yyhwm; /* High-water mark of the stack */
280
+ #endif
281
+ #ifndef YYNOERRORRECOVERY
282
+ int yyerrcnt; /* Shifts left before out of the error */
283
+ #endif
284
+ ITMZARG_SDECL /* A place to hold %extra_argument */
285
+ #if YYSTACKDEPTH<=0
286
+ int yystksz; /* Current side of the stack */
287
+ yyStackEntry * yystack; /* The parser's stack */
288
+ yyStackEntry yystk0; /* First stack entry */
289
+ #else
290
+ yyStackEntry yystack[YYSTACKDEPTH]; /* The parser's stack */
291
+ #endif
292
+ };
293
+ typedef struct yyParser yyParser;
294
+
295
+ #ifndef NDEBUG
296
+ #include <stdio.h>
297
+ static FILE * yyTraceFILE = 0;
298
+ static char * yyTracePrompt = 0;
299
+ #endif /* NDEBUG */
300
+
301
+ #ifndef NDEBUG
302
+ /*
303
+ ** Turn parser tracing on by giving a stream to which to write the trace
304
+ ** and a prompt to preface each trace message. Tracing is turned off
305
+ ** by making either argument NULL
306
+ **
307
+ ** Inputs:
308
+ ** <ul>
309
+ ** <li> A FILE* to which trace output should be written.
310
+ ** If NULL, then tracing is turned off.
311
+ ** <li> A prefix string written at the beginning of every
312
+ ** line of trace output. If NULL, then tracing is
313
+ ** turned off.
314
+ ** </ul>
315
+ **
316
+ ** Outputs:
317
+ ** None.
318
+ */
319
+ void ITMZTrace(FILE * TraceFILE, char * zTracePrompt) {
320
+ yyTraceFILE = TraceFILE;
321
+ yyTracePrompt = zTracePrompt;
322
+
323
+ if ( yyTraceFILE == 0 ) {
324
+ yyTracePrompt = 0;
325
+ } else if ( yyTracePrompt == 0 ) {
326
+ yyTraceFILE = 0;
327
+ }
328
+ }
329
+ #endif /* NDEBUG */
330
+
331
+ #ifndef NDEBUG
332
+ /* For tracing shifts, the names of all terminals and nonterminals
333
+ ** are required. The following table supplies these names */
334
+ static const char * const yyTokenName[] = {
335
+ "$", "ITMZ_ITHOUGHTS_OPEN", "ITMZ_ITHOUGHTS_CLOSE", "ITMZ_TOPICS_OPEN",
336
+ "ITMZ_TOPICS_CLOSE", "ITMZ_TOPIC_OPEN", "ITMZ_TOPIC_CLOSE", "ITMZ_TOPIC_PREAMBLE",
337
+ "ITMZ_TOPIC_METADATA", "ITMZ_TOPIC_SELF_CLOSE", "ITMZ_RELATIONSHIPS_OPEN", "ITMZ_RELATIONSHIPS_CLOSE",
338
+ "error", "doc", "doc_ithoughts", "itmz_topics_section",
339
+ "itmz_relationships", "itmz_topics", "itmz_topic",
340
+ };
341
+ #endif /* NDEBUG */
342
+
343
+ #ifndef NDEBUG
344
+ /* For tracing reduce actions, the names of all rules are required.
345
+ */
346
+ static const char * const yyRuleName[] = {
347
+ /* 0 */ "doc ::= doc_ithoughts",
348
+ /* 1 */ "doc_ithoughts ::= ITMZ_ITHOUGHTS_OPEN itmz_topics_section itmz_relationships ITMZ_ITHOUGHTS_CLOSE",
349
+ /* 2 */ "doc_ithoughts ::= ITMZ_ITHOUGHTS_OPEN itmz_relationships ITMZ_ITHOUGHTS_CLOSE",
350
+ /* 3 */ "itmz_topics_section ::= ITMZ_TOPICS_OPEN itmz_topics ITMZ_TOPICS_CLOSE",
351
+ /* 4 */ "itmz_topics_section ::= ITMZ_TOPICS_OPEN ITMZ_TOPICS_CLOSE",
352
+ /* 5 */ "itmz_topics_section ::= itmz_topics",
353
+ /* 6 */ "itmz_topics ::= itmz_topics itmz_topic",
354
+ /* 7 */ "itmz_topics ::= itmz_topic",
355
+ /* 8 */ "itmz_topic ::= ITMZ_TOPIC_OPEN ITMZ_TOPIC_CLOSE",
356
+ /* 9 */ "itmz_topic ::= ITMZ_TOPIC_PREAMBLE ITMZ_TOPIC_CLOSE",
357
+ /* 10 */ "itmz_topic ::= ITMZ_TOPIC_OPEN itmz_topics ITMZ_TOPIC_CLOSE",
358
+ /* 11 */ "itmz_topic ::= ITMZ_TOPIC_METADATA itmz_topics ITMZ_TOPIC_CLOSE",
359
+ /* 12 */ "itmz_topic ::= ITMZ_TOPIC_METADATA ITMZ_TOPIC_CLOSE",
360
+ /* 13 */ "itmz_topic ::= ITMZ_TOPIC_SELF_CLOSE",
361
+ /* 14 */ "itmz_relationships ::= ITMZ_RELATIONSHIPS_OPEN ITMZ_RELATIONSHIPS_CLOSE",
362
+ /* 15 */ "itmz_relationships ::=",
363
+ };
364
+ #endif /* NDEBUG */
365
+
366
+
367
+ #if YYSTACKDEPTH<=0
368
+ /*
369
+ ** Try to increase the size of the parser stack. Return the number
370
+ ** of errors. Return 0 on success.
371
+ */
372
+ static int yyGrowStack(yyParser * p) {
373
+ int newSize;
374
+ int idx;
375
+ yyStackEntry * pNew;
376
+
377
+ newSize = p->yystksz * 2 + 100;
378
+ idx = p->yytos ? (int)(p->yytos - p->yystack) : 0;
379
+
380
+ if ( p->yystack == &p->yystk0 ) {
381
+ pNew = malloc(newSize * sizeof(pNew[0]));
382
+
383
+ if ( pNew ) {
384
+ pNew[0] = p->yystk0;
385
+ }
386
+ } else {
387
+ pNew = realloc(p->yystack, newSize * sizeof(pNew[0]));
388
+ }
389
+
390
+ if ( pNew ) {
391
+ p->yystack = pNew;
392
+ p->yytos = &p->yystack[idx];
393
+ #ifndef NDEBUG
394
+
395
+ if ( yyTraceFILE ) {
396
+ fprintf(yyTraceFILE, "%sStack grows from %d to %d entries.\n",
397
+ yyTracePrompt, p->yystksz, newSize);
398
+ }
399
+
400
+ #endif
401
+ p->yystksz = newSize;
402
+ }
403
+
404
+ return pNew == 0;
405
+ }
406
+ #endif
407
+
408
+ /* Datatype of the argument to the memory allocated passed as the
409
+ ** second argument to ITMZAlloc() below. This can be changed by
410
+ ** putting an appropriate #define in the %include section of the input
411
+ ** grammar.
412
+ */
413
+ #ifndef YYMALLOCARGTYPE
414
+ #define YYMALLOCARGTYPE size_t
415
+ #endif
416
+
417
+ /*
418
+ ** This function allocates a new parser.
419
+ ** The only argument is a pointer to a function which works like
420
+ ** malloc.
421
+ **
422
+ ** Inputs:
423
+ ** A pointer to the function used to allocate memory.
424
+ **
425
+ ** Outputs:
426
+ ** A pointer to a parser. This pointer is used in subsequent calls
427
+ ** to ITMZ and ITMZFree.
428
+ */
429
+ void * ITMZAlloc(void * (*mallocProc)(YYMALLOCARGTYPE)) {
430
+ yyParser * pParser;
431
+ pParser = (yyParser *)(*mallocProc)( (YYMALLOCARGTYPE)sizeof(yyParser) );
432
+
433
+ if ( pParser ) {
434
+ #ifdef YYTRACKMAXSTACKDEPTH
435
+ pParser->yyhwm = 0;
436
+ #endif
437
+ #if YYSTACKDEPTH<=0
438
+ pParser->yytos = NULL;
439
+ pParser->yystack = NULL;
440
+ pParser->yystksz = 0;
441
+
442
+ if ( yyGrowStack(pParser) ) {
443
+ pParser->yystack = &pParser->yystk0;
444
+ pParser->yystksz = 1;
445
+ }
446
+
447
+ #endif
448
+ #ifndef YYNOERRORRECOVERY
449
+ pParser->yyerrcnt = -1;
450
+ #endif
451
+ pParser->yytos = pParser->yystack;
452
+ pParser->yystack[0].stateno = 0;
453
+ pParser->yystack[0].major = 0;
454
+ }
455
+
456
+ return pParser;
457
+ }
458
+
459
+ /* The following function deletes the "minor type" or semantic value
460
+ ** associated with a symbol. The symbol can be either a terminal
461
+ ** or nonterminal. "yymajor" is the symbol code, and "yypminor" is
462
+ ** a pointer to the value to be deleted. The code used to do the
463
+ ** deletions is derived from the %destructor and/or %token_destructor
464
+ ** directives of the input grammar.
465
+ */
466
+ static void yy_destructor(
467
+ yyParser * yypParser, /* The parser */
468
+ YYCODETYPE yymajor, /* Type code for object to destroy */
469
+ YYMINORTYPE * yypminor /* The object to be destroyed */
470
+ ) {
471
+ ITMZARG_FETCH;
472
+
473
+ switch ( yymajor ) {
474
+ /* Here is inserted the actions which take place when a
475
+ ** terminal or non-terminal is destroyed. This can happen
476
+ ** when the symbol is popped from the stack during a
477
+ ** reduce or during error processing or when a parser is
478
+ ** being destroyed before it is finished parsing.
479
+ **
480
+ ** Note: during a reduce, the only symbols destroyed are those
481
+ ** which appear on the RHS of the rule, but which are *not* used
482
+ ** inside the C code.
483
+ */
484
+ /********* Begin destructor definitions ***************************************/
485
+ /********* End destructor definitions *****************************************/
486
+ default:
487
+ break; /* If no destructor action specified: do nothing */
488
+ }
489
+ }
490
+
491
+ /*
492
+ ** Pop the parser's stack once.
493
+ **
494
+ ** If there is a destructor routine associated with the token which
495
+ ** is popped from the stack, then call it.
496
+ */
497
+ static void yy_pop_parser_stack(yyParser * pParser) {
498
+ yyStackEntry * yytos;
499
+ assert( pParser->yytos != 0 );
500
+ assert( pParser->yytos > pParser->yystack );
501
+ yytos = pParser->yytos--;
502
+ #ifndef NDEBUG
503
+
504
+ if ( yyTraceFILE ) {
505
+ fprintf(yyTraceFILE, "%sPopping %s\n",
506
+ yyTracePrompt,
507
+ yyTokenName[yytos->major]);
508
+ }
509
+
510
+ #endif
511
+ yy_destructor(pParser, yytos->major, &yytos->minor);
512
+ }
513
+
514
+ /*
515
+ ** Deallocate and destroy a parser. Destructors are called for
516
+ ** all stack elements before shutting the parser down.
517
+ **
518
+ ** If the YYPARSEFREENEVERNULL macro exists (for example because it
519
+ ** is defined in a %include section of the input grammar) then it is
520
+ ** assumed that the input pointer is never NULL.
521
+ */
522
+ void ITMZFree(
523
+ void * p, /* The parser to be deleted */
524
+ void (*freeProc)(void *) /* Function used to reclaim memory */
525
+ ) {
526
+ yyParser * pParser = (yyParser *)p;
527
+ #ifndef YYPARSEFREENEVERNULL
528
+
529
+ if ( pParser == 0 ) {
530
+ return;
531
+ }
532
+
533
+ #endif
534
+
535
+ while ( pParser->yytos > pParser->yystack ) {
536
+ yy_pop_parser_stack(pParser);
537
+ }
538
+
539
+ #if YYSTACKDEPTH<=0
540
+
541
+ if ( pParser->yystack != &pParser->yystk0 ) {
542
+ free(pParser->yystack);
543
+ }
544
+
545
+ #endif
546
+ (*freeProc)((void *)pParser);
547
+ }
548
+
549
+ /*
550
+ ** Return the peak depth of the stack for a parser.
551
+ */
552
+ #ifdef YYTRACKMAXSTACKDEPTH
553
+ int ITMZStackPeak(void * p) {
554
+ yyParser * pParser = (yyParser *)p;
555
+ return pParser->yyhwm;
556
+ }
557
+ #endif
558
+
559
+ /*
560
+ ** Find the appropriate action for a parser given the terminal
561
+ ** look-ahead token iLookAhead.
562
+ */
563
+ static unsigned int yy_find_shift_action(
564
+ yyParser * pParser, /* The parser */
565
+ YYCODETYPE iLookAhead /* The look-ahead token */
566
+ ) {
567
+ int i;
568
+ int stateno = pParser->yytos->stateno;
569
+
570
+ if ( stateno >= YY_MIN_REDUCE ) {
571
+ return stateno;
572
+ }
573
+
574
+ assert( stateno <= YY_SHIFT_COUNT );
575
+
576
+ do {
577
+ i = yy_shift_ofst[stateno];
578
+ assert( iLookAhead != YYNOCODE );
579
+ i += iLookAhead;
580
+
581
+ if ( i < 0 || i >= YY_ACTTAB_COUNT || yy_lookahead[i] != iLookAhead ) {
582
+ #ifdef YYFALLBACK
583
+ YYCODETYPE iFallback; /* Fallback token */
584
+
585
+ if ( iLookAhead < sizeof(yyFallback) / sizeof(yyFallback[0])
586
+ && (iFallback = yyFallback[iLookAhead]) != 0 ) {
587
+ #ifndef NDEBUG
588
+
589
+ if ( yyTraceFILE ) {
590
+ fprintf(yyTraceFILE, "%sFALLBACK %s => %s\n",
591
+ yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]);
592
+ }
593
+
594
+ #endif
595
+ assert( yyFallback[iFallback] == 0 ); /* Fallback loop must terminate */
596
+ iLookAhead = iFallback;
597
+ continue;
598
+ }
599
+
600
+ #endif
601
+ #ifdef YYWILDCARD
602
+ {
603
+ int j = i - iLookAhead + YYWILDCARD;
604
+
605
+ if (
606
+ #if YY_SHIFT_MIN+YYWILDCARD<0
607
+ j >= 0 &&
608
+ #endif
609
+ #if YY_SHIFT_MAX+YYWILDCARD>=YY_ACTTAB_COUNT
610
+ j < YY_ACTTAB_COUNT &&
611
+ #endif
612
+ yy_lookahead[j] == YYWILDCARD && iLookAhead > 0
613
+ ) {
614
+ #ifndef NDEBUG
615
+
616
+ if ( yyTraceFILE ) {
617
+ fprintf(yyTraceFILE, "%sWILDCARD %s => %s\n",
618
+ yyTracePrompt, yyTokenName[iLookAhead],
619
+ yyTokenName[YYWILDCARD]);
620
+ }
621
+
622
+ #endif /* NDEBUG */
623
+ return yy_action[j];
624
+ }
625
+ }
626
+ #endif /* YYWILDCARD */
627
+ return yy_default[stateno];
628
+ } else {
629
+ return yy_action[i];
630
+ }
631
+ } while (1);
632
+ }
633
+
634
+ /*
635
+ ** Find the appropriate action for a parser given the non-terminal
636
+ ** look-ahead token iLookAhead.
637
+ */
638
+ static int yy_find_reduce_action(
639
+ int stateno, /* Current state number */
640
+ YYCODETYPE iLookAhead /* The look-ahead token */
641
+ ) {
642
+ int i;
643
+ #ifdef YYERRORSYMBOL
644
+
645
+ if ( stateno > YY_REDUCE_COUNT ) {
646
+ return yy_default[stateno];
647
+ }
648
+
649
+ #else
650
+ assert( stateno <= YY_REDUCE_COUNT );
651
+ #endif
652
+ i = yy_reduce_ofst[stateno];
653
+ assert( i != YY_REDUCE_USE_DFLT );
654
+ assert( iLookAhead != YYNOCODE );
655
+ i += iLookAhead;
656
+ #ifdef YYERRORSYMBOL
657
+
658
+ if ( i < 0 || i >= YY_ACTTAB_COUNT || yy_lookahead[i] != iLookAhead ) {
659
+ return yy_default[stateno];
660
+ }
661
+
662
+ #else
663
+ assert( i >= 0 && i < YY_ACTTAB_COUNT );
664
+ assert( yy_lookahead[i] == iLookAhead );
665
+ #endif
666
+ return yy_action[i];
667
+ }
668
+
669
+ /*
670
+ ** The following routine is called if the stack overflows.
671
+ */
672
+ static void yyStackOverflow(yyParser * yypParser) {
673
+ ITMZARG_FETCH;
674
+ yypParser->yytos--;
675
+ #ifndef NDEBUG
676
+
677
+ if ( yyTraceFILE ) {
678
+ fprintf(yyTraceFILE, "%sStack Overflow!\n", yyTracePrompt);
679
+ }
680
+
681
+ #endif
682
+
683
+ while ( yypParser->yytos > yypParser->yystack ) {
684
+ yy_pop_parser_stack(yypParser);
685
+ }
686
+
687
+ /* Here code is inserted which will execute if the parser
688
+ ** stack every overflows */
689
+ /******** Begin %stack_overflow code ******************************************/
690
+ /******** End %stack_overflow code ********************************************/
691
+ ITMZARG_STORE; /* Suppress warning about unused %extra_argument var */
692
+ }
693
+
694
+ /*
695
+ ** Print tracing information for a SHIFT action
696
+ */
697
+ #ifndef NDEBUG
698
+ static void yyTraceShift(yyParser * yypParser, int yyNewState) {
699
+ if ( yyTraceFILE ) {
700
+ if ( yyNewState < YYNSTATE ) {
701
+ fprintf(yyTraceFILE, "%sShift '%s', go to state %d\n",
702
+ yyTracePrompt, yyTokenName[yypParser->yytos->major],
703
+ yyNewState);
704
+ } else {
705
+ fprintf(yyTraceFILE, "%sShift '%s'\n",
706
+ yyTracePrompt, yyTokenName[yypParser->yytos->major]);
707
+ }
708
+ }
709
+ }
710
+ #else
711
+ # define yyTraceShift(X,Y)
712
+ #endif
713
+
714
+ /*
715
+ ** Perform a shift action.
716
+ */
717
+ static void yy_shift(
718
+ yyParser * yypParser, /* The parser to be shifted */
719
+ int yyNewState, /* The new state to shift in */
720
+ int yyMajor, /* The major token to shift in */
721
+ ITMZTOKENTYPE yyMinor /* The minor token to shift in */
722
+ ) {
723
+ yyStackEntry * yytos;
724
+ yypParser->yytos++;
725
+ #ifdef YYTRACKMAXSTACKDEPTH
726
+
727
+ if ( (int)(yypParser->yytos - yypParser->yystack) > yypParser->yyhwm ) {
728
+ yypParser->yyhwm++;
729
+ assert( yypParser->yyhwm == (int)(yypParser->yytos - yypParser->yystack) );
730
+ }
731
+
732
+ #endif
733
+ #if YYSTACKDEPTH>0
734
+
735
+ if ( yypParser->yytos >= &yypParser->yystack[YYSTACKDEPTH] ) {
736
+ yyStackOverflow(yypParser);
737
+ return;
738
+ }
739
+
740
+ #else
741
+
742
+ if ( yypParser->yytos >= &yypParser->yystack[yypParser->yystksz] ) {
743
+ if ( yyGrowStack(yypParser) ) {
744
+ yyStackOverflow(yypParser);
745
+ return;
746
+ }
747
+ }
748
+
749
+ #endif
750
+
751
+ if ( yyNewState > YY_MAX_SHIFT ) {
752
+ yyNewState += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE;
753
+ }
754
+
755
+ yytos = yypParser->yytos;
756
+ yytos->stateno = (YYACTIONTYPE)yyNewState;
757
+ yytos->major = (YYCODETYPE)yyMajor;
758
+ yytos->minor.yy0 = yyMinor;
759
+ yyTraceShift(yypParser, yyNewState);
760
+ }
761
+
762
+ /* The following table contains information about every rule that
763
+ ** is used during the reduce.
764
+ */
765
+ static const struct {
766
+ YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */
767
+ unsigned char nrhs; /* Number of right-hand side symbols in the rule */
768
+ } yyRuleInfo[] = {
769
+ { 13, 1 },
770
+ { 14, 4 },
771
+ { 14, 3 },
772
+ { 15, 3 },
773
+ { 15, 2 },
774
+ { 15, 1 },
775
+ { 17, 2 },
776
+ { 17, 1 },
777
+ { 18, 2 },
778
+ { 18, 2 },
779
+ { 18, 3 },
780
+ { 18, 3 },
781
+ { 18, 2 },
782
+ { 18, 1 },
783
+ { 16, 2 },
784
+ { 16, 0 },
785
+ };
786
+
787
+ static void yy_accept(yyParser *); /* Forward Declaration */
788
+
789
+ /*
790
+ ** Perform a reduce action and the shift that must immediately
791
+ ** follow the reduce.
792
+ */
793
+ static void yy_reduce(
794
+ yyParser * yypParser, /* The parser */
795
+ unsigned int yyruleno /* Number of the rule by which to reduce */
796
+ ) {
797
+ int yygoto; /* The next state */
798
+ int yyact; /* The next action */
799
+ yyStackEntry * yymsp; /* The top of the parser's stack */
800
+ int yysize; /* Amount to pop the stack */
801
+ ITMZARG_FETCH;
802
+ yymsp = yypParser->yytos;
803
+ #ifndef NDEBUG
804
+
805
+ if ( yyTraceFILE && yyruleno < (int)(sizeof(yyRuleName) / sizeof(yyRuleName[0])) ) {
806
+ yysize = yyRuleInfo[yyruleno].nrhs;
807
+ fprintf(yyTraceFILE, "%sReduce [%s], go to state %d.\n", yyTracePrompt,
808
+ yyRuleName[yyruleno], yymsp[-yysize].stateno);
809
+ }
810
+
811
+ #endif /* NDEBUG */
812
+
813
+ /* Check that the stack is large enough to grow by a single entry
814
+ ** if the RHS of the rule is empty. This ensures that there is room
815
+ ** enough on the stack to push the LHS value */
816
+ if ( yyRuleInfo[yyruleno].nrhs == 0 ) {
817
+ #ifdef YYTRACKMAXSTACKDEPTH
818
+
819
+ if ( (int)(yypParser->yytos - yypParser->yystack) > yypParser->yyhwm ) {
820
+ yypParser->yyhwm++;
821
+ assert( yypParser->yyhwm == (int)(yypParser->yytos - yypParser->yystack));
822
+ }
823
+
824
+ #endif
825
+ #if YYSTACKDEPTH>0
826
+
827
+ if ( yypParser->yytos >= &yypParser->yystack[YYSTACKDEPTH - 1] ) {
828
+ yyStackOverflow(yypParser);
829
+ return;
830
+ }
831
+
832
+ #else
833
+
834
+ if ( yypParser->yytos >= &yypParser->yystack[yypParser->yystksz - 1] ) {
835
+ if ( yyGrowStack(yypParser) ) {
836
+ yyStackOverflow(yypParser);
837
+ return;
838
+ }
839
+
840
+ yymsp = yypParser->yytos;
841
+ }
842
+
843
+ #endif
844
+ }
845
+
846
+ switch ( yyruleno ) {
847
+ /* Beginning here are the reduction cases. A typical example
848
+ ** follows:
849
+ ** case 0:
850
+ ** #line <lineno> <grammarfile>
851
+ ** { ... } // User supplied code
852
+ ** #line <lineno> <thisfile>
853
+ ** break;
854
+ */
855
+ /********** Begin reduce actions **********************************************/
856
+ case 0: { /* doc ::= doc_ithoughts */
857
+ engine->root = yymsp[0].minor.yy0;
858
+ }
859
+ break;
860
+
861
+ default:
862
+ /* (1) doc_ithoughts ::= ITMZ_ITHOUGHTS_OPEN itmz_topics_section itmz_relationships ITMZ_ITHOUGHTS_CLOSE */
863
+ yytestcase(yyruleno == 1);
864
+ /* (2) doc_ithoughts ::= ITMZ_ITHOUGHTS_OPEN itmz_relationships ITMZ_ITHOUGHTS_CLOSE */ yytestcase(yyruleno == 2);
865
+ /* (3) itmz_topics_section ::= ITMZ_TOPICS_OPEN itmz_topics ITMZ_TOPICS_CLOSE */ yytestcase(yyruleno == 3);
866
+ /* (4) itmz_topics_section ::= ITMZ_TOPICS_OPEN ITMZ_TOPICS_CLOSE */ yytestcase(yyruleno == 4);
867
+ /* (5) itmz_topics_section ::= itmz_topics */ yytestcase(yyruleno == 5);
868
+ /* (6) itmz_topics ::= itmz_topics itmz_topic */ yytestcase(yyruleno == 6);
869
+ /* (7) itmz_topics ::= itmz_topic (OPTIMIZED OUT) */ assert(yyruleno != 7);
870
+ /* (8) itmz_topic ::= ITMZ_TOPIC_OPEN ITMZ_TOPIC_CLOSE */ yytestcase(yyruleno == 8);
871
+ /* (9) itmz_topic ::= ITMZ_TOPIC_PREAMBLE ITMZ_TOPIC_CLOSE */ yytestcase(yyruleno == 9);
872
+ /* (10) itmz_topic ::= ITMZ_TOPIC_OPEN itmz_topics ITMZ_TOPIC_CLOSE */ yytestcase(yyruleno == 10);
873
+ /* (11) itmz_topic ::= ITMZ_TOPIC_METADATA itmz_topics ITMZ_TOPIC_CLOSE */ yytestcase(yyruleno == 11);
874
+ /* (12) itmz_topic ::= ITMZ_TOPIC_METADATA ITMZ_TOPIC_CLOSE */ yytestcase(yyruleno == 12);
875
+ /* (13) itmz_topic ::= ITMZ_TOPIC_SELF_CLOSE */ yytestcase(yyruleno == 13);
876
+ /* (14) itmz_relationships ::= ITMZ_RELATIONSHIPS_OPEN ITMZ_RELATIONSHIPS_CLOSE */ yytestcase(yyruleno == 14);
877
+ /* (15) itmz_relationships ::= */ yytestcase(yyruleno == 15);
878
+ break;
879
+ /********** End reduce actions ************************************************/
880
+ };
881
+
882
+ assert( yyruleno < sizeof(yyRuleInfo) / sizeof(yyRuleInfo[0]) );
883
+
884
+ yygoto = yyRuleInfo[yyruleno].lhs;
885
+
886
+ yysize = yyRuleInfo[yyruleno].nrhs;
887
+
888
+ yyact = yy_find_reduce_action(yymsp[-yysize].stateno, (YYCODETYPE)yygoto);
889
+
890
+ if ( yyact <= YY_MAX_SHIFTREDUCE ) {
891
+ if ( yyact > YY_MAX_SHIFT ) {
892
+ yyact += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE;
893
+ }
894
+
895
+ yymsp -= yysize - 1;
896
+ yypParser->yytos = yymsp;
897
+ yymsp->stateno = (YYACTIONTYPE)yyact;
898
+ yymsp->major = (YYCODETYPE)yygoto;
899
+ yyTraceShift(yypParser, yyact);
900
+ } else {
901
+ assert( yyact == YY_ACCEPT_ACTION );
902
+ yypParser->yytos -= yysize;
903
+ yy_accept(yypParser);
904
+ }
905
+ }
906
+
907
+ /*
908
+ ** The following code executes when the parse fails
909
+ */
910
+ #ifndef YYNOERRORRECOVERY
911
+ static void yy_parse_failed(
912
+ yyParser * yypParser /* The parser */
913
+ ) {
914
+ ITMZARG_FETCH;
915
+ #ifndef NDEBUG
916
+
917
+ if ( yyTraceFILE ) {
918
+ fprintf(yyTraceFILE, "%sFail!\n", yyTracePrompt);
919
+ }
920
+
921
+ #endif
922
+
923
+ while ( yypParser->yytos > yypParser->yystack ) {
924
+ yy_pop_parser_stack(yypParser);
925
+ }
926
+
927
+ /* Here code is inserted which will be executed whenever the
928
+ ** parser fails */
929
+ /************ Begin %parse_failure code ***************************************/
930
+
931
+ fprintf(stderr, "Parser failed to successfully parse.\n");
932
+ /************ End %parse_failure code *****************************************/
933
+ ITMZARG_STORE; /* Suppress warning about unused %extra_argument variable */
934
+ }
935
+ #endif /* YYNOERRORRECOVERY */
936
+
937
+ /*
938
+ ** The following code executes when a syntax error first occurs.
939
+ */
940
+ static void yy_syntax_error(
941
+ yyParser * yypParser, /* The parser */
942
+ int yymajor, /* The major type of the error token */
943
+ ITMZTOKENTYPE yyminor /* The minor type of the error token */
944
+ ) {
945
+ ITMZARG_FETCH;
946
+ #define TOKEN yyminor
947
+ /************ Begin %syntax_error code ****************************************/
948
+
949
+ fprintf(stderr, "Parser syntax error.\n");
950
+ #ifndef NDEBUG
951
+ fprintf(stderr, "Parser syntax error.\n");
952
+ int n = sizeof(yyTokenName) / sizeof(yyTokenName[0]);
953
+
954
+ for (int i = 0; i < n; ++i) {
955
+ int a = yy_find_shift_action(yypParser, (YYCODETYPE)i);
956
+
957
+ if (a < YYNSTATE + YYNRULE) {
958
+ fprintf(stderr, "expected token: %s\n", yyTokenName[i]);
959
+ }
960
+ }
961
+
962
+ #endif
963
+ /************ End %syntax_error code ******************************************/
964
+ ITMZARG_STORE; /* Suppress warning about unused %extra_argument variable */
965
+ }
966
+
967
+ /*
968
+ ** The following is executed when the parser accepts
969
+ */
970
+ static void yy_accept(
971
+ yyParser * yypParser /* The parser */
972
+ ) {
973
+ ITMZARG_FETCH;
974
+ #ifndef NDEBUG
975
+
976
+ if ( yyTraceFILE ) {
977
+ fprintf(yyTraceFILE, "%sAccept!\n", yyTracePrompt);
978
+ }
979
+
980
+ #endif
981
+ #ifndef YYNOERRORRECOVERY
982
+ yypParser->yyerrcnt = -1;
983
+ #endif
984
+ assert( yypParser->yytos == yypParser->yystack );
985
+ /* Here code is inserted which will be executed whenever the
986
+ ** parser accepts */
987
+ /*********** Begin %parse_accept code *****************************************/
988
+
989
+ // printf("parsing completed successfully!\n");
990
+ /*********** End %parse_accept code *******************************************/
991
+ ITMZARG_STORE; /* Suppress warning about unused %extra_argument variable */
992
+ }
993
+
994
+ /* The main parser program.
995
+ ** The first argument is a pointer to a structure obtained from
996
+ ** "ITMZAlloc" which describes the current state of the parser.
997
+ ** The second argument is the major token number. The third is
998
+ ** the minor token. The fourth optional argument is whatever the
999
+ ** user wants (and specified in the grammar) and is available for
1000
+ ** use by the action routines.
1001
+ **
1002
+ ** Inputs:
1003
+ ** <ul>
1004
+ ** <li> A pointer to the parser (an opaque structure.)
1005
+ ** <li> The major token number.
1006
+ ** <li> The minor token number.
1007
+ ** <li> An option argument of a grammar-specified type.
1008
+ ** </ul>
1009
+ **
1010
+ ** Outputs:
1011
+ ** None.
1012
+ */
1013
+ void ITMZ(
1014
+ void * yyp, /* The parser */
1015
+ int yymajor, /* The major token code number */
1016
+ ITMZTOKENTYPE yyminor /* The value for the token */
1017
+ ITMZARG_PDECL /* Optional %extra_argument parameter */
1018
+ ) {
1019
+ YYMINORTYPE yyminorunion;
1020
+ unsigned int yyact; /* The parser action. */
1021
+ #if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY)
1022
+ int yyendofinput; /* True if we are at the end of input */
1023
+ #endif
1024
+ #ifdef YYERRORSYMBOL
1025
+ int yyerrorhit = 0; /* True if yymajor has invoked an error */
1026
+ #endif
1027
+ yyParser * yypParser; /* The parser */
1028
+
1029
+ yypParser = (yyParser *)yyp;
1030
+ assert( yypParser->yytos != 0 );
1031
+ #if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY)
1032
+ yyendofinput = (yymajor == 0);
1033
+ #endif
1034
+ ITMZARG_STORE;
1035
+
1036
+ #ifndef NDEBUG
1037
+
1038
+ if ( yyTraceFILE ) {
1039
+ fprintf(yyTraceFILE, "%sInput '%s'\n", yyTracePrompt, yyTokenName[yymajor]);
1040
+ }
1041
+
1042
+ #endif
1043
+
1044
+ do {
1045
+ yyact = yy_find_shift_action(yypParser, (YYCODETYPE)yymajor);
1046
+
1047
+ if ( yyact <= YY_MAX_SHIFTREDUCE ) {
1048
+ yy_shift(yypParser, yyact, yymajor, yyminor);
1049
+ #ifndef YYNOERRORRECOVERY
1050
+ yypParser->yyerrcnt--;
1051
+ #endif
1052
+ yymajor = YYNOCODE;
1053
+ } else if ( yyact <= YY_MAX_REDUCE ) {
1054
+ yy_reduce(yypParser, yyact - YY_MIN_REDUCE);
1055
+ } else {
1056
+ assert( yyact == YY_ERROR_ACTION );
1057
+ yyminorunion.yy0 = yyminor;
1058
+ #ifdef YYERRORSYMBOL
1059
+ int yymx;
1060
+ #endif
1061
+ #ifndef NDEBUG
1062
+
1063
+ if ( yyTraceFILE ) {
1064
+ fprintf(yyTraceFILE, "%sSyntax Error!\n", yyTracePrompt);
1065
+ }
1066
+
1067
+ #endif
1068
+ #ifdef YYERRORSYMBOL
1069
+
1070
+ /* A syntax error has occurred.
1071
+ ** The response to an error depends upon whether or not the
1072
+ ** grammar defines an error token "ERROR".
1073
+ **
1074
+ ** This is what we do if the grammar does define ERROR:
1075
+ **
1076
+ ** * Call the %syntax_error function.
1077
+ **
1078
+ ** * Begin popping the stack until we enter a state where
1079
+ ** it is legal to shift the error symbol, then shift
1080
+ ** the error symbol.
1081
+ **
1082
+ ** * Set the error count to three.
1083
+ **
1084
+ ** * Begin accepting and shifting new tokens. No new error
1085
+ ** processing will occur until three tokens have been
1086
+ ** shifted successfully.
1087
+ **
1088
+ */
1089
+ if ( yypParser->yyerrcnt < 0 ) {
1090
+ yy_syntax_error(yypParser, yymajor, yyminor);
1091
+ }
1092
+
1093
+ yymx = yypParser->yytos->major;
1094
+
1095
+ if ( yymx == YYERRORSYMBOL || yyerrorhit ) {
1096
+ #ifndef NDEBUG
1097
+
1098
+ if ( yyTraceFILE ) {
1099
+ fprintf(yyTraceFILE, "%sDiscard input token %s\n",
1100
+ yyTracePrompt, yyTokenName[yymajor]);
1101
+ }
1102
+
1103
+ #endif
1104
+ yy_destructor(yypParser, (YYCODETYPE)yymajor, &yyminorunion);
1105
+ yymajor = YYNOCODE;
1106
+ } else {
1107
+ while ( yypParser->yytos >= yypParser->yystack
1108
+ && yymx != YYERRORSYMBOL
1109
+ && (yyact = yy_find_reduce_action(
1110
+ yypParser->yytos->stateno,
1111
+ YYERRORSYMBOL)) >= YY_MIN_REDUCE
1112
+ ) {
1113
+ yy_pop_parser_stack(yypParser);
1114
+ }
1115
+
1116
+ if ( yypParser->yytos < yypParser->yystack || yymajor == 0 ) {
1117
+ yy_destructor(yypParser, (YYCODETYPE)yymajor, &yyminorunion);
1118
+ yy_parse_failed(yypParser);
1119
+ #ifndef YYNOERRORRECOVERY
1120
+ yypParser->yyerrcnt = -1;
1121
+ #endif
1122
+ yymajor = YYNOCODE;
1123
+ } else if ( yymx != YYERRORSYMBOL ) {
1124
+ yy_shift(yypParser, yyact, YYERRORSYMBOL, yyminor);
1125
+ }
1126
+ }
1127
+
1128
+ yypParser->yyerrcnt = 3;
1129
+ yyerrorhit = 1;
1130
+ #elif defined(YYNOERRORRECOVERY)
1131
+ /* If the YYNOERRORRECOVERY macro is defined, then do not attempt to
1132
+ ** do any kind of error recovery. Instead, simply invoke the syntax
1133
+ ** error routine and continue going as if nothing had happened.
1134
+ **
1135
+ ** Applications can set this macro (for example inside %include) if
1136
+ ** they intend to abandon the parse upon the first syntax error seen.
1137
+ */
1138
+ yy_syntax_error(yypParser, yymajor, yyminor);
1139
+ yy_destructor(yypParser, (YYCODETYPE)yymajor, &yyminorunion);
1140
+ yymajor = YYNOCODE;
1141
+
1142
+ #else /* YYERRORSYMBOL is not defined */
1143
+
1144
+ /* This is what we do if the grammar does not define ERROR:
1145
+ **
1146
+ ** * Report an error message, and throw away the input token.
1147
+ **
1148
+ ** * If the input token is $, then fail the parse.
1149
+ **
1150
+ ** As before, subsequent error messages are suppressed until
1151
+ ** three input tokens have been successfully shifted.
1152
+ */
1153
+ if ( yypParser->yyerrcnt <= 0 ) {
1154
+ yy_syntax_error(yypParser, yymajor, yyminor);
1155
+ }
1156
+
1157
+ yypParser->yyerrcnt = 3;
1158
+ yy_destructor(yypParser, (YYCODETYPE)yymajor, &yyminorunion);
1159
+
1160
+ if ( yyendofinput ) {
1161
+ yy_parse_failed(yypParser);
1162
+ #ifndef YYNOERRORRECOVERY
1163
+ yypParser->yyerrcnt = -1;
1164
+ #endif
1165
+ }
1166
+
1167
+ yymajor = YYNOCODE;
1168
+ #endif
1169
+ }
1170
+ } while ( yymajor != YYNOCODE && yypParser->yytos > yypParser->yystack );
1171
+
1172
+ #ifndef NDEBUG
1173
+
1174
+ if ( yyTraceFILE ) {
1175
+ yyStackEntry * i;
1176
+ char cDiv = '[';
1177
+ fprintf(yyTraceFILE, "%sReturn. Stack=", yyTracePrompt);
1178
+
1179
+ for (i = &yypParser->yystack[1]; i <= yypParser->yytos; i++) {
1180
+ fprintf(yyTraceFILE, "%c%s", cDiv, yyTokenName[i->major]);
1181
+ cDiv = ' ';
1182
+ }
1183
+
1184
+ fprintf(yyTraceFILE, "]\n");
1185
+ }
1186
+
1187
+ #endif
1188
+ return;
1189
+ }