Skip to content

Commit 2267836

Browse files
committed
Cleanup
1 parent 748f417 commit 2267836

File tree

5 files changed

+28
-34
lines changed

5 files changed

+28
-34
lines changed
File renamed without changes.
File renamed without changes.

docs-language/syntax.md

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@ import TokenScriptCodeBlock from '@site/src/components/TokenScriptCodeBlock';
88

99
# Lexical Syntax
1010

11-
TokenScript uses a lightweight, whitespace-insensitive syntax optimized for expressing token derivations. This chapter outlines the lexical rules enforced by the lexer (`src/interpreter/lexer.ts`) and the structural expectations enforced by the parser (`src/interpreter/parser.ts`).
12-
1311
## Character Set & Identifiers
1412

15-
- Source code is UTF-8. Identifiers may include standard ASCII letters, digits, hyphen (`-`), underscore (`_`), and extended Unicode characters (e.g., emoji).
13+
- Identifiers may include standard ASCII letters, digits, hyphen (`-`), underscore (`_`), and extended Unicode characters (e.g., emoji).
1614
- Identifiers must begin with an alphabetic or non-ASCII character (numbers are not allowed in the first position).
17-
- Identifiers are case-sensitive (`primaryColor` and `PrimaryColor` are distinct).
15+
- Identifiers are case-insensitive (`primaryColor` and `PrimaryColor` are treated equally).
1816

1917
## Whitespace & Newlines
2018

@@ -23,7 +21,7 @@ TokenScript uses a lightweight, whitespace-insensitive syntax optimized for expr
2321

2422
## Comments
2523

26-
- Single-line comments start with `//` and run to the end of the line. Block comments are not currently supported.
24+
- Single-line comments start with `//` and run to the end of the line.
2725

2826
<TokenScriptCodeBlock mode="script" showResult={false}>
2927
{`// A single-line comment
@@ -40,43 +38,36 @@ variable spacing: NumberWithUnit = 4px; // Trailing comments are allowed`}
4038
| Explicit Strings | `"quoted value"` or `'alternate quotes'` | Preserve whitespace and special characters. |
4139
| Booleans | `true`, `false` | Reserved keywords mapped to `Boolean`. |
4240
| Null | `null` | Reserved keyword mapped to `Null`. |
43-
| Undefined | `undefined` | Reserved keyword; the interpreter currently treats it as a literal string when encountered. |
4441
| Lists | `value1, value2, value3` | Comma-separated sequence; implicit lists use spaces when built by certain operations. |
4542

4643
## Units
4744

48-
Numbers may be suffixed with a unit from `src/types.ts#SupportedFormats`, including `px`, `em`, `rem`, `vw`, `vh`, `pt`, `in`, `cm`, `mm`, `deg`, `%`. The lexer emits a `FORMAT` token, which the parser combines with the preceding numeric literal to produce an `ElementWithUnitNode`. At runtime the interpreter constructs a `NumberWithUnitSymbol`.
49-
45+
Numbers may be suffixed with a units like `px`, `em`, `rem`, `vw`, `vh`, `pt`, `in`, `cm`, `mm`, `deg`, `%`.
5046
<TokenScriptCodeBlock mode="script" showResult={false}>
5147
{`variable padding: NumberWithUnit = 1.5rem;
5248
variable angle: NumberWithUnit = 45deg;`}
5349
</TokenScriptCodeBlock>
5450

5551
## References
5652

57-
Wrap token names in braces to read values from the reference map provided to the interpreter or resolver:
58-
59-
// TODO: in interpreter mode you can't use dot notation
53+
Wrap token paths in braces to read values from the references.
6054

6155
<TokenScriptCodeBlock mode="script" showResult={false}>
62-
{`// Dot notation works in token resolution
63-
variable primaryColor: Color = {colors.primary};
56+
{`variable primaryColor: Color = {colors.primary};
6457
variable spacingLg: NumberWithUnit = {spacing.base} * 3;`}
6558
</TokenScriptCodeBlock>
6659

67-
Nested references (e.g., `{theme.primary.color}`) are flattened during lexing.
68-
6960
## Reserved Keywords
7061

7162
The following keywords cannot be used as identifiers:
7263

73-
| Keyword | Purpose |
74-
| --- | --- |
75-
| `variable` | Starts a variable declaration. |
76-
| `if`, `elif`, `else` | Control flow branches. |
77-
| `while` | Loop construct. |
78-
| `return` | Exits the current block/expression. |
79-
| `true`, `false`, `null`, `undefined` | Literal values. |
64+
| Keyword | Purpose |
65+
|-------------------------|-------------------------------------|
66+
| `variable` | Starts a variable declaration. |
67+
| `if`, `elif`, `else` | Control flow branches. |
68+
| `while` | Loop construct. |
69+
| `return` | Exits the current block/expression. |
70+
| `true`, `false`, `null` | Literal values. |
8071

8172
## Statement Forms
8273

@@ -89,7 +80,9 @@ variable ramp: List = accent, accent.to.oklch();`}
8980
</TokenScriptCodeBlock>
9081

9182
- Type annotations are required (`Type` or `Type.SubType`).
92-
- Initializers are optional; without an initializer, variables start with the type’s `empty()` value.
83+
- Initializers are optional; without an initializer, variables start with the type’s `empty()` value, which in most symbols is `null`
84+
- For [Dictionary](/language/types#dictionary) its an empty dictionary.
85+
- For [List](/language/types#list) its an empty list.
9386

9487
### Assignments & Reassignments
9588

@@ -104,6 +97,7 @@ variable accentValue: String = "#0066FF";`}
10497
### Blocks
10598

10699
- Statement blocks are wrapped in square brackets `[...]`. They can contain multiple statements separated by semicolons or newlines.
100+
- Variable declaration in blocks are not allowed.
107101

108102
<TokenScriptCodeBlock
109103
mode="script"
@@ -112,9 +106,9 @@ variable accentValue: String = "#0066FF";`}
112106
{`variable condition: Boolean = true;
113107

114108
if (condition) [
115-
return 1;
109+
return 1;
116110
] else [
117-
return 0;
111+
return 0;
118112
]`}
119113
</TokenScriptCodeBlock>
120114

docusaurus.config.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ const config: Config = {
4242
[
4343
"@docusaurus/plugin-content-docs",
4444
{
45-
id: "intro",
46-
path: "./docs-intro",
47-
routeBasePath: "intro",
48-
sidebarPath: "./sidebars-intro.ts",
45+
id: "about",
46+
path: "./docs-about",
47+
routeBasePath: "about",
48+
sidebarPath: "./sidebars-about.ts",
4949
editUrl: undefined,
5050
showLastUpdateAuthor: false,
5151
showLastUpdateTime: false,
@@ -113,9 +113,9 @@ const config: Config = {
113113
{
114114
type: "doc",
115115
docId: "why-tokenscript",
116-
docsPluginId: "intro",
116+
docsPluginId: "about",
117117
position: "left",
118-
label: "Introduction",
118+
label: "About",
119119
},
120120
{
121121
type: "doc",
@@ -160,11 +160,11 @@ const config: Config = {
160160
items: [
161161
{
162162
label: "Why TokenScript",
163-
to: "/intro/why-tokenscript",
163+
to: "/about/why-tokenscript",
164164
},
165165
{
166166
label: "Quick Start",
167-
to: "/intro/quick-start",
167+
to: "/about/quick-start",
168168
},
169169
],
170170
},
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { SidebarsConfig } from "@docusaurus/plugin-content-docs";
22

33
const sidebars: SidebarsConfig = {
4-
introSidebar: ["why-tokenscript", "quick-start"],
4+
aboutSidebar: ["why-tokenscript", "quick-start"],
55
};
66

77
export default sidebars;

0 commit comments

Comments
 (0)