codemirror-mode-zig 1.0.8 → 1.0.11

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.
@@ -13,6 +13,7 @@ jobs:
13
13
  permissions:
14
14
  contents: read
15
15
  id-token: write
16
+ attestations: write
16
17
  steps:
17
18
  - uses: actions/checkout@v4
18
19
  - uses: actions/setup-node@v4
@@ -20,6 +21,11 @@ jobs:
20
21
  node-version: "20.x"
21
22
  registry-url: "https://registry.npmjs.org"
22
23
  - run: npm ci
24
+ - run: npm pack
25
+ - name: Attest package
26
+ uses: actions/attest-build-provenance@v1
27
+ with:
28
+ subject-path: "*.tgz"
23
29
  - run: npm publish --provenance
24
30
  env:
25
31
  NODE_AUTH_TOKEN: ${{secrets.npm_token}}
@@ -29,6 +35,7 @@ jobs:
29
35
  contents: read
30
36
  id-token: write
31
37
  packages: write
38
+ attestations: write
32
39
  steps:
33
40
  - uses: actions/checkout@v4
34
41
  - uses: actions/setup-node@v4
@@ -37,6 +44,11 @@ jobs:
37
44
  always-auth: true
38
45
  registry-url: "https://npm.pkg.github.com"
39
46
  - run: npm ci
47
+ - run: npm pack
48
+ - name: Attest package
49
+ uses: actions/attest-build-provenance@v1
50
+ with:
51
+ subject-path: "*.tgz"
40
52
  - run: |
41
53
  npm pkg set name="@imkylecat/codemirror-mode-zig"
42
54
  npm publish --provenance --access public --registry https://npm.pkg.github.com
Binary file
package/index.html ADDED
@@ -0,0 +1,74 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <title>CodeMirror Demo</title>
7
+ <link
8
+ rel="stylesheet"
9
+ href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.20/codemirror.min.css"
10
+ />
11
+ <style>
12
+ .CodeMirror {
13
+ height: auto;
14
+ border: 1px solid #ddd;
15
+ }
16
+ </style>
17
+ </head>
18
+ <body>
19
+ <textarea id="code" name="code">// Hello World in Zig with various features
20
+ const std = @import("std");
21
+
22
+ // This is a single-line comment
23
+ pub fn main() !void {
24
+ // Get stdout for printing
25
+ const stdout = std.io.getStdOut().writer();
26
+
27
+ // String example
28
+ const greeting = "Hello, World!";
29
+
30
+ // Number examples
31
+ const answer: i32 = 42;
32
+ const pi: f64 = 3.14159;
33
+ const hex_value = 0xFF;
34
+
35
+ // Print the greeting
36
+ try stdout.print("{s}\n", .{greeting});
37
+
38
+ // Print numbers
39
+ try stdout.print("The answer is: {d}\n", .{answer});
40
+ try stdout.print("Pi is approximately: {d}\n", .{pi});
41
+ try stdout.print("Hex value: 0x{X}\n", .{hex_value});
42
+
43
+ // Conditional example
44
+ if (answer == 42) {
45
+ try stdout.print("That's the answer!\n", .{});
46
+ } else {
47
+ try stdout.print("Wrong answer!\n", .{});
48
+ }
49
+
50
+ // Loop example
51
+ var i: usize = 0;
52
+ while (i < 3) : (i += 1) {
53
+ try stdout.print("Loop iteration: {d}\n", .{i});
54
+ }
55
+
56
+ // For loop
57
+ for (0..5) |num| {
58
+ try stdout.print("For loop: {d}\n", .{num});
59
+ }
60
+ }
61
+ </textarea>
62
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.20/codemirror.min.js"></script>
63
+ <script src="./index.js"></script>
64
+ <script>
65
+ var editor = CodeMirror.fromTextArea(
66
+ document.getElementById("code"),
67
+ {
68
+ lineNumbers: true,
69
+ mode: "zig",
70
+ }
71
+ );
72
+ </script>
73
+ </body>
74
+ </html>
package/index.js CHANGED
@@ -2,71 +2,101 @@ import CodeMirror from "codemirror";
2
2
 
3
3
  CodeMirror.defineMode("zig", function () {
4
4
  var keywords = {
5
- const: true,
6
- var: true,
7
- extern: true,
8
- packed: true,
9
- export: true,
10
- pub: true,
11
- noalias: true,
12
- inline: true,
13
- comptime: true,
14
- test: true,
15
- fn: true,
16
- usingnamespace: true,
17
- struct: true,
18
- enum: true,
19
- union: true,
20
- if: true,
21
- else: true,
22
- switch: true,
23
- while: true,
24
- for: true,
25
- break: true,
26
- continue: true,
27
- return: true,
28
- defer: true,
29
- errdefer: true,
30
- as: true,
31
- null: true,
5
+ const: true, var: true, fn: true, pub: true, extern: true, export: true,
6
+ packed: true, inline: true, noinline: true, comptime: true, noalias: true,
7
+ struct: true, enum: true, union: true, opaque: true, error: true,
8
+ if: true, else: true, switch: true, and: true, or: true, orelse: true,
9
+ while: true, for: true, break: true, continue: true, return: true,
10
+ defer: true, errdefer: true, async: true, await: true, suspend: true,
11
+ resume: true, nosuspend: true, try: true, catch: true, test: true,
12
+ usingnamespace: true, threadlocal: true, allowzero: true, volatile: true,
13
+ align: true, callconv: true, linksection: true, addrspace: true,
14
+ anyframe: true, asm: true, unreachable: true
32
15
  };
33
16
 
34
- var isOperatorChar = /[+\-*&%=<>!?|]/;
17
+ var atoms = {
18
+ true: true, false: true, null: true, undefined: true
19
+ };
20
+
21
+ var types = {
22
+ i8: true, i16: true, i32: true, i64: true, i128: true, isize: true,
23
+ u8: true, u16: true, u32: true, u64: true, u128: true, usize: true,
24
+ f16: true, f32: true, f64: true, f80: true, f128: true,
25
+ c_char: true, c_short: true, c_int: true, c_long: true, c_longlong: true,
26
+ c_ushort: true, c_uint: true, c_ulong: true, c_ulonglong: true,
27
+ c_longdouble: true, bool: true, void: true, noreturn: true, type: true,
28
+ anyerror: true, comptime_int: true, comptime_float: true, anyopaque: true,
29
+ anytype: true
30
+ };
31
+
32
+ var isOperatorChar = /[+\-*&^%=<>!|\/]/;
35
33
 
36
34
  function tokenBase(stream, state) {
37
35
  var ch = stream.next();
38
- if (ch == '"') {
36
+
37
+ if (ch == '"' || ch == "'") {
39
38
  state.tokenize = tokenString(ch);
40
39
  return state.tokenize(stream, state);
41
40
  }
42
- if (/[\d]/.test(ch)) {
43
- stream.eatWhile(/[\w\.]/);
44
- return "number";
41
+
42
+ if (ch == "/" && stream.eat("/")) {
43
+ stream.skipToEnd();
44
+ return "comment";
45
+ }
46
+
47
+ if (ch == "@") {
48
+ stream.eatWhile(/[\w]/);
49
+ return "builtin";
45
50
  }
46
- if (/[\w_]/.test(ch)) {
47
- stream.eatWhile(/[\w_]/);
48
- var cur = stream.current();
49
- if (keywords.propertyIsEnumerable(cur)) {
50
- return "keyword";
51
+
52
+ if (/\d/.test(ch) || (ch == "." && /\d/.test(stream.peek()))) {
53
+ if (ch == "0") {
54
+ if (stream.eat(/[xX]/)) {
55
+ stream.eatWhile(/[\da-fA-F_]/);
56
+ } else if (stream.eat(/[oO]/)) {
57
+ stream.eatWhile(/[0-7_]/);
58
+ } else if (stream.eat(/[bB]/)) {
59
+ stream.eatWhile(/[01_]/);
60
+ } else {
61
+ stream.eatWhile(/[\d_]/);
62
+ }
63
+ } else {
64
+ stream.eatWhile(/[\d_]/);
65
+ }
66
+ if (stream.eat(".")) {
67
+ stream.eatWhile(/[\d_]/);
51
68
  }
69
+ if (stream.eat(/[eE]/)) {
70
+ stream.eat(/[+\-]/);
71
+ stream.eatWhile(/[\d_]/);
72
+ }
73
+ return "number";
74
+ }
75
+
76
+ if (/[a-zA-Z_]/.test(ch)) {
77
+ stream.eatWhile(/[\w]/);
78
+ var word = stream.current();
79
+ if (keywords.hasOwnProperty(word)) return "keyword";
80
+ if (atoms.hasOwnProperty(word)) return "atom";
81
+ if (types.hasOwnProperty(word)) return "type";
52
82
  return "variable";
53
83
  }
84
+
54
85
  if (isOperatorChar.test(ch)) {
55
86
  stream.eatWhile(isOperatorChar);
56
87
  return "operator";
57
88
  }
58
- if (ch == "/" && stream.eat("/")) {
59
- stream.skipToEnd();
60
- return "comment";
89
+
90
+ if (/[\(\)\[\]\{\}]/.test(ch)) {
91
+ return "bracket";
61
92
  }
93
+
62
94
  return null;
63
95
  }
64
96
 
65
97
  function tokenString(quote) {
66
98
  return function (stream, state) {
67
- var escaped = false,
68
- next,
69
- end = false;
99
+ var escaped = false, next, end = false;
70
100
  while ((next = stream.next()) != null) {
71
101
  if (next == quote && !escaped) {
72
102
  end = true;
@@ -86,12 +116,9 @@ CodeMirror.defineMode("zig", function () {
86
116
  return { tokenize: tokenBase };
87
117
  },
88
118
  token: function (stream, state) {
89
- if (stream.eatSpace()) {
90
- return null;
91
- }
92
- var style = state.tokenize(stream, state);
93
- return style;
94
- },
119
+ if (stream.eatSpace()) return null;
120
+ return state.tokenize(stream, state);
121
+ }
95
122
  };
96
123
  });
97
124
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codemirror-mode-zig",
3
- "version": "1.0.8",
3
+ "version": "1.0.11",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "keywords": [