diff --git a/README.md b/README.md index 963360d..a71ca66 100644 --- a/README.md +++ b/README.md @@ -16,9 +16,9 @@ A parser library for System Verilog. | source_text | class_items | | | | | source_text | constraints | | | | | source_text | package_items | | | | -| declaration | module_parameter_declarations | | | | -| declaration | port_declarations | | | | -| declaration | type_declarations | | | | +| declaration | module_parameter_declarations | x | x | | +| declaration | port_declarations | x | x | | +| declaration | type_declarations | x | x | | | declaration | net_and_variable_types | | | | | declaration | strengths | | | | | declaration | delays | x | | | diff --git a/src/parser/behavioral_statements/continuous_assignment_and_net_alias_statements.rs b/src/parser/behavioral_statements/continuous_assignment_and_net_alias_statements.rs index a5f2099..6e6f4c8 100644 --- a/src/parser/behavioral_statements/continuous_assignment_and_net_alias_statements.rs +++ b/src/parser/behavioral_statements/continuous_assignment_and_net_alias_statements.rs @@ -15,7 +15,7 @@ pub enum ContinuousAssign<'a> { pub struct ContinuousAssignNet<'a> { pub nodes: ( Symbol<'a>, - Option, + Option>, Option>, ListOfNetAssignments<'a>, Symbol<'a>, diff --git a/src/parser/declarations/module_parameter_declarations.rs b/src/parser/declarations/module_parameter_declarations.rs index 7516b59..f38aebe 100644 --- a/src/parser/declarations/module_parameter_declarations.rs +++ b/src/parser/declarations/module_parameter_declarations.rs @@ -13,12 +13,16 @@ pub enum LocalParameterDeclaration<'a> { #[derive(Debug)] pub struct LocalParameterDeclarationParam<'a> { - pub nodes: (DataTypeOrImplicit<'a>, ListOfParamAssignments<'a>), + pub nodes: ( + Symbol<'a>, + DataTypeOrImplicit<'a>, + ListOfParamAssignments<'a>, + ), } #[derive(Debug)] pub struct LocalParameterDeclarationType<'a> { - pub nodes: (ListOfTypeAssignments<'a>,), + pub nodes: (Symbol<'a>, Symbol<'a>, ListOfTypeAssignments<'a>), } #[derive(Debug)] @@ -29,17 +33,26 @@ pub enum ParameterDeclaration<'a> { #[derive(Debug)] pub struct ParameterDeclarationParam<'a> { - pub nodes: (DataTypeOrImplicit<'a>, ListOfParamAssignments<'a>), + pub nodes: ( + Symbol<'a>, + DataTypeOrImplicit<'a>, + ListOfParamAssignments<'a>, + ), } #[derive(Debug)] pub struct ParameterDeclarationType<'a> { - pub nodes: (ListOfTypeAssignments<'a>,), + pub nodes: (Symbol<'a>, Symbol<'a>, ListOfTypeAssignments<'a>), } #[derive(Debug)] pub struct SpecparamDeclaration<'a> { - pub nodes: (Option>, ListOfSpecparamAssignments<'a>), + pub nodes: ( + Symbol<'a>, + Option>, + ListOfSpecparamAssignments<'a>, + Symbol<'a>, + ), } // ----------------------------------------------------------------------------- @@ -52,22 +65,22 @@ pub fn local_parameter_declaration(s: Span) -> IResult IResult { - let (s, _) = symbol("localparam")(s)?; - let (s, x) = data_type_or_implicit(s)?; - let (s, y) = list_of_param_assignments(s)?; + let (s, a) = symbol("localparam")(s)?; + let (s, b) = data_type_or_implicit(s)?; + let (s, c) = list_of_param_assignments(s)?; Ok(( s, - LocalParameterDeclaration::Param(LocalParameterDeclarationParam { nodes: (x, y) }), + LocalParameterDeclaration::Param(LocalParameterDeclarationParam { nodes: (a, b, c) }), )) } pub fn local_parameter_declaration_type(s: Span) -> IResult { - let (s, _) = symbol("localparam")(s)?; - let (s, _) = symbol("type")(s)?; - let (s, x) = list_of_type_assignments(s)?; + let (s, a) = symbol("localparam")(s)?; + let (s, b) = symbol("type")(s)?; + let (s, c) = list_of_type_assignments(s)?; Ok(( s, - LocalParameterDeclaration::Type(LocalParameterDeclarationType { nodes: (x,) }), + LocalParameterDeclaration::Type(LocalParameterDeclarationType { nodes: (a, b, c) }), )) } @@ -76,29 +89,34 @@ pub fn parameter_declaration(s: Span) -> IResult { } pub fn parameter_declaration_param(s: Span) -> IResult { - let (s, _) = symbol("parameter")(s)?; - let (s, x) = data_type_or_implicit(s)?; - let (s, y) = list_of_param_assignments(s)?; + let (s, a) = symbol("parameter")(s)?; + let (s, b) = data_type_or_implicit(s)?; + let (s, c) = list_of_param_assignments(s)?; Ok(( s, - ParameterDeclaration::Param(ParameterDeclarationParam { nodes: (x, y) }), + ParameterDeclaration::Param(ParameterDeclarationParam { nodes: (a, b, c) }), )) } pub fn parameter_declaration_type(s: Span) -> IResult { - let (s, _) = symbol("parameter")(s)?; - let (s, _) = symbol("type")(s)?; - let (s, x) = list_of_type_assignments(s)?; + let (s, a) = symbol("parameter")(s)?; + let (s, b) = symbol("type")(s)?; + let (s, c) = list_of_type_assignments(s)?; Ok(( s, - ParameterDeclaration::Type(ParameterDeclarationType { nodes: (x,) }), + ParameterDeclaration::Type(ParameterDeclarationType { nodes: (a, b, c) }), )) } pub fn specparam_declaration(s: Span) -> IResult { - let (s, _) = symbol("specparam")(s)?; - let (s, x) = opt(packed_dimension)(s)?; - let (s, y) = list_of_specparam_assignments(s)?; - let (s, _) = symbol(";")(s)?; - Ok((s, SpecparamDeclaration { nodes: (x, y) })) + let (s, a) = symbol("specparam")(s)?; + let (s, b) = opt(packed_dimension)(s)?; + let (s, c) = list_of_specparam_assignments(s)?; + let (s, d) = symbol(";")(s)?; + Ok(( + s, + SpecparamDeclaration { + nodes: (a, b, c, d), + }, + )) } diff --git a/src/parser/declarations/net_and_variable_types.rs b/src/parser/declarations/net_and_variable_types.rs index 165b721..cac4d41 100644 --- a/src/parser/declarations/net_and_variable_types.rs +++ b/src/parser/declarations/net_and_variable_types.rs @@ -176,19 +176,19 @@ pub enum NonIntegerType { } #[derive(Debug)] -pub enum NetType { - Supply0, - Supply1, - Tri, - Triand, - Trior, - Trireg, - Tri0, - Tri1, - Uwire, - Wire, - Wand, - Wor, +pub enum NetType<'a> { + Supply0(Symbol<'a>), + Supply1(Symbol<'a>), + Tri(Symbol<'a>), + Triand(Symbol<'a>), + Trior(Symbol<'a>), + Trireg(Symbol<'a>), + Tri0(Symbol<'a>), + Tri1(Symbol<'a>), + Uwire(Symbol<'a>), + Wire(Symbol<'a>), + Wand(Symbol<'a>), + Wor(Symbol<'a>), } #[derive(Debug)] @@ -200,7 +200,7 @@ pub enum NetPortType<'a> { #[derive(Debug)] pub struct NetPortTypeDataType<'a> { - pub nodes: (Option, DataTypeOrImplicit<'a>), + pub nodes: (Option>, DataTypeOrImplicit<'a>), } #[derive(Debug)] diff --git a/src/parser/declarations/port_declarations.rs b/src/parser/declarations/port_declarations.rs index 2ea4e82..5aa7344 100644 --- a/src/parser/declarations/port_declarations.rs +++ b/src/parser/declarations/port_declarations.rs @@ -8,7 +8,7 @@ use nom::IResult; #[derive(Debug)] pub struct InoutDeclaration<'a> { - pub nodes: (NetPortType<'a>, ListOfPortIdentifiers<'a>), + pub nodes: (Symbol<'a>, NetPortType<'a>, ListOfPortIdentifiers<'a>), } #[derive(Debug)] @@ -19,12 +19,16 @@ pub enum InputDeclaration<'a> { #[derive(Debug)] pub struct InputDeclarationNet<'a> { - pub nodes: (NetPortType<'a>, ListOfPortIdentifiers<'a>), + pub nodes: (Symbol<'a>, NetPortType<'a>, ListOfPortIdentifiers<'a>), } #[derive(Debug)] pub struct InputDeclarationVariable<'a> { - pub nodes: (VariablePortType<'a>, ListOfVariableIdentifiers<'a>), + pub nodes: ( + Symbol<'a>, + VariablePortType<'a>, + ListOfVariableIdentifiers<'a>, + ), } #[derive(Debug)] @@ -35,35 +39,43 @@ pub enum OutputDeclaration<'a> { #[derive(Debug)] pub struct OutputDeclarationNet<'a> { - pub nodes: (NetPortType<'a>, ListOfPortIdentifiers<'a>), + pub nodes: (Symbol<'a>, NetPortType<'a>, ListOfPortIdentifiers<'a>), } #[derive(Debug)] pub struct OutputDeclarationVariable<'a> { - pub nodes: (VariablePortType<'a>, ListOfVariableIdentifiers<'a>), + pub nodes: ( + Symbol<'a>, + VariablePortType<'a>, + ListOfVariableIdentifiers<'a>, + ), } #[derive(Debug)] pub struct InterfacePortDeclaration<'a> { pub nodes: ( InterfaceIdentifier<'a>, - Option>, + Option<(Symbol<'a>, ModportIdentifier<'a>)>, ListOfInterfaceIdentifiers<'a>, ), } #[derive(Debug)] pub struct RefDeclaration<'a> { - pub nodes: (VariablePortType<'a>, ListOfVariableIdentifiers<'a>), + pub nodes: ( + Symbol<'a>, + VariablePortType<'a>, + ListOfVariableIdentifiers<'a>, + ), } // ----------------------------------------------------------------------------- pub fn inout_declaratrion(s: Span) -> IResult { - let (s, _) = symbol("inout")(s)?; - let (s, x) = net_port_type(s)?; - let (s, y) = list_of_port_identifiers(s)?; - Ok((s, InoutDeclaration { nodes: (x, y) })) + let (s, a) = symbol("inout")(s)?; + let (s, b) = net_port_type(s)?; + let (s, c) = list_of_port_identifiers(s)?; + Ok((s, InoutDeclaration { nodes: (a, b, c) })) } pub fn input_declaratrion(s: Span) -> IResult { @@ -71,22 +83,22 @@ pub fn input_declaratrion(s: Span) -> IResult { } pub fn input_declaration_net(s: Span) -> IResult { - let (s, _) = symbol("input")(s)?; - let (s, x) = net_port_type(s)?; - let (s, y) = list_of_port_identifiers(s)?; + let (s, a) = symbol("input")(s)?; + let (s, b) = net_port_type(s)?; + let (s, c) = list_of_port_identifiers(s)?; Ok(( s, - InputDeclaration::Net(InputDeclarationNet { nodes: (x, y) }), + InputDeclaration::Net(InputDeclarationNet { nodes: (a, b, c) }), )) } pub fn input_declaration_variable(s: Span) -> IResult { - let (s, _) = symbol("input")(s)?; - let (s, x) = variable_port_type(s)?; - let (s, y) = list_of_variable_identifiers(s)?; + let (s, a) = symbol("input")(s)?; + let (s, b) = variable_port_type(s)?; + let (s, c) = list_of_variable_identifiers(s)?; Ok(( s, - InputDeclaration::Variable(InputDeclarationVariable { nodes: (x, y) }), + InputDeclaration::Variable(InputDeclarationVariable { nodes: (a, b, c) }), )) } @@ -95,35 +107,35 @@ pub fn output_declaratrion(s: Span) -> IResult { } pub fn output_declaration_net(s: Span) -> IResult { - let (s, _) = symbol("output")(s)?; - let (s, x) = net_port_type(s)?; - let (s, y) = list_of_port_identifiers(s)?; + let (s, a) = symbol("output")(s)?; + let (s, b) = net_port_type(s)?; + let (s, c) = list_of_port_identifiers(s)?; Ok(( s, - OutputDeclaration::Net(OutputDeclarationNet { nodes: (x, y) }), + OutputDeclaration::Net(OutputDeclarationNet { nodes: (a, b, c) }), )) } pub fn output_declaration_variable(s: Span) -> IResult { - let (s, _) = symbol("output")(s)?; - let (s, x) = variable_port_type(s)?; - let (s, y) = list_of_variable_identifiers(s)?; + let (s, a) = symbol("output")(s)?; + let (s, b) = variable_port_type(s)?; + let (s, c) = list_of_variable_identifiers(s)?; Ok(( s, - OutputDeclaration::Variable(OutputDeclarationVariable { nodes: (x, y) }), + OutputDeclaration::Variable(OutputDeclarationVariable { nodes: (a, b, c) }), )) } pub fn interface_port_declaration(s: Span) -> IResult { - let (s, x) = interface_identifier(s)?; - let (s, y) = opt(preceded(symbol("."), modport_identifier))(s)?; - let (s, z) = list_of_interface_identifiers(s)?; - Ok((s, InterfacePortDeclaration { nodes: (x, y, z) })) + let (s, a) = interface_identifier(s)?; + let (s, b) = opt(pair(symbol("."), modport_identifier))(s)?; + let (s, c) = list_of_interface_identifiers(s)?; + Ok((s, InterfacePortDeclaration { nodes: (a, b, c) })) } pub fn ref_declaration(s: Span) -> IResult { - let (s, _) = symbol("ref")(s)?; - let (s, x) = variable_port_type(s)?; - let (s, y) = list_of_variable_identifiers(s)?; - Ok((s, RefDeclaration { nodes: (x, y) })) + let (s, a) = symbol("ref")(s)?; + let (s, b) = variable_port_type(s)?; + let (s, c) = list_of_variable_identifiers(s)?; + Ok((s, RefDeclaration { nodes: (a, b, c) })) } diff --git a/src/parser/declarations/strengths.rs b/src/parser/declarations/strengths.rs index db4de27..9634bcf 100644 --- a/src/parser/declarations/strengths.rs +++ b/src/parser/declarations/strengths.rs @@ -7,36 +7,36 @@ use nom::{Err, IResult}; // ----------------------------------------------------------------------------- #[derive(Debug)] -pub enum DriveStrength { - Strength01(Strength0, Strength1), - Strength10(Strength1, Strength0), - Strength0z(Strength0), - Strength1z(Strength1), - Strengthz0(Strength0), - Strengthz1(Strength1), +pub enum DriveStrength<'a> { + Strength01(Strength0<'a>, Strength1<'a>), + Strength10(Strength1<'a>, Strength0<'a>), + Strength0z(Strength0<'a>), + Strength1z(Strength1<'a>), + Strengthz0(Strength0<'a>), + Strengthz1(Strength1<'a>), } #[derive(Debug)] -pub enum Strength0 { - Supply0, - Strong0, - Pull0, - Weak0, +pub enum Strength0<'a> { + Supply0(Symbol<'a>), + Strong0(Symbol<'a>), + Pull0(Symbol<'a>), + Weak0(Symbol<'a>), } #[derive(Debug)] -pub enum Strength1 { - Supply1, - Strong1, - Pull1, - Weak1, +pub enum Strength1<'a> { + Supply1(Symbol<'a>), + Strong1(Symbol<'a>), + Pull1(Symbol<'a>), + Weak1(Symbol<'a>), } #[derive(Debug)] -pub enum ChargeStrength { - Small, - Medium, - Large, +pub enum ChargeStrength<'a> { + Small(Symbol<'a>), + Medium(Symbol<'a>), + Large(Symbol<'a>), } // ----------------------------------------------------------------------------- diff --git a/src/parser/declarations/type_declarations.rs b/src/parser/declarations/type_declarations.rs index 02e1f5a..ff17208 100644 --- a/src/parser/declarations/type_declarations.rs +++ b/src/parser/declarations/type_declarations.rs @@ -1,3 +1,4 @@ +use crate::ast::*; use crate::parser::*; use nom::branch::*; use nom::combinator::*; @@ -10,58 +11,76 @@ use nom::IResult; #[derive(Debug)] pub enum DataDeclaration<'a> { Variable(DataDeclarationVariable<'a>), - Type(TypeDeclaration<'a>), - PackageImport(PackageImportDeclaration<'a>), - NetType(NetTypeDeclaration<'a>), + TypeDeclaration(TypeDeclaration<'a>), + PackageImportDeclaration(PackageImportDeclaration<'a>), + NetTypeDeclaration(NetTypeDeclaration<'a>), } #[derive(Debug)] pub struct DataDeclarationVariable<'a> { pub nodes: ( - Option, - Option, + Option>, + Option>, Option>, DataTypeOrImplicit<'a>, ListOfVariableDeclAssignments<'a>, + Symbol<'a>, ), } -#[derive(Debug)] -pub struct Const {} - -#[derive(Debug)] -pub struct Var {} - -#[derive(Debug)] -pub struct PackageImportDeclaration<'a> { - pub nodes: (Vec>,), +#[derive(Debug, Node)] +pub struct Const<'a> { + pub nodes: (Symbol<'a>,), } #[derive(Debug)] +pub struct PackageImportDeclaration<'a> { + pub nodes: ( + Symbol<'a>, + List, PackageImportItem<'a>>, + Symbol<'a>, + ), +} + +#[derive(Debug, Node)] pub enum PackageImportItem<'a> { Identifier(PackageImportItemIdentifier<'a>), Asterisk(PackageImportItemAsterisk<'a>), } -#[derive(Debug)] +#[derive(Debug, Node)] pub struct PackageImportItemIdentifier<'a> { - pub nodes: (PackageIdentifier<'a>, Identifier<'a>), + pub nodes: (PackageIdentifier<'a>, Symbol<'a>, Identifier<'a>), } -#[derive(Debug)] +#[derive(Debug, Node)] pub struct PackageImportItemAsterisk<'a> { - pub nodes: (PackageIdentifier<'a>,), + pub nodes: (PackageIdentifier<'a>, Symbol<'a>, Symbol<'a>), } -#[derive(Debug)] +#[derive(Debug, Node)] pub enum PackageExportDeclaration<'a> { - Asterisk, - Item(Vec>), + Asterisk(PackageExportDeclarationAsterisk<'a>), + Item(PackageExportDeclarationItem<'a>), +} + +#[derive(Debug, Node)] +pub struct PackageExportDeclarationAsterisk<'a> { + pub nodes: (Symbol<'a>, Symbol<'a>, Symbol<'a>), +} + +#[derive(Debug, Node)] +pub struct PackageExportDeclarationItem<'a> { + pub nodes: ( + Symbol<'a>, + List, PackageImportItem<'a>>, + Symbol<'a>, + ), } #[derive(Debug)] pub struct GenvarDeclaration<'a> { - pub nodes: (ListOfGenvarIdentifiers<'a>,), + pub nodes: (Symbol<'a>, ListOfGenvarIdentifiers<'a>, Symbol<'a>), } #[derive(Debug)] @@ -74,25 +93,26 @@ pub enum NetDeclaration<'a> { #[derive(Debug)] pub struct NetDeclarationNetType<'a> { pub nodes: ( - NetType, - Option, - Option, + NetType<'a>, + Option>, + Option>, DataTypeOrImplicit<'a>, Option>, ListOfNetDeclAssignments<'a>, + Symbol<'a>, ), } #[derive(Debug)] -pub enum Strength { - Drive(DriveStrength), - Charge(ChargeStrength), +pub enum Strength<'a> { + Drive(DriveStrength<'a>), + Charge(ChargeStrength<'a>), } -#[derive(Debug)] -pub enum VectorScalar { - Vectored, - Scalared, +#[derive(Debug, Node)] +pub enum VectorScalar<'a> { + Vectored(Symbol<'a>), + Scalared(Symbol<'a>), } #[derive(Debug)] @@ -101,17 +121,20 @@ pub struct NetDeclarationNetTypeIdentifier<'a> { NetTypeIdentifier<'a>, Option>, ListOfNetDeclAssignments<'a>, + Symbol<'a>, ), } #[derive(Debug)] pub struct NetDeclarationInterconnect<'a> { pub nodes: ( + Symbol<'a>, ImplicitDataType<'a>, - Option>, + Option<(Symbol<'a>, DelayValue<'a>)>, NetIdentifier<'a>, Vec>, - Option<(NetIdentifier<'a>, Vec>)>, + Option<(Symbol<'a>, NetIdentifier<'a>, Vec>)>, + Symbol<'a>, ), } @@ -124,31 +147,45 @@ pub enum TypeDeclaration<'a> { #[derive(Debug)] pub struct TypeDeclarationDataType<'a> { - pub nodes: (DataType<'a>, TypeIdentifier<'a>, Vec>), + pub nodes: ( + Symbol<'a>, + DataType<'a>, + TypeIdentifier<'a>, + Vec>, + Symbol<'a>, + ), } #[derive(Debug)] pub struct TypeDeclarationInterface<'a> { pub nodes: ( + Symbol<'a>, InterfaceInstanceIdentifier<'a>, ConstantBitSelect<'a>, + Symbol<'a>, TypeIdentifier<'a>, TypeIdentifier<'a>, + Symbol<'a>, ), } #[derive(Debug)] pub struct TypeDeclarationReserved<'a> { - pub nodes: (TypeDeclarationKeyword, TypeIdentifier<'a>), + pub nodes: ( + Symbol<'a>, + TypeDeclarationKeyword<'a>, + TypeIdentifier<'a>, + Symbol<'a>, + ), } -#[derive(Debug)] -pub enum TypeDeclarationKeyword { - Enum, - Struct, - Union, - Class, - InterfaceClass, +#[derive(Debug, Node)] +pub enum TypeDeclarationKeyword<'a> { + Enum(Symbol<'a>), + Struct(Symbol<'a>), + Union(Symbol<'a>), + Class(Symbol<'a>), + InterfaceClass((Symbol<'a>, Symbol<'a>)), } #[derive(Debug)] @@ -160,22 +197,30 @@ pub enum NetTypeDeclaration<'a> { #[derive(Debug)] pub struct NetTypeDeclarationDataType<'a> { pub nodes: ( + Symbol<'a>, DataType<'a>, NetTypeIdentifier<'a>, - Option<(Option>, TfIdentifier<'a>)>, + Option<( + Symbol<'a>, + Option>, + TfIdentifier<'a>, + )>, + Symbol<'a>, ), } #[derive(Debug)] pub struct NetTypeDeclarationNetType<'a> { pub nodes: ( + Symbol<'a>, Option>, NetTypeIdentifier<'a>, NetTypeIdentifier<'a>, + Symbol<'a>, ), } -#[derive(Debug)] +#[derive(Debug, Node)] pub enum Lifetime<'a> { Static(Symbol<'a>), Automatic(Symbol<'a>), @@ -186,34 +231,41 @@ pub enum Lifetime<'a> { pub fn data_declaration(s: Span) -> IResult { alt(( data_declaration_variable, - map(type_declaration, |x| DataDeclaration::Type(x)), + map(type_declaration, |x| DataDeclaration::TypeDeclaration(x)), map(package_import_declaration, |x| { - DataDeclaration::PackageImport(x) + DataDeclaration::PackageImportDeclaration(x) + }), + map(net_type_declaration, |x| { + DataDeclaration::NetTypeDeclaration(x) }), - map(net_type_declaration, |x| DataDeclaration::NetType(x)), ))(s) } pub fn data_declaration_variable(s: Span) -> IResult { - let (s, x) = opt(symbol("const"))(s)?; - let (s, y) = opt(symbol("var"))(s)?; - let (s, z) = opt(lifetime)(s)?; - let (s, v) = data_type_or_implicit(s)?; - let (s, w) = list_of_variable_decl_assignments(s)?; - let (s, _) = symbol(";")(s)?; + let (s, a) = opt(r#const)(s)?; + let (s, b) = opt(var)(s)?; + let (s, c) = opt(lifetime)(s)?; + let (s, d) = data_type_or_implicit(s)?; + let (s, e) = list_of_variable_decl_assignments(s)?; + let (s, f) = symbol(";")(s)?; Ok(( s, DataDeclaration::Variable(DataDeclarationVariable { - nodes: (x.map(|_| Const {}), y.map(|_| Var {}), z, v, w), + nodes: (a, b, c, d, e, f), }), )) } +pub fn r#const(s: Span) -> IResult { + let (s, a) = symbol("const")(s)?; + Ok((s, Const { nodes: (a,) })) +} + pub fn package_import_declaration(s: Span) -> IResult { - let (s, _) = symbol("import")(s)?; - let (s, x) = separated_nonempty_list(symbol(","), package_import_item)(s)?; - let (s, _) = symbol(";")(s)?; - Ok((s, PackageImportDeclaration { nodes: (x,) })) + let (s, a) = symbol("import")(s)?; + let (s, b) = list(symbol(","), package_import_item)(s)?; + let (s, c) = symbol(";")(s)?; + Ok((s, PackageImportDeclaration { nodes: (a, b, c) })) } pub fn package_import_item(s: Span) -> IResult { @@ -221,22 +273,22 @@ pub fn package_import_item(s: Span) -> IResult { } pub fn package_import_item_identifier(s: Span) -> IResult { - let (s, x) = package_identifier(s)?; - let (s, _) = symbol("::")(s)?; - let (s, y) = identifier(s)?; + let (s, a) = package_identifier(s)?; + let (s, b) = symbol("::")(s)?; + let (s, c) = identifier(s)?; Ok(( s, - PackageImportItem::Identifier(PackageImportItemIdentifier { nodes: (x, y) }), + PackageImportItem::Identifier(PackageImportItemIdentifier { nodes: (a, b, c) }), )) } pub fn package_import_item_asterisk(s: Span) -> IResult { - let (s, x) = package_identifier(s)?; - let (s, _) = symbol("::")(s)?; - let (s, _) = symbol("*")(s)?; + let (s, a) = package_identifier(s)?; + let (s, b) = symbol("::")(s)?; + let (s, c) = symbol("*")(s)?; Ok(( s, - PackageImportItem::Asterisk(PackageImportItemAsterisk { nodes: (x,) }), + PackageImportItem::Asterisk(PackageImportItemAsterisk { nodes: (a, b, c) }), )) } @@ -248,23 +300,30 @@ pub fn package_export_declaration(s: Span) -> IResult IResult { - let (s, _) = symbol("export")(s)?; - let (s, _) = symbol("*::*")(s)?; - let (s, _) = symbol(";")(s)?; - Ok((s, PackageExportDeclaration::Asterisk)) + let (s, a) = symbol("export")(s)?; + let (s, b) = symbol("*::*")(s)?; + let (s, c) = symbol(";")(s)?; + Ok(( + s, + PackageExportDeclaration::Asterisk(PackageExportDeclarationAsterisk { nodes: (a, b, c) }), + )) } pub fn package_export_declaration_item(s: Span) -> IResult { - let (s, _) = symbol("export")(s)?; - let (s, x) = separated_nonempty_list(symbol(","), package_import_item)(s)?; - let (s, _) = symbol(";")(s)?; - Ok((s, PackageExportDeclaration::Item(x))) + let (s, a) = symbol("export")(s)?; + let (s, b) = list(symbol(","), package_import_item)(s)?; + let (s, c) = symbol(";")(s)?; + Ok(( + s, + PackageExportDeclaration::Item(PackageExportDeclarationItem { nodes: (a, b, c) }), + )) } pub fn genvar_declaration(s: Span) -> IResult { - let (s, _) = symbol("genvar")(s)?; - let (s, x) = list_of_genvar_identifiers(s)?; - Ok((s, GenvarDeclaration { nodes: (x,) })) + let (s, a) = symbol("genvar")(s)?; + let (s, b) = list_of_genvar_identifiers(s)?; + let (s, c) = symbol(";")(s)?; + Ok((s, GenvarDeclaration { nodes: (a, b, c) })) } pub fn net_declaration(s: Span) -> IResult { @@ -276,17 +335,17 @@ pub fn net_declaration(s: Span) -> IResult { } pub fn net_declaration_net_type(s: Span) -> IResult { - let (s, x) = net_type(s)?; - let (s, y) = opt(strength)(s)?; - let (s, z) = opt(vector_scalar)(s)?; - let (s, v) = data_type_or_implicit(s)?; - let (s, w) = opt(delay3)(s)?; - let (s, u) = list_of_net_decl_assignments(s)?; - let (s, _) = symbol(";")(s)?; + let (s, a) = net_type(s)?; + let (s, b) = opt(strength)(s)?; + let (s, c) = opt(vector_scalar)(s)?; + let (s, d) = data_type_or_implicit(s)?; + let (s, e) = opt(delay3)(s)?; + let (s, f) = list_of_net_decl_assignments(s)?; + let (s, g) = symbol(";")(s)?; Ok(( s, NetDeclaration::NetType(NetDeclarationNetType { - nodes: (x, y, z, v, w, u), + nodes: (a, b, c, d, e, f, g), }), )) } @@ -300,36 +359,40 @@ pub fn strength(s: Span) -> IResult { pub fn vector_scalar(s: Span) -> IResult { alt(( - map(symbol("vectored"), |_| VectorScalar::Vectored), - map(symbol("scalared"), |_| VectorScalar::Scalared), + map(symbol("vectored"), |x| VectorScalar::Vectored(x)), + map(symbol("scalared"), |x| VectorScalar::Scalared(x)), ))(s) } pub fn net_declaration_net_type_identifier(s: Span) -> IResult { - let (s, x) = net_type_identifier(s)?; - let (s, y) = opt(delay_control)(s)?; - let (s, z) = list_of_net_decl_assignments(s)?; - let (s, _) = symbol(";")(s)?; + let (s, a) = net_type_identifier(s)?; + let (s, b) = opt(delay_control)(s)?; + let (s, c) = list_of_net_decl_assignments(s)?; + let (s, d) = symbol(";")(s)?; Ok(( s, - NetDeclaration::NetTypeIdentifier(NetDeclarationNetTypeIdentifier { nodes: (x, y, z) }), + NetDeclaration::NetTypeIdentifier(NetDeclarationNetTypeIdentifier { + nodes: (a, b, c, d), + }), )) } pub fn net_declaration_interconnect(s: Span) -> IResult { - let (s, _) = symbol("interconnect")(s)?; - let (s, x) = implicit_data_type(s)?; - let (s, y) = opt(preceded(symbol("#"), delay_value))(s)?; - let (s, z) = net_identifier(s)?; - let (s, v) = many0(unpacked_dimension)(s)?; - let (s, w) = opt(preceded( + let (s, a) = symbol("interconnect")(s)?; + let (s, b) = implicit_data_type(s)?; + let (s, c) = opt(pair(symbol("#"), delay_value))(s)?; + let (s, d) = net_identifier(s)?; + let (s, e) = many0(unpacked_dimension)(s)?; + let (s, f) = opt(triple( symbol(","), - pair(net_identifier, many0(unpacked_dimension)), + net_identifier, + many0(unpacked_dimension), ))(s)?; + let (s, g) = symbol(";")(s)?; Ok(( s, NetDeclaration::Interconnect(NetDeclarationInterconnect { - nodes: (x, y, z, v, w), + nodes: (a, b, c, d, e, f, g), }), )) } @@ -343,52 +406,56 @@ pub fn type_declaration(s: Span) -> IResult { } pub fn type_declaration_data_type(s: Span) -> IResult { - let (s, _) = symbol("typedef")(s)?; - let (s, x) = data_type(s)?; - let (s, y) = type_identifier(s)?; - let (s, z) = many0(variable_dimension)(s)?; - let (s, _) = symbol(";")(s)?; + let (s, a) = symbol("typedef")(s)?; + let (s, b) = data_type(s)?; + let (s, c) = type_identifier(s)?; + let (s, d) = many0(variable_dimension)(s)?; + let (s, e) = symbol(";")(s)?; Ok(( s, - TypeDeclaration::DataType(TypeDeclarationDataType { nodes: (x, y, z) }), + TypeDeclaration::DataType(TypeDeclarationDataType { + nodes: (a, b, c, d, e), + }), )) } pub fn type_declaration_interface(s: Span) -> IResult { - let (s, _) = symbol("typedef")(s)?; - let (s, x) = interface_instance_identifier(s)?; - let (s, y) = constant_bit_select(s)?; - let (s, _) = symbol(".")(s)?; - let (s, z) = type_identifier(s)?; - let (s, v) = type_identifier(s)?; - let (s, _) = symbol(";")(s)?; + let (s, a) = symbol("typedef")(s)?; + let (s, b) = interface_instance_identifier(s)?; + let (s, c) = constant_bit_select(s)?; + let (s, d) = symbol(".")(s)?; + let (s, e) = type_identifier(s)?; + let (s, f) = type_identifier(s)?; + let (s, g) = symbol(";")(s)?; Ok(( s, TypeDeclaration::Interface(TypeDeclarationInterface { - nodes: (x, y, z, v), + nodes: (a, b, c, d, e, f, g), }), )) } pub fn type_declaration_reserved(s: Span) -> IResult { - let (s, _) = symbol("typedef")(s)?; - let (s, x) = type_declaration_keyword(s)?; - let (s, y) = type_identifier(s)?; - let (s, _) = symbol(";")(s)?; + let (s, a) = symbol("typedef")(s)?; + let (s, b) = type_declaration_keyword(s)?; + let (s, c) = type_identifier(s)?; + let (s, d) = symbol(";")(s)?; Ok(( s, - TypeDeclaration::Reserved(TypeDeclarationReserved { nodes: (x, y) }), + TypeDeclaration::Reserved(TypeDeclarationReserved { + nodes: (a, b, c, d), + }), )) } pub fn type_declaration_keyword(s: Span) -> IResult { alt(( - map(symbol("enum"), |_| TypeDeclarationKeyword::Enum), - map(symbol("struct"), |_| TypeDeclarationKeyword::Struct), - map(symbol("union"), |_| TypeDeclarationKeyword::Union), - map(symbol("class"), |_| TypeDeclarationKeyword::Class), - map(pair(symbol("interface"), symbol("class")), |_| { - TypeDeclarationKeyword::InterfaceClass + map(symbol("enum"), |x| TypeDeclarationKeyword::Enum(x)), + map(symbol("struct"), |x| TypeDeclarationKeyword::Struct(x)), + map(symbol("union"), |x| TypeDeclarationKeyword::Union(x)), + map(symbol("class"), |x| TypeDeclarationKeyword::Class(x)), + map(pair(symbol("interface"), symbol("class")), |x| { + TypeDeclarationKeyword::InterfaceClass(x) }), ))(s) } @@ -401,29 +468,34 @@ pub fn net_type_declaration(s: Span) -> IResult { } pub fn net_type_declaration_data_type(s: Span) -> IResult { - let (s, _) = symbol("nettype")(s)?; - let (s, x) = data_type(s)?; - let (s, y) = net_type_identifier(s)?; - let (s, z) = opt(preceded( + let (s, a) = symbol("nettype")(s)?; + let (s, b) = data_type(s)?; + let (s, c) = net_type_identifier(s)?; + let (s, d) = opt(triple( symbol("with"), - pair(opt(package_scope_or_class_scope), tf_identifier), + opt(package_scope_or_class_scope), + tf_identifier, ))(s)?; - let (s, _) = symbol(";")(s)?; + let (s, e) = symbol(";")(s)?; Ok(( s, - NetTypeDeclaration::DataType(NetTypeDeclarationDataType { nodes: (x, y, z) }), + NetTypeDeclaration::DataType(NetTypeDeclarationDataType { + nodes: (a, b, c, d, e), + }), )) } pub fn net_type_declaration_net_type(s: Span) -> IResult { - let (s, _) = symbol("nettype")(s)?; - let (s, x) = opt(package_scope_or_class_scope)(s)?; - let (s, y) = net_type_identifier(s)?; - let (s, z) = net_type_identifier(s)?; - let (s, _) = symbol(";")(s)?; + let (s, a) = symbol("nettype")(s)?; + let (s, b) = opt(package_scope_or_class_scope)(s)?; + let (s, c) = net_type_identifier(s)?; + let (s, d) = net_type_identifier(s)?; + let (s, e) = symbol(";")(s)?; Ok(( s, - NetTypeDeclaration::NetType(NetTypeDeclarationNetType { nodes: (x, y, z) }), + NetTypeDeclaration::NetType(NetTypeDeclarationNetType { + nodes: (a, b, c, d, e), + }), )) }