Skip to content

Commit 47f17e0

Browse files
committed
feat(reference): Lexical Structure—Keywords
1 parent 36715c7 commit 47f17e0

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed

docs_config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ docs_groups:
9393
- reference/lexical_structure:
9494
- reference/lexical_structure/whitespace
9595
- reference/lexical_structure/comments
96-
# - reference/lexical_structure/keywords
96+
- reference/lexical_structure/keywords
9797
# - reference/lexical_structure/identifiers
9898
# - reference/lexical_structure/literals
9999
# - reference/lexical_structure/operators
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
---
2+
title: Keywords
3+
---
4+
5+
Languages typically classify keywords in three categories—strict, soft, and reserved.
6+
7+
## Strict keywords
8+
9+
Strict keywords can only be used where specified by the language and can never be used as identifiers. In Grain, these keywords are:
10+
11+
```ebnf
12+
keyword =
13+
| "assert"
14+
| "break"
15+
| "continue"
16+
| "else"
17+
| "enum"
18+
| "except"
19+
| "exception"
20+
| "export"
21+
| "fail"
22+
| "false"
23+
| "for"
24+
| "foreign"
25+
| "from"
26+
| "if"
27+
| "import"
28+
| "let"
29+
| "match"
30+
| "mut"
31+
| "primitive"
32+
| "rec"
33+
| "record"
34+
| "throw"
35+
| "true"
36+
| "type"
37+
| "void"
38+
| "wasm"
39+
| "when"
40+
| "while"
41+
;
42+
```
43+
44+
## Soft keywords
45+
46+
Soft keywords are sometimes allowed be used as an identifier, depending on the context.
47+
48+
Grain currently has no soft keywords.
49+
50+
## Reserved keywords
51+
52+
Reserved keywords are keywords that are not yet used by the language, but are disallowed as identifiers to allow programs to continue to be compatible with future versions of `grainc`.
53+
54+
The reserved keywords are as follows:
55+
56+
```ebnf
57+
reserved_keyword =
58+
| "try"
59+
| "catch"
60+
;
61+
```

0 commit comments

Comments
 (0)