Skip to content
This repository was archived by the owner on Jun 9, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/Language/Helpers/buildQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,13 @@ function buildQuery(query, builder = new Builder()) {
// Now, append that method to the builder object.
method.setParameters(parameters).callMethodOn(builder)
} catch (e) {
if (Array.isArray(parameters[0])) {
const lastIndex = parameters.length - 1
if (Array.isArray(parameters[lastIndex])) {
if (lastIndex !== 0) {
method.setParameters(parameters.slice(0, lastIndex))
}
method.callMethodOn(builder)
builder.and(buildQuery(parameters[0], new NonCapture()))
builder.and(buildQuery(parameters[lastIndex], new NonCapture()))
} else {
throw new SyntaxException(`Invalid parameter given for ${method.origin}`)
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "srl",
"version": "0.2.1",
"version": "0.2.2",
"description": "Simple Regex Language",
"main": "lib/SRL.js",
"scripts": {
Expand Down
19 changes: 19 additions & 0 deletions test/issue-11-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict'

const assert = require('assert')
const SRL = require('../')

describe('Fix issue 11', () => {
it('Numerical quantifies & non-capturing group', () => {
const query = new SRL('digit, exactly 5 times, (letter, twice) optional')
assert.ok(query.isMatching('12345'))
assert.ok(query.isMatching('12345aa'))
})

it('Complicated case', () => {
const query = new SRL('begin with, digit, exactly 5 times, ( literally \'-\', digit, exactly 4 times ), optional, must end')
assert.ok(query.isMatching('12345-1234'))
})
})


4 changes: 2 additions & 2 deletions test/parseParentheses-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ describe('ParseParentheses Test', () => {
assert.deepEqual(parseParentheses('foo (0)'), [ 'foo', [ '0' ] ])

assert.deepEqual(
parseParentheses('foo (bar (nested)) baz'),
[ 'foo', [ 'bar', [ 'nested' ] ], 'baz' ]
parseParentheses('foo (bar (nested)) baz'),
[ 'foo', [ 'bar', [ 'nested' ] ], 'baz' ]
)

assert.deepEqual(
Expand Down