diff --git a/src/parser.rs b/src/parser.rs index b6867c5..cf2bc21 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -1,8 +1,14 @@ pub mod behavioral_statements; +pub mod declarations; pub mod expressions; pub mod general; +pub mod instantiations; +pub mod source_text; pub mod utils; pub use behavioral_statements::*; +pub use declarations::*; pub use expressions::*; pub use general::*; +pub use instantiations::*; +pub use source_text::*; pub use utils::*; diff --git a/src/parser/behavioral_statements/assertion_statements.rs b/src/parser/behavioral_statements/assertion_statements.rs index a755430..3576afa 100644 --- a/src/parser/behavioral_statements/assertion_statements.rs +++ b/src/parser/behavioral_statements/assertion_statements.rs @@ -14,8 +14,10 @@ pub enum AssertionItem<'a> { #[derive(Debug)] pub struct DeferredImmediateAssetionItem<'a> { - pub identifier: Option>, - pub statement: DeferredImmediateAssertionStatement<'a>, + pub nodes: ( + Option>, + DeferredImmediateAssertionStatement<'a>, + ), } #[derive(Debug)] @@ -40,20 +42,17 @@ pub enum SimpleImmediateAssertionStatement<'a> { #[derive(Debug)] pub struct SimpleImmediateAssertStatement<'a> { - pub expression: Expression<'a>, - pub block: ActionBlock<'a>, + pub nodes: (Expression<'a>, ActionBlock<'a>), } #[derive(Debug)] pub struct SimpleImmediateAssumeStatement<'a> { - pub expression: Expression<'a>, - pub block: ActionBlock<'a>, + pub nodes: (Expression<'a>, ActionBlock<'a>), } #[derive(Debug)] pub struct SimpleImmediateCoverStatement<'a> { - pub expression: Expression<'a>, - pub statement: StatementOrNull<'a>, + pub nodes: (Expression<'a>, StatementOrNull<'a>), } #[derive(Debug)] @@ -65,23 +64,17 @@ pub enum DeferredImmediateAssertionStatement<'a> { #[derive(Debug)] pub struct DeferredImmediateAssertStatement<'a> { - pub timing: AssertTiming, - pub expression: Expression<'a>, - pub block: ActionBlock<'a>, + pub nodes: (AssertTiming, Expression<'a>, ActionBlock<'a>), } #[derive(Debug)] pub struct DeferredImmediateAssumeStatement<'a> { - pub timing: AssertTiming, - pub expression: Expression<'a>, - pub block: ActionBlock<'a>, + pub nodes: (AssertTiming, Expression<'a>, ActionBlock<'a>), } #[derive(Debug)] pub struct DeferredImmediateCoverStatement<'a> { - pub timing: AssertTiming, - pub expression: Expression<'a>, - pub statement: StatementOrNull<'a>, + pub nodes: (AssertTiming, Expression<'a>, StatementOrNull<'a>), } #[derive(Debug)] @@ -104,13 +97,7 @@ pub fn assertion_item(s: &str) -> IResult<&str, AssertionItem> { pub fn deferred_immediate_assertion_item(s: &str) -> IResult<&str, DeferredImmediateAssetionItem> { let (s, x) = opt(terminated(block_identifier, symbol(":")))(s)?; let (s, y) = deferred_immediate_assertion_statement(s)?; - Ok(( - s, - DeferredImmediateAssetionItem { - identifier: x, - statement: y, - }, - )) + Ok((s, DeferredImmediateAssetionItem { nodes: (x, y) })) } pub fn procedural_assertion_statement(s: &str) -> IResult<&str, ProceduralAssertionStatement> { @@ -160,13 +147,7 @@ pub fn simple_immediate_assert_statement(s: &str) -> IResult<&str, SimpleImmedia let (s, x) = expression(s)?; let (s, _) = symbol(")")(s)?; let (s, y) = action_block(s)?; - Ok(( - s, - SimpleImmediateAssertStatement { - expression: x, - block: y, - }, - )) + Ok((s, SimpleImmediateAssertStatement { nodes: (x, y) })) } pub fn simple_immediate_assume_statement(s: &str) -> IResult<&str, SimpleImmediateAssumeStatement> { @@ -175,13 +156,7 @@ pub fn simple_immediate_assume_statement(s: &str) -> IResult<&str, SimpleImmedia let (s, x) = expression(s)?; let (s, _) = symbol(")")(s)?; let (s, y) = action_block(s)?; - Ok(( - s, - SimpleImmediateAssumeStatement { - expression: x, - block: y, - }, - )) + Ok((s, SimpleImmediateAssumeStatement { nodes: (x, y) })) } pub fn simple_immediate_cover_statement(s: &str) -> IResult<&str, SimpleImmediateCoverStatement> { @@ -190,13 +165,7 @@ pub fn simple_immediate_cover_statement(s: &str) -> IResult<&str, SimpleImmediat let (s, x) = expression(s)?; let (s, _) = symbol(")")(s)?; let (s, y) = statement_or_null(s)?; - Ok(( - s, - SimpleImmediateCoverStatement { - expression: x, - statement: y, - }, - )) + Ok((s, SimpleImmediateCoverStatement { nodes: (x, y) })) } pub fn deferred_immediate_assertion_statement( @@ -224,14 +193,7 @@ pub fn deferred_immediate_assert_statement( let (s, y) = expression(s)?; let (s, _) = symbol(")")(s)?; let (s, z) = action_block(s)?; - Ok(( - s, - DeferredImmediateAssertStatement { - timing: x, - expression: y, - block: z, - }, - )) + Ok((s, DeferredImmediateAssertStatement { nodes: (x, y, z) })) } pub fn deferred_immediate_assume_statement( @@ -243,14 +205,7 @@ pub fn deferred_immediate_assume_statement( let (s, y) = expression(s)?; let (s, _) = symbol(")")(s)?; let (s, z) = action_block(s)?; - Ok(( - s, - DeferredImmediateAssumeStatement { - timing: x, - expression: y, - block: z, - }, - )) + Ok((s, DeferredImmediateAssumeStatement { nodes: (x, y, z) })) } pub fn deferred_immediate_cover_statement( @@ -262,14 +217,7 @@ pub fn deferred_immediate_cover_statement( let (s, y) = expression(s)?; let (s, _) = symbol(")")(s)?; let (s, z) = statement_or_null(s)?; - Ok(( - s, - DeferredImmediateCoverStatement { - timing: x, - expression: y, - statement: z, - }, - )) + Ok((s, DeferredImmediateCoverStatement { nodes: (x, y, z) })) } pub fn assert_timing(s: &str) -> IResult<&str, AssertTiming> { diff --git a/src/parser/behavioral_statements/case_statements.rs b/src/parser/behavioral_statements/case_statements.rs index 7f70b12..2d93d53 100644 --- a/src/parser/behavioral_statements/case_statements.rs +++ b/src/parser/behavioral_statements/case_statements.rs @@ -16,26 +16,32 @@ pub enum CaseStatement<'a> { #[derive(Debug)] pub struct CaseStatementNormal<'a> { - pub unique_priority: Option, - pub keyword: CaseKeyword, - pub expression: Expression<'a>, - pub item: Vec>, + pub nodes: ( + Option, + CaseKeyword, + Expression<'a>, + Vec>, + ), } #[derive(Debug)] pub struct CaseStatementMatches<'a> { - pub unique_priority: Option, - pub keyword: CaseKeyword, - pub expression: Expression<'a>, - pub item: Vec>, + pub nodes: ( + Option, + CaseKeyword, + Expression<'a>, + Vec>, + ), } #[derive(Debug)] pub struct CaseStatementInside<'a> { - pub unique_priority: Option, - pub keyword: CaseKeyword, - pub expression: Expression<'a>, - pub item: Vec>, + pub nodes: ( + Option, + CaseKeyword, + Expression<'a>, + Vec>, + ), } #[derive(Debug)] @@ -65,37 +71,42 @@ pub enum CaseInsideItem<'a> { #[derive(Debug)] pub struct CaseItemDefault<'a> { - pub statement: StatementOrNull<'a>, + pub nodes: (StatementOrNull<'a>,), } #[derive(Debug)] pub struct CaseItemNondefault<'a> { - pub expression: Vec>, - pub statement: StatementOrNull<'a>, + pub nodes: (Vec>, StatementOrNull<'a>), } #[derive(Debug)] pub struct CasePatternItemNondefault<'a> { - pub pattern: Pattern<'a>, - pub expression: Option>, - pub statement: StatementOrNull<'a>, + pub nodes: (Pattern<'a>, Option>, StatementOrNull<'a>), } #[derive(Debug)] pub struct CaseInsideItemNondefault<'a> { - pub open_range_list: Vec>, - pub statement: StatementOrNull<'a>, + pub nodes: (Vec>, StatementOrNull<'a>), } #[derive(Debug)] pub struct RandcaseStatement<'a> { - pub item: Vec>, + pub nodes: (Vec>,), } #[derive(Debug)] pub struct RandcaseItem<'a> { - pub expression: Expression<'a>, - pub statement: StatementOrNull<'a>, + pub nodes: (Expression<'a>, StatementOrNull<'a>), +} + +#[derive(Debug)] +pub struct OpenRangeList<'a> { + pub nodes: (Vec>,), +} + +#[derive(Debug)] +pub struct OpenRangeValue<'a> { + pub nodes: (ValueRange<'a>,), } // ----------------------------------------------------------------------------- @@ -119,10 +130,7 @@ pub fn case_statement_normal(s: &str) -> IResult<&str, CaseStatement> { Ok(( s, CaseStatement::Normal(CaseStatementNormal { - unique_priority: x, - keyword: y, - expression: z, - item: v, + nodes: (x, y, z, v), }), )) } @@ -139,10 +147,7 @@ pub fn case_statement_matches(s: &str) -> IResult<&str, CaseStatement> { Ok(( s, CaseStatement::Matches(CaseStatementMatches { - unique_priority: x, - keyword: y, - expression: z, - item: v, + nodes: (x, y, z, v), }), )) } @@ -159,10 +164,7 @@ pub fn case_statement_inside(s: &str) -> IResult<&str, CaseStatement> { Ok(( s, CaseStatement::Inside(CaseStatementInside { - unique_priority: x, - keyword: y, - expression: z, - item: v, + nodes: (x, y, z, v), }), )) } @@ -192,10 +194,7 @@ pub fn case_item_nondefault(s: &str) -> IResult<&str, CaseItem> { let (s, y) = statement_or_null(s)?; Ok(( s, - CaseItem::NonDefault(CaseItemNondefault { - expression: x, - statement: y, - }), + CaseItem::NonDefault(CaseItemNondefault { nodes: (x, y) }), )) } @@ -203,7 +202,7 @@ pub fn case_item_default(s: &str) -> IResult<&str, CaseItemDefault> { let (s, _) = symbol("default")(s)?; let (s, _) = opt(symbol(":"))(s)?; let (s, x) = statement_or_null(s)?; - Ok((s, CaseItemDefault { statement: x })) + Ok((s, CaseItemDefault { nodes: (x,) })) } pub fn case_pattern_item(s: &str) -> IResult<&str, CasePatternItem> { @@ -220,11 +219,7 @@ pub fn case_pattern_item_nondefault(s: &str) -> IResult<&str, CasePatternItem> { let (s, z) = statement_or_null(s)?; Ok(( s, - CasePatternItem::NonDefault(CasePatternItemNondefault { - pattern: x, - expression: y, - statement: z, - }), + CasePatternItem::NonDefault(CasePatternItemNondefault { nodes: (x, y, z) }), )) } @@ -241,10 +236,7 @@ pub fn case_inside_item_nondefault(s: &str) -> IResult<&str, CaseInsideItem> { let (s, y) = statement_or_null(s)?; Ok(( s, - CaseInsideItem::NonDefault(CaseInsideItemNondefault { - open_range_list: x, - statement: y, - }), + CaseInsideItem::NonDefault(CaseInsideItemNondefault { nodes: (x, y) }), )) } @@ -256,20 +248,14 @@ pub fn randcase_statement(s: &str) -> IResult<&str, RandcaseStatement> { let (s, _) = symbol("randcase")(s)?; let (s, x) = many1(randcase_item)(s)?; let (s, _) = symbol("endcase")(s)?; - Ok((s, RandcaseStatement { item: x })) + Ok((s, RandcaseStatement { nodes: (x,) })) } pub fn randcase_item(s: &str) -> IResult<&str, RandcaseItem> { let (s, x) = expression(s)?; let (s, _) = symbol(":")(s)?; let (s, y) = statement_or_null(s)?; - Ok(( - s, - RandcaseItem { - expression: x, - statement: y, - }, - )) + Ok((s, RandcaseItem { nodes: (x, y) })) } pub fn open_range_list(s: &str) -> IResult<&str, Vec> { diff --git a/src/parser/behavioral_statements/clocking_block.rs b/src/parser/behavioral_statements/clocking_block.rs index c2929e4..00e4674 100644 --- a/src/parser/behavioral_statements/clocking_block.rs +++ b/src/parser/behavioral_statements/clocking_block.rs @@ -15,18 +15,25 @@ pub enum ClockingDeclaration<'a> { #[derive(Debug)] pub struct ClockingDeclarationLocal<'a> { - pub default: bool, - pub beg_identifier: Option>, - pub event: ClockingEvent<'a>, - pub item: Vec>, - pub end_identifier: Option>, + pub nodes: ( + Option, + Option>, + ClockingEvent<'a>, + Vec>, + Option>, + ), } +#[derive(Debug)] +pub struct Default {} + #[derive(Debug)] pub struct ClockingDeclarationGlobal<'a> { - pub beg_identifier: Option>, - pub event: ClockingEvent<'a>, - pub end_identifier: Option>, + pub nodes: ( + Option>, + ClockingEvent<'a>, + Option>, + ), } #[derive(Debug)] @@ -44,14 +51,12 @@ pub enum ClockingItem<'a> { #[derive(Debug)] pub struct ClockingItemDirection<'a> { - pub direction: ClockingDirection<'a>, - pub assign: Vec>, + pub nodes: (ClockingDirection<'a>, Vec>), } #[derive(Debug)] pub struct ClockingItemAssertion<'a> { - pub attribute: Vec>, - pub declaration: AssertionItemDeclaration<'a>, + pub nodes: (Vec>, AssertionItemDeclaration<'a>), } #[derive(Debug)] @@ -71,8 +76,7 @@ pub enum ClockingDirection<'a> { #[derive(Debug)] pub struct ClockingDeclAssign<'a> { - pub identifier: Identifier<'a>, - pub expression: Option>, + pub nodes: (SignalIdentifier<'a>, Option>), } #[derive(Debug)] @@ -83,9 +87,11 @@ pub enum ClockingSkew<'a> { #[derive(Debug)] pub struct ClockingDrive<'a> { - pub lvalue: (HierarchicalIdentifier<'a>, Select<'a>), - pub cycle_delay: Option>, - pub rvalue: Expression<'a>, + pub nodes: ( + (HierarchicalIdentifier<'a>, Select<'a>), + Option>, + Expression<'a>, + ), } #[derive(Debug)] @@ -113,11 +119,7 @@ pub fn clocking_declaration_local(s: &str) -> IResult<&str, ClockingDeclaration> Ok(( s, ClockingDeclaration::Local(ClockingDeclarationLocal { - default: x.is_some(), - beg_identifier: y, - event: z, - item: v, - end_identifier: w, + nodes: (x.map(|_| Default {}), y, z, v, w), }), )) } @@ -132,11 +134,7 @@ pub fn clocking_declaration_global(s: &str) -> IResult<&str, ClockingDeclaration let (s, z) = opt(preceded(symbol(":"), clocking_identifier))(s)?; Ok(( s, - ClockingDeclaration::Global(ClockingDeclarationGlobal { - beg_identifier: x, - event: y, - end_identifier: z, - }), + ClockingDeclaration::Global(ClockingDeclarationGlobal { nodes: (x, y, z) }), )) } @@ -171,10 +169,7 @@ pub fn clocking_item_direction(s: &str) -> IResult<&str, ClockingItem> { let (s, y) = list_of_clocking_decl_assign(s)?; Ok(( s, - ClockingItem::Direction(ClockingItemDirection { - direction: x, - assign: y, - }), + ClockingItem::Direction(ClockingItemDirection { nodes: (x, y) }), )) } @@ -183,10 +178,7 @@ pub fn clocking_item_assertion(s: &str) -> IResult<&str, ClockingItem> { let (s, y) = assertion_item_declaration(s)?; Ok(( s, - ClockingItem::Assertion(ClockingItemAssertion { - attribute: x, - declaration: y, - }), + ClockingItem::Assertion(ClockingItemAssertion { nodes: (x, y) }), )) } @@ -259,13 +251,7 @@ pub fn list_of_clocking_decl_assign(s: &str) -> IResult<&str, Vec IResult<&str, ClockingDeclAssign> { let (s, x) = signal_identifier(s)?; let (s, y) = opt(preceded(symbol("="), expression))(s)?; - Ok(( - s, - ClockingDeclAssign { - identifier: x, - expression: y, - }, - )) + Ok((s, ClockingDeclAssign { nodes: (x, y) })) } pub fn clocking_skew(s: &str) -> IResult<&str, ClockingSkew> { @@ -288,14 +274,7 @@ pub fn clocking_drive(s: &str) -> IResult<&str, ClockingDrive> { let (s, _) = symbol("=")(s)?; let (s, y) = opt(cycle_delay)(s)?; let (s, z) = expression(s)?; - Ok(( - s, - ClockingDrive { - lvalue: x, - cycle_delay: y, - rvalue: z, - }, - )) + Ok((s, ClockingDrive { nodes: (x, y, z) })) } pub fn cycle_delay(s: &str) -> IResult<&str, CycleDelay> { diff --git a/src/parser/behavioral_statements/conditional_statements.rs b/src/parser/behavioral_statements/conditional_statements.rs index e0ac678..c6d20a9 100644 --- a/src/parser/behavioral_statements/conditional_statements.rs +++ b/src/parser/behavioral_statements/conditional_statements.rs @@ -9,10 +9,12 @@ use nom::IResult; #[derive(Debug)] pub struct ConditionalStatement<'a> { - pub unique_priority: Option, - pub if_statement: ConditionalStatementBody<'a>, - pub else_if_statement: Vec>, - pub else_statement: Option>, + pub nodes: ( + Option, + ConditionalStatementBody<'a>, + Vec>, + Option>, + ), } #[derive(Debug)] @@ -24,13 +26,12 @@ pub enum UniquePriority { #[derive(Debug)] pub struct ConditionalStatementBody<'a> { - pub predicate: CondPredicate<'a>, - pub statement: StatementOrNull<'a>, + pub nodes: (CondPredicate<'a>, StatementOrNull<'a>), } #[derive(Debug)] pub struct CondPredicate<'a> { - pub pattern: Vec>, + pub nodes: (Vec>,), } #[derive(Debug)] @@ -41,8 +42,7 @@ pub enum ExpressionOrCondPattern<'a> { #[derive(Debug)] pub struct CondPattern<'a> { - pub expression: Expression<'a>, - pub pattern: Pattern<'a>, + pub nodes: (Expression<'a>, Pattern<'a>), } // ----------------------------------------------------------------------------- @@ -60,10 +60,7 @@ pub fn conditional_statement(s: &str) -> IResult<&str, ConditionalStatement> { Ok(( s, ConditionalStatement { - unique_priority: x, - if_statement: y, - else_if_statement: z, - else_statement: v, + nodes: (x, y, z, v), }, )) } @@ -74,13 +71,7 @@ pub fn conditional_statement_body(s: &str) -> IResult<&str, ConditionalStatement let (s, _) = symbol(")")(s)?; let (s, y) = statement_or_null(s)?; - Ok(( - s, - ConditionalStatementBody { - predicate: x, - statement: y, - }, - )) + Ok((s, ConditionalStatementBody { nodes: (x, y) })) } pub fn unique_priority(s: &str) -> IResult<&str, UniquePriority> { @@ -92,8 +83,8 @@ pub fn unique_priority(s: &str) -> IResult<&str, UniquePriority> { } pub fn cond_predicate(s: &str) -> IResult<&str, CondPredicate> { - let (s, pattern) = separated_nonempty_list(symbol("&&&"), expression_or_cond_pattern)(s)?; - Ok((s, CondPredicate { pattern })) + let (s, x) = separated_nonempty_list(symbol("&&&"), expression_or_cond_pattern)(s)?; + Ok((s, CondPredicate { nodes: (x,) })) } pub fn expression_or_cond_pattern(s: &str) -> IResult<&str, ExpressionOrCondPattern> { @@ -107,11 +98,5 @@ pub fn cond_pattern(s: &str) -> IResult<&str, CondPattern> { let (s, x) = expression(s)?; let (s, _) = symbol("matches")(s)?; let (s, y) = pattern(s)?; - Ok(( - s, - CondPattern { - expression: x, - pattern: y, - }, - )) + Ok((s, CondPattern { nodes: (x, y) })) } diff --git a/src/parser/behavioral_statements/continuous_assignment_and_net_alias_statements.rs b/src/parser/behavioral_statements/continuous_assignment_and_net_alias_statements.rs index 637ad8f..49d1bea 100644 --- a/src/parser/behavioral_statements/continuous_assignment_and_net_alias_statements.rs +++ b/src/parser/behavioral_statements/continuous_assignment_and_net_alias_statements.rs @@ -15,27 +15,26 @@ pub enum ContinuousAssign<'a> { #[derive(Debug)] pub struct ContinuousAssignNet<'a> { - pub drive_strength: Option>, - pub delay3: Option>, - pub list: Vec>, + pub nodes: ( + Option, + Option>, + Vec>, + ), } #[derive(Debug)] pub struct ContinuousAssignVariable<'a> { - pub delay_control: Option>, - pub list: Vec>, + pub nodes: (Option>, Vec>), } #[derive(Debug)] pub struct NetAlias<'a> { - pub lvalue: NetLvalue<'a>, - pub rvalue: Vec>, + pub nodes: (NetLvalue<'a>, Vec>), } #[derive(Debug)] pub struct NetAssignment<'a> { - pub lvalue: NetLvalue<'a>, - pub rvalue: Expression<'a>, + pub nodes: (NetLvalue<'a>, Expression<'a>), } // ----------------------------------------------------------------------------- @@ -53,11 +52,7 @@ pub fn continuous_assign_net(s: &str) -> IResult<&str, ContinuousAssign> { Ok(( s, - ContinuousAssign::Net(ContinuousAssignNet { - drive_strength: x, - delay3: y, - list: z, - }), + ContinuousAssign::Net(ContinuousAssignNet { nodes: (x, y, z) }), )) } @@ -69,10 +64,7 @@ pub fn continuous_assign_variable(s: &str) -> IResult<&str, ContinuousAssign> { Ok(( s, - ContinuousAssign::Variable(ContinuousAssignVariable { - delay_control: x, - list: y, - }), + ContinuousAssign::Variable(ContinuousAssignVariable { nodes: (x, y) }), )) } @@ -89,13 +81,7 @@ pub fn net_alias(s: &str) -> IResult<&str, NetAlias> { let (s, x) = net_lvalue(s)?; let (s, y) = many1(preceded(symbol("="), net_lvalue))(s)?; - Ok(( - s, - NetAlias { - lvalue: x, - rvalue: y, - }, - )) + Ok((s, NetAlias { nodes: (x, y) })) } pub fn net_assignment(s: &str) -> IResult<&str, NetAssignment> { @@ -103,11 +89,5 @@ pub fn net_assignment(s: &str) -> IResult<&str, NetAssignment> { let (s, _) = symbol("=")(s)?; let (s, y) = expression(s)?; - Ok(( - s, - NetAssignment { - lvalue: x, - rvalue: y, - }, - )) + Ok((s, NetAssignment { nodes: (x, y) })) } diff --git a/src/parser/behavioral_statements/looping_statements.rs b/src/parser/behavioral_statements/looping_statements.rs index dea2462..48437a4 100644 --- a/src/parser/behavioral_statements/looping_statements.rs +++ b/src/parser/behavioral_statements/looping_statements.rs @@ -19,40 +19,41 @@ pub enum LoopStatement<'a> { #[derive(Debug)] pub struct LoopStatementForever<'a> { - pub statement: StatementOrNull<'a>, + pub nodes: (StatementOrNull<'a>,), } #[derive(Debug)] pub struct LoopStatementRepeat<'a> { - pub expression: Expression<'a>, - pub statement: StatementOrNull<'a>, + pub nodes: (Expression<'a>, StatementOrNull<'a>), } #[derive(Debug)] pub struct LoopStatementWhile<'a> { - pub expression: Expression<'a>, - pub statement: StatementOrNull<'a>, + pub nodes: (Expression<'a>, StatementOrNull<'a>), } #[derive(Debug)] pub struct LoopStatementFor<'a> { - pub initilization: Option>, - pub expression: Option>, - pub step: Option>>, - pub statement: StatementOrNull<'a>, + pub nodes: ( + Option>, + Option>, + Option>>, + StatementOrNull<'a>, + ), } #[derive(Debug)] pub struct LoopStatementDoWhile<'a> { - pub statement: StatementOrNull<'a>, - pub expression: Expression<'a>, + pub nodes: (StatementOrNull<'a>, Expression<'a>), } #[derive(Debug)] pub struct LoopStatementForeach<'a> { - pub identifier: ScopedIdentifier<'a>, - pub variable: Vec>>, - pub statement: Statement<'a>, + pub nodes: ( + PsOrHierarchicalArrayIdentifier<'a>, + LoopVariables<'a>, + Statement<'a>, + ), } #[derive(Debug)] @@ -63,11 +64,16 @@ pub enum ForInitialization<'a> { #[derive(Debug)] pub struct ForVariableDeclaration<'a> { - pub var: bool, - pub r#type: DataType<'a>, - pub declaration: Vec<(Identifier<'a>, Expression<'a>)>, + pub nodes: ( + Option, + DataType<'a>, + Vec<(VariableIdentifier<'a>, Expression<'a>)>, + ), } +#[derive(Debug)] +pub struct Var {} + #[derive(Debug)] pub enum ForStepAssignment<'a> { Operator(OperatorAssignment<'a>), @@ -75,6 +81,11 @@ pub enum ForStepAssignment<'a> { Subroutine(SubroutineCall<'a>), } +#[derive(Debug)] +pub struct LoopVariables<'a> { + pub nodes: (Vec>>,), +} + // ----------------------------------------------------------------------------- pub fn loop_statement(s: &str) -> IResult<&str, LoopStatement> { @@ -93,7 +104,7 @@ pub fn loop_statement_forever(s: &str) -> IResult<&str, LoopStatement> { let (s, x) = statement_or_null(s)?; Ok(( s, - LoopStatement::Forever(LoopStatementForever { statement: x }), + LoopStatement::Forever(LoopStatementForever { nodes: (x,) }), )) } @@ -105,10 +116,7 @@ pub fn loop_statement_repeat(s: &str) -> IResult<&str, LoopStatement> { let (s, y) = statement_or_null(s)?; Ok(( s, - LoopStatement::Repeat(LoopStatementRepeat { - expression: x, - statement: y, - }), + LoopStatement::Repeat(LoopStatementRepeat { nodes: (x, y) }), )) } @@ -120,10 +128,7 @@ pub fn loop_statement_while(s: &str) -> IResult<&str, LoopStatement> { let (s, y) = statement_or_null(s)?; Ok(( s, - LoopStatement::While(LoopStatementWhile { - expression: x, - statement: y, - }), + LoopStatement::While(LoopStatementWhile { nodes: (x, y) }), )) } @@ -140,10 +145,7 @@ pub fn loop_statement_for(s: &str) -> IResult<&str, LoopStatement> { Ok(( s, LoopStatement::For(LoopStatementFor { - initilization: x, - expression: y, - step: z, - statement: v, + nodes: (x, y, z, v), }), )) } @@ -158,10 +160,7 @@ pub fn loop_statement_do_while(s: &str) -> IResult<&str, LoopStatement> { let (s, _) = symbol(";")(s)?; Ok(( s, - LoopStatement::DoWhile(LoopStatementDoWhile { - statement: x, - expression: y, - }), + LoopStatement::DoWhile(LoopStatementDoWhile { nodes: (x, y) }), )) } @@ -176,11 +175,7 @@ pub fn loop_statement_foreach(s: &str) -> IResult<&str, LoopStatement> { let (s, z) = statement(s)?; Ok(( s, - LoopStatement::Foreach(LoopStatementForeach { - identifier: x, - variable: y, - statement: z, - }), + LoopStatement::Foreach(LoopStatementForeach { nodes: (x, y, z) }), )) } @@ -206,9 +201,7 @@ pub fn for_variable_declaration(s: &str) -> IResult<&str, ForVariableDeclaration Ok(( s, ForVariableDeclaration { - var: x.is_some(), - r#type: y, - declaration: z, + nodes: (x.map(|_| Var {}), y, z), }, )) } @@ -227,8 +220,9 @@ pub fn for_step_assignment(s: &str) -> IResult<&str, ForStepAssignment> { ))(s) } -pub fn loop_variables(s: &str) -> IResult<&str, Vec>> { - separated_nonempty_list(symbol(","), opt(index_variable_identifier))(s) +pub fn loop_variables(s: &str) -> IResult<&str, LoopVariables> { + let (s, x) = separated_nonempty_list(symbol(","), opt(index_variable_identifier))(s)?; + Ok((s, LoopVariables { nodes: (x,) })) } // ----------------------------------------------------------------------------- diff --git a/src/parser/behavioral_statements/parallel_and_sequential_blocks.rs b/src/parser/behavioral_statements/parallel_and_sequential_blocks.rs index dffbe25..fa02477 100644 --- a/src/parser/behavioral_statements/parallel_and_sequential_blocks.rs +++ b/src/parser/behavioral_statements/parallel_and_sequential_blocks.rs @@ -15,25 +15,28 @@ pub enum ActionBlock<'a> { #[derive(Debug)] pub struct ActionBlockElse<'a> { - pub statement: Option>, - pub else_statement: StatementOrNull<'a>, + pub nodes: (Option>, StatementOrNull<'a>), } #[derive(Debug)] pub struct SeqBlock<'a> { - pub beg_identifier: Option>, - pub declaration: Vec>, - pub statement: Vec>, - pub end_identifier: Option>, + pub nodes: ( + Option>, + Vec>, + Vec>, + Option>, + ), } #[derive(Debug)] pub struct ParBlock<'a> { - pub beg_identifier: Option>, - pub declaration: Vec>, - pub statement: Vec>, - pub keyword: JoinKeyword, - pub end_identifier: Option>, + pub nodes: ( + Option>, + Vec>, + Vec>, + JoinKeyword, + Option>, + ), } #[derive(Debug)] @@ -56,13 +59,7 @@ pub fn action_block_else(s: &str) -> IResult<&str, ActionBlock> { let (s, x) = opt(statement)(s)?; let (s, _) = symbol("else")(s)?; let (s, y) = statement_or_null(s)?; - Ok(( - s, - ActionBlock::Else(ActionBlockElse { - statement: x, - else_statement: y, - }), - )) + Ok((s, ActionBlock::Else(ActionBlockElse { nodes: (x, y) }))) } pub fn seq_block(s: &str) -> IResult<&str, SeqBlock> { @@ -75,10 +72,7 @@ pub fn seq_block(s: &str) -> IResult<&str, SeqBlock> { Ok(( s, SeqBlock { - beg_identifier: x, - declaration: y, - statement: z, - end_identifier: v, + nodes: (x, y, z, v), }, )) } @@ -93,11 +87,7 @@ pub fn par_block(s: &str) -> IResult<&str, ParBlock> { Ok(( s, ParBlock { - beg_identifier: x, - declaration: y, - statement: z, - keyword: v, - end_identifier: w, + nodes: (x, y, z, v, w), }, )) } diff --git a/src/parser/behavioral_statements/patterns.rs b/src/parser/behavioral_statements/patterns.rs index 46a7b5b..dbd1829 100644 --- a/src/parser/behavioral_statements/patterns.rs +++ b/src/parser/behavioral_statements/patterns.rs @@ -9,12 +9,12 @@ use nom::IResult; #[derive(Debug)] pub enum Pattern<'a> { - VariableIdentifier(Box>), + VariableIdentifier(Box>), Asterisk, ConstantExpression(Box>), - Tagged(Box<(Identifier<'a>, Option>)>), + Tagged(Box<(MemberIdentifier<'a>, Option>)>), Pattern(Box>>), - MemberPattern(Box, Pattern<'a>)>>), + MemberPattern(Box, Pattern<'a>)>>), } #[derive(Debug)] @@ -27,7 +27,7 @@ pub enum AssignmentPattern<'a> { #[derive(Debug)] pub enum StructurePatternKey<'a> { - Identifier(Identifier<'a>), + Identifier(MemberIdentifier<'a>), PatternKey(AssignmentPatternKey<'a>), } @@ -45,26 +45,28 @@ pub enum AssignmentPatternKey<'a> { #[derive(Debug)] pub struct AssignmentPatternExpression<'a> { - pub r#type: Option>, - pub pattern: AssignmentPattern<'a>, + pub nodes: ( + Option>, + AssignmentPattern<'a>, + ), } #[derive(Debug)] pub enum AssignmentPatternExpressionType<'a> { - Type(ScopedIdentifier<'a>), - Parameter(ScopedIdentifier<'a>), - IntegerAtom(IntegerAtomType<'a>), + Type(PsTypeIdentifier<'a>), + Parameter(PsParameterIdentifier<'a>), + IntegerAtom(IntegerAtomType), TypeReference(TypeReference<'a>), } #[derive(Debug)] pub struct AssignmentPatternNetLvalue<'a> { - pub lvalue: Vec>, + pub nodes: (Vec>,), } #[derive(Debug)] pub struct AssignmentPatternVariableLvalue<'a> { - pub lvalue: Vec>, + pub nodes: (Vec>,), } // ----------------------------------------------------------------------------- @@ -152,13 +154,7 @@ pub fn assignment_pattern_key(s: &str) -> IResult<&str, AssignmentPatternKey> { pub fn assignment_pattern_expression(s: &str) -> IResult<&str, AssignmentPatternExpression> { let (s, x) = opt(assignment_pattern_expression_type)(s)?; let (s, y) = assignment_pattern(s)?; - Ok(( - s, - AssignmentPatternExpression { - r#type: x, - pattern: y, - }, - )) + Ok((s, AssignmentPatternExpression { nodes: (x, y) })) } pub fn assignment_pattern_expression_type( @@ -188,14 +184,14 @@ pub fn constant_assignment_pattern_expression( pub fn assignment_pattern_net_lvalue(s: &str) -> IResult<&str, AssignmentPatternNetLvalue> { let (s, x) = apostrophe_brace(separated_nonempty_list(symbol(","), net_lvalue))(s)?; - Ok((s, AssignmentPatternNetLvalue { lvalue: x })) + Ok((s, AssignmentPatternNetLvalue { nodes: (x,) })) } pub fn assignment_pattern_variable_lvalue( s: &str, ) -> IResult<&str, AssignmentPatternVariableLvalue> { let (s, x) = apostrophe_brace(separated_nonempty_list(symbol(","), variable_lvalue))(s)?; - Ok((s, AssignmentPatternVariableLvalue { lvalue: x })) + Ok((s, AssignmentPatternVariableLvalue { nodes: (x,) })) } // ----------------------------------------------------------------------------- diff --git a/src/parser/behavioral_statements/procedural_blocks_and_assignments.rs b/src/parser/behavioral_statements/procedural_blocks_and_assignments.rs index 7186138..a1eafc1 100644 --- a/src/parser/behavioral_statements/procedural_blocks_and_assignments.rs +++ b/src/parser/behavioral_statements/procedural_blocks_and_assignments.rs @@ -8,13 +8,12 @@ use nom::IResult; #[derive(Debug)] pub struct InitialConstruct<'a> { - pub statement: StatementOrNull<'a>, + pub nodes: (StatementOrNull<'a>,), } #[derive(Debug)] pub struct AlwaysConstruct<'a> { - pub keyword: AlwaysKeyword, - pub statement: Statement<'a>, + pub nodes: (AlwaysKeyword, Statement<'a>), } #[derive(Debug)] @@ -27,7 +26,7 @@ pub enum AlwaysKeyword { #[derive(Debug)] pub struct FinalConstruct<'a> { - pub statement: Statement<'a>, + pub nodes: (FunctionStatement<'a>,), } #[derive(Debug)] @@ -40,37 +39,36 @@ pub enum BlockingAssignment<'a> { #[derive(Debug)] pub struct BlockingAssignmentVariable<'a> { - pub lvalue: VariableLvalue<'a>, - pub control: DelayOrEventControl<'a>, - pub rvalue: Expression<'a>, + pub nodes: (VariableLvalue<'a>, DelayOrEventControl<'a>, Expression<'a>), } #[derive(Debug)] pub struct BlockingAssignmentNonrangeVariable<'a> { - pub lvalue: NonrangeVariableLvalue<'a>, - pub rvalue: DynamicArrayNew<'a>, + pub nodes: (NonrangeVariableLvalue<'a>, DynamicArrayNew<'a>), } #[derive(Debug)] pub struct BlockingAssignmentHierarchicalVariable<'a> { - pub scope: Option>, - pub lvalue: HierarchicalIdentifier<'a>, - pub select: Select<'a>, - pub rvalue: ClassNew<'a>, + pub nodes: ( + Option>, + HierarchicalVariableIdentifier<'a>, + Select<'a>, + ClassNew<'a>, + ), } #[derive(Debug)] pub struct OperatorAssignment<'a> { - pub lvalue: VariableLvalue<'a>, - pub operator: Operator<'a>, - pub rvalue: Expression<'a>, + pub nodes: (VariableLvalue<'a>, Operator<'a>, Expression<'a>), } #[derive(Debug)] pub struct NonblockingAssignment<'a> { - pub lvalue: VariableLvalue<'a>, - pub control: Option>, - pub rvalue: Expression<'a>, + pub nodes: ( + VariableLvalue<'a>, + Option>, + Expression<'a>, + ), } #[derive(Debug)] @@ -85,8 +83,7 @@ pub enum ProceduralContinuousAssignment<'a> { #[derive(Debug)] pub struct VariableAssignment<'a> { - pub lvalue: VariableLvalue<'a>, - pub rvalue: Expression<'a>, + pub nodes: (VariableLvalue<'a>, Expression<'a>), } // ----------------------------------------------------------------------------- @@ -94,19 +91,13 @@ pub struct VariableAssignment<'a> { pub fn initial_construct(s: &str) -> IResult<&str, InitialConstruct> { let (s, _) = symbol("initial")(s)?; let (s, x) = statement_or_null(s)?; - Ok((s, InitialConstruct { statement: x })) + Ok((s, InitialConstruct { nodes: (x,) })) } pub fn always_construct(s: &str) -> IResult<&str, AlwaysConstruct> { let (s, x) = always_keyword(s)?; let (s, y) = statement(s)?; - Ok(( - s, - AlwaysConstruct { - keyword: x, - statement: y, - }, - )) + Ok((s, AlwaysConstruct { nodes: (x, y) })) } pub fn always_keyword(s: &str) -> IResult<&str, AlwaysKeyword> { @@ -121,7 +112,7 @@ pub fn always_keyword(s: &str) -> IResult<&str, AlwaysKeyword> { pub fn final_construct(s: &str) -> IResult<&str, FinalConstruct> { let (s, _) = symbol("final")(s)?; let (s, x) = function_statement(s)?; - Ok((s, FinalConstruct { statement: x })) + Ok((s, FinalConstruct { nodes: (x,) })) } pub fn blocking_assignment(s: &str) -> IResult<&str, BlockingAssignment> { @@ -140,11 +131,7 @@ pub fn blocking_assignment_variable(s: &str) -> IResult<&str, BlockingAssignment let (s, z) = expression(s)?; Ok(( s, - BlockingAssignment::Variable(BlockingAssignmentVariable { - lvalue: x, - control: y, - rvalue: z, - }), + BlockingAssignment::Variable(BlockingAssignmentVariable { nodes: (x, y, z) }), )) } @@ -154,19 +141,12 @@ pub fn blocking_assignment_nonrange_variable(s: &str) -> IResult<&str, BlockingA let (s, y) = dynamic_array_new(s)?; Ok(( s, - BlockingAssignment::NonrangeVariable(BlockingAssignmentNonrangeVariable { - lvalue: x, - rvalue: y, - }), + BlockingAssignment::NonrangeVariable(BlockingAssignmentNonrangeVariable { nodes: (x, y) }), )) } pub fn blocking_assignment_hierarchical_variable(s: &str) -> IResult<&str, BlockingAssignment> { - let (s, x) = opt(alt(( - terminated(implicit_class_handle, symbol(".")), - class_scope, - package_scope, - )))(s)?; + let (s, x) = opt(implicit_class_handle_or_class_scope_or_package_scope)(s)?; let (s, y) = hierarchical_variable_identifier(s)?; let (s, z) = select(s)?; let (s, _) = symbol("=")(s)?; @@ -174,10 +154,7 @@ pub fn blocking_assignment_hierarchical_variable(s: &str) -> IResult<&str, Block Ok(( s, BlockingAssignment::HierarchicalVariable(BlockingAssignmentHierarchicalVariable { - scope: x, - lvalue: y, - select: z, - rvalue: v, + nodes: (x, y, z, v), }), )) } @@ -186,31 +163,24 @@ pub fn operator_assignment(s: &str) -> IResult<&str, OperatorAssignment> { let (s, x) = variable_lvalue(s)?; let (s, y) = assignment_operator(s)?; let (s, z) = expression(s)?; - Ok(( - s, - OperatorAssignment { - lvalue: x, - operator: y, - rvalue: z, - }, - )) + Ok((s, OperatorAssignment { nodes: (x, y, z) })) } pub fn assignment_operator(s: &str) -> IResult<&str, Operator> { alt(( - map(symbol("="), |raw| Operator { raw }), - map(symbol("+="), |raw| Operator { raw }), - map(symbol("-="), |raw| Operator { raw }), - map(symbol("*="), |raw| Operator { raw }), - map(symbol("/="), |raw| Operator { raw }), - map(symbol("%="), |raw| Operator { raw }), - map(symbol("&="), |raw| Operator { raw }), - map(symbol("|="), |raw| Operator { raw }), - map(symbol("^="), |raw| Operator { raw }), - map(symbol("<<<="), |raw| Operator { raw }), - map(symbol(">>>="), |raw| Operator { raw }), - map(symbol("<<="), |raw| Operator { raw }), - map(symbol(">>="), |raw| Operator { raw }), + map(symbol("="), |x| Operator { nodes: (x,) }), + map(symbol("+="), |x| Operator { nodes: (x,) }), + map(symbol("-="), |x| Operator { nodes: (x,) }), + map(symbol("*="), |x| Operator { nodes: (x,) }), + map(symbol("/="), |x| Operator { nodes: (x,) }), + map(symbol("%="), |x| Operator { nodes: (x,) }), + map(symbol("&="), |x| Operator { nodes: (x,) }), + map(symbol("|="), |x| Operator { nodes: (x,) }), + map(symbol("^="), |x| Operator { nodes: (x,) }), + map(symbol("<<<="), |x| Operator { nodes: (x,) }), + map(symbol(">>>="), |x| Operator { nodes: (x,) }), + map(symbol("<<="), |x| Operator { nodes: (x,) }), + map(symbol(">>="), |x| Operator { nodes: (x,) }), ))(s) } @@ -219,14 +189,7 @@ pub fn nonblocking_assignment(s: &str) -> IResult<&str, NonblockingAssignment> { let (s, _) = symbol("<=")(s)?; let (s, y) = opt(delay_or_event_control)(s)?; let (s, z) = expression(s)?; - Ok(( - s, - NonblockingAssignment { - lvalue: x, - control: y, - rvalue: z, - }, - )) + Ok((s, NonblockingAssignment { nodes: (x, y, z) })) } pub fn procedural_continuous_assignment(s: &str) -> IResult<&str, ProceduralContinuousAssignment> { @@ -256,11 +219,5 @@ pub fn variable_assignment(s: &str) -> IResult<&str, VariableAssignment> { let (s, x) = variable_lvalue(s)?; let (s, _) = symbol("=")(s)?; let (s, y) = expression(s)?; - Ok(( - s, - VariableAssignment { - lvalue: x, - rvalue: y, - }, - )) + Ok((s, VariableAssignment { nodes: (x, y) })) } diff --git a/src/parser/behavioral_statements/randsequence.rs b/src/parser/behavioral_statements/randsequence.rs index bcc23d5..85e068a 100644 --- a/src/parser/behavioral_statements/randsequence.rs +++ b/src/parser/behavioral_statements/randsequence.rs @@ -9,23 +9,26 @@ use nom::IResult; #[derive(Debug)] pub struct RandsequenceStatement<'a> { - pub identifier: Option>, - pub production: Vec>, + pub nodes: (Option>, Vec>), } #[derive(Debug)] pub struct Production<'a> { - pub r#type: Option>, - pub identifier: Identifier<'a>, - pub tf_port_list: Option>, - pub rs_rule: Vec>, + pub nodes: ( + Option>, + ProductionIdentifier<'a>, + Option>, + Vec>, + ), } #[derive(Debug)] pub struct RsRule<'a> { - pub production: RsProductionList<'a>, - pub weight: Option>, - pub block: Option>, + pub nodes: ( + RsProductionList<'a>, + Option>, + Option>, + ), } #[derive(Debug)] @@ -37,14 +40,13 @@ pub enum RsProductionList<'a> { #[derive(Debug)] pub enum WeightSpecification<'a> { Number(Number<'a>), - Identifier(ScopedIdentifier<'a>), + Identifier(PsIdentifier<'a>), Expression(Expression<'a>), } #[derive(Debug)] pub struct RsCodeBlock<'a> { - pub declaration: Vec>, - pub statement: Vec>, + pub nodes: (Vec>, Vec>), } #[derive(Debug)] @@ -58,27 +60,26 @@ pub enum RsProd<'a> { #[derive(Debug)] pub struct ProductionItem<'a> { - pub identifier: Identifier<'a>, - pub argument: Option>, + pub nodes: (ProductionIdentifier<'a>, Option>), } #[derive(Debug)] pub struct RsIfElse<'a> { - pub expression: Expression<'a>, - pub item: ProductionItem<'a>, - pub else_item: Option>, + pub nodes: ( + Expression<'a>, + ProductionItem<'a>, + Option>, + ), } #[derive(Debug)] pub struct RsRepeat<'a> { - pub expression: Expression<'a>, - pub item: ProductionItem<'a>, + pub nodes: (Expression<'a>, ProductionItem<'a>), } #[derive(Debug)] pub struct RsCase<'a> { - pub expression: Expression<'a>, - pub item: Vec>, + pub nodes: (Expression<'a>, Vec>), } #[derive(Debug)] @@ -89,13 +90,12 @@ pub enum RsCaseItem<'a> { #[derive(Debug)] pub struct RsCaseItemDefault<'a> { - pub item: ProductionItem<'a>, + pub nodes: (ProductionItem<'a>,), } #[derive(Debug)] pub struct RsCaseItemNondefault<'a> { - pub expression: Vec>, - pub item: ProductionItem<'a>, + pub nodes: (Vec>, ProductionItem<'a>), } // ----------------------------------------------------------------------------- @@ -107,13 +107,7 @@ pub fn randsequence_statement(s: &str) -> IResult<&str, RandsequenceStatement> { let (s, _) = symbol(")")(s)?; let (s, y) = many1(production)(s)?; let (s, _) = symbol("endsequence")(s)?; - Ok(( - s, - RandsequenceStatement { - identifier: x, - production: y, - }, - )) + Ok((s, RandsequenceStatement { nodes: (x, y) })) } pub fn production(s: &str) -> IResult<&str, Production> { @@ -126,10 +120,7 @@ pub fn production(s: &str) -> IResult<&str, Production> { Ok(( s, Production { - r#type: x, - identifier: y, - tf_port_list: z, - rs_rule: v, + nodes: (x, y, z, v), }, )) } @@ -146,14 +137,7 @@ pub fn rs_rule(s: &str) -> IResult<&str, RsRule> { } else { (None, None) }; - Ok(( - s, - RsRule { - production: x, - weight: y, - block: z, - }, - )) + Ok((s, RsRule { nodes: (x, y, z) })) } pub fn rs_production_list(s: &str) -> IResult<&str, RsProductionList> { @@ -192,13 +176,7 @@ pub fn rs_code_block(s: &str) -> IResult<&str, RsCodeBlock> { let (s, x) = many0(data_declaration)(s)?; let (s, y) = many0(statement_or_null)(s)?; let (s, _) = symbol("}")(s)?; - Ok(( - s, - RsCodeBlock { - declaration: x, - statement: y, - }, - )) + Ok((s, RsCodeBlock { nodes: (x, y) })) } pub fn rs_prod(s: &str) -> IResult<&str, RsProd> { @@ -214,13 +192,7 @@ pub fn rs_prod(s: &str) -> IResult<&str, RsProd> { pub fn production_item(s: &str) -> IResult<&str, ProductionItem> { let (s, x) = production_identifier(s)?; let (s, y) = opt(paren(list_of_arguments))(s)?; - Ok(( - s, - ProductionItem { - identifier: x, - argument: y, - }, - )) + Ok((s, ProductionItem { nodes: (x, y) })) } pub fn rs_if_else(s: &str) -> IResult<&str, RsIfElse> { @@ -228,40 +200,21 @@ pub fn rs_if_else(s: &str) -> IResult<&str, RsIfElse> { let (s, x) = paren(expression)(s)?; let (s, y) = production_item(s)?; let (s, z) = opt(preceded(symbol("else"), production_item))(s)?; - Ok(( - s, - RsIfElse { - expression: x, - item: y, - else_item: z, - }, - )) + Ok((s, RsIfElse { nodes: (x, y, z) })) } pub fn rs_repeat(s: &str) -> IResult<&str, RsRepeat> { let (s, _) = symbol("repeat")(s)?; let (s, x) = paren(expression)(s)?; let (s, y) = production_item(s)?; - Ok(( - s, - RsRepeat { - expression: x, - item: y, - }, - )) + Ok((s, RsRepeat { nodes: (x, y) })) } pub fn rs_case(s: &str) -> IResult<&str, RsCase> { let (s, _) = symbol("case")(s)?; let (s, x) = paren(case_expression)(s)?; let (s, y) = many1(rs_case_item)(s)?; - Ok(( - s, - RsCase { - expression: x, - item: y, - }, - )) + Ok((s, RsCase { nodes: (x, y) })) } pub fn rs_case_item(s: &str) -> IResult<&str, RsCaseItem> { @@ -275,10 +228,7 @@ pub fn rs_case_item_nondefault(s: &str) -> IResult<&str, RsCaseItem> { let (s, _) = symbol(";")(s)?; Ok(( s, - RsCaseItem::NonDefault(RsCaseItemNondefault { - expression: x, - item: y, - }), + RsCaseItem::NonDefault(RsCaseItemNondefault { nodes: (x, y) }), )) } @@ -287,5 +237,5 @@ pub fn rs_case_item_default(s: &str) -> IResult<&str, RsCaseItem> { let (s, _) = opt(symbol(":"))(s)?; let (s, x) = production_item(s)?; let (s, _) = symbol(";")(s)?; - Ok((s, RsCaseItem::Default(RsCaseItemDefault { item: x }))) + Ok((s, RsCaseItem::Default(RsCaseItemDefault { nodes: (x,) }))) } diff --git a/src/parser/behavioral_statements/statements.rs b/src/parser/behavioral_statements/statements.rs index d4cd79c..0e111f2 100644 --- a/src/parser/behavioral_statements/statements.rs +++ b/src/parser/behavioral_statements/statements.rs @@ -15,9 +15,11 @@ pub enum StatementOrNull<'a> { #[derive(Debug)] pub struct Statement<'a> { - pub identifier: Option>, - pub attribute: Vec>, - pub item: StatementItem<'a>, + pub nodes: ( + Option>, + Vec>, + StatementItem<'a>, + ), } #[derive(Debug)] @@ -44,6 +46,22 @@ pub enum StatementItem<'a> { ExpectPropertyStatement(Box>), } +#[derive(Debug)] +pub struct FunctionStatement<'a> { + pub nodes: (Statement<'a>,), +} + +#[derive(Debug)] +pub enum FunctionStatementOrNull<'a> { + Statement(FunctionStatement<'a>), + Attribute(Vec>), +} + +#[derive(Debug)] +pub struct VariableIdentifierList<'a> { + pub nodes: (Vec>,), +} + // ----------------------------------------------------------------------------- pub fn statement_or_null(s: &str) -> IResult<&str, StatementOrNull> { @@ -59,14 +77,7 @@ pub fn statement(s: &str) -> IResult<&str, Statement> { let (s, x) = opt(terminated(block_identifier, symbol(":")))(s)?; let (s, y) = many0(attribute_instance)(s)?; let (s, z) = statement_item(s)?; - Ok(( - s, - Statement { - identifier: x, - attribute: y, - item: z, - }, - )) + Ok((s, Statement { nodes: (x, y, z) })) } pub fn statement_item(s: &str) -> IResult<&str, StatementItem> { @@ -129,14 +140,23 @@ pub fn statement_item(s: &str) -> IResult<&str, StatementItem> { ))(s) } -pub fn function_statement(s: &str) -> IResult<&str, Statement> { - statement(s) +pub fn function_statement(s: &str) -> IResult<&str, FunctionStatement> { + let (s, x) = statement(s)?; + Ok((s, FunctionStatement { nodes: (x,) })) } -pub fn function_statement_or_null(s: &str) -> IResult<&str, StatementOrNull> { - statement_or_null(s) +pub fn function_statement_or_null(s: &str) -> IResult<&str, FunctionStatementOrNull> { + alt(( + map(function_statement, |x| { + FunctionStatementOrNull::Statement(x) + }), + map(terminated(many0(attribute_instance), symbol(";")), |x| { + FunctionStatementOrNull::Attribute(x) + }), + ))(s) } -pub fn variable_identifier_list(s: &str) -> IResult<&str, Vec> { - separated_nonempty_list(symbol(","), variable_identifier)(s) +pub fn variable_identifier_list(s: &str) -> IResult<&str, VariableIdentifierList> { + let (s, x) = separated_nonempty_list(symbol(","), variable_identifier)(s)?; + Ok((s, VariableIdentifierList { nodes: (x,) })) } diff --git a/src/parser/behavioral_statements/timing_control_statements.rs b/src/parser/behavioral_statements/timing_control_statements.rs index 4334ba0..0143581 100644 --- a/src/parser/behavioral_statements/timing_control_statements.rs +++ b/src/parser/behavioral_statements/timing_control_statements.rs @@ -9,8 +9,7 @@ use nom::IResult; #[derive(Debug)] pub struct ProceduralTimingControlStatement<'a> { - pub control: ProceduralTimingControl<'a>, - pub statement: StatementOrNull<'a>, + pub nodes: (ProceduralTimingControl<'a>, StatementOrNull<'a>), } #[derive(Debug)] @@ -22,8 +21,7 @@ pub enum DelayOrEventControl<'a> { #[derive(Debug)] pub struct DelayOrEventControlRepeat<'a> { - pub expression: Expression<'a>, - pub control: EventControl<'a>, + pub nodes: (Expression<'a>, EventControl<'a>), } #[derive(Debug)] @@ -34,10 +32,10 @@ pub enum DelayControl<'a> { #[derive(Debug)] pub enum EventControl<'a> { - EventIdentifier(HierarchicalIdentifier<'a>), + EventIdentifier(HierarchicalEventIdentifier<'a>), EventExpression(EventExpression<'a>), Asterisk, - SequenceIdentifier(ScopedIdentifier<'a>), + SequenceIdentifier(PsOrHierarchicalSequenceIdentifier<'a>), } #[derive(Debug)] @@ -51,15 +49,16 @@ pub enum EventExpression<'a> { #[derive(Debug)] pub struct EventExpressionExpression<'a> { - pub edge: Option>, - pub expression: Expression<'a>, - pub iff: Option>, + pub nodes: ( + Option>, + Expression<'a>, + Option>, + ), } #[derive(Debug)] pub struct EventExpressionSequence<'a> { - pub instance: SequenceInstance<'a>, - pub iff: Option>, + pub nodes: (SequenceInstance<'a>, Option>), } #[derive(Debug)] @@ -78,7 +77,7 @@ pub enum JumpStatement<'a> { #[derive(Debug)] pub struct JumpStatementReturn<'a> { - pub expression: Option>, + pub nodes: (Option>,), } #[derive(Debug)] @@ -90,14 +89,12 @@ pub enum WaitStatement<'a> { #[derive(Debug)] pub struct WaitStatementWait<'a> { - pub expression: Expression<'a>, - pub statement: StatementOrNull<'a>, + pub nodes: (Expression<'a>, StatementOrNull<'a>), } #[derive(Debug)] pub struct WaitStatementOrder<'a> { - pub identifier: Vec>, - pub block: ActionBlock<'a>, + pub nodes: (Vec>, ActionBlock<'a>), } #[derive(Debug)] @@ -108,19 +105,21 @@ pub enum EventTrigger<'a> { #[derive(Debug)] pub struct EventTriggerNamed<'a> { - pub identifier: HierarchicalIdentifier<'a>, + pub nodes: (HierarchicalEventIdentifier<'a>,), } #[derive(Debug)] pub struct EventTriggerNonblocking<'a> { - pub control: Option>, - pub identifier: HierarchicalIdentifier<'a>, + pub nodes: ( + Option>, + HierarchicalEventIdentifier<'a>, + ), } #[derive(Debug)] pub enum DisableStatement<'a> { - Task(HierarchicalIdentifier<'a>), - Block(HierarchicalIdentifier<'a>), + Task(HierarchicalTaskIdentifier<'a>), + Block(HierarchicalBlockIdentifier<'a>), Fork, } @@ -131,13 +130,7 @@ pub fn procedural_timing_control_statement( ) -> IResult<&str, ProceduralTimingControlStatement> { let (s, x) = procedural_timing_control(s)?; let (s, y) = statement_or_null(s)?; - Ok(( - s, - ProceduralTimingControlStatement { - control: x, - statement: y, - }, - )) + Ok((s, ProceduralTimingControlStatement { nodes: (x, y) })) } pub fn delay_or_event_control(s: &str) -> IResult<&str, DelayOrEventControl> { @@ -156,10 +149,7 @@ pub fn delay_or_event_control_repeat(s: &str) -> IResult<&str, DelayOrEventContr let (s, y) = event_control(s)?; Ok(( s, - DelayOrEventControl::Repeat(DelayOrEventControlRepeat { - expression: x, - control: y, - }), + DelayOrEventControl::Repeat(DelayOrEventControlRepeat { nodes: (x, y) }), )) } @@ -231,11 +221,7 @@ pub fn event_expression_expression(s: &str) -> IResult<&str, EventExpression> { let (s, z) = opt(preceded(symbol("iff"), expression))(s)?; Ok(( s, - EventExpression::Expression(Box::new(EventExpressionExpression { - edge: x, - expression: y, - iff: z, - })), + EventExpression::Expression(Box::new(EventExpressionExpression { nodes: (x, y, z) })), )) } @@ -244,10 +230,7 @@ pub fn event_expression_sequence(s: &str) -> IResult<&str, EventExpression> { let (s, y) = opt(preceded(symbol("iff"), expression))(s)?; Ok(( s, - EventExpression::Sequence(Box::new(EventExpressionSequence { - instance: x, - iff: y, - })), + EventExpression::Sequence(Box::new(EventExpressionSequence { nodes: (x, y) })), )) } @@ -294,7 +277,7 @@ pub fn jump_statement_return(s: &str) -> IResult<&str, JumpStatement> { let (s, _) = symbol(";")(s)?; Ok(( s, - JumpStatement::Return(JumpStatementReturn { expression: x }), + JumpStatement::Return(JumpStatementReturn { nodes: (x,) }), )) } @@ -322,13 +305,7 @@ pub fn wait_statement_wait(s: &str) -> IResult<&str, WaitStatement> { let (s, _) = symbol("wait")(s)?; let (s, x) = paren(expression)(s)?; let (s, y) = statement_or_null(s)?; - Ok(( - s, - WaitStatement::Wait(WaitStatementWait { - expression: x, - statement: y, - }), - )) + Ok((s, WaitStatement::Wait(WaitStatementWait { nodes: (x, y) }))) } pub fn wait_statement_fork(s: &str) -> IResult<&str, WaitStatement> { @@ -347,10 +324,7 @@ pub fn wait_statement_order(s: &str) -> IResult<&str, WaitStatement> { let (s, y) = action_block(s)?; Ok(( s, - WaitStatement::Order(WaitStatementOrder { - identifier: x, - block: y, - }), + WaitStatement::Order(WaitStatementOrder { nodes: (x, y) }), )) } @@ -362,7 +336,7 @@ pub fn event_trigger_named(s: &str) -> IResult<&str, EventTrigger> { let (s, _) = symbol("->")(s)?; let (s, x) = hierarchical_event_identifier(s)?; let (s, _) = symbol(";")(s)?; - Ok((s, EventTrigger::Named(EventTriggerNamed { identifier: x }))) + Ok((s, EventTrigger::Named(EventTriggerNamed { nodes: (x,) }))) } pub fn event_trigger_nonblocking(s: &str) -> IResult<&str, EventTrigger> { @@ -372,10 +346,7 @@ pub fn event_trigger_nonblocking(s: &str) -> IResult<&str, EventTrigger> { let (s, _) = symbol(";")(s)?; Ok(( s, - EventTrigger::Nonblocking(EventTriggerNonblocking { - control: x, - identifier: y, - }), + EventTrigger::Nonblocking(EventTriggerNonblocking { nodes: (x, y) }), )) } diff --git a/src/parser/declarations/assertion_declarations.rs b/src/parser/declarations/assertion_declarations.rs new file mode 100644 index 0000000..6ccc0b2 --- /dev/null +++ b/src/parser/declarations/assertion_declarations.rs @@ -0,0 +1,750 @@ +use crate::parser::*; +//use nom::branch::*; +//use nom::combinator::*; +use nom::error::*; +use nom::{Err, IResult}; + +// ----------------------------------------------------------------------------- + +#[derive(Debug)] +pub enum ConcurrentAssertionItem<'a> { + Statement(ConcurrentAssertionItemStatement<'a>), + CheckerInstantiation(CheckerInstantiation<'a>), +} + +#[derive(Debug)] +pub struct ConcurrentAssertionItemStatement<'a> { + pub nodes: (Identifier<'a>, ConcurrentAssertionStatement<'a>), +} + +#[derive(Debug)] +pub enum ConcurrentAssertionStatement<'a> { + AssertProperty(AssertPropertyStatement<'a>), + AssumeProperty(AssumePropertyStatement<'a>), + CoverProperty(CoverPropertyStatement<'a>), + CoverSequence(CoverSequenceStatement<'a>), + RestrictProperty(RestrictPropertyStatement<'a>), +} + +#[derive(Debug)] +pub struct AssertPropertyStatement<'a> { + pub nodes: (PropertySpec<'a>, ActionBlock<'a>), +} + +#[derive(Debug)] +pub struct AssumePropertyStatement<'a> { + pub nodes: (PropertySpec<'a>, ActionBlock<'a>), +} + +#[derive(Debug)] +pub struct CoverPropertyStatement<'a> { + pub nodes: (PropertySpec<'a>, StatementOrNull<'a>), +} + +#[derive(Debug)] +pub struct ExpectPropertyStatement<'a> { + pub nodes: (PropertySpec<'a>, ActionBlock<'a>), +} + +#[derive(Debug)] +pub struct CoverSequenceStatement<'a> { + pub nodes: ( + Option>, + Option>, + SequenceExpr<'a>, + StatementOrNull<'a>, + ), +} + +#[derive(Debug)] +pub struct RestrictPropertyStatement<'a> { + pub nodes: (PropertySpec<'a>), +} + +#[derive(Debug)] +pub struct PropertyInstance<'a> { + pub nodes: (Identifier<'a>, Option>), +} + +#[derive(Debug)] +pub enum PropertyListOfArguments<'a> { + Ordered(PropertyListOfArgumentsOrdered<'a>), + Named(PropertyListOfArgumentsNamed<'a>), +} + +#[derive(Debug)] +pub struct PropertyListOfArgumentsOrdered<'a> { + pub nodes: ( + Vec>, + Vec<(Identifier<'a>, Option>)>, + ), +} + +#[derive(Debug)] +pub struct PropertyListOfArgumentsNamed<'a> { + pub nodes: (Vec<(Identifier<'a>, Option>)>,), +} + +#[derive(Debug)] +pub enum PropertyActualArg<'a> { + PropertyExpr(PropertyExpr<'a>), + SequenceActualArg(SequenceActualArg<'a>), +} + +#[derive(Debug)] +pub enum AssertionItemDeclaration<'a> { + PropertyDeclaration(PropertyDeclaration<'a>), + SequenceDeclaration(SequenceDeclaration<'a>), + LetDeclaration(LetDeclaration<'a>), +} + +#[derive(Debug)] +pub struct PropertyDeclaration<'a> { + pub nodes: ( + Identifier<'a>, + Option>, + Vec>, + PropertySpec<'a>, + ), +} + +#[derive(Debug)] +pub struct PropertyPortList<'a> { + pub nodes: (Vec>,), +} + +#[derive(Debug)] +pub struct PropertyPortItem<'a> { + pub nodes: ( + Vec>, + Option, + PropertyFormalType<'a>, + Identifier<'a>, + Vec>, + Option>, + ), +} + +#[derive(Debug)] +pub enum PropertyLvarPortDirection { + Input, +} + +#[derive(Debug)] +pub enum PropertyFormalType<'a> { + SequenceFormalType(SequenceFormalType<'a>), + Property, +} + +#[derive(Debug)] +pub struct PropertySpec<'a> { + pub nodes: ( + Option>, + Option>, + PropertyExpr<'a>, + ), +} + +#[derive(Debug)] +pub enum PropertyExpr<'a> { + SequenceExpr(SequenceExpr<'a>), + Strong(PropertyExprStrong<'a>), + Weak(PropertyExprWeak<'a>), + Paren(Box>), + Not(Box>), + Or(Box>), + And(Box>), + ImplicationOverlapped(Box>), + ImplicationNonoverlapped(Box>), + If(Box>), + Case(PropertyExprCase<'a>), + FollowedByOverlapped(Box>), + FollowedByNonoverlapped(Box>), + Nexttime(Box>), + SNexttime(Box>), + Always(Box>), + SAlways(Box>), + Eventually(Box>), + SEventually(Box>), + Until(Box>), + SUntil(Box>), + UntilWith(Box>), + SUntilWith(Box>), + Implies(Box>), + Iff(Box>), + AcceptOn(Box>), + RejectOn(Box>), + SyncAcceptOn(Box>), + SyncRejectOn(Box>), + PropertyInstance(Box>), + ClockingEvent(Box>), +} + +#[derive(Debug)] +pub struct PropertyExprStrong<'a> { + pub nodes: (SequenceExpr<'a>,), +} + +#[derive(Debug)] +pub struct PropertyExprWeak<'a> { + pub nodes: (SequenceExpr<'a>,), +} + +#[derive(Debug)] +pub struct PropertyExprParen<'a> { + pub nodes: (PropertyExpr<'a>,), +} + +#[derive(Debug)] +pub struct PropertyExprNot<'a> { + pub nodes: (PropertyExpr<'a>,), +} + +#[derive(Debug)] +pub struct PropertyExprOr<'a> { + pub nodes: (PropertyExpr<'a>, PropertyExpr<'a>), +} + +#[derive(Debug)] +pub struct PropertyExprAnd<'a> { + pub nodes: (PropertyExpr<'a>, PropertyExpr<'a>), +} + +#[derive(Debug)] +pub struct PropertyExprImplicationOverlapped<'a> { + pub nodes: (SequenceExpr<'a>, PropertyExpr<'a>), +} + +#[derive(Debug)] +pub struct PropertyExprImplicationNonoverlapped<'a> { + pub nodes: (SequenceExpr<'a>, PropertyExpr<'a>), +} + +#[derive(Debug)] +pub struct PropertyExprIf<'a> { + pub nodes: ( + ExpressionOrDist<'a>, + PropertyExpr<'a>, + Option>, + ), +} + +#[derive(Debug)] +pub struct PropertyExprCase<'a> { + pub nodes: (ExpressionOrDist<'a>, Vec>), +} + +#[derive(Debug)] +pub struct PropertyExprFollowedByOverlapped<'a> { + pub nodes: (SequenceExpr<'a>, PropertyExpr<'a>), +} + +#[derive(Debug)] +pub struct PropertyExprFollowedByNonoverlapped<'a> { + pub nodes: (SequenceExpr<'a>, PropertyExpr<'a>), +} + +#[derive(Debug)] +pub struct PropertyExprNexttime<'a> { + pub nodes: (Option>, PropertyExpr<'a>), +} + +#[derive(Debug)] +pub struct PropertyExprSNexttime<'a> { + pub nodes: (Option>, PropertyExpr<'a>), +} + +#[derive(Debug)] +pub struct PropertyExprAlways<'a> { + pub nodes: (Option>, PropertyExpr<'a>), +} + +#[derive(Debug)] +pub struct PropertyExprSAlways<'a> { + pub nodes: (Option>, PropertyExpr<'a>), +} + +#[derive(Debug)] +pub struct PropertyExprEventually<'a> { + pub nodes: (ConstantRange<'a>, PropertyExpr<'a>), +} + +#[derive(Debug)] +pub struct PropertyExprSEventually<'a> { + pub nodes: (Option>, PropertyExpr<'a>), +} + +#[derive(Debug)] +pub struct PropertyExprUntil<'a> { + pub nodes: (PropertyExpr<'a>, PropertyExpr<'a>), +} + +#[derive(Debug)] +pub struct PropertyExprSUntil<'a> { + pub nodes: (PropertyExpr<'a>, PropertyExpr<'a>), +} + +#[derive(Debug)] +pub struct PropertyExprUntilWith<'a> { + pub nodes: (PropertyExpr<'a>, PropertyExpr<'a>), +} + +#[derive(Debug)] +pub struct PropertyExprSUntilWith<'a> { + pub nodes: (PropertyExpr<'a>, PropertyExpr<'a>), +} + +#[derive(Debug)] +pub struct PropertyExprImplies<'a> { + pub nodes: (PropertyExpr<'a>, PropertyExpr<'a>), +} + +#[derive(Debug)] +pub struct PropertyExprIff<'a> { + pub nodes: (PropertyExpr<'a>, PropertyExpr<'a>), +} + +#[derive(Debug)] +pub struct PropertyExprAcceptOn<'a> { + pub nodes: (ExpressionOrDist<'a>, PropertyExpr<'a>), +} + +#[derive(Debug)] +pub struct PropertyExprRejectOn<'a> { + pub nodes: (ExpressionOrDist<'a>, PropertyExpr<'a>), +} + +#[derive(Debug)] +pub struct PropertyExprSyncAcceptOn<'a> { + pub nodes: (ExpressionOrDist<'a>, PropertyExpr<'a>), +} + +#[derive(Debug)] +pub struct PropertyExprSyncRejectOn<'a> { + pub nodes: (ExpressionOrDist<'a>, PropertyExpr<'a>), +} + +#[derive(Debug)] +pub struct PropertyExprClockingEvent<'a> { + pub nodes: (ClockingEvent<'a>, PropertyExpr<'a>), +} + +#[derive(Debug)] +pub enum PropertyCaseItem<'a> { + Nondefault(PropertyCaseItemNondefault<'a>), + Default(PropertyCaseItemDefault<'a>), +} + +#[derive(Debug)] +pub struct PropertyCaseItemNondefault<'a> { + pub nodes: (Vec>, PropertyExpr<'a>), +} + +#[derive(Debug)] +pub struct PropertyCaseItemDefault<'a> { + pub nodes: (PropertyExpr<'a>,), +} + +#[derive(Debug)] +pub struct SequenceDeclaration<'a> { + pub nodes: ( + Identifier<'a>, + Option>, + Vec>, + SequenceExpr<'a>, + Option>, + ), +} + +#[derive(Debug)] +pub struct SequencePortList<'a> { + pub nodes: (Vec>,), +} + +#[derive(Debug)] +pub struct SequencePortItem<'a> { + pub nodes: ( + Vec>, + Option, + SequenceFormalType<'a>, + Identifier<'a>, + Vec>, + Option>, + ), +} + +#[derive(Debug)] +pub enum SequenceLvarPortDirection { + Input, + Inout, + Output, +} + +#[derive(Debug)] +pub enum SequenceFormalType<'a> { + DataTypeOrImplicit(DataTypeOrImplicit<'a>), + Sequence, + Untyped, +} + +#[derive(Debug)] +pub enum SequenceExpr<'a> { + CycleDelayExpr(SequenceExprCycleDelayExpr<'a>), + ExprCycleDelayExpr(Box>), + Expression(SequenceExprExpression<'a>), + Instance(SequenceExprInstance<'a>), + Paren(Box>), + And(Box>), + Intersect(Box>), + Or(Box>), + FirstMatch(Box>), + Throughout(Box>), + Within(Box>), + ClockingEvent(Box>), +} + +#[derive(Debug)] +pub struct SequenceExprCycleDelayExpr<'a> { + pub nodes: (Vec<(CycleDelayRange<'a>, SequenceExpr<'a>)>,), +} + +#[derive(Debug)] +pub struct SequenceExprExprCycleDelayExpr<'a> { + pub nodes: ( + SequenceExpr<'a>, + Vec<(CycleDelayRange<'a>, SequenceExpr<'a>)>, + ), +} + +#[derive(Debug)] +pub struct SequenceExprExpression<'a> { + pub nodes: (ExpressionOrDist<'a>, Option>), +} + +#[derive(Debug)] +pub struct SequenceExprInstance<'a> { + pub nodes: (SequenceInstance<'a>, Option>), +} + +#[derive(Debug)] +pub struct SequenceExprParen<'a> { + pub nodes: ( + SequenceExpr<'a>, + Vec>, + Option>, + ), +} + +#[derive(Debug)] +pub struct SequenceExprAnd<'a> { + pub nodes: (SequenceExpr<'a>, SequenceExpr<'a>), +} + +#[derive(Debug)] +pub struct SequenceExprIntersect<'a> { + pub nodes: (SequenceExpr<'a>, SequenceExpr<'a>), +} + +#[derive(Debug)] +pub struct SequenceExprOr<'a> { + pub nodes: (SequenceExpr<'a>, SequenceExpr<'a>), +} + +#[derive(Debug)] +pub struct SequenceExprFirstMatch<'a> { + pub nodes: (SequenceExpr<'a>, Vec>), +} + +#[derive(Debug)] +pub struct SequenceExprThroughout<'a> { + pub nodes: (ExpressionOrDist<'a>, SequenceExpr<'a>), +} + +#[derive(Debug)] +pub struct SequenceExprWithin<'a> { + pub nodes: (SequenceExpr<'a>, SequenceExpr<'a>), +} + +#[derive(Debug)] +pub struct SequenceExprClockingEvent<'a> { + pub nodes: (ClockingEvent<'a>, SequenceExpr<'a>), +} + +#[derive(Debug)] +pub enum CycleDelayRange<'a> { + ConstantPrimary(ConstantPrimary<'a>), + CycleDelayConstRangeExpression(CycleDelayConstRangeExpression<'a>), + Asterisk, + Plus, +} + +#[derive(Debug)] +pub struct SequenceMethodCall<'a> { + pub nodes: (SequenceInstance<'a>, Identifier<'a>), +} + +#[derive(Debug)] +pub enum SequenceMatchItem<'a> { + OperatorAssignment(OperatorAssignment<'a>), + IncOrDecExpression(IncOrDecExpression<'a>), + SubroutineCall(SubroutineCall<'a>), +} + +#[derive(Debug)] +pub struct SequenceInstance<'a> { + pub nodes: (Identifier<'a>, Option>), +} + +#[derive(Debug)] +pub enum SequenceListOfArguments<'a> { + Ordered(SequenceListOfArgumentsOrdered<'a>), + Named(SequenceListOfArgumentsNamed<'a>), +} + +#[derive(Debug)] +pub struct SequenceListOfArgumentsOrdered<'a> { + pub nodes: ( + Vec>, + Vec<(Identifier<'a>, Option>)>, + ), +} + +#[derive(Debug)] +pub struct SequenceListOfArgumentsNamed<'a> { + pub nodes: (Vec<(Identifier<'a>, Option>)>,), +} + +#[derive(Debug)] +pub enum SequenceActualArg<'a> { + EventExpression(EventExpression<'a>), + SequenceExpr(SequenceExpr<'a>), +} + +#[derive(Debug)] +pub enum BooleanAbbrev<'a> { + ConsecutiveRepetition(ConsecutiveRepetition<'a>), + NonConsecutiveRepetition(NonConsecutiveRepetition<'a>), + GotoRepetition(GotoRepetition<'a>), +} + +#[derive(Debug)] +pub struct SequenceAbbrev<'a> { + pub nodes: (ConsecutiveRepetition<'a>,), +} + +#[derive(Debug)] +pub enum ConsecutiveRepetition<'a> { + ConstOrRangeExpression(ConstOrRangeExpression<'a>), + Asterisk, + Plus, +} + +#[derive(Debug)] +pub struct NonConsecutiveRepetition<'a> { + pub nodes: (ConstOrRangeExpression<'a>,), +} + +#[derive(Debug)] +pub struct GotoRepetition<'a> { + pub nodes: (ConstOrRangeExpression<'a>,), +} + +#[derive(Debug)] +pub enum ConstOrRangeExpression<'a> { + ConstantExpression(ConstantExpression<'a>), + CycleDelayConstRangeExpression(CycleDelayConstRangeExpression<'a>), +} + +#[derive(Debug)] +pub enum CycleDelayConstRangeExpression<'a> { + Binary(CycleDelayConstRangeExpressionBinary<'a>), + Dollar(CycleDelayConstRangeExpressionDollar<'a>), +} + +#[derive(Debug)] +pub struct CycleDelayConstRangeExpressionBinary<'a> { + pub nodes: (ConstantExpression<'a>, ConstantExpression<'a>), +} + +#[derive(Debug)] +pub struct CycleDelayConstRangeExpressionDollar<'a> { + pub nodes: (ConstantExpression<'a>,), +} + +#[derive(Debug)] +pub struct ExpressionOrDist<'a> { + pub nodes: (Expression<'a>, Option>), +} + +#[derive(Debug)] +pub struct AssertionVariableDeclaration<'a> { + pub nodes: (VarDataType<'a>, ListOfVariableDeclAssignments<'a>), +} + +// ----------------------------------------------------------------------------- + +pub fn concurrent_assertion_item(s: &str) -> IResult<&str, ConcurrentAssertionItem> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn concurrent_assertion_statement(s: &str) -> IResult<&str, ConcurrentAssertionStatement> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn assert_property_statement(s: &str) -> IResult<&str, AssertPropertyStatement> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn assume_property_statement(s: &str) -> IResult<&str, AssumePropertyStatement> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn cover_property_statement(s: &str) -> IResult<&str, CoverPropertyStatement> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn expect_property_statement(s: &str) -> IResult<&str, ExpectPropertyStatement> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn cover_sequence_statement(s: &str) -> IResult<&str, CoverSequenceStatement> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn restrict_property_statement(s: &str) -> IResult<&str, RestrictPropertyStatement> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn property_instance(s: &str) -> IResult<&str, PropertyInstance> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn property_list_of_arguments(s: &str) -> IResult<&str, PropertyListOfArguments> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn property_actual_arg(s: &str) -> IResult<&str, PropertyActualArg> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn assertion_item_declaration(s: &str) -> IResult<&str, AssertionItemDeclaration> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn property_declaration(s: &str) -> IResult<&str, PropertyDeclaration> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn property_port_list(s: &str) -> IResult<&str, PropertyPortList> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn property_port_item(s: &str) -> IResult<&str, PropertyPortItem> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn property_lvar_port_direction(s: &str) -> IResult<&str, PropertyLvarPortDirection> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn property_formal_type(s: &str) -> IResult<&str, PropertyFormalType> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn property_spec(s: &str) -> IResult<&str, PropertySpec> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn property_expr(s: &str) -> IResult<&str, PropertyExpr> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn property_case_item(s: &str) -> IResult<&str, PropertyCaseItem> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn sequence_declaration(s: &str) -> IResult<&str, SequenceDeclaration> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn sequence_port_list(s: &str) -> IResult<&str, SequencePortList> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn sequence_port_item(s: &str) -> IResult<&str, SequencePortItem> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn sequence_lvar_port_direction(s: &str) -> IResult<&str, SequenceLvarPortDirection> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn sequence_formal_type(s: &str) -> IResult<&str, SequenceFormalType> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn sequence_expr(s: &str) -> IResult<&str, SequenceExpr> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn cycle_delay_range(s: &str) -> IResult<&str, CycleDelayRange> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn sequence_method_call(s: &str) -> IResult<&str, SequenceMethodCall> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn sequence_match_item(s: &str) -> IResult<&str, SequenceMatchItem> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn sequence_instance(s: &str) -> IResult<&str, SequenceInstance> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn sequence_list_of_arguments(s: &str) -> IResult<&str, SequenceListOfArguments> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn sequence_actual_arg(s: &str) -> IResult<&str, SequenceActualArg> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn boolean_abbrev(s: &str) -> IResult<&str, BooleanAbbrev> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn sequence_abbrev(s: &str) -> IResult<&str, SequenceAbbrev> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn consecutive_repetition(s: &str) -> IResult<&str, ConsecutiveRepetition> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn non_consecutive_repetition(s: &str) -> IResult<&str, NonConsecutiveRepetition> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn goto_repetition(s: &str) -> IResult<&str, GotoRepetition> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn const_or_range_expression(s: &str) -> IResult<&str, ConstOrRangeExpression> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn cycle_delay_const_range_expression( + s: &str, +) -> IResult<&str, CycleDelayConstRangeExpression> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn expression_or_dist(s: &str) -> IResult<&str, ExpressionOrDist> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn assertion_variable_declaration(s: &str) -> IResult<&str, AssertionVariableDeclaration> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} diff --git a/src/parser/declarations/block_item_declarations.rs b/src/parser/declarations/block_item_declarations.rs new file mode 100644 index 0000000..fe24bf2 --- /dev/null +++ b/src/parser/declarations/block_item_declarations.rs @@ -0,0 +1,41 @@ +use crate::parser::*; +//use nom::branch::*; +//use nom::combinator::*; +use nom::error::*; +use nom::{Err, IResult}; + +// ----------------------------------------------------------------------------- + +#[derive(Debug)] +pub enum BlockItemDeclaration<'a> { + Data(BlockItemDeclarationData<'a>), + LocalParameter(BlockItemDeclarationLocalParameter<'a>), + Parameter(BlockItemDeclarationParameter<'a>), + Let(BlockItemDeclarationLet<'a>), +} + +#[derive(Debug)] +pub struct BlockItemDeclarationData<'a> { + pub nodes: (Vec>, DataDeclaration<'a>), +} + +#[derive(Debug)] +pub struct BlockItemDeclarationLocalParameter<'a> { + pub nodes: (Vec>, LocalParameterDeclaration<'a>), +} + +#[derive(Debug)] +pub struct BlockItemDeclarationParameter<'a> { + pub nodes: (Vec>, ParameterDeclaration<'a>), +} + +#[derive(Debug)] +pub struct BlockItemDeclarationLet<'a> { + pub nodes: (Vec>, LetDeclaration<'a>), +} + +// ----------------------------------------------------------------------------- + +pub fn block_item_declaration(s: &str) -> IResult<&str, BlockItemDeclaration> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} diff --git a/src/parser/declarations/covergroup_declarations.rs b/src/parser/declarations/covergroup_declarations.rs new file mode 100644 index 0000000..b04f64c --- /dev/null +++ b/src/parser/declarations/covergroup_declarations.rs @@ -0,0 +1,575 @@ +use crate::parser::*; +//use nom::branch::*; +//use nom::combinator::*; +use nom::error::*; +use nom::{Err, IResult}; + +// ----------------------------------------------------------------------------- + +#[derive(Debug)] +pub struct CovergroupDeclaration<'a> { + pub nodes: ( + Identifier<'a>, + Option>, + Option>, + Vec>, + Identifier<'a>, + ), +} + +#[derive(Debug)] +pub enum CoverageSpecOrOption<'a> { + Spec(CoverageSpecOrOptionSpec<'a>), + Option(CoverageSpecOrOptionOption<'a>), +} + +#[derive(Debug)] +pub struct CoverageSpecOrOptionSpec<'a> { + pub nodes: (Vec>, CoverageSpec<'a>), +} + +#[derive(Debug)] +pub struct CoverageSpecOrOptionOption<'a> { + pub nodes: (Vec>, CoverageOption<'a>), +} + +#[derive(Debug)] +pub enum CoverageOption<'a> { + Option(CoverageOptionOption<'a>), + TypeOption(CoverageOptionTypeOption<'a>), +} + +#[derive(Debug)] +pub struct CoverageOptionOption<'a> { + pub nodes: (Identifier<'a>, Expression<'a>), +} + +#[derive(Debug)] +pub struct CoverageOptionTypeOption<'a> { + pub nodes: (Identifier<'a>, ConstantExpression<'a>), +} + +#[derive(Debug)] +pub enum CoverageSpec<'a> { + CoverPoint(CoverPoint<'a>), + CoverCross(CoverCross<'a>), +} + +#[derive(Debug)] +pub enum CoverageEvent<'a> { + ClockingEvent(ClockingEvent<'a>), + Sample(CoverageEventSample<'a>), + At(CoverageEventAt<'a>), +} + +#[derive(Debug)] +pub struct CoverageEventSample<'a> { + pub nodes: (Option>,), +} + +#[derive(Debug)] +pub struct CoverageEventAt<'a> { + pub nodes: (BlockEventExpression<'a>,), +} + +#[derive(Debug)] +pub enum BlockEventExpression<'a> { + Or(Box>), + Begin(BlockEventExpressionBegin<'a>), + End(BlockEventExpressionEnd<'a>), +} + +#[derive(Debug)] +pub struct BlockEventExpressionOr<'a> { + pub nodes: (BlockEventExpression<'a>, BlockEventExpression<'a>), +} + +#[derive(Debug)] +pub struct BlockEventExpressionBegin<'a> { + pub nodes: (HierarchicalBtfIdentifier<'a>,), +} + +#[derive(Debug)] +pub struct BlockEventExpressionEnd<'a> { + pub nodes: (HierarchicalBtfIdentifier<'a>,), +} + +#[derive(Debug)] +pub enum HierarchicalBtfIdentifier<'a> { + Tf(Identifier<'a>), + Block(Identifier<'a>), + Method(HierarchicalBtfIdentifierMethod<'a>), +} + +#[derive(Debug)] +pub struct HierarchicalBtfIdentifierMethod<'a> { + pub nodes: ( + Option>, + Identifier<'a>, + ), +} + +#[derive(Debug)] +pub enum HierarchicalIdentifierOrClassScope<'a> { + HierarchicalIdentifier(HierarchicalIdentifier<'a>), + ClassScope(ClassScope<'a>), +} + +#[derive(Debug)] +pub struct CoverPoint<'a> { + pub nodes: ( + Option<(Option>, Identifier<'a>)>, + Expression<'a>, + Option>, + BinsOrEmpty<'a>, + ), +} + +#[derive(Debug)] +pub enum BinsOrEmpty<'a> { + NonEmpty(BinsOrEmptyNonEmpty<'a>), + Empty, +} + +#[derive(Debug)] +pub struct BinsOrEmptyNonEmpty<'a> { + pub nodes: (Vec>, Vec>), +} + +#[derive(Debug)] +pub enum BinsOrOptions<'a> { + Option(CoverageOption<'a>), + Covergroup(BinsOrOptionsCovergroup<'a>), + CoverPoint(BinsOrOptionsCoverPoint<'a>), + SetCovergroup(BinsOrOptionsSetCovergroup<'a>), + TransList(BinsOrOptionsTransList<'a>), + Default(BinsOrOptionsDefault<'a>), + DefaultSequence(BinsOrOptionsDefaultSequence<'a>), +} + +#[derive(Debug)] +pub struct BinsOrOptionsCovergroup<'a> { + pub nodes: ( + Option, + BinsKeyword, + Identifier<'a>, + Option>, + CovergroupRangeList<'a>, + Option>, + Option>, + ), +} + +#[derive(Debug)] +pub struct Wildcard {} + +#[derive(Debug)] +pub struct BinsOrOptionsCoverPoint<'a> { + pub nodes: ( + Option, + BinsKeyword, + Identifier<'a>, + Option>, + Identifier<'a>, + Option>, + Option>, + ), +} + +#[derive(Debug)] +pub struct BinsOrOptionsSetCovergroup<'a> { + pub nodes: ( + Option, + BinsKeyword, + Identifier<'a>, + Option>, + SetCovergroupExpression<'a>, + Option>, + ), +} + +#[derive(Debug)] +pub struct BinsOrOptionsTransList<'a> { + pub nodes: ( + Option, + BinsKeyword, + Identifier<'a>, + TransList<'a>, + Option>, + ), +} + +#[derive(Debug)] +pub struct BinsOrOptionsDefault<'a> { + pub nodes: ( + BinsKeyword, + Identifier<'a>, + Option>, + Option>, + ), +} + +#[derive(Debug)] +pub struct BinsOrOptionsDefaultSequence<'a> { + pub nodes: (BinsKeyword, Identifier<'a>, Option>), +} + +#[derive(Debug)] +pub enum BinsKeyword { + Bins, + IllegalBins, + IgnoreBins, +} + +#[derive(Debug)] +pub struct TransList<'a> { + pub nodes: (Vec>,), +} + +#[derive(Debug)] +pub struct TransSet<'a> { + pub nodes: (TransRangeList<'a>, Vec>), +} + +#[derive(Debug)] +pub enum TransRangeList<'a> { + Single(TransItem<'a>), + Asterisk(TransRangeListAsterisk<'a>), + Right(TransRangeListRight<'a>), + Equal(TransRangeListEqual<'a>), +} + +#[derive(Debug)] +pub struct TransRangeListAsterisk<'a> { + pub nodes: (TransItem<'a>, RepeatRange<'a>), +} + +#[derive(Debug)] +pub struct TransRangeListRight<'a> { + pub nodes: (TransItem<'a>, RepeatRange<'a>), +} + +#[derive(Debug)] +pub struct TransRangeListEqual<'a> { + pub nodes: (TransItem<'a>, RepeatRange<'a>), +} + +#[derive(Debug)] +pub struct TransItem<'a> { + pub nodes: (CovergroupRangeList<'a>,), +} + +#[derive(Debug)] +pub enum RepeatRange<'a> { + Single(CovergroupExpression<'a>), + Binary(RepeatRangeBinary<'a>), +} + +#[derive(Debug)] +pub struct RepeatRangeBinary<'a> { + pub nodes: (CovergroupExpression<'a>, CovergroupExpression<'a>), +} + +#[derive(Debug)] +pub struct CoverCross<'a> { + pub nodes: ( + Option>, + ListOfCrossItems<'a>, + Option>, + CrossBody<'a>, + ), +} + +#[derive(Debug)] +pub struct ListOfCrossItems<'a> { + pub nodes: (CrossItem<'a>, CrossItem<'a>, Option>), +} + +#[derive(Debug)] +pub enum CrossItem<'a> { + CoverPointIdentifier(Identifier<'a>), + VariableIdentifier(Identifier<'a>), +} + +#[derive(Debug)] +pub enum CrossBody<'a> { + NonEmpty(CrossBodyNonEmpty<'a>), + Empty, +} + +#[derive(Debug)] +pub struct CrossBodyNonEmpty<'a> { + pub nodes: (Vec>), +} + +#[derive(Debug)] +pub enum CrossBodyItem<'a> { + FunctionDeclaration(FunctionDeclaration<'a>), + BinsSelectionOrOption(BinsSelectionOrOption<'a>), +} + +#[derive(Debug)] +pub enum BinsSelectionOrOption<'a> { + Coverage(BinsSelectionOrOptionCoverage<'a>), + Bins(BinsSelectionOrOptionBins<'a>), +} + +#[derive(Debug)] +pub struct BinsSelectionOrOptionCoverage<'a> { + pub nodes: (Vec>, CoverageOption<'a>), +} + +#[derive(Debug)] +pub struct BinsSelectionOrOptionBins<'a> { + pub nodes: (Vec>, BinsSelection<'a>), +} + +#[derive(Debug)] +pub struct BinsSelection<'a> { + pub nodes: ( + BinsKeyword, + Identifier<'a>, + SelectExpression<'a>, + Option>, + ), +} + +#[derive(Debug)] +pub enum SelectExpression<'a> { + SelectCondition(SelectCondition<'a>), + Not(SelectExpressionNot<'a>), + And(Box>), + Or(Box>), + Paren(Box>), + With(Box>), + CrossIdentifier(Identifier<'a>), + CrossSet(SelectExpressionCrossSet<'a>), +} + +#[derive(Debug)] +pub struct SelectExpressionNot<'a> { + pub nodes: (SelectCondition<'a>,), +} + +#[derive(Debug)] +pub struct SelectExpressionAnd<'a> { + pub nodes: (SelectExpression<'a>, SelectExpression<'a>), +} + +#[derive(Debug)] +pub struct SelectExpressionOr<'a> { + pub nodes: (SelectExpression<'a>, SelectExpression<'a>), +} + +#[derive(Debug)] +pub struct SelectExpressionParen<'a> { + pub nodes: (SelectExpression<'a>,), +} + +#[derive(Debug)] +pub struct SelectExpressionWith<'a> { + pub nodes: ( + SelectExpression<'a>, + WithCovergroupExpression<'a>, + Option>, + ), +} + +#[derive(Debug)] +pub struct SelectExpressionCrossSet<'a> { + pub nodes: ( + CrossSetExpression<'a>, + Option>, + ), +} + +#[derive(Debug)] +pub struct SelectCondition<'a> { + pub nodes: (BinsExpression<'a>, Option>), +} + +#[derive(Debug)] +pub enum BinsExpression<'a> { + VariableIdentifier(Identifier<'a>), + CoverPoint(BinsExpressionCoverPoint<'a>), +} + +#[derive(Debug)] +pub struct BinsExpressionCoverPoint<'a> { + pub nodes: (Identifier<'a>, Option>), +} + +#[derive(Debug)] +pub struct CovergroupRangeList<'a> { + pub nodes: (Vec>,), +} + +#[derive(Debug)] +pub enum CovergroupValueRange<'a> { + Single(CovergroupExpression<'a>), + Binary(CovergroupValueRangeBinary<'a>), +} + +#[derive(Debug)] +pub struct CovergroupValueRangeBinary<'a> { + pub nodes: (CovergroupExpression<'a>, CovergroupExpression<'a>), +} + +#[derive(Debug)] +pub struct WithCovergroupExpression<'a> { + pub nodes: (CovergroupExpression<'a>,), +} + +#[derive(Debug)] +pub struct SetCovergroupExpression<'a> { + pub nodes: (CovergroupExpression<'a>,), +} + +#[derive(Debug)] +pub struct IntegerCovergroupExpression<'a> { + pub nodes: (CovergroupExpression<'a>,), +} + +#[derive(Debug)] +pub struct CrossSetExpression<'a> { + pub nodes: (CovergroupExpression<'a>,), +} + +#[derive(Debug)] +pub struct CovergroupExpression<'a> { + pub nodes: (Expression<'a>,), +} + +// ----------------------------------------------------------------------------- + +pub fn covergroup_declaration(s: &str) -> IResult<&str, CovergroupDeclaration> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn coverage_spec_or_option(s: &str) -> IResult<&str, CoverageSpecOrOption> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn coverage_option(s: &str) -> IResult<&str, CoverageOption> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn coverage_spec(s: &str) -> IResult<&str, CoverageSpec> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn coverage_event(s: &str) -> IResult<&str, CoverageEvent> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn block_event_expression(s: &str) -> IResult<&str, BlockEventExpression> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn hierarchical_btf_identifier(s: &str) -> IResult<&str, HierarchicalBtfIdentifier> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn cover_point(s: &str) -> IResult<&str, CoverPoint> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn bins_or_empty(s: &str) -> IResult<&str, BinsOrEmpty> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn bins_or_options(s: &str) -> IResult<&str, BinsOrOptions> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn bins_keyword(s: &str) -> IResult<&str, BinsKeyword> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn trans_list(s: &str) -> IResult<&str, TransList> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn trans_set(s: &str) -> IResult<&str, TransSet> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn trans_range_list(s: &str) -> IResult<&str, TransRangeList> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn trans_item(s: &str) -> IResult<&str, TransItem> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn repeat_range(s: &str) -> IResult<&str, RepeatRange> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn cover_cross(s: &str) -> IResult<&str, CoverCross> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn list_of_cross_items(s: &str) -> IResult<&str, ListOfCrossItems> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn cross_item(s: &str) -> IResult<&str, CrossItem> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn cross_body(s: &str) -> IResult<&str, CrossBody> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn cross_body_item(s: &str) -> IResult<&str, CrossBodyItem> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn bins_selection_or_option(s: &str) -> IResult<&str, BinsSelectionOrOption> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn bins_selection(s: &str) -> IResult<&str, BinsSelection> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn select_expression(s: &str) -> IResult<&str, SelectExpression> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn select_condition(s: &str) -> IResult<&str, SelectCondition> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn bins_expression(s: &str) -> IResult<&str, BinsExpression> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn covergroup_range_list(s: &str) -> IResult<&str, CovergroupRangeList> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn covergroup_value_range(s: &str) -> IResult<&str, CovergroupValueRange> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn with_covergroup_expression(s: &str) -> IResult<&str, WithCovergroupExpression> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn set_covergroup_expression(s: &str) -> IResult<&str, SetCovergroupExpression> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn integer_covergroup_expression(s: &str) -> IResult<&str, IntegerCovergroupExpression> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn cross_set_expression(s: &str) -> IResult<&str, CrossSetExpression> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn covergroup_expression(s: &str) -> IResult<&str, CovergroupExpression> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} diff --git a/src/parser/declarations/declaration_assignments.rs b/src/parser/declarations/declaration_assignments.rs new file mode 100644 index 0000000..13bd28c --- /dev/null +++ b/src/parser/declarations/declaration_assignments.rs @@ -0,0 +1,166 @@ +use crate::parser::*; +//use nom::branch::*; +//use nom::combinator::*; +use nom::error::*; +use nom::{Err, IResult}; + +// ----------------------------------------------------------------------------- + +#[derive(Debug)] +pub struct DefparamAssignment<'a> { + pub nodes: (HierarchicalIdentifier<'a>, ConstantMintypmaxExpression<'a>), +} + +#[derive(Debug)] +pub struct NetDeclAssignment<'a> { + pub nodes: (Identifier<'a>, Vec>, Expression<'a>), +} + +#[derive(Debug)] +pub struct ParamAssignment<'a> { + pub nodes: ( + Identifier<'a>, + Vec>, + ConstantParamExpression<'a>, + ), +} + +#[derive(Debug)] +pub enum SpecparamAssignment<'a> { + Mintypmax(SpecparamAssignmentMintypmax<'a>), + PulseControl(PulseControlSpecparam<'a>), +} + +#[derive(Debug)] +pub struct SpecparamAssignmentMintypmax<'a> { + pub nodes: (Identifier<'a>, ConstantMintypmaxExpression<'a>), +} + +#[derive(Debug)] +pub struct TypeAssignment<'a> { + pub nodes: (Identifier<'a>, Option>), +} + +#[derive(Debug)] +pub struct PulseControlSpecparam<'a> { + pub nodes: ( + Option<( + SpecifyInputTerminalDescriptor<'a>, + SpecifyOutputTerminalDescriptor<'a>, + )>, + RejectLimitValue<'a>, + Option>, + ), +} + +#[derive(Debug)] +pub struct ErrorLimitValue<'a> { + pub nodes: (LimitValue<'a>,), +} + +#[derive(Debug)] +pub struct RejectLimitValue<'a> { + pub nodes: (LimitValue<'a>,), +} + +#[derive(Debug)] +pub struct LimitValue<'a> { + pub nodes: (ConstantMintypmaxExpression<'a>,), +} + +#[derive(Debug)] +pub enum VariableDeclAssignment<'a> { + Variable(VariableDeclAssignmentVariable<'a>), + DynamicArray(VariableDeclAssignmentDynamicArray<'a>), + Class(VariableDeclAssignmentClass<'a>), +} + +#[derive(Debug)] +pub struct VariableDeclAssignmentVariable<'a> { + pub nodes: ( + Identifier<'a>, + Vec>, + Option>, + ), +} + +#[derive(Debug)] +pub struct VariableDeclAssignmentDynamicArray<'a> { + pub nodes: ( + Identifier<'a>, + UnsizedDimension, + Vec>, + Option>, + ), +} + +#[derive(Debug)] +pub struct VariableDeclAssignmentClass<'a> { + pub nodes: (Identifier<'a>, Option>), +} + +#[derive(Debug)] +pub enum ClassNew<'a> { + Argument(ClassNewArgument<'a>), + Expression(Expression<'a>), +} + +#[derive(Debug)] +pub struct ClassNewArgument<'a> { + pub nodes: (Option>, Option>), +} + +#[derive(Debug)] +pub struct DynamicArrayNew<'a> { + pub nodes: (Expression<'a>, Option>), +} + +// ----------------------------------------------------------------------------- + +pub fn defparam_assignment(s: &str) -> IResult<&str, DefparamAssignment> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn net_decl_assignment(s: &str) -> IResult<&str, NetDeclAssignment> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn param_assignment(s: &str) -> IResult<&str, ParamAssignment> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn specparam_assignment(s: &str) -> IResult<&str, SpecparamAssignment> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn type_assignment(s: &str) -> IResult<&str, TypeAssignment> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn pulse_control_specparam(s: &str) -> IResult<&str, PulseControlSpecparam> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn error_limit_value(s: &str) -> IResult<&str, ErrorLimitValue> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn reject_limit_value(s: &str) -> IResult<&str, RejectLimitValue> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn limit_value(s: &str) -> IResult<&str, LimitValue> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn variable_decl_assignment(s: &str) -> IResult<&str, VariableDeclAssignment> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn class_new(s: &str) -> IResult<&str, ClassNew> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn dynamic_array_new(s: &str) -> IResult<&str, DynamicArrayNew> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} diff --git a/src/parser/declarations/declaration_lists.rs b/src/parser/declarations/declaration_lists.rs new file mode 100644 index 0000000..087b7a7 --- /dev/null +++ b/src/parser/declarations/declaration_lists.rs @@ -0,0 +1,138 @@ +use crate::parser::*; +//use nom::branch::*; +//use nom::combinator::*; +use nom::error::*; +use nom::{Err, IResult}; + +// ----------------------------------------------------------------------------- + +#[derive(Debug)] +pub struct ListOfDefparamAssignments<'a> { + pub nodes: (Vec>,), +} + +#[derive(Debug)] +pub struct ListOfGenvarIdentifiers<'a> { + pub nodes: (Vec>,), +} + +#[derive(Debug)] +pub struct ListOfInterfaceIdentifiers<'a> { + pub nodes: (Vec<(Identifier<'a>, Vec>)>,), +} + +#[derive(Debug)] +pub struct ListOfNetDeclAssignments<'a> { + pub nodes: (Vec>,), +} + +#[derive(Debug)] +pub struct ListOfParamAssignments<'a> { + pub nodes: (Vec>,), +} + +#[derive(Debug)] +pub struct ListOfPortIdentifiers<'a> { + pub nodes: (Vec<(Identifier<'a>, Vec>)>,), +} + +#[derive(Debug)] +pub struct ListOfUdpPortIdentifiers<'a> { + pub nodes: (Vec>,), +} + +#[derive(Debug)] +pub struct ListOfSpecparamAssignments<'a> { + pub nodes: (Vec>,), +} + +#[derive(Debug)] +pub struct ListOfTfVariableIdentifiers<'a> { + pub nodes: ( + Vec<( + Identifier<'a>, + Vec>, + Option>, + )>, + ), +} + +#[derive(Debug)] +pub struct ListOfTypeAssignments<'a> { + pub nodes: (Vec>,), +} + +#[derive(Debug)] +pub struct ListOfVariableDeclAssignments<'a> { + pub nodes: (Vec>,), +} + +#[derive(Debug)] +pub struct ListOfVariableIdentifiers<'a> { + pub nodes: (Vec<(Identifier<'a>, Vec>)>,), +} + +#[derive(Debug)] +pub struct ListOfVariablePortIdentifiers<'a> { + pub nodes: ( + Vec<( + Identifier<'a>, + Vec>, + Option>, + )>, + ), +} + +// ----------------------------------------------------------------------------- + +pub fn list_of_defparam_assignments(s: &str) -> IResult<&str, ListOfDefparamAssignments> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn list_of_genvar_identifiers(s: &str) -> IResult<&str, ListOfGenvarIdentifiers> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn list_of_interface_identifiers(s: &str) -> IResult<&str, ListOfInterfaceIdentifiers> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn list_of_net_decl_assignments(s: &str) -> IResult<&str, ListOfNetDeclAssignments> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn list_of_param_assignments(s: &str) -> IResult<&str, ListOfParamAssignments> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn list_of_port_identifiers(s: &str) -> IResult<&str, ListOfPortIdentifiers> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn list_of_udp_port_identifiers(s: &str) -> IResult<&str, ListOfUdpPortIdentifiers> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn list_of_specparam_assignments(s: &str) -> IResult<&str, ListOfSpecparamAssignments> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn list_of_tf_variable_identifiers(s: &str) -> IResult<&str, ListOfTfVariableIdentifiers> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn list_of_type_assignments(s: &str) -> IResult<&str, ListOfTypeAssignments> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn list_of_variable_decl_assignments(s: &str) -> IResult<&str, ListOfVariableDeclAssignments> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn list_of_variable_identifiers(s: &str) -> IResult<&str, ListOfVariableIdentifiers> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn list_of_variable_port_identifiers(s: &str) -> IResult<&str, ListOfVariablePortIdentifiers> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} diff --git a/src/parser/declarations/declaration_ranges.rs b/src/parser/declarations/declaration_ranges.rs new file mode 100644 index 0000000..86fe80c --- /dev/null +++ b/src/parser/declarations/declaration_ranges.rs @@ -0,0 +1,69 @@ +use crate::parser::*; +//use nom::branch::*; +//use nom::combinator::*; +use nom::error::*; +use nom::{Err, IResult}; + +// ----------------------------------------------------------------------------- + +#[derive(Debug)] +pub enum UnpackedDimension<'a> { + Range(ConstantRange<'a>), + Expression(ConstantExpression<'a>), +} + +#[derive(Debug)] +pub enum PackedDimension<'a> { + Range(ConstantRange<'a>), + Unsized(UnsizedDimension), +} + +#[derive(Debug)] +pub enum AssociativeDimension<'a> { + DataType(DataType<'a>), + Asterisk, +} + +#[derive(Debug)] +pub enum VariableDimension<'a> { + Unsized(UnsizedDimension), + Unpacked(UnpackedDimension<'a>), + Associative(AssociativeDimension<'a>), + Queue(QueueDimension<'a>), +} + +#[derive(Debug)] +pub struct QueueDimension<'a> { + pub nodes: (Option>,), +} + +#[derive(Debug)] +pub struct UnsizedDimension { + pub nodes: (), +} + +// ----------------------------------------------------------------------------- + +pub fn unpacked_dimension(s: &str) -> IResult<&str, UnpackedDimension> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn packed_dimension(s: &str) -> IResult<&str, PackedDimension> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn associative_dimension(s: &str) -> IResult<&str, AssociativeDimension> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn variable_dimension(s: &str) -> IResult<&str, VariableDimension> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn queue_dimension(s: &str) -> IResult<&str, QueueDimension> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn unsized_dimension(s: &str) -> IResult<&str, UnsizedDimension> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} diff --git a/src/parser/declarations/delays.rs b/src/parser/declarations/delays.rs new file mode 100644 index 0000000..0c5cf8a --- /dev/null +++ b/src/parser/declarations/delays.rs @@ -0,0 +1,55 @@ +use crate::parser::*; +//use nom::branch::*; +//use nom::combinator::*; +use nom::error::*; +use nom::{Err, IResult}; + +// ----------------------------------------------------------------------------- + +#[derive(Debug)] +pub enum Delay3<'a> { + DelayValue(DelayValue<'a>), + Mintypmax(Delay3Mintypmax<'a>), +} + +#[derive(Debug)] +pub struct Delay3Mintypmax<'a> { + pub nodes: ( + MintypmaxExpression<'a>, + Option<(MintypmaxExpression<'a>, Option>)>, + ), +} + +#[derive(Debug)] +pub enum Delay2<'a> { + DelayValue(DelayValue<'a>), + Mintypmax(Delay2Mintypmax<'a>), +} + +#[derive(Debug)] +pub struct Delay2Mintypmax<'a> { + pub nodes: (MintypmaxExpression<'a>, Option>), +} + +#[derive(Debug)] +pub enum DelayValue<'a> { + UnsignedNumber(&'a str), + RealNumber(RealNumber<'a>), + Identifier(Identifier<'a>), + TimeLiteral(TimeLiteral<'a>), + Step1, +} + +// ----------------------------------------------------------------------------- + +pub fn delay3(s: &str) -> IResult<&str, Delay3> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn delay2(s: &str) -> IResult<&str, Delay2> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn delay_value(s: &str) -> IResult<&str, DelayValue> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} diff --git a/src/parser/declarations/function_declarations.rs b/src/parser/declarations/function_declarations.rs new file mode 100644 index 0000000..2491138 --- /dev/null +++ b/src/parser/declarations/function_declarations.rs @@ -0,0 +1,161 @@ +use crate::parser::*; +//use nom::branch::*; +//use nom::combinator::*; +use nom::error::*; +use nom::{Err, IResult}; + +// ----------------------------------------------------------------------------- + +#[derive(Debug)] +pub enum FunctionDataTypeOrImplicit<'a> { + DataType(DataTypeOrVoid<'a>), + Implicit(ImplicitDataType<'a>), +} + +#[derive(Debug)] +pub struct FunctionDeclaration<'a> { + pub nodes: (Option, FunctionBodyDeclaration<'a>), +} + +#[derive(Debug)] +pub enum FunctionBodyDeclaration<'a> { + WithoutPort(FunctionBodyDeclarationWithoutPort<'a>), + WithPort(FunctionBodyDeclarationWithPort<'a>), +} + +#[derive(Debug)] +pub struct FunctionBodyDeclarationWithoutPort<'a> { + pub nodes: ( + FunctionDataTypeOrImplicit<'a>, + Option>, + Identifier<'a>, + Vec>, + Vec>, + Option>, + ), +} + +#[derive(Debug)] +pub struct FunctionBodyDeclarationWithPort<'a> { + pub nodes: ( + FunctionDataTypeOrImplicit<'a>, + Option>, + Identifier<'a>, + Option>, + Vec>, + Vec>, + Option>, + ), +} + +#[derive(Debug)] +pub struct FunctionPrototype<'a> { + pub nodes: (DataTypeOrVoid<'a>, Identifier<'a>, Option>), +} + +#[derive(Debug)] +pub enum DpiImportExport<'a> { + ImportFunction(DpiImportExportImportFunction<'a>), + ImportTask(DpiImportExportImportTask<'a>), + ExportFunction(DpiImportExportExportFunction<'a>), + ExportTask(DpiImportExportExportTask<'a>), +} + +#[derive(Debug)] +pub struct DpiImportExportImportFunction<'a> { + pub nodes: ( + DpiSpecString, + Option, + Option>, + DpiFunctionProto<'a>, + ), +} + +#[derive(Debug)] +pub struct DpiImportExportImportTask<'a> { + pub nodes: ( + DpiSpecString, + Option, + Option>, + DpiTaskProto<'a>, + ), +} + +#[derive(Debug)] +pub struct DpiImportExportExportFunction<'a> { + pub nodes: (DpiSpecString, Option>, Identifier<'a>), +} + +#[derive(Debug)] +pub struct DpiImportExportExportTask<'a> { + pub nodes: (DpiSpecString, Option>, Identifier<'a>), +} + +#[derive(Debug)] +pub enum DpiSpecString { + DpiC, + Dpi, +} + +#[derive(Debug)] +pub enum DpiFunctionImportProperty { + Context, + Pure, +} + +#[derive(Debug)] +pub enum DpiTaskImportProperty { + Context, +} + +#[derive(Debug)] +pub struct DpiFunctionProto<'a> { + pub nodes: (FunctionPrototype<'a>,), +} + +#[derive(Debug)] +pub struct DpiTaskProto<'a> { + pub nodes: (TaskPrototype<'a>,), +} + +// ----------------------------------------------------------------------------- + +pub fn function_data_type_or_implicit(s: &str) -> IResult<&str, FunctionDataTypeOrImplicit> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn function_declaration(s: &str) -> IResult<&str, FunctionDeclaration> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn function_body_declaration(s: &str) -> IResult<&str, FunctionBodyDeclaration> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn function_prototype(s: &str) -> IResult<&str, FunctionPrototype> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn dpi_import_export(s: &str) -> IResult<&str, DpiImportExport> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn dpi_spec_string(s: &str) -> IResult<&str, DpiSpecString> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn dpi_function_import_property(s: &str) -> IResult<&str, DpiFunctionImportProperty> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn dpi_task_import_property(s: &str) -> IResult<&str, DpiTaskImportProperty> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn dpi_function_proto(s: &str) -> IResult<&str, DpiFunctionProto> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn dpi_task_proto(s: &str) -> IResult<&str, DpiTaskProto> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} diff --git a/src/parser/declarations/interface_declarations.rs b/src/parser/declarations/interface_declarations.rs new file mode 100644 index 0000000..9e1ca52 --- /dev/null +++ b/src/parser/declarations/interface_declarations.rs @@ -0,0 +1,123 @@ +use crate::parser::*; +//use nom::branch::*; +//use nom::combinator::*; +use nom::error::*; +use nom::{Err, IResult}; + +// ----------------------------------------------------------------------------- + +#[derive(Debug)] +pub struct ModportDeclaration<'a> { + pub nodes: (Vec>,), +} + +#[derive(Debug)] +pub struct ModportItem<'a> { + pub nodes: (Identifier<'a>, Vec>), +} + +#[derive(Debug)] +pub enum ModportPortsDeclaraton<'a> { + Simple(ModportPortsDeclaratonSimple<'a>), + Tf(ModportPortsDeclaratonTf<'a>), + Clocing(ModportPortsDeclaratonClocking<'a>), +} + +#[derive(Debug)] +pub struct ModportPortsDeclaratonSimple<'a> { + pub nodes: ( + Vec>, + ModportSimplePortsDeclaration<'a>, + ), +} + +#[derive(Debug)] +pub struct ModportPortsDeclaratonTf<'a> { + pub nodes: (Vec>, ModportTfPortsDeclaration<'a>), +} + +#[derive(Debug)] +pub struct ModportPortsDeclaratonClocking<'a> { + pub nodes: (Vec>, ModportClockingDeclaration<'a>), +} + +#[derive(Debug)] +pub struct ModportClockingDeclaration<'a> { + pub nodes: (Identifier<'a>), +} + +#[derive(Debug)] +pub struct ModportSimplePortsDeclaration<'a> { + pub nodes: (PortDirection, Vec>), +} + +#[derive(Debug)] +pub enum ModportSimplePort<'a> { + Ordered(ModportSimplePortOrdered<'a>), + Named(ModportSimplePortNamed<'a>), +} + +#[derive(Debug)] +pub struct ModportSimplePortOrdered<'a> { + pub nodes: (Identifier<'a>,), +} + +#[derive(Debug)] +pub struct ModportSimplePortNamed<'a> { + pub nodes: (Identifier<'a>, Option>), +} + +#[derive(Debug)] +pub struct ModportTfPortsDeclaration<'a> { + pub nodes: (ImportExport, Vec>), +} + +#[derive(Debug)] +pub enum ModportTfPort<'a> { + Prototype(MethodPrototype<'a>), + Identifier(Identifier<'a>), +} + +#[derive(Debug)] +pub enum ImportExport { + Import, + Export, +} + +// ----------------------------------------------------------------------------- + +pub fn modport_declaration(s: &str) -> IResult<&str, ModportDeclaration> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn modport_item(s: &str) -> IResult<&str, ModportItem> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn modport_ports_declaration(s: &str) -> IResult<&str, ModportPortsDeclaraton> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn modport_clocking_declaration(s: &str) -> IResult<&str, ModportClockingDeclaration> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn modport_simple_ports_declaration(s: &str) -> IResult<&str, ModportSimplePortsDeclaration> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn modport_simple_port(s: &str) -> IResult<&str, ModportSimplePort> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn modport_tf_ports_declaration(s: &str) -> IResult<&str, ModportTfPortsDeclaration> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn modport_tf_port(s: &str) -> IResult<&str, ModportTfPort> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn import_export(s: &str) -> IResult<&str, ImportExport> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} diff --git a/src/parser/declarations/let_declarations.rs b/src/parser/declarations/let_declarations.rs new file mode 100644 index 0000000..f29610e --- /dev/null +++ b/src/parser/declarations/let_declarations.rs @@ -0,0 +1,106 @@ +use crate::parser::*; +//use nom::branch::*; +//use nom::combinator::*; +use nom::error::*; +use nom::{Err, IResult}; + +// ----------------------------------------------------------------------------- + +#[derive(Debug)] +pub struct LetDeclaration<'a> { + pub nodes: (LetIdentifier<'a>, Option>, Expression<'a>), +} + +#[derive(Debug)] +pub struct LetIdentifier<'a> { + pub nodes: (Identifier<'a>,), +} + +#[derive(Debug)] +pub struct LetPortList<'a> { + pub nodes: (Vec>,), +} + +#[derive(Debug)] +pub struct LetPortItem<'a> { + pub nodes: ( + Vec>, + LetFormalType<'a>, + Identifier<'a>, + Vec>, + Option>, + ), +} + +#[derive(Debug)] +pub enum LetFormalType<'a> { + DataTypeOrImplicit(DataTypeOrImplicit<'a>), + Untyped, +} + +#[derive(Debug)] +pub struct LetExpression<'a> { + pub nodes: ( + Option>, + LetIdentifier<'a>, + Option>, + ), +} + +#[derive(Debug)] +pub enum LetListOfArguments<'a> { + Ordered(LetListOfArgumentsOrdered<'a>), + Named(LetListOfArgumentsNamed<'a>), +} + +#[derive(Debug)] +pub struct LetListOfArgumentsOrdered<'a> { + pub nodes: ( + Vec>, + Vec<(Identifier<'a>, LetActualArg<'a>)>, + ), +} + +#[derive(Debug)] +pub struct LetListOfArgumentsNamed<'a> { + pub nodes: (Vec<(Identifier<'a>, LetActualArg<'a>)>,), +} + +#[derive(Debug)] +pub struct LetActualArg<'a> { + pub nodes: (Expression<'a>,), +} + +// ----------------------------------------------------------------------------- + +pub fn let_declaration(s: &str) -> IResult<&str, LetDeclaration> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn let_identifier(s: &str) -> IResult<&str, LetIdentifier> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn let_port_list(s: &str) -> IResult<&str, LetPortList> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn let_port_item(s: &str) -> IResult<&str, LetPortItem> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn let_formal_type(s: &str) -> IResult<&str, LetFormalType> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn let_expression(s: &str) -> IResult<&str, LetExpression> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn let_list_of_arguments(s: &str) -> IResult<&str, LetListOfArguments> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn let_actual_arg(s: &str) -> IResult<&str, LetActualArg> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} diff --git a/src/parser/declarations/mod.rs b/src/parser/declarations/mod.rs new file mode 100644 index 0000000..0fde675 --- /dev/null +++ b/src/parser/declarations/mod.rs @@ -0,0 +1,32 @@ +pub mod assertion_declarations; +pub mod block_item_declarations; +pub mod covergroup_declarations; +pub mod declaration_assignments; +pub mod declaration_lists; +pub mod declaration_ranges; +pub mod delays; +pub mod function_declarations; +pub mod interface_declarations; +pub mod let_declarations; +pub mod module_parameter_declarations; +pub mod net_and_variable_types; +pub mod port_declarations; +pub mod strengths; +pub mod task_declarations; +pub mod type_declarations; +pub use assertion_declarations::*; +pub use block_item_declarations::*; +pub use covergroup_declarations::*; +pub use declaration_assignments::*; +pub use declaration_lists::*; +pub use declaration_ranges::*; +pub use delays::*; +pub use function_declarations::*; +pub use interface_declarations::*; +pub use let_declarations::*; +pub use module_parameter_declarations::*; +pub use net_and_variable_types::*; +pub use port_declarations::*; +pub use strengths::*; +pub use task_declarations::*; +pub use type_declarations::*; diff --git a/src/parser/declarations/module_parameter_declarations.rs b/src/parser/declarations/module_parameter_declarations.rs new file mode 100644 index 0000000..98b5352 --- /dev/null +++ b/src/parser/declarations/module_parameter_declarations.rs @@ -0,0 +1,104 @@ +use crate::parser::*; +use nom::branch::*; +use nom::combinator::*; +use nom::IResult; + +// ----------------------------------------------------------------------------- + +#[derive(Debug)] +pub enum LocalParameterDeclaration<'a> { + Param(LocalParameterDeclarationParam<'a>), + Type(LocalParameterDeclarationType<'a>), +} + +#[derive(Debug)] +pub struct LocalParameterDeclarationParam<'a> { + pub nodes: (DataTypeOrImplicit<'a>, ListOfParamAssignments<'a>), +} + +#[derive(Debug)] +pub struct LocalParameterDeclarationType<'a> { + pub nodes: (ListOfTypeAssignments<'a>,), +} + +#[derive(Debug)] +pub enum ParameterDeclaration<'a> { + Param(ParameterDeclarationParam<'a>), + Type(ParameterDeclarationType<'a>), +} + +#[derive(Debug)] +pub struct ParameterDeclarationParam<'a> { + pub nodes: (DataTypeOrImplicit<'a>, ListOfParamAssignments<'a>), +} + +#[derive(Debug)] +pub struct ParameterDeclarationType<'a> { + pub nodes: (ListOfTypeAssignments<'a>,), +} + +#[derive(Debug)] +pub struct SpecparamDeclaration<'a> { + pub nodes: (Option>, ListOfSpecparamAssignments<'a>), +} + +// ----------------------------------------------------------------------------- + +pub fn local_parameter_declaration(s: &str) -> IResult<&str, LocalParameterDeclaration> { + alt(( + local_parameter_declaration_param, + local_parameter_declaration_type, + ))(s) +} + +pub fn local_parameter_declaration_param(s: &str) -> IResult<&str, LocalParameterDeclaration> { + let (s, _) = symbol("localparam")(s)?; + let (s, x) = data_type_or_implicit(s)?; + let (s, y) = list_of_param_assignments(s)?; + Ok(( + s, + LocalParameterDeclaration::Param(LocalParameterDeclarationParam { nodes: (x, y) }), + )) +} + +pub fn local_parameter_declaration_type(s: &str) -> IResult<&str, LocalParameterDeclaration> { + let (s, _) = symbol("localparam")(s)?; + let (s, _) = symbol("type")(s)?; + let (s, x) = list_of_type_assignments(s)?; + Ok(( + s, + LocalParameterDeclaration::Type(LocalParameterDeclarationType { nodes: (x,) }), + )) +} + +pub fn parameter_declaration(s: &str) -> IResult<&str, ParameterDeclaration> { + alt((parameter_declaration_param, parameter_declaration_type))(s) +} + +pub fn parameter_declaration_param(s: &str) -> IResult<&str, ParameterDeclaration> { + let (s, _) = symbol("parameter")(s)?; + let (s, x) = data_type_or_implicit(s)?; + let (s, y) = list_of_param_assignments(s)?; + Ok(( + s, + ParameterDeclaration::Param(ParameterDeclarationParam { nodes: (x, y) }), + )) +} + +pub fn parameter_declaration_type(s: &str) -> IResult<&str, ParameterDeclaration> { + let (s, _) = symbol("parameter")(s)?; + let (s, _) = symbol("type")(s)?; + let (s, x) = list_of_type_assignments(s)?; + Ok(( + s, + ParameterDeclaration::Type(ParameterDeclarationType { nodes: (x,) }), + )) +} + +pub fn specparam_declaration(s: &str) -> IResult<&str, SpecparamDeclaration> { + let (s, _) = symbol("specparam")(s)?; + let (s, x) = opt(packed_dimension)(s)?; + let (s, y) = list_of_specparam_assignments(s)?; + let (s, _) = symbol(";")(s)?; + Ok((s, SpecparamDeclaration { nodes: (x, y) })) +} diff --git a/src/parser/declarations/net_and_variable_types.rs b/src/parser/declarations/net_and_variable_types.rs new file mode 100644 index 0000000..4d4e936 --- /dev/null +++ b/src/parser/declarations/net_and_variable_types.rs @@ -0,0 +1,344 @@ +use crate::parser::*; +//use nom::branch::*; +//use nom::combinator::*; +use nom::error::*; +use nom::{Err, IResult}; + +// ----------------------------------------------------------------------------- + +#[derive(Debug)] +pub enum CastingType<'a> { + SimpleType(Box>), + ConstantPrimary(Box>), + Signing(Box), + String, + Const, +} + +#[derive(Debug)] +pub enum DataType<'a> { + Vector(DataTypeVector<'a>), + Atom(DataTypeAtom), + NonIntegerType(NonIntegerType), + Union(DataTypeUnion<'a>), + Enum(DataTypeEnum<'a>), + String, + Chandle, + Virtual(DataTypeVirtual<'a>), + Type(DataTypeType<'a>), + ClassType(ClassType<'a>), + Event, + PsCovergroupIdentifier(PsCovergroupIdentifier<'a>), + TypeReference(Box>), +} + +#[derive(Debug)] +pub struct DataTypeVector<'a> { + pub nodes: (IntegerVectorType, Option, Vec>), +} + +#[derive(Debug)] +pub struct DataTypeAtom { + pub nodes: (IntegerAtomType, Option), +} + +#[derive(Debug)] +pub struct DataTypeUnion<'a> { + pub nodes: ( + StructUnion, + Option<(Packed, Option)>, + Vec>, + ), +} + +#[derive(Debug)] +pub struct Packed {} + +#[derive(Debug)] +pub struct DataTypeEnum<'a> { + pub nodes: ( + Option>, + Vec>, + Vec>, + ), +} + +#[derive(Debug)] +pub struct DataTypeVirtual<'a> { + pub nodes: ( + Option, + InterfaceIdentifier<'a>, + Option>, + Option>, + ), +} + +#[derive(Debug)] +pub struct Interface {} + +#[derive(Debug)] +pub struct DataTypeType<'a> { + pub nodes: ( + Option>, + TypeIdentifier<'a>, + Vec>, + ), +} + +#[derive(Debug)] +pub enum DataTypeOrImplicit<'a> { + DataType(DataType<'a>), + ImplicitDataType(ImplicitDataType<'a>), +} + +#[derive(Debug)] +pub struct ImplicitDataType<'a> { + pub nodes: (Option, Vec>), +} + +#[derive(Debug)] +pub enum EnumBaseType<'a> { + Atom(EnumBaseTypeAtom), + Vector(EnumBaseTypeVector<'a>), + Type(EnumBaseTypeType<'a>), +} + +#[derive(Debug)] +pub struct EnumBaseTypeAtom { + pub nodes: (IntegerAtomType, Option), +} + +#[derive(Debug)] +pub struct EnumBaseTypeVector<'a> { + pub nodes: ( + IntegerVectorType, + Option, + Option>, + ), +} + +#[derive(Debug)] +pub struct EnumBaseTypeType<'a> { + pub nodes: (Identifier<'a>, Option>), +} + +#[derive(Debug)] +pub struct EnumNameDeclaration<'a> { + pub nodes: ( + Identifier<'a>, + Option<(IntegralNumber<'a>, Option>)>, + Option>, + ), +} + +#[derive(Debug)] +pub struct ClassScope<'a> { + pub nodes: (ClassType<'a>,), +} + +#[derive(Debug)] +pub struct ClassType<'a> { + pub nodes: ( + Identifier<'a>, + Option>, + Vec<(Identifier<'a>, Option>)>, + ), +} + +#[derive(Debug)] +pub enum IntegerType { + Vector(IntegerVectorType), + Atom(IntegerAtomType), +} + +#[derive(Debug)] +pub enum IntegerAtomType { + Byte, + Shortint, + Int, + Longint, + Integer, + Time, +} + +#[derive(Debug)] +pub enum IntegerVectorType { + Bit, + Logic, + Reg, +} + +#[derive(Debug)] +pub enum NonIntegerType { + Shortreal, + Real, + Realtime, +} + +#[derive(Debug)] +pub enum NetType { + Supply0, + Supply1, + Tri, + Triand, + Trior, + Trireg, + Tri0, + Tri1, + Uwire, + Wire, + Wand, + Wor, +} + +#[derive(Debug)] +pub enum NetPortType<'a> { + DataType(NetPortTypeDataType<'a>), + NetType(Identifier<'a>), + Interconnect(ImplicitDataType<'a>), +} + +#[derive(Debug)] +pub struct NetPortTypeDataType<'a> { + pub nodes: (Option, DataTypeOrImplicit<'a>), +} + +#[derive(Debug)] +pub struct VariablePortType<'a> { + pub nodes: (VarDataType<'a>,), +} + +#[derive(Debug)] +pub enum VarDataType<'a> { + DataType(DataType<'a>), + DataTypeOrImplicit(DataTypeOrImplicit<'a>), +} + +#[derive(Debug)] +pub enum Signing { + Signed, + Unsigned, +} + +#[derive(Debug)] +pub enum SimpleType<'a> { + IntegerType(IntegerType), + NonNonIntegerType(IntegerType), + TypeIdentifier(Identifier<'a>), + ParameterIdentifier(Identifier<'a>), +} + +#[derive(Debug)] +pub struct StructUnionMember<'a> { + pub nodes: ( + Vec>, + Option, + DataTypeOrVoid<'a>, + ListOfVariableDeclAssignments<'a>, + ), +} + +#[derive(Debug)] +pub enum DataTypeOrVoid<'a> { + DataType(DataType<'a>), + Void, +} + +#[derive(Debug)] +pub enum StructUnion { + Struct, + Union, + UnionTagged, +} + +#[derive(Debug)] +pub enum TypeReference<'a> { + Expression(Expression<'a>), + DataType(DataType<'a>), +} + +// ----------------------------------------------------------------------------- + +pub fn casting_type(s: &str) -> IResult<&str, CastingType> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn data_type(s: &str) -> IResult<&str, DataType> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn data_type_or_implicit(s: &str) -> IResult<&str, DataTypeOrImplicit> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn implicit_data_type(s: &str) -> IResult<&str, ImplicitDataType> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn enum_base_type(s: &str) -> IResult<&str, EnumBaseType> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn enum_name_declaration(s: &str) -> IResult<&str, EnumNameDeclaration> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn class_scope(s: &str) -> IResult<&str, ClassScope> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn integer_type(s: &str) -> IResult<&str, IntegerType> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn integer_atom_type(s: &str) -> IResult<&str, IntegerAtomType> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn integer_vector_type(s: &str) -> IResult<&str, IntegerVectorType> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn non_integer_type(s: &str) -> IResult<&str, NonIntegerType> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn net_type(s: &str) -> IResult<&str, NetType> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn net_port_type(s: &str) -> IResult<&str, NetPortType> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn variable_port_type(s: &str) -> IResult<&str, VariablePortType> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn var_data_type(s: &str) -> IResult<&str, VarDataType> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn signing(s: &str) -> IResult<&str, Signing> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn simple_type(s: &str) -> IResult<&str, SimpleType> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn struct_union_member(s: &str) -> IResult<&str, StructUnionMember> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn data_type_or_void(s: &str) -> IResult<&str, DataTypeOrVoid> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn struct_union(s: &str) -> IResult<&str, StructUnion> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn type_reference(s: &str) -> IResult<&str, TypeReference> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} diff --git a/src/parser/declarations/port_declarations.rs b/src/parser/declarations/port_declarations.rs new file mode 100644 index 0000000..12bc037 --- /dev/null +++ b/src/parser/declarations/port_declarations.rs @@ -0,0 +1,129 @@ +use crate::parser::*; +use nom::branch::*; +use nom::combinator::*; +use nom::sequence::*; +use nom::IResult; + +// ----------------------------------------------------------------------------- + +#[derive(Debug)] +pub struct InoutDeclaration<'a> { + pub nodes: (NetPortType<'a>, ListOfPortIdentifiers<'a>), +} + +#[derive(Debug)] +pub enum InputDeclaration<'a> { + Net(InputDeclarationNet<'a>), + Variable(InputDeclarationVariable<'a>), +} + +#[derive(Debug)] +pub struct InputDeclarationNet<'a> { + pub nodes: (NetPortType<'a>, ListOfPortIdentifiers<'a>), +} + +#[derive(Debug)] +pub struct InputDeclarationVariable<'a> { + pub nodes: (VariablePortType<'a>, ListOfVariableIdentifiers<'a>), +} + +#[derive(Debug)] +pub enum OutputDeclaration<'a> { + Net(OutputDeclarationNet<'a>), + Variable(OutputDeclarationVariable<'a>), +} + +#[derive(Debug)] +pub struct OutputDeclarationNet<'a> { + pub nodes: (NetPortType<'a>, ListOfPortIdentifiers<'a>), +} + +#[derive(Debug)] +pub struct OutputDeclarationVariable<'a> { + pub nodes: (VariablePortType<'a>, ListOfVariableIdentifiers<'a>), +} + +#[derive(Debug)] +pub struct InterfacePortDeclaration<'a> { + pub nodes: ( + InterfaceIdentifier<'a>, + Option>, + ListOfInterfaceIdentifiers<'a>, + ), +} + +#[derive(Debug)] +pub struct RefDeclaration<'a> { + pub nodes: (VariablePortType<'a>, ListOfVariableIdentifiers<'a>), +} + +// ----------------------------------------------------------------------------- + +pub fn inout_declaratrion(s: &str) -> IResult<&str, InoutDeclaration> { + let (s, _) = symbol("inout")(s)?; + let (s, x) = net_port_type(s)?; + let (s, y) = list_of_port_identifiers(s)?; + Ok((s, InoutDeclaration { nodes: (x, y) })) +} + +pub fn input_declaratrion(s: &str) -> IResult<&str, InputDeclaration> { + alt((input_declaration_net, input_declaration_variable))(s) +} + +pub fn input_declaration_net(s: &str) -> IResult<&str, InputDeclaration> { + let (s, _) = symbol("input")(s)?; + let (s, x) = net_port_type(s)?; + let (s, y) = list_of_port_identifiers(s)?; + Ok(( + s, + InputDeclaration::Net(InputDeclarationNet { nodes: (x, y) }), + )) +} + +pub fn input_declaration_variable(s: &str) -> IResult<&str, InputDeclaration> { + let (s, _) = symbol("input")(s)?; + let (s, x) = variable_port_type(s)?; + let (s, y) = list_of_variable_identifiers(s)?; + Ok(( + s, + InputDeclaration::Variable(InputDeclarationVariable { nodes: (x, y) }), + )) +} + +pub fn output_declaratrion(s: &str) -> IResult<&str, OutputDeclaration> { + alt((output_declaration_net, output_declaration_variable))(s) +} + +pub fn output_declaration_net(s: &str) -> IResult<&str, OutputDeclaration> { + let (s, _) = symbol("output")(s)?; + let (s, x) = net_port_type(s)?; + let (s, y) = list_of_port_identifiers(s)?; + Ok(( + s, + OutputDeclaration::Net(OutputDeclarationNet { nodes: (x, y) }), + )) +} + +pub fn output_declaration_variable(s: &str) -> IResult<&str, OutputDeclaration> { + let (s, _) = symbol("output")(s)?; + let (s, x) = variable_port_type(s)?; + let (s, y) = list_of_variable_identifiers(s)?; + Ok(( + s, + OutputDeclaration::Variable(OutputDeclarationVariable { nodes: (x, y) }), + )) +} + +pub fn interface_port_declaration(s: &str) -> IResult<&str, InterfacePortDeclaration> { + let (s, x) = interface_identifier(s)?; + let (s, y) = opt(preceded(symbol("."), modport_identifier))(s)?; + let (s, z) = list_of_interface_identifiers(s)?; + Ok((s, InterfacePortDeclaration { nodes: (x, y, z) })) +} + +pub fn ref_declaration(s: &str) -> IResult<&str, RefDeclaration> { + let (s, _) = symbol("ref")(s)?; + let (s, x) = variable_port_type(s)?; + let (s, y) = list_of_variable_identifiers(s)?; + Ok((s, RefDeclaration { nodes: (x, y) })) +} diff --git a/src/parser/declarations/strengths.rs b/src/parser/declarations/strengths.rs new file mode 100644 index 0000000..4c89d86 --- /dev/null +++ b/src/parser/declarations/strengths.rs @@ -0,0 +1,58 @@ +//use crate::parser::*; +//use nom::branch::*; +//use nom::combinator::*; +use nom::error::*; +use nom::{Err, IResult}; + +// ----------------------------------------------------------------------------- + +#[derive(Debug)] +pub enum DriveStrength { + Strength01(Strength0, Strength1), + Strength10(Strength1, Strength0), + Strength0z(Strength0), + Strength1z(Strength1), + Strengthz0(Strength0), + Strengthz1(Strength1), +} + +#[derive(Debug)] +pub enum Strength0 { + Supply0, + Strong0, + Pull0, + Weak0, +} + +#[derive(Debug)] +pub enum Strength1 { + Supply1, + Strong1, + Pull1, + Weak1, +} + +#[derive(Debug)] +pub enum ChargeStrength { + Small, + Medium, + Large, +} + +// ----------------------------------------------------------------------------- + +pub fn drive_strength(s: &str) -> IResult<&str, DriveStrength> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn strength0(s: &str) -> IResult<&str, Strength0> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn strength1(s: &str) -> IResult<&str, Strength1> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn charge_strength(s: &str) -> IResult<&str, ChargeStrength> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} diff --git a/src/parser/declarations/task_declarations.rs b/src/parser/declarations/task_declarations.rs new file mode 100644 index 0000000..75b2732 --- /dev/null +++ b/src/parser/declarations/task_declarations.rs @@ -0,0 +1,129 @@ +use crate::parser::*; +//use nom::branch::*; +//use nom::combinator::*; +use nom::error::*; +use nom::{Err, IResult}; + +// ----------------------------------------------------------------------------- + +#[derive(Debug)] +pub struct TaskDeclaration<'a> { + pub nodes: (Option, TaskBodyDeclaration<'a>), +} + +#[derive(Debug)] +pub enum TaskBodyDeclaration<'a> { + WithoutPort(TaskBodyDeclarationWithoutPort<'a>), + WithPort(TaskBodyDeclarationWithPort<'a>), +} + +#[derive(Debug)] +pub struct TaskBodyDeclarationWithoutPort<'a> { + pub nodes: ( + Option>, + Identifier<'a>, + Vec>, + Vec>, + Option>, + ), +} + +#[derive(Debug)] +pub struct TaskBodyDeclarationWithPort<'a> { + pub nodes: ( + Option>, + Identifier<'a>, + Option>, + Vec>, + Vec>, + Option>, + ), +} + +#[derive(Debug)] +pub enum InterfaceIdentifierOrClassScope<'a> { + InterfaceIdentifier(InterfaceIdentifier<'a>), + ClassScope(ClassScope<'a>), +} + +#[derive(Debug)] +pub enum TfItemDeclaration<'a> { + Block(BlockItemDeclaration<'a>), + Port(TfPortDeclaration<'a>), +} + +#[derive(Debug)] +pub struct TfPortList<'a> { + pub nodes: (Vec>,), +} + +#[derive(Debug)] +pub struct TfPortItem<'a> { + pub nodes: ( + Vec>, + Option, + Option, + DataTypeOrImplicit<'a>, + Option<( + Identifier<'a>, + Vec>, + Option>, + )>, + ), +} + +#[derive(Debug)] +pub enum TfPortDirection { + PortDirection(PortDirection), + ConstRef, +} + +#[derive(Debug)] +pub struct TfPortDeclaration<'a> { + pub nodes: ( + Vec>, + TfPortDirection, + Option, + DataTypeOrImplicit<'a>, + ListOfTfVariableIdentifiers<'a>, + ), +} + +#[derive(Debug)] +pub struct TaskPrototype<'a> { + pub nodes: (Identifier<'a>, Option>), +} + +// ----------------------------------------------------------------------------- + +pub fn task_declaration(s: &str) -> IResult<&str, TaskDeclaration> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn task_body_declaration(s: &str) -> IResult<&str, TaskBodyDeclaration> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn tf_item_declaration(s: &str) -> IResult<&str, TfItemDeclaration> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn tf_port_list(s: &str) -> IResult<&str, TfPortList> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn tf_port_item(s: &str) -> IResult<&str, TfPortItem> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn tf_port_direction(s: &str) -> IResult<&str, TfPortDirection> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn tf_port_declaration(s: &str) -> IResult<&str, TfPortDeclaration> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn task_prototype(s: &str) -> IResult<&str, TaskPrototype> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} diff --git a/src/parser/declarations/type_declarations.rs b/src/parser/declarations/type_declarations.rs new file mode 100644 index 0000000..22b4059 --- /dev/null +++ b/src/parser/declarations/type_declarations.rs @@ -0,0 +1,435 @@ +use crate::parser::*; +use nom::branch::*; +use nom::combinator::*; +use nom::multi::*; +use nom::sequence::*; +use nom::IResult; + +// ----------------------------------------------------------------------------- + +#[derive(Debug)] +pub enum DataDeclaration<'a> { + Variable(DataDeclarationVariable<'a>), + Type(TypeDeclaration<'a>), + PackageImport(PackageImportDeclaration<'a>), + NetType(NetTypeDeclaration<'a>), +} + +#[derive(Debug)] +pub struct DataDeclarationVariable<'a> { + pub nodes: ( + Option, + Option, + Option, + DataTypeOrImplicit<'a>, + ListOfVariableDeclAssignments<'a>, + ), +} + +#[derive(Debug)] +pub struct Const {} + +#[derive(Debug)] +pub struct Var {} + +#[derive(Debug)] +pub struct PackageImportDeclaration<'a> { + pub nodes: (Vec>,), +} + +#[derive(Debug)] +pub enum PackageImportItem<'a> { + Identifier(PackageImportItemIdentifier<'a>), + Asterisk(PackageImportItemAsterisk<'a>), +} + +#[derive(Debug)] +pub struct PackageImportItemIdentifier<'a> { + pub nodes: (PackageIdentifier<'a>, Identifier<'a>), +} + +#[derive(Debug)] +pub struct PackageImportItemAsterisk<'a> { + pub nodes: (PackageIdentifier<'a>,), +} + +#[derive(Debug)] +pub enum PackageExportDeclaration<'a> { + Asterisk, + Item(Vec>), +} + +#[derive(Debug)] +pub struct GenvarDeclaration<'a> { + pub nodes: (ListOfGenvarIdentifiers<'a>,), +} + +#[derive(Debug)] +pub enum NetDeclaration<'a> { + NetType(NetDeclarationNetType<'a>), + NetTypeIdentifier(NetDeclarationNetTypeIdentifier<'a>), + Interconnect(NetDeclarationInterconnect<'a>), +} + +#[derive(Debug)] +pub struct NetDeclarationNetType<'a> { + pub nodes: ( + NetType, + Option, + Option, + DataTypeOrImplicit<'a>, + Option>, + ListOfNetDeclAssignments<'a>, + ), +} + +#[derive(Debug)] +pub enum Strength { + Drive(DriveStrength), + Charge(ChargeStrength), +} + +#[derive(Debug)] +pub enum VectorScalar { + Vectored, + Scalared, +} + +#[derive(Debug)] +pub struct NetDeclarationNetTypeIdentifier<'a> { + pub nodes: ( + NetTypeIdentifier<'a>, + Option>, + ListOfNetDeclAssignments<'a>, + ), +} + +#[derive(Debug)] +pub struct NetDeclarationInterconnect<'a> { + pub nodes: ( + ImplicitDataType<'a>, + Option>, + NetIdentifier<'a>, + Vec>, + Option<(NetIdentifier<'a>, Vec>)>, + ), +} + +#[derive(Debug)] +pub enum TypeDeclaration<'a> { + DataType(TypeDeclarationDataType<'a>), + Interface(TypeDeclarationInterface<'a>), + Reserved(TypeDeclarationReserved<'a>), +} + +#[derive(Debug)] +pub struct TypeDeclarationDataType<'a> { + pub nodes: (DataType<'a>, TypeIdentifier<'a>, Vec>), +} + +#[derive(Debug)] +pub struct TypeDeclarationInterface<'a> { + pub nodes: ( + InterfaceInstanceIdentifier<'a>, + ConstantBitSelect<'a>, + TypeIdentifier<'a>, + TypeIdentifier<'a>, + ), +} + +#[derive(Debug)] +pub struct TypeDeclarationReserved<'a> { + pub nodes: (TypeDeclarationKeyword, TypeIdentifier<'a>), +} + +#[derive(Debug)] +pub enum TypeDeclarationKeyword { + Enum, + Struct, + Union, + Class, + InterfaceClass, +} + +#[derive(Debug)] +pub enum NetTypeDeclaration<'a> { + DataType(NetTypeDeclarationDataType<'a>), + NetType(NetTypeDeclarationNetType<'a>), +} + +#[derive(Debug)] +pub struct NetTypeDeclarationDataType<'a> { + pub nodes: ( + DataType<'a>, + NetTypeIdentifier<'a>, + Option<(Option>, TfIdentifier<'a>)>, + ), +} + +#[derive(Debug)] +pub struct NetTypeDeclarationNetType<'a> { + pub nodes: ( + Option>, + NetTypeIdentifier<'a>, + NetTypeIdentifier<'a>, + ), +} + +#[derive(Debug)] +pub enum Lifetime { + Static, + Automatic, +} + +// ----------------------------------------------------------------------------- + +pub fn data_declaration(s: &str) -> IResult<&str, DataDeclaration> { + alt(( + data_declaration_variable, + map(type_declaration, |x| DataDeclaration::Type(x)), + map(package_import_declaration, |x| { + DataDeclaration::PackageImport(x) + }), + map(net_type_declaration, |x| DataDeclaration::NetType(x)), + ))(s) +} + +pub fn data_declaration_variable(s: &str) -> IResult<&str, DataDeclaration> { + let (s, x) = opt(symbol("const"))(s)?; + let (s, y) = opt(symbol("var"))(s)?; + let (s, z) = opt(lifetime)(s)?; + let (s, v) = data_type_or_implicit(s)?; + let (s, w) = list_of_variable_decl_assignments(s)?; + let (s, _) = symbol(";")(s)?; + Ok(( + s, + DataDeclaration::Variable(DataDeclarationVariable { + nodes: (x.map(|_| Const {}), y.map(|_| Var {}), z, v, w), + }), + )) +} + +pub fn package_import_declaration(s: &str) -> IResult<&str, PackageImportDeclaration> { + let (s, _) = symbol("import")(s)?; + let (s, x) = separated_nonempty_list(symbol(","), package_import_item)(s)?; + let (s, _) = symbol(";")(s)?; + Ok((s, PackageImportDeclaration { nodes: (x,) })) +} + +pub fn package_import_item(s: &str) -> IResult<&str, PackageImportItem> { + alt((package_import_item_identifier, package_import_item_asterisk))(s) +} + +pub fn package_import_item_identifier(s: &str) -> IResult<&str, PackageImportItem> { + let (s, x) = package_identifier(s)?; + let (s, _) = symbol("::")(s)?; + let (s, y) = identifier(s)?; + Ok(( + s, + PackageImportItem::Identifier(PackageImportItemIdentifier { nodes: (x, y) }), + )) +} + +pub fn package_import_item_asterisk(s: &str) -> IResult<&str, PackageImportItem> { + let (s, x) = package_identifier(s)?; + let (s, _) = symbol("::")(s)?; + let (s, _) = symbol("*")(s)?; + Ok(( + s, + PackageImportItem::Asterisk(PackageImportItemAsterisk { nodes: (x,) }), + )) +} + +pub fn package_export_declaration(s: &str) -> IResult<&str, PackageExportDeclaration> { + alt(( + package_export_declaration_asterisk, + package_export_declaration_item, + ))(s) +} + +pub fn package_export_declaration_asterisk(s: &str) -> IResult<&str, PackageExportDeclaration> { + let (s, _) = symbol("export")(s)?; + let (s, _) = symbol("*::*")(s)?; + let (s, _) = symbol(";")(s)?; + Ok((s, PackageExportDeclaration::Asterisk)) +} + +pub fn package_export_declaration_item(s: &str) -> IResult<&str, PackageExportDeclaration> { + let (s, _) = symbol("export")(s)?; + let (s, x) = separated_nonempty_list(symbol(","), package_import_item)(s)?; + let (s, _) = symbol(";")(s)?; + Ok((s, PackageExportDeclaration::Item(x))) +} + +pub fn genvar_declaration(s: &str) -> IResult<&str, GenvarDeclaration> { + let (s, _) = symbol("genvar")(s)?; + let (s, x) = list_of_genvar_identifiers(s)?; + Ok((s, GenvarDeclaration { nodes: (x,) })) +} + +pub fn net_declaration(s: &str) -> IResult<&str, NetDeclaration> { + alt(( + net_declaration_net_type, + net_declaration_net_type_identifier, + net_declaration_interconnect, + ))(s) +} + +pub fn net_declaration_net_type(s: &str) -> IResult<&str, NetDeclaration> { + let (s, x) = net_type(s)?; + let (s, y) = opt(strength)(s)?; + let (s, z) = opt(vector_scalar)(s)?; + let (s, v) = data_type_or_implicit(s)?; + let (s, w) = opt(delay3)(s)?; + let (s, u) = list_of_net_decl_assignments(s)?; + let (s, _) = symbol(";")(s)?; + Ok(( + s, + NetDeclaration::NetType(NetDeclarationNetType { + nodes: (x, y, z, v, w, u), + }), + )) +} + +pub fn strength(s: &str) -> IResult<&str, Strength> { + alt(( + map(drive_strength, |x| Strength::Drive(x)), + map(charge_strength, |x| Strength::Charge(x)), + ))(s) +} + +pub fn vector_scalar(s: &str) -> IResult<&str, VectorScalar> { + alt(( + map(symbol("vectored"), |_| VectorScalar::Vectored), + map(symbol("scalared"), |_| VectorScalar::Scalared), + ))(s) +} + +pub fn net_declaration_net_type_identifier(s: &str) -> IResult<&str, NetDeclaration> { + let (s, x) = net_type_identifier(s)?; + let (s, y) = opt(delay_control)(s)?; + let (s, z) = list_of_net_decl_assignments(s)?; + let (s, _) = symbol(";")(s)?; + Ok(( + s, + NetDeclaration::NetTypeIdentifier(NetDeclarationNetTypeIdentifier { nodes: (x, y, z) }), + )) +} + +pub fn net_declaration_interconnect(s: &str) -> IResult<&str, NetDeclaration> { + let (s, _) = symbol("interconnect")(s)?; + let (s, x) = implicit_data_type(s)?; + let (s, y) = opt(preceded(symbol("#"), delay_value))(s)?; + let (s, z) = net_identifier(s)?; + let (s, v) = many0(unpacked_dimension)(s)?; + let (s, w) = opt(preceded( + symbol(","), + pair(net_identifier, many0(unpacked_dimension)), + ))(s)?; + Ok(( + s, + NetDeclaration::Interconnect(NetDeclarationInterconnect { + nodes: (x, y, z, v, w), + }), + )) +} + +pub fn type_declaration(s: &str) -> IResult<&str, TypeDeclaration> { + alt(( + type_declaration_data_type, + type_declaration_interface, + type_declaration_reserved, + ))(s) +} + +pub fn type_declaration_data_type(s: &str) -> IResult<&str, TypeDeclaration> { + let (s, _) = symbol("typedef")(s)?; + let (s, x) = data_type(s)?; + let (s, y) = type_identifier(s)?; + let (s, z) = many0(variable_dimension)(s)?; + let (s, _) = symbol(";")(s)?; + Ok(( + s, + TypeDeclaration::DataType(TypeDeclarationDataType { nodes: (x, y, z) }), + )) +} + +pub fn type_declaration_interface(s: &str) -> IResult<&str, TypeDeclaration> { + let (s, _) = symbol("typedef")(s)?; + let (s, x) = interface_instance_identifier(s)?; + let (s, y) = constant_bit_select(s)?; + let (s, _) = symbol(".")(s)?; + let (s, z) = type_identifier(s)?; + let (s, v) = type_identifier(s)?; + let (s, _) = symbol(";")(s)?; + Ok(( + s, + TypeDeclaration::Interface(TypeDeclarationInterface { + nodes: (x, y, z, v), + }), + )) +} + +pub fn type_declaration_reserved(s: &str) -> IResult<&str, TypeDeclaration> { + let (s, _) = symbol("typedef")(s)?; + let (s, x) = type_declaration_keyword(s)?; + let (s, y) = type_identifier(s)?; + let (s, _) = symbol(";")(s)?; + Ok(( + s, + TypeDeclaration::Reserved(TypeDeclarationReserved { nodes: (x, y) }), + )) +} + +pub fn type_declaration_keyword(s: &str) -> IResult<&str, TypeDeclarationKeyword> { + alt(( + map(symbol("enum"), |_| TypeDeclarationKeyword::Enum), + map(symbol("struct"), |_| TypeDeclarationKeyword::Struct), + map(symbol("union"), |_| TypeDeclarationKeyword::Union), + map(symbol("class"), |_| TypeDeclarationKeyword::Class), + map(pair(symbol("interface"), symbol("class")), |_| { + TypeDeclarationKeyword::InterfaceClass + }), + ))(s) +} + +pub fn net_type_declaration(s: &str) -> IResult<&str, NetTypeDeclaration> { + alt(( + net_type_declaration_data_type, + net_type_declaration_net_type, + ))(s) +} + +pub fn net_type_declaration_data_type(s: &str) -> IResult<&str, NetTypeDeclaration> { + let (s, _) = symbol("nettype")(s)?; + let (s, x) = data_type(s)?; + let (s, y) = net_type_identifier(s)?; + let (s, z) = opt(preceded( + symbol("with"), + pair(opt(package_scope_or_class_scope), tf_identifier), + ))(s)?; + let (s, _) = symbol(";")(s)?; + Ok(( + s, + NetTypeDeclaration::DataType(NetTypeDeclarationDataType { nodes: (x, y, z) }), + )) +} + +pub fn net_type_declaration_net_type(s: &str) -> IResult<&str, NetTypeDeclaration> { + let (s, _) = symbol("nettype")(s)?; + let (s, x) = opt(package_scope_or_class_scope)(s)?; + let (s, y) = net_type_identifier(s)?; + let (s, z) = net_type_identifier(s)?; + let (s, _) = symbol(";")(s)?; + Ok(( + s, + NetTypeDeclaration::NetType(NetTypeDeclarationNetType { nodes: (x, y, z) }), + )) +} + +pub fn lifetime(s: &str) -> IResult<&str, Lifetime> { + alt(( + map(symbol("static"), |_| Lifetime::Static), + map(symbol("automatic"), |_| Lifetime::Automatic), + ))(s) +} diff --git a/src/parser/expressions/concatenations.rs b/src/parser/expressions/concatenations.rs index 2dce472..f16e298 100644 --- a/src/parser/expressions/concatenations.rs +++ b/src/parser/expressions/concatenations.rs @@ -9,42 +9,37 @@ use nom::IResult; #[derive(Debug)] pub struct Concatenation<'a> { - pub expression: Vec>, + pub nodes: (Vec>,), } #[derive(Debug)] pub struct ConstantConcatenation<'a> { - pub expression: Vec>, + pub nodes: (Vec>,), } #[derive(Debug)] pub struct ConstantMultipleConcatenation<'a> { - pub expression: ConstantExpression<'a>, - pub concatenation: ConstantConcatenation<'a>, + pub nodes: (ConstantExpression<'a>, ConstantConcatenation<'a>), } #[derive(Debug)] pub struct ModulePathConcatenation<'a> { - pub expression: Vec>, + pub nodes: (Vec>,), } #[derive(Debug)] pub struct ModulePathMultipleConcatenation<'a> { - pub expression: ConstantExpression<'a>, - pub concatenation: ModulePathConcatenation<'a>, + pub nodes: (ConstantExpression<'a>, ModulePathConcatenation<'a>), } #[derive(Debug)] pub struct MultipleConcatenation<'a> { - pub expression: Expression<'a>, - pub concatenation: Concatenation<'a>, + pub nodes: (Expression<'a>, Concatenation<'a>), } #[derive(Debug)] pub struct StreamingConcatenation<'a> { - pub operator: &'a str, - pub size: Option>, - pub concatenation: StreamConcatenation<'a>, + pub nodes: (Operator<'a>, Option>, StreamConcatenation<'a>), } #[derive(Debug)] @@ -55,32 +50,29 @@ pub enum SliceSize<'a> { #[derive(Debug)] pub struct StreamConcatenation<'a> { - pub expression: Vec>, + pub nodes: (Vec>,), } #[derive(Debug)] pub struct StreamExpression<'a> { - pub expression: Expression<'a>, - pub with: Option>, + pub nodes: (Expression<'a>, Option>), } #[derive(Debug)] pub struct ArrayRangeExpression<'a> { - pub arg0: Expression<'a>, - pub operator: Option<&'a str>, - pub arg1: Option>, + pub nodes: (Expression<'a>, Option>, Option>), } // ----------------------------------------------------------------------------- pub fn concatenation(s: &str) -> IResult<&str, Concatenation> { let (s, x) = brace(separated_nonempty_list(symbol(","), expression))(s)?; - Ok((s, Concatenation { expression: x })) + Ok((s, Concatenation { nodes: (x,) })) } pub fn constant_concatenation(s: &str) -> IResult<&str, ConstantConcatenation> { let (s, x) = brace(separated_nonempty_list(symbol(","), constant_expression))(s)?; - Ok((s, ConstantConcatenation { expression: x })) + Ok((s, ConstantConcatenation { nodes: (x,) })) } pub fn constant_multiple_concatenation(s: &str) -> IResult<&str, ConstantMultipleConcatenation> { @@ -88,18 +80,12 @@ pub fn constant_multiple_concatenation(s: &str) -> IResult<&str, ConstantMultipl let (s, x) = constant_expression(s)?; let (s, y) = constant_concatenation(s)?; let (s, _) = symbol("}")(s)?; - Ok(( - s, - ConstantMultipleConcatenation { - expression: x, - concatenation: y, - }, - )) + Ok((s, ConstantMultipleConcatenation { nodes: (x, y) })) } pub fn module_path_concatenation(s: &str) -> IResult<&str, ModulePathConcatenation> { let (s, x) = brace(separated_nonempty_list(symbol(","), module_path_expression))(s)?; - Ok((s, ModulePathConcatenation { expression: x })) + Ok((s, ModulePathConcatenation { nodes: (x,) })) } pub fn module_path_multiple_concatenation( @@ -109,13 +95,7 @@ pub fn module_path_multiple_concatenation( let (s, x) = constant_expression(s)?; let (s, y) = module_path_concatenation(s)?; let (s, _) = symbol("}")(s)?; - Ok(( - s, - ModulePathMultipleConcatenation { - expression: x, - concatenation: y, - }, - )) + Ok((s, ModulePathMultipleConcatenation { nodes: (x, y) })) } pub fn multiple_concatenation(s: &str) -> IResult<&str, MultipleConcatenation> { @@ -123,13 +103,7 @@ pub fn multiple_concatenation(s: &str) -> IResult<&str, MultipleConcatenation> { let (s, x) = expression(s)?; let (s, y) = concatenation(s)?; let (s, _) = symbol("}")(s)?; - Ok(( - s, - MultipleConcatenation { - expression: x, - concatenation: y, - }, - )) + Ok((s, MultipleConcatenation { nodes: (x, y) })) } pub fn streaming_concatenation(s: &str) -> IResult<&str, StreamingConcatenation> { @@ -138,18 +112,14 @@ pub fn streaming_concatenation(s: &str) -> IResult<&str, StreamingConcatenation> let (s, y) = opt(slice_size)(s)?; let (s, z) = stream_concatenation(s)?; let (s, _) = symbol("}")(s)?; - Ok(( - s, - StreamingConcatenation { - operator: x, - size: y, - concatenation: z, - }, - )) + Ok((s, StreamingConcatenation { nodes: (x, y, z) })) } -pub fn stream_operator(s: &str) -> IResult<&str, &str> { - alt((symbol(">>"), symbol("<<")))(s) +pub fn stream_operator(s: &str) -> IResult<&str, Operator> { + alt(( + map(symbol(">>"), |x| Operator { nodes: (x,) }), + map(symbol("<<"), |x| Operator { nodes: (x,) }), + ))(s) } pub fn slice_size(s: &str) -> IResult<&str, SliceSize> { @@ -161,40 +131,32 @@ pub fn slice_size(s: &str) -> IResult<&str, SliceSize> { pub fn stream_concatenation(s: &str) -> IResult<&str, StreamConcatenation> { let (s, x) = brace(separated_nonempty_list(symbol(","), stream_expression))(s)?; - Ok((s, StreamConcatenation { expression: x })) + Ok((s, StreamConcatenation { nodes: (x,) })) } pub fn stream_expression(s: &str) -> IResult<&str, StreamExpression> { let (s, x) = expression(s)?; let (s, y) = opt(preceded(symbol("with"), bracket(array_range_expression)))(s)?; - Ok(( - s, - StreamExpression { - expression: x, - with: y, - }, - )) + Ok((s, StreamExpression { nodes: (x, y) })) } pub fn array_range_expression(s: &str) -> IResult<&str, ArrayRangeExpression> { let (s, x) = expression(s)?; - let (s, y) = opt(pair( - alt((symbol(":"), symbol("+:"), symbol("-:"))), - expression, - ))(s)?; + let (s, y) = opt(pair(array_range_expression_operator, expression))(s)?; let (y, z) = if let Some((y, z)) = y { (Some(y), Some(z)) } else { (None, None) }; - Ok(( - s, - ArrayRangeExpression { - arg0: x, - operator: y, - arg1: z, - }, - )) + Ok((s, ArrayRangeExpression { nodes: (x, y, z) })) +} + +pub fn array_range_expression_operator(s: &str) -> IResult<&str, Operator> { + alt(( + map(symbol(":"), |x| Operator { nodes: (x,) }), + map(symbol("+:"), |x| Operator { nodes: (x,) }), + map(symbol("-:"), |x| Operator { nodes: (x,) }), + ))(s) } pub fn empty_unpacked_array_concatenation(s: &str) -> IResult<&str, ()> { diff --git a/src/parser/expressions/expression_leftside_values.rs b/src/parser/expressions/expression_leftside_values.rs index 08ff651..302b301 100644 --- a/src/parser/expressions/expression_leftside_values.rs +++ b/src/parser/expressions/expression_leftside_values.rs @@ -16,14 +16,15 @@ pub enum NetLvalue<'a> { #[derive(Debug)] pub struct NetLvalueIdentifier<'a> { - identifier: ScopedIdentifier<'a>, - select: ConstantSelect<'a>, + pub nodes: (PsOrHierarchicalNetIdentifier<'a>, ConstantSelect<'a>), } #[derive(Debug)] pub struct NetLvaluePattern<'a> { - r#type: Option>, - lvalue: AssignmentPatternNetLvalue<'a>, + pub nodes: ( + Option>, + AssignmentPatternNetLvalue<'a>, + ), } #[derive(Debug)] @@ -36,22 +37,28 @@ pub enum VariableLvalue<'a> { #[derive(Debug)] pub struct VariableLvalueIdentifier<'a> { - scope: Option>, - identifier: HierarchicalIdentifier<'a>, - select: Select<'a>, + pub nodes: ( + Option>, + HierarchicalVariableIdentifier<'a>, + Select<'a>, + ), } #[derive(Debug)] pub struct VariableLvaluePattern<'a> { - r#type: Option>, - lvalue: AssignmentPatternVariableLvalue<'a>, + pub nodes: ( + Option>, + AssignmentPatternVariableLvalue<'a>, + ), } #[derive(Debug)] pub struct NonrangeVariableLvalue<'a> { - scope: Option>, - identifier: HierarchicalIdentifier<'a>, - select: Select<'a>, + pub nodes: ( + Option>, + HierarchicalVariableIdentifier<'a>, + Select<'a>, + ), } // ----------------------------------------------------------------------------- @@ -65,10 +72,7 @@ pub fn net_lvalue_identifier(s: &str) -> IResult<&str, NetLvalue> { let (s, y) = constant_select(s)?; Ok(( s, - NetLvalue::Identifier(Box::new(NetLvalueIdentifier { - identifier: x, - select: y, - })), + NetLvalue::Identifier(Box::new(NetLvalueIdentifier { nodes: (x, y) })), )) } @@ -77,10 +81,7 @@ pub fn net_lvalue_pattern(s: &str) -> IResult<&str, NetLvalue> { let (s, y) = assignment_pattern_net_lvalue(s)?; Ok(( s, - NetLvalue::Pattern(Box::new(NetLvaluePattern { - r#type: x, - lvalue: y, - })), + NetLvalue::Pattern(Box::new(NetLvaluePattern { nodes: (x, y) })), )) } @@ -111,19 +112,12 @@ pub fn variable_lvalue(s: &str) -> IResult<&str, VariableLvalue> { } pub fn variable_lvalue_identifier(s: &str) -> IResult<&str, VariableLvalue> { - let (s, x) = opt(alt(( - terminated(implicit_class_handle, symbol(".")), - package_scope, - )))(s)?; + let (s, x) = opt(implicit_class_handle_or_package_scope)(s)?; let (s, y) = hierarchical_variable_identifier(s)?; let (s, z) = select(s)?; Ok(( s, - VariableLvalue::Identifier(Box::new(VariableLvalueIdentifier { - scope: x, - identifier: y, - select: z, - })), + VariableLvalue::Identifier(Box::new(VariableLvalueIdentifier { nodes: (x, y, z) })), )) } @@ -132,10 +126,7 @@ pub fn variable_lvalue_pattern(s: &str) -> IResult<&str, VariableLvalue> { let (s, y) = assignment_pattern_variable_lvalue(s)?; Ok(( s, - VariableLvalue::Pattern(Box::new(VariableLvaluePattern { - r#type: x, - lvalue: y, - })), + VariableLvalue::Pattern(Box::new(VariableLvaluePattern { nodes: (x, y) })), )) } @@ -155,20 +146,10 @@ pub fn variable_lvalue_lvalue(s: &str) -> IResult<&str, VariableLvalue> { } pub fn nonrange_variable_lvalue(s: &str) -> IResult<&str, NonrangeVariableLvalue> { - let (s, x) = opt(alt(( - terminated(implicit_class_handle, symbol(".")), - package_scope, - )))(s)?; + let (s, x) = opt(implicit_class_handle_or_package_scope)(s)?; let (s, y) = hierarchical_variable_identifier(s)?; let (s, z) = nonrange_select(s)?; - Ok(( - s, - NonrangeVariableLvalue { - scope: x, - identifier: y, - select: z, - }, - )) + Ok((s, NonrangeVariableLvalue { nodes: (x, y, z) })) } // ----------------------------------------------------------------------------- diff --git a/src/parser/expressions/expressions.rs b/src/parser/expressions/expressions.rs index 6e3a403..8266915 100644 --- a/src/parser/expressions/expressions.rs +++ b/src/parser/expressions/expressions.rs @@ -14,24 +14,22 @@ pub enum IncOrDecExpression<'a> { #[derive(Debug)] pub struct IncOrDecExpressionPrefix<'a> { - pub operator: Operator<'a>, - pub attribute: Vec>, - pub lvalue: VariableLvalue<'a>, + pub nodes: (Operator<'a>, Vec>, VariableLvalue<'a>), } #[derive(Debug)] pub struct IncOrDecExpressionSuffix<'a> { - pub lvalue: VariableLvalue<'a>, - pub attribute: Vec>, - pub operator: Operator<'a>, + pub nodes: (VariableLvalue<'a>, Vec>, Operator<'a>), } #[derive(Debug)] pub struct ConditionalExpression<'a> { - pub predicate: CondPredicate<'a>, - pub attribute: Vec>, - pub arg0: Expression<'a>, - pub arg1: Expression<'a>, + pub nodes: ( + CondPredicate<'a>, + Vec>, + Expression<'a>, + Expression<'a>, + ), } #[derive(Debug)] @@ -44,25 +42,31 @@ pub enum ConstantExpression<'a> { #[derive(Debug)] pub struct ConstantExpressionUnary<'a> { - pub operator: Operator<'a>, - pub attribute: Vec>, - pub arg0: ConstantPrimary<'a>, + pub nodes: ( + Operator<'a>, + Vec>, + ConstantPrimary<'a>, + ), } #[derive(Debug)] pub struct ConstantExpressionBinary<'a> { - pub arg0: ConstantExpression<'a>, - pub operator: Operator<'a>, - pub attribute: Vec>, - pub arg1: ConstantExpression<'a>, + pub nodes: ( + ConstantExpression<'a>, + Operator<'a>, + Vec>, + ConstantExpression<'a>, + ), } #[derive(Debug)] pub struct ConstantExpressionTernary<'a> { - pub predicate: ConstantExpression<'a>, - pub attribute: Vec>, - pub arg0: ConstantExpression<'a>, - pub arg1: ConstantExpression<'a>, + pub nodes: ( + ConstantExpression<'a>, + Vec>, + ConstantExpression<'a>, + ConstantExpression<'a>, + ), } #[derive(Debug)] @@ -99,8 +103,18 @@ pub enum ConstantRangeExpression<'a> { #[derive(Debug)] pub enum ConstantPartSelectRange<'a> { - Range((ConstantExpression<'a>, ConstantExpression<'a>)), - IndexedRange((ConstantExpression<'a>, &'a str, ConstantExpression<'a>)), + Range(ConstantRange<'a>), + IndexedRange(ConstantIndexedRange<'a>), +} + +#[derive(Debug)] +pub struct ConstantRange<'a> { + pub nodes: (ConstantExpression<'a>, ConstantExpression<'a>), +} + +#[derive(Debug)] +pub struct ConstantIndexedRange<'a> { + pub nodes: (ConstantExpression<'a>, Operator<'a>, ConstantExpression<'a>), } #[derive(Debug)] @@ -117,29 +131,27 @@ pub enum Expression<'a> { #[derive(Debug)] pub struct ExpressionUnary<'a> { - pub operator: Operator<'a>, - pub attribute: Vec>, - pub arg0: Primary<'a>, + pub nodes: (Operator<'a>, Vec>, Primary<'a>), } #[derive(Debug)] pub struct ExpressionBinary<'a> { - pub arg0: Expression<'a>, - pub operator: Operator<'a>, - pub attribute: Vec>, - pub arg1: Expression<'a>, + pub nodes: ( + Expression<'a>, + Operator<'a>, + Vec>, + Expression<'a>, + ), } #[derive(Debug)] pub struct TaggedUnionExpression<'a> { - pub identifier: Identifier<'a>, - pub expression: Option>, + pub nodes: (MemberIdentifier<'a>, Option>), } #[derive(Debug)] pub struct InsideExpression<'a> { - pub expression: Expression<'a>, - pub open_range_list: Vec>, + pub nodes: (Expression<'a>, Vec>), } #[derive(Debug)] @@ -156,10 +168,12 @@ pub enum MintypmaxExpression<'a> { #[derive(Debug)] pub struct ModulePathConditionalExpression<'a> { - pub predicate: ModulePathExpression<'a>, - pub attribute: Vec>, - pub arg0: ModulePathExpression<'a>, - pub arg1: ModulePathExpression<'a>, + pub nodes: ( + ModulePathExpression<'a>, + Vec>, + ModulePathExpression<'a>, + ModulePathExpression<'a>, + ), } #[derive(Debug)] @@ -172,17 +186,21 @@ pub enum ModulePathExpression<'a> { #[derive(Debug)] pub struct ModulePathExpressionUnary<'a> { - pub operator: Operator<'a>, - pub attribute: Vec>, - pub arg0: ModulePathPrimary<'a>, + pub nodes: ( + Operator<'a>, + Vec>, + ModulePathPrimary<'a>, + ), } #[derive(Debug)] pub struct ModulePathExpressionBinary<'a> { - pub arg0: ModulePathExpression<'a>, - pub operator: Operator<'a>, - pub attribute: Vec>, - pub arg1: ModulePathExpression<'a>, + pub nodes: ( + ModulePathExpression<'a>, + Operator<'a>, + Vec>, + ModulePathExpression<'a>, + ), } #[derive(Debug)] @@ -215,11 +233,7 @@ pub fn inc_or_dec_expression_prefix(s: &str) -> IResult<&str, IncOrDecExpression let (s, z) = variable_lvalue(s)?; Ok(( s, - IncOrDecExpression::Prefix(IncOrDecExpressionPrefix { - operator: x, - attribute: y, - lvalue: z, - }), + IncOrDecExpression::Prefix(IncOrDecExpressionPrefix { nodes: (x, y, z) }), )) } @@ -229,11 +243,7 @@ pub fn inc_or_dec_expression_suffix(s: &str) -> IResult<&str, IncOrDecExpression let (s, z) = inc_or_dec_operator(s)?; Ok(( s, - IncOrDecExpression::Suffix(IncOrDecExpressionSuffix { - lvalue: x, - attribute: y, - operator: z, - }), + IncOrDecExpression::Suffix(IncOrDecExpressionSuffix { nodes: (x, y, z) }), )) } @@ -247,10 +257,7 @@ pub fn conditional_expression(s: &str) -> IResult<&str, ConditionalExpression> { Ok(( s, ConditionalExpression { - predicate: x, - attribute: y, - arg0: z, - arg1: v, + nodes: (x, y, z, v), }, )) } @@ -272,11 +279,7 @@ pub fn constant_expression_unary(s: &str) -> IResult<&str, ConstantExpression> { let (s, z) = constant_primary(s)?; Ok(( s, - ConstantExpression::Unary(Box::new(ConstantExpressionUnary { - operator: x, - attribute: y, - arg0: z, - })), + ConstantExpression::Unary(Box::new(ConstantExpressionUnary { nodes: (x, y, z) })), )) } @@ -288,10 +291,7 @@ pub fn constant_expression_binary(s: &str) -> IResult<&str, ConstantExpression> Ok(( s, ConstantExpression::Binary(Box::new(ConstantExpressionBinary { - arg0: x, - operator: y, - attribute: z, - arg1: v, + nodes: (x, y, z, v), })), )) } @@ -306,10 +306,7 @@ pub fn constant_expression_ternary(s: &str) -> IResult<&str, ConstantExpression> Ok(( s, ConstantExpression::Ternary(Box::new(ConstantExpressionTernary { - predicate: x, - attribute: y, - arg0: z, - arg1: v, + nodes: (x, y, z, v), })), )) } @@ -364,21 +361,28 @@ pub fn constant_range_expression(s: &str) -> IResult<&str, ConstantRangeExpressi } pub fn constant_part_select_range(s: &str) -> IResult<&str, ConstantPartSelectRange> { - alt((constant_range, constant_indexed_range))(s) + alt(( + map(constant_range, |x| ConstantPartSelectRange::Range(x)), + map(constant_indexed_range, |x| { + ConstantPartSelectRange::IndexedRange(x) + }), + ))(s) } -pub fn constant_range(s: &str) -> IResult<&str, ConstantPartSelectRange> { +pub fn constant_range(s: &str) -> IResult<&str, ConstantRange> { let (s, x) = constant_expression(s)?; let (s, _) = symbol(":")(s)?; let (s, y) = constant_expression(s)?; - Ok((s, ConstantPartSelectRange::Range((x, y)))) + Ok((s, ConstantRange { nodes: (x, y) })) } -pub fn constant_indexed_range(s: &str) -> IResult<&str, ConstantPartSelectRange> { +pub fn constant_indexed_range(s: &str) -> IResult<&str, ConstantIndexedRange> { let (s, x) = constant_expression(s)?; - let (s, y) = alt((symbol("+:"), symbol("-:")))(s)?; + let (s, y) = map(alt((symbol("+:"), symbol("-:"))), |x| Operator { + nodes: (x,), + })(s)?; let (s, z) = constant_expression(s)?; - Ok((s, ConstantPartSelectRange::IndexedRange((x, y, z)))) + Ok((s, ConstantIndexedRange { nodes: (x, y, z) })) } pub fn expression(s: &str) -> IResult<&str, Expression> { @@ -406,11 +410,7 @@ pub fn expression_unary(s: &str) -> IResult<&str, Expression> { let (s, z) = primary(s)?; Ok(( s, - Expression::Unary(Box::new(ExpressionUnary { - operator: x, - attribute: y, - arg0: z, - })), + Expression::Unary(Box::new(ExpressionUnary { nodes: (x, y, z) })), )) } @@ -422,10 +422,7 @@ pub fn expression_binary(s: &str) -> IResult<&str, Expression> { Ok(( s, Expression::Binary(Box::new(ExpressionBinary { - arg0: x, - operator: y, - attribute: z, - arg1: v, + nodes: (x, y, z, v), })), )) } @@ -434,26 +431,14 @@ pub fn tagged_union_expression(s: &str) -> IResult<&str, TaggedUnionExpression> let (s, _) = symbol("tagged")(s)?; let (s, x) = member_identifier(s)?; let (s, y) = opt(expression)(s)?; - Ok(( - s, - TaggedUnionExpression { - identifier: x, - expression: y, - }, - )) + Ok((s, TaggedUnionExpression { nodes: (x, y) })) } pub fn inside_expression(s: &str) -> IResult<&str, InsideExpression> { let (s, x) = expression(s)?; let (s, _) = symbol("inside")(s)?; let (s, y) = brace(open_range_list)(s)?; - Ok(( - s, - InsideExpression { - expression: x, - open_range_list: y, - }, - )) + Ok((s, InsideExpression { nodes: (x, y) })) } pub fn value_range(s: &str) -> IResult<&str, ValueRange> { @@ -500,10 +485,7 @@ pub fn module_path_conditional_expression( Ok(( s, ModulePathConditionalExpression { - predicate: x, - attribute: y, - arg0: z, - arg1: v, + nodes: (x, y, z, v), }, )) } @@ -527,11 +509,7 @@ pub fn module_path_expression_unary(s: &str) -> IResult<&str, ModulePathExpressi let (s, z) = module_path_primary(s)?; Ok(( s, - ModulePathExpression::Unary(Box::new(ModulePathExpressionUnary { - operator: x, - attribute: y, - arg0: z, - })), + ModulePathExpression::Unary(Box::new(ModulePathExpressionUnary { nodes: (x, y, z) })), )) } @@ -543,10 +521,7 @@ pub fn module_path_expression_binary(s: &str) -> IResult<&str, ModulePathExpress Ok(( s, ModulePathExpression::Binary(Box::new(ModulePathExpressionBinary { - arg0: x, - operator: y, - attribute: z, - arg1: v, + nodes: (x, y, z, v), })), )) } diff --git a/src/parser/expressions/numbers.rs b/src/parser/expressions/numbers.rs index 2ff6b81..9b9af20 100644 --- a/src/parser/expressions/numbers.rs +++ b/src/parser/expressions/numbers.rs @@ -32,45 +32,32 @@ pub enum RealNumber<'a> { #[derive(Debug)] pub struct DecimalNumber<'a> { - pub size: Option<&'a str>, - pub decimal_base: &'a str, - pub decimal_value: &'a str, + pub nodes: (Option<&'a str>, &'a str, &'a str), } #[derive(Debug)] pub struct BinaryNumber<'a> { - pub size: Option<&'a str>, - pub binary_base: &'a str, - pub binary_value: &'a str, + pub nodes: (Option<&'a str>, &'a str, &'a str), } #[derive(Debug)] pub struct OctalNumber<'a> { - pub size: Option<&'a str>, - pub octal_base: &'a str, - pub octal_value: &'a str, + pub nodes: (Option<&'a str>, &'a str, &'a str), } #[derive(Debug)] pub struct HexNumber<'a> { - pub size: Option<&'a str>, - pub hex_base: &'a str, - pub hex_value: &'a str, + pub nodes: (Option<&'a str>, &'a str, &'a str), } #[derive(Debug)] pub struct FixedPointNumber<'a> { - pub integer_value: &'a str, - pub fraction_value: &'a str, + pub nodes: (&'a str, &'a str), } #[derive(Debug)] pub struct FloatingPointNumber<'a> { - pub integer_value: &'a str, - pub fraction_value: Option<&'a str>, - pub exponent: &'a str, - pub sign: Option<&'a str>, - pub exponent_value: &'a str, + pub nodes: (&'a str, Option<&'a str>, &'a str, Option<&'a str>, &'a str), } // ----------------------------------------------------------------------------- @@ -98,11 +85,7 @@ pub fn decimal_number(s: &str) -> IResult<&str, IntegralNumber> { ))(s)?; Ok(( s, - IntegralNumber::DecimalNumber(DecimalNumber { - size: x, - decimal_base: y, - decimal_value: z, - }), + IntegralNumber::DecimalNumber(DecimalNumber { nodes: (x, y, z) }), )) } @@ -115,11 +98,7 @@ pub fn binary_number(s: &str) -> IResult<&str, IntegralNumber> { let (s, (x, y, z)) = tuple((opt(size), binary_base, binary_value))(s)?; Ok(( s, - IntegralNumber::BinaryNumber(BinaryNumber { - size: x, - binary_base: y, - binary_value: z, - }), + IntegralNumber::BinaryNumber(BinaryNumber { nodes: (x, y, z) }), )) } @@ -127,24 +106,13 @@ pub fn octal_number(s: &str) -> IResult<&str, IntegralNumber> { let (s, (x, y, z)) = tuple((opt(size), octal_base, octal_value))(s)?; Ok(( s, - IntegralNumber::OctalNumber(OctalNumber { - size: x, - octal_base: y, - octal_value: z, - }), + IntegralNumber::OctalNumber(OctalNumber { nodes: (x, y, z) }), )) } pub fn hex_number(s: &str) -> IResult<&str, IntegralNumber> { let (s, (x, y, z)) = tuple((opt(size), hex_base, hex_value))(s)?; - Ok(( - s, - IntegralNumber::HexNumber(HexNumber { - size: x, - hex_base: y, - hex_value: z, - }), - )) + Ok((s, IntegralNumber::HexNumber(HexNumber { nodes: (x, y, z) }))) } pub fn size(s: &str) -> IResult<&str, &str> { @@ -167,10 +135,7 @@ pub fn fixed_point_number(s: &str) -> IResult<&str, RealNumber> { let (s, (x, _, y)) = tuple((unsigned_number, symbol("."), unsigned_number))(s)?; Ok(( s, - RealNumber::FixedPointNumber(FixedPointNumber { - integer_value: x, - fraction_value: y, - }), + RealNumber::FixedPointNumber(FixedPointNumber { nodes: (x, y) }), )) } @@ -184,11 +149,7 @@ pub fn floating_point_number(s: &str) -> IResult<&str, RealNumber> { Ok(( s, RealNumber::FloatingPointNumber(FloatingPointNumber { - integer_value: x, - fraction_value: y, - exponent: z, - sign: v, - exponent_value: w, + nodes: (x, y, z, v, w), }), )) } diff --git a/src/parser/expressions/operators.rs b/src/parser/expressions/operators.rs index 4490c12..4a33a0d 100644 --- a/src/parser/expressions/operators.rs +++ b/src/parser/expressions/operators.rs @@ -6,13 +6,13 @@ use nom::IResult; #[derive(Debug)] pub struct Operator<'a> { - pub raw: &'a str, + pub nodes: (&'a str,), } // ----------------------------------------------------------------------------- pub fn unary_operator(s: &str) -> IResult<&str, Operator> { - let (s, raw) = alt(( + let (s, x) = alt(( symbol("+"), symbol("-"), symbol("!"), @@ -25,11 +25,11 @@ pub fn unary_operator(s: &str) -> IResult<&str, Operator> { symbol("^"), symbol("~"), ))(s)?; - Ok((s, Operator { raw })) + Ok((s, Operator { nodes: (x,) })) } pub fn binary_operator(s: &str) -> IResult<&str, Operator> { - let (s, raw) = alt(( + let (s, x) = alt(( alt(( symbol("+"), symbol("-"), @@ -64,16 +64,16 @@ pub fn binary_operator(s: &str) -> IResult<&str, Operator> { symbol(">"), )), ))(s)?; - Ok((s, Operator { raw })) + Ok((s, Operator { nodes: (x,) })) } pub fn inc_or_dec_operator(s: &str) -> IResult<&str, Operator> { - let (s, raw) = alt((symbol("++"), symbol("--")))(s)?; - Ok((s, Operator { raw })) + let (s, x) = alt((symbol("++"), symbol("--")))(s)?; + Ok((s, Operator { nodes: (x,) })) } pub fn unary_module_path_operator(s: &str) -> IResult<&str, Operator> { - let (s, raw) = alt(( + let (s, x) = alt(( symbol("!"), symbol("&"), symbol("|"), @@ -84,11 +84,11 @@ pub fn unary_module_path_operator(s: &str) -> IResult<&str, Operator> { symbol("^"), symbol("~"), ))(s)?; - Ok((s, Operator { raw })) + Ok((s, Operator { nodes: (x,) })) } pub fn binary_module_path_operator(s: &str) -> IResult<&str, Operator> { - let (s, raw) = alt(( + let (s, x) = alt(( symbol("=="), symbol("!="), symbol("&&"), @@ -99,7 +99,7 @@ pub fn binary_module_path_operator(s: &str) -> IResult<&str, Operator> { symbol("^"), symbol("~^"), ))(s)?; - Ok((s, Operator { raw })) + Ok((s, Operator { nodes: (x,) })) } // ----------------------------------------------------------------------------- diff --git a/src/parser/expressions/primaries.rs b/src/parser/expressions/primaries.rs index afdd8f8..d36b87d 100644 --- a/src/parser/expressions/primaries.rs +++ b/src/parser/expressions/primaries.rs @@ -12,7 +12,7 @@ pub enum ConstantPrimary<'a> { PrimaryLiteral(PrimaryLiteral<'a>), PsParameter(ConstantPrimaryPsParameter<'a>), Specparam(ConstantPrimarySpecparam<'a>), - Genvar(Identifier<'a>), + Genvar(GenvarIdentifier<'a>), FormalPort(ConstantPrimaryFormalPort<'a>), Enum(ConstantPrimaryEnum<'a>), Concatenation(ConstantPrimaryConcatenation<'a>), @@ -28,38 +28,38 @@ pub enum ConstantPrimary<'a> { #[derive(Debug)] pub struct ConstantPrimaryPsParameter<'a> { - identifier: ScopedIdentifier<'a>, - select: ConstantSelect<'a>, + pub nodes: (PsParameterIdentifier<'a>, ConstantSelect<'a>), } #[derive(Debug)] pub struct ConstantPrimarySpecparam<'a> { - identifier: Identifier<'a>, - range: Option>, + pub nodes: (SpecparamIdentifier<'a>, Option>), } #[derive(Debug)] pub struct ConstantPrimaryFormalPort<'a> { - identifier: Identifier<'a>, - select: ConstantSelect<'a>, + pub nodes: (FormalPortIdentifier<'a>, ConstantSelect<'a>), } #[derive(Debug)] pub struct ConstantPrimaryEnum<'a> { - scope: Scope<'a>, - identifier: Identifier<'a>, + pub nodes: (PackageScopeOrClassScope<'a>, EnumIdentifier<'a>), } #[derive(Debug)] pub struct ConstantPrimaryConcatenation<'a> { - concatenation: ConstantConcatenation<'a>, - range: Option>, + pub nodes: ( + ConstantConcatenation<'a>, + Option>, + ), } #[derive(Debug)] pub struct ConstantPrimaryMultipleConcatenation<'a> { - concatenation: ConstantMultipleConcatenation<'a>, - range: Option>, + pub nodes: ( + ConstantMultipleConcatenation<'a>, + Option>, + ), } #[derive(Debug)] @@ -93,35 +93,37 @@ pub enum Primary<'a> { #[derive(Debug)] pub struct PrimaryHierarchical<'a> { - qualifier: Option>, - identifier: HierarchicalIdentifier<'a>, - select: Select<'a>, + pub nodes: ( + Option>, + HierarchicalIdentifier<'a>, + Select<'a>, + ), } #[derive(Debug)] pub struct PrimaryConcatenation<'a> { - concatenation: Concatenation<'a>, - range: Option>, + pub nodes: (Concatenation<'a>, Option>), } #[derive(Debug)] pub struct PrimaryMultipleConcatenation<'a> { - concatenation: MultipleConcatenation<'a>, - range: Option>, + pub nodes: (MultipleConcatenation<'a>, Option>), } #[derive(Debug)] pub enum PrimaryHierarchicalQualifier<'a> { ClassQualifier(ClassQualifier<'a>), - PackageScope(Scope<'a>), + PackageScope(PackageScope<'a>), } #[derive(Debug)] pub struct ClassQualifier<'a> { - local: bool, - scope: Option>, + pub nodes: (Option, Option>), } +#[derive(Debug)] +pub struct Local {} + #[derive(Debug)] pub enum RangeExpression<'a> { Expression(Expression<'a>), @@ -159,48 +161,60 @@ pub enum ImplicitClassHandle { ThisSuper, } +#[derive(Debug)] +pub struct BitSelect<'a> { + nodes: (Vec>,), +} + #[derive(Debug)] pub struct UnsignedTimeLiteral<'a> { - number: &'a str, - unit: TimeUnit, + pub nodes: (&'a str, TimeUnit), } #[derive(Debug)] pub struct FixedPointTimeLiteral<'a> { - number: RealNumber<'a>, - unit: TimeUnit, + pub nodes: (RealNumber<'a>, TimeUnit), } #[derive(Debug)] pub struct Select<'a> { - member: Option>, - bit_select: Vec>, - part_select_range: Option>, + pub nodes: ( + Option>, + BitSelect<'a>, + Option>, + ), +} + +#[derive(Debug)] +pub struct ConstantBitSelect<'a> { + nodes: (Vec>,), } #[derive(Debug)] pub struct ConstantSelect<'a> { - member: Option>, - bit_select: Vec>, - part_select_range: Option>, + pub nodes: ( + Option>, + ConstantBitSelect<'a>, + Option>, + ), } #[derive(Debug)] pub struct SelectMember<'a> { - upper: Vec<(Identifier<'a>, Vec>)>, - identifier: Identifier<'a>, + pub nodes: ( + Vec<(MemberIdentifier<'a>, BitSelect<'a>)>, + MemberIdentifier<'a>, + ), } #[derive(Debug)] pub struct Cast<'a> { - r#type: CastingType<'a>, - expression: Expression<'a>, + pub nodes: (CastingType<'a>, Expression<'a>), } #[derive(Debug)] pub struct ConstantCast<'a> { - r#type: CastingType<'a>, - expression: ConstantExpression<'a>, + pub nodes: (CastingType<'a>, ConstantExpression<'a>), } // ----------------------------------------------------------------------------- @@ -236,10 +250,7 @@ pub fn constant_primary_ps_parameter(s: &str) -> IResult<&str, ConstantPrimary> let (s, y) = constant_select(s)?; Ok(( s, - ConstantPrimary::PsParameter(ConstantPrimaryPsParameter { - identifier: x, - select: y, - }), + ConstantPrimary::PsParameter(ConstantPrimaryPsParameter { nodes: (x, y) }), )) } @@ -248,10 +259,7 @@ pub fn constant_primary_specparam(s: &str) -> IResult<&str, ConstantPrimary> { let (s, y) = opt(bracket(constant_range_expression))(s)?; Ok(( s, - ConstantPrimary::Specparam(ConstantPrimarySpecparam { - identifier: x, - range: y, - }), + ConstantPrimary::Specparam(ConstantPrimarySpecparam { nodes: (x, y) }), )) } @@ -260,22 +268,16 @@ pub fn constant_primary_formal_port(s: &str) -> IResult<&str, ConstantPrimary> { let (s, y) = constant_select(s)?; Ok(( s, - ConstantPrimary::FormalPort(ConstantPrimaryFormalPort { - identifier: x, - select: y, - }), + ConstantPrimary::FormalPort(ConstantPrimaryFormalPort { nodes: (x, y) }), )) } pub fn constant_primary_enum(s: &str) -> IResult<&str, ConstantPrimary> { - let (s, x) = alt((package_scope, class_scope))(s)?; + let (s, x) = package_scope_or_class_scope(s)?; let (s, y) = enum_identifier(s)?; Ok(( s, - ConstantPrimary::Enum(ConstantPrimaryEnum { - scope: x, - identifier: y, - }), + ConstantPrimary::Enum(ConstantPrimaryEnum { nodes: (x, y) }), )) } @@ -284,10 +286,7 @@ pub fn constant_primary_concatenation(s: &str) -> IResult<&str, ConstantPrimary> let (s, y) = opt(bracket(constant_range_expression))(s)?; Ok(( s, - ConstantPrimary::Concatenation(ConstantPrimaryConcatenation { - concatenation: x, - range: y, - }), + ConstantPrimary::Concatenation(ConstantPrimaryConcatenation { nodes: (x, y) }), )) } @@ -297,8 +296,7 @@ pub fn constant_primary_multiple_concatenation(s: &str) -> IResult<&str, Constan Ok(( s, ConstantPrimary::MultipleConcatenation(ConstantPrimaryMultipleConcatenation { - concatenation: x, - range: y, + nodes: (x, y), }), )) } @@ -362,11 +360,7 @@ pub fn primary_hierarchical(s: &str) -> IResult<&str, Primary> { let (s, z) = select(s)?; Ok(( s, - Primary::Hierarchical(PrimaryHierarchical { - qualifier: x, - identifier: y, - select: z, - }), + Primary::Hierarchical(PrimaryHierarchical { nodes: (x, y, z) }), )) } @@ -375,10 +369,7 @@ pub fn primary_concatenation(s: &str) -> IResult<&str, Primary> { let (s, y) = opt(range_expression)(s)?; Ok(( s, - Primary::Concatenation(PrimaryConcatenation { - concatenation: x, - range: y, - }), + Primary::Concatenation(PrimaryConcatenation { nodes: (x, y) }), )) } @@ -387,10 +378,7 @@ pub fn primary_multiple_concatenation(s: &str) -> IResult<&str, Primary> { let (s, y) = opt(range_expression)(s)?; Ok(( s, - Primary::MultipleConcatenation(PrimaryMultipleConcatenation { - concatenation: x, - range: y, - }), + Primary::MultipleConcatenation(PrimaryMultipleConcatenation { nodes: (x, y) }), )) } @@ -407,15 +395,11 @@ pub fn primary_hierarchical_qualifier(s: &str) -> IResult<&str, PrimaryHierarchi pub fn class_qualifier(s: &str) -> IResult<&str, ClassQualifier> { let (s, x) = opt(symbol("local::"))(s)?; - let (s, y) = opt(alt(( - terminated(implicit_class_handle, symbol(".")), - class_scope, - )))(s)?; + let (s, y) = opt(implicit_class_handle_or_class_scope)(s)?; Ok(( s, ClassQualifier { - local: x.is_some(), - scope: y, + nodes: (x.map(|_| Local {}), y), }, )) } @@ -447,7 +431,7 @@ pub fn unsigned_time_literal(s: &str) -> IResult<&str, TimeLiteral> { let (s, y) = time_unit(s)?; Ok(( s, - TimeLiteral::UnsignedTimeLiteral(UnsignedTimeLiteral { number: x, unit: y }), + TimeLiteral::UnsignedTimeLiteral(UnsignedTimeLiteral { nodes: (x, y) }), )) } @@ -456,7 +440,7 @@ pub fn fixed_point_time_literal(s: &str) -> IResult<&str, TimeLiteral> { let (s, y) = time_unit(s)?; Ok(( s, - TimeLiteral::FixedPointTimeLiteral(FixedPointTimeLiteral { number: x, unit: y }), + TimeLiteral::FixedPointTimeLiteral(FixedPointTimeLiteral { nodes: (x, y) }), )) } @@ -481,20 +465,20 @@ pub fn time_unit(s: &str) -> IResult<&str, TimeUnit> { Ok((s, unit)) } -pub fn implicit_class_handle(s: &str) -> IResult<&str, Scope> { - let (s, x) = alt(( +pub fn implicit_class_handle(s: &str) -> IResult<&str, ImplicitClassHandle> { + alt(( map( tuple((symbol("this"), symbol("."), symbol("super"))), |_| ImplicitClassHandle::ThisSuper, ), map(symbol("this"), |_| ImplicitClassHandle::This), map(symbol("super"), |_| ImplicitClassHandle::Super), - ))(s)?; - Ok((s, Scope::ImplicitClassHandle(x))) + ))(s) } -pub fn bit_select(s: &str) -> IResult<&str, Vec> { - many0(bracket(expression))(s) +pub fn bit_select(s: &str) -> IResult<&str, BitSelect> { + let (s, x) = many0(bracket(expression))(s)?; + Ok((s, BitSelect { nodes: (x,) })) } pub fn select(s: &str) -> IResult<&str, Select> { @@ -506,22 +490,12 @@ pub fn select(s: &str) -> IResult<&str, Select> { let (s, z) = opt(bracket(part_select_range))(s)?; let x = if let Some((x, y)) = x { - Some(SelectMember { - upper: x, - identifier: y, - }) + Some(SelectMember { nodes: (x, y) }) } else { None }; - Ok(( - s, - Select { - member: x, - bit_select: y, - part_select_range: z, - }, - )) + Ok((s, Select { nodes: (x, y, z) })) } pub fn nonrange_select(s: &str) -> IResult<&str, Select> { @@ -532,10 +506,7 @@ pub fn nonrange_select(s: &str) -> IResult<&str, Select> { let (s, y) = bit_select(s)?; let x = if let Some((x, y)) = x { - Some(SelectMember { - upper: x, - identifier: y, - }) + Some(SelectMember { nodes: (x, y) }) } else { None }; @@ -543,15 +514,14 @@ pub fn nonrange_select(s: &str) -> IResult<&str, Select> { Ok(( s, Select { - member: x, - bit_select: y, - part_select_range: None, + nodes: (x, y, None), }, )) } -pub fn constant_bit_select(s: &str) -> IResult<&str, Vec> { - many0(bracket(constant_expression))(s) +pub fn constant_bit_select(s: &str) -> IResult<&str, ConstantBitSelect> { + let (s, x) = many0(bracket(constant_expression))(s)?; + Ok((s, ConstantBitSelect { nodes: (x,) })) } pub fn constant_select(s: &str) -> IResult<&str, ConstantSelect> { @@ -563,35 +533,19 @@ pub fn constant_select(s: &str) -> IResult<&str, ConstantSelect> { let (s, z) = opt(bracket(constant_part_select_range))(s)?; let x = if let Some((x, y)) = x { - Some(SelectMember { - upper: x, - identifier: y, - }) + Some(SelectMember { nodes: (x, y) }) } else { None }; - Ok(( - s, - ConstantSelect { - member: x, - bit_select: y, - part_select_range: z, - }, - )) + Ok((s, ConstantSelect { nodes: (x, y, z) })) } pub fn constant_cast(s: &str) -> IResult<&str, ConstantCast> { let (s, x) = casting_type(s)?; let (s, _) = symbol("'")(s)?; let (s, y) = paren(constant_expression)(s)?; - Ok(( - s, - ConstantCast { - r#type: x, - expression: y, - }, - )) + Ok((s, ConstantCast { nodes: (x, y) })) } pub fn constant_let_expression(s: &str) -> IResult<&str, LetExpression> { @@ -602,13 +556,7 @@ pub fn cast(s: &str) -> IResult<&str, Cast> { let (s, x) = casting_type(s)?; let (s, _) = symbol("'")(s)?; let (s, y) = paren(expression)(s)?; - Ok(( - s, - Cast { - r#type: x, - expression: y, - }, - )) + Ok((s, Cast { nodes: (x, y) })) } // ----------------------------------------------------------------------------- diff --git a/src/parser/expressions/strings.rs b/src/parser/expressions/strings.rs index 7b69573..b0c9b06 100644 --- a/src/parser/expressions/strings.rs +++ b/src/parser/expressions/strings.rs @@ -9,7 +9,7 @@ use nom::IResult; #[derive(Debug)] pub struct StringLiteral<'a> { - pub raw: &'a str, + pub nodes: (&'a str,), } // ----------------------------------------------------------------------------- @@ -46,7 +46,7 @@ pub fn string_literal_impl(s: &str) -> IResult<&str, StringLiteral> { let raw = raw.unwrap(); - Ok((s, StringLiteral { raw })) + Ok((s, StringLiteral { nodes: (raw,) })) } // ----------------------------------------------------------------------------- diff --git a/src/parser/expressions/subroutine_calls.rs b/src/parser/expressions/subroutine_calls.rs index dc70286..f570878 100644 --- a/src/parser/expressions/subroutine_calls.rs +++ b/src/parser/expressions/subroutine_calls.rs @@ -9,18 +9,22 @@ use nom::IResult; #[derive(Debug)] pub struct TfCall<'a> { - pub identifier: ScopedIdentifier<'a>, - pub attribute: Vec>, - pub argument: Option>, + pub nodes: ( + PsOrHierarchicalTfIdentifier<'a>, + Vec>, + 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>, + pub nodes: ( + SystemTfIdentifier<'a>, + Option>, + Option>, + Option>>, + Option>, + ), } #[derive(Debug)] @@ -34,20 +38,21 @@ pub enum SubroutineCall<'a> { #[derive(Debug)] pub struct ListOfArguments<'a> { - pub unnamed: Vec>, - pub named: Vec<(Identifier<'a>, Option>)>, + pub nodes: ( + Vec>, + Vec<(Identifier<'a>, Option>)>, + ), } #[derive(Debug)] pub struct MethodCall<'a> { - pub root: MethodCallRoot<'a>, - pub body: MethodCallBody<'a>, + pub nodes: (MethodCallRoot<'a>, MethodCallBody<'a>), } #[derive(Debug)] pub enum MethodCallRoot<'a> { Primary(Primary<'a>), - ImplicitClassHandle(Scope<'a>), + ImplicitClassHandle(ImplicitClassHandle), } #[derive(Debug)] @@ -59,30 +64,36 @@ pub enum MethodCallBody<'a> { #[derive(Debug)] pub struct MethodCallBodyUser<'a> { - pub identifier: Identifier<'a>, - pub attribute: Vec>, - pub argument: Option>, + pub nodes: ( + MethodIdentifier<'a>, + Vec>, + Option>, + ), } #[derive(Debug)] pub struct ArrayManipulationCall<'a> { - pub name: ArrayMethodName<'a>, - pub attribute: Vec>, - pub argument: Option>, - pub with: Option>, + pub nodes: ( + ArrayMethodName<'a>, + Vec>, + Option>, + Option>, + ), } #[derive(Debug)] pub struct RandomizeCall<'a> { - pub attribute: Vec>, - pub argument: Vec>, - pub with: Vec>, - pub constraint_block: Option>, + pub nodes: ( + Vec>, + VariableIdentifierList<'a>, + IdentifierList<'a>, + Option>, + ), } #[derive(Debug)] pub enum ArrayMethodName<'a> { - Identifier(Identifier<'a>), + MethodIdentifier(MethodIdentifier<'a>), Unique, And, Or, @@ -99,14 +110,7 @@ pub fn tf_call(s: &str) -> IResult<&str, TfCall> { let (s, x) = ps_or_hierarchical_tf_identifier(s)?; let (s, y) = many0(attribute_instance)(s)?; let (s, z) = opt(paren(list_of_arguments))(s)?; - Ok(( - s, - TfCall { - identifier: x, - attribute: y, - argument: z, - }, - )) + Ok((s, TfCall { nodes: (x, y, z) })) } pub fn system_tf_call(s: &str) -> IResult<&str, SystemTfCall> { @@ -123,11 +127,7 @@ pub fn system_tf_call_list_of_arguments(s: &str) -> IResult<&str, SystemTfCall> Ok(( s, SystemTfCall { - identifier: x, - argument: y, - data_type: None, - expression: None, - clocking_event: None, + nodes: (x, y, None, None, None), }, )) } @@ -141,11 +141,7 @@ pub fn system_tf_call_data_type(s: &str) -> IResult<&str, SystemTfCall> { Ok(( s, SystemTfCall { - identifier: x, - argument: None, - data_type: Some(y), - expression: Some(vec![z]), - clocking_event: None, + nodes: (x, None, Some(y), Some(vec![z]), None), }, )) } @@ -160,11 +156,7 @@ pub fn system_tf_call_clocking_event(s: &str) -> IResult<&str, SystemTfCall> { Ok(( s, SystemTfCall { - identifier: x, - argument: None, - data_type: None, - expression: Some(y), - clocking_event: z, + nodes: (x, None, None, Some(y), z), }, )) } @@ -192,13 +184,7 @@ pub fn list_of_arguments(s: &str) -> IResult<&str, ListOfArguments> { symbol(","), pair(preceded(symbol("."), identifier), paren(opt(expression))), )(s)?; - Ok(( - s, - ListOfArguments { - unnamed: x, - named: y, - }, - )) + Ok((s, ListOfArguments { nodes: (x, y) })) } pub fn method_call(s: &str) -> IResult<&str, MethodCall> { @@ -206,7 +192,7 @@ pub fn method_call(s: &str) -> IResult<&str, MethodCall> { let (s, _) = symbol(".")(s)?; let (s, y) = method_call_body(s)?; - Ok((s, MethodCall { root: x, body: y })) + Ok((s, MethodCall { nodes: (x, y) })) } pub fn method_call_body(s: &str) -> IResult<&str, MethodCallBody> { @@ -219,11 +205,7 @@ pub fn method_call_body_user(s: &str) -> IResult<&str, MethodCallBody> { let (s, z) = opt(paren(list_of_arguments))(s)?; Ok(( s, - MethodCallBody::User(MethodCallBodyUser { - identifier: x, - attribute: y, - argument: z, - }), + MethodCallBody::User(MethodCallBodyUser { nodes: (x, y, z) }), )) } @@ -238,14 +220,11 @@ pub fn array_manipulation_call(s: &str) -> IResult<&str, ArrayManipulationCall> let (s, x) = array_method_name(s)?; let (s, y) = many0(attribute_instance)(s)?; let (s, z) = opt(paren(list_of_arguments))(s)?; - let (s, w) = opt(preceded(symbol("with"), paren(expression)))(s)?; + let (s, v) = opt(preceded(symbol("with"), paren(expression)))(s)?; Ok(( s, ArrayManipulationCall { - name: x, - attribute: y, - argument: z, - with: w, + nodes: (x, y, z, v), }, )) } @@ -255,26 +234,29 @@ pub fn randomize_call(s: &str) -> IResult<&str, RandomizeCall> { let (s, x) = many0(attribute_instance)(s)?; let (s, y) = opt(paren(opt(alt(( variable_identifier_list, - map(symbol("null"), |_| vec![]), + map(symbol("null"), |_| VariableIdentifierList { + nodes: (vec![],), + }), )))))(s)?; let (s, z) = opt(tuple(( symbol("with"), opt(paren(opt(identifier_list))), constraint_block, )))(s)?; - let y = if let Some(Some(y)) = y { y } else { vec![] }; - let (z, w) = if let Some((_, Some(Some(z)), w)) = z { - (z, Some(w)) + let y = if let Some(Some(y)) = y { + y } else { - (vec![], None) + VariableIdentifierList { nodes: (vec![],) } + }; + let (z, v) = if let Some((_, Some(Some(z)), v)) = z { + (z, Some(v)) + } else { + (IdentifierList { nodes: (vec![],) }, None) }; Ok(( s, RandomizeCall { - attribute: x, - argument: y, - with: z, - constraint_block: w, + nodes: (x, y, z, v), }, )) } @@ -294,7 +276,7 @@ pub fn array_method_name(s: &str) -> IResult<&str, ArrayMethodName> { map(symbol("and"), |_| ArrayMethodName::And), map(symbol("or"), |_| ArrayMethodName::Or), map(symbol("xor"), |_| ArrayMethodName::Xor), - map(method_identifier, |x| ArrayMethodName::Identifier(x)), + map(method_identifier, |x| ArrayMethodName::MethodIdentifier(x)), ))(s) } diff --git a/src/parser/general/attributes.rs b/src/parser/general/attributes.rs index b2ac62a..c8d0cba 100644 --- a/src/parser/general/attributes.rs +++ b/src/parser/general/attributes.rs @@ -8,13 +8,12 @@ use nom::IResult; #[derive(Debug)] pub struct AttributeInstance<'a> { - pub attr_spec: Vec>, + pub nodes: (Vec>,), } #[derive(Debug)] pub struct AttrSpec<'a> { - pub attr_name: Identifier<'a>, - pub rvalue: Option>, + pub nodes: (Identifier<'a>, Option>), } // ----------------------------------------------------------------------------- @@ -23,19 +22,13 @@ pub fn attribute_instance(s: &str) -> IResult<&str, AttributeInstance> { let (s, _) = symbol("(*")(s)?; let (s, x) = separated_nonempty_list(symbol(","), attr_spec)(s)?; let (s, _) = symbol("*)")(s)?; - Ok((s, AttributeInstance { attr_spec: x })) + Ok((s, AttributeInstance { nodes: (x,) })) } pub fn attr_spec(s: &str) -> IResult<&str, AttrSpec> { let (s, x) = identifier(s)?; let (s, y) = opt(preceded(symbol("="), constant_expression))(s)?; - Ok(( - s, - AttrSpec { - attr_name: x, - rvalue: y, - }, - )) + Ok((s, AttrSpec { nodes: (x, y) })) } // ----------------------------------------------------------------------------- diff --git a/src/parser/general/comments.rs b/src/parser/general/comments.rs index 6e75cf5..79f0694 100644 --- a/src/parser/general/comments.rs +++ b/src/parser/general/comments.rs @@ -6,7 +6,7 @@ use nom::IResult; #[derive(Debug)] pub struct Comment<'a> { - pub raw: &'a str, + nodes: (&'a str,), } // ----------------------------------------------------------------------------- @@ -18,17 +18,17 @@ pub fn comment(s: &str) -> IResult<&str, Comment> { pub fn one_line_comment(s: &str) -> IResult<&str, Comment> { let (s, x) = tag("//")(s)?; let (s, y) = is_not("\n")(s)?; - let raw = str_concat::concat(x, y).unwrap(); - Ok((s, Comment { raw })) + let x = str_concat::concat(x, y).unwrap(); + Ok((s, Comment { nodes: (x,) })) } pub fn block_comment(s: &str) -> IResult<&str, Comment> { let (s, x) = tag("/*")(s)?; let (s, y) = is_not("*/")(s)?; let (s, z) = tag("*/")(s)?; - let raw = str_concat::concat(x, y).unwrap(); - let raw = str_concat::concat(raw, z).unwrap(); - Ok((s, Comment { raw })) + let x = str_concat::concat(x, y).unwrap(); + let x = str_concat::concat(x, z).unwrap(); + Ok((s, Comment { nodes: (x,) })) } // ----------------------------------------------------------------------------- diff --git a/src/parser/general/identifiers.rs b/src/parser/general/identifiers.rs index 09cc60a..bc83491 100644 --- a/src/parser/general/identifiers.rs +++ b/src/parser/general/identifiers.rs @@ -2,9 +2,10 @@ use crate::parser::*; use nom::branch::*; use nom::bytes::complete::*; use nom::combinator::*; +use nom::error::*; use nom::multi::*; use nom::sequence::*; -use nom::IResult; +use nom::{Err, IResult}; // ----------------------------------------------------------------------------- @@ -13,578 +14,991 @@ const AZ09_: &str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456 const AZ09_DOLLAR: &str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_$"; #[derive(Debug)] -pub struct Identifier<'a> { - pub raw: &'a str, +pub struct ArrayIdentifier<'a> { + pub nodes: (Identifier<'a>,), } #[derive(Debug)] -pub struct ScopedIdentifier<'a> { - pub scope: Option>, - pub identifier: HierarchicalIdentifier<'a>, +pub struct BlockIdentifier<'a> { + pub nodes: (Identifier<'a>,), } #[derive(Debug)] -pub enum Scope<'a> { - LocalScope, - PackageScope(Identifier<'a>), - ClassScope, - ImplicitClassHandle(ImplicitClassHandle), - GenerateBlockScope(Vec>), +pub struct BinIdentifier<'a> { + pub nodes: (Identifier<'a>,), } #[derive(Debug)] -pub struct GenerateBlockScope<'a> { - pub identifier: Identifier<'a>, - pub constant_expression: Option>, +pub struct CIdentifier<'a> { + pub nodes: (&'a str,), +} + +#[derive(Debug)] +pub struct CellIdentifier<'a> { + pub nodes: (Identifier<'a>,), +} + +#[derive(Debug)] +pub struct CheckerIdentifier<'a> { + pub nodes: (Identifier<'a>,), +} + +#[derive(Debug)] +pub struct ClassIdentifier<'a> { + pub nodes: (Identifier<'a>,), +} + +#[derive(Debug)] +pub struct ClassVariableIdentifier<'a> { + pub nodes: (VariableIdentifier<'a>,), +} + +#[derive(Debug)] +pub struct ClockingIdentifier<'a> { + pub nodes: (Identifier<'a>,), +} + +#[derive(Debug)] +pub struct ConfigIdentifier<'a> { + pub nodes: (Identifier<'a>,), +} + +#[derive(Debug)] +pub struct ConstIdentifier<'a> { + pub nodes: (Identifier<'a>,), +} + +#[derive(Debug)] +pub struct ConstraintIdentifier<'a> { + pub nodes: (Identifier<'a>,), +} + +#[derive(Debug)] +pub struct CovergroupIdentifier<'a> { + pub nodes: (Identifier<'a>,), +} + +#[derive(Debug)] +pub struct CovergroupVariableIdentifier<'a> { + pub nodes: (VariableIdentifier<'a>,), +} + +#[derive(Debug)] +pub struct CoverPointIdentifier<'a> { + pub nodes: (Identifier<'a>,), +} + +#[derive(Debug)] +pub struct CrossIdentifier<'a> { + pub nodes: (Identifier<'a>,), +} + +#[derive(Debug)] +pub struct DynamicArrayVariableIdentifier<'a> { + pub nodes: (VariableIdentifier<'a>,), +} + +#[derive(Debug)] +pub struct EnumIdentifier<'a> { + pub nodes: (Identifier<'a>,), +} + +#[derive(Debug)] +pub struct EscapedIdentifier<'a> { + pub nodes: (&'a str,), +} + +#[derive(Debug)] +pub struct FormalIdentifier<'a> { + pub nodes: (Identifier<'a>,), +} + +#[derive(Debug)] +pub struct FormalPortIdentifier<'a> { + pub nodes: (Identifier<'a>,), +} + +#[derive(Debug)] +pub struct FunctionIdentifier<'a> { + pub nodes: (Identifier<'a>,), +} + +#[derive(Debug)] +pub struct GenerateBlockIdentifier<'a> { + pub nodes: (Identifier<'a>,), +} + +#[derive(Debug)] +pub struct GenvarIdentifier<'a> { + pub nodes: (Identifier<'a>,), +} + +#[derive(Debug)] +pub struct HierarchicalArrayIdentifier<'a> { + pub nodes: (HierarchicalIdentifier<'a>,), +} + +#[derive(Debug)] +pub struct HierarchicalBlockIdentifier<'a> { + pub nodes: (HierarchicalIdentifier<'a>,), +} + +#[derive(Debug)] +pub struct HierarchicalEventIdentifier<'a> { + pub nodes: (HierarchicalIdentifier<'a>,), } #[derive(Debug)] pub struct HierarchicalIdentifier<'a> { - pub hierarchy: Vec>, - pub identifier: Identifier<'a>, -} - -impl<'a> From> for HierarchicalIdentifier<'a> { - fn from(x: Identifier<'a>) -> Self { - HierarchicalIdentifier { - hierarchy: vec![], - identifier: x, - } - } + pub nodes: ( + Option, + Vec<(Identifier<'a>, ConstantBitSelect<'a>)>, + Identifier<'a>, + ), } #[derive(Debug)] -pub struct Hierarchy<'a> { - pub identifier: Identifier<'a>, - pub constant_bit_select: Option>>, +pub struct Root {} + +#[derive(Debug)] +pub struct HierarchicalNetIdentifier<'a> { + pub nodes: (HierarchicalIdentifier<'a>,), +} + +#[derive(Debug)] +pub struct HierarchicalParameterIdentifier<'a> { + pub nodes: (HierarchicalIdentifier<'a>,), +} + +#[derive(Debug)] +pub struct HierarchicalPropertyIdentifier<'a> { + pub nodes: (HierarchicalIdentifier<'a>,), +} + +#[derive(Debug)] +pub struct HierarchicalSequenceIdentifier<'a> { + pub nodes: (HierarchicalIdentifier<'a>,), +} + +#[derive(Debug)] +pub struct HierarchicalTaskIdentifier<'a> { + pub nodes: (HierarchicalIdentifier<'a>,), +} + +#[derive(Debug)] +pub struct HierarchicalTfIdentifier<'a> { + pub nodes: (HierarchicalIdentifier<'a>,), +} + +#[derive(Debug)] +pub struct HierarchicalVariableIdentifier<'a> { + pub nodes: (HierarchicalIdentifier<'a>,), +} + +#[derive(Debug)] +pub enum Identifier<'a> { + SimpleIdentifier(SimpleIdentifier<'a>), + EscapedIdentifier(EscapedIdentifier<'a>), +} + +#[derive(Debug)] +pub struct IndexVariableIdentifier<'a> { + pub nodes: (Identifier<'a>,), +} + +#[derive(Debug)] +pub struct InterfaceIdentifier<'a> { + pub nodes: (Identifier<'a>,), +} + +#[derive(Debug)] +pub struct InterfaceInstanceIdentifier<'a> { + pub nodes: (Identifier<'a>,), +} + +#[derive(Debug)] +pub struct InoutPortIdentifier<'a> { + pub nodes: (Identifier<'a>,), +} + +#[derive(Debug)] +pub struct InputPortIdentifier<'a> { + pub nodes: (Identifier<'a>,), +} + +#[derive(Debug)] +pub struct InstanceIdentifier<'a> { + pub nodes: (Identifier<'a>,), +} + +#[derive(Debug)] +pub struct LibraryIdentifier<'a> { + pub nodes: (Identifier<'a>,), +} + +#[derive(Debug)] +pub struct MemberIdentifier<'a> { + pub nodes: (Identifier<'a>,), +} + +#[derive(Debug)] +pub struct MethodIdentifier<'a> { + pub nodes: (Identifier<'a>,), +} + +#[derive(Debug)] +pub struct ModportIdentifier<'a> { + pub nodes: (Identifier<'a>,), +} + +#[derive(Debug)] +pub struct ModuleIdentifier<'a> { + pub nodes: (Identifier<'a>,), +} + +#[derive(Debug)] +pub struct NetIdentifier<'a> { + pub nodes: (Identifier<'a>,), +} + +#[derive(Debug)] +pub struct NetTypeIdentifier<'a> { + pub nodes: (Identifier<'a>,), +} + +#[derive(Debug)] +pub struct OutputPortIdentifier<'a> { + pub nodes: (Identifier<'a>,), +} + +#[derive(Debug)] +pub struct PackageIdentifier<'a> { + pub nodes: (Identifier<'a>,), +} + +#[derive(Debug)] +pub enum PackageScope<'a> { + PackageIdentifier(PackageIdentifier<'a>), + Unit, +} + +#[derive(Debug)] +pub struct ParameterIdentifier<'a> { + pub nodes: (Identifier<'a>,), +} + +#[derive(Debug)] +pub struct PortIdentifier<'a> { + pub nodes: (Identifier<'a>,), +} + +#[derive(Debug)] +pub struct ProductionIdentifier<'a> { + pub nodes: (Identifier<'a>,), +} + +#[derive(Debug)] +pub struct ProgramIdentifier<'a> { + pub nodes: (Identifier<'a>,), +} + +#[derive(Debug)] +pub struct PropertyIdentifier<'a> { + pub nodes: (Identifier<'a>,), +} + +#[derive(Debug)] +pub struct PsClassIdentifier<'a> { + pub nodes: (Option>, ClassIdentifier<'a>), +} + +#[derive(Debug)] +pub struct PsCovergroupIdentifier<'a> { + pub nodes: (Option>, CovergroupIdentifier<'a>), +} + +#[derive(Debug)] +pub struct PsCheckerIdentifier<'a> { + pub nodes: (Option>, CheckerIdentifier<'a>), +} + +#[derive(Debug)] +pub struct PsIdentifier<'a> { + pub nodes: (Option>, Identifier<'a>), +} + +#[derive(Debug)] +pub struct PsOrHierarchicalArrayIdentifier<'a> { + pub nodes: ( + Option>, + HierarchicalArrayIdentifier<'a>, + ), +} + +#[derive(Debug)] +pub enum PsOrHierarchicalNetIdentifier<'a> { + PackageScope(PsOrHierarchicalNetIdentifierPackageScope<'a>), + Hierarchical(PsOrHierarchicalNetIdentifierHierarchical<'a>), +} + +#[derive(Debug)] +pub struct PsOrHierarchicalNetIdentifierPackageScope<'a> { + pub nodes: (Option>, NetIdentifier<'a>), +} + +#[derive(Debug)] +pub struct PsOrHierarchicalNetIdentifierHierarchical<'a> { + pub nodes: (HierarchicalNetIdentifier<'a>), +} + +#[derive(Debug)] +pub enum PsOrHierarchicalPropertyIdentifier<'a> { + PackageScope(PsOrHierarchicalPropertyIdentifierPackageScope<'a>), + Hierarchical(PsOrHierarchicalPropertyIdentifierHierarchical<'a>), +} + +#[derive(Debug)] +pub struct PsOrHierarchicalPropertyIdentifierPackageScope<'a> { + pub nodes: (Option>, PropertyIdentifier<'a>), +} + +#[derive(Debug)] +pub struct PsOrHierarchicalPropertyIdentifierHierarchical<'a> { + pub nodes: (HierarchicalPropertyIdentifier<'a>), +} + +#[derive(Debug)] +pub enum PsOrHierarchicalSequenceIdentifier<'a> { + PackageScope(PsOrHierarchicalSequenceIdentifierPackageScope<'a>), + Hierarchical(PsOrHierarchicalSequenceIdentifierHierarchical<'a>), +} + +#[derive(Debug)] +pub struct PsOrHierarchicalSequenceIdentifierPackageScope<'a> { + pub nodes: (Option>, SequenceIdentifier<'a>), +} + +#[derive(Debug)] +pub struct PsOrHierarchicalSequenceIdentifierHierarchical<'a> { + pub nodes: (HierarchicalSequenceIdentifier<'a>), +} + +#[derive(Debug)] +pub enum PsOrHierarchicalTfIdentifier<'a> { + PackageScope(PsOrHierarchicalTfIdentifierPackageScope<'a>), + Hierarchical(PsOrHierarchicalTfIdentifierHierarchical<'a>), +} + +#[derive(Debug)] +pub struct PsOrHierarchicalTfIdentifierPackageScope<'a> { + pub nodes: (Option>, TfIdentifier<'a>), +} + +#[derive(Debug)] +pub struct PsOrHierarchicalTfIdentifierHierarchical<'a> { + pub nodes: (HierarchicalTfIdentifier<'a>), +} + +#[derive(Debug)] +pub enum PsParameterIdentifier<'a> { + Scope(PsParameterIdentifierScope<'a>), + Generate(PsParameterIdentifierGenerate<'a>), +} + +#[derive(Debug)] +pub struct PsParameterIdentifierScope<'a> { + pub nodes: ( + Option>, + ParameterIdentifier<'a>, + ), +} + +#[derive(Debug)] +pub struct PsParameterIdentifierGenerate<'a> { + pub nodes: ( + Vec<(GenerateBlockIdentifier<'a>, Option>)>, + ParameterIdentifier<'a>, + ), +} + +#[derive(Debug)] +pub struct PsTypeIdentifier<'a> { + pub nodes: ( + Option>, + TypeIdentifier<'a>, + ), +} + +#[derive(Debug)] +pub enum LocalOrPackageScopeOrClassScope<'a> { + Local, + PackageScope(PackageScope<'a>), + ClassScope(ClassScope<'a>), +} + +#[derive(Debug)] +pub struct SequenceIdentifier<'a> { + pub nodes: (Identifier<'a>,), +} + +#[derive(Debug)] +pub struct SignalIdentifier<'a> { + pub nodes: (Identifier<'a>,), +} + +#[derive(Debug)] +pub struct SimpleIdentifier<'a> { + pub nodes: (&'a str,), +} + +#[derive(Debug)] +pub struct SpecparamIdentifier<'a> { + pub nodes: (Identifier<'a>,), +} + +#[derive(Debug)] +pub struct SystemTfIdentifier<'a> { + pub nodes: (&'a str,), +} + +#[derive(Debug)] +pub struct TaskIdentifier<'a> { + pub nodes: (Identifier<'a>,), +} + +#[derive(Debug)] +pub struct TfIdentifier<'a> { + pub nodes: (Identifier<'a>,), +} + +#[derive(Debug)] +pub struct TerminalIdentifier<'a> { + pub nodes: (Identifier<'a>,), +} + +#[derive(Debug)] +pub struct TopmoduleIdentifier<'a> { + pub nodes: (Identifier<'a>,), +} + +#[derive(Debug)] +pub struct TypeIdentifier<'a> { + pub nodes: (Identifier<'a>,), +} + +#[derive(Debug)] +pub struct UdpIdentifier<'a> { + pub nodes: (Identifier<'a>,), +} + +#[derive(Debug)] +pub struct VariableIdentifier<'a> { + pub nodes: (Identifier<'a>,), +} + +#[derive(Debug)] +pub enum ImplicitClassHandleOrClassScopeOrPackageScope<'a> { + ImplicitClassHandle(ImplicitClassHandle), + ClassScope(ClassScope<'a>), + PackageScope(PackageScope<'a>), +} + +#[derive(Debug)] +pub enum ImplicitClassHandleOrPackageScope<'a> { + ImplicitClassHandle(ImplicitClassHandle), + PackageScope(PackageScope<'a>), +} + +#[derive(Debug)] +pub enum ImplicitClassHandleOrClassScope<'a> { + ImplicitClassHandle(ImplicitClassHandle), + ClassScope(ClassScope<'a>), +} + +#[derive(Debug)] +pub enum PackageScopeOrClassScope<'a> { + PackageScope(PackageScope<'a>), + ClassScope(ClassScope<'a>), } // ----------------------------------------------------------------------------- -pub fn array_identifier(s: &str) -> IResult<&str, Identifier> { - identifier(s) +pub fn array_identifier(s: &str) -> IResult<&str, ArrayIdentifier> { + let (s, a) = identifier(s)?; + Ok((s, ArrayIdentifier { nodes: (a,) })) } -pub fn block_identifier(s: &str) -> IResult<&str, Identifier> { - identifier(s) +pub fn block_identifier(s: &str) -> IResult<&str, BlockIdentifier> { + let (s, a) = identifier(s)?; + Ok((s, BlockIdentifier { nodes: (a,) })) } -pub fn bin_identifier(s: &str) -> IResult<&str, Identifier> { - identifier(s) +pub fn bin_identifier(s: &str) -> IResult<&str, BinIdentifier> { + let (s, a) = identifier(s)?; + Ok((s, BinIdentifier { nodes: (a,) })) } -pub fn c_identifier(s: &str) -> IResult<&str, Identifier> { +pub fn c_identifier(s: &str) -> IResult<&str, CIdentifier> { ws(c_identifier_impl)(s) } -pub fn c_identifier_impl(s: &str) -> IResult<&str, Identifier> { - let (s, x) = is_a(AZ_)(s)?; - let (s, y) = opt(is_a(AZ09_))(s)?; - let raw = if let Some(y) = y { - str_concat::concat(x, y).unwrap() +pub fn c_identifier_impl(s: &str) -> IResult<&str, CIdentifier> { + let (s, a) = is_a(AZ_)(s)?; + let (s, b) = opt(is_a(AZ09_))(s)?; + let a = if let Some(b) = b { + str_concat::concat(a, b).unwrap() } else { - x + a }; - Ok((s, Identifier { raw })) + Ok((s, CIdentifier { nodes: (a,) })) } -pub fn cell_identifier(s: &str) -> IResult<&str, Identifier> { - identifier(s) +pub fn cell_identifier(s: &str) -> IResult<&str, CellIdentifier> { + let (s, a) = identifier(s)?; + Ok((s, CellIdentifier { nodes: (a,) })) } -pub fn checker_identifier(s: &str) -> IResult<&str, Identifier> { - identifier(s) +pub fn checker_identifier(s: &str) -> IResult<&str, CheckerIdentifier> { + let (s, a) = identifier(s)?; + Ok((s, CheckerIdentifier { nodes: (a,) })) } -pub fn class_identifier(s: &str) -> IResult<&str, Identifier> { - identifier(s) +pub fn class_identifier(s: &str) -> IResult<&str, ClassIdentifier> { + let (s, a) = identifier(s)?; + Ok((s, ClassIdentifier { nodes: (a,) })) } -pub fn class_variable_identifier(s: &str) -> IResult<&str, Identifier> { - variable_identifier(s) +pub fn class_variable_identifier(s: &str) -> IResult<&str, ClassVariableIdentifier> { + let (s, a) = variable_identifier(s)?; + Ok((s, ClassVariableIdentifier { nodes: (a,) })) } -pub fn clocking_identifier(s: &str) -> IResult<&str, Identifier> { - identifier(s) +pub fn clocking_identifier(s: &str) -> IResult<&str, ClockingIdentifier> { + let (s, a) = identifier(s)?; + Ok((s, ClockingIdentifier { nodes: (a,) })) } -pub fn config_identifier(s: &str) -> IResult<&str, Identifier> { - identifier(s) +pub fn config_identifier(s: &str) -> IResult<&str, ConfigIdentifier> { + let (s, a) = identifier(s)?; + Ok((s, ConfigIdentifier { nodes: (a,) })) } -pub fn const_identifier(s: &str) -> IResult<&str, Identifier> { - identifier(s) +pub fn const_identifier(s: &str) -> IResult<&str, ConstIdentifier> { + let (s, a) = identifier(s)?; + Ok((s, ConstIdentifier { nodes: (a,) })) } -pub fn constraint_identifier(s: &str) -> IResult<&str, Identifier> { - identifier(s) +pub fn constraint_identifier(s: &str) -> IResult<&str, ConstraintIdentifier> { + let (s, a) = identifier(s)?; + Ok((s, ConstraintIdentifier { nodes: (a,) })) } -pub fn covergroup_identifier(s: &str) -> IResult<&str, Identifier> { - identifier(s) +pub fn covergroup_identifier(s: &str) -> IResult<&str, CovergroupIdentifier> { + let (s, a) = identifier(s)?; + Ok((s, CovergroupIdentifier { nodes: (a,) })) } -pub fn covergroup_variable_identifier(s: &str) -> IResult<&str, Identifier> { - variable_identifier(s) +pub fn covergroup_variable_identifier(s: &str) -> IResult<&str, CovergroupVariableIdentifier> { + let (s, a) = variable_identifier(s)?; + Ok((s, CovergroupVariableIdentifier { nodes: (a,) })) } -pub fn cover_point_identifier(s: &str) -> IResult<&str, Identifier> { - identifier(s) +pub fn cover_point_identifier(s: &str) -> IResult<&str, CoverPointIdentifier> { + let (s, a) = identifier(s)?; + Ok((s, CoverPointIdentifier { nodes: (a,) })) } -pub fn cross_identifier(s: &str) -> IResult<&str, Identifier> { - identifier(s) +pub fn cross_identifier(s: &str) -> IResult<&str, CrossIdentifier> { + let (s, a) = identifier(s)?; + Ok((s, CrossIdentifier { nodes: (a,) })) } -pub fn dynamic_array_variable_identifier(s: &str) -> IResult<&str, Identifier> { - variable_identifier(s) +pub fn dynamic_array_variable_identifier(s: &str) -> IResult<&str, DynamicArrayVariableIdentifier> { + let (s, a) = variable_identifier(s)?; + Ok((s, DynamicArrayVariableIdentifier { nodes: (a,) })) } -pub fn enum_identifier(s: &str) -> IResult<&str, Identifier> { - identifier(s) +pub fn enum_identifier(s: &str) -> IResult<&str, EnumIdentifier> { + let (s, a) = identifier(s)?; + Ok((s, EnumIdentifier { nodes: (a,) })) } -pub fn escaped_identifier(s: &str) -> IResult<&str, Identifier> { +pub fn escaped_identifier(s: &str) -> IResult<&str, EscapedIdentifier> { ws(escaped_identifier_impl)(s) } -pub fn escaped_identifier_impl(s: &str) -> IResult<&str, Identifier> { - let (s, x) = tag("\\")(s)?; - let (s, y) = is_not(" \t\r\n")(s)?; - Ok(( - s, - Identifier { - raw: str_concat::concat(x, y).unwrap(), - }, - )) +pub fn escaped_identifier_impl(s: &str) -> IResult<&str, EscapedIdentifier> { + let (s, a) = tag("\\")(s)?; + let (s, b) = is_not(" \t\r\n")(s)?; + let a = str_concat::concat(a, b).unwrap(); + Ok((s, EscapedIdentifier { nodes: (a,) })) } -pub fn formal_identifier(s: &str) -> IResult<&str, Identifier> { - identifier(s) +pub fn formal_identifier(s: &str) -> IResult<&str, FormalIdentifier> { + let (s, a) = identifier(s)?; + Ok((s, FormalIdentifier { nodes: (a,) })) } -pub fn formal_port_identifier(s: &str) -> IResult<&str, Identifier> { - identifier(s) +pub fn formal_port_identifier(s: &str) -> IResult<&str, FormalPortIdentifier> { + let (s, a) = identifier(s)?; + Ok((s, FormalPortIdentifier { nodes: (a,) })) } -pub fn function_identifier(s: &str) -> IResult<&str, Identifier> { - identifier(s) +pub fn function_identifier(s: &str) -> IResult<&str, FunctionIdentifier> { + let (s, a) = identifier(s)?; + Ok((s, FunctionIdentifier { nodes: (a,) })) } -pub fn generate_block_identifier(s: &str) -> IResult<&str, Identifier> { - identifier(s) +pub fn generate_block_identifier(s: &str) -> IResult<&str, GenerateBlockIdentifier> { + let (s, a) = identifier(s)?; + Ok((s, GenerateBlockIdentifier { nodes: (a,) })) } -pub fn genvar_identifier(s: &str) -> IResult<&str, Identifier> { - identifier(s) +pub fn genvar_identifier(s: &str) -> IResult<&str, GenvarIdentifier> { + let (s, a) = identifier(s)?; + Ok((s, GenvarIdentifier { nodes: (a,) })) } -pub fn hierarchical_array_identifier(s: &str) -> IResult<&str, HierarchicalIdentifier> { - hierarchical_identifier(s) +pub fn hierarchical_array_identifier(s: &str) -> IResult<&str, HierarchicalArrayIdentifier> { + let (s, a) = hierarchical_identifier(s)?; + Ok((s, HierarchicalArrayIdentifier { nodes: (a,) })) } -pub fn hierarchical_block_identifier(s: &str) -> IResult<&str, HierarchicalIdentifier> { - hierarchical_identifier(s) +pub fn hierarchical_block_identifier(s: &str) -> IResult<&str, HierarchicalBlockIdentifier> { + let (s, a) = hierarchical_identifier(s)?; + Ok((s, HierarchicalBlockIdentifier { nodes: (a,) })) } -pub fn hierarchical_event_identifier(s: &str) -> IResult<&str, HierarchicalIdentifier> { - hierarchical_identifier(s) -} - -pub fn hierarchy(s: &str) -> IResult<&str, Hierarchy> { - let (s, x) = identifier(s)?; - let (s, y) = constant_bit_select(s)?; - let (s, _) = symbol(".")(s)?; - - Ok(( - s, - Hierarchy { - identifier: x, - constant_bit_select: Some(y), - }, - )) +pub fn hierarchical_event_identifier(s: &str) -> IResult<&str, HierarchicalEventIdentifier> { + let (s, a) = hierarchical_identifier(s)?; + Ok((s, HierarchicalEventIdentifier { nodes: (a,) })) } pub fn hierarchical_identifier(s: &str) -> IResult<&str, HierarchicalIdentifier> { - let (s, x) = opt(terminated(symbol("$root"), symbol(".")))(s)?; - let (s, mut y) = many0(hierarchy)(s)?; - let (s, z) = identifier(s)?; - - if let Some(x) = x { - y.insert( - 0, - Hierarchy { - identifier: Identifier { raw: x }, - constant_bit_select: None, - }, - ); - } - - Ok(( - s, - HierarchicalIdentifier { - hierarchy: y, - identifier: z, - }, - )) + Err(Err::Error(make_error(s, ErrorKind::Fix))) } -pub fn hierarchical_net_identifier(s: &str) -> IResult<&str, HierarchicalIdentifier> { - hierarchical_identifier(s) +pub fn hierarchical_net_identifier(s: &str) -> IResult<&str, HierarchicalNetIdentifier> { + let (s, a) = hierarchical_identifier(s)?; + Ok((s, HierarchicalNetIdentifier { nodes: (a,) })) } -pub fn hierarchical_parameter_identifier(s: &str) -> IResult<&str, HierarchicalIdentifier> { - hierarchical_identifier(s) +pub fn hierarchical_parameter_identifier( + s: &str, +) -> IResult<&str, HierarchicalParameterIdentifier> { + let (s, a) = hierarchical_identifier(s)?; + Ok((s, HierarchicalParameterIdentifier { nodes: (a,) })) } -pub fn hierarchical_property_identifier(s: &str) -> IResult<&str, HierarchicalIdentifier> { - hierarchical_identifier(s) +pub fn hierarchical_property_identifier(s: &str) -> IResult<&str, HierarchicalPropertyIdentifier> { + let (s, a) = hierarchical_identifier(s)?; + Ok((s, HierarchicalPropertyIdentifier { nodes: (a,) })) } -pub fn hierarchical_sequence_identifier(s: &str) -> IResult<&str, HierarchicalIdentifier> { - hierarchical_identifier(s) +pub fn hierarchical_sequence_identifier(s: &str) -> IResult<&str, HierarchicalSequenceIdentifier> { + let (s, a) = hierarchical_identifier(s)?; + Ok((s, HierarchicalSequenceIdentifier { nodes: (a,) })) } -pub fn hierarchical_task_identifier(s: &str) -> IResult<&str, HierarchicalIdentifier> { - hierarchical_identifier(s) +pub fn hierarchical_task_identifier(s: &str) -> IResult<&str, HierarchicalTaskIdentifier> { + let (s, a) = hierarchical_identifier(s)?; + Ok((s, HierarchicalTaskIdentifier { nodes: (a,) })) } -pub fn hierarchical_tf_identifier(s: &str) -> IResult<&str, HierarchicalIdentifier> { - hierarchical_identifier(s) +pub fn hierarchical_tf_identifier(s: &str) -> IResult<&str, HierarchicalTfIdentifier> { + let (s, a) = hierarchical_identifier(s)?; + Ok((s, HierarchicalTfIdentifier { nodes: (a,) })) } -pub fn hierarchical_variable_identifier(s: &str) -> IResult<&str, HierarchicalIdentifier> { - hierarchical_identifier(s) +pub fn hierarchical_variable_identifier(s: &str) -> IResult<&str, HierarchicalVariableIdentifier> { + let (s, a) = hierarchical_identifier(s)?; + Ok((s, HierarchicalVariableIdentifier { nodes: (a,) })) } pub fn identifier(s: &str) -> IResult<&str, Identifier> { - alt((escaped_identifier, simple_identifier))(s) + alt(( + map(escaped_identifier, |x| Identifier::EscapedIdentifier(x)), + map(simple_identifier, |x| Identifier::SimpleIdentifier(x)), + ))(s) } -pub fn index_variable_identifier(s: &str) -> IResult<&str, Identifier> { - identifier(s) +pub fn index_variable_identifier(s: &str) -> IResult<&str, IndexVariableIdentifier> { + let (s, a) = identifier(s)?; + Ok((s, IndexVariableIdentifier { nodes: (a,) })) } -pub fn interface_identifier(s: &str) -> IResult<&str, Identifier> { - identifier(s) +pub fn interface_identifier(s: &str) -> IResult<&str, InterfaceIdentifier> { + let (s, a) = identifier(s)?; + Ok((s, InterfaceIdentifier { nodes: (a,) })) } -pub fn interface_instance_identifier(s: &str) -> IResult<&str, Identifier> { - identifier(s) +pub fn interface_instance_identifier(s: &str) -> IResult<&str, InterfaceInstanceIdentifier> { + let (s, a) = identifier(s)?; + Ok((s, InterfaceInstanceIdentifier { nodes: (a,) })) } -pub fn inout_port_identifier(s: &str) -> IResult<&str, Identifier> { - identifier(s) +pub fn inout_port_identifier(s: &str) -> IResult<&str, InoutPortIdentifier> { + let (s, a) = identifier(s)?; + Ok((s, InoutPortIdentifier { nodes: (a,) })) } -pub fn input_port_identifier(s: &str) -> IResult<&str, Identifier> { - identifier(s) +pub fn input_port_identifier(s: &str) -> IResult<&str, InputPortIdentifier> { + let (s, a) = identifier(s)?; + Ok((s, InputPortIdentifier { nodes: (a,) })) } -pub fn instance_identifier(s: &str) -> IResult<&str, Identifier> { - identifier(s) +pub fn instance_identifier(s: &str) -> IResult<&str, InstanceIdentifier> { + let (s, a) = identifier(s)?; + Ok((s, InstanceIdentifier { nodes: (a,) })) } -pub fn library_identifier(s: &str) -> IResult<&str, Identifier> { - identifier(s) +pub fn library_identifier(s: &str) -> IResult<&str, LibraryIdentifier> { + let (s, a) = identifier(s)?; + Ok((s, LibraryIdentifier { nodes: (a,) })) } -pub fn member_identifier(s: &str) -> IResult<&str, Identifier> { - identifier(s) +pub fn member_identifier(s: &str) -> IResult<&str, MemberIdentifier> { + let (s, a) = identifier(s)?; + Ok((s, MemberIdentifier { nodes: (a,) })) } -pub fn method_identifier(s: &str) -> IResult<&str, Identifier> { - identifier(s) +pub fn method_identifier(s: &str) -> IResult<&str, MethodIdentifier> { + let (s, a) = identifier(s)?; + Ok((s, MethodIdentifier { nodes: (a,) })) } -pub fn modport_identifier(s: &str) -> IResult<&str, Identifier> { - identifier(s) +pub fn modport_identifier(s: &str) -> IResult<&str, ModportIdentifier> { + let (s, a) = identifier(s)?; + Ok((s, ModportIdentifier { nodes: (a,) })) } -pub fn module_identifier(s: &str) -> IResult<&str, Identifier> { - identifier(s) +pub fn module_identifier(s: &str) -> IResult<&str, ModuleIdentifier> { + let (s, a) = identifier(s)?; + Ok((s, ModuleIdentifier { nodes: (a,) })) } -pub fn net_identifier(s: &str) -> IResult<&str, Identifier> { - identifier(s) +pub fn net_identifier(s: &str) -> IResult<&str, NetIdentifier> { + let (s, a) = identifier(s)?; + Ok((s, NetIdentifier { nodes: (a,) })) } -pub fn output_port_identifier(s: &str) -> IResult<&str, Identifier> { - identifier(s) +pub fn net_type_identifier(s: &str) -> IResult<&str, NetTypeIdentifier> { + let (s, a) = identifier(s)?; + Ok((s, NetTypeIdentifier { nodes: (a,) })) } -pub fn package_identifier(s: &str) -> IResult<&str, Identifier> { - identifier(s) +pub fn output_port_identifier(s: &str) -> IResult<&str, OutputPortIdentifier> { + let (s, a) = identifier(s)?; + Ok((s, OutputPortIdentifier { nodes: (a,) })) } -pub fn package_scope(s: &str) -> IResult<&str, Scope> { - let (s, x) = alt(( - terminated(package_identifier, symbol("::")), - terminated( - map(symbol("$unit"), |x| Identifier { raw: x }), - symbol("::"), - ), - ))(s)?; - Ok((s, Scope::PackageScope(x))) +pub fn package_identifier(s: &str) -> IResult<&str, PackageIdentifier> { + let (s, a) = identifier(s)?; + Ok((s, PackageIdentifier { nodes: (a,) })) } -pub fn parameter_identifier(s: &str) -> IResult<&str, Identifier> { - identifier(s) +pub fn package_scope(s: &str) -> IResult<&str, PackageScope> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) } -pub fn port_identifier(s: &str) -> IResult<&str, Identifier> { - identifier(s) +pub fn parameter_identifier(s: &str) -> IResult<&str, ParameterIdentifier> { + let (s, a) = identifier(s)?; + Ok((s, ParameterIdentifier { nodes: (a,) })) } -pub fn production_identifier(s: &str) -> IResult<&str, Identifier> { - identifier(s) +pub fn port_identifier(s: &str) -> IResult<&str, PortIdentifier> { + let (s, a) = identifier(s)?; + Ok((s, PortIdentifier { nodes: (a,) })) } -pub fn program_identifier(s: &str) -> IResult<&str, Identifier> { - identifier(s) +pub fn production_identifier(s: &str) -> IResult<&str, ProductionIdentifier> { + let (s, a) = identifier(s)?; + Ok((s, ProductionIdentifier { nodes: (a,) })) } -pub fn property_identifier(s: &str) -> IResult<&str, Identifier> { - identifier(s) +pub fn program_identifier(s: &str) -> IResult<&str, ProgramIdentifier> { + let (s, a) = identifier(s)?; + Ok((s, ProgramIdentifier { nodes: (a,) })) } -pub fn ps_class_identifier(s: &str) -> IResult<&str, ScopedIdentifier> { - let (s, x) = opt(package_scope)(s)?; - let (s, y) = class_identifier(s)?; - Ok(( - s, - ScopedIdentifier { - scope: x, - identifier: y.into(), - }, - )) +pub fn property_identifier(s: &str) -> IResult<&str, PropertyIdentifier> { + let (s, a) = identifier(s)?; + Ok((s, PropertyIdentifier { nodes: (a,) })) } -pub fn ps_covergroup_identifier(s: &str) -> IResult<&str, ScopedIdentifier> { - let (s, x) = opt(package_scope)(s)?; - let (s, y) = covergroup_identifier(s)?; - Ok(( - s, - ScopedIdentifier { - scope: x, - identifier: y.into(), - }, - )) +pub fn ps_class_identifier(s: &str) -> IResult<&str, PsClassIdentifier> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) } -pub fn ps_checker_identifier(s: &str) -> IResult<&str, ScopedIdentifier> { - let (s, x) = opt(package_scope)(s)?; - let (s, y) = checker_identifier(s)?; - Ok(( - s, - ScopedIdentifier { - scope: x, - identifier: y.into(), - }, - )) +pub fn ps_covergroup_identifier(s: &str) -> IResult<&str, PsCovergroupIdentifier> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) } -pub fn ps_identifier(s: &str) -> IResult<&str, ScopedIdentifier> { - let (s, x) = opt(package_scope)(s)?; - let (s, y) = identifier(s)?; - Ok(( - s, - ScopedIdentifier { - scope: x, - identifier: y.into(), - }, - )) +pub fn ps_checker_identifier(s: &str) -> IResult<&str, PsCheckerIdentifier> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) } -pub fn ps_or_hierarchical_array_identifier(s: &str) -> IResult<&str, ScopedIdentifier> { - let (s, x) = opt(alt(( - terminated(implicit_class_handle, symbol(".")), - class_scope, - package_scope, - )))(s)?; - let (s, y) = hierarchical_array_identifier(s)?; - Ok(( - s, - ScopedIdentifier { - scope: x, - identifier: y, - }, - )) +pub fn ps_identifier(s: &str) -> IResult<&str, PsIdentifier> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) } -pub fn ps_or_hierarchical_net_identifier(s: &str) -> IResult<&str, ScopedIdentifier> { - let (s, x) = opt(package_scope)(s)?; - let (s, y) = alt(( - map(net_identifier, |x| x.into()), - hierarchical_net_identifier, - ))(s)?; - Ok(( - s, - ScopedIdentifier { - scope: x, - identifier: y, - }, - )) +pub fn ps_or_hierarchical_array_identifier( + s: &str, +) -> IResult<&str, PsOrHierarchicalArrayIdentifier> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) } -pub fn ps_or_hierarchical_property_identifier(s: &str) -> IResult<&str, ScopedIdentifier> { - let (s, x) = opt(package_scope)(s)?; - let (s, y) = alt(( - map(property_identifier, |x| x.into()), - hierarchical_property_identifier, - ))(s)?; - Ok(( - s, - ScopedIdentifier { - scope: x, - identifier: y, - }, - )) +pub fn ps_or_hierarchical_net_identifier(s: &str) -> IResult<&str, PsOrHierarchicalNetIdentifier> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) } -pub fn ps_or_hierarchical_sequence_identifier(s: &str) -> IResult<&str, ScopedIdentifier> { - let (s, x) = opt(package_scope)(s)?; - let (s, y) = alt(( - map(sequence_identifier, |x| x.into()), - hierarchical_sequence_identifier, - ))(s)?; - Ok(( - s, - ScopedIdentifier { - scope: x, - identifier: y, - }, - )) +pub fn ps_or_hierarchical_property_identifier( + s: &str, +) -> IResult<&str, PsOrHierarchicalPropertyIdentifier> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) } -pub fn ps_or_hierarchical_tf_identifier(s: &str) -> IResult<&str, ScopedIdentifier> { - let (s, x) = opt(package_scope)(s)?; - let (s, y) = alt((map(tf_identifier, |x| x.into()), hierarchical_tf_identifier))(s)?; - Ok(( - s, - ScopedIdentifier { - scope: x, - identifier: y, - }, - )) +pub fn ps_or_hierarchical_sequence_identifier( + s: &str, +) -> IResult<&str, PsOrHierarchicalSequenceIdentifier> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) } -pub fn ps_parameter_identifier(s: &str) -> IResult<&str, ScopedIdentifier> { - let (s, x) = opt(alt((package_scope, class_scope, generate_block_scope)))(s)?; - let (s, y) = parameter_identifier(s)?; - Ok(( - s, - ScopedIdentifier { - scope: x, - identifier: y.into(), - }, - )) +pub fn ps_or_hierarchical_tf_identifier(s: &str) -> IResult<&str, PsOrHierarchicalTfIdentifier> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) } -pub fn generate_block_scope(s: &str) -> IResult<&str, Scope> { - let (s, x) = many0(tuple(( - generate_block_identifier, - opt(bracket(constant_expression)), - symbol("."), - )))(s)?; - - let mut ret = Vec::new(); - for (x, y, _) in x { - ret.push(GenerateBlockScope { - identifier: x, - constant_expression: y, - }); - } - - Ok((s, Scope::GenerateBlockScope(ret))) +pub fn ps_parameter_identifier(s: &str) -> IResult<&str, PsParameterIdentifier> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) } -pub fn ps_type_identifier(s: &str) -> IResult<&str, ScopedIdentifier> { - let (s, x) = opt(alt(( - map(terminated(symbol("local"), symbol("::")), |_| { - Scope::LocalScope - }), - package_scope, - class_scope, - )))(s)?; - let (s, y) = type_identifier(s)?; - Ok(( - s, - ScopedIdentifier { - scope: x, - identifier: y.into(), - }, - )) +pub fn ps_type_identifier(s: &str) -> IResult<&str, PsTypeIdentifier> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) } -pub fn sequence_identifier(s: &str) -> IResult<&str, Identifier> { - identifier(s) +pub fn sequence_identifier(s: &str) -> IResult<&str, SequenceIdentifier> { + let (s, a) = identifier(s)?; + Ok((s, SequenceIdentifier { nodes: (a,) })) } -pub fn signal_identifier(s: &str) -> IResult<&str, Identifier> { - identifier(s) +pub fn signal_identifier(s: &str) -> IResult<&str, SignalIdentifier> { + let (s, a) = identifier(s)?; + Ok((s, SignalIdentifier { nodes: (a,) })) } -pub fn simple_identifier(s: &str) -> IResult<&str, Identifier> { +pub fn simple_identifier(s: &str) -> IResult<&str, SimpleIdentifier> { ws(simple_identifier_impl)(s) } -pub fn simple_identifier_impl(s: &str) -> IResult<&str, Identifier> { - let (s, x) = is_a(AZ_)(s)?; - let (s, y) = opt(is_a(AZ09_DOLLAR))(s)?; - let raw = if let Some(y) = y { - str_concat::concat(x, y).unwrap() +pub fn simple_identifier_impl(s: &str) -> IResult<&str, SimpleIdentifier> { + let (s, a) = is_a(AZ_)(s)?; + let (s, b) = opt(is_a(AZ09_DOLLAR))(s)?; + let a = if let Some(b) = b { + str_concat::concat(a, b).unwrap() } else { - x + a }; - Ok((s, Identifier { raw })) + Ok((s, SimpleIdentifier { nodes: (a,) })) } -pub fn specparam_identifier(s: &str) -> IResult<&str, Identifier> { - identifier(s) +pub fn specparam_identifier(s: &str) -> IResult<&str, SpecparamIdentifier> { + let (s, a) = identifier(s)?; + Ok((s, SpecparamIdentifier { nodes: (a,) })) } -pub fn system_tf_identifier(s: &str) -> IResult<&str, Identifier> { +pub fn system_tf_identifier(s: &str) -> IResult<&str, SystemTfIdentifier> { ws(system_tf_identifier_impl)(s) } -pub fn system_tf_identifier_impl(s: &str) -> IResult<&str, Identifier> { - let (s, x) = tag("$")(s)?; - let (s, y) = is_a(AZ09_DOLLAR)(s)?; - Ok(( - s, - Identifier { - raw: str_concat::concat(x, y).unwrap(), - }, - )) +pub fn system_tf_identifier_impl(s: &str) -> IResult<&str, SystemTfIdentifier> { + let (s, a) = tag("$")(s)?; + let (s, b) = is_a(AZ09_DOLLAR)(s)?; + let a = str_concat::concat(a, b).unwrap(); + Ok((s, SystemTfIdentifier { nodes: (a,) })) } -pub fn task_identifier(s: &str) -> IResult<&str, Identifier> { - identifier(s) +pub fn task_identifier(s: &str) -> IResult<&str, TaskIdentifier> { + let (s, a) = identifier(s)?; + Ok((s, TaskIdentifier { nodes: (a,) })) } -pub fn tf_identifier(s: &str) -> IResult<&str, Identifier> { - identifier(s) +pub fn tf_identifier(s: &str) -> IResult<&str, TfIdentifier> { + let (s, a) = identifier(s)?; + Ok((s, TfIdentifier { nodes: (a,) })) } -pub fn terminal_identifier(s: &str) -> IResult<&str, Identifier> { - identifier(s) +pub fn terminal_identifier(s: &str) -> IResult<&str, TerminalIdentifier> { + let (s, a) = identifier(s)?; + Ok((s, TerminalIdentifier { nodes: (a,) })) } -pub fn topmodule_identifier(s: &str) -> IResult<&str, Identifier> { - identifier(s) +pub fn topmodule_identifier(s: &str) -> IResult<&str, TopmoduleIdentifier> { + let (s, a) = identifier(s)?; + Ok((s, TopmoduleIdentifier { nodes: (a,) })) } -pub fn type_identifier(s: &str) -> IResult<&str, Identifier> { - identifier(s) +pub fn type_identifier(s: &str) -> IResult<&str, TypeIdentifier> { + let (s, a) = identifier(s)?; + Ok((s, TypeIdentifier { nodes: (a,) })) } -pub fn udp_identifier(s: &str) -> IResult<&str, Identifier> { - identifier(s) +pub fn udp_identifier(s: &str) -> IResult<&str, UdpIdentifier> { + let (s, a) = identifier(s)?; + Ok((s, UdpIdentifier { nodes: (a,) })) } -pub fn variable_identifier(s: &str) -> IResult<&str, Identifier> { - identifier(s) +pub fn variable_identifier(s: &str) -> IResult<&str, VariableIdentifier> { + let (s, a) = identifier(s)?; + Ok((s, VariableIdentifier { nodes: (a,) })) +} + +pub fn implicit_class_handle_or_class_scope_or_package_scope( + s: &str, +) -> IResult<&str, ImplicitClassHandleOrClassScopeOrPackageScope> { + alt(( + map(terminated(implicit_class_handle, symbol(".")), |x| { + ImplicitClassHandleOrClassScopeOrPackageScope::ImplicitClassHandle(x) + }), + map(class_scope, |x| { + ImplicitClassHandleOrClassScopeOrPackageScope::ClassScope(x) + }), + map(package_scope, |x| { + ImplicitClassHandleOrClassScopeOrPackageScope::PackageScope(x) + }), + ))(s) +} + +pub fn implicit_class_handle_or_package_scope( + s: &str, +) -> IResult<&str, ImplicitClassHandleOrPackageScope> { + alt(( + map(terminated(implicit_class_handle, symbol(".")), |x| { + ImplicitClassHandleOrPackageScope::ImplicitClassHandle(x) + }), + map(package_scope, |x| { + ImplicitClassHandleOrPackageScope::PackageScope(x) + }), + ))(s) +} + +pub fn implicit_class_handle_or_class_scope( + s: &str, +) -> IResult<&str, ImplicitClassHandleOrClassScope> { + alt(( + map(terminated(implicit_class_handle, symbol(".")), |x| { + ImplicitClassHandleOrClassScope::ImplicitClassHandle(x) + }), + map(class_scope, |x| { + ImplicitClassHandleOrClassScope::ClassScope(x) + }), + ))(s) +} + +pub fn package_scope_or_class_scope(s: &str) -> IResult<&str, PackageScopeOrClassScope> { + alt(( + map(package_scope, |x| PackageScopeOrClassScope::PackageScope(x)), + map(class_scope, |x| PackageScopeOrClassScope::ClassScope(x)), + ))(s) } // ----------------------------------------------------------------------------- diff --git a/src/parser/instantiations/checker_instantiation.rs b/src/parser/instantiations/checker_instantiation.rs new file mode 100644 index 0000000..3e5cc68 --- /dev/null +++ b/src/parser/instantiations/checker_instantiation.rs @@ -0,0 +1,113 @@ +use crate::parser::*; +use nom::branch::*; +use nom::combinator::*; +use nom::multi::*; +use nom::IResult; + +// ----------------------------------------------------------------------------- + +#[derive(Debug)] +pub struct CheckerInstantiation<'a> { + pub nodes: ( + PsCheckerIdentifier<'a>, + NameOfInstance<'a>, + Option>, + ), +} + +#[derive(Debug)] +pub enum ListOfCheckerPortConnections<'a> { + Ordered(Vec>), + Named(Vec>), +} + +#[derive(Debug)] +pub struct OrderedCheckerPortConnection<'a> { + pub nodes: (Vec>, Option>), +} + +#[derive(Debug)] +pub enum NamedCheckerPortConnection<'a> { + Identifier(NamedCheckerPortConnectionIdentifier<'a>), + Asterisk(NamedCheckerPortConnectionAsterisk<'a>), +} + +#[derive(Debug)] +pub struct NamedCheckerPortConnectionIdentifier<'a> { + pub nodes: ( + Vec>, + FormalPortIdentifier<'a>, + Option>, + ), +} + +#[derive(Debug)] +pub struct NamedCheckerPortConnectionAsterisk<'a> { + pub nodes: (Vec>,), +} + +// ----------------------------------------------------------------------------- + +pub fn checker_instantiation(s: &str) -> IResult<&str, CheckerInstantiation> { + let (s, x) = ps_checker_identifier(s)?; + let (s, y) = name_of_instance(s)?; + let (s, z) = paren(opt(list_of_checker_port_connections))(s)?; + let (s, _) = symbol(";")(s)?; + Ok((s, CheckerInstantiation { nodes: (x, y, z) })) +} + +pub fn list_of_checker_port_connections(s: &str) -> IResult<&str, ListOfCheckerPortConnections> { + alt(( + map( + separated_nonempty_list(symbol(","), ordered_checker_port_connection), + |x| ListOfCheckerPortConnections::Ordered(x), + ), + map( + separated_nonempty_list(symbol(","), named_checker_port_connection), + |x| ListOfCheckerPortConnections::Named(x), + ), + ))(s) +} + +pub fn ordered_checker_port_connection(s: &str) -> IResult<&str, OrderedCheckerPortConnection> { + let (s, x) = many0(attribute_instance)(s)?; + let (s, y) = opt(property_actual_arg)(s)?; + Ok((s, OrderedCheckerPortConnection { nodes: (x, y) })) +} + +pub fn named_checker_port_connection(s: &str) -> IResult<&str, NamedCheckerPortConnection> { + alt(( + named_checker_port_connection_identifier, + named_checker_port_connection_asterisk, + ))(s) +} + +pub fn named_checker_port_connection_identifier( + s: &str, +) -> IResult<&str, NamedCheckerPortConnection> { + let (s, x) = many0(attribute_instance)(s)?; + let (s, _) = symbol(".")(s)?; + let (s, y) = formal_port_identifier(s)?; + let (s, z) = opt(paren(opt(property_actual_arg)))(s)?; + let z = if let Some(Some(z)) = z { Some(z) } else { None }; + Ok(( + s, + NamedCheckerPortConnection::Identifier(NamedCheckerPortConnectionIdentifier { + nodes: (x, y, z), + }), + )) +} + +pub fn named_checker_port_connection_asterisk( + s: &str, +) -> IResult<&str, NamedCheckerPortConnection> { + let (s, x) = many0(attribute_instance)(s)?; + let (s, _) = symbol(".")(s)?; + let (s, _) = symbol("*")(s)?; + Ok(( + s, + NamedCheckerPortConnection::Asterisk(NamedCheckerPortConnectionAsterisk { nodes: (x,) }), + )) +} + +// ----------------------------------------------------------------------------- diff --git a/src/parser/instantiations/generated_instantiation.rs b/src/parser/instantiations/generated_instantiation.rs new file mode 100644 index 0000000..0b08212 --- /dev/null +++ b/src/parser/instantiations/generated_instantiation.rs @@ -0,0 +1,273 @@ +use crate::parser::*; +use nom::branch::*; +use nom::combinator::*; +use nom::multi::*; +use nom::sequence::*; +use nom::IResult; + +// ----------------------------------------------------------------------------- + +#[derive(Debug)] +pub struct GenerateRegion<'a> { + pub nodes: (Vec>,), +} + +#[derive(Debug)] +pub struct LoopGenerateConstruct<'a> { + pub nodes: ( + GenvarInitialization<'a>, + ConstantExpression<'a>, + GenvarIteration<'a>, + GenerateBlock<'a>, + ), +} + +#[derive(Debug)] +pub struct GenvarInitialization<'a> { + pub nodes: (Option, GenvarIdentifier<'a>, ConstantExpression<'a>), +} + +#[derive(Debug)] +pub struct Genvar {} + +#[derive(Debug)] +pub enum GenvarIteration<'a> { + Assignment(GenvarIterationAssignment<'a>), + Prefix(GenvarIterationPrefix<'a>), + Suffix(GenvarIterationSuffix<'a>), +} + +#[derive(Debug)] +pub struct GenvarIterationAssignment<'a> { + pub nodes: (GenvarIdentifier<'a>, Operator<'a>, ConstantExpression<'a>), +} + +#[derive(Debug)] +pub struct GenvarIterationPrefix<'a> { + pub nodes: (Operator<'a>, GenvarIdentifier<'a>), +} + +#[derive(Debug)] +pub struct GenvarIterationSuffix<'a> { + pub nodes: (GenvarIdentifier<'a>, Operator<'a>), +} + +#[derive(Debug)] +pub enum ConditionalGenerateConstruct<'a> { + If(IfGenerateConstruct<'a>), + Case(CaseGenerateConstruct<'a>), +} + +#[derive(Debug)] +pub struct IfGenerateConstruct<'a> { + pub nodes: ( + ConstantExpression<'a>, + GenerateBlock<'a>, + Option>, + ), +} + +#[derive(Debug)] +pub struct CaseGenerateConstruct<'a> { + pub nodes: (ConstantExpression<'a>, Vec>), +} + +#[derive(Debug)] +pub enum CaseGenerateItem<'a> { + Nondefault(CaseGenerateItemNondefault<'a>), + Default(CaseGenerateItemDefault<'a>), +} + +#[derive(Debug)] +pub struct CaseGenerateItemNondefault<'a> { + pub nodes: (Vec>, GenerateBlock<'a>), +} + +#[derive(Debug)] +pub struct CaseGenerateItemDefault<'a> { + pub nodes: (GenerateBlock<'a>,), +} + +#[derive(Debug)] +pub enum GenerateBlock<'a> { + Single(GenerateItem<'a>), + Multiple(GenerateBlockMultiple<'a>), +} + +#[derive(Debug)] +pub struct GenerateBlockMultiple<'a> { + pub nodes: ( + Option>, + Option>, + Vec>, + Option>, + ), +} + +#[derive(Debug)] +pub enum GenerateItem<'a> { + Module(ModuleOrGenerateItem<'a>), + Interface(InterfaceOrGenerateItem<'a>), + Checker(CheckerOrGenerateItem<'a>), +} + +// ----------------------------------------------------------------------------- + +pub fn generate_region(s: &str) -> IResult<&str, GenerateRegion> { + let (s, _) = symbol("generate")(s)?; + let (s, x) = many0(generate_item)(s)?; + let (s, _) = symbol("endgenerate")(s)?; + Ok((s, GenerateRegion { nodes: (x,) })) +} + +pub fn loop_generate_construct(s: &str) -> IResult<&str, LoopGenerateConstruct> { + let (s, _) = symbol("for")(s)?; + let (s, _) = symbol("(")(s)?; + let (s, x) = generate_initialization(s)?; + let (s, _) = symbol(";")(s)?; + let (s, y) = genvar_expression(s)?; + let (s, _) = symbol(";")(s)?; + let (s, z) = genvar_iteration(s)?; + let (s, _) = symbol(")")(s)?; + let (s, v) = generate_block(s)?; + Ok(( + s, + LoopGenerateConstruct { + nodes: (x, y, z, v), + }, + )) +} + +pub fn generate_initialization(s: &str) -> IResult<&str, GenvarInitialization> { + let (s, x) = opt(symbol("genvar"))(s)?; + let (s, y) = genvar_identifier(s)?; + let (s, _) = symbol("=")(s)?; + let (s, z) = constant_expression(s)?; + Ok(( + s, + GenvarInitialization { + nodes: (x.map(|_| Genvar {}), y, z), + }, + )) +} + +pub fn genvar_iteration(s: &str) -> IResult<&str, GenvarIteration> { + alt(( + genvar_iteration_assignment, + genvar_iteration_prefix, + genvar_iteration_suffix, + ))(s) +} + +pub fn genvar_iteration_assignment(s: &str) -> IResult<&str, GenvarIteration> { + let (s, x) = genvar_identifier(s)?; + let (s, y) = assignment_operator(s)?; + let (s, z) = genvar_expression(s)?; + Ok(( + s, + GenvarIteration::Assignment(GenvarIterationAssignment { nodes: (x, y, z) }), + )) +} + +pub fn genvar_iteration_prefix(s: &str) -> IResult<&str, GenvarIteration> { + let (s, x) = inc_or_dec_operator(s)?; + let (s, y) = genvar_identifier(s)?; + Ok(( + s, + GenvarIteration::Prefix(GenvarIterationPrefix { nodes: (x, y) }), + )) +} + +pub fn genvar_iteration_suffix(s: &str) -> IResult<&str, GenvarIteration> { + let (s, x) = genvar_identifier(s)?; + let (s, y) = inc_or_dec_operator(s)?; + Ok(( + s, + GenvarIteration::Suffix(GenvarIterationSuffix { nodes: (x, y) }), + )) +} + +pub fn conditional_generate_construct(s: &str) -> IResult<&str, ConditionalGenerateConstruct> { + alt(( + map(if_generate_construct, |x| { + ConditionalGenerateConstruct::If(x) + }), + map(case_generate_construct, |x| { + ConditionalGenerateConstruct::Case(x) + }), + ))(s) +} + +pub fn if_generate_construct(s: &str) -> IResult<&str, IfGenerateConstruct> { + let (s, _) = symbol("if")(s)?; + let (s, x) = paren(constant_expression)(s)?; + let (s, y) = generate_block(s)?; + let (s, z) = opt(preceded(symbol("else"), generate_block))(s)?; + Ok((s, IfGenerateConstruct { nodes: (x, y, z) })) +} + +pub fn case_generate_construct(s: &str) -> IResult<&str, CaseGenerateConstruct> { + let (s, _) = symbol("case")(s)?; + let (s, x) = paren(constant_expression)(s)?; + let (s, y) = many1(case_generate_item)(s)?; + let (s, _) = symbol("endcase")(s)?; + Ok((s, CaseGenerateConstruct { nodes: (x, y) })) +} + +pub fn case_generate_item(s: &str) -> IResult<&str, CaseGenerateItem> { + alt((case_generate_item_nondefault, case_generate_item_default))(s) +} + +pub fn case_generate_item_nondefault(s: &str) -> IResult<&str, CaseGenerateItem> { + let (s, x) = separated_nonempty_list(symbol(","), constant_expression)(s)?; + let (s, _) = symbol(":")(s)?; + let (s, y) = generate_block(s)?; + Ok(( + s, + CaseGenerateItem::Nondefault(CaseGenerateItemNondefault { nodes: (x, y) }), + )) +} + +pub fn case_generate_item_default(s: &str) -> IResult<&str, CaseGenerateItem> { + let (s, _) = symbol("default")(s)?; + let (s, _) = opt(symbol(":"))(s)?; + let (s, x) = generate_block(s)?; + Ok(( + s, + CaseGenerateItem::Default(CaseGenerateItemDefault { nodes: (x,) }), + )) +} + +pub fn generate_block(s: &str) -> IResult<&str, GenerateBlock> { + alt((generate_block_single, generate_block_multiple))(s) +} + +pub fn generate_block_single(s: &str) -> IResult<&str, GenerateBlock> { + let (s, x) = generate_item(s)?; + Ok((s, GenerateBlock::Single(x))) +} + +pub fn generate_block_multiple(s: &str) -> IResult<&str, GenerateBlock> { + let (s, x) = opt(terminated(generate_block_identifier, symbol(":")))(s)?; + let (s, _) = symbol("begin")(s)?; + let (s, y) = opt(preceded(symbol(":"), generate_block_identifier))(s)?; + let (s, z) = many0(generate_item)(s)?; + let (s, _) = symbol("end")(s)?; + let (s, v) = opt(preceded(symbol(":"), generate_block_identifier))(s)?; + Ok(( + s, + GenerateBlock::Multiple(GenerateBlockMultiple { + nodes: (x, y, z, v), + }), + )) +} + +pub fn generate_item(s: &str) -> IResult<&str, GenerateItem> { + alt(( + map(module_or_generate_item, |x| GenerateItem::Module(x)), + map(interface_or_generate_item, |x| GenerateItem::Interface(x)), + map(checker_or_generate_item, |x| GenerateItem::Checker(x)), + ))(s) +} + +// ----------------------------------------------------------------------------- diff --git a/src/parser/instantiations/interface_instantiation.rs b/src/parser/instantiations/interface_instantiation.rs new file mode 100644 index 0000000..f7617e3 --- /dev/null +++ b/src/parser/instantiations/interface_instantiation.rs @@ -0,0 +1,27 @@ +use crate::parser::*; +use nom::combinator::*; +use nom::multi::*; +use nom::IResult; + +// ----------------------------------------------------------------------------- + +#[derive(Debug)] +pub struct InterfaceInstantiation<'a> { + pub nodes: ( + InterfaceIdentifier<'a>, + Option>, + Vec>, + ), +} + +// ----------------------------------------------------------------------------- + +pub fn interface_instantiation(s: &str) -> IResult<&str, InterfaceInstantiation> { + let (s, x) = interface_identifier(s)?; + let (s, y) = opt(parameter_value_assignment)(s)?; + let (s, z) = separated_nonempty_list(symbol(","), hierarchical_instance)(s)?; + let (s, _) = symbol(";")(s)?; + Ok((s, InterfaceInstantiation { nodes: (x, y, z) })) +} + +// ----------------------------------------------------------------------------- diff --git a/src/parser/instantiations/mod.rs b/src/parser/instantiations/mod.rs new file mode 100644 index 0000000..e2c71d7 --- /dev/null +++ b/src/parser/instantiations/mod.rs @@ -0,0 +1,10 @@ +pub mod checker_instantiation; +pub mod generated_instantiation; +pub mod interface_instantiation; +pub mod module_instantiation; +pub mod program_instantiation; +pub use checker_instantiation::*; +pub use generated_instantiation::*; +pub use interface_instantiation::*; +pub use module_instantiation::*; +pub use program_instantiation::*; diff --git a/src/parser/instantiations/module_instantiation.rs b/src/parser/instantiations/module_instantiation.rs new file mode 100644 index 0000000..4db6f9e --- /dev/null +++ b/src/parser/instantiations/module_instantiation.rs @@ -0,0 +1,181 @@ +use crate::parser::*; +use nom::branch::*; +use nom::combinator::*; +use nom::multi::*; +use nom::IResult; + +// ----------------------------------------------------------------------------- + +#[derive(Debug)] +pub struct ModuleInstantiation<'a> { + pub nodes: ( + ModuleIdentifier<'a>, + Option>, + Vec>, + ), +} + +#[derive(Debug)] +pub struct ParameterValueAssignment<'a> { + pub nodes: (ListOfParameterAssignments<'a>,), +} + +#[derive(Debug)] +pub enum ListOfParameterAssignments<'a> { + Ordered(Vec>), + Named(Vec>), +} + +#[derive(Debug)] +pub struct OrderedParameterAssignment<'a> { + pub nodes: (ParamExpression<'a>,), +} + +#[derive(Debug)] +pub struct NamedParameterAssignment<'a> { + pub nodes: (ParameterIdentifier<'a>, Option>), +} + +#[derive(Debug)] +pub struct HierarchicalInstance<'a> { + pub nodes: (NameOfInstance<'a>, Option>), +} + +#[derive(Debug)] +pub struct NameOfInstance<'a> { + pub nodes: (InstanceIdentifier<'a>, Vec>), +} + +#[derive(Debug)] +pub enum ListOfPortConnections<'a> { + Ordered(Vec>), + Named(Vec>), +} + +#[derive(Debug)] +pub struct OrderedPortConnection<'a> { + pub nodes: (Vec>, Option>), +} + +#[derive(Debug)] +pub enum NamedPortConnection<'a> { + Identifier(NamedPortConnectionIdentifier<'a>), + Asterisk(NamedPortConnectionAsterisk<'a>), +} + +#[derive(Debug)] +pub struct NamedPortConnectionIdentifier<'a> { + pub nodes: ( + Vec>, + PortIdentifier<'a>, + Option>, + ), +} + +#[derive(Debug)] +pub struct NamedPortConnectionAsterisk<'a> { + pub nodes: (Vec>,), +} + +// ----------------------------------------------------------------------------- + +pub fn module_instantiation(s: &str) -> IResult<&str, ModuleInstantiation> { + let (s, x) = module_identifier(s)?; + let (s, y) = opt(parameter_value_assignment)(s)?; + let (s, z) = separated_nonempty_list(symbol(","), hierarchical_instance)(s)?; + let (s, _) = symbol(";")(s)?; + Ok((s, ModuleInstantiation { nodes: (x, y, z) })) +} + +pub fn parameter_value_assignment(s: &str) -> IResult<&str, ParameterValueAssignment> { + let (s, _) = symbol("#")(s)?; + let (s, x) = paren(list_of_parameter_assignments)(s)?; + Ok((s, ParameterValueAssignment { nodes: (x,) })) +} + +pub fn list_of_parameter_assignments(s: &str) -> IResult<&str, ListOfParameterAssignments> { + alt(( + map( + separated_nonempty_list(symbol(","), ordered_parameter_assignment), + |x| ListOfParameterAssignments::Ordered(x), + ), + map( + separated_nonempty_list(symbol(","), named_parameter_assignment), + |x| ListOfParameterAssignments::Named(x), + ), + ))(s) +} + +pub fn ordered_parameter_assignment(s: &str) -> IResult<&str, OrderedParameterAssignment> { + let (s, x) = param_expression(s)?; + Ok((s, OrderedParameterAssignment { nodes: (x,) })) +} + +pub fn named_parameter_assignment(s: &str) -> IResult<&str, NamedParameterAssignment> { + let (s, _) = symbol(".")(s)?; + let (s, x) = parameter_identifier(s)?; + let (s, y) = paren(opt(param_expression))(s)?; + Ok((s, NamedParameterAssignment { nodes: (x, y) })) +} + +pub fn hierarchical_instance(s: &str) -> IResult<&str, HierarchicalInstance> { + let (s, x) = name_of_instance(s)?; + let (s, y) = paren(opt(list_of_port_connections))(s)?; + Ok((s, HierarchicalInstance { nodes: (x, y) })) +} + +pub fn name_of_instance(s: &str) -> IResult<&str, NameOfInstance> { + let (s, x) = instance_identifier(s)?; + let (s, y) = many0(unpacked_dimension)(s)?; + Ok((s, NameOfInstance { nodes: (x, y) })) +} + +pub fn list_of_port_connections(s: &str) -> IResult<&str, ListOfPortConnections> { + alt(( + map( + separated_nonempty_list(symbol(","), ordered_port_connection), + |x| ListOfPortConnections::Ordered(x), + ), + map( + separated_nonempty_list(symbol(","), named_port_connection), + |x| ListOfPortConnections::Named(x), + ), + ))(s) +} + +pub fn ordered_port_connection(s: &str) -> IResult<&str, OrderedPortConnection> { + let (s, x) = many0(attribute_instance)(s)?; + let (s, y) = opt(expression)(s)?; + Ok((s, OrderedPortConnection { nodes: (x, y) })) +} + +pub fn named_port_connection(s: &str) -> IResult<&str, NamedPortConnection> { + alt(( + named_port_connection_identifier, + named_port_connection_asterisk, + ))(s) +} + +pub fn named_port_connection_identifier(s: &str) -> IResult<&str, NamedPortConnection> { + let (s, x) = many0(attribute_instance)(s)?; + let (s, _) = symbol(".")(s)?; + let (s, y) = port_identifier(s)?; + let (s, z) = opt(paren(opt(expression)))(s)?; + let z = if let Some(Some(z)) = z { Some(z) } else { None }; + Ok(( + s, + NamedPortConnection::Identifier(NamedPortConnectionIdentifier { nodes: (x, y, z) }), + )) +} + +pub fn named_port_connection_asterisk(s: &str) -> IResult<&str, NamedPortConnection> { + let (s, x) = many0(attribute_instance)(s)?; + let (s, _) = symbol(".")(s)?; + let (s, _) = symbol("*")(s)?; + Ok(( + s, + NamedPortConnection::Asterisk(NamedPortConnectionAsterisk { nodes: (x,) }), + )) +} + +// ----------------------------------------------------------------------------- diff --git a/src/parser/instantiations/program_instantiation.rs b/src/parser/instantiations/program_instantiation.rs new file mode 100644 index 0000000..6983897 --- /dev/null +++ b/src/parser/instantiations/program_instantiation.rs @@ -0,0 +1,27 @@ +use crate::parser::*; +use nom::combinator::*; +use nom::multi::*; +use nom::IResult; + +// ----------------------------------------------------------------------------- + +#[derive(Debug)] +pub struct ProgramInstantiation<'a> { + pub nodes: ( + ProgramIdentifier<'a>, + Option>, + Vec>, + ), +} + +// ----------------------------------------------------------------------------- + +pub fn program_instantiation(s: &str) -> IResult<&str, ProgramInstantiation> { + let (s, x) = program_identifier(s)?; + let (s, y) = opt(parameter_value_assignment)(s)?; + let (s, z) = separated_nonempty_list(symbol(","), hierarchical_instance)(s)?; + let (s, _) = symbol(";")(s)?; + Ok((s, ProgramInstantiation { nodes: (x, y, z) })) +} + +// ----------------------------------------------------------------------------- diff --git a/src/parser/source_text/checker_items.rs b/src/parser/source_text/checker_items.rs new file mode 100644 index 0000000..2367057 --- /dev/null +++ b/src/parser/source_text/checker_items.rs @@ -0,0 +1,109 @@ +use crate::parser::*; +//use nom::branch::*; +//use nom::combinator::*; +use nom::error::*; +use nom::{Err, IResult}; + +// ----------------------------------------------------------------------------- + +#[derive(Debug)] +pub struct CheckerPortList<'a> { + pub nodes: (Vec>,), +} + +#[derive(Debug)] +pub struct CheckerPortItem<'a> { + pub nodes: ( + Vec>, + Option, + PropertyFormalType<'a>, + FormalPortIdentifier<'a>, + Vec>, + Option>, + ), +} + +#[derive(Debug)] +pub enum CheckerPortDirection { + Input, + Output, +} + +#[derive(Debug)] +pub enum CheckerOrGenerateItem<'a> { + CheckerOrGenerateItemDeclaration(CheckerOrGenerateItemDeclaration<'a>), + InitialConstruct(InitialConstruct<'a>), + AlwaysConstruct(AlwaysConstruct<'a>), + FinalConstruct(FinalConstruct<'a>), + AssertionItem(AssertionItem<'a>), + ContinuousAssign(ContinuousAssign<'a>), + CheckerGenerateItem(CheckerGenerateItem<'a>), +} + +#[derive(Debug)] +pub enum CheckerOrGenerateItemDeclaration<'a> { + Data(CheckerOrGenerateItemDeclarationData<'a>), + FunctionDeclaration(FunctionDeclaration<'a>), + CheckerDeclaration(CheckerDeclaration<'a>), + AssertionItemDeclaration(AssertionItemDeclaration<'a>), + CovergroupDeclaration(CovergroupDeclaration<'a>), + GenvarDeclaration(GenvarDeclaration<'a>), + ClockingDeclaration(ClockingDeclaration<'a>), + Clocking(CheckerOrGenerateItemDeclarationClocking<'a>), + Expression(CheckerOrGenerateItemDeclarationExpression<'a>), + Empty, +} + +#[derive(Debug)] +pub struct CheckerOrGenerateItemDeclarationData<'a> { + pub nodes: (Option, DataDeclaration<'a>), +} + +#[derive(Debug)] +pub struct Rand {} + +#[derive(Debug)] +pub struct CheckerOrGenerateItemDeclarationClocking<'a> { + pub nodes: (ClockingIdentifier<'a>,), +} + +#[derive(Debug)] +pub struct CheckerOrGenerateItemDeclarationExpression<'a> { + pub nodes: (ExpressionOrDist<'a>,), +} + +#[derive(Debug)] +pub enum CheckerGenerateItem<'a> { + LoopGenerateConstruct(Box>), + ConditionalGenerateConstruct(Box>), + GenerateRegion(GenerateRegion<'a>), + ElaborationSystemTask(ElaborationSystemTask<'a>), +} + +// ----------------------------------------------------------------------------- + +pub fn checker_port_list(s: &str) -> IResult<&str, CheckerPortList> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn checker_port_item(s: &str) -> IResult<&str, CheckerPortItem> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn checker_port_direction(s: &str) -> IResult<&str, CheckerPortDirection> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn checker_or_generate_item(s: &str) -> IResult<&str, CheckerOrGenerateItem> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn checker_or_generate_item_declaration( + s: &str, +) -> IResult<&str, CheckerOrGenerateItemDeclaration> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn checker_generate_item(s: &str) -> IResult<&str, CheckerGenerateItem> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} diff --git a/src/parser/source_text/class_items.rs b/src/parser/source_text/class_items.rs new file mode 100644 index 0000000..9ce06f3 --- /dev/null +++ b/src/parser/source_text/class_items.rs @@ -0,0 +1,205 @@ +use crate::parser::*; +//use nom::branch::*; +//use nom::combinator::*; +use nom::error::*; +use nom::{Err, IResult}; + +// ----------------------------------------------------------------------------- + +#[derive(Debug)] +pub enum ClassItem<'a> { + Property(ClassItemProperty<'a>), + Method(ClassItemMethod<'a>), + Constraint(ClassItemConstraint<'a>), + Declaration(ClassItemDeclaration<'a>), + Covergroup(ClassItemCovergroup<'a>), + LocalParameterDeclaration(LocalParameterDeclaration<'a>), + ParameterDeclaration(ParameterDeclaration<'a>), + Empty, +} + +#[derive(Debug)] +pub struct ClassItemProperty<'a> { + pub nodes: (Vec>, ClassProperty<'a>), +} + +#[derive(Debug)] +pub struct ClassItemMethod<'a> { + pub nodes: (Vec>, ClassMethod<'a>), +} + +#[derive(Debug)] +pub struct ClassItemConstraint<'a> { + pub nodes: (Vec>, ClassConstraint<'a>), +} + +#[derive(Debug)] +pub struct ClassItemDeclaration<'a> { + pub nodes: (Vec>, ClassDeclaration<'a>), +} + +#[derive(Debug)] +pub struct ClassItemCovergroup<'a> { + pub nodes: (Vec>, CovergroupDeclaration<'a>), +} + +#[derive(Debug)] +pub enum ClassProperty<'a> { + NonConst(ClassPropertyNonConst<'a>), + Const(ClassPropertyConst<'a>), +} + +#[derive(Debug)] +pub struct ClassPropertyNonConst<'a> { + pub nodes: (Vec, DataDeclaration<'a>), +} + +#[derive(Debug)] +pub struct ClassPropertyConst<'a> { + pub nodes: ( + Vec, + DataType<'a>, + ConstIdentifier<'a>, + Option>, + ), +} + +#[derive(Debug)] +pub enum ClassMethod<'a> { + Task(ClassMethodTask<'a>), + Function(ClassMethodFunction<'a>), + PureVirtual(ClassMethodPureVirtual<'a>), + ExternMethod(ClassMethodExternMethod<'a>), + Constructor(ClassMethodConstructor<'a>), + ExternConstructor(ClassMethodExternConstructor<'a>), +} + +#[derive(Debug)] +pub struct ClassMethodTask<'a> { + pub nodes: (Vec, TaskDeclaration<'a>), +} + +#[derive(Debug)] +pub struct ClassMethodFunction<'a> { + pub nodes: (Vec, FunctionDeclaration<'a>), +} + +#[derive(Debug)] +pub struct ClassMethodPureVirtual<'a> { + pub nodes: (Vec, MethodPrototype<'a>), +} + +#[derive(Debug)] +pub struct ClassMethodExternMethod<'a> { + pub nodes: (Vec, MethodPrototype<'a>), +} + +#[derive(Debug)] +pub struct ClassMethodConstructor<'a> { + pub nodes: (Vec, ClassConstructorPrototype<'a>), +} + +#[derive(Debug)] +pub struct ClassMethodExternConstructor<'a> { + pub nodes: (Vec, ClassConstructorPrototype<'a>), +} + +#[derive(Debug)] +pub struct ClassConstructorPrototype<'a> { + pub nodes: (Option>,), +} + +#[derive(Debug)] +pub enum ClassConstraint<'a> { + ConstraintPrototype(ConstraintPrototype<'a>), + ConstraintDeclaration(ConstraintDeclaration<'a>), +} + +#[derive(Debug)] +pub enum ClassItemQualifier { + Static, + Protected, + Local, +} + +#[derive(Debug)] +pub enum PropertyQualifier { + RandomQualifier(RandomQualifier), + ClassItemQualifier(ClassItemQualifier), +} + +#[derive(Debug)] +pub enum RandomQualifier { + Rand, + Randc, +} + +#[derive(Debug)] +pub enum MethodQualifier { + Virtual, + PureVirtual, + ClassItemQualifier(ClassItemQualifier), +} + +#[derive(Debug)] +pub enum MethodPrototype<'a> { + TaskPrototype(TaskPrototype<'a>), + FunctionPrototype(FunctionPrototype<'a>), +} + +#[derive(Debug)] +pub struct ClassConstructorDeclaration<'a> { + pub nodes: ( + Option>, + Option>>, + Vec>, + Option>>, + Vec>, + Option, + ), +} + +#[derive(Debug)] +pub struct New {} + +// ----------------------------------------------------------------------------- + +pub fn class_item(s: &str) -> IResult<&str, ClassItem> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn class_property(s: &str) -> IResult<&str, ClassProperty> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn class_method(s: &str) -> IResult<&str, ClassMethod> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn class_constructor_prototype(s: &str) -> IResult<&str, ClassConstructorPrototype> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn class_constraint(s: &str) -> IResult<&str, ClassConstraint> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn class_item_qualifier(s: &str) -> IResult<&str, ClassItemQualifier> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn property_qualifier(s: &str) -> IResult<&str, PropertyQualifier> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn random_qualifier(s: &str) -> IResult<&str, RandomQualifier> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn method_qualifier(s: &str) -> IResult<&str, MethodQualifier> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn class_constructor_declaration(s: &str) -> IResult<&str, ClassConstructorDeclaration> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} diff --git a/src/parser/source_text/configuration_source_text.rs b/src/parser/source_text/configuration_source_text.rs new file mode 100644 index 0000000..31e8297 --- /dev/null +++ b/src/parser/source_text/configuration_source_text.rs @@ -0,0 +1,152 @@ +use crate::parser::*; +//use nom::branch::*; +//use nom::combinator::*; +use nom::error::*; +use nom::{Err, IResult}; + +// ----------------------------------------------------------------------------- + +#[derive(Debug)] +pub struct ConfigDeclaration<'a> { + pub nodes: ( + ConfigIdentifier<'a>, + Vec>, + DesignStatement<'a>, + Vec>, + Option>, + ), +} + +#[derive(Debug)] +pub struct DesignStatement<'a> { + pub nodes: (Vec<(Option>, CellIdentifier<'a>)>,), +} + +#[derive(Debug)] +pub enum ConfigRuleStatement<'a> { + Default(ConfigRuleStatementDefault<'a>), + InstLib(ConfigRuleStatementInstLib<'a>), + InstUse(ConfigRuleStatementInstUse<'a>), + CellLib(ConfigRuleStatementCellLib<'a>), + CellUse(ConfigRuleStatementCellUse<'a>), +} + +#[derive(Debug)] +pub struct ConfigRuleStatementDefault<'a> { + pub nodes: (DefaultClause, LiblistClause<'a>), +} + +#[derive(Debug)] +pub struct ConfigRuleStatementInstLib<'a> { + pub nodes: (InstClause<'a>, LiblistClause<'a>), +} + +#[derive(Debug)] +pub struct ConfigRuleStatementInstUse<'a> { + pub nodes: (InstClause<'a>, UseClause<'a>), +} + +#[derive(Debug)] +pub struct ConfigRuleStatementCellLib<'a> { + pub nodes: (CellClause<'a>, LiblistClause<'a>), +} + +#[derive(Debug)] +pub struct ConfigRuleStatementCellUse<'a> { + pub nodes: (CellClause<'a>, UseClause<'a>), +} + +#[derive(Debug)] +pub struct DefaultClause {} + +#[derive(Debug)] +pub struct InstClause<'a> { + pub nodes: (InstName<'a>,), +} + +#[derive(Debug)] +pub struct InstName<'a> { + pub nodes: (TopmoduleIdentifier<'a>, Vec>), +} + +#[derive(Debug)] +pub struct CellClause<'a> { + pub nodes: (Option>, CellIdentifier<'a>), +} + +#[derive(Debug)] +pub struct LiblistClause<'a> { + pub nodes: (Vec>,), +} + +#[derive(Debug)] +pub enum UseClause<'a> { + Cell(UseClauseCell<'a>), + Named(UseClauseNamed<'a>), + CellNamed(UseClauseCellNamed<'a>), +} + +#[derive(Debug)] +pub struct UseClauseCell<'a> { + pub nodes: ( + Option>, + CellIdentifier<'a>, + Option, + ), +} + +#[derive(Debug)] +pub struct UseClauseNamed<'a> { + pub nodes: (Vec>, Option), +} + +#[derive(Debug)] +pub struct UseClauseCellNamed<'a> { + pub nodes: ( + Option>, + CellIdentifier<'a>, + Vec>, + Option, + ), +} + +#[derive(Debug)] +pub struct Config {} + +// ----------------------------------------------------------------------------- + +pub fn config_declaration(s: &str) -> IResult<&str, ConfigDeclaration> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn design_statement(s: &str) -> IResult<&str, DesignStatement> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn config_rule_statement(s: &str) -> IResult<&str, ConfigRuleStatement> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn default_clause(s: &str) -> IResult<&str, DefaultClause> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn inst_clause(s: &str) -> IResult<&str, InstClause> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn inst_name(s: &str) -> IResult<&str, InstName> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn cell_clause(s: &str) -> IResult<&str, CellClause> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn liblist_clause(s: &str) -> IResult<&str, LiblistClause> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn use_clause(s: &str) -> IResult<&str, UseClause> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} diff --git a/src/parser/source_text/constraints.rs b/src/parser/source_text/constraints.rs new file mode 100644 index 0000000..c57489c --- /dev/null +++ b/src/parser/source_text/constraints.rs @@ -0,0 +1,225 @@ +use crate::parser::*; +//use nom::branch::*; +//use nom::combinator::*; +use nom::error::*; +use nom::{Err, IResult}; + +// ----------------------------------------------------------------------------- + +#[derive(Debug)] +pub struct ConstraintDeclaration<'a> { + pub nodes: ( + Option, + ConstraintIdentifier<'a>, + ConstraintBlock<'a>, + ), +} + +#[derive(Debug)] +pub struct Static {} + +#[derive(Debug)] +pub struct ConstraintsBlock<'a> { + pub nodes: (Vec>,), +} + +#[derive(Debug)] +pub enum ConstraintBlockItem<'a> { + Solve(ConstraintBlockItemSolve<'a>), + ConstraintExpression(ConstraintExpression<'a>), +} + +#[derive(Debug)] +pub struct ConstraintBlockItemSolve<'a> { + pub nodes: (SolveBeforeList<'a>, SolveBeforeList<'a>), +} + +#[derive(Debug)] +pub struct SolveBeforeList<'a> { + pub nodes: (Vec>,), +} + +#[derive(Debug)] +pub struct ConstraintPrimary<'a> { + pub nodes: ( + Option>, + HierarchicalIdentifier<'a>, + Select<'a>, + ), +} + +#[derive(Debug)] +pub enum ConstraintExpression<'a> { + Expression(ConstraintExpressionExpression<'a>), + UniquenessConstraint(UniquenessConstraint<'a>), + Arrow(ConstraintExpressionArrow<'a>), + If(ConstraintExpressionIf<'a>), + Foreach(ConstraintExpressionForeach<'a>), + Disable(ConstraintExpressionDisable<'a>), +} + +#[derive(Debug)] +pub struct ConstraintExpressionExpression<'a> { + pub nodes: (Option, ExpressionOrDist<'a>), +} + +#[derive(Debug)] +pub struct Soft {} + +#[derive(Debug)] +pub struct ConstraintExpressionArrow<'a> { + pub nodes: (Expression<'a>, ConstraintSet<'a>), +} + +#[derive(Debug)] +pub struct ConstraintExpressionIf<'a> { + pub nodes: (Expression<'a>, ConstraintSet<'a>, Option>), +} + +#[derive(Debug)] +pub struct ConstraintExpressionForeach<'a> { + pub nodes: ( + PsOrHierarchicalArrayIdentifier<'a>, + LoopVariables<'a>, + ConstraintSet<'a>, + ), +} + +#[derive(Debug)] +pub struct ConstraintExpressionDisable<'a> { + pub nodes: (ConstraintPrimary<'a>,), +} + +#[derive(Debug)] +pub struct UniquenessConstraint<'a> { + pub nodes: (OpenRangeList<'a>,), +} + +#[derive(Debug)] +pub enum ConstraintSet<'a> { + ConstraintExpression(Box>), + Bracket(ConstraintSetBracket<'a>), +} + +#[derive(Debug)] +pub struct ConstraintSetBracket<'a> { + pub nodes: (Vec>,), +} + +#[derive(Debug)] +pub struct DistList<'a> { + pub nodes: (Vec>,), +} + +#[derive(Debug)] +pub struct DistItem<'a> { + pub nodes: (ValueRange<'a>, Option>), +} + +#[derive(Debug)] +pub enum DistWeight<'a> { + Equal(DistWeightEqual<'a>), + Divide(DistWeightDivide<'a>), +} + +#[derive(Debug)] +pub struct DistWeightEqual<'a> { + pub nodes: (Expression<'a>,), +} + +#[derive(Debug)] +pub struct DistWeightDivide<'a> { + pub nodes: (Expression<'a>,), +} + +#[derive(Debug)] +pub struct ConstraintPrototype<'a> { + pub nodes: ( + Option, + Option, + ConstraintIdentifier<'a>, + ), +} + +#[derive(Debug)] +pub enum ConstraintPrototypeQualifier { + Extern, + Pure, +} + +#[derive(Debug)] +pub struct ExternConstraintDeclaration<'a> { + pub nodes: ( + Option, + ClassScope<'a>, + ConstraintIdentifier<'a>, + ConstraintBlock<'a>, + ), +} + +#[derive(Debug)] +pub struct IdentifierList<'a> { + pub nodes: (Vec>,), +} + +// ----------------------------------------------------------------------------- + +pub fn constraint_declaration(s: &str) -> IResult<&str, ConstraintDeclaration> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn constraint_block(s: &str) -> IResult<&str, ConstraintBlock> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn constraint_block_item(s: &str) -> IResult<&str, ConstraintBlockItem> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn solve_before_list(s: &str) -> IResult<&str, SolveBeforeList> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn constraint_primary(s: &str) -> IResult<&str, ConstraintPrimary> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn constraint_expression(s: &str) -> IResult<&str, ConstraintExpression> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn uniqueness_constraint(s: &str) -> IResult<&str, UniquenessConstraint> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn constraint_set(s: &str) -> IResult<&str, ConstraintSet> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn dist_list(s: &str) -> IResult<&str, DistList> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn dist_item(s: &str) -> IResult<&str, DistItem> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn dist_weight(s: &str) -> IResult<&str, DistWeight> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn constraint_prototype(s: &str) -> IResult<&str, ConstraintPrototype> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn constraint_prototype_qualifier(s: &str) -> IResult<&str, ConstraintPrototypeQualifier> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn extern_constraint_declaration(s: &str) -> IResult<&str, ExternConstraintDeclaration> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn identifier_list(s: &str) -> IResult<&str, IdentifierList> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} diff --git a/src/parser/source_text/interface_items.rs b/src/parser/source_text/interface_items.rs new file mode 100644 index 0000000..88046c3 --- /dev/null +++ b/src/parser/source_text/interface_items.rs @@ -0,0 +1,73 @@ +use crate::parser::*; +//use nom::branch::*; +//use nom::combinator::*; +use nom::error::*; +use nom::{Err, IResult}; + +// ----------------------------------------------------------------------------- + +#[derive(Debug)] +pub enum InterfaceOrGenerateItem<'a> { + Module(InterfaceOrGenerateItemModule<'a>), + Extern(InterfaceOrGenerateItemExtern<'a>), +} + +#[derive(Debug)] +pub struct InterfaceOrGenerateItemModule<'a> { + pub nodes: (Vec>, ModuleCommonItem<'a>), +} + +#[derive(Debug)] +pub struct InterfaceOrGenerateItemExtern<'a> { + pub nodes: (Vec>, ExternTfDeclaration<'a>), +} + +#[derive(Debug)] +pub enum ExternTfDeclaration<'a> { + Method(ExternTfDeclarationMethod<'a>), + Task(ExternTfDeclarationTask<'a>), +} + +#[derive(Debug)] +pub struct ExternTfDeclarationMethod<'a> { + pub nodes: (MethodPrototype<'a>), +} + +#[derive(Debug)] +pub struct ExternTfDeclarationTask<'a> { + pub nodes: (TaskPrototype<'a>), +} + +#[derive(Debug)] +pub enum InterfaceItem<'a> { + PortDeclaration(PortDeclaration<'a>), + NonPortInterfaceItem(NonPortInterfaceItem<'a>), +} + +#[derive(Debug)] +pub enum NonPortInterfaceItem<'a> { + GenerateRegion(GenerateRegion<'a>), + InterfaceOrGenerateItem(InterfaceOrGenerateItem<'a>), + ProgramDeclaration(ProgramDeclaration<'a>), + ModportDeclaration(ModportDeclaration<'a>), + InterfaceDeclaration(InterfaceDeclaration<'a>), + TimeunitsDeclaration(TimeunitsDeclaration<'a>), +} + +// ----------------------------------------------------------------------------- + +pub fn interface_or_generate_item(s: &str) -> IResult<&str, InterfaceOrGenerateItem> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn extern_tf_declaration(s: &str) -> IResult<&str, ExternTfDeclaration> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn interface_item(s: &str) -> IResult<&str, InterfaceItem> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn non_port_interface_item(s: &str) -> IResult<&str, NonPortInterfaceItem> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} diff --git a/src/parser/source_text/library_source_text.rs b/src/parser/source_text/library_source_text.rs new file mode 100644 index 0000000..578cdf9 --- /dev/null +++ b/src/parser/source_text/library_source_text.rs @@ -0,0 +1,56 @@ +use crate::parser::*; +//use nom::branch::*; +//use nom::combinator::*; +use nom::error::*; +use nom::{Err, IResult}; + +// ----------------------------------------------------------------------------- + +#[derive(Debug)] +pub struct LibraryText<'a> { + pub nodes: (Vec>,), +} + +#[derive(Debug)] +pub enum LibraryDescription<'a> { + LibraryDeclaration(LibraryDeclaration<'a>), + IncludeStatement(IncludeStatement<'a>), + ConfigDeclaration(ConfigDeclaration<'a>), +} + +#[derive(Debug)] +pub struct LibraryDeclaration<'a> { + pub nodes: ( + LibraryIdentifier<'a>, + Vec>, + Option>>, + ), +} + +#[derive(Debug)] +pub struct IncludeStatement<'a> { + pub nodes: (FilePathSpec<'a>,), +} + +#[derive(Debug)] +pub struct FilePathSpec<'a> { + pub nodes: (&'a str,), +} + +// ----------------------------------------------------------------------------- + +pub fn library_text(s: &str) -> IResult<&str, LibraryText> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn library_description(s: &str) -> IResult<&str, LibraryDescription> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn library_declaration(s: &str) -> IResult<&str, LibraryDeclaration> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn include_statement(s: &str) -> IResult<&str, IncludeStatement> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} diff --git a/src/parser/source_text/mod.rs b/src/parser/source_text/mod.rs new file mode 100644 index 0000000..e2e0592 --- /dev/null +++ b/src/parser/source_text/mod.rs @@ -0,0 +1,20 @@ +pub mod checker_items; +pub mod class_items; +pub mod configuration_source_text; +pub mod constraints; +pub mod interface_items; +pub mod library_source_text; +pub mod module_items; +pub mod module_parameters_and_ports; +pub mod program_items; +pub mod system_verilog_source_text; +pub use checker_items::*; +pub use class_items::*; +pub use configuration_source_text::*; +pub use constraints::*; +pub use interface_items::*; +pub use library_source_text::*; +pub use module_items::*; +pub use module_parameters_and_ports::*; +pub use program_items::*; +pub use system_verilog_source_text::*; diff --git a/src/parser/source_text/module_items.rs b/src/parser/source_text/module_items.rs new file mode 100644 index 0000000..0968030 --- /dev/null +++ b/src/parser/source_text/module_items.rs @@ -0,0 +1,240 @@ +use crate::parser::*; +//use nom::branch::*; +//use nom::combinator::*; +use nom::error::*; +use nom::{Err, IResult}; + +// ----------------------------------------------------------------------------- + +#[derive(Debug)] +pub enum ElaborationSystemTask<'a> { + Fatal(ElaborationSystemTaskFatal<'a>), + Error(ElaborationSystemTaskError<'a>), + Warning(ElaborationSystemTaskWarning<'a>), + Info(ElaborationSystemTaskInfo<'a>), +} + +#[derive(Debug)] +pub struct ElaborationSystemTaskFatal<'a> { + pub nodes: (Option<(FinishNumber, Option>)>,), +} + +#[derive(Debug)] +pub struct ElaborationSystemTaskError<'a> { + pub nodes: (Option>>,), +} + +#[derive(Debug)] +pub struct ElaborationSystemTaskWarning<'a> { + pub nodes: (Option>>,), +} + +#[derive(Debug)] +pub struct ElaborationSystemTaskInfo<'a> { + pub nodes: (Option>>,), +} + +#[derive(Debug)] +pub enum FinishNumber { + Zero, + One, + Two, +} + +#[derive(Debug)] +pub enum ModuleCommonItem<'a> { + ModuleOrGenerateItemDeclaration(ModuleOrGenerateItemDeclaration<'a>), + InterfaceInstantiation(InterfaceInstantiation<'a>), + ProgramInstantiation(ProgramInstantiation<'a>), + AssertionItem(AssertionItem<'a>), + BindDirective(BindDirective<'a>), + ContinuousAssign(ContinuousAssign<'a>), + NetAlias(NetAlias<'a>), + InitialConstruct(InitialConstruct<'a>), + FinalConstruct(FinalConstruct<'a>), + AlwaysConstruct(AlwaysConstruct<'a>), + LoopGenerateConstruct(Box>), + ConditionalGenerateConstruct(Box>), + ElaborationSystemTask(ElaborationSystemTask<'a>), +} + +#[derive(Debug)] +pub enum ModuleItem<'a> { + PortDeclaratoin(PortDeclaration<'a>), + NonPortModuleItem(NonPortModuleItem<'a>), +} + +#[derive(Debug)] +pub enum ModuleOrGenerateItem<'a> { + Parameter(ModuleOrGenerateItemParameter<'a>), + Gate(ModuleOrGenerateItemGate<'a>), + Udp(ModuleOrGenerateItemUdp<'a>), + Module(ModuleOrGenerateItemModule<'a>), + ModuleItem(Box>), +} + +#[derive(Debug)] +pub struct ModuleOrGenerateItemParameter<'a> { + pub nodes: (Vec>, ParameterOverride<'a>), +} + +#[derive(Debug)] +pub struct ModuleOrGenerateItemGate<'a> { + pub nodes: (Vec>, GateInstantiation<'a>), +} + +#[derive(Debug)] +pub struct ModuleOrGenerateItemUdp<'a> { + pub nodes: (Vec>, UdpInstantiation<'a>), +} + +#[derive(Debug)] +pub struct ModuleOrGenerateItemModule<'a> { + pub nodes: (Vec>, ModuleInstantiation<'a>), +} + +#[derive(Debug)] +pub struct ModuleOrGenerateItemModuleItem<'a> { + pub nodes: (Vec>, ModuleCommonItem<'a>), +} + +#[derive(Debug)] +pub enum ModuleOrGenerateItemDeclaration<'a> { + PackageOrGenerateItemDeclaration(PackageOrGenerateItemDeclaration<'a>), + GenvarDeclaration(GenvarDeclaration<'a>), + ClockingDeclaration(ClockingDeclaration<'a>), + Clocking(ModuleOrGenerateItemDeclarationClocking<'a>), + Expression(ModuleOrGenerateItemDeclarationExpression<'a>), +} + +#[derive(Debug)] +pub struct ModuleOrGenerateItemDeclarationClocking<'a> { + pub nodes: (ClockingIdentifier<'a>), +} + +#[derive(Debug)] +pub struct ModuleOrGenerateItemDeclarationExpression<'a> { + pub nodes: (ExpressionOrDist<'a>), +} + +#[derive(Debug)] +pub enum NonPortModuleItem<'a> { + GenerateRegion(GenerateRegion<'a>), + ModuleOrGenerateItem(ModuleOrGenerateItem<'a>), + SpecifyBlock(SpecifyBlock<'a>), + Specparam(NonPortModuleItemSpecparam<'a>), + ProgramDeclaration(ProgramDeclaration<'a>), + ModuleDeclaration(ModuleDeclaration<'a>), + InterfaceDeclaration(InterfaceDeclaration<'a>), + TimeunitsDeclaration(TimeunitsDeclaration<'a>), +} + +#[derive(Debug)] +pub struct NonPortModuleItemSpecparam<'a> { + pub nodes: (Vec>, SpecparamDeclaration<'a>), +} + +#[derive(Debug)] +pub struct ParameterOverride<'a> { + pub nodes: (ListOfDefparamAssignments<'a>,), +} + +#[derive(Debug)] +pub enum BindDirective<'a> { + Scope(BindDirectiveScope<'a>), + Instance(BindDirectiveInstance<'a>), +} + +#[derive(Debug)] +pub struct BindDirectiveScope<'a> { + pub nodes: ( + BindTargetScope<'a>, + Option>, + BindInstantiation<'a>, + ), +} + +#[derive(Debug)] +pub struct BindDirectiveInstance<'a> { + pub nodes: (BindTargetInstanceList<'a>, BindInstantiation<'a>), +} + +#[derive(Debug)] +pub enum BindTargetScope<'a> { + ModuleIdentifier(ModuleIdentifier<'a>), + InterfaceIdentifier(InterfaceIdentifier<'a>), +} + +#[derive(Debug)] +pub struct BindTargetInstance<'a> { + pub nodes: (HierarchicalIdentifier<'a>, ConstantBitSelect<'a>), +} + +#[derive(Debug)] +pub struct BindTargetInstanceList<'a> { + pub nodes: (Vec>,), +} + +#[derive(Debug)] +pub enum BindInstantiation<'a> { + ProgramInstantiation(ProgramInstantiation<'a>), + ModuleInstantiation(ModuleInstantiation<'a>), + InterfaceInstantiation(InterfaceInstantiation<'a>), + CheckerInstantiation(CheckerInstantiation<'a>), +} + +// ----------------------------------------------------------------------------- + +pub fn elaboration_system_task(s: &str) -> IResult<&str, ElaborationSystemTask> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn finish_number(s: &str) -> IResult<&str, FinishNumber> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn module_common_item(s: &str) -> IResult<&str, ModuleCommonItem> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn module_item(s: &str) -> IResult<&str, ModuleItem> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn module_or_generate_item(s: &str) -> IResult<&str, ModuleOrGenerateItem> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn module_or_generate_item_declaration( + s: &str, +) -> IResult<&str, ModuleOrGenerateItemDeclaration> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn non_port_module_item(s: &str) -> IResult<&str, NonPortModuleItem> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn parameter_override(s: &str) -> IResult<&str, ParameterOverride> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn bind_directive(s: &str) -> IResult<&str, BindDirective> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn bind_target_scope(s: &str) -> IResult<&str, BindTargetScope> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn bind_target_instance(s: &str) -> IResult<&str, BindTargetInstance> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn bind_target_instance_list(s: &str) -> IResult<&str, BindTargetInstanceList> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn bind_instantiation(s: &str) -> IResult<&str, BindInstantiation> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} diff --git a/src/parser/source_text/module_parameters_and_ports.rs b/src/parser/source_text/module_parameters_and_ports.rs new file mode 100644 index 0000000..8467f2a --- /dev/null +++ b/src/parser/source_text/module_parameters_and_ports.rs @@ -0,0 +1,250 @@ +use crate::parser::*; +//use nom::branch::*; +//use nom::combinator::*; +use nom::error::*; +use nom::{Err, IResult}; + +// ----------------------------------------------------------------------------- + +#[derive(Debug)] +pub enum ParameterPortList<'a> { + Assignment(ParameterPortListAssignment<'a>), + Declaration(ParameterPortListDeclaration<'a>), + Empty, +} + +#[derive(Debug)] +pub struct ParameterPortListAssignment<'a> { + pub nodes: ( + ListOfParamAssignments<'a>, + Vec>, + ), +} + +#[derive(Debug)] +pub struct ParameterPortListDeclaration<'a> { + pub nodes: (Vec>,), +} + +#[derive(Debug)] +pub enum ParameterPortDeclaration<'a> { + ParameterDeclaration(ParameterDeclaration<'a>), + LocalParameterDeclaration(LocalParameterDeclaration<'a>), + ParamList(ParameterPortDeclarationParamList<'a>), + TypeList(ParameterPortDeclarationTypeList<'a>), +} + +#[derive(Debug)] +pub struct ParameterPortDeclarationParamList<'a> { + pub nodes: (DataType<'a>, ListOfParamAssignments<'a>), +} + +#[derive(Debug)] +pub struct ParameterPortDeclarationTypeList<'a> { + pub nodes: (ListOfTypeAssignments<'a>,), +} + +#[derive(Debug)] +pub struct ListOfPorts<'a> { + pub nodes: (Vec>,), +} + +#[derive(Debug)] +pub struct ListOfPortDeclarations<'a> { + pub nodes: (Option>, AnsiPortDeclaration<'a>)>>,), +} + +#[derive(Debug)] +pub enum PortDeclaration<'a> { + Inout(PortDeclarationInout<'a>), + Input(PortDeclarationInput<'a>), + Output(PortDeclarationOutput<'a>), + Ref(PortDeclarationRef<'a>), + Interface(PortDeclarationInterface<'a>), +} + +#[derive(Debug)] +pub struct PortDeclarationInout<'a> { + pub nodes: (Vec>, InoutDeclaration<'a>), +} + +#[derive(Debug)] +pub struct PortDeclarationInput<'a> { + pub nodes: (Vec>, InputDeclaration<'a>), +} + +#[derive(Debug)] +pub struct PortDeclarationOutput<'a> { + pub nodes: (Vec>, OutputDeclaration<'a>), +} + +#[derive(Debug)] +pub struct PortDeclarationRef<'a> { + pub nodes: (Vec>, RefDeclaration<'a>), +} + +#[derive(Debug)] +pub struct PortDeclarationInterface<'a> { + pub nodes: (Vec>, InterfacePortDeclaration<'a>), +} + +#[derive(Debug)] +pub enum Port<'a> { + NonNamed(PortNonNamed<'a>), + Named(PortNamed<'a>), +} + +#[derive(Debug)] +pub struct PortNonNamed<'a> { + pub nodes: (Option>,), +} + +#[derive(Debug)] +pub struct PortNamed<'a> { + pub nodes: (PortIdentifier<'a>, Option>), +} + +#[derive(Debug)] +pub enum PortExpression<'a> { + PortReference(PortReference<'a>), + Bracket(PortExpressionBracket<'a>), +} + +#[derive(Debug)] +pub struct PortExpressionBracket<'a> { + pub nodes: (Vec>,), +} + +#[derive(Debug)] +pub struct PortReference<'a> { + pub nodes: (PortIdentifier<'a>, ConstantSelect<'a>), +} + +#[derive(Debug)] +pub enum PortDirection { + Input, + Output, + Inout, + Ref, +} + +#[derive(Debug)] +pub struct NetPortHeader<'a> { + pub nodes: (Option, NetPortType<'a>), +} + +#[derive(Debug)] +pub struct VariablePortHeader<'a> { + pub nodes: (Option, VariablePortType<'a>), +} + +#[derive(Debug)] +pub enum InterfacePortHeader<'a> { + Identifier(InterfacePortHeaderIdentifier<'a>), + Interface(InterfacePortHeaderInterface<'a>), +} + +#[derive(Debug)] +pub struct InterfacePortHeaderIdentifier<'a> { + pub nodes: (InterfaceIdentifier<'a>, Option>), +} + +#[derive(Debug)] +pub struct InterfacePortHeaderInterface<'a> { + pub nodes: (Option>,), +} + +#[derive(Debug)] +pub enum NetPortHeaderOrInterfacePortHeader<'a> { + NetPortHeader(NetPortHeader<'a>), + InterfacePortHeader(InterfacePortHeader<'a>), +} +#[derive(Debug)] +pub enum AnsiPortDeclaration<'a> { + Net(AnsiPortDeclarationNet<'a>), + Variable(AnsiPortDeclarationVariable<'a>), + Paren(AnsiPortDeclarationParen<'a>), +} + +#[derive(Debug)] +pub struct AnsiPortDeclarationNet<'a> { + pub nodes: ( + Option>, + PortIdentifier<'a>, + Vec>, + Option>, + ), +} + +#[derive(Debug)] +pub struct AnsiPortDeclarationVariable<'a> { + pub nodes: ( + Option>, + PortIdentifier<'a>, + Vec>, + Option>, + ), +} + +#[derive(Debug)] +pub struct AnsiPortDeclarationParen<'a> { + pub nodes: ( + Option, + PortIdentifier<'a>, + Option>, + ), +} + +// ----------------------------------------------------------------------------- + +pub fn parameter_port_list(s: &str) -> IResult<&str, ParameterPortList> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn parameter_port_declaration(s: &str) -> IResult<&str, ParameterPortDeclaration> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn list_of_ports(s: &str) -> IResult<&str, ListOfPorts> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn list_of_port_declarations(s: &str) -> IResult<&str, ListOfPortDeclarations> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn port_declaration(s: &str) -> IResult<&str, PortDeclaration> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn port(s: &str) -> IResult<&str, Port> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn port_expression(s: &str) -> IResult<&str, PortExpression> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn port_reference(s: &str) -> IResult<&str, PortReference> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn port_direction(s: &str) -> IResult<&str, PortDirection> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn net_port_header(s: &str) -> IResult<&str, NetPortHeader> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn variable_port_header(s: &str) -> IResult<&str, VariablePortHeader> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn interface_port_header(s: &str) -> IResult<&str, InterfacePortHeader> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn ansi_port_declaration(s: &str) -> IResult<&str, AnsiPortDeclaration> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} diff --git a/src/parser/source_text/program_items.rs b/src/parser/source_text/program_items.rs new file mode 100644 index 0000000..2ab366f --- /dev/null +++ b/src/parser/source_text/program_items.rs @@ -0,0 +1,74 @@ +use crate::parser::*; +//use nom::branch::*; +//use nom::combinator::*; +use nom::error::*; +use nom::{Err, IResult}; + +// ----------------------------------------------------------------------------- + +#[derive(Debug)] +pub enum ProgramItem<'a> { + PortDeclaration(PortDeclaration<'a>), + NonPortProgramItem(NonPortProgramItem<'a>), +} + +#[derive(Debug)] +pub enum NonPortProgramItem<'a> { + Assign(NonPortProgramItemAssign<'a>), + Module(NonPortProgramItemModule<'a>), + Initial(NonPortProgramItemInitial<'a>), + Final(NonPortProgramItemFinal<'a>), + Assertion(NonPortProgramItemAssertion<'a>), + TimeunitsDeclaration(TimeunitsDeclaration<'a>), + ProgramGenerateItem(ProgramGenerateItem<'a>), +} + +#[derive(Debug)] +pub struct NonPortProgramItemAssign<'a> { + pub nodes: (Vec>, ContinuousAssign<'a>), +} + +#[derive(Debug)] +pub struct NonPortProgramItemModule<'a> { + pub nodes: ( + Vec>, + ModuleOrGenerateItemDeclaration<'a>, + ), +} + +#[derive(Debug)] +pub struct NonPortProgramItemInitial<'a> { + pub nodes: (Vec>, InitialConstruct<'a>), +} + +#[derive(Debug)] +pub struct NonPortProgramItemFinal<'a> { + pub nodes: (Vec>, FinalConstruct<'a>), +} + +#[derive(Debug)] +pub struct NonPortProgramItemAssertion<'a> { + pub nodes: (Vec>, ConcurrentAssertionItem<'a>), +} + +#[derive(Debug)] +pub enum ProgramGenerateItem<'a> { + LoopGenerateConstuct(LoopGenerateConstruct<'a>), + ConditionalGenerateConstruct(ConditionalGenerateConstruct<'a>), + GenerateRegion(GenerateRegion<'a>), + ElaborationSystemTask(ElaborationSystemTask<'a>), +} + +// ----------------------------------------------------------------------------- + +pub fn program_item(s: &str) -> IResult<&str, ProgramItem> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn non_port_program_item(s: &str) -> IResult<&str, NonPortProgramItem> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn program_generate_item(s: &str) -> IResult<&str, ProgramGenerateItem> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} diff --git a/src/parser/source_text/system_verilog_source_text.rs b/src/parser/source_text/system_verilog_source_text.rs new file mode 100644 index 0000000..1b13f21 --- /dev/null +++ b/src/parser/source_text/system_verilog_source_text.rs @@ -0,0 +1,450 @@ +use crate::parser::*; +//use nom::branch::*; +//use nom::combinator::*; +use nom::error::*; +use nom::{Err, IResult}; + +// ----------------------------------------------------------------------------- + +#[derive(Debug)] +pub struct SourceText<'a> { + pub nodes: (Option>, Vec>), +} + +#[derive(Debug)] +pub enum Description<'a> { + ModuleDeclaration(ModuleDeclaration<'a>), + UdpDeclaration(UdpDeclaration<'a>), + InterfaceDeclaration(InterfaceDeclaration<'a>), + ProgramDeclaration(ProgramDeclaration<'a>), + PackageDeclaration(PackageDeclaration<'a>), + PackageItem(DescriptionPackageItem<'a>), + BindDirective(DescriptionBindDirective<'a>), + ConfigDeclaration(ConfigDeclaration<'a>), +} + +#[derive(Debug)] +pub struct DescriptionPackageItem<'a> { + pub nodes: (Vec>, PackageItem<'a>), +} + +#[derive(Debug)] +pub struct DescriptionBindDirective<'a> { + pub nodes: (Vec>, BindDirective<'a>), +} + +#[derive(Debug)] +pub struct ModuleNonansiHeader<'a> { + pub nodes: ( + Vec>, + ModuleKeyword, + Option, + ModuleIdentifier<'a>, + Vec>, + Option>, + ListOfPorts<'a>, + ), +} + +#[derive(Debug)] +pub struct ModuleAnsiHeader<'a> { + pub nodes: ( + Vec>, + ModuleKeyword, + Option, + ModuleIdentifier<'a>, + Vec>, + Option>, + Option>, + ), +} + +#[derive(Debug)] +pub enum ModuleDeclaration<'a> { + Nonansi(ModuleDeclarationNonansi<'a>), + Ansi(ModuleDeclarationAnsi<'a>), + Wildcard(ModuleDeclarationWildcard<'a>), + ExternNonansi(ModuleDeclarationExternNonansi<'a>), + ExternAnsi(ModuleDeclarationExternAnsi<'a>), +} + +#[derive(Debug)] +pub struct ModuleDeclarationNonansi<'a> { + pub nodes: ( + ModuleNonansiHeader<'a>, + Option>, + Vec>, + Option>, + ), +} + +#[derive(Debug)] +pub struct ModuleDeclarationAnsi<'a> { + pub nodes: ( + ModuleAnsiHeader<'a>, + Option>, + Vec>, + Option>, + ), +} + +#[derive(Debug)] +pub struct ModuleDeclarationWildcard<'a> { + pub nodes: ( + Vec>, + ModuleKeyword, + Option, + ModuleIdentifier<'a>, + Option>, + Vec>, + Option>, + ), +} + +#[derive(Debug)] +pub struct ModuleDeclarationExternNonansi<'a> { + pub nodes: (ModuleNonansiHeader<'a>,), +} + +#[derive(Debug)] +pub struct ModuleDeclarationExternAnsi<'a> { + pub nodes: (ModuleAnsiHeader<'a>,), +} + +#[derive(Debug)] +pub enum ModuleKeyword { + Module, + Macromodule, +} + +#[derive(Debug)] +pub enum InterfaceDeclaration<'a> { + Nonansi(InterfaceDeclarationNonansi<'a>), + Ansi(InterfaceDeclarationAnsi<'a>), + Wildcard(InterfaceDeclarationWildcard<'a>), + ExternNonansi(InterfaceDeclarationExternNonansi<'a>), + ExternAnsi(InterfaceDeclarationExternAnsi<'a>), +} + +#[derive(Debug)] +pub struct InterfaceDeclarationNonansi<'a> { + pub nodes: ( + InterfaceNonansiHeader<'a>, + Option>, + Vec>, + Option>, + ), +} + +#[derive(Debug)] +pub struct InterfaceDeclarationAnsi<'a> { + pub nodes: ( + InterfaceAnsiHeader<'a>, + Option>, + Vec>, + Option>, + ), +} + +#[derive(Debug)] +pub struct InterfaceDeclarationWildcard<'a> { + pub nodes: ( + Vec>, + InterfaceIdentifier<'a>, + Option>, + Vec>, + Option>, + ), +} + +#[derive(Debug)] +pub struct InterfaceDeclarationExternNonansi<'a> { + pub nodes: (InterfaceNonansiHeader<'a>,), +} + +#[derive(Debug)] +pub struct InterfaceDeclarationExternAnsi<'a> { + pub nodes: (InterfaceAnsiHeader<'a>,), +} + +#[derive(Debug)] +pub struct InterfaceNonansiHeader<'a> { + pub nodes: ( + Vec>, + Option, + InterfaceIdentifier<'a>, + Vec>, + Option>, + ListOfPorts<'a>, + ), +} + +#[derive(Debug)] +pub struct InterfaceAnsiHeader<'a> { + pub nodes: ( + Vec>, + Option, + InterfaceIdentifier<'a>, + Vec>, + Option>, + Option>, + ), +} + +#[derive(Debug)] +pub enum ProgramDeclaration<'a> { + Nonansi(ProgramDeclarationNonansi<'a>), + Ansi(ProgramDeclarationAnsi<'a>), + Wildcard(ProgramDeclarationWildcard<'a>), + ExternNonansi(ProgramDeclarationExternNonansi<'a>), + ExternAnsi(ProgramDeclarationExternAnsi<'a>), +} + +#[derive(Debug)] +pub struct ProgramDeclarationNonansi<'a> { + pub nodes: ( + ProgramNonansiHeader<'a>, + Option>, + Vec>, + Option>, + ), +} + +#[derive(Debug)] +pub struct ProgramDeclarationAnsi<'a> { + pub nodes: ( + ProgramAnsiHeader<'a>, + Option>, + Vec>, + Option>, + ), +} + +#[derive(Debug)] +pub struct ProgramDeclarationWildcard<'a> { + pub nodes: ( + Vec>, + ProgramIdentifier<'a>, + Option>, + Vec>, + Option>, + ), +} + +#[derive(Debug)] +pub struct ProgramDeclarationExternNonansi<'a> { + pub nodes: (ProgramNonansiHeader<'a>,), +} + +#[derive(Debug)] +pub struct ProgramDeclarationExternAnsi<'a> { + pub nodes: (ProgramAnsiHeader<'a>,), +} + +#[derive(Debug)] +pub struct ProgramNonansiHeader<'a> { + pub nodes: ( + Vec>, + Option, + ProgramIdentifier<'a>, + Vec>, + Option>, + ListOfPorts<'a>, + ), +} + +#[derive(Debug)] +pub struct ProgramAnsiHeader<'a> { + pub nodes: ( + Vec>, + Option, + ProgramIdentifier<'a>, + Vec>, + Option>, + Option>, + ), +} + +#[derive(Debug)] +pub struct CheckerDeclaration<'a> { + pub nodes: ( + CheckerIdentifier<'a>, + Option>, + Vec<(Vec>, CheckerOrGenerateItem<'a>)>, + Option>, + ), +} + +#[derive(Debug)] +pub struct ClassDeclaration<'a> { + pub nodes: ( + Option, + Option, + ClassIdentifier<'a>, + Option>, + Option<(ClassType<'a>, Option>)>, + Option>>, + Vec>, + Option>, + ), +} + +#[derive(Debug)] +pub struct Virtual {} + +#[derive(Debug)] +pub struct InterfaceClassType<'a> { + pub nodes: (PsClassIdentifier<'a>, Option>), +} + +#[derive(Debug)] +pub struct InterfaceClassDeclaration<'a> { + pub nodes: ( + ClassIdentifier<'a>, + Option>, + Option>>, + Vec>, + Option>, + ), +} + +#[derive(Debug)] +pub enum InterfaceClassItem<'a> { + TypeDeclaration(TypeDeclaration<'a>), + Method(InterfaceClassItemMethod<'a>), + LocalParameterDeclaration(LocalParameterDeclaration<'a>), + ParameterDeclaration(ParameterDeclaration<'a>), + Empty, +} + +#[derive(Debug)] +pub struct InterfaceClassItemMethod<'a> { + pub nodes: (Vec>, InterfaceClassMethod<'a>), +} + +#[derive(Debug)] +pub struct InterfaceClassMethod<'a> { + pub nodes: (MethodPrototype<'a>,), +} + +#[derive(Debug)] +pub struct PackageDeclaration<'a> { + pub nodes: ( + Vec>, + Option, + PackageIdentifier<'a>, + Option>, + Vec<(Vec>, PackageItem<'a>)>, + Option>, + ), +} + +#[derive(Debug)] +pub enum TimeunitsDeclaration<'a> { + Timeunit(TimeunitsDeclarationTimeunit<'a>), + Timeprecision(TimeunitsDeclarationTimeprecision<'a>), + TimeunitTimeprecision(TimeunitsDeclarationTimeunitTimeprecision<'a>), + TimeprecisionTimeunit(TimeunitsDeclarationTimeprecisionTimeunit<'a>), +} + +#[derive(Debug)] +pub struct TimeunitsDeclarationTimeunit<'a> { + pub nodes: (TimeLiteral<'a>, Option>), +} + +#[derive(Debug)] +pub struct TimeunitsDeclarationTimeprecision<'a> { + pub nodes: (TimeLiteral<'a>,), +} + +#[derive(Debug)] +pub struct TimeunitsDeclarationTimeunitTimeprecision<'a> { + pub nodes: (TimeLiteral<'a>, TimeLiteral<'a>), +} + +#[derive(Debug)] +pub struct TimeunitsDeclarationTimeprecisionTimeunit<'a> { + pub nodes: (TimeLiteral<'a>, TimeLiteral<'a>), +} + +// ----------------------------------------------------------------------------- + +pub fn source_text(s: &str) -> IResult<&str, SourceText> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn description(s: &str) -> IResult<&str, Description> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn module_nonansi_header(s: &str) -> IResult<&str, ModuleNonansiHeader> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn module_ansi_header(s: &str) -> IResult<&str, ModuleAnsiHeader> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn module_declaration(s: &str) -> IResult<&str, ModuleDeclaration> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn module_keyword(s: &str) -> IResult<&str, ModuleKeyword> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn interface_declaration(s: &str) -> IResult<&str, InterfaceDeclaration> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn interface_nonansi_header(s: &str) -> IResult<&str, InterfaceNonansiHeader> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn interface_ansi_header(s: &str) -> IResult<&str, InterfaceAnsiHeader> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn program_declaration(s: &str) -> IResult<&str, ProgramDeclaration> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn program_nonansi_header(s: &str) -> IResult<&str, ProgramNonansiHeader> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn program_ansi_header(s: &str) -> IResult<&str, ProgramAnsiHeader> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn checker_declaration(s: &str) -> IResult<&str, CheckerDeclaration> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn class_declaration(s: &str) -> IResult<&str, ClassDeclaration> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn interface_class_type(s: &str) -> IResult<&str, InterfaceClassType> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn interface_class_declaration(s: &str) -> IResult<&str, InterfaceClassDeclaration> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn interface_class_item(s: &str) -> IResult<&str, InterfaceClassItem> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn interface_class_method(s: &str) -> IResult<&str, InterfaceClassMethod> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn package_declaration(s: &str) -> IResult<&str, PackageDeclaration> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} + +pub fn timeunit_declaration(s: &str) -> IResult<&str, TimeunitsDeclaration> { + Err(Err::Error(make_error(s, ErrorKind::Fix))) +} diff --git a/src/parser/utils.rs b/src/parser/utils.rs index a849950..92d5690 100644 --- a/src/parser/utils.rs +++ b/src/parser/utils.rs @@ -71,153 +71,49 @@ where // ----------------------------------------------------------------------------- -#[derive(Debug)] -pub struct CastingType<'a> { - pub raw: Vec<&'a str>, -} - -#[derive(Debug)] -pub struct LetExpression<'a> { - pub raw: Vec<&'a str>, -} - -#[derive(Debug)] -pub struct TypeReference<'a> { - pub raw: Vec<&'a str>, -} - -#[derive(Debug)] -pub struct SequenceMethodCall<'a> { - pub raw: Vec<&'a str>, -} - -#[derive(Debug)] -pub struct DataType<'a> { - pub raw: Vec<&'a str>, -} - #[derive(Debug)] pub struct ConstraintBlock<'a> { pub raw: Vec<&'a str>, } -#[derive(Debug)] -pub struct SimpleType<'a> { - pub raw: Vec<&'a str>, -} - -#[derive(Debug)] -pub struct DriveStrength<'a> { - pub raw: Vec<&'a str>, -} - -#[derive(Debug)] -pub struct Delay3<'a> { - pub raw: Vec<&'a str>, -} - -#[derive(Debug)] -pub struct DynamicArrayNew<'a> { - pub raw: Vec<&'a str>, -} - -#[derive(Debug)] -pub struct ClassNew<'a> { - pub raw: Vec<&'a str>, -} - -#[derive(Debug)] -pub struct BlockItemDeclaration<'a> { - pub raw: Vec<&'a str>, -} - -#[derive(Debug)] -pub struct ExpectPropertyStatement<'a> { - pub raw: Vec<&'a str>, -} - -#[derive(Debug)] -pub struct SequenceInstance<'a> { - pub raw: Vec<&'a str>, -} - -#[derive(Debug)] -pub struct DelayValue<'a> { - pub raw: Vec<&'a str>, -} - #[derive(Debug)] pub struct EdgeIdentifier<'a> { pub raw: Vec<&'a str>, } -#[derive(Debug)] -pub struct IntegerAtomType<'a> { - pub raw: Vec<&'a str>, -} - #[derive(Debug)] pub struct IncOrDecDeclaration<'a> { pub raw: Vec<&'a str>, } -#[derive(Debug)] -pub struct ConcurrentAssertionItem<'a> { - pub raw: Vec<&'a str>, -} - -#[derive(Debug)] -pub struct ConcurrentAssertionStatement<'a> { - pub raw: Vec<&'a str>, -} - #[derive(Debug)] pub struct CheckerInstantiation<'a> { pub raw: Vec<&'a str>, } -#[derive(Debug)] -pub struct AssertionItemDeclaration<'a> { - pub raw: Vec<&'a str>, -} - -#[derive(Debug)] -pub struct DataTypeOrVoid<'a> { - pub raw: Vec<&'a str>, -} - -#[derive(Debug)] -pub struct TfPortList<'a> { - pub raw: Vec<&'a str>, -} - #[derive(Debug)] pub struct DataDeclaration<'a> { pub raw: Vec<&'a str>, } -pub fn class_scope(s: &str) -> IResult<&str, Scope> { - Ok((s, Scope::ClassScope)) +#[derive(Debug)] +pub struct ModuleOrGenerateItem<'a> { + pub raw: Vec<&'a str>, } -pub fn casting_type(s: &str) -> IResult<&str, CastingType> { - Ok((s, CastingType { raw: vec![] })) +#[derive(Debug)] +pub struct InterfaceOrGenerateItem<'a> { + pub raw: Vec<&'a str>, } -pub fn let_expression(s: &str) -> IResult<&str, LetExpression> { - Ok((s, LetExpression { raw: vec![] })) +#[derive(Debug)] +pub struct CheckerOrGenerateItem<'a> { + pub raw: Vec<&'a str>, } -pub fn type_reference(s: &str) -> IResult<&str, TypeReference> { - Ok((s, TypeReference { raw: vec![] })) -} - -pub fn sequence_method_call(s: &str) -> IResult<&str, SequenceMethodCall> { - Ok((s, SequenceMethodCall { raw: vec![] })) -} - -pub fn data_type(s: &str) -> IResult<&str, DataType> { - Ok((s, DataType { raw: vec![] })) +#[derive(Debug)] +pub struct RandomQualifier<'a> { + pub raw: Vec<&'a str>, } pub fn constraint_block(s: &str) -> IResult<&str, ConstraintBlock> { @@ -228,78 +124,34 @@ pub fn identifier_list(s: &str) -> IResult<&str, Vec> { Ok((s, vec![])) } -pub fn simple_type(s: &str) -> IResult<&str, SimpleType> { - Ok((s, SimpleType { raw: vec![] })) -} - -pub fn drive_strength(s: &str) -> IResult<&str, DriveStrength> { - Ok((s, DriveStrength { raw: vec![] })) -} - -pub fn delay3(s: &str) -> IResult<&str, Delay3> { - Ok((s, Delay3 { raw: vec![] })) -} - -pub fn dynamic_array_new(s: &str) -> IResult<&str, DynamicArrayNew> { - Ok((s, DynamicArrayNew { raw: vec![] })) -} - -pub fn class_new(s: &str) -> IResult<&str, ClassNew> { - Ok((s, ClassNew { raw: vec![] })) -} - -pub fn block_item_declaration(s: &str) -> IResult<&str, BlockItemDeclaration> { - Ok((s, BlockItemDeclaration { raw: vec![] })) -} - -pub fn expect_property_statement(s: &str) -> IResult<&str, ExpectPropertyStatement> { - Ok((s, ExpectPropertyStatement { raw: vec![] })) -} - -pub fn sequence_instance(s: &str) -> IResult<&str, SequenceInstance> { - Ok((s, SequenceInstance { raw: vec![] })) -} - -pub fn delay_value(s: &str) -> IResult<&str, DelayValue> { - Ok((s, DelayValue { raw: vec![] })) -} - pub fn edge_identifier(s: &str) -> IResult<&str, EdgeIdentifier> { Ok((s, EdgeIdentifier { raw: vec![] })) } -pub fn integer_atom_type(s: &str) -> IResult<&str, IntegerAtomType> { - Ok((s, IntegerAtomType { raw: vec![] })) -} - pub fn inc_or_dec_declaration(s: &str) -> IResult<&str, IncOrDecDeclaration> { Ok((s, IncOrDecDeclaration { raw: vec![] })) } -pub fn concurrent_assertion_item(s: &str) -> IResult<&str, ConcurrentAssertionItem> { - Ok((s, ConcurrentAssertionItem { raw: vec![] })) -} - -pub fn concurrent_assertion_statement(s: &str) -> IResult<&str, ConcurrentAssertionStatement> { - Ok((s, ConcurrentAssertionStatement { raw: vec![] })) -} - pub fn checker_instantiation(s: &str) -> IResult<&str, CheckerInstantiation> { Ok((s, CheckerInstantiation { raw: vec![] })) } -pub fn assertion_item_declaration(s: &str) -> IResult<&str, AssertionItemDeclaration> { - Ok((s, AssertionItemDeclaration { raw: vec![] })) -} - -pub fn data_type_or_void(s: &str) -> IResult<&str, DataTypeOrVoid> { - Ok((s, DataTypeOrVoid { raw: vec![] })) -} - -pub fn tf_port_list(s: &str) -> IResult<&str, TfPortList> { - Ok((s, TfPortList { raw: vec![] })) -} - pub fn data_declaration(s: &str) -> IResult<&str, DataDeclaration> { Ok((s, DataDeclaration { raw: vec![] })) } + +pub fn module_or_generate_item(s: &str) -> IResult<&str, ModuleOrGenerateItem> { + Ok((s, ModuleOrGenerateItem { raw: vec![] })) +} + +pub fn interface_or_generate_item(s: &str) -> IResult<&str, InterfaceOrGenerateItem> { + Ok((s, InterfaceOrGenerateItem { raw: vec![] })) +} + +pub fn checker_or_generate_item(s: &str) -> IResult<&str, CheckerOrGenerateItem> { + Ok((s, CheckerOrGenerateItem { raw: vec![] })) +} + +pub fn random_qualifier(s: &str) -> IResult<&str, RandomQualifier> { + Ok((s, RandomQualifier { raw: vec![] })) +}