Skip to content

Commit 481e3a2

Browse files
committed
feat(reference): Lexical Structure—Keywords
1 parent 84fe443 commit 481e3a2

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
@@ -97,7 +97,7 @@ docs_groups:
9797
- reference/lexical_structure:
9898
- reference/lexical_structure/whitespace
9999
- reference/lexical_structure/comments
100-
# - reference/lexical_structure/keywords
100+
- reference/lexical_structure/keywords
101101
# - reference/lexical_structure/identifiers
102102
# - reference/lexical_structure/literals
103103
# - 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)