aboutsummaryrefslogtreecommitdiffstats
path: root/lib/asn1/src/asn1ct_parser2.erl
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2014-12-02 17:11:22 +0100
committerBjörn Gustavsson <[email protected]>2015-01-12 12:22:56 +0100
commitff8b523c9ad18d52c9ff53882bba0056f2ceb679 (patch)
tree3b4abbb7f802de1b9be97ad08ead8c2503da59ff /lib/asn1/src/asn1ct_parser2.erl
parent657fe1cdf9f0e630a3a66ddcad24f143df6e1880 (diff)
downloadotp-ff8b523c9ad18d52c9ff53882bba0056f2ceb679.tar.gz
otp-ff8b523c9ad18d52c9ff53882bba0056f2ceb679.tar.bz2
otp-ff8b523c9ad18d52c9ff53882bba0056f2ceb679.zip
asn1ct_parser2: Simplify parse_Type/1
The parse_Type/1 calls various type parse functions. Most of those functions return a #type record, but not all of them. If a #type{} record is not returned, parse_Type/1 will wrap the return value in a We can simplify the code in parse_Type/1 if we make sure that the type parsing functions called by parse_Type/1 always return a #type{} record.
Diffstat (limited to 'lib/asn1/src/asn1ct_parser2.erl')
-rw-r--r--lib/asn1/src/asn1ct_parser2.erl34
1 files changed, 12 insertions, 22 deletions
diff --git a/lib/asn1/src/asn1ct_parser2.erl b/lib/asn1/src/asn1ct_parser2.erl
index 4a576ce2d2..d368e149e3 100644
--- a/lib/asn1/src/asn1ct_parser2.erl
+++ b/lib/asn1/src/asn1ct_parser2.erl
@@ -393,22 +393,13 @@ parse_Type(Tokens) ->
Result ->
Result
end,
- case hd(Rest5) of
- {'(',_} ->
+ case Rest5 of
+ [{'(',_}|_] ->
{Constraints,Rest6} = parse_Constraints(Rest5),
- if is_record(Type,type) ->
- {Type#type{constraint=merge_constraints(Constraints),
- tag=Tag2},Rest6};
- true ->
- {#type{def=Type,constraint=merge_constraints(Constraints),
- tag=Tag2},Rest6}
- end;
- _ ->
- if is_record(Type,type) ->
- {Type#type{tag=Tag2},Rest5};
- true ->
- {#type{def=Type,tag=Tag2},Rest5}
- end
+ {Type#type{tag=Tag2,
+ constraint=merge_constraints(Constraints)},Rest6};
+ [_|_] ->
+ {Type#type{tag=Tag2},Rest5}
end.
parse_BuiltinType([{'BIT',_},{'STRING',_}|Rest]) ->
@@ -423,7 +414,7 @@ parse_BuiltinType([{'BIT',_},{'STRING',_}|Rest]) ->
[got,get_token(hd(Rest3)),expected,'}']}})
end;
_ ->
- {{'BIT STRING',[]},Rest}
+ {#type{def={'BIT STRING',[]}},Rest}
end;
parse_BuiltinType([{'BOOLEAN',_}|Rest]) ->
{#type{def='BOOLEAN'},Rest};
@@ -558,7 +549,7 @@ parse_BuiltinType([{'SEQUENCE',_},{'{',_}|Rest]) ->
parse_BuiltinType([{'SEQUENCE',_},{'OF',_},Id={identifier,_,_},Lt={'<',_}|Rest]) ->
%% TODO: take care of the identifier for something useful
{Type,Rest2} = parse_SelectionType([Id,Lt|Rest]),
- {#type{def={'SEQUENCE OF',#type{def=Type,tag=[]}}},Rest2};
+ {#type{def={'SEQUENCE OF',Type}},Rest2};
parse_BuiltinType([{'SEQUENCE',_},{'OF',_},{identifier,_,_} |Rest]) ->
%% TODO: take care of the identifier for something useful
@@ -604,8 +595,7 @@ parse_BuiltinType([{'SET',_},{'{',_}|Rest]) ->
parse_BuiltinType([{'SET',_},{'OF',_},Id={identifier,_,_},Lt={'<',_}|Rest]) ->
%% TODO: take care of the identifier for something useful
{Type,Rest2} = parse_SelectionType([Id,Lt|Rest]),
- {#type{def={'SET OF',#type{def=Type,tag=[]}}},Rest2};
-
+ {#type{def={'SET OF',Type}},Rest2};
parse_BuiltinType([{'SET',_},{'OF',_},{identifier,_,_}|Rest]) ->
%%TODO: take care of the identifier for something useful
@@ -763,7 +753,7 @@ parse_DefinedType(Tokens) ->
parse_SelectionType([{identifier,_,Name},{'<',_}|Rest]) ->
{Type,Rest2} = parse_Type(Rest),
- {{'SelectionType',Name,Type},Rest2};
+ {#type{def={'SelectionType',Name,Type}},Rest2};
parse_SelectionType(Tokens) ->
throw({asn1_error,{get_line(hd(Tokens)),get(asn1_module),
[got,get_token(hd(Tokens)),expected,'identifier <']}}).
@@ -1700,7 +1690,7 @@ parse_TypeFromObject(Tokens) ->
{Name,Rest3} = parse_FieldName(Rest2),
case lists:last(Name) of
{typefieldreference,_FieldName} ->
- {{'TypeFromObject',Objects,Name},Rest3};
+ {#type{def={'TypeFromObject',Objects,Name}},Rest3};
_ ->
throw({asn1_error,{get_line(hd(Rest2)),get(asn1_module),
[got,get_token(hd(Rest2)),expected,
@@ -2169,7 +2159,7 @@ parse_SimpleDefinedValue(Tokens) ->
parse_ParameterizedType(Tokens) ->
{Type,Rest} = parse_SimpleDefinedType(Tokens),
{Params,Rest2} = parse_ActualParameterList(Rest),
- {{pt,Type,Params},Rest2}.
+ {#type{def={pt,Type,Params}},Rest2}.
parse_ParameterizedValue(Tokens) ->
{Value,Rest} = parse_SimpleDefinedValue(Tokens),