From 2c42125bf2074b7d0e82e344855e47a835eeeeba Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Thu, 11 Jul 2024 10:53:22 -0400 Subject: [PATCH 1/2] Add polar to list of supported languages --- lib/grammars/polar.tmLanguage.json | 331 +++++++++++++++++++++++++++++ lib/src/language-data.ts | 9 + lib/utils/languages.mjs | 5 + 3 files changed, 345 insertions(+) create mode 100644 lib/grammars/polar.tmLanguage.json diff --git a/lib/grammars/polar.tmLanguage.json b/lib/grammars/polar.tmLanguage.json new file mode 100644 index 0000000..2e52bc1 --- /dev/null +++ b/lib/grammars/polar.tmLanguage.json @@ -0,0 +1,331 @@ +{ + "$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json", + "name": "polar", + "patterns": [ + { + "include": "#comment" + }, + { + "include": "#rule" + }, + { + "include": "#rule-type" + }, + { + "include": "#inline-query" + }, + { + "include": "#resource-block" + }, + { + "include": "#test-block" + } + ], + "repository": { + "comment": { + "name": "comment.line.number-sign", + "match": "#.*" + }, + "rule": { + "name": "meta.rule", + "patterns": [ + { + "include": "#rule-functor" + }, + { + "begin": "\\bif\\b", + "beginCaptures": { + "0": { + "name": "keyword.control.if" + } + }, + "end": ";", + "patterns": [ + { + "include": "#term" + } + ] + }, + { + "match": ";" + } + ] + }, + "rule-type": { + "name": "meta.rule-type", + "begin": "\\btype\\b", + "beginCaptures": { + "0": { + "name": "keyword.other.type-decl" + } + }, + "end": ";", + "patterns": [ + { + "include": "#rule-functor" + } + ] + }, + "inline-query": { + "name": "meta.inline-query", + "begin": "\\?=", + "end": ";", + "beginCaptures": { + "0": { + "name": "keyword.control" + } + }, + "patterns": [ + { + "include": "#term" + } + ] + }, + "resource-block": { + "name": "meta.resource-block", + "begin": "((resource|actor)\\s+([a-zA-Z_][a-zA-Z0-9_]*(?:::[a-zA-Z0-9_]+)*)|(global))\\s*\\{", + "beginCaptures": { + "2": { + "name": "keyword.control" + }, + "3": { + "name": "entity.name.type" + }, + "4": { + "name": "keyword.control" + } + }, + "end": "\\}", + "patterns": [ + { + "name": "punctuation.separator.sequence.declarations", + "match": ";" + }, + { + "name": "meta.relation-declaration", + "begin": "\\{", + "end": "\\}", + "patterns": [ + { + "include": "#specializer" + }, + { + "include": "#comment" + }, + { + "name": "punctuation.separator.sequence.dict", + "match": "," + } + ] + }, + { + "include": "#term" + } + ] + }, + "test-block": { + "name": "meta.test-block", + "begin": "(test)\\s+(\"[^\"]*\")\\s*\\{", + "beginCaptures": { + "1": { + "name": "keyword.control" + }, + "2": { + "name": "string.quoted.double" + } + }, + "end": "\\}", + "patterns": [ + { + "name": "meta.test-setup", + "begin": "(setup)\\s*\\{", + "beginCaptures": { + "1": { + "name": "keyword.control" + } + }, + "end": "\\}", + "patterns": [ + { + "include": "#rule" + }, + { + "include": "#comment" + } + ] + }, + { + "include": "#rule" + }, + { + "name": "keyword.other", + "match": "\\b(assert|assert_not)\\b" + }, + { + "include": "#comment" + } + ] + }, + "term": { + "patterns": [ + { + "include": "#comment" + }, + { + "include": "#string" + }, + { + "include": "#number" + }, + { + "include": "#keyword" + }, + { + "include": "#operator" + }, + { + "include": "#boolean" + }, + { + "include": "#object-literal" + }, + { + "name": "meta.bracket.list", + "begin": "\\[", + "end": "\\]", + "patterns": [ + { + "include": "#term" + }, + { + "name": "punctuation.separator.sequence.list", + "match": "," + } + ] + }, + { + "name": "meta.bracket.dict", + "begin": "\\{", + "end": "\\}", + "patterns": [ + { + "include": "#term" + }, + { + "name": "punctuation.separator.sequence.dict", + "match": "," + } + ] + }, + { + "name": "meta.parens", + "begin": "\\(", + "end": "\\)", + "patterns": [ + { + "include": "#term" + } + ] + } + ] + }, + "string": { + "name": "string.quoted.double", + "begin": "\"", + "end": "\"", + "patterns": [ + { + "name": "constant.character.escape", + "match": "\\\\." + } + ] + }, + "number": { + "patterns": [ + { + "name": "constant.numeric.float", + "match": "\\b[+-]?\\d+(?:(\\.)\\d+(?:e[+-]?\\d+)?|(?:e[+-]?\\d+))\\b" + }, + { + "name": "constant.numeric.integer", + "match": "\\b(\\+|\\-)[\\d]+\\b" + }, + { + "name": "constant.numeric.natural", + "match": "\\b[\\d]+\\b" + } + ] + }, + "boolean": { + "name": "constant.language.boolean", + "match": "\\b(true|false)\\b" + }, + "keyword": { + "patterns": [ + { + "match": "\\b(cut|or|debug|print|in|forall|if|and|of|not|matches|type|on|global)\\b", + "name": "constant.character" + } + ] + }, + "operator": { + "match": "(\\+|-|\\*|\\/|<|>|=|!)", + "captures": { + "1": { + "name": "keyword.control" + } + } + }, + "rule-functor": { + "begin": "([a-zA-Z_][a-zA-Z0-9_]*(?:::[a-zA-Z0-9_]+)*)\\s*\\(", + "beginCaptures": { + "1": { + "name": "support.function.rule" + } + }, + "end": "\\)", + "patterns": [ + { + "include": "#specializer" + }, + { + "name": "punctuation.separator.sequence.list", + "match": "," + }, + { + "include": "#term" + } + ] + }, + "specializer": { + "match": "[a-zA-Z_][a-zA-Z0-9_]*(?:::[a-zA-Z0-9_]+)*\\s*:\\s*([a-zA-Z_][a-zA-Z0-9_]*(?:::[a-zA-Z0-9_]+)*)", + "captures": { + "1": { + "name": "entity.name.type.resource" + } + } + }, + "object-literal": { + "name": "constant.other.object-literal", + "begin": "([a-zA-Z_][a-zA-Z0-9_]*(?:::[a-zA-Z0-9_]+)*)\\s*\\{", + "beginCaptures": { + "1": { + "name": "entity.name.type.resource" + } + }, + "end": "\\}", + "patterns": [ + { + "include": "#string" + }, + { + "include": "#number" + }, + { + "include": "#boolean" + } + ] + } + }, + "scopeName": "source.polar" +} diff --git a/lib/src/language-data.ts b/lib/src/language-data.ts index c2d82be..ba7c652 100644 --- a/lib/src/language-data.ts +++ b/lib/src/language-data.ts @@ -130,6 +130,7 @@ export const LANG_NAMES = [ "perl6", "php", "plsql", + "polar", "postcss", "powerquery", "powershell", @@ -321,6 +322,7 @@ export type LanguageName = | "perl" | "php" | "plsql" + | "polar" | "postcss" | "powerquery" | "powershell" @@ -490,6 +492,7 @@ export type ScopeName = | "source.perl" | "source.php" | "source.plsql.oracle" + | "source.polar" | "source.css.postcss" | "source.powerquery" | "source.powershell" @@ -686,6 +689,7 @@ export const aliasOrIdToScope: Record = { "perl": "source.perl", "php": "source.php", "plsql": "source.plsql.oracle", + "polar": "source.polar", "postcss": "source.css.postcss", "powerquery": "source.powerquery", "powershell": "source.powershell", @@ -1840,6 +1844,11 @@ export const scopeToLanguageData: Record = { "path": "plsql.tmLanguage.json", "embeddedScopes": [] }, + "source.polar": { + "id": "polar", + "path": "polar.tmLanguage.json", + "embeddedScopes": [] + }, "source.css.postcss": { "id": "postcss", "path": "postcss.tmLanguage.json", diff --git a/lib/utils/languages.mjs b/lib/utils/languages.mjs index 6f306f3..17c8983 100644 --- a/lib/utils/languages.mjs +++ b/lib/utils/languages.mjs @@ -877,6 +877,11 @@ export const languages = [ "scopeName": "source.plsql.oracle", "path": "plsql.tmLanguage.json" }, + { + "id": "polar", + "scopeName": "source.polar", + "path": "polar.tmLanguage.json" + }, { "id": "postcss", "scopeName": "source.css.postcss", From 332a0e832c3a77888c8e4d2453e5eeb5e02aa61d Mon Sep 17 00:00:00 2001 From: Rodrigo Pombo Date: Sat, 13 Jul 2024 12:14:12 +0000 Subject: [PATCH 2/2] Add grammar and changeset --- .changeset/tough-fishes-compare.md | 5 +++++ web/public/grammars/polar.json | 1 + 2 files changed, 6 insertions(+) create mode 100644 .changeset/tough-fishes-compare.md create mode 100644 web/public/grammars/polar.json diff --git a/.changeset/tough-fishes-compare.md b/.changeset/tough-fishes-compare.md new file mode 100644 index 0000000..0aee1bb --- /dev/null +++ b/.changeset/tough-fishes-compare.md @@ -0,0 +1,5 @@ +--- +"@code-hike/lighter": patch +--- + +Add polar grammar diff --git a/web/public/grammars/polar.json b/web/public/grammars/polar.json new file mode 100644 index 0000000..8dc8890 --- /dev/null +++ b/web/public/grammars/polar.json @@ -0,0 +1 @@ +[{"$schema":"https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json","name":"polar","patterns":[{"include":"#comment"},{"include":"#rule"},{"include":"#rule-type"},{"include":"#inline-query"},{"include":"#resource-block"},{"include":"#test-block"}],"repository":{"comment":{"name":"comment.line.number-sign","match":"#.*"},"rule":{"name":"meta.rule","patterns":[{"include":"#rule-functor"},{"begin":"\\bif\\b","beginCaptures":{"0":{"name":"keyword.control.if"}},"end":";","patterns":[{"include":"#term"}]},{"match":";"}]},"rule-type":{"name":"meta.rule-type","begin":"\\btype\\b","beginCaptures":{"0":{"name":"keyword.other.type-decl"}},"end":";","patterns":[{"include":"#rule-functor"}]},"inline-query":{"name":"meta.inline-query","begin":"\\?=","end":";","beginCaptures":{"0":{"name":"keyword.control"}},"patterns":[{"include":"#term"}]},"resource-block":{"name":"meta.resource-block","begin":"((resource|actor)\\s+([a-zA-Z_][a-zA-Z0-9_]*(?:::[a-zA-Z0-9_]+)*)|(global))\\s*\\{","beginCaptures":{"2":{"name":"keyword.control"},"3":{"name":"entity.name.type"},"4":{"name":"keyword.control"}},"end":"\\}","patterns":[{"name":"punctuation.separator.sequence.declarations","match":";"},{"name":"meta.relation-declaration","begin":"\\{","end":"\\}","patterns":[{"include":"#specializer"},{"include":"#comment"},{"name":"punctuation.separator.sequence.dict","match":","}]},{"include":"#term"}]},"test-block":{"name":"meta.test-block","begin":"(test)\\s+(\"[^\"]*\")\\s*\\{","beginCaptures":{"1":{"name":"keyword.control"},"2":{"name":"string.quoted.double"}},"end":"\\}","patterns":[{"name":"meta.test-setup","begin":"(setup)\\s*\\{","beginCaptures":{"1":{"name":"keyword.control"}},"end":"\\}","patterns":[{"include":"#rule"},{"include":"#comment"}]},{"include":"#rule"},{"name":"keyword.other","match":"\\b(assert|assert_not)\\b"},{"include":"#comment"}]},"term":{"patterns":[{"include":"#comment"},{"include":"#string"},{"include":"#number"},{"include":"#keyword"},{"include":"#operator"},{"include":"#boolean"},{"include":"#object-literal"},{"name":"meta.bracket.list","begin":"\\[","end":"\\]","patterns":[{"include":"#term"},{"name":"punctuation.separator.sequence.list","match":","}]},{"name":"meta.bracket.dict","begin":"\\{","end":"\\}","patterns":[{"include":"#term"},{"name":"punctuation.separator.sequence.dict","match":","}]},{"name":"meta.parens","begin":"\\(","end":"\\)","patterns":[{"include":"#term"}]}]},"string":{"name":"string.quoted.double","begin":"\"","end":"\"","patterns":[{"name":"constant.character.escape","match":"\\\\."}]},"number":{"patterns":[{"name":"constant.numeric.float","match":"\\b[+-]?\\d+(?:(\\.)\\d+(?:e[+-]?\\d+)?|(?:e[+-]?\\d+))\\b"},{"name":"constant.numeric.integer","match":"\\b(\\+|\\-)[\\d]+\\b"},{"name":"constant.numeric.natural","match":"\\b[\\d]+\\b"}]},"boolean":{"name":"constant.language.boolean","match":"\\b(true|false)\\b"},"keyword":{"patterns":[{"match":"\\b(cut|or|debug|print|in|forall|if|and|of|not|matches|type|on|global)\\b","name":"constant.character"}]},"operator":{"match":"(\\+|-|\\*|\\/|<|>|=|!)","captures":{"1":{"name":"keyword.control"}}},"rule-functor":{"begin":"([a-zA-Z_][a-zA-Z0-9_]*(?:::[a-zA-Z0-9_]+)*)\\s*\\(","beginCaptures":{"1":{"name":"support.function.rule"}},"end":"\\)","patterns":[{"include":"#specializer"},{"name":"punctuation.separator.sequence.list","match":","},{"include":"#term"}]},"specializer":{"match":"[a-zA-Z_][a-zA-Z0-9_]*(?:::[a-zA-Z0-9_]+)*\\s*:\\s*([a-zA-Z_][a-zA-Z0-9_]*(?:::[a-zA-Z0-9_]+)*)","captures":{"1":{"name":"entity.name.type.resource"}}},"object-literal":{"name":"constant.other.object-literal","begin":"([a-zA-Z_][a-zA-Z0-9_]*(?:::[a-zA-Z0-9_]+)*)\\s*\\{","beginCaptures":{"1":{"name":"entity.name.type.resource"}},"end":"\\}","patterns":[{"include":"#string"},{"include":"#number"},{"include":"#boolean"}]}},"scopeName":"source.polar"}] \ No newline at end of file