Ace编辑器HighlightRules,规则无休止地嵌套

时间:2015-08-05 13:27:45

标签: javascript syntax-highlighting ace-editor

使用Ace Editor HighlightRules ,我想知道如何定义可以无限嵌套的规则。

const rules = {
  start: [
    { ...segmentationName, next: 'segmentation' },
  ],
  segment: [
    { ...enclosingOperatorStart, next: 'enclosingOperator' },
    segmentCommand,
    { ...emptyLine, next: 'segmentation' },
  ],
  enclosingOperator: [
    segmentCommand,
    { ...enclosingOperatorEnd, next: 'segment' },
  ],
};

在上面的规则中,我希望enclosingOperator无限地嵌套,以便能够允许以下示例。

@Frankenstein/tf1-et-vous/PhotosList  //segmentationName
host www.tf1.fr                       //segmentCommand
path /tf1-et-vous/*
and (                                 //enclosingOperatorStart
path */photos/*                       //segmentCommand
path */photos-* 
or (                                  //enclosingOperatorStart
path */photos/*
path */photos-*
path */photo/*
)                                     //enclosingOperatorEnd
path */photo/*
)                                     //enclosingOperatorEnd

我可以在enclosingOperatorStart步骤中添加enclosingOperator节点,但在enclosingOperatorEnd中,下一个需要segment,如果最高级别否则堆叠enclosingOperator

const rules = {
  start: [
    { ...segmentationName, next: 'segmentation' },
  ],
  segment: [
    { ...enclosingOperatorStart, next: 'enclosingOperator' },
    segmentCommand,
    { ...emptyLine, next: 'segmentation' },
  ],
  enclosingOperator: [
    { ...enclosingOperatorStart, next: 'enclosingOperator' },
    segmentCommand,
    { ...enclosingOperatorEnd, next: '?????????' },
  ],
};

1 个答案:

答案 0 :(得分:0)

使用push: <statename>向堆栈添加状态,并使用next: pop将其删除。请注意,要使用此功能,您需要在构造函数中调用this.normalizeRules()