|
@@ -0,0 +1,189 @@
|
|
|
+-module(erlydtl_parser).
|
|
|
+-export([parse/1, parse_and_scan/1, format_error/1]).
|
|
|
+-file("src/erlydtl/erlydtl_parser.yrl", 63).
|
|
|
+
|
|
|
+block({_, _, [Name]}, Content) ->
|
|
|
+ {block, list_to_atom(Name), Content}.
|
|
|
+-file("/Users/rsaccon/R11B/erlang/lib/parsetools-1.4.1.1/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("src/erlydtl/erlydtl_parser.erl", 100).
|
|
|
+
|
|
|
+yeccpars2(0, __Cat, __Ss, __Stack, __T, __Ts, __Tzr) ->
|
|
|
+ __NewStack = yeccpars2_0_(__Stack),
|
|
|
+ yeccpars2(1, __Cat, [0 | __Ss], __NewStack, __T, __Ts, __Tzr);
|
|
|
+yeccpars2(1, '$end', _, __Stack, _, _, _) ->
|
|
|
+ {ok, hd(__Stack)};
|
|
|
+yeccpars2(1, block, __Ss, __Stack, __T, __Ts, __Tzr) ->
|
|
|
+ yeccpars1(__Ts, __Tzr, 3, [1 | __Ss], [__T | __Stack]);
|
|
|
+yeccpars2(1, extends, __Ss, __Stack, __T, __Ts, __Tzr) ->
|
|
|
+ yeccpars1(__Ts, __Tzr, 4, [1 | __Ss], [__T | __Stack]);
|
|
|
+yeccpars2(1, string, __Ss, __Stack, __T, __Ts, __Tzr) ->
|
|
|
+ yeccpars1(__Ts, __Tzr, 5, [1 | __Ss], [__T | __Stack]);
|
|
|
+yeccpars2(1, var, __Ss, __Stack, __T, __Ts, __Tzr) ->
|
|
|
+ yeccpars1(__Ts, __Tzr, 6, [1 | __Ss], [__T | __Stack]);
|
|
|
+yeccpars2(1, _, _, _, __T, _, _) ->
|
|
|
+ yeccerror(__T);
|
|
|
+yeccpars2(2, __Cat, __Ss, __Stack, __T, __Ts, __Tzr) ->
|
|
|
+ __NewStack = yeccpars2_2_(__Stack),
|
|
|
+ __Nss = lists:nthtail(1, __Ss),
|
|
|
+ yeccpars2(yeccgoto('Elements', hd(__Nss)), __Cat, __Nss, __NewStack, __T, __Ts, __Tzr);
|
|
|
+yeccpars2(3, __Cat, __Ss, __Stack, __T, __Ts, __Tzr) ->
|
|
|
+ __NewStack = yeccpars2_3_(__Stack),
|
|
|
+ yeccpars2(7, __Cat, [3 | __Ss], __NewStack, __T, __Ts, __Tzr);
|
|
|
+yeccpars2(4, __Cat, __Ss, __Stack, __T, __Ts, __Tzr) ->
|
|
|
+ yeccpars2(yeccgoto('Element', hd(__Ss)), __Cat, __Ss, __Stack, __T, __Ts, __Tzr);
|
|
|
+yeccpars2(5, __Cat, __Ss, __Stack, __T, __Ts, __Tzr) ->
|
|
|
+ yeccpars2(yeccgoto('Element', hd(__Ss)), __Cat, __Ss, __Stack, __T, __Ts, __Tzr);
|
|
|
+yeccpars2(6, __Cat, __Ss, __Stack, __T, __Ts, __Tzr) ->
|
|
|
+ yeccpars2(yeccgoto('Element', hd(__Ss)), __Cat, __Ss, __Stack, __T, __Ts, __Tzr);
|
|
|
+yeccpars2(7, block, __Ss, __Stack, __T, __Ts, __Tzr) ->
|
|
|
+ yeccpars1(__Ts, __Tzr, 3, [7 | __Ss], [__T | __Stack]);
|
|
|
+yeccpars2(7, endblock, __Ss, __Stack, __T, __Ts, __Tzr) ->
|
|
|
+ yeccpars1(__Ts, __Tzr, 8, [7 | __Ss], [__T | __Stack]);
|
|
|
+yeccpars2(7, extends, __Ss, __Stack, __T, __Ts, __Tzr) ->
|
|
|
+ yeccpars1(__Ts, __Tzr, 4, [7 | __Ss], [__T | __Stack]);
|
|
|
+yeccpars2(7, string, __Ss, __Stack, __T, __Ts, __Tzr) ->
|
|
|
+ yeccpars1(__Ts, __Tzr, 5, [7 | __Ss], [__T | __Stack]);
|
|
|
+yeccpars2(7, var, __Ss, __Stack, __T, __Ts, __Tzr) ->
|
|
|
+ yeccpars1(__Ts, __Tzr, 6, [7 | __Ss], [__T | __Stack]);
|
|
|
+yeccpars2(7, _, _, _, __T, _, _) ->
|
|
|
+ yeccerror(__T);
|
|
|
+yeccpars2(8, __Cat, __Ss, __Stack, __T, __Ts, __Tzr) ->
|
|
|
+ __NewStack = yeccpars2_8_(__Stack),
|
|
|
+ __Nss = lists:nthtail(2, __Ss),
|
|
|
+ yeccpars2(yeccgoto('Element', hd(__Nss)), __Cat, __Nss, __NewStack, __T, __Ts, __Tzr);
|
|
|
+yeccpars2(__Other, _, _, _, _, _, _) ->
|
|
|
+ erlang:error({yecc_bug,"1.1",{missing_state_in_action_table, __Other}}).
|
|
|
+
|
|
|
+yeccgoto('Element', 1) ->
|
|
|
+ 2;
|
|
|
+yeccgoto('Element', 7) ->
|
|
|
+ 2;
|
|
|
+yeccgoto('Elements', 0) ->
|
|
|
+ 1;
|
|
|
+yeccgoto('Elements', 3) ->
|
|
|
+ 7;
|
|
|
+yeccgoto(__Symbol, __State) ->
|
|
|
+ erlang:error({yecc_bug,"1.1",{__Symbol, __State, missing_in_goto_table}}).
|
|
|
+
|
|
|
+-compile({inline,{yeccpars2_0_,1}}).
|
|
|
+-file("src/erlydtl/erlydtl_parser.yrl", 51).
|
|
|
+yeccpars2_0_(__Stack) ->
|
|
|
+ [begin
|
|
|
+ nil
|
|
|
+ end | __Stack].
|
|
|
+
|
|
|
+-compile({inline,{yeccpars2_2_,1}}).
|
|
|
+-file("src/erlydtl/erlydtl_parser.yrl", 52).
|
|
|
+yeccpars2_2_([__2,__1 | __Stack]) ->
|
|
|
+ [begin
|
|
|
+ [ __1 , __2 ]
|
|
|
+ end | __Stack].
|
|
|
+
|
|
|
+-compile({inline,{yeccpars2_3_,1}}).
|
|
|
+-file("src/erlydtl/erlydtl_parser.yrl", 51).
|
|
|
+yeccpars2_3_(__Stack) ->
|
|
|
+ [begin
|
|
|
+ nil
|
|
|
+ end | __Stack].
|
|
|
+
|
|
|
+-compile({inline,{yeccpars2_8_,1}}).
|
|
|
+-file("src/erlydtl/erlydtl_parser.yrl", 57).
|
|
|
+yeccpars2_8_([__3,__2,__1 | __Stack]) ->
|
|
|
+ [begin
|
|
|
+ block ( __1 , __2 )
|
|
|
+ end | __Stack].
|
|
|
+
|
|
|
+
|
|
|
+-file("src/erlydtl/erlydtl_parser.yrl", 66).
|