Adding code to indicate subexpression numbers

This commit is contained in:
Jeff Avallone 2014-12-10 06:18:55 -05:00
parent 4a8103f404
commit 60d7cab504
3 changed files with 14 additions and 2 deletions

View File

@ -36,4 +36,8 @@ parser.Parser.RepeatOptional = RepeatOptional;
parser.Parser.RepeatRequired = RepeatRequired;
parser.Parser.RepeatSpec = RepeatSpec;
parser.resetGroupCounter = () => {
parser.Parser.Subexp.resetCounter();
}
export default parser;

View File

@ -1,6 +1,8 @@
import _ from 'lodash';
import Base from './base.js';
var groupCounter = 1;
export default _.extend({}, Base, {
type: 'subexp',
@ -72,7 +74,11 @@ export default _.extend({}, Base, {
if (_.has(this.labelMap, this._capture.textValue)) {
return this.labelMap[this._capture.textValue];
} else {
return 'group #TBA';
}
return 'group #' + (groupCounter++);
}
},
resetCounter() {
groupCounter = 1;
},
});

View File

@ -87,6 +87,8 @@ export default class Regexper {
snap.selectAll('g').remove();
parser.resetGroupCounter();
return Q.fcall(parser.parse.bind(parser), expression)
.then((result) => {
result.container = snap.group();