-module(erlydtl_parser). -export([parse/1, parse_and_scan/1, format_error/1]). -file("src/erlydtl/erlydtl_parser.yrl", 68). string({_, String}) -> erl_syntax:binary([erl_syntax:binary_field(erl_syntax:integer(X)) || X <- String]). var({_, Line, Var}) -> {var, Line, list_to_atom("A" ++ Var)}. extends({_, Line, [Name]}) -> %% TODO: check if string (enclosed with "") or variable. %% for now we handle it (even not enclosed with "") as string {extends, Line, string:strip(Name, both, $")}. block({_, Line, [Name]}, Content) -> {block, Line, list_to_atom(Name), Content}. tag({_, Line, [TagName | Args]}) -> %% TODO: check if string (enclosed with "") or variable. %% for now we handle it (even not enclosed with "") as string Args2 = lists:foldl(fun(X, Acc) -> case string:chr(X, $=) of 0 -> Acc; Pos -> Var = list_to_atom(string:sub_string(X, 1, Pos-1)), Val = string:sub_string(X, Pos+1), Val2 = string:strip(Val, both, $"), [{Var, Val2}| Acc] end end, [], Args), {tag, Line, TagName, Args2}. for({_, Line, [Iterator, _, Var]}, Content) -> {for, Line, list_to_atom("A" ++ Iterator), list_to_atom("A" ++ Var), 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", 137). 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, for, __Ss, __Stack, __T, __Ts, __Tzr) -> yeccpars1(__Ts, __Tzr, 5, [1 | __Ss], [__T | __Stack]); yeccpars2(1, string, __Ss, __Stack, __T, __Ts, __Tzr) -> yeccpars1(__Ts, __Tzr, 6, [1 | __Ss], [__T | __Stack]); yeccpars2(1, tag, __Ss, __Stack, __T, __Ts, __Tzr) -> yeccpars1(__Ts, __Tzr, 7, [1 | __Ss], [__T | __Stack]); yeccpars2(1, var, __Ss, __Stack, __T, __Ts, __Tzr) -> yeccpars1(__Ts, __Tzr, 8, [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(11, __Cat, [3 | __Ss], __NewStack, __T, __Ts, __Tzr); yeccpars2(4, __Cat, __Ss, __Stack, __T, __Ts, __Tzr) -> __NewStack = yeccpars2_4_(__Stack), yeccpars2(yeccgoto('Element', hd(__Ss)), __Cat, __Ss, __NewStack, __T, __Ts, __Tzr); yeccpars2(5, __Cat, __Ss, __Stack, __T, __Ts, __Tzr) -> __NewStack = yeccpars2_5_(__Stack), yeccpars2(9, __Cat, [5 | __Ss], __NewStack, __T, __Ts, __Tzr); yeccpars2(6, __Cat, __Ss, __Stack, __T, __Ts, __Tzr) -> __NewStack = yeccpars2_6_(__Stack), yeccpars2(yeccgoto('Element', hd(__Ss)), __Cat, __Ss, __NewStack, __T, __Ts, __Tzr); yeccpars2(7, __Cat, __Ss, __Stack, __T, __Ts, __Tzr) -> __NewStack = yeccpars2_7_(__Stack), yeccpars2(yeccgoto('Element', hd(__Ss)), __Cat, __Ss, __NewStack, __T, __Ts, __Tzr); yeccpars2(8, __Cat, __Ss, __Stack, __T, __Ts, __Tzr) -> __NewStack = yeccpars2_8_(__Stack), yeccpars2(yeccgoto('Element', hd(__Ss)), __Cat, __Ss, __NewStack, __T, __Ts, __Tzr); yeccpars2(9, block, __Ss, __Stack, __T, __Ts, __Tzr) -> yeccpars1(__Ts, __Tzr, 3, [9 | __Ss], [__T | __Stack]); yeccpars2(9, endfor, __Ss, __Stack, __T, __Ts, __Tzr) -> yeccpars1(__Ts, __Tzr, 10, [9 | __Ss], [__T | __Stack]); yeccpars2(9, extends, __Ss, __Stack, __T, __Ts, __Tzr) -> yeccpars1(__Ts, __Tzr, 4, [9 | __Ss], [__T | __Stack]); yeccpars2(9, for, __Ss, __Stack, __T, __Ts, __Tzr) -> yeccpars1(__Ts, __Tzr, 5, [9 | __Ss], [__T | __Stack]); yeccpars2(9, string, __Ss, __Stack, __T, __Ts, __Tzr) -> yeccpars1(__Ts, __Tzr, 6, [9 | __Ss], [__T | __Stack]); yeccpars2(9, tag, __Ss, __Stack, __T, __Ts, __Tzr) -> yeccpars1(__Ts, __Tzr, 7, [9 | __Ss], [__T | __Stack]); yeccpars2(9, var, __Ss, __Stack, __T, __Ts, __Tzr) -> yeccpars1(__Ts, __Tzr, 8, [9 | __Ss], [__T | __Stack]); yeccpars2(9, _, _, _, __T, _, _) -> yeccerror(__T); yeccpars2(10, __Cat, __Ss, __Stack, __T, __Ts, __Tzr) -> __NewStack = yeccpars2_10_(__Stack), __Nss = lists:nthtail(2, __Ss), yeccpars2(yeccgoto('Element', hd(__Nss)), __Cat, __Nss, __NewStack, __T, __Ts, __Tzr); yeccpars2(11, block, __Ss, __Stack, __T, __Ts, __Tzr) -> yeccpars1(__Ts, __Tzr, 3, [11 | __Ss], [__T | __Stack]); yeccpars2(11, endblock, __Ss, __Stack, __T, __Ts, __Tzr) -> yeccpars1(__Ts, __Tzr, 12, [11 | __Ss], [__T | __Stack]); yeccpars2(11, extends, __Ss, __Stack, __T, __Ts, __Tzr) -> yeccpars1(__Ts, __Tzr, 4, [11 | __Ss], [__T | __Stack]); yeccpars2(11, for, __Ss, __Stack, __T, __Ts, __Tzr) -> yeccpars1(__Ts, __Tzr, 5, [11 | __Ss], [__T | __Stack]); yeccpars2(11, string, __Ss, __Stack, __T, __Ts, __Tzr) -> yeccpars1(__Ts, __Tzr, 6, [11 | __Ss], [__T | __Stack]); yeccpars2(11, tag, __Ss, __Stack, __T, __Ts, __Tzr) -> yeccpars1(__Ts, __Tzr, 7, [11 | __Ss], [__T | __Stack]); yeccpars2(11, var, __Ss, __Stack, __T, __Ts, __Tzr) -> yeccpars1(__Ts, __Tzr, 8, [11 | __Ss], [__T | __Stack]); yeccpars2(11, _, _, _, __T, _, _) -> yeccerror(__T); yeccpars2(12, __Cat, __Ss, __Stack, __T, __Ts, __Tzr) -> __NewStack = yeccpars2_12_(__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', 9) -> 2; yeccgoto('Element', 11) -> 2; yeccgoto('Elements', 0) -> 1; yeccgoto('Elements', 3) -> 11; yeccgoto('Elements', 5) -> 9; 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", 54). yeccpars2_0_(__Stack) -> [begin nil end | __Stack]. -compile({inline,{yeccpars2_2_,1}}). -file("src/erlydtl/erlydtl_parser.yrl", 55). yeccpars2_2_([__2,__1 | __Stack]) -> [begin [ __1 , __2 ] end | __Stack]. -compile({inline,{yeccpars2_3_,1}}). -file("src/erlydtl/erlydtl_parser.yrl", 54). yeccpars2_3_(__Stack) -> [begin nil end | __Stack]. -compile({inline,{yeccpars2_4_,1}}). -file("src/erlydtl/erlydtl_parser.yrl", 59). yeccpars2_4_([__1 | __Stack]) -> [begin extends ( __1 ) end | __Stack]. -compile({inline,{yeccpars2_5_,1}}). -file("src/erlydtl/erlydtl_parser.yrl", 54). yeccpars2_5_(__Stack) -> [begin nil end | __Stack]. -compile({inline,{yeccpars2_6_,1}}). -file("src/erlydtl/erlydtl_parser.yrl", 57). yeccpars2_6_([__1 | __Stack]) -> [begin string ( __1 ) end | __Stack]. -compile({inline,{yeccpars2_7_,1}}). -file("src/erlydtl/erlydtl_parser.yrl", 61). yeccpars2_7_([__1 | __Stack]) -> [begin tag ( __1 ) end | __Stack]. -compile({inline,{yeccpars2_8_,1}}). -file("src/erlydtl/erlydtl_parser.yrl", 58). yeccpars2_8_([__1 | __Stack]) -> [begin var ( __1 ) end | __Stack]. -compile({inline,{yeccpars2_10_,1}}). -file("src/erlydtl/erlydtl_parser.yrl", 62). yeccpars2_10_([__3,__2,__1 | __Stack]) -> [begin for ( __1 , __2 ) end | __Stack]. -compile({inline,{yeccpars2_12_,1}}). -file("src/erlydtl/erlydtl_parser.yrl", 60). yeccpars2_12_([__3,__2,__1 | __Stack]) -> [begin block ( __1 , __2 ) end | __Stack]. -file("src/erlydtl/erlydtl_parser.yrl", 108).