diff --git a/src/attributes.rs b/src/attributes.rs index 985f1e5..416681b 100644 --- a/src/attributes.rs +++ b/src/attributes.rs @@ -1,3 +1,4 @@ +use crate::expressions::*; use crate::identifiers::*; use crate::util::*; 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 }] }))" ); - // TODO after constant_expression - //assert_eq!( - // format!( - // "{:?}", - // all_consuming(attribute_instance)("(* full_case=1 *)") - // ), - // "" - //); + assert_eq!( + format!( + "{:?}", + 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\"])))))) }] }))" + ); } } diff --git a/src/expressions.rs b/src/expressions.rs new file mode 100644 index 0000000..1cbc4f1 --- /dev/null +++ b/src/expressions.rs @@ -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>, + pub lvalue: VariableLvalue<'a>, +} + +#[derive(Debug)] +pub struct IncOrDecExpressionSuffix<'a> { + pub lvalue: VariableLvalue<'a>, + pub attribute: Vec>, + pub operator: Operator<'a>, +} + +#[derive(Debug)] +pub struct ConditionalExpression<'a> { + pub predicate: CondPredicate<'a>, + pub attribute: Vec>, + pub arg0: Expression<'a>, + pub arg1: Expression<'a>, +} + +#[derive(Debug)] +pub enum ConstantExpression<'a> { + Nullary(Box>), + Unary(Box>), + Binary(Box>), + Ternary(Box>), +} + +#[derive(Debug)] +pub struct ConstantExpressionUnary<'a> { + pub operator: Operator<'a>, + pub attribute: Vec>, + pub arg0: ConstantPrimary<'a>, +} + +#[derive(Debug)] +pub struct ConstantExpressionBinary<'a> { + pub arg0: ConstantExpression<'a>, + pub operator: Operator<'a>, + pub attribute: Vec>, + pub arg1: ConstantExpression<'a>, +} + +#[derive(Debug)] +pub struct ConstantExpressionTernary<'a> { + pub predicate: ConstantExpression<'a>, + pub attribute: Vec>, + 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>), + Unary(Box>), + IncOrDec(Box>), + Assignment(Box>), + Binary(Box>), + Conditional(Box>), + Inside(Box>), + TaggedUnion(Box>), +} + +#[derive(Debug)] +pub struct ExpressionUnary<'a> { + pub operator: Operator<'a>, + pub attribute: Vec>, + pub arg0: Primary<'a>, +} + +#[derive(Debug)] +pub struct ExpressionBinary<'a> { + pub arg0: Expression<'a>, + pub operator: Operator<'a>, + pub attribute: Vec>, + pub arg1: Expression<'a>, +} + +#[derive(Debug)] +pub struct TaggedUnionExpression<'a> { + pub identifier: Identifier<'a>, + pub expression: Option>, +} + +#[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>, + pub arg0: ModulePathExpression<'a>, + pub arg1: ModulePathExpression<'a>, +} + +#[derive(Debug)] +pub enum ModulePathExpression<'a> { + Nullary(Box>), + Unary(Box>), + Binary(Box>), + Conditional(Box>), +} + +#[derive(Debug)] +pub struct ModulePathExpressionUnary<'a> { + pub operator: Operator<'a>, + pub attribute: Vec>, + pub arg0: ModulePathPrimary<'a>, +} + +#[derive(Debug)] +pub struct ModulePathExpressionBinary<'a> { + pub arg0: ModulePathExpression<'a>, + pub operator: Operator<'a>, + pub attribute: Vec>, + 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)") + // ), + // "" + //); + } +} diff --git a/src/identifiers.rs b/src/identifiers.rs index c1fecf6..15bde82 100644 --- a/src/identifiers.rs +++ b/src/identifiers.rs @@ -1,3 +1,4 @@ +use crate::expressions::*; use crate::primaries::*; use crate::util::*; use nom::branch::*; @@ -57,7 +58,7 @@ impl<'a> From> for HierarchicalIdentifier<'a> { #[derive(Debug)] pub struct Hierarchy<'a> { pub identifier: Identifier<'a>, - pub constant_bit_select: Option>, + pub constant_bit_select: Option>>, } // ----------------------------------------------------------------------------- diff --git a/src/lib.rs b/src/lib.rs index 4b23b31..14e759b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,9 +1,11 @@ pub mod attributes; pub mod comments; +pub mod expressions; pub mod identifiers; pub mod lvalues; pub mod numbers; pub mod operators; pub mod primaries; pub mod strings; +pub mod subroutine_calls; pub mod util; diff --git a/src/lvalues.rs b/src/lvalues.rs index 581a7f0..e7cb211 100644 --- a/src/lvalues.rs +++ b/src/lvalues.rs @@ -169,5 +169,46 @@ mod tests { use super::*; #[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 } }))" + ); + } } diff --git a/src/primaries.rs b/src/primaries.rs index 637506b..8980d63 100644 --- a/src/primaries.rs +++ b/src/primaries.rs @@ -1,6 +1,8 @@ +use crate::expressions::*; use crate::identifiers::*; use crate::numbers::*; use crate::strings::*; +use crate::subroutine_calls::*; use crate::util::*; use nom::branch::*; use nom::bytes::complete::*; @@ -21,7 +23,7 @@ pub enum ConstantPrimary<'a> { Enum(ConstantPrimaryEnum<'a>), Concatenation(ConstantPrimaryConcatenation<'a>), MultipleConcatenation(ConstantPrimaryMultipleConcatenation<'a>), - FunctionCall(ConstantFunctionCall<'a>), + FunctionCall(SubroutineCall<'a>), LetExpression(LetExpression<'a>), MintypmaxExpression(ConstantMintypmaxExpression<'a>), Cast(ConstantCast<'a>), @@ -72,7 +74,7 @@ pub enum ModulePathPrimary<'a> { Identifier(Identifier<'a>), ModulePathConcatenation(ModulePathConcatenation<'a>), ModulePathMultipleConcatenation(ModulePathMultipleConcatenation<'a>), - FunctionSubroutineCall(FunctionSubroutineCall<'a>), + FunctionSubroutineCall(SubroutineCall<'a>), ModulePathMintypmaxExpression(ModulePathMintypmaxExpression<'a>), } @@ -83,7 +85,7 @@ pub enum Primary<'a> { EmptyUnpackedArrayConcatenation(EmptyUnpackedArrayConcatenation<'a>), Concatenation(PrimaryConcatenation<'a>), MultipleConcatenation(PrimaryMultipleConcatenation<'a>), - FunctionSubroutineCall(FunctionSubroutineCall<'a>), + FunctionSubroutineCall(SubroutineCall<'a>), LetExpression(LetExpression<'a>), MintypmaxExpression(MintypmaxExpression<'a>), Cast(Cast<'a>), @@ -178,20 +180,20 @@ pub struct FixedPointTimeLiteral<'a> { #[derive(Debug)] pub struct Select<'a> { member: Option>, - bit_select: Expression<'a>, + bit_select: Vec>, part_select_range: Option>, } #[derive(Debug)] pub struct ConstantSelect<'a> { member: Option>, - bit_select: ConstantExpression<'a>, + bit_select: Vec>, part_select_range: Option>, } #[derive(Debug)] pub struct SelectMember<'a> { - upper: Vec<(Identifier<'a>, Expression<'a>)>, + upper: Vec<(Identifier<'a>, Vec>)>, identifier: Identifier<'a>, } @@ -224,6 +226,10 @@ pub fn constant_primary(s: &str) -> IResult<&str, ConstantPrimary> { map(constant_let_expression, |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_assignment_pattern_expression, |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> { alt(( - map(tag("this"), |_| Primary::This), - map(tag("$"), |_| Primary::Dollar), - map(tag("null"), |_| Primary::Null), map(primary_literal, |x| Primary::PrimaryLiteral(x)), primary_hierarchical, map(empty_unpacked_array_concatenation, |x| { @@ -356,6 +359,9 @@ pub fn primary(s: &str) -> IResult<&str, Primary> { Primary::StreamingConcatenation(x) }), map(sequence_method_call, |x| Primary::SequenceMethodCall(x)), + map(tag("this"), |_| Primary::This), + map(tag("$"), |_| Primary::Dollar), + map(tag("null"), |_| Primary::Null), ))(s) } @@ -411,8 +417,8 @@ pub fn primary_hierarchical_qualifier(s: &str) -> IResult<&str, PrimaryHierarchi pub fn class_qualifier(s: &str) -> IResult<&str, ClassQualifier> { let (s, local) = opt(tag("local::"))(s)?; let (s, scope) = opt(alt(( - terminated(implicit_class_handle, sp(tag("."))), - class_scope, + terminated(sp(implicit_class_handle), sp(tag("."))), + sp(class_scope), )))(s)?; Ok(( s, @@ -486,17 +492,17 @@ pub fn time_unit(s: &str) -> IResult<&str, TimeUnit> { pub fn implicit_class_handle(s: &str) -> IResult<&str, Scope> { let (s, x) = alt(( - map(tag("this"), |_| ImplicitClassHandle::This), - map(tag("super"), |_| ImplicitClassHandle::Super), map(tuple((tag("this"), sp(tag(".")), sp(tag("super")))), |_| { ImplicitClassHandle::ThisSuper }), + map(tag("this"), |_| ImplicitClassHandle::This), + map(tag("super"), |_| ImplicitClassHandle::Super), ))(s)?; Ok((s, Scope::ImplicitClassHandle(x))) } -pub fn bit_select(s: &str) -> IResult<&str, Expression> { - delimited(tag("["), sp(expression), sp(tag("]")))(s) +pub fn bit_select(s: &str) -> IResult<&str, Vec> { + many0(delimited(sp(tag("[")), sp(expression), sp(tag("]"))))(s) } 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)), ))(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 { 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> { - delimited(tag("["), sp(constant_expression), sp(tag("]")))(s) +pub fn constant_bit_select(s: &str) -> IResult<&str, Vec> { + many0(delimited( + sp(tag("[")), + sp(constant_expression), + sp(tag("]")), + ))(s) } 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)), ))(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 { Some(SelectMember { upper, identifier }) @@ -629,17 +644,21 @@ mod tests { format!("{:?}", all_consuming(primary)("\"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!( - format!("{:?}", all_consuming(primary)("this")), - "Ok((\"\", This))" - ); - assert_eq!( - format!("{:?}", all_consuming(primary)("$")), - "Ok((\"\", Dollar))" - ); - assert_eq!( - format!("{:?}", all_consuming(primary)("null")), - "Ok((\"\", Null))" + format!("{:?}", all_consuming(primary)("this . super.a")), + "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(module_path_primary)("10")), diff --git a/src/subroutine_calls.rs b/src/subroutine_calls.rs new file mode 100644 index 0000000..a831a72 --- /dev/null +++ b/src/subroutine_calls.rs @@ -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>, + pub argument: Option>, +} + +#[derive(Debug)] +pub struct SystemTfCall<'a> { + pub identifier: Identifier<'a>, + pub argument: Option>, + pub data_type: Option>, + pub expression: Option>>, + pub clocking_event: Option>, +} + +#[derive(Debug)] +pub enum SubroutineCall<'a> { + Tf(Box>), + SystemTf(Box>), + Method(Box>), + Randomize(Box>), + StdRandomize(Box>), +} + +#[derive(Debug)] +pub struct ListOfArguments<'a> { + pub unnamed: Vec>, + pub named: Vec<(Identifier<'a>, Option>)>, +} + +#[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>, + pub argument: Option>, +} + +#[derive(Debug)] +pub struct ArrayManipulationCall<'a> { + pub name: ArrayMethodName<'a>, + pub attribute: Vec>, + pub argument: Option>, + pub with: Option>, +} + +#[derive(Debug)] +pub struct RandomizeCall<'a> { + pub attribute: Vec>, + pub argument: Vec>, + pub with: Vec>, + pub constraint_block: Option>, +} + +#[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) +} + +// ----------------------------------------------------------------------------- diff --git a/src/util.rs b/src/util.rs index 33a24e5..6f65fd5 100644 --- a/src/util.rs +++ b/src/util.rs @@ -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)] pub struct Concatenation<'a> { pub raw: Vec<&'a str>, @@ -37,26 +27,11 @@ pub struct MultipleConcatenation<'a> { pub raw: Vec<&'a str>, } -#[derive(Debug)] -pub struct ConstantFunctionCall<'a> { - pub raw: Vec<&'a str>, -} - #[derive(Debug)] pub struct ConstantLetExpression<'a> { 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)] pub struct CastingType<'a> { pub raw: Vec<&'a str>, @@ -87,36 +62,11 @@ pub struct ModulePathMultipleConcatenation<'a> { 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)] pub struct EmptyUnpackedArrayConcatenation<'a> { pub raw: Vec<&'a str>, } -#[derive(Debug)] -pub struct MintypmaxExpression<'a> { - pub raw: Vec<&'a str>, -} - #[derive(Debug)] pub struct AssignmentPatternExpression<'a> { pub raw: Vec<&'a str>, @@ -147,18 +97,40 @@ pub struct AssignmentPatternVariableLvalue<'a> { 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> { 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> { Ok((s, Concatenation { raw: vec![] })) } @@ -167,22 +139,10 @@ pub fn constant_multiple_concatenation(s: &str) -> IResult<&str, MultipleConcate 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> { 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> { Ok((s, CastingType { raw: vec![] })) } @@ -211,22 +171,6 @@ pub fn module_path_multiple_concatenation( 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( s: &str, ) -> IResult<&str, EmptyUnpackedArrayConcatenation> { @@ -241,10 +185,6 @@ pub fn multiple_concatenation(s: &str) -> IResult<&str, MultipleConcatenation> { 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> { Ok((s, AssignmentPatternExpression { raw: vec![] })) } @@ -272,3 +212,35 @@ pub fn assignment_pattern_variable_lvalue( ) -> IResult<&str, AssignmentPatternVariableLvalue> { 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> { + Ok((s, vec![])) +} + +pub fn identifier_list(s: &str) -> IResult<&str, Vec> { + Ok((s, vec![])) +}