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 tests: clean app eunit ct
eunit: eunit:
@$(REBAR) eunit skip_deps=true
@$(REBAR) -C rebar.test.config eunit skip_deps=true
ct: ct:
@$(REBAR) ct skip_deps=true
@$(REBAR) -C rebar.test.config ct skip_deps=true
build-plt: build-plt:
@$(DIALYZER) --build_plt --output_plt .$(APPNAME)_dialyzer.plt \ @$(DIALYZER) --build_plt --output_plt .$(APPNAME)_dialyzer.plt \

+ 0
- 6
rebar.config View File

@ -1,12 +1,6 @@
{cover_enabled, true}. {cover_enabled, true}.
{eunit_opts, [{report, {eunit_surefire, [{dir, "."}]}}]}.
{erl_opts, [ {erl_opts, [
%% bin_opt_info, %% bin_opt_info,
%% warn_missing_spec, %% warn_missing_spec,
warnings_as_errors,
warn_export_all 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). %% glc:eq(a, 0).
%% %% Select all events where 'a' exists and is less than 0. %% %% Select all events where 'a' exists and is less than 0.
%% glc:lt(a, 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. %% %% Select no input events. Used as black hole query.
%% glc:null(false). %% glc:null(false).
@ -68,7 +70,8 @@
-export([ -export([
lt/2, lt/2,
eq/2, eq/2,
gt/2
gt/2,
wc/1
]). ]).
-export([ -export([
@ -100,6 +103,9 @@ eq(Key, Term) ->
gt(Key, Term) -> gt(Key, Term) ->
glc_ops: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. %% @doc Filter the input using multiple filters.
%% %%

+ 7
- 4
src/glc_code.erl View File

@ -27,7 +27,7 @@
compile(Module, ModuleData) -> compile(Module, ModuleData) ->
{ok, forms, Forms} = abstract_module(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, loaded, Module} = load_binary(Module, Binary),
{ok, Module}. {ok, Module}.
@ -150,6 +150,10 @@ abstract_filter_({null, true}, OnMatch, _OnNomatch, State) ->
OnMatch(State); OnMatch(State);
abstract_filter_({null, false}, _OnMatch, OnNomatch, State) -> abstract_filter_({null, false}, _OnMatch, OnNomatch, State) ->
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) abstract_filter_({Key, Op, Value}, OnMatch, OnNomatch, State)
when Op =:= '>'; Op =:= '='; Op =:= '<' -> when Op =:= '>'; Op =:= '='; Op =:= '<' ->
Op2 = case Op of '=' -> '=:='; Op -> Op end, Op2 = case Op of '=' -> '=:='; Op -> Op end,
@ -176,7 +180,6 @@ abstract_opfilter(Key, Opname, Value, OnMatch, OnNomatch, State) ->
OnNomatch(State2))])] end, OnNomatch(State2))])] end,
_OnNomatch=fun(State2) -> OnNomatch(State2) end, State). _OnNomatch=fun(State2) -> OnNomatch(State2) end, State).
%% @private Generate an `all' filter. %% @private Generate an `all' filter.
%% An `all' filter is evaluated by testing all conditions that must hold. If %% 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 %% 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. %% @private Compile an abstract module.
-spec compile_forms(term(), [term()]) -> {ok, atom(), binary()}. -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}; {ok, Module, Binary};
{ok, Module, Binary, _Warnings} -> {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 case gre:find(Key, Event) of
{true, Term2} -> Term2 > Term; {true, Term2} -> Term2 > Term;
false -> false false -> false
end;
matches({Key, '*'}, Event) ->
case gre:find(Key, Event) of
{true, _} -> true;
false -> false
end. end.
%% @private Repeatedly apply a function to a query. %% @private Repeatedly apply a function to a query.
@ -88,6 +93,8 @@ onoutput({_, '=', _}) ->
output; output;
onoutput({_, '>', _}) -> onoutput({_, '>', _}) ->
output; output;
onoutput({_, '*'}) ->
output;
onoutput(Query) -> onoutput(Query) ->
erlang:error(badarg, [Query]). erlang:error(badarg, [Query]).
@ -237,6 +244,8 @@ is_valid({Field, '=', _Term}) when is_atom(Field) ->
true; true;
is_valid({Field, '>', _Term}) when is_atom(Field) -> is_valid({Field, '>', _Term}) when is_atom(Field) ->
true; true;
is_valid({Field, '*'}) when is_atom(Field) ->
true;
is_valid({null, true}) -> is_valid({null, true}) ->
true; true;
is_valid({null, false}) -> is_valid({null, false}) ->
@ -344,7 +353,8 @@ delete_from_any_test() ->
default_is_output_test_() -> default_is_output_test_() ->
[?_assertEqual(output, glc_lib:onoutput(glc:lt(a, 1))), [?_assertEqual(output, glc_lib:onoutput(glc:lt(a, 1))),
?_assertEqual(output, glc_lib:onoutput(glc:eq(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). -ifdef(PROPER).

+ 9
- 1
src/glc_ops.erl View File

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

Loading…
Cancel
Save