@@ -7,12 +7,12 @@ defining CDDL in Huddle.
7
7
8
8
## Core Types
9
9
Huddle utilizes several core types to represent CDDL constructs:
10
- ● Huddle: The top-level type representing a collection of rules.
11
- ● HuddleItem: Represents individual items within a Huddle, such as rules, groups, or generic rules.
12
- ● Rule: A named type definition.
13
- ● Named: A type wrapper for associating a name, value, and optional description with an item.
14
- ● Value: A type representing primitive CBOR values.
15
- ● Group: Represents a collection of entries within a map or array.
10
+ - Huddle: The top-level type representing a collection of rules.
11
+ - HuddleItem: Represents individual items within a Huddle, such as rules, groups, or generic rules.
12
+ - Rule: A named type definition.
13
+ - Named: A type wrapper for associating a name, value, and optional description with an item.
14
+ - Value: A type representing primitive CBOR values.
15
+ - Group: Represents a collection of entries within a map or array.
16
16
17
17
## Language Extensions
18
18
@@ -39,16 +39,18 @@ In addition, if using hlint, we suggest disabling the following hints:
39
39
Rules are defined using the =:= operator. The left-hand side of the operator is
40
40
the rule name (a T.Text value), and the right-hand side is the type definition.
41
41
42
- ruleName =:= typeDefinition
42
+ ` ruleName =:= typeDefinition `
43
43
44
44
### Example:
45
- ` age =:= VUInt `
45
+ ``` haskell
46
+ age =:= VUInt
47
+ ```
46
48
47
49
## Maps
48
50
Maps are defined using the mp function and the ==> operator to specify key-value
49
51
pairs.
50
52
51
- mapName =:= mp [ key1 ==> value1, key2 ==> value2 ]
53
+ ` mapName =:= mp [ key1 ==> value1, key2 ==> value2 ] `
52
54
53
55
### Example:
54
56
``` haskell
@@ -61,26 +63,35 @@ location =:= mp [
61
63
## Arrays
62
64
Arrays are defined using the arr function and the a function to indicate array elements.
63
65
64
- arrayName =:= arr [ a element1, a element2 ]
66
+ ` arrayName =:= arr [ a element1, a element2 ] `
65
67
66
68
### Example:
69
+ ``` haskell
67
70
point =:= arr [ a int, a int ]
71
+ ```
72
+
68
73
## Groups
69
74
Groups are collections of entries within maps or arrays. They can be named using
70
75
the =:~ operator.
71
76
72
- groupName =:~ grp [ entry1, entry2 ]
77
+ ` groupName =:~ grp [ entry1, entry2 ] `
78
+
73
79
### Example:
74
80
``` haskell
75
81
personalinfo =:~ grp [
76
82
" name" ==> tstr,
77
83
" age" ==> uint
78
84
]
79
85
```
86
+
80
87
## Choices
88
+
81
89
Huddle represents choices between types using the / operator.
90
+
82
91
### Example:
92
+ ``` haskell
83
93
value =:= int / tstr
94
+ ```
84
95
85
96
Huddle does not have a direct equivalent for the CDDL // operator (group
86
97
choice). Instead, choices within arrays are represented by creating separate
@@ -96,9 +107,9 @@ choice =:= optionA / optionB
96
107
## Quantifiers
97
108
Huddle provides functions to specify occurrence quantifiers for group entries
98
109
and array elements:
99
- ● <+ : Lower bound
100
- ● +> : Upper bound
101
- ● opt: Optional (0 or 1 occurrences)
110
+ - ` <+ ` : Lower bound
111
+ - ` +> ` : Upper bound
112
+ - ` opt ` : Optional (0 or 1 occurrences)
102
113
103
114
### Example:
104
115
``` haskell
@@ -112,7 +123,7 @@ which will be included as comments in the generated CDDL.
112
123
### Example:
113
124
``` haskell
114
125
person =:= comment " Represents a person" $ mp [
115
- comment " Person's name" $ " name " ==> VBytes ,
126
+ " name" ==> VBytes & comment " Person's name " ,
116
127
" age" ==> VUIntf
117
128
]
118
129
```
@@ -129,11 +140,11 @@ message = binding $ \t -> "message" =:= {
129
140
```
130
141
131
142
## Converting to CDDL
132
- The toCDDL and toCDDLNoRoot functions convert a Huddle definition to CDDL.
133
- toCDDL generates a top-level root element, while toCDDLNoRoot skips the root
143
+ The ` toCDDL ` and ` toCDDLNoRoot ` functions convert a Huddle definition to CDDL.
144
+ ` toCDDL ` generates a top-level root element, while ` toCDDLNoRoot ` skips the root
134
145
element.
135
146
136
147
## Example File (Conway.hs)
137
- The Conway.hs example file showcases a practical application of Huddle to define
138
- the CDDL for a specific data structure. The file defines numerous rules and
139
- groups using the Huddle syntax and functions described above.
148
+ The ` Conway.hs ` example file showcases a practical application of Huddle to
149
+ define the CDDL for a specific data structure. The file defines numerous rules
150
+ and groups using the Huddle syntax and functions described above.
0 commit comments