Skip to content

Commit

Permalink
add not equals
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianHicks committed Jun 11, 2021
1 parent fa7769e commit e32342b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Datalog.elm
Expand Up @@ -870,6 +870,7 @@ type Token
| GreaterThan
| GreaterThanOrEquals
| Equals
| NotEquals
| OrToken
| NotToken
| LineComment
Expand Down Expand Up @@ -1012,6 +1013,8 @@ opParser =
|. Parser.token greaterThanToken
, Parser.succeed eq
|. Parser.token equalsToken
, Parser.succeed (\lhs rhs -> not_ (eq lhs rhs))
|. Parser.token notEqualsToken
]


Expand Down Expand Up @@ -1174,6 +1177,11 @@ equalsToken =
Parser.Token "=" (ExpectedToken Equals)


notEqualsToken : Parser.Token ParsingProblem
notEqualsToken =
Parser.Token "!=" (ExpectedToken NotEquals)


orToken : Parser.Token ParsingProblem
orToken =
Parser.Token "||" (ExpectedToken OrToken)
Expand Down
12 changes: 12 additions & 0 deletions tests/DatalogTests.elm
Expand Up @@ -485,6 +485,18 @@ datalogTests =
|> with "thing" [ var "name", var "legs" ]
|> filter (eq "legs" (int 8))
]
, test "not equal to" <|
\_ ->
expectParses
"""
notASpider(name) :-
thing(name, legs),
legs != 8.
"""
[ rule "notASpider" [ "name" ]
|> with "thing" [ var "name", var "legs" ]
|> filter (not_ (eq "legs" (int 8)))
]
, test "or" <|
\_ ->
expectParses
Expand Down

0 comments on commit e32342b

Please sign in to comment.