Skip to content

Commit ab1fee2

Browse files
authored
Consistency improvements in fsgrammar listings (#86)
Improves the consistency of `fsgrammar` listings. The following changes were applied in general: - Replaced `opt` or `~opt` suffixes with `?` - Enclosed symbolic keywords and operators with single quotes - Used parentheses to group optional terms in `attribute := ( attribute-target ':' )? object-construction`
1 parent 716386d commit ab1fee2

11 files changed

Lines changed: 421 additions & 414 deletions

spec/custom-attributes-and-reflection.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ describes these mechanisms for F#.
88
Attributes are given by the following grammar:
99

1010
```fsgrammar
11-
attribute := attribute-target : opt object-construction
11+
attribute := ( attribute-target ':' )? object-construction
1212
13-
attribute-set := [< attribute ; ... ; attribute >]
13+
attribute-set := '[<' attribute ';' ... ';' attribute '>]'
1414
1515
attributes := attribute-set ... attribute-set
1616

spec/expressions.md

Lines changed: 146 additions & 146 deletions
Large diffs are not rendered by default.

spec/features-for-ml-compatibility.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,22 +73,22 @@ F# includes the following additional syntactic forms for ML compatibility:
7373
```fsgrammar
7474
expr :=
7575
| ...
76-
| expr .( expr ) // array lookup
77-
| expr .( expr ) <- expr // array assignment
76+
| expr '.(' expr ')' // array lookup
77+
| expr '.(' expr ')' '<-' expr // array assignment
7878
```
7979

8080
```fsgrammar
8181
type :=
8282
| ...
83-
| ( type ,..., type ) long-ident // generic type instantiation
83+
| '(' type ',' ... ',' type ')' long-ident // generic type instantiation
8484
8585
module-implementation :=
8686
| ...
87-
| module ident = struct ... end
87+
| module ident '=' struct ... end
8888
8989
module-signature :=
9090
| ...
91-
| module ident : sig ... end
91+
| module ident ':' sig ... end
9292
```
9393

9494
An ML compatibility warning occurs when these constructs are used.
@@ -100,13 +100,13 @@ The following expression forms
100100
```fsgrammar
101101
expr :=
102102
| ...
103-
| expr.(expr) // array lookup
104-
| expr.(expr) <- expr // array assignment
103+
| expr '.(' expr ')' // array lookup
104+
| expr '.(' expr ')' '<-' expr // array assignment
105105
```
106106

107107
Are equivalent to the following uses of library-defined operators:
108108

109-
```fsgrammar
109+
```fsharp
110110
e1.(e2) → (.()) e1 e2
111111
e1.(e2) <- e3 → (.()<-) e1 e2 e3
112112
```
@@ -115,7 +115,7 @@ e1.(e2) <- e3 → (.()<-) e1 e2 e3
115115

116116
F# defines the following two additional shortcut operators:
117117

118-
```fsgrammar
118+
```fsharp
119119
e1 or e2 → (or) e1 e2
120120
e1 & e2 → (&) e1 e2
121121
```

spec/introduction.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ val vowels: char list = ['e'; 'i'; 'o'; 'u']
6464
6565
> ['a'] @ vowels;;
6666
val it: char list = ['a'; 'e'; 'i'; 'o'; 'u']
67-
67+
6868
> vowels @ ['y'];;
6969
val it: char list = ['e'; 'i'; 'o'; 'u'; 'y']
7070
```
@@ -451,4 +451,4 @@ Regular expressions are typically used to specify tokens.
451451
token token-name = regexp
452452
```
453453

454-
In the grammar rules, the notation `element-name?` indicates an optional element. The notation `...` indicates repetition of the preceding non-terminal construct and the separator token. For example, `expr ',' ... ',' expr` means a sequence of one or more `expr` elements separated by commas.
454+
In the grammar rules, the notation `element-name?` indicates an optional element. Where the optional element requires multiple tokens, it is enclosed in parentheses `(e1 e2)?`. The notation `...` indicates repetition of the preceding non-terminal construct and the separator token. For example, `expr ',' ... ',' expr` means a sequence of one or more `expr` elements separated by commas. Literal symbols like `,` that appear in the grammer are enclosed in single quotes i.e. `','`, except the single quote character itself which is enclosed in double quotes `"'"`. Comments may be placed at the end of a line, prefixed with `--`.

spec/lexical-analysis.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ used for the name of a types, union type case, module, or namespace, the followi
135135
not allowed even inside double-backtick marks:
136136

137137
```fsgrammar
138-
.', '+', '$', '&', '[', ']', '/', '\\', '*', '\"', '`'
138+
'.', '+', '$', '&', '[', ']', '/', '\\', '*', '\"', '`'
139139
```
140140

141141
All input files are currently assumed to be encoded as UTF-8. See the C# specification for a list of the
@@ -178,7 +178,7 @@ The following token forms are reserved, except when they are part of a symbolic
178178

179179
```fsgrammar
180180
token reserved-ident-formats =
181-
| ident-text ( '!' | '#')
181+
| ident-text ( '!' | '#' )
182182
```
183183

184184
In the remainder of this specification, we refer to the token that is generated for a keyword simply

spec/namespace-and-module-signatures.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module-signature :=
1212
module ident = module-signature-body
1313
1414
module-signature-element :=
15-
val mutable~opt curried-sig -- value signature
15+
val mutable? curried-sig -- value signature
1616
val value-defn -- literal value signature
1717
type type-signatures -- type(s) signature
1818
exception exception-signature -- exception signature
@@ -40,21 +40,21 @@ type-signature :=
4040
type-signatures := type-signature ... and ... type-signature
4141
4242
type-signature-element :=
43-
attributesopt access~opt new : uncurried-sig -- constructor signature
44-
attributesopt member acces~opt member-sig -- member signature
45-
attributesopt abstract access~opt member-sig -- member signature
46-
attributesopt override member-sig -- member signature
47-
attributesopt default member-sig -- member signature
48-
attributes~opt static member access~opt member-sig -- static member signature
43+
attributes? access? new : uncurried-sig -- constructor signature
44+
attributes? member access? member-sig -- member signature
45+
attributes? abstract access? member-sig -- member signature
46+
attributes? override member-sig -- member signature
47+
attributes? default member-sig -- member signature
48+
attributes? static member access? member-sig -- static member signature
4949
interface type -- interface signature
5050
5151
abbrev-type-signature := type-name '=' type
5252
5353
union-type-signature := type-name '=' union-type-cases type-extension-elements-
54-
signature~opt
54+
signature?
5555
5656
record-type-signature := type-name '=' '{' record-fields '}' type-extension-
57-
elements-signature~opt
57+
elements-signature?
5858
5959
anon-type-signature := type-name '=' begin type-elements-signature end
6060
@@ -194,7 +194,7 @@ values are implicit in module signatures. A signature that contains the followin
194194
`[A1 ... An]` for `F`:
195195

196196
```fsgrammar
197-
val F : ty11 * ... * ty1A1 - > ... -> tyn1 * ... * tynAn - > rty
197+
val F : ty11 '*' ... '*' ty1A1 '->' ... '->' tyn1 '*' ... '*' tynAn '->' rty
198198
```
199199

200200
Arities in a signature must be equal to or shorter than the corresponding arities in an

spec/namespaces-and-modules.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ namespace-decl-group :=
1616
namespace global module-elems -- elements within no namespace
1717
1818
module-defn :=
19-
attributesopt module accessopt ident = module-defn-body
19+
attributes? module access? ident = module-defn-body
2020
2121
module-defn-body :=
22-
begin module-elemsopt end
22+
begin module-elems? end
2323
2424
module-elem :=
2525
module-function-or-value-defn -- function or value definitions
@@ -31,16 +31,16 @@ module-elem :=
3131
compiler-directive-decl -- compiler directives
3232
3333
module-function-or-value-defn :=
34-
attributesopt let function-defn
35-
attributesopt let value-defn
36-
attributesopt let rec opt function-or-value-defns
37-
attributesopt do expr
34+
attributes? let function-defn
35+
attributes? let value-defn
36+
attributes? let rec? function-or-value-defns
37+
attributes? do expr
3838
3939
import-decl := open long-ident
4040
4141
module-abbrev := module ident = long-ident
4242
43-
compiler-directive-decl := # ident string ... string
43+
compiler-directive-decl := '#' ident string ... string
4444
4545
module-elems := module-elem ... module-elem
4646
@@ -240,7 +240,7 @@ dogCage |> Cage.getPet |> Dog.bark
240240
Function and value definitionsin modules introduce named values and functions.
241241

242242
```fsgrammar
243-
let rec~opt function-or-value-defn1 and ... and function-or-value-defnn
243+
let rec? function-or-value-defn1 and ... and function-or-value-defnn
244244
```
245245

246246
The following example defines value `x` and functions `id` and `fib`:
@@ -354,7 +354,7 @@ A value that has the `Literal` attribute is subject to the following restriction
354354

355355
### Type Function Definitions in Modules
356356

357-
Value definitions within modules may have explicit generic parameters. For example, `T` is a generic
357+
Value definitions within modules may have explicit generic parameters. For example, `'T` is a generic
358358
parameter to the value `empty`:
359359

360360
```fsharp
@@ -405,13 +405,13 @@ The elaborated form of a type function is that of a function definition that tak
405405
type `unit`. That is, the elaborated form of
406406

407407
```fsgrammar
408-
let ident typar-defns = expr
408+
let ident typar-defns '=' expr
409409
```
410410

411411
is the same as the compiled form for the following declaration:
412412

413413
```fsgrammar
414-
let ident typar-defns () = expr
414+
let ident typar-defns '()' '=' expr
415415
```
416416

417417
References to type functions are elaborated to invocations of such a function.
@@ -486,7 +486,7 @@ attribute.
486486
A module abbreviation defines a local name for a module long identifier, as follows:
487487

488488
```fsgrammar
489-
module ident = long-ident
489+
module ident '=' long-ident
490490
```
491491

492492
For example:

spec/patterns.md

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -7,63 +7,63 @@ in the subsequent table.
77

88
```fsgrammar
99
rule :=
10-
pat pattern-guard~opt -> expr -- pattern, optional guard and action
10+
pat pattern-guard? '->' expr -- pattern, optional guard and action
1111
1212
pattern-guard := when expr
1313
1414
pat :=
15-
const -- constant pattern
16-
long-ident pat-param~opt pat~opt -- named pattern
17-
_ -- wildcard pattern
18-
pat as ident -- "as" pattern
19-
pat '|' pat -- disjunctive pattern
20-
pat '&' pat -- conjunctive pattern
21-
pat :: pat -- "cons" pattern
22-
pat : type -- pattern with type constraint
23-
pat , ... , pat -- tuple pattern
24-
struct (pat , ... , pat) -- struct tuple pattern
25-
( pat ) -- parenthesized pattern
26-
list-pat -- list pattern
27-
array-pat -- array pattern
28-
record-pat -- record pattern
29-
:? atomic-type -- dynamic type test pattern
30-
:? atomic-type as ident -- dynamic type test pattern
31-
null -- null-test pattern
32-
attributes pat -- pattern with attributes
15+
const -- constant pattern
16+
long-ident pat-param? pat? -- named pattern
17+
_ -- wildcard pattern
18+
pat as ident -- "as" pattern
19+
pat '|' pat -- disjunctive pattern
20+
pat '&' pat -- conjunctive pattern
21+
pat '::' pat -- "cons" pattern
22+
pat ':' type -- pattern with type constraint
23+
pat ',' ... ',' pat -- tuple pattern
24+
struct '(' pat ',' ... ',' pat ')' -- struct tuple pattern
25+
'(' pat ')' -- parenthesized pattern
26+
list-pat -- list pattern
27+
array-pat -- array pattern
28+
record-pat -- record pattern
29+
':?' atomic-type -- dynamic type test pattern
30+
':?' atomic-type as ident -- dynamic type test pattern
31+
null -- null-test pattern
32+
attributes pat -- pattern with attributes
3333
3434
list-pat :=
35-
[ ]
36-
[ pat ; ... ; pat ]
35+
'[' ']'
36+
'[' pat ';' ... ';' pat ']'
3737
3838
array-pat :=
39-
[| |]
40-
[| pat ; ... ; pat |]
39+
'[|' '|]'
40+
'[|' pat ';' ... ';' pat '|]'
4141
4242
record-pat :=
43-
{ field-pat ; ... ; field-pat }
43+
'{' field-pat ';' ... ';' field-pat '}'
4444
4545
atomic-pat :=
4646
pat : one of
4747
const long-ident list-pat record-pat array-pat ( pat )
4848
:? atomic-type
4949
null _
5050
51-
field-pat := long-ident = pat
51+
field-pat := long-ident '=' pat
5252
5353
pat-param :=
54-
| const
55-
| long-ident
56-
| [ pat-param ; ... ; pat-param ]
57-
| ( pat-param , ..., pat-param )
58-
| long-ident pat-param
59-
| pat-param : type
60-
| <@ expr @>
61-
| <@@ expr @@>
62-
| null
54+
'|' const
55+
'|' long-ident
56+
'|' '[' pat-param ';' ... ';' pat-param ']'
57+
'|' '(' pat-param ',' ... ',' pat-param ')'
58+
'|' long-ident pat-param
59+
'|' pat-param ':' type
60+
'|' '<@' expr '@>'
61+
'|' '<@@' expr '@@>'
62+
'|' null
6363
64-
pats := pat , ... , pat
65-
field-pats := field-pat ; ... ; field-pat
66-
rules := '|'~opt rule '|' ... '|' rule
64+
pats := pat ',' ... ',' pat
65+
field-pats := field-pat ';' ... ';' field-pat
66+
rules := '|'? rule '|' ... '|' rule
6767
```
6868

6969
Patterns are elaborated to expressions through a process called _pattern match compilation_. This
@@ -107,9 +107,9 @@ strings.
107107
Patterns in the following forms are _named patterns_ :
108108

109109
```fsgrammar
110-
Long-ident
111-
Long-ident pat
112-
Long-ident pat-params pat
110+
long-ident
111+
long-ident pat
112+
long-ident pat-params pat
113113
```
114114

115115
If `long-ident` is a single identifier that does not begin with an uppercase character, it is interpreted
@@ -355,7 +355,7 @@ In the example, if `x` is `0`, the match returns `1`. If `x` has any other value
355355
A disjunctive pattern matches an input value against one or the other of two patterns:
356356

357357
```fsgrammar
358-
pat | pat
358+
pat '|' pat
359359
```
360360

361361
At runtime, the pattern input is matched against the first pattern. If that fails, the pattern input is
@@ -381,7 +381,7 @@ pattern.
381381
A conjunctive pattern matches the pattern input against two patterns.
382382

383383
```fsgrammar
384-
pat1 & pat2
384+
pat1 '&' pat2
385385
```
386386

387387
For example:
@@ -430,7 +430,7 @@ In this example, both `result1` and `result2` are given the value `6`.
430430
A _type-annotated pattern_ specifies the type of the value to match to a pattern.
431431

432432
```fsgrammar
433-
pat : type
433+
pat ':' type
434434
```
435435

436436
For example:
@@ -452,8 +452,8 @@ static type
452452
_Dynamic type-test patterns_ have the following two forms:
453453

454454
```fsgrammar
455-
:? type
456-
:? type as ident
455+
':?' type
456+
':?' type as ident
457457
```
458458

459459
A dynamic type-test pattern matches any value whose runtime type is `type` or a subtype of `type`. For
@@ -509,7 +509,7 @@ to the results of a dynamic coercion expression `e :?> ty`.
509509
The following is a _record pattern_ :
510510

511511
```fsgrammar
512-
{ long-ident1 = pat1 ; ... ; long-identn = patn }
512+
'{' long-ident1 '=' pat1 ';' ... ';' long-identn '=' patn '}'
513513
```
514514

515515
For example:
@@ -533,7 +533,7 @@ specified in the pattern.
533533
An _array pattern_ matches an array of a partciular length:
534534

535535
```fsgrammar
536-
[| pat ; ... ; pat |]
536+
'[|' pat ';' ... ';' pat '|]'
537537
```
538538

539539
For example:

0 commit comments

Comments
 (0)