-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSPEC.tyml
More file actions
771 lines (611 loc) · 31.3 KB
/
SPEC.tyml
File metadata and controls
771 lines (611 loc) · 31.3 KB
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
{!tyml 1.0}
{Specification !ns:<tyml.org/spec/0.9>
Title:<Tyml Specification 0.9 - Draft>
Content:![
{Section <Introduction> ![
Tyml is a text based and typed markup and data description language that is meant to
be an alternative to XML, JSON and YAML. Tyml is the abbreviation of Typed markup language.
Because Tyml is typed, every object must specify a global type for which it describes an instance.
Tyml documents can be validated and processed easily by using the associated type information.
This makes tools possible that can provide domain specific assistance like autocompletion or graphical
user interfaces for editing Tyml documents.
The concept of namespaces that is inspired by xml prevents type and attribute naming collisions,
so that each tyml object can be extended by custom attributes in a custom namespace without
neccessary influencing the processing of the document. Thus, each tyml document can be extended at will.
Tyml supports the description of objects, lists, strings and primitives.
Primitives are strings that have a user defined meaning like numbers or booleans.
Moreover, tyml supports embedding objects mixed with arbitrary text into a markup string.
This makes tyml suitable to describe complex configurations and extensive markup documents,
while still being appropriate to store and transmit simple data due to its compact notation.
{Section <Terminology> ![
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
"SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and
"OPTIONAL" in this document are to be interpreted as described in
{Link <https://www.ietf.org/rfc/rfc2119.txt> <RFC 2119>}.
]}
{Section <Goal of this Specification> ![
This specification defines the formal language of Tyml, the logical tree of well-formed Tyml documents and how programs can process Tyml documents.
]}
{Section <Tyml Programs> ![
Tyml addresses all programs that want to write or read any kind of structured data.
{Definition <Tyml Processor> ![
Any program that processes {Reference <Tyml Document+s>},
whether it is reading or writing, is called {Keyword <Tyml Processor>}.
]}
{Definition <Tyml Text Editor> ![
Any program that provides a textual editor for editing tyml documents by modifying characters, is called {Keyword <Tyml Text Editor>}.
]}
]}
]}
{Section <Logical Structure> ![
{Section <Notation> ![
In the following, the Expressive Grammar Language (EGL) 1.0 is used to describe {Reference <Productions>} that define various {Reference <Symbols>}.
The underlying {Reference <Alphabet>} consists of exactly all {Reference <Unicode Printable Characters>}.
If a String matches a given {Reference <Symbol>}, {Reference <Parse Trees>} are yielded as described by the EGL specification.
These {Reference <Parse Trees>} describe all possible logical structures of the String that matched the given {Reference <Symbol>}.
When this specification names a certain symbol, it often refers to the corresponding nodes of the parse trees.
The text of an optional child node is the text of the child node if it exists, otherwise it is the {Reference <Empty String>}.
{Null} refers to a special value that is different from every other value.
]}
{Section <Identifiers> ![
Identifiers have the following form:
{Productions <<
Identifier ::= IdentifierStartChar IdentifierContChar*
IdentifierStartChar ::= '_' | unicode:ID_Start
IdentifierContChar ::= '_' | '.' | '-' | unicode:ID_Continue
>>}
{Reference <unicode:ID_Start>} and {Reference <unicode:ID_Continue>} refer to the corresponding Unicode properties.
]}
{Section <Whitespaces and Comments> ![
Whitespace characters are described as following:
{Productions <<
SingleLineWSChar ::= #x09 | #x20
LineBreak ::= #x0D #x0A | #x0D | #x0A
WS ::= SingleLineWSChar | LineBreak
>>}
Comments have the following structure:
{Productions <<
Comment ::= '{-' Delimiter '-' AnyText '-' Delimiter '-}'
Delimiter ::= unicode:ID_Continue*
AnyText ::= .*
>>}
{Constraint <Syntactical Correctness> ![
The text of both {Reference <Delimiter>} children of a {Reference <Comment>} MUST match and is called the {Keyword <Delimiter>} of the {Reference <Comment>}.
The text of {Reference <AnyText>} children MUST NOT contain {Text <->} followed by the {Reference <Delimiter>} and then by {Text <-}>}.
]}
Trivias are a sequence of whitespaces or comments:
{Productions <<
Trivias ::= (WS | Comment)+
>>}
{--
{-todo-
If a {Reference <Tyml Processor>} stores {Reference <Trivias>},
they should be stor
{Reference <LdTrv>} nodes SHOULD be assigned to the terminal character or node that follows the trivia.
{Reference <TrlTrv>} nodes SHOULD be assigned to the terminal character or node that precedes the trivia.
{Example <Trivias> ![
{TymlCode <<
Element1 {-- Comment1 - -}
{-- Comment2 - -}
{-txt-Comment3- -}-txt-}
Element2
>>}
The trailing trivia {Reference <Comment1>} as well as its surrounding whitespace and the line break belong to {Reference <Element1>},
The leading trivia {Reference <Comment2>}, {Reference <Comment3>} and its surrounding whitespace including both line breaks
belong to {Reference <Element2>}.
The Delimiter of {Reference <Comment3>} is {Text <txt>}, the text of its {Reference <AnyText>} child is {Text <Comment3- -}>}.
]}
-todo-} --}
]}
{Section <Namespace System> ![
Namespaces are used to avoid naming collisions.
Since namespaces can become quite long, prefixes are used to shorten them:
{Productions <<
Namespace ::= (Identifier '/')* Identifier
Prefix ::= Identifier?
>>}
Such namespace prefixes can be defined by {Reference <PrefixDef+s>} nodes in the following way:
{Productions <<
PrefixDef ::= '!ns' '/' Prefix ':' Trivias? '<' Namespace '>'
>>}
{Property <PrefixDef> <Prefix> ![
The prefix defined by a {Reference <PrefixDef>} is the text of the {Reference <Prefix>} child.
]}
{Property <PrefixDef> <Namespace> ![
The namespace specified by a {Reference <PrefixDef>} is the text of its {Reference <Namespace>} child.
]}
Namespaces SHOULD start with a domain name owned by the author to prevent naming collisions.
Each node of a {Reference <Parse Tree>} resolves a prefix to either a namespace or to {Null}.
If not defined otherwise, a node resolves a prefix to {Null} if it does not have a parent.
If it has a parent, the prefix is resolved to the value the parent resolves the prefix to.
However, if the node has a {Reference <PrefixDef>} child that defines the prefix,
the prefix is resolved to the namespace the {Reference <PrefixDef>} child specifies.
{Constraint <Well-formedness> ![
When removing a {Reference <PrefixDef>} node from its {Reference <Parse Tree>},
its former parent must resolve the prefix defined by the {Reference <PrefixDef>} to {Null}.
]}
Prefixes are used for type names:
{Productions <<
LocalTypeName ::= Identifier
TypeName ::= (Prefix '/')? LocalTypeName
QualifiedTypeName ::= Namespace '#' LocalTypeName
>>}
A {Reference <TypeName>} consists of a prefix that is the text of the optional {Reference <Prefix>} child
and a local type name that is the text of the {Reference <LocalTypeName>} child.
{Constraint <Well-formedness> ![
A {Reference <TypeName>} MUST NOT resolve its prefix to {Null}.
]}
{Property <TypeName> <Qualified Type Name> ![
A {Reference <TypeName>} node resolves to a {Reference <QualifiedTypeName>}.
It consists of the namespace to which the node resolves the prefix and of the local type name.
]}
{Example <Type Name resolution> ![
{TymlCode <<
{t/MyTypeName !ns/t:<tyml.org/example>}
{MyTypeName !ns/:<tyml.org/example>}
>>}
Both type names resolve to the qualified type name {Text <tyml.org/example#MyTypeName>}.
]}
]}
{Section <Tyml Documents> ![
{Definition <Tyml Document> ![
A {Reference <String>} is called a {Keyword <Tyml Document>}
iff it matches the production {Reference <RecognizedAsTymlDocument>}.
]}
{Productions <<
RecognizedAsTymlDocument ::= '{!tyml' AnyText
>>}
{Definition <Syntactically Correct> ![
A {Reference <Tyml Document>} is called {Keyword <Syntactically Correct>}
iff it matches the production {Reference <Document>} and
there is at least one Parse Tree that fulfills all {Reference <Syntactical Correctness>}
constraints given in this specification.
]}
{Definition <Logical Tree> ![
The syntactical correctness constraints ensure that
{Reference <Syntactically Correct>} {Reference <Tyml Document+s>} have exactly one Parse Tree.
This tree is called the {Keyword <Logical Tree>} of the {Reference <Tyml Document>}.
]}
{Definition <Well-formed> ![
A {Reference <Syntactically Correct>} {Reference <Tyml Document>} is called {Keyword <Well-formed>} iff its
{Reference <Logical Tree>} fulfills all {Reference <Well-formedness>} constraints given in this specification.
]}
{Productions <<
Document ::= Header (Trivias? Object)* Trivias?
>>}
The document header is used for recognizing a tyml document including its version and for specifying global namespace prefixes.
Document nodes use the Header child for resolving prefixes.
The header is defined as follows:
{Productions <<
Header ::= '{!tyml 0.9' (Trivias PrefixDef)*
(Trivias AliasDef)*
(Trivias HeaderAttr)* Trivias? '}'
>>}
Later versions of Tyml will not change the {Reference <RecognizedAsTymlDocument>} production but will increase the header's version number.
For future Tyml 1.0 documents however, the version will be optional and a non-digit char will follow instead.
Alias definitions can be used to shorten object types. They are defined as follows:
{Productions <<
AliasDef ::= '!alias/' AliasIndicator AliasName ':' Trivias? '<' TypeName '>'
AliasIndicator ::= '#'
AliasName ::= Identifier
>>}
An {Reference <AliasDef>} defines an alias name and assigns it the qualified type name of its {Reference <TypeName>} child.
{Constraint <Well-formedness> ![
Different {Reference <AliasDef+s>} MUST define different alias names.
]}
Header attributes are defined as following:
{Productions <<
HeaderAttr ::= HeaderAttrName ':' Trivias? AttributeValue
HeaderAttrName ::= Identifier
AttributeValue ::= Expression
>>}
Valid header attributes are defined in type system section.
{-- Maybe !type-alias suits better? --}
{Example <Well-formed Tyml Document> ![
{TymlCode <<
{!tyml 0.9 !ns/:<tyml.org/example>
!alias/#Root:<ApplicationRoot>
}
{#Root}
>>}
]}
]}
{Section <Expressions> ![
{Reference <Expressions>} can either be literals or containers for other {Reference <Expressions>}:
{Productions <<
Expression ::= Literal | Container
Literal ::= Primitive | String
Container ::= Object | Array
>>}
{Property <Literal> <Value> ![Literals represent an unicode string called {Keyword <Value>}.]}
{Section <Primitives> ![
Primitives represent atomic values like booleans or numbers:
{Productions <<
Primitive ::= PrimitiveChar+
PrimitiveChar ::= IdentifierContChar | [+*=|~!?,;/\"'()^&@%$#]
>>}
{Property <Primitive> <Value> ![The {Reference <Value>} of a {Reference <Primitive>} is its Text.]}
]}
{Section <Strings> ![
There are two different possibilities to represent strings:
{Productions <<
String ::= OrdinaryString | HeredocString
>>}
{Section <Ordinary Strings> ![
The following productions describe ordinary strings:
{Productions <<
OrdinaryString ::= '<' (OrdinaryStringChar | EscapeSequence)* '>'
OrdinaryStringChar ::= . \ ('\' | '<' | '>' | LineBreak)
>>}
{Property <OrdinaryString> <Value> ![
The {Reference <Value>} of an ordinary string is the concatenation of the
{Reference <Value+s>} from all its children.
]}
The {Reference <Value>} of an ordinary string char is its text.
Escape sequences are constructed as following:
{Productions <<
EscapeSequence ::= '\' (EscapedCR | EscapedLF | EscapedTab | EscapedSpecialChar | CodePointRef | IgnoredWS)
EscapedCR ::= 'r'
EscapedLF ::= 'n'
EscapedTab ::= 't'
EscapedSpecialChar ::= [\<>{}] | '[' | ']'
CodePointRef ::= 'u' Hex Hex Hex Hex
Hex ::= [0-9A-F]
IgnoredWS ::= LineBreak SingleLineWSChar*
>>}
The {Reference <Value+s>} of the escape sequences {Reference <EscapedCR>}, {Reference <EscapedLF>} and {Reference <EscapedTab>}
are the unicode characters {Text <#x0D>}, {Text <#x0A>} and {Text <#x09>}.
The {Reference <Value>} of an {Reference <EscapedSpecialChar>} is its text.
The {Reference <Value>} of a {Reference <CodePointRef>} is the unicode character with the given hexadecimal codepoint.
The {Reference <Value>} of an {Reference <IgnoredWS>} node is the empty string.
The {Reference <IgnoredWS>} escape sequence can be used to insert line breaks and indentations into strings without changing its {Reference <Value>}.
{Example <Ordinary Strings> ![
{TymlCode <<
<ordinary string\nthat cannot contain \
unescaped line breaks>
>>}
Its {Reference <Value>} is the following:
{TymlCode <<
ordinary string
that cannot contain unescaped line breaks
>>}
]}
]}
{Section <Heredoc Strings> ![
The following production describes heredoc strings:
{Productions <<
HeredocString ::= '<' Delimiter '<' (AnyText | '\' Delimiter EscapeSequence)* '>' Delimiter '>'
>>}
{Constraint <Syntactical Correctness> ![
The text of all {Reference <Delimiter>} children of a {Reference <HeredocString>} MUST match and
is called the {Keyword <Delimiter>} of the {Reference <HeredocString>}.
{Reference <AnyText>} children MUST NOT contain {Text <\>>} followed by {Reference <Delimiter>} and then {Text <\>>} or
{Text <\\>} followed by {Reference <Delimiter>} and then {Text <\\>}.
]}
{Property <HeredocString> <Value> ![
The {Reference <Value>} of an {Reference <HeredocString>} is the concatenation of the {Reference <Value+s>} from all children.
]}
The {Reference <Value>} of an {Reference <AnyText>} node is its text.
{Example <Heredoc Strings> ![
{TymlCode <<
<txt<heredoc string
that can contain <, >, \txt\
txt or even <txt<.>txt>
>>}
Its {Reference <Value>} is the following:
{TymlCode <<
heredoc string
that can contain <, >, txt or even <txt<.
>>}
]}
]}
]}
{Section <Objects> ![
Objects can compose other elements by using attributes. They have the following structure:
{Productions <<
Object ::= '{' ObjType (Trivias PrefixDef)* (Trivias Attribute)* Trivias? '}'
ObjType ::= (CastIndicator? (TypeName | AliasIndicator AliasName)) | InferenceIndicator
CastIndicator ::= '='
InferenceIndicator ::= '~'
>>}
{Constraint <Well-formedness> ![
An {Reference <AliasName>} child of an {Reference <ObjType>} must be defined by
a corresponding {Reference <AliasDef>} element.
]}
{Definition <Cast Object> ![
The parent {Reference <Object>} of a {Reference <CastIndicator>} node is called {Keyword <Cast Object>}.
]}
{Definition <Inference Object> ![
The parent {Reference <Object>} of a {Reference <InferenceIndicator>} node
is called {Keyword <Inference Object>}.
]}
{Property <Object> <Qualified Type Name> ![
Each {Reference <Object>} that is not an {Reference <Inference Object>} has a qualified type name.
If the {Reference <ObjType>} child has a {Reference <TypeName>} child, its qualified type name is used.
Otherwise, if the {Reference <ObjType>} has an {Reference <AliasName>} child,
the qualified type name is used that is assigned to the alias name
by the corresponding {Reference <AliasDef>} element.
]}
{Example <Cast Object, Qualified Type Name> ![
{TymlCode <<
{!tyml 0.9 !ns/t:<tyml.org/example>
!alias/#MyAliasName:<t/MyTypeName>
}
{=#MyAliasName <Value for implicit attribute>}
>>}
The root object of this document is a {Reference <Cast Object>} and
its qualified type name is {Text <tyml.org/example#MyTypeName>}.
]}
Attributes are defined as follows:
{Productions <<
Attribute ::= ImplicitAttribute | ExplicitAttribute
ImplicitAttribute ::= AttributeValue
TypeAttributeIndicator ::= "'"
ExplicitAttribute ::= TypeAttributeIndicator? AttributeName ':' Trivias? AttributeValue
>>}
An {Reference <AttributeName>} is defined similar to {Reference <TypeName>}, however its prefix can be empty:
{Productions <<
LocalAttrName ::= Identifier
AttributeName ::= (Prefix '/')? LocalAttrName
QualifiedAttrName ::= (Namespace | QualifiedTypeName) ':' LocalAttrName
>>}
An {Reference <AttributeName>} consists of a prefix and a local attribute name:
The prefix is the text of the {Reference <Prefix>} child if it has one, otherwise it is {Null}.
The local attribute name is the text of the {Reference <LocalAttrName>} child.
{Constraint <Well-formedness> ![
An {Reference <AttributeName>} MUST NOT resolve its prefix to {Null} unless the prefix is {Null} itself.
]}
{Property <AttributeName> <Qualified Attribute Name> ![
An {Reference <AttributeName>} resolves to
a {Reference <QualifiedAttrName>} with a matching local attribute name.
]}
{Definition <Ordinary Attribute> ![
If the prefix of an {Reference <AttributeName>} is {Null},
its parent {Reference <ExplicitAttribute>} is called {Keyword <Ordinary Attribute>}.
In this case, the qualified type name of the parent {Reference <Object>}
is used as {Reference <QualifiedTypeName>} child for the qualified attribute name.
]}
{Definition <Attached Attribute> ![
Otherwise, if the prefix is not {Null},
its parent {Reference <ExplicitAttribute>} is called {Keyword <Attached Attribute>}.
In that case, the namespace the prefix is resolved to is used as
{Reference <Namespace>} child for the qualified attribute name.
]}
{Example <Attributes> ![
{TymlCode <<
{!tyml 0.9 !ns/:<tyml.org/example1> !ns/t:<tyml.org/example2>}
{Root1 Attr1:0 /Attr2:0 t/Attr3:0}
{t/Root2 Attr4:0 /Attr5:0 t/Attr6:0}
>>}
These attributes resolve to:
{TymlCode <<
tyml.org/example1#Root1:Attr1,
tyml.org/example1:Attr2,
tyml.org/example2:Attr3,
tyml.org/example2#Root2:Attr4,
tyml.org/example1:Attr5,
tyml.org/example2:Attr6,
>>}
]}
]}
{Section <Arrays> ![
There are two different types of arrays: {Reference <OrdinaryArray+s>} and {Reference <MarkupArray+s>}:
{Productions <<
Array ::= OrdinaryArray | MarkupArray
>>}
Ordinary arrays are specified as follows:
{Productions <<
OrdinaryArray ::= '[' Expression? (Trivias Expression)* Trivias? ']'
>>}
The following production rules describe markup arrays:
{Productions <<
MarkupArray ::= '![' Comment? (MarkupElement Comment?)* ']'
MarkupElement ::= String | Object | OrdinaryArray | MarkupString
MarkupStringChar ::= Char \ ([\<>{}] | '[' | ']')
MarkupString ::= (MarkupStringChar | EscapeSequence)*
>>}
Hence, all whitespace characters within markup arrays are interpreted as markup strings.
{Example <Array vs. Markup Array> ![
{TymlCode <<
![ This is an {Bold <Markup Array>}! ]
>>}
This represents the {Reference <MarkupString>} and {Reference <Object>}
items {Text < This is an >}, {Text <{Bold ...}>} and {Text <! >}.
All whitespaces are treated as markup strings.
{TymlCode <<
[ This is an {Bold <Array>}! ]
>>}
In contrast to the markup array, this represents the {Reference <Primitive>} and {Reference <Object>}
items {Text <This>}, {Text <is>}, {Text <an>}, {Text <{Bold ...}>} and {Text <!>}. All separating whitespaces are treated as trivias.
]}
]}
]}
]}
{Section <Type System> ![
{Section <Assignability> ![
The set {Reference <BaseTypeDefinitions>} represents unique types that cannot be assigned to each other unless explicitly stated.
{Reference <AliasTypeDefinitions>} represents types that stand for other types. These sets MUST be disjunct:
{LatexBlock <txt<
BaseTypeDefinitions \cap AliasTypeDefinitions = \emptyset
>txt>}
Together they form the set of all type definitions. Each type definition specfies an arity that defines how many type arguments it accepts:
{LatexBlock <txt<
& TypeDefinitions &&:=&& BaseTypeDefinitions \cup AliasTypeDefinitions \\
& arity&&: && TypeDefinitions \to \mathbb{N}_0
>txt>}
The term algebra {Reference <Types>} represents all types that can be build using the given type definitions.
A natural number {Latex <n>} represents a type variable.
Both union ({Latex <\\cup>}) and instantiation ({Latex <[...]>}) operations are interpreted as algebraic data type constructors.
{Reference <Types>} is the smallest set that contains all natural numbers and that is closed under type union and instantiation of type definitions:
{LatexBlock <txt<
\mathbb{N} &&\subset & \quad Types \\
t_1, t_2 \in Types &&\Rightarrow & \quad t_1 \cup t_2 \in Types \\
t \in BaseTypeDefinitions, t_1, ..., t_n \in Types &&\Rightarrow &\quad t[t_1, ..., t_n] \in Types \quad \text{if}\: n = arity(t)
>txt>}
{Reference <BaseTypes>} are types which specify type arguments for {Reference <BaseTypeDefinitions>}.
{Reference <ClosedTypes>} are types without any type variables.
{LatexBlock <txt<
BaseTypes &&:=\quad& \{ t[t_1, ..., t_n] \; | \; t \in BaseTypeDefinitions, t_1, ..., t_n \in Types, n = arity(t) \} \\
ClosedTypes &&:=\quad& \{ t \in Types \; | \; t \; \text{does#not#contain#any#number} \} \\
ClosedBaseTypes &&:=\quad& BaseTypes \cap ClosedTypes
>txt>}
In the following, {Latex <<\operatorname{ Fin}(S)>>} denotes the set of all finite subsets from a set {Latex <S>}.
The map {Reference <directlyAssignableTo>} specifies a finite set of base types that instances of a given base type definition can be assigned to.
The map {Reference <aliasType>} specifies the type a given alias type definition refers to:
{LatexBlock <txt<
directlyAssignableTo&&:& \quad BaseTypeDefinitions \to \operatorname{ Fin}( BaseTypes) \\
aliasType&&:& \quad AliasTypeDefinitions \to Types
>txt>}
The return values of both maps MUST NOT contain numbers that are greater than the arity of their arguments.
The graph induced by {Reference <directlyAssignableTo>} MUST NOT contain cycles.
Type arguments are not considered and do not yield edges.
Insert replaces all occurrences of the number {Latex <i>} in its argument with the type {Latex <t_i>}:
{LatexBlock <txt<
insert_{t_1, ..., t_n}: Types \to Types
>txt>}
{Reference <normalize>} resolves aliases and factors out union types:
{LatexBlock <txt<
normalize: ClosedTypes &&\to& \quad \operatorname{ Fin}( ClosedBaseTypes) \\
t_1 \cup t_2 &&\mapsto& \quad normalize(t_1) \cup normalize(t_2) \\
t[t_1, ..., t_n] &&\mapsto& \quad normalize( insert_{t_1, ..., t_n}( aliased(t))) \quad \text{if}\;t \in AliasTypeDefinitions \\
t &&\mapsto& \quad \{ t \} \quad \text{if}\: t \in BaseTypes
>txt>}
{-- A type {Latex <t>} is called a {Keyword <Union Type>} iff {Latex <|normalize(t)| \\geq 2>}. --}
{Reference <directlyAssignableTo>} can be continued on {Reference <<ClosedBaseTypes>>}:
{LatexBlock <txt<
directlyAssignableTo: \quad ClosedBaseTypes &&\to& \quad\operatorname{ Fin}( ClosedBaseTypes) \\
t[t_1, ..., t_n] &&\mapsto& \quad \{ insert_{t_1, ..., t_n}(t') \; | \; t' \in directlyAssignableTo(t) \}
>txt>}
This makes it possible to continue {Reference <assignableTo>} as relation {Latex <<\preceq>>}
for {Reference <ClosedTypes>} {Latex <a>} and {Latex <b>} (read "{Latex <a>} is assignable to {Latex <b>}"):
{LatexBlock <txt<
a \preceq b \quad \Leftrightarrow \quad &\forall a'[a_1, ..., a_n] \in normalize(a): \exists b'[b_1, ..., b_n] \in normalize(b):\\
&(a' = b' \:\land\: \forall i \in \{1, ..., n\}: a_i \preceq b_i \:\land\: b_i \preceq a_i) \\
\lor \: &\exists t \in directlyAssignableTo(a'[a_1, ..., a_n]): t \preceq b[b_1, ..., b_n]
>txt>}
]}
{Section <Types in Tyml> ![
{Definition <Root Types> ![
The set {Reference <BaseTypeDefinitions>} contains at least the root types
{Keyword <Any>}, {Keyword <Primitive>}, {Keyword <String>} and {Keyword <Object>}
with an arity of zero and {Keyword <Array>} with an arity of one.
All these types are directly assignable only to the root type {Reference <Any>} and
{Reference <Any>} is not directly assignable to any type.
]}
User defined type definitions expand the {Reference <TypeDefinitions>} set.
Each user defined type definition can be adressed by an unique name that matches the {Reference <QualifiedTypeName>} production.
Except alias type definitions, user defined type definitions are members of the set {Reference <BaseTypeDefinitions>} and can extend other {Reference <BaseTypes>}.
Such type definitions are at least directly assignable to the type they extend.
User defined type definitions belong to exactly one of the following categories:
{List [
![
{Keyword <Primitive Type Definitions>}
Extend either a primitive type or the root type {Reference <Primitive>}. Have an arity of zero.
]
![
{Keyword <String Types Definitions>}
Extend either a string type or the root type {Reference <String>}. Have an arity of zero.
]
![
{Keyword <Object Types Definitions>}
Extend either an object type or the root type {Reference <Object>}. Their arity is user defined.
Object types specify a list of interface types they implement.
They are directly assignable to the type they extend and to all interfaces they implement.
]
![
{Keyword <Interface Types Definitions>}
Specify a list of closed interface types they extend. Their arity is user defined.
They are directly assignable to {Reference <Object>} and all interfaces they extend.
]
![
{Keyword <Array Types Definitions>}
Extends an other array type or the root type {Reference <Array>}. Has an arity of one.
]
![
{Keyword <Alias Types>}
Defines an alias for a type. Its arity is user defined.
]
]}
{-- TODO: constraints --}
]}
{Section <Object Types> ![
Object types define a list of own attributes.
Attributes have the following properties:
{List [
![
{Keyword <Name>}.
The attribute's name.
Its values must match the {Reference <Identifier>} production.
]
![
{Keyword <Type>}.
The attribute's type. Its values are members of {Reference <Types>}.
Must not contain numbers that are greater than the object type's arity.
]
![
{Keyword <CanBeImplicit>}. Is either {Text <true>} or {Text <false>} and specfies whether the name of the attribute can be omitted.
]
![
{Keyword <IsOptional>}. Is either {Text <true>} or {Text <false>} and specfies whether the attribute is optional.
]
]}
{Property <Object Type> <Attribute Liste> ![
The attribute list of a given object type
is defined as the concatenation of the extended type's attribute list with the list of own attributes.
]}
Elements of the attribute list MUST have different names.
{Property <Object Type> <nth Implicit Attribute> ![
The {Latex <n>}th implicit attribute of an object type refers to the
{Latex <n>}th element of the attribute list whose {Reference <CanBeImplicit>} property is set to {Text <true>}.
]}
All these definitions apply to closed object types likewise.
However, numbers within the type property of attributes are replaced by the corresponding type argument.
]}
{Section <Defining User Defined Types> ![
User defined types are described by {Text <tyml.org/typedef/0.9#DefinitionPackage>} objects.
]}
{Section <Type Inference> ![
The type of an expression depends on the expression kind, its value and its expected type:
{LatexBlock <<
inferType_{ expected \in Types}: Expressions \to Types \cup \{ null \}
>>}
Let {Latex <<\{ e_1, e_2, ..., e_n \}>>} be the result of {Latex < normalize( expected)>}.
{List [
![
If the expression is a {Reference <Primitive>} (or a {Reference <String>}):
If there is exactly one {Latex <e_i>} that is assignable to the root type {Reference <Primitive>} (or {Reference <String>})
whose constraints are met by the value of the expression, the inferred type is {Latex <e_i>}.
If there is no such an {Latex <e_i>} at all, but an {Latex <e_j>} that equals the root type {Reference <Any>},
the inferred type is the closed root type {Reference <Primitive>} (or {Reference <String>}).
Otherwise, the inferred type is {Null}.
]
![
If the expression is an {Reference <Array>}:
If there is exactly one {Latex <e_i>} that is assignable to the root type {Reference <Array>}, the inferred type is {Latex <e_i>}.
If there is no such an {Latex <e_i>} at all, but an {Latex <e_j>} that equals the root type {Reference <Any>},
the inferred type is the root type {Reference <Array>} instantiated with the root type {Reference <Any>}. Otherwise, the inferred type is {Null}.
]
![
If the expression is an {Reference <Object>}:
If the object is an {Reference <Inference Object>}:
If there is exactly one {Latex <e_i>} that is an user defined object type, the inferred type is {Latex <e_i>}.
Otherwise, the inferred type is {Null}.
If the object is not an {Reference <Inference Object>}:
The qualified type name of the {Reference <Object>} must point to a user defined type.
If the object has an attached attribute with the qualified attribute name {Text <<tyml.org/types:TypeArgs>>},
the types blablablab.
Otherwise, the type arguments are inferred from the expected type.
]
]}
{Constraint <Validness> ![
If an {Reference <Object>} is not a {Reference <Cast Object>}, its estimated type MUST be an object type.
]}
]}
{Section <Validation> ![
The expected type of the root object is the root type {Reference <Any>}.
]}
{Section <Defining Types> ![
]}
]}
]
}