Add expressions/subroutine_calls

This commit is contained in:
dalance 2019-07-03 15:04:51 +09:00
parent 46f61155cb
commit 2f5396642f
8 changed files with 1125 additions and 129 deletions

View File

@ -1,3 +1,4 @@
use crate::expressions::*;
use crate::identifiers::*; use crate::identifiers::*;
use crate::util::*; use crate::util::*;
use nom::bytes::complete::*; use nom::bytes::complete::*;
@ -49,13 +50,19 @@ mod tests {
), ),
"Ok((\"\", AttributeInstance { attr_spec: [AttrSpec { attr_name: Identifier { raw: [\"full_case\"] }, rvalue: None }, AttrSpec { attr_name: Identifier { raw: [\"parallel_case\"] }, rvalue: None }] }))" "Ok((\"\", AttributeInstance { attr_spec: [AttrSpec { attr_name: Identifier { raw: [\"full_case\"] }, rvalue: None }, AttrSpec { attr_name: Identifier { raw: [\"parallel_case\"] }, rvalue: None }] }))"
); );
// TODO after constant_expression assert_eq!(
//assert_eq!( format!(
// format!( "{:?}",
// "{:?}", all_consuming(attribute_instance)("(* full_case=1 *)")
// all_consuming(attribute_instance)("(* full_case=1 *)") ),
// ), "Ok((\"\", AttributeInstance { attr_spec: [AttrSpec { attr_name: Identifier { raw: [\"full_case\"] }, rvalue: Some(Nullary(PrimaryLiteral(Number(IntegralNumber(UnsignedNumber([\"1\"])))))) }] }))"
// "" );
//); assert_eq!(
format!(
"{:?}",
all_consuming(attribute_instance)("(* full_case=1, parallel_case = 0 *)")
),
"Ok((\"\", AttributeInstance { attr_spec: [AttrSpec { attr_name: Identifier { raw: [\"full_case\"] }, rvalue: Some(Nullary(PrimaryLiteral(Number(IntegralNumber(UnsignedNumber([\"1\"])))))) }, AttrSpec { attr_name: Identifier { raw: [\"parallel_case\"] }, rvalue: Some(Nullary(PrimaryLiteral(Number(IntegralNumber(UnsignedNumber([\"0\"])))))) }] }))"
);
} }
} }

629
src/expressions.rs Normal file
View File

@ -0,0 +1,629 @@
use crate::attributes::*;
use crate::identifiers::*;
use crate::lvalues::*;
use crate::operators::*;
use crate::primaries::*;
use crate::util::*;
use nom::branch::*;
use nom::bytes::complete::*;
use nom::combinator::*;
use nom::multi::*;
use nom::sequence::*;
use nom::IResult;
// -----------------------------------------------------------------------------
#[derive(Debug)]
pub enum IncOrDecExpression<'a> {
Prefix(IncOrDecExpressionPrefix<'a>),
Suffix(IncOrDecExpressionSuffix<'a>),
}
#[derive(Debug)]
pub struct IncOrDecExpressionPrefix<'a> {
pub operator: Operator<'a>,
pub attribute: Vec<AttributeInstance<'a>>,
pub lvalue: VariableLvalue<'a>,
}
#[derive(Debug)]
pub struct IncOrDecExpressionSuffix<'a> {
pub lvalue: VariableLvalue<'a>,
pub attribute: Vec<AttributeInstance<'a>>,
pub operator: Operator<'a>,
}
#[derive(Debug)]
pub struct ConditionalExpression<'a> {
pub predicate: CondPredicate<'a>,
pub attribute: Vec<AttributeInstance<'a>>,
pub arg0: Expression<'a>,
pub arg1: Expression<'a>,
}
#[derive(Debug)]
pub enum ConstantExpression<'a> {
Nullary(Box<ConstantPrimary<'a>>),
Unary(Box<ConstantExpressionUnary<'a>>),
Binary(Box<ConstantExpressionBinary<'a>>),
Ternary(Box<ConstantExpressionTernary<'a>>),
}
#[derive(Debug)]
pub struct ConstantExpressionUnary<'a> {
pub operator: Operator<'a>,
pub attribute: Vec<AttributeInstance<'a>>,
pub arg0: ConstantPrimary<'a>,
}
#[derive(Debug)]
pub struct ConstantExpressionBinary<'a> {
pub arg0: ConstantExpression<'a>,
pub operator: Operator<'a>,
pub attribute: Vec<AttributeInstance<'a>>,
pub arg1: ConstantExpression<'a>,
}
#[derive(Debug)]
pub struct ConstantExpressionTernary<'a> {
pub predicate: ConstantExpression<'a>,
pub attribute: Vec<AttributeInstance<'a>>,
pub arg0: ConstantExpression<'a>,
pub arg1: ConstantExpression<'a>,
}
#[derive(Debug)]
pub enum ConstantMintypmaxExpression<'a> {
Unary(ConstantExpression<'a>),
Ternary(
(
ConstantExpression<'a>,
ConstantExpression<'a>,
ConstantExpression<'a>,
),
),
}
#[derive(Debug)]
pub enum ConstantParamExpression<'a> {
Mintypmax(ConstantMintypmaxExpression<'a>),
DataType(DataType<'a>),
Dollar,
}
#[derive(Debug)]
pub enum ParamExpression<'a> {
Mintypmax(MintypmaxExpression<'a>),
DataType(DataType<'a>),
Dollar,
}
#[derive(Debug)]
pub enum ConstantRangeExpression<'a> {
Expression(ConstantExpression<'a>),
PartSelectRange(ConstantPartSelectRange<'a>),
}
#[derive(Debug)]
pub enum ConstantPartSelectRange<'a> {
Range((ConstantExpression<'a>, ConstantExpression<'a>)),
IndexedRange((ConstantExpression<'a>, &'a str, ConstantExpression<'a>)),
}
#[derive(Debug)]
pub enum Expression<'a> {
Nullary(Box<Primary<'a>>),
Unary(Box<ExpressionUnary<'a>>),
IncOrDec(Box<IncOrDecExpression<'a>>),
Assignment(Box<OperatorAssignment<'a>>),
Binary(Box<ExpressionBinary<'a>>),
Conditional(Box<ConditionalExpression<'a>>),
Inside(Box<InsideExpression<'a>>),
TaggedUnion(Box<TaggedUnionExpression<'a>>),
}
#[derive(Debug)]
pub struct ExpressionUnary<'a> {
pub operator: Operator<'a>,
pub attribute: Vec<AttributeInstance<'a>>,
pub arg0: Primary<'a>,
}
#[derive(Debug)]
pub struct ExpressionBinary<'a> {
pub arg0: Expression<'a>,
pub operator: Operator<'a>,
pub attribute: Vec<AttributeInstance<'a>>,
pub arg1: Expression<'a>,
}
#[derive(Debug)]
pub struct TaggedUnionExpression<'a> {
pub identifier: Identifier<'a>,
pub expression: Option<Expression<'a>>,
}
#[derive(Debug)]
pub struct InsideExpression<'a> {
pub expression: Expression<'a>,
pub open_range_list: OpenRangeList<'a>,
}
#[derive(Debug)]
pub enum ValueRange<'a> {
Unary(Expression<'a>),
Binary((Expression<'a>, Expression<'a>)),
}
#[derive(Debug)]
pub enum MintypmaxExpression<'a> {
Unary(Expression<'a>),
Ternary((Expression<'a>, Expression<'a>, Expression<'a>)),
}
#[derive(Debug)]
pub struct ModulePathConditionalExpression<'a> {
pub predicate: ModulePathExpression<'a>,
pub attribute: Vec<AttributeInstance<'a>>,
pub arg0: ModulePathExpression<'a>,
pub arg1: ModulePathExpression<'a>,
}
#[derive(Debug)]
pub enum ModulePathExpression<'a> {
Nullary(Box<ModulePathPrimary<'a>>),
Unary(Box<ModulePathExpressionUnary<'a>>),
Binary(Box<ModulePathExpressionBinary<'a>>),
Conditional(Box<ModulePathConditionalExpression<'a>>),
}
#[derive(Debug)]
pub struct ModulePathExpressionUnary<'a> {
pub operator: Operator<'a>,
pub attribute: Vec<AttributeInstance<'a>>,
pub arg0: ModulePathPrimary<'a>,
}
#[derive(Debug)]
pub struct ModulePathExpressionBinary<'a> {
pub arg0: ModulePathExpression<'a>,
pub operator: Operator<'a>,
pub attribute: Vec<AttributeInstance<'a>>,
pub arg1: ModulePathExpression<'a>,
}
#[derive(Debug)]
pub enum ModulePathMintypmaxExpression<'a> {
Unary(ModulePathExpression<'a>),
Ternary(
(
ModulePathExpression<'a>,
ModulePathExpression<'a>,
ModulePathExpression<'a>,
),
),
}
#[derive(Debug)]
pub enum PartSelectRange<'a> {
Range((ConstantExpression<'a>, ConstantExpression<'a>)),
IndexedRange((Expression<'a>, &'a str, ConstantExpression<'a>)),
}
// -----------------------------------------------------------------------------
pub fn inc_or_dec_expression(s: &str) -> IResult<&str, IncOrDecExpression> {
alt((inc_or_dec_expression_prefix, inc_or_dec_expression_suffix))(s)
}
pub fn inc_or_dec_expression_prefix(s: &str) -> IResult<&str, IncOrDecExpression> {
let (s, operator) = inc_or_dec_operator(s)?;
let (s, attribute) = many0(sp(attribute_instance))(s)?;
let (s, lvalue) = sp(variable_lvalue)(s)?;
Ok((
s,
IncOrDecExpression::Prefix(IncOrDecExpressionPrefix {
operator,
attribute,
lvalue,
}),
))
}
pub fn inc_or_dec_expression_suffix(s: &str) -> IResult<&str, IncOrDecExpression> {
let (s, lvalue) = variable_lvalue(s)?;
let (s, attribute) = many0(sp(attribute_instance))(s)?;
let (s, operator) = sp(inc_or_dec_operator)(s)?;
Ok((
s,
IncOrDecExpression::Suffix(IncOrDecExpressionSuffix {
lvalue,
attribute,
operator,
}),
))
}
pub fn conditional_expression(s: &str) -> IResult<&str, ConditionalExpression> {
let (s, predicate) = cond_predicate(s)?;
let (s, _) = sp(tag("?"))(s)?;
let (s, attribute) = many0(sp(attribute_instance))(s)?;
let (s, arg0) = sp(expression)(s)?;
let (s, _) = sp(tag(":"))(s)?;
let (s, arg1) = sp(expression)(s)?;
Ok((
s,
ConditionalExpression {
predicate,
attribute,
arg0,
arg1,
},
))
}
pub fn constant_expression(s: &str) -> IResult<&str, ConstantExpression> {
alt((
map(constant_primary, |x| {
ConstantExpression::Nullary(Box::new(x))
}),
constant_expression_unary,
constant_expression_binary,
constant_expression_ternary,
))(s)
}
pub fn constant_expression_unary(s: &str) -> IResult<&str, ConstantExpression> {
let (s, operator) = unary_operator(s)?;
let (s, attribute) = many0(sp(attribute_instance))(s)?;
let (s, arg0) = sp(constant_primary)(s)?;
Ok((
s,
ConstantExpression::Unary(Box::new(ConstantExpressionUnary {
operator,
attribute,
arg0,
})),
))
}
pub fn constant_expression_binary(s: &str) -> IResult<&str, ConstantExpression> {
let (s, arg0) = constant_expression(s)?;
let (s, operator) = sp(binary_operator)(s)?;
let (s, attribute) = many0(sp(attribute_instance))(s)?;
let (s, arg1) = sp(constant_expression)(s)?;
Ok((
s,
ConstantExpression::Binary(Box::new(ConstantExpressionBinary {
arg0,
operator,
attribute,
arg1,
})),
))
}
pub fn constant_expression_ternary(s: &str) -> IResult<&str, ConstantExpression> {
let (s, predicate) = constant_expression(s)?;
let (s, _) = sp(tag("?"))(s)?;
let (s, attribute) = many0(sp(attribute_instance))(s)?;
let (s, arg0) = constant_expression(s)?;
let (s, _) = sp(tag(":"))(s)?;
let (s, arg1) = sp(constant_expression)(s)?;
Ok((
s,
ConstantExpression::Ternary(Box::new(ConstantExpressionTernary {
predicate,
attribute,
arg0,
arg1,
})),
))
}
pub fn constant_mintypmax_expression(s: &str) -> IResult<&str, ConstantMintypmaxExpression> {
alt((
constant_mintypmax_expression_ternary,
map(constant_expression, |x| {
ConstantMintypmaxExpression::Unary(x)
}),
))(s)
}
pub fn constant_mintypmax_expression_ternary(
s: &str,
) -> IResult<&str, ConstantMintypmaxExpression> {
let (s, x) = constant_expression(s)?;
let (s, _) = sp(tag(":"))(s)?;
let (s, y) = sp(constant_expression)(s)?;
let (s, _) = sp(tag(":"))(s)?;
let (s, z) = sp(constant_expression)(s)?;
Ok((s, ConstantMintypmaxExpression::Ternary((x, y, z))))
}
pub fn constant_param_expression(s: &str) -> IResult<&str, ConstantParamExpression> {
alt((
map(tag("$"), |_| ConstantParamExpression::Dollar),
map(constant_mintypmax_expression, |x| {
ConstantParamExpression::Mintypmax(x)
}),
map(data_type, |x| ConstantParamExpression::DataType(x)),
))(s)
}
pub fn param_expression(s: &str) -> IResult<&str, ParamExpression> {
alt((
map(tag("$"), |_| ParamExpression::Dollar),
map(mintypmax_expression, |x| ParamExpression::Mintypmax(x)),
map(data_type, |x| ParamExpression::DataType(x)),
))(s)
}
pub fn constant_range_expression(s: &str) -> IResult<&str, ConstantRangeExpression> {
alt((
map(constant_part_select_range, |x| {
ConstantRangeExpression::PartSelectRange(x)
}),
map(constant_expression, |x| {
ConstantRangeExpression::Expression(x)
}),
))(s)
}
pub fn constant_part_select_range(s: &str) -> IResult<&str, ConstantPartSelectRange> {
alt((constant_range, constant_indexed_range))(s)
}
pub fn constant_range(s: &str) -> IResult<&str, ConstantPartSelectRange> {
let (s, x) = constant_expression(s)?;
let (s, _) = sp(tag(":"))(s)?;
let (s, y) = sp(constant_expression)(s)?;
Ok((s, ConstantPartSelectRange::Range((x, y))))
}
pub fn constant_indexed_range(s: &str) -> IResult<&str, ConstantPartSelectRange> {
let (s, x) = constant_expression(s)?;
let (s, y) = sp(alt((tag("+:"), tag("-:"))))(s)?;
let (s, z) = sp(constant_expression)(s)?;
Ok((s, ConstantPartSelectRange::IndexedRange((x, y, z))))
}
pub fn expression(s: &str) -> IResult<&str, Expression> {
alt((
map(primary, |x| Expression::Nullary(Box::new(x))),
expression_unary,
map(inc_or_dec_expression, |x| Expression::IncOrDec(Box::new(x))),
map(
delimited(tag("("), sp(operator_assignment), sp(tag(")"))),
|x| Expression::Assignment(Box::new(x)),
),
expression_binary,
map(conditional_expression, |x| {
Expression::Conditional(Box::new(x))
}),
map(inside_expression, |x| Expression::Inside(Box::new(x))),
map(tagged_union_expression, |x| {
Expression::TaggedUnion(Box::new(x))
}),
))(s)
}
pub fn expression_unary(s: &str) -> IResult<&str, Expression> {
let (s, operator) = unary_operator(s)?;
let (s, attribute) = many0(sp(attribute_instance))(s)?;
let (s, arg0) = sp(primary)(s)?;
Ok((
s,
Expression::Unary(Box::new(ExpressionUnary {
operator,
attribute,
arg0,
})),
))
}
pub fn expression_binary(s: &str) -> IResult<&str, Expression> {
let (s, arg0) = expression(s)?;
let (s, operator) = sp(binary_operator)(s)?;
let (s, attribute) = many0(sp(attribute_instance))(s)?;
let (s, arg1) = sp(expression)(s)?;
Ok((
s,
Expression::Binary(Box::new(ExpressionBinary {
arg0,
operator,
attribute,
arg1,
})),
))
}
pub fn tagged_union_expression(s: &str) -> IResult<&str, TaggedUnionExpression> {
let (s, _) = tag("tagged")(s)?;
let (s, identifier) = sp(member_identifier)(s)?;
let (s, expression) = opt(sp(expression))(s)?;
Ok((
s,
TaggedUnionExpression {
identifier,
expression,
},
))
}
pub fn inside_expression(s: &str) -> IResult<&str, InsideExpression> {
let (s, expression) = expression(s)?;
let (s, _) = sp(tag("inside"))(s)?;
let (s, open_range_list) = delimited(sp(tag("{")), sp(open_range_list), sp(tag("}")))(s)?;
Ok((
s,
InsideExpression {
expression,
open_range_list,
},
))
}
pub fn value_range(s: &str) -> IResult<&str, ValueRange> {
alt((
value_range_binary,
map(expression, |x| ValueRange::Unary(x)),
))(s)
}
pub fn value_range_binary(s: &str) -> IResult<&str, ValueRange> {
let (s, _) = tag("[")(s)?;
let (s, x) = sp(expression)(s)?;
let (s, _) = sp(tag(":"))(s)?;
let (s, y) = sp(expression)(s)?;
let (s, _) = sp(tag("]"))(s)?;
Ok((s, ValueRange::Binary((x, y))))
}
pub fn mintypmax_expression(s: &str) -> IResult<&str, MintypmaxExpression> {
alt((
mintypmax_expression_ternary,
map(expression, |x| MintypmaxExpression::Unary(x)),
))(s)
}
pub fn mintypmax_expression_ternary(s: &str) -> IResult<&str, MintypmaxExpression> {
let (s, x) = expression(s)?;
let (s, _) = sp(tag(":"))(s)?;
let (s, y) = sp(expression)(s)?;
let (s, _) = sp(tag(":"))(s)?;
let (s, z) = sp(expression)(s)?;
Ok((s, MintypmaxExpression::Ternary((x, y, z))))
}
pub fn module_path_conditional_expression(
s: &str,
) -> IResult<&str, ModulePathConditionalExpression> {
let (s, predicate) = module_path_expression(s)?;
let (s, _) = sp(tag("?"))(s)?;
let (s, attribute) = many0(sp(attribute_instance))(s)?;
let (s, arg0) = sp(module_path_expression)(s)?;
let (s, _) = sp(tag(":"))(s)?;
let (s, arg1) = sp(module_path_expression)(s)?;
Ok((
s,
ModulePathConditionalExpression {
predicate,
attribute,
arg0,
arg1,
},
))
}
pub fn module_path_expression(s: &str) -> IResult<&str, ModulePathExpression> {
alt((
map(module_path_primary, |x| {
ModulePathExpression::Nullary(Box::new(x))
}),
module_path_expression_unary,
module_path_expression_binary,
map(module_path_conditional_expression, |x| {
ModulePathExpression::Conditional(Box::new(x))
}),
))(s)
}
pub fn module_path_expression_unary(s: &str) -> IResult<&str, ModulePathExpression> {
let (s, operator) = unary_module_path_operator(s)?;
let (s, attribute) = many0(sp(attribute_instance))(s)?;
let (s, arg0) = sp(module_path_primary)(s)?;
Ok((
s,
ModulePathExpression::Unary(Box::new(ModulePathExpressionUnary {
operator,
attribute,
arg0,
})),
))
}
pub fn module_path_expression_binary(s: &str) -> IResult<&str, ModulePathExpression> {
let (s, arg0) = module_path_expression(s)?;
let (s, operator) = sp(binary_module_path_operator)(s)?;
let (s, attribute) = many0(sp(attribute_instance))(s)?;
let (s, arg1) = sp(module_path_expression)(s)?;
Ok((
s,
ModulePathExpression::Binary(Box::new(ModulePathExpressionBinary {
arg0,
operator,
attribute,
arg1,
})),
))
}
pub fn module_path_mintypmax_expression(s: &str) -> IResult<&str, ModulePathMintypmaxExpression> {
alt((
module_path_mintypmax_expression_ternary,
map(module_path_expression, |x| {
ModulePathMintypmaxExpression::Unary(x)
}),
))(s)
}
pub fn module_path_mintypmax_expression_ternary(
s: &str,
) -> IResult<&str, ModulePathMintypmaxExpression> {
let (s, x) = module_path_expression(s)?;
let (s, _) = sp(tag(":"))(s)?;
let (s, y) = sp(module_path_expression)(s)?;
let (s, _) = sp(tag(":"))(s)?;
let (s, z) = sp(module_path_expression)(s)?;
Ok((s, ModulePathMintypmaxExpression::Ternary((x, y, z))))
}
pub fn part_select_range(s: &str) -> IResult<&str, PartSelectRange> {
alt((range, indexed_range))(s)
}
pub fn range(s: &str) -> IResult<&str, PartSelectRange> {
let (s, x) = constant_expression(s)?;
let (s, _) = sp(tag(":"))(s)?;
let (s, y) = sp(constant_expression)(s)?;
Ok((s, PartSelectRange::Range((x, y))))
}
pub fn indexed_range(s: &str) -> IResult<&str, PartSelectRange> {
let (s, x) = expression(s)?;
let (s, y) = sp(alt((tag("+:"), tag("-:"))))(s)?;
let (s, z) = sp(constant_expression)(s)?;
Ok((s, PartSelectRange::IndexedRange((x, y, z))))
}
pub fn genvar_expression(s: &str) -> IResult<&str, ConstantExpression> {
constant_expression(s)
}
// -----------------------------------------------------------------------------
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test() {
// TODO after operator_assignment
//assert_eq!(
// format!(
// "{:?}",
// all_consuming(expression)("(a:b:c) + (d:e:f)")
// ),
// ""
//);
// TODO after operator_assignment
//assert_eq!(
// format!(
// "{:?}",
// all_consuming(expression)("val - (32'd 50: 32'd 75: 32'd 100)")
// ),
// ""
//);
}
}

View File

@ -1,3 +1,4 @@
use crate::expressions::*;
use crate::primaries::*; use crate::primaries::*;
use crate::util::*; use crate::util::*;
use nom::branch::*; use nom::branch::*;
@ -57,7 +58,7 @@ impl<'a> From<Identifier<'a>> for HierarchicalIdentifier<'a> {
#[derive(Debug)] #[derive(Debug)]
pub struct Hierarchy<'a> { pub struct Hierarchy<'a> {
pub identifier: Identifier<'a>, pub identifier: Identifier<'a>,
pub constant_bit_select: Option<ConstantExpression<'a>>, pub constant_bit_select: Option<Vec<ConstantExpression<'a>>>,
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------

View File

@ -1,9 +1,11 @@
pub mod attributes; pub mod attributes;
pub mod comments; pub mod comments;
pub mod expressions;
pub mod identifiers; pub mod identifiers;
pub mod lvalues; pub mod lvalues;
pub mod numbers; pub mod numbers;
pub mod operators; pub mod operators;
pub mod primaries; pub mod primaries;
pub mod strings; pub mod strings;
pub mod subroutine_calls;
pub mod util; pub mod util;

View File

@ -169,5 +169,46 @@ mod tests {
use super::*; use super::*;
#[test] #[test]
fn test() {} fn test() {
assert_eq!(
format!("{:?}", all_consuming(net_lvalue)("a")),
"Ok((\"\", Identifier(NetLvalueIdentifier { identifier: ScopedIdentifier { scope: None, identifier: HierarchicalIdentifier { hierarchy: [], identifier: Identifier { raw: [\"a\"] } } }, select: ConstantSelect { member: None, bit_select: [], part_select_range: None } })))"
);
assert_eq!(
format!("{:?}", all_consuming(net_lvalue)("a[1][2]")),
"Ok((\"\", Identifier(NetLvalueIdentifier { identifier: ScopedIdentifier { scope: None, identifier: HierarchicalIdentifier { hierarchy: [], identifier: Identifier { raw: [\"a\"] } } }, select: ConstantSelect { member: None, bit_select: [Nullary(PrimaryLiteral(Number(IntegralNumber(UnsignedNumber([\"1\"]))))), Nullary(PrimaryLiteral(Number(IntegralNumber(UnsignedNumber([\"2\"])))))], part_select_range: None } })))"
);
assert_eq!(
format!("{:?}", all_consuming(net_lvalue)("a[1][10:5]")),
"Ok((\"\", Identifier(NetLvalueIdentifier { identifier: ScopedIdentifier { scope: None, identifier: HierarchicalIdentifier { hierarchy: [], identifier: Identifier { raw: [\"a\"] } } }, select: ConstantSelect { member: None, bit_select: [Nullary(PrimaryLiteral(Number(IntegralNumber(UnsignedNumber([\"1\"])))))], part_select_range: Some(Range((Nullary(PrimaryLiteral(Number(IntegralNumber(UnsignedNumber([\"10\"]))))), Nullary(PrimaryLiteral(Number(IntegralNumber(UnsignedNumber([\"5\"])))))))) } })))"
);
assert_eq!(
format!("{:?}", all_consuming(net_lvalue)("{a, b[1], c}")),
"Ok((\"\", Lvalue([Identifier(NetLvalueIdentifier { identifier: ScopedIdentifier { scope: None, identifier: HierarchicalIdentifier { hierarchy: [], identifier: Identifier { raw: [\"a\"] } } }, select: ConstantSelect { member: None, bit_select: [], part_select_range: None } }), Identifier(NetLvalueIdentifier { identifier: ScopedIdentifier { scope: None, identifier: HierarchicalIdentifier { hierarchy: [], identifier: Identifier { raw: [\"b\"] } } }, select: ConstantSelect { member: None, bit_select: [Nullary(PrimaryLiteral(Number(IntegralNumber(UnsignedNumber([\"1\"])))))], part_select_range: None } }), Identifier(NetLvalueIdentifier { identifier: ScopedIdentifier { scope: None, identifier: HierarchicalIdentifier { hierarchy: [], identifier: Identifier { raw: [\"c\"] } } }, select: ConstantSelect { member: None, bit_select: [], part_select_range: None } })])))"
);
assert_eq!(
format!("{:?}", all_consuming(variable_lvalue)("a")),
"Ok((\"\", Identifier(VariableLvalueIdentifier { scope: None, identifier: HierarchicalIdentifier { hierarchy: [], identifier: Identifier { raw: [\"a\"] } }, select: Select { member: None, bit_select: [], part_select_range: None } })))"
);
assert_eq!(
format!("{:?}", all_consuming(variable_lvalue)("a[1][2]")),
"Ok((\"\", Identifier(VariableLvalueIdentifier { scope: None, identifier: HierarchicalIdentifier { hierarchy: [], identifier: Identifier { raw: [\"a\"] } }, select: Select { member: None, bit_select: [Nullary(PrimaryLiteral(Number(IntegralNumber(UnsignedNumber([\"1\"]))))), Nullary(PrimaryLiteral(Number(IntegralNumber(UnsignedNumber([\"2\"])))))], part_select_range: None } })))"
);
assert_eq!(
format!("{:?}", all_consuming(variable_lvalue)("a[1][10:5]")),
"Ok((\"\", Identifier(VariableLvalueIdentifier { scope: None, identifier: HierarchicalIdentifier { hierarchy: [], identifier: Identifier { raw: [\"a\"] } }, select: Select { member: None, bit_select: [Nullary(PrimaryLiteral(Number(IntegralNumber(UnsignedNumber([\"1\"])))))], part_select_range: Some(Range((Nullary(PrimaryLiteral(Number(IntegralNumber(UnsignedNumber([\"10\"]))))), Nullary(PrimaryLiteral(Number(IntegralNumber(UnsignedNumber([\"5\"])))))))) } })))"
);
assert_eq!(
format!("{:?}", all_consuming(variable_lvalue)("{a, b[1], c}")),
"Ok((\"\", Lvalue([Identifier(VariableLvalueIdentifier { scope: None, identifier: HierarchicalIdentifier { hierarchy: [], identifier: Identifier { raw: [\"a\"] } }, select: Select { member: None, bit_select: [], part_select_range: None } }), Identifier(VariableLvalueIdentifier { scope: None, identifier: HierarchicalIdentifier { hierarchy: [], identifier: Identifier { raw: [\"b\"] } }, select: Select { member: None, bit_select: [Nullary(PrimaryLiteral(Number(IntegralNumber(UnsignedNumber([\"1\"])))))], part_select_range: None } }), Identifier(VariableLvalueIdentifier { scope: None, identifier: HierarchicalIdentifier { hierarchy: [], identifier: Identifier { raw: [\"c\"] } }, select: Select { member: None, bit_select: [], part_select_range: None } })])))"
);
assert_eq!(
format!("{:?}", all_consuming(nonrange_variable_lvalue)("a")),
"Ok((\"\", NonrangeVariableLvalue { scope: None, identifier: HierarchicalIdentifier { hierarchy: [], identifier: Identifier { raw: [\"a\"] } }, select: Select { member: None, bit_select: [], part_select_range: None } }))"
);
assert_eq!(
format!("{:?}", all_consuming(nonrange_variable_lvalue)("a[1][2]")),
"Ok((\"\", NonrangeVariableLvalue { scope: None, identifier: HierarchicalIdentifier { hierarchy: [], identifier: Identifier { raw: [\"a\"] } }, select: Select { member: None, bit_select: [Nullary(PrimaryLiteral(Number(IntegralNumber(UnsignedNumber([\"1\"]))))), Nullary(PrimaryLiteral(Number(IntegralNumber(UnsignedNumber([\"2\"])))))], part_select_range: None } }))"
);
}
} }

View File

@ -1,6 +1,8 @@
use crate::expressions::*;
use crate::identifiers::*; use crate::identifiers::*;
use crate::numbers::*; use crate::numbers::*;
use crate::strings::*; use crate::strings::*;
use crate::subroutine_calls::*;
use crate::util::*; use crate::util::*;
use nom::branch::*; use nom::branch::*;
use nom::bytes::complete::*; use nom::bytes::complete::*;
@ -21,7 +23,7 @@ pub enum ConstantPrimary<'a> {
Enum(ConstantPrimaryEnum<'a>), Enum(ConstantPrimaryEnum<'a>),
Concatenation(ConstantPrimaryConcatenation<'a>), Concatenation(ConstantPrimaryConcatenation<'a>),
MultipleConcatenation(ConstantPrimaryMultipleConcatenation<'a>), MultipleConcatenation(ConstantPrimaryMultipleConcatenation<'a>),
FunctionCall(ConstantFunctionCall<'a>), FunctionCall(SubroutineCall<'a>),
LetExpression(LetExpression<'a>), LetExpression(LetExpression<'a>),
MintypmaxExpression(ConstantMintypmaxExpression<'a>), MintypmaxExpression(ConstantMintypmaxExpression<'a>),
Cast(ConstantCast<'a>), Cast(ConstantCast<'a>),
@ -72,7 +74,7 @@ pub enum ModulePathPrimary<'a> {
Identifier(Identifier<'a>), Identifier(Identifier<'a>),
ModulePathConcatenation(ModulePathConcatenation<'a>), ModulePathConcatenation(ModulePathConcatenation<'a>),
ModulePathMultipleConcatenation(ModulePathMultipleConcatenation<'a>), ModulePathMultipleConcatenation(ModulePathMultipleConcatenation<'a>),
FunctionSubroutineCall(FunctionSubroutineCall<'a>), FunctionSubroutineCall(SubroutineCall<'a>),
ModulePathMintypmaxExpression(ModulePathMintypmaxExpression<'a>), ModulePathMintypmaxExpression(ModulePathMintypmaxExpression<'a>),
} }
@ -83,7 +85,7 @@ pub enum Primary<'a> {
EmptyUnpackedArrayConcatenation(EmptyUnpackedArrayConcatenation<'a>), EmptyUnpackedArrayConcatenation(EmptyUnpackedArrayConcatenation<'a>),
Concatenation(PrimaryConcatenation<'a>), Concatenation(PrimaryConcatenation<'a>),
MultipleConcatenation(PrimaryMultipleConcatenation<'a>), MultipleConcatenation(PrimaryMultipleConcatenation<'a>),
FunctionSubroutineCall(FunctionSubroutineCall<'a>), FunctionSubroutineCall(SubroutineCall<'a>),
LetExpression(LetExpression<'a>), LetExpression(LetExpression<'a>),
MintypmaxExpression(MintypmaxExpression<'a>), MintypmaxExpression(MintypmaxExpression<'a>),
Cast(Cast<'a>), Cast(Cast<'a>),
@ -178,20 +180,20 @@ pub struct FixedPointTimeLiteral<'a> {
#[derive(Debug)] #[derive(Debug)]
pub struct Select<'a> { pub struct Select<'a> {
member: Option<SelectMember<'a>>, member: Option<SelectMember<'a>>,
bit_select: Expression<'a>, bit_select: Vec<Expression<'a>>,
part_select_range: Option<PartSelectRange<'a>>, part_select_range: Option<PartSelectRange<'a>>,
} }
#[derive(Debug)] #[derive(Debug)]
pub struct ConstantSelect<'a> { pub struct ConstantSelect<'a> {
member: Option<SelectMember<'a>>, member: Option<SelectMember<'a>>,
bit_select: ConstantExpression<'a>, bit_select: Vec<ConstantExpression<'a>>,
part_select_range: Option<ConstantPartSelectRange<'a>>, part_select_range: Option<ConstantPartSelectRange<'a>>,
} }
#[derive(Debug)] #[derive(Debug)]
pub struct SelectMember<'a> { pub struct SelectMember<'a> {
upper: Vec<(Identifier<'a>, Expression<'a>)>, upper: Vec<(Identifier<'a>, Vec<Expression<'a>>)>,
identifier: Identifier<'a>, identifier: Identifier<'a>,
} }
@ -224,6 +226,10 @@ pub fn constant_primary(s: &str) -> IResult<&str, ConstantPrimary> {
map(constant_let_expression, |x| { map(constant_let_expression, |x| {
ConstantPrimary::LetExpression(x) ConstantPrimary::LetExpression(x)
}), }),
map(
delimited(tag("("), sp(constant_mintypmax_expression), sp(tag(")"))),
|x| ConstantPrimary::MintypmaxExpression(x),
),
map(constant_cast, |x| ConstantPrimary::Cast(x)), map(constant_cast, |x| ConstantPrimary::Cast(x)),
map(constant_assignment_pattern_expression, |x| { map(constant_assignment_pattern_expression, |x| {
ConstantPrimary::AssignmentPatternExpression(x) ConstantPrimary::AssignmentPatternExpression(x)
@ -331,9 +337,6 @@ pub fn module_path_primary(s: &str) -> IResult<&str, ModulePathPrimary> {
pub fn primary(s: &str) -> IResult<&str, Primary> { pub fn primary(s: &str) -> IResult<&str, Primary> {
alt(( alt((
map(tag("this"), |_| Primary::This),
map(tag("$"), |_| Primary::Dollar),
map(tag("null"), |_| Primary::Null),
map(primary_literal, |x| Primary::PrimaryLiteral(x)), map(primary_literal, |x| Primary::PrimaryLiteral(x)),
primary_hierarchical, primary_hierarchical,
map(empty_unpacked_array_concatenation, |x| { map(empty_unpacked_array_concatenation, |x| {
@ -356,6 +359,9 @@ pub fn primary(s: &str) -> IResult<&str, Primary> {
Primary::StreamingConcatenation(x) Primary::StreamingConcatenation(x)
}), }),
map(sequence_method_call, |x| Primary::SequenceMethodCall(x)), map(sequence_method_call, |x| Primary::SequenceMethodCall(x)),
map(tag("this"), |_| Primary::This),
map(tag("$"), |_| Primary::Dollar),
map(tag("null"), |_| Primary::Null),
))(s) ))(s)
} }
@ -411,8 +417,8 @@ pub fn primary_hierarchical_qualifier(s: &str) -> IResult<&str, PrimaryHierarchi
pub fn class_qualifier(s: &str) -> IResult<&str, ClassQualifier> { pub fn class_qualifier(s: &str) -> IResult<&str, ClassQualifier> {
let (s, local) = opt(tag("local::"))(s)?; let (s, local) = opt(tag("local::"))(s)?;
let (s, scope) = opt(alt(( let (s, scope) = opt(alt((
terminated(implicit_class_handle, sp(tag("."))), terminated(sp(implicit_class_handle), sp(tag("."))),
class_scope, sp(class_scope),
)))(s)?; )))(s)?;
Ok(( Ok((
s, s,
@ -486,17 +492,17 @@ pub fn time_unit(s: &str) -> IResult<&str, TimeUnit> {
pub fn implicit_class_handle(s: &str) -> IResult<&str, Scope> { pub fn implicit_class_handle(s: &str) -> IResult<&str, Scope> {
let (s, x) = alt(( let (s, x) = alt((
map(tag("this"), |_| ImplicitClassHandle::This),
map(tag("super"), |_| ImplicitClassHandle::Super),
map(tuple((tag("this"), sp(tag(".")), sp(tag("super")))), |_| { map(tuple((tag("this"), sp(tag(".")), sp(tag("super")))), |_| {
ImplicitClassHandle::ThisSuper ImplicitClassHandle::ThisSuper
}), }),
map(tag("this"), |_| ImplicitClassHandle::This),
map(tag("super"), |_| ImplicitClassHandle::Super),
))(s)?; ))(s)?;
Ok((s, Scope::ImplicitClassHandle(x))) Ok((s, Scope::ImplicitClassHandle(x)))
} }
pub fn bit_select(s: &str) -> IResult<&str, Expression> { pub fn bit_select(s: &str) -> IResult<&str, Vec<Expression>> {
delimited(tag("["), sp(expression), sp(tag("]")))(s) many0(delimited(sp(tag("[")), sp(expression), sp(tag("]"))))(s)
} }
pub fn select(s: &str) -> IResult<&str, Select> { pub fn select(s: &str) -> IResult<&str, Select> {
@ -508,7 +514,8 @@ pub fn select(s: &str) -> IResult<&str, Select> {
preceded(sp(tag(".")), sp(member_identifier)), preceded(sp(tag(".")), sp(member_identifier)),
))(s)?; ))(s)?;
let (s, bit_select) = sp(bit_select)(s)?; let (s, bit_select) = sp(bit_select)(s)?;
let (s, part_select_range) = opt(sp(part_select_range))(s)?; let (s, part_select_range) =
opt(delimited(sp(tag("[")), sp(part_select_range), sp(tag("]"))))(s)?;
let member = if let Some((upper, identifier)) = member { let member = if let Some((upper, identifier)) = member {
Some(SelectMember { upper, identifier }) Some(SelectMember { upper, identifier })
@ -552,8 +559,12 @@ pub fn nonrange_select(s: &str) -> IResult<&str, Select> {
)) ))
} }
pub fn constant_bit_select(s: &str) -> IResult<&str, ConstantExpression> { pub fn constant_bit_select(s: &str) -> IResult<&str, Vec<ConstantExpression>> {
delimited(tag("["), sp(constant_expression), sp(tag("]")))(s) many0(delimited(
sp(tag("[")),
sp(constant_expression),
sp(tag("]")),
))(s)
} }
pub fn constant_select(s: &str) -> IResult<&str, ConstantSelect> { pub fn constant_select(s: &str) -> IResult<&str, ConstantSelect> {
@ -565,7 +576,11 @@ pub fn constant_select(s: &str) -> IResult<&str, ConstantSelect> {
preceded(sp(tag(".")), sp(member_identifier)), preceded(sp(tag(".")), sp(member_identifier)),
))(s)?; ))(s)?;
let (s, bit_select) = sp(constant_bit_select)(s)?; let (s, bit_select) = sp(constant_bit_select)(s)?;
let (s, part_select_range) = opt(sp(constant_part_select_range))(s)?; let (s, part_select_range) = opt(delimited(
sp(tag("[")),
sp(constant_part_select_range),
sp(tag("]")),
))(s)?;
let member = if let Some((upper, identifier)) = member { let member = if let Some((upper, identifier)) = member {
Some(SelectMember { upper, identifier }) Some(SelectMember { upper, identifier })
@ -629,17 +644,21 @@ mod tests {
format!("{:?}", all_consuming(primary)("\"aaa\"")), format!("{:?}", all_consuming(primary)("\"aaa\"")),
"Ok((\"\", PrimaryLiteral(StringLiteral(StringLiteral { raw: [\"aaa\"] }))))" "Ok((\"\", PrimaryLiteral(StringLiteral(StringLiteral { raw: [\"aaa\"] }))))"
); );
//assert_eq!(
// format!("{:?}", all_consuming(primary)("this")),
// "Ok((\"\", This))"
//);
//assert_eq!(
// format!("{:?}", all_consuming(primary)("$")),
// "Ok((\"\", Dollar))"
//);
//assert_eq!(
// format!("{:?}", all_consuming(primary)("null")),
// "Ok((\"\", Null))"
//);
assert_eq!( assert_eq!(
format!("{:?}", all_consuming(primary)("this")), format!("{:?}", all_consuming(primary)("this . super.a")),
"Ok((\"\", This))" "Ok((\"\", Hierarchical(PrimaryHierarchical { qualifier: Some(ClassQualifier(ClassQualifier { local: false, scope: Some(ImplicitClassHandle(ThisSuper)) })), identifier: HierarchicalIdentifier { hierarchy: [], identifier: Identifier { raw: [\"a\"] } }, select: Select { member: None, bit_select: [], part_select_range: None } })))"
);
assert_eq!(
format!("{:?}", all_consuming(primary)("$")),
"Ok((\"\", Dollar))"
);
assert_eq!(
format!("{:?}", all_consuming(primary)("null")),
"Ok((\"\", Null))"
); );
assert_eq!( assert_eq!(
format!("{:?}", all_consuming(module_path_primary)("10")), format!("{:?}", all_consuming(module_path_primary)("10")),

325
src/subroutine_calls.rs Normal file
View File

@ -0,0 +1,325 @@
use crate::attributes::*;
use crate::expressions::*;
use crate::identifiers::*;
use crate::primaries::*;
use crate::util::*;
use nom::branch::*;
use nom::bytes::complete::*;
use nom::combinator::*;
use nom::multi::*;
use nom::sequence::*;
use nom::IResult;
// -----------------------------------------------------------------------------
#[derive(Debug)]
pub struct TfCall<'a> {
pub identifier: ScopedIdentifier<'a>,
pub attribute: Vec<AttributeInstance<'a>>,
pub argument: Option<ListOfArguments<'a>>,
}
#[derive(Debug)]
pub struct SystemTfCall<'a> {
pub identifier: Identifier<'a>,
pub argument: Option<ListOfArguments<'a>>,
pub data_type: Option<DataType<'a>>,
pub expression: Option<Vec<Expression<'a>>>,
pub clocking_event: Option<ClockingEvent<'a>>,
}
#[derive(Debug)]
pub enum SubroutineCall<'a> {
Tf(Box<TfCall<'a>>),
SystemTf(Box<SystemTfCall<'a>>),
Method(Box<MethodCall<'a>>),
Randomize(Box<RandomizeCall<'a>>),
StdRandomize(Box<RandomizeCall<'a>>),
}
#[derive(Debug)]
pub struct ListOfArguments<'a> {
pub unnamed: Vec<Expression<'a>>,
pub named: Vec<(Identifier<'a>, Option<Expression<'a>>)>,
}
#[derive(Debug)]
pub struct MethodCall<'a> {
pub root: MethodCallRoot<'a>,
pub body: MethodCallBody<'a>,
}
#[derive(Debug)]
pub enum MethodCallRoot<'a> {
Primary(Primary<'a>),
ImplicitClassHandle(Scope<'a>),
}
#[derive(Debug)]
pub enum MethodCallBody<'a> {
User(MethodCallBodyUser<'a>),
Array(ArrayManipulationCall<'a>),
Randomize(RandomizeCall<'a>),
}
#[derive(Debug)]
pub struct MethodCallBodyUser<'a> {
pub identifier: Identifier<'a>,
pub attribute: Vec<AttributeInstance<'a>>,
pub argument: Option<ListOfArguments<'a>>,
}
#[derive(Debug)]
pub struct ArrayManipulationCall<'a> {
pub name: ArrayMethodName<'a>,
pub attribute: Vec<AttributeInstance<'a>>,
pub argument: Option<ListOfArguments<'a>>,
pub with: Option<Expression<'a>>,
}
#[derive(Debug)]
pub struct RandomizeCall<'a> {
pub attribute: Vec<AttributeInstance<'a>>,
pub argument: Vec<Identifier<'a>>,
pub with: Vec<Identifier<'a>>,
pub constraint_block: Option<ConstraintBlock<'a>>,
}
#[derive(Debug)]
pub enum ArrayMethodName<'a> {
Identifier(Identifier<'a>),
Unique,
And,
Or,
Xor,
}
// -----------------------------------------------------------------------------
pub fn constant_function_call(s: &str) -> IResult<&str, SubroutineCall> {
function_subroutine_call(s)
}
pub fn tf_call(s: &str) -> IResult<&str, TfCall> {
let (s, identifier) = ps_or_hierarchical_tf_identifier(s)?;
let (s, attribute) = many0(sp(attribute_instance))(s)?;
let (s, argument) = opt(delimited(sp(tag("(")), sp(list_of_arguments), sp(tag(")"))))(s)?;
Ok((
s,
TfCall {
identifier,
attribute,
argument,
},
))
}
pub fn system_tf_call(s: &str) -> IResult<&str, SystemTfCall> {
alt((
system_tf_call_list_of_arguments,
system_tf_call_data_type,
system_tf_call_clocking_event,
))(s)
}
pub fn system_tf_call_list_of_arguments(s: &str) -> IResult<&str, SystemTfCall> {
let (s, identifier) = system_tf_identifier(s)?;
let (s, argument) = opt(delimited(sp(tag("(")), sp(list_of_arguments), sp(tag(")"))))(s)?;
Ok((
s,
SystemTfCall {
identifier,
argument,
data_type: None,
expression: None,
clocking_event: None,
},
))
}
pub fn system_tf_call_data_type(s: &str) -> IResult<&str, SystemTfCall> {
let (s, identifier) = system_tf_identifier(s)?;
let (s, _) = sp(tag("("))(s)?;
let (s, data_type) = sp(data_type)(s)?;
let (s, expression) = sp(preceded(sp(tag(",")), expression))(s)?;
let (s, _) = sp(tag(")"))(s)?;
let data_type = Some(data_type);
let expression = Some(vec![expression]);
Ok((
s,
SystemTfCall {
identifier,
argument: None,
data_type,
expression,
clocking_event: None,
},
))
}
pub fn system_tf_call_clocking_event(s: &str) -> IResult<&str, SystemTfCall> {
let (s, identifier) = system_tf_identifier(s)?;
let (s, _) = sp(tag("("))(s)?;
let (s, expression) = separated_nonempty_list(sp(tag(",")), sp(expression))(s)?;
let (s, clocking_event) = opt(preceded(sp(tag(",")), opt(sp(clocking_event))))(s)?;
let (s, _) = sp(tag(")"))(s)?;
let expression = Some(expression);
let clocking_event = if let Some(Some(x)) = clocking_event {
Some(x)
} else {
None
};
Ok((
s,
SystemTfCall {
identifier,
argument: None,
data_type: None,
expression,
clocking_event,
},
))
}
pub fn subroutine_call(s: &str) -> IResult<&str, SubroutineCall> {
alt((
map(tf_call, |x| SubroutineCall::Tf(Box::new(x))),
map(system_tf_call, |x| SubroutineCall::SystemTf(Box::new(x))),
map(method_call, |x| SubroutineCall::Method(Box::new(x))),
map(
tuple((tag("std"), sp(tag("::")), randomize_call)),
|(_, _, x)| SubroutineCall::StdRandomize(Box::new(x)),
),
map(randomize_call, |x| SubroutineCall::Randomize(Box::new(x))),
))(s)
}
pub fn function_subroutine_call(s: &str) -> IResult<&str, SubroutineCall> {
subroutine_call(s)
}
pub fn list_of_arguments(s: &str) -> IResult<&str, ListOfArguments> {
let (s, unnamed) = separated_list(sp(tag(",")), sp(expression))(s)?;
let (s, named) = separated_list(
sp(tag(",")),
pair(
preceded(tag("."), identifier),
delimited(sp(tag("(")), opt(sp(expression)), sp(tag(")"))),
),
)(s)?;
Ok((s, ListOfArguments { unnamed, named }))
}
pub fn method_call(s: &str) -> IResult<&str, MethodCall> {
let (s, root) = method_call_root(s)?;
let (s, _) = sp(tag("."))(s)?;
let (s, body) = method_call_body(s)?;
Ok((s, MethodCall { root, body }))
}
pub fn method_call_body(s: &str) -> IResult<&str, MethodCallBody> {
alt((method_call_body_user, built_in_method_call))(s)
}
pub fn method_call_body_user(s: &str) -> IResult<&str, MethodCallBody> {
let (s, identifier) = method_identifier(s)?;
let (s, attribute) = many0(sp(attribute_instance))(s)?;
let (s, argument) = opt(delimited(sp(tag("(")), sp(list_of_arguments), sp(tag(")"))))(s)?;
Ok((
s,
MethodCallBody::User(MethodCallBodyUser {
identifier,
attribute,
argument,
}),
))
}
pub fn built_in_method_call(s: &str) -> IResult<&str, MethodCallBody> {
alt((
map(array_manipulation_call, |x| MethodCallBody::Array(x)),
map(randomize_call, |x| MethodCallBody::Randomize(x)),
))(s)
}
pub fn array_manipulation_call(s: &str) -> IResult<&str, ArrayManipulationCall> {
let (s, name) = array_method_name(s)?;
let (s, attribute) = many0(sp(attribute_instance))(s)?;
let (s, argument) = opt(delimited(sp(tag("(")), sp(list_of_arguments), sp(tag(")"))))(s)?;
let (s, with) = opt(preceded(
sp(tag("with")),
delimited(sp(tag("(")), sp(expression), sp(tag(")"))),
))(s)?;
Ok((
s,
ArrayManipulationCall {
name,
attribute,
argument,
with,
},
))
}
pub fn randomize_call(s: &str) -> IResult<&str, RandomizeCall> {
let (s, _) = tag("randomize")(s)?;
let (s, attribute) = many0(sp(attribute_instance))(s)?;
let (s, argument) = opt(delimited(
sp(tag("(")),
opt(alt((
sp(variable_identifier_list),
map(sp(tag("null")), |_| vec![]),
))),
sp(tag(")")),
))(s)?;
let (s, with) = opt(tuple((
sp(tag("with")),
opt(delimited(
sp(tag("(")),
opt(sp(identifier_list)),
sp(tag(")")),
)),
constraint_block,
)))(s)?;
let argument = if let Some(Some(x)) = argument {
x
} else {
vec![]
};
let (with, constraint_block) = if let Some((_, Some(Some(x)), y)) = with {
(x, Some(y))
} else {
(vec![], None)
};
Ok((
s,
RandomizeCall {
attribute,
argument,
with,
constraint_block,
},
))
}
pub fn method_call_root(s: &str) -> IResult<&str, MethodCallRoot> {
alt((
map(primary, |x| MethodCallRoot::Primary(x)),
map(implicit_class_handle, |x| {
MethodCallRoot::ImplicitClassHandle(x)
}),
))(s)
}
pub fn array_method_name(s: &str) -> IResult<&str, ArrayMethodName> {
alt((
map(tag("unique"), |_| ArrayMethodName::Unique),
map(tag("and"), |_| ArrayMethodName::And),
map(tag("or"), |_| ArrayMethodName::Or),
map(tag("xor"), |_| ArrayMethodName::Xor),
map(method_identifier, |x| ArrayMethodName::Identifier(x)),
))(s)
}
// -----------------------------------------------------------------------------

View File

@ -17,16 +17,6 @@ where
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#[derive(Debug)]
pub struct ConstantExpression<'a> {
pub raw: Vec<&'a str>,
}
#[derive(Debug)]
pub struct ConstantRangeExpression<'a> {
pub raw: Vec<&'a str>,
}
#[derive(Debug)] #[derive(Debug)]
pub struct Concatenation<'a> { pub struct Concatenation<'a> {
pub raw: Vec<&'a str>, pub raw: Vec<&'a str>,
@ -37,26 +27,11 @@ pub struct MultipleConcatenation<'a> {
pub raw: Vec<&'a str>, pub raw: Vec<&'a str>,
} }
#[derive(Debug)]
pub struct ConstantFunctionCall<'a> {
pub raw: Vec<&'a str>,
}
#[derive(Debug)] #[derive(Debug)]
pub struct ConstantLetExpression<'a> { pub struct ConstantLetExpression<'a> {
pub raw: Vec<&'a str>, pub raw: Vec<&'a str>,
} }
#[derive(Debug)]
pub struct ConstantMintypmaxExpression<'a> {
pub raw: Vec<&'a str>,
}
#[derive(Debug)]
pub struct Expression<'a> {
pub raw: Vec<&'a str>,
}
#[derive(Debug)] #[derive(Debug)]
pub struct CastingType<'a> { pub struct CastingType<'a> {
pub raw: Vec<&'a str>, pub raw: Vec<&'a str>,
@ -87,36 +62,11 @@ pub struct ModulePathMultipleConcatenation<'a> {
pub raw: Vec<&'a str>, pub raw: Vec<&'a str>,
} }
#[derive(Debug)]
pub struct FunctionSubroutineCall<'a> {
pub raw: Vec<&'a str>,
}
#[derive(Debug)]
pub struct ModulePathMintypmaxExpression<'a> {
pub raw: Vec<&'a str>,
}
#[derive(Debug)]
pub struct PartSelectRange<'a> {
pub raw: Vec<&'a str>,
}
#[derive(Debug)]
pub struct ConstantPartSelectRange<'a> {
pub raw: Vec<&'a str>,
}
#[derive(Debug)] #[derive(Debug)]
pub struct EmptyUnpackedArrayConcatenation<'a> { pub struct EmptyUnpackedArrayConcatenation<'a> {
pub raw: Vec<&'a str>, pub raw: Vec<&'a str>,
} }
#[derive(Debug)]
pub struct MintypmaxExpression<'a> {
pub raw: Vec<&'a str>,
}
#[derive(Debug)] #[derive(Debug)]
pub struct AssignmentPatternExpression<'a> { pub struct AssignmentPatternExpression<'a> {
pub raw: Vec<&'a str>, pub raw: Vec<&'a str>,
@ -147,18 +97,40 @@ pub struct AssignmentPatternVariableLvalue<'a> {
pub raw: Vec<&'a str>, pub raw: Vec<&'a str>,
} }
#[derive(Debug)]
pub struct CondPredicate<'a> {
pub raw: Vec<&'a str>,
}
#[derive(Debug)]
pub struct DataType<'a> {
pub raw: Vec<&'a str>,
}
#[derive(Debug)]
pub struct OperatorAssignment<'a> {
pub raw: Vec<&'a str>,
}
#[derive(Debug)]
pub struct OpenRangeList<'a> {
pub raw: Vec<&'a str>,
}
#[derive(Debug)]
pub struct ClockingEvent<'a> {
pub raw: Vec<&'a str>,
}
#[derive(Debug)]
pub struct ConstraintBlock<'a> {
pub raw: Vec<&'a str>,
}
pub fn class_scope(s: &str) -> IResult<&str, Scope> { pub fn class_scope(s: &str) -> IResult<&str, Scope> {
Ok((s, Scope::ClassScope)) Ok((s, Scope::ClassScope))
} }
pub fn constant_expression(s: &str) -> IResult<&str, ConstantExpression> {
Ok((s, ConstantExpression { raw: vec![] }))
}
pub fn constant_range_expression(s: &str) -> IResult<&str, ConstantRangeExpression> {
Ok((s, ConstantRangeExpression { raw: vec![] }))
}
pub fn constant_concatenation(s: &str) -> IResult<&str, Concatenation> { pub fn constant_concatenation(s: &str) -> IResult<&str, Concatenation> {
Ok((s, Concatenation { raw: vec![] })) Ok((s, Concatenation { raw: vec![] }))
} }
@ -167,22 +139,10 @@ pub fn constant_multiple_concatenation(s: &str) -> IResult<&str, MultipleConcate
Ok((s, MultipleConcatenation { raw: vec![] })) Ok((s, MultipleConcatenation { raw: vec![] }))
} }
pub fn constant_function_call(s: &str) -> IResult<&str, ConstantFunctionCall> {
Ok((s, ConstantFunctionCall { raw: vec![] }))
}
pub fn constant_let_expression(s: &str) -> IResult<&str, ConstantLetExpression> { pub fn constant_let_expression(s: &str) -> IResult<&str, ConstantLetExpression> {
Ok((s, ConstantLetExpression { raw: vec![] })) Ok((s, ConstantLetExpression { raw: vec![] }))
} }
pub fn constant_mintypmax_expression(s: &str) -> IResult<&str, ConstantMintypmaxExpression> {
Ok((s, ConstantMintypmaxExpression { raw: vec![] }))
}
pub fn expression(s: &str) -> IResult<&str, Expression> {
Ok((s, Expression { raw: vec![] }))
}
pub fn casting_type(s: &str) -> IResult<&str, CastingType> { pub fn casting_type(s: &str) -> IResult<&str, CastingType> {
Ok((s, CastingType { raw: vec![] })) Ok((s, CastingType { raw: vec![] }))
} }
@ -211,22 +171,6 @@ pub fn module_path_multiple_concatenation(
Ok((s, ModulePathMultipleConcatenation { raw: vec![] })) Ok((s, ModulePathMultipleConcatenation { raw: vec![] }))
} }
pub fn function_subroutine_call(s: &str) -> IResult<&str, FunctionSubroutineCall> {
Ok((s, FunctionSubroutineCall { raw: vec![] }))
}
pub fn module_path_mintypmax_expression(s: &str) -> IResult<&str, ModulePathMintypmaxExpression> {
Ok((s, ModulePathMintypmaxExpression { raw: vec![] }))
}
pub fn part_select_range(s: &str) -> IResult<&str, PartSelectRange> {
Ok((s, PartSelectRange { raw: vec![] }))
}
pub fn constant_part_select_range(s: &str) -> IResult<&str, ConstantPartSelectRange> {
Ok((s, ConstantPartSelectRange { raw: vec![] }))
}
pub fn empty_unpacked_array_concatenation( pub fn empty_unpacked_array_concatenation(
s: &str, s: &str,
) -> IResult<&str, EmptyUnpackedArrayConcatenation> { ) -> IResult<&str, EmptyUnpackedArrayConcatenation> {
@ -241,10 +185,6 @@ pub fn multiple_concatenation(s: &str) -> IResult<&str, MultipleConcatenation> {
Ok((s, MultipleConcatenation { raw: vec![] })) Ok((s, MultipleConcatenation { raw: vec![] }))
} }
pub fn mintypmax_expression(s: &str) -> IResult<&str, MintypmaxExpression> {
Ok((s, MintypmaxExpression { raw: vec![] }))
}
pub fn assignment_pattern_expression(s: &str) -> IResult<&str, AssignmentPatternExpression> { pub fn assignment_pattern_expression(s: &str) -> IResult<&str, AssignmentPatternExpression> {
Ok((s, AssignmentPatternExpression { raw: vec![] })) Ok((s, AssignmentPatternExpression { raw: vec![] }))
} }
@ -272,3 +212,35 @@ pub fn assignment_pattern_variable_lvalue(
) -> IResult<&str, AssignmentPatternVariableLvalue> { ) -> IResult<&str, AssignmentPatternVariableLvalue> {
Ok((s, AssignmentPatternVariableLvalue { raw: vec![] })) Ok((s, AssignmentPatternVariableLvalue { raw: vec![] }))
} }
pub fn cond_predicate(s: &str) -> IResult<&str, CondPredicate> {
Ok((s, CondPredicate { raw: vec![] }))
}
pub fn data_type(s: &str) -> IResult<&str, DataType> {
Ok((s, DataType { raw: vec![] }))
}
pub fn operator_assignment(s: &str) -> IResult<&str, OperatorAssignment> {
Ok((s, OperatorAssignment { raw: vec![] }))
}
pub fn open_range_list(s: &str) -> IResult<&str, OpenRangeList> {
Ok((s, OpenRangeList { raw: vec![] }))
}
pub fn clocking_event(s: &str) -> IResult<&str, ClockingEvent> {
Ok((s, ClockingEvent { raw: vec![] }))
}
pub fn constraint_block(s: &str) -> IResult<&str, ConstraintBlock> {
Ok((s, ConstraintBlock { raw: vec![] }))
}
pub fn variable_identifier_list(s: &str) -> IResult<&str, Vec<Identifier>> {
Ok((s, vec![]))
}
pub fn identifier_list(s: &str) -> IResult<&str, Vec<Identifier>> {
Ok((s, vec![]))
}