From b8ca9aeb5d57302d2af8d9accc02ce4678d61f70 Mon Sep 17 00:00:00 2001 From: Paul Monson Date: Sat, 28 Oct 2023 09:25:28 -0500 Subject: [PATCH 1/4] Update makefile and depdencies --- Makefile | 79 ++++++++++++++++++++++--------------------------- bin_test/help.t | 2 +- 2 files changed, 37 insertions(+), 44 deletions(-) diff --git a/Makefile b/Makefile index 08fd845..ed7d1f3 100644 --- a/Makefile +++ b/Makefile @@ -1,70 +1,63 @@ +OPAM_SWITCH_VER=5.0.0 +RELEASE_NAME!=git describe --tags --always --abbrev=7 +RELEASE_NAME ?= $(shell git describe --tags --always --abbrev=7) + .PHONY: build -build: - @dune build @all -j8 +build: deps + @opam exec -- 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 - -.PHONY: lock -lock: - opam lock -d fex - -.PHONY: update-deps -update-deps: update upgrade lock + @opam exec -- dune build fex_js/fex.bc.js --profile=release -j8 .PHONY: watch watch: - @dune build @all --watch -j8 + @opam exec -- 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 fex_js/fex.bc.js --profile=release -w -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)" + +.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 --yes 2>>/dev/null diff --git a/bin_test/help.t b/bin_test/help.t index c135b16..4166688 100644 --- a/bin_test/help.t +++ b/bin_test/help.t @@ -29,7 +29,7 @@ Show version information. EXIT STATUS - fex exits with the following status: + fex exits with: 0 on success. From 20e56c03c72c546d55e0dff767de6edfe5e2df3a Mon Sep 17 00:00:00 2001 From: Paul Monson Date: Sun, 17 Dec 2023 15:09:27 -0600 Subject: [PATCH 2/4] Minor clean ups --- .github/workflows/workflow.yml | 8 +------- Makefile | 12 ++---------- bin/fex.ml | 13 +++++++++---- fex_js/dune | 6 ------ fex_js/fex.ml | 29 ----------------------------- fex_js_test/dune | 0 fex_js_test/example.t | 2 -- 7 files changed, 12 insertions(+), 58 deletions(-) delete mode 100644 fex_js/dune delete mode 100644 fex_js/fex.ml delete mode 100644 fex_js_test/dune delete mode 100644 fex_js_test/example.t diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 4f608d6..f0e787e 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -1,7 +1,7 @@ --- name: Main workflow -on: +"on": - pull_request jobs: @@ -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 diff --git a/Makefile b/Makefile index ed7d1f3..2777cde 100644 --- a/Makefile +++ b/Makefile @@ -1,23 +1,15 @@ OPAM_SWITCH_VER=5.0.0 -RELEASE_NAME!=git describe --tags --always --abbrev=7 -RELEASE_NAME ?= $(shell git describe --tags --always --abbrev=7) +RELEASE_NAME!=git describe --tags --always --dirty --abbrev=7 +RELEASE_NAME ?= $(shell git describe --tags --always --dirty --abbrev=7) .PHONY: build build: deps @opam exec -- dune build @all -j8 -.PHONY: build-js -build-js: - @opam exec -- dune build fex_js/fex.bc.js --profile=release -j8 - .PHONY: watch watch: @opam exec -- dune build @all --watch -j8 -.PHONY: build-js -watch-js: - @opam exec -- dune build fex_js/fex.bc.js --profile=release -w -j8 - .PHONY: test test: @opam exec -- dune runtest --force diff --git a/bin/fex.ml b/bin/fex.ml index 620ace7..e49b874 100644 --- a/bin/fex.ml +++ b/bin/fex.ml @@ -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 ; diff --git a/fex_js/dune b/fex_js/dune deleted file mode 100644 index 7709a3c..0000000 --- a/fex_js/dune +++ /dev/null @@ -1,6 +0,0 @@ -(executable - (modes js) - (name fex) - (libraries js_of_ocaml fex.compiler brr fex.flattener yojson) - (preprocess - (pps js_of_ocaml-ppx))) diff --git a/fex_js/fex.ml b/fex_js/fex.ml deleted file mode 100644 index 8aa4928..0000000 --- a/fex_js/fex.ml +++ /dev/null @@ -1,29 +0,0 @@ -open Js_of_ocaml - -let a = - Js.export_all - (object%js - (* method flattenArray (obj)= *) - (* let as_yojson = obj |> Jv.to_string |> Yojson.Safe.from_string in *) - (* let as_list = match as_yojson with *) - (* | `List lst -> `List lst *) - (* | _ -> failwith "must be a json array" *) - (* in *) - (* Fex_flattener.pairs_from_json_array as_list *) - - (* method flattenObject (obj:Jv.t) = *) - (* let as_yojson = obj |> Jv.to_string |> Yojson.Safe.from_string in *) - (* Fex_flattener.pair_list_of_json as_yojson *) - - (* method applyListFilter (filter:Jstr.t) pairs = *) - (* let filter' = Fex_compiler.filter_from_string filter in *) - (* match filter' with *) - (* | Ok filters -> Fex_compiler.apply_list_filter filters pairs *) - (* | Error err -> failwith err *) - - (* method applyListOfFiltersForPair (filter:Jstr.t) pairs = *) - (* let filter' = Fex_compiler.filter_from_string filter in *) - (* match filter' with *) - (* | Ok filters -> Fex_compiler.apply_list_filter_for_pairs filters pairs *) - (* | Error err -> failwith err *) - end) diff --git a/fex_js_test/dune b/fex_js_test/dune deleted file mode 100644 index e69de29..0000000 diff --git a/fex_js_test/example.t b/fex_js_test/example.t deleted file mode 100644 index 5cafc66..0000000 --- a/fex_js_test/example.t +++ /dev/null @@ -1,2 +0,0 @@ - $ echo shit - shit From 5dfa4455c0e87754770e01475a5566628639f918 Mon Sep 17 00:00:00 2001 From: Paul Monson Date: Fri, 22 Dec 2023 08:51:22 -0600 Subject: [PATCH 3/4] Staging --- Makefile | 4 +-- bin/dune | 1 - compiler/filter_lexer.mll | 4 +-- compiler/filter_parser.mly | 13 ++++------ dune-project | 5 ---- fex.opam | 4 --- fex.opam.locked | 51 ------------------------------------- flattener/fex_flattener.ml | 2 ++ flattener/fex_flattener.mli | 1 + flattener_test/json_test.ml | 14 ++++++++++ 10 files changed, 26 insertions(+), 73 deletions(-) delete mode 100644 fex.opam.locked diff --git a/Makefile b/Makefile index 2777cde..1d95a42 100644 --- a/Makefile +++ b/Makefile @@ -35,7 +35,7 @@ clean: .PHONY: create-switch create-switch: _opam/.opam-switch/config/ocaml.config - @echo "current switch: $$(opam switch show)" + @echo "current switch: $$(opam switch show) $(RELEASE_NAME)" .PHONY: setup setup: create-switch @@ -52,4 +52,4 @@ deps: create-switch fi; _opam/.opam-switch/config/ocaml.config: - -opam switch create . ${OPAM_SWITCH_VER} --deps-only --yes 2>>/dev/null + -opam switch create . ${OPAM_SWITCH_VER} --deps-only --with-test --locked --yes 2>>/dev/null diff --git a/bin/dune b/bin/dune index 6cac9b4..d98f4cb 100644 --- a/bin/dune +++ b/bin/dune @@ -1,5 +1,4 @@ (executable - (modes js exe) (name fex) (public_name fex) (instrumentation diff --git a/compiler/filter_lexer.mll b/compiler/filter_lexer.mll index f29b5d1..5801a8e 100644 --- a/compiler/filter_lexer.mll +++ b/compiler/filter_lexer.mll @@ -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 @@ -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) } diff --git a/compiler/filter_parser.mly b/compiler/filter_parser.mly index 3373909..92903c1 100644 --- a/compiler/filter_parser.mly +++ b/compiler/filter_parser.mly @@ -22,8 +22,6 @@ op_result: %inline string_list: | values= separated_nonempty_list(" ", STRING) { values } - | f= FLOAT; values= separated_nonempty_list(" ", STRING) - { (string_of_float f) :: values } %inline q_string_list: | values= separated_nonempty_list(" ", Q_STRING) { values } @@ -40,12 +38,11 @@ standard_term: number: | f= FLOAT { f } -number_value_term: - | "<"; f= number; { Ast.less_than_of_float f } - | ">"; f= number; { Ast.greater_than_of_float f } - | "="; f= number; { Ast.exact_of_float f } - | l= number; " "*; ".."; h= number - { Ast.between_of_float l h } +number_value_term: (* The operator needs to be managed differently and moved into the term clause, it makes me wonder if we want a seperate value lexer clause to deal with this? *) + | "<"; f= number; { Ast.less_than_of_float f } (* should maybe be the Number.t here? *) + | ">"; f= number; { Ast.greater_than_of_float f } + | "="; f= number; { Ast.exact_of_float f } + | l= number; " "*; ".."; h= number { Ast.between_of_float l h } %inline value_term: | " "*; term= standard_term { term } diff --git a/dune-project b/dune-project index 5626c46..e5f1d0c 100644 --- a/dune-project +++ b/dune-project @@ -1,6 +1,5 @@ (lang dune 2.7) (using menhir 2.0) -(explicit_js_mode) (cram enable) (name fex) @@ -22,12 +21,9 @@ (depends (dune (>= 2.5)) (ocaml (>= 4.08)) - (js_of_ocaml-compiler (>= 3.7)) - (js_of_ocaml-ppx (>= 3.7)) (cmdliner (>= 0.9)) (bos (>= 0.2)) - (brr (>= 0.0.1)) (containers (>= 3.2)) (menhir (>= 20200624)) (yojson (>= 1.7.0)) @@ -36,7 +32,6 @@ ;; Testing (alcotest (and :with-test (>= 1.1))) - (merlin :dev) (ocamlformat :dev) (ocp-indent :dev) (ocp-index :dev) diff --git a/fex.opam b/fex.opam index c3092ea..5cb308e 100644 --- a/fex.opam +++ b/fex.opam @@ -12,17 +12,13 @@ bug-reports: "https://github.com/pmonson711/fex/issues" depends: [ "dune" {>= "2.7" & >= "2.5"} "ocaml" {>= "4.08"} - "js_of_ocaml-compiler" {>= "3.7"} - "js_of_ocaml-ppx" {>= "3.7"} "cmdliner" {>= "0.9"} "bos" {>= "0.2"} - "brr" {>= "0.0.1"} "containers" {>= "3.2"} "menhir" {>= "20200624"} "yojson" {>= "1.7.0"} "ppx_deriving" {>= "4.4"} "alcotest" {with-test & >= "1.1"} - "merlin" {dev} "ocamlformat" {dev} "ocp-indent" {dev} "ocp-index" {dev} diff --git a/fex.opam.locked b/fex.opam.locked deleted file mode 100644 index 3440a89..0000000 --- a/fex.opam.locked +++ /dev/null @@ -1,51 +0,0 @@ -opam-version: "2.0" -name: "fex" -version: "unreleased" -synopsis: "Parser generater for fex" -description: "Parser generater for fex" -maintainer: "pmonson711@gmail.com" -authors: "Paul Monson" -license: "MIT" -homepage: "https://github.com/pmonson711/fex/" -doc: "https://github.com/pmonson711/fex/" -bug-reports: "https://github.com/pmonson711/fex/issues" -depends: [ - "alcotest" {with-test & = "1.5.0"} - "bisect_ppx" {= "2.8.0" & dev} - "bos" {= "0.2.1"} - "brr" {= "0.0.3"} - "cmdliner" {= "1.1.0"} - "containers" {= "3.6.1"} - "dune" {= "2.9.3"} - "js_of_ocaml-compiler" {= "4.0.0"} - "js_of_ocaml-ppx" {= "4.0.0"} - "menhir" {= "20220210"} - "merlin" {= "4.4-413" & dev} - "ocaml" {= "4.13.1"} - "ocamlformat" {= "0.20.1" & dev} - "ocp-indent" {= "1.8.1" & dev} - "ocp-index" {= "1.3.3" & dev} - "odig" {= "0.0.8" & dev} - "odoc" {= "2.1.0" & with-doc} - "ppx_deriving" {= "5.2.1"} - "utop" {= "2.9.0" & dev} - "yojson" {= "1.7.0"} -] -build: [ - ["dune" "subst"] {dev} - [ - "dune" - "build" - "-p" - name - "-j" - jobs - "@install" - "@runtest" {with-test} - "@doc" {with-doc} - ] -] -dev-repo: "git+https://github.com/pmonson711/fex/" -url { - src: "git+file:///usr/home/pmonson/src/ocaml/fex#main" -} \ No newline at end of file diff --git a/flattener/fex_flattener.ml b/flattener/fex_flattener.ml index bed2098..79420a9 100644 --- a/flattener/fex_flattener.ml +++ b/flattener/fex_flattener.ml @@ -57,3 +57,5 @@ let pairs_from_json_array (`List lst) = List.map pair_from_json lst let pair_list_of_json = function | `List lst -> pairs_from_json_array (`List lst) |> List.flatten | json -> pair_from_json json + +let pair_to_string_tuple = List.map to_string_tuple diff --git a/flattener/fex_flattener.mli b/flattener/fex_flattener.mli index 5a7ddda..8d297fd 100644 --- a/flattener/fex_flattener.mli +++ b/flattener/fex_flattener.mli @@ -18,3 +18,4 @@ type pairs = Pair.StringPair.t list [@@deriving show, eq] val pair_from_json : JSON.t -> pairs val pairs_from_json_array : [ `List of JSON.t list ] -> pairs list val pair_list_of_json : JSON.t -> pairs +val pair_to_string_tuple : pairs -> (string * string) list diff --git a/flattener_test/json_test.ml b/flattener_test/json_test.ml index b66cfaf..82b2c9c 100644 --- a/flattener_test/json_test.ml +++ b/flattener_test/json_test.ml @@ -66,6 +66,19 @@ let l2_composite () = ] {|[{"a": "b"}, "d", 1, 2.3]|} +let to_string_pairs () = + let open Alcotest in + let make_test input expect = + check + (list (pair string string)) + (Printf.sprintf "%s value" @@ Yojson.Safe.to_string input) + (Fex_flattener.pair_to_string_tuple @@ Fex_flattener.pair_from_json input) + expect + in + make_test + (`Assoc [ ("a", `String "b"); ("b", `Int 1); ("c", `Float 1.1) ]) + [ ("a", "b"); ("b", "1"); ("c", "1.1") ] + let suite = let open Alcotest in ( test_name @@ -73,4 +86,5 @@ let suite = ; test_case "Empty Composite values" `Quick empty_composite ; test_case "Level 1 Composite values" `Quick l1_composite ; test_case "Level 2 Composite values" `Quick l2_composite + ; test_case "String pairs" `Quick to_string_pairs ] ) From d798ee17d58bbcc0b15818d4dd10ed3cf94fc00d Mon Sep 17 00:00:00 2001 From: Paul Monson Date: Fri, 22 Dec 2023 15:12:52 -0600 Subject: [PATCH 4/4] Many small updates --- bin_test/examples.t | 9 +- compiler/ast.ml | 24 +- compiler/ast.mli | 9 +- compiler/combiner.ml | 4 +- compiler/filter_lexer.mll | 6 +- compiler/filter_parser.messages | 810 ++++++++++++++++++++++++----- compiler/filter_parser.mly | 125 ++++- compiler/match_in_order.ml | 2 +- compiler_test/fex_compiler_test.ml | 3 +- compiler_test/messages_test.ml | 81 +-- compiler_test/parser_test.ml | 42 +- 11 files changed, 863 insertions(+), 252 deletions(-) diff --git a/bin_test/examples.t b/bin_test/examples.t index c3efec5..a9dd239 100644 --- a/bin_test/examples.t +++ b/bin_test/examples.t @@ -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| @@ -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: - - diff --git a/compiler/ast.ml b/compiler/ast.ml index 31cce63..167aa0b 100644 --- a/compiler/ast.ml +++ b/compiler/ast.ml @@ -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 = @@ -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 = @@ -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) diff --git a/compiler/ast.mli b/compiler/ast.mli index d83f8e5..caa5d69 100644 --- a/compiler/ast.mli +++ b/compiler/ast.mli @@ -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 @@ -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 = @@ -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} *) @@ -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 diff --git a/compiler/combiner.ml b/compiler/combiner.ml index f6cae11..599f8aa 100644 --- a/compiler/combiner.ml +++ b/compiler/combiner.ml @@ -51,7 +51,7 @@ 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 @@ -59,7 +59,7 @@ let group_as ~equal_fun a b = 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 diff --git a/compiler/filter_lexer.mll b/compiler/filter_lexer.mll index 5801a8e..595f3f3 100644 --- a/compiler/filter_lexer.mll +++ b/compiler/filter_lexer.mll @@ -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) } diff --git a/compiler/filter_parser.messages b/compiler/filter_parser.messages index fd0ba8c..809c915 100644 --- a/compiler/filter_parser.messages +++ b/compiler/filter_parser.messages @@ -1,40 +1,62 @@ -terms: COLON PLUS +terms: SPACE COMMA +## +## Ends in an error in state: 1. +## +## list(SPACE) -> SPACE . list(SPACE) [ STRING R_ANGLE Q_STRING PLUS NUMBER MINUS L_ANGLE EQUAL EOF DOTDOT ] +## +## The known suffix of the stack is as follows: +## SPACE +## + + + +terms: COMMA EOF ## ## Ends in an error in state: 5. ## -## term -> COLON . list(SPACE) standard_term [ EOF COMMA ] +## nonempty_list(COMMA) -> COMMA . [ STRING SPACE R_ANGLE Q_STRING PLUS NUMBER MINUS L_ANGLE EQUAL DOTDOT COLON ] +## nonempty_list(COMMA) -> COMMA . nonempty_list(COMMA) [ STRING SPACE R_ANGLE Q_STRING PLUS NUMBER MINUS L_ANGLE EQUAL DOTDOT COLON ] ## ## The known suffix of the stack is as follows: -## COLON +## COMMA ## -terms: COLON Q_STRING COLON +terms: COLON EOF ## -## Ends in an error in state: 31. +## Ends in an error in state: 7. ## -## separated_nonempty_list(COMMA,term) -> term . [ EOF ] -## separated_nonempty_list(COMMA,term) -> term . COMMA separated_nonempty_list(COMMA,term) [ EOF ] +## nonempty_list(COLON) -> COLON . [ COMMA ] +## nonempty_list(COLON) -> COLON . nonempty_list(COLON) [ COMMA ] +## term -> COLON . list(SPACE) value_standard_term [ EOF COMMA ] +## term -> COLON . list(SPACE) number_value_term [ EOF COMMA ] ## ## The known suffix of the stack is as follows: -## term +## COLON ## -## WARNING: This example involves spurious reductions. -## This implies that, although the LR(1) items shown above provide an -## accurate view of the past (what has been recognized so far), they -## may provide an INCOMPLETE view of the future (what was expected next). -## In state 10, spurious reduction of production standard_term -> Q_STRING -## In state 18, spurious reduction of production term -> COLON list(SPACE) standard_term + + + +terms: COLON COLON STRING +## +## Ends in an error in state: 8. +## +## nonempty_list(COLON) -> COLON . [ COMMA ] +## nonempty_list(COLON) -> COLON . nonempty_list(COLON) [ COMMA ] +## +## The known suffix of the stack is as follows: +## COLON ## -terms: COLON SPACE COMMA +terms: COLON SPACE EOF ## -## Ends in an error in state: 6. +## Ends in an error in state: 10. ## -## term -> COLON list(SPACE) . standard_term [ EOF COMMA ] +## term -> COLON list(SPACE) . value_standard_term [ EOF COMMA ] +## term -> COLON list(SPACE) . number_value_term [ EOF COMMA ] ## ## The known suffix of the stack is as follows: ## COLON list(SPACE) @@ -49,132 +71,500 @@ terms: COLON SPACE COMMA -terms: COMMA STRING +terms: COLON STRING STRING ## -## Ends in an error in state: 49. +## Ends in an error in state: 11. ## -## nonempty_list(COMMA) -> COMMA . [ EOF ] -## nonempty_list(COMMA) -> COMMA . nonempty_list(COMMA) [ EOF ] +## separated_nonempty_list(SPACE,value_string_2) -> STRING . list(COLON) [ EOF DOTDOT COMMA ] +## separated_nonempty_list(SPACE,value_string_2) -> STRING . list(COLON) SPACE separated_nonempty_list(SPACE,value_string_2) [ EOF DOTDOT COMMA ] ## ## The known suffix of the stack is as follows: -## COMMA +## STRING ## -terms: DOTDOT Q_STRING STRING +terms: COLON MINUS COLON STRING ## ## Ends in an error in state: 12. ## -## separated_nonempty_list(SPACE,Q_STRING) -> Q_STRING . [ EOF DOTDOT COMMA COLON ] -## separated_nonempty_list(SPACE,Q_STRING) -> Q_STRING . SPACE separated_nonempty_list(SPACE,Q_STRING) [ EOF DOTDOT COMMA COLON ] +## list(COLON) -> COLON . list(COLON) [ SPACE EOF DOTDOT COMMA ] ## ## The known suffix of the stack is as follows: -## Q_STRING +## COLON ## -terms: DOTDOT SPACE +terms: COLON STRING SPACE SPACE ## -## Ends in an error in state: 14. +## Ends in an error in state: 15. ## -## standard_term -> DOTDOT . separated_nonempty_list(SPACE,STRING) [ EOF COMMA COLON ] -## standard_term -> DOTDOT . separated_nonempty_list(SPACE,Q_STRING) [ EOF COMMA COLON ] -## standard_term -> DOTDOT . separated_nonempty_list(SPACE,Q_STRING) DOTDOT [ EOF COMMA COLON ] +## separated_nonempty_list(SPACE,value_string_2) -> STRING list(COLON) SPACE . separated_nonempty_list(SPACE,value_string_2) [ EOF DOTDOT COMMA ] ## ## The known suffix of the stack is as follows: -## DOTDOT +## STRING list(COLON) SPACE ## -terms: PLUS PLUS +terms: COLON PLUS R_ANGLE ## -## Ends in an error in state: 34. +## Ends in an error in state: 16. ## -## term -> op_result . list(SPACE) standard_term COLON list(SPACE) standard_term [ EOF COMMA ] -## term -> op_result . list(SPACE) standard_term COLON [ EOF COMMA ] -## term -> op_result . list(SPACE) standard_term [ EOF COMMA ] +## nonempty_list(PLUS) -> PLUS . [ STRING SPACE NUMBER MINUS EOF DOTDOT COMMA COLON ] +## nonempty_list(PLUS) -> PLUS . nonempty_list(PLUS) [ STRING SPACE NUMBER MINUS EOF DOTDOT COMMA COLON ] ## ## The known suffix of the stack is as follows: -## op_result +## PLUS ## -terms: PLUS SPACE COMMA +terms: COLON NUMBER R_ANGLE +## +## Ends in an error in state: 18. +## +## separated_nonempty_list(SPACE,value_string_2) -> NUMBER . list(COLON) [ EOF DOTDOT COMMA ] +## separated_nonempty_list(SPACE,value_string_2) -> NUMBER . STRING list(COLON) [ EOF DOTDOT COMMA ] +## separated_nonempty_list(SPACE,value_string_2) -> NUMBER . list(COLON) SPACE separated_nonempty_list(SPACE,value_string_2) [ EOF DOTDOT COMMA ] +## separated_nonempty_list(SPACE,value_string_2) -> NUMBER . STRING list(COLON) SPACE separated_nonempty_list(SPACE,value_string_2) [ EOF DOTDOT COMMA ] +## +## The known suffix of the stack is as follows: +## NUMBER +## + + + +terms: COLON NUMBER STRING STRING +## +## Ends in an error in state: 19. +## +## separated_nonempty_list(SPACE,value_string_2) -> NUMBER STRING . list(COLON) [ EOF DOTDOT COMMA ] +## separated_nonempty_list(SPACE,value_string_2) -> NUMBER STRING . list(COLON) SPACE separated_nonempty_list(SPACE,value_string_2) [ EOF DOTDOT COMMA ] +## +## The known suffix of the stack is as follows: +## NUMBER STRING +## + + + +terms: COLON NUMBER STRING SPACE SPACE +## +## Ends in an error in state: 21. +## +## separated_nonempty_list(SPACE,value_string_2) -> NUMBER STRING list(COLON) SPACE . separated_nonempty_list(SPACE,value_string_2) [ EOF DOTDOT COMMA ] +## +## The known suffix of the stack is as follows: +## NUMBER STRING list(COLON) SPACE +## + + + +terms: COLON MINUS R_ANGLE +## +## Ends in an error in state: 22. +## +## nonempty_list(MINUS) -> MINUS . [ STRING SPACE PLUS NUMBER EOF DOTDOT COMMA COLON ] +## nonempty_list(MINUS) -> MINUS . nonempty_list(MINUS) [ STRING SPACE PLUS NUMBER EOF DOTDOT COMMA COLON ] +## +## The known suffix of the stack is as follows: +## MINUS +## + + + +terms: COLON PLUS STRING STRING +## +## Ends in an error in state: 26. +## +## separated_nonempty_list(SPACE,value_string_2) -> nonempty_list(PLUS) STRING . list(COLON) [ EOF DOTDOT COMMA ] +## separated_nonempty_list(SPACE,value_string_2) -> nonempty_list(PLUS) STRING . list(COLON) SPACE separated_nonempty_list(SPACE,value_string_2) [ EOF DOTDOT COMMA ] +## +## The known suffix of the stack is as follows: +## nonempty_list(PLUS) STRING +## + + + +terms: COLON PLUS STRING SPACE SPACE +## +## Ends in an error in state: 28. +## +## separated_nonempty_list(SPACE,value_string_2) -> nonempty_list(PLUS) STRING list(COLON) SPACE . separated_nonempty_list(SPACE,value_string_2) [ EOF DOTDOT COMMA ] +## +## The known suffix of the stack is as follows: +## nonempty_list(PLUS) STRING list(COLON) SPACE +## + + + +terms: COLON MINUS STRING STRING +## +## Ends in an error in state: 31. +## +## separated_nonempty_list(SPACE,value_string_2) -> nonempty_list(MINUS) STRING . list(COLON) [ EOF DOTDOT COMMA ] +## separated_nonempty_list(SPACE,value_string_2) -> nonempty_list(MINUS) STRING . list(COLON) SPACE separated_nonempty_list(SPACE,value_string_2) [ EOF DOTDOT COMMA ] +## +## The known suffix of the stack is as follows: +## nonempty_list(MINUS) STRING +## + + + +terms: COLON MINUS STRING SPACE SPACE +## +## Ends in an error in state: 33. +## +## separated_nonempty_list(SPACE,value_string_2) -> nonempty_list(MINUS) STRING list(COLON) SPACE . separated_nonempty_list(SPACE,value_string_2) [ EOF DOTDOT COMMA ] +## +## The known suffix of the stack is as follows: +## nonempty_list(MINUS) STRING list(COLON) SPACE +## + + + +terms: COLON MINUS NUMBER R_ANGLE ## ## Ends in an error in state: 35. ## -## term -> op_result list(SPACE) . standard_term COLON list(SPACE) standard_term [ EOF COMMA ] -## term -> op_result list(SPACE) . standard_term COLON [ EOF COMMA ] -## term -> op_result list(SPACE) . standard_term [ EOF COMMA ] +## separated_nonempty_list(SPACE,value_string_2) -> nonempty_list(MINUS) NUMBER . list(COLON) [ EOF DOTDOT COMMA ] +## separated_nonempty_list(SPACE,value_string_2) -> nonempty_list(MINUS) NUMBER . STRING list(COLON) [ EOF DOTDOT COMMA ] +## separated_nonempty_list(SPACE,value_string_2) -> nonempty_list(MINUS) NUMBER . list(COLON) SPACE separated_nonempty_list(SPACE,value_string_2) [ EOF DOTDOT COMMA ] +## separated_nonempty_list(SPACE,value_string_2) -> nonempty_list(MINUS) NUMBER . STRING list(COLON) SPACE separated_nonempty_list(SPACE,value_string_2) [ EOF DOTDOT COMMA ] ## ## The known suffix of the stack is as follows: -## op_result list(SPACE) +## nonempty_list(MINUS) NUMBER +## + + + +terms: COLON MINUS NUMBER STRING STRING +## +## Ends in an error in state: 36. +## +## separated_nonempty_list(SPACE,value_string_2) -> nonempty_list(MINUS) NUMBER STRING . list(COLON) [ EOF DOTDOT COMMA ] +## separated_nonempty_list(SPACE,value_string_2) -> nonempty_list(MINUS) NUMBER STRING . list(COLON) SPACE separated_nonempty_list(SPACE,value_string_2) [ EOF DOTDOT COMMA ] +## +## The known suffix of the stack is as follows: +## nonempty_list(MINUS) NUMBER STRING +## + + + +terms: COLON MINUS NUMBER STRING SPACE SPACE +## +## Ends in an error in state: 38. +## +## separated_nonempty_list(SPACE,value_string_2) -> nonempty_list(MINUS) NUMBER STRING list(COLON) SPACE . separated_nonempty_list(SPACE,value_string_2) [ EOF DOTDOT COMMA ] +## +## The known suffix of the stack is as follows: +## nonempty_list(MINUS) NUMBER STRING list(COLON) SPACE +## + + + +terms: COLON MINUS NUMBER SPACE SPACE +## +## Ends in an error in state: 41. +## +## separated_nonempty_list(SPACE,value_string_2) -> nonempty_list(MINUS) NUMBER list(COLON) SPACE . separated_nonempty_list(SPACE,value_string_2) [ EOF DOTDOT COMMA ] +## +## The known suffix of the stack is as follows: +## nonempty_list(MINUS) NUMBER list(COLON) SPACE +## + + + +terms: COLON MINUS PLUS STRING +## +## Ends in an error in state: 43. +## +## separated_nonempty_list(SPACE,value_string_2) -> nonempty_list(MINUS) nonempty_list(PLUS) . list(COLON) [ EOF DOTDOT COMMA ] +## separated_nonempty_list(SPACE,value_string_2) -> nonempty_list(MINUS) nonempty_list(PLUS) . list(COLON) SPACE separated_nonempty_list(SPACE,value_string_2) [ EOF DOTDOT COMMA ] +## +## The known suffix of the stack is as follows: +## nonempty_list(MINUS) nonempty_list(PLUS) ## ## WARNING: This example involves spurious reductions. ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 1, spurious reduction of production list(SPACE) -> -## In state 2, spurious reduction of production list(SPACE) -> SPACE list(SPACE) +## In state 16, spurious reduction of production nonempty_list(PLUS) -> PLUS ## -terms: PLUS STRING COLON PLUS +terms: COLON MINUS PLUS SPACE SPACE ## -## Ends in an error in state: 37. +## Ends in an error in state: 45. ## -## term -> op_result list(SPACE) standard_term COLON . list(SPACE) standard_term [ EOF COMMA ] -## term -> op_result list(SPACE) standard_term COLON . [ EOF COMMA ] +## separated_nonempty_list(SPACE,value_string_2) -> nonempty_list(MINUS) nonempty_list(PLUS) list(COLON) SPACE . separated_nonempty_list(SPACE,value_string_2) [ EOF DOTDOT COMMA ] ## ## The known suffix of the stack is as follows: -## op_result list(SPACE) standard_term COLON +## nonempty_list(MINUS) nonempty_list(PLUS) list(COLON) SPACE ## -terms: PLUS STRING COLON SPACE COMMA +terms: COLON MINUS SPACE SPACE ## -## Ends in an error in state: 38. +## Ends in an error in state: 48. ## -## term -> op_result list(SPACE) standard_term COLON list(SPACE) . standard_term [ EOF COMMA ] +## separated_nonempty_list(SPACE,value_string_2) -> nonempty_list(MINUS) list(COLON) SPACE . separated_nonempty_list(SPACE,value_string_2) [ EOF DOTDOT COMMA ] ## ## The known suffix of the stack is as follows: -## op_result list(SPACE) standard_term COLON list(SPACE) +## nonempty_list(MINUS) list(COLON) SPACE +## + + + +terms: COLON PLUS NUMBER R_ANGLE +## +## Ends in an error in state: 50. +## +## separated_nonempty_list(SPACE,value_string_2) -> nonempty_list(PLUS) NUMBER . list(COLON) [ EOF DOTDOT COMMA ] +## separated_nonempty_list(SPACE,value_string_2) -> nonempty_list(PLUS) NUMBER . STRING list(COLON) [ EOF DOTDOT COMMA ] +## separated_nonempty_list(SPACE,value_string_2) -> nonempty_list(PLUS) NUMBER . list(COLON) SPACE separated_nonempty_list(SPACE,value_string_2) [ EOF DOTDOT COMMA ] +## separated_nonempty_list(SPACE,value_string_2) -> nonempty_list(PLUS) NUMBER . STRING list(COLON) SPACE separated_nonempty_list(SPACE,value_string_2) [ EOF DOTDOT COMMA ] +## +## The known suffix of the stack is as follows: +## nonempty_list(PLUS) NUMBER +## + + + +terms: COLON PLUS NUMBER STRING STRING +## +## Ends in an error in state: 51. +## +## separated_nonempty_list(SPACE,value_string_2) -> nonempty_list(PLUS) NUMBER STRING . list(COLON) [ EOF DOTDOT COMMA ] +## separated_nonempty_list(SPACE,value_string_2) -> nonempty_list(PLUS) NUMBER STRING . list(COLON) SPACE separated_nonempty_list(SPACE,value_string_2) [ EOF DOTDOT COMMA ] +## +## The known suffix of the stack is as follows: +## nonempty_list(PLUS) NUMBER STRING +## + + + +terms: COLON PLUS NUMBER STRING SPACE SPACE +## +## Ends in an error in state: 53. +## +## separated_nonempty_list(SPACE,value_string_2) -> nonempty_list(PLUS) NUMBER STRING list(COLON) SPACE . separated_nonempty_list(SPACE,value_string_2) [ EOF DOTDOT COMMA ] +## +## The known suffix of the stack is as follows: +## nonempty_list(PLUS) NUMBER STRING list(COLON) SPACE +## + + + +terms: COLON PLUS NUMBER SPACE SPACE +## +## Ends in an error in state: 56. +## +## separated_nonempty_list(SPACE,value_string_2) -> nonempty_list(PLUS) NUMBER list(COLON) SPACE . separated_nonempty_list(SPACE,value_string_2) [ EOF DOTDOT COMMA ] +## +## The known suffix of the stack is as follows: +## nonempty_list(PLUS) NUMBER list(COLON) SPACE +## + + + +terms: COLON PLUS MINUS STRING +## +## Ends in an error in state: 58. +## +## separated_nonempty_list(SPACE,value_string_2) -> nonempty_list(PLUS) nonempty_list(MINUS) . list(COLON) [ EOF DOTDOT COMMA ] +## separated_nonempty_list(SPACE,value_string_2) -> nonempty_list(PLUS) nonempty_list(MINUS) . list(COLON) SPACE separated_nonempty_list(SPACE,value_string_2) [ EOF DOTDOT COMMA ] +## +## The known suffix of the stack is as follows: +## nonempty_list(PLUS) nonempty_list(MINUS) ## ## WARNING: This example involves spurious reductions. ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 1, spurious reduction of production list(SPACE) -> -## In state 2, spurious reduction of production list(SPACE) -> SPACE list(SPACE) +## In state 22, spurious reduction of production nonempty_list(MINUS) -> MINUS ## -terms: PLUS STRING DOTDOT STRING +terms: COLON PLUS MINUS SPACE SPACE ## -## Ends in an error in state: 36. +## Ends in an error in state: 60. ## -## term -> op_result list(SPACE) standard_term . COLON list(SPACE) standard_term [ EOF COMMA ] -## term -> op_result list(SPACE) standard_term . COLON [ EOF COMMA ] -## term -> op_result list(SPACE) standard_term . [ EOF COMMA ] +## separated_nonempty_list(SPACE,value_string_2) -> nonempty_list(PLUS) nonempty_list(MINUS) list(COLON) SPACE . separated_nonempty_list(SPACE,value_string_2) [ EOF DOTDOT COMMA ] ## ## The known suffix of the stack is as follows: -## op_result list(SPACE) standard_term +## nonempty_list(PLUS) nonempty_list(MINUS) list(COLON) SPACE ## -terms: Q_STRING SPACE Q_STRING EOF +terms: COLON PLUS SPACE SPACE ## -## Ends in an error in state: 21. +## Ends in an error in state: 63. ## -## standard_term -> separated_nonempty_list(SPACE,Q_STRING) . DOTDOT [ EOF COMMA COLON ] +## separated_nonempty_list(SPACE,value_string_2) -> nonempty_list(PLUS) list(COLON) SPACE . separated_nonempty_list(SPACE,value_string_2) [ EOF DOTDOT COMMA ] +## +## The known suffix of the stack is as follows: +## nonempty_list(PLUS) list(COLON) SPACE +## + + + +terms: COLON NUMBER SPACE SPACE +## +## Ends in an error in state: 66. +## +## separated_nonempty_list(SPACE,value_string_2) -> NUMBER list(COLON) SPACE . separated_nonempty_list(SPACE,value_string_2) [ EOF DOTDOT COMMA ] +## +## The known suffix of the stack is as follows: +## NUMBER list(COLON) SPACE +## + + + +terms: COLON R_ANGLE STRING +## +## Ends in an error in state: 69. +## +## number_value_term -> R_ANGLE . number [ EOF COMMA ] +## +## The known suffix of the stack is as follows: +## R_ANGLE +## + + + +terms: COLON Q_STRING STRING +## +## Ends in an error in state: 72. +## +## separated_nonempty_list(SPACE,Q_STRING) -> Q_STRING . [ DOTDOT ] +## separated_nonempty_list(SPACE,Q_STRING) -> Q_STRING . SPACE separated_nonempty_list(SPACE,Q_STRING) [ DOTDOT ] +## value_standard_term -> Q_STRING . [ EOF COMMA ] +## +## The known suffix of the stack is as follows: +## Q_STRING +## + + + +terms: Q_STRING SPACE STRING +## +## Ends in an error in state: 73. +## +## separated_nonempty_list(SPACE,Q_STRING) -> Q_STRING SPACE . separated_nonempty_list(SPACE,Q_STRING) [ EOF DOTDOT COMMA COLON ] +## +## The known suffix of the stack is as follows: +## Q_STRING SPACE +## + + + +terms: DOTDOT Q_STRING STRING +## +## Ends in an error in state: 74. +## +## separated_nonempty_list(SPACE,Q_STRING) -> Q_STRING . [ EOF DOTDOT COMMA COLON ] +## separated_nonempty_list(SPACE,Q_STRING) -> Q_STRING . SPACE separated_nonempty_list(SPACE,Q_STRING) [ EOF DOTDOT COMMA COLON ] +## +## The known suffix of the stack is as follows: +## Q_STRING +## + + + +terms: COLON L_ANGLE STRING +## +## Ends in an error in state: 76. +## +## number_value_term -> L_ANGLE . number [ EOF COMMA ] +## +## The known suffix of the stack is as follows: +## L_ANGLE +## + + + +terms: COLON EQUAL STRING +## +## Ends in an error in state: 78. +## +## number_value_term -> EQUAL . number [ EOF COMMA ] +## number_value_term -> EQUAL . number DOTDOT number [ EOF COMMA ] +## +## The known suffix of the stack is as follows: +## EQUAL +## + + + +terms: COLON EQUAL NUMBER STRING +## +## Ends in an error in state: 79. +## +## number_value_term -> EQUAL number . [ EOF COMMA ] +## number_value_term -> EQUAL number . DOTDOT number [ EOF COMMA ] +## +## The known suffix of the stack is as follows: +## EQUAL number +## + + + +terms: COLON EQUAL NUMBER DOTDOT STRING +## +## Ends in an error in state: 80. +## +## number_value_term -> EQUAL number DOTDOT . number [ EOF COMMA ] +## +## The known suffix of the stack is as follows: +## EQUAL number DOTDOT +## + + + +terms: COLON DOTDOT SPACE +## +## Ends in an error in state: 82. +## +## value_standard_term -> DOTDOT . separated_nonempty_list(SPACE,value_string_2) [ EOF COMMA ] +## value_standard_term -> DOTDOT . separated_nonempty_list(SPACE,Q_STRING) [ EOF COMMA ] +## value_standard_term -> DOTDOT . separated_nonempty_list(SPACE,Q_STRING) DOTDOT [ EOF COMMA ] +## +## The known suffix of the stack is as follows: +## DOTDOT +## + + + +terms: COLON DOTDOT Q_STRING COLON +## +## Ends in an error in state: 84. +## +## value_standard_term -> DOTDOT separated_nonempty_list(SPACE,Q_STRING) . [ EOF COMMA ] +## value_standard_term -> DOTDOT separated_nonempty_list(SPACE,Q_STRING) . DOTDOT [ EOF COMMA ] +## +## The known suffix of the stack is as follows: +## DOTDOT separated_nonempty_list(SPACE,Q_STRING) +## +## WARNING: This example involves spurious reductions. +## This implies that, although the LR(1) items shown above provide an +## accurate view of the past (what has been recognized so far), they +## may provide an INCOMPLETE view of the future (what was expected next). +## In state 74, spurious reduction of production separated_nonempty_list(SPACE,Q_STRING) -> Q_STRING +## + + + +terms: COLON Q_STRING SPACE Q_STRING EOF +## +## Ends in an error in state: 89. +## +## value_standard_term -> separated_nonempty_list(SPACE,Q_STRING) . DOTDOT [ EOF COMMA ] ## ## The known suffix of the stack is as follows: ## separated_nonempty_list(SPACE,Q_STRING) @@ -183,31 +573,130 @@ terms: Q_STRING SPACE Q_STRING EOF ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 12, spurious reduction of production separated_nonempty_list(SPACE,Q_STRING) -> Q_STRING -## In state 13, spurious reduction of production separated_nonempty_list(SPACE,Q_STRING) -> Q_STRING SPACE separated_nonempty_list(SPACE,Q_STRING) +## In state 74, spurious reduction of production separated_nonempty_list(SPACE,Q_STRING) -> Q_STRING +## In state 75, spurious reduction of production separated_nonempty_list(SPACE,Q_STRING) -> Q_STRING SPACE separated_nonempty_list(SPACE,Q_STRING) ## -terms: Q_STRING SPACE STRING +terms: EQUAL EOF STRING ## -## Ends in an error in state: 11. +## Ends in an error in state: 92. ## -## separated_nonempty_list(SPACE,Q_STRING) -> Q_STRING SPACE . separated_nonempty_list(SPACE,Q_STRING) [ EOF DOTDOT COMMA COLON ] +## terms -> value_lst . option(SPACE) list(COMMA) EOF [ # ] ## ## The known suffix of the stack is as follows: -## Q_STRING SPACE +## value_lst +## + + + +terms: EQUAL EOF SPACE STRING +## +## Ends in an error in state: 94. +## +## terms -> value_lst option(SPACE) . list(COMMA) EOF [ # ] +## +## The known suffix of the stack is as follows: +## value_lst option(SPACE) +## + + + +terms: EQUAL EOF COMMA STRING +## +## Ends in an error in state: 95. +## +## list(COMMA) -> COMMA . list(COMMA) [ EOF ] +## +## The known suffix of the stack is as follows: +## COMMA +## + + + +terms: COLON L_ANGLE NUMBER STRING +## +## Ends in an error in state: 100. +## +## separated_nonempty_list(COMMA,term) -> term . [ EOF ] +## separated_nonempty_list(COMMA,term) -> term . COMMA separated_nonempty_list(COMMA,term) [ EOF ] +## +## The known suffix of the stack is as follows: +## term +## + + + +terms: EQUAL COMMA EOF +## +## Ends in an error in state: 101. +## +## separated_nonempty_list(COMMA,term) -> term COMMA . separated_nonempty_list(COMMA,term) [ EOF ] +## +## The known suffix of the stack is as follows: +## term COMMA +## + + + +terms: COMMA COLON EOF +## +## Ends in an error in state: 102. +## +## term -> COLON . list(SPACE) value_standard_term [ EOF COMMA ] +## term -> COLON . list(SPACE) number_value_term [ EOF COMMA ] +## +## The known suffix of the stack is as follows: +## COLON +## + + + +terms: MINUS PLUS +## +## Ends in an error in state: 104. +## +## term -> op_result . list(SPACE) key_standard_term COLON list(SPACE) value_standard_term [ EOF COMMA ] +## term -> op_result . list(SPACE) key_standard_term COLON list(SPACE) number_value_term [ EOF COMMA ] +## term -> op_result . list(SPACE) key_standard_term COLON [ EOF COMMA ] +## term -> op_result . list(SPACE) key_standard_term [ EOF COMMA ] +## +## The known suffix of the stack is as follows: +## op_result +## + + + +terms: MINUS SPACE PLUS +## +## Ends in an error in state: 105. +## +## term -> op_result list(SPACE) . key_standard_term COLON list(SPACE) value_standard_term [ EOF COMMA ] +## term -> op_result list(SPACE) . key_standard_term COLON list(SPACE) number_value_term [ EOF COMMA ] +## term -> op_result list(SPACE) . key_standard_term COLON [ EOF COMMA ] +## term -> op_result list(SPACE) . key_standard_term [ EOF COMMA ] +## +## The known suffix of the stack is as follows: +## op_result list(SPACE) +## +## WARNING: This example involves spurious reductions. +## This implies that, although the LR(1) items shown above provide an +## accurate view of the past (what has been recognized so far), they +## may provide an INCOMPLETE view of the future (what was expected next). +## In state 1, spurious reduction of production list(SPACE) -> +## In state 2, spurious reduction of production list(SPACE) -> SPACE list(SPACE) ## terms: Q_STRING STRING ## -## Ends in an error in state: 10. +## Ends in an error in state: 108. ## +## key_standard_term -> Q_STRING . [ EOF COMMA COLON ] ## separated_nonempty_list(SPACE,Q_STRING) -> Q_STRING . [ DOTDOT ] ## separated_nonempty_list(SPACE,Q_STRING) -> Q_STRING . SPACE separated_nonempty_list(SPACE,Q_STRING) [ DOTDOT ] -## standard_term -> Q_STRING . [ EOF COMMA COLON ] ## ## The known suffix of the stack is as follows: ## Q_STRING @@ -215,69 +704,121 @@ terms: Q_STRING STRING -terms: SPACE PLUS +terms: DOTDOT SPACE ## -## Ends in an error in state: 1. +## Ends in an error in state: 112. ## -## list(SPACE) -> SPACE . list(SPACE) [ STRING Q_STRING EOF DOTDOT COMMA ] +## key_standard_term -> DOTDOT . separated_nonempty_list(SPACE,key_value) [ EOF COMMA COLON ] +## key_standard_term -> DOTDOT . separated_nonempty_list(SPACE,Q_STRING) [ EOF COMMA COLON ] +## key_standard_term -> DOTDOT . separated_nonempty_list(SPACE,Q_STRING) DOTDOT [ EOF COMMA COLON ] ## ## The known suffix of the stack is as follows: -## SPACE +## DOTDOT ## -terms: STRING COLON PLUS +terms: EQUAL STRING ## -## Ends in an error in state: 42. +## Ends in an error in state: 116. ## -## term -> list(SPACE) standard_term COLON . list(SPACE) standard_term [ EOF COMMA ] -## term -> list(SPACE) standard_term COLON . [ EOF COMMA ] +## separated_nonempty_list(SPACE,key_value) -> key_value . [ EOF DOTDOT COMMA COLON ] +## separated_nonempty_list(SPACE,key_value) -> key_value . SPACE separated_nonempty_list(SPACE,key_value) [ EOF DOTDOT COMMA COLON ] ## ## The known suffix of the stack is as follows: -## list(SPACE) standard_term COLON +## key_value ## -terms: STRING COLON SPACE COMMA +terms: EQUAL SPACE SPACE ## -## Ends in an error in state: 43. +## Ends in an error in state: 117. +## +## separated_nonempty_list(SPACE,key_value) -> key_value SPACE . separated_nonempty_list(SPACE,key_value) [ EOF DOTDOT COMMA COLON ] +## +## The known suffix of the stack is as follows: +## key_value SPACE +## + + + +terms: Q_STRING SPACE Q_STRING EOF +## +## Ends in an error in state: 121. ## -## term -> list(SPACE) standard_term COLON list(SPACE) . standard_term [ EOF COMMA ] +## key_standard_term -> separated_nonempty_list(SPACE,Q_STRING) . DOTDOT [ EOF COMMA COLON ] ## ## The known suffix of the stack is as follows: -## list(SPACE) standard_term COLON list(SPACE) +## separated_nonempty_list(SPACE,Q_STRING) ## ## WARNING: This example involves spurious reductions. ## This implies that, although the LR(1) items shown above provide an ## accurate view of the past (what has been recognized so far), they ## may provide an INCOMPLETE view of the future (what was expected next). -## In state 1, spurious reduction of production list(SPACE) -> -## In state 2, spurious reduction of production list(SPACE) -> SPACE list(SPACE) +## In state 74, spurious reduction of production separated_nonempty_list(SPACE,Q_STRING) -> Q_STRING +## In state 75, spurious reduction of production separated_nonempty_list(SPACE,Q_STRING) -> Q_STRING SPACE separated_nonempty_list(SPACE,Q_STRING) ## -terms: STRING COMMA EOF +terms: MINUS Q_STRING DOTDOT DOTDOT ## -## Ends in an error in state: 32. +## Ends in an error in state: 123. ## -## separated_nonempty_list(COMMA,term) -> term COMMA . separated_nonempty_list(COMMA,term) [ EOF ] +## term -> op_result list(SPACE) key_standard_term . COLON list(SPACE) value_standard_term [ EOF COMMA ] +## term -> op_result list(SPACE) key_standard_term . COLON list(SPACE) number_value_term [ EOF COMMA ] +## term -> op_result list(SPACE) key_standard_term . COLON [ EOF COMMA ] +## term -> op_result list(SPACE) key_standard_term . [ EOF COMMA ] ## ## The known suffix of the stack is as follows: -## term COMMA +## op_result list(SPACE) key_standard_term +## + + + +terms: MINUS EQUAL COLON COLON +## +## Ends in an error in state: 124. +## +## term -> op_result list(SPACE) key_standard_term COLON . list(SPACE) value_standard_term [ EOF COMMA ] +## term -> op_result list(SPACE) key_standard_term COLON . list(SPACE) number_value_term [ EOF COMMA ] +## term -> op_result list(SPACE) key_standard_term COLON . [ EOF COMMA ] +## +## The known suffix of the stack is as follows: +## op_result list(SPACE) key_standard_term COLON ## -terms: STRING COMMA SPACE COMMA +terms: MINUS EQUAL COLON SPACE EOF ## -## Ends in an error in state: 40. +## Ends in an error in state: 125. ## -## term -> list(SPACE) . standard_term COLON list(SPACE) standard_term [ EOF COMMA ] -## term -> list(SPACE) . standard_term COLON [ EOF COMMA ] -## term -> list(SPACE) . standard_term [ EOF COMMA ] +## term -> op_result list(SPACE) key_standard_term COLON list(SPACE) . value_standard_term [ EOF COMMA ] +## term -> op_result list(SPACE) key_standard_term COLON list(SPACE) . number_value_term [ EOF COMMA ] +## +## The known suffix of the stack is as follows: +## op_result list(SPACE) key_standard_term COLON list(SPACE) +## +## WARNING: This example involves spurious reductions. +## This implies that, although the LR(1) items shown above provide an +## accurate view of the past (what has been recognized so far), they +## may provide an INCOMPLETE view of the future (what was expected next). +## In state 1, spurious reduction of production list(SPACE) -> +## In state 2, spurious reduction of production list(SPACE) -> SPACE list(SPACE) +## + + + +terms: COMMA SPACE PLUS +## +## Ends in an error in state: 128. +## +## term -> list(SPACE) . key_standard_term COLON list(SPACE) value_standard_term [ EOF COMMA ] +## term -> list(SPACE) . key_standard_term COLON list(SPACE) number_value_term [ EOF COMMA ] +## term -> list(SPACE) . key_standard_term COLON [ EOF COMMA ] +## term -> list(SPACE) . key_standard_term [ EOF COMMA ] ## ## The known suffix of the stack is as follows: ## list(SPACE) @@ -292,77 +833,98 @@ terms: STRING COMMA SPACE COMMA -terms: STRING DOTDOT STRING +terms: Q_STRING DOTDOT DOTDOT ## -## Ends in an error in state: 41. +## Ends in an error in state: 129. ## -## term -> list(SPACE) standard_term . COLON list(SPACE) standard_term [ EOF COMMA ] -## term -> list(SPACE) standard_term . COLON [ EOF COMMA ] -## term -> list(SPACE) standard_term . [ EOF COMMA ] +## term -> list(SPACE) key_standard_term . COLON list(SPACE) value_standard_term [ EOF COMMA ] +## term -> list(SPACE) key_standard_term . COLON list(SPACE) number_value_term [ EOF COMMA ] +## term -> list(SPACE) key_standard_term . COLON [ EOF COMMA ] +## term -> list(SPACE) key_standard_term . [ EOF COMMA ] ## ## The known suffix of the stack is as follows: -## list(SPACE) standard_term +## list(SPACE) key_standard_term ## -terms: STRING EOF COMMA STRING +terms: EQUAL COLON COLON ## -## Ends in an error in state: 26. +## Ends in an error in state: 130. ## -## list(COMMA) -> COMMA . list(COMMA) [ EOF ] +## term -> list(SPACE) key_standard_term COLON . list(SPACE) value_standard_term [ EOF COMMA ] +## term -> list(SPACE) key_standard_term COLON . list(SPACE) number_value_term [ EOF COMMA ] +## term -> list(SPACE) key_standard_term COLON . [ EOF COMMA ] ## ## The known suffix of the stack is as follows: -## COMMA +## list(SPACE) key_standard_term COLON ## -terms: STRING EOF SPACE COLON +terms: EQUAL COLON SPACE EOF ## -## Ends in an error in state: 25. +## Ends in an error in state: 131. ## -## terms -> value_lst option(SPACE) . list(COMMA) EOF [ # ] +## term -> list(SPACE) key_standard_term COLON list(SPACE) . value_standard_term [ EOF COMMA ] +## term -> list(SPACE) key_standard_term COLON list(SPACE) . number_value_term [ EOF COMMA ] ## ## The known suffix of the stack is as follows: -## value_lst option(SPACE) +## list(SPACE) key_standard_term COLON list(SPACE) +## +## WARNING: This example involves spurious reductions. +## This implies that, although the LR(1) items shown above provide an +## accurate view of the past (what has been recognized so far), they +## may provide an INCOMPLETE view of the future (what was expected next). +## In state 1, spurious reduction of production list(SPACE) -> +## In state 2, spurious reduction of production list(SPACE) -> SPACE list(SPACE) ## -terms: STRING EOF STRING +terms: COMMA EQUAL EOF STRING ## -## Ends in an error in state: 23. +## Ends in an error in state: 137. ## -## terms -> value_lst . option(SPACE) list(COMMA) EOF [ # ] +## terms -> nonempty_list(COMMA) value_lst . EOF [ # ] ## ## The known suffix of the stack is as follows: -## value_lst +## nonempty_list(COMMA) value_lst ## -terms: STRING SPACE SPACE +terms: COLON COMMA EQUAL EOF STRING ## -## Ends in an error in state: 8. +## Ends in an error in state: 141. ## -## separated_nonempty_list(SPACE,STRING) -> STRING SPACE . separated_nonempty_list(SPACE,STRING) [ EOF DOTDOT COMMA COLON ] +## terms -> nonempty_list(COLON) nonempty_list(COMMA) value_lst . EOF [ # ] ## ## The known suffix of the stack is as follows: -## STRING SPACE +## nonempty_list(COLON) nonempty_list(COMMA) value_lst ## -terms: STRING STRING +terms: SPACE PLUS ## -## Ends in an error in state: 7. +## Ends in an error in state: 143. ## -## separated_nonempty_list(SPACE,STRING) -> STRING . [ EOF DOTDOT COMMA COLON ] -## separated_nonempty_list(SPACE,STRING) -> STRING . SPACE separated_nonempty_list(SPACE,STRING) [ EOF DOTDOT COMMA COLON ] +## term -> list(SPACE) . key_standard_term COLON list(SPACE) value_standard_term [ EOF COMMA ] +## term -> list(SPACE) . key_standard_term COLON list(SPACE) number_value_term [ EOF COMMA ] +## term -> list(SPACE) . key_standard_term COLON [ EOF COMMA ] +## term -> list(SPACE) . key_standard_term [ EOF COMMA ] +## terms -> list(SPACE) . EOF [ # ] ## ## The known suffix of the stack is as follows: -## STRING +## list(SPACE) +## +## WARNING: This example involves spurious reductions. +## This implies that, although the LR(1) items shown above provide an +## accurate view of the past (what has been recognized so far), they +## may provide an INCOMPLETE view of the future (what was expected next). +## In state 1, spurious reduction of production list(SPACE) -> +## In state 2, spurious reduction of production list(SPACE) -> SPACE list(SPACE) ## diff --git a/compiler/filter_parser.mly b/compiler/filter_parser.mly index 92903c1..9c5d2db 100644 --- a/compiler/filter_parser.mly +++ b/compiler/filter_parser.mly @@ -1,6 +1,6 @@ %token STRING %token Q_STRING -%token FLOAT +%token NUMBER %token COLON ":" %token COMMA "," %token DOTDOT ".." @@ -19,55 +19,138 @@ op_result: | "-"; { Ast.Exclude } | "+"; { Ast.Include } -%inline string_list: - | values= separated_nonempty_list(" ", STRING) - { values } - %inline q_string_list: | values= separated_nonempty_list(" ", Q_STRING) { values } -standard_term: - | ".."; values= string_list { Ast.ends_with_in_order values } - | values= string_list; ".." { Ast.begins_with_in_order values } - | values= string_list { Ast.contains_in_order values } +key_value: + | value= STRING { value } + | value= NUMBER { String.trim value } + | R_ANGLE { ">" } + | L_ANGLE { "<" } + | EQUAL { "=" } +%inline key_string_list: + | values= separated_nonempty_list(" ", key_value) + { values } +key_standard_term: + | ".."; values= key_string_list { Ast.ends_with_in_order values } + | values= key_string_list; ".." { Ast.begins_with_in_order values } + | values= key_string_list { Ast.contains_in_order values } + | ".." { Ast.contains_in_order [".."] } | ".."; values= q_string_list { Ast.ends_with_in_order values } | ".."; values= q_string_list; ".." { Ast.contains_in_order values } | values= q_string_list; ".." { Ast.begins_with_in_order values } | value= Q_STRING; { Ast.exact value } number: - | f= FLOAT { f } + | f= NUMBER { f } + +number_value_term: + | "<"; f= number; { Ast.less_than_of_string f } + | ">"; f= number; { Ast.greater_than_of_string f } + | "="; f= number; { Ast.exact_of_string f } + | "="; l= number; ".."; h= number + { Ast.between_of_string l h } + +%inline value_string_string: + | value= STRING { value } + | value= NUMBER { String.trim value } + | v1= NUMBER; "+"; v2= NUMBER { let b = Buffer.create 16 in + Buffer.add_string b (String.trim v1) ; + Buffer.add_char b '+' ; + Buffer.add_string b (String.trim v2) ; + Buffer.contents b + } + | v1= NUMBER; v2= STRING { let b = Buffer.create 16 in + Buffer.add_string b (String.trim v1) ; + Buffer.add_string b v2 ; + Buffer.contents b + } + +%inline value_string: + | value= value_string_string { value } + | lst= "-"+ + { let b = Buffer.create (List.length lst) in + List.iter (fun () -> Buffer.add_char b '-') lst ; + Buffer.contents b + } + | lst1= "-"+; lst2= "+"+ + { let b = Buffer.create ((List.length lst1) + (List.length lst2)) in + List.iter (fun () -> Buffer.add_char b '-') lst1 ; + List.iter (fun () -> Buffer.add_char b '+') lst2 ; + Buffer.contents b + } + | lst= "-"+; value= value_string_string + { let b = Buffer.create (List.length lst) in + List.iter (fun () -> Buffer.add_char b '-') lst ; + Buffer.add_string b value ; + Buffer.contents b + } + | lst= "+"+; value= value_string_string + { let b = Buffer.create (List.length lst) in + List.iter (fun () -> Buffer.add_char b '+') lst ; + Buffer.add_string b value ; + Buffer.contents b + } + | lst= "+"+ + { let b = Buffer.create (List.length lst) in + List.iter (fun () -> Buffer.add_char b '+') lst ; + Buffer.contents b + } + | lst1= "+"+; lst2= "-"+ + { let b = Buffer.create ((List.length lst1) + (List.length lst2)) in + List.iter (fun () -> Buffer.add_char b '+') lst1 ; + List.iter (fun () -> Buffer.add_char b '-') lst2 ; + Buffer.contents b + } + +%inline value_string_2: + | value= value_string; lst= ":"* + { let b = Buffer.create (List.length lst) in + Buffer.add_string b value ; + List.iter (fun () -> Buffer.add_char b ':') lst ; + Buffer.contents b + } + +%inline value_string_list: + | values= separated_nonempty_list(" ", value_string_2) + { values } + +value_standard_term: + | ".."; values= value_string_list { Ast.ends_with_in_order values } + | values= value_string_list; ".." { Ast.begins_with_in_order values } + | values= value_string_list { Ast.contains_in_order values } + | ".." { Ast.contains_in_order [".."] } + | ".."; values= q_string_list { Ast.ends_with_in_order values } + | ".."; values= q_string_list; ".." { Ast.contains_in_order values } + | values= q_string_list; ".." { Ast.begins_with_in_order values } + | value= Q_STRING; { Ast.exact value } -number_value_term: (* The operator needs to be managed differently and moved into the term clause, it makes me wonder if we want a seperate value lexer clause to deal with this? *) - | "<"; f= number; { Ast.less_than_of_float f } (* should maybe be the Number.t here? *) - | ">"; f= number; { Ast.greater_than_of_float f } - | "="; f= number; { Ast.exact_of_float f } - | l= number; " "*; ".."; h= number { Ast.between_of_float l h } %inline value_term: - | " "*; term= standard_term { term } + | " "*; term= value_standard_term { term } | " "*; term= number_value_term { term } %inline key_term: - | " "*; term= standard_term { term } + | " "*; term= key_standard_term { term } term: | result= op_result; key= key_term; ":"; value= value_term { Ast.pair_filter result key value } | result= op_result; key= key_term; ":" { Ast.key_filter result key } - | result= op_result; value= value_term + | result= op_result; value= key_term { Ast.value_filter result value } | key= key_term; ":"; value= value_term { Ast.pair_filter Ast.inc key value } | key= key_term; ":" { Ast.key_filter Ast.inc key } | ":"; value= value_term { Ast.value_filter Ast.inc value } - | value= value_term { Ast.value_filter Ast.inc value } + | value= key_term { Ast.value_filter Ast.inc value } value_lst: | lst= separated_nonempty_list(",", term); EOF { lst } terms: - | " "*; EOF { [] } - | " "*; ","+; EOF { [] } + | " "*; EOF; { [] } + | ","+; lst= value_lst; EOF { lst } + | ":"+; ","+; lst= value_lst; EOF { lst } | lst= value_lst; " "?; ","*; EOF { lst } diff --git a/compiler/match_in_order.ml b/compiler/match_in_order.ml index f323633..6ffe6cf 100644 --- a/compiler/match_in_order.ml +++ b/compiler/match_in_order.ml @@ -57,7 +57,7 @@ let number_match_operation (from_input : Ast.number) | ExactNumber expected -> Ast.number_comp from_input expected == 0 | Ast.LessThanNumber lower -> Ast.number_comp lower from_input == 1 | Ast.GreaterThanNumber upper -> Ast.number_comp from_input upper == 1 - | Ast.BetweeNumber (lower, upper) -> + | Ast.BetweenNumber (lower, upper) -> Ast.number_comp from_input upper == -1 && Ast.number_comp lower from_input == -1 diff --git a/compiler_test/fex_compiler_test.ml b/compiler_test/fex_compiler_test.ml index 3769a93..8f40ddb 100644 --- a/compiler_test/fex_compiler_test.ml +++ b/compiler_test/fex_compiler_test.ml @@ -1,7 +1,8 @@ let suites = [ Parser_test.suite ; Predicate_test.suite - ; Combiner_test.suite (* ; Messages_test.suite *) + ; Combiner_test.suite + ; Messages_test.suite ] let () = diff --git a/compiler_test/messages_test.ml b/compiler_test/messages_test.ml index 5b2ca87..d0bc27c 100644 --- a/compiler_test/messages_test.ml +++ b/compiler_test/messages_test.ml @@ -2,7 +2,11 @@ let test_name = "Parser Messages" let fex = let open Alcotest in - Fex_compiler.Ast.(testable pp equal) + let string_pp = Fex_compiler.Ast.pp Fex_compiler__Match_in_order.T.pp in + let string_equal = + Fex_compiler.Ast.equal Fex_compiler__Match_in_order.T.equal + in + testable string_pp string_equal let parse = Fex_compiler.filter_from_string @@ -17,85 +21,14 @@ let parse_single_test case_name expected to_parse = check string case_name expected (Result.get_error (parse to_parse) |> scanned)) -let colon_plus () = - let msg = - "The `+` (plus) operator can not directly follow a `:` (colon) operator." - in - parse_single_test "COLON PLUS" msg ":+" ; - parse_single_test "COLON" msg (* TODO why is this being hit here? *) ":" - -let colon_qstring_colon () = - let msg = "The `:` (colon) can only be included once in each query term." in - parse_single_test "COLON Q_STRING COLON" msg ":'':" ; - parse_single_test "COLON Q_STRING COLON" msg {|:"":|} - -let colon_space_comma () = - let msg = - "The `+` (plus) operator can not directly follow a `:` (colon) operator." - in - parse_single_test "COLON SPACE COMMA" msg ": ," - -let colon_string () = - let msg = - "A `,` (comma) followed by a string seems to be missing a filiter before \ - the `,`" - in - parse_single_test "COLON STRING" msg ",somestring" - let base_cases = let state_msg = - [ ( "COLON PLUS" - , {|`+` (plus) in only valid before a term. -here the (plus) is used directly after a `:` (colon) -did you mean `+:` instead of `:+`?|} - ) - ; ( "COLON Q_STRING COLON" + [ ( "COLON Q_STRING COLON" , {|`:` (colon) in only valid between a key term and value term. Here the `:` both begins and ends the filter which is ambiguous. -did you forget a `,` (comma) or add an extra `:`?|} - ) - ; ( "COLON SPACE COMMA" - , {|`:` (colon) alone is not a valid filter term. -Here `:` has no key or value term before a `,` (comma) -Did you forget to add a key or value term?|} - ) - ; ( "COMMA STRING" - , {|`,` (comma) is only valid as a term separator. -Here `,` seems to a beginning empty filter. -did you mean to have the beginning `,`?|} - ) - ; ( "COMMA SPACE STRING" - , {|`,` (comma) is only valid as a term separator. -Here `,` seems to a beginning empty filter. -did you mean to have the beginning `,`?|} +Did you forget a `,` (comma) or add an extra `:`?|} ) ; ("DOTDOT Q_STRING STRING", "") - ; ( "DOTDOT SPACE" - , {|`..` (dot dot) must be followed by a string. -Here `..` is followed by a ` ` (space). -Did you mean to have a string directly before or after the `..`?|} - ) - ; ("MINUS SPACE", "") - ; ("MINUS STRING COLON PLUS", "") - ; ("MINUS STRING COLON SPACE PLUS", "") - ; ("MINUS STRING DOTDOT STRING", "") - ; ("PLUS SPACE", "") - ; ("PLUS STRING COLON PLUS", "") - ; ("PLUS STRING COLON SPACE PLUS", "") - ; ("PLUS STRING DOTDOT STRING", "") - ; ("Q_STRING SPACE Q_STRING EOF", "") - ; ("Q_STRING SPACE STRING", "") - ; ("Q_STRING STRING", "") - ; ("SPACE COLON", "") - (* ; ("SPACE STRING", "") *) - ; ("STRING COLON PLUS", "") - ; ("STRING COLON SPACE PLUS", "") - ; ("STRING COMMA EOF", "") - (* ; ("STRING COMMA SPACE EOF", "") *) - ; ("STRING DOTDOT STRING", "") - (* ; ("STRING EOF STRING", "") *) - (* ; ("STRING SPACE SPACE", "") *) - (* ; ("STRING STRING", "") *) ] in let to_char = function diff --git a/compiler_test/parser_test.ml b/compiler_test/parser_test.ml index 0410a19..15785cd 100644 --- a/compiler_test/parser_test.ml +++ b/compiler_test/parser_test.ml @@ -44,7 +44,9 @@ let value_only () = make_test "leadingspace" "+ leadingspace" ; make_test "leadingspace" " +leadingspace" ; make_test "trailingspace" "trailingspace " ; - make_test "trailingspace" "+trailingspace " + make_test "trailingspace" "+trailingspace " ; + make_test "5" " 5" ; + make_test "-5" " -5" let value_only_exclude () = let open Fex_compiler.Ast in @@ -60,7 +62,9 @@ let value_only_exclude () = make_test "surround" " -surround " ; make_test "leadingspace" "- leadingspace" ; make_test "leadingspace" " -leadingspace" ; - make_test "trailingspace" "-trailingspace " + make_test "trailingspace" "-trailingspace " ; + make_test "5" "- 5 " ; + make_test "-5" "--5 " let key_only () = let open Fex_compiler.Ast in @@ -78,7 +82,9 @@ let key_only () = make_test "surround" " +surround :" ; make_test "leadingspace" "+ leadingspace:" ; make_test "leadingspace" " +leadingspace:" ; - make_test "trailingspace" "+trailingspace :" + make_test "trailingspace" "+trailingspace :" ; + make_test "5" "5 :" ; + make_test "-5" "-5 :" let key_only_exclude () = let open Fex_compiler.Ast in @@ -93,7 +99,10 @@ let key_only_exclude () = make_test "surround" " -surround :" ; make_test "leadingspace" "- leadingspace:" ; make_test "leadingspace" " -leadingspace:" ; - make_test "trailingspace" "-trailingspace :" + make_test "trailingspace" "-trailingspace :" ; + make_test "5" "- 5:" ; + make_test "-5" "--5:" ; + make_test "-5" "- -5:" let key_value () = let open Fex_compiler.Ast in @@ -118,7 +127,15 @@ let key_value () = make_test ("trailingspace", "value") "+trailingspace :value" ; make_test ("key", "surround") "+key: surround " ; make_test ("key", "leadingspace") "+key: leadingspace" ; - make_test ("key", "trailingspace") "+key:trailingspace " + make_test ("key", "trailingspace") "+key:trailingspace " ; + make_test ("key", "-leadingminus") "key:-leadingminus" ; + make_test ("key", "--leadingminus") "key:--leadingminus" ; + make_test ("key", "trailingminus-") "key:trailingminus-" ; + make_test ("key", "trailingminus--") "key:trailingminus--" ; + make_test ("key", "+leadingplus") "key:+leadingplus" ; + make_test ("key", "++leadingplus") "key:++leadingplus" ; + make_test ("key", "trailingplus+") "key:trailingplus+" ; + make_test ("key", "trailingplus++") "key:trailingplus++" let key_value_exclude () = let open Fex_compiler.Ast in @@ -236,9 +253,10 @@ let int_value_number_betwween_test () = (value_filter inc @@ op expected1 expected2) input in - make_test between_of_int 1 10 ":1..10" ; - make_test between_of_int (-1) 10 ":-1..10" ; - make_test between_of_int (-1) (-10) ":-1..-10" + make_test between_of_int 1 10 ":= 1..10" ; + make_test between_of_int (-1) 10 ":= -1..10" ; + make_test between_of_int (-1) (-10) ":= -1..-10" ; + make_test between_of_int 1 (-10) ":= 1..-10" let float_value_number_betwween_test () = let open Fex_compiler.Ast in @@ -249,9 +267,9 @@ let float_value_number_betwween_test () = (value_filter inc @@ op expected1 expected2) input in - make_test between_of_float 1. 10.01 ":1..10.01" ; - make_test between_of_float (-1.01) 10. ":-1.01..10" ; - make_test between_of_float (-1.01) (-10.01) ":-1.01..-10.01" + make_test between_of_float 1. 10.01 ":= 1..10.01" ; + make_test between_of_float (-1.01) 10. ":= -1.01..10" ; + make_test between_of_float (-1.01) (-10.01) ":= -1.01..-10.01" let float_value_number_test () = let open Fex_compiler.Ast in @@ -287,7 +305,7 @@ let suite = ; test_case "Key Only" `Quick key_only ; test_case "Key Only Exclude" `Quick key_only_exclude ; test_case "Key Value" `Quick key_value - ; test_case "Key Value Exclude" `Quick key_only_exclude + ; test_case "Key Value Exclude" `Quick key_value_exclude ; test_case "Splits" `Quick combinatorials ; test_case "Begins with" `Quick value_only_begins_with ; test_case "Ends with" `Quick value_only_ends_with