@puruslang/prettier-plugin-purus 0.7.1 → 0.8.0

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +28 -13
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@puruslang/prettier-plugin-purus",
3
- "version": "0.7.1",
3
+ "version": "0.8.0",
4
4
  "description": "Prettier plugin for the Purus language",
5
5
  "license": "Apache-2.0",
6
6
  "main": "src/index.js",
package/src/index.js CHANGED
@@ -4,25 +4,28 @@ const KEYWORDS = new Set([
4
4
  "const", "let", "var", "be",
5
5
  "fn", "async", "return", "to", "gives",
6
6
  "if", "elif", "else", "unless", "then",
7
- "while", "until", "for", "in", "range",
8
- "match", "when", "witch", "case",
7
+ "while", "until", "do", "for", "in", "range",
8
+ "match", "when", "switch", "case",
9
9
  "try", "catch", "finally", "throw",
10
10
  "import", "from", "export", "default", "require", "use", "namespace", "public", "all", "with",
11
- "add", "sub", "mul", "div", "mod", "neg", "pow",
11
+ "add", "sub", "mul", "div", "fdiv", "mod", "neg", "pow",
12
12
  "eq", "neq", "lt", "gt", "le", "ge",
13
13
  "and", "or", "not", "pipe", "coal",
14
- "is", "as", "of", "typeof", "instanceof", "type",
15
- "new", "delete", "this", "await",
16
- "class", "extends", "super", "static", "private", "get", "set",
17
- "true", "false", "null", "nil", "undefined", "nan",
14
+ "band", "bor", "bxor", "bnot", "shl", "shr", "ushr",
15
+ "as", "of", "typeof", "instanceof", "type",
16
+ "new", "delete", "this", "await", "yield", "void",
17
+ "class", "extends", "super", "static", "private", "protected", "get", "set",
18
+ "true", "false", "null", "nil", "undefined", "nan", "infinity",
18
19
  "break", "continue",
19
20
  "list", "object",
21
+ "function",
20
22
  ]);
21
23
 
22
24
  const BLOCK_STARTERS = new Set([
23
25
  "fn", "if", "elif", "else", "unless",
24
- "while", "until", "for",
25
- "match", "when", "witch", "case",
26
+ "while", "until", "do", "for",
27
+ "match", "when", "switch", "case",
28
+ "try", "catch", "finally", "class",
26
29
  ]);
27
30
 
28
31
  function tokenize(source) {
@@ -136,13 +139,25 @@ function tokenize(source) {
136
139
  continue;
137
140
  }
138
141
 
139
- // Number
142
+ // Number (decimal, 0b binary, 0x hex, BigInt n-suffix)
140
143
  if (/[0-9]/.test(source[i])) {
141
144
  let start = i;
142
- while (i < len && /[0-9]/.test(source[i])) i++;
143
- if (i < len && source[i] === "." && i + 1 < len && /[0-9]/.test(source[i + 1])) {
144
- i++;
145
+ if (source[i] === "0" && i + 1 < len && (source[i + 1] === "b" || source[i + 1] === "B")) {
146
+ i += 2;
147
+ while (i < len && /[01]/.test(source[i])) i++;
148
+ } else if (source[i] === "0" && i + 1 < len && (source[i + 1] === "x" || source[i + 1] === "X")) {
149
+ i += 2;
150
+ while (i < len && /[0-9a-fA-F]/.test(source[i])) i++;
151
+ } else {
145
152
  while (i < len && /[0-9]/.test(source[i])) i++;
153
+ if (i < len && source[i] === "." && i + 1 < len && /[0-9]/.test(source[i + 1])) {
154
+ i++;
155
+ while (i < len && /[0-9]/.test(source[i])) i++;
156
+ }
157
+ }
158
+ // BigInt suffix: n
159
+ if (i < len && source[i] === "n" && (i + 1 >= len || !/[a-zA-Z0-9_]/.test(source[i + 1]))) {
160
+ i++;
146
161
  }
147
162
  tokens.push({ type: "number", value: source.slice(start, i) });
148
163
  continue;