diff --git a/README.md b/README.md index 8efcbe0..385a7fe 100644 --- a/README.md +++ b/README.md @@ -15,27 +15,27 @@ A parser library for System Verilog. | source_text | checker_items | | | | | source_text | class_items | | | | | source_text | constraints | | | | -| source_text | package_items | | | | +| source_text | package_items | x | x | | | declaration | module_parameter_declarations | x | x | | | declaration | port_declarations | x | x | | | declaration | type_declarations | x | x | | -| declaration | net_and_variable_types | | | | +| declaration | net_and_variable_types | x | | | | declaration | strengths | x | x | x | | declaration | delays | x | x | | -| declaration | declaration_lists | | | | -| declaration | declaration_assignments | | | | -| declaration | declaration_ranges | | | | -| declaration | function_declarations | | | | -| declaration | task_declarations | | | | +| declaration | declaration_lists | x | | | +| declaration | declaration_assignments | x | | | +| declaration | declaration_ranges | x | | | +| declaration | function_declarations | x | | | +| declaration | task_declarations | x | | | | declaration | block_item_declarations | x | x | | -| declaration | interface_declarations | | | | -| declaration | assertion_declarations | | | | +| declaration | interface_declarations | x | | | +| declaration | assertion_declarations | x | | | | declaration | covergroup_declarations | | | | | declaration | let_declarations | | | | -| primitive_instance | primitive_instantiation_and_instances | | | | -| primitive_instance | primitive_strengths | | | | -| primitive_instance | primitive_terminals | | | | -| primitive_instance | primitive_gate_and_switch_types | | | | +| primitive_instance | primitive_instantiation_and_instances | x | x | | +| primitive_instance | primitive_strengths | x | x | x | +| primitive_instance | primitive_terminals | x | x | | +| primitive_instance | primitive_gate_and_switch_types | x | x | x | | instantiations | module_instantiation | x | x | | | instantiations | interface_instantiation | x | x | | | instantiations | program_instantiation | x | x | | diff --git a/src/ast/any_node.rs b/src/ast/any_node.rs index 2f6b4e3..a25a163 100644 --- a/src/ast/any_node.rs +++ b/src/ast/any_node.rs @@ -67,70 +67,118 @@ where } } -impl<'a, T: 'a, U: 'a> From<&'a (T, U)> for AnyNodes<'a> +impl<'a, T0: 'a, T1: 'a> From<&'a (T0, T1)> for AnyNodes<'a> where - &'a T: Into>, - &'a U: Into>, + &'a T0: Into>, + &'a T1: Into>, { - fn from(x: &'a (T, U)) -> Self { + fn from(x: &'a (T0, T1)) -> Self { let mut ret = Vec::new(); - let (t, u) = x; - ret.append(&mut t.into().0); - ret.append(&mut u.into().0); + let (t0, t1) = x; + ret.append(&mut t0.into().0); + ret.append(&mut t1.into().0); ret.into() } } -impl<'a, T: 'a, U: 'a, V: 'a> From<&'a (T, U, V)> for AnyNodes<'a> +impl<'a, T0: 'a, T1: 'a, T2: 'a> From<&'a (T0, T1, T2)> for AnyNodes<'a> where - &'a T: Into>, - &'a U: Into>, - &'a V: Into>, + &'a T0: Into>, + &'a T1: Into>, + &'a T2: Into>, { - fn from(x: &'a (T, U, V)) -> Self { + fn from(x: &'a (T0, T1, T2)) -> Self { let mut ret = Vec::new(); - let (t, u, v) = x; - ret.append(&mut t.into().0); - ret.append(&mut u.into().0); - ret.append(&mut v.into().0); + let (t0, t1, t2) = x; + ret.append(&mut t0.into().0); + ret.append(&mut t1.into().0); + ret.append(&mut t2.into().0); ret.into() } } -impl<'a, T: 'a, U: 'a, V: 'a, W: 'a> From<&'a (T, U, V, W)> for AnyNodes<'a> +impl<'a, T0: 'a, T1: 'a, T2: 'a, T3: 'a> From<&'a (T0, T1, T2, T3)> for AnyNodes<'a> where - &'a T: Into>, - &'a U: Into>, - &'a V: Into>, - &'a W: Into>, + &'a T0: Into>, + &'a T1: Into>, + &'a T2: Into>, + &'a T3: Into>, { - fn from(x: &'a (T, U, V, W)) -> Self { + fn from(x: &'a (T0, T1, T2, T3)) -> Self { let mut ret = Vec::new(); - let (t, u, v, w) = x; - ret.append(&mut t.into().0); - ret.append(&mut u.into().0); - ret.append(&mut v.into().0); - ret.append(&mut w.into().0); + let (t0, t1, t2, t3) = x; + ret.append(&mut t0.into().0); + ret.append(&mut t1.into().0); + ret.append(&mut t2.into().0); + ret.append(&mut t3.into().0); ret.into() } } -impl<'a, T: 'a, U: 'a, V: 'a, W: 'a, S: 'a> From<&'a (T, U, V, W, S)> for AnyNodes<'a> +impl<'a, T0: 'a, T1: 'a, T2: 'a, T3: 'a, T4: 'a> From<&'a (T0, T1, T2, T3, T4)> for AnyNodes<'a> where - &'a T: Into>, - &'a U: Into>, - &'a V: Into>, - &'a W: Into>, - &'a S: Into>, + &'a T0: Into>, + &'a T1: Into>, + &'a T2: Into>, + &'a T3: Into>, + &'a T4: Into>, { - fn from(x: &'a (T, U, V, W, S)) -> Self { + fn from(x: &'a (T0, T1, T2, T3, T4)) -> Self { let mut ret = Vec::new(); - let (t, u, v, w, s) = x; - ret.append(&mut t.into().0); - ret.append(&mut u.into().0); - ret.append(&mut v.into().0); - ret.append(&mut w.into().0); - ret.append(&mut s.into().0); + let (t0, t1, t2, t3, t4) = x; + ret.append(&mut t0.into().0); + ret.append(&mut t1.into().0); + ret.append(&mut t2.into().0); + ret.append(&mut t3.into().0); + ret.append(&mut t4.into().0); + ret.into() + } +} + +impl<'a, T0: 'a, T1: 'a, T2: 'a, T3: 'a, T4: 'a, T5: 'a> From<&'a (T0, T1, T2, T3, T4, T5)> + for AnyNodes<'a> +where + &'a T0: Into>, + &'a T1: Into>, + &'a T2: Into>, + &'a T3: Into>, + &'a T4: Into>, + &'a T5: Into>, +{ + fn from(x: &'a (T0, T1, T2, T3, T4, T5)) -> Self { + let mut ret = Vec::new(); + let (t0, t1, t2, t3, t4, t5) = x; + ret.append(&mut t0.into().0); + ret.append(&mut t1.into().0); + ret.append(&mut t2.into().0); + ret.append(&mut t3.into().0); + ret.append(&mut t4.into().0); + ret.append(&mut t5.into().0); + ret.into() + } +} + +impl<'a, T0: 'a, T1: 'a, T2: 'a, T3: 'a, T4: 'a, T5: 'a, T6: 'a> + From<&'a (T0, T1, T2, T3, T4, T5, T6)> for AnyNodes<'a> +where + &'a T0: Into>, + &'a T1: Into>, + &'a T2: Into>, + &'a T3: Into>, + &'a T4: Into>, + &'a T5: Into>, + &'a T6: Into>, +{ + fn from(x: &'a (T0, T1, T2, T3, T4, T5, T6)) -> Self { + let mut ret = Vec::new(); + let (t0, t1, t2, t3, t4, t5, t6) = x; + ret.append(&mut t0.into().0); + ret.append(&mut t1.into().0); + ret.append(&mut t2.into().0); + ret.append(&mut t3.into().0); + ret.append(&mut t4.into().0); + ret.append(&mut t5.into().0); + ret.append(&mut t6.into().0); ret.into() } } diff --git a/src/parser/declarations/assertion_declarations.rs b/src/parser/declarations/assertion_declarations.rs index 4aa4a28..efbc638 100644 --- a/src/parser/declarations/assertion_declarations.rs +++ b/src/parser/declarations/assertion_declarations.rs @@ -15,7 +15,10 @@ pub enum ConcurrentAssertionItem<'a> { #[derive(Debug, Node)] pub struct ConcurrentAssertionItemStatement<'a> { - pub nodes: (Identifier<'a>, ConcurrentAssertionStatement<'a>), + pub nodes: ( + Option<(BlockIdentifier<'a>, Symbol<'a>)>, + ConcurrentAssertionStatement<'a>, + ), } #[derive(Debug, Node)] @@ -29,42 +32,77 @@ pub enum ConcurrentAssertionStatement<'a> { #[derive(Debug, Node)] pub struct AssertPropertyStatement<'a> { - pub nodes: (PropertySpec<'a>, ActionBlock<'a>), + pub nodes: ( + Symbol<'a>, + Symbol<'a>, + Paren<'a, PropertySpec<'a>>, + ActionBlock<'a>, + ), } #[derive(Debug, Node)] pub struct AssumePropertyStatement<'a> { - pub nodes: (PropertySpec<'a>, ActionBlock<'a>), + pub nodes: ( + Symbol<'a>, + Symbol<'a>, + Paren<'a, PropertySpec<'a>>, + ActionBlock<'a>, + ), } #[derive(Debug, Node)] pub struct CoverPropertyStatement<'a> { - pub nodes: (PropertySpec<'a>, StatementOrNull<'a>), + pub nodes: ( + Symbol<'a>, + Symbol<'a>, + Paren<'a, PropertySpec<'a>>, + StatementOrNull<'a>, + ), } #[derive(Debug, Node)] pub struct ExpectPropertyStatement<'a> { - pub nodes: (PropertySpec<'a>, ActionBlock<'a>), + pub nodes: ( + Symbol<'a>, + Symbol<'a>, + Paren<'a, PropertySpec<'a>>, + ActionBlock<'a>, + ), } #[derive(Debug, Node)] pub struct CoverSequenceStatement<'a> { pub nodes: ( - Option>, - Option>, - SequenceExpr<'a>, + Symbol<'a>, + Symbol<'a>, + Paren< + 'a, + ( + Option>, + Option<(Symbol<'a>, Symbol<'a>, Paren<'a, ExpressionOrDist<'a>>)>, + SequenceExpr<'a>, + ), + >, StatementOrNull<'a>, ), } #[derive(Debug, Node)] pub struct RestrictPropertyStatement<'a> { - pub nodes: (PropertySpec<'a>), + pub nodes: ( + Symbol<'a>, + Symbol<'a>, + Paren<'a, PropertySpec<'a>>, + Symbol<'a>, + ), } #[derive(Debug, Node)] pub struct PropertyInstance<'a> { - pub nodes: (Identifier<'a>, Option>), + pub nodes: ( + PsOrHierarchicalPropertyIdentifier<'a>, + Option>>>, + ), } #[derive(Debug, Node)] @@ -76,14 +114,28 @@ pub enum PropertyListOfArguments<'a> { #[derive(Debug, Node)] pub struct PropertyListOfArgumentsOrdered<'a> { pub nodes: ( - Vec>, - Vec<(Identifier<'a>, Option>)>, + List, Option>>, + Vec<( + Symbol<'a>, + Symbol<'a>, + Identifier<'a>, + Paren<'a, Option>>, + )>, ), } #[derive(Debug, Node)] pub struct PropertyListOfArgumentsNamed<'a> { - pub nodes: (Vec<(Identifier<'a>, Option>)>,), + pub nodes: ( + List< + Symbol<'a>, + ( + Symbol<'a>, + Identifier<'a>, + Paren<'a, Option>>, + ), + >, + ), } #[derive(Debug, Node)] @@ -102,27 +154,32 @@ pub enum AssertionItemDeclaration<'a> { #[derive(Debug, Node)] pub struct PropertyDeclaration<'a> { pub nodes: ( - Identifier<'a>, - Option>, + Symbol<'a>, + PropertyIdentifier<'a>, + Option>>>, + Symbol<'a>, Vec>, PropertySpec<'a>, + Option>, + Symbol<'a>, + Option<(Symbol<'a>, PropertyIdentifier<'a>)>, ), } #[derive(Debug, Node)] pub struct PropertyPortList<'a> { - pub nodes: (Vec>,), + pub nodes: (List, PropertyPortItem<'a>>,), } #[derive(Debug, Node)] pub struct PropertyPortItem<'a> { pub nodes: ( Vec>, - Option>, + Option<(Symbol<'a>, Option>)>, PropertyFormalType<'a>, - Identifier<'a>, + FormalPortIdentifier<'a>, Vec>, - Option>, + Option<(Symbol<'a>, PropertyActualArg<'a>)>, ), } @@ -141,7 +198,7 @@ pub enum PropertyFormalType<'a> { pub struct PropertySpec<'a> { pub nodes: ( Option>, - Option>, + Option<(Symbol<'a>, Symbol<'a>, Paren<'a, ExpressionOrDist<'a>>)>, PropertyExpr<'a>, ), } @@ -158,7 +215,7 @@ pub enum PropertyExpr<'a> { ImplicationOverlapped(Box>), ImplicationNonoverlapped(Box>), If(Box>), - Case(PropertyExprCase<'a>), + Case(Box>), FollowedByOverlapped(Box>), FollowedByNonoverlapped(Box>), Nexttime(Box>), @@ -183,146 +240,189 @@ pub enum PropertyExpr<'a> { #[derive(Debug, Node)] pub struct PropertyExprStrong<'a> { - pub nodes: (SequenceExpr<'a>,), + pub nodes: (Symbol<'a>, Paren<'a, SequenceExpr<'a>>), } #[derive(Debug, Node)] pub struct PropertyExprWeak<'a> { - pub nodes: (SequenceExpr<'a>,), + pub nodes: (Symbol<'a>, Paren<'a, SequenceExpr<'a>>), } #[derive(Debug, Node)] pub struct PropertyExprParen<'a> { - pub nodes: (PropertyExpr<'a>,), + pub nodes: (Paren<'a, SequenceExpr<'a>>,), } #[derive(Debug, Node)] pub struct PropertyExprNot<'a> { - pub nodes: (PropertyExpr<'a>,), + pub nodes: (Symbol<'a>, PropertyExpr<'a>), } #[derive(Debug, Node)] pub struct PropertyExprOr<'a> { - pub nodes: (PropertyExpr<'a>, PropertyExpr<'a>), + pub nodes: (PropertyExpr<'a>, Symbol<'a>, PropertyExpr<'a>), } #[derive(Debug, Node)] pub struct PropertyExprAnd<'a> { - pub nodes: (PropertyExpr<'a>, PropertyExpr<'a>), + pub nodes: (PropertyExpr<'a>, Symbol<'a>, PropertyExpr<'a>), } #[derive(Debug, Node)] pub struct PropertyExprImplicationOverlapped<'a> { - pub nodes: (SequenceExpr<'a>, PropertyExpr<'a>), + pub nodes: (SequenceExpr<'a>, Symbol<'a>, PropertyExpr<'a>), } #[derive(Debug, Node)] pub struct PropertyExprImplicationNonoverlapped<'a> { - pub nodes: (SequenceExpr<'a>, PropertyExpr<'a>), + pub nodes: (SequenceExpr<'a>, Symbol<'a>, PropertyExpr<'a>), } #[derive(Debug, Node)] pub struct PropertyExprIf<'a> { pub nodes: ( - ExpressionOrDist<'a>, + Symbol<'a>, + Paren<'a, ExpressionOrDist<'a>>, PropertyExpr<'a>, - Option>, + Option<(Symbol<'a>, PropertyExpr<'a>)>, ), } #[derive(Debug, Node)] pub struct PropertyExprCase<'a> { - pub nodes: (ExpressionOrDist<'a>, Vec>), + pub nodes: ( + Symbol<'a>, + Paren<'a, ExpressionOrDist<'a>>, + PropertyCaseItem<'a>, + Vec>, + Symbol<'a>, + ), } #[derive(Debug, Node)] pub struct PropertyExprFollowedByOverlapped<'a> { - pub nodes: (SequenceExpr<'a>, PropertyExpr<'a>), + pub nodes: (SequenceExpr<'a>, Symbol<'a>, PropertyExpr<'a>), } #[derive(Debug, Node)] pub struct PropertyExprFollowedByNonoverlapped<'a> { - pub nodes: (SequenceExpr<'a>, PropertyExpr<'a>), + pub nodes: (SequenceExpr<'a>, Symbol<'a>, PropertyExpr<'a>), } #[derive(Debug, Node)] pub struct PropertyExprNexttime<'a> { - pub nodes: (Option>, PropertyExpr<'a>), + pub nodes: ( + Symbol<'a>, + Option>>, + PropertyExpr<'a>, + ), } #[derive(Debug, Node)] pub struct PropertyExprSNexttime<'a> { - pub nodes: (Option>, PropertyExpr<'a>), + pub nodes: ( + Symbol<'a>, + Option>>, + PropertyExpr<'a>, + ), } #[derive(Debug, Node)] pub struct PropertyExprAlways<'a> { - pub nodes: (Option>, PropertyExpr<'a>), + pub nodes: ( + Symbol<'a>, + Option>>, + PropertyExpr<'a>, + ), } #[derive(Debug, Node)] pub struct PropertyExprSAlways<'a> { - pub nodes: (Option>, PropertyExpr<'a>), + pub nodes: ( + Symbol<'a>, + Option>>, + PropertyExpr<'a>, + ), } #[derive(Debug, Node)] pub struct PropertyExprEventually<'a> { - pub nodes: (ConstantRange<'a>, PropertyExpr<'a>), + pub nodes: (Symbol<'a>, Paren<'a, ConstantRange<'a>>, PropertyExpr<'a>), } #[derive(Debug, Node)] pub struct PropertyExprSEventually<'a> { - pub nodes: (Option>, PropertyExpr<'a>), + pub nodes: ( + Symbol<'a>, + Option>>, + PropertyExpr<'a>, + ), } #[derive(Debug, Node)] pub struct PropertyExprUntil<'a> { - pub nodes: (PropertyExpr<'a>, PropertyExpr<'a>), + pub nodes: (PropertyExpr<'a>, Symbol<'a>, PropertyExpr<'a>), } #[derive(Debug, Node)] pub struct PropertyExprSUntil<'a> { - pub nodes: (PropertyExpr<'a>, PropertyExpr<'a>), + pub nodes: (PropertyExpr<'a>, Symbol<'a>, PropertyExpr<'a>), } #[derive(Debug, Node)] pub struct PropertyExprUntilWith<'a> { - pub nodes: (PropertyExpr<'a>, PropertyExpr<'a>), + pub nodes: (PropertyExpr<'a>, Symbol<'a>, PropertyExpr<'a>), } #[derive(Debug, Node)] pub struct PropertyExprSUntilWith<'a> { - pub nodes: (PropertyExpr<'a>, PropertyExpr<'a>), + pub nodes: (PropertyExpr<'a>, Symbol<'a>, PropertyExpr<'a>), } #[derive(Debug, Node)] pub struct PropertyExprImplies<'a> { - pub nodes: (PropertyExpr<'a>, PropertyExpr<'a>), + pub nodes: (PropertyExpr<'a>, Symbol<'a>, PropertyExpr<'a>), } #[derive(Debug, Node)] pub struct PropertyExprIff<'a> { - pub nodes: (PropertyExpr<'a>, PropertyExpr<'a>), + pub nodes: (PropertyExpr<'a>, Symbol<'a>, PropertyExpr<'a>), } #[derive(Debug, Node)] pub struct PropertyExprAcceptOn<'a> { - pub nodes: (ExpressionOrDist<'a>, PropertyExpr<'a>), + pub nodes: ( + Symbol<'a>, + Paren<'a, ExpressionOrDist<'a>>, + PropertyExpr<'a>, + ), } #[derive(Debug, Node)] pub struct PropertyExprRejectOn<'a> { - pub nodes: (ExpressionOrDist<'a>, PropertyExpr<'a>), + pub nodes: ( + Symbol<'a>, + Paren<'a, ExpressionOrDist<'a>>, + PropertyExpr<'a>, + ), } #[derive(Debug, Node)] pub struct PropertyExprSyncAcceptOn<'a> { - pub nodes: (ExpressionOrDist<'a>, PropertyExpr<'a>), + pub nodes: ( + Symbol<'a>, + Paren<'a, ExpressionOrDist<'a>>, + PropertyExpr<'a>, + ), } #[derive(Debug, Node)] pub struct PropertyExprSyncRejectOn<'a> { - pub nodes: (ExpressionOrDist<'a>, PropertyExpr<'a>), + pub nodes: ( + Symbol<'a>, + Paren<'a, ExpressionOrDist<'a>>, + PropertyExpr<'a>, + ), } #[derive(Debug, Node)] @@ -338,39 +438,48 @@ pub enum PropertyCaseItem<'a> { #[derive(Debug, Node)] pub struct PropertyCaseItemNondefault<'a> { - pub nodes: (Vec>, PropertyExpr<'a>), + pub nodes: ( + List, ExpressionOrDist<'a>>, + Symbol<'a>, + PropertyExpr<'a>, + Symbol<'a>, + ), } #[derive(Debug, Node)] pub struct PropertyCaseItemDefault<'a> { - pub nodes: (PropertyExpr<'a>,), + pub nodes: (Symbol<'a>, Option>, PropertyExpr<'a>, Symbol<'a>), } #[derive(Debug, Node)] pub struct SequenceDeclaration<'a> { pub nodes: ( - Identifier<'a>, - Option>, + Symbol<'a>, + SequenceIdentifier<'a>, + Option>>>, + Symbol<'a>, Vec>, SequenceExpr<'a>, - Option>, + Option>, + Symbol<'a>, + Option<(Symbol<'a>, SequenceIdentifier<'a>)>, ), } #[derive(Debug, Node)] pub struct SequencePortList<'a> { - pub nodes: (Vec>,), + pub nodes: (List, SequencePortItem<'a>>,), } #[derive(Debug, Node)] pub struct SequencePortItem<'a> { pub nodes: ( Vec>, - Option>, + Option<(Symbol<'a>, Option>)>, SequenceFormalType<'a>, - Identifier<'a>, + FormalPortIdentifier<'a>, Vec>, - Option>, + Option<(Symbol<'a>, SequenceActualArg<'a>)>, ), } @@ -390,10 +499,10 @@ pub enum SequenceFormalType<'a> { #[derive(Debug, Node)] pub enum SequenceExpr<'a> { - CycleDelayExpr(SequenceExprCycleDelayExpr<'a>), + CycleDelayExpr(Box>), ExprCycleDelayExpr(Box>), Expression(SequenceExprExpression<'a>), - Instance(SequenceExprInstance<'a>), + Instance(Box>), Paren(Box>), And(Box>), Intersect(Box>), @@ -406,12 +515,18 @@ pub enum SequenceExpr<'a> { #[derive(Debug, Node)] pub struct SequenceExprCycleDelayExpr<'a> { - pub nodes: (Vec<(CycleDelayRange<'a>, SequenceExpr<'a>)>,), + pub nodes: ( + CycleDelayRange<'a>, + SequenceExpr<'a>, + Vec<(CycleDelayRange<'a>, SequenceExpr<'a>)>, + ), } #[derive(Debug, Node)] pub struct SequenceExprExprCycleDelayExpr<'a> { pub nodes: ( + SequenceExpr<'a>, + CycleDelayRange<'a>, SequenceExpr<'a>, Vec<(CycleDelayRange<'a>, SequenceExpr<'a>)>, ), @@ -430,40 +545,42 @@ pub struct SequenceExprInstance<'a> { #[derive(Debug, Node)] pub struct SequenceExprParen<'a> { pub nodes: ( - SequenceExpr<'a>, - Vec>, + Paren<'a, (SequenceExpr<'a>, Vec<(Symbol<'a>, SequenceMatchItem<'a>)>)>, Option>, ), } #[derive(Debug, Node)] pub struct SequenceExprAnd<'a> { - pub nodes: (SequenceExpr<'a>, SequenceExpr<'a>), + pub nodes: (SequenceExpr<'a>, Symbol<'a>, SequenceExpr<'a>), } #[derive(Debug, Node)] pub struct SequenceExprIntersect<'a> { - pub nodes: (SequenceExpr<'a>, SequenceExpr<'a>), + pub nodes: (SequenceExpr<'a>, Symbol<'a>, SequenceExpr<'a>), } #[derive(Debug, Node)] pub struct SequenceExprOr<'a> { - pub nodes: (SequenceExpr<'a>, SequenceExpr<'a>), + pub nodes: (SequenceExpr<'a>, Symbol<'a>, SequenceExpr<'a>), } #[derive(Debug, Node)] pub struct SequenceExprFirstMatch<'a> { - pub nodes: (SequenceExpr<'a>, Vec>), + pub nodes: ( + Symbol<'a>, + Paren<'a, (SequenceExpr<'a>, Vec<(Symbol<'a>, SequenceMatchItem<'a>)>)>, + ), } #[derive(Debug, Node)] pub struct SequenceExprThroughout<'a> { - pub nodes: (ExpressionOrDist<'a>, SequenceExpr<'a>), + pub nodes: (ExpressionOrDist<'a>, Symbol<'a>, SequenceExpr<'a>), } #[derive(Debug, Node)] pub struct SequenceExprWithin<'a> { - pub nodes: (SequenceExpr<'a>, SequenceExpr<'a>), + pub nodes: (SequenceExpr<'a>, Symbol<'a>, SequenceExpr<'a>), } #[derive(Debug, Node)] @@ -473,15 +590,35 @@ pub struct SequenceExprClockingEvent<'a> { #[derive(Debug, Node)] pub enum CycleDelayRange<'a> { - ConstantPrimary(ConstantPrimary<'a>), - CycleDelayConstRangeExpression(CycleDelayConstRangeExpression<'a>), - Asterisk(Symbol<'a>), - Plus(Symbol<'a>), + Primary(CycleDelayRangePrimary<'a>), + Expression(CycleDelayRangeExpression<'a>), + Asterisk(CycleDelayRangeAsterisk<'a>), + Plus(CycleDelayRangePlus<'a>), +} + +#[derive(Debug, Node)] +pub struct CycleDelayRangePrimary<'a> { + pub nodes: (Symbol<'a>, ConstantPrimary<'a>), +} + +#[derive(Debug, Node)] +pub struct CycleDelayRangeExpression<'a> { + pub nodes: (Symbol<'a>, Bracket<'a, CycleDelayConstRangeExpression<'a>>), +} + +#[derive(Debug, Node)] +pub struct CycleDelayRangeAsterisk<'a> { + pub nodes: (Symbol<'a>, Bracket<'a, Symbol<'a>>), +} + +#[derive(Debug, Node)] +pub struct CycleDelayRangePlus<'a> { + pub nodes: (Symbol<'a>, Bracket<'a, Symbol<'a>>), } #[derive(Debug, Node)] pub struct SequenceMethodCall<'a> { - pub nodes: (SequenceInstance<'a>, Identifier<'a>), + pub nodes: (SequenceInstance<'a>, Symbol<'a>, MethodIdentifier<'a>), } #[derive(Debug, Node)] @@ -493,7 +630,10 @@ pub enum SequenceMatchItem<'a> { #[derive(Debug, Node)] pub struct SequenceInstance<'a> { - pub nodes: (Identifier<'a>, Option>), + pub nodes: ( + PsOrHierarchicalSequenceIdentifier<'a>, + Option>>>, + ), } #[derive(Debug, Node)] @@ -505,14 +645,28 @@ pub enum SequenceListOfArguments<'a> { #[derive(Debug, Node)] pub struct SequenceListOfArgumentsOrdered<'a> { pub nodes: ( - Vec>, - Vec<(Identifier<'a>, Option>)>, + List, Option>>, + Vec<( + Symbol<'a>, + Symbol<'a>, + Identifier<'a>, + Paren<'a, Option>>, + )>, ), } #[derive(Debug, Node)] pub struct SequenceListOfArgumentsNamed<'a> { - pub nodes: (Vec<(Identifier<'a>, Option>)>,), + pub nodes: ( + List< + Symbol<'a>, + ( + Symbol<'a>, + Identifier<'a>, + Paren<'a, Option>>, + ), + >, + ), } #[derive(Debug, Node)] @@ -535,19 +689,34 @@ pub struct SequenceAbbrev<'a> { #[derive(Debug, Node)] pub enum ConsecutiveRepetition<'a> { - ConstOrRangeExpression(ConstOrRangeExpression<'a>), - Asterisk(Symbol<'a>), - Plus(Symbol<'a>), + Expression(ConsecutiveRepetitionExpression<'a>), + Asterisk(ConsecutiveRepetitionAsterisk<'a>), + Plus(ConsecutiveRepetitionPlus<'a>), +} + +#[derive(Debug, Node)] +pub struct ConsecutiveRepetitionExpression<'a> { + pub nodes: (Bracket<'a, (Symbol<'a>, ConstOrRangeExpression<'a>)>), +} + +#[derive(Debug, Node)] +pub struct ConsecutiveRepetitionAsterisk<'a> { + pub nodes: (Bracket<'a, Symbol<'a>>,), +} + +#[derive(Debug, Node)] +pub struct ConsecutiveRepetitionPlus<'a> { + pub nodes: (Bracket<'a, Symbol<'a>>,), } #[derive(Debug, Node)] pub struct NonConsecutiveRepetition<'a> { - pub nodes: (ConstOrRangeExpression<'a>,), + pub nodes: (Bracket<'a, (Symbol<'a>, ConstOrRangeExpression<'a>)>,), } #[derive(Debug, Node)] pub struct GotoRepetition<'a> { - pub nodes: (ConstOrRangeExpression<'a>,), + pub nodes: (Bracket<'a, (Symbol<'a>, ConstOrRangeExpression<'a>)>,), } #[derive(Debug, Node)] @@ -564,22 +733,29 @@ pub enum CycleDelayConstRangeExpression<'a> { #[derive(Debug, Node)] pub struct CycleDelayConstRangeExpressionBinary<'a> { - pub nodes: (ConstantExpression<'a>, ConstantExpression<'a>), + pub nodes: (ConstantExpression<'a>, Symbol<'a>, ConstantExpression<'a>), } #[derive(Debug, Node)] pub struct CycleDelayConstRangeExpressionDollar<'a> { - pub nodes: (ConstantExpression<'a>,), + pub nodes: (ConstantExpression<'a>, Symbol<'a>, Symbol<'a>), } #[derive(Debug, Node)] pub struct ExpressionOrDist<'a> { - pub nodes: (Expression<'a>, Option>), + pub nodes: ( + Expression<'a>, + Option<(Symbol<'a>, Brace<'a, DistList<'a>>)>, + ), } #[derive(Debug, Node)] pub struct AssertionVariableDeclaration<'a> { - pub nodes: (VarDataType<'a>, ListOfVariableDeclAssignments<'a>), + pub nodes: ( + VarDataType<'a>, + ListOfVariableDeclAssignments<'a>, + Symbol<'a>, + ), } // ----------------------------------------------------------------------------- diff --git a/src/parser/declarations/declaration_assignments.rs b/src/parser/declarations/declaration_assignments.rs index 6a7cc78..646d1a3 100644 --- a/src/parser/declarations/declaration_assignments.rs +++ b/src/parser/declarations/declaration_assignments.rs @@ -9,20 +9,28 @@ use nom::{Err, IResult}; #[derive(Debug, Node)] pub struct DefparamAssignment<'a> { - pub nodes: (HierarchicalIdentifier<'a>, ConstantMintypmaxExpression<'a>), + pub nodes: ( + HierarchicalParameterIdentifier<'a>, + Symbol<'a>, + ConstantMintypmaxExpression<'a>, + ), } #[derive(Debug, Node)] pub struct NetDeclAssignment<'a> { - pub nodes: (Identifier<'a>, Vec>, Expression<'a>), + pub nodes: ( + NetIdentifier<'a>, + Vec>, + Option<(Symbol<'a>, Expression<'a>)>, + ), } #[derive(Debug, Node)] pub struct ParamAssignment<'a> { pub nodes: ( - Identifier<'a>, + ParameterIdentifier<'a>, Vec>, - ConstantParamExpression<'a>, + Option<(Symbol<'a>, ConstantParamExpression<'a>)>, ), } @@ -34,23 +42,54 @@ pub enum SpecparamAssignment<'a> { #[derive(Debug, Node)] pub struct SpecparamAssignmentMintypmax<'a> { - pub nodes: (Identifier<'a>, ConstantMintypmaxExpression<'a>), + pub nodes: ( + SpecparamIdentifier<'a>, + Symbol<'a>, + ConstantMintypmaxExpression<'a>, + ), } #[derive(Debug, Node)] pub struct TypeAssignment<'a> { - pub nodes: (Identifier<'a>, Option>), + pub nodes: (TypeIdentifier<'a>, Option<(Symbol<'a>, DataType<'a>)>), } #[derive(Debug, Node)] -pub struct PulseControlSpecparam<'a> { +pub enum PulseControlSpecparam<'a> { + WithoutDescriptor(PulseControlSpecparamWithoutDescriptor<'a>), + WithDescriptor(PulseControlSpecparamWithDescriptor<'a>), +} + +#[derive(Debug, Node)] +pub struct PulseControlSpecparamWithoutDescriptor<'a> { pub nodes: ( - Option<( - SpecifyInputTerminalDescriptor<'a>, - SpecifyOutputTerminalDescriptor<'a>, - )>, - RejectLimitValue<'a>, - Option>, + Symbol<'a>, + Symbol<'a>, + Paren< + 'a, + ( + RejectLimitValue<'a>, + Option<(Symbol<'a>, ErrorLimitValue<'a>)>, + ), + >, + ), +} + +#[derive(Debug, Node)] +pub struct PulseControlSpecparamWithDescriptor<'a> { + pub nodes: ( + Symbol<'a>, + SpecifyInputTerminalDescriptor<'a>, + Symbol<'a>, + SpecifyOutputTerminalDescriptor<'a>, + Symbol<'a>, + Paren< + 'a, + ( + RejectLimitValue<'a>, + Option<(Symbol<'a>, ErrorLimitValue<'a>)>, + ), + >, ), } @@ -79,41 +118,57 @@ pub enum VariableDeclAssignment<'a> { #[derive(Debug, Node)] pub struct VariableDeclAssignmentVariable<'a> { pub nodes: ( - Identifier<'a>, + VariableIdentifier<'a>, Vec>, - Option>, + Option<(Symbol<'a>, Expression<'a>)>, ), } #[derive(Debug, Node)] pub struct VariableDeclAssignmentDynamicArray<'a> { pub nodes: ( - Identifier<'a>, + DynamicArrayVariableIdentifier<'a>, UnsizedDimension<'a>, Vec>, - Option>, + Option<(Symbol<'a>, DynamicArrayNew<'a>)>, ), } #[derive(Debug, Node)] pub struct VariableDeclAssignmentClass<'a> { - pub nodes: (Identifier<'a>, Option>), + pub nodes: ( + ClassVariableIdentifier<'a>, + Option<(Symbol<'a>, ClassNew<'a>)>, + ), } #[derive(Debug, Node)] pub enum ClassNew<'a> { Argument(ClassNewArgument<'a>), - Expression(Expression<'a>), + Expression(ClassNewExpression<'a>), } #[derive(Debug, Node)] pub struct ClassNewArgument<'a> { - pub nodes: (Option>, Option>), + pub nodes: ( + Option>, + Symbol<'a>, + Option>>, + ), +} + +#[derive(Debug, Node)] +pub struct ClassNewExpression<'a> { + pub nodes: (Symbol<'a>, Expression<'a>), } #[derive(Debug, Node)] pub struct DynamicArrayNew<'a> { - pub nodes: (Expression<'a>, Option>), + pub nodes: ( + Symbol<'a>, + Bracket<'a, Expression<'a>>, + Option>>, + ), } // ----------------------------------------------------------------------------- diff --git a/src/parser/declarations/declaration_lists.rs b/src/parser/declarations/declaration_lists.rs index dd5f574..665dc1f 100644 --- a/src/parser/declarations/declaration_lists.rs +++ b/src/parser/declarations/declaration_lists.rs @@ -9,78 +9,84 @@ use nom::{Err, IResult}; #[derive(Debug, Node)] pub struct ListOfDefparamAssignments<'a> { - pub nodes: (Vec>,), + pub nodes: (List, DefparamAssignment<'a>>,), } #[derive(Debug, Node)] pub struct ListOfGenvarIdentifiers<'a> { - pub nodes: (Vec>,), + pub nodes: (List, GenvarIdentifier<'a>>,), } #[derive(Debug, Node)] pub struct ListOfInterfaceIdentifiers<'a> { - pub nodes: (Vec<(Identifier<'a>, Vec>)>,), + pub nodes: (List, (InterfaceIdentifier<'a>, Vec>)>,), } #[derive(Debug, Node)] pub struct ListOfNetDeclAssignments<'a> { - pub nodes: (Vec>,), + pub nodes: (List, NetDeclAssignment<'a>>,), } #[derive(Debug, Node)] pub struct ListOfParamAssignments<'a> { - pub nodes: (Vec>,), + pub nodes: (List, ParamAssignment<'a>>,), } #[derive(Debug, Node)] pub struct ListOfPortIdentifiers<'a> { - pub nodes: (Vec<(Identifier<'a>, Vec>)>,), + pub nodes: (List, (PortIdentifier<'a>, Vec>)>,), } #[derive(Debug, Node)] pub struct ListOfUdpPortIdentifiers<'a> { - pub nodes: (Vec>,), + pub nodes: (List, PortIdentifier<'a>>,), } #[derive(Debug, Node)] pub struct ListOfSpecparamAssignments<'a> { - pub nodes: (Vec>,), + pub nodes: (List, SpecparamAssignment<'a>>,), } #[derive(Debug, Node)] pub struct ListOfTfVariableIdentifiers<'a> { pub nodes: ( - Vec<( - Identifier<'a>, - Vec>, - Option>, - )>, + List< + Symbol<'a>, + ( + PortIdentifier<'a>, + Vec>, + Option<(Symbol<'a>, Expression<'a>)>, + ), + >, ), } #[derive(Debug, Node)] pub struct ListOfTypeAssignments<'a> { - pub nodes: (Vec>,), + pub nodes: (List, TypeAssignment<'a>>,), } #[derive(Debug, Node)] pub struct ListOfVariableDeclAssignments<'a> { - pub nodes: (Vec>,), + pub nodes: (List, VariableDeclAssignment<'a>>,), } #[derive(Debug, Node)] pub struct ListOfVariableIdentifiers<'a> { - pub nodes: (Vec<(Identifier<'a>, Vec>)>,), + pub nodes: (List, (VariableIdentifier<'a>, Vec>)>,), } #[derive(Debug, Node)] pub struct ListOfVariablePortIdentifiers<'a> { pub nodes: ( - Vec<( - Identifier<'a>, - Vec>, - Option>, - )>, + List< + Symbol<'a>, + ( + PortIdentifier<'a>, + Vec>, + Option<(Symbol<'a>, ConstantExpression<'a>)>, + ), + >, ), } diff --git a/src/parser/declarations/declaration_ranges.rs b/src/parser/declarations/declaration_ranges.rs index 2b6626d..c12790d 100644 --- a/src/parser/declarations/declaration_ranges.rs +++ b/src/parser/declarations/declaration_ranges.rs @@ -9,38 +9,63 @@ use nom::{Err, IResult}; #[derive(Debug, Node)] pub enum UnpackedDimension<'a> { - Range(ConstantRange<'a>), - Expression(ConstantExpression<'a>), + Range(UnpackedDimensionRange<'a>), + Expression(UnpackedDimensionExpression<'a>), +} + +#[derive(Debug, Node)] +pub struct UnpackedDimensionRange<'a> { + pub nodes: (Bracket<'a, ConstantRange<'a>>,), +} + +#[derive(Debug, Node)] +pub struct UnpackedDimensionExpression<'a> { + pub nodes: (Bracket<'a, ConstantExpression<'a>>,), } #[derive(Debug, Node)] pub enum PackedDimension<'a> { - Range(ConstantRange<'a>), + Range(PackedDimensionRange<'a>), Unsized(UnsizedDimension<'a>), } +#[derive(Debug, Node)] +pub struct PackedDimensionRange<'a> { + pub nodes: (Bracket<'a, ConstantRange<'a>>,), +} + #[derive(Debug, Node)] pub enum AssociativeDimension<'a> { - DataType(DataType<'a>), - Asterisk(Symbol<'a>), + DataType(AssociativeDimensionDataType<'a>), + Asterisk(AssociativeDimensionAsterisk<'a>), +} + +#[derive(Debug, Node)] +pub struct AssociativeDimensionDataType<'a> { + pub nodes: (Bracket<'a, DataType<'a>>,), +} + +#[derive(Debug, Node)] +pub struct AssociativeDimensionAsterisk<'a> { + pub nodes: (Bracket<'a, Symbol<'a>>,), } #[derive(Debug, Node)] pub enum VariableDimension<'a> { - Unsized(UnsizedDimension<'a>), - Unpacked(UnpackedDimension<'a>), - Associative(AssociativeDimension<'a>), - Queue(QueueDimension<'a>), + UnsizedDimension(UnsizedDimension<'a>), + UnpackedDimension(UnpackedDimension<'a>), + AssociativeDimension(AssociativeDimension<'a>), + QueueDimension(QueueDimension<'a>), } #[derive(Debug, Node)] pub struct QueueDimension<'a> { - pub nodes: (Option>,), + pub nodes: (Bracket<'a, (Symbol<'a>, Option<(Symbol<'a>, ConstantExpression<'a>)>)>,), } #[derive(Debug, Node)] pub struct UnsizedDimension<'a> { - pub nodes: (Symbol<'a>,), + pub nodes: ((Symbol<'a>, Symbol<'a>),), } // ----------------------------------------------------------------------------- diff --git a/src/parser/declarations/function_declarations.rs b/src/parser/declarations/function_declarations.rs index 6463c42..64b779a 100644 --- a/src/parser/declarations/function_declarations.rs +++ b/src/parser/declarations/function_declarations.rs @@ -9,13 +9,17 @@ use nom::{Err, IResult}; #[derive(Debug, Node)] pub enum FunctionDataTypeOrImplicit<'a> { - DataType(DataTypeOrVoid<'a>), - Implicit(ImplicitDataType<'a>), + DataTypeOrVoid(DataTypeOrVoid<'a>), + ImplicitDataType(ImplicitDataType<'a>), } #[derive(Debug, Node)] pub struct FunctionDeclaration<'a> { - pub nodes: (Option>, FunctionBodyDeclaration<'a>), + pub nodes: ( + Symbol<'a>, + Option>, + FunctionBodyDeclaration<'a>, + ), } #[derive(Debug, Node)] @@ -29,10 +33,12 @@ pub struct FunctionBodyDeclarationWithoutPort<'a> { pub nodes: ( FunctionDataTypeOrImplicit<'a>, Option>, - Identifier<'a>, + FunctionIdentifier<'a>, + Symbol<'a>, Vec>, Vec>, - Option>, + Symbol<'a>, + Option<(Symbol<'a>, FunctionIdentifier<'a>)>, ), } @@ -41,17 +47,24 @@ pub struct FunctionBodyDeclarationWithPort<'a> { pub nodes: ( FunctionDataTypeOrImplicit<'a>, Option>, - Identifier<'a>, - Option>, + FunctionIdentifier<'a>, + Paren<'a, Option>>, + Symbol<'a>, Vec>, Vec>, - Option>, + Symbol<'a>, + Option<(Symbol<'a>, FunctionIdentifier<'a>)>, ), } #[derive(Debug, Node)] pub struct FunctionPrototype<'a> { - pub nodes: (DataTypeOrVoid<'a>, Identifier<'a>, Option>), + pub nodes: ( + Symbol<'a>, + DataTypeOrVoid<'a>, + FunctionIdentifier<'a>, + Option>>>, + ), } #[derive(Debug, Node)] @@ -65,31 +78,47 @@ pub enum DpiImportExport<'a> { #[derive(Debug, Node)] pub struct DpiImportExportImportFunction<'a> { pub nodes: ( + Symbol<'a>, DpiSpecString<'a>, Option>, - Option>, + Option<(CIdentifier<'a>, Symbol<'a>)>, DpiFunctionProto<'a>, + Symbol<'a>, ), } #[derive(Debug, Node)] pub struct DpiImportExportImportTask<'a> { pub nodes: ( + Symbol<'a>, DpiSpecString<'a>, Option>, - Option>, + Option<(CIdentifier<'a>, Symbol<'a>)>, DpiTaskProto<'a>, + Symbol<'a>, ), } #[derive(Debug, Node)] pub struct DpiImportExportExportFunction<'a> { - pub nodes: (DpiSpecString<'a>, Option>, Identifier<'a>), + pub nodes: ( + Symbol<'a>, + DpiSpecString<'a>, + Option<(CIdentifier<'a>, Symbol<'a>)>, + Symbol<'a>, + FunctionIdentifier<'a>, + ), } #[derive(Debug, Node)] pub struct DpiImportExportExportTask<'a> { - pub nodes: (DpiSpecString<'a>, Option>, Identifier<'a>), + pub nodes: ( + Symbol<'a>, + DpiSpecString<'a>, + Option<(CIdentifier<'a>, Symbol<'a>)>, + Symbol<'a>, + TaskIdentifier<'a>, + ), } #[derive(Debug, Node)] diff --git a/src/parser/declarations/interface_declarations.rs b/src/parser/declarations/interface_declarations.rs index 0b1b231..7e53b9d 100644 --- a/src/parser/declarations/interface_declarations.rs +++ b/src/parser/declarations/interface_declarations.rs @@ -9,12 +9,15 @@ use nom::{Err, IResult}; #[derive(Debug, Node)] pub struct ModportDeclaration<'a> { - pub nodes: (Vec>,), + pub nodes: (Symbol<'a>, List, ModportItem<'a>>, Symbol<'a>), } #[derive(Debug, Node)] pub struct ModportItem<'a> { - pub nodes: (Identifier<'a>, Vec>), + pub nodes: ( + ModportIdentifier<'a>, + Paren<'a, List, ModportPortsDeclaraton<'a>>>, + ), } #[derive(Debug, Node)] @@ -44,12 +47,12 @@ pub struct ModportPortsDeclaratonClocking<'a> { #[derive(Debug, Node)] pub struct ModportClockingDeclaration<'a> { - pub nodes: (Identifier<'a>), + pub nodes: (Symbol<'a>, ClockingIdentifier<'a>), } #[derive(Debug, Node)] pub struct ModportSimplePortsDeclaration<'a> { - pub nodes: (PortDirection<'a>, Vec>), + pub nodes: (PortDirection<'a>, List, ModportSimplePort<'a>>), } #[derive(Debug, Node)] @@ -60,23 +63,27 @@ pub enum ModportSimplePort<'a> { #[derive(Debug, Node)] pub struct ModportSimplePortOrdered<'a> { - pub nodes: (Identifier<'a>,), + pub nodes: (PortIdentifier<'a>,), } #[derive(Debug, Node)] pub struct ModportSimplePortNamed<'a> { - pub nodes: (Identifier<'a>, Option>), + pub nodes: ( + Symbol<'a>, + PortIdentifier<'a>, + Paren<'a, Option>>, + ), } #[derive(Debug, Node)] pub struct ModportTfPortsDeclaration<'a> { - pub nodes: (ImportExport<'a>, Vec>), + pub nodes: (ImportExport<'a>, List, ModportTfPort<'a>>), } #[derive(Debug, Node)] pub enum ModportTfPort<'a> { - Prototype(MethodPrototype<'a>), - Identifier(Identifier<'a>), + MethodPrototype(MethodPrototype<'a>), + TfIdentifier(TfIdentifier<'a>), } #[derive(Debug, Node)] diff --git a/src/parser/declarations/net_and_variable_types.rs b/src/parser/declarations/net_and_variable_types.rs index b64b83b..8f4b584 100644 --- a/src/parser/declarations/net_and_variable_types.rs +++ b/src/parser/declarations/net_and_variable_types.rs @@ -21,7 +21,7 @@ pub enum DataType<'a> { Vector(DataTypeVector<'a>), Atom(DataTypeAtom<'a>), NonIntegerType(NonIntegerType<'a>), - Union(DataTypeUnion<'a>), + Union(Box>), Enum(DataTypeEnum<'a>), String(Symbol<'a>), Chandle(Symbol<'a>), @@ -52,7 +52,8 @@ pub struct DataTypeUnion<'a> { pub nodes: ( StructUnion<'a>, Option<(Packed<'a>, Option>)>, - Vec>, + Brace<'a, (StructUnionMember<'a>, Vec>)>, + Vec>, ), } @@ -64,8 +65,9 @@ pub struct Packed<'a> { #[derive(Debug, Node)] pub struct DataTypeEnum<'a> { pub nodes: ( + Symbol<'a>, Option>, - Vec>, + Brace<'a, List, EnumNameDeclaration<'a>>>, Vec>, ), } @@ -73,10 +75,11 @@ pub struct DataTypeEnum<'a> { #[derive(Debug, Node)] pub struct DataTypeVirtual<'a> { pub nodes: ( + Symbol<'a>, Option>, InterfaceIdentifier<'a>, Option>, - Option>, + Option<(Symbol<'a>, ModportIdentifier<'a>)>, ), } @@ -134,30 +137,34 @@ pub struct EnumBaseTypeType<'a> { #[derive(Debug, Node)] pub struct EnumNameDeclaration<'a> { pub nodes: ( - Identifier<'a>, - Option<(IntegralNumber<'a>, Option>)>, - Option>, + EnumIdentifier<'a>, + Option, Option<(Symbol<'a>, IntegralNumber<'a>)>)>>, + Option<(Symbol<'a>, ConstantExpression<'a>)>, ), } #[derive(Debug, Node)] pub struct ClassScope<'a> { - pub nodes: (ClassType<'a>,), + pub nodes: (ClassType<'a>, Symbol<'a>), } #[derive(Debug, Node)] pub struct ClassType<'a> { pub nodes: ( - Identifier<'a>, + PsClassIdentifier<'a>, Option>, - Vec<(Identifier<'a>, Option>)>, + Vec<( + Symbol<'a>, + Identifier<'a>, + Option>, + )>, ), } #[derive(Debug, Node)] pub enum IntegerType<'a> { - Vector(IntegerVectorType<'a>), - Atom(IntegerAtomType<'a>), + IntegerVectorType(IntegerVectorType<'a>), + IntegerAtomType(IntegerAtomType<'a>), } #[derive(Debug, Node)] @@ -203,8 +210,8 @@ pub enum NetType<'a> { #[derive(Debug, Node)] pub enum NetPortType<'a> { DataType(NetPortTypeDataType<'a>), - NetType(Identifier<'a>), - Interconnect(ImplicitDataType<'a>), + NetTypeIdentifier(NetTypeIdentifier<'a>), + Interconnect(NetPortTypeInterconnect<'a>), } #[derive(Debug, Node)] @@ -212,6 +219,11 @@ pub struct NetPortTypeDataType<'a> { pub nodes: (Option>, DataTypeOrImplicit<'a>), } +#[derive(Debug, Node)] +pub struct NetPortTypeInterconnect<'a> { + pub nodes: (Symbol<'a>, ImplicitDataType<'a>), +} + #[derive(Debug, Node)] pub struct VariablePortType<'a> { pub nodes: (VarDataType<'a>,), @@ -220,7 +232,12 @@ pub struct VariablePortType<'a> { #[derive(Debug, Node)] pub enum VarDataType<'a> { DataType(DataType<'a>), - DataTypeOrImplicit(DataTypeOrImplicit<'a>), + Var(VarDataTypeVar<'a>), +} + +#[derive(Debug, Node)] +pub struct VarDataTypeVar<'a> { + pub nodes: (Symbol<'a>, DataTypeOrImplicit<'a>), } #[derive(Debug, Node)] @@ -233,8 +250,8 @@ pub enum Signing<'a> { pub enum SimpleType<'a> { IntegerType(IntegerType<'a>), NonNonIntegerType(IntegerType<'a>), - TypeIdentifier(Identifier<'a>), - ParameterIdentifier(Identifier<'a>), + PsTypeIdentifier(PsTypeIdentifier<'a>), + PsParameterIdentifier(PsParameterIdentifier<'a>), } #[derive(Debug, Node)] @@ -244,6 +261,7 @@ pub struct StructUnionMember<'a> { Option>, DataTypeOrVoid<'a>, ListOfVariableDeclAssignments<'a>, + Symbol<'a>, ), } @@ -257,13 +275,23 @@ pub enum DataTypeOrVoid<'a> { pub enum StructUnion<'a> { Struct(Symbol<'a>), Union(Symbol<'a>), - UnionTagged(Symbol<'a>), + UnionTagged((Symbol<'a>, Symbol<'a>)), } #[derive(Debug, Node)] pub enum TypeReference<'a> { - Expression(Expression<'a>), - DataType(DataType<'a>), + Expression(TypeReferenceExpression<'a>), + DataType(TypeReferenceDataType<'a>), +} + +#[derive(Debug, Node)] +pub struct TypeReferenceExpression<'a> { + pub nodes: (Symbol<'a>, Paren<'a, Expression<'a>>), +} + +#[derive(Debug, Node)] +pub struct TypeReferenceDataType<'a> { + pub nodes: (Symbol<'a>, Paren<'a, DataType<'a>>), } // ----------------------------------------------------------------------------- diff --git a/src/parser/declarations/task_declarations.rs b/src/parser/declarations/task_declarations.rs index bacb6ab..2c5390b 100644 --- a/src/parser/declarations/task_declarations.rs +++ b/src/parser/declarations/task_declarations.rs @@ -9,7 +9,7 @@ use nom::{Err, IResult}; #[derive(Debug, Node)] pub struct TaskDeclaration<'a> { - pub nodes: (Option>, TaskBodyDeclaration<'a>), + pub nodes: (Symbol<'a>, Option>, TaskBodyDeclaration<'a>), } #[derive(Debug, Node)] @@ -22,10 +22,12 @@ pub enum TaskBodyDeclaration<'a> { pub struct TaskBodyDeclarationWithoutPort<'a> { pub nodes: ( Option>, - Identifier<'a>, + TaskIdentifier<'a>, + Symbol<'a>, Vec>, - Vec>, - Option>, + Vec>, + Symbol<'a>, + Option<(Symbol<'a>, TaskIdentifier<'a>)>, ), } @@ -33,29 +35,30 @@ pub struct TaskBodyDeclarationWithoutPort<'a> { pub struct TaskBodyDeclarationWithPort<'a> { pub nodes: ( Option>, - Identifier<'a>, - Option>, + TaskIdentifier<'a>, + Paren<'a, Option>>, + Symbol<'a>, Vec>, - Vec>, - Option>, + Vec>, + Option<(Symbol<'a>, TaskIdentifier<'a>)>, ), } #[derive(Debug, Node)] pub enum InterfaceIdentifierOrClassScope<'a> { - InterfaceIdentifier(InterfaceIdentifier<'a>), + InterfaceIdentifier((InterfaceIdentifier<'a>, Symbol<'a>)), ClassScope(ClassScope<'a>), } #[derive(Debug, Node)] pub enum TfItemDeclaration<'a> { - Block(BlockItemDeclaration<'a>), - Port(TfPortDeclaration<'a>), + BlockItemDeclaration(BlockItemDeclaration<'a>), + TfPortDeclaration(TfPortDeclaration<'a>), } #[derive(Debug, Node)] pub struct TfPortList<'a> { - pub nodes: (Vec>,), + pub nodes: (List, TfPortItem<'a>>,), } #[derive(Debug, Node)] @@ -66,9 +69,9 @@ pub struct TfPortItem<'a> { Option>, DataTypeOrImplicit<'a>, Option<( - Identifier<'a>, + PortIdentifier<'a>, Vec>, - Option>, + Option<(Symbol<'a>, Expression<'a>)>, )>, ), } @@ -76,7 +79,7 @@ pub struct TfPortItem<'a> { #[derive(Debug, Node)] pub enum TfPortDirection<'a> { PortDirection(PortDirection<'a>), - ConstRef(Symbol<'a>), + ConstRef((Symbol<'a>, Symbol<'a>)), } #[derive(Debug, Node)] @@ -87,12 +90,17 @@ pub struct TfPortDeclaration<'a> { Option>, DataTypeOrImplicit<'a>, ListOfTfVariableIdentifiers<'a>, + Symbol<'a>, ), } #[derive(Debug, Node)] pub struct TaskPrototype<'a> { - pub nodes: (Identifier<'a>, Option>), + pub nodes: ( + Symbol<'a>, + TaskIdentifier<'a>, + Option>>>, + ), } // ----------------------------------------------------------------------------- diff --git a/src/parser/primitive_instances/mod.rs b/src/parser/primitive_instances/mod.rs index 4038f47..58ef15f 100644 --- a/src/parser/primitive_instances/mod.rs +++ b/src/parser/primitive_instances/mod.rs @@ -1,2 +1,8 @@ +pub mod primitive_gate_and_switch_types; pub mod primitive_instantiation_and_instances; +pub mod primitive_strengths; +pub mod primitive_terminals; +pub use primitive_gate_and_switch_types::*; pub use primitive_instantiation_and_instances::*; +pub use primitive_strengths::*; +pub use primitive_terminals::*; diff --git a/src/parser/primitive_instances/primitive_gate_and_switch_types.rs b/src/parser/primitive_instances/primitive_gate_and_switch_types.rs new file mode 100644 index 0000000..09275a4 --- /dev/null +++ b/src/parser/primitive_instances/primitive_gate_and_switch_types.rs @@ -0,0 +1,160 @@ +use crate::ast::*; +use crate::parser::*; +use nom::branch::*; +use nom::IResult; + +// ----------------------------------------------------------------------------- + +#[derive(Debug, Node)] +pub struct CmosSwitchtype<'a> { + pub nodes: (Symbol<'a>,), +} + +#[derive(Debug, Node)] +pub struct EnableGatetype<'a> { + pub nodes: (Symbol<'a>,), +} + +#[derive(Debug, Node)] +pub struct MosSwitchtype<'a> { + pub nodes: (Symbol<'a>,), +} + +#[derive(Debug, Node)] +pub struct NInputGatetype<'a> { + pub nodes: (Symbol<'a>,), +} + +#[derive(Debug, Node)] +pub struct NOutputGatetype<'a> { + pub nodes: (Symbol<'a>,), +} + +#[derive(Debug, Node)] +pub struct PassEnSwitchtype<'a> { + pub nodes: (Symbol<'a>,), +} + +#[derive(Debug, Node)] +pub struct PassSwitchtype<'a> { + pub nodes: (Symbol<'a>,), +} + +// ----------------------------------------------------------------------------- + +pub fn cmos_switchtype(s: Span) -> IResult { + let (s, a) = alt((symbol("cmos"), symbol("rcmos")))(s)?; + Ok((s, CmosSwitchtype { nodes: (a,) })) +} + +pub fn enable_gatetype(s: Span) -> IResult { + let (s, a) = alt(( + symbol("bufif0"), + symbol("bufif1"), + symbol("notif0"), + symbol("notif1"), + ))(s)?; + Ok((s, EnableGatetype { nodes: (a,) })) +} + +pub fn mos_switchtype(s: Span) -> IResult { + let (s, a) = alt(( + symbol("nmos"), + symbol("pmos"), + symbol("rnmos"), + symbol("rpmos"), + ))(s)?; + Ok((s, MosSwitchtype { nodes: (a,) })) +} + +pub fn n_input_gatetype(s: Span) -> IResult { + let (s, a) = alt(( + symbol("and"), + symbol("nand"), + symbol("or"), + symbol("nor"), + symbol("xor"), + symbol("xnor"), + ))(s)?; + Ok((s, NInputGatetype { nodes: (a,) })) +} + +pub fn n_output_gatetype(s: Span) -> IResult { + let (s, a) = alt((symbol("buf"), symbol("not")))(s)?; + Ok((s, NOutputGatetype { nodes: (a,) })) +} + +pub fn pass_en_switchtype(s: Span) -> IResult { + let (s, a) = alt(( + symbol("tranif0"), + symbol("tranif1"), + symbol("rtranif0"), + symbol("rtranif1"), + ))(s)?; + Ok((s, PassEnSwitchtype { nodes: (a,) })) +} + +pub fn pass_switchtype(s: Span) -> IResult { + let (s, a) = alt((symbol("tran"), symbol("rtran")))(s)?; + Ok((s, PassSwitchtype { nodes: (a,) })) +} + +// ----------------------------------------------------------------------------- + +#[cfg(test)] +mod tests { + use super::*; + use nom::combinator::*; + + #[test] + fn test_cmos_switchtype() { + parser_test!(cmos_switchtype, "cmos", Ok((_, _))); + parser_test!(cmos_switchtype, "rcmos", Ok((_, _))); + } + + #[test] + fn test_enable_gatetype() { + parser_test!(enable_gatetype, "bufif0", Ok((_, _))); + parser_test!(enable_gatetype, "bufif1", Ok((_, _))); + parser_test!(enable_gatetype, "notif0", Ok((_, _))); + parser_test!(enable_gatetype, "notif1", Ok((_, _))); + } + + #[test] + fn test_mos_switchtype() { + parser_test!(mos_switchtype, "nmos", Ok((_, _))); + parser_test!(mos_switchtype, "pmos", Ok((_, _))); + parser_test!(mos_switchtype, "rnmos", Ok((_, _))); + parser_test!(mos_switchtype, "rpmos", Ok((_, _))); + } + + #[test] + fn test_n_input_gatetype() { + parser_test!(n_input_gatetype, "and", Ok((_, _))); + parser_test!(n_input_gatetype, "nand", Ok((_, _))); + parser_test!(n_input_gatetype, "or", Ok((_, _))); + parser_test!(n_input_gatetype, "nor", Ok((_, _))); + parser_test!(n_input_gatetype, "xor", Ok((_, _))); + parser_test!(n_input_gatetype, "xnor", Ok((_, _))); + } + + #[test] + fn test_n_output_gatetype() { + parser_test!(n_output_gatetype, "buf", Ok((_, _))); + parser_test!(n_output_gatetype, "not", Ok((_, _))); + } + + #[test] + fn test_pass_en_switchtype() { + parser_test!(pass_en_switchtype, "tranif0", Ok((_, _))); + parser_test!(pass_en_switchtype, "tranif1", Ok((_, _))); + parser_test!(pass_en_switchtype, "rtranif0", Ok((_, _))); + parser_test!(pass_en_switchtype, "rtranif1", Ok((_, _))); + } + + #[test] + fn test_pass_switchtype() { + parser_test!(pass_switchtype, "tran", Ok((_, _))); + parser_test!(pass_switchtype, "rtran", Ok((_, _))); + } +} diff --git a/src/parser/primitive_instances/primitive_instantiation_and_instances.rs b/src/parser/primitive_instances/primitive_instantiation_and_instances.rs index ec22f45..f3ca350 100644 --- a/src/parser/primitive_instances/primitive_instantiation_and_instances.rs +++ b/src/parser/primitive_instances/primitive_instantiation_and_instances.rs @@ -1,19 +1,441 @@ use crate::ast::*; use crate::parser::*; -//use nom::branch::*; -//use nom::combinator::*; -use nom::error::*; -use nom::{Err, IResult}; +use nom::branch::*; +use nom::combinator::*; +use nom::sequence::*; +use nom::IResult; // ----------------------------------------------------------------------------- #[derive(Debug, Node)] -pub struct GateInstantiation<'a> { - pub nodes: (Identifier<'a>,), +pub enum GateInstantiation<'a> { + Cmos(GateInstantiationCmos<'a>), + Enable(GateInstantiationEnable<'a>), + Mos(GateInstantiationMos<'a>), + NInput(GateInstantiationNInput<'a>), + NOutput(GateInstantiationNOutput<'a>), + PassEn(GateInstantiationPassEn<'a>), + Pass(GateInstantiationPass<'a>), + Pulldown(GateInstantiationPulldown<'a>), + Pullup(GateInstantiationPullup<'a>), +} + +#[derive(Debug, Node)] +pub struct GateInstantiationCmos<'a> { + pub nodes: ( + CmosSwitchtype<'a>, + Option>, + List, CmosSwitchInstance<'a>>, + Symbol<'a>, + ), +} + +#[derive(Debug, Node)] +pub struct GateInstantiationEnable<'a> { + pub nodes: ( + EnableGatetype<'a>, + Option>, + Option>, + List, EnableGateInstance<'a>>, + Symbol<'a>, + ), +} + +#[derive(Debug, Node)] +pub struct GateInstantiationMos<'a> { + pub nodes: ( + MosSwitchtype<'a>, + Option>, + List, MosSwitchInstance<'a>>, + Symbol<'a>, + ), +} + +#[derive(Debug, Node)] +pub struct GateInstantiationNInput<'a> { + pub nodes: ( + NInputGatetype<'a>, + Option>, + Option>, + List, NInputGateInstance<'a>>, + Symbol<'a>, + ), +} + +#[derive(Debug, Node)] +pub struct GateInstantiationNOutput<'a> { + pub nodes: ( + NOutputGatetype<'a>, + Option>, + Option>, + List, NOutputGateInstance<'a>>, + Symbol<'a>, + ), +} + +#[derive(Debug, Node)] +pub struct GateInstantiationPassEn<'a> { + pub nodes: ( + PassEnSwitchtype<'a>, + Option>, + List, PassEnableSwitchInstance<'a>>, + Symbol<'a>, + ), +} + +#[derive(Debug, Node)] +pub struct GateInstantiationPass<'a> { + pub nodes: ( + PassSwitchtype<'a>, + List, PassSwitchInstance<'a>>, + Symbol<'a>, + ), +} + +#[derive(Debug, Node)] +pub struct GateInstantiationPulldown<'a> { + pub nodes: ( + Symbol<'a>, + Option>, + List, PullGateInstance<'a>>, + Symbol<'a>, + ), +} + +#[derive(Debug, Node)] +pub struct GateInstantiationPullup<'a> { + pub nodes: ( + Symbol<'a>, + Option>, + List, PullGateInstance<'a>>, + Symbol<'a>, + ), +} + +#[derive(Debug, Node)] +pub struct CmosSwitchInstance<'a> { + pub nodes: ( + Option>, + Paren< + 'a, + ( + OutputTerminal<'a>, + Symbol<'a>, + InputTerminal<'a>, + Symbol<'a>, + NcontrolTerminal<'a>, + Symbol<'a>, + PcontrolTerminal<'a>, + ), + >, + ), +} + +#[derive(Debug, Node)] +pub struct EnableGateInstance<'a> { + pub nodes: ( + Option>, + Paren< + 'a, + ( + OutputTerminal<'a>, + Symbol<'a>, + InputTerminal<'a>, + Symbol<'a>, + EnableTerminal<'a>, + ), + >, + ), +} + +#[derive(Debug, Node)] +pub struct MosSwitchInstance<'a> { + pub nodes: ( + Option>, + Paren< + 'a, + ( + OutputTerminal<'a>, + Symbol<'a>, + InputTerminal<'a>, + Symbol<'a>, + EnableTerminal<'a>, + ), + >, + ), +} + +#[derive(Debug, Node)] +pub struct NInputGateInstance<'a> { + pub nodes: ( + Option>, + Paren< + 'a, + ( + OutputTerminal<'a>, + Symbol<'a>, + List, InputTerminal<'a>>, + ), + >, + ), +} + +#[derive(Debug, Node)] +pub struct NOutputGateInstance<'a> { + pub nodes: ( + Option>, + Paren< + 'a, + ( + List, OutputTerminal<'a>>, + Symbol<'a>, + InputTerminal<'a>, + ), + >, + ), +} + +#[derive(Debug, Node)] +pub struct PassSwitchInstance<'a> { + pub nodes: ( + Option>, + Paren<'a, (InoutTerminal<'a>, Symbol<'a>, InoutTerminal<'a>)>, + ), +} + +#[derive(Debug, Node)] +pub struct PassEnableSwitchInstance<'a> { + pub nodes: ( + Option>, + Paren< + 'a, + ( + InoutTerminal<'a>, + Symbol<'a>, + InoutTerminal<'a>, + Symbol<'a>, + EnableTerminal<'a>, + ), + >, + ), +} + +#[derive(Debug, Node)] +pub struct PullGateInstance<'a> { + pub nodes: (Option>, Paren<'a, OutputTerminal<'a>>), } // ----------------------------------------------------------------------------- pub fn gate_instantiation(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + alt(( + gate_instantiation_cmos, + gate_instantiation_enable, + gate_instantiation_mos, + gate_instantiation_n_input, + gate_instantiation_n_output, + gate_instantiation_pass_en, + gate_instantiation_pass, + gate_instantiation_pulldown, + gate_instantiation_pullup, + ))(s) +} + +pub fn gate_instantiation_cmos(s: Span) -> IResult { + let (s, a) = cmos_switchtype(s)?; + let (s, b) = opt(delay3)(s)?; + let (s, c) = list(symbol(","), cmos_switch_instance)(s)?; + let (s, d) = symbol(";")(s)?; + Ok(( + s, + GateInstantiation::Cmos(GateInstantiationCmos { + nodes: (a, b, c, d), + }), + )) +} + +pub fn gate_instantiation_enable(s: Span) -> IResult { + let (s, a) = enable_gatetype(s)?; + let (s, b) = opt(drive_strength)(s)?; + let (s, c) = opt(delay3)(s)?; + let (s, d) = list(symbol(","), enable_gate_instance)(s)?; + let (s, e) = symbol(";")(s)?; + Ok(( + s, + GateInstantiation::Enable(GateInstantiationEnable { + nodes: (a, b, c, d, e), + }), + )) +} + +pub fn gate_instantiation_mos(s: Span) -> IResult { + let (s, a) = mos_switchtype(s)?; + let (s, b) = opt(delay3)(s)?; + let (s, c) = list(symbol(","), mos_switch_instance)(s)?; + let (s, d) = symbol(";")(s)?; + Ok(( + s, + GateInstantiation::Mos(GateInstantiationMos { + nodes: (a, b, c, d), + }), + )) +} + +pub fn gate_instantiation_n_input(s: Span) -> IResult { + let (s, a) = n_input_gatetype(s)?; + let (s, b) = opt(drive_strength)(s)?; + let (s, c) = opt(delay2)(s)?; + let (s, d) = list(symbol(","), n_input_gate_instance)(s)?; + let (s, e) = symbol(";")(s)?; + Ok(( + s, + GateInstantiation::NInput(GateInstantiationNInput { + nodes: (a, b, c, d, e), + }), + )) +} + +pub fn gate_instantiation_n_output(s: Span) -> IResult { + let (s, a) = n_output_gatetype(s)?; + let (s, b) = opt(drive_strength)(s)?; + let (s, c) = opt(delay2)(s)?; + let (s, d) = list(symbol(","), n_output_gate_instance)(s)?; + let (s, e) = symbol(";")(s)?; + Ok(( + s, + GateInstantiation::NOutput(GateInstantiationNOutput { + nodes: (a, b, c, d, e), + }), + )) +} + +pub fn gate_instantiation_pass_en(s: Span) -> IResult { + let (s, a) = pass_en_switchtype(s)?; + let (s, b) = opt(delay2)(s)?; + let (s, c) = list(symbol(","), pass_enable_switch_instance)(s)?; + let (s, d) = symbol(";")(s)?; + Ok(( + s, + GateInstantiation::PassEn(GateInstantiationPassEn { + nodes: (a, b, c, d), + }), + )) +} + +pub fn gate_instantiation_pass(s: Span) -> IResult { + let (s, a) = pass_switchtype(s)?; + let (s, b) = list(symbol(","), pass_switch_instance)(s)?; + let (s, c) = symbol(";")(s)?; + Ok(( + s, + GateInstantiation::Pass(GateInstantiationPass { nodes: (a, b, c) }), + )) +} + +pub fn gate_instantiation_pulldown(s: Span) -> IResult { + let (s, a) = symbol("pulldown")(s)?; + let (s, b) = opt(pulldown_strength)(s)?; + let (s, c) = list(symbol(","), pull_gate_instance)(s)?; + let (s, d) = symbol(";")(s)?; + Ok(( + s, + GateInstantiation::Pulldown(GateInstantiationPulldown { + nodes: (a, b, c, d), + }), + )) +} + +pub fn gate_instantiation_pullup(s: Span) -> IResult { + let (s, a) = symbol("pullup")(s)?; + let (s, b) = opt(pullup_strength)(s)?; + let (s, c) = list(symbol(","), pull_gate_instance)(s)?; + let (s, d) = symbol(";")(s)?; + Ok(( + s, + GateInstantiation::Pullup(GateInstantiationPullup { + nodes: (a, b, c, d), + }), + )) +} + +pub fn cmos_switch_instance(s: Span) -> IResult { + let (s, a) = opt(name_of_instance)(s)?; + let (s, b) = paren(tuple(( + output_terminal, + symbol(","), + input_terminal, + symbol(","), + ncontrol_terminal, + symbol(","), + pcontrol_terminal, + )))(s)?; + Ok((s, CmosSwitchInstance { nodes: (a, b) })) +} + +pub fn enable_gate_instance(s: Span) -> IResult { + let (s, a) = opt(name_of_instance)(s)?; + let (s, b) = paren(tuple(( + output_terminal, + symbol(","), + input_terminal, + symbol(","), + enable_terminal, + )))(s)?; + Ok((s, EnableGateInstance { nodes: (a, b) })) +} + +pub fn mos_switch_instance(s: Span) -> IResult { + let (s, a) = opt(name_of_instance)(s)?; + let (s, b) = paren(tuple(( + output_terminal, + symbol(","), + input_terminal, + symbol(","), + enable_terminal, + )))(s)?; + Ok((s, MosSwitchInstance { nodes: (a, b) })) +} + +pub fn n_input_gate_instance(s: Span) -> IResult { + let (s, a) = opt(name_of_instance)(s)?; + let (s, b) = paren(tuple(( + output_terminal, + symbol(","), + list(symbol(","), input_terminal), + )))(s)?; + Ok((s, NInputGateInstance { nodes: (a, b) })) +} + +pub fn n_output_gate_instance(s: Span) -> IResult { + let (s, a) = opt(name_of_instance)(s)?; + let (s, b) = paren(tuple(( + list(symbol(","), output_terminal), + symbol(","), + input_terminal, + )))(s)?; + Ok((s, NOutputGateInstance { nodes: (a, b) })) +} + +pub fn pass_switch_instance(s: Span) -> IResult { + let (s, a) = opt(name_of_instance)(s)?; + let (s, b) = paren(tuple((inout_terminal, symbol(","), inout_terminal)))(s)?; + Ok((s, PassSwitchInstance { nodes: (a, b) })) +} + +pub fn pass_enable_switch_instance(s: Span) -> IResult { + let (s, a) = opt(name_of_instance)(s)?; + let (s, b) = paren(tuple(( + inout_terminal, + symbol(","), + inout_terminal, + symbol(","), + enable_terminal, + )))(s)?; + Ok((s, PassEnableSwitchInstance { nodes: (a, b) })) +} + +pub fn pull_gate_instance(s: Span) -> IResult { + let (s, a) = opt(name_of_instance)(s)?; + let (s, b) = paren(output_terminal)(s)?; + Ok((s, PullGateInstance { nodes: (a, b) })) } diff --git a/src/parser/primitive_instances/primitive_strengths.rs b/src/parser/primitive_instances/primitive_strengths.rs new file mode 100644 index 0000000..34f4dd1 --- /dev/null +++ b/src/parser/primitive_instances/primitive_strengths.rs @@ -0,0 +1,130 @@ +use crate::ast::*; +use crate::parser::*; +use nom::branch::*; +use nom::IResult; + +// ----------------------------------------------------------------------------- + +#[derive(Debug, Node)] +pub enum PulldownStrength<'a> { + Strength01(PulldownStrength01<'a>), + Strength10(PulldownStrength10<'a>), + Strength0(PulldownStrength0<'a>), +} + +#[derive(Debug, Node)] +pub struct PulldownStrength01<'a> { + pub nodes: (Paren<'a, (Strength0<'a>, Symbol<'a>, Strength1<'a>)>,), +} + +#[derive(Debug, Node)] +pub struct PulldownStrength10<'a> { + pub nodes: (Paren<'a, (Strength1<'a>, Symbol<'a>, Strength0<'a>)>,), +} + +#[derive(Debug, Node)] +pub struct PulldownStrength0<'a> { + pub nodes: (Paren<'a, Strength0<'a>>,), +} + +#[derive(Debug, Node)] +pub enum PullupStrength<'a> { + Strength01(PullupStrength01<'a>), + Strength10(PullupStrength10<'a>), + Strength1(PullupStrength1<'a>), +} + +#[derive(Debug, Node)] +pub struct PullupStrength01<'a> { + pub nodes: (Paren<'a, (Strength0<'a>, Symbol<'a>, Strength1<'a>)>,), +} + +#[derive(Debug, Node)] +pub struct PullupStrength10<'a> { + pub nodes: (Paren<'a, (Strength1<'a>, Symbol<'a>, Strength0<'a>)>,), +} + +#[derive(Debug, Node)] +pub struct PullupStrength1<'a> { + pub nodes: (Paren<'a, Strength1<'a>>,), +} + +// ----------------------------------------------------------------------------- + +pub fn pulldown_strength(s: Span) -> IResult { + alt((pulldown_strength01, pulldown_strength10, pulldown_strength0))(s) +} + +pub fn pulldown_strength01(s: Span) -> IResult { + let (s, a) = paren(triple(strength0, symbol(","), strength1))(s)?; + Ok(( + s, + PulldownStrength::Strength01(PulldownStrength01 { nodes: (a,) }), + )) +} + +pub fn pulldown_strength10(s: Span) -> IResult { + let (s, a) = paren(triple(strength1, symbol(","), strength0))(s)?; + Ok(( + s, + PulldownStrength::Strength10(PulldownStrength10 { nodes: (a,) }), + )) +} + +pub fn pulldown_strength0(s: Span) -> IResult { + let (s, a) = paren(strength0)(s)?; + Ok(( + s, + PulldownStrength::Strength0(PulldownStrength0 { nodes: (a,) }), + )) +} + +pub fn pullup_strength(s: Span) -> IResult { + alt((pullup_strength01, pullup_strength10, pullup_strength1))(s) +} + +pub fn pullup_strength01(s: Span) -> IResult { + let (s, a) = paren(triple(strength0, symbol(","), strength1))(s)?; + Ok(( + s, + PullupStrength::Strength01(PullupStrength01 { nodes: (a,) }), + )) +} + +pub fn pullup_strength10(s: Span) -> IResult { + let (s, a) = paren(triple(strength1, symbol(","), strength0))(s)?; + Ok(( + s, + PullupStrength::Strength10(PullupStrength10 { nodes: (a,) }), + )) +} + +pub fn pullup_strength1(s: Span) -> IResult { + let (s, a) = paren(strength1)(s)?; + Ok(( + s, + PullupStrength::Strength1(PullupStrength1 { nodes: (a,) }), + )) +} + +// ----------------------------------------------------------------------------- + +#[cfg(test)] +mod tests { + use super::*; + use nom::combinator::*; + + #[test] + fn test_pulldown_strength() { + parser_test!(pulldown_strength, "(supply0, strong1)", Ok((_, _))); + parser_test!(pulldown_strength, "(pull1, weak0)", Ok((_, _))); + parser_test!(pulldown_strength, "(pull0)", Ok((_, _))); + } + + #[test] + fn test_pullup_strength() { + parser_test!(pullup_strength, "(supply0, strong1)", Ok((_, _))); + parser_test!(pullup_strength, "(pull1, weak0)", Ok((_, _))); + parser_test!(pullup_strength, "(supply1)", Ok((_, _))); + } +} diff --git a/src/parser/primitive_instances/primitive_terminals.rs b/src/parser/primitive_instances/primitive_terminals.rs new file mode 100644 index 0000000..f8e1c84 --- /dev/null +++ b/src/parser/primitive_instances/primitive_terminals.rs @@ -0,0 +1,69 @@ +use crate::ast::*; +use crate::parser::*; +use nom::IResult; + +// ----------------------------------------------------------------------------- + +#[derive(Debug, Node)] +pub struct EnableTerminal<'a> { + pub nodes: (Expression<'a>,), +} + +#[derive(Debug, Node)] +pub struct InoutTerminal<'a> { + pub nodes: (NetLvalue<'a>,), +} + +#[derive(Debug, Node)] +pub struct InputTerminal<'a> { + pub nodes: (Expression<'a>,), +} + +#[derive(Debug, Node)] +pub struct NcontrolTerminal<'a> { + pub nodes: (Expression<'a>,), +} + +#[derive(Debug, Node)] +pub struct OutputTerminal<'a> { + pub nodes: (NetLvalue<'a>,), +} + +#[derive(Debug, Node)] +pub struct PcontrolTerminal<'a> { + pub nodes: (Expression<'a>,), +} + +// ----------------------------------------------------------------------------- + +pub fn enable_terminal(s: Span) -> IResult { + let (s, a) = expression(s)?; + Ok((s, EnableTerminal { nodes: (a,) })) +} + +pub fn inout_terminal(s: Span) -> IResult { + let (s, a) = net_lvalue(s)?; + Ok((s, InoutTerminal { nodes: (a,) })) +} + +pub fn input_terminal(s: Span) -> IResult { + let (s, a) = expression(s)?; + Ok((s, InputTerminal { nodes: (a,) })) +} + +pub fn ncontrol_terminal(s: Span) -> IResult { + let (s, a) = expression(s)?; + Ok((s, NcontrolTerminal { nodes: (a,) })) +} + +pub fn output_terminal(s: Span) -> IResult { + let (s, a) = net_lvalue(s)?; + Ok((s, OutputTerminal { nodes: (a,) })) +} + +pub fn pcontrol_terminal(s: Span) -> IResult { + let (s, a) = expression(s)?; + Ok((s, PcontrolTerminal { nodes: (a,) })) +} + +// ----------------------------------------------------------------------------- diff --git a/src/parser/source_text/package_items.rs b/src/parser/source_text/package_items.rs index 1b31036..93a4598 100644 --- a/src/parser/source_text/package_items.rs +++ b/src/parser/source_text/package_items.rs @@ -1,9 +1,10 @@ use crate::ast::*; use crate::parser::*; -//use nom::branch::*; -//use nom::combinator::*; -use nom::error::*; -use nom::{Err, IResult}; +use nom::branch::*; +use nom::combinator::*; +use nom::multi::*; +use nom::sequence::*; +use nom::IResult; // ----------------------------------------------------------------------------- @@ -26,8 +27,8 @@ pub enum PackageOrGenerateItemDeclaration<'a> { ExternConstraintDeclaration(ExternConstraintDeclaration<'a>), ClassDeclaration(ClassDeclaration<'a>), ClassConstructorDeclaration(ClassConstructorDeclaration<'a>), - LocalParameterDeclaration(LocalParameterDeclaration<'a>), - ParameterDeclaration(ParameterDeclaration<'a>), + LocalParameterDeclaration((LocalParameterDeclaration<'a>, Symbol<'a>)), + ParameterDeclaration((ParameterDeclaration<'a>, Symbol<'a>)), CovergroupDeclaration(CovergroupDeclaration<'a>), AssertionItemDeclaration(AssertionItemDeclaration<'a>), Empty(Symbol<'a>), @@ -35,7 +36,12 @@ pub enum PackageOrGenerateItemDeclaration<'a> { #[derive(Debug, Node)] pub struct AnonymousProgram<'a> { - pub nodes: (Vec>,), + pub nodes: ( + Symbol<'a>, + Symbol<'a>, + Vec>, + Symbol<'a>, + ), } #[derive(Debug, Node)] @@ -51,19 +57,97 @@ pub enum AnonymousProgramItem<'a> { // ----------------------------------------------------------------------------- pub fn package_item(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + alt(( + map(package_or_generate_item_declaration, |x| { + PackageItem::PackageOrGenerateItemDeclaration(x) + }), + map(anonymous_program, |x| PackageItem::AnonymousProgram(x)), + map(package_export_declaration, |x| { + PackageItem::PackageExportDeclaration(x) + }), + map(timeunits_declaration, |x| { + PackageItem::TimeunitsDeclaration(x) + }), + ))(s) } pub fn package_or_generate_item_declaration( s: Span, ) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + alt(( + map(net_declaration, |x| { + PackageOrGenerateItemDeclaration::NetDeclaration(x) + }), + map(data_declaration, |x| { + PackageOrGenerateItemDeclaration::DataDeclaration(x) + }), + map(task_declaration, |x| { + PackageOrGenerateItemDeclaration::TaskDeclaration(x) + }), + map(function_declaration, |x| { + PackageOrGenerateItemDeclaration::FunctionDeclaration(x) + }), + map(checker_declaration, |x| { + PackageOrGenerateItemDeclaration::CheckerDeclaration(x) + }), + map(dpi_import_export, |x| { + PackageOrGenerateItemDeclaration::DpiImportExport(x) + }), + map(extern_constraint_declaration, |x| { + PackageOrGenerateItemDeclaration::ExternConstraintDeclaration(x) + }), + map(class_declaration, |x| { + PackageOrGenerateItemDeclaration::ClassDeclaration(x) + }), + map(class_constructor_declaration, |x| { + PackageOrGenerateItemDeclaration::ClassConstructorDeclaration(x) + }), + map(pair(local_parameter_declaration, symbol(";")), |x| { + PackageOrGenerateItemDeclaration::LocalParameterDeclaration(x) + }), + map(pair(parameter_declaration, symbol(";")), |x| { + PackageOrGenerateItemDeclaration::ParameterDeclaration(x) + }), + map(covergroup_declaration, |x| { + PackageOrGenerateItemDeclaration::CovergroupDeclaration(x) + }), + map(assertion_item_declaration, |x| { + PackageOrGenerateItemDeclaration::AssertionItemDeclaration(x) + }), + map(symbol(";"), |x| PackageOrGenerateItemDeclaration::Empty(x)), + ))(s) } pub fn anonymous_program(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + let (s, a) = symbol("program")(s)?; + let (s, b) = symbol(";")(s)?; + let (s, c) = many0(anonymous_program_item)(s)?; + let (s, d) = symbol("endprogram")(s)?; + Ok(( + s, + AnonymousProgram { + nodes: (a, b, c, d), + }, + )) } pub fn anonymous_program_item(s: Span) -> IResult { - Err(Err::Error(make_error(s, ErrorKind::Fix))) + alt(( + map(task_declaration, |x| { + AnonymousProgramItem::TaskDeclaration(x) + }), + map(function_declaration, |x| { + AnonymousProgramItem::FunctionDeclaration(x) + }), + map(class_declaration, |x| { + AnonymousProgramItem::ClassDeclaration(x) + }), + map(covergroup_declaration, |x| { + AnonymousProgramItem::CovergroupDeclaration(x) + }), + map(class_constructor_declaration, |x| { + AnonymousProgramItem::ClassConstructorDeclaration(x) + }), + map(symbol(";"), |x| AnonymousProgramItem::Empty(x)), + ))(s) }