Refactoring

This commit is contained in:
dalance 2019-07-12 16:14:36 +09:00
parent c06ff35e87
commit 8dda1ab3de
4 changed files with 532 additions and 271 deletions

View File

@ -55,9 +55,9 @@ A parser library for System Verilog.
| behavioral_statements | patterns | x | x | | | behavioral_statements | patterns | x | x | |
| behavioral_statements | looping_statements | x | x | | | behavioral_statements | looping_statements | x | x | |
| behavioral_statements | subroutine_call_statements | x | x | | | behavioral_statements | subroutine_call_statements | x | x | |
| behavioral_statements | assertion_statements | | | | | behavioral_statements | assertion_statements | x | x | |
| behavioral_statements | clocking_block | | | | | behavioral_statements | clocking_block | x | x | |
| behavioral_statements | randsequence | | | | | behavioral_statements | randsequence | x | x | |
| specify_section | specify_block_declaration | | | | | specify_section | specify_block_declaration | | | |
| specify_section | specify_path_declarations | | | | | specify_section | specify_path_declarations | | | |
| specify_section | specify_block_terminals | | | | | specify_section | specify_block_terminals | | | |

View File

@ -1,3 +1,4 @@
use crate::ast::*;
use crate::parser::*; use crate::parser::*;
use nom::branch::*; use nom::branch::*;
use nom::combinator::*; use nom::combinator::*;
@ -15,7 +16,7 @@ pub enum AssertionItem<'a> {
#[derive(Debug)] #[derive(Debug)]
pub struct DeferredImmediateAssetionItem<'a> { pub struct DeferredImmediateAssetionItem<'a> {
pub nodes: ( pub nodes: (
Option<BlockIdentifier<'a>>, Option<(BlockIdentifier<'a>, Symbol<'a>)>,
DeferredImmediateAssertionStatement<'a>, DeferredImmediateAssertionStatement<'a>,
), ),
} }
@ -42,17 +43,17 @@ pub enum SimpleImmediateAssertionStatement<'a> {
#[derive(Debug)] #[derive(Debug)]
pub struct SimpleImmediateAssertStatement<'a> { pub struct SimpleImmediateAssertStatement<'a> {
pub nodes: (Expression<'a>, ActionBlock<'a>), pub nodes: (Symbol<'a>, Paren<'a, Expression<'a>>, ActionBlock<'a>),
} }
#[derive(Debug)] #[derive(Debug)]
pub struct SimpleImmediateAssumeStatement<'a> { pub struct SimpleImmediateAssumeStatement<'a> {
pub nodes: (Expression<'a>, ActionBlock<'a>), pub nodes: (Symbol<'a>, Paren<'a, Expression<'a>>, ActionBlock<'a>),
} }
#[derive(Debug)] #[derive(Debug)]
pub struct SimpleImmediateCoverStatement<'a> { pub struct SimpleImmediateCoverStatement<'a> {
pub nodes: (Expression<'a>, StatementOrNull<'a>), pub nodes: (Symbol<'a>, Paren<'a, Expression<'a>>, StatementOrNull<'a>),
} }
#[derive(Debug)] #[derive(Debug)]
@ -64,23 +65,38 @@ pub enum DeferredImmediateAssertionStatement<'a> {
#[derive(Debug)] #[derive(Debug)]
pub struct DeferredImmediateAssertStatement<'a> { pub struct DeferredImmediateAssertStatement<'a> {
pub nodes: (AssertTiming, Expression<'a>, ActionBlock<'a>), pub nodes: (
Symbol<'a>,
AssertTiming<'a>,
Paren<'a, Expression<'a>>,
ActionBlock<'a>,
),
} }
#[derive(Debug)] #[derive(Debug)]
pub struct DeferredImmediateAssumeStatement<'a> { pub struct DeferredImmediateAssumeStatement<'a> {
pub nodes: (AssertTiming, Expression<'a>, ActionBlock<'a>), pub nodes: (
Symbol<'a>,
AssertTiming<'a>,
Paren<'a, Expression<'a>>,
ActionBlock<'a>,
),
} }
#[derive(Debug)] #[derive(Debug)]
pub struct DeferredImmediateCoverStatement<'a> { pub struct DeferredImmediateCoverStatement<'a> {
pub nodes: (AssertTiming, Expression<'a>, StatementOrNull<'a>), pub nodes: (
Symbol<'a>,
AssertTiming<'a>,
Paren<'a, Expression<'a>>,
StatementOrNull<'a>,
),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub enum AssertTiming { pub enum AssertTiming<'a> {
Zero, Zero(Symbol<'a>),
Final, Final(Symbol<'a>),
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -95,9 +111,9 @@ pub fn assertion_item(s: Span) -> IResult<Span, AssertionItem> {
} }
pub fn deferred_immediate_assertion_item(s: Span) -> IResult<Span, DeferredImmediateAssetionItem> { pub fn deferred_immediate_assertion_item(s: Span) -> IResult<Span, DeferredImmediateAssetionItem> {
let (s, x) = opt(terminated(block_identifier, symbol(":")))(s)?; let (s, a) = opt(pair(block_identifier, symbol(":")))(s)?;
let (s, y) = deferred_immediate_assertion_statement(s)?; let (s, b) = deferred_immediate_assertion_statement(s)?;
Ok((s, DeferredImmediateAssetionItem { nodes: (x, y) })) Ok((s, DeferredImmediateAssetionItem { nodes: (a, b) }))
} }
pub fn procedural_assertion_statement(s: Span) -> IResult<Span, ProceduralAssertionStatement> { pub fn procedural_assertion_statement(s: Span) -> IResult<Span, ProceduralAssertionStatement> {
@ -142,30 +158,24 @@ pub fn simple_immediate_assertion_statement(
} }
pub fn simple_immediate_assert_statement(s: Span) -> IResult<Span, SimpleImmediateAssertStatement> { pub fn simple_immediate_assert_statement(s: Span) -> IResult<Span, SimpleImmediateAssertStatement> {
let (s, _) = symbol("assert")(s)?; let (s, a) = symbol("assert")(s)?;
let (s, _) = symbol("(")(s)?; let (s, b) = paren2(expression)(s)?;
let (s, x) = expression(s)?; let (s, c) = action_block(s)?;
let (s, _) = symbol(")")(s)?; Ok((s, SimpleImmediateAssertStatement { nodes: (a, b, c) }))
let (s, y) = action_block(s)?;
Ok((s, SimpleImmediateAssertStatement { nodes: (x, y) }))
} }
pub fn simple_immediate_assume_statement(s: Span) -> IResult<Span, SimpleImmediateAssumeStatement> { pub fn simple_immediate_assume_statement(s: Span) -> IResult<Span, SimpleImmediateAssumeStatement> {
let (s, _) = symbol("assume")(s)?; let (s, a) = symbol("assume")(s)?;
let (s, _) = symbol("(")(s)?; let (s, b) = paren2(expression)(s)?;
let (s, x) = expression(s)?; let (s, c) = action_block(s)?;
let (s, _) = symbol(")")(s)?; Ok((s, SimpleImmediateAssumeStatement { nodes: (a, b, c) }))
let (s, y) = action_block(s)?;
Ok((s, SimpleImmediateAssumeStatement { nodes: (x, y) }))
} }
pub fn simple_immediate_cover_statement(s: Span) -> IResult<Span, SimpleImmediateCoverStatement> { pub fn simple_immediate_cover_statement(s: Span) -> IResult<Span, SimpleImmediateCoverStatement> {
let (s, _) = symbol("cover")(s)?; let (s, a) = symbol("cover")(s)?;
let (s, _) = symbol("(")(s)?; let (s, b) = paren2(expression)(s)?;
let (s, x) = expression(s)?; let (s, c) = statement_or_null(s)?;
let (s, _) = symbol(")")(s)?; Ok((s, SimpleImmediateCoverStatement { nodes: (a, b, c) }))
let (s, y) = statement_or_null(s)?;
Ok((s, SimpleImmediateCoverStatement { nodes: (x, y) }))
} }
pub fn deferred_immediate_assertion_statement( pub fn deferred_immediate_assertion_statement(
@ -187,43 +197,52 @@ pub fn deferred_immediate_assertion_statement(
pub fn deferred_immediate_assert_statement( pub fn deferred_immediate_assert_statement(
s: Span, s: Span,
) -> IResult<Span, DeferredImmediateAssertStatement> { ) -> IResult<Span, DeferredImmediateAssertStatement> {
let (s, _) = symbol("assert")(s)?; let (s, a) = symbol("assert")(s)?;
let (s, x) = assert_timing(s)?; let (s, b) = assert_timing(s)?;
let (s, _) = symbol("(")(s)?; let (s, c) = paren2(expression)(s)?;
let (s, y) = expression(s)?; let (s, d) = action_block(s)?;
let (s, _) = symbol(")")(s)?; Ok((
let (s, z) = action_block(s)?; s,
Ok((s, DeferredImmediateAssertStatement { nodes: (x, y, z) })) DeferredImmediateAssertStatement {
nodes: (a, b, c, d),
},
))
} }
pub fn deferred_immediate_assume_statement( pub fn deferred_immediate_assume_statement(
s: Span, s: Span,
) -> IResult<Span, DeferredImmediateAssumeStatement> { ) -> IResult<Span, DeferredImmediateAssumeStatement> {
let (s, _) = symbol("assume")(s)?; let (s, a) = symbol("assume")(s)?;
let (s, x) = assert_timing(s)?; let (s, b) = assert_timing(s)?;
let (s, _) = symbol("(")(s)?; let (s, c) = paren2(expression)(s)?;
let (s, y) = expression(s)?; let (s, d) = action_block(s)?;
let (s, _) = symbol(")")(s)?; Ok((
let (s, z) = action_block(s)?; s,
Ok((s, DeferredImmediateAssumeStatement { nodes: (x, y, z) })) DeferredImmediateAssumeStatement {
nodes: (a, b, c, d),
},
))
} }
pub fn deferred_immediate_cover_statement( pub fn deferred_immediate_cover_statement(
s: Span, s: Span,
) -> IResult<Span, DeferredImmediateCoverStatement> { ) -> IResult<Span, DeferredImmediateCoverStatement> {
let (s, _) = symbol("cover")(s)?; let (s, a) = symbol("cover")(s)?;
let (s, x) = assert_timing(s)?; let (s, b) = assert_timing(s)?;
let (s, _) = symbol("(")(s)?; let (s, c) = paren2(expression)(s)?;
let (s, y) = expression(s)?; let (s, d) = statement_or_null(s)?;
let (s, _) = symbol(")")(s)?; Ok((
let (s, z) = statement_or_null(s)?; s,
Ok((s, DeferredImmediateCoverStatement { nodes: (x, y, z) })) DeferredImmediateCoverStatement {
nodes: (a, b, c, d),
},
))
} }
pub fn assert_timing(s: Span) -> IResult<Span, AssertTiming> { pub fn assert_timing(s: Span) -> IResult<Span, AssertTiming> {
alt(( alt((
map(symbol("#0"), |_| AssertTiming::Zero), map(symbol("#0"), |x| AssertTiming::Zero(x)),
map(symbol("final"), |_| AssertTiming::Final), map(symbol("final"), |x| AssertTiming::Final(x)),
))(s) ))(s)
} }

View File

@ -1,3 +1,4 @@
use crate::ast::*;
use crate::parser::*; use crate::parser::*;
use nom::branch::*; use nom::branch::*;
use nom::combinator::*; use nom::combinator::*;
@ -16,42 +17,70 @@ pub enum ClockingDeclaration<'a> {
#[derive(Debug)] #[derive(Debug)]
pub struct ClockingDeclarationLocal<'a> { pub struct ClockingDeclarationLocal<'a> {
pub nodes: ( pub nodes: (
Option<Default>, Option<Default<'a>>,
Symbol<'a>,
Option<ClockingIdentifier<'a>>, Option<ClockingIdentifier<'a>>,
ClockingEvent<'a>, ClockingEvent<'a>,
Symbol<'a>,
Vec<ClockingItem<'a>>, Vec<ClockingItem<'a>>,
Option<ClockingIdentifier<'a>>, Symbol<'a>,
Option<(Symbol<'a>, ClockingIdentifier<'a>)>,
), ),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct Default {} pub struct Default<'a> {
pub nodes: (Symbol<'a>,),
}
#[derive(Debug)] #[derive(Debug)]
pub struct ClockingDeclarationGlobal<'a> { pub struct ClockingDeclarationGlobal<'a> {
pub nodes: ( pub nodes: (
Symbol<'a>,
Symbol<'a>,
Option<ClockingIdentifier<'a>>, Option<ClockingIdentifier<'a>>,
ClockingEvent<'a>, ClockingEvent<'a>,
Option<ClockingIdentifier<'a>>, Symbol<'a>,
Symbol<'a>,
Option<(Symbol<'a>, ClockingIdentifier<'a>)>,
), ),
} }
#[derive(Debug)] #[derive(Debug)]
pub enum ClockingEvent<'a> { pub enum ClockingEvent<'a> {
Identifier(Identifier<'a>), Identifier(ClockingEventIdentifier<'a>),
Expression(EventExpression<'a>), Expression(ClockingEventExpression<'a>),
}
#[derive(Debug, Node)]
pub struct ClockingEventIdentifier<'a> {
pub nodes: (Symbol<'a>, Identifier<'a>),
}
#[derive(Debug)]
pub struct ClockingEventExpression<'a> {
pub nodes: (Symbol<'a>, Paren<'a, EventExpression<'a>>),
} }
#[derive(Debug)] #[derive(Debug)]
pub enum ClockingItem<'a> { pub enum ClockingItem<'a> {
DefaultSkew(DefaultSkew<'a>), Default(ClockingItemDefault<'a>),
Direction(ClockingItemDirection<'a>), Direction(ClockingItemDirection<'a>),
Assertion(ClockingItemAssertion<'a>), Assertion(ClockingItemAssertion<'a>),
} }
#[derive(Debug)]
pub struct ClockingItemDefault<'a> {
pub nodes: (Symbol<'a>, DefaultSkew<'a>, Symbol<'a>),
}
#[derive(Debug)] #[derive(Debug)]
pub struct ClockingItemDirection<'a> { pub struct ClockingItemDirection<'a> {
pub nodes: (ClockingDirection<'a>, Vec<ClockingDeclAssign<'a>>), pub nodes: (
ClockingDirection<'a>,
ListOfClockingDeclAssign<'a>,
Symbol<'a>,
),
} }
#[derive(Debug)] #[derive(Debug)]
@ -61,34 +90,80 @@ pub struct ClockingItemAssertion<'a> {
#[derive(Debug)] #[derive(Debug)]
pub enum DefaultSkew<'a> { pub enum DefaultSkew<'a> {
Input(ClockingSkew<'a>), Input(DefaultSkewInput<'a>),
Output(ClockingSkew<'a>), Output(DefaultSkewOutput<'a>),
InputOutput((ClockingSkew<'a>, ClockingSkew<'a>)), InputOutput(DefaultSkewInputOutput<'a>),
}
#[derive(Debug)]
pub struct DefaultSkewInput<'a> {
pub nodes: (Symbol<'a>, ClockingSkew<'a>),
}
#[derive(Debug)]
pub struct DefaultSkewOutput<'a> {
pub nodes: (Symbol<'a>, ClockingSkew<'a>),
}
#[derive(Debug)]
pub struct DefaultSkewInputOutput<'a> {
pub nodes: (Symbol<'a>, ClockingSkew<'a>, Symbol<'a>, ClockingSkew<'a>),
} }
#[derive(Debug)] #[derive(Debug)]
pub enum ClockingDirection<'a> { pub enum ClockingDirection<'a> {
Input(Option<ClockingSkew<'a>>), Input(ClockingDirectionInput<'a>),
Output(Option<ClockingSkew<'a>>), Output(ClockingDirectionOutput<'a>),
InputOutput((Option<ClockingSkew<'a>>, Option<ClockingSkew<'a>>)), InputOutput(ClockingDirectionInputOutput<'a>),
Inout, Inout(Symbol<'a>),
}
#[derive(Debug)]
pub struct ClockingDirectionInput<'a> {
pub nodes: (Symbol<'a>, Option<ClockingSkew<'a>>),
}
#[derive(Debug)]
pub struct ClockingDirectionOutput<'a> {
pub nodes: (Symbol<'a>, Option<ClockingSkew<'a>>),
}
#[derive(Debug)]
pub struct ClockingDirectionInputOutput<'a> {
pub nodes: (
Symbol<'a>,
Option<ClockingSkew<'a>>,
Symbol<'a>,
Option<ClockingSkew<'a>>,
),
}
#[derive(Debug)]
pub struct ListOfClockingDeclAssign<'a> {
pub nodes: (List<Symbol<'a>, ClockingDeclAssign<'a>>,),
} }
#[derive(Debug)] #[derive(Debug)]
pub struct ClockingDeclAssign<'a> { pub struct ClockingDeclAssign<'a> {
pub nodes: (SignalIdentifier<'a>, Option<Expression<'a>>), pub nodes: (SignalIdentifier<'a>, Option<(Symbol<'a>, Expression<'a>)>),
} }
#[derive(Debug)] #[derive(Debug)]
pub enum ClockingSkew<'a> { pub enum ClockingSkew<'a> {
Edge((EdgeIdentifier<'a>, Option<DelayControl<'a>>)), Edge(ClockingSkewEdge<'a>),
Delay(DelayControl<'a>), DelayControl(DelayControl<'a>),
}
#[derive(Debug)]
pub struct ClockingSkewEdge<'a> {
pub nodes: (EdgeIdentifier<'a>, Option<DelayControl<'a>>),
} }
#[derive(Debug)] #[derive(Debug)]
pub struct ClockingDrive<'a> { pub struct ClockingDrive<'a> {
pub nodes: ( pub nodes: (
(HierarchicalIdentifier<'a>, Select<'a>), ClockvarExpression<'a>,
Symbol<'a>,
Option<CycleDelay<'a>>, Option<CycleDelay<'a>>,
Expression<'a>, Expression<'a>,
), ),
@ -96,11 +171,35 @@ pub struct ClockingDrive<'a> {
#[derive(Debug)] #[derive(Debug)]
pub enum CycleDelay<'a> { pub enum CycleDelay<'a> {
IntegralNumber(IntegralNumber<'a>), Integral(CycleDelayIntegral<'a>),
Identifier(Identifier<'a>), Identifier(CycleDelayIdentifier<'a>),
Expression(Expression<'a>), Expression(CycleDelayExpression<'a>),
} }
#[derive(Debug, Node)]
pub struct CycleDelayIntegral<'a> {
pub nodes: (Symbol<'a>, IntegralNumber<'a>),
}
#[derive(Debug, Node)]
pub struct CycleDelayIdentifier<'a> {
pub nodes: (Symbol<'a>, Identifier<'a>),
}
#[derive(Debug)]
pub struct CycleDelayExpression<'a> {
pub nodes: (Symbol<'a>, Paren<'a, Expression<'a>>),
}
#[derive(Debug)]
pub struct Clockvar<'a> {
pub nodes: (HierarchicalIdentifier<'a>,),
}
#[derive(Debug)]
pub struct ClockvarExpression<'a> {
pub nodes: (Clockvar<'a>, Select<'a>),
}
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
pub fn clocking_declaration(s: Span) -> IResult<Span, ClockingDeclaration> { pub fn clocking_declaration(s: Span) -> IResult<Span, ClockingDeclaration> {
@ -108,77 +207,99 @@ pub fn clocking_declaration(s: Span) -> IResult<Span, ClockingDeclaration> {
} }
pub fn clocking_declaration_local(s: Span) -> IResult<Span, ClockingDeclaration> { pub fn clocking_declaration_local(s: Span) -> IResult<Span, ClockingDeclaration> {
let (s, x) = opt(symbol("default"))(s)?; let (s, a) = opt(default)(s)?;
let (s, _) = symbol("clocking")(s)?; let (s, b) = symbol("clocking")(s)?;
let (s, y) = opt(clocking_identifier)(s)?; let (s, c) = opt(clocking_identifier)(s)?;
let (s, z) = clocking_event(s)?; let (s, d) = clocking_event(s)?;
let (s, _) = symbol(";")(s)?; let (s, e) = symbol(";")(s)?;
let (s, v) = many0(clocking_item)(s)?; let (s, f) = many0(clocking_item)(s)?;
let (s, _) = symbol("endclocking")(s)?; let (s, g) = symbol("endclocking")(s)?;
let (s, w) = opt(preceded(symbol(":"), clocking_identifier))(s)?; let (s, h) = opt(pair(symbol(":"), clocking_identifier))(s)?;
Ok(( Ok((
s, s,
ClockingDeclaration::Local(ClockingDeclarationLocal { ClockingDeclaration::Local(ClockingDeclarationLocal {
nodes: (x.map(|_| Default {}), y, z, v, w), nodes: (a, b, c, d, e, f, g, h),
}), }),
)) ))
} }
pub fn default(s: Span) -> IResult<Span, Default> {
let (s, a) = symbol("default")(s)?;
Ok((s, Default { nodes: (a,) }))
}
pub fn clocking_declaration_global(s: Span) -> IResult<Span, ClockingDeclaration> { pub fn clocking_declaration_global(s: Span) -> IResult<Span, ClockingDeclaration> {
let (s, _) = opt(symbol("global"))(s)?; let (s, a) = symbol("global")(s)?;
let (s, _) = symbol("clocking")(s)?; let (s, b) = symbol("clocking")(s)?;
let (s, x) = opt(clocking_identifier)(s)?; let (s, c) = opt(clocking_identifier)(s)?;
let (s, y) = clocking_event(s)?; let (s, d) = clocking_event(s)?;
let (s, _) = symbol(";")(s)?; let (s, e) = symbol(";")(s)?;
let (s, _) = symbol("endclocking")(s)?; let (s, f) = symbol("endclocking")(s)?;
let (s, z) = opt(preceded(symbol(":"), clocking_identifier))(s)?; let (s, g) = opt(pair(symbol(":"), clocking_identifier))(s)?;
Ok(( Ok((
s, s,
ClockingDeclaration::Global(ClockingDeclarationGlobal { nodes: (x, y, z) }), ClockingDeclaration::Global(ClockingDeclarationGlobal {
nodes: (a, b, c, d, e, f, g),
}),
)) ))
} }
pub fn clocking_event(s: Span) -> IResult<Span, ClockingEvent> { pub fn clocking_event(s: Span) -> IResult<Span, ClockingEvent> {
alt(( alt((clocking_event_identifier, clocking_event_expression))(s)
map(preceded(symbol("@"), identifier), |x| { }
ClockingEvent::Identifier(x)
}), pub fn clocking_event_identifier(s: Span) -> IResult<Span, ClockingEvent> {
map(preceded(symbol("@"), paren(event_expression)), |x| { let (s, a) = symbol("@")(s)?;
ClockingEvent::Expression(x) let (s, b) = identifier(s)?;
}), Ok((
))(s) s,
ClockingEvent::Identifier(ClockingEventIdentifier { nodes: (a, b) }),
))
}
pub fn clocking_event_expression(s: Span) -> IResult<Span, ClockingEvent> {
let (s, a) = symbol("@")(s)?;
let (s, b) = paren2(event_expression)(s)?;
Ok((
s,
ClockingEvent::Expression(ClockingEventExpression { nodes: (a, b) }),
))
} }
pub fn clocking_item(s: Span) -> IResult<Span, ClockingItem> { pub fn clocking_item(s: Span) -> IResult<Span, ClockingItem> {
alt(( alt((
clocking_item_default_skew, clocking_item_default,
clocking_item_direction, clocking_item_direction,
clocking_item_assertion, clocking_item_assertion,
))(s) ))(s)
} }
pub fn clocking_item_default_skew(s: Span) -> IResult<Span, ClockingItem> { pub fn clocking_item_default(s: Span) -> IResult<Span, ClockingItem> {
let (s, _) = symbol("default")(s)?; let (s, a) = symbol("default")(s)?;
let (s, x) = default_skew(s)?; let (s, b) = default_skew(s)?;
let (s, _) = symbol(";")(s)?; let (s, c) = symbol(";")(s)?;
Ok((s, ClockingItem::DefaultSkew(x))) Ok((
s,
ClockingItem::Default(ClockingItemDefault { nodes: (a, b, c) }),
))
} }
pub fn clocking_item_direction(s: Span) -> IResult<Span, ClockingItem> { pub fn clocking_item_direction(s: Span) -> IResult<Span, ClockingItem> {
let (s, x) = clocking_direction(s)?; let (s, a) = clocking_direction(s)?;
let (s, y) = list_of_clocking_decl_assign(s)?; let (s, b) = list_of_clocking_decl_assign(s)?;
let (s, c) = symbol(";")(s)?;
Ok(( Ok((
s, s,
ClockingItem::Direction(ClockingItemDirection { nodes: (x, y) }), ClockingItem::Direction(ClockingItemDirection { nodes: (a, b, c) }),
)) ))
} }
pub fn clocking_item_assertion(s: Span) -> IResult<Span, ClockingItem> { pub fn clocking_item_assertion(s: Span) -> IResult<Span, ClockingItem> {
let (s, x) = many0(attribute_instance)(s)?; let (s, a) = many0(attribute_instance)(s)?;
let (s, y) = assertion_item_declaration(s)?; let (s, b) = assertion_item_declaration(s)?;
Ok(( Ok((
s, s,
ClockingItem::Assertion(ClockingItemAssertion { nodes: (x, y) }), ClockingItem::Assertion(ClockingItemAssertion { nodes: (a, b) }),
)) ))
} }
@ -191,23 +312,28 @@ pub fn default_skew(s: Span) -> IResult<Span, DefaultSkew> {
} }
pub fn default_skew_input(s: Span) -> IResult<Span, DefaultSkew> { pub fn default_skew_input(s: Span) -> IResult<Span, DefaultSkew> {
let (s, _) = symbol("input")(s)?; let (s, a) = symbol("input")(s)?;
let (s, x) = clocking_skew(s)?; let (s, b) = clocking_skew(s)?;
Ok((s, DefaultSkew::Input(x))) Ok((s, DefaultSkew::Input(DefaultSkewInput { nodes: (a, b) })))
} }
pub fn default_skew_output(s: Span) -> IResult<Span, DefaultSkew> { pub fn default_skew_output(s: Span) -> IResult<Span, DefaultSkew> {
let (s, _) = symbol("output")(s)?; let (s, a) = symbol("output")(s)?;
let (s, x) = clocking_skew(s)?; let (s, b) = clocking_skew(s)?;
Ok((s, DefaultSkew::Output(x))) Ok((s, DefaultSkew::Output(DefaultSkewOutput { nodes: (a, b) })))
} }
pub fn default_skew_input_output(s: Span) -> IResult<Span, DefaultSkew> { pub fn default_skew_input_output(s: Span) -> IResult<Span, DefaultSkew> {
let (s, _) = symbol("input")(s)?; let (s, a) = symbol("input")(s)?;
let (s, x) = clocking_skew(s)?; let (s, b) = clocking_skew(s)?;
let (s, _) = symbol("output")(s)?; let (s, c) = symbol("output")(s)?;
let (s, y) = clocking_skew(s)?; let (s, d) = clocking_skew(s)?;
Ok((s, DefaultSkew::InputOutput((x, y)))) Ok((
s,
DefaultSkew::InputOutput(DefaultSkewInputOutput {
nodes: (a, b, c, d),
}),
))
} }
pub fn clocking_direction(s: Span) -> IResult<Span, ClockingDirection> { pub fn clocking_direction(s: Span) -> IResult<Span, ClockingDirection> {
@ -220,83 +346,122 @@ pub fn clocking_direction(s: Span) -> IResult<Span, ClockingDirection> {
} }
pub fn clocking_direction_input(s: Span) -> IResult<Span, ClockingDirection> { pub fn clocking_direction_input(s: Span) -> IResult<Span, ClockingDirection> {
let (s, _) = symbol("input")(s)?; let (s, a) = symbol("input")(s)?;
let (s, x) = opt(clocking_skew)(s)?; let (s, b) = opt(clocking_skew)(s)?;
Ok((s, ClockingDirection::Input(x))) Ok((
s,
ClockingDirection::Input(ClockingDirectionInput { nodes: (a, b) }),
))
} }
pub fn clocking_direction_output(s: Span) -> IResult<Span, ClockingDirection> { pub fn clocking_direction_output(s: Span) -> IResult<Span, ClockingDirection> {
let (s, _) = symbol("output")(s)?; let (s, a) = symbol("output")(s)?;
let (s, x) = opt(clocking_skew)(s)?; let (s, b) = opt(clocking_skew)(s)?;
Ok((s, ClockingDirection::Output(x))) Ok((
s,
ClockingDirection::Output(ClockingDirectionOutput { nodes: (a, b) }),
))
} }
pub fn clocking_direction_input_output(s: Span) -> IResult<Span, ClockingDirection> { pub fn clocking_direction_input_output(s: Span) -> IResult<Span, ClockingDirection> {
let (s, _) = symbol("input")(s)?; let (s, a) = symbol("input")(s)?;
let (s, x) = opt(clocking_skew)(s)?; let (s, b) = opt(clocking_skew)(s)?;
let (s, _) = symbol("output")(s)?; let (s, c) = symbol("output")(s)?;
let (s, y) = opt(clocking_skew)(s)?; let (s, d) = opt(clocking_skew)(s)?;
Ok((s, ClockingDirection::InputOutput((x, y)))) Ok((
s,
ClockingDirection::InputOutput(ClockingDirectionInputOutput {
nodes: (a, b, c, d),
}),
))
} }
pub fn clocking_direction_inout(s: Span) -> IResult<Span, ClockingDirection> { pub fn clocking_direction_inout(s: Span) -> IResult<Span, ClockingDirection> {
let (s, _) = symbol("inout")(s)?; let (s, a) = symbol("inout")(s)?;
Ok((s, ClockingDirection::Inout)) Ok((s, ClockingDirection::Inout(a)))
} }
pub fn list_of_clocking_decl_assign(s: Span) -> IResult<Span, Vec<ClockingDeclAssign>> { pub fn list_of_clocking_decl_assign(s: Span) -> IResult<Span, ListOfClockingDeclAssign> {
many1(clocking_decl_assign)(s) let (s, a) = list(symbol(","), clocking_decl_assign)(s)?;
Ok((s, ListOfClockingDeclAssign { nodes: (a,) }))
} }
pub fn clocking_decl_assign(s: Span) -> IResult<Span, ClockingDeclAssign> { pub fn clocking_decl_assign(s: Span) -> IResult<Span, ClockingDeclAssign> {
let (s, x) = signal_identifier(s)?; let (s, a) = signal_identifier(s)?;
let (s, y) = opt(preceded(symbol("="), expression))(s)?; let (s, b) = opt(pair(symbol("="), expression))(s)?;
Ok((s, ClockingDeclAssign { nodes: (x, y) })) Ok((s, ClockingDeclAssign { nodes: (a, b) }))
} }
pub fn clocking_skew(s: Span) -> IResult<Span, ClockingSkew> { pub fn clocking_skew(s: Span) -> IResult<Span, ClockingSkew> {
alt((clocking_skew_edge, clocking_skew_delay))(s) alt((
clocking_skew_edge,
map(delay_control, |x| ClockingSkew::DelayControl(x)),
))(s)
} }
pub fn clocking_skew_edge(s: Span) -> IResult<Span, ClockingSkew> { pub fn clocking_skew_edge(s: Span) -> IResult<Span, ClockingSkew> {
let (s, x) = edge_identifier(s)?; let (s, a) = edge_identifier(s)?;
let (s, y) = opt(delay_control)(s)?; let (s, b) = opt(delay_control)(s)?;
Ok((s, ClockingSkew::Edge((x, y)))) Ok((s, ClockingSkew::Edge(ClockingSkewEdge { nodes: (a, b) })))
}
pub fn clocking_skew_delay(s: Span) -> IResult<Span, ClockingSkew> {
let (s, x) = delay_control(s)?;
Ok((s, ClockingSkew::Delay(x)))
} }
pub fn clocking_drive(s: Span) -> IResult<Span, ClockingDrive> { pub fn clocking_drive(s: Span) -> IResult<Span, ClockingDrive> {
let (s, x) = clockvar_expression(s)?; let (s, a) = clockvar_expression(s)?;
let (s, _) = symbol("=")(s)?; let (s, b) = symbol("<=")(s)?;
let (s, y) = opt(cycle_delay)(s)?; let (s, c) = opt(cycle_delay)(s)?;
let (s, z) = expression(s)?; let (s, d) = expression(s)?;
Ok((s, ClockingDrive { nodes: (x, y, z) })) Ok((
s,
ClockingDrive {
nodes: (a, b, c, d),
},
))
} }
pub fn cycle_delay(s: Span) -> IResult<Span, CycleDelay> { pub fn cycle_delay(s: Span) -> IResult<Span, CycleDelay> {
alt(( alt((
map(preceded(symbol("##"), integral_number), |x| { cycle_delay_integral,
CycleDelay::IntegralNumber(x) cycle_delay_identifier,
}), cycle_delay_expression,
map(preceded(symbol("##"), identifier), |x| {
CycleDelay::Identifier(x)
}),
map(preceded(symbol("##"), paren(expression)), |x| {
CycleDelay::Expression(x)
}),
))(s) ))(s)
} }
pub fn clockvar(s: Span) -> IResult<Span, HierarchicalIdentifier> { pub fn cycle_delay_integral(s: Span) -> IResult<Span, CycleDelay> {
hierarchical_identifier(s) let (s, a) = symbol("##")(s)?;
let (s, b) = integral_number(s)?;
Ok((
s,
CycleDelay::Integral(CycleDelayIntegral { nodes: (a, b) }),
))
} }
pub fn clockvar_expression(s: Span) -> IResult<Span, (HierarchicalIdentifier, Select)> { pub fn cycle_delay_identifier(s: Span) -> IResult<Span, CycleDelay> {
pair(clockvar, select)(s) let (s, a) = symbol("##")(s)?;
let (s, b) = identifier(s)?;
Ok((
s,
CycleDelay::Identifier(CycleDelayIdentifier { nodes: (a, b) }),
))
}
pub fn cycle_delay_expression(s: Span) -> IResult<Span, CycleDelay> {
let (s, a) = symbol("##")(s)?;
let (s, b) = paren2(expression)(s)?;
Ok((
s,
CycleDelay::Expression(CycleDelayExpression { nodes: (a, b) }),
))
}
pub fn clockvar(s: Span) -> IResult<Span, Clockvar> {
let (s, a) = hierarchical_identifier(s)?;
Ok((s, Clockvar { nodes: (a,) }))
}
pub fn clockvar_expression(s: Span) -> IResult<Span, ClockvarExpression> {
let (s, a) = clockvar(s)?;
let (s, b) = select(s)?;
Ok((s, ClockvarExpression { nodes: (a, b) }))
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------

View File

@ -9,7 +9,13 @@ use nom::IResult;
#[derive(Debug)] #[derive(Debug)]
pub struct RandsequenceStatement<'a> { pub struct RandsequenceStatement<'a> {
pub nodes: (Option<ProductionIdentifier<'a>>, Vec<Production<'a>>), pub nodes: (
Symbol<'a>,
Paren<'a, Option<ProductionIdentifier<'a>>>,
Production<'a>,
Vec<Production<'a>>,
Symbol<'a>,
),
} }
#[derive(Debug)] #[derive(Debug)]
@ -17,8 +23,10 @@ pub struct Production<'a> {
pub nodes: ( pub nodes: (
Option<DataTypeOrVoid<'a>>, Option<DataTypeOrVoid<'a>>,
ProductionIdentifier<'a>, ProductionIdentifier<'a>,
Option<TfPortList<'a>>, Option<Paren<'a, TfPortList<'a>>>,
Vec<RsRule<'a>>, Symbol<'a>,
List<Symbol<'a>, RsRule<'a>>,
Symbol<'a>,
), ),
} }
@ -26,60 +34,91 @@ pub struct Production<'a> {
pub struct RsRule<'a> { pub struct RsRule<'a> {
pub nodes: ( pub nodes: (
RsProductionList<'a>, RsProductionList<'a>,
Option<WeightSpecification<'a>>, Option<(Symbol<'a>, WeightSpecification<'a>, Option<RsCodeBlock<'a>>)>,
Option<RsCodeBlock<'a>>,
), ),
} }
#[derive(Debug)] #[derive(Debug)]
pub enum RsProductionList<'a> { pub enum RsProductionList<'a> {
Prod(Vec<RsProd<'a>>), Prod(RsProductionListProd<'a>),
Join((Option<Expression<'a>>, Vec<ProductionItem<'a>>)), Join(RsProductionListJoin<'a>),
}
#[derive(Debug)]
pub struct RsProductionListProd<'a> {
pub nodes: (RsProd<'a>, Vec<RsProd<'a>>),
}
#[derive(Debug)]
pub struct RsProductionListJoin<'a> {
pub nodes: (
Symbol<'a>,
Symbol<'a>,
Option<Paren<'a, Expression<'a>>>,
ProductionItem<'a>,
ProductionItem<'a>,
Vec<ProductionItem<'a>>,
),
} }
#[derive(Debug)] #[derive(Debug)]
pub enum WeightSpecification<'a> { pub enum WeightSpecification<'a> {
IntegralNumber(IntegralNumber<'a>), IntegralNumber(IntegralNumber<'a>),
PsIdentifier(PsIdentifier<'a>), PsIdentifier(PsIdentifier<'a>),
Expression(Expression<'a>), Expression(WeightSpecificationExpression<'a>),
}
#[derive(Debug)]
pub struct WeightSpecificationExpression<'a> {
pub nodes: (Paren<'a, Expression<'a>>,),
} }
#[derive(Debug)] #[derive(Debug)]
pub struct RsCodeBlock<'a> { pub struct RsCodeBlock<'a> {
pub nodes: (Vec<DataDeclaration<'a>>, Vec<StatementOrNull<'a>>), pub nodes: (Brace<'a, (Vec<DataDeclaration<'a>>, Vec<StatementOrNull<'a>>)>,),
} }
#[derive(Debug)] #[derive(Debug)]
pub enum RsProd<'a> { pub enum RsProd<'a> {
Item(ProductionItem<'a>), ProductionItem(ProductionItem<'a>),
CodeBlock(RsCodeBlock<'a>), RsCodeBlock(RsCodeBlock<'a>),
IfElse(RsIfElse<'a>), RsIfElse(RsIfElse<'a>),
Repeat(RsRepeat<'a>), RsRepeat(RsRepeat<'a>),
Case(RsCase<'a>), RsCase(RsCase<'a>),
} }
#[derive(Debug)] #[derive(Debug)]
pub struct ProductionItem<'a> { pub struct ProductionItem<'a> {
pub nodes: (ProductionIdentifier<'a>, Option<ListOfArguments<'a>>), pub nodes: (
ProductionIdentifier<'a>,
Option<Paren<'a, ListOfArguments<'a>>>,
),
} }
#[derive(Debug)] #[derive(Debug)]
pub struct RsIfElse<'a> { pub struct RsIfElse<'a> {
pub nodes: ( pub nodes: (
Expression<'a>, Symbol<'a>,
Paren<'a, Expression<'a>>,
ProductionItem<'a>, ProductionItem<'a>,
Option<ProductionItem<'a>>, Option<(Symbol<'a>, ProductionItem<'a>)>,
), ),
} }
#[derive(Debug)] #[derive(Debug)]
pub struct RsRepeat<'a> { pub struct RsRepeat<'a> {
pub nodes: (Expression<'a>, ProductionItem<'a>), pub nodes: (Symbol<'a>, Paren<'a, Expression<'a>>, ProductionItem<'a>),
} }
#[derive(Debug)] #[derive(Debug)]
pub struct RsCase<'a> { pub struct RsCase<'a> {
pub nodes: (CaseExpression<'a>, Vec<RsCaseItem<'a>>), pub nodes: (
Symbol<'a>,
Paren<'a, CaseExpression<'a>>,
RsCaseItem<'a>,
Vec<RsCaseItem<'a>>,
Symbol<'a>,
),
} }
#[derive(Debug)] #[derive(Debug)]
@ -89,55 +128,64 @@ pub enum RsCaseItem<'a> {
} }
#[derive(Debug)] #[derive(Debug)]
pub struct RsCaseItemDefault<'a> { pub struct RsCaseItemNondefault<'a> {
pub nodes: (ProductionItem<'a>,), pub nodes: (
List<Symbol<'a>, CaseItemExpression<'a>>,
Symbol<'a>,
ProductionItem<'a>,
Symbol<'a>,
),
} }
#[derive(Debug)] #[derive(Debug)]
pub struct RsCaseItemNondefault<'a> { pub struct RsCaseItemDefault<'a> {
pub nodes: (Vec<CaseItemExpression<'a>>, ProductionItem<'a>), pub nodes: (
Symbol<'a>,
Option<Symbol<'a>>,
ProductionItem<'a>,
Symbol<'a>,
),
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
pub fn randsequence_statement(s: Span) -> IResult<Span, RandsequenceStatement> { pub fn randsequence_statement(s: Span) -> IResult<Span, RandsequenceStatement> {
let (s, _) = symbol("randsequence")(s)?; let (s, a) = symbol("randsequence")(s)?;
let (s, _) = symbol("(")(s)?; let (s, b) = paren2(opt(production_identifier))(s)?;
let (s, x) = opt(production_identifier)(s)?; let (s, c) = production(s)?;
let (s, _) = symbol(")")(s)?; let (s, d) = many0(production)(s)?;
let (s, y) = many1(production)(s)?; let (s, e) = symbol("endsequence")(s)?;
let (s, _) = symbol("endsequence")(s)?; Ok((
Ok((s, RandsequenceStatement { nodes: (x, y) })) s,
RandsequenceStatement {
nodes: (a, b, c, d, e),
},
))
} }
pub fn production(s: Span) -> IResult<Span, Production> { pub fn production(s: Span) -> IResult<Span, Production> {
let (s, x) = opt(data_type_or_void)(s)?; let (s, a) = opt(data_type_or_void)(s)?;
let (s, y) = production_identifier(s)?; let (s, b) = production_identifier(s)?;
let (s, z) = opt(paren(tf_port_list))(s)?; let (s, c) = opt(paren2(tf_port_list))(s)?;
let (s, _) = symbol(":")(s)?; let (s, d) = symbol(":")(s)?;
let (s, v) = separated_nonempty_list(symbol("|"), rs_rule)(s)?; let (s, e) = list(symbol("|"), rs_rule)(s)?;
let (s, _) = symbol(";")(s)?; let (s, f) = symbol(";")(s)?;
Ok(( Ok((
s, s,
Production { Production {
nodes: (x, y, z, v), nodes: (a, b, c, d, e, f),
}, },
)) ))
} }
pub fn rs_rule(s: Span) -> IResult<Span, RsRule> { pub fn rs_rule(s: Span) -> IResult<Span, RsRule> {
let (s, x) = rs_production_list(s)?; let (s, a) = rs_production_list(s)?;
let (s, y) = opt(preceded( let (s, b) = opt(triple(
symbol(":="), symbol(":="),
pair(weight_specification, opt(rs_code_block)), weight_specification,
opt(rs_code_block),
))(s)?; ))(s)?;
Ok((s, RsRule { nodes: (a, b) }))
let (y, z) = if let Some((y, z)) = y {
(Some(y), z)
} else {
(None, None)
};
Ok((s, RsRule { nodes: (x, y, z) }))
} }
pub fn rs_production_list(s: Span) -> IResult<Span, RsProductionList> { pub fn rs_production_list(s: Span) -> IResult<Span, RsProductionList> {
@ -145,76 +193,98 @@ pub fn rs_production_list(s: Span) -> IResult<Span, RsProductionList> {
} }
pub fn rs_production_list_prod(s: Span) -> IResult<Span, RsProductionList> { pub fn rs_production_list_prod(s: Span) -> IResult<Span, RsProductionList> {
let (s, x) = many1(rs_prod)(s)?; let (s, a) = rs_prod(s)?;
Ok((s, RsProductionList::Prod(x))) let (s, b) = many0(rs_prod)(s)?;
Ok((
s,
RsProductionList::Prod(RsProductionListProd { nodes: (a, b) }),
))
} }
pub fn rs_production_list_join(s: Span) -> IResult<Span, RsProductionList> { pub fn rs_production_list_join(s: Span) -> IResult<Span, RsProductionList> {
let (s, _) = symbol("rand")(s)?; let (s, a) = symbol("rand")(s)?;
let (s, _) = symbol("join")(s)?; let (s, b) = symbol("join")(s)?;
let (s, x) = opt(paren(expression))(s)?; let (s, c) = opt(paren2(expression))(s)?;
let (s, y) = production_item(s)?; let (s, d) = production_item(s)?;
let (s, z) = many1(production_item)(s)?; let (s, e) = production_item(s)?;
let (s, f) = many0(production_item)(s)?;
let mut y = vec![y]; Ok((
for z in z { s,
y.push(z); RsProductionList::Join(RsProductionListJoin {
} nodes: (a, b, c, d, e, f),
Ok((s, RsProductionList::Join((x, y)))) }),
))
} }
pub fn weight_specification(s: Span) -> IResult<Span, WeightSpecification> { pub fn weight_specification(s: Span) -> IResult<Span, WeightSpecification> {
alt(( alt((
map(integral_number, |x| WeightSpecification::IntegralNumber(x)), map(integral_number, |x| WeightSpecification::IntegralNumber(x)),
map(ps_identifier, |x| WeightSpecification::PsIdentifier(x)), map(ps_identifier, |x| WeightSpecification::PsIdentifier(x)),
map(paren(expression), |x| WeightSpecification::Expression(x)), weight_specification_expression,
))(s) ))(s)
} }
pub fn weight_specification_expression(s: Span) -> IResult<Span, WeightSpecification> {
let (s, a) = paren2(expression)(s)?;
Ok((
s,
WeightSpecification::Expression(WeightSpecificationExpression { nodes: (a,) }),
))
}
pub fn rs_code_block(s: Span) -> IResult<Span, RsCodeBlock> { pub fn rs_code_block(s: Span) -> IResult<Span, RsCodeBlock> {
let (s, _) = symbol("{")(s)?; let (s, a) = brace2(pair(many0(data_declaration), many0(statement_or_null)))(s)?;
let (s, x) = many0(data_declaration)(s)?; Ok((s, RsCodeBlock { nodes: (a,) }))
let (s, y) = many0(statement_or_null)(s)?;
let (s, _) = symbol("}")(s)?;
Ok((s, RsCodeBlock { nodes: (x, y) }))
} }
pub fn rs_prod(s: Span) -> IResult<Span, RsProd> { pub fn rs_prod(s: Span) -> IResult<Span, RsProd> {
alt(( alt((
map(production_item, |x| RsProd::Item(x)), map(production_item, |x| RsProd::ProductionItem(x)),
map(rs_code_block, |x| RsProd::CodeBlock(x)), map(rs_code_block, |x| RsProd::RsCodeBlock(x)),
map(rs_if_else, |x| RsProd::IfElse(x)), map(rs_if_else, |x| RsProd::RsIfElse(x)),
map(rs_repeat, |x| RsProd::Repeat(x)), map(rs_repeat, |x| RsProd::RsRepeat(x)),
map(rs_case, |x| RsProd::Case(x)), map(rs_case, |x| RsProd::RsCase(x)),
))(s) ))(s)
} }
pub fn production_item(s: Span) -> IResult<Span, ProductionItem> { pub fn production_item(s: Span) -> IResult<Span, ProductionItem> {
let (s, x) = production_identifier(s)?; let (s, a) = production_identifier(s)?;
let (s, y) = opt(paren(list_of_arguments))(s)?; let (s, b) = opt(paren2(list_of_arguments))(s)?;
Ok((s, ProductionItem { nodes: (x, y) })) Ok((s, ProductionItem { nodes: (a, b) }))
} }
pub fn rs_if_else(s: Span) -> IResult<Span, RsIfElse> { pub fn rs_if_else(s: Span) -> IResult<Span, RsIfElse> {
let (s, _) = symbol("if")(s)?; let (s, a) = symbol("if")(s)?;
let (s, x) = paren(expression)(s)?; let (s, b) = paren2(expression)(s)?;
let (s, y) = production_item(s)?; let (s, c) = production_item(s)?;
let (s, z) = opt(preceded(symbol("else"), production_item))(s)?; let (s, d) = opt(pair(symbol("else"), production_item))(s)?;
Ok((s, RsIfElse { nodes: (x, y, z) })) Ok((
s,
RsIfElse {
nodes: (a, b, c, d),
},
))
} }
pub fn rs_repeat(s: Span) -> IResult<Span, RsRepeat> { pub fn rs_repeat(s: Span) -> IResult<Span, RsRepeat> {
let (s, _) = symbol("repeat")(s)?; let (s, a) = symbol("repeat")(s)?;
let (s, x) = paren(expression)(s)?; let (s, b) = paren2(expression)(s)?;
let (s, y) = production_item(s)?; let (s, c) = production_item(s)?;
Ok((s, RsRepeat { nodes: (x, y) })) Ok((s, RsRepeat { nodes: (a, b, c) }))
} }
pub fn rs_case(s: Span) -> IResult<Span, RsCase> { pub fn rs_case(s: Span) -> IResult<Span, RsCase> {
let (s, _) = symbol("case")(s)?; let (s, a) = symbol("case")(s)?;
let (s, x) = paren(case_expression)(s)?; let (s, b) = paren2(case_expression)(s)?;
let (s, y) = many1(rs_case_item)(s)?; let (s, c) = rs_case_item(s)?;
Ok((s, RsCase { nodes: (x, y) })) let (s, d) = many0(rs_case_item)(s)?;
let (s, e) = symbol("endcase")(s)?;
Ok((
s,
RsCase {
nodes: (a, b, c, d, e),
},
))
} }
pub fn rs_case_item(s: Span) -> IResult<Span, RsCaseItem> { pub fn rs_case_item(s: Span) -> IResult<Span, RsCaseItem> {
@ -222,20 +292,27 @@ pub fn rs_case_item(s: Span) -> IResult<Span, RsCaseItem> {
} }
pub fn rs_case_item_nondefault(s: Span) -> IResult<Span, RsCaseItem> { pub fn rs_case_item_nondefault(s: Span) -> IResult<Span, RsCaseItem> {
let (s, x) = separated_nonempty_list(symbol(","), case_item_expression)(s)?; let (s, a) = list(symbol(","), case_item_expression)(s)?;
let (s, _) = symbol(":")(s)?; let (s, b) = symbol(":")(s)?;
let (s, y) = production_item(s)?; let (s, c) = production_item(s)?;
let (s, _) = symbol(";")(s)?; let (s, d) = symbol(";")(s)?;
Ok(( Ok((
s, s,
RsCaseItem::NonDefault(RsCaseItemNondefault { nodes: (x, y) }), RsCaseItem::NonDefault(RsCaseItemNondefault {
nodes: (a, b, c, d),
}),
)) ))
} }
pub fn rs_case_item_default(s: Span) -> IResult<Span, RsCaseItem> { pub fn rs_case_item_default(s: Span) -> IResult<Span, RsCaseItem> {
let (s, _) = symbol("default")(s)?; let (s, a) = symbol("default")(s)?;
let (s, _) = opt(symbol(":"))(s)?; let (s, b) = opt(symbol(":"))(s)?;
let (s, x) = production_item(s)?; let (s, c) = production_item(s)?;
let (s, _) = symbol(";")(s)?; let (s, d) = symbol(";")(s)?;
Ok((s, RsCaseItem::Default(RsCaseItemDefault { nodes: (x,) }))) Ok((
s,
RsCaseItem::Default(RsCaseItemDefault {
nodes: (a, b, c, d),
}),
))
} }