You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs-language/types.md
+15-24Lines changed: 15 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,12 +6,12 @@ sidebar_label: Types
6
6
7
7
# Types and Symbols
8
8
9
-
Every TokenScript variable declaration specifies a type using `Type` or `Type.SubType` notation. The interpreter enforces type correctness during assignment and method calls by instantiating corresponding `Symbol` classes (`src/interpreter/symbols.ts`). This chapter documents each built-in type.
9
+
Every TokenScript variable declaration specifies a type using `Type` or `Type.SubType` notation. The interpreter enforces type correctness during assignment and method calls by instantiating corresponding `Symbol` classes.
10
10
11
11
## Declarations & Defaults
12
12
13
13
-`variable name: Type;` initializes `name` with the type’s `empty()` value, if no initializer is provided.
14
-
- Subtypes (`Type.SubType`) are primarily used for colors. For other types, the interpreter treats `Type` and `Type.Something` equivalently unless extension managers add meaning.
14
+
- Subtypes (`Type.SubType`) are primarily used for colors.
15
15
- Reassignments must respect the declared type; the interpreter throws an `InterpreterError` on mismatch.
16
16
17
17
## Primitive Types
@@ -27,8 +27,6 @@ Every TokenScript variable declaration specifies a type using `Type` or `Type.Su
|`to_string`|`Number.to_string(radix?: Number)`| Returns the numeric value as a string. Radix (2–36) is optional; base 16 rounds halves downward for color conversions. |
29
29
30
-
- Attributes: `value` (read-only `Number`).
31
-
32
30
### String
33
31
34
32
- Represents UTF-8 strings.
@@ -68,13 +66,10 @@ Every TokenScript variable declaration specifies a type using `Type` or `Type.Su
68
66
|`to_number`|`NumberWithUnit.to_number()`| Returns the unitless numeric value. |
69
67
||||
70
68
71
-
- Attributes: `value` (`Number`).
72
-
- Arithmetic operators respect units; the `UnitManager` converts compatible units or throws descriptive errors (e.g., mixing `px` and `deg`).
73
-
74
69
## List
75
70
76
71
- Heterogeneous ordered collection.
77
-
- Declared with `List`. Subtype hints (e.g., `List.String`) are allowed syntactically but not enforced at runtime.
72
+
- Declared with `List`.
78
73
- Created via comma-separated literals or dynamic operations.
79
74
- Methods:
80
75
@@ -94,22 +89,20 @@ Every TokenScript variable declaration specifies a type using `Type` or `Type.Su
|`length`|`Dictionary.length()`| Number of entries. |
105
+
|`clear`|`Dictionary.clear()`| Removes all entries. |
113
106
114
107
## Color
115
108
@@ -133,13 +126,11 @@ Every TokenScript variable declaration specifies a type using `Type` or `Type.Su
133
126
134
127
## References
135
128
136
-
- Reference literals (`{token.name}`) resolve to values from the interpreter’s reference map or the shared map used by `TokenSetResolver`.
129
+
- Reference literals (`{token.name}`) resolve to values from the interpreter’s reference map.
137
130
- References do not introduce a distinct type; they evaluate to whichever symbol is stored for the token.
138
131
139
132
## Type Equality & Coercion
140
133
141
134
- Equality comparisons require operands of the same type (with special cases for `Null` and hex colors).
142
135
-`Number` and `NumberWithUnit` interoperate in math operations via `UnitManager` conversions.
143
136
- Attempting to mix incompatible units, compare unlike types, or call undefined methods results in an `InterpreterError` with the originating token metadata.
144
-
145
-
Proceed to [Control Flow](control-flow.md) to learn how statements execute and how loops are guarded against infinite execution.
0 commit comments