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
{feature} place number suffix parsing behind a flag
Number suffix parsing was added as an experiment, and the
experimental implementation is very unlikely to resemble
what will finally land in the spec.
The 0.4 release is stuck on pre-releases as long as it
deviates from the spec, so hiding this deviation behind a
flag makes it possible to release 0.4.0 without waiting
on the spec to land the number suffix PR.
Copy file name to clipboardExpand all lines: documentation/src/api/parse.md
+29Lines changed: 29 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -52,6 +52,35 @@ The pride flag that consists of four code points is a single grapheme.
52
52
Tracking by code points is the default for the simple reason that it seems to match how columns are tracked in editors like VS Code or Zed.
53
53
There's also a 6.5x speed difference between the two methods, but even with `graphemeLocations` enabled the parser succeeds in parsing thousands of documents per second.
54
54
55
+
## Parser flags
56
+
57
+
The `parse` function accepts optional flags to define parser behaviour.
58
+
There is currently a single flag:
59
+
60
+
-[`experimentalSuffixedNumbers`](./reference/index/index.md#experimentalsuffixednumbers): if enabled, numbers can have a suffix tag (e.g. `10px` is equivalent to `(px)10`).
61
+
This suffix is used as tag for the value, which implies a number cannot have both a tag and a suffix.
62
+
The following limitations apply unless a `#` is used as separator:
63
+
64
+
- Binary, octal, and hexadecimal numbers cannot have a suffix, only decimal numbers
65
+
- Decimal numbers cannot have both an exponent and a suffix, e.g. `1e1lorem` is invalid
66
+
- A suffix cannot start with a letter followed by a digit or an underscore (`_`)
67
+
- A suffix cannot start with `x` or `X` followed by the letter a through f or A through F
68
+
- A suffix cannot start on a dot (`.`) or comma (`,`)
69
+
70
+
```js
71
+
import {parse} from"@bgotink/kdl";
72
+
73
+
assert.throws(() =>parse("node 10px"));
74
+
75
+
assert.doesNotThrow(() =>
76
+
parse("node 10px", {
77
+
flags: {
78
+
experimentalSuffixedNumbers:true,
79
+
},
80
+
}),
81
+
);
82
+
```
83
+
55
84
## Quirks
56
85
57
86
This package turns KDL documents into JavaScript objects and vice versa. It is therefore limited by the JavaScript language.
0 commit comments