Skip to content
Draft
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
12 changes: 3 additions & 9 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
---
name: Main workflow

on:
"on":
- pull_request

jobs:
build:
strategy:
fail-fast: false
fail-fast: true
matrix:
os:
- ubuntu-latest
ocaml-version:
- 4.13.1
- 5.0.0

runs-on: ${{ matrix.os }}

Expand All @@ -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
18 changes: 13 additions & 5 deletions bin/fex.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,31 @@ let sprint_key (`Pair (`Key key, _value)) = sprint_value key
let sprint_pair (`Pair (_key, `Value value)) = sprint_value value

let fex_record_op fex json =
let list_of_pairs =
let (list_of_pairs : Fex_flattener.pairs list) =
match json with
| `List lst -> Fex_flattener.pairs_from_json_array (`List lst)
| _ ->
Printf.eprintf "must be a json array" ;
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
(List.map Fex_compiler.Predicate.pair_of 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
66 changes: 23 additions & 43 deletions compiler/ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,21 @@ type match_operation_result =
| Exclude
[@@deriving show, eq]

type 'a match_type =
[ `String of 'a
| `Int of int
| `Float of float
]

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

let 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))
end

type 'a string_match_operation =
| ExactString of 'a
| ContainsString of 'a list
| BeginsWithString of 'a list
| EndsWithString of 'a list
[@@deriving show, eq]

type number = Number.t [@@deriving show, eq, ord]

type number_match_operation =
| ExactNumber of number
| LessThanNumber of number
| GreaterThanNumber of number
| BetweeNumber of number * number
[@@deriving show, eq]

type 'a match_operation =
| StringOp of 'a string_match_operation
type match_type = ..
type match_type += String of string | Int of int | Float of float
type string_match_operation = Match_string.op [@@deriving show, eq]
type number = Match_number.t [@@deriving show, eq, ord]
type number_match_operation = Match_number.op [@@deriving show, eq]

type match_operation =
| StringOp of string_match_operation
| NumberOp of number_match_operation
[@@deriving show, eq]

type 'a t =
| ValueFilter of match_operation_result * 'a match_operation
| KeyFilter of match_operation_result * 'a match_operation
| PairFilter of
match_operation_result * 'a match_operation * 'a match_operation
type t =
| ValueFilter of match_operation_result * match_operation
| KeyFilter of match_operation_result * match_operation
| PairFilter of match_operation_result * match_operation * match_operation
[@@deriving show, eq]

let exc = Exclude
Expand Down Expand Up @@ -81,21 +54,28 @@ let is_exclude = function
| PairFilter (Exclude, _, _) -> true
| _ -> false

let number_of_int = Number.of_int
let number_of_float = Number.of_float
let number_comp = Number.compare
let number_of_int = Match_number.T.of_int
let number_of_float = Match_number.T.of_float
let number_of_string = Match_number.T.of_string
let number_comp = Match_number.T.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)
Loading