114 lines
2.9 KiB
Markdown
114 lines
2.9 KiB
Markdown
# Terrace Language Specification
|
|
|
|
The Terrace language is designed to be a minimal meta-language, capable of being both human and machine readable and writable, but doing little of its own accord other than offering a set of basic conventions that other languages built on top of Terrace can use to their own advantage.
|
|
|
|
## Semantics
|
|
At its core, Terrace has only three semantic character classes:
|
|
|
|
1. Leading whitespace - Leading space (configurable) characters indicate the nesting level of a given section of the document.
|
|
- No characters other than whitespace may be exist at the start of a line unless the line is at the root of the nesting hierarchy.
|
|
2. Newlines (\n) - Newlines indicate when to start matching the next line. The \n character is matched. Carriage returns are treated literally and not used for parsing.
|
|
3. Every other character - The first character encountered after a newline and optional sequence of indent spaces is considered the start of a line's contents. Terrace will process the line verbatim until reaching a newline character.
|
|
|
|
### Exception: Blank Lines
|
|
|
|
Blank lines will be treated as if they were indented to the same level of the previous line. This allows blocks with embedded text and documents to retain whitespace relevant to their own internal semantics even if it is stripped out by well-meaning code formatters or unintentionally ignored.
|
|
|
|
Example:
|
|
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Source</th>
|
|
<th>Interpreted As</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td>
|
|
|
|
```tce
|
|
markdown
|
|
# Title
|
|
|
|
|
|
Dolore do do sit velit ullamco labore nisi laborum ut.
|
|
|
|
markdown
|
|
# Title 2
|
|
|
|
Incididunt qui nulla est enim officia ad sunt excepteur consequat sunt.
|
|
|
|
```
|
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
```tce
|
|
markdown
|
|
-># Title
|
|
->
|
|
->
|
|
->Dolore do do sit velit ullamco labore nisi laborum ut.
|
|
->
|
|
markdown
|
|
-># Title 2
|
|
->
|
|
->Incididunt qui nulla est enim officia ad sunt excepteur consequat sunt.
|
|
->
|
|
```
|
|
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
|
|
## Structure
|
|
|
|
A Terrace document consists of lines of arbitrary characters with leading whitespace indicating their nesting level relative to each other.
|
|
|
|
The following document contains two root-level elements, the first a line with the word "hello" with two lines of "world" nested under it, and the other line with the words "hello again" with "terrace" nested under it.
|
|
|
|
```tce
|
|
hello
|
|
world
|
|
world
|
|
|
|
hello again
|
|
terrace
|
|
```
|
|
|
|
Each line may be nested arbitrarily deeper than its parent, though one level is used by convention. Terrace-based languages may introduce additional restrictions, but the core parser accepts arbitrarily deep nesting.
|
|
|
|
**Acceptable:**
|
|
|
|
```tce
|
|
level 1
|
|
level 2
|
|
level 3
|
|
level 2
|
|
level 3
|
|
level 4
|
|
level 4
|
|
level 5
|
|
level 2
|
|
|
|
level 1
|
|
level 2
|
|
```
|
|
|
|
**Also Acceptable:** (even though "level 5" and "level 6" lines are nested more than one level deeper than their parent)
|
|
|
|
```tce
|
|
level 1
|
|
level 2
|
|
level 5
|
|
level 3
|
|
level 6
|
|
level 2
|
|
|
|
level 1
|
|
level 2
|
|
```
|