Skip to content

Commit 72086d2

Browse files
author
jared
committed
Documentation improvements to docs/syntax.md
- Fixed strange whitespace (added whitespace after headers / put paragraphs in a single line) - Changed `long` to `modulealias` - General wording improvements + fixed error in `opaque` type defn.
1 parent 7f685c0 commit 72086d2

File tree

2 files changed

+37
-38
lines changed

2 files changed

+37
-38
lines changed

docs/SUMMARY.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
- [LambdaBuffers to Purescript](purescript.md)
77
- [Design](design.md)
88
- [API](api.md)
9-
- [LambdaBuffers file](syntax.md)
9+
- [LambdaBuffers Frontend (.lbf) syntax](syntax.md)
1010
- [Compiler](compiler.md)
1111
- [Codegen](codegen.md)
1212
- [Command line interface](command-line-interface.md)

docs/syntax.md

+36-37
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
# LambdaBuffers file
1+
# LambdaBuffers Frontend (.lbf) syntax
22

3-
The input to LambdaBuffers is a text file which contains a module that defines
4-
a specification of the types you want to generate.
5-
This section gives the exact syntax of a LambdaBuffers file, and informally describes meaning of the syntactic constructs.
3+
The input to the LambdaBuffers Frontend is a text file which contains a module that defines a specification of the types and type class instances you want to generate. This chapter gives the exact syntax of a LambdaBuffers Frontend file, and informally describes meaning of the syntactic constructs.
64

7-
The name of a LambdaBuffers file must end with `.lbf`.
5+
The name of a LambdaBuffers Frontend file must end with `.lbf`, and hence may also be referred to as a .lbf file or a .lbf schema.
86

97
## Notation
10-
In the following description of a LambdaBuffers file's syntax, we use
11-
a similar BNF syntax from [Section 10.1 of the Haskell Report](https://www.haskell.org/onlinereport/haskell2010/).
12-
So, the following notational conventions are used for presenting syntax.
8+
9+
In the following description of a LambdaBuffers Frontend file's syntax, we use a similar BNF syntax from [Section 10.1 of the Haskell Report](https://www.haskell.org/onlinereport/haskell2010/). So, the following notational conventions are used for presenting syntax.
1310

1411
| Syntax | Description |
1512
| ------------- | --------------------------------------------------------------------------- |
@@ -26,20 +23,20 @@ So, the following notational conventions are used for presenting syntax.
2623
| `pat1|pat2` | choice |
2724
-->
2825

29-
Note that the terminal syntax permits C-style escape sequences e.g.
30-
`'\n'` denotes line feed (newline), and `'\r'` denotes carriage return.
26+
Note that the terminal syntax permits C-style escape sequences e.g. `'\n'` denotes line feed (newline), and `'\r'` denotes carriage return.
3127

32-
Productions will be of the form
28+
Productions will be of the form:
3329

3430
```text
3531
nonterm -> alt1 | ... | altn
3632
```
3733

3834
## Input file representation
39-
The input file is Unicode text where the encoding is subject to the system locale.
40-
We will often use the unqualified term *character* to refer to a Unicode code point in the input file.
35+
36+
The input file is Unicode text where the encoding is subject to the system locale. We will often use the unqualified term *character* to refer to a Unicode code point in the input file.
4137

4238
## Characters
39+
4340
The following terms are used to denote specific Unicode character categories:
4441

4542
- `upper` denotes a Unicode code point categorized as an uppercase letter or titlecase letter (i.e., with General Category value Lt or Lu).
@@ -54,56 +51,54 @@ Interested readers may find details of Unicode character categories in [Section
5451

5552
## Lexical syntax
5653

57-
Tokens form the vocabulary of LambdaBuffers files.
58-
The classes of tokens are defined as follows.
54+
Tokens form the vocabulary of LambdaBuffers Frontend files. The classes of tokens are defined as follows.
5955

6056
```text
6157
keyword -> 'module' | 'sum' | 'prod' | 'record'
6258
| 'opaque' | 'class' | 'instance' | 'import'
6359
| 'qualified' | 'as'
6460
modulename -> uppercamelcase
65-
longmodulename -> long modulename
61+
longmodulename -> modulealias modulename
6662
typename -> uppercamelcase
6763
fieldname -> lowercamelcase\keyword
68-
longtypename -> long typename
64+
longtypename -> modulealias typename
6965
varname -> lowers\keyword
7066
punctuation -> '<=' | ',' | '(' | ')' | '{' | '}'
7167
| ':' | ':-' | '=' | '|'
7268
classname -> uppercamelcase
73-
longclassname -> long uppercamelcase
69+
longclassname -> modulealias uppercamelcase
7470
```
7571

7672
where
7773

7874
```text
7975
uppercamelcase -> upper { alphanum }
8076
lowercamelcase -> lower { alphanum }
81-
long -> { uppercamelcase '.' }
77+
modulealias -> { uppercamelcase '.' }
8278
lowers -> lower { lower }
8379
```
8480

85-
Input files are broken into *tokens* which use the *maximal munch* rule i.e.,
86-
at each point, the next token is the longest sequence of characters that
87-
form a valid token.
88-
`space`s or line comments are ignored except as it separates tokens that
89-
would otherwise combine into a single token.
81+
Input files are broken into *tokens* which use the *maximal munch* rule i.e., at each point, the next token is the longest sequence of characters that form a valid token. `space`s or line comments are ignored except as it separates tokens that would otherwise combine into a single token.
9082

9183
### Line comments
84+
9285
A *line comment* starts with the terminal `'--'` followed by zero or more printable Unicode characters stopping at the first end of line (`'\n'` or `'\r\n'`).
9386

94-
## Syntax of LambdaBuffers files
95-
A LambdaBuffers file defines a module that is a collection of data types, classes, instance clauses, and derive clauses.
87+
## Syntax of LambdaBuffers Frontend files
9688

97-
The overall layout of a LambdaBuffers file is:
89+
A LambdaBuffers Frontend file defines a module that is a collection of data types, classes, instance clauses, and derive clauses.
90+
91+
The overall layout of a LambdaBuffers Frontend file is:
9892

9993
```text
10094
module -> 'module' longmodulename { import } { statement }
10195
```
10296

103-
The file must specify the module's `longmodulename` where its `modulename` must match the file's name not including the `.lbf` extension.
97+
The file must specify the module's `longmodulename` where its `modulename` must match the LambdaBuffers Frontend file's file name not including the `.lbf` extension.
10498
After, the file may contain a sequence of `import`s followed by a sequence of `statement`s.
10599

106100
### Import
101+
107102
Imports bring *entities* (types and classes) of other modules into scope.
108103

109104
```text
@@ -125,13 +120,15 @@ statement -> typedef
125120
```
126121

127122
#### Type definitions
123+
128124
Types may be either sum types, product types, record types, or opaque types.
129125

130126
```text
131127
typedef -> prodtypedef | sumtypedef | recordtypedef | opaquetypedef
132128
```
133129

134130
##### Product type definition
131+
135132
A product type definition defines a new product type.
136133

137134
```text
@@ -145,6 +142,7 @@ typeexp -> varname
145142
Product type definitions instruct the code generator to generate a product type for the target language.
146143

147144
##### Sum type definition
145+
148146
A sum type definition defines a new sum type.
149147

150148
```text
@@ -156,6 +154,7 @@ sumconstructor -> typename prod
156154
Sum type definitions instruct the code generator to generate a sum type for the target language.
157155

158156
##### Record type definition
157+
159158
A record type definition defines a new record type.
160159

161160
```text
@@ -167,15 +166,17 @@ field -> fieldname ':' prod
167166
Record type definitions instruct the code generator to generate a record type for the target language.
168167
169168
##### Opaque type definition
169+
170170
An opaque type definition defines a new opaque type.
171171
172172
```text
173173
opaquetypedef -> 'opaque' typename { varname }
174174
```
175175

176-
Opaque type definitions do not instruct the code generator to generate code, and an opaque type must be instead implemented in the target language.
176+
Opaque type definitions must map to existing types in the target language and it's up to the Codegen module to determine how that's exactly done.
177177

178178
#### Class definition
179+
179180
A class definition introduces a new class.
180181

181182
```text
@@ -185,24 +186,21 @@ constraintexp -> classref { varname }
185186
constraintexps -> [ constraintexp { ',' constraintexp } ]
186187
```
187188

188-
Class definitions do not instruct the code generator to generate code, but
189-
instead provides a means to communicate with the code generator the
190-
instances one would like to generate (via a derive clause).
189+
Class definitions communicate with the code generator the implementations that already exist (via instance clauses) or that one would like to generate (via derive clauses).
191190

192191
#### Instance clause
192+
193193
An instance clause specifies a type is an instance of a class.
194194

195195
```text
196196
instanceclause -> 'instance' constraint [ ':-' constraintexps ]
197197
constraint -> classref { typeexp }
198198
```
199199

200-
Instance clauses do not instruct the code generator to generate code, but
201-
instead instructs the compiler (semantic checking) that the target language
202-
provides instances for the given type provided that the given `constraintexps`
203-
have instances.
200+
Instance clauses do not instruct the code generator to generate code, but instead instructs the compiler (semantic checking) that the target language environment provides type class implementations for the given type (provided that the given `constraintexps` also have implementations).
204201

205202
#### Derive clause
203+
206204
Derive clauses instruct the code generator to generate code for a type so that it is an instance of a class.
207205

208206
```text
@@ -212,7 +210,8 @@ deriveclause -> 'derive' constraint
212210
Note the code generation of a type for a class is implemented via builtin derivation rules (which developers may extend).
213211

214212
### Syntax reference
215-
The summarized productions of a LambdaBuffers file is as follows.
213+
214+
The summarized productions of a LambdaBuffers Frontend file is as follows.
216215

217216
```text
218217
module -> 'module' longmodulename { import } { statement }

0 commit comments

Comments
 (0)