Refactoring
This commit is contained in:
parent
c06ff35e87
commit
8dda1ab3de
@ -55,9 +55,9 @@ A parser library for System Verilog.
|
||||
| behavioral_statements | patterns | x | x | |
|
||||
| behavioral_statements | looping_statements | x | x | |
|
||||
| behavioral_statements | subroutine_call_statements | x | x | |
|
||||
| behavioral_statements | assertion_statements | | | |
|
||||
| behavioral_statements | clocking_block | | | |
|
||||
| behavioral_statements | randsequence | | | |
|
||||
| behavioral_statements | assertion_statements | x | x | |
|
||||
| behavioral_statements | clocking_block | x | x | |
|
||||
| behavioral_statements | randsequence | x | x | |
|
||||
| specify_section | specify_block_declaration | | | |
|
||||
| specify_section | specify_path_declarations | | | |
|
||||
| specify_section | specify_block_terminals | | | |
|
||||
|
@ -1,3 +1,4 @@
|
||||
use crate::ast::*;
|
||||
use crate::parser::*;
|
||||
use nom::branch::*;
|
||||
use nom::combinator::*;
|
||||
@ -15,7 +16,7 @@ pub enum AssertionItem<'a> {
|
||||
#[derive(Debug)]
|
||||
pub struct DeferredImmediateAssetionItem<'a> {
|
||||
pub nodes: (
|
||||
Option<BlockIdentifier<'a>>,
|
||||
Option<(BlockIdentifier<'a>, Symbol<'a>)>,
|
||||
DeferredImmediateAssertionStatement<'a>,
|
||||
),
|
||||
}
|
||||
@ -42,17 +43,17 @@ pub enum SimpleImmediateAssertionStatement<'a> {
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct SimpleImmediateAssertStatement<'a> {
|
||||
pub nodes: (Expression<'a>, ActionBlock<'a>),
|
||||
pub nodes: (Symbol<'a>, Paren<'a, Expression<'a>>, ActionBlock<'a>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct SimpleImmediateAssumeStatement<'a> {
|
||||
pub nodes: (Expression<'a>, ActionBlock<'a>),
|
||||
pub nodes: (Symbol<'a>, Paren<'a, Expression<'a>>, ActionBlock<'a>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct SimpleImmediateCoverStatement<'a> {
|
||||
pub nodes: (Expression<'a>, StatementOrNull<'a>),
|
||||
pub nodes: (Symbol<'a>, Paren<'a, Expression<'a>>, StatementOrNull<'a>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@ -64,23 +65,38 @@ pub enum DeferredImmediateAssertionStatement<'a> {
|
||||
|
||||
#[derive(Debug)]
|
||||
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)]
|
||||
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)]
|
||||
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)]
|
||||
pub enum AssertTiming {
|
||||
Zero,
|
||||
Final,
|
||||
#[derive(Debug, Node)]
|
||||
pub enum AssertTiming<'a> {
|
||||
Zero(Symbol<'a>),
|
||||
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> {
|
||||
let (s, x) = opt(terminated(block_identifier, symbol(":")))(s)?;
|
||||
let (s, y) = deferred_immediate_assertion_statement(s)?;
|
||||
Ok((s, DeferredImmediateAssetionItem { nodes: (x, y) }))
|
||||
let (s, a) = opt(pair(block_identifier, symbol(":")))(s)?;
|
||||
let (s, b) = deferred_immediate_assertion_statement(s)?;
|
||||
Ok((s, DeferredImmediateAssetionItem { nodes: (a, b) }))
|
||||
}
|
||||
|
||||
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> {
|
||||
let (s, _) = symbol("assert")(s)?;
|
||||
let (s, _) = symbol("(")(s)?;
|
||||
let (s, x) = expression(s)?;
|
||||
let (s, _) = symbol(")")(s)?;
|
||||
let (s, y) = action_block(s)?;
|
||||
Ok((s, SimpleImmediateAssertStatement { nodes: (x, y) }))
|
||||
let (s, a) = symbol("assert")(s)?;
|
||||
let (s, b) = paren2(expression)(s)?;
|
||||
let (s, c) = action_block(s)?;
|
||||
Ok((s, SimpleImmediateAssertStatement { nodes: (a, b, c) }))
|
||||
}
|
||||
|
||||
pub fn simple_immediate_assume_statement(s: Span) -> IResult<Span, SimpleImmediateAssumeStatement> {
|
||||
let (s, _) = symbol("assume")(s)?;
|
||||
let (s, _) = symbol("(")(s)?;
|
||||
let (s, x) = expression(s)?;
|
||||
let (s, _) = symbol(")")(s)?;
|
||||
let (s, y) = action_block(s)?;
|
||||
Ok((s, SimpleImmediateAssumeStatement { nodes: (x, y) }))
|
||||
let (s, a) = symbol("assume")(s)?;
|
||||
let (s, b) = paren2(expression)(s)?;
|
||||
let (s, c) = action_block(s)?;
|
||||
Ok((s, SimpleImmediateAssumeStatement { nodes: (a, b, c) }))
|
||||
}
|
||||
|
||||
pub fn simple_immediate_cover_statement(s: Span) -> IResult<Span, SimpleImmediateCoverStatement> {
|
||||
let (s, _) = symbol("cover")(s)?;
|
||||
let (s, _) = symbol("(")(s)?;
|
||||
let (s, x) = expression(s)?;
|
||||
let (s, _) = symbol(")")(s)?;
|
||||
let (s, y) = statement_or_null(s)?;
|
||||
Ok((s, SimpleImmediateCoverStatement { nodes: (x, y) }))
|
||||
let (s, a) = symbol("cover")(s)?;
|
||||
let (s, b) = paren2(expression)(s)?;
|
||||
let (s, c) = statement_or_null(s)?;
|
||||
Ok((s, SimpleImmediateCoverStatement { nodes: (a, b, c) }))
|
||||
}
|
||||
|
||||
pub fn deferred_immediate_assertion_statement(
|
||||
@ -187,43 +197,52 @@ pub fn deferred_immediate_assertion_statement(
|
||||
pub fn deferred_immediate_assert_statement(
|
||||
s: Span,
|
||||
) -> IResult<Span, DeferredImmediateAssertStatement> {
|
||||
let (s, _) = symbol("assert")(s)?;
|
||||
let (s, x) = assert_timing(s)?;
|
||||
let (s, _) = symbol("(")(s)?;
|
||||
let (s, y) = expression(s)?;
|
||||
let (s, _) = symbol(")")(s)?;
|
||||
let (s, z) = action_block(s)?;
|
||||
Ok((s, DeferredImmediateAssertStatement { nodes: (x, y, z) }))
|
||||
let (s, a) = symbol("assert")(s)?;
|
||||
let (s, b) = assert_timing(s)?;
|
||||
let (s, c) = paren2(expression)(s)?;
|
||||
let (s, d) = action_block(s)?;
|
||||
Ok((
|
||||
s,
|
||||
DeferredImmediateAssertStatement {
|
||||
nodes: (a, b, c, d),
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
pub fn deferred_immediate_assume_statement(
|
||||
s: Span,
|
||||
) -> IResult<Span, DeferredImmediateAssumeStatement> {
|
||||
let (s, _) = symbol("assume")(s)?;
|
||||
let (s, x) = assert_timing(s)?;
|
||||
let (s, _) = symbol("(")(s)?;
|
||||
let (s, y) = expression(s)?;
|
||||
let (s, _) = symbol(")")(s)?;
|
||||
let (s, z) = action_block(s)?;
|
||||
Ok((s, DeferredImmediateAssumeStatement { nodes: (x, y, z) }))
|
||||
let (s, a) = symbol("assume")(s)?;
|
||||
let (s, b) = assert_timing(s)?;
|
||||
let (s, c) = paren2(expression)(s)?;
|
||||
let (s, d) = action_block(s)?;
|
||||
Ok((
|
||||
s,
|
||||
DeferredImmediateAssumeStatement {
|
||||
nodes: (a, b, c, d),
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
pub fn deferred_immediate_cover_statement(
|
||||
s: Span,
|
||||
) -> IResult<Span, DeferredImmediateCoverStatement> {
|
||||
let (s, _) = symbol("cover")(s)?;
|
||||
let (s, x) = assert_timing(s)?;
|
||||
let (s, _) = symbol("(")(s)?;
|
||||
let (s, y) = expression(s)?;
|
||||
let (s, _) = symbol(")")(s)?;
|
||||
let (s, z) = statement_or_null(s)?;
|
||||
Ok((s, DeferredImmediateCoverStatement { nodes: (x, y, z) }))
|
||||
let (s, a) = symbol("cover")(s)?;
|
||||
let (s, b) = assert_timing(s)?;
|
||||
let (s, c) = paren2(expression)(s)?;
|
||||
let (s, d) = statement_or_null(s)?;
|
||||
Ok((
|
||||
s,
|
||||
DeferredImmediateCoverStatement {
|
||||
nodes: (a, b, c, d),
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
pub fn assert_timing(s: Span) -> IResult<Span, AssertTiming> {
|
||||
alt((
|
||||
map(symbol("#0"), |_| AssertTiming::Zero),
|
||||
map(symbol("final"), |_| AssertTiming::Final),
|
||||
map(symbol("#0"), |x| AssertTiming::Zero(x)),
|
||||
map(symbol("final"), |x| AssertTiming::Final(x)),
|
||||
))(s)
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
use crate::ast::*;
|
||||
use crate::parser::*;
|
||||
use nom::branch::*;
|
||||
use nom::combinator::*;
|
||||
@ -16,42 +17,70 @@ pub enum ClockingDeclaration<'a> {
|
||||
#[derive(Debug)]
|
||||
pub struct ClockingDeclarationLocal<'a> {
|
||||
pub nodes: (
|
||||
Option<Default>,
|
||||
Option<Default<'a>>,
|
||||
Symbol<'a>,
|
||||
Option<ClockingIdentifier<'a>>,
|
||||
ClockingEvent<'a>,
|
||||
Symbol<'a>,
|
||||
Vec<ClockingItem<'a>>,
|
||||
Option<ClockingIdentifier<'a>>,
|
||||
Symbol<'a>,
|
||||
Option<(Symbol<'a>, ClockingIdentifier<'a>)>,
|
||||
),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Default {}
|
||||
#[derive(Debug, Node)]
|
||||
pub struct Default<'a> {
|
||||
pub nodes: (Symbol<'a>,),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ClockingDeclarationGlobal<'a> {
|
||||
pub nodes: (
|
||||
Symbol<'a>,
|
||||
Symbol<'a>,
|
||||
Option<ClockingIdentifier<'a>>,
|
||||
ClockingEvent<'a>,
|
||||
Option<ClockingIdentifier<'a>>,
|
||||
Symbol<'a>,
|
||||
Symbol<'a>,
|
||||
Option<(Symbol<'a>, ClockingIdentifier<'a>)>,
|
||||
),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum ClockingEvent<'a> {
|
||||
Identifier(Identifier<'a>),
|
||||
Expression(EventExpression<'a>),
|
||||
Identifier(ClockingEventIdentifier<'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)]
|
||||
pub enum ClockingItem<'a> {
|
||||
DefaultSkew(DefaultSkew<'a>),
|
||||
Default(ClockingItemDefault<'a>),
|
||||
Direction(ClockingItemDirection<'a>),
|
||||
Assertion(ClockingItemAssertion<'a>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ClockingItemDefault<'a> {
|
||||
pub nodes: (Symbol<'a>, DefaultSkew<'a>, Symbol<'a>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ClockingItemDirection<'a> {
|
||||
pub nodes: (ClockingDirection<'a>, Vec<ClockingDeclAssign<'a>>),
|
||||
pub nodes: (
|
||||
ClockingDirection<'a>,
|
||||
ListOfClockingDeclAssign<'a>,
|
||||
Symbol<'a>,
|
||||
),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@ -61,34 +90,80 @@ pub struct ClockingItemAssertion<'a> {
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum DefaultSkew<'a> {
|
||||
Input(ClockingSkew<'a>),
|
||||
Output(ClockingSkew<'a>),
|
||||
InputOutput((ClockingSkew<'a>, ClockingSkew<'a>)),
|
||||
Input(DefaultSkewInput<'a>),
|
||||
Output(DefaultSkewOutput<'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)]
|
||||
pub enum ClockingDirection<'a> {
|
||||
Input(Option<ClockingSkew<'a>>),
|
||||
Output(Option<ClockingSkew<'a>>),
|
||||
InputOutput((Option<ClockingSkew<'a>>, Option<ClockingSkew<'a>>)),
|
||||
Inout,
|
||||
Input(ClockingDirectionInput<'a>),
|
||||
Output(ClockingDirectionOutput<'a>),
|
||||
InputOutput(ClockingDirectionInputOutput<'a>),
|
||||
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)]
|
||||
pub struct ClockingDeclAssign<'a> {
|
||||
pub nodes: (SignalIdentifier<'a>, Option<Expression<'a>>),
|
||||
pub nodes: (SignalIdentifier<'a>, Option<(Symbol<'a>, Expression<'a>)>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum ClockingSkew<'a> {
|
||||
Edge((EdgeIdentifier<'a>, Option<DelayControl<'a>>)),
|
||||
Delay(DelayControl<'a>),
|
||||
Edge(ClockingSkewEdge<'a>),
|
||||
DelayControl(DelayControl<'a>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ClockingSkewEdge<'a> {
|
||||
pub nodes: (EdgeIdentifier<'a>, Option<DelayControl<'a>>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ClockingDrive<'a> {
|
||||
pub nodes: (
|
||||
(HierarchicalIdentifier<'a>, Select<'a>),
|
||||
ClockvarExpression<'a>,
|
||||
Symbol<'a>,
|
||||
Option<CycleDelay<'a>>,
|
||||
Expression<'a>,
|
||||
),
|
||||
@ -96,11 +171,35 @@ pub struct ClockingDrive<'a> {
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum CycleDelay<'a> {
|
||||
IntegralNumber(IntegralNumber<'a>),
|
||||
Identifier(Identifier<'a>),
|
||||
Expression(Expression<'a>),
|
||||
Integral(CycleDelayIntegral<'a>),
|
||||
Identifier(CycleDelayIdentifier<'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> {
|
||||
@ -108,77 +207,99 @@ pub fn clocking_declaration(s: Span) -> IResult<Span, ClockingDeclaration> {
|
||||
}
|
||||
|
||||
pub fn clocking_declaration_local(s: Span) -> IResult<Span, ClockingDeclaration> {
|
||||
let (s, x) = opt(symbol("default"))(s)?;
|
||||
let (s, _) = symbol("clocking")(s)?;
|
||||
let (s, y) = opt(clocking_identifier)(s)?;
|
||||
let (s, z) = clocking_event(s)?;
|
||||
let (s, _) = symbol(";")(s)?;
|
||||
let (s, v) = many0(clocking_item)(s)?;
|
||||
let (s, _) = symbol("endclocking")(s)?;
|
||||
let (s, w) = opt(preceded(symbol(":"), clocking_identifier))(s)?;
|
||||
let (s, a) = opt(default)(s)?;
|
||||
let (s, b) = symbol("clocking")(s)?;
|
||||
let (s, c) = opt(clocking_identifier)(s)?;
|
||||
let (s, d) = clocking_event(s)?;
|
||||
let (s, e) = symbol(";")(s)?;
|
||||
let (s, f) = many0(clocking_item)(s)?;
|
||||
let (s, g) = symbol("endclocking")(s)?;
|
||||
let (s, h) = opt(pair(symbol(":"), clocking_identifier))(s)?;
|
||||
Ok((
|
||||
s,
|
||||
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> {
|
||||
let (s, _) = opt(symbol("global"))(s)?;
|
||||
let (s, _) = symbol("clocking")(s)?;
|
||||
let (s, x) = opt(clocking_identifier)(s)?;
|
||||
let (s, y) = clocking_event(s)?;
|
||||
let (s, _) = symbol(";")(s)?;
|
||||
let (s, _) = symbol("endclocking")(s)?;
|
||||
let (s, z) = opt(preceded(symbol(":"), clocking_identifier))(s)?;
|
||||
let (s, a) = symbol("global")(s)?;
|
||||
let (s, b) = symbol("clocking")(s)?;
|
||||
let (s, c) = opt(clocking_identifier)(s)?;
|
||||
let (s, d) = clocking_event(s)?;
|
||||
let (s, e) = symbol(";")(s)?;
|
||||
let (s, f) = symbol("endclocking")(s)?;
|
||||
let (s, g) = opt(pair(symbol(":"), clocking_identifier))(s)?;
|
||||
Ok((
|
||||
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> {
|
||||
alt((
|
||||
map(preceded(symbol("@"), identifier), |x| {
|
||||
ClockingEvent::Identifier(x)
|
||||
}),
|
||||
map(preceded(symbol("@"), paren(event_expression)), |x| {
|
||||
ClockingEvent::Expression(x)
|
||||
}),
|
||||
))(s)
|
||||
alt((clocking_event_identifier, clocking_event_expression))(s)
|
||||
}
|
||||
|
||||
pub fn clocking_event_identifier(s: Span) -> IResult<Span, ClockingEvent> {
|
||||
let (s, a) = symbol("@")(s)?;
|
||||
let (s, b) = identifier(s)?;
|
||||
Ok((
|
||||
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> {
|
||||
alt((
|
||||
clocking_item_default_skew,
|
||||
clocking_item_default,
|
||||
clocking_item_direction,
|
||||
clocking_item_assertion,
|
||||
))(s)
|
||||
}
|
||||
|
||||
pub fn clocking_item_default_skew(s: Span) -> IResult<Span, ClockingItem> {
|
||||
let (s, _) = symbol("default")(s)?;
|
||||
let (s, x) = default_skew(s)?;
|
||||
let (s, _) = symbol(";")(s)?;
|
||||
Ok((s, ClockingItem::DefaultSkew(x)))
|
||||
pub fn clocking_item_default(s: Span) -> IResult<Span, ClockingItem> {
|
||||
let (s, a) = symbol("default")(s)?;
|
||||
let (s, b) = default_skew(s)?;
|
||||
let (s, c) = symbol(";")(s)?;
|
||||
Ok((
|
||||
s,
|
||||
ClockingItem::Default(ClockingItemDefault { nodes: (a, b, c) }),
|
||||
))
|
||||
}
|
||||
|
||||
pub fn clocking_item_direction(s: Span) -> IResult<Span, ClockingItem> {
|
||||
let (s, x) = clocking_direction(s)?;
|
||||
let (s, y) = list_of_clocking_decl_assign(s)?;
|
||||
let (s, a) = clocking_direction(s)?;
|
||||
let (s, b) = list_of_clocking_decl_assign(s)?;
|
||||
let (s, c) = symbol(";")(s)?;
|
||||
Ok((
|
||||
s,
|
||||
ClockingItem::Direction(ClockingItemDirection { nodes: (x, y) }),
|
||||
ClockingItem::Direction(ClockingItemDirection { nodes: (a, b, c) }),
|
||||
))
|
||||
}
|
||||
|
||||
pub fn clocking_item_assertion(s: Span) -> IResult<Span, ClockingItem> {
|
||||
let (s, x) = many0(attribute_instance)(s)?;
|
||||
let (s, y) = assertion_item_declaration(s)?;
|
||||
let (s, a) = many0(attribute_instance)(s)?;
|
||||
let (s, b) = assertion_item_declaration(s)?;
|
||||
Ok((
|
||||
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> {
|
||||
let (s, _) = symbol("input")(s)?;
|
||||
let (s, x) = clocking_skew(s)?;
|
||||
Ok((s, DefaultSkew::Input(x)))
|
||||
let (s, a) = symbol("input")(s)?;
|
||||
let (s, b) = clocking_skew(s)?;
|
||||
Ok((s, DefaultSkew::Input(DefaultSkewInput { nodes: (a, b) })))
|
||||
}
|
||||
|
||||
pub fn default_skew_output(s: Span) -> IResult<Span, DefaultSkew> {
|
||||
let (s, _) = symbol("output")(s)?;
|
||||
let (s, x) = clocking_skew(s)?;
|
||||
Ok((s, DefaultSkew::Output(x)))
|
||||
let (s, a) = symbol("output")(s)?;
|
||||
let (s, b) = clocking_skew(s)?;
|
||||
Ok((s, DefaultSkew::Output(DefaultSkewOutput { nodes: (a, b) })))
|
||||
}
|
||||
|
||||
pub fn default_skew_input_output(s: Span) -> IResult<Span, DefaultSkew> {
|
||||
let (s, _) = symbol("input")(s)?;
|
||||
let (s, x) = clocking_skew(s)?;
|
||||
let (s, _) = symbol("output")(s)?;
|
||||
let (s, y) = clocking_skew(s)?;
|
||||
Ok((s, DefaultSkew::InputOutput((x, y))))
|
||||
let (s, a) = symbol("input")(s)?;
|
||||
let (s, b) = clocking_skew(s)?;
|
||||
let (s, c) = symbol("output")(s)?;
|
||||
let (s, d) = clocking_skew(s)?;
|
||||
Ok((
|
||||
s,
|
||||
DefaultSkew::InputOutput(DefaultSkewInputOutput {
|
||||
nodes: (a, b, c, d),
|
||||
}),
|
||||
))
|
||||
}
|
||||
|
||||
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> {
|
||||
let (s, _) = symbol("input")(s)?;
|
||||
let (s, x) = opt(clocking_skew)(s)?;
|
||||
Ok((s, ClockingDirection::Input(x)))
|
||||
let (s, a) = symbol("input")(s)?;
|
||||
let (s, b) = opt(clocking_skew)(s)?;
|
||||
Ok((
|
||||
s,
|
||||
ClockingDirection::Input(ClockingDirectionInput { nodes: (a, b) }),
|
||||
))
|
||||
}
|
||||
|
||||
pub fn clocking_direction_output(s: Span) -> IResult<Span, ClockingDirection> {
|
||||
let (s, _) = symbol("output")(s)?;
|
||||
let (s, x) = opt(clocking_skew)(s)?;
|
||||
Ok((s, ClockingDirection::Output(x)))
|
||||
let (s, a) = symbol("output")(s)?;
|
||||
let (s, b) = opt(clocking_skew)(s)?;
|
||||
Ok((
|
||||
s,
|
||||
ClockingDirection::Output(ClockingDirectionOutput { nodes: (a, b) }),
|
||||
))
|
||||
}
|
||||
|
||||
pub fn clocking_direction_input_output(s: Span) -> IResult<Span, ClockingDirection> {
|
||||
let (s, _) = symbol("input")(s)?;
|
||||
let (s, x) = opt(clocking_skew)(s)?;
|
||||
let (s, _) = symbol("output")(s)?;
|
||||
let (s, y) = opt(clocking_skew)(s)?;
|
||||
Ok((s, ClockingDirection::InputOutput((x, y))))
|
||||
let (s, a) = symbol("input")(s)?;
|
||||
let (s, b) = opt(clocking_skew)(s)?;
|
||||
let (s, c) = symbol("output")(s)?;
|
||||
let (s, d) = opt(clocking_skew)(s)?;
|
||||
Ok((
|
||||
s,
|
||||
ClockingDirection::InputOutput(ClockingDirectionInputOutput {
|
||||
nodes: (a, b, c, d),
|
||||
}),
|
||||
))
|
||||
}
|
||||
|
||||
pub fn clocking_direction_inout(s: Span) -> IResult<Span, ClockingDirection> {
|
||||
let (s, _) = symbol("inout")(s)?;
|
||||
Ok((s, ClockingDirection::Inout))
|
||||
let (s, a) = symbol("inout")(s)?;
|
||||
Ok((s, ClockingDirection::Inout(a)))
|
||||
}
|
||||
|
||||
pub fn list_of_clocking_decl_assign(s: Span) -> IResult<Span, Vec<ClockingDeclAssign>> {
|
||||
many1(clocking_decl_assign)(s)
|
||||
pub fn list_of_clocking_decl_assign(s: Span) -> IResult<Span, ListOfClockingDeclAssign> {
|
||||
let (s, a) = list(symbol(","), clocking_decl_assign)(s)?;
|
||||
Ok((s, ListOfClockingDeclAssign { nodes: (a,) }))
|
||||
}
|
||||
|
||||
pub fn clocking_decl_assign(s: Span) -> IResult<Span, ClockingDeclAssign> {
|
||||
let (s, x) = signal_identifier(s)?;
|
||||
let (s, y) = opt(preceded(symbol("="), expression))(s)?;
|
||||
Ok((s, ClockingDeclAssign { nodes: (x, y) }))
|
||||
let (s, a) = signal_identifier(s)?;
|
||||
let (s, b) = opt(pair(symbol("="), expression))(s)?;
|
||||
Ok((s, ClockingDeclAssign { nodes: (a, b) }))
|
||||
}
|
||||
|
||||
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> {
|
||||
let (s, x) = edge_identifier(s)?;
|
||||
let (s, y) = opt(delay_control)(s)?;
|
||||
Ok((s, ClockingSkew::Edge((x, y))))
|
||||
}
|
||||
|
||||
pub fn clocking_skew_delay(s: Span) -> IResult<Span, ClockingSkew> {
|
||||
let (s, x) = delay_control(s)?;
|
||||
Ok((s, ClockingSkew::Delay(x)))
|
||||
let (s, a) = edge_identifier(s)?;
|
||||
let (s, b) = opt(delay_control)(s)?;
|
||||
Ok((s, ClockingSkew::Edge(ClockingSkewEdge { nodes: (a, b) })))
|
||||
}
|
||||
|
||||
pub fn clocking_drive(s: Span) -> IResult<Span, ClockingDrive> {
|
||||
let (s, x) = clockvar_expression(s)?;
|
||||
let (s, _) = symbol("=")(s)?;
|
||||
let (s, y) = opt(cycle_delay)(s)?;
|
||||
let (s, z) = expression(s)?;
|
||||
Ok((s, ClockingDrive { nodes: (x, y, z) }))
|
||||
let (s, a) = clockvar_expression(s)?;
|
||||
let (s, b) = symbol("<=")(s)?;
|
||||
let (s, c) = opt(cycle_delay)(s)?;
|
||||
let (s, d) = expression(s)?;
|
||||
Ok((
|
||||
s,
|
||||
ClockingDrive {
|
||||
nodes: (a, b, c, d),
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
pub fn cycle_delay(s: Span) -> IResult<Span, CycleDelay> {
|
||||
alt((
|
||||
map(preceded(symbol("##"), integral_number), |x| {
|
||||
CycleDelay::IntegralNumber(x)
|
||||
}),
|
||||
map(preceded(symbol("##"), identifier), |x| {
|
||||
CycleDelay::Identifier(x)
|
||||
}),
|
||||
map(preceded(symbol("##"), paren(expression)), |x| {
|
||||
CycleDelay::Expression(x)
|
||||
}),
|
||||
cycle_delay_integral,
|
||||
cycle_delay_identifier,
|
||||
cycle_delay_expression,
|
||||
))(s)
|
||||
}
|
||||
|
||||
pub fn clockvar(s: Span) -> IResult<Span, HierarchicalIdentifier> {
|
||||
hierarchical_identifier(s)
|
||||
pub fn cycle_delay_integral(s: Span) -> IResult<Span, CycleDelay> {
|
||||
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)> {
|
||||
pair(clockvar, select)(s)
|
||||
pub fn cycle_delay_identifier(s: Span) -> IResult<Span, CycleDelay> {
|
||||
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) }))
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
@ -9,7 +9,13 @@ use nom::IResult;
|
||||
|
||||
#[derive(Debug)]
|
||||
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)]
|
||||
@ -17,8 +23,10 @@ pub struct Production<'a> {
|
||||
pub nodes: (
|
||||
Option<DataTypeOrVoid<'a>>,
|
||||
ProductionIdentifier<'a>,
|
||||
Option<TfPortList<'a>>,
|
||||
Vec<RsRule<'a>>,
|
||||
Option<Paren<'a, TfPortList<'a>>>,
|
||||
Symbol<'a>,
|
||||
List<Symbol<'a>, RsRule<'a>>,
|
||||
Symbol<'a>,
|
||||
),
|
||||
}
|
||||
|
||||
@ -26,60 +34,91 @@ pub struct Production<'a> {
|
||||
pub struct RsRule<'a> {
|
||||
pub nodes: (
|
||||
RsProductionList<'a>,
|
||||
Option<WeightSpecification<'a>>,
|
||||
Option<RsCodeBlock<'a>>,
|
||||
Option<(Symbol<'a>, WeightSpecification<'a>, Option<RsCodeBlock<'a>>)>,
|
||||
),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum RsProductionList<'a> {
|
||||
Prod(Vec<RsProd<'a>>),
|
||||
Join((Option<Expression<'a>>, Vec<ProductionItem<'a>>)),
|
||||
Prod(RsProductionListProd<'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)]
|
||||
pub enum WeightSpecification<'a> {
|
||||
IntegralNumber(IntegralNumber<'a>),
|
||||
PsIdentifier(PsIdentifier<'a>),
|
||||
Expression(Expression<'a>),
|
||||
Expression(WeightSpecificationExpression<'a>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct WeightSpecificationExpression<'a> {
|
||||
pub nodes: (Paren<'a, Expression<'a>>,),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct RsCodeBlock<'a> {
|
||||
pub nodes: (Vec<DataDeclaration<'a>>, Vec<StatementOrNull<'a>>),
|
||||
pub nodes: (Brace<'a, (Vec<DataDeclaration<'a>>, Vec<StatementOrNull<'a>>)>,),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum RsProd<'a> {
|
||||
Item(ProductionItem<'a>),
|
||||
CodeBlock(RsCodeBlock<'a>),
|
||||
IfElse(RsIfElse<'a>),
|
||||
Repeat(RsRepeat<'a>),
|
||||
Case(RsCase<'a>),
|
||||
ProductionItem(ProductionItem<'a>),
|
||||
RsCodeBlock(RsCodeBlock<'a>),
|
||||
RsIfElse(RsIfElse<'a>),
|
||||
RsRepeat(RsRepeat<'a>),
|
||||
RsCase(RsCase<'a>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ProductionItem<'a> {
|
||||
pub nodes: (ProductionIdentifier<'a>, Option<ListOfArguments<'a>>),
|
||||
pub nodes: (
|
||||
ProductionIdentifier<'a>,
|
||||
Option<Paren<'a, ListOfArguments<'a>>>,
|
||||
),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct RsIfElse<'a> {
|
||||
pub nodes: (
|
||||
Expression<'a>,
|
||||
Symbol<'a>,
|
||||
Paren<'a, Expression<'a>>,
|
||||
ProductionItem<'a>,
|
||||
Option<ProductionItem<'a>>,
|
||||
Option<(Symbol<'a>, ProductionItem<'a>)>,
|
||||
),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct RsRepeat<'a> {
|
||||
pub nodes: (Expression<'a>, ProductionItem<'a>),
|
||||
pub nodes: (Symbol<'a>, Paren<'a, Expression<'a>>, ProductionItem<'a>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
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)]
|
||||
@ -89,55 +128,64 @@ pub enum RsCaseItem<'a> {
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct RsCaseItemDefault<'a> {
|
||||
pub nodes: (ProductionItem<'a>,),
|
||||
pub struct RsCaseItemNondefault<'a> {
|
||||
pub nodes: (
|
||||
List<Symbol<'a>, CaseItemExpression<'a>>,
|
||||
Symbol<'a>,
|
||||
ProductionItem<'a>,
|
||||
Symbol<'a>,
|
||||
),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct RsCaseItemNondefault<'a> {
|
||||
pub nodes: (Vec<CaseItemExpression<'a>>, ProductionItem<'a>),
|
||||
pub struct RsCaseItemDefault<'a> {
|
||||
pub nodes: (
|
||||
Symbol<'a>,
|
||||
Option<Symbol<'a>>,
|
||||
ProductionItem<'a>,
|
||||
Symbol<'a>,
|
||||
),
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
pub fn randsequence_statement(s: Span) -> IResult<Span, RandsequenceStatement> {
|
||||
let (s, _) = symbol("randsequence")(s)?;
|
||||
let (s, _) = symbol("(")(s)?;
|
||||
let (s, x) = opt(production_identifier)(s)?;
|
||||
let (s, _) = symbol(")")(s)?;
|
||||
let (s, y) = many1(production)(s)?;
|
||||
let (s, _) = symbol("endsequence")(s)?;
|
||||
Ok((s, RandsequenceStatement { nodes: (x, y) }))
|
||||
let (s, a) = symbol("randsequence")(s)?;
|
||||
let (s, b) = paren2(opt(production_identifier))(s)?;
|
||||
let (s, c) = production(s)?;
|
||||
let (s, d) = many0(production)(s)?;
|
||||
let (s, e) = symbol("endsequence")(s)?;
|
||||
Ok((
|
||||
s,
|
||||
RandsequenceStatement {
|
||||
nodes: (a, b, c, d, e),
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
pub fn production(s: Span) -> IResult<Span, Production> {
|
||||
let (s, x) = opt(data_type_or_void)(s)?;
|
||||
let (s, y) = production_identifier(s)?;
|
||||
let (s, z) = opt(paren(tf_port_list))(s)?;
|
||||
let (s, _) = symbol(":")(s)?;
|
||||
let (s, v) = separated_nonempty_list(symbol("|"), rs_rule)(s)?;
|
||||
let (s, _) = symbol(";")(s)?;
|
||||
let (s, a) = opt(data_type_or_void)(s)?;
|
||||
let (s, b) = production_identifier(s)?;
|
||||
let (s, c) = opt(paren2(tf_port_list))(s)?;
|
||||
let (s, d) = symbol(":")(s)?;
|
||||
let (s, e) = list(symbol("|"), rs_rule)(s)?;
|
||||
let (s, f) = symbol(";")(s)?;
|
||||
Ok((
|
||||
s,
|
||||
Production {
|
||||
nodes: (x, y, z, v),
|
||||
nodes: (a, b, c, d, e, f),
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
pub fn rs_rule(s: Span) -> IResult<Span, RsRule> {
|
||||
let (s, x) = rs_production_list(s)?;
|
||||
let (s, y) = opt(preceded(
|
||||
let (s, a) = rs_production_list(s)?;
|
||||
let (s, b) = opt(triple(
|
||||
symbol(":="),
|
||||
pair(weight_specification, opt(rs_code_block)),
|
||||
weight_specification,
|
||||
opt(rs_code_block),
|
||||
))(s)?;
|
||||
|
||||
let (y, z) = if let Some((y, z)) = y {
|
||||
(Some(y), z)
|
||||
} else {
|
||||
(None, None)
|
||||
};
|
||||
Ok((s, RsRule { nodes: (x, y, z) }))
|
||||
Ok((s, RsRule { nodes: (a, b) }))
|
||||
}
|
||||
|
||||
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> {
|
||||
let (s, x) = many1(rs_prod)(s)?;
|
||||
Ok((s, RsProductionList::Prod(x)))
|
||||
let (s, a) = rs_prod(s)?;
|
||||
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> {
|
||||
let (s, _) = symbol("rand")(s)?;
|
||||
let (s, _) = symbol("join")(s)?;
|
||||
let (s, x) = opt(paren(expression))(s)?;
|
||||
let (s, y) = production_item(s)?;
|
||||
let (s, z) = many1(production_item)(s)?;
|
||||
|
||||
let mut y = vec![y];
|
||||
for z in z {
|
||||
y.push(z);
|
||||
}
|
||||
Ok((s, RsProductionList::Join((x, y))))
|
||||
let (s, a) = symbol("rand")(s)?;
|
||||
let (s, b) = symbol("join")(s)?;
|
||||
let (s, c) = opt(paren2(expression))(s)?;
|
||||
let (s, d) = production_item(s)?;
|
||||
let (s, e) = production_item(s)?;
|
||||
let (s, f) = many0(production_item)(s)?;
|
||||
Ok((
|
||||
s,
|
||||
RsProductionList::Join(RsProductionListJoin {
|
||||
nodes: (a, b, c, d, e, f),
|
||||
}),
|
||||
))
|
||||
}
|
||||
|
||||
pub fn weight_specification(s: Span) -> IResult<Span, WeightSpecification> {
|
||||
alt((
|
||||
map(integral_number, |x| WeightSpecification::IntegralNumber(x)),
|
||||
map(ps_identifier, |x| WeightSpecification::PsIdentifier(x)),
|
||||
map(paren(expression), |x| WeightSpecification::Expression(x)),
|
||||
weight_specification_expression,
|
||||
))(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> {
|
||||
let (s, _) = symbol("{")(s)?;
|
||||
let (s, x) = many0(data_declaration)(s)?;
|
||||
let (s, y) = many0(statement_or_null)(s)?;
|
||||
let (s, _) = symbol("}")(s)?;
|
||||
Ok((s, RsCodeBlock { nodes: (x, y) }))
|
||||
let (s, a) = brace2(pair(many0(data_declaration), many0(statement_or_null)))(s)?;
|
||||
Ok((s, RsCodeBlock { nodes: (a,) }))
|
||||
}
|
||||
|
||||
pub fn rs_prod(s: Span) -> IResult<Span, RsProd> {
|
||||
alt((
|
||||
map(production_item, |x| RsProd::Item(x)),
|
||||
map(rs_code_block, |x| RsProd::CodeBlock(x)),
|
||||
map(rs_if_else, |x| RsProd::IfElse(x)),
|
||||
map(rs_repeat, |x| RsProd::Repeat(x)),
|
||||
map(rs_case, |x| RsProd::Case(x)),
|
||||
map(production_item, |x| RsProd::ProductionItem(x)),
|
||||
map(rs_code_block, |x| RsProd::RsCodeBlock(x)),
|
||||
map(rs_if_else, |x| RsProd::RsIfElse(x)),
|
||||
map(rs_repeat, |x| RsProd::RsRepeat(x)),
|
||||
map(rs_case, |x| RsProd::RsCase(x)),
|
||||
))(s)
|
||||
}
|
||||
|
||||
pub fn production_item(s: Span) -> IResult<Span, ProductionItem> {
|
||||
let (s, x) = production_identifier(s)?;
|
||||
let (s, y) = opt(paren(list_of_arguments))(s)?;
|
||||
Ok((s, ProductionItem { nodes: (x, y) }))
|
||||
let (s, a) = production_identifier(s)?;
|
||||
let (s, b) = opt(paren2(list_of_arguments))(s)?;
|
||||
Ok((s, ProductionItem { nodes: (a, b) }))
|
||||
}
|
||||
|
||||
pub fn rs_if_else(s: Span) -> IResult<Span, RsIfElse> {
|
||||
let (s, _) = symbol("if")(s)?;
|
||||
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 { nodes: (x, y, z) }))
|
||||
let (s, a) = symbol("if")(s)?;
|
||||
let (s, b) = paren2(expression)(s)?;
|
||||
let (s, c) = production_item(s)?;
|
||||
let (s, d) = opt(pair(symbol("else"), production_item))(s)?;
|
||||
Ok((
|
||||
s,
|
||||
RsIfElse {
|
||||
nodes: (a, b, c, d),
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
pub fn rs_repeat(s: Span) -> IResult<Span, RsRepeat> {
|
||||
let (s, _) = symbol("repeat")(s)?;
|
||||
let (s, x) = paren(expression)(s)?;
|
||||
let (s, y) = production_item(s)?;
|
||||
Ok((s, RsRepeat { nodes: (x, y) }))
|
||||
let (s, a) = symbol("repeat")(s)?;
|
||||
let (s, b) = paren2(expression)(s)?;
|
||||
let (s, c) = production_item(s)?;
|
||||
Ok((s, RsRepeat { nodes: (a, b, c) }))
|
||||
}
|
||||
|
||||
pub fn rs_case(s: Span) -> IResult<Span, RsCase> {
|
||||
let (s, _) = symbol("case")(s)?;
|
||||
let (s, x) = paren(case_expression)(s)?;
|
||||
let (s, y) = many1(rs_case_item)(s)?;
|
||||
Ok((s, RsCase { nodes: (x, y) }))
|
||||
let (s, a) = symbol("case")(s)?;
|
||||
let (s, b) = paren2(case_expression)(s)?;
|
||||
let (s, c) = rs_case_item(s)?;
|
||||
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> {
|
||||
@ -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> {
|
||||
let (s, x) = separated_nonempty_list(symbol(","), case_item_expression)(s)?;
|
||||
let (s, _) = symbol(":")(s)?;
|
||||
let (s, y) = production_item(s)?;
|
||||
let (s, _) = symbol(";")(s)?;
|
||||
let (s, a) = list(symbol(","), case_item_expression)(s)?;
|
||||
let (s, b) = symbol(":")(s)?;
|
||||
let (s, c) = production_item(s)?;
|
||||
let (s, d) = symbol(";")(s)?;
|
||||
Ok((
|
||||
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> {
|
||||
let (s, _) = symbol("default")(s)?;
|
||||
let (s, _) = opt(symbol(":"))(s)?;
|
||||
let (s, x) = production_item(s)?;
|
||||
let (s, _) = symbol(";")(s)?;
|
||||
Ok((s, RsCaseItem::Default(RsCaseItemDefault { nodes: (x,) })))
|
||||
let (s, a) = symbol("default")(s)?;
|
||||
let (s, b) = opt(symbol(":"))(s)?;
|
||||
let (s, c) = production_item(s)?;
|
||||
let (s, d) = symbol(";")(s)?;
|
||||
Ok((
|
||||
s,
|
||||
RsCaseItem::Default(RsCaseItemDefault {
|
||||
nodes: (a, b, c, d),
|
||||
}),
|
||||
))
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user