Recursive blocks in Ace editor

北战南征 提交于 2019-12-07 00:53:35

问题


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])])

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' } ],
        },

But, as you might've guessed, this will stop at brace at the end of test: '[ concat([test ], [blah])]'...

Other examples are:

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

回答1:


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


来源:https://stackoverflow.com/questions/22765435/recursive-blocks-in-ace-editor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!