-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcifParser.cpp
2152 lines (1772 loc) · 72.6 KB
/
cifParser.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/** \file
* This C source file was generated by $ANTLR version 3.4
*
* - From the grammar source file : cif.g
* - On : 2013-04-16 18:47:22
* - for the parser : cifParserParser
*
* Editing it, at least manually, is not wise.
*
* C language generator and runtime by Jim Idle, jimi|hereisanat|idle|dotgoeshere|ws.
*
*
*/
// [The "BSD license"]
// Copyright (c) 2005-2009 Jim Idle, Temporal Wave LLC
// http://www.temporal-wave.com
// http://www.linkedin.com/in/jimidle
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// 3. The name of the author may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/* -----------------------------------------
* Include the ANTLR3 generated header file.
*/
#include "cifParser.h"
/* ----------------------------------------- */
/** CIF Version 1.1 Working specification grammar
Translated from the grammar defined at
http://www.iucr.org/resources/cif/spec/version1.1/cifsyntax#bnf
A compiled version of the parser, with C language target, but contains
C++ code in the actions, therefore the output files must be renamed to *.cpp
Richard Gildea
April 2010
*/
/* MACROS that hide the C interface implementations from the
* generated code, which makes it a little more understandable to the human eye.
* I am very much against using C pre-processor macros for function calls and bits
* of code as you cannot see what is happening when single stepping in debuggers
* and so on. The exception (in my book at least) is for generated code, where you are
* not maintaining it, but may wish to read and understand it. If you single step it, you know that input()
* hides some indirect calls, but is always referring to the input stream. This is
* probably more readable than ctx->input->istream->input(snarfle0->blarg) and allows me to rejig
* the runtime interfaces without changing the generated code too often, without
* confusing the reader of the generated output, who may not wish to know the gory
* details of the interface inheritance.
*/
#define CTX ctx
/* Aids in accessing scopes for grammar programmers
*/
#undef SCOPE_TYPE
#undef SCOPE_STACK
#undef SCOPE_TOP
#define SCOPE_TYPE(scope) pcifParser_##scope##_SCOPE
#define SCOPE_STACK(scope) pcifParser_##scope##Stack
#define SCOPE_TOP(scope) ctx->pcifParser_##scope##Top
#define SCOPE_SIZE(scope) ctx->pcifParser_##scope##Stack_limit
#define SCOPE_INSTANCE(scope, i) (ctx->SCOPE_STACK(scope)->get(ctx->SCOPE_STACK(scope),i))
/* Macros for accessing things in the parser
*/
#undef PARSER
#undef RECOGNIZER
#undef HAVEPARSEDRULE
#undef MEMOIZE
#undef INPUT
#undef STRSTREAM
#undef HASEXCEPTION
#undef EXCEPTION
#undef MATCHT
#undef MATCHANYT
#undef FOLLOWSTACK
#undef FOLLOWPUSH
#undef FOLLOWPOP
#undef PRECOVER
#undef PREPORTERROR
#undef LA
#undef LT
#undef CONSTRUCTEX
#undef CONSUME
#undef MARK
#undef REWIND
#undef REWINDLAST
#undef PERRORRECOVERY
#undef HASFAILED
#undef FAILEDFLAG
#undef RECOVERFROMMISMATCHEDSET
#undef RECOVERFROMMISMATCHEDELEMENT
#undef INDEX
#undef ADAPTOR
#undef SEEK
#undef RULEMEMO
#undef DBG
#define PARSER ctx->pParser
#define RECOGNIZER PARSER->rec
#define PSRSTATE RECOGNIZER->state
#define HAVEPARSEDRULE(r) RECOGNIZER->alreadyParsedRule(RECOGNIZER, r)
#define MEMOIZE(ri,si) RECOGNIZER->memoize(RECOGNIZER, ri, si)
#define INPUT PARSER->tstream
#define STRSTREAM INPUT
#define ISTREAM INPUT->istream
#define INDEX() ISTREAM->index(INPUT->istream)
#define HASEXCEPTION() (PSRSTATE->error == ANTLR3_TRUE)
#define EXCEPTION PSRSTATE->exception
#define MATCHT(t, fs) RECOGNIZER->match(RECOGNIZER, t, fs)
#define MATCHANYT() RECOGNIZER->matchAny(RECOGNIZER)
#define FOLLOWSTACK PSRSTATE->following
#ifdef SKIP_FOLLOW_SETS
#define FOLLOWPUSH(x)
#define FOLLOWPOP()
#else
#define FOLLOWPUSH(x) FOLLOWSTACK->push(FOLLOWSTACK, ((void *)(&(x))), NULL)
#define FOLLOWPOP() FOLLOWSTACK->pop(FOLLOWSTACK)
#endif
#define PRECOVER() RECOGNIZER->recover(RECOGNIZER)
#define PREPORTERROR() RECOGNIZER->reportError(RECOGNIZER)
#define LA(n) INPUT->istream->_LA(ISTREAM, n)
#define LT(n) INPUT->_LT(INPUT, n)
#define CONSTRUCTEX() RECOGNIZER->exConstruct(RECOGNIZER)
#define CONSUME() ISTREAM->consume(ISTREAM)
#define MARK() ISTREAM->mark(ISTREAM)
#define REWIND(m) ISTREAM->rewind(ISTREAM, m)
#define REWINDLAST() ISTREAM->rewindLast(ISTREAM)
#define SEEK(n) ISTREAM->seek(ISTREAM, n)
#define PERRORRECOVERY PSRSTATE->errorRecovery
#define FAILEDFLAG PSRSTATE->failed
#define HASFAILED() (FAILEDFLAG == ANTLR3_TRUE)
#define BACKTRACKING PSRSTATE->backtracking
#define RECOVERFROMMISMATCHEDSET(s) RECOGNIZER->recoverFromMismatchedSet(RECOGNIZER, s)
#define RECOVERFROMMISMATCHEDELEMENT(e) RECOGNIZER->recoverFromMismatchedElement(RECOGNIZER, s)
#define ADAPTOR ctx->adaptor
#define RULEMEMO PSRSTATE->ruleMemo
#define DBG RECOGNIZER->debugger
#define TOKTEXT(tok, txt) tok, (pANTLR3_UINT8)txt
/* The 4 tokens defined below may well clash with your own #defines or token types. If so
* then for the present you must use different names for your defines as these are hard coded
* in the code generator. It would be better not to use such names internally, and maybe
* we can change this in a forthcoming release. I deliberately do not #undef these
* here as this will at least give you a redefined error somewhere if they clash.
*/
#define UP ANTLR3_TOKEN_UP
#define DOWN ANTLR3_TOKEN_DOWN
#define EOR ANTLR3_TOKEN_EOR
#define INVALID ANTLR3_TOKEN_INVALID
/* =============================================================================
* Functions to create and destroy scopes. First come the rule scopes, followed
* by the global declared scopes.
*/
/* ruleAttributeScopeFuncDecl(scope)
*/
/* -----------------------------------------------------------------------------
* Function declarations for creating a cifParser_parse scope set
*/
static pcifParser_parse_SCOPE pcifParser_parsePush(pcifParser ctx);
static void ANTLR3_CDECL parseFree(pcifParser_parse_SCOPE scope);
/* ----------------------------------------------------------------------------- */
/* ruleAttributeScopeFuncs(scope)
*/
/* attributeFuncs(scope)
*/
static void ANTLR3_CDECL parseFree(pcifParser_parse_SCOPE scope)
{
ANTLR3_FREE(scope);
}
/** \brief Allocate initial memory for a cifParser parse scope variable stack entry and
* add it to the top of the stack.
*
* \remark
* By default the structure is freed with ANTLR_FREE(), but you can use the
* the \@init action to install a pointer to a custom free() routine by
* adding the code:
* \code
* ctx->pcifParser_parseTop->free = myroutine;
* \endcode
*
* With lots of comments of course! The routine should be declared in
* \@members { } as:
* \code
* void ANTLR3_CDECL myfunc( pcifParser_parse_SCOPE ptr).
* \endcode
*
* It should perform any custom freeing stuff that you need (call ANTLR_FREE3, not free()
* NB: It should not free the pointer it is given, which is the scope stack entry itself
* and will be freed by the function that calls your custom free routine.
*
*/
static pcifParser_parse_SCOPE
pcifParser_parsePush(pcifParser ctx)
{
/* Pointer used to create a new set of attributes
*/
pcifParser_parse_SCOPE newAttributes;
/* Allocate the memory for a new structure if we need one.
*/
if (ctx->pcifParser_parseStack->size(ctx->pcifParser_parseStack) > ctx->pcifParser_parseStack_limit)
{
// The current limit value was less than the number of scopes available on the stack so
// we can just reuse one. Our limit tracks the stack count, so the index of the entry we want
// is one less than that, or conveniently, the current value of limit.
//
newAttributes = (pcifParser_parse_SCOPE)ctx->pcifParser_parseStack->get(ctx->pcifParser_parseStack, ctx->pcifParser_parseStack_limit);
}
else
{
// Need a new allocation
//
newAttributes = (pcifParser_parse_SCOPE) ANTLR3_MALLOC(sizeof(cifParser_parse_SCOPE));
if (newAttributes != NULL)
{
/* Standard ANTLR3 library implementation
*/
ctx->pcifParser_parseStack->push(ctx->pcifParser_parseStack, newAttributes, (void (*)(void *))parseFree);
}
}
// Blank out any previous free pointer, the user might or might install a new one.
//
newAttributes->free = NULL;
// Indicate the position in the available stack that the current level is at
//
ctx->pcifParser_parseStack_limit++;
/* Return value is the pointer to the new entry, which may be used locally
* without de-referencing via the context.
*/
return newAttributes;
}
/* ruleAttributeScopeFuncDecl(scope)
*/
/* -----------------------------------------------------------------------------
* Function declarations for creating a cifParser_loop_body scope set
*/
static pcifParser_loop_body_SCOPE pcifParser_loop_bodyPush(pcifParser ctx);
static void ANTLR3_CDECL loop_bodyFree(pcifParser_loop_body_SCOPE scope);
/* ----------------------------------------------------------------------------- */
/* ruleAttributeScopeFuncs(scope)
*/
/* attributeFuncs(scope)
*/
static void ANTLR3_CDECL loop_bodyFree(pcifParser_loop_body_SCOPE scope)
{
ANTLR3_FREE(scope);
}
/** \brief Allocate initial memory for a cifParser loop_body scope variable stack entry and
* add it to the top of the stack.
*
* \remark
* By default the structure is freed with ANTLR_FREE(), but you can use the
* the \@init action to install a pointer to a custom free() routine by
* adding the code:
* \code
* ctx->pcifParser_loop_bodyTop->free = myroutine;
* \endcode
*
* With lots of comments of course! The routine should be declared in
* \@members { } as:
* \code
* void ANTLR3_CDECL myfunc( pcifParser_loop_body_SCOPE ptr).
* \endcode
*
* It should perform any custom freeing stuff that you need (call ANTLR_FREE3, not free()
* NB: It should not free the pointer it is given, which is the scope stack entry itself
* and will be freed by the function that calls your custom free routine.
*
*/
static pcifParser_loop_body_SCOPE
pcifParser_loop_bodyPush(pcifParser ctx)
{
/* Pointer used to create a new set of attributes
*/
pcifParser_loop_body_SCOPE newAttributes;
/* Allocate the memory for a new structure if we need one.
*/
if (ctx->pcifParser_loop_bodyStack->size(ctx->pcifParser_loop_bodyStack) > ctx->pcifParser_loop_bodyStack_limit)
{
// The current limit value was less than the number of scopes available on the stack so
// we can just reuse one. Our limit tracks the stack count, so the index of the entry we want
// is one less than that, or conveniently, the current value of limit.
//
newAttributes = (pcifParser_loop_body_SCOPE)ctx->pcifParser_loop_bodyStack->get(ctx->pcifParser_loop_bodyStack, ctx->pcifParser_loop_bodyStack_limit);
}
else
{
// Need a new allocation
//
newAttributes = (pcifParser_loop_body_SCOPE) ANTLR3_MALLOC(sizeof(cifParser_loop_body_SCOPE));
if (newAttributes != NULL)
{
/* Standard ANTLR3 library implementation
*/
ctx->pcifParser_loop_bodyStack->push(ctx->pcifParser_loop_bodyStack, newAttributes, (void (*)(void *))loop_bodyFree);
}
}
// Blank out any previous free pointer, the user might or might install a new one.
//
newAttributes->free = NULL;
// Indicate the position in the available stack that the current level is at
//
ctx->pcifParser_loop_bodyStack_limit++;
/* Return value is the pointer to the new entry, which may be used locally
* without de-referencing via the context.
*/
return newAttributes;
}
/* ruleAttributeScopeFuncDecl(scope)
*/
/* -----------------------------------------------------------------------------
* Function declarations for creating a cifParser_data_items scope set
*/
static pcifParser_data_items_SCOPE pcifParser_data_itemsPush(pcifParser ctx);
static void ANTLR3_CDECL data_itemsFree(pcifParser_data_items_SCOPE scope);
/* ----------------------------------------------------------------------------- */
/* ruleAttributeScopeFuncs(scope)
*/
/* attributeFuncs(scope)
*/
static void ANTLR3_CDECL data_itemsFree(pcifParser_data_items_SCOPE scope)
{
ANTLR3_FREE(scope);
}
/** \brief Allocate initial memory for a cifParser data_items scope variable stack entry and
* add it to the top of the stack.
*
* \remark
* By default the structure is freed with ANTLR_FREE(), but you can use the
* the \@init action to install a pointer to a custom free() routine by
* adding the code:
* \code
* ctx->pcifParser_data_itemsTop->free = myroutine;
* \endcode
*
* With lots of comments of course! The routine should be declared in
* \@members { } as:
* \code
* void ANTLR3_CDECL myfunc( pcifParser_data_items_SCOPE ptr).
* \endcode
*
* It should perform any custom freeing stuff that you need (call ANTLR_FREE3, not free()
* NB: It should not free the pointer it is given, which is the scope stack entry itself
* and will be freed by the function that calls your custom free routine.
*
*/
static pcifParser_data_items_SCOPE
pcifParser_data_itemsPush(pcifParser ctx)
{
/* Pointer used to create a new set of attributes
*/
pcifParser_data_items_SCOPE newAttributes;
/* Allocate the memory for a new structure if we need one.
*/
if (ctx->pcifParser_data_itemsStack->size(ctx->pcifParser_data_itemsStack) > ctx->pcifParser_data_itemsStack_limit)
{
// The current limit value was less than the number of scopes available on the stack so
// we can just reuse one. Our limit tracks the stack count, so the index of the entry we want
// is one less than that, or conveniently, the current value of limit.
//
newAttributes = (pcifParser_data_items_SCOPE)ctx->pcifParser_data_itemsStack->get(ctx->pcifParser_data_itemsStack, ctx->pcifParser_data_itemsStack_limit);
}
else
{
// Need a new allocation
//
newAttributes = (pcifParser_data_items_SCOPE) ANTLR3_MALLOC(sizeof(cifParser_data_items_SCOPE));
if (newAttributes != NULL)
{
/* Standard ANTLR3 library implementation
*/
ctx->pcifParser_data_itemsStack->push(ctx->pcifParser_data_itemsStack, newAttributes, (void (*)(void *))data_itemsFree);
}
}
// Blank out any previous free pointer, the user might or might install a new one.
//
newAttributes->free = NULL;
// Indicate the position in the available stack that the current level is at
//
ctx->pcifParser_data_itemsStack_limit++;
/* Return value is the pointer to the new entry, which may be used locally
* without de-referencing via the context.
*/
return newAttributes;
}
/* ============================================================================= */
/* =============================================================================
* Start of recognizer
*/
/** \brief Table of all token names in symbolic order, mainly used for
* error reporting.
*/
pANTLR3_UINT8 cifParserTokenNames[34+4]
= {
(pANTLR3_UINT8) "<invalid>", /* String to print to indicate an invalid token */
(pANTLR3_UINT8) "<EOR>",
(pANTLR3_UINT8) "<DOWN>",
(pANTLR3_UINT8) "<UP>",
(pANTLR3_UINT8) "ANY_PRINT_CHAR",
(pANTLR3_UINT8) "CHAR_STRING",
(pANTLR3_UINT8) "COMMENTS",
(pANTLR3_UINT8) "DATA_",
(pANTLR3_UINT8) "DATA_BLOCK_HEADING",
(pANTLR3_UINT8) "DIGIT",
(pANTLR3_UINT8) "DOUBLE_QUOTE",
(pANTLR3_UINT8) "DOUBLE_QUOTED_STRING",
(pANTLR3_UINT8) "EOL",
(pANTLR3_UINT8) "EXPONENT",
(pANTLR3_UINT8) "FLOAT",
(pANTLR3_UINT8) "GLOBAL_",
(pANTLR3_UINT8) "INAPPLICABLE",
(pANTLR3_UINT8) "INTEGER",
(pANTLR3_UINT8) "LOOP_",
(pANTLR3_UINT8) "NON_BLANK_CHAR",
(pANTLR3_UINT8) "NON_BLANK_CHAR_",
(pANTLR3_UINT8) "NUMBER",
(pANTLR3_UINT8) "NUMERIC",
(pANTLR3_UINT8) "ORDINARY_CHAR",
(pANTLR3_UINT8) "SAVE",
(pANTLR3_UINT8) "SAVE_",
(pANTLR3_UINT8) "SAVE_FRAME_HEADING",
(pANTLR3_UINT8) "SEMI_COLON_TEXT_FIELD",
(pANTLR3_UINT8) "SINGLE_QUOTE",
(pANTLR3_UINT8) "SINGLE_QUOTED_STRING",
(pANTLR3_UINT8) "STOP_",
(pANTLR3_UINT8) "TAG",
(pANTLR3_UINT8) "TEXT_LEAD_CHAR",
(pANTLR3_UINT8) "UNKNOWN",
(pANTLR3_UINT8) "UNQUOTED_STRING",
(pANTLR3_UINT8) "UNSIGNED_INTEGER",
(pANTLR3_UINT8) "WHITESPACE",
(pANTLR3_UINT8) "'\\u001a'"
};
/* ruleAttributeScopeFuncMacro(scope)
*/
/** Function for popping the top value from a pcifParser_parseStack
*/
void
pcifParser_parsePop(pcifParser ctx)
{
// First see if the user defined a function they want to be called when a
// scope is popped/freed.
//
// If the user supplied the scope entries with a free function,then call it first
//
if (SCOPE_TOP(parse)->free != NULL)
{
SCOPE_TOP(parse)->free(SCOPE_TOP(parse));
}
// Now we decrement the scope's upper limit bound. We do not actually pop the scope as
// we want to reuse scope entries if we do continuous push and pops. Most scopes don't
// next too far so we don't want to keep freeing and allocating them
//
ctx->pcifParser_parseStack_limit--;
SCOPE_TOP(parse) = (pcifParser_parse_SCOPE)(ctx->pcifParser_parseStack->get(ctx->pcifParser_parseStack, ctx->pcifParser_parseStack_limit - 1));
}
/* ruleAttributeScopeFuncMacro(scope)
*/
/** Function for popping the top value from a pcifParser_loop_bodyStack
*/
void
pcifParser_loop_bodyPop(pcifParser ctx)
{
// First see if the user defined a function they want to be called when a
// scope is popped/freed.
//
// If the user supplied the scope entries with a free function,then call it first
//
if (SCOPE_TOP(loop_body)->free != NULL)
{
SCOPE_TOP(loop_body)->free(SCOPE_TOP(loop_body));
}
// Now we decrement the scope's upper limit bound. We do not actually pop the scope as
// we want to reuse scope entries if we do continuous push and pops. Most scopes don't
// next too far so we don't want to keep freeing and allocating them
//
ctx->pcifParser_loop_bodyStack_limit--;
SCOPE_TOP(loop_body) = (pcifParser_loop_body_SCOPE)(ctx->pcifParser_loop_bodyStack->get(ctx->pcifParser_loop_bodyStack, ctx->pcifParser_loop_bodyStack_limit - 1));
}
/* ruleAttributeScopeFuncMacro(scope)
*/
/** Function for popping the top value from a pcifParser_data_itemsStack
*/
void
pcifParser_data_itemsPop(pcifParser ctx)
{
// First see if the user defined a function they want to be called when a
// scope is popped/freed.
//
// If the user supplied the scope entries with a free function,then call it first
//
if (SCOPE_TOP(data_items)->free != NULL)
{
SCOPE_TOP(data_items)->free(SCOPE_TOP(data_items));
}
// Now we decrement the scope's upper limit bound. We do not actually pop the scope as
// we want to reuse scope entries if we do continuous push and pops. Most scopes don't
// next too far so we don't want to keep freeing and allocating them
//
ctx->pcifParser_data_itemsStack_limit--;
SCOPE_TOP(data_items) = (pcifParser_data_items_SCOPE)(ctx->pcifParser_data_itemsStack->get(ctx->pcifParser_data_itemsStack, ctx->pcifParser_data_itemsStack_limit - 1));
}
// Forward declare the locally static matching functions we have generated.
//
static
void
parse (pcifParser ctx, ucif::builder_base* builder_, bool strict_);
static
void
cif (pcifParser ctx);
static
void
loop_body (pcifParser ctx);
static
void
save_frame (pcifParser ctx);
static
void
data_items (pcifParser ctx);
static
void
data_block (pcifParser ctx);
static
void
loop_header (pcifParser ctx);
static
cifParser_value_return
value (pcifParser ctx);
static
void
char_string (pcifParser ctx);
static
void
text_field (pcifParser ctx);
static void cifParserFree(pcifParser ctx);
static void cifParserReset (pcifParser ctx);
/* For use in tree output where we are accumulating rule labels via label += ruleRef
* we need a function that knows how to free a return scope when the list is destroyed.
* We cannot just use ANTLR3_FREE because in debug tracking mode, this is a macro.
*/
static void ANTLR3_CDECL freeScope(void * scope)
{
ANTLR3_FREE(scope);
}
/** \brief Name of the grammar file that generated this code
*/
static const char fileName[] = "cif.g";
/** \brief Return the name of the grammar file that generated this code.
*/
static const char * getGrammarFileName()
{
return fileName;
}
/** \brief Create a new cifParser parser and return a context for it.
*
* \param[in] instream Pointer to an input stream interface.
*
* \return Pointer to new parser context upon success.
*/
ANTLR3_API pcifParser
cifParserNew (pANTLR3_COMMON_TOKEN_STREAM instream)
{
// See if we can create a new parser with the standard constructor
//
return cifParserNewSSD(instream, NULL);
}
/** \brief Create a new cifParser parser and return a context for it.
*
* \param[in] instream Pointer to an input stream interface.
*
* \return Pointer to new parser context upon success.
*/
ANTLR3_API pcifParser
cifParserNewSSD (pANTLR3_COMMON_TOKEN_STREAM instream, pANTLR3_RECOGNIZER_SHARED_STATE state)
{
pcifParser ctx; /* Context structure we will build and return */
ctx = (pcifParser) ANTLR3_CALLOC(1, sizeof(cifParser));
if (ctx == NULL)
{
// Failed to allocate memory for parser context
//
return NULL;
}
/* -------------------------------------------------------------------
* Memory for basic structure is allocated, now to fill in
* the base ANTLR3 structures. We initialize the function pointers
* for the standard ANTLR3 parser function set, but upon return
* from here, the programmer may set the pointers to provide custom
* implementations of each function.
*
* We don't use the macros defined in cifParser.h here, in order that you can get a sense
* of what goes where.
*/
/* Create a base parser/recognizer, using the supplied token stream
*/
ctx->pParser = antlr3ParserNewStream(ANTLR3_SIZE_HINT, instream->tstream, state);
/* Install the implementation of our cifParser interface
*/
ctx->parse = parse;
ctx->cif = cif;
ctx->loop_body = loop_body;
ctx->save_frame = save_frame;
ctx->data_items = data_items;
ctx->data_block = data_block;
ctx->loop_header = loop_header;
ctx->value = value;
ctx->char_string = char_string;
ctx->text_field = text_field;
ctx->free = cifParserFree;
ctx->reset = cifParserReset;
ctx->getGrammarFileName = getGrammarFileName;
/* Install the scope pushing methods.
*/
/* ruleAttributeScope(scope)
*/
ctx->pcifParser_parsePush = pcifParser_parsePush;
ctx->pcifParser_parseStack = antlr3StackNew(0);
ctx->pcifParser_parseStack_limit = 0;
ctx->pcifParser_parseTop = NULL;
/* ruleAttributeScope(scope)
*/
ctx->pcifParser_loop_bodyPush = pcifParser_loop_bodyPush;
ctx->pcifParser_loop_bodyStack = antlr3StackNew(0);
ctx->pcifParser_loop_bodyStack_limit = 0;
ctx->pcifParser_loop_bodyTop = NULL;
/* ruleAttributeScope(scope)
*/
ctx->pcifParser_data_itemsPush = pcifParser_data_itemsPush;
ctx->pcifParser_data_itemsStack = antlr3StackNew(0);
ctx->pcifParser_data_itemsStack_limit = 0;
ctx->pcifParser_data_itemsTop = NULL;
PARSER->super = (void *)ctx;
/* Install the token table
*/
PSRSTATE->tokenNames = cifParserTokenNames;
/* Return the newly built parser to the caller
*/
return ctx;
}
static void
cifParserReset (pcifParser ctx)
{
RECOGNIZER->reset(RECOGNIZER);
}
/** Free the parser resources
*/
static void
cifParserFree(pcifParser ctx)
{
/* Free any scope memory
*/
/* ruleAttributeScope(scope)
*/
ctx->pcifParser_parseStack->free(ctx->pcifParser_parseStack);
/* ruleAttributeScope(scope)
*/
ctx->pcifParser_loop_bodyStack->free(ctx->pcifParser_loop_bodyStack);
/* ruleAttributeScope(scope)
*/
ctx->pcifParser_data_itemsStack->free(ctx->pcifParser_data_itemsStack);
// Free this parser
//
ctx->pParser->free(ctx->pParser);
ANTLR3_FREE(ctx);
/* Everything is released, so we can return
*/
return;
}
/** Return token names used by this
parser
*
* The returned pointer is used as an index into the token names table (using the token
* number as the index).
*
* \return Pointer to first char * in the table.
*/
static pANTLR3_UINT8 *getTokenNames()
{
return cifParserTokenNames;
}
std::string to_std_string(pANTLR3_COMMON_TOKEN token) {
ANTLR3_MARKER start = token->start;
ANTLR3_MARKER stop = token->stop;
std::string str((const char*)start, stop-start+1);
if ((str[0] == '\'' && str[str.size()-1] == '\'') ||
(str[0] == '"' && str[str.size()-1] == '"'))
{ str = str.substr(1, str.size()-2); }
return str;
}
/* Declare the bitsets
*/
/** Bitset defining follow set for error recovery in rule state: FOLLOW_cif_in_parse95 */
static ANTLR3_BITWORD FOLLOW_cif_in_parse95_bits[] = { ANTLR3_UINT64_LIT(0x0000002000000000) };
static ANTLR3_BITSET_LIST FOLLOW_cif_in_parse95 = { FOLLOW_cif_in_parse95_bits, 1 };
/** Bitset defining follow set for error recovery in rule state: FOLLOW_set_in_parse97 */
static ANTLR3_BITWORD FOLLOW_set_in_parse97_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000002) };
static ANTLR3_BITSET_LIST FOLLOW_set_in_parse97 = { FOLLOW_set_in_parse97_bits, 1 };
/** Bitset defining follow set for error recovery in rule state: FOLLOW_COMMENTS_in_cif118 */
static ANTLR3_BITWORD FOLLOW_COMMENTS_in_cif118_bits[] = { ANTLR3_UINT64_LIT(0x0000000000008102) };
static ANTLR3_BITSET_LIST FOLLOW_COMMENTS_in_cif118 = { FOLLOW_COMMENTS_in_cif118_bits, 1 };
/** Bitset defining follow set for error recovery in rule state: FOLLOW_data_block_in_cif121 */
static ANTLR3_BITWORD FOLLOW_data_block_in_cif121_bits[] = { ANTLR3_UINT64_LIT(0x0000000000008102) };
static ANTLR3_BITSET_LIST FOLLOW_data_block_in_cif121 = { FOLLOW_data_block_in_cif121_bits, 1 };
/** Bitset defining follow set for error recovery in rule state: FOLLOW_value_in_loop_body146 */
static ANTLR3_BITWORD FOLLOW_value_in_loop_body146_bits[] = { ANTLR3_UINT64_LIT(0x0000000208410022) };
static ANTLR3_BITSET_LIST FOLLOW_value_in_loop_body146 = { FOLLOW_value_in_loop_body146_bits, 1 };
/** Bitset defining follow set for error recovery in rule state: FOLLOW_value_in_loop_body156 */
static ANTLR3_BITWORD FOLLOW_value_in_loop_body156_bits[] = { ANTLR3_UINT64_LIT(0x0000000208410022) };
static ANTLR3_BITSET_LIST FOLLOW_value_in_loop_body156 = { FOLLOW_value_in_loop_body156_bits, 1 };
/** Bitset defining follow set for error recovery in rule state: FOLLOW_SAVE_FRAME_HEADING_in_save_frame174 */
static ANTLR3_BITWORD FOLLOW_SAVE_FRAME_HEADING_in_save_frame174_bits[] = { ANTLR3_UINT64_LIT(0x0000000080040000) };
static ANTLR3_BITSET_LIST FOLLOW_SAVE_FRAME_HEADING_in_save_frame174 = { FOLLOW_SAVE_FRAME_HEADING_in_save_frame174_bits, 1 };
/** Bitset defining follow set for error recovery in rule state: FOLLOW_data_items_in_save_frame182 */
static ANTLR3_BITWORD FOLLOW_data_items_in_save_frame182_bits[] = { ANTLR3_UINT64_LIT(0x0000000081040000) };
static ANTLR3_BITSET_LIST FOLLOW_data_items_in_save_frame182 = { FOLLOW_data_items_in_save_frame182_bits, 1 };
/** Bitset defining follow set for error recovery in rule state: FOLLOW_SAVE_in_save_frame187 */
static ANTLR3_BITWORD FOLLOW_SAVE_in_save_frame187_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000002) };
static ANTLR3_BITSET_LIST FOLLOW_SAVE_in_save_frame187 = { FOLLOW_SAVE_in_save_frame187_bits, 1 };
/** Bitset defining follow set for error recovery in rule state: FOLLOW_TAG_in_data_items216 */
static ANTLR3_BITWORD FOLLOW_TAG_in_data_items216_bits[] = { ANTLR3_UINT64_LIT(0x0000000208410020) };
static ANTLR3_BITSET_LIST FOLLOW_TAG_in_data_items216 = { FOLLOW_TAG_in_data_items216_bits, 1 };
/** Bitset defining follow set for error recovery in rule state: FOLLOW_value_in_data_items218 */
static ANTLR3_BITWORD FOLLOW_value_in_data_items218_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000002) };
static ANTLR3_BITSET_LIST FOLLOW_value_in_data_items218 = { FOLLOW_value_in_data_items218_bits, 1 };
/** Bitset defining follow set for error recovery in rule state: FOLLOW_loop_header_in_data_items226 */
static ANTLR3_BITWORD FOLLOW_loop_header_in_data_items226_bits[] = { ANTLR3_UINT64_LIT(0x0000000208410020) };
static ANTLR3_BITSET_LIST FOLLOW_loop_header_in_data_items226 = { FOLLOW_loop_header_in_data_items226_bits, 1 };
/** Bitset defining follow set for error recovery in rule state: FOLLOW_loop_body_in_data_items228 */
static ANTLR3_BITWORD FOLLOW_loop_body_in_data_items228_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000002) };
static ANTLR3_BITSET_LIST FOLLOW_loop_body_in_data_items228 = { FOLLOW_loop_body_in_data_items228_bits, 1 };
/** Bitset defining follow set for error recovery in rule state: FOLLOW_DATA_BLOCK_HEADING_in_data_block245 */
static ANTLR3_BITWORD FOLLOW_DATA_BLOCK_HEADING_in_data_block245_bits[] = { ANTLR3_UINT64_LIT(0x0000000084040002) };
static ANTLR3_BITSET_LIST FOLLOW_DATA_BLOCK_HEADING_in_data_block245 = { FOLLOW_DATA_BLOCK_HEADING_in_data_block245_bits, 1 };
/** Bitset defining follow set for error recovery in rule state: FOLLOW_data_items_in_data_block255 */
static ANTLR3_BITWORD FOLLOW_data_items_in_data_block255_bits[] = { ANTLR3_UINT64_LIT(0x0000000084040002) };
static ANTLR3_BITSET_LIST FOLLOW_data_items_in_data_block255 = { FOLLOW_data_items_in_data_block255_bits, 1 };
/** Bitset defining follow set for error recovery in rule state: FOLLOW_save_frame_in_data_block259 */
static ANTLR3_BITWORD FOLLOW_save_frame_in_data_block259_bits[] = { ANTLR3_UINT64_LIT(0x0000000084040002) };
static ANTLR3_BITSET_LIST FOLLOW_save_frame_in_data_block259 = { FOLLOW_save_frame_in_data_block259_bits, 1 };
/** Bitset defining follow set for error recovery in rule state: FOLLOW_GLOBAL__in_data_block278 */
static ANTLR3_BITWORD FOLLOW_GLOBAL__in_data_block278_bits[] = { ANTLR3_UINT64_LIT(0x0000000084040002) };
static ANTLR3_BITSET_LIST FOLLOW_GLOBAL__in_data_block278 = { FOLLOW_GLOBAL__in_data_block278_bits, 1 };
/** Bitset defining follow set for error recovery in rule state: FOLLOW_data_items_in_data_block284 */
static ANTLR3_BITWORD FOLLOW_data_items_in_data_block284_bits[] = { ANTLR3_UINT64_LIT(0x0000000084040002) };
static ANTLR3_BITSET_LIST FOLLOW_data_items_in_data_block284 = { FOLLOW_data_items_in_data_block284_bits, 1 };
/** Bitset defining follow set for error recovery in rule state: FOLLOW_save_frame_in_data_block288 */
static ANTLR3_BITWORD FOLLOW_save_frame_in_data_block288_bits[] = { ANTLR3_UINT64_LIT(0x0000000084040002) };
static ANTLR3_BITSET_LIST FOLLOW_save_frame_in_data_block288 = { FOLLOW_save_frame_in_data_block288_bits, 1 };
/** Bitset defining follow set for error recovery in rule state: FOLLOW_LOOP__in_loop_header307 */
static ANTLR3_BITWORD FOLLOW_LOOP__in_loop_header307_bits[] = { ANTLR3_UINT64_LIT(0x0000000080000000) };
static ANTLR3_BITSET_LIST FOLLOW_LOOP__in_loop_header307 = { FOLLOW_LOOP__in_loop_header307_bits, 1 };
/** Bitset defining follow set for error recovery in rule state: FOLLOW_TAG_in_loop_header311 */
static ANTLR3_BITWORD FOLLOW_TAG_in_loop_header311_bits[] = { ANTLR3_UINT64_LIT(0x0000000080000002) };
static ANTLR3_BITSET_LIST FOLLOW_TAG_in_loop_header311 = { FOLLOW_TAG_in_loop_header311_bits, 1 };
/** Bitset defining follow set for error recovery in rule state: FOLLOW_INAPPLICABLE_in_value333 */
static ANTLR3_BITWORD FOLLOW_INAPPLICABLE_in_value333_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000002) };
static ANTLR3_BITSET_LIST FOLLOW_INAPPLICABLE_in_value333 = { FOLLOW_INAPPLICABLE_in_value333_bits, 1 };
/** Bitset defining follow set for error recovery in rule state: FOLLOW_UNKNOWN_in_value337 */
static ANTLR3_BITWORD FOLLOW_UNKNOWN_in_value337_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000002) };
static ANTLR3_BITSET_LIST FOLLOW_UNKNOWN_in_value337 = { FOLLOW_UNKNOWN_in_value337_bits, 1 };
/** Bitset defining follow set for error recovery in rule state: FOLLOW_NUMERIC_in_value341 */
static ANTLR3_BITWORD FOLLOW_NUMERIC_in_value341_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000002) };
static ANTLR3_BITSET_LIST FOLLOW_NUMERIC_in_value341 = { FOLLOW_NUMERIC_in_value341_bits, 1 };
/** Bitset defining follow set for error recovery in rule state: FOLLOW_char_string_in_value345 */
static ANTLR3_BITWORD FOLLOW_char_string_in_value345_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000002) };
static ANTLR3_BITSET_LIST FOLLOW_char_string_in_value345 = { FOLLOW_char_string_in_value345_bits, 1 };
/** Bitset defining follow set for error recovery in rule state: FOLLOW_text_field_in_value349 */
static ANTLR3_BITWORD FOLLOW_text_field_in_value349_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000002) };
static ANTLR3_BITSET_LIST FOLLOW_text_field_in_value349 = { FOLLOW_text_field_in_value349_bits, 1 };
/** Bitset defining follow set for error recovery in rule state: FOLLOW_CHAR_STRING_in_char_string362 */
static ANTLR3_BITWORD FOLLOW_CHAR_STRING_in_char_string362_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000002) };
static ANTLR3_BITSET_LIST FOLLOW_CHAR_STRING_in_char_string362 = { FOLLOW_CHAR_STRING_in_char_string362_bits, 1 };
/** Bitset defining follow set for error recovery in rule state: FOLLOW_SEMI_COLON_TEXT_FIELD_in_text_field373 */
static ANTLR3_BITWORD FOLLOW_SEMI_COLON_TEXT_FIELD_in_text_field373_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000002) };
static ANTLR3_BITSET_LIST FOLLOW_SEMI_COLON_TEXT_FIELD_in_text_field373 = { FOLLOW_SEMI_COLON_TEXT_FIELD_in_text_field373_bits, 1 };
/* ==============================================
* Parsing rules
*/
/**
* $ANTLR start parse
* cif.g:66:1: parse[ucif::builder_base* builder_, bool strict_] : cif ( EOF | '\\u001a' ) ;
*/
static void
parse(pcifParser ctx, ucif::builder_base* builder_, bool strict_)
{
/* Initialize rule variables
*/
ctx->pcifParser_parseTop = pcifParser_parsePush(ctx);
(SCOPE_TOP(parse))->builder= builder_;
(SCOPE_TOP(parse))->strict= strict_;
{
// cif.g:75:3: ( cif ( EOF | '\\u001a' ) )
// cif.g:75:5: cif ( EOF | '\\u001a' )
{
FOLLOWPUSH(FOLLOW_cif_in_parse95);
cif(ctx);
FOLLOWPOP();
if (HASEXCEPTION())
{
goto ruleparseEx;
}
if ( LA(1) == EOF || LA(1) == 37 )
{
CONSUME();
PERRORRECOVERY=ANTLR3_FALSE;
}
else
{
CONSTRUCTEX();
EXCEPTION->type = ANTLR3_MISMATCHED_SET_EXCEPTION;
EXCEPTION->name = (void *)ANTLR3_MISMATCHED_SET_NAME;
EXCEPTION->expectingSet = NULL;
goto ruleparseEx;
}
}
}
// This is where rules clean up and exit
//
goto ruleparseEx; /* Prevent compiler warnings */
ruleparseEx: ;
if (HASEXCEPTION())
{
PREPORTERROR();
PRECOVER();
}
pcifParser_parsePop(ctx);
return ;
}
/* $ANTLR end parse */
/**
* $ANTLR start cif
* cif.g:80:1: cif : ( COMMENTS )? ( data_block )* ;
*/
static void
cif(pcifParser ctx)
{
/* Initialize rule variables
*/
{
// cif.g:81:3: ( ( COMMENTS )? ( data_block )* )
// cif.g:81:5: ( COMMENTS )? ( data_block )*
{
// cif.g:81:5: ( COMMENTS )?
{
int alt1=2;
switch ( LA(1) )
{
case COMMENTS:
{
alt1=1;
}
break;
}
switch (alt1)
{
case 1:
// cif.g:81:5: COMMENTS