feat(complex-matcher): empty string is supported (#31)
This commit is contained in:
parent
2e945e8349
commit
8532d563de
@ -74,6 +74,16 @@ class Node {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class Null extends Node {
|
||||||
|
match () {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
toString () {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const formatTerms = terms => terms.map(term => term.toString(true)).join(' ')
|
const formatTerms = terms => terms.map(term => term.toString(true)).join(' ')
|
||||||
|
|
||||||
export class And extends Node {
|
export class And extends Node {
|
||||||
@ -202,7 +212,8 @@ export class TruthyProperty extends Node {
|
|||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
|
|
||||||
// terms = term+
|
// terms = null || term+
|
||||||
|
// *null = /$/
|
||||||
// term = ws (and | or | not | property | truthyProperty | string) ws
|
// term = ws (and | or | not | property | truthyProperty | string) ws
|
||||||
// ws = ' '*
|
// ws = ' '*
|
||||||
// *and = "(" terms ")"
|
// *and = "(" terms ")"
|
||||||
@ -234,7 +245,7 @@ export const parse = invoke(() => {
|
|||||||
const parseTerms = Node => {
|
const parseTerms = Node => {
|
||||||
let term = parseTerm()
|
let term = parseTerm()
|
||||||
if (!term) {
|
if (!term) {
|
||||||
return
|
return new Null()
|
||||||
}
|
}
|
||||||
|
|
||||||
const terms = [term]
|
const terms = [term]
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
getPropertyClausesStrings,
|
getPropertyClausesStrings,
|
||||||
|
Null,
|
||||||
parse,
|
parse,
|
||||||
setPropertyClause,
|
setPropertyClause,
|
||||||
} from './'
|
} from './'
|
||||||
@ -15,8 +16,14 @@ it('getPropertyClausesStrings', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('parse', () => {
|
describe('parse', () => {
|
||||||
expect(parse(pattern)).toEqual(ast)
|
it('analyses a string and returns a node/tree', () => {
|
||||||
|
expect(parse(pattern)).toEqual(ast)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('supports an empty string', () => {
|
||||||
|
expect(parse('')).toEqual(new Null())
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('setPropertyClause', () => {
|
describe('setPropertyClause', () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user