Fix data_type_or_implicit
This commit is contained in:
parent
bdddb4a8ce
commit
2a36aad0cc
@ -11,7 +11,6 @@ trace = ["nom-tracable/trace"]
|
||||
[dependencies]
|
||||
nom = "5.0.0"
|
||||
nom_locate = "0.4.0"
|
||||
nom-both = {path = "../../nom-both/nom-both"}
|
||||
nom-packrat = {path = "../../nom-packrat/nom-packrat"}
|
||||
nom-recursive = {path = "../../nom-recursive/nom-recursive"}
|
||||
nom-tracable = {path = "../../nom-tracable/nom-tracable"}
|
||||
|
@ -234,12 +234,11 @@ pub(crate) fn property_port_list(s: Span) -> IResult<Span, PropertyPortList> {
|
||||
Ok((s, PropertyPortList { nodes: (a,) }))
|
||||
}
|
||||
|
||||
#[both_parser]
|
||||
#[tracable_parser]
|
||||
pub(crate) fn property_port_item(s: Span) -> IResult<Span, PropertyPortItem> {
|
||||
let (s, a) = many0(attribute_instance)(s)?;
|
||||
let (s, b) = opt(pair(local, opt(property_lvar_port_direction)))(s)?;
|
||||
let (s, c) = both_opt(property_formal_type)(s)?;
|
||||
let (s, c) = property_formal_type(s)?;
|
||||
let (s, d) = formal_port_identifier(s)?;
|
||||
let (s, e) = many0(variable_dimension)(s)?;
|
||||
let (s, f) = opt(pair(symbol("="), property_actual_arg))(s)?;
|
||||
@ -724,12 +723,11 @@ pub(crate) fn sequence_port_list(s: Span) -> IResult<Span, SequencePortList> {
|
||||
Ok((s, SequencePortList { nodes: (a,) }))
|
||||
}
|
||||
|
||||
#[both_parser]
|
||||
#[tracable_parser]
|
||||
pub(crate) fn sequence_port_item(s: Span) -> IResult<Span, SequencePortItem> {
|
||||
let (s, a) = many0(attribute_instance)(s)?;
|
||||
let (s, b) = opt(pair(local, opt(sequence_lvar_port_direction)))(s)?;
|
||||
let (s, c) = both_opt(sequence_formal_type)(s)?;
|
||||
let (s, c) = sequence_formal_type(s)?;
|
||||
let (s, d) = formal_port_identifier(s)?;
|
||||
let (s, e) = many0(variable_dimension)(s)?;
|
||||
let (s, f) = opt(pair(symbol("="), sequence_actual_arg))(s)?;
|
||||
@ -759,7 +757,7 @@ pub(crate) fn sequence_lvar_port_direction(s: Span) -> IResult<Span, SequenceLva
|
||||
#[tracable_parser]
|
||||
pub(crate) fn sequence_formal_type(s: Span) -> IResult<Span, SequenceFormalType> {
|
||||
alt((
|
||||
map(data_type_or_implicit, |x| {
|
||||
map(data_type_or_implicit_sequence_formal_type, |x| {
|
||||
SequenceFormalType::DataTypeOrImplicit(Box::new(x))
|
||||
}),
|
||||
map(keyword("sequence"), |x| {
|
||||
@ -771,6 +769,21 @@ pub(crate) fn sequence_formal_type(s: Span) -> IResult<Span, SequenceFormalType>
|
||||
))(s)
|
||||
}
|
||||
|
||||
#[tracable_parser]
|
||||
pub(crate) fn data_type_or_implicit_sequence_formal_type(
|
||||
s: Span,
|
||||
) -> IResult<Span, DataTypeOrImplicit> {
|
||||
alt((
|
||||
map(terminated(data_type, peek(formal_port_identifier)), |x| {
|
||||
DataTypeOrImplicit::DataType(Box::new(x))
|
||||
}),
|
||||
map(
|
||||
terminated(implicit_data_type, peek(formal_port_identifier)),
|
||||
|x| DataTypeOrImplicit::ImplicitDataType(Box::new(x)),
|
||||
),
|
||||
))(s)
|
||||
}
|
||||
|
||||
#[tracable_parser]
|
||||
pub(crate) fn sequence_expr(s: Span) -> IResult<Span, SequenceExpr> {
|
||||
alt((
|
||||
|
@ -206,11 +206,10 @@ pub(crate) fn hierarchical_identifier_or_class_scope(
|
||||
))(s)
|
||||
}
|
||||
|
||||
#[both_parser]
|
||||
#[tracable_parser]
|
||||
pub(crate) fn cover_point(s: Span) -> IResult<Span, CoverPoint> {
|
||||
let (s, a) = opt(triple(
|
||||
both_opt(data_type_or_implicit),
|
||||
opt(data_type_or_implicit_cover_point),
|
||||
cover_point_identifier,
|
||||
symbol(":"),
|
||||
))(s)?;
|
||||
@ -226,6 +225,19 @@ pub(crate) fn cover_point(s: Span) -> IResult<Span, CoverPoint> {
|
||||
))
|
||||
}
|
||||
|
||||
#[tracable_parser]
|
||||
pub(crate) fn data_type_or_implicit_cover_point(s: Span) -> IResult<Span, DataTypeOrImplicit> {
|
||||
alt((
|
||||
map(terminated(data_type, peek(cover_point_identifier)), |x| {
|
||||
DataTypeOrImplicit::DataType(Box::new(x))
|
||||
}),
|
||||
map(
|
||||
terminated(implicit_data_type, peek(cover_point_identifier)),
|
||||
|x| DataTypeOrImplicit::ImplicitDataType(Box::new(x)),
|
||||
),
|
||||
))(s)
|
||||
}
|
||||
|
||||
#[tracable_parser]
|
||||
pub(crate) fn bins_or_empty(s: Span) -> IResult<Span, BinsOrEmpty> {
|
||||
alt((
|
||||
|
@ -5,12 +5,26 @@ use crate::*;
|
||||
#[tracable_parser]
|
||||
pub(crate) fn function_data_type_or_implicit(s: Span) -> IResult<Span, FunctionDataTypeOrImplicit> {
|
||||
alt((
|
||||
map(data_type_or_void, |x| {
|
||||
FunctionDataTypeOrImplicit::DataTypeOrVoid(Box::new(x))
|
||||
}),
|
||||
map(implicit_data_type, |x| {
|
||||
FunctionDataTypeOrImplicit::ImplicitDataType(Box::new(x))
|
||||
}),
|
||||
map(
|
||||
terminated(
|
||||
data_type_or_void,
|
||||
peek(pair(
|
||||
opt(interface_identifier_or_class_scope),
|
||||
function_identifier,
|
||||
)),
|
||||
),
|
||||
|x| FunctionDataTypeOrImplicit::DataTypeOrVoid(Box::new(x)),
|
||||
),
|
||||
map(
|
||||
terminated(
|
||||
implicit_data_type,
|
||||
peek(pair(
|
||||
opt(interface_identifier_or_class_scope),
|
||||
function_identifier,
|
||||
)),
|
||||
),
|
||||
|x| FunctionDataTypeOrImplicit::ImplicitDataType(Box::new(x)),
|
||||
),
|
||||
))(s)
|
||||
}
|
||||
|
||||
@ -30,12 +44,11 @@ pub(crate) fn function_body_declaration(s: Span) -> IResult<Span, FunctionBodyDe
|
||||
))(s)
|
||||
}
|
||||
|
||||
#[both_parser]
|
||||
#[tracable_parser]
|
||||
pub(crate) fn function_body_declaration_without_port(
|
||||
s: Span,
|
||||
) -> IResult<Span, FunctionBodyDeclaration> {
|
||||
let (s, a) = both_opt(function_data_type_or_implicit)(s)?;
|
||||
let (s, a) = function_data_type_or_implicit(s)?;
|
||||
let (s, b) = opt(interface_identifier_or_class_scope)(s)?;
|
||||
let (s, c) = function_identifier(s)?;
|
||||
let (s, d) = symbol(";")(s)?;
|
||||
@ -51,12 +64,11 @@ pub(crate) fn function_body_declaration_without_port(
|
||||
))
|
||||
}
|
||||
|
||||
#[both_parser]
|
||||
#[tracable_parser]
|
||||
pub(crate) fn function_body_declaration_with_port(
|
||||
s: Span,
|
||||
) -> IResult<Span, FunctionBodyDeclaration> {
|
||||
let (s, a) = both_opt(function_data_type_or_implicit)(s)?;
|
||||
let (s, a) = function_data_type_or_implicit(s)?;
|
||||
let (s, b) = opt(interface_identifier_or_class_scope)(s)?;
|
||||
let (s, c) = function_identifier(s)?;
|
||||
let (s, d) = paren(opt(tf_port_list))(s)?;
|
||||
|
@ -30,11 +30,10 @@ pub(crate) fn let_port_list(s: Span) -> IResult<Span, LetPortList> {
|
||||
Ok((s, LetPortList { nodes: (a,) }))
|
||||
}
|
||||
|
||||
#[both_parser]
|
||||
#[tracable_parser]
|
||||
pub(crate) fn let_port_item(s: Span) -> IResult<Span, LetPortItem> {
|
||||
let (s, a) = many0(attribute_instance)(s)?;
|
||||
let (s, b) = both_opt(let_formal_type)(s)?;
|
||||
let (s, b) = let_formal_type(s)?;
|
||||
let (s, c) = formal_port_identifier(s)?;
|
||||
let (s, d) = many0(variable_dimension)(s)?;
|
||||
let (s, e) = opt(pair(symbol("="), expression))(s)?;
|
||||
@ -49,13 +48,26 @@ pub(crate) fn let_port_item(s: Span) -> IResult<Span, LetPortItem> {
|
||||
#[tracable_parser]
|
||||
pub(crate) fn let_formal_type(s: Span) -> IResult<Span, LetFormalType> {
|
||||
alt((
|
||||
map(data_type_or_implicit, |x| {
|
||||
map(data_type_or_implicit_let_formal_type, |x| {
|
||||
LetFormalType::DataTypeOrImplicit(Box::new(x))
|
||||
}),
|
||||
map(keyword("untyped"), |x| LetFormalType::Untyped(Box::new(x))),
|
||||
))(s)
|
||||
}
|
||||
|
||||
#[tracable_parser]
|
||||
pub(crate) fn data_type_or_implicit_let_formal_type(s: Span) -> IResult<Span, DataTypeOrImplicit> {
|
||||
alt((
|
||||
map(terminated(data_type, peek(formal_port_identifier)), |x| {
|
||||
DataTypeOrImplicit::DataType(Box::new(x))
|
||||
}),
|
||||
map(
|
||||
terminated(implicit_data_type, peek(formal_port_identifier)),
|
||||
|x| DataTypeOrImplicit::ImplicitDataType(Box::new(x)),
|
||||
),
|
||||
))(s)
|
||||
}
|
||||
|
||||
#[tracable_parser]
|
||||
pub(crate) fn let_expression(s: Span) -> IResult<Span, LetExpression> {
|
||||
let (s, a) = opt(package_scope)(s)?;
|
||||
|
@ -10,13 +10,12 @@ pub(crate) fn local_parameter_declaration(s: Span) -> IResult<Span, LocalParamet
|
||||
))(s)
|
||||
}
|
||||
|
||||
#[both_parser]
|
||||
#[tracable_parser]
|
||||
pub(crate) fn local_parameter_declaration_param(
|
||||
s: Span,
|
||||
) -> IResult<Span, LocalParameterDeclaration> {
|
||||
let (s, a) = keyword("localparam")(s)?;
|
||||
let (s, b) = both_opt(data_type_or_implicit)(s)?;
|
||||
let (s, b) = data_type_or_implicit_local_parameter_declaration_param(s)?;
|
||||
let (s, c) = list_of_param_assignments(s)?;
|
||||
Ok((
|
||||
s,
|
||||
@ -26,6 +25,21 @@ pub(crate) fn local_parameter_declaration_param(
|
||||
))
|
||||
}
|
||||
|
||||
#[tracable_parser]
|
||||
pub(crate) fn data_type_or_implicit_local_parameter_declaration_param(
|
||||
s: Span,
|
||||
) -> IResult<Span, DataTypeOrImplicit> {
|
||||
alt((
|
||||
map(terminated(data_type, peek(param_assignment)), |x| {
|
||||
DataTypeOrImplicit::DataType(Box::new(x))
|
||||
}),
|
||||
map(
|
||||
terminated(implicit_data_type, peek(param_assignment)),
|
||||
|x| DataTypeOrImplicit::ImplicitDataType(Box::new(x)),
|
||||
),
|
||||
))(s)
|
||||
}
|
||||
|
||||
#[tracable_parser]
|
||||
pub(crate) fn local_parameter_declaration_type(
|
||||
s: Span,
|
||||
@ -46,11 +60,10 @@ pub(crate) fn parameter_declaration(s: Span) -> IResult<Span, ParameterDeclarati
|
||||
alt((parameter_declaration_param, parameter_declaration_type))(s)
|
||||
}
|
||||
|
||||
#[both_parser]
|
||||
#[tracable_parser]
|
||||
pub(crate) fn parameter_declaration_param(s: Span) -> IResult<Span, ParameterDeclaration> {
|
||||
let (s, a) = keyword("parameter")(s)?;
|
||||
let (s, b) = both_opt(data_type_or_implicit)(s)?;
|
||||
let (s, b) = data_type_or_implicit_parameter_declaration_param(s)?;
|
||||
let (s, c) = list_of_param_assignments(s)?;
|
||||
Ok((
|
||||
s,
|
||||
@ -58,6 +71,21 @@ pub(crate) fn parameter_declaration_param(s: Span) -> IResult<Span, ParameterDec
|
||||
))
|
||||
}
|
||||
|
||||
#[tracable_parser]
|
||||
pub(crate) fn data_type_or_implicit_parameter_declaration_param(
|
||||
s: Span,
|
||||
) -> IResult<Span, DataTypeOrImplicit> {
|
||||
alt((
|
||||
map(terminated(data_type, peek(param_assignment)), |x| {
|
||||
DataTypeOrImplicit::DataType(Box::new(x))
|
||||
}),
|
||||
map(
|
||||
terminated(implicit_data_type, peek(param_assignment)),
|
||||
|x| DataTypeOrImplicit::ImplicitDataType(Box::new(x)),
|
||||
),
|
||||
))(s)
|
||||
}
|
||||
|
||||
#[tracable_parser]
|
||||
pub(crate) fn parameter_declaration_type(s: Span) -> IResult<Span, ParameterDeclaration> {
|
||||
let (s, a) = keyword("parameter")(s)?;
|
||||
|
@ -121,6 +121,8 @@ pub(crate) fn data_type_type(s: Span) -> IResult<Span, DataType> {
|
||||
))
|
||||
}
|
||||
|
||||
// all data_type_or_implicit call are specialized for each parser
|
||||
#[allow(dead_code)]
|
||||
#[tracable_parser]
|
||||
pub(crate) fn data_type_or_implicit(s: Span) -> IResult<Span, DataTypeOrImplicit> {
|
||||
alt((
|
||||
@ -293,13 +295,27 @@ pub(crate) fn net_port_type(s: Span) -> IResult<Span, NetPortType> {
|
||||
#[tracable_parser]
|
||||
pub(crate) fn net_port_type_data_type(s: Span) -> IResult<Span, NetPortType> {
|
||||
let (s, a) = opt(net_type)(s)?;
|
||||
let (s, b) = data_type_or_implicit(s)?;
|
||||
let (s, b) = data_type_or_implicit_net_port_type_data_type(s)?;
|
||||
Ok((
|
||||
s,
|
||||
NetPortType::DataType(Box::new(NetPortTypeDataType { nodes: (a, b) })),
|
||||
))
|
||||
}
|
||||
|
||||
#[tracable_parser]
|
||||
pub(crate) fn data_type_or_implicit_net_port_type_data_type(
|
||||
s: Span,
|
||||
) -> IResult<Span, DataTypeOrImplicit> {
|
||||
alt((
|
||||
map(terminated(data_type, peek(port_identifier)), |x| {
|
||||
DataTypeOrImplicit::DataType(Box::new(x))
|
||||
}),
|
||||
map(terminated(implicit_data_type, peek(port_identifier)), |x| {
|
||||
DataTypeOrImplicit::ImplicitDataType(Box::new(x))
|
||||
}),
|
||||
))(s)
|
||||
}
|
||||
|
||||
#[tracable_parser]
|
||||
pub(crate) fn net_port_type_interconnect(s: Span) -> IResult<Span, NetPortType> {
|
||||
let (s, a) = keyword("interconnect")(s)?;
|
||||
@ -319,7 +335,9 @@ pub(crate) fn variable_port_type(s: Span) -> IResult<Span, VariablePortType> {
|
||||
#[tracable_parser]
|
||||
pub(crate) fn var_data_type(s: Span) -> IResult<Span, VarDataType> {
|
||||
alt((
|
||||
map(data_type, |x| VarDataType::DataType(Box::new(x))),
|
||||
map(terminated(data_type, peek(variable_identifier)), |x| {
|
||||
VarDataType::DataType(Box::new(x))
|
||||
}),
|
||||
var_data_type_var,
|
||||
))(s)
|
||||
}
|
||||
@ -327,13 +345,28 @@ pub(crate) fn var_data_type(s: Span) -> IResult<Span, VarDataType> {
|
||||
#[tracable_parser]
|
||||
pub(crate) fn var_data_type_var(s: Span) -> IResult<Span, VarDataType> {
|
||||
let (s, a) = keyword("var")(s)?;
|
||||
let (s, b) = data_type_or_implicit(s)?;
|
||||
let (s, b) = data_type_or_implicit_var_data_type_var(s)?;
|
||||
Ok((
|
||||
s,
|
||||
VarDataType::Var(Box::new(VarDataTypeVar { nodes: (a, b) })),
|
||||
))
|
||||
}
|
||||
|
||||
#[tracable_parser]
|
||||
pub(crate) fn data_type_or_implicit_var_data_type_var(
|
||||
s: Span,
|
||||
) -> IResult<Span, DataTypeOrImplicit> {
|
||||
alt((
|
||||
map(terminated(data_type, peek(variable_identifier)), |x| {
|
||||
DataTypeOrImplicit::DataType(Box::new(x))
|
||||
}),
|
||||
map(
|
||||
terminated(implicit_data_type, peek(variable_identifier)),
|
||||
|x| DataTypeOrImplicit::ImplicitDataType(Box::new(x)),
|
||||
),
|
||||
))(s)
|
||||
}
|
||||
|
||||
#[tracable_parser]
|
||||
pub(crate) fn signing(s: Span) -> IResult<Span, Signing> {
|
||||
alt((
|
||||
|
@ -2,11 +2,10 @@ use crate::*;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#[both_parser]
|
||||
#[tracable_parser]
|
||||
pub(crate) fn inout_declaration(s: Span) -> IResult<Span, InoutDeclaration> {
|
||||
let (s, a) = keyword("inout")(s)?;
|
||||
let (s, b) = both_opt(net_port_type)(s)?;
|
||||
let (s, b) = net_port_type(s)?;
|
||||
let (s, c) = list_of_port_identifiers(s)?;
|
||||
Ok((s, InoutDeclaration { nodes: (a, b, c) }))
|
||||
}
|
||||
@ -16,11 +15,10 @@ pub(crate) fn input_declaration(s: Span) -> IResult<Span, InputDeclaration> {
|
||||
alt((input_declaration_net, input_declaration_variable))(s)
|
||||
}
|
||||
|
||||
#[both_parser]
|
||||
#[tracable_parser]
|
||||
pub(crate) fn input_declaration_net(s: Span) -> IResult<Span, InputDeclaration> {
|
||||
let (s, a) = keyword("input")(s)?;
|
||||
let (s, b) = both_opt(net_port_type)(s)?;
|
||||
let (s, b) = net_port_type(s)?;
|
||||
let (s, c) = list_of_port_identifiers(s)?;
|
||||
Ok((
|
||||
s,
|
||||
@ -28,11 +26,10 @@ pub(crate) fn input_declaration_net(s: Span) -> IResult<Span, InputDeclaration>
|
||||
))
|
||||
}
|
||||
|
||||
#[both_parser]
|
||||
#[tracable_parser]
|
||||
pub(crate) fn input_declaration_variable(s: Span) -> IResult<Span, InputDeclaration> {
|
||||
let (s, a) = keyword("input")(s)?;
|
||||
let (s, b) = both_alt(variable_port_type, implicit_var)(s)?;
|
||||
let (s, b) = variable_port_type(s)?;
|
||||
let (s, c) = list_of_variable_identifiers(s)?;
|
||||
Ok((
|
||||
s,
|
||||
@ -45,11 +42,10 @@ pub(crate) fn output_declaration(s: Span) -> IResult<Span, OutputDeclaration> {
|
||||
alt((output_declaration_net, output_declaration_variable))(s)
|
||||
}
|
||||
|
||||
#[both_parser]
|
||||
#[tracable_parser]
|
||||
pub(crate) fn output_declaration_net(s: Span) -> IResult<Span, OutputDeclaration> {
|
||||
let (s, a) = keyword("output")(s)?;
|
||||
let (s, b) = both_opt(net_port_type)(s)?;
|
||||
let (s, b) = net_port_type(s)?;
|
||||
let (s, c) = list_of_port_identifiers(s)?;
|
||||
Ok((
|
||||
s,
|
||||
@ -57,11 +53,10 @@ pub(crate) fn output_declaration_net(s: Span) -> IResult<Span, OutputDeclaration
|
||||
))
|
||||
}
|
||||
|
||||
#[both_parser]
|
||||
#[tracable_parser]
|
||||
pub(crate) fn output_declaration_variable(s: Span) -> IResult<Span, OutputDeclaration> {
|
||||
let (s, a) = keyword("output")(s)?;
|
||||
let (s, b) = both_alt(variable_port_type, implicit_var)(s)?;
|
||||
let (s, b) = variable_port_type(s)?;
|
||||
let (s, c) = list_of_variable_port_identifiers(s)?;
|
||||
Ok((
|
||||
s,
|
||||
@ -77,29 +72,10 @@ pub(crate) fn interface_port_declaration(s: Span) -> IResult<Span, InterfacePort
|
||||
Ok((s, InterfacePortDeclaration { nodes: (a, b, c) }))
|
||||
}
|
||||
|
||||
#[both_parser]
|
||||
#[tracable_parser]
|
||||
pub(crate) fn ref_declaration(s: Span) -> IResult<Span, RefDeclaration> {
|
||||
let (s, a) = keyword("ref")(s)?;
|
||||
let (s, b) = both_alt(variable_port_type, implicit_var)(s)?;
|
||||
let (s, b) = variable_port_type(s)?;
|
||||
let (s, c) = list_of_variable_identifiers(s)?;
|
||||
Ok((s, RefDeclaration { nodes: (a, b, c) }))
|
||||
}
|
||||
|
||||
#[tracable_parser]
|
||||
pub(crate) fn implicit_var(s: Span) -> IResult<Span, VariablePortType> {
|
||||
let (s, a) = keyword("var")(s)?;
|
||||
Ok((
|
||||
s,
|
||||
VariablePortType {
|
||||
nodes: (VarDataType::Var(Box::new(VarDataTypeVar {
|
||||
nodes: (
|
||||
a,
|
||||
DataTypeOrImplicit::ImplicitDataType(Box::new(ImplicitDataType {
|
||||
nodes: (None, vec![]),
|
||||
})),
|
||||
),
|
||||
})),),
|
||||
},
|
||||
))
|
||||
}
|
||||
|
@ -71,13 +71,12 @@ pub(crate) fn tf_port_list(s: Span) -> IResult<Span, TfPortList> {
|
||||
Ok((s, TfPortList { nodes: (a,) }))
|
||||
}
|
||||
|
||||
#[both_parser]
|
||||
#[tracable_parser]
|
||||
pub(crate) fn tf_port_item(s: Span) -> IResult<Span, TfPortItem> {
|
||||
let (s, a) = many0(attribute_instance)(s)?;
|
||||
let (s, b) = opt(tf_port_direction)(s)?;
|
||||
let (s, c) = opt(var)(s)?;
|
||||
let (s, d) = both_opt(data_type_or_implicit)(s)?;
|
||||
let (s, d) = data_type_or_implicit_tf_port_item(s)?;
|
||||
let (s, e) = opt(triple(
|
||||
port_identifier,
|
||||
many0(variable_dimension),
|
||||
@ -91,6 +90,40 @@ pub(crate) fn tf_port_item(s: Span) -> IResult<Span, TfPortItem> {
|
||||
))
|
||||
}
|
||||
|
||||
#[tracable_parser]
|
||||
pub(crate) fn data_type_or_implicit_tf_port_item(s: Span) -> IResult<Span, DataTypeOrImplicit> {
|
||||
alt((
|
||||
map(
|
||||
terminated(
|
||||
data_type,
|
||||
peek(pair(
|
||||
opt(triple(
|
||||
port_identifier,
|
||||
many0(variable_dimension),
|
||||
opt(pair(symbol(":"), expression)),
|
||||
)),
|
||||
alt((symbol(","), symbol(")"))),
|
||||
)),
|
||||
),
|
||||
|x| DataTypeOrImplicit::DataType(Box::new(x)),
|
||||
),
|
||||
map(
|
||||
terminated(
|
||||
implicit_data_type,
|
||||
peek(pair(
|
||||
opt(triple(
|
||||
port_identifier,
|
||||
many0(variable_dimension),
|
||||
opt(pair(symbol(":"), expression)),
|
||||
)),
|
||||
alt((symbol(","), symbol(")"))),
|
||||
)),
|
||||
),
|
||||
|x| DataTypeOrImplicit::ImplicitDataType(Box::new(x)),
|
||||
),
|
||||
))(s)
|
||||
}
|
||||
|
||||
#[tracable_parser]
|
||||
pub(crate) fn tf_port_direction(s: Span) -> IResult<Span, TfPortDirection> {
|
||||
alt((
|
||||
@ -103,13 +136,12 @@ pub(crate) fn tf_port_direction(s: Span) -> IResult<Span, TfPortDirection> {
|
||||
))(s)
|
||||
}
|
||||
|
||||
#[both_parser]
|
||||
#[tracable_parser]
|
||||
pub(crate) fn tf_port_declaration(s: Span) -> IResult<Span, TfPortDeclaration> {
|
||||
let (s, a) = many0(attribute_instance)(s)?;
|
||||
let (s, b) = tf_port_direction(s)?;
|
||||
let (s, c) = opt(var)(s)?;
|
||||
let (s, d) = both_opt(data_type_or_implicit)(s)?;
|
||||
let (s, d) = data_type_or_implicit_tf_port_declaration(s)?;
|
||||
let (s, e) = list_of_tf_variable_identifiers(s)?;
|
||||
let (s, f) = symbol(";")(s)?;
|
||||
Ok((
|
||||
@ -120,6 +152,21 @@ pub(crate) fn tf_port_declaration(s: Span) -> IResult<Span, TfPortDeclaration> {
|
||||
))
|
||||
}
|
||||
|
||||
#[tracable_parser]
|
||||
pub(crate) fn data_type_or_implicit_tf_port_declaration(
|
||||
s: Span,
|
||||
) -> IResult<Span, DataTypeOrImplicit> {
|
||||
alt((
|
||||
map(terminated(data_type, peek(variable_identifier)), |x| {
|
||||
DataTypeOrImplicit::DataType(Box::new(x))
|
||||
}),
|
||||
map(
|
||||
terminated(implicit_data_type, peek(variable_identifier)),
|
||||
|x| DataTypeOrImplicit::ImplicitDataType(Box::new(x)),
|
||||
),
|
||||
))(s)
|
||||
}
|
||||
|
||||
#[tracable_parser]
|
||||
pub(crate) fn task_prototype(s: Span) -> IResult<Span, TaskPrototype> {
|
||||
let (s, a) = keyword("task")(s)?;
|
||||
|
@ -18,13 +18,12 @@ pub(crate) fn data_declaration(s: Span) -> IResult<Span, DataDeclaration> {
|
||||
))(s)
|
||||
}
|
||||
|
||||
#[both_parser]
|
||||
#[tracable_parser]
|
||||
pub(crate) fn data_declaration_variable(s: Span) -> IResult<Span, DataDeclaration> {
|
||||
let (s, a) = opt(r#const)(s)?;
|
||||
let (s, b) = opt(var)(s)?;
|
||||
let (s, c) = opt(lifetime)(s)?;
|
||||
let (s, d) = both_opt(data_type_or_implicit)(s)?;
|
||||
let (s, d) = data_type_or_implicit_data_declaration_variable(s)?;
|
||||
let (s, e) = list_of_variable_decl_assignments(s)?;
|
||||
let (s, f) = symbol(";")(s)?;
|
||||
Ok((
|
||||
@ -35,6 +34,21 @@ pub(crate) fn data_declaration_variable(s: Span) -> IResult<Span, DataDeclaratio
|
||||
))
|
||||
}
|
||||
|
||||
#[tracable_parser]
|
||||
pub(crate) fn data_type_or_implicit_data_declaration_variable(
|
||||
s: Span,
|
||||
) -> IResult<Span, DataTypeOrImplicit> {
|
||||
alt((
|
||||
map(terminated(data_type, peek(variable_decl_assignment)), |x| {
|
||||
DataTypeOrImplicit::DataType(Box::new(x))
|
||||
}),
|
||||
map(
|
||||
terminated(implicit_data_type, peek(variable_decl_assignment)),
|
||||
|x| DataTypeOrImplicit::ImplicitDataType(Box::new(x)),
|
||||
),
|
||||
))(s)
|
||||
}
|
||||
|
||||
#[tracable_parser]
|
||||
pub(crate) fn r#const(s: Span) -> IResult<Span, Const> {
|
||||
let (s, a) = keyword("const")(s)?;
|
||||
@ -127,13 +141,12 @@ pub(crate) fn net_declaration(s: Span) -> IResult<Span, NetDeclaration> {
|
||||
))(s)
|
||||
}
|
||||
|
||||
#[both_parser]
|
||||
#[tracable_parser]
|
||||
pub(crate) fn net_declaration_net_type(s: Span) -> IResult<Span, NetDeclaration> {
|
||||
let (s, a) = net_type(s)?;
|
||||
let (s, b) = opt(strength)(s)?;
|
||||
let (s, c) = opt(vector_scalar)(s)?;
|
||||
let (s, d) = both_opt(data_type_or_implicit)(s)?;
|
||||
let (s, d) = data_type_or_implicit_net_declaration_net_type(s)?;
|
||||
let (s, e) = opt(delay3)(s)?;
|
||||
let (s, f) = list_of_net_decl_assignments(s)?;
|
||||
let (s, g) = symbol(";")(s)?;
|
||||
@ -145,6 +158,25 @@ pub(crate) fn net_declaration_net_type(s: Span) -> IResult<Span, NetDeclaration>
|
||||
))
|
||||
}
|
||||
|
||||
#[tracable_parser]
|
||||
pub(crate) fn data_type_or_implicit_net_declaration_net_type(
|
||||
s: Span,
|
||||
) -> IResult<Span, DataTypeOrImplicit> {
|
||||
alt((
|
||||
map(
|
||||
terminated(data_type, peek(pair(opt(delay3), net_decl_assignment))),
|
||||
|x| DataTypeOrImplicit::DataType(Box::new(x)),
|
||||
),
|
||||
map(
|
||||
terminated(
|
||||
implicit_data_type,
|
||||
peek(pair(opt(delay3), net_decl_assignment)),
|
||||
),
|
||||
|x| DataTypeOrImplicit::ImplicitDataType(Box::new(x)),
|
||||
),
|
||||
))(s)
|
||||
}
|
||||
|
||||
#[tracable_parser]
|
||||
pub(crate) fn strength(s: Span) -> IResult<Span, Strength> {
|
||||
alt((
|
||||
|
@ -31,7 +31,6 @@ pub(crate) use nom::error::{make_error, ErrorKind};
|
||||
pub(crate) use nom::multi::*;
|
||||
pub(crate) use nom::sequence::*;
|
||||
pub(crate) use nom::{Err, IResult};
|
||||
pub(crate) use nom_both::both_parser;
|
||||
pub(crate) use nom_packrat::{self, packrat_parser, HasExtraState};
|
||||
pub(crate) use nom_recursive::{recursive_parser, HasRecursiveInfo, RecursiveInfo};
|
||||
pub(crate) use nom_tracable::tracable_parser;
|
||||
|
@ -803,3 +803,18 @@ fn test_attribute_instance() {
|
||||
fn test_expression() {
|
||||
test!(expression, "(!a ? 0 : !b : 1 : c ? 0 : 1)", Ok((_, _)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_clause3() {
|
||||
test!(
|
||||
module_declaration,
|
||||
r##"module mux2to1 (input wire a, b, sel, // combined port and type declaration
|
||||
output logic y);
|
||||
always_comb begin // procedural block
|
||||
if (sel) y = a; // procedural statement
|
||||
else y = b;
|
||||
end
|
||||
endmodule: mux2to1"##,
|
||||
Ok((_, _))
|
||||
);
|
||||
}
|
||||
|
@ -129,7 +129,7 @@ pub struct PropertyPortItem {
|
||||
pub nodes: (
|
||||
Vec<AttributeInstance>,
|
||||
Option<(Local, Option<PropertyLvarPortDirection>)>,
|
||||
Option<PropertyFormalType>,
|
||||
PropertyFormalType,
|
||||
FormalPortIdentifier,
|
||||
Vec<VariableDimension>,
|
||||
Option<(Symbol, PropertyActualArg)>,
|
||||
@ -400,7 +400,7 @@ pub struct SequencePortItem {
|
||||
pub nodes: (
|
||||
Vec<AttributeInstance>,
|
||||
Option<(Local, Option<SequenceLvarPortDirection>)>,
|
||||
Option<SequenceFormalType>,
|
||||
SequenceFormalType,
|
||||
FormalPortIdentifier,
|
||||
Vec<VariableDimension>,
|
||||
Option<(Symbol, SequenceActualArg)>,
|
||||
|
@ -22,7 +22,7 @@ pub enum FunctionBodyDeclaration {
|
||||
#[derive(Clone, Debug, Node)]
|
||||
pub struct FunctionBodyDeclarationWithoutPort {
|
||||
pub nodes: (
|
||||
Option<FunctionDataTypeOrImplicit>,
|
||||
FunctionDataTypeOrImplicit,
|
||||
Option<InterfaceIdentifierOrClassScope>,
|
||||
FunctionIdentifier,
|
||||
Symbol,
|
||||
@ -36,7 +36,7 @@ pub struct FunctionBodyDeclarationWithoutPort {
|
||||
#[derive(Clone, Debug, Node)]
|
||||
pub struct FunctionBodyDeclarationWithPort {
|
||||
pub nodes: (
|
||||
Option<FunctionDataTypeOrImplicit>,
|
||||
FunctionDataTypeOrImplicit,
|
||||
Option<InterfaceIdentifierOrClassScope>,
|
||||
FunctionIdentifier,
|
||||
Paren<Option<TfPortList>>,
|
||||
|
@ -28,7 +28,7 @@ pub struct LetPortList {
|
||||
pub struct LetPortItem {
|
||||
pub nodes: (
|
||||
Vec<AttributeInstance>,
|
||||
Option<LetFormalType>,
|
||||
LetFormalType,
|
||||
FormalPortIdentifier,
|
||||
Vec<VariableDimension>,
|
||||
Option<(Symbol, Expression)>,
|
||||
|
@ -10,7 +10,7 @@ pub enum LocalParameterDeclaration {
|
||||
|
||||
#[derive(Clone, Debug, Node)]
|
||||
pub struct LocalParameterDeclarationParam {
|
||||
pub nodes: (Keyword, Option<DataTypeOrImplicit>, ListOfParamAssignments),
|
||||
pub nodes: (Keyword, DataTypeOrImplicit, ListOfParamAssignments),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Node)]
|
||||
@ -26,7 +26,7 @@ pub enum ParameterDeclaration {
|
||||
|
||||
#[derive(Clone, Debug, Node)]
|
||||
pub struct ParameterDeclarationParam {
|
||||
pub nodes: (Keyword, Option<DataTypeOrImplicit>, ListOfParamAssignments),
|
||||
pub nodes: (Keyword, DataTypeOrImplicit, ListOfParamAssignments),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Node)]
|
||||
|
@ -4,7 +4,7 @@ use crate::*;
|
||||
|
||||
#[derive(Clone, Debug, Node)]
|
||||
pub struct InoutDeclaration {
|
||||
pub nodes: (Keyword, Option<NetPortType>, ListOfPortIdentifiers),
|
||||
pub nodes: (Keyword, NetPortType, ListOfPortIdentifiers),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Node)]
|
||||
@ -15,7 +15,7 @@ pub enum InputDeclaration {
|
||||
|
||||
#[derive(Clone, Debug, Node)]
|
||||
pub struct InputDeclarationNet {
|
||||
pub nodes: (Keyword, Option<NetPortType>, ListOfPortIdentifiers),
|
||||
pub nodes: (Keyword, NetPortType, ListOfPortIdentifiers),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Node)]
|
||||
@ -31,7 +31,7 @@ pub enum OutputDeclaration {
|
||||
|
||||
#[derive(Clone, Debug, Node)]
|
||||
pub struct OutputDeclarationNet {
|
||||
pub nodes: (Keyword, Option<NetPortType>, ListOfPortIdentifiers),
|
||||
pub nodes: (Keyword, NetPortType, ListOfPortIdentifiers),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Node)]
|
||||
|
@ -57,7 +57,7 @@ pub struct TfPortItem {
|
||||
Vec<AttributeInstance>,
|
||||
Option<TfPortDirection>,
|
||||
Option<Var>,
|
||||
Option<DataTypeOrImplicit>,
|
||||
DataTypeOrImplicit,
|
||||
Option<(
|
||||
PortIdentifier,
|
||||
Vec<VariableDimension>,
|
||||
@ -78,7 +78,7 @@ pub struct TfPortDeclaration {
|
||||
Vec<AttributeInstance>,
|
||||
TfPortDirection,
|
||||
Option<Var>,
|
||||
Option<DataTypeOrImplicit>,
|
||||
DataTypeOrImplicit,
|
||||
ListOfTfVariableIdentifiers,
|
||||
Symbol,
|
||||
),
|
||||
|
@ -16,7 +16,7 @@ pub struct DataDeclarationVariable {
|
||||
Option<Const>,
|
||||
Option<Var>,
|
||||
Option<Lifetime>,
|
||||
Option<DataTypeOrImplicit>,
|
||||
DataTypeOrImplicit,
|
||||
ListOfVariableDeclAssignments,
|
||||
Symbol,
|
||||
),
|
||||
@ -82,7 +82,7 @@ pub struct NetDeclarationNetType {
|
||||
NetType,
|
||||
Option<Strength>,
|
||||
Option<VectorScalar>,
|
||||
Option<DataTypeOrImplicit>,
|
||||
DataTypeOrImplicit,
|
||||
Option<Delay3>,
|
||||
ListOfNetDeclAssignments,
|
||||
Symbol,
|
||||
|
Loading…
x
Reference in New Issue
Block a user