Repository navigation
Fix #209: Syntax Highlighting for GitHub #283
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # Copyright 2026 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # https://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| load("@rules_python//python:py_test.bzl", "py_test") | ||
|
|
||
| package(default_visibility = ["//visibility:public"]) | ||
|
|
||
| exports_files(["emboss.tmLanguage.json"]) | ||
|
|
||
| py_test( | ||
| name = "textmate_test", | ||
| srcs = ["textmate_test.py"], | ||
| data = ["emboss.tmLanguage.json"], | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| # TextMate Grammar for Emboss | ||
|
|
||
| This directory contains the TextMate grammar (`emboss.tmLanguage.json`) for the Emboss language. | ||
|
|
||
| It provides syntax highlighting for tools that support TextMate grammars, such as: | ||
| - VS Code (via extensions) | ||
| - GitHub (via Linguist) | ||
| - Sublime Text | ||
|
|
||
| To add Emboss syntax highlighting to GitHub, this file can be used by GitHub's [Linguist](https://github.com/github-linguist/linguist) library. |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,160 @@ | ||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||
| "name": "Emboss", | ||||||||||||||||||||||||||||||||||||||||||||
| "scopeName": "source.emboss", | ||||||||||||||||||||||||||||||||||||||||||||
| "fileTypes": [ | ||||||||||||||||||||||||||||||||||||||||||||
| "emb" | ||||||||||||||||||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||||||||||||||||||
| "patterns": [ | ||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||
| "include": "#strings" | ||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||
| "include": "#comments" | ||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||
| "include": "#doc-comments" | ||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||
| "include": "#keywords" | ||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||
| "include": "#builtins" | ||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||
| "include": "#types" | ||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||
| "include": "#constants" | ||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||
| "include": "#numbers" | ||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||
| "include": "#operators" | ||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||
| "include": "#punctuation" | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+31
to
+37
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||||||||||||||||||
| "repository": { | ||||||||||||||||||||||||||||||||||||||||||||
| "comments": { | ||||||||||||||||||||||||||||||||||||||||||||
| "patterns": [ | ||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||
| "name": "comment.line.number-sign.emboss", | ||||||||||||||||||||||||||||||||||||||||||||
| "match": "#.*$" | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||
| "doc-comments": { | ||||||||||||||||||||||||||||||||||||||||||||
| "patterns": [ | ||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||
| "name": "comment.line.double-dash.documentation.emboss", | ||||||||||||||||||||||||||||||||||||||||||||
| "match": "--(?: .*|)$" | ||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||
| "name": "invalid.illegal.documentation.emboss", | ||||||||||||||||||||||||||||||||||||||||||||
| "match": "--[^ ].*$" | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||
| "strings": { | ||||||||||||||||||||||||||||||||||||||||||||
| "patterns": [ | ||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||
| "name": "string.quoted.double.emboss", | ||||||||||||||||||||||||||||||||||||||||||||
| "begin": "\"", | ||||||||||||||||||||||||||||||||||||||||||||
| "end": "\"", | ||||||||||||||||||||||||||||||||||||||||||||
| "patterns": [ | ||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||
| "name": "constant.character.escape.emboss", | ||||||||||||||||||||||||||||||||||||||||||||
| "match": "\\\\[n\\\\\"]" | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||
| "keywords": { | ||||||||||||||||||||||||||||||||||||||||||||
| "patterns": [ | ||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||
| "name": "keyword.control.emboss", | ||||||||||||||||||||||||||||||||||||||||||||
| "match": "\\b(struct|enum|bits|external|import|as|if|let)\\b" | ||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+78
to
+81
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The keyword {
"name": "keyword.control.emboss",
"match": "\\b(struct|enum|bits|external|import|as|if|let)\\b"
}, |
||||||||||||||||||||||||||||||||||||||||||||
| "name": "constant.language.emboss", | ||||||||||||||||||||||||||||||||||||||||||||
| "match": "\\b(true|false)\\b" | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||
| "builtins": { | ||||||||||||||||||||||||||||||||||||||||||||
| "patterns": [ | ||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||
| "name": "variable.language.emboss", | ||||||||||||||||||||||||||||||||||||||||||||
| "match": "(?<!\\w)(\\$default|\\$static_size_in_bits|\\$is_statically_sized|\\$next|\\$max|\\$present|\\$upper_bound|\\$lower_bound)\\b" | ||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+90
to
+93
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The builtins list includes {
"name": "variable.language.emboss",
"match": "(?<!\\w)(\\$default|\\$static_size_in_bits|\\$is_statically_sized|\\$next|\\$max|\\$present|\\$upper_bound|\\$lower_bound)\\b"
}, |
||||||||||||||||||||||||||||||||||||||||||||
| "name": "variable.other.emboss", | ||||||||||||||||||||||||||||||||||||||||||||
| "match": "(?<!\\w)(\\$size_in_bits|\\$size_in_bytes|\\$max_size_in_bits|\\$max_size_in_bytes|\\$min_size_in_bits|\\$min_size_in_bytes)\\b" | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||
| "types": { | ||||||||||||||||||||||||||||||||||||||||||||
| "patterns": [ | ||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||
| "name": "entity.name.type.emboss", | ||||||||||||||||||||||||||||||||||||||||||||
| "match": "\\b[A-Z][a-zA-Z0-9]*[a-z][a-zA-Z0-9]*\\b" | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||
| "constants": { | ||||||||||||||||||||||||||||||||||||||||||||
| "patterns": [ | ||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||
| "name": "variable.other.constant.emboss", | ||||||||||||||||||||||||||||||||||||||||||||
| "match": "\\b[A-Z][A-Z_0-9]*[A-Z_][A-Z_0-9]*\\b" | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||
| "numbers": { | ||||||||||||||||||||||||||||||||||||||||||||
| "patterns": [ | ||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||
| "name": "constant.numeric.hex.emboss", | ||||||||||||||||||||||||||||||||||||||||||||
| "match": "\\b0[xX](?:[0-9a-fA-F]+|_?[0-9a-fA-F]{1,4}(?:_[0-9a-fA-F]{4})*|_?[0-9a-fA-F]{1,8}(?:_[0-9a-fA-F]{8})*)\\b" | ||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||
| "name": "constant.numeric.binary.emboss", | ||||||||||||||||||||||||||||||||||||||||||||
| "match": "\\b0[bB](?:[01]+|_?[01]{1,4}(?:_[01]{4})*|_?[01]{1,8}(?:_[01]{8})*)\\b" | ||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||
| "name": "constant.numeric.decimal.emboss", | ||||||||||||||||||||||||||||||||||||||||||||
| "match": "\\b(?:\\d+|\\d{1,3}(?:_\\d{3})+)\\b" | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+118
to
+128
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The number regexes do not fully align with the Emboss compiler's tokenizer:
Updating these regexes ensures accurate syntax highlighting that matches the compiler's behavior.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||
| "operators": { | ||||||||||||||||||||||||||||||||||||||||||||
| "patterns": [ | ||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||
| "name": "keyword.operator.emboss", | ||||||||||||||||||||||||||||||||||||||||||||
| "match": "==|!=|<=|>=|<|>|&&|\\|\\||\\+|-|\\*|\\?|=" | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||
| "punctuation": { | ||||||||||||||||||||||||||||||||||||||||||||
| "patterns": [ | ||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||
| "name": "punctuation.separator.emboss", | ||||||||||||||||||||||||||||||||||||||||||||
| "match": "[:,]" | ||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||
| "name": "punctuation.section.brackets.emboss", | ||||||||||||||||||||||||||||||||||||||||||||
| "match": "\\[|\\]" | ||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||
| "name": "punctuation.section.parens.emboss", | ||||||||||||||||||||||||||||||||||||||||||||
| "match": "\\(|\\)" | ||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||
| "name": "punctuation.accessor.emboss", | ||||||||||||||||||||||||||||||||||||||||||||
| "match": "\\." | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+134
to
+156
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+131
to
+158
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding explicit highlighting for punctuation (such as colons, commas, brackets, parentheses, and member access dots) will significantly improve the readability and visual structure of Emboss code in editors like VS Code and GitHub. "operators": {
"patterns": [
{
"name": "keyword.operator.emboss",
"match": "==|!=|<=|>=|<|>|&&|\\|\\||\\+|-|\\*|="
}
]
},
"punctuation": {
"patterns": [
{
"name": "punctuation.separator.emboss",
"match": "[:|,]"
},
{
"name": "punctuation.section.brackets.emboss",
"match": "\\\\[|\\\\]"
},
{
"name": "punctuation.section.parens.emboss",
"match": "\\\\(|\\\\)"
},
{
"name": "punctuation.accessor.emboss",
"match": "\\\\."
}
]
} |
||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| # Copyright 2026 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # https://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import json | ||
| import os | ||
| import re | ||
| import unittest | ||
|
|
||
|
|
||
| class TextmateTest(unittest.TestCase): | ||
| @classmethod | ||
| def setUpClass(cls): | ||
| super().setUpClass() | ||
| json_path = os.path.join(os.path.dirname(__file__), "emboss.tmLanguage.json") | ||
| with open(json_path, encoding="utf-8") as f: | ||
| cls.data = json.load(f) | ||
|
|
||
| def test_valid_json(self): | ||
| self.assertEqual(self.data.get("name"), "Emboss") | ||
| self.assertEqual(self.data.get("scopeName"), "source.emboss") | ||
| self.assertIn("emb", self.data.get("fileTypes", [])) | ||
|
|
||
| def test_all_includes_exist_and_regexes_compile(self): | ||
| repository = self.data.get("repository", {}) | ||
|
|
||
| def check_pattern(pattern): | ||
| if "include" in pattern: | ||
| include = pattern["include"] | ||
| if include.startswith("#"): | ||
| self.assertIn(include[1:], repository) | ||
| for regex_key in ("match", "begin", "end"): | ||
| if regex_key in pattern: | ||
| re.compile(pattern[regex_key]) | ||
| if "patterns" in pattern: | ||
| for p in pattern["patterns"]: | ||
| check_pattern(p) | ||
|
|
||
| if "patterns" in self.data: | ||
| for p in self.data["patterns"]: | ||
| check_pattern(p) | ||
| for val in repository.values(): | ||
| check_pattern(val) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the
patternsarray,#commentsand#doc-commentsare included before#strings. This causes any#or--character inside a double-quoted string literal to be incorrectly highlighted as a comment. Moving#stringsto the top of the patterns list ensures that string literals are matched first.