Advertisement
Guest User

Untitled

a guest
Jul 3rd, 2015
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.11 KB | None | 0 0
  1. -file("/www/nitrogen-git/nitrogen/rel/nitrogen/lib/parsetools-2.0.12/include/leexinc.hrl", 0).
  2. %% The source of this file is part of leex distribution, as such it
  3. %% has the same Copyright as the other files in the leex
  4. %% distribution. The Copyright is defined in the accompanying file
  5. %% COPYRIGHT. However, the resultant scanner generated by leex is the
  6. %% property of the creator of the scanner and is not covered by that
  7. %% Copyright.
  8.  
  9. -module(mimetypes_scan).
  10.  
  11. -export([string/1,string/2,token/2,token/3,tokens/2,tokens/3]).
  12. -export([format_error/1]).
  13.  
  14. %% User code. This is placed here to allow extra attributes.
  15. -file("src/mimetypes_scan.xrl", 18).
  16.  
  17.  
  18. -file("/www/nitrogen-git/nitrogen/rel/nitrogen/lib/parsetools-2.0.12/include/leexinc.hrl", 14).
  19.  
  20. format_error({illegal,S}) -> ["illegal characters ",io_lib:write_string(S)];
  21. format_error({user,S}) -> S.
  22.  
  23. string(String) -> string(String, 1).
  24.  
  25. string(String, Line) -> string(String, Line, String, []).
  26.  
  27. %% string(InChars, Line, TokenChars, Tokens) ->
  28. %% {ok,Tokens,Line} | {error,ErrorInfo,Line}.
  29. %% Note the line number going into yystate, L0, is line of token
  30. %% start while line number returned is line of token end. We want line
  31. %% of token start.
  32.  
  33. string([], L, [], Ts) -> % No partial tokens!
  34. {ok,yyrev(Ts),L};
  35. string(Ics0, L0, Tcs, Ts) ->
  36. case yystate(yystate(), Ics0, L0, 0, reject, 0) of
  37. {A,Alen,Ics1,L1} -> % Accepting end state
  38. string_cont(Ics1, L1, yyaction(A, Alen, Tcs, L0), Ts);
  39. {A,Alen,Ics1,L1,_S1} -> % Accepting transistion state
  40. string_cont(Ics1, L1, yyaction(A, Alen, Tcs, L0), Ts);
  41. {reject,_Alen,Tlen,_Ics1,L1,_S1} -> % After a non-accepting state
  42. {error,{L0,?MODULE,{illegal,yypre(Tcs, Tlen+1)}},L1};
  43. {A,Alen,_Tlen,_Ics1,_L1,_S1} ->
  44. string_cont(yysuf(Tcs, Alen), L0, yyaction(A, Alen, Tcs, L0), Ts)
  45. end.
  46.  
  47. %% string_cont(RestChars, Line, Token, Tokens)
  48. %% Test for and remove the end token wrapper. Push back characters
  49. %% are prepended to RestChars.
  50.  
  51. string_cont(Rest, Line, {token,T}, Ts) ->
  52. string(Rest, Line, Rest, [T|Ts]);
  53. string_cont(Rest, Line, {token,T,Push}, Ts) ->
  54. NewRest = Push ++ Rest,
  55. string(NewRest, Line, NewRest, [T|Ts]);
  56. string_cont(Rest, Line, {end_token,T}, Ts) ->
  57. string(Rest, Line, Rest, [T|Ts]);
  58. string_cont(Rest, Line, {end_token,T,Push}, Ts) ->
  59. NewRest = Push ++ Rest,
  60. string(NewRest, Line, NewRest, [T|Ts]);
  61. string_cont(Rest, Line, skip_token, Ts) ->
  62. string(Rest, Line, Rest, Ts);
  63. string_cont(Rest, Line, {skip_token,Push}, Ts) ->
  64. NewRest = Push ++ Rest,
  65. string(NewRest, Line, NewRest, Ts);
  66. string_cont(_Rest, Line, {error,S}, _Ts) ->
  67. {error,{Line,?MODULE,{user,S}},Line}.
  68.  
  69. %% token(Continuation, Chars) ->
  70. %% token(Continuation, Chars, Line) ->
  71. %% {more,Continuation} | {done,ReturnVal,RestChars}.
  72. %% Must be careful when re-entering to append the latest characters to the
  73. %% after characters in an accept. The continuation is:
  74. %% {token,State,CurrLine,TokenChars,TokenLen,TokenLine,AccAction,AccLen}
  75.  
  76. token(Cont, Chars) -> token(Cont, Chars, 1).
  77.  
  78. token([], Chars, Line) ->
  79. token(yystate(), Chars, Line, Chars, 0, Line, reject, 0);
  80. token({token,State,Line,Tcs,Tlen,Tline,Action,Alen}, Chars, _) ->
  81. token(State, Chars, Line, Tcs ++ Chars, Tlen, Tline, Action, Alen).
  82.  
  83. %% token(State, InChars, Line, TokenChars, TokenLen, TokenLine,
  84. %% AcceptAction, AcceptLen) ->
  85. %% {more,Continuation} | {done,ReturnVal,RestChars}.
  86. %% The argument order is chosen to be more efficient.
  87.  
  88. token(S0, Ics0, L0, Tcs, Tlen0, Tline, A0, Alen0) ->
  89. case yystate(S0, Ics0, L0, Tlen0, A0, Alen0) of
  90. %% Accepting end state, we have a token.
  91. {A1,Alen1,Ics1,L1} ->
  92. token_cont(Ics1, L1, yyaction(A1, Alen1, Tcs, Tline));
  93. %% Accepting transition state, can take more chars.
  94. {A1,Alen1,[],L1,S1} -> % Need more chars to check
  95. {more,{token,S1,L1,Tcs,Alen1,Tline,A1,Alen1}};
  96. {A1,Alen1,Ics1,L1,_S1} -> % Take what we got
  97. token_cont(Ics1, L1, yyaction(A1, Alen1, Tcs, Tline));
  98. %% After a non-accepting state, maybe reach accept state later.
  99. {A1,Alen1,Tlen1,[],L1,S1} -> % Need more chars to check
  100. {more,{token,S1,L1,Tcs,Tlen1,Tline,A1,Alen1}};
  101. {reject,_Alen1,Tlen1,eof,L1,_S1} -> % No token match
  102. %% Check for partial token which is error.
  103. Ret = if Tlen1 > 0 -> {error,{Tline,?MODULE,
  104. %% Skip eof tail in Tcs.
  105. {illegal,yypre(Tcs, Tlen1)}},L1};
  106. true -> {eof,L1}
  107. end,
  108. {done,Ret,eof};
  109. {reject,_Alen1,Tlen1,Ics1,L1,_S1} -> % No token match
  110. Error = {Tline,?MODULE,{illegal,yypre(Tcs, Tlen1+1)}},
  111. {done,{error,Error,L1},Ics1};
  112. {A1,Alen1,_Tlen1,_Ics1,_L1,_S1} -> % Use last accept match
  113. token_cont(yysuf(Tcs, Alen1), L0, yyaction(A1, Alen1, Tcs, Tline))
  114. end.
  115.  
  116. %% token_cont(RestChars, Line, Token)
  117. %% If we have a token or error then return done, else if we have a
  118. %% skip_token then continue.
  119.  
  120. token_cont(Rest, Line, {token,T}) ->
  121. {done,{ok,T,Line},Rest};
  122. token_cont(Rest, Line, {token,T,Push}) ->
  123. NewRest = Push ++ Rest,
  124. {done,{ok,T,Line},NewRest};
  125. token_cont(Rest, Line, {end_token,T}) ->
  126. {done,{ok,T,Line},Rest};
  127. token_cont(Rest, Line, {end_token,T,Push}) ->
  128. NewRest = Push ++ Rest,
  129. {done,{ok,T,Line},NewRest};
  130. token_cont(Rest, Line, skip_token) ->
  131. token(yystate(), Rest, Line, Rest, 0, Line, reject, 0);
  132. token_cont(Rest, Line, {skip_token,Push}) ->
  133. NewRest = Push ++ Rest,
  134. token(yystate(), NewRest, Line, NewRest, 0, Line, reject, 0);
  135. token_cont(Rest, Line, {error,S}) ->
  136. {done,{error,{Line,?MODULE,{user,S}},Line},Rest}.
  137.  
  138. %% tokens(Continuation, Chars, Line) ->
  139. %% {more,Continuation} | {done,ReturnVal,RestChars}.
  140. %% Must be careful when re-entering to append the latest characters to the
  141. %% after characters in an accept. The continuation is:
  142. %% {tokens,State,CurrLine,TokenChars,TokenLen,TokenLine,Tokens,AccAction,AccLen}
  143. %% {skip_tokens,State,CurrLine,TokenChars,TokenLen,TokenLine,Error,AccAction,AccLen}
  144.  
  145. tokens(Cont, Chars) -> tokens(Cont, Chars, 1).
  146.  
  147. tokens([], Chars, Line) ->
  148. tokens(yystate(), Chars, Line, Chars, 0, Line, [], reject, 0);
  149. tokens({tokens,State,Line,Tcs,Tlen,Tline,Ts,Action,Alen}, Chars, _) ->
  150. tokens(State, Chars, Line, Tcs ++ Chars, Tlen, Tline, Ts, Action, Alen);
  151. tokens({skip_tokens,State,Line,Tcs,Tlen,Tline,Error,Action,Alen}, Chars, _) ->
  152. skip_tokens(State, Chars, Line, Tcs ++ Chars, Tlen, Tline, Error, Action, Alen).
  153.  
  154. %% tokens(State, InChars, Line, TokenChars, TokenLen, TokenLine, Tokens,
  155. %% AcceptAction, AcceptLen) ->
  156. %% {more,Continuation} | {done,ReturnVal,RestChars}.
  157.  
  158. tokens(S0, Ics0, L0, Tcs, Tlen0, Tline, Ts, A0, Alen0) ->
  159. case yystate(S0, Ics0, L0, Tlen0, A0, Alen0) of
  160. %% Accepting end state, we have a token.
  161. {A1,Alen1,Ics1,L1} ->
  162. tokens_cont(Ics1, L1, yyaction(A1, Alen1, Tcs, Tline), Ts);
  163. %% Accepting transition state, can take more chars.
  164. {A1,Alen1,[],L1,S1} -> % Need more chars to check
  165. {more,{tokens,S1,L1,Tcs,Alen1,Tline,Ts,A1,Alen1}};
  166. {A1,Alen1,Ics1,L1,_S1} -> % Take what we got
  167. tokens_cont(Ics1, L1, yyaction(A1, Alen1, Tcs, Tline), Ts);
  168. %% After a non-accepting state, maybe reach accept state later.
  169. {A1,Alen1,Tlen1,[],L1,S1} -> % Need more chars to check
  170. {more,{tokens,S1,L1,Tcs,Tlen1,Tline,Ts,A1,Alen1}};
  171. {reject,_Alen1,Tlen1,eof,L1,_S1} -> % No token match
  172. %% Check for partial token which is error, no need to skip here.
  173. Ret = if Tlen1 > 0 -> {error,{Tline,?MODULE,
  174. %% Skip eof tail in Tcs.
  175. {illegal,yypre(Tcs, Tlen1)}},L1};
  176. Ts == [] -> {eof,L1};
  177. true -> {ok,yyrev(Ts),L1}
  178. end,
  179. {done,Ret,eof};
  180. {reject,_Alen1,Tlen1,_Ics1,L1,_S1} ->
  181. %% Skip rest of tokens.
  182. Error = {L1,?MODULE,{illegal,yypre(Tcs, Tlen1+1)}},
  183. skip_tokens(yysuf(Tcs, Tlen1+1), L1, Error);
  184. {A1,Alen1,_Tlen1,_Ics1,_L1,_S1} ->
  185. Token = yyaction(A1, Alen1, Tcs, Tline),
  186. tokens_cont(yysuf(Tcs, Alen1), L0, Token, Ts)
  187. end.
  188.  
  189. %% tokens_cont(RestChars, Line, Token, Tokens)
  190. %% If we have an end_token or error then return done, else if we have
  191. %% a token then save it and continue, else if we have a skip_token
  192. %% just continue.
  193.  
  194. tokens_cont(Rest, Line, {token,T}, Ts) ->
  195. tokens(yystate(), Rest, Line, Rest, 0, Line, [T|Ts], reject, 0);
  196. tokens_cont(Rest, Line, {token,T,Push}, Ts) ->
  197. NewRest = Push ++ Rest,
  198. tokens(yystate(), NewRest, Line, NewRest, 0, Line, [T|Ts], reject, 0);
  199. tokens_cont(Rest, Line, {end_token,T}, Ts) ->
  200. {done,{ok,yyrev(Ts, [T]),Line},Rest};
  201. tokens_cont(Rest, Line, {end_token,T,Push}, Ts) ->
  202. NewRest = Push ++ Rest,
  203. {done,{ok,yyrev(Ts, [T]),Line},NewRest};
  204. tokens_cont(Rest, Line, skip_token, Ts) ->
  205. tokens(yystate(), Rest, Line, Rest, 0, Line, Ts, reject, 0);
  206. tokens_cont(Rest, Line, {skip_token,Push}, Ts) ->
  207. NewRest = Push ++ Rest,
  208. tokens(yystate(), NewRest, Line, NewRest, 0, Line, Ts, reject, 0);
  209. tokens_cont(Rest, Line, {error,S}, _Ts) ->
  210. skip_tokens(Rest, Line, {Line,?MODULE,{user,S}}).
  211.  
  212. %%skip_tokens(InChars, Line, Error) -> {done,{error,Error,Line},Ics}.
  213. %% Skip tokens until an end token, junk everything and return the error.
  214.  
  215. skip_tokens(Ics, Line, Error) ->
  216. skip_tokens(yystate(), Ics, Line, Ics, 0, Line, Error, reject, 0).
  217.  
  218. %% skip_tokens(State, InChars, Line, TokenChars, TokenLen, TokenLine, Tokens,
  219. %% AcceptAction, AcceptLen) ->
  220. %% {more,Continuation} | {done,ReturnVal,RestChars}.
  221.  
  222. skip_tokens(S0, Ics0, L0, Tcs, Tlen0, Tline, Error, A0, Alen0) ->
  223. case yystate(S0, Ics0, L0, Tlen0, A0, Alen0) of
  224. {A1,Alen1,Ics1,L1} -> % Accepting end state
  225. skip_cont(Ics1, L1, yyaction(A1, Alen1, Tcs, Tline), Error);
  226. {A1,Alen1,[],L1,S1} -> % After an accepting state
  227. {more,{skip_tokens,S1,L1,Tcs,Alen1,Tline,Error,A1,Alen1}};
  228. {A1,Alen1,Ics1,L1,_S1} ->
  229. skip_cont(Ics1, L1, yyaction(A1, Alen1, Tcs, Tline), Error);
  230. {A1,Alen1,Tlen1,[],L1,S1} -> % After a non-accepting state
  231. {more,{skip_tokens,S1,L1,Tcs,Tlen1,Tline,Error,A1,Alen1}};
  232. {reject,_Alen1,_Tlen1,eof,L1,_S1} ->
  233. {done,{error,Error,L1},eof};
  234. {reject,_Alen1,Tlen1,_Ics1,L1,_S1} ->
  235. skip_tokens(yysuf(Tcs, Tlen1+1), L1, Error);
  236. {A1,Alen1,_Tlen1,_Ics1,L1,_S1} ->
  237. Token = yyaction(A1, Alen1, Tcs, Tline),
  238. skip_cont(yysuf(Tcs, Alen1), L1, Token, Error)
  239. end.
  240.  
  241. %% skip_cont(RestChars, Line, Token, Error)
  242. %% Skip tokens until we have an end_token or error then return done
  243. %% with the original rror.
  244.  
  245. skip_cont(Rest, Line, {token,_T}, Error) ->
  246. skip_tokens(yystate(), Rest, Line, Rest, 0, Line, Error, reject, 0);
  247. skip_cont(Rest, Line, {token,_T,Push}, Error) ->
  248. NewRest = Push ++ Rest,
  249. skip_tokens(yystate(), NewRest, Line, NewRest, 0, Line, Error, reject, 0);
  250. skip_cont(Rest, Line, {end_token,_T}, Error) ->
  251. {done,{error,Error,Line},Rest};
  252. skip_cont(Rest, Line, {end_token,_T,Push}, Error) ->
  253. NewRest = Push ++ Rest,
  254. {done,{error,Error,Line},NewRest};
  255. skip_cont(Rest, Line, skip_token, Error) ->
  256. skip_tokens(yystate(), Rest, Line, Rest, 0, Line, Error, reject, 0);
  257. skip_cont(Rest, Line, {skip_token,Push}, Error) ->
  258. NewRest = Push ++ Rest,
  259. skip_tokens(yystate(), NewRest, Line, NewRest, 0, Line, Error, reject, 0);
  260. skip_cont(Rest, Line, {error,_S}, Error) ->
  261. skip_tokens(yystate(), Rest, Line, Rest, 0, Line, Error, reject, 0).
  262.  
  263. yyrev(List) -> lists:reverse(List).
  264. yyrev(List, Tail) -> lists:reverse(List, Tail).
  265. yypre(List, N) -> lists:sublist(List, N).
  266. yysuf(List, N) -> lists:nthtail(N, List).
  267.  
  268. %% yystate() -> InitialState.
  269. %% yystate(State, InChars, Line, CurrTokLen, AcceptAction, AcceptLen) ->
  270. %% {Action, AcceptLen, RestChars, Line} |
  271. %% {Action, AcceptLen, RestChars, Line, State} |
  272. %% {reject, AcceptLen, CurrTokLen, RestChars, Line, State} |
  273. %% {Action, AcceptLen, CurrTokLen, RestChars, Line, State}.
  274. %% Generated state transition functions. The non-accepting end state
  275. %% return signal either an unrecognised character or end of current
  276. %% input.
  277.  
  278. -file("src/mimetypes_scan.erl", 277).
  279. yystate() -> 3.
  280.  
  281. yystate(6, Ics, Line, Tlen, _, _) ->
  282. {2,Tlen,Ics,Line};
  283. yystate(5, [32|Ics], Line, Tlen, _, _) ->
  284. yystate(5, Ics, Line, Tlen+1, 3, Tlen);
  285. yystate(5, [9|Ics], Line, Tlen, _, _) ->
  286. yystate(5, Ics, Line, Tlen+1, 3, Tlen);
  287. yystate(5, Ics, Line, Tlen, _, _) ->
  288. {3,Tlen,Ics,Line,5};
  289. yystate(4, [10|Ics], Line, Tlen, Action, Alen) ->
  290. yystate(6, Ics, Line+1, Tlen+1, Action, Alen);
  291. yystate(4, [C|Ics], Line, Tlen, Action, Alen) when C >= 0, C =< 9 ->
  292. yystate(4, Ics, Line, Tlen+1, Action, Alen);
  293. yystate(4, [C|Ics], Line, Tlen, Action, Alen) when C >= 11 ->
  294. yystate(4, Ics, Line, Tlen+1, Action, Alen);
  295. yystate(4, Ics, Line, Tlen, Action, Alen) ->
  296. {Action,Alen,Tlen,Ics,Line,4};
  297. yystate(3, [95|Ics], Line, Tlen, Action, Alen) ->
  298. yystate(0, Ics, Line, Tlen+1, Action, Alen);
  299. yystate(3, [43|Ics], Line, Tlen, Action, Alen) ->
  300. yystate(0, Ics, Line, Tlen+1, Action, Alen);
  301. yystate(3, [35|Ics], Line, Tlen, Action, Alen) ->
  302. yystate(4, Ics, Line, Tlen+1, Action, Alen);
  303. yystate(3, [32|Ics], Line, Tlen, Action, Alen) ->
  304. yystate(5, Ics, Line, Tlen+1, Action, Alen);
  305. yystate(3, [13|Ics], Line, Tlen, Action, Alen) ->
  306. yystate(2, Ics, Line, Tlen+1, Action, Alen);
  307. yystate(3, [10|Ics], Line, Tlen, Action, Alen) ->
  308. yystate(1, Ics, Line+1, Tlen+1, Action, Alen);
  309. yystate(3, [9|Ics], Line, Tlen, Action, Alen) ->
  310. yystate(5, Ics, Line, Tlen+1, Action, Alen);
  311. yystate(3, [C|Ics], Line, Tlen, Action, Alen) when C >= 45, C =< 57 ->
  312. yystate(0, Ics, Line, Tlen+1, Action, Alen);
  313. yystate(3, [C|Ics], Line, Tlen, Action, Alen) when C >= 65, C =< 90 ->
  314. yystate(0, Ics, Line, Tlen+1, Action, Alen);
  315. yystate(3, [C|Ics], Line, Tlen, Action, Alen) when C >= 97, C =< 122 ->
  316. yystate(0, Ics, Line, Tlen+1, Action, Alen);
  317. yystate(3, Ics, Line, Tlen, Action, Alen) ->
  318. {Action,Alen,Tlen,Ics,Line,3};
  319. yystate(2, [10|Ics], Line, Tlen, Action, Alen) ->
  320. yystate(1, Ics, Line+1, Tlen+1, Action, Alen);
  321. yystate(2, Ics, Line, Tlen, Action, Alen) ->
  322. {Action,Alen,Tlen,Ics,Line,2};
  323. yystate(1, Ics, Line, Tlen, _, _) ->
  324. {1,Tlen,Ics,Line};
  325. yystate(0, [95|Ics], Line, Tlen, _, _) ->
  326. yystate(0, Ics, Line, Tlen+1, 0, Tlen);
  327. yystate(0, [43|Ics], Line, Tlen, _, _) ->
  328. yystate(0, Ics, Line, Tlen+1, 0, Tlen);
  329. yystate(0, [C|Ics], Line, Tlen, _, _) when C >= 45, C =< 57 ->
  330. yystate(0, Ics, Line, Tlen+1, 0, Tlen);
  331. yystate(0, [C|Ics], Line, Tlen, _, _) when C >= 65, C =< 90 ->
  332. yystate(0, Ics, Line, Tlen+1, 0, Tlen);
  333. yystate(0, [C|Ics], Line, Tlen, _, _) when C >= 97, C =< 122 ->
  334. yystate(0, Ics, Line, Tlen+1, 0, Tlen);
  335. yystate(0, Ics, Line, Tlen, _, _) ->
  336. {0,Tlen,Ics,Line,0};
  337. yystate(S, Ics, Line, Tlen, Action, Alen) ->
  338. {Action,Alen,Tlen,Ics,Line,S}.
  339.  
  340. %% yyaction(Action, TokenLength, TokenChars, TokenLine) ->
  341. %% {token,Token} | {end_token, Token} | skip_token | {error,String}.
  342. %% Generated action function.
  343.  
  344. yyaction(0, TokenLen, YYtcs, TokenLine) ->
  345. TokenChars = yypre(YYtcs, TokenLen),
  346. yyaction_0(TokenChars, TokenLine);
  347. yyaction(1, _, _, TokenLine) ->
  348. yyaction_1(TokenLine);
  349. yyaction(2, _, _, _) ->
  350. yyaction_2();
  351. yyaction(3, _, _, _) ->
  352. yyaction_3();
  353. yyaction(_, _, _, _) -> error.
  354.  
  355. -compile({inline,yyaction_0/2}).
  356. -file("src/mimetypes_scan.xrl", 9).
  357. yyaction_0(TokenChars, TokenLine) ->
  358. { token, { string, TokenLine, TokenChars } } .
  359.  
  360. -compile({inline,yyaction_1/1}).
  361. -file("src/mimetypes_scan.xrl", 10).
  362. yyaction_1(TokenLine) ->
  363. { token, { newline, TokenLine } } .
  364.  
  365. -compile({inline,yyaction_2/0}).
  366. -file("src/mimetypes_scan.xrl", 12).
  367. yyaction_2() ->
  368. skip_token .
  369.  
  370. -compile({inline,yyaction_3/0}).
  371. -file("src/mimetypes_scan.xrl", 13).
  372. yyaction_3() ->
  373. skip_token .
  374.  
  375. -file("/www/nitrogen-git/nitrogen/rel/nitrogen/lib/parsetools-2.0.12/include/leexinc.hrl", 282).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement