Browse Source

Add wildcard op, .gitignore & update rebar.configs

pull/1/head
Pedram Nimreezi 12 years ago
parent
commit
7ff9b03e40
7 changed files with 44 additions and 15 deletions
  1. +8
    -0
      .gitignore
  2. +2
    -2
      Makefile
  3. +0
    -6
      rebar.config
  4. +7
    -1
      src/glc.erl
  5. +7
    -4
      src/glc_code.erl
  6. +11
    -1
      src/glc_lib.erl
  7. +9
    -1
      src/glc_ops.erl

+ 8
- 0
.gitignore View File

@ -0,0 +1,8 @@
.eunit
*.beam
ebin
doc
*.swp
erl_crash.dump
.project
log

+ 2
- 2
Makefile View File

@ -20,10 +20,10 @@ clean:
tests: clean app eunit ct
eunit:
@$(REBAR) eunit skip_deps=true
@$(REBAR) -C rebar.test.config eunit skip_deps=true
ct:
@$(REBAR) ct skip_deps=true
@$(REBAR) -C rebar.test.config ct skip_deps=true
build-plt:
@$(DIALYZER) --build_plt --output_plt .$(APPNAME)_dialyzer.plt \

+ 0
- 6
rebar.config View File

@ -1,12 +1,6 @@
{cover_enabled, true}.
{eunit_opts, [{report, {eunit_surefire, [{dir, "."}]}}]}.
{erl_opts, [
%% bin_opt_info,
%% warn_missing_spec,
warnings_as_errors,
warn_export_all
]}.
{deps, [
{proper, ".*",
{git, "git://github.com/manopapad/proper.git", "master"}}
]}.

+ 7
- 1
src/glc.erl View File

@ -30,6 +30,8 @@
%% glc:eq(a, 0).
%% %% Select all events where 'a' exists and is less than 0.
%% glc:lt(a, 0).
%% %% Select all events where 'a' exists and is anything.
%% glc:wc(a).
%%
%% %% Select no input events. Used as black hole query.
%% glc:null(false).
@ -68,7 +70,8 @@
-export([
lt/2,
eq/2,
gt/2
gt/2,
wc/1
]).
-export([
@ -100,6 +103,9 @@ eq(Key, Term) ->
gt(Key, Term) ->
glc_ops:gt(Key, Term).
-spec wc(atom()) -> glc_ops:op().
wc(Key) ->
glc_ops:wc(Key).
%% @doc Filter the input using multiple filters.
%%

+ 7
- 4
src/glc_code.erl View File

@ -27,7 +27,7 @@
compile(Module, ModuleData) ->
{ok, forms, Forms} = abstract_module(Module, ModuleData),
{ok, Module, Binary} = compile_forms(Forms, []),
{ok, Module, Binary} = compile_forms(Forms, [nowarn_unused_vars]),
{ok, loaded, Module} = load_binary(Module, Binary),
{ok, Module}.
@ -150,6 +150,10 @@ abstract_filter_({null, true}, OnMatch, _OnNomatch, State) ->
OnMatch(State);
abstract_filter_({null, false}, _OnMatch, OnNomatch, State) ->
OnNomatch(State);
abstract_filter_({Key, '*'}, OnMatch, OnNomatch, State) ->
abstract_getkey(Key,
_OnMatch=fun(#state{}=State2) -> OnMatch(State2) end,
_OnNomatch=fun(State2) -> OnNomatch(State2) end, State);
abstract_filter_({Key, Op, Value}, OnMatch, OnNomatch, State)
when Op =:= '>'; Op =:= '='; Op =:= '<' ->
Op2 = case Op of '=' -> '=:='; Op -> Op end,
@ -176,7 +180,6 @@ abstract_opfilter(Key, Opname, Value, OnMatch, OnNomatch, State) ->
OnNomatch(State2))])] end,
_OnNomatch=fun(State2) -> OnNomatch(State2) end, State).
%% @private Generate an `all' filter.
%% An `all' filter is evaluated by testing all conditions that must hold. If
%% any of the conditions does not hold the evaluation is short circuted at that
@ -334,8 +337,8 @@ abstract_getcount(Counter) ->
%% @private Compile an abstract module.
-spec compile_forms(term(), [term()]) -> {ok, atom(), binary()}.
compile_forms(Forms, _Opts) ->
case compile:forms(Forms) of
compile_forms(Forms, Opts) ->
case compile:forms(Forms, Opts) of
{ok, Module, Binary} ->
{ok, Module, Binary};
{ok, Module, Binary, _Warnings} ->

+ 11
- 1
src/glc_lib.erl View File

@ -69,6 +69,11 @@ matches({Key, '>', Term}, Event) ->
case gre:find(Key, Event) of
{true, Term2} -> Term2 > Term;
false -> false
end;
matches({Key, '*'}, Event) ->
case gre:find(Key, Event) of
{true, _} -> true;
false -> false
end.
%% @private Repeatedly apply a function to a query.
@ -88,6 +93,8 @@ onoutput({_, '=', _}) ->
output;
onoutput({_, '>', _}) ->
output;
onoutput({_, '*'}) ->
output;
onoutput(Query) ->
erlang:error(badarg, [Query]).
@ -237,6 +244,8 @@ is_valid({Field, '=', _Term}) when is_atom(Field) ->
true;
is_valid({Field, '>', _Term}) when is_atom(Field) ->
true;
is_valid({Field, '*'}) when is_atom(Field) ->
true;
is_valid({null, true}) ->
true;
is_valid({null, false}) ->
@ -344,7 +353,8 @@ delete_from_any_test() ->
default_is_output_test_() ->
[?_assertEqual(output, glc_lib:onoutput(glc:lt(a, 1))),
?_assertEqual(output, glc_lib:onoutput(glc:eq(a, 1))),
?_assertEqual(output, glc_lib:onoutput(glc:gt(a, 1)))
?_assertEqual(output, glc_lib:onoutput(glc:gt(a, 1))),
?_assertEqual(output, glc_lib:onoutput(glc:wc(a)))
].
-ifdef(PROPER).

+ 9
- 1
src/glc_ops.erl View File

@ -4,7 +4,8 @@
-export([
lt/2,
eq/2,
gt/2
gt/2,
wc/1
]).
-export([
@ -22,6 +23,7 @@
{atom(), '<', term()} |
{atom(), '=', term()} |
{atom(), '>', term()} |
{atom(), '*'} |
{any, [op(), ...]} |
{all, [op(), ...]} |
{null, true|false}.
@ -49,6 +51,12 @@ gt(Key, Term) when is_atom(Key) ->
gt(Key, Term) ->
erlang:error(badarg, [Key, Term]).
%% @doc Test that a field value is exists.
-spec wc(atom()) -> op().
wc(Key) when is_atom(Key) ->
{Key, '*'};
wc(Key) ->
erlang:error(badarg, [Key]).
%% @doc Filter the input using multiple filters.
%%

Loading…
Cancel
Save