Adding lookbehind assertion

This commit is contained in:
LiHS 2019-08-15 14:02:53 +08:00
parent ac8d90e65a
commit c092b5fa3a
3 changed files with 18 additions and 2 deletions

View File

@ -22,6 +22,12 @@ describe('parser/javascript/subexp.js', function() {
'(?!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' })
@ -110,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

View File

@ -11,7 +11,7 @@ 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:( "?<" groupname:name ">" / "?:" / "?=" / "?!" )? regexp ")" <Subexp> subexp <- "(" capture:( "?<" groupname:name ">" / "?:" / "?=" / "?!" / "?<=" / "?<!" )? regexp ")" <Subexp>
name <- alpha (alpha / numeric)* name <- alpha (alpha / numeric)*
alpha <- [a-zA-Z] alpha <- [a-zA-Z]
numeric <- [0-9] numeric <- [0-9]

View File

@ -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.