aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMelody Horn <melody@boringcactus.com>2020-11-02 23:20:34 -0700
committerMelody Horn <melody@boringcactus.com>2020-11-02 23:20:34 -0700
commitabe957952ecf232481a5e9819b94dececa2a5f21 (patch)
treea57685e3fc6f2d3489f0ebb2c24f80596bebe203
parentc7f8dc29ea3b4307d35d1f38596ba970af9318fd (diff)
downloadspec-abe957952ecf232481a5e9819b94dececa2a5f21.tar.gz
spec-abe957952ecf232481a5e9819b94dececa2a5f21.zip
add skeleton of type syntax
-rw-r--r--index.rst1
-rw-r--r--language/index.rst1
-rw-r--r--language/types.rst17
-rw-r--r--syntax.md25
-rw-r--r--types.md3
-rw-r--r--vs-c.rst2
6 files changed, 19 insertions, 30 deletions
diff --git a/index.rst b/index.rst
index 2724bc0..cab4271 100644
--- a/index.rst
+++ b/index.rst
@@ -52,7 +52,6 @@ Chapters
:numbered:
vs-c
- types
safety
errors
syntax
diff --git a/language/index.rst b/language/index.rst
index e1e2b01..3f776f9 100644
--- a/language/index.rst
+++ b/language/index.rst
@@ -20,3 +20,4 @@ Syntax elements in this document are given in the form of `parsing expression gr
type-definition
functions
statements/index
+ types
diff --git a/language/types.rst b/language/types.rst
new file mode 100644
index 0000000..0a38239
--- /dev/null
+++ b/language/types.rst
@@ -0,0 +1,17 @@
+Types
+-----
+
+.. crowbar:element:: Type <- ConstType / PointerType / ArrayType / FunctionType / BasicType
+
+.. crowbar:element:: ConstType <- 'const' BasicType
+
+.. crowbar:element:: PointerType <- BasicType '*'
+
+.. crowbar:element:: ArrayType <- BasicType '[' Expression ']'
+
+.. crowbar:element:: FunctionType <- BasicType 'function' '(' FunctionTypeArgs? ')'
+ FunctionTypeArgs <- BasicType (',' BasicType)* ','?
+
+.. crowbar:element:: BasicType <- 'void' / 'bool' / 'float32' / 'float64' / 'int8' / 'int16' / 'int32' / 'int64' / 'intaddr' / 'intmax' / 'intsize' / 'uint8' / 'uint16' / 'uint32' / 'uint64' / 'uintaddr' / 'uintmax' / 'uintsize' / 'struct' identifier / 'enum' identifier / 'union' identifier / '(' Type ')'
+
+.. todo:: define like any of these
diff --git a/syntax.md b/syntax.md
index 9f7fc59..8aed84b 100644
--- a/syntax.md
+++ b/syntax.md
@@ -23,31 +23,6 @@ AssignmentStatementBody ← AssignmentTargetExpression '=' Expression /
ExpressionStatement ← Expression ';'
```
-### Types
-
-```PEG
-Type ← 'const' BasicType /
- BasicType '*' /
- BasicType '[' Expression ']' /
- BasicType 'function' '(' (BasicType ',')* ')' /
- BasicType
-BasicType ← 'void' /
- IntegerType /
- 'signed' IntegerType /
- 'unsigned' IntegerType /
- 'float' /
- 'double' /
- 'bool' /
- 'struct' identifier /
- 'enum' identifier /
- 'typedef' identifier /
- '(' Type ')'
-IntegerType ← 'char' /
- 'short' /
- 'int' /
- 'long'
-```
-
### Expressions
```PEG
diff --git a/types.md b/types.md
deleted file mode 100644
index a86d937..0000000
--- a/types.md
+++ /dev/null
@@ -1,3 +0,0 @@
-# Types
-
-TODO
diff --git a/vs-c.rst b/vs-c.rst
index 42f8a38..73d0653 100644
--- a/vs-c.rst
+++ b/vs-c.rst
@@ -58,7 +58,7 @@ C's syntax isn't perfect, but it's usually pretty good.
However, sometimes it just sucks, and in those cases Crowbar makes changes.
* C's variable declaration syntax is far from intuitive in nontrivial cases (function pointers, pointer-to-``const`` vs ``const``-pointer, etc).
- Crowbar uses :doc:`simplified type syntax <types>` to keep types and variable names distinct.
+ Crowbar uses :crowbar:ref:`simplified type syntax <Type>` to keep types and variable names distinct.
* ``_Bool`` is just ``bool``, ``_Complex`` is just ``complex`` (why drag the preprocessor into it?)
* Adding a ``_`` to numeric literals as a separator
* All string literals, char literals, etc are UTF-8