Skip to content

Commit

Permalink
feat: add Zig syntax highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
sebthom committed May 13, 2024
1 parent 88b3073 commit bfae038
Show file tree
Hide file tree
Showing 10 changed files with 476 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ This [EclipseⓇ](https://eclipse.org) plug-in adds syntax highlighting support
- Prisma - https://www.prisma.io/
- Svelte - https://svelte.dev/
- TOML - https://toml.io/en/
- Zig - https://ziglang.org/

For a lot more formats install the TM4E **Language Pack** from the TM4E update site https://download.eclipse.org/tm4e/releases/latest/

Expand Down Expand Up @@ -133,6 +134,7 @@ To install the plugin into an existing Eclipse installation do:
| Starlark <img src="plugin/syntaxes/bazel/icon.png" width=16/> | file-extensions="BUILD, WORKSPACE, bazel, bzl, bzlmod, sky, star"<br />file-names="BUILD, WORKSPACE" | [master@bazelbuild/vscode-bazel](https://github.com/bazelbuild/vscode-bazel/tree/60051c54854332f9a00891ebd6fa46ac08a4c577/)
| Svelte <img src="plugin/syntaxes/svelte/icon.png" width=16/> | file-extensions="svelte" | [master@sveltejs/language-tools](https://github.com/sveltejs/language-tools/tree/9d7907ef8b65efeda2698f61490b964d2f1a7069/packages/svelte-vscode)
| TOML Config File <img src="plugin/syntaxes/toml/icon.png" width=16/> | file-extensions="toml"<br />file-names="Cargo.lock, Pipfile, pdm.lock" | [master@juggernautjp/less-toml](https://github.com/juggernautjp/less-toml/tree/13eb891232e98c4a9c595bf8c657893c84edf3a9/) [[upstream]](https://github.com/textmate/toml.tmbundle/commit/e82b64c1e86396220786846201e9aa3f0a2d9ca2)
| Zig <img src="plugin/syntaxes/zig/icon.png" width=16/> | file-extensions="zig, zon" | [master@ziglang/vscode-zig](https://github.com/ziglang/vscode-zig/tree/ed1ad075696eb5a9ba0a98c96c3c8d9626eb78ee/)

<!-- END-GENERATED -->

Expand Down
24 changes: 24 additions & 0 deletions plugin/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1247,5 +1247,29 @@
<grammar scopeName="markdown.toml.codeblock" path="syntaxes/toml/markdown.toml.codeblock.tmLanguage.json" />
</extension>

<!-- ======================================== -->
<!-- zig/zig: Zig -->
<!-- ======================================== -->
<extension point="org.eclipse.core.contenttype.contentTypes">
<content-type id="extra-syntax-highlighting.zig" name="Zig" base-type="extra-syntax-highlighting.basetype" priority="normal"
file-extensions="zig,zon" />
</extension>
<extension point="org.eclipse.tm4e.registry.grammars">
<grammar scopeName="source.zig" path="syntaxes/zig/zig.tmLanguage.json" />
<scopeNameContentTypeBinding scopeName="source.zig" contentTypeId="extra-syntax-highlighting.zig" />
</extension>

<extension point="org.eclipse.tm4e.languageconfiguration.languageConfigurations">
<languageConfiguration contentTypeId="extra-syntax-highlighting.zig" path="syntaxes/zig/zig.language-configuration.json" />
</extension>

<extension point="org.eclipse.ui.genericeditor.icons">
<icon contentType="extra-syntax-highlighting.zig" icon="syntaxes/zig/icon.png"/>
</extension>

<extension point="org.eclipse.tm4e.ui.snippets">
<snippet name="Zig Example" path="syntaxes/zig/zig.example.zig" scopeName="source.zig" />
</extension>

<!-- END-GENERATED -->
</plugin>
21 changes: 21 additions & 0 deletions plugin/syntaxes/zig/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2017 Marc Tiehuis

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
Binary file added plugin/syntaxes/zig/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added plugin/syntaxes/zig/icon@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 47 additions & 0 deletions plugin/syntaxes/zig/zig.example.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const std = @import("std");

pub fn main() !void {
// Declarations
const name: []const u8 = "Zig";
var age: u8 = 5;

// Print statements
std.debug.print("Hello, {}!\n", .{name});
std.debug.print("I am {} years old.\n", .{age});

// Control flow
if (age >= 18) {
std.debug.print("I am an adult.\n");
} else {
std.debug.print("I am still a child.\n");
}

// Looping
var i: u8 = 0;
while (i < 5) : (i += 1) {
std.debug.print("Counting: {}\n", .{i});
}

// Function definition
fn add(x: i32, y: i32) i32 {
return x + y;
}

// Function call
const sum = add(3, 5);
std.debug.print("The sum is: {}\n", .{sum});

// Error handling
const result = divide(10, 0);
try std.debug.print("Result: {}\n", .{result});
catch |err| {
std.debug.print("Error: {}\n", .{err});
}
}

fn divide(x: i32, y: i32) !i32 {
if (y == 0) {
return std.zig.err.InvalidInteger("Division by zero");
}
return x / y;
}
53 changes: 53 additions & 0 deletions plugin/syntaxes/zig/zig.language-configuration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"comments": {
"lineComment": "//"
},
"brackets": [
["{", "}"],
["[", "]"],
["(", ")"]
],
"autoClosingPairs": [
["{", "}"],
["[", "]"],
["(", ")"],
["\"", "\""],
["'", "'"]
],
"surroundingPairs": [
["{", "}"],
["[", "]"],
["(", ")"],
["\"", "\""],
["'", "'"]
],
"folding": {
"markers": {
"start": "// zig fmt: off\\b",
"end": "// zig fmt: on\\b"
}
},
"onEnterRules": [
{
"beforeText": "^\\s*//!.*$",
"action": {
"indent": "none",
"appendText": "//! "
}
},
{
"beforeText": "^\\s*///.*$",
"action": {
"indent": "none",
"appendText": "/// "
}
},
{
"beforeText": "^\\s*\\\\\\\\.*$",
"action": {
"indent": "none",
"appendText": "\\\\"
}
}
]
}

0 comments on commit bfae038

Please sign in to comment.