Skip to content
Open
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: 1 addition & 7 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
name: Main workflow

on:
"on":
- pull_request

jobs:
Expand Down Expand Up @@ -33,9 +33,3 @@ jobs:
- run: opam exec -- dune runtest --instrument-with bisect_ppx --force

- run: opam exec -- bisect-ppx-report summary --per-file

- name: Upload the build artifact
uses: actions/upload-artifact@v2
with:
name: ${{ matrix.os }}-${{ matrix.ocaml-version }}-fex.exe
path: _build/default/bin/fex.exe
83 changes: 34 additions & 49 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,70 +1,55 @@
.PHONY: build
build:
@dune build @all -j8

.PHONY: build-js
build-js:
@dune build fex_js/fex.bc.js --profile=release -j8

.PHONY: install-deps
install-deps:
@opam install . --deps-only --with-doc --with-test

.PHONY: update
update:
opam update

.PHONY: upgrade
upgrade:
opam upgrade
OPAM_SWITCH_VER=5.0.0
RELEASE_NAME!=git describe --tags --always --dirty --abbrev=7
RELEASE_NAME ?= $(shell git describe --tags --always --dirty --abbrev=7)

.PHONY: lock
lock:
opam lock -d fex

.PHONY: update-deps
update-deps: update upgrade lock
.PHONY: build
build: deps
@opam exec -- dune build @all -j8

.PHONY: watch
watch:
@dune build @all --watch -j8

.PHONY: build-js
watch-js:
@dune build fex_js/fex.bc.js --profile=release -w -j8

.PHONY: install
install:
@dune install
@opam exec -- dune build @all --watch -j8

.PHONY: test
test:
@dune runtest --force
@opam exec -- dune runtest --force

.PHONY: watch-test
watch-test:
@dune runtest -w
@opam exec -- dune runtest -w

.PHONY: coverage
coverage:
@dune runtest --instrument-with bisect_ppx --force
@bisect-ppx-report summary --per-file
@bisect-ppx-report html
@opam exec -- dune runtest --instrument-with bisect_ppx --force
@opam exec -- bisect-ppx-report summary --per-file
@opam exec -- bisect-ppx-report html

.PHONY: fmt
.PHONY: format
format:
@dune build @fmt --auto-promote
@opam exec -- dune build @fmt --auto-promote

.PHONY: clean
clean:
@dune clean
@rm -Rf _coverage

.PHONY: doc
doc:
@dune build @doc

.PHONY: doc-serve
doc-serve:
@dune build @doc -w &
@(cd _build/default/_doc/_html/; cohttp-server-lwt)
.PHONY: create-switch
create-switch: _opam/.opam-switch/config/ocaml.config
@echo "current switch: $$(opam switch show) $(RELEASE_NAME)"

.PHONY: setup
setup: create-switch
-opam install dune
-opam install ocaml-lsp-server ocamlformat odig utop bisect_ppx
-opam exec -- dune build @install
opam install . --deps-only --with-test

.PHONY: deps
deps: create-switch
@if ! opam install . --check --deps-only; then \
echo "Fetching and building deps..."; \
opam install . --deps-only --yes; \
fi;

_opam/.opam-switch/config/ocaml.config:
-opam switch create . ${OPAM_SWITCH_VER} --deps-only --with-test --locked --yes 2>>/dev/null
1 change: 0 additions & 1 deletion bin/dune
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
(executable
(modes js exe)
(name fex)
(public_name fex)
(instrumentation
Expand Down
13 changes: 9 additions & 4 deletions bin/fex.ml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,20 @@ let fex_record_op fex json =
exit 124
in
let print_for_pairs filter_lst pairs =
if Fex_compiler.apply_list_filter_for_pairs filter_lst pairs then
if Fex_compiler.apply_list_filter_for_pairs filter_lst pairs then (
try
List.iter sprint_pair pairs ;
print_newline ()
with
| Invalid_argument a ->
print_endline a ;
print_endline "fuck off"
| _ -> print_endline "shit"
let stack = Printexc.get_backtrace () in
Printf.eprintf "Argument Error [%s] %s\n" a stack ;
exit 124
| e ->
let msg = Printexc.to_string e
and stack = Printexc.get_backtrace () in
Printf.eprintf "Error %s%s\n" msg stack ;
exit 123)
in
let _ =
list_of_pairs |> List.hd |> List.iter sprint_key ;
Expand Down
9 changes: 3 additions & 6 deletions bin_test/examples.t
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,17 @@ Finds person under 51
person a|50|1|d|

Finds person betwen 49 and 51
$ fex "age:49..51" data.json
$ fex "age:=49..51" data.json
name|age|prop.a|prop.b.c|
person a|50|1|d|

Finds person betwen 50 and 52
$ fex "age:50..52" data.json
$ fex "age:=50..52" data.json
name|age|prop.a|prop.b.c|
person b|51|2|f|

Finds person betwen 40 and 60
$ fex "age:40..60" data.json
$ fex "age:=40..60" data.json
name|age|prop.a|prop.b.c|
person a|50|1|d|
person b|51|2|f|
Expand All @@ -93,6 +93,3 @@ Finds person with prop.a > 1
Finds person nested c and value exists
$ fex ":+" data.json
name|age|prop.a|prop.b.c|
Syntax error 5 on line 1, character 2: <YOUR SYNTAX ERROR MESSAGE HERE>


2 changes: 1 addition & 1 deletion bin_test/help.t
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
Show version information.

EXIT STATUS
fex exits with the following status:
fex exits with:

0 on success.

Expand Down
24 changes: 18 additions & 6 deletions compiler/ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@ type 'a match_type =
]

module Number = struct
type t = int * float option [@@deriving show, eq, ord]
type t = string * int * float option [@@deriving show, ord]

let of_int i = (i, None)
let equal (_, i1, rf1) (_, i2, rf2) = i1 = i2 && rf1 = rf2
let of_int i = (string_of_int i, i, None)

let of_float f =
if Float.is_integer f then (Float.to_int f, None)
else (Float.to_int f, Some (f -. Float.trunc f))
if Float.is_integer f then (Float.to_string f, Float.to_int f, None)
else (Float.to_string f, Float.to_int f, Some (f -. Float.trunc f))

let of_string s =
let _, i, rf = of_float @@ Float.of_string s in
(String.trim s, i, rf)
end

type 'a string_match_operation =
Expand All @@ -32,7 +37,7 @@ type number_match_operation =
| ExactNumber of number
| LessThanNumber of number
| GreaterThanNumber of number
| BetweeNumber of number * number
| BetweenNumber of number * number
[@@deriving show, eq]

type 'a match_operation =
Expand Down Expand Up @@ -83,19 +88,26 @@ let is_exclude = function

let number_of_int = Number.of_int
let number_of_float = Number.of_float
let number_of_string = Number.of_string
let number_comp = Number.compare
let number_op op = NumberOp op
let exact_of_num num = number_op (ExactNumber num)
let exact_of_int num = num |> number_of_int |> exact_of_num
let exact_of_float num = num |> number_of_float |> exact_of_num
let exact_of_string num = num |> number_of_string |> exact_of_num
let less_than num = number_op (LessThanNumber num)
let less_than_of_int num = num |> number_of_int |> less_than
let less_than_of_float num = num |> number_of_float |> less_than
let less_than_of_string num = num |> number_of_string |> less_than
let greater_than num = number_op (GreaterThanNumber num)
let greater_than_of_int num = num |> number_of_int |> greater_than
let greater_than_of_float num = num |> number_of_float |> greater_than
let between low high = number_op (BetweeNumber (low, high))
let greater_than_of_string num = num |> number_of_string |> greater_than
let between low high = number_op (BetweenNumber (low, high))
let between_of_int low high = between (number_of_int low) (number_of_int high)

let between_of_float low high =
between (number_of_float low) (number_of_float high)

let between_of_string low high =
between (number_of_string low) (number_of_string high)
9 changes: 7 additions & 2 deletions compiler/ast.mli
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type match_operation_result =
| Exclude
[@@deriving show, eq]

type number = int * float option [@@deriving show, eq, ord]
type number = string * int * float option [@@deriving show, eq, ord]

type 'a match_type =
[ `String of 'a
Expand All @@ -35,7 +35,7 @@ type number_match_operation =
| ExactNumber of number
| LessThanNumber of number
| GreaterThanNumber of number
| BetweeNumber of number * number
| BetweenNumber of number * number
[@@deriving show, eq]

type 'a match_operation =
Expand Down Expand Up @@ -103,15 +103,19 @@ val contains_value : ?op:match_operation_result -> 'a -> 'a t

val exact_of_int : int -> 'a match_operation
val exact_of_float : float -> 'a match_operation
val exact_of_string : string -> 'a match_operation
val exact_of_num : number -> 'a match_operation
val less_than_of_int : int -> 'a match_operation
val less_than_of_float : float -> 'a match_operation
val less_than_of_string : string -> 'a match_operation
val less_than : number -> 'a match_operation
val greater_than_of_int : int -> 'a match_operation
val greater_than_of_float : float -> 'a match_operation
val greater_than_of_string : string -> 'a match_operation
val greater_than : number -> 'a match_operation
val between_of_int : int -> int -> 'a match_operation
val between_of_float : float -> float -> 'a match_operation
val between_of_string : string -> string -> 'a match_operation
val between : number -> number -> 'a match_operation

(** {2 Ast helpers} *)
Expand All @@ -134,6 +138,7 @@ val is_include : 'a t -> bool

val number_of_int : int -> number
val number_of_float : float -> number
val number_of_string : string -> number
val string_op_of_op : 'a match_operation -> 'a string_match_operation option
val number_op_of_op : 'a match_operation -> number_match_operation option
val number_comp : number -> number -> int
4 changes: 2 additions & 2 deletions compiler/combiner.ml
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ let group_as ~equal_fun a b =
IncludePairGroupLessThanNumber num
| PairFilter (Include, NumberOp (GreaterThanNumber num), _) ->
IncludePairGroupGreaterThanNumber num
| PairFilter (Include, NumberOp (BetweeNumber (bottom, top)), _) ->
| PairFilter (Include, NumberOp (BetweenNumber (bottom, top)), _) ->
IncludePairGroupBetweenNumber (bottom, top)
| PairFilter (Exclude, NumberOp (ExactNumber num), _) ->
ExcludePairGroupExactNumber num
| PairFilter (Exclude, NumberOp (LessThanNumber num), _) ->
ExcludePairGroupLessThanNumber num
| PairFilter (Exclude, NumberOp (GreaterThanNumber num), _) ->
ExcludePairGroupGreaterThanNumber num
| PairFilter (Exclude, NumberOp (BetweeNumber (bottom, top)), _) ->
| PairFilter (Exclude, NumberOp (BetweenNumber (bottom, top)), _) ->
ExcludePairGroupBetweenNumber (bottom, top)
in
let category_a = categorize a in
Expand Down
10 changes: 5 additions & 5 deletions compiler/filter_lexer.mll
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ rule read_tokens =
| ws '=' { EQUAL }
| ws '<' { L_ANGLE }
| ws '>' { R_ANGLE }
| '.' '.'+ { DOTDOT }
| ws '.' '.'+ ws { DOTDOT }
| ws '-'? digit+
{ FLOAT (Lexing.lexeme lexbuf |> float_of_string) }
{ NUMBER (Lexing.lexeme lexbuf) }
| ws '-'? digit+ '.' digit+
{ FLOAT (Lexing.lexeme lexbuf |> float_of_string) }
{ NUMBER (Lexing.lexeme lexbuf) }
| '\'' { read_string (Buffer.create 1) lexbuf }
| '"' { read_string2 (Buffer.create 1) lexbuf }
| str { STRING (Lexing.lexeme lexbuf |> String.trim) }
Expand All @@ -55,7 +55,7 @@ and read_string buf =
{ Buffer.add_string buf (Lexing.lexeme lexbuf);
read_string buf lexbuf }
| _ { raise (SyntaxError ("Illegal string character: " ^ Lexing.lexeme lexbuf)) }
| eof { raise (SyntaxError ("String is not terminated")) }
| eof { STRING ("'" ^ Buffer.contents buf) }

and read_string2 buf =
parse
Expand All @@ -68,4 +68,4 @@ and read_string2 buf =
{ Buffer.add_string buf (Lexing.lexeme lexbuf);
read_string2 buf lexbuf }
| _ { raise (SyntaxError ("Illegal string character: " ^ Lexing.lexeme lexbuf)) }
| eof { raise (SyntaxError ("String is not terminated")) }
| eof { STRING ("\"" ^ Buffer.contents buf) }
Loading