-
Notifications
You must be signed in to change notification settings - Fork 10
/
asn1.y
1071 lines (865 loc) · 30.9 KB
/
asn1.y
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
// header
%{
package asn1go
import (
"math"
)
%}
////////////////////////////
// declarations section
//
// extra SymType fields
%union{
name string
numberRepr string
Number Number
Real Real
TagDefault int
ExtensionDefault bool
ModuleIdentifier ModuleIdentifier
DefinitiveObjIdComponent DefinitiveObjIdComponent
DefinitiveObjIdComponentList []DefinitiveObjIdComponent
DefinitiveIdentifier DefinitiveIdentifier
Type Type
ObjectIdElement ObjectIdElement
DefinedValue DefinedValue
ObjectIdentifierValue ObjectIdentifierValue
Value Value
Assignment Assignment
AssignmentList AssignmentList
ModuleBody ModuleBody
ValueReference ValueReference
TypeReference TypeReference
Constraint Constraint
ConstraintSpec ConstraintSpec
ElementSetSpec ElementSetSpec
Unions Unions
Intersections Intersections
IntersectionElements IntersectionElements
Exclusions Exclusions
Elements Elements
SubtypeConstraint SubtypeConstraint
RangeEndpoint RangeEndpoint
NamedType NamedType
ComponentType ComponentType
ComponentTypeLists ComponentTypeLists
ComponentTypeList ComponentTypeList
SequenceType SequenceType
Tag Tag
Class int
SequenceOfType SequenceOfType
NamedBitList []NamedBit
NamedBit NamedBit
Imports []SymbolsFromModule
SymbolsFromModule SymbolsFromModule
SymbolList []Symbol
Symbol Symbol
GlobalModuleReference GlobalModuleReference
AlternativeTypeList []NamedType
ChoiceType ChoiceType
ExtensionAdditionAlternative ChoiceExtension
ExtensionAdditionAlternativesList []ChoiceExtension
ExtensionAdditions []ExtensionAddition
NamedNumberList []NamedNumber
NamedNumber NamedNumber
EnumeratedType EnumeratedType
Enumeration []EnumerationItem
EnumerationItem EnumerationItem
}
%token WHITESPACE
%token NEWLINE
%token <name> TYPEORMODULEREFERENCE
%token <name> VALUEIDENTIFIER
%token <Number> NUMBER
%token <bstring> BSTRING // TODO not implemented in lexer
%token <bstring> XMLBSTRING // TODO not implemented in lexer
%token <hstring> HSTRING // TODO not implemented in lexer
%token <hstring> XMLHSTRING // TODO not implemented in lexer
%token <cstring> CSTRING // TODO not implemented in lexer
%token <cstring> XMLCSTRING // TODO not implemented in lexer
%token ASSIGNMENT
%token RANGE_SEPARATOR
%token ELLIPSIS
%token LEFT_VERSION_BRACKETS
%token RIGHT_VERSION_BRACKETS
%token XML_END_TAG_START // TODO not implemented in lexer
%token XML_SINGLE_START_END // TODO not implemented in lexer
%token XML_BOOLEAN_TRUE // TODO not implemented in lexer
%token XML_BOOLEAN_FALSE // TODO not implemented in lexer
%token XMLASN1TYPENAME // TODO not implemented in lexer
%token EXPONENT // differs from spec, for REAL values to work
// single-symbol tokens
%token OPEN_CURLY // "{"
%token CLOSE_CURLY // "}"
%token LESS // "<"
%token GREATER // ">"
%token COMMA // ","
%token DOT // "."
%token OPEN_ROUND // "("
%token CLOSE_ROUND // ")"
%token OPEN_SQUARE // "["
%token CLOSE_SQUARE // "]"
%token MINUS // "-" (HYPEN-MINUS)
%token COLON // ":"
%token EQUALS // "="
%token QUOTATION_MARK // """ (QUOTATION MARK)
%token APOSTROPHE // "'" (APOSTROPHE)
%token SPACE // " " (SPACE) // TODO won't be parsed probably
%token SEMICOLON // ";"
%token AT // "@"
%token PIPE // "|"
%token EXCLAMATION // "!"
%token CARET // "^"
// reserved words
%token ABSENT
%token ENCODED
%token INTEGER
%token RELATIVE_OID
%token ABSTRACT_SYNTAX
%token END
%token INTERSECTION
%token SEQUENCE
%token ALL
%token ENUMERATED
%token ISO646String
%token SET
%token APPLICATION
%token EXCEPT
%token MAX
%token SIZE
%token AUTOMATIC
%token EXPLICIT
%token MIN
%token STRING
%token BEGIN
%token EXPORTS
%token MINUS_INFINITY
%token SYNTAX
%token BIT
%token EXTENSIBILITY
%token NULL
%token T61String
%token BMPString
%token EXTERNAL
%token NumericString
%token TAGS
%token BOOLEAN
%token FALSE
%token OBJECT
%token TeletexString
%token BY
%token FROM
%token ObjectDescriptor
%token TRUE
%token CHARACTER
%token GeneralizedTime
%token OCTET
%token TYPE_IDENTIFIER
%token CHOICE
%token GeneralString
%token OF
%token UNION
%token CLASS
%token GraphicString
%token OPTIONAL
%token UNIQUE
%token COMPONENT
%token IA5String
%token PATTERN
%token UNIVERSAL
%token COMPONENTS
%token IDENTIFIER
%token PDV
%token UniversalString
%token CONSTRAINED
%token IMPLICIT
%token PLUS_INFINITY
%token UTCTime
%token CONTAINING
%token IMPLIED
%token PRESENT
%token UTF8String
%token DEFAULT
%token IMPORTS
%token PrintableString
%token VideotexString
%token DEFINITIONS
%token INCLUDES
%token PRIVATE
%token VisibleString
%token EMBEDDED
%token INSTANCE
%token REAL
%token WITH
// X.208-specific
%token ANY
%token DEFINED
// When adding new reserved words, make sure to update lexer.go.
%type <Real> realnumber
%type <Number> SignedExponent
%type <name> modulereference
%type <TypeReference> typereference
%type <name> identifier
%type <ExtensionDefault> ExtensionDefault
%type <TagDefault> TagDefault
%type <ModuleIdentifier> ModuleIdentifier
%type <DefinitiveObjIdComponent> DefinitiveObjIdComponent
%type <Number> DefinitiveNumberForm
%type <DefinitiveObjIdComponentList> DefinitiveObjIdComponentList
%type <DefinitiveObjIdComponent> DefinitiveNameAndNumberForm
%type <DefinitiveIdentifier> DefinitiveIdentifier
%type <name> NameForm
%type <DefinedValue> DefinedValue
%type <Type> ObjectIdentifierType
%type <Type> IntegerType
%type <Type> BooleanType
%type <Type> BuiltinType
%type <Type> Type
%type <Type> NullType
%type <Type> EnumeratedType
%type <Type> AnyType
%type <NamedType> NamedType
%type <ObjectIdElement> NumberForm
%type <ObjectIdElement> NameAndNumberForm
%type <ObjectIdElement> ObjIdComponents
%type <ObjectIdentifierValue> ObjIdComponentsList
%type <ObjectIdentifierValue> ObjectIdentifierValue
%type <Value> BuiltinValue
%type <Value> Value
%type <Value> IntegerValue
%type <Type> RealType
%type <Value> RealValue
%type <Type> BooleanType
%type <Value> BooleanValue
%type <Value> NumericRealValue SpecialRealValue
%type <Number> SignedNumber
%type <Number> number
%type <Assignment> Assignment
%type <Assignment> ValueAssignment
%type <Assignment> TypeAssignment
%type <AssignmentList> AssignmentList
%type <ModuleBody> ModuleBody
%type <ValueReference> valuereference
%type <Type> ConstrainedType
%type <Type> TypeWithConstraint
%type <Constraint> Constraint
%type <ConstraintSpec> ConstraintSpec
%type <SubtypeConstraint> SubtypeConstraint
%type <SubtypeConstraint> ElementSetSpecs
%type <SubtypeConstraint> RootElementSetSpec
%type <ElementSetSpec> AdditionalElementSetSpec
%type <ElementSetSpec> ElementSetSpec
%type <Unions> Unions
%type <Unions> UElems
%type <Intersections> Intersections
%type <Intersections> IElems
%type <IntersectionElements> IntersectionElements
%type <Exclusions> Exclusions
%type <Elements> Elements
%type <Elements> Elems
%type <Elements> SingleValue
%type <Elements> ValueRange
%type <Elements> SubtypeElements
%type <Elements> TypeConstraint
%type <Elements> InnerTypeConstraints
%type <Elements> SizeConstraint
%type <RangeEndpoint> LowerEndpoint UpperEndpoint
%type <Value> LowerEndValue UpperEndValue
%type <Type> CharacterStringType RestrictedCharacterStringType UnrestrictedCharacterStringType
%type <Type> DefinedType ReferencedType
%type <Type> SequenceType
%type <Type> SequenceOfType
%type <Type> SetType
%type <Type> SetOfType
%type <ComponentType> ComponentType
%type <ComponentTypeList> ComponentTypeList
%type <ComponentTypeList> RootComponentTypeList
%type <ComponentTypeLists> ComponentTypeLists
%type <Type> TaggedType
%type <Tag> Tag
%type <Value> ClassNumber
%type <Class> Class
%type <Type> UsefulType
%type <Type> OctetStringType
%type <Type> BitStringType
%type <NamedBitList> NamedBitList
%type <NamedBit> NamedBit
%type <Imports> Imports
%type <Imports> SymbolsImported
%type <Imports> SymbolsFromModuleList
%type <SymbolsFromModule> SymbolsFromModule
%type <SymbolList> SymbolList
%type <Symbol> Symbol
%type <Symbol> Reference // quite questionable
%type <Value> AssignedIdentifier
%type <GlobalModuleReference> GlobalModuleReference
%type <Type> ChoiceType
%type <ChoiceType> AlternativeTypeLists
%type <AlternativeTypeList> AlternativeTypeList RootAlternativeTypeList
%type <NamedType> NamedType
%type <ExtensionAdditionAlternative> ExtensionAdditionAlternative
%type <ExtensionAdditionAlternativesList> ExtensionAdditionAlternatives
%type <ExtensionAdditionAlternativesList> ExtensionAdditionAlternativesList
%type <ExtensionAdditions> ExtensionAdditions
%type <ExtensionAdditions> ExtensionAdditionList
%type <ExtensionAdditions> ExtensionAddition
%type <NamedNumber> NamedNumber
%type <NamedNumberList> NamedNumberList
%type <EnumeratedType> Enumerations
%type <Enumeration> Enumeration RootEnumeration AdditionalEnumeration
%type <EnumerationItem> EnumerationItem
//
// end declarations
////////////////////////////
%%
////////////////////////////
// grammar/rules section
//
// Code inside the grammar actions may refer to the variable yylex,
// which holds the yyLexer passed to yyParse.
ModuleDefinition :
ModuleIdentifier
DEFINITIONS
TagDefault
ExtensionDefault
ASSIGNMENT
BEGIN
ModuleBody
END
{ yylex.(*MyLexer).result = &ModuleDefinition{ModuleIdentifier: $1, TagDefault: $3, ExtensibilityImplied: $4, ModuleBody: $7} }
;
typereference: TYPEORMODULEREFERENCE { $$ = TypeReference($1) }
;
modulereference: TYPEORMODULEREFERENCE;
valuereference: VALUEIDENTIFIER { $$ = ValueReference($1) }
;
number : NUMBER
;
identifier: VALUEIDENTIFIER;
ModuleIdentifier :
modulereference
DefinitiveIdentifier
{ $$ = ModuleIdentifier{Reference: $1, DefinitiveIdentifier: $2} }
;
DefinitiveIdentifier : OPEN_CURLY DefinitiveObjIdComponentList CLOSE_CURLY { $$ = DefinitiveIdentifier($2) }
| /*empty*/ { $$ = DefinitiveIdentifier(make([]DefinitiveObjIdComponent, 0)) }
;
DefinitiveObjIdComponentList : DefinitiveObjIdComponent { $$ = append(make([]DefinitiveObjIdComponent, 0), $1) }
| DefinitiveObjIdComponent DefinitiveObjIdComponentList { $$ = append(append(make([]DefinitiveObjIdComponent, 0), $1), $2...) }
;
DefinitiveObjIdComponent : NameForm { $$ = DefinitiveObjIdComponent{Name: $1} }
| DefinitiveNumberForm { $$ = DefinitiveObjIdComponent{Id: $1.IntValue()} }
| DefinitiveNameAndNumberForm { $$ = $1 }
;
DefinitiveNumberForm : NUMBER { $$ = $1 }
;
DefinitiveNameAndNumberForm : identifier OPEN_ROUND DefinitiveNumberForm CLOSE_ROUND
{ $$ = DefinitiveObjIdComponent{Name: $1, Id: $3.IntValue()} }
;
TagDefault : EXPLICIT TAGS { $$ = TAGS_EXPLICIT }
| IMPLICIT TAGS { $$ = TAGS_IMPLICIT }
| AUTOMATIC TAGS { $$ = TAGS_AUTOMATIC }
| /*empty*/ { $$ = TAGS_EXPLICIT }
;
ExtensionDefault : EXTENSIBILITY IMPLIED { $$ = true }
| /*empty*/ { $$ = false }
;
ModuleBody : Exports Imports AssignmentList { $$ = ModuleBody{Imports: $2, AssignmentList: $3} }
| /*empty*/ { $$ = ModuleBody{} }
;
Exports : EXPORTS SymbolsExported SEMICOLON
| EXPORTS ALL SEMICOLON
| /*empty*/
;
SymbolsExported : SymbolList
| /*empty*/
;
Imports : IMPORTS SymbolsImported SEMICOLON { $$ = $2 }
| /*empty*/ { $$ = make([]SymbolsFromModule, 0) }
;
SymbolsImported : SymbolsFromModuleList { $$ = $1 }
| /*empty*/ { $$ = make([]SymbolsFromModule, 0) }
;
SymbolsFromModuleList : SymbolsFromModule { $$ = append(make([]SymbolsFromModule, 0), $1) }
| SymbolsFromModuleList SymbolsFromModule { $$ = append($1, $2) }
;
SymbolsFromModule : SymbolList FROM GlobalModuleReference { $$ = SymbolsFromModule{$1, $3} }
;
GlobalModuleReference : modulereference AssignedIdentifier { $$ = GlobalModuleReference{$1, $2} }
;
AssignedIdentifier : ObjectIdentifierValue { $$ = $1 }
| DefinedValue { $$ = $1 }
| /*empty*/ { $$ = nil }
;
SymbolList : Symbol { $$ = append(make([]Symbol, 0), $1) }
| SymbolList COMMA Symbol { $$ = append($1, $3) }
;
Symbol : Reference
// | ParameterizedReference
;
Reference : typereference { $$ = TypeReference($1) }
| modulereference { $$ = ModuleReference($1) }
| valuereference { $$ = ValueReference($1) }
// | objectclassreference
// | objectreference
// | objectsetreference
;
AssignmentList : Assignment { $$ = AssignmentList{$1} }
| AssignmentList Assignment { $$ = append($1, $2) }
;
Assignment : TypeAssignment
| ValueAssignment
// | XMLValueAssignment
// | ValueSetTypeAssignment
// | ObjectClassAssignment
// | ObjectAssignment
// | ObjectSetAssignment
// | ParameterizedAssignment
;
// 13.1
DefinedType : // ExternalTypeReference
/*|*/ typereference { $$ = $1 }
// | ParameterizedType
// | ParameterizedValueSetType
;
// 13.3
DefinedValue :
modulereference DOT valuereference { $$ = DefinedValue{ModuleReference($1), $3} }
| valuereference { $$ = DefinedValue{ValueName: $1} }
// | ParameterizedValue
;
// 13.6
// Not used, defined inline in DefinedValue to simplicy and avoid yacc conflicts.
// ExternalValueReference ::=
// modulereference
// "."
// valuereference
// 15.1
TypeAssignment : typereference ASSIGNMENT Type { $$ = TypeAssignment{$1, $3} }
;
ValueAssignment : valuereference Type ASSIGNMENT Value { $$ = ValueAssignment{$1, $2, $4} }
;
// 16.1
Type : BuiltinType
| ReferencedType
| ConstrainedType
;
// 16.2
BuiltinType : BitStringType
| BooleanType
| CharacterStringType
| ChoiceType
// | EmbeddedPDVType
| EnumeratedType
// | ExternalType
// | InstanceOfType
| IntegerType
| NullType
// | ObjectClassFieldType
| ObjectIdentifierType
| OctetStringType
| RealType
// | RelativeOIDType
| SequenceType
| SequenceOfType
| SetType
| SetOfType
// modification - taken from X.208
| AnyType
| TaggedType
;
// 16.3
ReferencedType : DefinedType
| UsefulType
// | SelectionType
// | TypeFromObject
// | ValueSetFromObjects
;
// 16.5
NamedType : identifier Type { $$ = NamedType{Identifier: Identifier($1), Type: $2} }
;
// 16.7
Value : BuiltinValue
// | ReferencedValue
// | ObjectClassFieldValue
;
// 16.8
// TODO
BuiltinValue : // BitStringValue
/*|*/ BooleanValue
// | CharacterStringValue
// | ChoiceValue
// | EmbeddedPDVValue
// | EnumeratedValue
// | ExternalValue
// | InstanceOfValue
| IntegerValue
// | NullValue
| ObjectIdentifierValue { $$ = $1 }
// | OctetStringValue
| RealValue
// | RelativeOIDValue
// | SequenceValue
// | SequenceOfValue
// | SetValue
// | SetOfValue
// | TaggedValue
;
// 17.3
BooleanType : BOOLEAN { $$ = BooleanType{} }
;
BooleanValue : TRUE { $$ = Boolean(true) }
| FALSE { $$ = Boolean(false) }
;
// 18.1
IntegerType : INTEGER { $$ = IntegerType{} }
| INTEGER OPEN_CURLY NamedNumberList CLOSE_CURLY { $$ = IntegerType{$3} }
;
NamedNumberList : NamedNumber { $$ = []NamedNumber{$1} }
| NamedNumberList COMMA NamedNumber { $$ = append($1, $3) }
;
NamedNumber : identifier OPEN_ROUND SignedNumber CLOSE_ROUND { $$ = NamedNumber{Identifier($1), $3} }
| identifier OPEN_ROUND DefinedValue CLOSE_ROUND { $$ = NamedNumber{Identifier($1), $3} }
;
SignedNumber : NUMBER { $$ = $1 }
| MINUS NUMBER { $$ = $2.UnaryMinus() }
;
// 18.9
IntegerValue : SignedNumber { $$ = $1 }
| identifier { $$ = IdentifiedIntegerValue{Name: $1} }
;
// 19.1
EnumeratedType : ENUMERATED OPEN_CURLY Enumerations CLOSE_CURLY { $$ = $3 }
;
Enumerations : RootEnumeration { $$ = EnumeratedType{RootEnumeration: $1} }
| RootEnumeration COMMA ELLIPSIS ExceptionSpec { $$ = EnumeratedType{RootEnumeration: $1} }
| RootEnumeration COMMA ELLIPSIS ExceptionSpec COMMA AdditionalEnumeration { $$ = EnumeratedType{RootEnumeration: $1, AdditionalEnumeration: $6} }
RootEnumeration : Enumeration
;
AdditionalEnumeration : Enumeration
;
Enumeration : EnumerationItem { $$ = []EnumerationItem{$1} }
| EnumerationItem COMMA Enumeration { $$ = append([]EnumerationItem{$1}, $3...) }
;
EnumerationItem : NamedNumber { $$ = $1 }
| identifier { $$ = Identifier($1) }
;
// 20.1
RealType : REAL { $$ = RealType{} }
;
// 20.6
RealValue : NumericRealValue
| SpecialRealValue
;
NumericRealValue : realnumber { $$ = $1 }
| MINUS realnumber { $$ = $2.UnaryMinus() }
// | SequenceValue // Value of the associated sequence type
;
SpecialRealValue : PLUS_INFINITY { $$ = Real(math.Inf(1)) }
| MINUS_INFINITY { $$ = Real(math.Inf(-1)) }
;
// TODO this seem to be not strict enough (spaces can sneak in into composite value)
realnumber : NUMBER { $$ = parseRealNumber($1, 0, 0) }
| NUMBER DOT NUMBER { $$ = parseRealNumber($1, $3, 0) }
| NUMBER DOT NUMBER EXPONENT SignedExponent { $$ = parseRealNumber($1, $3, $5) }
| NUMBER EXPONENT SignedExponent { $$ = parseRealNumber($1, 0, $3) }
;
SignedExponent : NUMBER
| MINUS NUMBER { $$ = Number(-int($2)) }
;
// 21.1
BitStringType : BIT STRING { $$ = BitStringType{} }
| BIT STRING OPEN_CURLY NamedBitList CLOSE_CURLY { $$ = BitStringType{NamedBits: $4} }
;
NamedBitList : NamedBit { $$ = append(make([]NamedBit, 0), $1) }
| NamedBitList COMMA NamedBit { $$ = append($1, $3) }
;
NamedBit : identifier OPEN_ROUND number CLOSE_ROUND { $$ = NamedBit{Name: Identifier($1), Index: $3} }
| identifier OPEN_ROUND DefinedValue CLOSE_ROUND { $$ = NamedBit{Name: Identifier($1), Index: $3} }
;
// 22.1
OctetStringType : OCTET STRING { $$ = OctetStringType{} }
;
// 23.1
NullType : NULL { $$ = NullType{} }
;
// 24.1
SequenceType : SEQUENCE OPEN_CURLY CLOSE_CURLY { $$ = SequenceType{} }
| SEQUENCE OPEN_CURLY ExtensionAndException OptionalExtensionMarker CLOSE_CURLY { $$ = SequenceType{} }
| SEQUENCE OPEN_CURLY ComponentTypeLists CLOSE_CURLY { $$ = SequenceType{Components: append($3.Components, $3.TrailingComponents...), ExtensionAdditions: $3.ExtensionAdditions} }
;
ExtensionAndException : ELLIPSIS
| ELLIPSIS ExceptionSpec
;
OptionalExtensionMarker : COMMA ELLIPSIS | /*empty*/
;
// TODO Extensions are not fully supported, extension information will be ignored.
// Edited from the doc - ComponentTypeList used directly instead of RootComponentTypeList to avoid ambiguity around COMMA.
ComponentTypeLists : ComponentTypeList { $$ = ComponentTypeLists{Components: $1} }
| ComponentTypeList COMMA ExtensionAndException ExtensionAdditions OptionalExtensionMarker { $$ = ComponentTypeLists{Components: $1, ExtensionAdditions: $4} }
| ComponentTypeList COMMA ExtensionAndException ExtensionAdditions ExtensionEndMarker COMMA ComponentTypeList { $$ = ComponentTypeLists{Components: $1, ExtensionAdditions: $4, TrailingComponents: $7} }
// | ExtensionAndException ExtensionAdditions ExtensionEndMarker "," RootComponentTypeList
// | ExtensionAndException ExtensionAdditions OptionalExtensionMarker
;
// Unused, as it generates ambiguity around COMMA in ComponentTypeLists
RootComponentTypeList : ComponentTypeList
;
ExtensionEndMarker : COMMA ELLIPSIS
;
ExtensionAdditions : COMMA ExtensionAdditionList { $$ = $2 }
| /*empty*/ { $$ = nil }
;
ExtensionAdditionList : ExtensionAddition { $$ = append([]ExtensionAddition{}, $1...) }
| ExtensionAdditionList COMMA ExtensionAddition { $$ = append($1, $3...) }
;
ExtensionAddition : ComponentType { $$ = []ExtensionAddition{$1} }
| ExtensionAdditionGroup { $$ = nil }
ExtensionAdditionGroup : LEFT_VERSION_BRACKETS VersionNumber ComponentTypeList RIGHT_VERSION_BRACKETS
;
VersionNumber : /*empty*/
| NUMBER COLON
;
ComponentTypeList : ComponentType { $$ = append(make(ComponentTypeList, 0), $1) }
| ComponentTypeList COMMA ComponentType { $$ = append($1, $3) }
;
ComponentType : NamedType { $$ = NamedComponentType{NamedType: $1} }
| NamedType OPTIONAL { $$ = NamedComponentType{NamedType: $1, IsOptional: true} }
| NamedType DEFAULT Value { $$ = NamedComponentType{NamedType: $1, Default: &$3} }
| COMPONENTS OF Type { $$ = ComponentsOfComponentType{Type: $3} }
;
// 26.1
SetType : SET OPEN_CURLY CLOSE_CURLY { $$ = SetType{} }
| SET OPEN_CURLY ExtensionAndException OptionalExtensionMarker CLOSE_CURLY { $$ = SetType{} }
| SET OPEN_CURLY ComponentTypeLists CLOSE_CURLY { $$ = SetType{Components: append($3.Components, $3.TrailingComponents...), ExtensionAdditions: $3.ExtensionAdditions} }
// 27.1
SetOfType : SET OF Type { $$ = SetOfType{$3} }
| SET OF NamedType { $$ = SetOfType{$3} }
// 27.1 from x.208
AnyType : ANY { $$ = AnyType{} }
| ANY DEFINED BY identifier { $$ = AnyType{Identifier($4)} }
// 28.1
ChoiceType : CHOICE OPEN_CURLY AlternativeTypeLists CLOSE_CURLY { $$ = $3 }
;
AlternativeTypeLists : AlternativeTypeList COMMA ExtensionAndException ExtensionAdditionAlternatives OptionalExtensionMarker { $$ = ChoiceType{$1,$4} }
| AlternativeTypeList { $$ = ChoiceType{AlternativeTypeList: $1} }
| ExtensionAndException ExtensionAdditionAlternatives OptionalExtensionMarker { $$ = ChoiceType{nil, $2} }
;
// defined in grammar, but screws up ExtensionAndException parsing
RootAlternativeTypeList : AlternativeTypeList
;
ExtensionAdditionAlternatives : COMMA ExtensionAdditionAlternativesList { $$ = $2 }
| /*empty*/ { $$ = make([]ChoiceExtension, 0) }
;
ExtensionAdditionAlternativesList : ExtensionAdditionAlternative { $$ = append(make([]ChoiceExtension, 0), $1) }
| ExtensionAdditionAlternativesList COMMA ExtensionAdditionAlternative { $$ = append($1, $3) }
;
ExtensionAdditionAlternative : /*ExtensionAdditionAlternativesGroup
| */NamedType { $$ = $1 }
;
// TODO
ExtensionAdditionAlternativesGroup : LEFT_VERSION_BRACKETS VersionNumber AlternativeTypeList RIGHT_VERSION_BRACKETS
;
AlternativeTypeList : NamedType { $$ = append(make([]NamedType, 0), $1) }
| AlternativeTypeList COMMA NamedType { $$ = append($1, $3) }
;
// 30.1
TaggedType : Tag Type { $$ = TaggedType{Tag: $1, Type: $2} }
| Tag IMPLICIT Type { $$ = TaggedType{Tag: $1, Type: $3, TagType: TAGS_IMPLICIT, HasTagType: true} }
| Tag EXPLICIT Type { $$ = TaggedType{Tag: $1, Type: $3, TagType: TAGS_EXPLICIT, HasTagType: true} }
;
Tag : OPEN_SQUARE Class ClassNumber CLOSE_SQUARE { $$ = Tag{Class: $2, ClassNumber: $3} }
;
ClassNumber : number { $$ = $1 }
| DefinedValue { $$ = $1 }
;
Class : UNIVERSAL { $$ = CLASS_UNIVERSAL }
| APPLICATION { $$ = CLASS_APPLICATION }
| PRIVATE { $$ = CLASS_PRIVATE }
| /*empty*/ { $$ = CLASS_CONTEXT_SPECIFIC }
;
// 25.1
SequenceOfType : SEQUENCE OF Type { $$ = SequenceOfType{$3} }
| SEQUENCE OF NamedType { $$ = SequenceOfType{$3} }
;
// 31.1
ObjectIdentifierType : OBJECT IDENTIFIER { $$ = ObjectIdentifierType{} }
;
// 31.3
ObjectIdentifierValue : OPEN_CURLY ObjIdComponentsList CLOSE_CURLY { $$ = $2 }
| OPEN_CURLY DefinedValue ObjIdComponentsList CLOSE_CURLY { $$ = append(ObjectIdentifierValue{ObjectIdElement{Reference: &$2}}, $3...) }
;
ObjIdComponentsList : ObjIdComponents { $$ = ObjectIdentifierValue{$1} }
| ObjIdComponents ObjIdComponentsList { $$ = append(ObjectIdentifierValue{$1}, $2...) }
;
ObjIdComponents : NameForm { $$ = ObjectIdElement{Name: $1} }
| NumberForm
| NameAndNumberForm
| DefinedValue { cpy := $1; $$ = ObjectIdElement{Reference: &cpy} }
;
NumberForm : NUMBER { $$ = ObjectIdElement{ID: $1.IntValue()} }
| DefinedValue { cpy := $1; $$ = ObjectIdElement{Reference: &cpy} }
;
NameAndNumberForm : identifier OPEN_ROUND NumberForm CLOSE_ROUND
{ $$ = ObjectIdElement{Name: $1, ID: $3.ID , Reference: $3.Reference} }
;
NameForm : identifier
;
// 36.1
CharacterStringType : RestrictedCharacterStringType
| UnrestrictedCharacterStringType
;
RestrictedCharacterStringType : BMPString { $$ = RestrictedStringType{LexType: BMPString} }
| GeneralString { $$ = RestrictedStringType{LexType: GeneralString} }
| GraphicString { $$ = RestrictedStringType{LexType: GraphicString} }
| IA5String { $$ = RestrictedStringType{LexType: IA5String} }
| ISO646String { $$ = RestrictedStringType{LexType: ISO646String} }
| NumericString { $$ = RestrictedStringType{LexType: NumericString} }
| PrintableString { $$ = RestrictedStringType{LexType: PrintableString} }
| TeletexString { $$ = RestrictedStringType{LexType: TeletexString} }
| T61String { $$ = RestrictedStringType{LexType: T61String} }
| UniversalString { $$ = RestrictedStringType{LexType: UniversalString} }
| UTF8String { $$ = RestrictedStringType{LexType: UTF8String} }
| VideotexString { $$ = RestrictedStringType{LexType: VideotexString} }
| VisibleString { $$ = RestrictedStringType{LexType: VisibleString} }
;
// 40.1
UnrestrictedCharacterStringType : CHARACTER STRING { $$ = CharacterStringType{} }
;
// 41.1
UsefulType : GeneralizedTime { $$ = TypeReference("GeneralizedTime") }
| UTCTime { $$ = TypeReference("UTCTime") }
;
// 45.1
ConstrainedType : Type Constraint { $$ = ConstraintedType{$1, $2} }
| TypeWithConstraint
;
// 45.5
TypeWithConstraint : SET Constraint OF Type { $$ = ConstraintedType{SetOfType{$4}, $2} }
| SET SizeConstraint OF Type { $$ = ConstraintedType{SetOfType{$4}, SingleElementConstraint($2)} }
| SEQUENCE Constraint OF Type { $$ = ConstraintedType{SequenceOfType{$4}, $2} }
| SEQUENCE SizeConstraint OF Type { $$ = ConstraintedType{SequenceOfType{$4}, SingleElementConstraint($2)} }
| SET Constraint OF NamedType { $$ = ConstraintedType{SetOfType{$4}, $2} }
| SET SizeConstraint OF NamedType { $$ = ConstraintedType{SetOfType{$4}, SingleElementConstraint($2)} }
| SEQUENCE Constraint OF NamedType { $$ = ConstraintedType{SequenceOfType{$4}, $2} }
| SEQUENCE SizeConstraint OF NamedType { $$ = ConstraintedType{SequenceOfType{$4}, SingleElementConstraint($2)} }
;
// 45.6
Constraint : OPEN_ROUND ConstraintSpec ExceptionSpec CLOSE_ROUND { $$ = Constraint{ConstraintSpec: $2} }
;
ConstraintSpec : SubtypeConstraint { $$ = $1 }
// | GeneralConstraint
;
SubtypeConstraint : ElementSetSpecs
;
// 46.1
ElementSetSpecs : RootElementSetSpec
| RootElementSetSpec COMMA ELLIPSIS { $$ = $1 }
| RootElementSetSpec COMMA ELLIPSIS COMMA AdditionalElementSetSpec { $$ = append($1, $5) }
;
RootElementSetSpec : ElementSetSpec { $$ = SubtypeConstraint{$1} }
;
AdditionalElementSetSpec : ElementSetSpec
;
ElementSetSpec : Unions { $$ = $1 }
| ALL Exclusions { $$ = $2 }
;
Unions : Intersections { $$ = Unions{$1} }
| UElems UnionMark Intersections { $$ = append($1, $3) }
;
UElems : Unions
;
Intersections : IntersectionElements { $$ = Intersections{$1} }
| IElems IntersectionMark IntersectionElements { $$ = append($1, $3) }
;
IElems : Intersections
;
IntersectionElements : Elements { $$ = IntersectionElements{Elements: $1} }
| Elems Exclusions { $$ = IntersectionElements{Elements: $1, Exclusions: $2} }
;
Elems : Elements
;
Exclusions : EXCEPT Elements { $$ = Exclusions{$2} }
;
UnionMark : PIPE | UNION
;
IntersectionMark : CARET | INTERSECTION
;
Elements : SubtypeElements { $$ = $1 }
// | ObjectSetElements
| OPEN_ROUND ElementSetSpec CLOSE_ROUND { $$ = $2 }
;
SubtypeElements : SingleValue
// | ContainedSubtype
| ValueRange
// | PermittedAlphabet
| SizeConstraint
| TypeConstraint
| InnerTypeConstraints
// | PatternConstraint
;
// 47.2
SingleValue : Value { $$ = SingleValue{$1} }
;
// 47.4
ValueRange : LowerEndpoint RANGE_SEPARATOR UpperEndpoint { $$ = ValueRange{$1, $3} }
;
LowerEndpoint : LowerEndValue { $$ = RangeEndpoint{Value: $1} }
| LowerEndValue LESS { $$ = RangeEndpoint{Value: $1, IsOpen: true} }
;
UpperEndpoint : UpperEndValue { $$ = RangeEndpoint{Value: $1} }
| LESS UpperEndValue { $$ = RangeEndpoint{Value: $2, IsOpen: true} }
;
LowerEndValue : Value
| MIN { $$ = nil }
;
UpperEndValue : Value
| MAX { $$ = nil }
;