regexper-static/src/js/parser/javascript/subexp.js

51 lines
1.0 KiB
JavaScript
Raw Normal View History

import _ from 'lodash';
import Base from './base.js';
var groupCounter = 1;
export default _.extend({}, Base, {
2014-12-08 02:16:23 +00:00
type: 'subexp',
labelMap: {
'?:': '',
'?=': 'positive lookahead',
'?!': 'negative lookahead'
},
_render() {
2014-12-08 02:16:23 +00:00
var label = this.groupLabel();
if (label) {
return this.regexp.render(this.container.group())
.then(this.renderLabeledBox.bind(this, label, this.regexp, {
padding: 10
}));
2014-12-08 02:16:23 +00:00
} else {
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 {
return 'group #' + (groupCounter++);
2014-12-08 02:16:23 +00:00
}
},
resetCounter() {
groupCounter = 1;
},
2014-12-15 00:08:14 +00:00
_getAnchor() {
var anchor = this.regexp.getAnchor(),
matrix = this.transform().localMatrix;
return _.extend(anchor, {
ax: matrix.x(anchor.ax, anchor.ay),
ax2: matrix.x(anchor.ax2, anchor.ay),
ay: matrix.y(anchor.ax, anchor.ay)
});
}
});