use crate::ast::*; use crate::parser::*; use nom::branch::*; use nom::combinator::*; use nom::multi::*; use nom::IResult; // ----------------------------------------------------------------------------- #[derive(Debug, Node)] pub struct ModuleInstantiation<'a> { pub nodes: ( ModuleIdentifier<'a>, Option>, List, HierarchicalInstance<'a>>, Symbol<'a>, ), } #[derive(Debug, Node)] pub struct ParameterValueAssignment<'a> { pub nodes: ( Symbol<'a>, Paren<'a, Option>>, ), } #[derive(Debug, Node)] pub enum ListOfParameterAssignments<'a> { Ordered(ListOfParameterAssignmentsOrdered<'a>), Named(ListOfParameterAssignmentsNamed<'a>), } #[derive(Debug, Node)] pub struct ListOfParameterAssignmentsOrdered<'a> { pub nodes: (List, OrderedParameterAssignment<'a>>,), } #[derive(Debug, Node)] pub struct ListOfParameterAssignmentsNamed<'a> { pub nodes: (List, NamedParameterAssignment<'a>>,), } #[derive(Debug, Node)] pub struct OrderedParameterAssignment<'a> { pub nodes: (ParamExpression<'a>,), } #[derive(Debug, Node)] pub struct NamedParameterAssignment<'a> { pub nodes: ( Symbol<'a>, ParameterIdentifier<'a>, Paren<'a, Option>>, ), } #[derive(Debug, Node)] pub struct HierarchicalInstance<'a> { pub nodes: ( NameOfInstance<'a>, Paren<'a, Option>>, ), } #[derive(Debug, Node)] pub struct NameOfInstance<'a> { pub nodes: (InstanceIdentifier<'a>, Vec>), } #[derive(Debug, Node)] pub enum ListOfPortConnections<'a> { Ordered(ListOfPortConnectionsOrdered<'a>), Named(ListOfPortConnectionsNamed<'a>), } #[derive(Debug, Node)] pub struct ListOfPortConnectionsOrdered<'a> { pub nodes: (List, OrderedPortConnection<'a>>,), } #[derive(Debug, Node)] pub struct ListOfPortConnectionsNamed<'a> { pub nodes: (List, NamedPortConnection<'a>>,), } #[derive(Debug, Node)] pub struct OrderedPortConnection<'a> { pub nodes: (Vec>, Option>), } #[derive(Debug, Node)] pub enum NamedPortConnection<'a> { Identifier(NamedPortConnectionIdentifier<'a>), Asterisk(NamedPortConnectionAsterisk<'a>), } #[derive(Debug, Node)] pub struct NamedPortConnectionIdentifier<'a> { pub nodes: ( Vec>, Symbol<'a>, PortIdentifier<'a>, Option>>>, ), } #[derive(Debug, Node)] pub struct NamedPortConnectionAsterisk<'a> { pub nodes: (Vec>, Symbol<'a>), } // ----------------------------------------------------------------------------- #[trace] pub fn module_instantiation(s: Span) -> IResult { let (s, a) = module_identifier(s)?; let (s, b) = opt(parameter_value_assignment)(s)?; let (s, c) = list(symbol(","), hierarchical_instance)(s)?; let (s, d) = symbol(";")(s)?; Ok(( s, ModuleInstantiation { nodes: (a, b, c, d), }, )) } #[trace] pub fn parameter_value_assignment(s: Span) -> IResult { let (s, a) = symbol("#")(s)?; let (s, b) = paren(opt(list_of_parameter_assignments))(s)?; Ok((s, ParameterValueAssignment { nodes: (a, b) })) } #[trace] pub fn list_of_parameter_assignments(s: Span) -> IResult { alt(( list_of_parameter_assignments_ordered, list_of_parameter_assignments_named, ))(s) } #[trace] pub fn list_of_parameter_assignments_ordered(s: Span) -> IResult { let (s, a) = list(symbol(","), ordered_parameter_assignment)(s)?; Ok(( s, ListOfParameterAssignments::Ordered(ListOfParameterAssignmentsOrdered { nodes: (a,) }), )) } #[trace] pub fn list_of_parameter_assignments_named(s: Span) -> IResult { let (s, a) = list(symbol(","), named_parameter_assignment)(s)?; Ok(( s, ListOfParameterAssignments::Named(ListOfParameterAssignmentsNamed { nodes: (a,) }), )) } #[trace] pub fn ordered_parameter_assignment(s: Span) -> IResult { let (s, x) = param_expression(s)?; Ok((s, OrderedParameterAssignment { nodes: (x,) })) } #[trace] pub fn named_parameter_assignment(s: Span) -> IResult { let (s, a) = symbol(".")(s)?; let (s, b) = parameter_identifier(s)?; let (s, c) = paren(opt(param_expression))(s)?; Ok((s, NamedParameterAssignment { nodes: (a, b, c) })) } #[trace] pub fn hierarchical_instance(s: Span) -> IResult { let (s, a) = name_of_instance(s)?; let (s, b) = paren(opt(list_of_port_connections))(s)?; Ok((s, HierarchicalInstance { nodes: (a, b) })) } #[trace] pub fn name_of_instance(s: Span) -> IResult { let (s, x) = instance_identifier(s)?; let (s, y) = many0(unpacked_dimension)(s)?; Ok((s, NameOfInstance { nodes: (x, y) })) } #[trace] pub fn list_of_port_connections(s: Span) -> IResult { alt(( list_of_port_connections_ordered, list_of_port_connections_named, ))(s) } #[trace] pub fn list_of_port_connections_ordered(s: Span) -> IResult { let (s, a) = list(symbol(","), ordered_port_connection)(s)?; Ok(( s, ListOfPortConnections::Ordered(ListOfPortConnectionsOrdered { nodes: (a,) }), )) } #[trace] pub fn list_of_port_connections_named(s: Span) -> IResult { let (s, a) = list(symbol(","), named_port_connection)(s)?; Ok(( s, ListOfPortConnections::Named(ListOfPortConnectionsNamed { nodes: (a,) }), )) } #[trace] pub fn ordered_port_connection(s: Span) -> IResult { let (s, x) = many0(attribute_instance)(s)?; let (s, y) = opt(expression)(s)?; Ok((s, OrderedPortConnection { nodes: (x, y) })) } #[trace] pub fn named_port_connection(s: Span) -> IResult { alt(( named_port_connection_identifier, named_port_connection_asterisk, ))(s) } #[trace] pub fn named_port_connection_identifier(s: Span) -> IResult { let (s, a) = many0(attribute_instance)(s)?; let (s, b) = symbol(".")(s)?; let (s, c) = port_identifier(s)?; let (s, d) = opt(paren(opt(expression)))(s)?; Ok(( s, NamedPortConnection::Identifier(NamedPortConnectionIdentifier { nodes: (a, b, c, d), }), )) } #[trace] pub fn named_port_connection_asterisk(s: Span) -> IResult { let (s, a) = many0(attribute_instance)(s)?; let (s, b) = symbol(".*")(s)?; Ok(( s, NamedPortConnection::Asterisk(NamedPortConnectionAsterisk { nodes: (a, b) }), )) } // -----------------------------------------------------------------------------