Skip to content

Commit

Permalink
Support negation (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vadim Demedes authored Nov 3, 2020
1 parent 4cdb252 commit 3cacebc
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/lexer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,3 +243,28 @@ test('Lexer passes new line fixtures', () => {
)
])
})

test('Lexer passes negations', () => {
testFixtures([
fix('!true', [t.Operator('!'), t.Ident('true'), t.EOS()], false),
fix('!(event = "X")', [
t.Operator('!'),
t.ParenLeft(),
t.Ident('event'),
t.Operator('='),
t.String('"X"'),
t.ParenRight(),
t.EOS()
], false),
fix('!contains(event, "X")', [
t.Operator('!'),
t.Ident('contains'),
t.ParenLeft(),
t.Ident('event'),
t.Comma(),
t.String('"X"'),
t.ParenRight(),
t.EOS()
], false)
])
})
9 changes: 9 additions & 0 deletions src/lexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ export class Lexer {
continue
}

if (char === '!') {
const nextChar = this.peek()

if (isAlpha(nextChar) || nextChar === '(') {
tokens.push(t.Operator('!'))
continue
}
}

if (isAlpha(char) || char === '!' || char === '=' || char === '>' || char === '<') {
tokens.push(this.lexOperatorOrConditional(char))
continue
Expand Down

0 comments on commit 3cacebc

Please sign in to comment.