Adding documentation to subexp.js
This commit is contained in:
parent
661e7fa6fb
commit
ff9e84f20e
@ -1,9 +1,14 @@
|
|||||||
|
// Subexp nodes are for expressions inside of parenthesis. It is rendered as a
|
||||||
|
// labeled box around the contained expression if a label is required.
|
||||||
|
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
type: 'subexp',
|
type: 'subexp',
|
||||||
|
|
||||||
definedProperties: {
|
definedProperties: {
|
||||||
|
// Default anchor is overridden to move it down to account for the group
|
||||||
|
// label and outline box.
|
||||||
_anchor: {
|
_anchor: {
|
||||||
get: function() {
|
get: function() {
|
||||||
var anchor = this.regexp.getBBox(),
|
var anchor = this.regexp.getBBox(),
|
||||||
@ -24,37 +29,38 @@ export default {
|
|||||||
'?!': 'negative lookahead'
|
'?!': 'negative lookahead'
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Renders the subexp into the currently set container.
|
||||||
_render() {
|
_render() {
|
||||||
// NOTE: this.label() MUST be called here, in _render and before any child
|
// **NOTE:** `this.label()` **MUST** be called here, in _render, and before
|
||||||
// nodes are rendered. This is to keep the group numbers in the correct
|
// any child nodes are rendered. This is to keep the group numbers in the
|
||||||
// order.
|
// correct order.
|
||||||
var label = this.label();
|
var label = this.label();
|
||||||
|
|
||||||
|
// Render the contained regexp.
|
||||||
return this.regexp.render(this.container.group())
|
return this.regexp.render(this.container.group())
|
||||||
.then(() => {
|
.then(() => {
|
||||||
|
// Create the labeled box around the regexp.
|
||||||
return this.renderLabeledBox(label, this.regexp, {
|
return this.renderLabeledBox(label, this.regexp, {
|
||||||
padding: 10
|
padding: 10
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Returns the label for the subexpression.
|
||||||
label() {
|
label() {
|
||||||
if (typeof this._label === 'undefined') {
|
|
||||||
if (_.has(this.labelMap, this.properties.capture.textValue)) {
|
if (_.has(this.labelMap, this.properties.capture.textValue)) {
|
||||||
this._label = this.labelMap[this.properties.capture.textValue];
|
return this.labelMap[this.properties.capture.textValue];
|
||||||
} else {
|
} else {
|
||||||
this._label = 'group #' + (this.state.groupCounter++);
|
return `group #${this.state.groupCounter++}`;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return this._label;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
setup() {
|
setup() {
|
||||||
// NOTE: DO NOT call this.label() in setup. It will lead to groups being
|
// **NOTE:** **DO NOT** call `this.label()` in setup. It will lead to
|
||||||
// numbered in reverse order
|
// groups being numbered in reverse order.
|
||||||
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 (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