diff options
author | 2025-05-28 22:04:52 +0100 | |
---|---|---|
committer | 2025-05-28 22:04:52 +0100 | |
commit | fd1d5ac093e54992bf86155f847a10b9557d5594 (patch) | |
tree | 570a76837d91a7f00123ea8e88c72e17ccb619a1 /src | |
parent | Add PSL GenServer (diff) |
Add leex and yecc files & Elixir interface for DMARC parse
Diffstat (limited to 'src')
-rw-r--r-- | src/dmarc_lexer.erl | 1013 | ||||
-rw-r--r-- | src/dmarc_lexer.xrl | 21 | ||||
-rw-r--r-- | src/dmarc_parser.erl | 514 | ||||
-rw-r--r-- | src/dmarc_parser.yrl | 47 |
4 files changed, 1595 insertions, 0 deletions
diff --git a/src/dmarc_lexer.erl b/src/dmarc_lexer.erl new file mode 100644 index 0000000..d60b417 --- /dev/null +++ b/src/dmarc_lexer.erl @@ -0,0 +1,1013 @@ +-file("/home/joe/.asdf/installs/erlang/27.2/lib/parsetools-2.6/include/leexinc.hrl", 0). +%% The source of this file is part of leex distribution, as such it +%% has the same Copyright as the other files in the leex +%% distribution. The Copyright is defined in the accompanying file +%% COPYRIGHT. However, the resultant scanner generated by leex is the +%% property of the creator of the scanner and is not covered by that +%% Copyright. + +-module(dmarc_lexer). + +-export([string/1,string/2,token/2,token/3,tokens/2,tokens/3]). +-export([format_error/1]). + +%% User code. This is placed here to allow extra attributes. +-file("src/dmarc_lexer.xrl", 21). + +-file("/home/joe/.asdf/installs/erlang/27.2/lib/parsetools-2.6/include/leexinc.hrl", 14). + +format_error({illegal,S}) -> ["illegal characters ",io_lib:write_string(S)]; +format_error({user,S}) -> S. + +%% string(InChars) -> +%% string(InChars, Loc) -> +%% {ok,Tokens,EndLoc} | {error,ErrorInfo,EndLoc}. +%% Loc is the starting location of the token, while EndLoc is the first not scanned +%% location. Location is either Line or {Line,Column}, depending on the "error_location" option. + +string(Ics) -> + string(Ics,1). +string(Ics,L0) -> + string(Ics, L0, 1, Ics, []). +string(Ics, L0, C0, Tcs, Ts) -> + case do_string(Ics, L0, C0, Tcs, Ts) of + {ok, T, {L,_}} -> {ok, T, L}; + {error, {{EL,_},M,D}, {L,_}} -> + EI = {EL,M,D}, + {error, EI, L} + end. + +do_string([], L, C, [], Ts) -> % No partial tokens! + {ok,yyrev(Ts),{L,C}}; +do_string(Ics0, L0, C0, Tcs, Ts) -> + case yystate(yystate(), Ics0, L0, C0, 0, reject, 0) of + {A,Alen,Ics1,L1,_C1} -> % Accepting end state + C2 = adjust_col(Tcs, Alen, C0), + string_cont(Ics1, L1, C2, yyaction(A, Alen, Tcs, L0, C0), Ts); + {A,Alen,Ics1,L1,_C1,_S1} -> % Accepting transition state + C2 = adjust_col(Tcs, Alen, C0), + string_cont(Ics1, L1, C2, yyaction(A, Alen, Tcs, L0, C0), Ts); + {reject,_Alen,Tlen,_Ics1,_L1,_C1,_S1} -> % After a non-accepting state + {error,{{L0, C0} ,?MODULE,{illegal,yypre(Tcs, Tlen+1)}},{L0, C0}}; + {A,Alen,Tlen,_Ics1,L1, C1,_S1}-> + Tcs1 = yysuf(Tcs, Alen), + L2 = adjust_line(Tlen, Alen, Tcs1, L1), + C2 = adjust_col(Tcs, Alen, C1), + string_cont(Tcs1, L2, C2, yyaction(A, Alen, Tcs, L0,C0), Ts) + end. + +%% string_cont(RestChars, Line, Col, Token, Tokens) +%% Test for and remove the end token wrapper. Push back characters +%% are prepended to RestChars. + +-dialyzer({nowarn_function, string_cont/5}). + +string_cont(Rest, Line, Col, {token,T}, Ts) -> + do_string(Rest, Line, Col, Rest, [T|Ts]); +string_cont(Rest, Line, Col, {token,T,Push}, Ts) -> + NewRest = Push ++ Rest, + do_string(NewRest, Line, Col, NewRest, [T|Ts]); +string_cont(Rest, Line, Col, {end_token,T}, Ts) -> + do_string(Rest, Line, Col, Rest, [T|Ts]); +string_cont(Rest, Line, Col, {end_token,T,Push}, Ts) -> + NewRest = Push ++ Rest, + do_string(NewRest, Line, Col, NewRest, [T|Ts]); +string_cont(Rest, Line, Col, skip_token, Ts) -> + do_string(Rest, Line, Col, Rest, Ts); +string_cont(Rest, Line, Col, {skip_token,Push}, Ts) -> + NewRest = Push ++ Rest, + do_string(NewRest, Line, Col, NewRest, Ts); +string_cont(_Rest, Line, Col, {error,S}, _Ts) -> + {error,{{Line, Col},?MODULE,{user,S}},{Line,Col}}. + +%% token(Continuation, Chars) -> +%% token(Continuation, Chars, Loc) -> +%% {more,Continuation} | {done,ReturnVal,RestChars}. +%% Must be careful when re-entering to append the latest characters to the +%% after characters in an accept. The continuation is: +%% {token,State,CurrLine,CurrCol,TokenChars,TokenLen,TokenLine,TokenCol,AccAction,AccLen} + +token(Cont,Chars) -> + token(Cont,Chars,1). +token(Cont, Chars, Line) -> + case do_token(Cont,Chars,Line,1) of + {more, _} = C -> C; + {done, Ret0, R} -> + Ret1 = case Ret0 of + {ok, T, {L,_}} -> {ok, T, L}; + {eof, {L,_}} -> {eof, L}; + {error, {{EL,_},M,D},{L,_}} -> {error, {EL,M,D},L} + end, + {done, Ret1, R} + end. + +do_token([], Chars, Line, Col) -> + token(yystate(), Chars, Line, Col, Chars, 0, Line, Col, reject, 0); +do_token({token,State,Line,Col,Tcs,Tlen,Tline,Tcol,Action,Alen}, Chars, _, _) -> + token(State, Chars, Line, Col, Tcs ++ Chars, Tlen, Tline, Tcol, Action, Alen). + +%% token(State, InChars, Line, Col, TokenChars, TokenLen, TokenLine, TokenCol +%% AcceptAction, AcceptLen) -> +%% {more,Continuation} | {done,ReturnVal,RestChars}. +%% The argument order is chosen to be more efficient. + +token(S0, Ics0, L0, C0, Tcs, Tlen0, Tline, Tcol, A0, Alen0) -> + case yystate(S0, Ics0, L0, C0, Tlen0, A0, Alen0) of + %% Accepting end state, we have a token. + {A1,Alen1,Ics1,L1,C1} -> + C2 = adjust_col(Tcs, Alen1, C1), + token_cont(Ics1, L1, C2, yyaction(A1, Alen1, Tcs, Tline,Tcol)); + %% Accepting transition state, can take more chars. + {A1,Alen1,[],L1,C1,S1} -> % Need more chars to check + {more,{token,S1,L1,C1,Tcs,Alen1,Tline,Tcol,A1,Alen1}}; + {A1,Alen1,Ics1,L1,C1,_S1} -> % Take what we got + C2 = adjust_col(Tcs, Alen1, C1), + token_cont(Ics1, L1, C2, yyaction(A1, Alen1, Tcs, Tline,Tcol)); + %% After a non-accepting state, maybe reach accept state later. + {A1,Alen1,Tlen1,[],L1,C1,S1} -> % Need more chars to check + {more,{token,S1,L1,C1,Tcs,Tlen1,Tline,Tcol,A1,Alen1}}; + {reject,_Alen1,Tlen1,eof,L1,C1,_S1} -> % No token match + %% Check for partial token which is error. + Ret = if Tlen1 > 0 -> {error,{{Tline,Tcol},?MODULE, + %% Skip eof tail in Tcs. + {illegal,yypre(Tcs, Tlen1)}},{L1,C1}}; + true -> {eof,{L1,C1}} + end, + {done,Ret,eof}; + {reject,_Alen1,Tlen1,Ics1,_L1,_C1,_S1} -> % No token match + Error = {{Tline,Tcol},?MODULE,{illegal,yypre(Tcs, Tlen1+1)}}, + {done,{error,Error,{Tline,Tcol}},Ics1}; + {A1,Alen1,Tlen1,_Ics1,L1,_C1,_S1} -> % Use last accept match + Tcs1 = yysuf(Tcs, Alen1), + L2 = adjust_line(Tlen1, Alen1, Tcs1, L1), + C2 = C0 + Alen1, + token_cont(Tcs1, L2, C2, yyaction(A1, Alen1, Tcs, Tline, Tcol)) + end. + +%% token_cont(RestChars, Line, Col, Token) +%% If we have a token or error then return done, else if we have a +%% skip_token then continue. + +-dialyzer({nowarn_function, token_cont/4}). + +token_cont(Rest, Line, Col, {token,T}) -> + {done,{ok,T,{Line,Col}},Rest}; +token_cont(Rest, Line, Col, {token,T,Push}) -> + NewRest = Push ++ Rest, + {done,{ok,T,{Line,Col}},NewRest}; +token_cont(Rest, Line, Col, {end_token,T}) -> + {done,{ok,T,{Line,Col}},Rest}; +token_cont(Rest, Line, Col, {end_token,T,Push}) -> + NewRest = Push ++ Rest, + {done,{ok,T,{Line,Col}},NewRest}; +token_cont(Rest, Line, Col, skip_token) -> + token(yystate(), Rest, Line, Col, Rest, 0, Line, Col, reject, 0); +token_cont(Rest, Line, Col, {skip_token,Push}) -> + NewRest = Push ++ Rest, + token(yystate(), NewRest, Line, Col, NewRest, 0, Line, Col, reject, 0); +token_cont(Rest, Line, Col, {error,S}) -> + {done,{error,{{Line, Col},?MODULE,{user,S}},{Line, Col}},Rest}. + +%% tokens(Continuation, Chars) -> +%% tokens(Continuation, Chars, Loc) -> +%% {more,Continuation} | {done,ReturnVal,RestChars}. +%% Must be careful when re-entering to append the latest characters to the +%% after characters in an accept. The continuation is: +%% {tokens,State,CurrLine,CurrCol,TokenChars,TokenLen,TokenLine,TokenCur,Tokens,AccAction,AccLen} +%% {skip_tokens,State,CurrLine,CurrCol,TokenChars,TokenLen,TokenLine,TokenCur,Error,AccAction,AccLen} + +tokens(Cont,Chars) -> + tokens(Cont,Chars,1). +tokens(Cont, Chars, Line) -> + case do_tokens(Cont,Chars,Line,1) of + {more, _} = C -> C; + {done, Ret0, R} -> + Ret1 = case Ret0 of + {ok, T, {L,_}} -> {ok, T, L}; + {eof, {L,_}} -> {eof, L}; + {error, {{EL,_},M,D},{L,_}} -> {error, {EL,M,D},L} + end, + {done, Ret1, R} + end. + +do_tokens([], Chars, Line, Col) -> + tokens(yystate(), Chars, Line, Col, Chars, 0, Line, Col, [], reject, 0); +do_tokens({tokens,State,Line,Col,Tcs,Tlen,Tline,Tcol,Ts,Action,Alen}, Chars, _,_) -> + tokens(State, Chars, Line, Col, Tcs ++ Chars, Tlen, Tline, Tcol, Ts, Action, Alen); +do_tokens({skip_tokens,State,Line, Col, Tcs,Tlen,Tline,Tcol,Error,Action,Alen}, Chars, _,_) -> + skip_tokens(State, Chars, Line, Col, Tcs ++ Chars, Tlen, Tline, Tcol, Error, Action, Alen). + +%% tokens(State, InChars, Line, Col, TokenChars, TokenLen, TokenLine, TokenCol,Tokens, +%% AcceptAction, AcceptLen) -> +%% {more,Continuation} | {done,ReturnVal,RestChars}. + +tokens(S0, Ics0, L0, C0, Tcs, Tlen0, Tline, Tcol, Ts, A0, Alen0) -> + case yystate(S0, Ics0, L0, C0, Tlen0, A0, Alen0) of + %% Accepting end state, we have a token. + {A1,Alen1,Ics1,L1,C1} -> + C2 = adjust_col(Tcs, Alen1, C1), + tokens_cont(Ics1, L1, C2, yyaction(A1, Alen1, Tcs, Tline, Tcol), Ts); + %% Accepting transition state, can take more chars. + {A1,Alen1,[],L1,C1,S1} -> % Need more chars to check + {more,{tokens,S1,L1,C1,Tcs,Alen1,Tline,Tcol,Ts,A1,Alen1}}; + {A1,Alen1,Ics1,L1,C1,_S1} -> % Take what we got + C2 = adjust_col(Tcs, Alen1, C1), + tokens_cont(Ics1, L1, C2, yyaction(A1, Alen1, Tcs, Tline,Tcol), Ts); + %% After a non-accepting state, maybe reach accept state later. + {A1,Alen1,Tlen1,[],L1,C1,S1} -> % Need more chars to check + {more,{tokens,S1,L1,C1,Tcs,Tlen1,Tline,Tcol,Ts,A1,Alen1}}; + {reject,_Alen1,Tlen1,eof,L1,C1,_S1} -> % No token match + %% Check for partial token which is error, no need to skip here. + Ret = if Tlen1 > 0 -> {error,{{Tline,Tcol},?MODULE, + %% Skip eof tail in Tcs. + {illegal,yypre(Tcs, Tlen1)}},{L1,C1}}; + Ts == [] -> {eof,{L1,C1}}; + true -> {ok,yyrev(Ts),{L1,C1}} + end, + {done,Ret,eof}; + {reject,_Alen1,Tlen1,_Ics1,L1,C1,_S1} -> + %% Skip rest of tokens. + Error = {{L1,C1},?MODULE,{illegal,yypre(Tcs, Tlen1+1)}}, + skip_tokens(yysuf(Tcs, Tlen1+1), L1, C1, Error); + {A1,Alen1,Tlen1,_Ics1,L1,_C1,_S1} -> + Token = yyaction(A1, Alen1, Tcs, Tline,Tcol), + Tcs1 = yysuf(Tcs, Alen1), + L2 = adjust_line(Tlen1, Alen1, Tcs1, L1), + C2 = C0 + Alen1, + tokens_cont(Tcs1, L2, C2, Token, Ts) + end. + +%% tokens_cont(RestChars, Line, Column, Token, Tokens) +%% If we have an end_token or error then return done, else if we have +%% a token then save it and continue, else if we have a skip_token +%% just continue. + +-dialyzer({nowarn_function, tokens_cont/5}). + +tokens_cont(Rest, Line, Col, {token,T}, Ts) -> + tokens(yystate(), Rest, Line, Col, Rest, 0, Line, Col, [T|Ts], reject, 0); +tokens_cont(Rest, Line, Col, {token,T,Push}, Ts) -> + NewRest = Push ++ Rest, + tokens(yystate(), NewRest, Line, Col, NewRest, 0, Line, Col, [T|Ts], reject, 0); +tokens_cont(Rest, Line, Col, {end_token,T}, Ts) -> + {done,{ok,yyrev(Ts, [T]),{Line,Col}},Rest}; +tokens_cont(Rest, Line, Col, {end_token,T,Push}, Ts) -> + NewRest = Push ++ Rest, + {done,{ok,yyrev(Ts, [T]),{Line, Col}},NewRest}; +tokens_cont(Rest, Line, Col, skip_token, Ts) -> + tokens(yystate(), Rest, Line, Col, Rest, 0, Line, Col, Ts, reject, 0); +tokens_cont(Rest, Line, Col, {skip_token,Push}, Ts) -> + NewRest = Push ++ Rest, + tokens(yystate(), NewRest, Line, Col, NewRest, 0, Line, Col, Ts, reject, 0); +tokens_cont(Rest, Line, Col, {error,S}, _Ts) -> + skip_tokens(Rest, Line, Col, {{Line,Col},?MODULE,{user,S}}). + +%% skip_tokens(InChars, Line, Col, Error) -> {done,{error,Error,{Line,Col}},Ics}. +%% Skip tokens until an end token, junk everything and return the error. + +skip_tokens(Ics, Line, Col, Error) -> + skip_tokens(yystate(), Ics, Line, Col, Ics, 0, Line, Col, Error, reject, 0). + +%% skip_tokens(State, InChars, Line, Col, TokenChars, TokenLen, TokenLine, TokenCol, Tokens, +%% AcceptAction, AcceptLen) -> +%% {more,Continuation} | {done,ReturnVal,RestChars}. + +skip_tokens(S0, Ics0, L0, C0, Tcs, Tlen0, Tline, Tcol, Error, A0, Alen0) -> + case yystate(S0, Ics0, L0, C0, Tlen0, A0, Alen0) of + {A1,Alen1,Ics1,L1, C1} -> % Accepting end state + skip_cont(Ics1, L1, C1, yyaction(A1, Alen1, Tcs, Tline, Tcol), Error); + {A1,Alen1,[],L1,C1, S1} -> % After an accepting state + {more,{skip_tokens,S1,L1,C1,Tcs,Alen1,Tline,Tcol,Error,A1,Alen1}}; + {A1,Alen1,Ics1,L1,C1,_S1} -> + skip_cont(Ics1, L1, C1, yyaction(A1, Alen1, Tcs, Tline, Tcol), Error); + {A1,Alen1,Tlen1,[],L1,C1,S1} -> % After a non-accepting state + {more,{skip_tokens,S1,L1,C1,Tcs,Tlen1,Tline,Tcol,Error,A1,Alen1}}; + {reject,_Alen1,_Tlen1,eof,L1,C1,_S1} -> + {done,{error,Error,{L1,C1}},eof}; + {reject,_Alen1,Tlen1,_Ics1,L1,C1,_S1} -> + skip_tokens(yysuf(Tcs, Tlen1+1), L1, C1,Error); + {A1,Alen1,Tlen1,_Ics1,L1,C1,_S1} -> + Token = yyaction(A1, Alen1, Tcs, Tline, Tcol), + Tcs1 = yysuf(Tcs, Alen1), + L2 = adjust_line(Tlen1, Alen1, Tcs1, L1), + skip_cont(Tcs1, L2, C1, Token, Error) + end. + +%% skip_cont(RestChars, Line, Col, Token, Error) +%% Skip tokens until we have an end_token or error then return done +%% with the original rror. + +-dialyzer({nowarn_function, skip_cont/5}). + +skip_cont(Rest, Line, Col, {token,_T}, Error) -> + skip_tokens(yystate(), Rest, Line, Col, Rest, 0, Line, Col, Error, reject, 0); +skip_cont(Rest, Line, Col, {token,_T,Push}, Error) -> + NewRest = Push ++ Rest, + skip_tokens(yystate(), NewRest, Line, Col, NewRest, 0, Line, Col, Error, reject, 0); +skip_cont(Rest, Line, Col, {end_token,_T}, Error) -> + {done,{error,Error,{Line,Col}},Rest}; +skip_cont(Rest, Line, Col, {end_token,_T,Push}, Error) -> + NewRest = Push ++ Rest, + {done,{error,Error,{Line,Col}},NewRest}; +skip_cont(Rest, Line, Col, skip_token, Error) -> + skip_tokens(yystate(), Rest, Line, Col, Rest, 0, Line, Col, Error, reject, 0); +skip_cont(Rest, Line, Col, {skip_token,Push}, Error) -> + NewRest = Push ++ Rest, + skip_tokens(yystate(), NewRest, Line, Col, NewRest, 0, Line, Col, Error, reject, 0); +skip_cont(Rest, Line, Col, {error,_S}, Error) -> + skip_tokens(yystate(), Rest, Line, Col, Rest, 0, Line, Col, Error, reject, 0). + +-compile({nowarn_unused_function, [yyrev/1, yyrev/2, yypre/2, yysuf/2]}). + +yyrev(List) -> lists:reverse(List). +yyrev(List, Tail) -> lists:reverse(List, Tail). +yypre(List, N) -> lists:sublist(List, N). +yysuf(List, N) -> lists:nthtail(N, List). + +%% adjust_line(TokenLength, AcceptLength, Chars, Line) -> NewLine +%% Make sure that newlines in Chars are not counted twice. +%% Line has been updated with respect to newlines in the prefix of +%% Chars consisting of (TokenLength - AcceptLength) characters. + +-compile({nowarn_unused_function, adjust_line/4}). + +adjust_line(N, N, _Cs, L) -> L; +adjust_line(T, A, [$\n|Cs], L) -> + adjust_line(T-1, A, Cs, L-1); +adjust_line(T, A, [_|Cs], L) -> + adjust_line(T-1, A, Cs, L). + +%% adjust_col(Chars, AcceptLength, Col) -> NewCol +%% Handle newlines, tabs and unicode chars. +adjust_col(_, 0, Col) -> + Col; +adjust_col([$\n | R], L, _) -> + adjust_col(R, L-1, 1); +adjust_col([$\t | R], L, Col) -> + adjust_col(R, L-1, tab_forward(Col)+1); +adjust_col([C | R], L, Col) when C>=0 andalso C=< 16#7F -> + adjust_col(R, L-1, Col+1); +adjust_col([C | R], L, Col) when C>= 16#80 andalso C=< 16#7FF -> + adjust_col(R, L-1, Col+2); +adjust_col([C | R], L, Col) when C>= 16#800 andalso C=< 16#FFFF -> + adjust_col(R, L-1, Col+3); +adjust_col([C | R], L, Col) when C>= 16#10000 andalso C=< 16#10FFFF -> + adjust_col(R, L-1, Col+4). + +tab_forward(C) -> + D = C rem tab_size(), + A = tab_size()-D, + C+A. + +tab_size() -> 8. + +%% yystate() -> InitialState. +%% yystate(State, InChars, Line, Col, CurrTokLen, AcceptAction, AcceptLen) -> +%% {Action, AcceptLen, RestChars, Line, Col} | +%% {Action, AcceptLen, RestChars, Line, Col, State} | +%% {reject, AcceptLen, CurrTokLen, RestChars, Line, Col, State} | +%% {Action, AcceptLen, CurrTokLen, RestChars, Line, Col, State}. +%% Generated state transition functions. The non-accepting end state +%% return signal either an unrecognised character or end of current +%% input. + +-file("src/dmarc_lexer.erl", 339). +yystate() -> 24. + +yystate(27, [11|Ics], Line, Col, Tlen, Action, Alen) -> + yystate(25, Ics, Line, Col, Tlen+1, Action, Alen); +yystate(27, [12|Ics], Line, Col, Tlen, Action, Alen) -> + yystate(25, Ics, Line, Col, Tlen+1, Action, Alen); +yystate(27, [C|Ics], Line, Col, Tlen, Action, Alen) when C >= 0, C =< 8 -> + yystate(25, Ics, Line, Col, Tlen+1, Action, Alen); +yystate(27, [C|Ics], Line, Col, Tlen, Action, Alen) when C >= 14, C =< 31 -> + yystate(25, Ics, Line, Col, Tlen+1, Action, Alen); +yystate(27, [C|Ics], Line, Col, Tlen, Action, Alen) when C >= 33, C =< 43 -> + yystate(25, Ics, Line, Col, Tlen+1, Action, Alen); +yystate(27, [C|Ics], Line, Col, Tlen, Action, Alen) when C >= 45, C =< 58 -> + yystate(25, Ics, Line, Col, Tlen+1, Action, Alen); +yystate(27, [C|Ics], Line, Col, Tlen, Action, Alen) when C >= 60 -> + yystate(25, Ics, Line, Col, Tlen+1, Action, Alen); +yystate(27, Ics, Line, Col, Tlen, Action, Alen) -> + {Action,Alen,Tlen,Ics,Line,Col,27}; +yystate(26, [60|Ics], Line, Col, Tlen, _, _) -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(26, [11|Ics], Line, Col, Tlen, _, _) -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(26, [12|Ics], Line, Col, Tlen, _, _) -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(26, [C|Ics], Line, Col, Tlen, _, _) when C >= 0, C =< 8 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(26, [C|Ics], Line, Col, Tlen, _, _) when C >= 14, C =< 31 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(26, [C|Ics], Line, Col, Tlen, _, _) when C >= 33, C =< 43 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(26, [C|Ics], Line, Col, Tlen, _, _) when C >= 45, C =< 57 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(26, [C|Ics], Line, Col, Tlen, _, _) when C >= 62 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(26, Ics, Line, Col, Tlen, _, _) -> + {7,Tlen,Ics,Line,Col,26}; +yystate(25, [11|Ics], Line, Col, Tlen, _, _) -> + yystate(25, Ics, Line, Col, Tlen+1, 1, Tlen); +yystate(25, [12|Ics], Line, Col, Tlen, _, _) -> + yystate(25, Ics, Line, Col, Tlen+1, 1, Tlen); +yystate(25, [C|Ics], Line, Col, Tlen, _, _) when C >= 0, C =< 8 -> + yystate(25, Ics, Line, Col, Tlen+1, 1, Tlen); +yystate(25, [C|Ics], Line, Col, Tlen, _, _) when C >= 14, C =< 31 -> + yystate(25, Ics, Line, Col, Tlen+1, 1, Tlen); +yystate(25, [C|Ics], Line, Col, Tlen, _, _) when C >= 33, C =< 43 -> + yystate(25, Ics, Line, Col, Tlen+1, 1, Tlen); +yystate(25, [C|Ics], Line, Col, Tlen, _, _) when C >= 45, C =< 58 -> + yystate(25, Ics, Line, Col, Tlen+1, 1, Tlen); +yystate(25, [C|Ics], Line, Col, Tlen, _, _) when C >= 60 -> + yystate(25, Ics, Line, Col, Tlen+1, 1, Tlen); +yystate(25, Ics, Line, Col, Tlen, _, _) -> + {1,Tlen,Ics,Line,Col,25}; +yystate(24, [118|Ics], Line, Col, Tlen, Action, Alen) -> + yystate(20, Ics, Line, Col, Tlen+1, Action, Alen); +yystate(24, [116|Ics], Line, Col, Tlen, Action, Alen) -> + yystate(26, Ics, Line, Col, Tlen+1, Action, Alen); +yystate(24, [117|Ics], Line, Col, Tlen, Action, Alen) -> + yystate(26, Ics, Line, Col, Tlen+1, Action, Alen); +yystate(24, [115|Ics], Line, Col, Tlen, Action, Alen) -> + yystate(16, Ics, Line, Col, Tlen+1, Action, Alen); +yystate(24, [114|Ics], Line, Col, Tlen, Action, Alen) -> + yystate(12, Ics, Line, Col, Tlen+1, Action, Alen); +yystate(24, [113|Ics], Line, Col, Tlen, Action, Alen) -> + yystate(26, Ics, Line, Col, Tlen+1, Action, Alen); +yystate(24, [112|Ics], Line, Col, Tlen, Action, Alen) -> + yystate(4, Ics, Line, Col, Tlen+1, Action, Alen); +yystate(24, [110|Ics], Line, Col, Tlen, Action, Alen) -> + yystate(26, Ics, Line, Col, Tlen+1, Action, Alen); +yystate(24, [111|Ics], Line, Col, Tlen, Action, Alen) -> + yystate(26, Ics, Line, Col, Tlen+1, Action, Alen); +yystate(24, [109|Ics], Line, Col, Tlen, Action, Alen) -> + yystate(3, Ics, Line, Col, Tlen+1, Action, Alen); +yystate(24, [102|Ics], Line, Col, Tlen, Action, Alen) -> + yystate(21, Ics, Line, Col, Tlen+1, Action, Alen); +yystate(24, [97|Ics], Line, Col, Tlen, Action, Alen) -> + yystate(17, Ics, Line, Col, Tlen+1, Action, Alen); +yystate(24, [61|Ics], Line, Col, Tlen, Action, Alen) -> + yystate(6, Ics, Line, Col, Tlen+1, Action, Alen); +yystate(24, [60|Ics], Line, Col, Tlen, Action, Alen) -> + yystate(26, Ics, Line, Col, Tlen+1, Action, Alen); +yystate(24, [59|Ics], Line, Col, Tlen, Action, Alen) -> + yystate(10, Ics, Line, Col, Tlen+1, Action, Alen); +yystate(24, [58|Ics], Line, Col, Tlen, Action, Alen) -> + yystate(14, Ics, Line, Col, Tlen+1, Action, Alen); +yystate(24, [44|Ics], Line, Col, Tlen, Action, Alen) -> + yystate(18, Ics, Line, Col, Tlen+1, Action, Alen); +yystate(24, [32|Ics], Line, Col, Tlen, Action, Alen) -> + yystate(22, Ics, Line, Col, Tlen+1, Action, Alen); +yystate(24, [13|Ics], Line, Col, Tlen, Action, Alen) -> + yystate(22, Ics, Line, Col, Tlen+1, Action, Alen); +yystate(24, [11|Ics], Line, Col, Tlen, Action, Alen) -> + yystate(26, Ics, Line, Col, Tlen+1, Action, Alen); +yystate(24, [12|Ics], Line, Col, Tlen, Action, Alen) -> + yystate(26, Ics, Line, Col, Tlen+1, Action, Alen); +yystate(24, [9|Ics], Line, Col, Tlen, Action, Alen) -> + yystate(22, Ics, Line, Col, Tlen+1, Action, Alen); +yystate(24, [10|Ics], Line, _, Tlen, Action, Alen) -> + yystate(22, Ics, Line+1, 1, Tlen+1, Action, Alen); +yystate(24, [C|Ics], Line, Col, Tlen, Action, Alen) when C >= 0, C =< 8 -> + yystate(26, Ics, Line, Col, Tlen+1, Action, Alen); +yystate(24, [C|Ics], Line, Col, Tlen, Action, Alen) when C >= 14, C =< 31 -> + yystate(26, Ics, Line, Col, Tlen+1, Action, Alen); +yystate(24, [C|Ics], Line, Col, Tlen, Action, Alen) when C >= 33, C =< 43 -> + yystate(26, Ics, Line, Col, Tlen+1, Action, Alen); +yystate(24, [C|Ics], Line, Col, Tlen, Action, Alen) when C >= 45, C =< 57 -> + yystate(26, Ics, Line, Col, Tlen+1, Action, Alen); +yystate(24, [C|Ics], Line, Col, Tlen, Action, Alen) when C >= 62, C =< 96 -> + yystate(26, Ics, Line, Col, Tlen+1, Action, Alen); +yystate(24, [C|Ics], Line, Col, Tlen, Action, Alen) when C >= 98, C =< 101 -> + yystate(26, Ics, Line, Col, Tlen+1, Action, Alen); +yystate(24, [C|Ics], Line, Col, Tlen, Action, Alen) when C >= 103, C =< 108 -> + yystate(26, Ics, Line, Col, Tlen+1, Action, Alen); +yystate(24, [C|Ics], Line, Col, Tlen, Action, Alen) when C >= 119 -> + yystate(26, Ics, Line, Col, Tlen+1, Action, Alen); +yystate(24, Ics, Line, Col, Tlen, Action, Alen) -> + {Action,Alen,Tlen,Ics,Line,Col,24}; +yystate(23, [60|Ics], Line, Col, Tlen, _, _) -> + yystate(26, Ics, Line, Col, Tlen+1, 6, Tlen); +yystate(23, [58|Ics], Line, Col, Tlen, _, _) -> + yystate(27, Ics, Line, Col, Tlen+1, 6, Tlen); +yystate(23, [11|Ics], Line, Col, Tlen, _, _) -> + yystate(26, Ics, Line, Col, Tlen+1, 6, Tlen); +yystate(23, [12|Ics], Line, Col, Tlen, _, _) -> + yystate(26, Ics, Line, Col, Tlen+1, 6, Tlen); +yystate(23, [C|Ics], Line, Col, Tlen, _, _) when C >= 0, C =< 8 -> + yystate(26, Ics, Line, Col, Tlen+1, 6, Tlen); +yystate(23, [C|Ics], Line, Col, Tlen, _, _) when C >= 14, C =< 31 -> + yystate(26, Ics, Line, Col, Tlen+1, 6, Tlen); +yystate(23, [C|Ics], Line, Col, Tlen, _, _) when C >= 33, C =< 43 -> + yystate(26, Ics, Line, Col, Tlen+1, 6, Tlen); +yystate(23, [C|Ics], Line, Col, Tlen, _, _) when C >= 45, C =< 57 -> + yystate(26, Ics, Line, Col, Tlen+1, 6, Tlen); +yystate(23, [C|Ics], Line, Col, Tlen, _, _) when C >= 62 -> + yystate(26, Ics, Line, Col, Tlen+1, 6, Tlen); +yystate(23, Ics, Line, Col, Tlen, _, _) -> + {6,Tlen,Ics,Line,Col,23}; +yystate(22, [32|Ics], Line, Col, Tlen, _, _) -> + yystate(22, Ics, Line, Col, Tlen+1, 8, Tlen); +yystate(22, [13|Ics], Line, Col, Tlen, _, _) -> + yystate(22, Ics, Line, Col, Tlen+1, 8, Tlen); +yystate(22, [9|Ics], Line, Col, Tlen, _, _) -> + yystate(22, Ics, Line, Col, Tlen+1, 8, Tlen); +yystate(22, [10|Ics], Line, _, Tlen, _, _) -> + yystate(22, Ics, Line+1, 1, Tlen+1, 8, Tlen); +yystate(22, Ics, Line, Col, Tlen, _, _) -> + {8,Tlen,Ics,Line,Col,22}; +yystate(21, [111|Ics], Line, Col, Tlen, _, _) -> + yystate(20, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(21, [60|Ics], Line, Col, Tlen, _, _) -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(21, [11|Ics], Line, Col, Tlen, _, _) -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(21, [12|Ics], Line, Col, Tlen, _, _) -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(21, [C|Ics], Line, Col, Tlen, _, _) when C >= 0, C =< 8 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(21, [C|Ics], Line, Col, Tlen, _, _) when C >= 14, C =< 31 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(21, [C|Ics], Line, Col, Tlen, _, _) when C >= 33, C =< 43 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(21, [C|Ics], Line, Col, Tlen, _, _) when C >= 45, C =< 57 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(21, [C|Ics], Line, Col, Tlen, _, _) when C >= 62, C =< 110 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(21, [C|Ics], Line, Col, Tlen, _, _) when C >= 112 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(21, Ics, Line, Col, Tlen, _, _) -> + {7,Tlen,Ics,Line,Col,21}; +yystate(20, [60|Ics], Line, Col, Tlen, _, _) -> + yystate(26, Ics, Line, Col, Tlen+1, 0, Tlen); +yystate(20, [11|Ics], Line, Col, Tlen, _, _) -> + yystate(26, Ics, Line, Col, Tlen+1, 0, Tlen); +yystate(20, [12|Ics], Line, Col, Tlen, _, _) -> + yystate(26, Ics, Line, Col, Tlen+1, 0, Tlen); +yystate(20, [C|Ics], Line, Col, Tlen, _, _) when C >= 0, C =< 8 -> + yystate(26, Ics, Line, Col, Tlen+1, 0, Tlen); +yystate(20, [C|Ics], Line, Col, Tlen, _, _) when C >= 14, C =< 31 -> + yystate(26, Ics, Line, Col, Tlen+1, 0, Tlen); +yystate(20, [C|Ics], Line, Col, Tlen, _, _) when C >= 33, C =< 43 -> + yystate(26, Ics, Line, Col, Tlen+1, 0, Tlen); +yystate(20, [C|Ics], Line, Col, Tlen, _, _) when C >= 45, C =< 57 -> + yystate(26, Ics, Line, Col, Tlen+1, 0, Tlen); +yystate(20, [C|Ics], Line, Col, Tlen, _, _) when C >= 62 -> + yystate(26, Ics, Line, Col, Tlen+1, 0, Tlen); +yystate(20, Ics, Line, Col, Tlen, _, _) -> + {0,Tlen,Ics,Line,Col,20}; +yystate(19, [111|Ics], Line, Col, Tlen, _, _) -> + yystate(23, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(19, [60|Ics], Line, Col, Tlen, _, _) -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(19, [11|Ics], Line, Col, Tlen, _, _) -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(19, [12|Ics], Line, Col, Tlen, _, _) -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(19, [C|Ics], Line, Col, Tlen, _, _) when C >= 0, C =< 8 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(19, [C|Ics], Line, Col, Tlen, _, _) when C >= 14, C =< 31 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(19, [C|Ics], Line, Col, Tlen, _, _) when C >= 33, C =< 43 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(19, [C|Ics], Line, Col, Tlen, _, _) when C >= 45, C =< 57 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(19, [C|Ics], Line, Col, Tlen, _, _) when C >= 62, C =< 110 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(19, [C|Ics], Line, Col, Tlen, _, _) when C >= 112 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(19, Ics, Line, Col, Tlen, _, _) -> + {7,Tlen,Ics,Line,Col,19}; +yystate(18, Ics, Line, Col, Tlen, _, _) -> + {5,Tlen,Ics,Line,Col}; +yystate(17, [115|Ics], Line, Col, Tlen, _, _) -> + yystate(13, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(17, [100|Ics], Line, Col, Tlen, _, _) -> + yystate(5, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(17, [60|Ics], Line, Col, Tlen, _, _) -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(17, [11|Ics], Line, Col, Tlen, _, _) -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(17, [12|Ics], Line, Col, Tlen, _, _) -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(17, [C|Ics], Line, Col, Tlen, _, _) when C >= 0, C =< 8 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(17, [C|Ics], Line, Col, Tlen, _, _) when C >= 14, C =< 31 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(17, [C|Ics], Line, Col, Tlen, _, _) when C >= 33, C =< 43 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(17, [C|Ics], Line, Col, Tlen, _, _) when C >= 45, C =< 57 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(17, [C|Ics], Line, Col, Tlen, _, _) when C >= 62, C =< 99 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(17, [C|Ics], Line, Col, Tlen, _, _) when C >= 101, C =< 114 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(17, [C|Ics], Line, Col, Tlen, _, _) when C >= 116 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(17, Ics, Line, Col, Tlen, _, _) -> + {7,Tlen,Ics,Line,Col,17}; +yystate(16, [112|Ics], Line, Col, Tlen, _, _) -> + yystate(20, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(16, [60|Ics], Line, Col, Tlen, _, _) -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(16, [11|Ics], Line, Col, Tlen, _, _) -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(16, [12|Ics], Line, Col, Tlen, _, _) -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(16, [C|Ics], Line, Col, Tlen, _, _) when C >= 0, C =< 8 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(16, [C|Ics], Line, Col, Tlen, _, _) when C >= 14, C =< 31 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(16, [C|Ics], Line, Col, Tlen, _, _) when C >= 33, C =< 43 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(16, [C|Ics], Line, Col, Tlen, _, _) when C >= 45, C =< 57 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(16, [C|Ics], Line, Col, Tlen, _, _) when C >= 62, C =< 111 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(16, [C|Ics], Line, Col, Tlen, _, _) when C >= 113 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(16, Ics, Line, Col, Tlen, _, _) -> + {7,Tlen,Ics,Line,Col,16}; +yystate(15, [116|Ics], Line, Col, Tlen, _, _) -> + yystate(19, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(15, [60|Ics], Line, Col, Tlen, _, _) -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(15, [11|Ics], Line, Col, Tlen, _, _) -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(15, [12|Ics], Line, Col, Tlen, _, _) -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(15, [C|Ics], Line, Col, Tlen, _, _) when C >= 0, C =< 8 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(15, [C|Ics], Line, Col, Tlen, _, _) when C >= 14, C =< 31 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(15, [C|Ics], Line, Col, Tlen, _, _) when C >= 33, C =< 43 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(15, [C|Ics], Line, Col, Tlen, _, _) when C >= 45, C =< 57 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(15, [C|Ics], Line, Col, Tlen, _, _) when C >= 62, C =< 115 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(15, [C|Ics], Line, Col, Tlen, _, _) when C >= 117 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(15, Ics, Line, Col, Tlen, _, _) -> + {7,Tlen,Ics,Line,Col,15}; +yystate(14, Ics, Line, Col, Tlen, _, _) -> + {3,Tlen,Ics,Line,Col}; +yystate(13, [112|Ics], Line, Col, Tlen, _, _) -> + yystate(9, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(13, [60|Ics], Line, Col, Tlen, _, _) -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(13, [11|Ics], Line, Col, Tlen, _, _) -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(13, [12|Ics], Line, Col, Tlen, _, _) -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(13, [C|Ics], Line, Col, Tlen, _, _) when C >= 0, C =< 8 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(13, [C|Ics], Line, Col, Tlen, _, _) when C >= 14, C =< 31 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(13, [C|Ics], Line, Col, Tlen, _, _) when C >= 33, C =< 43 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(13, [C|Ics], Line, Col, Tlen, _, _) when C >= 45, C =< 57 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(13, [C|Ics], Line, Col, Tlen, _, _) when C >= 62, C =< 111 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(13, [C|Ics], Line, Col, Tlen, _, _) when C >= 113 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(13, Ics, Line, Col, Tlen, _, _) -> + {7,Tlen,Ics,Line,Col,13}; +yystate(12, [117|Ics], Line, Col, Tlen, _, _) -> + yystate(8, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(12, [105|Ics], Line, Col, Tlen, _, _) -> + yystate(20, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(12, [103|Ics], Line, Col, Tlen, _, _) -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(12, [104|Ics], Line, Col, Tlen, _, _) -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(12, [102|Ics], Line, Col, Tlen, _, _) -> + yystate(20, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(12, [60|Ics], Line, Col, Tlen, _, _) -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(12, [11|Ics], Line, Col, Tlen, _, _) -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(12, [12|Ics], Line, Col, Tlen, _, _) -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(12, [C|Ics], Line, Col, Tlen, _, _) when C >= 0, C =< 8 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(12, [C|Ics], Line, Col, Tlen, _, _) when C >= 14, C =< 31 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(12, [C|Ics], Line, Col, Tlen, _, _) when C >= 33, C =< 43 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(12, [C|Ics], Line, Col, Tlen, _, _) when C >= 45, C =< 57 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(12, [C|Ics], Line, Col, Tlen, _, _) when C >= 62, C =< 101 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(12, [C|Ics], Line, Col, Tlen, _, _) when C >= 106, C =< 116 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(12, [C|Ics], Line, Col, Tlen, _, _) when C >= 118 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(12, Ics, Line, Col, Tlen, _, _) -> + {7,Tlen,Ics,Line,Col,12}; +yystate(11, [108|Ics], Line, Col, Tlen, _, _) -> + yystate(15, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(11, [60|Ics], Line, Col, Tlen, _, _) -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(11, [11|Ics], Line, Col, Tlen, _, _) -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(11, [12|Ics], Line, Col, Tlen, _, _) -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(11, [C|Ics], Line, Col, Tlen, _, _) when C >= 0, C =< 8 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(11, [C|Ics], Line, Col, Tlen, _, _) when C >= 14, C =< 31 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(11, [C|Ics], Line, Col, Tlen, _, _) when C >= 33, C =< 43 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(11, [C|Ics], Line, Col, Tlen, _, _) when C >= 45, C =< 57 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(11, [C|Ics], Line, Col, Tlen, _, _) when C >= 62, C =< 107 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(11, [C|Ics], Line, Col, Tlen, _, _) when C >= 109 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(11, Ics, Line, Col, Tlen, _, _) -> + {7,Tlen,Ics,Line,Col,11}; +yystate(10, Ics, Line, Col, Tlen, _, _) -> + {4,Tlen,Ics,Line,Col}; +yystate(9, [102|Ics], Line, Col, Tlen, _, _) -> + yystate(20, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(9, [60|Ics], Line, Col, Tlen, _, _) -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(9, [11|Ics], Line, Col, Tlen, _, _) -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(9, [12|Ics], Line, Col, Tlen, _, _) -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(9, [C|Ics], Line, Col, Tlen, _, _) when C >= 0, C =< 8 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(9, [C|Ics], Line, Col, Tlen, _, _) when C >= 14, C =< 31 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(9, [C|Ics], Line, Col, Tlen, _, _) when C >= 33, C =< 43 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(9, [C|Ics], Line, Col, Tlen, _, _) when C >= 45, C =< 57 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(9, [C|Ics], Line, Col, Tlen, _, _) when C >= 62, C =< 101 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(9, [C|Ics], Line, Col, Tlen, _, _) when C >= 103 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(9, Ics, Line, Col, Tlen, _, _) -> + {7,Tlen,Ics,Line,Col,9}; +yystate(8, [102|Ics], Line, Col, Tlen, _, _) -> + yystate(20, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(8, [97|Ics], Line, Col, Tlen, _, _) -> + yystate(20, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(8, [60|Ics], Line, Col, Tlen, _, _) -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(8, [11|Ics], Line, Col, Tlen, _, _) -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(8, [12|Ics], Line, Col, Tlen, _, _) -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(8, [C|Ics], Line, Col, Tlen, _, _) when C >= 0, C =< 8 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(8, [C|Ics], Line, Col, Tlen, _, _) when C >= 14, C =< 31 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(8, [C|Ics], Line, Col, Tlen, _, _) when C >= 33, C =< 43 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(8, [C|Ics], Line, Col, Tlen, _, _) when C >= 45, C =< 57 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(8, [C|Ics], Line, Col, Tlen, _, _) when C >= 62, C =< 96 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(8, [C|Ics], Line, Col, Tlen, _, _) when C >= 98, C =< 101 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(8, [C|Ics], Line, Col, Tlen, _, _) when C >= 103 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(8, Ics, Line, Col, Tlen, _, _) -> + {7,Tlen,Ics,Line,Col,8}; +yystate(7, [105|Ics], Line, Col, Tlen, _, _) -> + yystate(11, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(7, [60|Ics], Line, Col, Tlen, _, _) -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(7, [11|Ics], Line, Col, Tlen, _, _) -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(7, [12|Ics], Line, Col, Tlen, _, _) -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(7, [C|Ics], Line, Col, Tlen, _, _) when C >= 0, C =< 8 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(7, [C|Ics], Line, Col, Tlen, _, _) when C >= 14, C =< 31 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(7, [C|Ics], Line, Col, Tlen, _, _) when C >= 33, C =< 43 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(7, [C|Ics], Line, Col, Tlen, _, _) when C >= 45, C =< 57 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(7, [C|Ics], Line, Col, Tlen, _, _) when C >= 62, C =< 104 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(7, [C|Ics], Line, Col, Tlen, _, _) when C >= 106 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(7, Ics, Line, Col, Tlen, _, _) -> + {7,Tlen,Ics,Line,Col,7}; +yystate(6, Ics, Line, Col, Tlen, _, _) -> + {2,Tlen,Ics,Line,Col}; +yystate(5, [107|Ics], Line, Col, Tlen, _, _) -> + yystate(1, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(5, [60|Ics], Line, Col, Tlen, _, _) -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(5, [11|Ics], Line, Col, Tlen, _, _) -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(5, [12|Ics], Line, Col, Tlen, _, _) -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(5, [C|Ics], Line, Col, Tlen, _, _) when C >= 0, C =< 8 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(5, [C|Ics], Line, Col, Tlen, _, _) when C >= 14, C =< 31 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(5, [C|Ics], Line, Col, Tlen, _, _) when C >= 33, C =< 43 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(5, [C|Ics], Line, Col, Tlen, _, _) when C >= 45, C =< 57 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(5, [C|Ics], Line, Col, Tlen, _, _) when C >= 62, C =< 106 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(5, [C|Ics], Line, Col, Tlen, _, _) when C >= 108 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(5, Ics, Line, Col, Tlen, _, _) -> + {7,Tlen,Ics,Line,Col,5}; +yystate(4, [99|Ics], Line, Col, Tlen, _, _) -> + yystate(0, Ics, Line, Col, Tlen+1, 0, Tlen); +yystate(4, [60|Ics], Line, Col, Tlen, _, _) -> + yystate(26, Ics, Line, Col, Tlen+1, 0, Tlen); +yystate(4, [11|Ics], Line, Col, Tlen, _, _) -> + yystate(26, Ics, Line, Col, Tlen+1, 0, Tlen); +yystate(4, [12|Ics], Line, Col, Tlen, _, _) -> + yystate(26, Ics, Line, Col, Tlen+1, 0, Tlen); +yystate(4, [C|Ics], Line, Col, Tlen, _, _) when C >= 0, C =< 8 -> + yystate(26, Ics, Line, Col, Tlen+1, 0, Tlen); +yystate(4, [C|Ics], Line, Col, Tlen, _, _) when C >= 14, C =< 31 -> + yystate(26, Ics, Line, Col, Tlen+1, 0, Tlen); +yystate(4, [C|Ics], Line, Col, Tlen, _, _) when C >= 33, C =< 43 -> + yystate(26, Ics, Line, Col, Tlen+1, 0, Tlen); +yystate(4, [C|Ics], Line, Col, Tlen, _, _) when C >= 45, C =< 57 -> + yystate(26, Ics, Line, Col, Tlen+1, 0, Tlen); +yystate(4, [C|Ics], Line, Col, Tlen, _, _) when C >= 62, C =< 98 -> + yystate(26, Ics, Line, Col, Tlen+1, 0, Tlen); +yystate(4, [C|Ics], Line, Col, Tlen, _, _) when C >= 100 -> + yystate(26, Ics, Line, Col, Tlen+1, 0, Tlen); +yystate(4, Ics, Line, Col, Tlen, _, _) -> + {0,Tlen,Ics,Line,Col,4}; +yystate(3, [97|Ics], Line, Col, Tlen, _, _) -> + yystate(7, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(3, [60|Ics], Line, Col, Tlen, _, _) -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(3, [11|Ics], Line, Col, Tlen, _, _) -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(3, [12|Ics], Line, Col, Tlen, _, _) -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(3, [C|Ics], Line, Col, Tlen, _, _) when C >= 0, C =< 8 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(3, [C|Ics], Line, Col, Tlen, _, _) when C >= 14, C =< 31 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(3, [C|Ics], Line, Col, Tlen, _, _) when C >= 33, C =< 43 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(3, [C|Ics], Line, Col, Tlen, _, _) when C >= 45, C =< 57 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(3, [C|Ics], Line, Col, Tlen, _, _) when C >= 62, C =< 96 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(3, [C|Ics], Line, Col, Tlen, _, _) when C >= 98 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(3, Ics, Line, Col, Tlen, _, _) -> + {7,Tlen,Ics,Line,Col,3}; +yystate(2, [109|Ics], Line, Col, Tlen, _, _) -> + yystate(20, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(2, [60|Ics], Line, Col, Tlen, _, _) -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(2, [11|Ics], Line, Col, Tlen, _, _) -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(2, [12|Ics], Line, Col, Tlen, _, _) -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(2, [C|Ics], Line, Col, Tlen, _, _) when C >= 0, C =< 8 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(2, [C|Ics], Line, Col, Tlen, _, _) when C >= 14, C =< 31 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(2, [C|Ics], Line, Col, Tlen, _, _) when C >= 33, C =< 43 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(2, [C|Ics], Line, Col, Tlen, _, _) when C >= 45, C =< 57 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(2, [C|Ics], Line, Col, Tlen, _, _) when C >= 62, C =< 108 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(2, [C|Ics], Line, Col, Tlen, _, _) when C >= 110 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(2, Ics, Line, Col, Tlen, _, _) -> + {7,Tlen,Ics,Line,Col,2}; +yystate(1, [105|Ics], Line, Col, Tlen, _, _) -> + yystate(2, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(1, [60|Ics], Line, Col, Tlen, _, _) -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(1, [11|Ics], Line, Col, Tlen, _, _) -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(1, [12|Ics], Line, Col, Tlen, _, _) -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(1, [C|Ics], Line, Col, Tlen, _, _) when C >= 0, C =< 8 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(1, [C|Ics], Line, Col, Tlen, _, _) when C >= 14, C =< 31 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(1, [C|Ics], Line, Col, Tlen, _, _) when C >= 33, C =< 43 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(1, [C|Ics], Line, Col, Tlen, _, _) when C >= 45, C =< 57 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(1, [C|Ics], Line, Col, Tlen, _, _) when C >= 62, C =< 104 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(1, [C|Ics], Line, Col, Tlen, _, _) when C >= 106 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(1, Ics, Line, Col, Tlen, _, _) -> + {7,Tlen,Ics,Line,Col,1}; +yystate(0, [116|Ics], Line, Col, Tlen, _, _) -> + yystate(20, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(0, [60|Ics], Line, Col, Tlen, _, _) -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(0, [11|Ics], Line, Col, Tlen, _, _) -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(0, [12|Ics], Line, Col, Tlen, _, _) -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(0, [C|Ics], Line, Col, Tlen, _, _) when C >= 0, C =< 8 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(0, [C|Ics], Line, Col, Tlen, _, _) when C >= 14, C =< 31 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(0, [C|Ics], Line, Col, Tlen, _, _) when C >= 33, C =< 43 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(0, [C|Ics], Line, Col, Tlen, _, _) when C >= 45, C =< 57 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(0, [C|Ics], Line, Col, Tlen, _, _) when C >= 62, C =< 115 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(0, [C|Ics], Line, Col, Tlen, _, _) when C >= 117 -> + yystate(26, Ics, Line, Col, Tlen+1, 7, Tlen); +yystate(0, Ics, Line, Col, Tlen, _, _) -> + {7,Tlen,Ics,Line,Col,0}; +yystate(S, Ics, Line, Col, Tlen, Action, Alen) -> + {Action,Alen,Tlen,Ics,Line,Col,S}. + +%% yyaction(Action, TokenLength, TokenChars, TokenLine, TokenCol) -> +%% {token,Token} | {end_token, Token} | skip_token | {error,String}. +%% Generated action function. + +yyaction(0, TokenLen, YYtcs, TokenLine, _) -> + TokenChars = yypre(YYtcs, TokenLen), + yyaction_0(TokenChars, TokenLine); +yyaction(1, TokenLen, YYtcs, TokenLine, _) -> + TokenChars = yypre(YYtcs, TokenLen), + yyaction_1(TokenChars, TokenLine); +yyaction(2, _, _, TokenLine, _) -> + yyaction_2(TokenLine); +yyaction(3, _, _, TokenLine, _) -> + yyaction_3(TokenLine); +yyaction(4, _, _, TokenLine, _) -> + yyaction_4(TokenLine); +yyaction(5, _, _, TokenLine, _) -> + yyaction_5(TokenLine); +yyaction(6, _, _, _, _) -> + yyaction_6(); +yyaction(7, TokenLen, YYtcs, TokenLine, _) -> + TokenChars = yypre(YYtcs, TokenLen), + yyaction_7(TokenChars, TokenLine); +yyaction(8, _, _, _, _) -> + yyaction_8(); +yyaction(_, _, _, _, _) -> error. + +-compile({inline,yyaction_0/2}). +-file("src/dmarc_lexer.xrl", 9). +yyaction_0(TokenChars, TokenLine) -> + { token, { key, TokenLine, list_to_atom (TokenChars) } } . + +-compile({inline,yyaction_1/2}). +-file("src/dmarc_lexer.xrl", 10). +yyaction_1(TokenChars, TokenLine) -> + { token, { mailto, TokenLine, TokenChars } } . + +-compile({inline,yyaction_2/1}). +-file("src/dmarc_lexer.xrl", 11). +yyaction_2(TokenLine) -> + { token, { equals, TokenLine } } . + +-compile({inline,yyaction_3/1}). +-file("src/dmarc_lexer.xrl", 12). +yyaction_3(TokenLine) -> + { token, { colon, TokenLine } } . + +-compile({inline,yyaction_4/1}). +-file("src/dmarc_lexer.xrl", 13). +yyaction_4(TokenLine) -> + { token, { semicolon, TokenLine } } . + +-compile({inline,yyaction_5/1}). +-file("src/dmarc_lexer.xrl", 14). +yyaction_5(TokenLine) -> + { token, { comma, TokenLine } } . + +-compile({inline,yyaction_6/0}). +-file("src/dmarc_lexer.xrl", 15). +yyaction_6() -> + { error, invalid_mailto } . + +-compile({inline,yyaction_7/2}). +-file("src/dmarc_lexer.xrl", 16). +yyaction_7(TokenChars, TokenLine) -> + { token, { string, TokenLine, TokenChars } } . + +-compile({inline,yyaction_8/0}). +-file("src/dmarc_lexer.xrl", 17). +yyaction_8() -> + skip_token . +-file("/home/joe/.asdf/installs/erlang/27.2/lib/parsetools-2.6/include/leexinc.hrl", 344). diff --git a/src/dmarc_lexer.xrl b/src/dmarc_lexer.xrl new file mode 100644 index 0000000..29bc778 --- /dev/null +++ b/src/dmarc_lexer.xrl @@ -0,0 +1,21 @@ +Definitions. + +WHITESPACE = [\s\t\n\r] +KEY = (adkim|aspf|fo|pct|p|sp|rua|ruf|v|ri|rf) +VALUE = [^=;:,\s\t\n\r]+ +MAILTO_EMAIL = (mailto:[^\s\t\n\r,;]+) +LOST_MAILTO = mailto + +Rules. + +{KEY} : {token, {key, TokenLine, list_to_atom(TokenChars)}}. +{MAILTO_EMAIL} : {token, {mailto, TokenLine, TokenChars}}. += : {token, {equals, TokenLine}}. +: : {token, {colon, TokenLine}}. +; : {token, {semicolon, TokenLine}}. +, : {token, {comma, TokenLine}}. +{LOST_MAILTO} : {error, invalid_mailto}. +{VALUE} : {token, {string, TokenLine, TokenChars}}. +{WHITESPACE}+ : skip_token. + +Erlang code. diff --git a/src/dmarc_parser.erl b/src/dmarc_parser.erl new file mode 100644 index 0000000..00f5157 --- /dev/null +++ b/src/dmarc_parser.erl @@ -0,0 +1,514 @@ +-file("src/dmarc_parser.yrl", 0). +-module(dmarc_parser). +-file("src/dmarc_parser.erl", 3). +-export([parse/1, parse_and_scan/1, format_error/1]). +-file("src/dmarc_parser.yrl", 28). + +value({_, _, Value}) -> Value. + +value_to_list(Value) when is_tuple(Value) -> + [Value]; +value_to_list(Values) when is_list(Values) -> + Values. + +join_values(First, Rest) when is_tuple(Rest) -> + [First, Rest]; +join_values(First, RestList) when is_list(RestList) -> + [First | RestList]. + +process_value(Key, Values) when Key =:= rua; Key =:= ruf; Key =:= fo; Key =:= rf -> + lists:map(fun value/1, Values); +process_value(_Key, [Value]) -> + value(Value); +process_value(_Key, Values) -> + [value(V) || V <- Values]. + +-file("/home/joe/.asdf/installs/erlang/27.2/lib/parsetools-2.6/include/yeccpre.hrl", 0). +%% +%% %CopyrightBegin% +%% +%% Copyright Ericsson AB 1996-2024. All Rights Reserved. +%% +%% Licensed under the Apache License, Version 2.0 (the "License"); +%% you may not use this file except in compliance with the License. +%% You may obtain a copy of the License at +%% +%% http://www.apache.org/licenses/LICENSE-2.0 +%% +%% Unless required by applicable law or agreed to in writing, software +%% distributed under the License is distributed on an "AS IS" BASIS, +%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +%% See the License for the specific language governing permissions and +%% limitations under the License. +%% +%% %CopyrightEnd% +%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% The parser generator will insert appropriate declarations before this line.% + +-type yecc_ret() :: {'error', _} | {'ok', _}. + +-ifdef (YECC_PARSE_DOC). +-doc ?YECC_PARSE_DOC. +-endif. +-spec parse(Tokens :: list()) -> yecc_ret(). +parse(Tokens) -> + yeccpars0(Tokens, {no_func, no_location}, 0, [], []). + +-ifdef (YECC_PARSE_AND_SCAN_DOC). +-doc ?YECC_PARSE_AND_SCAN_DOC. +-endif. +-spec parse_and_scan({function() | {atom(), atom()}, [_]} + | {atom(), atom(), [_]}) -> yecc_ret(). +parse_and_scan({F, A}) -> + yeccpars0([], {{F, A}, no_location}, 0, [], []); +parse_and_scan({M, F, A}) -> + Arity = length(A), + yeccpars0([], {{fun M:F/Arity, A}, no_location}, 0, [], []). + +-ifdef (YECC_FORMAT_ERROR_DOC). +-doc ?YECC_FORMAT_ERROR_DOC. +-endif. +-spec format_error(any()) -> [char() | list()]. +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}). +-spec return_error(erl_anno:location(), any()) -> no_return(). +return_error(Location, Message) -> + throw({error, {Location, ?MODULE, Message}}). + +-define(CODE_VERSION, "1.4"). + +yeccpars0(Tokens, Tzr, State, States, Vstack) -> + try yeccpars1(Tokens, Tzr, State, States, Vstack) + catch + error: Error: Stacktrace -> + try yecc_error_type(Error, Stacktrace) of + Desc -> + erlang:raise(error, {yecc_bug, ?CODE_VERSION, Desc}, + Stacktrace) + catch _:_ -> erlang:raise(error, Error, Stacktrace) + end; + %% Probably thrown from return_error/2: + throw: {error, {_Location, ?MODULE, _M}} = Error -> + Error + end. + +yecc_error_type(function_clause, [{?MODULE,F,ArityOrArgs,_} | _]) -> + case atom_to_list(F) of + "yeccgoto_" ++ SymbolL -> + {ok,[{atom,_,Symbol}],_} = erl_scan:string(SymbolL), + State = case ArityOrArgs of + [S,_,_,_,_,_,_] -> S; + _ -> state_is_unknown + end, + {Symbol, State, missing_in_goto_table} + end. + +yeccpars1([Token | Tokens], Tzr, State, States, Vstack) -> + yeccpars2(State, element(1, Token), States, Vstack, Token, Tokens, Tzr); +yeccpars1([], {{F, A},_Location}, State, States, Vstack) -> + case apply(F, A) of + {ok, Tokens, EndLocation} -> + yeccpars1(Tokens, {{F, A}, EndLocation}, State, States, Vstack); + {eof, EndLocation} -> + yeccpars1([], {no_func, EndLocation}, State, States, Vstack); + {error, Descriptor, _EndLocation} -> + {error, Descriptor} + end; +yeccpars1([], {no_func, no_location}, State, States, Vstack) -> + Line = 999999, + yeccpars2(State, '$end', States, Vstack, yecc_end(Line), [], + {no_func, Line}); +yeccpars1([], {no_func, EndLocation}, State, States, Vstack) -> + yeccpars2(State, '$end', States, Vstack, yecc_end(EndLocation), [], + {no_func, EndLocation}). + +%% yeccpars1/7 is called from generated code. +%% +%% When using the {includefile, Includefile} option, make sure that +%% yeccpars1/7 can be found by parsing the file without following +%% include directives. yecc will otherwise assume that an old +%% yeccpre.hrl is included (one which defines yeccpars1/5). +yeccpars1(State1, State, States, Vstack, Token0, [Token | Tokens], Tzr) -> + yeccpars2(State, element(1, Token), [State1 | States], + [Token0 | Vstack], Token, Tokens, Tzr); +yeccpars1(State1, State, States, Vstack, Token0, [], {{_F,_A}, _Location}=Tzr) -> + yeccpars1([], Tzr, State, [State1 | States], [Token0 | Vstack]); +yeccpars1(State1, State, States, Vstack, Token0, [], {no_func, no_location}) -> + Location = yecctoken_end_location(Token0), + yeccpars2(State, '$end', [State1 | States], [Token0 | Vstack], + yecc_end(Location), [], {no_func, Location}); +yeccpars1(State1, State, States, Vstack, Token0, [], {no_func, Location}) -> + yeccpars2(State, '$end', [State1 | States], [Token0 | Vstack], + yecc_end(Location), [], {no_func, Location}). + +%% For internal use only. +yecc_end(Location) -> + {'$end', Location}. + +yecctoken_end_location(Token) -> + try erl_anno:end_location(element(2, Token)) of + undefined -> yecctoken_location(Token); + Loc -> Loc + catch _:_ -> yecctoken_location(Token) + end. + +-compile({nowarn_unused_function, yeccerror/1}). +yeccerror(Token) -> + Text = yecctoken_to_string(Token), + Location = yecctoken_location(Token), + {error, {Location, ?MODULE, ["syntax error before: ", Text]}}. + +-compile({nowarn_unused_function, yecctoken_to_string/1}). +yecctoken_to_string(Token) -> + try erl_scan:text(Token) of + undefined -> yecctoken2string(Token); + Txt -> Txt + catch _:_ -> yecctoken2string(Token) + end. + +yecctoken_location(Token) -> + try erl_scan:location(Token) + catch _:_ -> element(2, Token) + end. + +-compile({nowarn_unused_function, yecctoken2string/1}). +yecctoken2string(Token) -> + try + yecctoken2string1(Token) + catch + _:_ -> + io_lib:format("~tp", [Token]) + end. + +-compile({nowarn_unused_function, yecctoken2string1/1}). +yecctoken2string1({atom, _, A}) -> io_lib:write_atom(A); +yecctoken2string1({integer,_,N}) -> io_lib:write(N); +yecctoken2string1({float,_,F}) -> io_lib:write(F); +yecctoken2string1({char,_,C}) -> io_lib:write_char(C); +yecctoken2string1({var,_,V}) -> io_lib:format("~s", [V]); +yecctoken2string1({string,_,S}) -> io_lib:write_string(S); +yecctoken2string1({reserved_symbol, _, A}) -> io_lib:write(A); +yecctoken2string1({_Cat, _, Val}) -> io_lib:format("~tp", [Val]); +yecctoken2string1({dot, _}) -> "'.'"; +yecctoken2string1({'$end', _}) -> []; +yecctoken2string1({Other, _}) when is_atom(Other) -> + io_lib:write_atom(Other); +yecctoken2string1(Other) -> + io_lib:format("~tp", [Other]). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + + +-file("src/dmarc_parser.erl", 214). + +-dialyzer({nowarn_function, yeccpars2/7}). +-compile({nowarn_unused_function, yeccpars2/7}). +yeccpars2(0=S, Cat, Ss, Stack, T, Ts, Tzr) -> + yeccpars2_0(S, Cat, Ss, Stack, T, Ts, Tzr); +%% yeccpars2(1=S, Cat, Ss, Stack, T, Ts, Tzr) -> +%% yeccpars2_1(S, Cat, Ss, Stack, T, Ts, Tzr); +%% yeccpars2(2=S, Cat, Ss, Stack, T, Ts, Tzr) -> +%% yeccpars2_2(S, Cat, Ss, Stack, T, Ts, Tzr); +%% yeccpars2(3=S, Cat, Ss, Stack, T, Ts, Tzr) -> +%% yeccpars2_3(S, Cat, Ss, Stack, T, Ts, Tzr); +yeccpars2(4=S, Cat, Ss, Stack, T, Ts, Tzr) -> + yeccpars2_4(S, Cat, Ss, Stack, T, Ts, Tzr); +yeccpars2(5=S, Cat, Ss, Stack, T, Ts, Tzr) -> + yeccpars2_5(S, Cat, Ss, Stack, T, Ts, Tzr); +%% yeccpars2(6=S, Cat, Ss, Stack, T, Ts, Tzr) -> +%% yeccpars2_6(S, Cat, Ss, Stack, T, Ts, Tzr); +yeccpars2(7=S, Cat, Ss, Stack, T, Ts, Tzr) -> + yeccpars2_7(S, Cat, Ss, Stack, T, Ts, Tzr); +yeccpars2(8=S, Cat, Ss, Stack, T, Ts, Tzr) -> + yeccpars2_8(S, Cat, Ss, Stack, T, Ts, Tzr); +yeccpars2(9=S, Cat, Ss, Stack, T, Ts, Tzr) -> + yeccpars2_5(S, Cat, Ss, Stack, T, Ts, Tzr); +%% yeccpars2(10=S, Cat, Ss, Stack, T, Ts, Tzr) -> +%% yeccpars2_10(S, Cat, Ss, Stack, T, Ts, Tzr); +yeccpars2(11=S, Cat, Ss, Stack, T, Ts, Tzr) -> + yeccpars2_5(S, Cat, Ss, Stack, T, Ts, Tzr); +%% yeccpars2(12=S, Cat, Ss, Stack, T, Ts, Tzr) -> +%% yeccpars2_12(S, Cat, Ss, Stack, T, Ts, Tzr); +yeccpars2(13=S, Cat, Ss, Stack, T, Ts, Tzr) -> + yeccpars2_13(S, Cat, Ss, Stack, T, Ts, Tzr); +%% yeccpars2(14=S, Cat, Ss, Stack, T, Ts, Tzr) -> +%% yeccpars2_14(S, Cat, Ss, Stack, T, Ts, Tzr); +%% yeccpars2(15=S, Cat, Ss, Stack, T, Ts, Tzr) -> +%% yeccpars2_15(S, Cat, Ss, Stack, T, Ts, Tzr); +yeccpars2(16=S, Cat, Ss, Stack, T, Ts, Tzr) -> + yeccpars2_16(S, Cat, Ss, Stack, T, Ts, Tzr); +yeccpars2(Other, _, _, _, _, _, _) -> + erlang:error({yecc_bug,"1.4",{missing_state_in_action_table, Other}}). + +-dialyzer({nowarn_function, yeccpars2_0/7}). +-compile({nowarn_unused_function, yeccpars2_0/7}). +yeccpars2_0(S, 'key', Ss, Stack, T, Ts, Tzr) -> + yeccpars1(S, 4, Ss, Stack, T, Ts, Tzr); +yeccpars2_0(_, _, _, _, T, _, _) -> + yeccerror(T). + +-dialyzer({nowarn_function, yeccpars2_1/7}). +-compile({nowarn_unused_function, yeccpars2_1/7}). +yeccpars2_1(_S, '$end', _Ss, Stack, _T, _Ts, _Tzr) -> + {ok, hd(Stack)}; +yeccpars2_1(_, _, _, _, T, _, _) -> + yeccerror(T). + +-dialyzer({nowarn_function, yeccpars2_2/7}). +-compile({nowarn_unused_function, yeccpars2_2/7}). +yeccpars2_2(S, 'semicolon', Ss, Stack, T, Ts, Tzr) -> + yeccpars1(S, 16, Ss, Stack, T, Ts, Tzr); +yeccpars2_2(_S, Cat, Ss, Stack, T, Ts, Tzr) -> + NewStack = yeccpars2_2_(Stack), + yeccpars2_15(_S, Cat, [2 | Ss], NewStack, T, Ts, Tzr). + +-dialyzer({nowarn_function, yeccpars2_3/7}). +-compile({nowarn_unused_function, yeccpars2_3/7}). +yeccpars2_3(S, 'key', Ss, Stack, T, Ts, Tzr) -> + yeccpars1(S, 4, Ss, Stack, T, Ts, Tzr); +yeccpars2_3(_S, Cat, Ss, Stack, T, Ts, Tzr) -> + NewStack = yeccpars2_3_(Stack), + yeccgoto_property_list(hd(Ss), Cat, Ss, NewStack, T, Ts, Tzr). + +-dialyzer({nowarn_function, yeccpars2_4/7}). +-compile({nowarn_unused_function, yeccpars2_4/7}). +yeccpars2_4(S, 'equals', Ss, Stack, T, Ts, Tzr) -> + yeccpars1(S, 5, Ss, Stack, T, Ts, Tzr); +yeccpars2_4(_, _, _, _, T, _, _) -> + yeccerror(T). + +-dialyzer({nowarn_function, yeccpars2_5/7}). +-compile({nowarn_unused_function, yeccpars2_5/7}). +yeccpars2_5(S, 'mailto', Ss, Stack, T, Ts, Tzr) -> + yeccpars1(S, 7, Ss, Stack, T, Ts, Tzr); +yeccpars2_5(S, 'string', Ss, Stack, T, Ts, Tzr) -> + yeccpars1(S, 8, Ss, Stack, T, Ts, Tzr); +yeccpars2_5(_, _, _, _, T, _, _) -> + yeccerror(T). + +-dialyzer({nowarn_function, yeccpars2_6/7}). +-compile({nowarn_unused_function, yeccpars2_6/7}). +yeccpars2_6(S, 'semicolon', Ss, Stack, T, Ts, Tzr) -> + yeccpars1(S, 13, Ss, Stack, T, Ts, Tzr); +yeccpars2_6(_S, Cat, Ss, Stack, T, Ts, Tzr) -> + [_,_|Nss] = Ss, + NewStack = yeccpars2_6_(Stack), + yeccgoto_property(hd(Nss), Cat, Nss, NewStack, T, Ts, Tzr). + +-dialyzer({nowarn_function, yeccpars2_7/7}). +-compile({nowarn_unused_function, yeccpars2_7/7}). +yeccpars2_7(S, 'comma', Ss, Stack, T, Ts, Tzr) -> + yeccpars1(S, 11, Ss, Stack, T, Ts, Tzr); +yeccpars2_7(_S, Cat, Ss, Stack, T, Ts, Tzr) -> + NewStack = yeccpars2_7_(Stack), + yeccgoto_value(hd(Ss), Cat, Ss, NewStack, T, Ts, Tzr). + +-dialyzer({nowarn_function, yeccpars2_8/7}). +-compile({nowarn_unused_function, yeccpars2_8/7}). +yeccpars2_8(S, 'colon', Ss, Stack, T, Ts, Tzr) -> + yeccpars1(S, 9, Ss, Stack, T, Ts, Tzr); +yeccpars2_8(_S, Cat, Ss, Stack, T, Ts, Tzr) -> + NewStack = yeccpars2_8_(Stack), + yeccgoto_value(hd(Ss), Cat, Ss, NewStack, T, Ts, Tzr). + +%% yeccpars2_9: see yeccpars2_5 + +-dialyzer({nowarn_function, yeccpars2_10/7}). +-compile({nowarn_unused_function, yeccpars2_10/7}). +yeccpars2_10(_S, Cat, Ss, Stack, T, Ts, Tzr) -> + [_,_|Nss] = Ss, + NewStack = yeccpars2_10_(Stack), + yeccgoto_value(hd(Nss), Cat, Nss, NewStack, T, Ts, Tzr). + +%% yeccpars2_11: see yeccpars2_5 + +-dialyzer({nowarn_function, yeccpars2_12/7}). +-compile({nowarn_unused_function, yeccpars2_12/7}). +yeccpars2_12(_S, Cat, Ss, Stack, T, Ts, Tzr) -> + [_,_|Nss] = Ss, + NewStack = yeccpars2_12_(Stack), + yeccgoto_value(hd(Nss), Cat, Nss, NewStack, T, Ts, Tzr). + +-dialyzer({nowarn_function, yeccpars2_13/7}). +-compile({nowarn_unused_function, yeccpars2_13/7}). +yeccpars2_13(_S, Cat, Ss, Stack, T, Ts, Tzr) -> + [_,_,_|Nss] = Ss, + NewStack = yeccpars2_13_(Stack), + yeccgoto_property(hd(Nss), Cat, Nss, NewStack, T, Ts, Tzr). + +-dialyzer({nowarn_function, yeccpars2_14/7}). +-compile({nowarn_unused_function, yeccpars2_14/7}). +yeccpars2_14(_S, Cat, Ss, Stack, T, Ts, Tzr) -> + [_|Nss] = Ss, + NewStack = yeccpars2_14_(Stack), + yeccgoto_property_list(hd(Nss), Cat, Nss, NewStack, T, Ts, Tzr). + +-dialyzer({nowarn_function, yeccpars2_15/7}). +-compile({nowarn_unused_function, yeccpars2_15/7}). +yeccpars2_15(_S, Cat, Ss, Stack, T, Ts, Tzr) -> + [_|Nss] = Ss, + NewStack = yeccpars2_15_(Stack), + yeccgoto_record(hd(Nss), Cat, Nss, NewStack, T, Ts, Tzr). + +-dialyzer({nowarn_function, yeccpars2_16/7}). +-compile({nowarn_unused_function, yeccpars2_16/7}). +yeccpars2_16(_S, Cat, Ss, Stack, T, Ts, Tzr) -> + NewStack = yeccpars2_16_(Stack), + yeccgoto_optional_semicolon(hd(Ss), Cat, Ss, NewStack, T, Ts, Tzr). + +-dialyzer({nowarn_function, yeccgoto_optional_semicolon/7}). +-compile({nowarn_unused_function, yeccgoto_optional_semicolon/7}). +yeccgoto_optional_semicolon(2=_S, Cat, Ss, Stack, T, Ts, Tzr) -> + yeccpars2_15(_S, Cat, Ss, Stack, T, Ts, Tzr). + +-dialyzer({nowarn_function, yeccgoto_property/7}). +-compile({nowarn_unused_function, yeccgoto_property/7}). +yeccgoto_property(0, Cat, Ss, Stack, T, Ts, Tzr) -> + yeccpars2_3(3, Cat, Ss, Stack, T, Ts, Tzr); +yeccgoto_property(3, Cat, Ss, Stack, T, Ts, Tzr) -> + yeccpars2_3(3, Cat, Ss, Stack, T, Ts, Tzr). + +-dialyzer({nowarn_function, yeccgoto_property_list/7}). +-compile({nowarn_unused_function, yeccgoto_property_list/7}). +yeccgoto_property_list(0, Cat, Ss, Stack, T, Ts, Tzr) -> + yeccpars2_2(2, Cat, Ss, Stack, T, Ts, Tzr); +yeccgoto_property_list(3=_S, Cat, Ss, Stack, T, Ts, Tzr) -> + yeccpars2_14(_S, Cat, Ss, Stack, T, Ts, Tzr). + +-dialyzer({nowarn_function, yeccgoto_record/7}). +-compile({nowarn_unused_function, yeccgoto_record/7}). +yeccgoto_record(0, Cat, Ss, Stack, T, Ts, Tzr) -> + yeccpars2_1(1, Cat, Ss, Stack, T, Ts, Tzr). + +-dialyzer({nowarn_function, yeccgoto_value/7}). +-compile({nowarn_unused_function, yeccgoto_value/7}). +yeccgoto_value(5, Cat, Ss, Stack, T, Ts, Tzr) -> + yeccpars2_6(6, Cat, Ss, Stack, T, Ts, Tzr); +yeccgoto_value(9=_S, Cat, Ss, Stack, T, Ts, Tzr) -> + yeccpars2_10(_S, Cat, Ss, Stack, T, Ts, Tzr); +yeccgoto_value(11=_S, Cat, Ss, Stack, T, Ts, Tzr) -> + yeccpars2_12(_S, Cat, Ss, Stack, T, Ts, Tzr). + +-compile({inline,yeccpars2_2_/1}). +-dialyzer({nowarn_function, yeccpars2_2_/1}). +-compile({nowarn_unused_function, yeccpars2_2_/1}). +-file("src/dmarc_parser.yrl", 8). +yeccpars2_2_(__Stack0) -> + [begin + [] + end | __Stack0]. + +-compile({inline,yeccpars2_3_/1}). +-dialyzer({nowarn_function, yeccpars2_3_/1}). +-compile({nowarn_unused_function, yeccpars2_3_/1}). +-file("src/dmarc_parser.yrl", 10). +yeccpars2_3_(__Stack0) -> + [___1 | __Stack] = __Stack0, + [begin + [___1] + end | __Stack]. + +-compile({inline,yeccpars2_6_/1}). +-dialyzer({nowarn_function, yeccpars2_6_/1}). +-compile({nowarn_unused_function, yeccpars2_6_/1}). +-file("src/dmarc_parser.yrl", 14). +yeccpars2_6_(__Stack0) -> + [___3,___2,___1 | __Stack] = __Stack0, + [begin + {value(___1), process_value(value(___1), value_to_list(___3))} + end | __Stack]. + +-compile({inline,yeccpars2_7_/1}). +-dialyzer({nowarn_function, yeccpars2_7_/1}). +-compile({nowarn_unused_function, yeccpars2_7_/1}). +-file("src/dmarc_parser.yrl", 16). +yeccpars2_7_(__Stack0) -> + [___1 | __Stack] = __Stack0, + [begin + ___1 + end | __Stack]. + +-compile({inline,yeccpars2_8_/1}). +-dialyzer({nowarn_function, yeccpars2_8_/1}). +-compile({nowarn_unused_function, yeccpars2_8_/1}). +-file("src/dmarc_parser.yrl", 19). +yeccpars2_8_(__Stack0) -> + [___1 | __Stack] = __Stack0, + [begin + ___1 + end | __Stack]. + +-compile({inline,yeccpars2_10_/1}). +-dialyzer({nowarn_function, yeccpars2_10_/1}). +-compile({nowarn_unused_function, yeccpars2_10_/1}). +-file("src/dmarc_parser.yrl", 20). +yeccpars2_10_(__Stack0) -> + [___3,___2,___1 | __Stack] = __Stack0, + [begin + join_values(___1, ___3) + end | __Stack]. + +-compile({inline,yeccpars2_12_/1}). +-dialyzer({nowarn_function, yeccpars2_12_/1}). +-compile({nowarn_unused_function, yeccpars2_12_/1}). +-file("src/dmarc_parser.yrl", 17). +yeccpars2_12_(__Stack0) -> + [___3,___2,___1 | __Stack] = __Stack0, + [begin + join_values(___1, ___3) + end | __Stack]. + +-compile({inline,yeccpars2_13_/1}). +-dialyzer({nowarn_function, yeccpars2_13_/1}). +-compile({nowarn_unused_function, yeccpars2_13_/1}). +-file("src/dmarc_parser.yrl", 13). +yeccpars2_13_(__Stack0) -> + [___4,___3,___2,___1 | __Stack] = __Stack0, + [begin + {value(___1), process_value(value(___1), value_to_list(___3))} + end | __Stack]. + +-compile({inline,yeccpars2_14_/1}). +-dialyzer({nowarn_function, yeccpars2_14_/1}). +-compile({nowarn_unused_function, yeccpars2_14_/1}). +-file("src/dmarc_parser.yrl", 11). +yeccpars2_14_(__Stack0) -> + [___2,___1 | __Stack] = __Stack0, + [begin + [___1 | ___2] + end | __Stack]. + +-compile({inline,yeccpars2_15_/1}). +-dialyzer({nowarn_function, yeccpars2_15_/1}). +-compile({nowarn_unused_function, yeccpars2_15_/1}). +-file("src/dmarc_parser.yrl", 5). +yeccpars2_15_(__Stack0) -> + [___2,___1 | __Stack] = __Stack0, + [begin + ___1 + end | __Stack]. + +-compile({inline,yeccpars2_16_/1}). +-dialyzer({nowarn_function, yeccpars2_16_/1}). +-compile({nowarn_unused_function, yeccpars2_16_/1}). +-file("src/dmarc_parser.yrl", 7). +yeccpars2_16_(__Stack0) -> + [___1 | __Stack] = __Stack0, + [begin + [] + end | __Stack]. + + +-file("src/dmarc_parser.yrl", 48). diff --git a/src/dmarc_parser.yrl b/src/dmarc_parser.yrl new file mode 100644 index 0000000..c1f4e1d --- /dev/null +++ b/src/dmarc_parser.yrl @@ -0,0 +1,47 @@ +Nonterminals + record property_list property optional_semicolon value. + +Terminals + key equals semicolon string comma colon mailto. + +Rootsymbol record. + +record -> property_list optional_semicolon : '$1'. + +optional_semicolon -> semicolon : []. +optional_semicolon -> '$empty' : []. + +property_list -> property : ['$1']. +property_list -> property property_list : ['$1' | '$2']. + +property -> key equals value semicolon : {value('$1'), process_value(value('$1'), value_to_list('$3'))}. +property -> key equals value : {value('$1'), process_value(value('$1'), value_to_list('$3'))}. + +value -> mailto : '$1'. +value -> mailto comma value : join_values('$1', '$3'). + +value -> string : '$1'. +value -> string colon value : join_values('$1', '$3'). + +Expect 1. + +Erlang code. + +value({_, _, Value}) -> Value. + +value_to_list(Value) when is_tuple(Value) -> + [Value]; +value_to_list(Values) when is_list(Values) -> + Values. + +join_values(First, Rest) when is_tuple(Rest) -> + [First, Rest]; +join_values(First, RestList) when is_list(RestList) -> + [First | RestList]. + +process_value(Key, Values) when Key =:= rua; Key =:= ruf; Key =:= fo; Key =:= rf -> + lists:map(fun value/1, Values); +process_value(_Key, [Value]) -> + value(Value); +process_value(_Key, Values) -> + [value(V) || V <- Values]. |