textmate-bjolang: code highlighted as VS Code does, as Bjolang values
TextMateSharp runs VS Code's TextMate grammars and themes; this hands the result over once, as Bjolang values, so nothing using it needs to know TextMateSharp is there. `tokenize` gives each line's tokens and their scopes, `highlight` each line's spans in the theme's colours, and `highlight->node` and `code->node` give (text xml) nodes: a pre and a code element around spans, coloured inline by the theme or by class names taken from the scopes. `highlighter-css` writes the stylesheet for the classes from a theme, choosing each class's rule the way TextMateSharp's tokenizer chooses a token's. Bjolang's own grammar is in grammars/bjolang, laid out as a VS Code extension, and every highlighter reads it from beside the package's src/. It follows what Bjolang's reader reads, including interpolated strings with expressions in their holes. There is no C# shim: everything goes through import/class and import/extern. The package is kept within TextMateSharp 2.0, because token colours are decoded with a class in its Internal namespace. 🤖 Generated with [ECA](https://eca.dev) (anthropic/claude-opus-4-7) Co-Authored-By: eca-agent <git@eca.dev>
This commit is contained in:
commit
0ecc65e134
10 changed files with 2012 additions and 0 deletions
23
grammars/bjolang/language-configuration.json
Normal file
23
grammars/bjolang/language-configuration.json
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"comments": {
|
||||
"lineComment": ";"
|
||||
},
|
||||
"brackets": [
|
||||
["(", ")"],
|
||||
["[", "]"],
|
||||
["{", "}"]
|
||||
],
|
||||
"autoClosingPairs": [
|
||||
{ "open": "(", "close": ")" },
|
||||
{ "open": "[", "close": "]" },
|
||||
{ "open": "{", "close": "}" },
|
||||
{ "open": "\"", "close": "\"", "notIn": ["string", "comment"] }
|
||||
],
|
||||
"surroundingPairs": [
|
||||
["(", ")"],
|
||||
["[", "]"],
|
||||
["{", "}"],
|
||||
["\"", "\""]
|
||||
],
|
||||
"wordPattern": "[^\\s()\\[\\]{},:\"';]+"
|
||||
}
|
||||
28
grammars/bjolang/package.json
Normal file
28
grammars/bjolang/package.json
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
{
|
||||
"name": "bjolang",
|
||||
"displayName": "Bjolang",
|
||||
"description": "Syntax highlighting for Bjolang.",
|
||||
"version": "0.1.0",
|
||||
"publisher": "bjoli",
|
||||
"license": "MPL-2.0",
|
||||
"engines": {
|
||||
"vscode": "^1.60.0"
|
||||
},
|
||||
"contributes": {
|
||||
"languages": [
|
||||
{
|
||||
"id": "bjolang",
|
||||
"aliases": ["Bjolang", "bjolang", "bjo"],
|
||||
"extensions": [".bjo", ".protobjo"],
|
||||
"configuration": "./language-configuration.json"
|
||||
}
|
||||
],
|
||||
"grammars": [
|
||||
{
|
||||
"language": "bjolang",
|
||||
"scopeName": "source.bjolang",
|
||||
"path": "./syntaxes/bjolang.tmLanguage.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
410
grammars/bjolang/syntaxes/bjolang.tmLanguage.json
Normal file
410
grammars/bjolang/syntaxes/bjolang.tmLanguage.json
Normal file
|
|
@ -0,0 +1,410 @@
|
|||
{
|
||||
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
|
||||
"name": "Bjolang",
|
||||
"scopeName": "source.bjolang",
|
||||
"fileTypes": [
|
||||
"bjo",
|
||||
"protobjo"
|
||||
],
|
||||
"patterns": [
|
||||
{
|
||||
"include": "#forms"
|
||||
}
|
||||
],
|
||||
"repository": {
|
||||
"forms": {
|
||||
"patterns": [
|
||||
{
|
||||
"include": "#comment"
|
||||
},
|
||||
{
|
||||
"include": "#character"
|
||||
},
|
||||
{
|
||||
"include": "#boolean"
|
||||
},
|
||||
{
|
||||
"include": "#interpolated-string"
|
||||
},
|
||||
{
|
||||
"include": "#string"
|
||||
},
|
||||
{
|
||||
"include": "#hash-forms"
|
||||
},
|
||||
{
|
||||
"include": "#signature"
|
||||
},
|
||||
{
|
||||
"include": "#definition"
|
||||
},
|
||||
{
|
||||
"include": "#special-form"
|
||||
},
|
||||
{
|
||||
"include": "#keyword"
|
||||
},
|
||||
{
|
||||
"include": "#arrow"
|
||||
},
|
||||
{
|
||||
"include": "#member"
|
||||
},
|
||||
{
|
||||
"include": "#number"
|
||||
},
|
||||
{
|
||||
"include": "#type-variable"
|
||||
},
|
||||
{
|
||||
"include": "#quoted-symbol"
|
||||
},
|
||||
{
|
||||
"include": "#quote"
|
||||
},
|
||||
{
|
||||
"include": "#primitive-type"
|
||||
},
|
||||
{
|
||||
"include": "#type-name"
|
||||
},
|
||||
{
|
||||
"include": "#braces"
|
||||
},
|
||||
{
|
||||
"include": "#delimiter"
|
||||
}
|
||||
]
|
||||
},
|
||||
"comment": {
|
||||
"comment": "A ; comment runs to the end of the line. There are no block comments.",
|
||||
"match": "(;+).*$",
|
||||
"name": "comment.line.semicolon.bjolang",
|
||||
"captures": {
|
||||
"1": {
|
||||
"name": "punctuation.definition.comment.bjolang"
|
||||
}
|
||||
}
|
||||
},
|
||||
"character": {
|
||||
"comment": "#\\c, #\\space, #\\x41, #\\( — a name when more than one symbol character follows, otherwise the one character.",
|
||||
"match": "(?<![^\\s()\\[\\]{},:\"';])#\\\\(?:[^\\s()\\[\\]{},:\"';]{2,}|.)",
|
||||
"name": "constant.character.bjolang"
|
||||
},
|
||||
"boolean": {
|
||||
"match": "(?<![^\\s()\\[\\]{},:\"';])#[tf](?![^\\s()\\[\\]{},:\"';])",
|
||||
"name": "constant.language.boolean.bjolang"
|
||||
},
|
||||
"escape": {
|
||||
"patterns": [
|
||||
{
|
||||
"match": "\\\\[ntr\"\\\\]",
|
||||
"name": "constant.character.escape.bjolang"
|
||||
},
|
||||
{
|
||||
"comment": "An escape Bjolang does not define keeps both characters.",
|
||||
"match": "\\\\."
|
||||
}
|
||||
]
|
||||
},
|
||||
"string": {
|
||||
"begin": "\"",
|
||||
"beginCaptures": {
|
||||
"0": {
|
||||
"name": "punctuation.definition.string.begin.bjolang"
|
||||
}
|
||||
},
|
||||
"end": "\"",
|
||||
"endCaptures": {
|
||||
"0": {
|
||||
"name": "punctuation.definition.string.end.bjolang"
|
||||
}
|
||||
},
|
||||
"name": "string.quoted.double.bjolang",
|
||||
"patterns": [
|
||||
{
|
||||
"include": "#escape"
|
||||
}
|
||||
]
|
||||
},
|
||||
"interpolated-string": {
|
||||
"comment": "#\"a ${x} b\": a hole is any expression, interpolated strings and braces included.",
|
||||
"begin": "(?<![^\\s()\\[\\]{},:\"';])#\"",
|
||||
"beginCaptures": {
|
||||
"0": {
|
||||
"name": "punctuation.definition.string.begin.bjolang"
|
||||
}
|
||||
},
|
||||
"end": "\"",
|
||||
"endCaptures": {
|
||||
"0": {
|
||||
"name": "punctuation.definition.string.end.bjolang"
|
||||
}
|
||||
},
|
||||
"name": "string.interpolated.bjolang",
|
||||
"patterns": [
|
||||
{
|
||||
"match": "\\\\\\$",
|
||||
"name": "constant.character.escape.bjolang"
|
||||
},
|
||||
{
|
||||
"include": "#escape"
|
||||
},
|
||||
{
|
||||
"begin": "\\$\\{",
|
||||
"beginCaptures": {
|
||||
"0": {
|
||||
"name": "punctuation.section.embedded.begin.bjolang"
|
||||
}
|
||||
},
|
||||
"end": "\\}",
|
||||
"endCaptures": {
|
||||
"0": {
|
||||
"name": "punctuation.section.embedded.end.bjolang"
|
||||
}
|
||||
},
|
||||
"name": "meta.embedded.line.bjolang",
|
||||
"contentName": "source.bjolang",
|
||||
"patterns": [
|
||||
{
|
||||
"include": "#forms"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"hash-forms": {
|
||||
"patterns": [
|
||||
{
|
||||
"comment": "#[1 2 3], an array, and #(...).",
|
||||
"match": "(?<![^\\s()\\[\\]{},:\"';])#[\\[(]",
|
||||
"name": "punctuation.section.array.begin.bjolang"
|
||||
},
|
||||
{
|
||||
"comment": "#'(template), a syntax quote.",
|
||||
"match": "(?<![^\\s()\\[\\]{},:\"';])#'",
|
||||
"name": "keyword.operator.quote.bjolang"
|
||||
},
|
||||
{
|
||||
"comment": "#name( and #name[, a hash macro. #t( and #f( are booleans, which come first.",
|
||||
"match": "(?<![^\\s()\\[\\]{},:\"';])#[^\\s()\\[\\]{},:\"';]+(?=[\\[(])",
|
||||
"name": "entity.name.function.macro.bjolang"
|
||||
}
|
||||
]
|
||||
},
|
||||
"signature": {
|
||||
"comment": "(: name type). The colon alone, which is not a :keyword.",
|
||||
"patterns": [
|
||||
{
|
||||
"match": "(?<=\\()(:)\\s+([A-Z][^\\s()\\[\\]{},:\"';]*)",
|
||||
"captures": {
|
||||
"1": {
|
||||
"name": "keyword.other.signature.bjolang"
|
||||
},
|
||||
"2": {
|
||||
"name": "entity.name.type.bjolang"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"match": "(?<=\\()(:)\\s+([^\\s()\\[\\]{},:\"';]+)",
|
||||
"captures": {
|
||||
"1": {
|
||||
"name": "keyword.other.signature.bjolang"
|
||||
},
|
||||
"2": {
|
||||
"name": "entity.name.function.bjolang"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"match": "(?<=\\()(:)(?=\\s|\\()",
|
||||
"captures": {
|
||||
"1": {
|
||||
"name": "keyword.other.signature.bjolang"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"definition": {
|
||||
"patterns": [
|
||||
{
|
||||
"comment": "(defun (name args) ...): the name is inside the parameter list.",
|
||||
"match": "(?<=\\()(def/pattern|defbjouble|def/macro|defbjo|defun)(?![^\\s()\\[\\]{},:\"';])(?:\\s*(\\()\\s*([^\\s()\\[\\]{},:\"';]+))?",
|
||||
"captures": {
|
||||
"1": {
|
||||
"name": "storage.type.function.bjolang"
|
||||
},
|
||||
"2": {
|
||||
"name": "punctuation.section.parens.begin.bjolang"
|
||||
},
|
||||
"3": {
|
||||
"name": "entity.name.function.bjolang"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"comment": "(def/trait (Name %a) ...), (impl (Trait Type) ...).",
|
||||
"match": "(?<=\\()(impl/extern|type/derive|def/trait|impl)(?![^\\s()\\[\\]{},:\"';])(?:\\s*(\\()\\s*([^\\s()\\[\\]{},:\"';]+))?",
|
||||
"captures": {
|
||||
"1": {
|
||||
"name": "storage.type.bjolang"
|
||||
},
|
||||
"2": {
|
||||
"name": "punctuation.section.parens.begin.bjolang"
|
||||
},
|
||||
"3": {
|
||||
"name": "entity.name.type.bjolang"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"comment": "(def name value). A def whose pattern is a list names nothing here.",
|
||||
"match": "(?<=\\()(def/mutable|def)(?![^\\s()\\[\\]{},:\"';])(?:\\s+([^\\s()\\[\\]{},:\"';]+))?",
|
||||
"captures": {
|
||||
"1": {
|
||||
"name": "storage.type.bjolang"
|
||||
},
|
||||
"2": {
|
||||
"name": "entity.name.variable.bjolang"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"match": "(?<=\\()(def/json-type|type-rec|def\\*|type)(?![^\\s()\\[\\]{},:\"';])",
|
||||
"captures": {
|
||||
"1": {
|
||||
"name": "storage.type.bjolang"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"special-form": {
|
||||
"patterns": [
|
||||
{
|
||||
"match": "(?<=\\()(import/extern|import/class|prefix-types|postfix-defs|prefix-defs|re-export|include|postfix|import|export|except|rename|prefix|only)(?![^\\s()\\[\\]{},:\"';])",
|
||||
"captures": {
|
||||
"1": {
|
||||
"name": "keyword.control.import.bjolang"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"match": "(?<=\\()(spawn/detached|parameterize\\*|with-deadline|with-response|parameterize|syntax-match|syntax-quote|spawn/daemon|with-return|with-cancel|with-shield|record-set!|struct-set!|task->event|record-ref|record-set|struct-ref|struct-set|yield-from|bjoroutine|with-open|spawn-evt|let/mono|when-let|with-run|time-it|unless|letrec|if-let|some->|match|begin|yield|spawn|when|case|else|let\\*|loop|seql|set!|cast|cond|let|seq|try|fun|and|not|bjo|if|do|or)(?![^\\s()\\[\\]{},:\"';])",
|
||||
"captures": {
|
||||
"1": {
|
||||
"name": "keyword.control.bjolang"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"keyword": {
|
||||
"comment": "#:keyword and :keyword, which is also how loop clauses and def's failure parts are written.",
|
||||
"match": "#?:[^\\s()\\[\\]{},:\"';]+",
|
||||
"name": "variable.parameter.keyword.bjolang"
|
||||
},
|
||||
"arrow": {
|
||||
"comment": "->, -bjo-> (a bjoroutine), -?-> (either colour), and =>.",
|
||||
"match": "(?<![^\\s()\\[\\]{},:\"';])(?:->|-bjo->|-\\?->|=>)(?![^\\s()\\[\\]{},:\"';])",
|
||||
"name": "storage.type.function.arrow.bjolang"
|
||||
},
|
||||
"member": {
|
||||
"patterns": [
|
||||
{
|
||||
"match": "(?<![^\\s()\\[\\]{},:\"';])\\.\\.\\.(?![^\\s()\\[\\]{},:\"';])",
|
||||
"name": "keyword.operator.spread.bjolang"
|
||||
},
|
||||
{
|
||||
"comment": ".-Length, a .NET property or field.",
|
||||
"match": "(?<![^\\s()\\[\\]{},:\"';])\\.-[^\\s()\\[\\]{},:\"';]+",
|
||||
"name": "variable.other.property.bjolang"
|
||||
},
|
||||
{
|
||||
"comment": ".Write, a .NET method.",
|
||||
"match": "(?<![^\\s()\\[\\]{},:\"';])\\.[^\\s()\\[\\]{},:\\\"';.\\d][^\\s()\\[\\]{},:\"';]*",
|
||||
"name": "entity.name.function.member.bjolang"
|
||||
}
|
||||
]
|
||||
},
|
||||
"number": {
|
||||
"match": "(?<![^\\s()\\[\\]{},:\"';])-?\\d[\\w.\\-]*",
|
||||
"name": "constant.numeric.bjolang"
|
||||
},
|
||||
"type-variable": {
|
||||
"match": "(?<![^\\s()\\[\\]{},:\"';])%[^\\s()\\[\\]{},:\"';]+",
|
||||
"name": "entity.name.type.parameter.bjolang"
|
||||
},
|
||||
"quoted-symbol": {
|
||||
"match": "'[^\\s()\\[\\]{},:\"';]+",
|
||||
"name": "constant.language.symbol.bjolang"
|
||||
},
|
||||
"quote": {
|
||||
"patterns": [
|
||||
{
|
||||
"match": ",@",
|
||||
"name": "keyword.operator.unquote.bjolang"
|
||||
},
|
||||
{
|
||||
"match": ",",
|
||||
"name": "keyword.operator.unquote.bjolang"
|
||||
},
|
||||
{
|
||||
"match": "'",
|
||||
"name": "keyword.operator.quote.bjolang"
|
||||
}
|
||||
]
|
||||
},
|
||||
"primitive-type": {
|
||||
"match": "(?<![^\\s()\\[\\]{},:\"';])(?:decimal|ushort|double|string|short|ulong|sbyte|float|long|uint|byte|bool|char|void|unit|int)(?![^\\s()\\[\\]{},:\"';])",
|
||||
"name": "support.type.primitive.bjolang"
|
||||
},
|
||||
"type-name": {
|
||||
"comment": "A capitalised name: a type, a union case or a .NET class, Some and System.Text.StringBuilder alike.",
|
||||
"match": "(?<![^\\s()\\[\\]{},:\"';])[A-Z][^\\s()\\[\\]{},:\"';]*",
|
||||
"name": "entity.name.type.bjolang"
|
||||
},
|
||||
"braces": {
|
||||
"comment": "A comprehension. A region, so that a } inside an interpolated string's hole closes the right one.",
|
||||
"begin": "\\{",
|
||||
"beginCaptures": {
|
||||
"0": {
|
||||
"name": "punctuation.section.braces.begin.bjolang"
|
||||
}
|
||||
},
|
||||
"end": "\\}",
|
||||
"endCaptures": {
|
||||
"0": {
|
||||
"name": "punctuation.section.braces.end.bjolang"
|
||||
}
|
||||
},
|
||||
"patterns": [
|
||||
{
|
||||
"include": "#forms"
|
||||
}
|
||||
]
|
||||
},
|
||||
"delimiter": {
|
||||
"patterns": [
|
||||
{
|
||||
"match": "\\(",
|
||||
"name": "punctuation.section.parens.begin.bjolang"
|
||||
},
|
||||
{
|
||||
"match": "\\)",
|
||||
"name": "punctuation.section.parens.end.bjolang"
|
||||
},
|
||||
{
|
||||
"match": "\\[",
|
||||
"name": "punctuation.section.brackets.begin.bjolang"
|
||||
},
|
||||
{
|
||||
"match": "\\]",
|
||||
"name": "punctuation.section.brackets.end.bjolang"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue