Skip to content

Commit

Permalink
Squashed types, fixed tests for older version support
Browse files Browse the repository at this point in the history
  • Loading branch information
mtvch committed Feb 19, 2024
1 parent 60de611 commit 73d1788
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
12 changes: 5 additions & 7 deletions lib/ex_pression/parser/grammar.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ defmodule ExPression.Parser.Grammar do
S <- {' ', '\t', '\r', '\n'}

# Basic atoms
True <- "true" * fn cs -> [true | cs] end
TrueP <- "True" * fn cs -> [true | cs] end
False <- "false" * fn cs -> [false | cs] end
FalseP <- "False" * fn cs -> [false | cs] end
Null <- "null" * fn cs -> [nil | cs] end
True <- ("True" | "true") * fn cs -> [true | cs] end
False <- ("False" | "false") * fn cs -> [false | cs] end
Null <- ("None" | "null") * fn cs -> [nil | cs] end

# Strings
Xdigit <- {'0'..'9', 'a'..'f', 'A'..'F'}
Expand All @@ -28,7 +26,7 @@ defmodule ExPression.Parser.Grammar do
Integer <- int(opt('-') * ('0' | {'1'..'9'}) * star({'0'..'9'}))
Float <- float(opt('-') * ('0' | {'1'..'9'}) * star({'0'..'9'}) * (("." * +{'0'..'9'}) | ({'e', 'E'} * opt({'+', '-'}) * +{'0'..'9'})))

KeyWord <- ("False" | "True" | "false" | "true" | "null" | "or" | "and" | "not")
KeyWord <- ("None" | "False" | "True" | "false" | "true" | "null" | "or" | "and" | "not")
IdentifierRest <- {'a'..'z', 'A'..'Z', '_', '0'..'9'}
Identifier1 <- {'a'..'z', 'A'..'Z', '_'} * star(IdentifierRest)
Identifier <- str((KeyWord * Identifier1) | (!KeyWord * Identifier1))
Expand All @@ -41,7 +39,7 @@ defmodule ExPression.Parser.Grammar do
L5 <- L6 * star(L5BinOp)
L6 <- L7 * star(L6BinOp)
L7 <- (Special | FCall | Object | Array | Var | Const | "(" * star(S) * Expr * star(S) * ")") * star(AccessOp)
Const <- String | Float | Integer | Null | True | False | TrueP | FalseP
Const <- String | Float | Integer | Null | True | False
Var <- Identifier * fn [name | cs] -> [{:var, [name]} | cs] end

Special <- str("$") * (String | str(+IdentifierRest)) * fn [value, special | cs] -> [{:special, [special, value]} | cs] end
Expand Down
2 changes: 1 addition & 1 deletion test/ex_pression/interpreter_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ defmodule ExPression.InterpreterTest do
test "function_call and deep dig (sad path)" do
{:ok, ast} = Parser.parse("some_result().key.unknown_field")

assert_raise(ArgumentError, ~r/existing atom/, fn ->
assert_raise(ArgumentError, ~r/(existing atom)|(argument error)/, fn ->
Interpreter.eval(ast, %{}, ObjWithStruct)
end)
end
Expand Down

0 comments on commit 73d1788

Please sign in to comment.