Add Paren/Brace/Barcket/List

This commit is contained in:
dalance 2019-07-10 19:55:20 +09:00
parent 26cb4e6818
commit 9983826bdf
13 changed files with 265 additions and 472 deletions

View File

@ -1,7 +1,6 @@
use crate::parser::*;
use nom::branch::*;
use nom::combinator::*;
use nom::multi::*;
use nom::sequence::*;
use nom::IResult;
@ -9,67 +8,45 @@ use nom::IResult;
#[derive(Debug)]
pub struct Concatenation<'a> {
pub nodes: (
Symbol<'a>,
Expression<'a>,
Vec<(Symbol<'a>, Expression<'a>)>,
Symbol<'a>,
),
pub nodes: (Brace<'a, List<Symbol<'a>, Expression<'a>>>,),
}
#[derive(Debug)]
pub struct ConstantConcatenation<'a> {
pub nodes: (
Symbol<'a>,
ConstantExpression<'a>,
Vec<(Symbol<'a>, ConstantExpression<'a>)>,
Symbol<'a>,
),
pub nodes: (Brace<'a, List<Symbol<'a>, ConstantExpression<'a>>>,),
}
#[derive(Debug)]
pub struct ConstantMultipleConcatenation<'a> {
pub nodes: (
Symbol<'a>,
ConstantExpression<'a>,
ConstantConcatenation<'a>,
Symbol<'a>,
),
pub nodes: (Brace<'a, (ConstantExpression<'a>, ConstantConcatenation<'a>)>,),
}
#[derive(Debug)]
pub struct ModulePathConcatenation<'a> {
pub nodes: (
Symbol<'a>,
ModulePathExpression<'a>,
Vec<(Symbol<'a>, ModulePathExpression<'a>)>,
Symbol<'a>,
),
pub nodes: (Brace<'a, List<Symbol<'a>, ModulePathExpression<'a>>>,),
}
#[derive(Debug)]
pub struct ModulePathMultipleConcatenation<'a> {
pub nodes: (
Symbol<'a>,
ConstantExpression<'a>,
ModulePathConcatenation<'a>,
Symbol<'a>,
),
pub nodes: (Brace<'a, (ConstantExpression<'a>, ModulePathConcatenation<'a>)>,),
}
#[derive(Debug)]
pub struct MultipleConcatenation<'a> {
pub nodes: (Symbol<'a>, Expression<'a>, Concatenation<'a>, Symbol<'a>),
pub nodes: (Brace<'a, (Expression<'a>, Concatenation<'a>)>,),
}
#[derive(Debug)]
pub struct StreamingConcatenation<'a> {
pub nodes: (
Symbol<'a>,
StreamOperator<'a>,
Option<SliceSize<'a>>,
StreamConcatenation<'a>,
Symbol<'a>,
Brace<
'a,
(
StreamOperator<'a>,
Option<SliceSize<'a>>,
StreamConcatenation<'a>,
),
>,
),
}
@ -86,22 +63,14 @@ pub enum SliceSize<'a> {
#[derive(Debug)]
pub struct StreamConcatenation<'a> {
pub nodes: (
Symbol<'a>,
StreamExpression<'a>,
Vec<(Symbol<'a>, StreamExpression<'a>)>,
Symbol<'a>,
),
pub nodes: (Brace<'a, List<Symbol<'a>, StreamExpression<'a>>>,),
}
#[derive(Debug)]
pub struct StreamExpression<'a> {
pub nodes: (
Expression<'a>,
Option<(
Symbol<'a>,
(Symbol<'a>, ArrayRangeExpression<'a>, Symbol<'a>),
)>,
Option<(Symbol<'a>, Bracket<'a, ArrayRangeExpression<'a>>)>,
),
}
@ -136,97 +105,44 @@ pub struct EmptyUnpackedArrayConcatenation<'a> {
// -----------------------------------------------------------------------------
pub fn concatenation(s: Span) -> IResult<Span, Concatenation> {
let (s, a) = symbol("{")(s)?;
let (s, b) = expression(s)?;
let (s, c) = many0(pair(symbol(","), expression))(s)?;
let (s, d) = symbol("}")(s)?;
Ok((
s,
Concatenation {
nodes: (a, b, c, d),
},
))
let (s, a) = brace2(list(symbol(","), expression))(s)?;
Ok((s, Concatenation { nodes: (a,) }))
}
pub fn constant_concatenation(s: Span) -> IResult<Span, ConstantConcatenation> {
let (s, a) = symbol("{")(s)?;
let (s, b) = constant_expression(s)?;
let (s, c) = many0(pair(symbol(","), constant_expression))(s)?;
let (s, d) = symbol("}")(s)?;
Ok((
s,
ConstantConcatenation {
nodes: (a, b, c, d),
},
))
let (s, a) = brace2(list(symbol(","), constant_expression))(s)?;
Ok((s, ConstantConcatenation { nodes: (a,) }))
}
pub fn constant_multiple_concatenation(s: Span) -> IResult<Span, ConstantMultipleConcatenation> {
let (s, a) = symbol("{")(s)?;
let (s, b) = constant_expression(s)?;
let (s, c) = constant_concatenation(s)?;
let (s, d) = symbol("}")(s)?;
Ok((
s,
ConstantMultipleConcatenation {
nodes: (a, b, c, d),
},
))
let (s, a) = brace2(pair(constant_expression, constant_concatenation))(s)?;
Ok((s, ConstantMultipleConcatenation { nodes: (a,) }))
}
pub fn module_path_concatenation(s: Span) -> IResult<Span, ModulePathConcatenation> {
let (s, a) = symbol("{")(s)?;
let (s, b) = module_path_expression(s)?;
let (s, c) = many0(pair(symbol(","), module_path_expression))(s)?;
let (s, d) = symbol("}")(s)?;
Ok((
s,
ModulePathConcatenation {
nodes: (a, b, c, d),
},
))
let (s, a) = brace2(list(symbol(","), module_path_expression))(s)?;
Ok((s, ModulePathConcatenation { nodes: (a,) }))
}
pub fn module_path_multiple_concatenation(
s: Span,
) -> IResult<Span, ModulePathMultipleConcatenation> {
let (s, a) = symbol("{")(s)?;
let (s, b) = constant_expression(s)?;
let (s, c) = module_path_concatenation(s)?;
let (s, d) = symbol("}")(s)?;
Ok((
s,
ModulePathMultipleConcatenation {
nodes: (a, b, c, d),
},
))
let (s, a) = brace2(pair(constant_expression, module_path_concatenation))(s)?;
Ok((s, ModulePathMultipleConcatenation { nodes: (a,) }))
}
pub fn multiple_concatenation(s: Span) -> IResult<Span, MultipleConcatenation> {
let (s, a) = symbol("{")(s)?;
let (s, b) = expression(s)?;
let (s, c) = concatenation(s)?;
let (s, d) = symbol("}")(s)?;
Ok((
s,
MultipleConcatenation {
nodes: (a, b, c, d),
},
))
let (s, a) = brace2(pair(expression, concatenation))(s)?;
Ok((s, MultipleConcatenation { nodes: (a,) }))
}
pub fn streaming_concatenation(s: Span) -> IResult<Span, StreamingConcatenation> {
let (s, a) = symbol("{")(s)?;
let (s, b) = stream_operator(s)?;
let (s, c) = opt(slice_size)(s)?;
let (s, d) = stream_concatenation(s)?;
let (s, e) = symbol("}")(s)?;
Ok((
s,
StreamingConcatenation {
nodes: (a, b, c, d, e),
},
))
let (s, a) = brace2(triple(
stream_operator,
opt(slice_size),
stream_concatenation,
))(s)?;
Ok((s, StreamingConcatenation { nodes: (a,) }))
}
pub fn stream_operator(s: Span) -> IResult<Span, StreamOperator> {
@ -244,16 +160,8 @@ pub fn slice_size(s: Span) -> IResult<Span, SliceSize> {
}
pub fn stream_concatenation(s: Span) -> IResult<Span, StreamConcatenation> {
let (s, a) = symbol("{")(s)?;
let (s, b) = stream_expression(s)?;
let (s, c) = many0(pair(symbol(","), stream_expression))(s)?;
let (s, d) = symbol("}")(s)?;
Ok((
s,
StreamConcatenation {
nodes: (a, b, c, d),
},
))
let (s, a) = brace2(list(symbol(","), stream_expression))(s)?;
Ok((s, StreamConcatenation { nodes: (a,) }))
}
pub fn stream_expression(s: Span) -> IResult<Span, StreamExpression> {

View File

@ -1,8 +1,6 @@
use crate::parser::*;
use nom::branch::*;
use nom::combinator::*;
use nom::multi::*;
use nom::sequence::*;
use nom::IResult;
// -----------------------------------------------------------------------------
@ -21,12 +19,7 @@ pub struct NetLvalueIdentifier<'a> {
#[derive(Debug)]
pub struct NetLvalueLvalue<'a> {
pub nodes: (
Symbol<'a>,
NetLvalue<'a>,
Vec<(Symbol<'a>, NetLvalue<'a>)>,
Symbol<'a>,
),
pub nodes: (Brace<'a, List<Symbol<'a>, NetLvalue<'a>>>,),
}
#[derive(Debug)]
@ -56,12 +49,7 @@ pub struct VariableLvalueIdentifier<'a> {
#[derive(Debug)]
pub struct VariableLvalueLvalue<'a> {
pub nodes: (
Symbol<'a>,
VariableLvalue<'a>,
Vec<(Symbol<'a>, VariableLvalue<'a>)>,
Symbol<'a>,
),
pub nodes: (Brace<'a, List<Symbol<'a>, VariableLvalue<'a>>>,),
}
#[derive(Debug)]
@ -103,15 +91,10 @@ pub fn net_lvalue_pattern(s: Span) -> IResult<Span, NetLvalue> {
}
pub fn net_lvalue_lvalue(s: Span) -> IResult<Span, NetLvalue> {
let (s, a) = symbol("{")(s)?;
let (s, b) = net_lvalue(s)?;
let (s, c) = many0(pair(symbol(","), net_lvalue))(s)?;
let (s, d) = symbol("}")(s)?;
let (s, a) = brace2(list(symbol(","), net_lvalue))(s)?;
Ok((
s,
NetLvalue::Lvalue(Box::new(NetLvalueLvalue {
nodes: (a, b, c, d),
})),
NetLvalue::Lvalue(Box::new(NetLvalueLvalue { nodes: (a,) })),
))
}
@ -146,15 +129,10 @@ pub fn variable_lvalue_pattern(s: Span) -> IResult<Span, VariableLvalue> {
}
pub fn variable_lvalue_lvalue(s: Span) -> IResult<Span, VariableLvalue> {
let (s, a) = symbol("{")(s)?;
let (s, b) = variable_lvalue(s)?;
let (s, c) = many0(pair(symbol(","), variable_lvalue))(s)?;
let (s, d) = symbol("}")(s)?;
let (s, a) = brace2(list(symbol(","), variable_lvalue))(s)?;
Ok((
s,
VariableLvalue::Lvalue(Box::new(VariableLvalueLvalue {
nodes: (a, b, c, d),
})),
VariableLvalue::Lvalue(Box::new(VariableLvalueLvalue { nodes: (a,) })),
))
}

View File

@ -153,7 +153,7 @@ pub struct ExpressionUnary<'a> {
#[derive(Debug)]
pub struct ExpressionOperatorAssignment<'a> {
pub nodes: (Symbol<'a>, OperatorAssignment<'a>, Symbol<'a>),
pub nodes: (Paren<'a, OperatorAssignment<'a>>,),
}
#[derive(Debug)]
@ -173,13 +173,7 @@ pub struct TaggedUnionExpression<'a> {
#[derive(Debug)]
pub struct InsideExpression<'a> {
pub nodes: (
Expression<'a>,
Symbol<'a>,
Symbol<'a>,
Vec<ValueRange<'a>>,
Symbol<'a>,
),
pub nodes: (Expression<'a>, Symbol<'a>, Brace<'a, Vec<ValueRange<'a>>>),
}
#[derive(Debug)]
@ -190,13 +184,7 @@ pub enum ValueRange<'a> {
#[derive(Debug)]
pub struct ValueRangeBinary<'a> {
pub nodes: (
Symbol<'a>,
Expression<'a>,
Symbol<'a>,
Expression<'a>,
Symbol<'a>,
),
pub nodes: (Bracket<'a, (Expression<'a>, Symbol<'a>, Expression<'a>)>,),
}
#[derive(Debug)]
@ -494,7 +482,7 @@ pub fn expression_operator_assignment(s: Span) -> IResult<Span, Expression> {
let (s, a) = paren2(operator_assignment)(s)?;
Ok((
s,
Expression::OperatorAssignment(Box::new(ExpressionOperatorAssignment { nodes: a })),
Expression::OperatorAssignment(Box::new(ExpressionOperatorAssignment { nodes: (a,) })),
))
}
@ -521,15 +509,8 @@ pub fn tagged_union_expression(s: Span) -> IResult<Span, TaggedUnionExpression>
pub fn inside_expression(s: Span) -> IResult<Span, InsideExpression> {
let (s, a) = expression(s)?;
let (s, b) = symbol("inside")(s)?;
let (s, c) = symbol("{")(s)?;
let (s, d) = brace(open_range_list)(s)?;
let (s, e) = symbol("}")(s)?;
Ok((
s,
InsideExpression {
nodes: (a, b, c, d, e),
},
))
let (s, c) = brace2(open_range_list)(s)?;
Ok((s, InsideExpression { nodes: (a, b, c) }))
}
pub fn value_range(s: Span) -> IResult<Span, ValueRange> {
@ -540,17 +521,8 @@ pub fn value_range(s: Span) -> IResult<Span, ValueRange> {
}
pub fn value_range_binary(s: Span) -> IResult<Span, ValueRange> {
let (s, a) = symbol("[")(s)?;
let (s, b) = expression(s)?;
let (s, c) = symbol(":")(s)?;
let (s, d) = expression(s)?;
let (s, e) = symbol("]")(s)?;
Ok((
s,
ValueRange::Binary(ValueRangeBinary {
nodes: (a, b, c, d, e),
}),
))
let (s, a) = bracket2(triple(expression, symbol(":"), expression))(s)?;
Ok((s, ValueRange::Binary(ValueRangeBinary { nodes: (a,) })))
}
pub fn mintypmax_expression(s: Span) -> IResult<Span, MintypmaxExpression> {

View File

@ -34,7 +34,7 @@ pub struct ConstantPrimaryPsParameter<'a> {
pub struct ConstantPrimarySpecparam<'a> {
pub nodes: (
SpecparamIdentifier<'a>,
Option<(Symbol<'a>, ConstantRangeExpression<'a>, Symbol<'a>)>,
Option<Bracket<'a, ConstantRangeExpression<'a>>>,
),
}
@ -52,7 +52,7 @@ pub struct ConstantPrimaryEnum<'a> {
pub struct ConstantPrimaryConcatenation<'a> {
pub nodes: (
ConstantConcatenation<'a>,
Option<(Symbol<'a>, ConstantRangeExpression<'a>, Symbol<'a>)>,
Option<Bracket<'a, ConstantRangeExpression<'a>>>,
),
}
@ -60,13 +60,13 @@ pub struct ConstantPrimaryConcatenation<'a> {
pub struct ConstantPrimaryMultipleConcatenation<'a> {
pub nodes: (
ConstantMultipleConcatenation<'a>,
Option<(Symbol<'a>, ConstantRangeExpression<'a>, Symbol<'a>)>,
Option<Bracket<'a, ConstantRangeExpression<'a>>>,
),
}
#[derive(Debug)]
pub struct ConstantPrimaryMintypmaxExpression<'a> {
pub nodes: (Symbol<'a>, ConstantMintypmaxExpression<'a>, Symbol<'a>),
pub nodes: (Paren<'a, ConstantMintypmaxExpression<'a>>,),
}
#[derive(Debug)]
@ -81,7 +81,7 @@ pub enum ModulePathPrimary<'a> {
#[derive(Debug)]
pub struct ModulePathPrimaryMintypmax<'a> {
pub nodes: (Symbol<'a>, ModulePathMintypmaxExpression<'a>, Symbol<'a>),
pub nodes: (Paren<'a, ModulePathMintypmaxExpression<'a>>,),
}
#[derive(Debug)]
@ -114,23 +114,20 @@ pub struct PrimaryHierarchical<'a> {
#[derive(Debug)]
pub struct PrimaryConcatenation<'a> {
pub nodes: (
Concatenation<'a>,
Option<(Symbol<'a>, RangeExpression<'a>, Symbol<'a>)>,
),
pub nodes: (Concatenation<'a>, Option<Bracket<'a, RangeExpression<'a>>>),
}
#[derive(Debug)]
pub struct PrimaryMultipleConcatenation<'a> {
pub nodes: (
MultipleConcatenation<'a>,
Option<(Symbol<'a>, RangeExpression<'a>, Symbol<'a>)>,
Option<Bracket<'a, RangeExpression<'a>>>,
),
}
#[derive(Debug)]
pub struct PrimaryMintypmaxExpression<'a> {
pub nodes: (Symbol<'a>, MintypmaxExpression<'a>, Symbol<'a>),
pub nodes: (Paren<'a, MintypmaxExpression<'a>>,),
}
#[derive(Debug)]
@ -201,7 +198,7 @@ pub enum ImplicitClassHandle<'a> {
#[derive(Debug)]
pub struct BitSelect<'a> {
nodes: (Vec<(Symbol<'a>, Expression<'a>, Symbol<'a>)>,),
nodes: (Vec<Bracket<'a, Expression<'a>>>,),
}
#[derive(Debug)]
@ -213,7 +210,7 @@ pub struct Select<'a> {
MemberIdentifier<'a>,
)>,
BitSelect<'a>,
Option<(Symbol<'a>, PartSelectRange<'a>, Symbol<'a>)>,
Option<Bracket<'a, PartSelectRange<'a>>>,
),
}
@ -231,7 +228,7 @@ pub struct NonrangeSelect<'a> {
#[derive(Debug)]
pub struct ConstantBitSelect<'a> {
nodes: (Vec<(Symbol<'a>, ConstantExpression<'a>, Symbol<'a>)>,),
nodes: (Vec<Bracket<'a, ConstantExpression<'a>>>,),
}
#[derive(Debug)]
@ -243,7 +240,7 @@ pub struct ConstantSelect<'a> {
MemberIdentifier<'a>,
)>,
ConstantBitSelect<'a>,
Option<(Symbol<'a>, ConstantPartSelectRange<'a>, Symbol<'a>)>,
Option<Bracket<'a, ConstantPartSelectRange<'a>>>,
),
}
@ -252,9 +249,7 @@ pub struct ConstantCast<'a> {
pub nodes: (
CastingType<'a>,
Symbol<'a>,
Symbol<'a>,
ConstantExpression<'a>,
Symbol<'a>,
Paren<'a, ConstantExpression<'a>>,
),
}
@ -265,13 +260,7 @@ pub struct ConstantLetExpression<'a> {
#[derive(Debug)]
pub struct Cast<'a> {
pub nodes: (
CastingType<'a>,
Symbol<'a>,
Symbol<'a>,
Expression<'a>,
Symbol<'a>,
),
pub nodes: (CastingType<'a>, Symbol<'a>, Paren<'a, Expression<'a>>),
}
// -----------------------------------------------------------------------------
@ -362,7 +351,7 @@ pub fn constant_primary_mintypmax_expression(s: Span) -> IResult<Span, ConstantP
let (s, a) = paren2(constant_mintypmax_expression)(s)?;
Ok((
s,
ConstantPrimary::MintypmaxExpression(ConstantPrimaryMintypmaxExpression { nodes: a }),
ConstantPrimary::MintypmaxExpression(ConstantPrimaryMintypmaxExpression { nodes: (a,) }),
))
}
@ -387,7 +376,7 @@ pub fn module_path_primary_mintypmax_expression(s: Span) -> IResult<Span, Module
let (s, a) = paren2(module_path_mintypmax_expression)(s)?;
Ok((
s,
ModulePathPrimary::Mintypmax(ModulePathPrimaryMintypmax { nodes: a }),
ModulePathPrimary::Mintypmax(ModulePathPrimaryMintypmax { nodes: (a,) }),
))
}
@ -450,7 +439,7 @@ pub fn primary_mintypmax_expression(s: Span) -> IResult<Span, Primary> {
let (s, a) = paren2(mintypmax_expression)(s)?;
Ok((
s,
Primary::MintypmaxExpression(PrimaryMintypmaxExpression { nodes: a }),
Primary::MintypmaxExpression(PrimaryMintypmaxExpression { nodes: (a,) }),
))
}
@ -583,13 +572,8 @@ pub fn constant_select(s: Span) -> IResult<Span, ConstantSelect> {
pub fn constant_cast(s: Span) -> IResult<Span, ConstantCast> {
let (s, a) = casting_type(s)?;
let (s, b) = symbol("'")(s)?;
let (s, (c, d, e)) = paren2(constant_expression)(s)?;
Ok((
s,
ConstantCast {
nodes: (a, b, c, d, e),
},
))
let (s, c) = paren2(constant_expression)(s)?;
Ok((s, ConstantCast { nodes: (a, b, c) }))
}
pub fn constant_let_expression(s: Span) -> IResult<Span, ConstantLetExpression> {
@ -600,13 +584,8 @@ pub fn constant_let_expression(s: Span) -> IResult<Span, ConstantLetExpression>
pub fn cast(s: Span) -> IResult<Span, Cast> {
let (s, a) = casting_type(s)?;
let (s, b) = symbol("'")(s)?;
let (s, (c, d, e)) = paren2(expression)(s)?;
Ok((
s,
Cast {
nodes: (a, b, c, d, e),
},
))
let (s, c) = paren2(expression)(s)?;
Ok((s, Cast { nodes: (a, b, c) }))
}
// -----------------------------------------------------------------------------

View File

@ -17,7 +17,7 @@ pub struct TfCall<'a> {
pub nodes: (
PsOrHierarchicalTfIdentifier<'a>,
Vec<AttributeInstance<'a>>,
Option<(Symbol<'a>, ListOfArguments<'a>, Symbol<'a>)>,
Option<Paren<'a, ListOfArguments<'a>>>,
),
}
@ -32,7 +32,7 @@ pub enum SystemTfCall<'a> {
pub struct SystemTfCallArgOptional<'a> {
pub nodes: (
SystemTfIdentifier<'a>,
Option<(Symbol<'a>, ListOfArguments<'a>, Symbol<'a>)>,
Option<Paren<'a, ListOfArguments<'a>>>,
),
}
@ -40,10 +40,7 @@ pub struct SystemTfCallArgOptional<'a> {
pub struct SystemTfCallArgDataType<'a> {
pub nodes: (
SystemTfIdentifier<'a>,
Symbol<'a>,
DataType<'a>,
Option<(Symbol<'a>, Expression<'a>)>,
Symbol<'a>,
Paren<'a, (DataType<'a>, Option<(Symbol<'a>, Expression<'a>)>)>,
),
}
@ -51,11 +48,13 @@ pub struct SystemTfCallArgDataType<'a> {
pub struct SystemTfCallArgExpression<'a> {
pub nodes: (
SystemTfIdentifier<'a>,
Symbol<'a>,
Expression<'a>,
Vec<(Symbol<'a>, Option<Expression<'a>>)>,
Option<(Symbol<'a>, Option<ClockingEvent<'a>>)>,
Symbol<'a>,
Paren<
'a,
(
List<Symbol<'a>, Option<Expression<'a>>>,
Option<(Symbol<'a>, Option<ClockingEvent<'a>>)>,
),
>,
),
}
@ -86,15 +85,12 @@ pub enum ListOfArguments<'a> {
#[derive(Debug)]
pub struct ListOfArgumentsOrdered<'a> {
pub nodes: (
Option<Expression<'a>>,
Vec<(Symbol<'a>, Option<Expression<'a>>)>,
List<Symbol<'a>, Option<Expression<'a>>>,
Vec<(
Symbol<'a>,
Symbol<'a>,
Identifier<'a>,
Symbol<'a>,
Option<Expression<'a>>,
Symbol<'a>,
Paren<'a, Option<Expression<'a>>>,
)>,
),
}
@ -104,16 +100,12 @@ pub struct ListOfArgumentsNamed<'a> {
pub nodes: (
Symbol<'a>,
Identifier<'a>,
Symbol<'a>,
Option<Expression<'a>>,
Symbol<'a>,
Paren<'a, Option<Expression<'a>>>,
Vec<(
Symbol<'a>,
Symbol<'a>,
Identifier<'a>,
Symbol<'a>,
Option<Expression<'a>>,
Symbol<'a>,
Paren<'a, Option<Expression<'a>>>,
)>,
),
}
@ -134,7 +126,7 @@ pub struct MethodCallBodyUser<'a> {
pub nodes: (
MethodIdentifier<'a>,
Vec<AttributeInstance<'a>>,
Option<(Symbol<'a>, ListOfArguments<'a>, Symbol<'a>)>,
Option<Paren<'a, ListOfArguments<'a>>>,
),
}
@ -149,8 +141,8 @@ pub struct ArrayManipulationCall<'a> {
pub nodes: (
ArrayMethodName<'a>,
Vec<AttributeInstance<'a>>,
Option<(Symbol<'a>, ListOfArguments<'a>, Symbol<'a>)>,
Option<(Symbol<'a>, (Symbol<'a>, Expression<'a>, Symbol<'a>))>,
Option<Paren<'a, ListOfArguments<'a>>>,
Option<(Symbol<'a>, Paren<'a, Expression<'a>>)>,
),
}
@ -159,14 +151,10 @@ pub struct RandomizeCall<'a> {
pub nodes: (
Symbol<'a>,
Vec<AttributeInstance<'a>>,
Option<Paren<'a, Option<VariableIdentifierListOrNull<'a>>>>,
Option<(
Symbol<'a>,
Option<VariableIdentifierListOrNull<'a>>,
Symbol<'a>,
)>,
Option<(
Symbol<'a>,
Option<(Symbol<'a>, Option<IdentifierList<'a>>, Symbol<'a>)>,
Option<Paren<'a, Option<IdentifierList<'a>>>>,
ConstraintBlock<'a>,
)>,
),
@ -226,30 +214,22 @@ pub fn system_tf_call_arg_optional(s: Span) -> IResult<Span, SystemTfCall> {
pub fn system_tf_call_arg_data_type(s: Span) -> IResult<Span, SystemTfCall> {
let (s, a) = system_tf_identifier(s)?;
let (s, b) = symbol("(")(s)?;
let (s, c) = data_type(s)?;
let (s, d) = opt(pair(symbol(","), expression))(s)?;
let (s, e) = symbol(")")(s)?;
let (s, b) = paren2(pair(data_type, opt(pair(symbol(","), expression))))(s)?;
Ok((
s,
SystemTfCall::ArgDataType(SystemTfCallArgDataType {
nodes: (a, b, c, d, e),
}),
SystemTfCall::ArgDataType(SystemTfCallArgDataType { nodes: (a, b) }),
))
}
pub fn system_tf_call_arg_expression(s: Span) -> IResult<Span, SystemTfCall> {
let (s, a) = system_tf_identifier(s)?;
let (s, b) = symbol("(")(s)?;
let (s, c) = expression(s)?;
let (s, d) = many0(pair(symbol(","), opt(expression)))(s)?;
let (s, e) = opt(pair(symbol(","), opt(clocking_event)))(s)?;
let (s, f) = symbol(")")(s)?;
let (s, b) = paren2(pair(
list(symbol(","), opt(expression)),
opt(pair(symbol(","), opt(clocking_event))),
))(s)?;
Ok((
s,
SystemTfCall::ArgExpression(SystemTfCallArgExpression {
nodes: (a, b, c, d, e, f),
}),
SystemTfCall::ArgExpression(SystemTfCallArgExpression { nodes: (a, b) }),
))
}
@ -282,40 +262,33 @@ pub fn list_of_arguments(s: Span) -> IResult<Span, ListOfArguments> {
}
pub fn list_of_arguments_ordered(s: Span) -> IResult<Span, ListOfArguments> {
let (s, a) = opt(expression)(s)?;
let (s, b) = many0(pair(symbol(","), opt(expression)))(s)?;
let (s, c) = many0(tuple((
let (s, a) = list(symbol(","), opt(expression))(s)?;
let (s, b) = many0(tuple((
symbol(","),
symbol("."),
identifier,
symbol("("),
opt(expression),
symbol(")"),
paren2(opt(expression)),
)))(s)?;
Ok((
s,
ListOfArguments::Ordered(ListOfArgumentsOrdered { nodes: (a, b, c) }),
ListOfArguments::Ordered(ListOfArgumentsOrdered { nodes: (a, b) }),
))
}
pub fn list_of_arguments_named(s: Span) -> IResult<Span, ListOfArguments> {
let (s, a) = symbol(".")(s)?;
let (s, b) = identifier(s)?;
let (s, c) = symbol("(")(s)?;
let (s, d) = opt(expression)(s)?;
let (s, e) = symbol(")")(s)?;
let (s, f) = many0(tuple((
let (s, c) = paren2(opt(expression))(s)?;
let (s, d) = many0(tuple((
symbol(","),
symbol("."),
identifier,
symbol("("),
opt(expression),
symbol(")"),
paren2(opt(expression)),
)))(s)?;
Ok((
s,
ListOfArguments::Named(ListOfArgumentsNamed {
nodes: (a, b, c, d, e, f),
nodes: (a, b, c, d),
}),
))
}

View File

@ -1,6 +1,5 @@
use crate::parser::*;
use nom::combinator::*;
use nom::multi::*;
use nom::sequence::*;
use nom::IResult;
@ -8,12 +7,7 @@ use nom::IResult;
#[derive(Debug)]
pub struct AttributeInstance<'a> {
pub nodes: (
Symbol<'a>,
AttrSpec<'a>,
Vec<(Symbol<'a>, AttrSpec<'a>)>,
Symbol<'a>,
),
pub nodes: (Symbol<'a>, List<Symbol<'a>, AttrSpec<'a>>, Symbol<'a>),
}
#[derive(Debug)]
@ -25,15 +19,9 @@ pub struct AttrSpec<'a> {
pub fn attribute_instance(s: Span) -> IResult<Span, AttributeInstance> {
let (s, a) = symbol("(*")(s)?;
let (s, b) = attr_spec(s)?;
let (s, c) = many0(pair(symbol(","), attr_spec))(s)?;
let (s, d) = symbol("*)")(s)?;
Ok((
s,
AttributeInstance {
nodes: (a, b, c, d),
},
))
let (s, b) = list(symbol(","), attr_spec)(s)?;
let (s, c) = symbol("*)")(s)?;
Ok((s, AttributeInstance { nodes: (a, b, c) }))
}
pub fn attr_spec(s: Span) -> IResult<Span, AttrSpec> {

View File

@ -2,7 +2,6 @@ use crate::parser::*;
use nom::branch::*;
use nom::combinator::*;
use nom::multi::*;
use nom::sequence::*;
use nom::IResult;
// -----------------------------------------------------------------------------
@ -12,9 +11,7 @@ pub struct CheckerInstantiation<'a> {
pub nodes: (
PsCheckerIdentifier<'a>,
NameOfInstance<'a>,
Symbol<'a>,
Option<ListOfCheckerPortConnections<'a>>,
Symbol<'a>,
Paren<'a, Option<ListOfCheckerPortConnections<'a>>>,
Symbol<'a>,
),
}
@ -27,18 +24,12 @@ pub enum ListOfCheckerPortConnections<'a> {
#[derive(Debug)]
pub struct ListOfCheckerPortConnectionsOrdered<'a> {
pub nodes: (
OrderedCheckerPortConnection<'a>,
Vec<(Symbol<'a>, OrderedCheckerPortConnection<'a>)>,
),
pub nodes: (List<Symbol<'a>, OrderedCheckerPortConnection<'a>>,),
}
#[derive(Debug)]
pub struct ListOfCheckerPortConnectionsNamed<'a> {
pub nodes: (
NamedCheckerPortConnection<'a>,
Vec<(Symbol<'a>, NamedCheckerPortConnection<'a>)>,
),
pub nodes: (List<Symbol<'a>, NamedCheckerPortConnection<'a>>,),
}
#[derive(Debug)]
@ -58,7 +49,7 @@ pub struct NamedCheckerPortConnectionIdentifier<'a> {
Vec<AttributeInstance<'a>>,
Symbol<'a>,
FormalPortIdentifier<'a>,
Option<(Symbol<'a>, Option<PropertyActualArg<'a>>, Symbol<'a>)>,
Option<Paren<'a, Option<PropertyActualArg<'a>>>>,
),
}
@ -72,12 +63,12 @@ pub struct NamedCheckerPortConnectionAsterisk<'a> {
pub fn checker_instantiation(s: Span) -> IResult<Span, CheckerInstantiation> {
let (s, a) = ps_checker_identifier(s)?;
let (s, b) = name_of_instance(s)?;
let (s, (c, d, e)) = paren2(opt(list_of_checker_port_connections))(s)?;
let (s, f) = symbol(";")(s)?;
let (s, c) = paren2(opt(list_of_checker_port_connections))(s)?;
let (s, d) = symbol(";")(s)?;
Ok((
s,
CheckerInstantiation {
nodes: (a, b, c, d, e, f),
nodes: (a, b, c, d),
},
))
}
@ -92,24 +83,20 @@ pub fn list_of_checker_port_connections(s: Span) -> IResult<Span, ListOfCheckerP
pub fn list_of_checker_port_connections_ordered(
s: Span,
) -> IResult<Span, ListOfCheckerPortConnections> {
let (s, a) = ordered_checker_port_connection(s)?;
let (s, b) = many0(pair(symbol(","), ordered_checker_port_connection))(s)?;
let (s, a) = list(symbol(","), ordered_checker_port_connection)(s)?;
Ok((
s,
ListOfCheckerPortConnections::Ordered(ListOfCheckerPortConnectionsOrdered {
nodes: (a, b),
}),
ListOfCheckerPortConnections::Ordered(ListOfCheckerPortConnectionsOrdered { nodes: (a,) }),
))
}
pub fn list_of_checker_port_connections_named(
s: Span,
) -> IResult<Span, ListOfCheckerPortConnections> {
let (s, a) = named_checker_port_connection(s)?;
let (s, b) = many0(pair(symbol(","), named_checker_port_connection))(s)?;
let (s, a) = list(symbol(","), named_checker_port_connection)(s)?;
Ok((
s,
ListOfCheckerPortConnections::Named(ListOfCheckerPortConnectionsNamed { nodes: (a, b) }),
ListOfCheckerPortConnections::Named(ListOfCheckerPortConnectionsNamed { nodes: (a,) }),
))
}

View File

@ -1,7 +1,5 @@
use crate::parser::*;
use nom::combinator::*;
use nom::multi::*;
use nom::sequence::*;
use nom::IResult;
// -----------------------------------------------------------------------------
@ -11,8 +9,7 @@ pub struct InterfaceInstantiation<'a> {
pub nodes: (
InterfaceIdentifier<'a>,
Option<ParameterValueAssignment<'a>>,
HierarchicalInstance<'a>,
Vec<(Symbol<'a>, HierarchicalInstance<'a>)>,
List<Symbol<'a>, HierarchicalInstance<'a>>,
Symbol<'a>,
),
}
@ -22,13 +19,12 @@ pub struct InterfaceInstantiation<'a> {
pub fn interface_instantiation(s: Span) -> IResult<Span, InterfaceInstantiation> {
let (s, a) = interface_identifier(s)?;
let (s, b) = opt(parameter_value_assignment)(s)?;
let (s, c) = hierarchical_instance(s)?;
let (s, d) = many0(pair(symbol(","), hierarchical_instance))(s)?;
let (s, e) = symbol(";")(s)?;
let (s, c) = list(symbol(","), hierarchical_instance)(s)?;
let (s, d) = symbol(";")(s)?;
Ok((
s,
InterfaceInstantiation {
nodes: (a, b, c, d, e),
nodes: (a, b, c, d),
},
))
}

View File

@ -2,7 +2,6 @@ use crate::parser::*;
use nom::branch::*;
use nom::combinator::*;
use nom::multi::*;
use nom::sequence::*;
use nom::IResult;
// -----------------------------------------------------------------------------
@ -12,8 +11,7 @@ pub struct ModuleInstantiation<'a> {
pub nodes: (
ModuleIdentifier<'a>,
Option<ParameterValueAssignment<'a>>,
HierarchicalInstance<'a>,
Vec<(Symbol<'a>, HierarchicalInstance<'a>)>,
List<Symbol<'a>, HierarchicalInstance<'a>>,
Symbol<'a>,
),
}
@ -22,11 +20,7 @@ pub struct ModuleInstantiation<'a> {
pub struct ParameterValueAssignment<'a> {
pub nodes: (
Symbol<'a>,
(
Symbol<'a>,
Option<ListOfParameterAssignments<'a>>,
Symbol<'a>,
),
Paren<'a, Option<ListOfParameterAssignments<'a>>>,
),
}
@ -38,18 +32,12 @@ pub enum ListOfParameterAssignments<'a> {
#[derive(Debug)]
pub struct ListOfParameterAssignmentsOrdered<'a> {
pub nodes: (
OrderedParameterAssignment<'a>,
Vec<(Symbol<'a>, OrderedParameterAssignment<'a>)>,
),
pub nodes: (List<Symbol<'a>, OrderedParameterAssignment<'a>>,),
}
#[derive(Debug)]
pub struct ListOfParameterAssignmentsNamed<'a> {
pub nodes: (
NamedParameterAssignment<'a>,
Vec<(Symbol<'a>, NamedParameterAssignment<'a>)>,
),
pub nodes: (List<Symbol<'a>, NamedParameterAssignment<'a>>,),
}
#[derive(Debug)]
@ -62,7 +50,7 @@ pub struct NamedParameterAssignment<'a> {
pub nodes: (
Symbol<'a>,
ParameterIdentifier<'a>,
(Symbol<'a>, Option<ParamExpression<'a>>, Symbol<'a>),
Paren<'a, Option<ParamExpression<'a>>>,
),
}
@ -70,7 +58,7 @@ pub struct NamedParameterAssignment<'a> {
pub struct HierarchicalInstance<'a> {
pub nodes: (
NameOfInstance<'a>,
(Symbol<'a>, Option<ListOfPortConnections<'a>>, Symbol<'a>),
Paren<'a, Option<ListOfPortConnections<'a>>>,
),
}
@ -87,18 +75,12 @@ pub enum ListOfPortConnections<'a> {
#[derive(Debug)]
pub struct ListOfPortConnectionsOrdered<'a> {
pub nodes: (
OrderedPortConnection<'a>,
Vec<(Symbol<'a>, OrderedPortConnection<'a>)>,
),
pub nodes: (List<Symbol<'a>, OrderedPortConnection<'a>>,),
}
#[derive(Debug)]
pub struct ListOfPortConnectionsNamed<'a> {
pub nodes: (
NamedPortConnection<'a>,
Vec<(Symbol<'a>, NamedPortConnection<'a>)>,
),
pub nodes: (List<Symbol<'a>, NamedPortConnection<'a>>,),
}
#[derive(Debug)]
@ -118,7 +100,7 @@ pub struct NamedPortConnectionIdentifier<'a> {
Vec<AttributeInstance<'a>>,
Symbol<'a>,
PortIdentifier<'a>,
Option<(Symbol<'a>, Option<Expression<'a>>, Symbol<'a>)>,
Option<Paren<'a, Option<Expression<'a>>>>,
),
}
@ -132,13 +114,12 @@ pub struct NamedPortConnectionAsterisk<'a> {
pub fn module_instantiation(s: Span) -> IResult<Span, ModuleInstantiation> {
let (s, a) = module_identifier(s)?;
let (s, b) = opt(parameter_value_assignment)(s)?;
let (s, c) = hierarchical_instance(s)?;
let (s, d) = many0(pair(symbol(","), hierarchical_instance))(s)?;
let (s, e) = symbol(";")(s)?;
let (s, c) = list(symbol(","), hierarchical_instance)(s)?;
let (s, d) = symbol(";")(s)?;
Ok((
s,
ModuleInstantiation {
nodes: (a, b, c, d, e),
nodes: (a, b, c, d),
},
))
}
@ -157,20 +138,18 @@ pub fn list_of_parameter_assignments(s: Span) -> IResult<Span, ListOfParameterAs
}
pub fn list_of_parameter_assignments_ordered(s: Span) -> IResult<Span, ListOfParameterAssignments> {
let (s, a) = ordered_parameter_assignment(s)?;
let (s, b) = many0(pair(symbol(","), ordered_parameter_assignment))(s)?;
let (s, a) = list(symbol(","), ordered_parameter_assignment)(s)?;
Ok((
s,
ListOfParameterAssignments::Ordered(ListOfParameterAssignmentsOrdered { nodes: (a, b) }),
ListOfParameterAssignments::Ordered(ListOfParameterAssignmentsOrdered { nodes: (a,) }),
))
}
pub fn list_of_parameter_assignments_named(s: Span) -> IResult<Span, ListOfParameterAssignments> {
let (s, a) = named_parameter_assignment(s)?;
let (s, b) = many0(pair(symbol(","), named_parameter_assignment))(s)?;
let (s, a) = list(symbol(","), named_parameter_assignment)(s)?;
Ok((
s,
ListOfParameterAssignments::Named(ListOfParameterAssignmentsNamed { nodes: (a, b) }),
ListOfParameterAssignments::Named(ListOfParameterAssignmentsNamed { nodes: (a,) }),
))
}
@ -206,20 +185,18 @@ pub fn list_of_port_connections(s: Span) -> IResult<Span, ListOfPortConnections>
}
pub fn list_of_port_connections_ordered(s: Span) -> IResult<Span, ListOfPortConnections> {
let (s, a) = ordered_port_connection(s)?;
let (s, b) = many0(pair(symbol(","), ordered_port_connection))(s)?;
let (s, a) = list(symbol(","), ordered_port_connection)(s)?;
Ok((
s,
ListOfPortConnections::Ordered(ListOfPortConnectionsOrdered { nodes: (a, b) }),
ListOfPortConnections::Ordered(ListOfPortConnectionsOrdered { nodes: (a,) }),
))
}
pub fn list_of_port_connections_named(s: Span) -> IResult<Span, ListOfPortConnections> {
let (s, a) = named_port_connection(s)?;
let (s, b) = many0(pair(symbol(","), named_port_connection))(s)?;
let (s, a) = list(symbol(","), named_port_connection)(s)?;
Ok((
s,
ListOfPortConnections::Named(ListOfPortConnectionsNamed { nodes: (a, b) }),
ListOfPortConnections::Named(ListOfPortConnectionsNamed { nodes: (a,) }),
))
}

View File

@ -1,7 +1,5 @@
use crate::parser::*;
use nom::combinator::*;
use nom::multi::*;
use nom::sequence::*;
use nom::IResult;
// -----------------------------------------------------------------------------
@ -11,8 +9,7 @@ pub struct ProgramInstantiation<'a> {
pub nodes: (
ProgramIdentifier<'a>,
Option<ParameterValueAssignment<'a>>,
HierarchicalInstance<'a>,
Vec<(Symbol<'a>, HierarchicalInstance<'a>)>,
List<Symbol<'a>, HierarchicalInstance<'a>>,
Symbol<'a>,
),
}
@ -22,13 +19,12 @@ pub struct ProgramInstantiation<'a> {
pub fn program_instantiation(s: Span) -> IResult<Span, ProgramInstantiation> {
let (s, a) = program_identifier(s)?;
let (s, b) = opt(parameter_value_assignment)(s)?;
let (s, c) = hierarchical_instance(s)?;
let (s, d) = many0(pair(symbol(","), hierarchical_instance))(s)?;
let (s, e) = symbol(";")(s)?;
let (s, c) = list(symbol(","), hierarchical_instance)(s)?;
let (s, d) = symbol(";")(s)?;
Ok((
s,
ProgramInstantiation {
nodes: (a, b, c, d, e),
nodes: (a, b, c, d),
},
))
}

View File

@ -25,13 +25,8 @@ pub struct LibraryDeclaration<'a> {
pub nodes: (
Symbol<'a>,
LibraryIdentifier<'a>,
FilePathSpec<'a>,
Vec<(Symbol<'a>, FilePathSpec<'a>)>,
Option<(
Symbol<'a>,
FilePathSpec<'a>,
Vec<(Symbol<'a>, FilePathSpec<'a>)>,
)>,
List<Symbol<'a>, FilePathSpec<'a>>,
Option<(Symbol<'a>, List<Symbol<'a>, FilePathSpec<'a>>)>,
Symbol<'a>,
),
}
@ -71,18 +66,13 @@ pub fn library_description(s: Span) -> IResult<Span, LibraryDescription> {
pub fn library_declaration(s: Span) -> IResult<Span, LibraryDeclaration> {
let (s, a) = symbol("library")(s)?;
let (s, b) = library_identifier(s)?;
let (s, c) = file_path_spec(s)?;
let (s, d) = many0(pair(symbol(","), file_path_spec))(s)?;
let (s, e) = opt(triple(
symbol("-incdir"),
file_path_spec,
many0(pair(symbol(","), file_path_spec)),
))(s)?;
let (s, f) = symbol(";")(s)?;
let (s, c) = list(symbol(","), file_path_spec)(s)?;
let (s, d) = opt(pair(symbol("-incdir"), list(symbol(","), file_path_spec)))(s)?;
let (s, e) = symbol(";")(s)?;
Ok((
s,
LibraryDeclaration {
nodes: (a, b, c, d, e, f),
nodes: (a, b, c, d, e),
},
))
}

View File

@ -100,9 +100,7 @@ pub struct ModuleDeclarationWildcard<'a> {
ModuleKeyword<'a>,
Option<Lifetime<'a>>,
ModuleIdentifier<'a>,
Symbol<'a>,
Symbol<'a>,
Symbol<'a>,
Paren<'a, Symbol<'a>>,
Symbol<'a>,
Option<TimeunitsDeclaration<'a>>,
Vec<ModuleItem<'a>>,
@ -165,9 +163,7 @@ pub struct InterfaceDeclarationWildcard<'a> {
Symbol<'a>,
Option<Lifetime<'a>>,
InterfaceIdentifier<'a>,
Symbol<'a>,
Symbol<'a>,
Symbol<'a>,
Paren<'a, Symbol<'a>>,
Symbol<'a>,
Option<TimeunitsDeclaration<'a>>,
Vec<InterfaceItem<'a>>,
@ -251,9 +247,7 @@ pub struct ProgramDeclarationWildcard<'a> {
Vec<AttributeInstance<'a>>,
Symbol<'a>,
ProgramIdentifier<'a>,
Symbol<'a>,
Symbol<'a>,
Symbol<'a>,
Paren<'a, Symbol<'a>>,
Symbol<'a>,
Option<TimeunitsDeclaration<'a>>,
Vec<ProgramItem<'a>>,
@ -305,7 +299,7 @@ pub struct CheckerDeclaration<'a> {
pub nodes: (
Symbol<'a>,
CheckerIdentifier<'a>,
Option<(Symbol<'a>, Option<CheckerPortList<'a>>, Symbol<'a>)>,
Option<Paren<'a, Option<CheckerPortList<'a>>>>,
Symbol<'a>,
Vec<(Vec<AttributeInstance<'a>>, CheckerOrGenerateItem<'a>)>,
Symbol<'a>,
@ -324,13 +318,9 @@ pub struct ClassDeclaration<'a> {
Option<(
Symbol<'a>,
ClassType<'a>,
Option<(Symbol<'a>, ListOfArguments<'a>, Symbol<'a>)>,
)>,
Option<(
Symbol<'a>,
InterfaceClassType<'a>,
Vec<(Symbol<'a>, InterfaceClassType<'a>)>,
Option<Paren<'a, ListOfArguments<'a>>>,
)>,
Option<(Symbol<'a>, List<Symbol<'a>, InterfaceClassType<'a>>)>,
Symbol<'a>,
Vec<ClassItem<'a>>,
Symbol<'a>,
@ -355,11 +345,7 @@ pub struct InterfaceClassDeclaration<'a> {
Symbol<'a>,
ClassIdentifier<'a>,
Option<ParameterPortList<'a>>,
Option<(
Symbol<'a>,
InterfaceClassType<'a>,
Vec<(Symbol<'a>, InterfaceClassType<'a>)>,
)>,
Option<(Symbol<'a>, List<Symbol<'a>, InterfaceClassType<'a>>)>,
Symbol<'a>,
Vec<InterfaceClassItem<'a>>,
Symbol<'a>,
@ -566,18 +552,16 @@ pub fn module_declaration_wildcard(s: Span) -> IResult<Span, ModuleDeclaration>
let (s, b) = module_keyword(s)?;
let (s, c) = opt(lifetime)(s)?;
let (s, d) = module_identifier(s)?;
let (s, e) = symbol("(")(s)?;
let (s, f) = symbol(".*")(s)?;
let (s, g) = symbol(")")(s)?;
let (s, h) = symbol(";")(s)?;
let (s, i) = opt(timeunits_declaration)(s)?;
let (s, j) = many0(module_item)(s)?;
let (s, k) = symbol("endmodule")(s)?;
let (s, l) = opt(pair(symbol(":"), module_identifier))(s)?;
let (s, e) = paren2(symbol(".*"))(s)?;
let (s, f) = symbol(";")(s)?;
let (s, g) = opt(timeunits_declaration)(s)?;
let (s, h) = many0(module_item)(s)?;
let (s, i) = symbol("endmodule")(s)?;
let (s, j) = opt(pair(symbol(":"), module_identifier))(s)?;
Ok((
s,
ModuleDeclaration::Wildcard(ModuleDeclarationWildcard {
nodes: (a, b, c, d, e, f, g, h, i, j, k, l),
nodes: (a, b, c, d, e, f, g, h, i, j),
}),
))
}
@ -650,18 +634,16 @@ pub fn interface_declaration_wildcard(s: Span) -> IResult<Span, InterfaceDeclara
let (s, b) = symbol("interface")(s)?;
let (s, c) = opt(lifetime)(s)?;
let (s, d) = interface_identifier(s)?;
let (s, e) = symbol("(")(s)?;
let (s, f) = symbol(".*")(s)?;
let (s, g) = symbol(")")(s)?;
let (s, h) = symbol(";")(s)?;
let (s, i) = opt(timeunits_declaration)(s)?;
let (s, j) = many0(interface_item)(s)?;
let (s, k) = symbol("endinterface")(s)?;
let (s, l) = opt(pair(symbol(":"), interface_identifier))(s)?;
let (s, e) = paren2(symbol(".*"))(s)?;
let (s, f) = symbol(";")(s)?;
let (s, g) = opt(timeunits_declaration)(s)?;
let (s, h) = many0(interface_item)(s)?;
let (s, i) = symbol("endinterface")(s)?;
let (s, j) = opt(pair(symbol(":"), interface_identifier))(s)?;
Ok((
s,
InterfaceDeclaration::Wildcard(InterfaceDeclarationWildcard {
nodes: (a, b, c, d, e, f, g, h, i, j, k, l),
nodes: (a, b, c, d, e, f, g, h, i, j),
}),
))
}
@ -760,18 +742,16 @@ pub fn program_declaration_wildcard(s: Span) -> IResult<Span, ProgramDeclaration
let (s, a) = many0(attribute_instance)(s)?;
let (s, b) = symbol("program")(s)?;
let (s, c) = program_identifier(s)?;
let (s, d) = symbol("(")(s)?;
let (s, e) = symbol(".*")(s)?;
let (s, f) = symbol(")")(s)?;
let (s, g) = symbol(";")(s)?;
let (s, h) = opt(timeunits_declaration)(s)?;
let (s, i) = many0(program_item)(s)?;
let (s, j) = symbol("endprogram")(s)?;
let (s, k) = opt(pair(symbol(":"), program_identifier))(s)?;
let (s, d) = paren2(symbol(".*"))(s)?;
let (s, e) = symbol(";")(s)?;
let (s, f) = opt(timeunits_declaration)(s)?;
let (s, g) = many0(program_item)(s)?;
let (s, h) = symbol("endprogram")(s)?;
let (s, i) = opt(pair(symbol(":"), program_identifier))(s)?;
Ok((
s,
ProgramDeclaration::Wildcard(ProgramDeclarationWildcard {
nodes: (a, b, c, d, e, f, g, h, i, j, k),
nodes: (a, b, c, d, e, f, g, h, i),
}),
))
}
@ -831,7 +811,7 @@ pub fn program_ansi_header(s: Span) -> IResult<Span, ProgramAnsiHeader> {
pub fn checker_declaration(s: Span) -> IResult<Span, CheckerDeclaration> {
let (s, a) = symbol("checker")(s)?;
let (s, b) = checker_identifier(s)?;
let (s, c) = opt(triple(symbol("("), opt(checker_port_list), symbol(")")))(s)?;
let (s, c) = opt(paren2(opt(checker_port_list)))(s)?;
let (s, d) = symbol(";")(s)?;
let (s, e) = many0(pair(many0(attribute_instance), checker_or_generate_item))(s)?;
let (s, f) = symbol("endchecker")(s)?;
@ -853,12 +833,11 @@ pub fn class_declaration(s: Span) -> IResult<Span, ClassDeclaration> {
let (s, f) = opt(triple(
symbol("extends"),
class_type,
opt(triple(symbol("("), list_of_arguments, symbol(")"))),
opt(paren2(list_of_arguments)),
))(s)?;
let (s, g) = opt(triple(
let (s, g) = opt(pair(
symbol("implements"),
interface_class_type,
many0(pair(symbol(","), interface_class_type)),
list(symbol(","), interface_class_type),
))(s)?;
let (s, h) = symbol(";")(s)?;
let (s, i) = many0(class_item)(s)?;
@ -883,10 +862,9 @@ pub fn interface_class_declaration(s: Span) -> IResult<Span, InterfaceClassDecla
let (s, b) = symbol("class")(s)?;
let (s, c) = class_identifier(s)?;
let (s, d) = opt(parameter_port_list)(s)?;
let (s, e) = opt(triple(
let (s, e) = opt(pair(
symbol("extends"),
interface_class_type,
many0(pair(symbol(","), interface_class_type)),
list(symbol(","), interface_class_type),
))(s)?;
let (s, f) = symbol(";")(s)?;
let (s, g) = many0(interface_class_item)(s)?;

View File

@ -20,6 +20,31 @@ pub enum WhiteSpace<'a> {
Comment(Comment<'a>),
}
#[derive(Debug)]
pub struct Paren<'a, T: 'a> {
pub nodes: (Symbol<'a>, T, Symbol<'a>),
}
#[derive(Debug)]
pub struct Brace<'a, T: 'a> {
pub nodes: (Symbol<'a>, T, Symbol<'a>),
}
#[derive(Debug)]
pub struct Bracket<'a, T: 'a> {
pub nodes: (Symbol<'a>, T, Symbol<'a>),
}
#[derive(Debug)]
pub struct ApostropheBrace<'a, T: 'a> {
pub nodes: (Symbol<'a>, T, Symbol<'a>),
}
#[derive(Debug)]
pub struct List<U, T> {
pub nodes: (T, Vec<(U, T)>),
}
// -----------------------------------------------------------------------------
pub fn ws<'a, O, F>(f: F) -> impl Fn(Span<'a>) -> IResult<Span<'a>, (O, Vec<WhiteSpace<'a>>)>
@ -37,7 +62,7 @@ pub fn symbol<'a>(t: &'a str) -> impl Fn(Span<'a>) -> IResult<Span<'a>, Symbol<'
move |s: Span<'a>| map(ws(tag(t.clone())), |x| Symbol { nodes: x })(s)
}
pub fn paren2<'a, O, F>(f: F) -> impl Fn(Span<'a>) -> IResult<Span<'a>, (Symbol<'a>, O, Symbol<'a>)>
pub fn paren2<'a, O, F>(f: F) -> impl Fn(Span<'a>) -> IResult<Span<'a>, Paren<O>>
where
F: Fn(Span<'a>) -> IResult<Span<'a>, O>,
{
@ -45,13 +70,11 @@ where
let (s, a) = symbol("(")(s)?;
let (s, b) = f(s)?;
let (s, c) = symbol(")")(s)?;
Ok((s, (a, b, c)))
Ok((s, Paren { nodes: (a, b, c) }))
}
}
pub fn bracket2<'a, O, F>(
f: F,
) -> impl Fn(Span<'a>) -> IResult<Span<'a>, (Symbol<'a>, O, Symbol<'a>)>
pub fn bracket2<'a, O, F>(f: F) -> impl Fn(Span<'a>) -> IResult<Span<'a>, Bracket<O>>
where
F: Fn(Span<'a>) -> IResult<Span<'a>, O>,
{
@ -59,7 +82,55 @@ where
let (s, a) = symbol("[")(s)?;
let (s, b) = f(s)?;
let (s, c) = symbol("]")(s)?;
Ok((s, (a, b, c)))
Ok((s, Bracket { nodes: (a, b, c) }))
}
}
pub fn brace2<'a, O, F>(f: F) -> impl Fn(Span<'a>) -> IResult<Span<'a>, Brace<O>>
where
F: Fn(Span<'a>) -> IResult<Span<'a>, O>,
{
move |s: Span<'a>| {
let (s, a) = symbol("{")(s)?;
let (s, b) = f(s)?;
let (s, c) = symbol("}")(s)?;
Ok((s, Brace { nodes: (a, b, c) }))
}
}
pub fn apostrophe_brace2<'a, O, F>(
f: F,
) -> impl Fn(Span<'a>) -> IResult<Span<'a>, ApostropheBrace<O>>
where
F: Fn(Span<'a>) -> IResult<Span<'a>, O>,
{
move |s: Span<'a>| {
let (s, a) = symbol("'{")(s)?;
let (s, b) = f(s)?;
let (s, c) = symbol("}")(s)?;
Ok((s, ApostropheBrace { nodes: (a, b, c) }))
}
}
pub fn list<'a, O1, O2, F, G>(f: F, g: G) -> impl Fn(Span<'a>) -> IResult<Span<'a>, List<O1, O2>>
where
F: Fn(Span<'a>) -> IResult<Span<'a>, O1>,
G: Fn(Span<'a>) -> IResult<Span<'a>, O2>,
{
move |s: Span<'a>| {
let (s, a) = g(s)?;
let mut s = s.clone();
let mut ret = Vec::new();
loop {
if let Ok((t, b)) = f(s) {
let (u, c) = g(t)?;
s = u;
ret.push((b, c));
} else {
break;
}
}
Ok((s, List { nodes: (a, ret) }))
}
}