⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xref_parser.erl

📁 OTP是开放电信平台的简称
💻 ERL
📖 第 1 页 / 共 5 页
字号:
-module(xref_parser).-export([parse/1, parse_and_scan/1, format_error/1]).-file("xref_parser.yrl", 107).-export([t2s/1]).-import(lists, [concat/1, flatten/1]).%%% Syntax of the parse tree:%%% Start = [Statement]%%% Statement = {assign, AOp, VarName, Expr}%%%           | Expr%%% AOp = tmp | user%%% Expr = Constants | Variable | Unary | Binary | RegExpr%%% Constants = {list, [Constant]}  % not empty list%%%           | {tuple, [Constant]}%%%           | Constant % only to avoid [ and ] in error messages...%%% Constant = {constant, 'Fun', vertex, MFA} | %%%            {constant, AtomType, vertex, atom()} |%%%            {constant, 'Fun', edge, {MFA, MFA}} | %%%            {constant, AtomType, edge, {atom(), atom()}}%%% Variable = {variable, VarName}%%% VarName = atom()%%% Unary = {set, SetUOp, Expr} %%%       | {graph, GraphUOp, Expr}%%%       | {type, {TypeOp, Type}, Expr}%%%       | {numeric, NumOp, Expr, Expr}%%% SetUOp = range | domain | weak | strict%%% GraphUOp = components | condensation | closure%%% Binary = {set, SetBOp, Expr, Expr}%%%        | {restr, RestrOp, Expr, Expr}%%%        | {path, Expr, Expr}%%% SetBOp = union | intersection | difference%%% RestrOp = '|' | '||' | '|||'%%% TypeOp = type | convert%%% NumOp = '#'%%% RegExpr = {regexpr, RExpr, Type}%%% RExpr = string() | {AtomReg, AtomReg, IntReg}%%% AtomReg = string() | atom() | variable()%%% IntReg = string() | integer()%%% MFA = {atom(), atom(), integer()}%%% Type = 'Rel' | 'App' | 'Mod' | 'Fun'%%%      | 'Lin' | 'LLin' | 'XLin' | 'ELin' | 'XXL'%%% AtomType = unknown | 'Rel' | 'App' | 'Mod'value_of(Token) ->    element(3, Token).prefix(Op, Expr) ->    case is_prefix_op(Op) of	false ->	    return_error(0, ["invalid_operator", Op]);	UOp ->	    {UOp, Op, Expr}    end.is_prefix_op(range) -> set;is_prefix_op(domain) -> set;is_prefix_op(weak) -> set;is_prefix_op(strict) -> set;is_prefix_op(components) -> graph;is_prefix_op(condensation) -> graph;is_prefix_op(closure) -> graph;is_prefix_op('#') -> numeric;is_prefix_op(_) -> false.check_regexp(String) ->    case regexp:parse(String) of	{ok, _Expr} ->	    {regexpr, String};	{error, Reason} ->	    F = regexp:format_error(Reason),	    return_error(0, ["invalid_regexp", String, F])    end.check_regexp_variable('_') ->    variable;check_regexp_variable(Var) ->    return_error(0, ["invalid_regexp_variable", Var]).regexp(func, RExpr, unknown) ->    {regexpr, RExpr, 'Fun'};regexp(_, RExpr, unknown) ->    return_error(0, ["missing_type", t2s({regexpr, RExpr, unknown})]);regexp(Kind, RExpr, Type) ->    E = {type, {type, Type}, {regexpr, RExpr, Type}},    case Type of	'Fun' when Kind =:= func -> E;	'Mod' when Kind =:= atom -> E;	'App' when Kind =:= atom -> E;	'Rel' when Kind =:= atom -> E;	_Else -> return_error(0, ["type_mismatch", t2s(E)])    end.type(Expr, unknown) ->    Expr;type(Expr, Type) ->    {type, {type, Type}, type_constants(Expr, Type, Expr)}.type_constants({list, L}, Type, E) ->    {list, type_constants(L, Type, E)};type_constants({tuple, L}, Type, E) ->    {tuple, type_constants(L, Type, E)};type_constants([C | Cs], Type, E) ->    [type_constants(C, Type, E) | type_constants(Cs, Type, E)];type_constants([], _Type, _E) ->    [];type_constants({constant, unknown, OType, Con}, 'Rel', _E) ->    {constant, 'Rel', OType, Con};type_constants({constant, unknown, OType, Con}, 'App', _E) ->    {constant, 'App', OType, Con};type_constants({constant, unknown, OType, Con}, 'Mod', _E) ->    {constant, 'Mod', OType, Con};type_constants(C={constant, Type, _OType, _Con}, Type, _E) ->    C;type_constants(_C, Type, E) ->    return_error(0, ["type_mismatch", t2s({type, {type, Type}, E})]).t2s(T) ->    concat(flatten(e2s(T, 0))).%% Does not handle list of statements.e2s({assign, VarType, Name, E}, P) ->    [left(P, 100), Name, name_it(VarType), e2s(E, 100), right(P, 100)];e2s({constant, 'Fun', vertex, MFA}, _P) ->    mfa2s(MFA);e2s({constant, _Type, vertex, A}, _P) ->    [c2s(A)];e2s({constant, 'Fun', edge, {MFA1,MFA2}}, _P) ->    [mfa2s(MFA1),' -> ',mfa2s(MFA2)];e2s({constant, _Type, edge, {A1,A2}}, _P) ->    [c2s(A1),' -> ',c2s(A2)];e2s({variable, Name}, _P) ->    [Name];e2s({list, E}, _P) ->    ['[', e2s(E, 0), ']'];e2s({tuple, E}, _P) ->    ['{', e2s(E, 0), '}'];e2s({type, {convert, Type}, E}, P) ->    [left(P, 700), '(',Type,') ', e2s(E, 700), right(P, 700)];e2s({type, {type, Type}, E}, P) ->    [left(P, 700), e2s(E, 700), ' : ', Type, right(P, 700)];e2s({set, Op, E}, P) ->    [left(P, 700), name_it(Op), ' ', e2s(E, 700), right(P, 700)];e2s({graph, Op, E}, P) ->    [left(P, 700), name_it(Op), ' ', e2s(E, 700), right(P, 700)];e2s({numeric, Op, E}, P) ->    [left(P, 400), name_it(Op), ' ', e2s(E, 400), right(P, 400)];e2s({set, Op, E1, E2}, P) ->    P1 = prio(Op),    [left(P, P1), e2s(E1, P1),name_it(Op),e2s(E2, P1+50), right(P, P1)];e2s({path, E1, E2}, P) ->    P1 = 600,    [left(P, P1), e2s(E1, P1),' of ',e2s(E2, P1+50), right(P, P1)];e2s({regexpr, Expr={regexpr,_}, _Type}, _P) ->    [re(Expr)];e2s({regexpr, {M,F,A}, _Type}, _P) ->    [re(M),':',re(F),'/', re(A)];e2s({restr, Op, E1, E2}, P) ->    P1 = 500,    [left(P, P1), e2s(E1, P1),name_it(Op),e2s(E2, P1+50), right(P, P1)];e2s([], _P) ->    [];e2s([E], P) ->    e2s(E, P);e2s([E | Es], P) ->    [e2s(E, P),', ',e2s(Es, P)].mfa2s({M,F,A}) ->    [c2s(M),':',c2s(F),'/',A].c2s(C) ->    [S] = io_lib:format("~p", [C]),    list_to_atom(S).re(variable) -> ['_'];re({atom, Atom}) -> [Atom];re({integer, Int}) -> [Int];re({regexpr, Str}) -> ['"',erlang:list_to_atom(Str),'"'].left(P1, P2) when P1 > P2 -> ['('];left(_P1, _P2) -> [].right(P1, P2) when P1 > P2 -> [')'];right(_P1, _P2) -> [].prio(intersection) -> 300;prio(difference)   -> 200;prio(union)        -> 200.name_it(tmp)           -> ' = ';name_it(user)          -> ' := ';name_it('|')           -> ' | ';name_it('||')          -> ' || ';name_it('|||')         -> ' ||| ';name_it(union)         -> ' + ';name_it(intersection)  -> ' * ';name_it(difference)    -> ' - ';name_it(Name) -> Name.   -file("/ldisk/daily_build/otp_prebuild_r11b.2007-06-11_19/otp_src_R11B-5/bootstrap/lib/parsetools/include/yeccpre.hrl", 0).%% ``The contents of this file are subject to the Erlang Public License,%% Version 1.1, (the "License"); you may not use this file except in%% compliance with the License. You should have received a copy of the%% Erlang Public License along with this software. If not, it can be%% retrieved via the world wide web at http://www.erlang.org/.%% %% Software distributed under the License is distributed on an "AS IS"%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See%% the License for the specific language governing rights and limitations%% under the License.%% %% The Initial Developer of the Original Code is Ericsson Utvecklings AB.%% Portions created by Ericsson are Copyright 1999, Ericsson Utvecklings%% AB. All Rights Reserved.''%% %%     $Id $%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% The parser generator will insert appropriate declarations before this line.%parse(Tokens) ->    yeccpars0(Tokens, false).parse_and_scan({F, A}) -> % Fun or {M, F}    yeccpars0([], {F, A});parse_and_scan({M, F, A}) ->    yeccpars0([], {{M, F}, A}).format_error(Message) ->    case io_lib:deep_char_list(Message) of	true ->	    Message;	_ ->	    io_lib:write(Message)    end.% To be used in grammar files to throw an error message to the parser% toplevel. Doesn't have to be exported!-compile({nowarn_unused_function,{return_error,2}}).return_error(Line, Message) ->    throw({error, {Line, ?MODULE, Message}}).yeccpars0(Tokens, MFA) ->    try yeccpars1(Tokens, MFA, 0, [], [])    catch         throw: {error, {_Line, ?MODULE, _M}} = Error ->                    Error % probably from return_error/1    end.% Don't change yeccpars1/6 too much, it is called recursively by yeccpars2/8!yeccpars1([Token | Tokens], Tokenizer, State, States, Vstack) ->    yeccpars2(State, element(1, Token), States, Vstack, Token, Tokens,	      Tokenizer);yeccpars1([], {F, A}, State, States, Vstack) ->    case apply(F, A) of        {ok, Tokens, _Endline} ->	    yeccpars1(Tokens, {F, A}, State, States, Vstack);        {eof, _Endline} ->            yeccpars1([], false, State, States, Vstack);        {error, Descriptor, _Endline} ->            {error, Descriptor}    end;yeccpars1([], false, State, States, Vstack) ->    yeccpars2(State, '$end', States, Vstack, {'$end', 999999}, [], false).% For internal use only.yeccerror(Token) ->    {error,     {element(2, Token), ?MODULE,      ["syntax error before: ", yecctoken2string(Token)]}}.yecctoken2string({atom, _, A}) -> io_lib:write(A);yecctoken2string({integer,_,N}) -> io_lib:write(N);yecctoken2string({float,_,F}) -> io_lib:write(F);yecctoken2string({char,_,C}) -> io_lib:write_char(C);yecctoken2string({var,_,V}) -> io_lib:format('~s', [V]);yecctoken2string({string,_,S}) -> io_lib:write_string(S);yecctoken2string({reserved_symbol, _, A}) -> io_lib:format('~w', [A]);yecctoken2string({_Cat, _, Val}) -> io_lib:format('~w', [Val]);yecctoken2string({'dot', _}) -> io_lib:format('~w', ['.']);yecctoken2string({'$end', _}) ->    [];yecctoken2string({Other, _}) when is_atom(Other) ->    io_lib:format('~w', [Other]);yecctoken2string(Other) ->    io_lib:write(Other).%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%-file("./xref_parser.erl", 294).yeccpars2(0, '#', __Ss, __Stack, __T, __Ts, __Tzr) -> yeccpars1(__Ts, __Tzr, 16, [0 | __Ss], [__T | __Stack]);yeccpars2(0, '(', __Ss, __Stack, __T, __Ts, __Tzr) -> yeccpars1(__Ts, __Tzr, 17, [0 | __Ss], [__T | __Stack]);yeccpars2(0, '[', __Ss, __Stack, __T, __Ts, __Tzr) -> yeccpars1(__Ts, __Tzr, 18, [0 | __Ss], [__T | __Stack]);yeccpars2(0, atom, __Ss, __Stack, __T, __Ts, __Tzr) -> yeccpars1(__Ts, __Tzr, 19, [0 | __Ss], [__T | __Stack]);yeccpars2(0, edge, __Ss, __Stack, __T, __Ts, __Tzr) -> yeccpars1(__Ts, __Tzr, 20, [0 | __Ss], [__T | __Stack]);yeccpars2(0, string, __Ss, __Stack, __T, __Ts, __Tzr) -> yeccpars1(__Ts, __Tzr, 21, [0 | __Ss], [__T | __Stack]);yeccpars2(0, var, __Ss, __Stack, __T, __Ts, __Tzr) -> yeccpars1(__Ts, __Tzr, 22, [0 | __Ss], [__T | __Stack]);yeccpars2(0, vertex, __Ss, __Stack, __T, __Ts, __Tzr) -> yeccpars1(__Ts, __Tzr, 23, [0 | __Ss], [__T | __Stack]);yeccpars2(0, '{', __Ss, __Stack, __T, __Ts, __Tzr) -> yeccpars1(__Ts, __Tzr, 24, [0 | __Ss], [__T | __Stack]);yeccpars2(0, _, _, _, __T, _, _) -> yeccerror(__T);yeccpars2(1, '$end', _, __Stack, _, _, _) -> {ok, hd(__Stack)};yeccpars2(1, _, _, _, __T, _, _) -> yeccerror(__T);yeccpars2(2, ':=', __Ss, __Stack, __T, __Ts, __Tzr) -> yeccpars1(__Ts, __Tzr, 77, [2 | __Ss], [__T | __Stack]);yeccpars2(2, '=', __Ss, __Stack, __T, __Ts, __Tzr) -> yeccpars1(__Ts, __Tzr, 78, [2 | __Ss], [__T | __Stack]);yeccpars2(2, '$end', __Ss, __Stack, __T, __Ts, __Tzr) -> __NewStack = 'yeccpars2_2_$end'(__Stack), yeccpars2(yeccgoto(expr, hd(__Ss)), '$end', __Ss, __NewStack, __T, __Ts, __Tzr);yeccpars2(2, '*', __Ss, __Stack, __T, __Ts, __Tzr) -> __NewStack = 'yeccpars2_2_*'(__Stack), yeccpars2(yeccgoto(expr, hd(__Ss)), '*', __Ss, __NewStack, __T, __Ts, __Tzr);yeccpars2(2, '+', __Ss, __Stack, __T, __Ts, __Tzr) -> __NewStack = 'yeccpars2_2_+'(__Stack), yeccpars2(yeccgoto(expr, hd(__Ss)), '+', __Ss, __NewStack, __T, __Ts, __Tzr);yeccpars2(2, '-', __Ss, __Stack, __T, __Ts, __Tzr) -> __NewStack = 'yeccpars2_2_-'(__Stack), yeccpars2(yeccgoto(expr, hd(__Ss)), '-', __Ss, __NewStack, __T, __Ts, __Tzr);yeccpars2(2, 'of', __Ss, __Stack, __T, __Ts, __Tzr) -> __NewStack = yeccpars2_2_of(__Stack), yeccpars2(yeccgoto(expr, hd(__Ss)), 'of', __Ss, __NewStack, __T, __Ts, __Tzr);yeccpars2(2, '|', __Ss, __Stack, __T, __Ts, __Tzr) -> __NewStack = 'yeccpars2_2_|'(__Stack), yeccpars2(yeccgoto(expr, hd(__Ss)), '|', __Ss, __NewStack, __T, __Ts, __Tzr);yeccpars2(2, '||', __Ss, __Stack, __T, __Ts, __Tzr) -> __NewStack = 'yeccpars2_2_||'(__Stack), yeccpars2(yeccgoto(expr, hd(__Ss)), '||', __Ss, __NewStack, __T, __Ts, __Tzr);yeccpars2(2, '|||', __Ss, __Stack, __T, __Ts, __Tzr) -> __NewStack = 'yeccpars2_2_|||'(__Stack), yeccpars2(yeccgoto(expr, hd(__Ss)), '|||', __Ss, __NewStack, __T, __Ts, __Tzr);yeccpars2(2, __Cat, __Ss, __Stack, __T, __Ts, __Tzr) -> __NewStack = yeccpars2_2_(__Stack), yeccpars2(yeccgoto(regvar, hd(__Ss)), __Cat, __Ss, __NewStack, __T, __Ts, __Tzr);yeccpars2(3, __Cat, __Ss, __Stack, __T, __Ts, __Tzr) -> yeccpars2(yeccgoto(xref, hd(__Ss)), __Cat, __Ss, __Stack, __T, __Ts, __Tzr);yeccpars2(4, ',', __Ss, __Stack, __T, __Ts, __Tzr) -> yeccpars1(__Ts, __Tzr, 74, [4 | __Ss], [__T | __Stack]);yeccpars2(4, __Cat, __Ss, __Stack, __T, __Ts, __Tzr) -> __NewStack = yeccpars2_4_(__Stack), yeccpars2(yeccgoto(statements, hd(__Ss)), __Cat, __Ss, __NewStack, __T, __Ts, __Tzr);yeccpars2(5, __Cat, __Ss, __Stack, __T, __Ts, __Tzr) -> yeccpars2(yeccgoto(regatom, hd(__Ss)), __Cat, __Ss, __Stack, __T, __Ts, __Tzr);yeccpars2(6, decl, __Ss, __Stack, __T, __Ts, __Tzr) -> yeccpars1(__Ts, __Tzr, 33, [6 | __Ss], [__T | __Stack]);yeccpars2(6, '$end', __Ss, __Stack, __T, __Ts, __Tzr) -> __NewStack = 'yeccpars2_6_$end'(__Stack), yeccpars2(73, '$end', [6 | __Ss], __NewStack, __T, __Ts, __Tzr);yeccpars2(6, ')', __Ss, __Stack, __T, __Ts, __Tzr) -> __NewStack = 'yeccpars2_6_)'(__Stack), yeccpars2(73, ')', [6 | __Ss], __NewStack, __T, __Ts, __Tzr);yeccpars2(6, '*', __Ss, __Stack, __T, __Ts, __Tzr) -> __NewStack = 'yeccpars2_6_*'(__Stack), yeccpars2(73, '*', [6 | __Ss], __NewStack, __T, __Ts, __Tzr);yeccpars2(6, '+', __Ss, __Stack, __T, __Ts, __Tzr) -> __NewStack = 'yeccpars2_6_+'(__Stack), yeccpars2(73, '+', [6 | __Ss], __NewStack, __T, __Ts, __Tzr);yeccpars2(6, ',', __Ss, __Stack, __T, __Ts, __Tzr) -> __NewStack = 'yeccpars2_6_,'(__Stack), yeccpars2(73, ',', [6 | __Ss], __NewStack, __T, __Ts, __Tzr);yeccpars2(6, '-', __Ss, __Stack, __T, __Ts, __Tzr) -> __NewStack = 'yeccpars2_6_-'(__Stack), yeccpars2(73, '-', [6 | __Ss], __NewStack, __T, __Ts, __Tzr);yeccpars2(6, 'of', __Ss, __Stack, __T, __Ts, __Tzr) -> __NewStack = yeccpars2_6_of(__Stack), yeccpars2(73, 'of', [6 | __Ss], __NewStack, __T, __Ts, __Tzr);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -