Refactoring
This commit is contained in:
parent
9c4aceb631
commit
26cb4e6818
@ -36,7 +36,7 @@ A parser library for System Verilog.
|
|||||||
| primitive_instance | primitive_strengths | | | |
|
| primitive_instance | primitive_strengths | | | |
|
||||||
| primitive_instance | primitive_terminals | | | |
|
| primitive_instance | primitive_terminals | | | |
|
||||||
| primitive_instance | primitive_gate_and_switch_types | | | |
|
| primitive_instance | primitive_gate_and_switch_types | | | |
|
||||||
| instantiations | module_instantiation | | | |
|
| instantiations | module_instantiation | x | x | |
|
||||||
| instantiations | interface_instantiation | x | x | |
|
| instantiations | interface_instantiation | x | x | |
|
||||||
| instantiations | program_instantiation | x | x | |
|
| instantiations | program_instantiation | x | x | |
|
||||||
| instantiations | checker_instantiation | x | x | |
|
| instantiations | checker_instantiation | x | x | |
|
||||||
@ -65,8 +65,8 @@ A parser library for System Verilog.
|
|||||||
| specify_section | system_timing_check_commands | | | |
|
| specify_section | system_timing_check_commands | | | |
|
||||||
| specify_section | system_timing_check_command_arguments | | | |
|
| specify_section | system_timing_check_command_arguments | | | |
|
||||||
| specify_section | system_timing_check_event_definitions | | | |
|
| specify_section | system_timing_check_event_definitions | | | |
|
||||||
| expressions | concatenations | | | |
|
| expressions | concatenations | x | x | |
|
||||||
| expressions | subroutine_calls | | | |
|
| expressions | subroutine_calls | x | x | |
|
||||||
| expressions | expressions | x | x | |
|
| expressions | expressions | x | x | |
|
||||||
| expressions | primaries | x | x | |
|
| expressions | primaries | x | x | |
|
||||||
| expressions | expression_leftside_values | x | x | |
|
| expressions | expression_leftside_values | x | x | |
|
||||||
|
@ -9,40 +9,67 @@ use nom::IResult;
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Concatenation<'a> {
|
pub struct Concatenation<'a> {
|
||||||
pub nodes: (Vec<Expression<'a>>,),
|
pub nodes: (
|
||||||
|
Symbol<'a>,
|
||||||
|
Expression<'a>,
|
||||||
|
Vec<(Symbol<'a>, Expression<'a>)>,
|
||||||
|
Symbol<'a>,
|
||||||
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ConstantConcatenation<'a> {
|
pub struct ConstantConcatenation<'a> {
|
||||||
pub nodes: (Vec<ConstantExpression<'a>>,),
|
pub nodes: (
|
||||||
|
Symbol<'a>,
|
||||||
|
ConstantExpression<'a>,
|
||||||
|
Vec<(Symbol<'a>, ConstantExpression<'a>)>,
|
||||||
|
Symbol<'a>,
|
||||||
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ConstantMultipleConcatenation<'a> {
|
pub struct ConstantMultipleConcatenation<'a> {
|
||||||
pub nodes: (ConstantExpression<'a>, ConstantConcatenation<'a>),
|
pub nodes: (
|
||||||
|
Symbol<'a>,
|
||||||
|
ConstantExpression<'a>,
|
||||||
|
ConstantConcatenation<'a>,
|
||||||
|
Symbol<'a>,
|
||||||
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ModulePathConcatenation<'a> {
|
pub struct ModulePathConcatenation<'a> {
|
||||||
pub nodes: (Vec<ModulePathExpression<'a>>,),
|
pub nodes: (
|
||||||
|
Symbol<'a>,
|
||||||
|
ModulePathExpression<'a>,
|
||||||
|
Vec<(Symbol<'a>, ModulePathExpression<'a>)>,
|
||||||
|
Symbol<'a>,
|
||||||
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ModulePathMultipleConcatenation<'a> {
|
pub struct ModulePathMultipleConcatenation<'a> {
|
||||||
pub nodes: (ConstantExpression<'a>, ModulePathConcatenation<'a>),
|
pub nodes: (
|
||||||
|
Symbol<'a>,
|
||||||
|
ConstantExpression<'a>,
|
||||||
|
ModulePathConcatenation<'a>,
|
||||||
|
Symbol<'a>,
|
||||||
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct MultipleConcatenation<'a> {
|
pub struct MultipleConcatenation<'a> {
|
||||||
pub nodes: (Expression<'a>, Concatenation<'a>),
|
pub nodes: (Symbol<'a>, Expression<'a>, Concatenation<'a>, Symbol<'a>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct StreamingConcatenation<'a> {
|
pub struct StreamingConcatenation<'a> {
|
||||||
pub nodes: (
|
pub nodes: (
|
||||||
|
Symbol<'a>,
|
||||||
StreamOperator<'a>,
|
StreamOperator<'a>,
|
||||||
Option<SliceSize<'a>>,
|
Option<SliceSize<'a>>,
|
||||||
StreamConcatenation<'a>,
|
StreamConcatenation<'a>,
|
||||||
|
Symbol<'a>,
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,32 +80,52 @@ pub struct StreamOperator<'a> {
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum SliceSize<'a> {
|
pub enum SliceSize<'a> {
|
||||||
Type(SimpleType<'a>),
|
SimpleType(SimpleType<'a>),
|
||||||
Expression(ConstantExpression<'a>),
|
ConstantExpression(ConstantExpression<'a>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct StreamConcatenation<'a> {
|
pub struct StreamConcatenation<'a> {
|
||||||
pub nodes: (Vec<StreamExpression<'a>>,),
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct StreamExpression<'a> {
|
|
||||||
pub nodes: (Expression<'a>, Option<ArrayRangeExpression<'a>>),
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct ArrayRangeExpression<'a> {
|
|
||||||
pub nodes: (
|
pub nodes: (
|
||||||
Expression<'a>,
|
Symbol<'a>,
|
||||||
Option<ArrayRangeOperator<'a>>,
|
StreamExpression<'a>,
|
||||||
Option<Expression<'a>>,
|
Vec<(Symbol<'a>, StreamExpression<'a>)>,
|
||||||
|
Symbol<'a>,
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ArrayRangeOperator<'a> {
|
pub struct StreamExpression<'a> {
|
||||||
pub nodes: (Symbol<'a>,),
|
pub nodes: (
|
||||||
|
Expression<'a>,
|
||||||
|
Option<(
|
||||||
|
Symbol<'a>,
|
||||||
|
(Symbol<'a>, ArrayRangeExpression<'a>, Symbol<'a>),
|
||||||
|
)>,
|
||||||
|
),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum ArrayRangeExpression<'a> {
|
||||||
|
Expression(Expression<'a>),
|
||||||
|
Colon(ArrayRangeExpressionColon<'a>),
|
||||||
|
PlusColon(ArrayRangeExpressionPlusColon<'a>),
|
||||||
|
MinusColon(ArrayRangeExpressionMinusColon<'a>),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct ArrayRangeExpressionColon<'a> {
|
||||||
|
pub nodes: (Expression<'a>, Symbol<'a>, Expression<'a>),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct ArrayRangeExpressionPlusColon<'a> {
|
||||||
|
pub nodes: (Expression<'a>, Symbol<'a>, Expression<'a>),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct ArrayRangeExpressionMinusColon<'a> {
|
||||||
|
pub nodes: (Expression<'a>, Symbol<'a>, Expression<'a>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -89,53 +136,97 @@ pub struct EmptyUnpackedArrayConcatenation<'a> {
|
|||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
pub fn concatenation(s: Span) -> IResult<Span, Concatenation> {
|
pub fn concatenation(s: Span) -> IResult<Span, Concatenation> {
|
||||||
let (s, x) = brace(separated_nonempty_list(symbol(","), expression))(s)?;
|
let (s, a) = symbol("{")(s)?;
|
||||||
Ok((s, Concatenation { nodes: (x,) }))
|
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),
|
||||||
|
},
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn constant_concatenation(s: Span) -> IResult<Span, ConstantConcatenation> {
|
pub fn constant_concatenation(s: Span) -> IResult<Span, ConstantConcatenation> {
|
||||||
let (s, x) = brace(separated_nonempty_list(symbol(","), constant_expression))(s)?;
|
let (s, a) = symbol("{")(s)?;
|
||||||
Ok((s, ConstantConcatenation { nodes: (x,) }))
|
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),
|
||||||
|
},
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn constant_multiple_concatenation(s: Span) -> IResult<Span, ConstantMultipleConcatenation> {
|
pub fn constant_multiple_concatenation(s: Span) -> IResult<Span, ConstantMultipleConcatenation> {
|
||||||
let (s, _) = symbol("{")(s)?;
|
let (s, a) = symbol("{")(s)?;
|
||||||
let (s, x) = constant_expression(s)?;
|
let (s, b) = constant_expression(s)?;
|
||||||
let (s, y) = constant_concatenation(s)?;
|
let (s, c) = constant_concatenation(s)?;
|
||||||
let (s, _) = symbol("}")(s)?;
|
let (s, d) = symbol("}")(s)?;
|
||||||
Ok((s, ConstantMultipleConcatenation { nodes: (x, y) }))
|
Ok((
|
||||||
|
s,
|
||||||
|
ConstantMultipleConcatenation {
|
||||||
|
nodes: (a, b, c, d),
|
||||||
|
},
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn module_path_concatenation(s: Span) -> IResult<Span, ModulePathConcatenation> {
|
pub fn module_path_concatenation(s: Span) -> IResult<Span, ModulePathConcatenation> {
|
||||||
let (s, x) = brace(separated_nonempty_list(symbol(","), module_path_expression))(s)?;
|
let (s, a) = symbol("{")(s)?;
|
||||||
Ok((s, ModulePathConcatenation { nodes: (x,) }))
|
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),
|
||||||
|
},
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn module_path_multiple_concatenation(
|
pub fn module_path_multiple_concatenation(
|
||||||
s: Span,
|
s: Span,
|
||||||
) -> IResult<Span, ModulePathMultipleConcatenation> {
|
) -> IResult<Span, ModulePathMultipleConcatenation> {
|
||||||
let (s, _) = symbol("{")(s)?;
|
let (s, a) = symbol("{")(s)?;
|
||||||
let (s, x) = constant_expression(s)?;
|
let (s, b) = constant_expression(s)?;
|
||||||
let (s, y) = module_path_concatenation(s)?;
|
let (s, c) = module_path_concatenation(s)?;
|
||||||
let (s, _) = symbol("}")(s)?;
|
let (s, d) = symbol("}")(s)?;
|
||||||
Ok((s, ModulePathMultipleConcatenation { nodes: (x, y) }))
|
Ok((
|
||||||
|
s,
|
||||||
|
ModulePathMultipleConcatenation {
|
||||||
|
nodes: (a, b, c, d),
|
||||||
|
},
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn multiple_concatenation(s: Span) -> IResult<Span, MultipleConcatenation> {
|
pub fn multiple_concatenation(s: Span) -> IResult<Span, MultipleConcatenation> {
|
||||||
let (s, _) = symbol("{")(s)?;
|
let (s, a) = symbol("{")(s)?;
|
||||||
let (s, x) = expression(s)?;
|
let (s, b) = expression(s)?;
|
||||||
let (s, y) = concatenation(s)?;
|
let (s, c) = concatenation(s)?;
|
||||||
let (s, _) = symbol("}")(s)?;
|
let (s, d) = symbol("}")(s)?;
|
||||||
Ok((s, MultipleConcatenation { nodes: (x, y) }))
|
Ok((
|
||||||
|
s,
|
||||||
|
MultipleConcatenation {
|
||||||
|
nodes: (a, b, c, d),
|
||||||
|
},
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn streaming_concatenation(s: Span) -> IResult<Span, StreamingConcatenation> {
|
pub fn streaming_concatenation(s: Span) -> IResult<Span, StreamingConcatenation> {
|
||||||
let (s, _) = symbol("{")(s)?;
|
let (s, a) = symbol("{")(s)?;
|
||||||
let (s, x) = stream_operator(s)?;
|
let (s, b) = stream_operator(s)?;
|
||||||
let (s, y) = opt(slice_size)(s)?;
|
let (s, c) = opt(slice_size)(s)?;
|
||||||
let (s, z) = stream_concatenation(s)?;
|
let (s, d) = stream_concatenation(s)?;
|
||||||
let (s, _) = symbol("}")(s)?;
|
let (s, e) = symbol("}")(s)?;
|
||||||
Ok((s, StreamingConcatenation { nodes: (x, y, z) }))
|
Ok((
|
||||||
|
s,
|
||||||
|
StreamingConcatenation {
|
||||||
|
nodes: (a, b, c, d, e),
|
||||||
|
},
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn stream_operator(s: Span) -> IResult<Span, StreamOperator> {
|
pub fn stream_operator(s: Span) -> IResult<Span, StreamOperator> {
|
||||||
@ -147,39 +238,67 @@ pub fn stream_operator(s: Span) -> IResult<Span, StreamOperator> {
|
|||||||
|
|
||||||
pub fn slice_size(s: Span) -> IResult<Span, SliceSize> {
|
pub fn slice_size(s: Span) -> IResult<Span, SliceSize> {
|
||||||
alt((
|
alt((
|
||||||
map(simple_type, |x| SliceSize::Type(x)),
|
map(simple_type, |x| SliceSize::SimpleType(x)),
|
||||||
map(constant_expression, |x| SliceSize::Expression(x)),
|
map(constant_expression, |x| SliceSize::ConstantExpression(x)),
|
||||||
))(s)
|
))(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn stream_concatenation(s: Span) -> IResult<Span, StreamConcatenation> {
|
pub fn stream_concatenation(s: Span) -> IResult<Span, StreamConcatenation> {
|
||||||
let (s, x) = brace(separated_nonempty_list(symbol(","), stream_expression))(s)?;
|
let (s, a) = symbol("{")(s)?;
|
||||||
Ok((s, StreamConcatenation { nodes: (x,) }))
|
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),
|
||||||
|
},
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn stream_expression(s: Span) -> IResult<Span, StreamExpression> {
|
pub fn stream_expression(s: Span) -> IResult<Span, StreamExpression> {
|
||||||
let (s, x) = expression(s)?;
|
let (s, a) = expression(s)?;
|
||||||
let (s, y) = opt(preceded(symbol("with"), bracket(array_range_expression)))(s)?;
|
let (s, b) = opt(pair(symbol("with"), bracket2(array_range_expression)))(s)?;
|
||||||
Ok((s, StreamExpression { nodes: (x, y) }))
|
Ok((s, StreamExpression { nodes: (a, b) }))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn array_range_expression(s: Span) -> IResult<Span, ArrayRangeExpression> {
|
pub fn array_range_expression(s: Span) -> IResult<Span, ArrayRangeExpression> {
|
||||||
let (s, x) = expression(s)?;
|
alt((
|
||||||
let (s, y) = opt(pair(array_range_operator, expression))(s)?;
|
map(expression, |x| ArrayRangeExpression::Expression(x)),
|
||||||
let (y, z) = if let Some((y, z)) = y {
|
array_range_expression_colon,
|
||||||
(Some(y), Some(z))
|
array_range_expression_plus_colon,
|
||||||
} else {
|
array_range_expression_minus_colon,
|
||||||
(None, None)
|
))(s)
|
||||||
};
|
|
||||||
Ok((s, ArrayRangeExpression { nodes: (x, y, z) }))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn array_range_operator(s: Span) -> IResult<Span, ArrayRangeOperator> {
|
pub fn array_range_expression_colon(s: Span) -> IResult<Span, ArrayRangeExpression> {
|
||||||
alt((
|
let (s, a) = expression(s)?;
|
||||||
map(symbol(":"), |x| ArrayRangeOperator { nodes: (x,) }),
|
let (s, b) = symbol(":")(s)?;
|
||||||
map(symbol("+:"), |x| ArrayRangeOperator { nodes: (x,) }),
|
let (s, c) = expression(s)?;
|
||||||
map(symbol("-:"), |x| ArrayRangeOperator { nodes: (x,) }),
|
Ok((
|
||||||
))(s)
|
s,
|
||||||
|
ArrayRangeExpression::Colon(ArrayRangeExpressionColon { nodes: (a, b, c) }),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn array_range_expression_plus_colon(s: Span) -> IResult<Span, ArrayRangeExpression> {
|
||||||
|
let (s, a) = expression(s)?;
|
||||||
|
let (s, b) = symbol("+:")(s)?;
|
||||||
|
let (s, c) = expression(s)?;
|
||||||
|
Ok((
|
||||||
|
s,
|
||||||
|
ArrayRangeExpression::PlusColon(ArrayRangeExpressionPlusColon { nodes: (a, b, c) }),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn array_range_expression_minus_colon(s: Span) -> IResult<Span, ArrayRangeExpression> {
|
||||||
|
let (s, a) = expression(s)?;
|
||||||
|
let (s, b) = symbol("-:")(s)?;
|
||||||
|
let (s, c) = expression(s)?;
|
||||||
|
Ok((
|
||||||
|
s,
|
||||||
|
ArrayRangeExpression::MinusColon(ArrayRangeExpressionMinusColon { nodes: (a, b, c) }),
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn empty_unpacked_array_concatenation(
|
pub fn empty_unpacked_array_concatenation(
|
||||||
|
@ -108,7 +108,7 @@ pub enum ConstantParamExpression<'a> {
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum ParamExpression<'a> {
|
pub enum ParamExpression<'a> {
|
||||||
MintypmaxExpression(MintypmaxExpression<'a>),
|
MintypmaxExpression(MintypmaxExpression<'a>),
|
||||||
DataType(DataType<'a>),
|
DataType(Box<DataType<'a>>),
|
||||||
Dollar(Symbol<'a>),
|
Dollar(Symbol<'a>),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -419,7 +419,7 @@ pub fn param_expression(s: Span) -> IResult<Span, ParamExpression> {
|
|||||||
map(mintypmax_expression, |x| {
|
map(mintypmax_expression, |x| {
|
||||||
ParamExpression::MintypmaxExpression(x)
|
ParamExpression::MintypmaxExpression(x)
|
||||||
}),
|
}),
|
||||||
map(data_type, |x| ParamExpression::DataType(x)),
|
map(data_type, |x| ParamExpression::DataType(Box::new(x))),
|
||||||
))(s)
|
))(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,28 +17,59 @@ pub struct TfCall<'a> {
|
|||||||
pub nodes: (
|
pub nodes: (
|
||||||
PsOrHierarchicalTfIdentifier<'a>,
|
PsOrHierarchicalTfIdentifier<'a>,
|
||||||
Vec<AttributeInstance<'a>>,
|
Vec<AttributeInstance<'a>>,
|
||||||
Option<ListOfArguments<'a>>,
|
Option<(Symbol<'a>, ListOfArguments<'a>, Symbol<'a>)>,
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct SystemTfCall<'a> {
|
pub enum SystemTfCall<'a> {
|
||||||
|
ArgOptionl(SystemTfCallArgOptional<'a>),
|
||||||
|
ArgDataType(SystemTfCallArgDataType<'a>),
|
||||||
|
ArgExpression(SystemTfCallArgExpression<'a>),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct SystemTfCallArgOptional<'a> {
|
||||||
pub nodes: (
|
pub nodes: (
|
||||||
SystemTfIdentifier<'a>,
|
SystemTfIdentifier<'a>,
|
||||||
Option<ListOfArguments<'a>>,
|
Option<(Symbol<'a>, ListOfArguments<'a>, Symbol<'a>)>,
|
||||||
Option<DataType<'a>>,
|
),
|
||||||
Option<Vec<Expression<'a>>>,
|
}
|
||||||
Option<ClockingEvent<'a>>,
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct SystemTfCallArgDataType<'a> {
|
||||||
|
pub nodes: (
|
||||||
|
SystemTfIdentifier<'a>,
|
||||||
|
Symbol<'a>,
|
||||||
|
DataType<'a>,
|
||||||
|
Option<(Symbol<'a>, Expression<'a>)>,
|
||||||
|
Symbol<'a>,
|
||||||
|
),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
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>,
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum SubroutineCall<'a> {
|
pub enum SubroutineCall<'a> {
|
||||||
Tf(Box<TfCall<'a>>),
|
TfCall(Box<TfCall<'a>>),
|
||||||
SystemTf(Box<SystemTfCall<'a>>),
|
SystemTfCall(Box<SystemTfCall<'a>>),
|
||||||
Method(Box<MethodCall<'a>>),
|
MethodCall(Box<MethodCall<'a>>),
|
||||||
Randomize(Box<RandomizeCall<'a>>),
|
Randomize(Box<SubroutineCallRandomize<'a>>),
|
||||||
StdRandomize(Box<RandomizeCall<'a>>),
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct SubroutineCallRandomize<'a> {
|
||||||
|
pub nodes: (Option<(Symbol<'a>, Symbol<'a>)>, RandomizeCall<'a>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -47,16 +78,49 @@ pub struct FunctionSubroutineCall<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ListOfArguments<'a> {
|
pub enum ListOfArguments<'a> {
|
||||||
|
Ordered(ListOfArgumentsOrdered<'a>),
|
||||||
|
Named(ListOfArgumentsNamed<'a>),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct ListOfArgumentsOrdered<'a> {
|
||||||
pub nodes: (
|
pub nodes: (
|
||||||
Vec<Expression<'a>>,
|
Option<Expression<'a>>,
|
||||||
Vec<(Identifier<'a>, Option<Expression<'a>>)>,
|
Vec<(Symbol<'a>, Option<Expression<'a>>)>,
|
||||||
|
Vec<(
|
||||||
|
Symbol<'a>,
|
||||||
|
Symbol<'a>,
|
||||||
|
Identifier<'a>,
|
||||||
|
Symbol<'a>,
|
||||||
|
Option<Expression<'a>>,
|
||||||
|
Symbol<'a>,
|
||||||
|
)>,
|
||||||
|
),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct ListOfArgumentsNamed<'a> {
|
||||||
|
pub nodes: (
|
||||||
|
Symbol<'a>,
|
||||||
|
Identifier<'a>,
|
||||||
|
Symbol<'a>,
|
||||||
|
Option<Expression<'a>>,
|
||||||
|
Symbol<'a>,
|
||||||
|
Vec<(
|
||||||
|
Symbol<'a>,
|
||||||
|
Symbol<'a>,
|
||||||
|
Identifier<'a>,
|
||||||
|
Symbol<'a>,
|
||||||
|
Option<Expression<'a>>,
|
||||||
|
Symbol<'a>,
|
||||||
|
)>,
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct MethodCall<'a> {
|
pub struct MethodCall<'a> {
|
||||||
pub nodes: (MethodCallRoot<'a>, MethodCallBody<'a>),
|
pub nodes: (MethodCallRoot<'a>, Symbol<'a>, MethodCallBody<'a>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -70,7 +134,7 @@ pub struct MethodCallBodyUser<'a> {
|
|||||||
pub nodes: (
|
pub nodes: (
|
||||||
MethodIdentifier<'a>,
|
MethodIdentifier<'a>,
|
||||||
Vec<AttributeInstance<'a>>,
|
Vec<AttributeInstance<'a>>,
|
||||||
Option<ListOfArguments<'a>>,
|
Option<(Symbol<'a>, ListOfArguments<'a>, Symbol<'a>)>,
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,21 +149,35 @@ pub struct ArrayManipulationCall<'a> {
|
|||||||
pub nodes: (
|
pub nodes: (
|
||||||
ArrayMethodName<'a>,
|
ArrayMethodName<'a>,
|
||||||
Vec<AttributeInstance<'a>>,
|
Vec<AttributeInstance<'a>>,
|
||||||
Option<ListOfArguments<'a>>,
|
Option<(Symbol<'a>, ListOfArguments<'a>, Symbol<'a>)>,
|
||||||
Option<Expression<'a>>,
|
Option<(Symbol<'a>, (Symbol<'a>, Expression<'a>, Symbol<'a>))>,
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct RandomizeCall<'a> {
|
pub struct RandomizeCall<'a> {
|
||||||
pub nodes: (
|
pub nodes: (
|
||||||
|
Symbol<'a>,
|
||||||
Vec<AttributeInstance<'a>>,
|
Vec<AttributeInstance<'a>>,
|
||||||
VariableIdentifierList<'a>,
|
Option<(
|
||||||
IdentifierList<'a>,
|
Symbol<'a>,
|
||||||
Option<ConstraintBlock<'a>>,
|
Option<VariableIdentifierListOrNull<'a>>,
|
||||||
|
Symbol<'a>,
|
||||||
|
)>,
|
||||||
|
Option<(
|
||||||
|
Symbol<'a>,
|
||||||
|
Option<(Symbol<'a>, Option<IdentifierList<'a>>, Symbol<'a>)>,
|
||||||
|
ConstraintBlock<'a>,
|
||||||
|
)>,
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum VariableIdentifierListOrNull<'a> {
|
||||||
|
VariableIdentifierList(VariableIdentifierList<'a>),
|
||||||
|
Null(Symbol<'a>),
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum MethodCallRoot<'a> {
|
pub enum MethodCallRoot<'a> {
|
||||||
Primary(Primary<'a>),
|
Primary(Primary<'a>),
|
||||||
@ -109,10 +187,10 @@ pub enum MethodCallRoot<'a> {
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum ArrayMethodName<'a> {
|
pub enum ArrayMethodName<'a> {
|
||||||
MethodIdentifier(MethodIdentifier<'a>),
|
MethodIdentifier(MethodIdentifier<'a>),
|
||||||
Unique,
|
Unique(Symbol<'a>),
|
||||||
And,
|
And(Symbol<'a>),
|
||||||
Or,
|
Or(Symbol<'a>),
|
||||||
Xor,
|
Xor(Symbol<'a>),
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
@ -123,92 +201,131 @@ pub fn constant_function_call(s: Span) -> IResult<Span, ConstantFunctionCall> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn tf_call(s: Span) -> IResult<Span, TfCall> {
|
pub fn tf_call(s: Span) -> IResult<Span, TfCall> {
|
||||||
let (s, x) = ps_or_hierarchical_tf_identifier(s)?;
|
let (s, a) = ps_or_hierarchical_tf_identifier(s)?;
|
||||||
let (s, y) = many0(attribute_instance)(s)?;
|
let (s, b) = many0(attribute_instance)(s)?;
|
||||||
let (s, z) = opt(paren(list_of_arguments))(s)?;
|
let (s, c) = opt(paren2(list_of_arguments))(s)?;
|
||||||
Ok((s, TfCall { nodes: (x, y, z) }))
|
Ok((s, TfCall { nodes: (a, b, c) }))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn system_tf_call(s: Span) -> IResult<Span, SystemTfCall> {
|
pub fn system_tf_call(s: Span) -> IResult<Span, SystemTfCall> {
|
||||||
alt((
|
alt((
|
||||||
system_tf_call_list_of_arguments,
|
system_tf_call_arg_optional,
|
||||||
system_tf_call_data_type,
|
system_tf_call_arg_data_type,
|
||||||
system_tf_call_clocking_event,
|
system_tf_call_arg_expression,
|
||||||
))(s)
|
))(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn system_tf_call_list_of_arguments(s: Span) -> IResult<Span, SystemTfCall> {
|
pub fn system_tf_call_arg_optional(s: Span) -> IResult<Span, SystemTfCall> {
|
||||||
let (s, x) = system_tf_identifier(s)?;
|
let (s, a) = system_tf_identifier(s)?;
|
||||||
let (s, y) = opt(paren(list_of_arguments))(s)?;
|
let (s, b) = opt(paren2(list_of_arguments))(s)?;
|
||||||
Ok((
|
Ok((
|
||||||
s,
|
s,
|
||||||
SystemTfCall {
|
SystemTfCall::ArgOptionl(SystemTfCallArgOptional { nodes: (a, b) }),
|
||||||
nodes: (x, y, None, None, None),
|
|
||||||
},
|
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn system_tf_call_data_type(s: Span) -> IResult<Span, SystemTfCall> {
|
pub fn system_tf_call_arg_data_type(s: Span) -> IResult<Span, SystemTfCall> {
|
||||||
let (s, x) = system_tf_identifier(s)?;
|
let (s, a) = system_tf_identifier(s)?;
|
||||||
let (s, _) = symbol("(")(s)?;
|
let (s, b) = symbol("(")(s)?;
|
||||||
let (s, y) = data_type(s)?;
|
let (s, c) = data_type(s)?;
|
||||||
let (s, z) = preceded(symbol(","), expression)(s)?;
|
let (s, d) = opt(pair(symbol(","), expression))(s)?;
|
||||||
let (s, _) = symbol(")")(s)?;
|
let (s, e) = symbol(")")(s)?;
|
||||||
Ok((
|
Ok((
|
||||||
s,
|
s,
|
||||||
SystemTfCall {
|
SystemTfCall::ArgDataType(SystemTfCallArgDataType {
|
||||||
nodes: (x, None, Some(y), Some(vec![z]), None),
|
nodes: (a, b, c, d, e),
|
||||||
},
|
}),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn system_tf_call_clocking_event(s: Span) -> IResult<Span, SystemTfCall> {
|
pub fn system_tf_call_arg_expression(s: Span) -> IResult<Span, SystemTfCall> {
|
||||||
let (s, x) = system_tf_identifier(s)?;
|
let (s, a) = system_tf_identifier(s)?;
|
||||||
let (s, _) = symbol("(")(s)?;
|
let (s, b) = symbol("(")(s)?;
|
||||||
let (s, y) = separated_nonempty_list(symbol(","), expression)(s)?;
|
let (s, c) = expression(s)?;
|
||||||
let (s, z) = opt(preceded(symbol(","), opt(clocking_event)))(s)?;
|
let (s, d) = many0(pair(symbol(","), opt(expression)))(s)?;
|
||||||
let (s, _) = symbol(")")(s)?;
|
let (s, e) = opt(pair(symbol(","), opt(clocking_event)))(s)?;
|
||||||
let z = if let Some(Some(z)) = z { Some(z) } else { None };
|
let (s, f) = symbol(")")(s)?;
|
||||||
Ok((
|
Ok((
|
||||||
s,
|
s,
|
||||||
SystemTfCall {
|
SystemTfCall::ArgExpression(SystemTfCallArgExpression {
|
||||||
nodes: (x, None, None, Some(y), z),
|
nodes: (a, b, c, d, e, f),
|
||||||
},
|
}),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn subroutine_call(s: Span) -> IResult<Span, SubroutineCall> {
|
pub fn subroutine_call(s: Span) -> IResult<Span, SubroutineCall> {
|
||||||
alt((
|
alt((
|
||||||
map(tf_call, |x| SubroutineCall::Tf(Box::new(x))),
|
map(tf_call, |x| SubroutineCall::TfCall(Box::new(x))),
|
||||||
map(system_tf_call, |x| SubroutineCall::SystemTf(Box::new(x))),
|
map(system_tf_call, |x| {
|
||||||
map(method_call, |x| SubroutineCall::Method(Box::new(x))),
|
SubroutineCall::SystemTfCall(Box::new(x))
|
||||||
map(
|
}),
|
||||||
triple(symbol("std"), symbol("::"), randomize_call),
|
map(method_call, |x| SubroutineCall::MethodCall(Box::new(x))),
|
||||||
|(_, _, x)| SubroutineCall::StdRandomize(Box::new(x)),
|
subroutine_call_randomize,
|
||||||
),
|
|
||||||
map(randomize_call, |x| SubroutineCall::Randomize(Box::new(x))),
|
|
||||||
))(s)
|
))(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn subroutine_call_randomize(s: Span) -> IResult<Span, SubroutineCall> {
|
||||||
|
let (s, a) = opt(pair(symbol("std"), symbol("::")))(s)?;
|
||||||
|
let (s, b) = randomize_call(s)?;
|
||||||
|
Ok((
|
||||||
|
s,
|
||||||
|
SubroutineCall::Randomize(Box::new(SubroutineCallRandomize { nodes: (a, b) })),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
pub fn function_subroutine_call(s: Span) -> IResult<Span, FunctionSubroutineCall> {
|
pub fn function_subroutine_call(s: Span) -> IResult<Span, FunctionSubroutineCall> {
|
||||||
map(subroutine_call, |x| FunctionSubroutineCall { nodes: (x,) })(s)
|
map(subroutine_call, |x| FunctionSubroutineCall { nodes: (x,) })(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn list_of_arguments(s: Span) -> IResult<Span, ListOfArguments> {
|
pub fn list_of_arguments(s: Span) -> IResult<Span, ListOfArguments> {
|
||||||
let (s, x) = separated_list(symbol(","), expression)(s)?;
|
alt((list_of_arguments_ordered, list_of_arguments_named))(s)
|
||||||
let (s, y) = separated_list(
|
}
|
||||||
|
|
||||||
|
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((
|
||||||
symbol(","),
|
symbol(","),
|
||||||
pair(preceded(symbol("."), identifier), paren(opt(expression))),
|
symbol("."),
|
||||||
)(s)?;
|
identifier,
|
||||||
Ok((s, ListOfArguments { nodes: (x, y) }))
|
symbol("("),
|
||||||
|
opt(expression),
|
||||||
|
symbol(")"),
|
||||||
|
)))(s)?;
|
||||||
|
Ok((
|
||||||
|
s,
|
||||||
|
ListOfArguments::Ordered(ListOfArgumentsOrdered { nodes: (a, b, c) }),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
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((
|
||||||
|
symbol(","),
|
||||||
|
symbol("."),
|
||||||
|
identifier,
|
||||||
|
symbol("("),
|
||||||
|
opt(expression),
|
||||||
|
symbol(")"),
|
||||||
|
)))(s)?;
|
||||||
|
Ok((
|
||||||
|
s,
|
||||||
|
ListOfArguments::Named(ListOfArgumentsNamed {
|
||||||
|
nodes: (a, b, c, d, e, f),
|
||||||
|
}),
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn method_call(s: Span) -> IResult<Span, MethodCall> {
|
pub fn method_call(s: Span) -> IResult<Span, MethodCall> {
|
||||||
let (s, x) = method_call_root(s)?;
|
let (s, a) = method_call_root(s)?;
|
||||||
let (s, _) = symbol(".")(s)?;
|
let (s, b) = symbol(".")(s)?;
|
||||||
let (s, y) = method_call_body(s)?;
|
let (s, c) = method_call_body(s)?;
|
||||||
|
|
||||||
Ok((s, MethodCall { nodes: (x, y) }))
|
Ok((s, MethodCall { nodes: (a, b, c) }))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn method_call_body(s: Span) -> IResult<Span, MethodCallBody> {
|
pub fn method_call_body(s: Span) -> IResult<Span, MethodCallBody> {
|
||||||
@ -221,12 +338,12 @@ pub fn method_call_body(s: Span) -> IResult<Span, MethodCallBody> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn method_call_body_user(s: Span) -> IResult<Span, MethodCallBody> {
|
pub fn method_call_body_user(s: Span) -> IResult<Span, MethodCallBody> {
|
||||||
let (s, x) = method_identifier(s)?;
|
let (s, a) = method_identifier(s)?;
|
||||||
let (s, y) = many0(attribute_instance)(s)?;
|
let (s, b) = many0(attribute_instance)(s)?;
|
||||||
let (s, z) = opt(paren(list_of_arguments))(s)?;
|
let (s, c) = opt(paren2(list_of_arguments))(s)?;
|
||||||
Ok((
|
Ok((
|
||||||
s,
|
s,
|
||||||
MethodCallBody::User(MethodCallBodyUser { nodes: (x, y, z) }),
|
MethodCallBody::User(MethodCallBodyUser { nodes: (a, b, c) }),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -240,50 +357,44 @@ pub fn built_in_method_call(s: Span) -> IResult<Span, BuiltInMethodCall> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn array_manipulation_call(s: Span) -> IResult<Span, ArrayManipulationCall> {
|
pub fn array_manipulation_call(s: Span) -> IResult<Span, ArrayManipulationCall> {
|
||||||
let (s, x) = array_method_name(s)?;
|
let (s, a) = array_method_name(s)?;
|
||||||
let (s, y) = many0(attribute_instance)(s)?;
|
let (s, b) = many0(attribute_instance)(s)?;
|
||||||
let (s, z) = opt(paren(list_of_arguments))(s)?;
|
let (s, c) = opt(paren2(list_of_arguments))(s)?;
|
||||||
let (s, v) = opt(preceded(symbol("with"), paren(expression)))(s)?;
|
let (s, d) = opt(pair(symbol("with"), paren2(expression)))(s)?;
|
||||||
Ok((
|
Ok((
|
||||||
s,
|
s,
|
||||||
ArrayManipulationCall {
|
ArrayManipulationCall {
|
||||||
nodes: (x, y, z, v),
|
nodes: (a, b, c, d),
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn randomize_call(s: Span) -> IResult<Span, RandomizeCall> {
|
pub fn randomize_call(s: Span) -> IResult<Span, RandomizeCall> {
|
||||||
let (s, _) = symbol("randomize")(s)?;
|
let (s, a) = symbol("randomize")(s)?;
|
||||||
let (s, x) = many0(attribute_instance)(s)?;
|
let (s, b) = many0(attribute_instance)(s)?;
|
||||||
let (s, y) = opt(paren(opt(alt((
|
let (s, c) = opt(paren2(opt(variable_identifier_list_or_null)))(s)?;
|
||||||
variable_identifier_list,
|
let (s, d) = opt(triple(
|
||||||
map(symbol("null"), |_| VariableIdentifierList {
|
|
||||||
nodes: (vec![],),
|
|
||||||
}),
|
|
||||||
)))))(s)?;
|
|
||||||
let (s, z) = opt(triple(
|
|
||||||
symbol("with"),
|
symbol("with"),
|
||||||
opt(paren(opt(identifier_list))),
|
opt(paren2(opt(identifier_list))),
|
||||||
constraint_block,
|
constraint_block,
|
||||||
))(s)?;
|
))(s)?;
|
||||||
let y = if let Some(Some(y)) = y {
|
|
||||||
y
|
|
||||||
} else {
|
|
||||||
VariableIdentifierList { nodes: (vec![],) }
|
|
||||||
};
|
|
||||||
let (z, v) = if let Some((_, Some(Some(z)), v)) = z {
|
|
||||||
(z, Some(v))
|
|
||||||
} else {
|
|
||||||
(IdentifierList { nodes: (vec![],) }, None)
|
|
||||||
};
|
|
||||||
Ok((
|
Ok((
|
||||||
s,
|
s,
|
||||||
RandomizeCall {
|
RandomizeCall {
|
||||||
nodes: (x, y, z, v),
|
nodes: (a, b, c, d),
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn variable_identifier_list_or_null(s: Span) -> IResult<Span, VariableIdentifierListOrNull> {
|
||||||
|
alt((
|
||||||
|
map(variable_identifier_list, |x| {
|
||||||
|
VariableIdentifierListOrNull::VariableIdentifierList(x)
|
||||||
|
}),
|
||||||
|
map(symbol("null"), |x| VariableIdentifierListOrNull::Null(x)),
|
||||||
|
))(s)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn method_call_root(s: Span) -> IResult<Span, MethodCallRoot> {
|
pub fn method_call_root(s: Span) -> IResult<Span, MethodCallRoot> {
|
||||||
alt((
|
alt((
|
||||||
map(primary, |x| MethodCallRoot::Primary(x)),
|
map(primary, |x| MethodCallRoot::Primary(x)),
|
||||||
@ -295,10 +406,10 @@ pub fn method_call_root(s: Span) -> IResult<Span, MethodCallRoot> {
|
|||||||
|
|
||||||
pub fn array_method_name(s: Span) -> IResult<Span, ArrayMethodName> {
|
pub fn array_method_name(s: Span) -> IResult<Span, ArrayMethodName> {
|
||||||
alt((
|
alt((
|
||||||
map(symbol("unique"), |_| ArrayMethodName::Unique),
|
map(symbol("unique"), |x| ArrayMethodName::Unique(x)),
|
||||||
map(symbol("and"), |_| ArrayMethodName::And),
|
map(symbol("and"), |x| ArrayMethodName::And(x)),
|
||||||
map(symbol("or"), |_| ArrayMethodName::Or),
|
map(symbol("or"), |x| ArrayMethodName::Or(x)),
|
||||||
map(symbol("xor"), |_| ArrayMethodName::Xor),
|
map(symbol("xor"), |x| ArrayMethodName::Xor(x)),
|
||||||
map(method_identifier, |x| ArrayMethodName::MethodIdentifier(x)),
|
map(method_identifier, |x| ArrayMethodName::MethodIdentifier(x)),
|
||||||
))(s)
|
))(s)
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ use crate::parser::*;
|
|||||||
use nom::branch::*;
|
use nom::branch::*;
|
||||||
use nom::combinator::*;
|
use nom::combinator::*;
|
||||||
use nom::multi::*;
|
use nom::multi::*;
|
||||||
|
use nom::sequence::*;
|
||||||
use nom::IResult;
|
use nom::IResult;
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
@ -11,19 +12,44 @@ pub struct ModuleInstantiation<'a> {
|
|||||||
pub nodes: (
|
pub nodes: (
|
||||||
ModuleIdentifier<'a>,
|
ModuleIdentifier<'a>,
|
||||||
Option<ParameterValueAssignment<'a>>,
|
Option<ParameterValueAssignment<'a>>,
|
||||||
Vec<HierarchicalInstance<'a>>,
|
HierarchicalInstance<'a>,
|
||||||
|
Vec<(Symbol<'a>, HierarchicalInstance<'a>)>,
|
||||||
|
Symbol<'a>,
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ParameterValueAssignment<'a> {
|
pub struct ParameterValueAssignment<'a> {
|
||||||
pub nodes: (ListOfParameterAssignments<'a>,),
|
pub nodes: (
|
||||||
|
Symbol<'a>,
|
||||||
|
(
|
||||||
|
Symbol<'a>,
|
||||||
|
Option<ListOfParameterAssignments<'a>>,
|
||||||
|
Symbol<'a>,
|
||||||
|
),
|
||||||
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum ListOfParameterAssignments<'a> {
|
pub enum ListOfParameterAssignments<'a> {
|
||||||
Ordered(Vec<OrderedParameterAssignment<'a>>),
|
Ordered(ListOfParameterAssignmentsOrdered<'a>),
|
||||||
Named(Vec<NamedParameterAssignment<'a>>),
|
Named(ListOfParameterAssignmentsNamed<'a>),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct ListOfParameterAssignmentsOrdered<'a> {
|
||||||
|
pub nodes: (
|
||||||
|
OrderedParameterAssignment<'a>,
|
||||||
|
Vec<(Symbol<'a>, OrderedParameterAssignment<'a>)>,
|
||||||
|
),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct ListOfParameterAssignmentsNamed<'a> {
|
||||||
|
pub nodes: (
|
||||||
|
NamedParameterAssignment<'a>,
|
||||||
|
Vec<(Symbol<'a>, NamedParameterAssignment<'a>)>,
|
||||||
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -33,12 +59,19 @@ pub struct OrderedParameterAssignment<'a> {
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct NamedParameterAssignment<'a> {
|
pub struct NamedParameterAssignment<'a> {
|
||||||
pub nodes: (ParameterIdentifier<'a>, Option<ParamExpression<'a>>),
|
pub nodes: (
|
||||||
|
Symbol<'a>,
|
||||||
|
ParameterIdentifier<'a>,
|
||||||
|
(Symbol<'a>, Option<ParamExpression<'a>>, Symbol<'a>),
|
||||||
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct HierarchicalInstance<'a> {
|
pub struct HierarchicalInstance<'a> {
|
||||||
pub nodes: (NameOfInstance<'a>, Option<ListOfPortConnections<'a>>),
|
pub nodes: (
|
||||||
|
NameOfInstance<'a>,
|
||||||
|
(Symbol<'a>, Option<ListOfPortConnections<'a>>, Symbol<'a>),
|
||||||
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -48,8 +81,24 @@ pub struct NameOfInstance<'a> {
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum ListOfPortConnections<'a> {
|
pub enum ListOfPortConnections<'a> {
|
||||||
Ordered(Vec<OrderedPortConnection<'a>>),
|
Ordered(ListOfPortConnectionsOrdered<'a>),
|
||||||
Named(Vec<NamedPortConnection<'a>>),
|
Named(ListOfPortConnectionsNamed<'a>),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct ListOfPortConnectionsOrdered<'a> {
|
||||||
|
pub nodes: (
|
||||||
|
OrderedPortConnection<'a>,
|
||||||
|
Vec<(Symbol<'a>, OrderedPortConnection<'a>)>,
|
||||||
|
),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct ListOfPortConnectionsNamed<'a> {
|
||||||
|
pub nodes: (
|
||||||
|
NamedPortConnection<'a>,
|
||||||
|
Vec<(Symbol<'a>, NamedPortConnection<'a>)>,
|
||||||
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -67,61 +116,80 @@ pub enum NamedPortConnection<'a> {
|
|||||||
pub struct NamedPortConnectionIdentifier<'a> {
|
pub struct NamedPortConnectionIdentifier<'a> {
|
||||||
pub nodes: (
|
pub nodes: (
|
||||||
Vec<AttributeInstance<'a>>,
|
Vec<AttributeInstance<'a>>,
|
||||||
|
Symbol<'a>,
|
||||||
PortIdentifier<'a>,
|
PortIdentifier<'a>,
|
||||||
Option<Expression<'a>>,
|
Option<(Symbol<'a>, Option<Expression<'a>>, Symbol<'a>)>,
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct NamedPortConnectionAsterisk<'a> {
|
pub struct NamedPortConnectionAsterisk<'a> {
|
||||||
pub nodes: (Vec<AttributeInstance<'a>>,),
|
pub nodes: (Vec<AttributeInstance<'a>>, Symbol<'a>),
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
pub fn module_instantiation(s: Span) -> IResult<Span, ModuleInstantiation> {
|
pub fn module_instantiation(s: Span) -> IResult<Span, ModuleInstantiation> {
|
||||||
let (s, x) = module_identifier(s)?;
|
let (s, a) = module_identifier(s)?;
|
||||||
let (s, y) = opt(parameter_value_assignment)(s)?;
|
let (s, b) = opt(parameter_value_assignment)(s)?;
|
||||||
let (s, z) = separated_nonempty_list(symbol(","), hierarchical_instance)(s)?;
|
let (s, c) = hierarchical_instance(s)?;
|
||||||
let (s, _) = symbol(";")(s)?;
|
let (s, d) = many0(pair(symbol(","), hierarchical_instance))(s)?;
|
||||||
Ok((s, ModuleInstantiation { nodes: (x, y, z) }))
|
let (s, e) = symbol(";")(s)?;
|
||||||
|
Ok((
|
||||||
|
s,
|
||||||
|
ModuleInstantiation {
|
||||||
|
nodes: (a, b, c, d, e),
|
||||||
|
},
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parameter_value_assignment(s: Span) -> IResult<Span, ParameterValueAssignment> {
|
pub fn parameter_value_assignment(s: Span) -> IResult<Span, ParameterValueAssignment> {
|
||||||
let (s, _) = symbol("#")(s)?;
|
let (s, a) = symbol("#")(s)?;
|
||||||
let (s, x) = paren(list_of_parameter_assignments)(s)?;
|
let (s, b) = paren2(opt(list_of_parameter_assignments))(s)?;
|
||||||
Ok((s, ParameterValueAssignment { nodes: (x,) }))
|
Ok((s, ParameterValueAssignment { nodes: (a, b) }))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn list_of_parameter_assignments(s: Span) -> IResult<Span, ListOfParameterAssignments> {
|
pub fn list_of_parameter_assignments(s: Span) -> IResult<Span, ListOfParameterAssignments> {
|
||||||
alt((
|
alt((
|
||||||
map(
|
list_of_parameter_assignments_ordered,
|
||||||
separated_nonempty_list(symbol(","), ordered_parameter_assignment),
|
list_of_parameter_assignments_named,
|
||||||
|x| ListOfParameterAssignments::Ordered(x),
|
|
||||||
),
|
|
||||||
map(
|
|
||||||
separated_nonempty_list(symbol(","), named_parameter_assignment),
|
|
||||||
|x| ListOfParameterAssignments::Named(x),
|
|
||||||
),
|
|
||||||
))(s)
|
))(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)?;
|
||||||
|
Ok((
|
||||||
|
s,
|
||||||
|
ListOfParameterAssignments::Ordered(ListOfParameterAssignmentsOrdered { nodes: (a, b) }),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
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)?;
|
||||||
|
Ok((
|
||||||
|
s,
|
||||||
|
ListOfParameterAssignments::Named(ListOfParameterAssignmentsNamed { nodes: (a, b) }),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
pub fn ordered_parameter_assignment(s: Span) -> IResult<Span, OrderedParameterAssignment> {
|
pub fn ordered_parameter_assignment(s: Span) -> IResult<Span, OrderedParameterAssignment> {
|
||||||
let (s, x) = param_expression(s)?;
|
let (s, x) = param_expression(s)?;
|
||||||
Ok((s, OrderedParameterAssignment { nodes: (x,) }))
|
Ok((s, OrderedParameterAssignment { nodes: (x,) }))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn named_parameter_assignment(s: Span) -> IResult<Span, NamedParameterAssignment> {
|
pub fn named_parameter_assignment(s: Span) -> IResult<Span, NamedParameterAssignment> {
|
||||||
let (s, _) = symbol(".")(s)?;
|
let (s, a) = symbol(".")(s)?;
|
||||||
let (s, x) = parameter_identifier(s)?;
|
let (s, b) = parameter_identifier(s)?;
|
||||||
let (s, y) = paren(opt(param_expression))(s)?;
|
let (s, c) = paren2(opt(param_expression))(s)?;
|
||||||
Ok((s, NamedParameterAssignment { nodes: (x, y) }))
|
Ok((s, NamedParameterAssignment { nodes: (a, b, c) }))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn hierarchical_instance(s: Span) -> IResult<Span, HierarchicalInstance> {
|
pub fn hierarchical_instance(s: Span) -> IResult<Span, HierarchicalInstance> {
|
||||||
let (s, x) = name_of_instance(s)?;
|
let (s, a) = name_of_instance(s)?;
|
||||||
let (s, y) = paren(opt(list_of_port_connections))(s)?;
|
let (s, b) = paren2(opt(list_of_port_connections))(s)?;
|
||||||
Ok((s, HierarchicalInstance { nodes: (x, y) }))
|
Ok((s, HierarchicalInstance { nodes: (a, b) }))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn name_of_instance(s: Span) -> IResult<Span, NameOfInstance> {
|
pub fn name_of_instance(s: Span) -> IResult<Span, NameOfInstance> {
|
||||||
@ -132,17 +200,29 @@ pub fn name_of_instance(s: Span) -> IResult<Span, NameOfInstance> {
|
|||||||
|
|
||||||
pub fn list_of_port_connections(s: Span) -> IResult<Span, ListOfPortConnections> {
|
pub fn list_of_port_connections(s: Span) -> IResult<Span, ListOfPortConnections> {
|
||||||
alt((
|
alt((
|
||||||
map(
|
list_of_port_connections_ordered,
|
||||||
separated_nonempty_list(symbol(","), ordered_port_connection),
|
list_of_port_connections_named,
|
||||||
|x| ListOfPortConnections::Ordered(x),
|
|
||||||
),
|
|
||||||
map(
|
|
||||||
separated_nonempty_list(symbol(","), named_port_connection),
|
|
||||||
|x| ListOfPortConnections::Named(x),
|
|
||||||
),
|
|
||||||
))(s)
|
))(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)?;
|
||||||
|
Ok((
|
||||||
|
s,
|
||||||
|
ListOfPortConnections::Ordered(ListOfPortConnectionsOrdered { nodes: (a, b) }),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
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)?;
|
||||||
|
Ok((
|
||||||
|
s,
|
||||||
|
ListOfPortConnections::Named(ListOfPortConnectionsNamed { nodes: (a, b) }),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
pub fn ordered_port_connection(s: Span) -> IResult<Span, OrderedPortConnection> {
|
pub fn ordered_port_connection(s: Span) -> IResult<Span, OrderedPortConnection> {
|
||||||
let (s, x) = many0(attribute_instance)(s)?;
|
let (s, x) = many0(attribute_instance)(s)?;
|
||||||
let (s, y) = opt(expression)(s)?;
|
let (s, y) = opt(expression)(s)?;
|
||||||
@ -157,24 +237,24 @@ pub fn named_port_connection(s: Span) -> IResult<Span, NamedPortConnection> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn named_port_connection_identifier(s: Span) -> IResult<Span, NamedPortConnection> {
|
pub fn named_port_connection_identifier(s: Span) -> IResult<Span, NamedPortConnection> {
|
||||||
let (s, x) = many0(attribute_instance)(s)?;
|
let (s, a) = many0(attribute_instance)(s)?;
|
||||||
let (s, _) = symbol(".")(s)?;
|
let (s, b) = symbol(".")(s)?;
|
||||||
let (s, y) = port_identifier(s)?;
|
let (s, c) = port_identifier(s)?;
|
||||||
let (s, z) = opt(paren(opt(expression)))(s)?;
|
let (s, d) = opt(paren2(opt(expression)))(s)?;
|
||||||
let z = if let Some(Some(z)) = z { Some(z) } else { None };
|
|
||||||
Ok((
|
Ok((
|
||||||
s,
|
s,
|
||||||
NamedPortConnection::Identifier(NamedPortConnectionIdentifier { nodes: (x, y, z) }),
|
NamedPortConnection::Identifier(NamedPortConnectionIdentifier {
|
||||||
|
nodes: (a, b, c, d),
|
||||||
|
}),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn named_port_connection_asterisk(s: Span) -> IResult<Span, NamedPortConnection> {
|
pub fn named_port_connection_asterisk(s: Span) -> IResult<Span, NamedPortConnection> {
|
||||||
let (s, x) = many0(attribute_instance)(s)?;
|
let (s, a) = many0(attribute_instance)(s)?;
|
||||||
let (s, _) = symbol(".")(s)?;
|
let (s, b) = symbol(".*")(s)?;
|
||||||
let (s, _) = symbol("*")(s)?;
|
|
||||||
Ok((
|
Ok((
|
||||||
s,
|
s,
|
||||||
NamedPortConnection::Asterisk(NamedPortConnectionAsterisk { nodes: (x,) }),
|
NamedPortConnection::Asterisk(NamedPortConnectionAsterisk { nodes: (a, b) }),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user