diff --git a/examples/learn.md b/examples/learn.md index 9e5ff17..f0782fc 100644 --- a/examples/learn.md +++ b/examples/learn.md @@ -2572,6 +2572,43 @@ jump 0 lessThan 6 10 例如 `is a foo` 为 `IS_A_FOO` +利用无限重复块避免深层递归 +------------------------------------------------------------------------------- +在 [重复块](#重复块) 一章中, 有说到重复块无限重复的情况, +可以利用它来替换掉一些用递归解决可能远超递归层数限制的问题 + +例如如果想给一千以内整数附加上一个 pi 绑定量: + +``` +const Each = (match @ { + [1000] {} + N { + take*N.pi = N*3.1415926535897932; + take Each[(*N+1)]; + } +}); +Each! 0; +print 8.pi; +``` +编译上述代码, 产生递归超限, 我们可以利用无限重复块将其改为: +``` +{ + take N = 0; + inline 0@{ + match N { [1000] { Builtin.StopRepeat!; } N { + take*N.pi = N*3.1415926535897932; + take*N = N+1; + } } + } +} +print 8.pi; +``` +编译为 +``` +print 25.132741228718345 +``` + + 关于一些名词命名的解释 =============================================================================== 这里讲解一些奇特命名的可能解释, diff --git a/syntax/MT-Manager/MindustryLogicBangLang.mtsx b/syntax/MT-Manager/MindustryLogicBangLang.mtsx index b7da4e5..b24b318 100644 --- a/syntax/MT-Manager/MindustryLogicBangLang.mtsx +++ b/syntax/MT-Manager/MindustryLogicBangLang.mtsx @@ -61,9 +61,17 @@ match: /'[^\s']+'/ 0: "constant" } + { // 参数展开 + match: /@/ + 0: "keyword" + } + { // control can star + match: keywordsToRegex("case") + /\*?/ + 0: "keyword" + } { // control match: keywordsToRegex( - "while gwhile do skip goto if elif else switch case" + "while gwhile do skip goto if elif else switch" "select break continue" ) 0: "keyword" @@ -72,9 +80,17 @@ match: /\$/ 0: "keyword2" } + { // 绑定者 + match: /\.\./ + 0: "keyword2" + } + { // other keywords can star + match: keywordsToRegex("take inline") + /\*?/ + 0: "keyword2" + } { // other keywords match: keywordsToRegex( - "const take match setres inline print set op noop" + "const match setres print set op noop" ) 0: "keyword2" } @@ -89,12 +105,28 @@ ) 0: "tagName" } + { // cmp operator + match: /[<>](?![<>])=?|[=!]==?/ + 0: "default" + } + { // match fat arrow + match: /=>/ + 0: "keyword2" + } + { // self inc and dec + match: /([+\-])\1/ + 0: "tagName" + } + { // self operator + match: /(?:\/\/|\*\*|&&|<<|>>|[+\-*\/%|&^])?=/ + 0: "tagName" + } { // 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_\-]*)[\[!]|[\[\]])/ + match: /(?:(?:[a-zA-Z_][a-zA-Z0-9_]*)(?:!|(?:->)?\[)|[\[\]]|->|\b_\b)/ 0: "variable" } { // control operator diff --git a/syntax/vim/syntax/mdtlbl.vim b/syntax/vim/syntax/mdtlbl.vim index fdea9d7..1615fc4 100644 --- a/syntax/vim/syntax/mdtlbl.vim +++ b/syntax/vim/syntax/mdtlbl.vim @@ -24,10 +24,11 @@ syn keyword mdtlblKeyword \ const setres select match \ op noop print syn keyword mdtlblKeyword goto nextgroup=mdtlblIdentLabelRest -syn keyword mdtlblKeyword case nextgroup=mdtlblStar skipwhite -syn keyword mdtlblKeyword take nextgroup=mdtlblStar skipwhite -syn keyword mdtlblKeyword inline nextgroup=mdtlblStar skipwhite +syn keyword mdtlblKeyword case nextgroup=mdtlblStar skipwhite +syn keyword mdtlblKeyword take nextgroup=mdtlblStar skipwhite +syn keyword mdtlblKeyword inline nextgroup=mdtlblStar,mdtlblRepeatZero skipwhite syn match mdtlblStar /\*/ contained +syn match mdtlblRepeatZero /0\ze\s*@/ contained syn keyword mdtlblOpFunKeyword \ add sub mul div idiv mod pow @@ -41,7 +42,7 @@ syn keyword mdtlblOpFunKeyword syn match mdtlblOpExprCtrl "\%(//\|\*\*\|&&\|<<\|>>\|[+\-*/%|&^]\)\==" syn match mdtlblOpExprCtrl /++\|--/ syn match mdtlblCmpTreeOper /&&\|||\|!\|=>/ -syn match mdtlblCmpOper /[<>]=\=\|[=!]==\=/ +syn match mdtlblCmpOper /[<>][<>]\@!=\=\|[=!]==\=/ syn match mdtlblArgsExpand /@/ " 注释 {{{1 @@ -69,6 +70,7 @@ syn region mdtlblSubParenNum matchgroup=mdtlblSubParenNumParen start=/\v-@<=\(\z syn match mdtlblSubSpaceNum /-\zs \%(\S- \)\@<=\ze\d/ conceal syn match mdtlblResultHandle /\$/ +syn match mdtlblBinder /\.\./ " Label And ResultH {{{1 syn match mdtlblDefineResultHandle /\v%(\([%?]=)@2<=(`=)-=_@![0-9_]+%(\._@![0-9_]+|e[+-]=-=_@![0-9_]+)=>\1:/ @@ -159,6 +161,7 @@ setlocal indentkeys+=0= " END And Color Links {{{1 hi def link mdtlblKeyword Keyword hi def link mdtlblStar Keyword +hi def link mdtlblRepeatZero Keyword hi def link mdtlblOpFunKeyword Operator hi def link mdtlblCmpTreeOper Operator hi def link mdtlblCmpOper NONE @@ -176,6 +179,7 @@ hi def link mdtlblNumber Number hi def link mdtlblBoolean Boolean hi def link mdtlblNull Boolean hi def link mdtlblResultHandle Identifier +hi def link mdtlblBinder Keyword hi def link mdtlblDefineResultHandle Identifier hi def link mdtlblIdentLabel Label hi def link mdtlblIdentLabelRest mdtlblIdentLabel