使用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: '?????????' },
],
};
答案 0 :(得分:0)
使用push: <statename>
向堆栈添加状态,并使用next: pop
将其删除。请注意,要使用此功能,您需要在构造函数中调用this.normalizeRules()
。