Refactoring

This commit is contained in:
dalance 2019-07-12 17:12:32 +09:00
parent e1a5c5aa8a
commit c1a46fc018
7 changed files with 341 additions and 239 deletions

View File

@ -16,9 +16,9 @@ A parser library for System Verilog.
| source_text | class_items | | | | | source_text | class_items | | | |
| source_text | constraints | | | | | source_text | constraints | | | |
| source_text | package_items | | | | | source_text | package_items | | | |
| declaration | module_parameter_declarations | | | | | declaration | module_parameter_declarations | x | x | |
| declaration | port_declarations | | | | | declaration | port_declarations | x | x | |
| declaration | type_declarations | | | | | declaration | type_declarations | x | x | |
| declaration | net_and_variable_types | | | | | declaration | net_and_variable_types | | | |
| declaration | strengths | | | | | declaration | strengths | | | |
| declaration | delays | x | | | | declaration | delays | x | | |

View File

@ -15,7 +15,7 @@ pub enum ContinuousAssign<'a> {
pub struct ContinuousAssignNet<'a> { pub struct ContinuousAssignNet<'a> {
pub nodes: ( pub nodes: (
Symbol<'a>, Symbol<'a>,
Option<DriveStrength>, Option<DriveStrength<'a>>,
Option<Delay3<'a>>, Option<Delay3<'a>>,
ListOfNetAssignments<'a>, ListOfNetAssignments<'a>,
Symbol<'a>, Symbol<'a>,

View File

@ -13,12 +13,16 @@ pub enum LocalParameterDeclaration<'a> {
#[derive(Debug)] #[derive(Debug)]
pub struct LocalParameterDeclarationParam<'a> { pub struct LocalParameterDeclarationParam<'a> {
pub nodes: (DataTypeOrImplicit<'a>, ListOfParamAssignments<'a>), pub nodes: (
Symbol<'a>,
DataTypeOrImplicit<'a>,
ListOfParamAssignments<'a>,
),
} }
#[derive(Debug)] #[derive(Debug)]
pub struct LocalParameterDeclarationType<'a> { pub struct LocalParameterDeclarationType<'a> {
pub nodes: (ListOfTypeAssignments<'a>,), pub nodes: (Symbol<'a>, Symbol<'a>, ListOfTypeAssignments<'a>),
} }
#[derive(Debug)] #[derive(Debug)]
@ -29,17 +33,26 @@ pub enum ParameterDeclaration<'a> {
#[derive(Debug)] #[derive(Debug)]
pub struct ParameterDeclarationParam<'a> { pub struct ParameterDeclarationParam<'a> {
pub nodes: (DataTypeOrImplicit<'a>, ListOfParamAssignments<'a>), pub nodes: (
Symbol<'a>,
DataTypeOrImplicit<'a>,
ListOfParamAssignments<'a>,
),
} }
#[derive(Debug)] #[derive(Debug)]
pub struct ParameterDeclarationType<'a> { pub struct ParameterDeclarationType<'a> {
pub nodes: (ListOfTypeAssignments<'a>,), pub nodes: (Symbol<'a>, Symbol<'a>, ListOfTypeAssignments<'a>),
} }
#[derive(Debug)] #[derive(Debug)]
pub struct SpecparamDeclaration<'a> { pub struct SpecparamDeclaration<'a> {
pub nodes: (Option<PackedDimension<'a>>, ListOfSpecparamAssignments<'a>), pub nodes: (
Symbol<'a>,
Option<PackedDimension<'a>>,
ListOfSpecparamAssignments<'a>,
Symbol<'a>,
),
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -52,22 +65,22 @@ pub fn local_parameter_declaration(s: Span) -> IResult<Span, LocalParameterDecla
} }
pub fn local_parameter_declaration_param(s: Span) -> IResult<Span, LocalParameterDeclaration> { pub fn local_parameter_declaration_param(s: Span) -> IResult<Span, LocalParameterDeclaration> {
let (s, _) = symbol("localparam")(s)?; let (s, a) = symbol("localparam")(s)?;
let (s, x) = data_type_or_implicit(s)?; let (s, b) = data_type_or_implicit(s)?;
let (s, y) = list_of_param_assignments(s)?; let (s, c) = list_of_param_assignments(s)?;
Ok(( Ok((
s, s,
LocalParameterDeclaration::Param(LocalParameterDeclarationParam { nodes: (x, y) }), LocalParameterDeclaration::Param(LocalParameterDeclarationParam { nodes: (a, b, c) }),
)) ))
} }
pub fn local_parameter_declaration_type(s: Span) -> IResult<Span, LocalParameterDeclaration> { pub fn local_parameter_declaration_type(s: Span) -> IResult<Span, LocalParameterDeclaration> {
let (s, _) = symbol("localparam")(s)?; let (s, a) = symbol("localparam")(s)?;
let (s, _) = symbol("type")(s)?; let (s, b) = symbol("type")(s)?;
let (s, x) = list_of_type_assignments(s)?; let (s, c) = list_of_type_assignments(s)?;
Ok(( Ok((
s, s,
LocalParameterDeclaration::Type(LocalParameterDeclarationType { nodes: (x,) }), LocalParameterDeclaration::Type(LocalParameterDeclarationType { nodes: (a, b, c) }),
)) ))
} }
@ -76,29 +89,34 @@ pub fn parameter_declaration(s: Span) -> IResult<Span, ParameterDeclaration> {
} }
pub fn parameter_declaration_param(s: Span) -> IResult<Span, ParameterDeclaration> { pub fn parameter_declaration_param(s: Span) -> IResult<Span, ParameterDeclaration> {
let (s, _) = symbol("parameter")(s)?; let (s, a) = symbol("parameter")(s)?;
let (s, x) = data_type_or_implicit(s)?; let (s, b) = data_type_or_implicit(s)?;
let (s, y) = list_of_param_assignments(s)?; let (s, c) = list_of_param_assignments(s)?;
Ok(( Ok((
s, s,
ParameterDeclaration::Param(ParameterDeclarationParam { nodes: (x, y) }), ParameterDeclaration::Param(ParameterDeclarationParam { nodes: (a, b, c) }),
)) ))
} }
pub fn parameter_declaration_type(s: Span) -> IResult<Span, ParameterDeclaration> { pub fn parameter_declaration_type(s: Span) -> IResult<Span, ParameterDeclaration> {
let (s, _) = symbol("parameter")(s)?; let (s, a) = symbol("parameter")(s)?;
let (s, _) = symbol("type")(s)?; let (s, b) = symbol("type")(s)?;
let (s, x) = list_of_type_assignments(s)?; let (s, c) = list_of_type_assignments(s)?;
Ok(( Ok((
s, s,
ParameterDeclaration::Type(ParameterDeclarationType { nodes: (x,) }), ParameterDeclaration::Type(ParameterDeclarationType { nodes: (a, b, c) }),
)) ))
} }
pub fn specparam_declaration(s: Span) -> IResult<Span, SpecparamDeclaration> { pub fn specparam_declaration(s: Span) -> IResult<Span, SpecparamDeclaration> {
let (s, _) = symbol("specparam")(s)?; let (s, a) = symbol("specparam")(s)?;
let (s, x) = opt(packed_dimension)(s)?; let (s, b) = opt(packed_dimension)(s)?;
let (s, y) = list_of_specparam_assignments(s)?; let (s, c) = list_of_specparam_assignments(s)?;
let (s, _) = symbol(";")(s)?; let (s, d) = symbol(";")(s)?;
Ok((s, SpecparamDeclaration { nodes: (x, y) })) Ok((
s,
SpecparamDeclaration {
nodes: (a, b, c, d),
},
))
} }

View File

@ -176,19 +176,19 @@ pub enum NonIntegerType {
} }
#[derive(Debug)] #[derive(Debug)]
pub enum NetType { pub enum NetType<'a> {
Supply0, Supply0(Symbol<'a>),
Supply1, Supply1(Symbol<'a>),
Tri, Tri(Symbol<'a>),
Triand, Triand(Symbol<'a>),
Trior, Trior(Symbol<'a>),
Trireg, Trireg(Symbol<'a>),
Tri0, Tri0(Symbol<'a>),
Tri1, Tri1(Symbol<'a>),
Uwire, Uwire(Symbol<'a>),
Wire, Wire(Symbol<'a>),
Wand, Wand(Symbol<'a>),
Wor, Wor(Symbol<'a>),
} }
#[derive(Debug)] #[derive(Debug)]
@ -200,7 +200,7 @@ pub enum NetPortType<'a> {
#[derive(Debug)] #[derive(Debug)]
pub struct NetPortTypeDataType<'a> { pub struct NetPortTypeDataType<'a> {
pub nodes: (Option<NetType>, DataTypeOrImplicit<'a>), pub nodes: (Option<NetType<'a>>, DataTypeOrImplicit<'a>),
} }
#[derive(Debug)] #[derive(Debug)]

View File

@ -8,7 +8,7 @@ use nom::IResult;
#[derive(Debug)] #[derive(Debug)]
pub struct InoutDeclaration<'a> { pub struct InoutDeclaration<'a> {
pub nodes: (NetPortType<'a>, ListOfPortIdentifiers<'a>), pub nodes: (Symbol<'a>, NetPortType<'a>, ListOfPortIdentifiers<'a>),
} }
#[derive(Debug)] #[derive(Debug)]
@ -19,12 +19,16 @@ pub enum InputDeclaration<'a> {
#[derive(Debug)] #[derive(Debug)]
pub struct InputDeclarationNet<'a> { pub struct InputDeclarationNet<'a> {
pub nodes: (NetPortType<'a>, ListOfPortIdentifiers<'a>), pub nodes: (Symbol<'a>, NetPortType<'a>, ListOfPortIdentifiers<'a>),
} }
#[derive(Debug)] #[derive(Debug)]
pub struct InputDeclarationVariable<'a> { pub struct InputDeclarationVariable<'a> {
pub nodes: (VariablePortType<'a>, ListOfVariableIdentifiers<'a>), pub nodes: (
Symbol<'a>,
VariablePortType<'a>,
ListOfVariableIdentifiers<'a>,
),
} }
#[derive(Debug)] #[derive(Debug)]
@ -35,35 +39,43 @@ pub enum OutputDeclaration<'a> {
#[derive(Debug)] #[derive(Debug)]
pub struct OutputDeclarationNet<'a> { pub struct OutputDeclarationNet<'a> {
pub nodes: (NetPortType<'a>, ListOfPortIdentifiers<'a>), pub nodes: (Symbol<'a>, NetPortType<'a>, ListOfPortIdentifiers<'a>),
} }
#[derive(Debug)] #[derive(Debug)]
pub struct OutputDeclarationVariable<'a> { pub struct OutputDeclarationVariable<'a> {
pub nodes: (VariablePortType<'a>, ListOfVariableIdentifiers<'a>), pub nodes: (
Symbol<'a>,
VariablePortType<'a>,
ListOfVariableIdentifiers<'a>,
),
} }
#[derive(Debug)] #[derive(Debug)]
pub struct InterfacePortDeclaration<'a> { pub struct InterfacePortDeclaration<'a> {
pub nodes: ( pub nodes: (
InterfaceIdentifier<'a>, InterfaceIdentifier<'a>,
Option<ModportIdentifier<'a>>, Option<(Symbol<'a>, ModportIdentifier<'a>)>,
ListOfInterfaceIdentifiers<'a>, ListOfInterfaceIdentifiers<'a>,
), ),
} }
#[derive(Debug)] #[derive(Debug)]
pub struct RefDeclaration<'a> { 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<Span, InoutDeclaration> { pub fn inout_declaratrion(s: Span) -> IResult<Span, InoutDeclaration> {
let (s, _) = symbol("inout")(s)?; let (s, a) = symbol("inout")(s)?;
let (s, x) = net_port_type(s)?; let (s, b) = net_port_type(s)?;
let (s, y) = list_of_port_identifiers(s)?; let (s, c) = list_of_port_identifiers(s)?;
Ok((s, InoutDeclaration { nodes: (x, y) })) Ok((s, InoutDeclaration { nodes: (a, b, c) }))
} }
pub fn input_declaratrion(s: Span) -> IResult<Span, InputDeclaration> { pub fn input_declaratrion(s: Span) -> IResult<Span, InputDeclaration> {
@ -71,22 +83,22 @@ pub fn input_declaratrion(s: Span) -> IResult<Span, InputDeclaration> {
} }
pub fn input_declaration_net(s: Span) -> IResult<Span, InputDeclaration> { pub fn input_declaration_net(s: Span) -> IResult<Span, InputDeclaration> {
let (s, _) = symbol("input")(s)?; let (s, a) = symbol("input")(s)?;
let (s, x) = net_port_type(s)?; let (s, b) = net_port_type(s)?;
let (s, y) = list_of_port_identifiers(s)?; let (s, c) = list_of_port_identifiers(s)?;
Ok(( Ok((
s, s,
InputDeclaration::Net(InputDeclarationNet { nodes: (x, y) }), InputDeclaration::Net(InputDeclarationNet { nodes: (a, b, c) }),
)) ))
} }
pub fn input_declaration_variable(s: Span) -> IResult<Span, InputDeclaration> { pub fn input_declaration_variable(s: Span) -> IResult<Span, InputDeclaration> {
let (s, _) = symbol("input")(s)?; let (s, a) = symbol("input")(s)?;
let (s, x) = variable_port_type(s)?; let (s, b) = variable_port_type(s)?;
let (s, y) = list_of_variable_identifiers(s)?; let (s, c) = list_of_variable_identifiers(s)?;
Ok(( Ok((
s, 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<Span, OutputDeclaration> {
} }
pub fn output_declaration_net(s: Span) -> IResult<Span, OutputDeclaration> { pub fn output_declaration_net(s: Span) -> IResult<Span, OutputDeclaration> {
let (s, _) = symbol("output")(s)?; let (s, a) = symbol("output")(s)?;
let (s, x) = net_port_type(s)?; let (s, b) = net_port_type(s)?;
let (s, y) = list_of_port_identifiers(s)?; let (s, c) = list_of_port_identifiers(s)?;
Ok(( Ok((
s, s,
OutputDeclaration::Net(OutputDeclarationNet { nodes: (x, y) }), OutputDeclaration::Net(OutputDeclarationNet { nodes: (a, b, c) }),
)) ))
} }
pub fn output_declaration_variable(s: Span) -> IResult<Span, OutputDeclaration> { pub fn output_declaration_variable(s: Span) -> IResult<Span, OutputDeclaration> {
let (s, _) = symbol("output")(s)?; let (s, a) = symbol("output")(s)?;
let (s, x) = variable_port_type(s)?; let (s, b) = variable_port_type(s)?;
let (s, y) = list_of_variable_identifiers(s)?; let (s, c) = list_of_variable_identifiers(s)?;
Ok(( Ok((
s, s,
OutputDeclaration::Variable(OutputDeclarationVariable { nodes: (x, y) }), OutputDeclaration::Variable(OutputDeclarationVariable { nodes: (a, b, c) }),
)) ))
} }
pub fn interface_port_declaration(s: Span) -> IResult<Span, InterfacePortDeclaration> { pub fn interface_port_declaration(s: Span) -> IResult<Span, InterfacePortDeclaration> {
let (s, x) = interface_identifier(s)?; let (s, a) = interface_identifier(s)?;
let (s, y) = opt(preceded(symbol("."), modport_identifier))(s)?; let (s, b) = opt(pair(symbol("."), modport_identifier))(s)?;
let (s, z) = list_of_interface_identifiers(s)?; let (s, c) = list_of_interface_identifiers(s)?;
Ok((s, InterfacePortDeclaration { nodes: (x, y, z) })) Ok((s, InterfacePortDeclaration { nodes: (a, b, c) }))
} }
pub fn ref_declaration(s: Span) -> IResult<Span, RefDeclaration> { pub fn ref_declaration(s: Span) -> IResult<Span, RefDeclaration> {
let (s, _) = symbol("ref")(s)?; let (s, a) = symbol("ref")(s)?;
let (s, x) = variable_port_type(s)?; let (s, b) = variable_port_type(s)?;
let (s, y) = list_of_variable_identifiers(s)?; let (s, c) = list_of_variable_identifiers(s)?;
Ok((s, RefDeclaration { nodes: (x, y) })) Ok((s, RefDeclaration { nodes: (a, b, c) }))
} }

View File

@ -7,36 +7,36 @@ use nom::{Err, IResult};
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#[derive(Debug)] #[derive(Debug)]
pub enum DriveStrength { pub enum DriveStrength<'a> {
Strength01(Strength0, Strength1), Strength01(Strength0<'a>, Strength1<'a>),
Strength10(Strength1, Strength0), Strength10(Strength1<'a>, Strength0<'a>),
Strength0z(Strength0), Strength0z(Strength0<'a>),
Strength1z(Strength1), Strength1z(Strength1<'a>),
Strengthz0(Strength0), Strengthz0(Strength0<'a>),
Strengthz1(Strength1), Strengthz1(Strength1<'a>),
} }
#[derive(Debug)] #[derive(Debug)]
pub enum Strength0 { pub enum Strength0<'a> {
Supply0, Supply0(Symbol<'a>),
Strong0, Strong0(Symbol<'a>),
Pull0, Pull0(Symbol<'a>),
Weak0, Weak0(Symbol<'a>),
} }
#[derive(Debug)] #[derive(Debug)]
pub enum Strength1 { pub enum Strength1<'a> {
Supply1, Supply1(Symbol<'a>),
Strong1, Strong1(Symbol<'a>),
Pull1, Pull1(Symbol<'a>),
Weak1, Weak1(Symbol<'a>),
} }
#[derive(Debug)] #[derive(Debug)]
pub enum ChargeStrength { pub enum ChargeStrength<'a> {
Small, Small(Symbol<'a>),
Medium, Medium(Symbol<'a>),
Large, Large(Symbol<'a>),
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------

View File

@ -1,3 +1,4 @@
use crate::ast::*;
use crate::parser::*; use crate::parser::*;
use nom::branch::*; use nom::branch::*;
use nom::combinator::*; use nom::combinator::*;
@ -10,58 +11,76 @@ use nom::IResult;
#[derive(Debug)] #[derive(Debug)]
pub enum DataDeclaration<'a> { pub enum DataDeclaration<'a> {
Variable(DataDeclarationVariable<'a>), Variable(DataDeclarationVariable<'a>),
Type(TypeDeclaration<'a>), TypeDeclaration(TypeDeclaration<'a>),
PackageImport(PackageImportDeclaration<'a>), PackageImportDeclaration(PackageImportDeclaration<'a>),
NetType(NetTypeDeclaration<'a>), NetTypeDeclaration(NetTypeDeclaration<'a>),
} }
#[derive(Debug)] #[derive(Debug)]
pub struct DataDeclarationVariable<'a> { pub struct DataDeclarationVariable<'a> {
pub nodes: ( pub nodes: (
Option<Const>, Option<Const<'a>>,
Option<Var>, Option<Var<'a>>,
Option<Lifetime<'a>>, Option<Lifetime<'a>>,
DataTypeOrImplicit<'a>, DataTypeOrImplicit<'a>,
ListOfVariableDeclAssignments<'a>, ListOfVariableDeclAssignments<'a>,
Symbol<'a>,
), ),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct Const {} pub struct Const<'a> {
pub nodes: (Symbol<'a>,),
#[derive(Debug)]
pub struct Var {}
#[derive(Debug)]
pub struct PackageImportDeclaration<'a> {
pub nodes: (Vec<PackageImportItem<'a>>,),
} }
#[derive(Debug)] #[derive(Debug)]
pub struct PackageImportDeclaration<'a> {
pub nodes: (
Symbol<'a>,
List<Symbol<'a>, PackageImportItem<'a>>,
Symbol<'a>,
),
}
#[derive(Debug, Node)]
pub enum PackageImportItem<'a> { pub enum PackageImportItem<'a> {
Identifier(PackageImportItemIdentifier<'a>), Identifier(PackageImportItemIdentifier<'a>),
Asterisk(PackageImportItemAsterisk<'a>), Asterisk(PackageImportItemAsterisk<'a>),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct PackageImportItemIdentifier<'a> { 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 struct PackageImportItemAsterisk<'a> {
pub nodes: (PackageIdentifier<'a>,), pub nodes: (PackageIdentifier<'a>, Symbol<'a>, Symbol<'a>),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub enum PackageExportDeclaration<'a> { pub enum PackageExportDeclaration<'a> {
Asterisk, Asterisk(PackageExportDeclarationAsterisk<'a>),
Item(Vec<PackageImportItem<'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<Symbol<'a>, PackageImportItem<'a>>,
Symbol<'a>,
),
} }
#[derive(Debug)] #[derive(Debug)]
pub struct GenvarDeclaration<'a> { pub struct GenvarDeclaration<'a> {
pub nodes: (ListOfGenvarIdentifiers<'a>,), pub nodes: (Symbol<'a>, ListOfGenvarIdentifiers<'a>, Symbol<'a>),
} }
#[derive(Debug)] #[derive(Debug)]
@ -74,25 +93,26 @@ pub enum NetDeclaration<'a> {
#[derive(Debug)] #[derive(Debug)]
pub struct NetDeclarationNetType<'a> { pub struct NetDeclarationNetType<'a> {
pub nodes: ( pub nodes: (
NetType, NetType<'a>,
Option<Strength>, Option<Strength<'a>>,
Option<VectorScalar>, Option<VectorScalar<'a>>,
DataTypeOrImplicit<'a>, DataTypeOrImplicit<'a>,
Option<Delay3<'a>>, Option<Delay3<'a>>,
ListOfNetDeclAssignments<'a>, ListOfNetDeclAssignments<'a>,
Symbol<'a>,
), ),
} }
#[derive(Debug)] #[derive(Debug)]
pub enum Strength { pub enum Strength<'a> {
Drive(DriveStrength), Drive(DriveStrength<'a>),
Charge(ChargeStrength), Charge(ChargeStrength<'a>),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub enum VectorScalar { pub enum VectorScalar<'a> {
Vectored, Vectored(Symbol<'a>),
Scalared, Scalared(Symbol<'a>),
} }
#[derive(Debug)] #[derive(Debug)]
@ -101,17 +121,20 @@ pub struct NetDeclarationNetTypeIdentifier<'a> {
NetTypeIdentifier<'a>, NetTypeIdentifier<'a>,
Option<DelayControl<'a>>, Option<DelayControl<'a>>,
ListOfNetDeclAssignments<'a>, ListOfNetDeclAssignments<'a>,
Symbol<'a>,
), ),
} }
#[derive(Debug)] #[derive(Debug)]
pub struct NetDeclarationInterconnect<'a> { pub struct NetDeclarationInterconnect<'a> {
pub nodes: ( pub nodes: (
Symbol<'a>,
ImplicitDataType<'a>, ImplicitDataType<'a>,
Option<DelayValue<'a>>, Option<(Symbol<'a>, DelayValue<'a>)>,
NetIdentifier<'a>, NetIdentifier<'a>,
Vec<UnpackedDimension<'a>>, Vec<UnpackedDimension<'a>>,
Option<(NetIdentifier<'a>, Vec<UnpackedDimension<'a>>)>, Option<(Symbol<'a>, NetIdentifier<'a>, Vec<UnpackedDimension<'a>>)>,
Symbol<'a>,
), ),
} }
@ -124,31 +147,45 @@ pub enum TypeDeclaration<'a> {
#[derive(Debug)] #[derive(Debug)]
pub struct TypeDeclarationDataType<'a> { pub struct TypeDeclarationDataType<'a> {
pub nodes: (DataType<'a>, TypeIdentifier<'a>, Vec<VariableDimension<'a>>), pub nodes: (
Symbol<'a>,
DataType<'a>,
TypeIdentifier<'a>,
Vec<VariableDimension<'a>>,
Symbol<'a>,
),
} }
#[derive(Debug)] #[derive(Debug)]
pub struct TypeDeclarationInterface<'a> { pub struct TypeDeclarationInterface<'a> {
pub nodes: ( pub nodes: (
Symbol<'a>,
InterfaceInstanceIdentifier<'a>, InterfaceInstanceIdentifier<'a>,
ConstantBitSelect<'a>, ConstantBitSelect<'a>,
Symbol<'a>,
TypeIdentifier<'a>, TypeIdentifier<'a>,
TypeIdentifier<'a>, TypeIdentifier<'a>,
Symbol<'a>,
), ),
} }
#[derive(Debug)] #[derive(Debug)]
pub struct TypeDeclarationReserved<'a> { pub struct TypeDeclarationReserved<'a> {
pub nodes: (TypeDeclarationKeyword, TypeIdentifier<'a>), pub nodes: (
Symbol<'a>,
TypeDeclarationKeyword<'a>,
TypeIdentifier<'a>,
Symbol<'a>,
),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub enum TypeDeclarationKeyword { pub enum TypeDeclarationKeyword<'a> {
Enum, Enum(Symbol<'a>),
Struct, Struct(Symbol<'a>),
Union, Union(Symbol<'a>),
Class, Class(Symbol<'a>),
InterfaceClass, InterfaceClass((Symbol<'a>, Symbol<'a>)),
} }
#[derive(Debug)] #[derive(Debug)]
@ -160,22 +197,30 @@ pub enum NetTypeDeclaration<'a> {
#[derive(Debug)] #[derive(Debug)]
pub struct NetTypeDeclarationDataType<'a> { pub struct NetTypeDeclarationDataType<'a> {
pub nodes: ( pub nodes: (
Symbol<'a>,
DataType<'a>, DataType<'a>,
NetTypeIdentifier<'a>, NetTypeIdentifier<'a>,
Option<(Option<PackageScopeOrClassScope<'a>>, TfIdentifier<'a>)>, Option<(
Symbol<'a>,
Option<PackageScopeOrClassScope<'a>>,
TfIdentifier<'a>,
)>,
Symbol<'a>,
), ),
} }
#[derive(Debug)] #[derive(Debug)]
pub struct NetTypeDeclarationNetType<'a> { pub struct NetTypeDeclarationNetType<'a> {
pub nodes: ( pub nodes: (
Symbol<'a>,
Option<PackageScopeOrClassScope<'a>>, Option<PackageScopeOrClassScope<'a>>,
NetTypeIdentifier<'a>, NetTypeIdentifier<'a>,
NetTypeIdentifier<'a>, NetTypeIdentifier<'a>,
Symbol<'a>,
), ),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub enum Lifetime<'a> { pub enum Lifetime<'a> {
Static(Symbol<'a>), Static(Symbol<'a>),
Automatic(Symbol<'a>), Automatic(Symbol<'a>),
@ -186,34 +231,41 @@ pub enum Lifetime<'a> {
pub fn data_declaration(s: Span) -> IResult<Span, DataDeclaration> { pub fn data_declaration(s: Span) -> IResult<Span, DataDeclaration> {
alt(( alt((
data_declaration_variable, data_declaration_variable,
map(type_declaration, |x| DataDeclaration::Type(x)), map(type_declaration, |x| DataDeclaration::TypeDeclaration(x)),
map(package_import_declaration, |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) ))(s)
} }
pub fn data_declaration_variable(s: Span) -> IResult<Span, DataDeclaration> { pub fn data_declaration_variable(s: Span) -> IResult<Span, DataDeclaration> {
let (s, x) = opt(symbol("const"))(s)?; let (s, a) = opt(r#const)(s)?;
let (s, y) = opt(symbol("var"))(s)?; let (s, b) = opt(var)(s)?;
let (s, z) = opt(lifetime)(s)?; let (s, c) = opt(lifetime)(s)?;
let (s, v) = data_type_or_implicit(s)?; let (s, d) = data_type_or_implicit(s)?;
let (s, w) = list_of_variable_decl_assignments(s)?; let (s, e) = list_of_variable_decl_assignments(s)?;
let (s, _) = symbol(";")(s)?; let (s, f) = symbol(";")(s)?;
Ok(( Ok((
s, s,
DataDeclaration::Variable(DataDeclarationVariable { 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<Span, Const> {
let (s, a) = symbol("const")(s)?;
Ok((s, Const { nodes: (a,) }))
}
pub fn package_import_declaration(s: Span) -> IResult<Span, PackageImportDeclaration> { pub fn package_import_declaration(s: Span) -> IResult<Span, PackageImportDeclaration> {
let (s, _) = symbol("import")(s)?; let (s, a) = symbol("import")(s)?;
let (s, x) = separated_nonempty_list(symbol(","), package_import_item)(s)?; let (s, b) = list(symbol(","), package_import_item)(s)?;
let (s, _) = symbol(";")(s)?; let (s, c) = symbol(";")(s)?;
Ok((s, PackageImportDeclaration { nodes: (x,) })) Ok((s, PackageImportDeclaration { nodes: (a, b, c) }))
} }
pub fn package_import_item(s: Span) -> IResult<Span, PackageImportItem> { pub fn package_import_item(s: Span) -> IResult<Span, PackageImportItem> {
@ -221,22 +273,22 @@ pub fn package_import_item(s: Span) -> IResult<Span, PackageImportItem> {
} }
pub fn package_import_item_identifier(s: Span) -> IResult<Span, PackageImportItem> { pub fn package_import_item_identifier(s: Span) -> IResult<Span, PackageImportItem> {
let (s, x) = package_identifier(s)?; let (s, a) = package_identifier(s)?;
let (s, _) = symbol("::")(s)?; let (s, b) = symbol("::")(s)?;
let (s, y) = identifier(s)?; let (s, c) = identifier(s)?;
Ok(( Ok((
s, s,
PackageImportItem::Identifier(PackageImportItemIdentifier { nodes: (x, y) }), PackageImportItem::Identifier(PackageImportItemIdentifier { nodes: (a, b, c) }),
)) ))
} }
pub fn package_import_item_asterisk(s: Span) -> IResult<Span, PackageImportItem> { pub fn package_import_item_asterisk(s: Span) -> IResult<Span, PackageImportItem> {
let (s, x) = package_identifier(s)?; let (s, a) = package_identifier(s)?;
let (s, _) = symbol("::")(s)?; let (s, b) = symbol("::")(s)?;
let (s, _) = symbol("*")(s)?; let (s, c) = symbol("*")(s)?;
Ok(( Ok((
s, 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<Span, PackageExportDeclara
} }
pub fn package_export_declaration_asterisk(s: Span) -> IResult<Span, PackageExportDeclaration> { pub fn package_export_declaration_asterisk(s: Span) -> IResult<Span, PackageExportDeclaration> {
let (s, _) = symbol("export")(s)?; let (s, a) = symbol("export")(s)?;
let (s, _) = symbol("*::*")(s)?; let (s, b) = symbol("*::*")(s)?;
let (s, _) = symbol(";")(s)?; let (s, c) = symbol(";")(s)?;
Ok((s, PackageExportDeclaration::Asterisk)) Ok((
s,
PackageExportDeclaration::Asterisk(PackageExportDeclarationAsterisk { nodes: (a, b, c) }),
))
} }
pub fn package_export_declaration_item(s: Span) -> IResult<Span, PackageExportDeclaration> { pub fn package_export_declaration_item(s: Span) -> IResult<Span, PackageExportDeclaration> {
let (s, _) = symbol("export")(s)?; let (s, a) = symbol("export")(s)?;
let (s, x) = separated_nonempty_list(symbol(","), package_import_item)(s)?; let (s, b) = list(symbol(","), package_import_item)(s)?;
let (s, _) = symbol(";")(s)?; let (s, c) = symbol(";")(s)?;
Ok((s, PackageExportDeclaration::Item(x))) Ok((
s,
PackageExportDeclaration::Item(PackageExportDeclarationItem { nodes: (a, b, c) }),
))
} }
pub fn genvar_declaration(s: Span) -> IResult<Span, GenvarDeclaration> { pub fn genvar_declaration(s: Span) -> IResult<Span, GenvarDeclaration> {
let (s, _) = symbol("genvar")(s)?; let (s, a) = symbol("genvar")(s)?;
let (s, x) = list_of_genvar_identifiers(s)?; let (s, b) = list_of_genvar_identifiers(s)?;
Ok((s, GenvarDeclaration { nodes: (x,) })) let (s, c) = symbol(";")(s)?;
Ok((s, GenvarDeclaration { nodes: (a, b, c) }))
} }
pub fn net_declaration(s: Span) -> IResult<Span, NetDeclaration> { pub fn net_declaration(s: Span) -> IResult<Span, NetDeclaration> {
@ -276,17 +335,17 @@ pub fn net_declaration(s: Span) -> IResult<Span, NetDeclaration> {
} }
pub fn net_declaration_net_type(s: Span) -> IResult<Span, NetDeclaration> { pub fn net_declaration_net_type(s: Span) -> IResult<Span, NetDeclaration> {
let (s, x) = net_type(s)?; let (s, a) = net_type(s)?;
let (s, y) = opt(strength)(s)?; let (s, b) = opt(strength)(s)?;
let (s, z) = opt(vector_scalar)(s)?; let (s, c) = opt(vector_scalar)(s)?;
let (s, v) = data_type_or_implicit(s)?; let (s, d) = data_type_or_implicit(s)?;
let (s, w) = opt(delay3)(s)?; let (s, e) = opt(delay3)(s)?;
let (s, u) = list_of_net_decl_assignments(s)?; let (s, f) = list_of_net_decl_assignments(s)?;
let (s, _) = symbol(";")(s)?; let (s, g) = symbol(";")(s)?;
Ok(( Ok((
s, s,
NetDeclaration::NetType(NetDeclarationNetType { 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<Span, Strength> {
pub fn vector_scalar(s: Span) -> IResult<Span, VectorScalar> { pub fn vector_scalar(s: Span) -> IResult<Span, VectorScalar> {
alt(( alt((
map(symbol("vectored"), |_| VectorScalar::Vectored), map(symbol("vectored"), |x| VectorScalar::Vectored(x)),
map(symbol("scalared"), |_| VectorScalar::Scalared), map(symbol("scalared"), |x| VectorScalar::Scalared(x)),
))(s) ))(s)
} }
pub fn net_declaration_net_type_identifier(s: Span) -> IResult<Span, NetDeclaration> { pub fn net_declaration_net_type_identifier(s: Span) -> IResult<Span, NetDeclaration> {
let (s, x) = net_type_identifier(s)?; let (s, a) = net_type_identifier(s)?;
let (s, y) = opt(delay_control)(s)?; let (s, b) = opt(delay_control)(s)?;
let (s, z) = list_of_net_decl_assignments(s)?; let (s, c) = list_of_net_decl_assignments(s)?;
let (s, _) = symbol(";")(s)?; let (s, d) = symbol(";")(s)?;
Ok(( Ok((
s, s,
NetDeclaration::NetTypeIdentifier(NetDeclarationNetTypeIdentifier { nodes: (x, y, z) }), NetDeclaration::NetTypeIdentifier(NetDeclarationNetTypeIdentifier {
nodes: (a, b, c, d),
}),
)) ))
} }
pub fn net_declaration_interconnect(s: Span) -> IResult<Span, NetDeclaration> { pub fn net_declaration_interconnect(s: Span) -> IResult<Span, NetDeclaration> {
let (s, _) = symbol("interconnect")(s)?; let (s, a) = symbol("interconnect")(s)?;
let (s, x) = implicit_data_type(s)?; let (s, b) = implicit_data_type(s)?;
let (s, y) = opt(preceded(symbol("#"), delay_value))(s)?; let (s, c) = opt(pair(symbol("#"), delay_value))(s)?;
let (s, z) = net_identifier(s)?; let (s, d) = net_identifier(s)?;
let (s, v) = many0(unpacked_dimension)(s)?; let (s, e) = many0(unpacked_dimension)(s)?;
let (s, w) = opt(preceded( let (s, f) = opt(triple(
symbol(","), symbol(","),
pair(net_identifier, many0(unpacked_dimension)), net_identifier,
many0(unpacked_dimension),
))(s)?; ))(s)?;
let (s, g) = symbol(";")(s)?;
Ok(( Ok((
s, s,
NetDeclaration::Interconnect(NetDeclarationInterconnect { 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<Span, TypeDeclaration> {
} }
pub fn type_declaration_data_type(s: Span) -> IResult<Span, TypeDeclaration> { pub fn type_declaration_data_type(s: Span) -> IResult<Span, TypeDeclaration> {
let (s, _) = symbol("typedef")(s)?; let (s, a) = symbol("typedef")(s)?;
let (s, x) = data_type(s)?; let (s, b) = data_type(s)?;
let (s, y) = type_identifier(s)?; let (s, c) = type_identifier(s)?;
let (s, z) = many0(variable_dimension)(s)?; let (s, d) = many0(variable_dimension)(s)?;
let (s, _) = symbol(";")(s)?; let (s, e) = symbol(";")(s)?;
Ok(( Ok((
s, 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<Span, TypeDeclaration> { pub fn type_declaration_interface(s: Span) -> IResult<Span, TypeDeclaration> {
let (s, _) = symbol("typedef")(s)?; let (s, a) = symbol("typedef")(s)?;
let (s, x) = interface_instance_identifier(s)?; let (s, b) = interface_instance_identifier(s)?;
let (s, y) = constant_bit_select(s)?; let (s, c) = constant_bit_select(s)?;
let (s, _) = symbol(".")(s)?; let (s, d) = symbol(".")(s)?;
let (s, z) = type_identifier(s)?; let (s, e) = type_identifier(s)?;
let (s, v) = type_identifier(s)?; let (s, f) = type_identifier(s)?;
let (s, _) = symbol(";")(s)?; let (s, g) = symbol(";")(s)?;
Ok(( Ok((
s, s,
TypeDeclaration::Interface(TypeDeclarationInterface { TypeDeclaration::Interface(TypeDeclarationInterface {
nodes: (x, y, z, v), nodes: (a, b, c, d, e, f, g),
}), }),
)) ))
} }
pub fn type_declaration_reserved(s: Span) -> IResult<Span, TypeDeclaration> { pub fn type_declaration_reserved(s: Span) -> IResult<Span, TypeDeclaration> {
let (s, _) = symbol("typedef")(s)?; let (s, a) = symbol("typedef")(s)?;
let (s, x) = type_declaration_keyword(s)?; let (s, b) = type_declaration_keyword(s)?;
let (s, y) = type_identifier(s)?; let (s, c) = type_identifier(s)?;
let (s, _) = symbol(";")(s)?; let (s, d) = symbol(";")(s)?;
Ok(( Ok((
s, s,
TypeDeclaration::Reserved(TypeDeclarationReserved { nodes: (x, y) }), TypeDeclaration::Reserved(TypeDeclarationReserved {
nodes: (a, b, c, d),
}),
)) ))
} }
pub fn type_declaration_keyword(s: Span) -> IResult<Span, TypeDeclarationKeyword> { pub fn type_declaration_keyword(s: Span) -> IResult<Span, TypeDeclarationKeyword> {
alt(( alt((
map(symbol("enum"), |_| TypeDeclarationKeyword::Enum), map(symbol("enum"), |x| TypeDeclarationKeyword::Enum(x)),
map(symbol("struct"), |_| TypeDeclarationKeyword::Struct), map(symbol("struct"), |x| TypeDeclarationKeyword::Struct(x)),
map(symbol("union"), |_| TypeDeclarationKeyword::Union), map(symbol("union"), |x| TypeDeclarationKeyword::Union(x)),
map(symbol("class"), |_| TypeDeclarationKeyword::Class), map(symbol("class"), |x| TypeDeclarationKeyword::Class(x)),
map(pair(symbol("interface"), symbol("class")), |_| { map(pair(symbol("interface"), symbol("class")), |x| {
TypeDeclarationKeyword::InterfaceClass TypeDeclarationKeyword::InterfaceClass(x)
}), }),
))(s) ))(s)
} }
@ -401,29 +468,34 @@ pub fn net_type_declaration(s: Span) -> IResult<Span, NetTypeDeclaration> {
} }
pub fn net_type_declaration_data_type(s: Span) -> IResult<Span, NetTypeDeclaration> { pub fn net_type_declaration_data_type(s: Span) -> IResult<Span, NetTypeDeclaration> {
let (s, _) = symbol("nettype")(s)?; let (s, a) = symbol("nettype")(s)?;
let (s, x) = data_type(s)?; let (s, b) = data_type(s)?;
let (s, y) = net_type_identifier(s)?; let (s, c) = net_type_identifier(s)?;
let (s, z) = opt(preceded( let (s, d) = opt(triple(
symbol("with"), symbol("with"),
pair(opt(package_scope_or_class_scope), tf_identifier), opt(package_scope_or_class_scope),
tf_identifier,
))(s)?; ))(s)?;
let (s, _) = symbol(";")(s)?; let (s, e) = symbol(";")(s)?;
Ok(( Ok((
s, 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<Span, NetTypeDeclaration> { pub fn net_type_declaration_net_type(s: Span) -> IResult<Span, NetTypeDeclaration> {
let (s, _) = symbol("nettype")(s)?; let (s, a) = symbol("nettype")(s)?;
let (s, x) = opt(package_scope_or_class_scope)(s)?; let (s, b) = opt(package_scope_or_class_scope)(s)?;
let (s, y) = net_type_identifier(s)?; let (s, c) = net_type_identifier(s)?;
let (s, z) = net_type_identifier(s)?; let (s, d) = net_type_identifier(s)?;
let (s, _) = symbol(";")(s)?; let (s, e) = symbol(";")(s)?;
Ok(( Ok((
s, s,
NetTypeDeclaration::NetType(NetTypeDeclarationNetType { nodes: (x, y, z) }), NetTypeDeclaration::NetType(NetTypeDeclarationNetType {
nodes: (a, b, c, d, e),
}),
)) ))
} }