Skip to content

Commit

Permalink
稍微修整一下高亮
Browse files Browse the repository at this point in the history
  • Loading branch information
A4-Tacks committed Dec 30, 2023
1 parent 9f709e7 commit e69fe68
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 58 deletions.
131 changes: 75 additions & 56 deletions syntax/MT-Manager/MindustryLogicBangLang.mtsx
Original file line number Diff line number Diff line change
@@ -1,82 +1,101 @@
// mindustry logic bang lang 的语法高亮规则
// https://github.com/A4-Tacks/mindustry_logic_bang_lang
{
name: ["MindustryLogicBangLang", ".mdtlbl"],
name: ["MindustryLogicBangLang", ".mdtlbl"]
// no hidden
hide: false,
comment: { startsWith: "#", addToContains: false },
hide: false
comment: { startsWith: "#", addToContains: false }
defines: [
"ws": /(?:[\s\r\n]*)/
]
contains: [
{
// long comments
start: { match: /#\*/ },
end: { match: /\*#/ },
{ // long comments
start: { match: /#\*/ }
end: { match: /\*#/ }
color: "comment"
},
{
// inline comments
start: { match: /#/ },
end: { match: /\n|$/ },
}
{ // inline comments
start: { match: /#(?!=\*)/ }
end: { match: /(?=\n|$)/ }
color: "comment"

},
{
// number
match: /\b(?:0(?:x-?[\da-fA-F][_\da-fA-F]*|b-?[01][_01]*)/
+ /|-?\d[_\d]*(?:\.\d[\d_]*|e[+\-]?\d[\d_]*)?)\b/,
}
{ // number
match: /(?:\b0(?:x\-?[\da-fA-F][\da-fA-F_]*|b\-?[01][_01]*)/
+ /|\-?\b\d[0-9_]*(?:\.\d[\d_]*|e[+\-]?\d[\d_]*)?)\b/
0: "number"
}
{ // boolean
match: /\b(?:true|false)\b/
0: "number"
},
{
// string
match: /"(?:(\\n)|[^"])*"/,
0: "string",
1: "strEscape"
},
{
// 元标识符,由于MT管理器的正则并没有\i \I \p [[:idnet:]]等匹配标识符的手段
// 只能手动枚举ASCII字符
match: /@[a-zA-Z_][a-zA-Z0-9_\-]*/,
}
{ // null
match: /\bnull\b/
0: "number"
}
{ // DExp result handle define
match: /\(/+include("ws")+/([a-zA-Z_][a-zA-Z0-9_\-]*:)/
1: "keyword2"
}
{ // string
start: {match: /"/}
end: {match: /"/}
color: "string"
contains: [
{ // string escape
match: /(?:(?<=\n)\s*\\ |\\(?:[n\[\\]|\r?\n)|(\\.))/
0: "strEscape"
1: "error"
}
{ // string color
match: /\[(?:#[\da-fA-F]{6,8}|(?:c(?:lear|yan|oral)|b(?:l(?:ack|ue)|r(?:own|ick))|white|li(?:ghtgray|me)|g(?:r(?:ay|een)|old(?:enrod)?)|darkgray|navy|r(?:oyal|ed)|s(?:late|ky|carlet|almon)|t(?:eal|an)|acid|forest|o(?:live|range)|yellow|p(?:ink|urple)|ma(?:genta|roon)|violet))\]/
0: "strEscape"
}
]
}
{ // 元标识符
match: /@[a-zA-Z_][a-zA-Z0-9_\-]*/
0: "meta"
},
{
// 原始标识符
match: /'[^\s']*'/,
}
{ // 原始标识符
match: /'[^\s']+'/
0: "constant"
},
{
// control
}
{ // control
match: keywordsToRegex(
"while gwhile do skip goto if elif else switch case"
"select break continue"
),
)
0: "keyword"
},
}
{ // 返回句柄替换符
match: /\$/,
match: /\$/
0: "keyword2"
},
{
// other
}
{ // other
match: keywordsToRegex(
"const take setres inline print set op noop"
),
)
0: "keyword2"
},
{
// operator
}
{ // operator
match: keywordsToRegex(
"abs", "acos", "add", "and", "angle", "asin", "atan", "ceil",
"cos", "div", "equal", "floor", "greaterThan", "greaterThanEq",
"idiv", "land", "len", "lessThan", "lessThanEq", "lnot", "log",
"max", "min", "mod", "mul", "noise", "not", "notEqual", "or",
"pow", "rand", "shl", "shr", "sin", "sqrt", "strictEqual",
"strictNotEqual", "sub", "tan", "xor",
),
"abs acos add and angle asin atan ceil"
"cos div equal floor greaterThan greaterThanEq"
"idiv land len lessThan lessThanEq lnot log"
"max min mod mul noise not notEqual or"
"pow rand shl shr sin sqrt strictEqual"
"strictNotEqual sub tan xor"
)
0: "tagName"
},
{
// label
match: /:(?:[a-zA-Z]|[a-zA-Z_][a-zA-Z0-9_]+)\b/,
}
{ // label
match: /:(?:[a-zA-Z]|[a-zA-Z_][a-zA-Z0-9_]+)\b/
0: "label"
}
{ // quick dexp take
match: /(?:(?:[a-zA-Z_][a-zA-Z0-9_\-]*)?/+include("ws")+/\[|\])/
0: "variable"
}
]
}
5 changes: 3 additions & 2 deletions syntax/vim/mdtlbl.vim
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ syn keyword mdtlblOpFunKeyword
syn match mdtlblCmpTreeOper /&&\|||\|!/

" 注释 {{{1
syn region mdtlblComment start=/#/ end=/$/ oneline
syn region mdtlblComment start=/#[^*]\=/ end=/$/ oneline
syn region mdtlblLongComment start=/#\*/ end=/\*#/ fold

setlocal comments=s:#*,mb:*,ex:*#,:#
Expand Down Expand Up @@ -78,7 +78,7 @@ syn region mdtlblArgs matchgroup=mdtlblArgsBracket start=/\[/ end=/\]/ transpare
function! <SID>lineFilter(line)
" 过滤掉注释与字符串与原始标识符
let regex_a = ''
\. '#\*.\{-0,}\*#'
\. '#\*.\{-}\*#'
\. '\|#.*$'
let regex_b = '@\I\i*\(-\i*\)*'
\. '\|' . "'[^' \\t]*'"
Expand Down Expand Up @@ -117,6 +117,7 @@ endfunction
setlocal indentexpr=<SID>getMdtlblIndent()
setlocal indentkeys+==case
setlocal indentkeys+==}
setlocal indentkeys+==]
setlocal indentkeys+==)
setlocal indentkeys+==:

Expand Down

0 comments on commit e69fe68

Please sign in to comment.