@vertekum/schema-builder 0.1.5 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @vertekum/schema-builder
2
2
 
3
+ ## 0.1.6
4
+
5
+ ### Patch Changes
6
+
7
+ - [`2e9a56f`](https://github.com/moros-oxus/vertekum/commit/2e9a56f5cc52de26ee8768ae0035178ebe4d847e) Thanks [@tschemmer](https://github.com/tschemmer)! - Names may start with digits when they contain a letter (`2xs`, `4k-display`) — everywhere a name works, including pick/omit lists. Pure numbers and scale expressions keep their numeric meaning; the syntax highlighting follows suit.
8
+
3
9
  ## 0.1.5
4
10
 
5
11
  ### Patch Changes
package/docs/language.md CHANGED
@@ -29,9 +29,10 @@ root = color.[text | icon].<role>.<@emphasis>
29
29
  ```
30
30
 
31
31
  - **`#` starts a comment**, running to the end of the line.
32
- - **Identifiers** are `[A-Za-z][A-Za-z0-9-]*` — letters, digits, hyphens
33
- (`color-role`). A term that starts with a digit is numeric: a bare number (`950`) or
34
- a [scale expression](./scales.md) (`100-300/50`) — which is why hyphens inside names
32
+ - **Identifiers** are letters, digits, and hyphens (`color-role`), and may start with
33
+ digits **when they contain a letter** (`2xs`, `4k-display`). A term that is purely
34
+ numeric keeps its numeric meaning: a bare number (`950`) or a
35
+ [scale expression](./scales.md) (`100-300/50`) — which is why hyphens inside names
35
36
  never collide with range syntax.
36
37
  - **Strings** (pragma and `use` arguments) are double-quoted.
37
38
 
@@ -61,7 +61,7 @@
61
61
  }
62
62
  },
63
63
  "production": {
64
- "match": "^([A-Za-z][A-Za-z0-9-]*)\\s*(=)",
64
+ "match": "^(\\d+[A-Za-z][A-Za-z0-9-]*|[A-Za-z][A-Za-z0-9-]*)\\s*(=)",
65
65
  "captures": {
66
66
  "1": {
67
67
  "name": "entity.name.function.production.dfn"
@@ -127,7 +127,7 @@
127
127
  },
128
128
  "patterns": [
129
129
  {
130
- "match": "([A-Za-z][A-Za-z0-9-]*)(/)([A-Za-z][A-Za-z0-9-]*)",
130
+ "match": "(\\d+[A-Za-z][A-Za-z0-9-]*|[A-Za-z][A-Za-z0-9-]*)(/)(\\d+[A-Za-z][A-Za-z0-9-]*|[A-Za-z][A-Za-z0-9-]*)",
131
131
  "captures": {
132
132
  "1": {
133
133
  "name": "entity.name.namespace.module.dfn"
@@ -145,7 +145,7 @@
145
145
  },
146
146
  {
147
147
  "name": "variable.other.reference.imported.dfn",
148
- "match": "[A-Za-z][A-Za-z0-9-]*"
148
+ "match": "\\d+[A-Za-z][A-Za-z0-9-]*|[A-Za-z][A-Za-z0-9-]*"
149
149
  }
150
150
  ]
151
151
  },
@@ -171,7 +171,7 @@
171
171
  },
172
172
  {
173
173
  "name": "variable.other.reference.dfn",
174
- "match": "[A-Za-z][A-Za-z0-9-]*"
174
+ "match": "\\d+[A-Za-z][A-Za-z0-9-]*|[A-Za-z][A-Za-z0-9-]*"
175
175
  }
176
176
  ]
177
177
  },
@@ -197,7 +197,7 @@
197
197
  "patterns": [
198
198
  {
199
199
  "name": "variable.parameter.member.dfn",
200
- "match": "[A-Za-z][A-Za-z0-9-]*|\\d+"
200
+ "match": "\\d+[A-Za-z][A-Za-z0-9-]*|[A-Za-z][A-Za-z0-9-]*|\\d+"
201
201
  },
202
202
  {
203
203
  "name": "punctuation.separator.comma.dfn",
@@ -245,7 +245,7 @@
245
245
  },
246
246
  "name": {
247
247
  "name": "constant.language.name.dfn",
248
- "match": "[A-Za-z][A-Za-z0-9-]*"
248
+ "match": "\\d+[A-Za-z][A-Za-z0-9-]*|[A-Za-z][A-Za-z0-9-]*"
249
249
  }
250
250
  }
251
251
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vertekum/schema-builder",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "Declare token vocabularies as grammar; build them into JSON Schema files",
5
5
  "license": "Apache-2.0",
6
6
  "keywords": [
package/src/tokenizer.ts CHANGED
@@ -49,6 +49,12 @@ export interface Token {
49
49
 
50
50
  const IDENT = /^[A-Za-z][A-Za-z0-9-]*/;
51
51
  const RANGE = /^(\d+)-(\d+)([*/])(\d+(?:\.\d+)?)(?:~(\d+))?/;
52
+ /**
53
+ * A digit-leading NAME (`2xs`, `4k-display`): digits, then at least one letter. Tried after
54
+ * RANGE — so `100-300/50` stays numeric — and before NUMBER, so the whole word is one token
55
+ * rather than `2` + `xs`. Real design systems name t-shirt sizes this way.
56
+ */
57
+ const WORD = /^\d+[A-Za-z][A-Za-z0-9-]*/;
52
58
  const NUMBER = /^\d+/;
53
59
 
54
60
  /** "Write the numbers as they appear": a leading zero declares the pad width. */
@@ -113,6 +119,11 @@ export function tokenize(source: string): Token[] {
113
119
  text = text.slice(range[0].length);
114
120
  continue;
115
121
  }
122
+ const word = text.match(WORD);
123
+ if (word) {
124
+ push('ident', word[0]);
125
+ continue;
126
+ }
116
127
  const number = text.match(NUMBER);
117
128
  if (number) {
118
129
  push('number', number[0]);