From 60d7cab5043693965820390f26e9b0eb257ab126 Mon Sep 17 00:00:00 2001 From: Jeff Avallone Date: Wed, 10 Dec 2014 06:18:55 -0500 Subject: [PATCH] Adding code to indicate subexpression numbers --- src/js/parser/javascript.js | 4 ++++ src/js/parser/javascript/subexp.js | 10 ++++++++-- src/js/regexper.js | 2 ++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/js/parser/javascript.js b/src/js/parser/javascript.js index 7679bb2..48ce9f2 100644 --- a/src/js/parser/javascript.js +++ b/src/js/parser/javascript.js @@ -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; diff --git a/src/js/parser/javascript/subexp.js b/src/js/parser/javascript/subexp.js index a796bbb..607b281 100644 --- a/src/js/parser/javascript/subexp.js +++ b/src/js/parser/javascript/subexp.js @@ -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; + }, }); diff --git a/src/js/regexper.js b/src/js/regexper.js index 6079a51..3134fcf 100644 --- a/src/js/regexper.js +++ b/src/js/regexper.js @@ -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();