Merge branch 'es2018-grammar' into 'master'
Es2018 grammar See merge request javallone/regexper-static!44
This commit is contained in:
commit
2ffb3cbc02
@ -13,12 +13,21 @@ describe('parser/javascript/subexp.js', function() {
|
|||||||
'(test)': {
|
'(test)': {
|
||||||
regexp: jasmine.objectContaining({ textValue: 'test' })
|
regexp: jasmine.objectContaining({ textValue: 'test' })
|
||||||
},
|
},
|
||||||
|
'(?<name>test)': {
|
||||||
|
regexp: jasmine.objectContaining({ textValue: 'test' })
|
||||||
|
},
|
||||||
'(?=test)': {
|
'(?=test)': {
|
||||||
regexp: jasmine.objectContaining({ textValue: 'test' })
|
regexp: jasmine.objectContaining({ textValue: 'test' })
|
||||||
},
|
},
|
||||||
'(?!test)': {
|
'(?!test)': {
|
||||||
regexp: jasmine.objectContaining({ textValue: 'test' })
|
regexp: jasmine.objectContaining({ textValue: 'test' })
|
||||||
},
|
},
|
||||||
|
'(?<=test)': {
|
||||||
|
regexp: jasmine.objectContaining({ textValue: 'test' })
|
||||||
|
},
|
||||||
|
'(?<!test)': {
|
||||||
|
regexp: jasmine.objectContaining({ textValue: 'test' })
|
||||||
|
},
|
||||||
'(?:test)': {
|
'(?:test)': {
|
||||||
regexp: jasmine.objectContaining({ textValue: 'test' }),
|
regexp: jasmine.objectContaining({ textValue: 'test' }),
|
||||||
proxy: jasmine.objectContaining({ textValue: 'test' })
|
proxy: jasmine.objectContaining({ textValue: 'test' })
|
||||||
@ -66,7 +75,7 @@ describe('parser/javascript/subexp.js', function() {
|
|||||||
this.node = new javascript.Parser('(test)').__consume__subexp();
|
this.node = new javascript.Parser('(test)').__consume__subexp();
|
||||||
this.node.regexp = jasmine.createSpyObj('regexp', ['render']);
|
this.node.regexp = jasmine.createSpyObj('regexp', ['render']);
|
||||||
this.node.container = jasmine.createSpyObj('container', ['addClass', 'group']);
|
this.node.container = jasmine.createSpyObj('container', ['addClass', 'group']);
|
||||||
spyOn(this.node, 'label').and.returnValue('example label')
|
spyOn(this.node, 'label').and.returnValue('example label');
|
||||||
|
|
||||||
this.node.regexp.render.and.returnValue(this.renderDeferred.promise);
|
this.node.regexp.render.and.returnValue(this.renderDeferred.promise);
|
||||||
});
|
});
|
||||||
@ -95,6 +104,10 @@ describe('parser/javascript/subexp.js', function() {
|
|||||||
label: 'group #1',
|
label: 'group #1',
|
||||||
groupCounter: 2
|
groupCounter: 2
|
||||||
},
|
},
|
||||||
|
'(?<name>test)': {
|
||||||
|
label: 'group \'name\'',
|
||||||
|
groupCounter: 1
|
||||||
|
},
|
||||||
'(?=test)': {
|
'(?=test)': {
|
||||||
label: 'positive lookahead',
|
label: 'positive lookahead',
|
||||||
groupCounter: 1
|
groupCounter: 1
|
||||||
@ -103,6 +116,14 @@ describe('parser/javascript/subexp.js', function() {
|
|||||||
label: 'negative lookahead',
|
label: 'negative lookahead',
|
||||||
groupCounter: 1
|
groupCounter: 1
|
||||||
},
|
},
|
||||||
|
'(?<=test)': {
|
||||||
|
label: 'positive lookbehind',
|
||||||
|
groupCounter: 1
|
||||||
|
},
|
||||||
|
'(?<!test)': {
|
||||||
|
label: 'negative lookbehind',
|
||||||
|
groupCounter: 1
|
||||||
|
},
|
||||||
'(?:test)': {
|
'(?:test)': {
|
||||||
label: '',
|
label: '',
|
||||||
groupCounter: 1
|
groupCounter: 1
|
||||||
|
@ -11,7 +11,10 @@ grammar JavascriptRegexp
|
|||||||
repeat_spec <- ( "{" min:[0-9]+ "," max:[0-9]+ "}"
|
repeat_spec <- ( "{" min:[0-9]+ "," max:[0-9]+ "}"
|
||||||
/ "{" min:[0-9]+ ",}"
|
/ "{" min:[0-9]+ ",}"
|
||||||
/ "{" exact:[0-9]+ "}" ) <RepeatSpec>
|
/ "{" exact:[0-9]+ "}" ) <RepeatSpec>
|
||||||
subexp <- "(" capture:( "?:" / "?=" / "?!" )? regexp ")" <Subexp>
|
subexp <- "(" capture:( "?<" groupname:name ">" / "?:" / "?=" / "?!" / "?<=" / "?<!" )? regexp ")" <Subexp>
|
||||||
|
name <- alpha (alpha / numeric)*
|
||||||
|
alpha <- [a-zA-Z]
|
||||||
|
numeric <- [0-9]
|
||||||
charset <- "[" invert:"^"? parts:( charset_range / charset_terminal )* "]" <Charset>
|
charset <- "[" invert:"^"? parts:( charset_range / charset_terminal )* "]" <Charset>
|
||||||
charset_range <- first:charset_range_terminal "-" last:charset_range_terminal <CharsetRange>
|
charset_range <- first:charset_range_terminal "-" last:charset_range_terminal <CharsetRange>
|
||||||
charset_terminal <- charset_escape <CharsetEscape>
|
charset_terminal <- charset_escape <CharsetEscape>
|
||||||
|
@ -26,7 +26,9 @@ export default {
|
|||||||
labelMap: {
|
labelMap: {
|
||||||
'?:': '',
|
'?:': '',
|
||||||
'?=': 'positive lookahead',
|
'?=': 'positive lookahead',
|
||||||
'?!': 'negative lookahead'
|
'?!': 'negative lookahead',
|
||||||
|
'?<=': 'positive lookbehind',
|
||||||
|
'?<!': 'negative lookbehind'
|
||||||
},
|
},
|
||||||
|
|
||||||
// Renders the subexp into the currently set container.
|
// Renders the subexp into the currently set container.
|
||||||
@ -48,6 +50,10 @@ export default {
|
|||||||
label() {
|
label() {
|
||||||
if (_.has(this.labelMap, this.properties.capture.textValue)) {
|
if (_.has(this.labelMap, this.properties.capture.textValue)) {
|
||||||
return this.labelMap[this.properties.capture.textValue];
|
return this.labelMap[this.properties.capture.textValue];
|
||||||
|
} else if (this.properties.capture !== undefined
|
||||||
|
&& this.properties.capture.properties !== undefined
|
||||||
|
&& this.properties.capture.properties.groupname) {
|
||||||
|
return `group '${this.properties.capture.properties.groupname.textValue}'`;
|
||||||
} else {
|
} else {
|
||||||
return `group #${this.state.groupCounter++}`;
|
return `group #${this.state.groupCounter++}`;
|
||||||
}
|
}
|
||||||
@ -59,7 +65,7 @@ export default {
|
|||||||
this.regexp = this.properties.regexp;
|
this.regexp = this.properties.regexp;
|
||||||
|
|
||||||
// If there is no need for a label, then proxy to the nested regexp.
|
// If there is no need for a label, then proxy to the nested regexp.
|
||||||
if (this.properties.capture.textValue == '?:') {
|
if (this.properties.capture.textValue === '?:') {
|
||||||
this.proxy = this.regexp;
|
this.proxy = this.regexp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user