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
| Numbers |`42`, `3.1415`, `.5`| Integers and decimals; leading zero added for `.5` style numbers by the lexer. |
36
36
| Hex Colors |`#FFAA00`, `#abc`| Interpreted as `Color.Hex`. |
37
37
| Strings |`identifierStyle`| Bare identifiers not bound in scope fall back to string literals. |
38
-
| Explicit Strings |`"quoted value"` or `'alternate quotes'`|Preserve whitespace and special characters. |
38
+
| Explicit Strings |`"quoted value"` or `'alternate quotes'`|Preserves whitespace and special characters. |
39
39
| Booleans |`true`, `false`| Reserved keywords mapped to `Boolean`. |
40
40
| Null |`null`| Reserved keyword mapped to `Null`. |
41
41
| Lists |`value1, value2, value3`| Comma-separated sequence; implicit lists use spaces when built by certain operations. |
42
42
43
+
## Implicit Strings and Lists
44
+
45
+
### Overview
46
+
47
+
TokenScript supports **implicit strings** - strings that don't require quotes. This is a fallback mechanism for when a string is not made explicit with quotes.
48
+
49
+
:::warning Recommendation: Use Explicit Strings
50
+
Implicit strings exist for backward compatibility and convenience, but they have confusing edge cases.
51
+
52
+
**Prefer to use quotes around strings (`"hello"`) instead of relying on implicit strings (`hello`).**
53
+
:::
54
+
55
+
### Basic Behavior
56
+
57
+
Implicit strings are recognized when the lexer/parser encounters text that:
58
+
59
+
1. Starts with a valid identifier character (letters, emoji, etc.)
60
+
2. Or starts with a number followed by text that is **not a recognized unit**
61
+
62
+
<TokenScriptCodeBlockmode="script">
63
+
{`Implicit strings supported`}
64
+
</TokenScriptCodeBlock>
65
+
66
+
<TokenScriptCodeBlockmode="script">
67
+
{`// Strings starting with numbers (not recognized units)
68
+
// ⚠️ GOTCHA: Space is added between number and text!
69
+
1unknown // Output: ["1", "unknown"] (List) - not "1unknown"!
70
+
5test // Output: ["5", "test"] (List) - not "5test"!
71
+
3D-Font // Output: ["3", "D-Font"] (List) - not "3D-Font"!`}
72
+
</TokenScriptCodeBlock>
73
+
74
+
<TokenScriptCodeBlockmode="script">
75
+
{`1px
76
+
5rem
77
+
10%`}
78
+
</TokenScriptCodeBlock>
79
+
80
+
### Implicit Lists
81
+
82
+
When multiple values are combined without operators, they form **implicit lists**.
83
+
<br />This allows natural composition of values:
84
+
85
+
<TokenScriptCodeBlockmode="script">
86
+
{`1px solid black`}
87
+
</TokenScriptCodeBlock>
88
+
89
+
### Edge Cases and Pitfalls
90
+
91
+
#### Arithmetic Operations with Implicit Strings
92
+
93
+
When you mix arithmetic operators with implicit strings, the behavior may surprise you:
94
+
95
+
<TokenScriptCodeBlockmode="script">
96
+
{`// ⚠️ This evaluates to "2 unknown" not an error!
97
+
// The arithmetic happens first: (1 + 1) = 2
98
+
// Then creates implicit list with result and string: "2 unknown"
99
+
1 + 1unknown`}
100
+
</TokenScriptCodeBlock>
101
+
102
+
##### Recommended usage
103
+
104
+
Use recognized units for arithmetic:
105
+
106
+
<TokenScriptCodeBlockmode="script">
107
+
{`1px + 1px`}
108
+
</TokenScriptCodeBlock>
109
+
110
+
Use explicit strings to avoid the edge cases:
111
+
112
+
<TokenScriptCodeBlockmode="script">
113
+
{`"1unknown"`}
114
+
</TokenScriptCodeBlock>
115
+
116
+
So the aforementioned example will now throw an error:
117
+
118
+
<TokenScriptCodeBlockmode="script">
119
+
{`1 + "1unknown"`}
120
+
</TokenScriptCodeBlock>
121
+
122
+
#### 2. Strings Starting with Numbers
123
+
124
+
Unlike CSS (which disallows unquoted identifiers starting with numbers), TokenScript allows them as implicit strings:
125
+
126
+
<TokenScriptCodeBlockmode="script">
127
+
{`3D Font`}
128
+
</TokenScriptCodeBlock>
129
+
130
+
<TokenScriptCodeBlockmode="script">
131
+
{`"3D Font"`}
132
+
</TokenScriptCodeBlock>
133
+
134
+
### Best Practices
135
+
136
+
:::warning Always Use Explicit Strings When Possible
137
+
While implicit strings are convenient, they can lead to confusion and errors.<br />**We recommend using explicit strings in most cases.**
138
+
:::
139
+
140
+
<TokenScriptCodeBlockmode="script">
141
+
{`// Use explicit strings (clear intent)
142
+
"3D Font", "some other font", "Font with emoji 😼";`}
143
+
</TokenScriptCodeBlock>
144
+
145
+
#### When Implicit Strings Are Acceptable
146
+
147
+
Implicit strings are mainly useful for:
148
+
149
+
1.**Simple identifiers without spaces or special characters**
150
+
151
+
<TokenScriptCodeBlockmode="script">
152
+
{`primary`}
153
+
</TokenScriptCodeBlock>
154
+
155
+
2.**CSS-like shorthand values**
156
+
157
+
<TokenScriptCodeBlockmode="script">
158
+
{`1px solid black`}
159
+
</TokenScriptCodeBlock>
160
+
161
+
3.**Backward compatibility** - Existing TokenScript code may rely on implicit strings
162
+
43
163
## Units
44
164
45
-
Numbers may be suffixed with a units like `px`, `em`, `rem`, `vw`, `vh`, `pt`, `in`, `cm`, `mm`, `deg`, `%`.
165
+
Numbers may be suffixed with units like `px`, `em`, `rem`, `vw`, `vh`, `pt`, `in`, `cm`, `mm`, `deg`, `%`.
0 commit comments