2014-12-03 02:02:48 +00:00
|
|
|
import _ from 'lodash';
|
|
|
|
import Base from './base.js';
|
|
|
|
|
2014-12-10 11:18:55 +00:00
|
|
|
var groupCounter = 1;
|
|
|
|
|
2014-12-03 02:02:48 +00:00
|
|
|
export default _.extend({}, Base, {
|
2014-12-08 02:16:23 +00:00
|
|
|
type: 'subexp',
|
|
|
|
|
|
|
|
labelMap: {
|
|
|
|
'?:': '',
|
|
|
|
'?=': 'positive lookahead',
|
|
|
|
'?!': 'negative lookahead'
|
|
|
|
},
|
|
|
|
|
2014-12-11 00:01:57 +00:00
|
|
|
_render() {
|
2014-12-08 02:16:23 +00:00
|
|
|
var label = this.groupLabel();
|
|
|
|
|
|
|
|
if (label) {
|
2014-12-13 17:55:03 +00:00
|
|
|
return this.regexp.render(this.container.group())
|
2014-12-13 18:26:43 +00:00
|
|
|
.then(this.renderLabeledBox.bind(this, label, this.regexp, {
|
|
|
|
padding: 10
|
|
|
|
}));
|
2014-12-08 02:16:23 +00:00
|
|
|
} else {
|
2014-12-13 14:09:58 +00:00
|
|
|
return this.proxy(this.regexp);
|
2014-12-08 02:16:23 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
groupLabel() {
|
|
|
|
if (_.has(this.labelMap, this._capture.textValue)) {
|
|
|
|
return this.labelMap[this._capture.textValue];
|
|
|
|
} else {
|
2014-12-10 11:18:55 +00:00
|
|
|
return 'group #' + (groupCounter++);
|
2014-12-08 02:16:23 +00:00
|
|
|
}
|
2014-12-10 11:18:55 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
resetCounter() {
|
|
|
|
groupCounter = 1;
|
|
|
|
},
|
2014-12-03 02:02:48 +00:00
|
|
|
});
|