gpt4 book ai didi

javascript - Ace 编辑器中的递归 block

转载 作者:数据小太阳 更新时间:2023-10-29 04:44:15 25 4
gpt4 key购买 nike

我们有自己使用的脚本语言。该语言非常简单,但它有一个“独有”的东西:字符串是使用“[”和“]”定义的(因此“test”将是 [test]),并且这些大括号可以在彼此内部:

lateinit([concat([test], [blah])])

此外,没有转义字符。如何将此 block 解析为一个字符串(从而突出显示 [concat([test], [blah])] block )?我目前有以下规则:

     { token: 'punctuation.definition.string.begin.vcl',
regex: '\\[',
push:
[
{ token: 'punctuation.definition.string.end.vcl',
regex: '\\]',
next: 'pop' },
{ defaultToken: 'string.quoted.other.vcl' } ],
},

但是,正如您可能已经猜到的那样,这将在测试结束时停止在大括号处:'[ concat([test ], [blah])] '...

其他例子是:

setexpratt(1, [if(comparetext([yes], [no]), msg([test expression]))]);
terminator([confirm([Are you sure you want to exit?])]);
registerfunction([testfunction], 1, 3, [], [msg(concat([Argument 1: ], p(1), [, Argument 2: ], p(2), [, Argument 3: ], p(3)))]);

最佳答案

你需要为 [ 添加规则到内部字符串状态,尝试

this.$rules = { 
start: [
{ token: 'string.begin.vcl', regex: '\\[', push: "string" }
],
string : [
{ token: 'string.begin.vcl', regex: '\\[', push: "string" },
{ token: 'string.end.vcl', regex: '\\]', next: 'pop' },
{ defaultToken: 'string.quoted.other.vcl' },
]
};
this.normalizeRules();

关于javascript - Ace 编辑器中的递归 block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22765435/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com