File tree 3 files changed +37
-2
lines changed
3 files changed +37
-2
lines changed Original file line number Diff line number Diff line change @@ -93,6 +93,9 @@ class Builder {
93
93
94
94
/** @var {string} _implodeString String to join with. */
95
95
this . _implodeString = ''
96
+
97
+ /** @var {array} _captureNames Save capture names to map */
98
+ this . _captureNames = [ ]
96
99
}
97
100
98
101
/**********************************************************/
@@ -254,9 +257,14 @@ class Builder {
254
257
* Create capture group of given conditions.
255
258
*
256
259
* @param {Closure|Builder|string } condition Anonymous function with its Builder as a first parameter.
260
+ * @param {String } name
257
261
* @return {Builder }
258
262
*/
259
- capture ( conditions ) {
263
+ capture ( conditions , name ) {
264
+ if ( name ) {
265
+ this . _captureNames . push ( name )
266
+ }
267
+
260
268
this . _validateAndAddMethodType ( METHOD_TYPE_GROUP , METHOD_TYPES_ALLOWED_FOR_CHARACTERS )
261
269
262
270
return this . _addClosure ( new Builder ( ) . _extends ( '(%s)' ) , conditions )
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ const SimpleMethod = require('../Methods/SimpleMethod')
6
6
const ToMethod = require ( '../Methods/ToMethod' )
7
7
const TimesMethod = require ( '../Methods/TimesMethod' )
8
8
const AndMethod = require ( '../Methods/AndMethod' )
9
+ const AsMethod = require ( '../Methods/AsMethod' )
9
10
10
11
const SyntaxException = require ( '../../Exceptions/Syntax' )
11
12
@@ -49,7 +50,7 @@ const mapper = {
49
50
'exactly' : { 'class' : TimesMethod , 'method' : 'exactly' } ,
50
51
'at least' : { 'class' : TimesMethod , 'method' : 'atLeast' } ,
51
52
'between' : { 'class' : AndMethod , 'method' : 'between' } ,
52
- 'capture' : { 'class' : DefaultMethod , 'method' : 'capture' }
53
+ 'capture' : { 'class' : AsMethod , 'method' : 'capture' }
53
54
}
54
55
55
56
/**
Original file line number Diff line number Diff line change
1
+ 'use strict'
2
+
3
+ const Method = require ( './Method' )
4
+
5
+ /**
6
+ * Method having simple parameter(s) ignoring "as".
7
+ */
8
+ class AsMethod extends Method {
9
+ /**
10
+ * @inheritdoc
11
+ */
12
+ setParameters ( parameters ) {
13
+ parameters = parameters . filter ( ( parameter ) => {
14
+ if ( typeof parameter !== 'string' ) {
15
+ return true
16
+ }
17
+
18
+ const lower = parameter . toLowerCase ( )
19
+ return lower !== 'as'
20
+ } )
21
+
22
+ return super . setParameters ( parameters )
23
+ }
24
+ }
25
+
26
+ module . exports = AsMethod
You can’t perform that action at this time.
0 commit comments