Skip to content
Browse files

Regenerate RFC4234 parsers

  • Loading branch information...
1 parent bcf4fc3 commit 8450b3c4163e7c8a55f681625bea8ab63c9a29ec @aggregatum aggregatum committed Jan 25, 2012
Showing with 143 additions and 228 deletions.
  1. +46 −83 src/abnfc_rfc4234.erl
  2. +97 −145 src/rfc4234_core.erl
View
129 src/abnfc_rfc4234.erl
@@ -1,6 +1,6 @@
%%% Do not modify this file, it is automatically generated by abnfc.
%%% All changes will be lost when it is regenerated.
-%%% Generated by abnfc_gen on 2010-12-15 00:05:09
+%%% Generated by abnfc_gen on 2012-01-25 19:00:09
-module(abnfc_rfc4234).
@@ -134,12 +134,7 @@ elements() ->
__P = '__seq'([alternation(),
'__repeat'(0, infinity, 'c-wsp'())]),
case __P(T) of
- {ok, [_YY1, _YY2] = _YY, _T1} ->
- try _YY1 of
- __Ret -> {ok, __Ret, _T1}
- catch
- fail -> fail
- end;
+ {ok, [_YY1, _YY2] = _YY, _T1} -> {ok, _YY1, _T1};
fail -> fail
end
end.
@@ -148,12 +143,7 @@ elements() ->
fun (T) ->
__P = '__alt'(['WSP'(), '__seq'(['c-nl'(), 'WSP'()])]),
case __P(T) of
- {ok, _YY, _T1} ->
- try 'c-wsp' of
- __Ret -> {ok, __Ret, _T1}
- catch
- fail -> fail
- end;
+ {ok, _YY, _T1} -> {ok, 'c-wsp', _T1};
fail -> fail
end
end.
@@ -162,12 +152,7 @@ elements() ->
fun (T) ->
__P = '__alt'([comment(), 'CRLF'()]),
case __P(T) of
- {ok, _YY, _T1} ->
- try 'c-nl' of
- __Ret -> {ok, __Ret, _T1}
- catch
- fail -> fail
- end;
+ {ok, _YY, _T1} -> {ok, 'c-nl', _T1};
fail -> fail
end
end.
@@ -181,11 +166,7 @@ comment() ->
'CRLF'()]),
case __P(T) of
{ok, [_YY1, _YY2, _YY3] = _YY, _T1} ->
- try comment of
- __Ret -> {ok, __Ret, _T1}
- catch
- fail -> fail
- end;
+ {ok, comment, _T1};
fail -> fail
end
end.
@@ -285,11 +266,8 @@ repeat() ->
end.
element() ->
- fun (T) ->
- __P = '__alt'([rulename(), group(), option(),
- 'char-val'(), 'num-val'(), 'prose-val'()]),
- __P(T)
- end.
+ '__alt'([rulename(), group(), option(), 'char-val'(),
+ 'num-val'(), 'prose-val'()]).
group() ->
fun (T) ->
@@ -303,11 +281,7 @@ group() ->
end]),
case __P(T) of
{ok, [_YY1, _YY2, _YY3, _YY4, _YY5] = _YY, _T1} ->
- try _YY3 of
- __Ret -> {ok, __Ret, _T1}
- catch
- fail -> fail
- end;
+ {ok, _YY3, _T1};
fail -> fail
end
end.
@@ -324,11 +298,7 @@ option() ->
end]),
case __P(T) of
{ok, [_YY1, _YY2, _YY3, _YY4, _YY5] = _YY, _T1} ->
- try {repeat, 0, 1, _YY3} of
- __Ret -> {ok, __Ret, _T1}
- catch
- fail -> fail
- end;
+ {ok, {repeat, 0, 1, _YY3}, _T1};
fail -> fail
end
end.
@@ -337,9 +307,9 @@ option() ->
fun (T) ->
__P = '__seq'(['DQUOTE'(),
'__repeat'(0, infinity,
- fun ([C | Tl]) when (C >= 32) and (C =< 33) ->
+ fun ([C | Tl]) when (C >= 35) and (C =< 126) ->
{ok, C, Tl};
- ([C | Tl]) when (C >= 35) and (C =< 126) ->
+ ([C | Tl]) when (C >= 32) and (C =< 33) ->
{ok, C, Tl};
(_) -> fail
end),
@@ -375,12 +345,7 @@ option() ->
end,
'__alt'(['bin-val'(), 'dec-val'(), 'hex-val'()])]),
case __P(T) of
- {ok, [_YY1, _YY2] = _YY, _T1} ->
- try _YY2 of
- __Ret -> {ok, __Ret, _T1}
- catch
- fail -> fail
- end;
+ {ok, [_YY1, _YY2] = _YY, _T1} -> {ok, _YY2, _T1};
fail -> fail
end
end.
@@ -520,9 +485,9 @@ option() ->
(_) -> fail
end,
'__repeat'(0, infinity,
- fun ([C | Tl]) when (C >= 32) and (C =< 61) ->
+ fun ([C | Tl]) when (C >= 63) and (C =< 126) ->
{ok, C, Tl};
- ([C | Tl]) when (C >= 63) and (C =< 126) ->
+ ([C | Tl]) when (C >= 32) and (C =< 61) ->
{ok, C, Tl};
(_) -> fail
end),
@@ -540,44 +505,42 @@ option() ->
end
end.
-'__alt'([P | Ps]) ->
- fun (T) ->
- case P(T) of
- {ok, _R, _T1} = Res -> Res;
- fail ->
- case Ps of
- [] -> fail;
- _ -> ('__alt'(Ps))(T)
- end
- end
- end.
+'__alt'(Ps) -> fun (T) -> '__do_alt'(Ps, T) end.
+
+'__do_alt'([P | Ps], T) ->
+ case P(T) of
+ {ok, _R, _T1} = Res -> Res;
+ fail -> '__do_alt'(Ps, T)
+ end;
+'__do_alt'([], _) -> fail.
'__repeat'(Min, Max, P) -> '__repeat'(Min, Max, P, 0).
'__repeat'(Min, Max, P, Found) ->
- fun (T) ->
- case P(T) of
- {ok, R1, T1} when Max == Found + 1 -> {ok, [R1], T1};
- {ok, R1, T1} ->
- case ('__repeat'(Min, Max, P, Found + 1))(T1) of
- {ok, R2, T2} -> {ok, [R1 | R2], T2};
- fail when Found >= Min -> {ok, [R1], T1};
- fail -> fail
- end;
- fail when Found >= Min -> {ok, [], T};
- fail -> fail
- end
+ fun (T) -> '__do_repeat'(Min, Max, P, Found, T) end.
+
+'__do_repeat'(Min, Max, P, Found, T) ->
+ case P(T) of
+ {ok, R1, T1} when Max == Found + 1 -> {ok, [R1], T1};
+ {ok, R1, T1} ->
+ case '__do_repeat'(Min, Max, P, Found + 1, T1) of
+ {ok, R2, T2} -> {ok, [R1 | R2], T2};
+ fail when Found >= Min -> {ok, [R1], T1};
+ fail -> fail
+ end;
+ fail when Found >= Min -> {ok, [], T};
+ fail -> fail
end.
-'__seq'([P | Ps]) ->
- fun (T) ->
- case P(T) of
- {ok, R1, T1} ->
- case ('__seq'(Ps))(T1) of
- {ok, R2, T2} -> {ok, [R1 | R2], T2};
- fail -> fail
- end;
- fail -> fail
- end
+'__seq'(Ps) -> fun (T) -> '__do_seq'(Ps, T) end.
+
+'__do_seq'([P | Ps], T) ->
+ case P(T) of
+ {ok, R1, T1} ->
+ case '__do_seq'(Ps, T1) of
+ {ok, R2, T2} -> {ok, [R1 | R2], T2};
+ fail -> fail
+ end;
+ fail -> fail
end;
-'__seq'([]) -> fun (T) -> {ok, [], T} end.
+'__do_seq'([], T) -> {ok, [], T}.
View
242 src/rfc4234_core.erl
@@ -1,6 +1,6 @@
%%% Do not modify this file, it is automatically generated by abnfc.
%%% All changes will be lost when it is regenerated.
-%%% Generated by abnfc_gen on 2010-12-15 00:05:09
+%%% Generated by abnfc_gen on 2012-01-25 18:56:43
-module(rfc4234_core).
@@ -29,194 +29,146 @@ decode('VCHAR', Str) -> ('VCHAR'())(Str);
decode('WSP', Str) -> ('WSP'())(Str).
'ALPHA'() ->
- fun (T) ->
- __P = fun ([C | Tl]) when (C >= 65) and (C =< 90) ->
- {ok, C, Tl};
- ([C | Tl]) when (C >= 97) and (C =< 122) -> {ok, C, Tl};
- (_) -> fail
- end,
- __P(T)
+ fun ([C | Tl]) when (C >= 65) and (C =< 90) ->
+ {ok, C, Tl};
+ ([C | Tl]) when (C >= 97) and (C =< 122) -> {ok, C, Tl};
+ (_) -> fail
end.
'BIT'() ->
- fun (T) ->
- __P = fun ([C | Tl]) when (C >= 48) and (C =< 49) ->
- {ok, C, Tl};
- (_) -> fail
- end,
- __P(T)
+ fun ([C | Tl]) when (C >= 48) and (C =< 49) ->
+ {ok, C, Tl};
+ (_) -> fail
end.
'CHAR'() ->
- fun (T) ->
- __P = fun ([C | Tl]) when (C >= 1) and (C =< 127) ->
- {ok, C, Tl};
- (_) -> fail
- end,
- __P(T)
+ fun ([C | Tl]) when (C >= 1) and (C =< 127) ->
+ {ok, C, Tl};
+ (_) -> fail
end.
'CR'() ->
- fun (T) ->
- __P = fun ([13 | Tl]) -> {ok, 13, Tl};
- (_) -> fail
- end,
- __P(T)
+ fun ([13 | Tl]) -> {ok, 13, Tl};
+ (_) -> fail
end.
'CRLF'() ->
- fun (T) ->
- __P = '__alt'(['LF'(), '__seq'(['CR'(), 'LF'()])]),
- __P(T)
- end.
+ '__alt'(['LF'(), '__seq'(['CR'(), 'LF'()])]).
'CTL'() ->
- fun (T) ->
- __P = fun ([C | Tl]) when C == 127 -> {ok, C, Tl};
- ([C | Tl]) when (C >= 0) and (C =< 31) -> {ok, C, Tl};
- (_) -> fail
- end,
- __P(T)
+ fun ([C | Tl]) when (C >= 0) and (C =< 31) ->
+ {ok, C, Tl};
+ ([C | Tl]) when C == 127 -> {ok, C, Tl};
+ (_) -> fail
end.
'DIGIT'() ->
- fun (T) ->
- __P = fun ([C | Tl]) when (C >= 48) and (C =< 57) ->
- {ok, C, Tl};
- (_) -> fail
- end,
- __P(T)
+ fun ([C | Tl]) when (C >= 48) and (C =< 57) ->
+ {ok, C, Tl};
+ (_) -> fail
end.
'DQUOTE'() ->
- fun (T) ->
- __P = fun ([34 | Tl]) -> {ok, 34, Tl};
- (_) -> fail
- end,
- __P(T)
+ fun ([34 | Tl]) -> {ok, 34, Tl};
+ (_) -> fail
end.
'HEXDIG'() ->
- fun (T) ->
- __P = '__alt'(['DIGIT'(),
- fun ([C | Tl]) when C == 97 -> {ok, C, Tl};
- ([C | Tl]) when C == 65 -> {ok, C, Tl};
- (_) -> fail
- end,
- fun ([C | Tl]) when C == 98 -> {ok, C, Tl};
- ([C | Tl]) when C == 66 -> {ok, C, Tl};
- (_) -> fail
- end,
- fun ([C | Tl]) when C == 99 -> {ok, C, Tl};
- ([C | Tl]) when C == 67 -> {ok, C, Tl};
- (_) -> fail
- end,
- fun ([C | Tl]) when C == 100 -> {ok, C, Tl};
- ([C | Tl]) when C == 68 -> {ok, C, Tl};
- (_) -> fail
- end,
- fun ([C | Tl]) when C == 101 -> {ok, C, Tl};
- ([C | Tl]) when C == 69 -> {ok, C, Tl};
- (_) -> fail
- end,
- fun ([C | Tl]) when C == 102 -> {ok, C, Tl};
- ([C | Tl]) when C == 70 -> {ok, C, Tl};
- (_) -> fail
- end]),
- __P(T)
- end.
+ '__alt'(['DIGIT'(),
+ fun ([C | Tl]) when C == 97 -> {ok, C, Tl};
+ ([C | Tl]) when C == 65 -> {ok, C, Tl};
+ (_) -> fail
+ end,
+ fun ([C | Tl]) when C == 98 -> {ok, C, Tl};
+ ([C | Tl]) when C == 66 -> {ok, C, Tl};
+ (_) -> fail
+ end,
+ fun ([C | Tl]) when C == 99 -> {ok, C, Tl};
+ ([C | Tl]) when C == 67 -> {ok, C, Tl};
+ (_) -> fail
+ end,
+ fun ([C | Tl]) when C == 100 -> {ok, C, Tl};
+ ([C | Tl]) when C == 68 -> {ok, C, Tl};
+ (_) -> fail
+ end,
+ fun ([C | Tl]) when C == 101 -> {ok, C, Tl};
+ ([C | Tl]) when C == 69 -> {ok, C, Tl};
+ (_) -> fail
+ end,
+ fun ([C | Tl]) when C == 102 -> {ok, C, Tl};
+ ([C | Tl]) when C == 70 -> {ok, C, Tl};
+ (_) -> fail
+ end]).
'HTAB'() ->
- fun (T) ->
- __P = fun ([9 | Tl]) -> {ok, 9, Tl};
- (_) -> fail
- end,
- __P(T)
+ fun ([9 | Tl]) -> {ok, 9, Tl};
+ (_) -> fail
end.
'LF'() ->
- fun (T) ->
- __P = fun ([10 | Tl]) -> {ok, 10, Tl};
- (_) -> fail
- end,
- __P(T)
+ fun ([10 | Tl]) -> {ok, 10, Tl};
+ (_) -> fail
end.
'LWSP'() ->
- fun (T) ->
- __P = '__repeat'(0, infinity,
- '__alt'(['WSP'(), '__seq'(['CRLF'(), 'WSP'()])])),
- __P(T)
- end.
+ '__repeat'(0, infinity,
+ '__alt'(['WSP'(), '__seq'(['CRLF'(), 'WSP'()])])).
'OCTET'() ->
- fun (T) ->
- __P = fun ([C | Tl]) when (C >= 0) and (C =< 255) ->
- {ok, C, Tl};
- (_) -> fail
- end,
- __P(T)
+ fun ([C | Tl]) when (C >= 0) and (C =< 255) ->
+ {ok, C, Tl};
+ (_) -> fail
end.
'SP'() ->
- fun (T) ->
- __P = fun ([32 | Tl]) -> {ok, 32, Tl};
- (_) -> fail
- end,
- __P(T)
+ fun ([32 | Tl]) -> {ok, 32, Tl};
+ (_) -> fail
end.
'VCHAR'() ->
- fun (T) ->
- __P = fun ([C | Tl]) when (C >= 33) and (C =< 126) ->
- {ok, C, Tl};
- (_) -> fail
- end,
- __P(T)
+ fun ([C | Tl]) when (C >= 33) and (C =< 126) ->
+ {ok, C, Tl};
+ (_) -> fail
end.
-'WSP'() ->
- fun (T) -> __P = '__alt'(['SP'(), 'HTAB'()]), __P(T)
- end.
+'WSP'() -> '__alt'(['SP'(), 'HTAB'()]).
-'__alt'([P | Ps]) ->
- fun (T) ->
- case P(T) of
- {ok, _R, _T1} = Res -> Res;
- fail ->
- case Ps of
- [] -> fail;
- _ -> ('__alt'(Ps))(T)
- end
- end
- end.
+'__alt'(Ps) -> fun (T) -> '__do_alt'(Ps, T) end.
+
+'__do_alt'([P | Ps], T) ->
+ case P(T) of
+ {ok, _R, _T1} = Res -> Res;
+ fail -> '__do_alt'(Ps, T)
+ end;
+'__do_alt'([], _) -> fail.
'__repeat'(Min, Max, P) -> '__repeat'(Min, Max, P, 0).
'__repeat'(Min, Max, P, Found) ->
- fun (T) ->
- case P(T) of
- {ok, R1, T1} when Max == Found + 1 -> {ok, [R1], T1};
- {ok, R1, T1} ->
- case ('__repeat'(Min, Max, P, Found + 1))(T1) of
- {ok, R2, T2} -> {ok, [R1 | R2], T2};
- fail when Found >= Min -> {ok, [R1], T1};
- fail -> fail
- end;
- fail when Found >= Min -> {ok, [], T};
- fail -> fail
- end
- end.
-
-'__seq'([P | Ps]) ->
- fun (T) ->
- case P(T) of
- {ok, R1, T1} ->
- case ('__seq'(Ps))(T1) of
- {ok, R2, T2} -> {ok, [R1 | R2], T2};
- fail -> fail
- end;
- fail -> fail
- end
+ fun (T) -> '__do_repeat'(Min, Max, P, Found, T) end.
+
+'__do_repeat'(Min, Max, P, Found, T) ->
+ case P(T) of
+ {ok, R1, T1} when Max == Found + 1 -> {ok, [R1], T1};
+ {ok, R1, T1} ->
+ case '__do_repeat'(Min, Max, P, Found + 1, T1) of
+ {ok, R2, T2} -> {ok, [R1 | R2], T2};
+ fail when Found >= Min -> {ok, [R1], T1};
+ fail -> fail
+ end;
+ fail when Found >= Min -> {ok, [], T};
+ fail -> fail
+ end.
+
+'__seq'(Ps) -> fun (T) -> '__do_seq'(Ps, T) end.
+
+'__do_seq'([P | Ps], T) ->
+ case P(T) of
+ {ok, R1, T1} ->
+ case '__do_seq'(Ps, T1) of
+ {ok, R2, T2} -> {ok, [R1 | R2], T2};
+ fail -> fail
+ end;
+ fail -> fail
end;
-'__seq'([]) -> fun (T) -> {ok, [], T} end.
+'__do_seq'([], T) -> {ok, [], T}.

0 comments on commit 8450b3c

Please sign in to comment.
Something went wrong with that request. Please try again.