1%% 2%% %CopyrightBegin% 3%% 4%% Copyright Ericsson AB 2008-2016. All Rights Reserved. 5%% 6%% Licensed under the Apache License, Version 2.0 (the "License"); 7%% you may not use this file except in compliance with the License. 8%% You may obtain a copy of the License at 9%% 10%% http://www.apache.org/licenses/LICENSE-2.0 11%% 12%% Unless required by applicable law or agreed to in writing, software 13%% distributed under the License is distributed on an "AS IS" BASIS, 14%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15%% See the License for the specific language governing permissions and 16%% limitations under the License. 17%% 18%% %CopyrightEnd% 19%% 20 21%% 22-module(xmerl_xpath_lib). 23 24-include("xmerl.hrl"). 25 26-export([eval/3]). 27 28-define(string(X), #xmlObj{type = string, 29 value = X}). 30-define(number(X), #xmlObj{type = number, 31 value = X}). 32 33 34eval(primary_expr,PrimExpr,C) -> 35 primary_expr(PrimExpr, C); 36eval(predicate,Pred,C) -> 37 xmerl_xpath_pred:eval(Pred,C). 38 39primary_expr({number, N}, _C) -> 40 ?number(N); 41primary_expr({literal, S}, _C) -> 42 ?string(S); 43primary_expr({function_call, F, Args}, C) -> 44 case xmerl_xpath_pred:core_function(F) of 45 {true, F1} -> 46 xmerl_xpath_pred:F1(C, Args); 47 true -> 48 xmerl_xpath_pred:F(C, Args); 49 false -> 50 %% here, we should look up the function in the context provided 51 %% by the caller, but we haven't figured this out yet. 52 exit({not_a_core_function, F}) 53 end; 54primary_expr(PrimExpr, _C) -> 55 exit({primary_expression, {not_implemented, PrimExpr}}). 56 57