Ace 编辑器中的递归块

Recursive blocks in Ace editor

本文关键字:递归 编辑器 Ace      更新时间:2023-09-26

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

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

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

     { 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();