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

查看:89
本文介绍了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天全站免登陆