2014-03-31 44 views
6

我们有我们自己使用的脚本语言。这个语言很简单,但它有一个'独占'的东西:字符串是用'['和']'定义的(所以“test”将会是[test]),并且这些大括号可以在彼此之内:Ace编辑器中的递归块

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([测试],[等等] )” ......

其他例子是:

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

嵌套它们的目的是什么? –

+0

@ExplosionPills这是语法;没有逃脱的角色......我给出的例子执行了一个对象加载后给出的代码。因此''concat([test],[blah])'被再次解析,然后运行。 – Diamondo25

+0

该json的东西的任何条件? –

回答

4

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

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

之间递归所有内容谢谢, )。我知道它比我想象的更进步 – Diamondo25