Skip to content

Fix symbol list #67

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 31 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,52 +1,60 @@
Zig Language
============

Syntax highlighting for [Zig](http://ziglang.org/).
Syntax highlighting for [Zig](http://ziglang.org/)
for [Sublime Text](sublimetext.com/) editor.
Use [Package control](https://packagecontrol.io) to install this.

This repository serves both as the grammar for
[github/linguist](https://github.com/github/linguist) (Github's site wide
syntax highlighting) and as a standalone Sublime Text package.
The two syntaxes
----------------

The source of truth is `Zig.YAML-tmLanguage`. This file is read by linguist
directly and used as the source to compile to `Zig.tmLanguage` using
[PackageDev](https://github.com/SublimeText/PackageDev) from within Sublime. Do
not edit `Zig.tmLanguage` directly.
Sublime Text 3 and above uses the `.sublime-syntax` file.
This is the one you should edit to improve Sublime Text support.
See [official docs](http://www.sublimetext.com/docs/3/syntax.html)

Installation
-----------
This repository also contains a `.tmLanguage` syntax for old versions of Sublime Text or TextMate.
This file is also used by **Github's syntax highlighting**:
[Github Linguist](https://github.com/github/linguist).

Use [Package control](https://packagecontrol.io).

Or add `Zig.tmLanguage` to the packages directory. On OSX This is usually
Sublime text Installation
-----------

```
~/Library/Application\ Support/Sublime\ Text\ 3/Packages/
```
Use [Package control](https://packagecontrol.io) to install this.

But to find the path on your machine go to `Preferences > Browse Packages` from
within Sublime Text.

TextMate Installation
---------------------

This language is also compatible with TextMate's `.tmBundle` format. To install in TextMate clone or download this repository. Then rename the repository directory to `Zig.tmBundle` and double-click it to install it into TextMate. However, see [Zig.tmbundle](https://github.com/ziglang/Zig.tmbundle) for dedicated TextMate support.
The `Zig.tmLanguage` is also compatible with TextMate.
To install in TextMate clone or download this repository.
Then rename the repository directory to `Zig.tmBundle` and double-click it to install it into TextMate.
However, see [Zig.tmbundle](https://github.com/ziglang/Zig.tmbundle) for dedicated TextMate support.

Local Development
-----------------

Install https://github.com/SublimeText/PackageDev.

Clone or copy this repository to your local Sublime Text folder. e.g.

```
git clone https://github.com/ziglang/sublime-zig-language.git "/Users/$USER/Library/Application Support/Sublime Text 3/Packages/Zig Language"
```

Edit the YAML entry and use the `Convert (YAML, JSON, PList) to...` command
to generate the other entries. Sublime Text will automatically reload the plugin, showing changes in the build system, syntax highlighting, etc.
For working on ST3+ support, you can edit the `.sublime-syntax` directly.
But installing [PackageDev](https://packagecontrol.io/packages/PackageDev)
will provide some syntax highlighting.
You can run the tests in [syntax_test.zig](./Syntaxes/syntax_test.zig)
with the "Syntax Tests" builtin build system.
Sublime Text will automatically reload the syntax on save.
If you have a big Zig project open this can make your CPU spin while Sublime reindex everything.


For working on the old `.tmLanguage` syntax, work on the `Zig.YAML-tmLanguage` file.
**Important** Github Linguist's source of truth is `Zig.YAML-tmLanguage`.
Work on `Zig.YAML-tmLanguage` the use PackageDev command: `Convert (YAML, JSON, PList) to...`
to generate the `.tmLanguage`.
Sublime Text should also automatically reload the plugin, but doesn't have unit tests for `tmLanguage`.

On Linux, this is located under `~/.config/sublime-text-3/`.

Build System
------------
Expand Down
99 changes: 55 additions & 44 deletions Syntaxes/Zig.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,25 @@ file_extensions:
scope: source.zig
contexts:
main:
- include: dummy_main
- include: label
- include: function_type
- include: punctuation
- include: storage_modifier
- include: container_decl
- include: constants
- include: comments
- include: strings
- include: test
- include: storage
- include: keywords
- include: operators
- include: support
- include: field_decl
- include: block
- include: function_def
- include: function_call
- include: enum_literal
- include: variables
block:
- match: '([a-zA-Z_][\w.]*|@\".+\")?\s*(\{)'
captures:
Expand All @@ -18,7 +36,7 @@ contexts:
captures:
1: punctuation.section.braces.end.zig
pop: true
- include: dummy_main
- include: main
character_escapes:
- match: \\n
scope: constant.character.escape.newline.zig
Expand Down Expand Up @@ -69,37 +87,18 @@ contexts:
scope: constant.numeric.float.hexadecimal.zig
container_decl:
- match: '\b(?!\d)([a-zA-Z_]\w*|@\".+\")?(?=\s*=\s*(?:extern|packed)?\b\s*(?:union)\s*[(\{])'
scope: entity.name.union.zig
scope: entity.name.class.union.zig
- match: '\b(?!\d)([a-zA-Z_]\w*|@\".+\")?(?=\s*=\s*(?:extern|packed)?\b\s*(?:struct)\s*[(\{])'
scope: entity.name.struct.zig
scope: entity.name.class.struct.zig
- match: '\b(?!\d)([a-zA-Z_]\w*|@\".+\")?(?=\s*=\s*(?:extern|packed)?\b\s*(?:enum)\s*[(\{])'
scope: entity.name.enum.zig
scope: entity.name.class.enum.zig
- match: '\b(?!\d)([a-zA-Z_]\w*|@\".+\")?(?=\s*=\s*(?:error)\s*[(\{])'
scope: entity.name.error.zig
scope: entity.name.class.error.zig
- match: '\b(error)(\.)([a-zA-Z_]\w*|@\".+\")'
captures:
1: storage.type.error.zig
2: punctuation.accessor.zig
3: entity.name.error.zig
dummy_main:
- include: label
- include: function_type
- include: punctuation
- include: storage_modifier
- include: container_decl
- include: constants
- include: comments
- include: strings
- include: storage
- include: keywords
- include: operators
- include: support
- include: field_decl
- include: block
- include: function_def
- include: function_call
- include: enum_literal
- include: variables
3: constant.other.error.zig
enum_literal:
- match: '(^|\s+)(\.(?:[a-zA-Z_]\w*\b|@\"[^\"]*\"))(?!\(|\s*=[^=>])'
scope: constant.language.enum
Expand All @@ -115,14 +114,14 @@ contexts:
2: punctuation.separator.zig
3: keyword.operator.assignment.zig
pop: true
- include: dummy_main
- include: main
function_call:
- match: '\b([a-zA-Z_]\w*|@\".+\")(?=\s*\()'
scope: variable.function.zig
scope: meta.function-call.zig variable.function.zig
function_def:
- match: '\b(fn)\s+([a-zA-Z_]\w*|@\".+\")(\()'
captures:
1: storage.type.function.zig
1: keyword.declaration.function.zig
2: entity.name.function
3: punctuation.section.parens.begin.zig
push:
Expand All @@ -133,7 +132,7 @@ contexts:
- match: '\)'
scope: punctuation.section.parens.end.zig
set: function_def_after_params
- include: dummy_main
- include: main
function_def_after_params:
# TODO: be more precise here
- match: '\s*([a-zA-Z_][\w.]*|@\".+\")?(!)?\s*(?:([a-zA-Z_][\w.]*|@\".+\")\b(?!\s*\())?'
Expand All @@ -148,7 +147,7 @@ contexts:
function_type:
- match: \b(fn)\s*(\()
captures:
1: storage.type.function.zig
1: keyword.declaration.function.zig
2: punctuation.section.parens.begin.zig
push:
- meta_content_scope: meta.function.parameters.zig
Expand All @@ -159,7 +158,7 @@ contexts:
- match: '\)'
scope: punctuation.section.parens.end.zig
set: function_type_after_params
- include: dummy_main
- include: main
function_type_after_params:
# TODO: Can we merge with function_def_after_params ? It seems similar.
- match: '\s*([a-zA-Z_][\w.]*|@\".+\")?\s*(!)?\s*([a-zA-Z_][\w.]*|@\".+\")'
Expand Down Expand Up @@ -190,12 +189,17 @@ contexts:
operators:
- match: \b!\b
scope: keyword.operator.zig
- match: '((?:(?:\+|-|\*)%?|/|%|<<|>>|&|\|(?=[^\|])|\^)=)'
scope: keyword.operator.assignment.zig
# The => is for switch expression, I'm not sure this is the best scope.
- match: '=>'
scope: keyword.operator.assignment.zig
- match: (==|(?:!|>|<)=?)
scope: keyword.operator.logical.zig
- match: '='
scope: keyword.operator.assignment.zig
- match: \b(and|or)\b
scope: keyword.operator.word.zig
- match: '((?:(?:\+|-|\*)\%?|/|%|<<|>>|&|\|(?=[^\|])|\^)?=)'
scope: keyword.operator.assignment.zig
- match: ((?:\+|-|\*)\%?|/(?!/)|%)
scope: keyword.operator.arithmetic.zig
- match: '(<<|>>|&(?=[a-zA-Z_]|@\")|\|(?=[^\|])|\^|~)'
Expand All @@ -215,7 +219,7 @@ contexts:
2: punctuation.separator.zig
3: punctuation.section.parens.end.zig
pop: true
- include: dummy_main
- include: main
- match: '([a-zA-Z_][\w.]*|@\".+\")'
scope: storage.type.zig
punctuation:
Expand All @@ -230,19 +234,19 @@ contexts:
storage:
- match: '\b(anyframe)\b\s*(->)?\s*(?:([a-zA-Z_][\w.]*|@\".+\")\b(?!\s*\())?'
captures:
1: storage.type.zig
1: keyword.declaration.anyframe.zig
2: keyword.operator.zig
3: storage.type.zig
3: keyword.declaration.zig
- match: \btest\b
scope: storage.type.test.zig
scope: keyword.declaration.test.zig
- match: \bstruct\b
scope: storage.type.struct.zig
scope: keyword.declaration.struct.zig
- match: \benum\b
scope: storage.type.enum.zig
scope: keyword.declaration.enum.zig
- match: \bunion\b
scope: storage.type.union.zig
scope: keyword.declaration.union.zig
- match: \berror\b
scope: storage.type.error.zig
scope: keyword.declaration.error.zig
storage_modifier:
- match: \b(const|var|extern|packed|export|pub|noalias|inline|noinline|comptime|volatile|align|linksection|threadlocal|allowzero)\b
scope: storage.modifier.zig
Expand Down Expand Up @@ -276,11 +280,18 @@ contexts:
scope: variable.constant.zig

- match: '\b[_a-zA-Z][_a-zA-Z0-9]*_t\b'
scope: entity.name.type.zig
scope: storage.type.zig

- match: '\b[A-Z][a-zA-Z0-9]*\b'
scope: entity.name.type.zig
scope: storage.type.zig

- match: '\b[_a-zA-Z][_a-zA-Z0-9]*\b'
scope: variable.zig

test:
- match: \b(test)\b\s+(\")(.*)(\")
captures:
0: entity.name.function.test.zig
1: keyword.declaration.test.zig
2: punctuation.string.start.zig
4: punctuation.string.end.zig
Loading