Skip to content

Commit

Permalink
教程添加无限重复块的技巧, 简单调整高亮
Browse files Browse the repository at this point in the history
  • Loading branch information
A4-Tacks committed Jan 31, 2025
1 parent 198221b commit f47c619
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 7 deletions.
37 changes: 37 additions & 0 deletions examples/learn.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```


关于一些名词命名的解释
===============================================================================
这里讲解一些奇特命名的可能解释,
Expand Down
38 changes: 35 additions & 3 deletions syntax/MT-Manager/MindustryLogicBangLang.mtsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
}
Expand All @@ -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
Expand Down
12 changes: 8 additions & 4 deletions syntax/vim/syntax/mdtlbl.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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:/
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit f47c619

Please sign in to comment.