Ace 编辑器中的递归块 [英] Recursive blocks in Ace editor

查看:33
本文介绍了Ace 编辑器中的递归块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有自己使用的脚本语言.该语言非常简单,但它有一个独占"的东西:字符串是使用 '[' 和 ']' 定义的(所以test"应该是 [test]),并且这些大括号可以相互包含:

We've got our own scripting language that we use. The language is quite simple, but it has one 'exclusive' thing: strings are defined using '[' and ']' (so "test" would be [test]), and these braces can be inside each other:

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

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

Also, there's no escaping character. How does one parse this block as one string (thus highlighting the [concat([test], [blah])] block)? I currently got the following rule:

     { 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])]'...

But, as you might've guessed, this will stop at brace at the end of test: '[ 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)))]);

推荐答案

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

You need to add rule for [ into the inner string state, try

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

这篇关于Ace 编辑器中的递归块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆