forked from itod/parsekit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSRGSParser.m
792 lines (655 loc) · 22 KB
/
SRGSParser.m
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
// Copyright 2010 Todd Ditchendorf
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#import "SRGSParser.h"
#import "NSString+ParseKitAdditions.h"
@interface SRGSParser ()
- (void)didMatchWord:(PKAssembly *)a;
- (void)didMatchNum:(PKAssembly *)a;
- (void)didMatchQuotedString:(PKAssembly *)a;
- (void)didMatchStar:(PKAssembly *)a;
- (void)didMatchQuestion:(PKAssembly *)a;
- (void)didMatchAnd:(PKAssembly *)a;
- (void)didMatchOr:(PKAssembly *)a;
- (void)didMatchAssignment:(PKAssembly *)a;
- (void)didMatchVariable:(PKAssembly *)a;
@end
@implementation SRGSParser
- (id)init {
if (self = [super init]) {
[self add:self.grammar];
}
return self;
}
- (void)dealloc {
self.selfIdentHeader = nil;
self.ruleName = nil;
self.tagFormat = nil;
self.lexiconURI = nil;
self.weight = nil;
self.repeat = nil;
self.probability = nil;
self.externalRuleRef = nil;
self.token = nil;
self.languageAttachment = nil;
self.tag = nil;
self.grammar = nil;
self.declaration = nil;
self.baseDecl = nil;
self.languageDecl = nil;
self.modeDecl = nil;
self.rootRuleDecl = nil;
self.tagFormatDecl = nil;
self.lexiconDecl = nil;
self.metaDecl = nil;
self.tagDecl = nil;
self.ruleDefinition = nil;
self.scope = nil;
self.ruleExpansion = nil;
self.ruleAlternative = nil;
self.sequenceElement = nil;
self.subexpansion = nil;
self.ruleRef = nil;
self.localRuleRef = nil;
self.specialRuleRef = nil;
self.repeatOperator = nil;
self.baseURI = nil;
self.languageCode = nil;
self.ABNF_URI = nil;
self.ABNF_URI_with_Media_Type = nil;
[super dealloc];
}
- (id)parse:(NSString *)s {
PKAssembly *a = [self assemblyWithString:s];
a = [self completeMatchFor:a];
return [a pop];
}
- (PKAssembly *)assemblyWithString:(NSString *)s {
PKTokenizer *t = [[[PKTokenizer alloc] initWithString:s] autorelease];
[t setTokenizerState:t.symbolState from: '-' to: '-'];
[t setTokenizerState:t.symbolState from: '.' to: '.'];
//[t.wordState setWordChars:YES from:'-' to:'-'];
PKTokenAssembly *a = [PKTokenAssembly assemblyWithTokenizer:t];
// TDNCNameState *NCNameState = [[[TDNCNameState alloc] init] autorelease];
return a;
}
//selfIdentHeader ::= '#ABNF' #x20 VersionNumber (#x20 CharEncoding)? ';'
//VersionNumber ::= '1.0'
//CharEncoding ::= Nmtoken
- (PKCollectionParser *)selfIdentHeader {
if (!selfIdentHeader) {
self.selfIdentHeader = [PKSequence sequence];
selfIdentHeader.name = @"selfIdentHeader";
[selfIdentHeader add:[PKSymbol symbolWithString:@"#"]];
[selfIdentHeader add:[PKLiteral literalWithString:@"ABNF"]];
[selfIdentHeader add:[PKNumber number]]; // VersionNumber
PKAlternation *a = [PKAlternation alternation];
[a add:[PKEmpty empty]];
[a add:[PKWord word]]; // CharEncoding
[selfIdentHeader add:a];
[selfIdentHeader add:[PKSymbol symbolWithString:@";"]];
}
return selfIdentHeader;
}
//RuleName ::= '$' ConstrainedName
//ConstrainedName ::= Name - (Char* ('.' | ':' | '-') Char*)
- (PKCollectionParser *)ruleName {
if (!ruleName) {
self.ruleName = [PKSequence sequence];
[ruleName add:[PKSymbol symbolWithString:@"$"]];
[ruleName add:[PKWord word]]; // TODO: ConstrainedName
}
return ruleName;
}
//TagFormat ::= ABNF_URI
- (PKParser *)tagFormat {
if (!tagFormat) {
self.tagFormat = self.ABNF_URI;
}
return tagFormat;
}
//LexiconURI ::= ABNF_URI | ABNF_URI_with_Media_Type
- (PKCollectionParser *)lexiconURI {
if (!lexiconURI) {
self.lexiconURI = [PKAlternation alternation];
[lexiconURI add:self.ABNF_URI];
[lexiconURI add:self.ABNF_URI_with_Media_Type];
}
return lexiconURI;
}
//Weight ::= '/' Number '/'
- (PKCollectionParser *)weight {
if (!weight) {
self.weight = [PKSequence sequence];
[weight add:[PKSymbol symbolWithString:@"/"]];
[weight add:[PKNumber number]];
[weight add:[PKSymbol symbolWithString:@"/"]];
}
return weight;
}
//Repeat ::= [0-9]+ ('-' [0-9]*)?
- (PKCollectionParser *)repeat {
if (!repeat) {
self.repeat = [PKSequence sequence];
[repeat add:[PKNumber number]];
PKSequence *s = [PKSequence sequence];
[s add:[PKSymbol symbolWithString:@"-"]];
[s add:[PKNumber number]];
PKAlternation *a = [PKAlternation alternation];
[a add:[PKEmpty empty]];
[a add:s];
[repeat add:a];
}
return repeat;
}
//Probability ::= '/' Number '/'
- (PKCollectionParser *)probability {
if (!probability) {
self.probability = [PKSequence sequence];
[probability add:[PKSymbol symbolWithString:@"/"]];
[probability add:[PKNumber number]];
[probability add:[PKSymbol symbolWithString:@"/"]];
}
return probability;
}
//ExternalRuleRef ::= '$' ABNF_URI | '$' ABNF_URI_with_Media_Type
- (PKCollectionParser *)externalRuleRef {
if (!externalRuleRef) {
self.externalRuleRef = [PKAlternation alternation];
PKSequence *s = [PKSequence sequence];
[s add:[PKSymbol symbolWithString:@"$"]];
[s add:self.ABNF_URI];
[externalRuleRef add:s];
s = [PKSequence sequence];
[s add:[PKSymbol symbolWithString:@"$"]];
[s add:self.ABNF_URI_with_Media_Type];
[externalRuleRef add:s];
}
return externalRuleRef;
}
//Token ::= Nmtoken | DoubleQuotedCharacters
- (PKCollectionParser *)token {
if (!token) {
self.token = [PKAlternation alternation];
[token add:[PKWord word]];
[token add:[PKQuotedString quotedString]];
}
return token;
}
//LanguageAttachment ::= '!' LanguageCode
- (PKCollectionParser *)languageAttachment {
if (!languageAttachment) {
self.languageAttachment = [PKSequence sequence];
[languageAttachment add:[PKSymbol symbolWithString:@"!"]];
[languageAttachment add:self.languageCode];
}
return languageAttachment;
}
//Tag ::= '{' [^}]* '}' | '{!{' (Char* - (Char* '}!}' Char*)) '}!}'
- (PKCollectionParser *)tag {
if (!tag) {
self.tag = [PKAlternation alternation];
PKSequence *s = [PKSequence sequence];
[s add:[PKSymbol symbolWithString:@"{"]];
PKAlternation *a = [PKAlternation alternation];
[a add:[PKWord word]];
[a add:[PKNumber number]];
[a add:[PKSymbol symbol]];
[a add:[PKQuotedString quotedString]];
[s add:[PKRepetition repetitionWithSubparser:a]];
[s add:[PKSymbol symbolWithString:@"}"]];
[tag add:s];
s = [PKSequence sequence];
[s add:[PKLiteral literalWithString:@"{!{"]];
a = [PKAlternation alternation];
[a add:[PKWord word]];
[a add:[PKNumber number]];
[a add:[PKSymbol symbol]];
[a add:[PKQuotedString quotedString]];
[s add:[PKRepetition repetitionWithSubparser:a]];
[s add:[PKLiteral literalWithString:@"}!}"]];
[tag add:s];
}
return tag;
}
#pragma mark -
#pragma mark Grammar
// grammar ::= selfIdentHeader declaration* ruleDefinition*
- (PKCollectionParser *)grammar {
if (!grammar) {
self.grammar = [PKSequence sequence];
[grammar add:self.selfIdentHeader];
[grammar add:[PKRepetition repetitionWithSubparser:self.declaration]];
[grammar add:[PKRepetition repetitionWithSubparser:self.ruleDefinition]];
}
return grammar;
}
// declaration ::= baseDecl | languageDecl | modeDecl | rootRuleDecl | tagFormatDecl | lexiconDecl | metaDecl | tagDecl
- (PKCollectionParser *)declaration {
if (!declaration) {
self.declaration = [PKAlternation alternation];
[declaration add:self.baseDecl];
[declaration add:self.languageDecl];
[declaration add:self.modeDecl];
[declaration add:self.rootRuleDecl];
[declaration add:self.tagFormatDecl];
[declaration add:self.lexiconDecl];
[declaration add:self.tagDecl];
}
return declaration;
}
// baseDecl ::= 'base' BaseURI ';'
- (PKCollectionParser *)baseDecl {
if (!baseDecl) {
self.baseDecl = [PKSequence sequence];
[baseDecl add:[PKLiteral literalWithString:@"base"]];
[baseDecl add:self.baseURI];
[baseDecl add:[PKSymbol symbolWithString:@";"]];
}
return baseDecl;
}
// languageDecl ::= 'language' LanguageCode ';'
- (PKCollectionParser *)languageDecl {
if (!languageDecl) {
self.languageDecl = [PKSequence sequence];
[languageDecl add:[PKLiteral literalWithString:@"language"]];
[languageDecl add:self.languageCode];
[languageDecl add:[PKSymbol symbolWithString:@";"]];
}
return languageDecl;
}
// modeDecl ::= 'mode' 'voice' ';' | 'mode' 'dtmf' ';'
- (PKCollectionParser *)modeDecl {
if (!modeDecl) {
self.modeDecl = [PKAlternation alternation];
PKSequence *s = [PKSequence sequence];
[s add:[PKLiteral literalWithString:@"mode"]];
[s add:[PKLiteral literalWithString:@"voice"]];
[s add:[PKSymbol symbolWithString:@";"]];
[modeDecl add:s];
s = [PKSequence sequence];
[s add:[PKLiteral literalWithString:@"mode"]];
[s add:[PKLiteral literalWithString:@"dtmf"]];
[s add:[PKSymbol symbolWithString:@";"]];
[modeDecl add:s];
}
return modeDecl;
}
// rootRuleDecl ::= 'root' RuleName ';'
- (PKCollectionParser *)rootRuleDecl {
if (!rootRuleDecl) {
self.rootRuleDecl = [PKSequence sequence];
[rootRuleDecl add:[PKLiteral literalWithString:@"root"]];
[rootRuleDecl add:self.ruleName];
[rootRuleDecl add:[PKSymbol symbolWithString:@";"]];
}
return rootRuleDecl;
}
// tagFormatDecl ::= 'tag-format' TagFormat ';'
- (PKCollectionParser *)tagFormatDecl {
if (!tagFormatDecl) {
self.tagFormatDecl = [PKSequence sequence];
[tagFormatDecl add:[PKLiteral literalWithString:@"tag-format"]];
[tagFormatDecl add:self.tagFormat];
[tagFormatDecl add:[PKSymbol symbolWithString:@";"]];
}
return tagFormatDecl;
}
// lexiconDecl ::= 'lexicon' LexiconURI ';'
- (PKCollectionParser *)lexiconDecl {
if (!lexiconDecl) {
self.lexiconDecl = [PKSequence sequence];
[lexiconDecl add:[PKLiteral literalWithString:@"lexicon"]];
[lexiconDecl add:self.lexiconURI];
[lexiconDecl add:[PKSymbol symbolWithString:@";"]];
}
return lexiconDecl;
}
// metaDecl ::=
// 'http-equiv' QuotedCharacters 'is' QuotedCharacters ';'
// | 'meta' QuotedCharacters 'is' QuotedCharacters ';'
- (PKCollectionParser *)metaDecl {
if (!metaDecl) {
self.metaDecl = [PKAlternation alternation];
PKSequence *s = [PKSequence sequence];
[s add:[PKLiteral literalWithString:@"http-equiv"]];
[s add:[PKQuotedString quotedString]];
[s add:[PKLiteral literalWithString:@"is"]];
[s add:[PKQuotedString quotedString]];
[s add:[PKSymbol symbolWithString:@";"]];
[metaDecl add:s];
s = [PKSequence sequence];
[s add:[PKLiteral literalWithString:@"meta"]];
[s add:[PKQuotedString quotedString]];
[s add:[PKLiteral literalWithString:@"is"]];
[s add:[PKQuotedString quotedString]];
[s add:[PKSymbol symbolWithString:@";"]];
[metaDecl add:s];
}
return metaDecl;
}
// tagDecl ::= Tag ';'
- (PKCollectionParser *)tagDecl {
if (!tagDecl) {
self.tagDecl = [PKSequence sequence];
[tagDecl add:self.tag];
[tagDecl add:[PKSymbol symbolWithString:@";"]];
}
return tagDecl;
}
// ruleDefinition ::= scope? RuleName '=' ruleExpansion ';'
- (PKCollectionParser *)ruleDefinition {
if (!ruleDefinition) {
self.ruleDefinition = [PKSequence sequence];
PKAlternation *a = [PKAlternation alternation];
[a add:[PKEmpty empty]];
[a add:self.scope];
[ruleDefinition add:a];
[ruleDefinition add:self.ruleName];
[ruleDefinition add:[PKSymbol symbolWithString:@"="]];
[ruleDefinition add:self.ruleExpansion];
[ruleDefinition add:[PKSymbol symbolWithString:@";"]];
}
return ruleDefinition;
}
// scope ::= 'private' | 'public'
- (PKCollectionParser *)scope {
if (!scope) {
self.scope = [PKAlternation alternation];
[scope add:[PKLiteral literalWithString:@"private"]];
[scope add:[PKLiteral literalWithString:@"public"]];
}
return scope;
}
// ruleExpansion ::= ruleAlternative ( '|' ruleAlternative )*
- (PKCollectionParser *)ruleExpansion {
if (!ruleExpansion) {
self.ruleExpansion = [PKSequence sequence];
[ruleExpansion add:self.ruleAlternative];
PKSequence *pipeRuleAlternative = [PKSequence sequence];
[pipeRuleAlternative add:[PKSymbol symbolWithString:@"|"]];
[pipeRuleAlternative add:self.ruleAlternative];
[ruleExpansion add:[PKRepetition repetitionWithSubparser:pipeRuleAlternative]];
}
return ruleExpansion;
}
// ruleAlternative ::= Weight? sequenceElement+
- (PKCollectionParser *)ruleAlternative {
if (!ruleAlternative) {
self.ruleAlternative = [PKSequence sequence];
PKAlternation *a = [PKAlternation alternation];
[a add:[PKEmpty empty]];
[a add:self.weight];
[ruleAlternative add:a];
[ruleAlternative add:self.sequenceElement];
[ruleAlternative add:[PKRepetition repetitionWithSubparser:self.sequenceElement]];
}
return ruleAlternative;
}
// sequenceElement ::= subexpansion | subexpansion repeatOperator
// me: changing to:
// sequenceElement ::= subexpansion repeatOperator?
- (PKCollectionParser *)sequenceElement {
if (!sequenceElement) {
// self.sequenceElement = [PKAlternation alternation];
// [sequenceElement add:self.subexpansion];
//
// PKSequence *s = [PKSequence sequence];
// [s add:self.subexpansion];
// [s add:self.repeatOperator];
//
// [sequenceElement add:s];
self.sequenceElement = [PKSequence sequence];
[sequenceElement add:self.subexpansion];
PKAlternation *a = [PKAlternation alternation];
[a add:[PKEmpty empty]];
[a add:self.repeatOperator];
[sequenceElement add:a];
}
return sequenceElement;
}
// subexpansion ::=
// Token LanguageAttachment?
// | ruleRef
// | Tag
// | '(' ')'
// | '(' ruleExpansion ')' LanguageAttachment?
// | '[' ruleExpansion ']' LanguageAttachment?
- (PKCollectionParser *)subexpansion {
if (!subexpansion) {
self.subexpansion = [PKAlternation alternation];
PKSequence *s = [PKSequence sequence];
[s add:self.token];
PKAlternation *a = [PKAlternation alternation];
[a add:[PKEmpty empty]];
[a add:self.languageAttachment];
[s add:a];
[subexpansion add:s];
[subexpansion add:self.ruleRef];
[subexpansion add:self.tag];
s = [PKSequence sequence];
[s add:[PKSymbol symbolWithString:@"("]];
[s add:[PKSymbol symbolWithString:@")"]];
[subexpansion add:s];
s = [PKSequence sequence];
[s add:[PKSymbol symbolWithString:@"("]];
[s add:self.ruleExpansion];
[s add:[PKSymbol symbolWithString:@")"]];
a = [PKAlternation alternation];
[a add:[PKEmpty empty]];
[a add:self.languageAttachment];
[s add:a];
[subexpansion add:s];
s = [PKSequence sequence];
[s add:[PKSymbol symbolWithString:@"["]];
[s add:self.ruleExpansion];
[s add:[PKSymbol symbolWithString:@"]"]];
a = [PKAlternation alternation];
[a add:[PKEmpty empty]];
[a add:self.languageAttachment];
[s add:a];
[subexpansion add:s];
}
return subexpansion;
}
// ruleRef ::= localRuleRef | ExternalRuleRef | specialRuleRef
- (PKCollectionParser *)ruleRef {
if (!ruleRef) {
self.ruleRef = [PKAlternation alternation];
[ruleRef add:self.localRuleRef];
[ruleRef add:self.externalRuleRef];
[ruleRef add:self.specialRuleRef];
}
return ruleRef;
}
// localRuleRef ::= RuleName
- (PKCollectionParser *)localRuleRef {
if (!localRuleRef) {
self.localRuleRef = self.ruleName;
}
return localRuleRef;
}
// specialRuleRef ::= '$NULL' | '$VOID' | '$GARBAGE'
- (PKCollectionParser *)specialRuleRef {
if (!specialRuleRef) {
self.specialRuleRef = [PKAlternation alternation];
[specialRuleRef add:[PKLiteral literalWithString:@"$NULL"]];
[specialRuleRef add:[PKLiteral literalWithString:@"$VOID"]];
[specialRuleRef add:[PKLiteral literalWithString:@"$GARBAGE"]];
}
return specialRuleRef;
}
// repeatOperator ::='<' Repeat Probability? '>'
- (PKCollectionParser *)repeatOperator {
if (!repeatOperator) {
self.repeatOperator = [PKSequence sequence];
[repeatOperator add:[PKSymbol symbolWithString:@"<"]];
[repeatOperator add:self.repeat];
PKAlternation *a = [PKAlternation alternation];
[a add:[PKEmpty empty]];
[a add:self.probability];
[repeatOperator add:a];
[repeatOperator add:[PKSymbol symbolWithString:@">"]];
}
return repeatOperator;
}
//BaseURI ::= ABNF_URI
- (PKParser *)baseURI {
if (!baseURI) {
self.baseURI = [PKWord word];
}
return baseURI;
}
//LanguageCode ::= Nmtoken
- (PKCollectionParser *)languageCode {
if (!languageCode) {
self.languageCode = [PKSequence sequence];
[languageCode add:[PKWord word]];
// [languageCode add:[PKSymbol symbolWithString:@"-"]];
// [languageCode add:[PKWord word]];
}
return languageCode;
}
- (PKParser *)ABNF_URI {
if (!ABNF_URI) {
self.ABNF_URI = [PKWord word];
}
return ABNF_URI;
}
- (PKParser *)ABNF_URI_with_Media_Type {
if (!ABNF_URI_with_Media_Type) {
self.ABNF_URI_with_Media_Type = [PKWord word];
}
return ABNF_URI_with_Media_Type;
}
#pragma mark -
#pragma mark Assembler Methods
- (void)didMatchWord:(PKAssembly *)a {
// NSLog(@"%s", _cmd);
// NSLog(@"a: %@", a);
PKToken *tok = [a pop];
[a push:[PKLiteral literalWithString:tok.stringValue]];
}
- (void)didMatchNum:(PKAssembly *)a {
// NSLog(@"%s", _cmd);
// NSLog(@"a: %@", a);
PKToken *tok = [a pop];
[a push:[PKLiteral literalWithString:tok.stringValue]];
}
- (void)didMatchQuotedString:(PKAssembly *)a {
// NSLog(@"%s", _cmd);
// NSLog(@"a: %@", a);
PKToken *tok = [a pop];
NSString *s = [tok.stringValue stringByTrimmingQuotes];
PKSequence *p = [PKSequence sequence];
PKTokenizer *t = [PKTokenizer tokenizerWithString:s];
PKToken *eof = [PKToken EOFToken];
while (eof != (tok = [t nextToken])) {
[p add:[PKLiteral literalWithString:tok.stringValue]];
}
[a push:p];
}
- (void)didMatchStar:(PKAssembly *)a {
// NSLog(@"%s", _cmd);
// NSLog(@"a: %@", a);
PKRepetition *p = [PKRepetition repetitionWithSubparser:[a pop]];
[a push:p];
}
- (void)didMatchQuestion:(PKAssembly *)a {
// NSLog(@"%s", _cmd);
// NSLog(@"a: %@", a);
PKAlternation *p = [PKAlternation alternation];
[p add:[a pop]];
[p add:[PKEmpty empty]];
[a push:p];
}
- (void)didMatchAnd:(PKAssembly *)a {
// NSLog(@"%s", _cmd);
// NSLog(@"a: %@", a);
id top = [a pop];
PKSequence *p = [PKSequence sequence];
[p add:[a pop]];
[p add:top];
[a push:p];
}
- (void)didMatchOr:(PKAssembly *)a {
// NSLog(@"%s", _cmd);
// NSLog(@"a: %@", a);
id top = [a pop];
// NSLog(@"top: %@", top);
// NSLog(@"top class: %@", [top class]);
PKAlternation *p = [PKAlternation alternation];
[p add:[a pop]];
[p add:top];
[a push:p];
}
- (void)didMatchAssignment:(PKAssembly *)a {
// NSLog(@"%s", _cmd);
// NSLog(@"a: %@", a);
id val = [a pop];
PKToken *keyTok = [a pop];
NSMutableDictionary *table = [NSMutableDictionary dictionaryWithDictionary:a.target];
[table setObject:val forKey:keyTok.stringValue];
a.target = table;
}
- (void)didMatchVariable:(PKAssembly *)a {
// NSLog(@"%s", _cmd);
// NSLog(@"a: %@", a);
PKToken *keyTok = [a pop];
id val = [a.target objectForKey:keyTok.stringValue];
// PKParser *p = nil;
// if (valTok.isWord) {
// p = [PKWord wordWithString:valTok.value];
// } else if (valTok.isQuotedString) {
// p = [PKQuotedString quotedStringWithString:valTok.value];
// } else if (valTok.isNumber) {
// p = [PKNum numWithString:valTok.stringValue];
// }
[a push:val];
}
@synthesize selfIdentHeader;
@synthesize ruleName;
@synthesize tagFormat;
@synthesize lexiconURI;
@synthesize weight;
@synthesize repeat;
@synthesize probability;
@synthesize externalRuleRef;
@synthesize token;
@synthesize languageAttachment;
@synthesize tag;
@synthesize grammar;
@synthesize declaration;
@synthesize baseDecl;
@synthesize languageDecl;
@synthesize modeDecl;
@synthesize rootRuleDecl;
@synthesize tagFormatDecl;
@synthesize lexiconDecl;
@synthesize metaDecl;
@synthesize tagDecl;
@synthesize ruleDefinition;
@synthesize scope;
@synthesize ruleExpansion;
@synthesize ruleAlternative;
@synthesize sequenceElement;
@synthesize subexpansion;
@synthesize ruleRef;
@synthesize localRuleRef;
@synthesize specialRuleRef;
@synthesize repeatOperator;
@synthesize baseURI;
@synthesize languageCode;
@synthesize ABNF_URI;
@synthesize ABNF_URI_with_Media_Type;
@end