feat(frontend): Shiki 白名单语言高亮并支持 aardio
显式加载常用语言;修复 pretty-code 去 shiki class 导致不上色,以及 aardio 循环别名。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
117
frontend/components/markdown/aardioGrammar.ts
Normal file
117
frontend/components/markdown/aardioGrammar.ts
Normal file
@@ -0,0 +1,117 @@
|
||||
import type { LanguageRegistration } from "shiki";
|
||||
|
||||
/**
|
||||
* aardio TextMate grammar(对齐官方 Prism / 用户提供的 highlight.js 规则):
|
||||
* https://www.aardio.com/zh-cn/docs/js/prism.js
|
||||
*/
|
||||
export const aardioGrammar: LanguageRegistration = {
|
||||
name: "aardio",
|
||||
scopeName: "source.aardio",
|
||||
// 勿把 name 自身再写进 aliases,否则 Shiki 报 Circular alias `aardio -> aardio`
|
||||
patterns: [
|
||||
{ include: "#block-comment" },
|
||||
{ include: "#line-comment" },
|
||||
{ include: "#string-double" },
|
||||
{ include: "#string-backtick" },
|
||||
{ include: "#string-single" },
|
||||
{ include: "#constant-underscore" },
|
||||
{ include: "#class-decl" },
|
||||
{ include: "#keywords" },
|
||||
{ include: "#literals" },
|
||||
{ include: "#function-call" },
|
||||
{ include: "#numbers" },
|
||||
{ include: "#operators" },
|
||||
],
|
||||
repository: {
|
||||
"block-comment": {
|
||||
name: "comment.block.aardio",
|
||||
begin: "/\\*+",
|
||||
end: "\\*+/",
|
||||
patterns: [{ include: "self" }],
|
||||
},
|
||||
"line-comment": {
|
||||
name: "comment.line.double-slash.aardio",
|
||||
match: "//.*$",
|
||||
},
|
||||
"string-double": {
|
||||
name: "string.quoted.double.aardio",
|
||||
begin: '"',
|
||||
end: '"',
|
||||
patterns: [{ name: "constant.character.escape.aardio", match: '""' }],
|
||||
},
|
||||
"string-backtick": {
|
||||
name: "string.quoted.other.aardio",
|
||||
begin: "`",
|
||||
end: "`",
|
||||
patterns: [{ name: "constant.character.escape.aardio", match: "``" }],
|
||||
},
|
||||
"string-single": {
|
||||
name: "string.quoted.single.aardio",
|
||||
begin: "'",
|
||||
end: "'",
|
||||
patterns: [
|
||||
{
|
||||
name: "constant.character.escape.aardio",
|
||||
match: "\\\\.",
|
||||
},
|
||||
],
|
||||
},
|
||||
"constant-underscore": {
|
||||
name: "constant.other.aardio",
|
||||
match: "\\b_[A-Za-z]\\w*\\b",
|
||||
},
|
||||
"class-decl": {
|
||||
begin: "\\b(class)\\b",
|
||||
beginCaptures: {
|
||||
"1": { name: "keyword.control.aardio" },
|
||||
},
|
||||
end: "(?=[{;])",
|
||||
patterns: [
|
||||
{
|
||||
name: "entity.name.type.class.aardio",
|
||||
match: "[\\w.\\\\]+",
|
||||
},
|
||||
],
|
||||
},
|
||||
keywords: {
|
||||
name: "keyword.control.aardio",
|
||||
match:
|
||||
"\\b(?:begin|end|if|lambda|λ|else|elseif|class|function|return|while|do|namespace|select|case|catch|try|for|in|this|global|self|owner|var|def|and|not|or|break|continue|import|with|ctor|eval|type|assert|assert2|assertf|error|rget|callex|errput|loadcode|dumpcode|collectgarbage|call|invoke|tostring|topointer|tonumber|sleep|execute|setlocale|setprivilege|loadcodex|reduce|switch)\\b",
|
||||
},
|
||||
literals: {
|
||||
name: "constant.language.aardio",
|
||||
match: "\\b(?:true|false|null)\\b",
|
||||
},
|
||||
"function-call": {
|
||||
// 排除关键字,避免 if( 被当成函数
|
||||
name: "entity.name.function.aardio",
|
||||
match:
|
||||
"\\b(?!(?:begin|end|if|lambda|λ|else|elseif|class|function|return|while|do|namespace|select|case|catch|try|for|in|this|global|self|owner|var|def|null|and|not|or|break|continue|import|with|ctor|eval|type|assert|assert2|assertf|error|rget|callex|errput|loadcode|dumpcode|collectgarbage|call|invoke|tostring|topointer|tonumber|sleep|execute|setlocale|setprivilege|loadcodex|reduce|switch|true|false)\\b)[_$[:alpha:]][_$[:alnum:]]*(?=\\s*\\()",
|
||||
},
|
||||
numbers: {
|
||||
patterns: [
|
||||
{
|
||||
name: "constant.numeric.aardio",
|
||||
match: "\\b0x[a-fA-F_\\d]+(?:\\.[a-fA-F_\\d]*)?(?:p[+-]?\\d[_\\d]*)?\\b",
|
||||
},
|
||||
{
|
||||
name: "constant.numeric.aardio",
|
||||
match: "\\b\\d+#[\\d_]+\\b",
|
||||
},
|
||||
{
|
||||
name: "constant.numeric.aardio",
|
||||
match: "\\b\\d[_\\d]*(?:\\.(?![\\w.])|\\.[_\\d]*)?(?:e[+-]?\\d[_\\d]*)?\\b",
|
||||
},
|
||||
{
|
||||
name: "constant.numeric.aardio",
|
||||
match: "\\.\\d[_\\d]*(?:e[+-]?\\d[_\\d]*)?\\b",
|
||||
},
|
||||
],
|
||||
},
|
||||
operators: {
|
||||
name: "keyword.operator.aardio",
|
||||
match:
|
||||
"\\.\\.|--|\\+\\+|\\*\\*=?|&&=?|\\|\\|=?|[!=]==|<<=?|>>>?=?|[-+*/%&|^!=<>]=?|[~:?]",
|
||||
},
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user