Add behavioral_statements

This commit is contained in:
dalance 2019-07-05 17:24:28 +09:00
parent 82372ee859
commit 317f18d845
18 changed files with 1901 additions and 589 deletions

View File

@ -0,0 +1,281 @@
use crate::parser::*;
use nom::branch::*;
use nom::combinator::*;
use nom::multi::*;
use nom::sequence::*;
use nom::IResult;
// -----------------------------------------------------------------------------
#[derive(Debug)]
pub enum CaseStatement<'a> {
Normal(CaseStatementNormal<'a>),
Matches(CaseStatementMatches<'a>),
Inside(CaseStatementInside<'a>),
}
#[derive(Debug)]
pub struct CaseStatementNormal<'a> {
pub unique_priority: Option<UniquePriority>,
pub keyword: CaseKeyword,
pub expression: Expression<'a>,
pub item: Vec<CaseItem<'a>>,
}
#[derive(Debug)]
pub struct CaseStatementMatches<'a> {
pub unique_priority: Option<UniquePriority>,
pub keyword: CaseKeyword,
pub expression: Expression<'a>,
pub item: Vec<CasePatternItem<'a>>,
}
#[derive(Debug)]
pub struct CaseStatementInside<'a> {
pub unique_priority: Option<UniquePriority>,
pub keyword: CaseKeyword,
pub expression: Expression<'a>,
pub item: Vec<CaseInsideItem<'a>>,
}
#[derive(Debug)]
pub enum CaseKeyword {
Case,
Casez,
Casex,
}
#[derive(Debug)]
pub enum CaseItem<'a> {
NonDefault(CaseItemNondefault<'a>),
Default(CaseItemDefault<'a>),
}
#[derive(Debug)]
pub enum CasePatternItem<'a> {
NonDefault(CasePatternItemNondefault<'a>),
Default(CaseItemDefault<'a>),
}
#[derive(Debug)]
pub enum CaseInsideItem<'a> {
NonDefault(CaseInsideItemNondefault<'a>),
Default(CaseItemDefault<'a>),
}
#[derive(Debug)]
pub struct CaseItemDefault<'a> {
pub statement: StatementOrNull<'a>,
}
#[derive(Debug)]
pub struct CaseItemNondefault<'a> {
pub expression: Vec<Expression<'a>>,
pub statement: StatementOrNull<'a>,
}
#[derive(Debug)]
pub struct CasePatternItemNondefault<'a> {
pub pattern: Pattern<'a>,
pub expression: Option<Expression<'a>>,
pub statement: StatementOrNull<'a>,
}
#[derive(Debug)]
pub struct CaseInsideItemNondefault<'a> {
pub open_range_list: Vec<ValueRange<'a>>,
pub statement: StatementOrNull<'a>,
}
#[derive(Debug)]
pub struct RandcaseStatement<'a> {
pub item: Vec<RandcaseItem<'a>>,
}
#[derive(Debug)]
pub struct RandcaseItem<'a> {
pub expression: Expression<'a>,
pub statement: StatementOrNull<'a>,
}
// -----------------------------------------------------------------------------
pub fn case_statement(s: &str) -> IResult<&str, CaseStatement> {
alt((
case_statement_normal,
case_statement_matches,
case_statement_inside,
))(s)
}
pub fn case_statement_normal(s: &str) -> IResult<&str, CaseStatement> {
let (s, x) = opt(unique_priority)(s)?;
let (s, y) = case_keyword(s)?;
let (s, _) = symbol("(")(s)?;
let (s, z) = case_expression(s)?;
let (s, _) = symbol(")")(s)?;
let (s, v) = many1(case_item)(s)?;
let (s, _) = symbol("endcase")(s)?;
Ok((
s,
CaseStatement::Normal(CaseStatementNormal {
unique_priority: x,
keyword: y,
expression: z,
item: v,
}),
))
}
pub fn case_statement_matches(s: &str) -> IResult<&str, CaseStatement> {
let (s, x) = opt(unique_priority)(s)?;
let (s, y) = case_keyword(s)?;
let (s, _) = symbol("(")(s)?;
let (s, z) = case_expression(s)?;
let (s, _) = symbol(")")(s)?;
let (s, _) = symbol("matches")(s)?;
let (s, v) = many1(case_pattern_item)(s)?;
let (s, _) = symbol("endcase")(s)?;
Ok((
s,
CaseStatement::Matches(CaseStatementMatches {
unique_priority: x,
keyword: y,
expression: z,
item: v,
}),
))
}
pub fn case_statement_inside(s: &str) -> IResult<&str, CaseStatement> {
let (s, x) = opt(unique_priority)(s)?;
let (s, y) = case_keyword(s)?;
let (s, _) = symbol("(")(s)?;
let (s, z) = case_expression(s)?;
let (s, _) = symbol(")")(s)?;
let (s, _) = symbol("inside")(s)?;
let (s, v) = many1(case_inside_item)(s)?;
let (s, _) = symbol("endcase")(s)?;
Ok((
s,
CaseStatement::Inside(CaseStatementInside {
unique_priority: x,
keyword: y,
expression: z,
item: v,
}),
))
}
pub fn case_keyword(s: &str) -> IResult<&str, CaseKeyword> {
alt((
map(symbol("casez"), |_| CaseKeyword::Casez),
map(symbol("casex"), |_| CaseKeyword::Casex),
map(symbol("case"), |_| CaseKeyword::Case),
))(s)
}
pub fn case_expression(s: &str) -> IResult<&str, Expression> {
expression(s)
}
pub fn case_item(s: &str) -> IResult<&str, CaseItem> {
alt((
case_item_nondefault,
map(case_item_default, |x| CaseItem::Default(x)),
))(s)
}
pub fn case_item_nondefault(s: &str) -> IResult<&str, CaseItem> {
let (s, x) = separated_nonempty_list(symbol(","), case_item_expression)(s)?;
let (s, _) = symbol(":")(s)?;
let (s, y) = statement_or_null(s)?;
Ok((
s,
CaseItem::NonDefault(CaseItemNondefault {
expression: x,
statement: y,
}),
))
}
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 }))
}
pub fn case_pattern_item(s: &str) -> IResult<&str, CasePatternItem> {
alt((
case_pattern_item_nondefault,
map(case_item_default, |x| CasePatternItem::Default(x)),
))(s)
}
pub fn case_pattern_item_nondefault(s: &str) -> IResult<&str, CasePatternItem> {
let (s, x) = pattern(s)?;
let (s, y) = opt(preceded(symbol("&&&"), expression))(s)?;
let (s, _) = symbol(":")(s)?;
let (s, z) = statement_or_null(s)?;
Ok((
s,
CasePatternItem::NonDefault(CasePatternItemNondefault {
pattern: x,
expression: y,
statement: z,
}),
))
}
pub fn case_inside_item(s: &str) -> IResult<&str, CaseInsideItem> {
alt((
case_inside_item_nondefault,
map(case_item_default, |x| CaseInsideItem::Default(x)),
))(s)
}
pub fn case_inside_item_nondefault(s: &str) -> IResult<&str, CaseInsideItem> {
let (s, x) = open_range_list(s)?;
let (s, _) = symbol(":")(s)?;
let (s, y) = statement_or_null(s)?;
Ok((
s,
CaseInsideItem::NonDefault(CaseInsideItemNondefault {
open_range_list: x,
statement: y,
}),
))
}
pub fn case_item_expression(s: &str) -> IResult<&str, Expression> {
expression(s)
}
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 }))
}
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,
},
))
}
pub fn open_range_list(s: &str) -> IResult<&str, Vec<ValueRange>> {
separated_nonempty_list(symbol(","), open_value_range)(s)
}
pub fn open_value_range(s: &str) -> IResult<&str, ValueRange> {
value_range(s)
}

View File

@ -0,0 +1,117 @@
use crate::parser::*;
use nom::branch::*;
use nom::combinator::*;
use nom::multi::*;
use nom::sequence::*;
use nom::IResult;
// -----------------------------------------------------------------------------
#[derive(Debug)]
pub struct ConditionalStatement<'a> {
pub unique_priority: Option<UniquePriority>,
pub if_statement: ConditionalStatementBody<'a>,
pub else_if_statement: Vec<ConditionalStatementBody<'a>>,
pub else_statement: Option<StatementOrNull<'a>>,
}
#[derive(Debug)]
pub enum UniquePriority {
Unique,
Unique0,
Priority,
}
#[derive(Debug)]
pub struct ConditionalStatementBody<'a> {
pub predicate: CondPredicate<'a>,
pub statement: StatementOrNull<'a>,
}
#[derive(Debug)]
pub struct CondPredicate<'a> {
pub pattern: Vec<ExpressionOrCondPattern<'a>>,
}
#[derive(Debug)]
pub enum ExpressionOrCondPattern<'a> {
Expression(Expression<'a>),
CondPattern(CondPattern<'a>),
}
#[derive(Debug)]
pub struct CondPattern<'a> {
pub expression: Expression<'a>,
pub pattern: Pattern<'a>,
}
// -----------------------------------------------------------------------------
pub fn conditional_statement(s: &str) -> IResult<&str, ConditionalStatement> {
let (s, x) = opt(unique_priority)(s)?;
let (s, _) = symbol("if")(s)?;
let (s, y) = conditional_statement_body(s)?;
let (s, z) = many0(preceded(
pair(symbol("else"), symbol("if")),
conditional_statement_body,
))(s)?;
let (s, v) = opt(preceded(symbol("else"), statement_or_null))(s)?;
Ok((
s,
ConditionalStatement {
unique_priority: x,
if_statement: y,
else_if_statement: z,
else_statement: v,
},
))
}
pub fn conditional_statement_body(s: &str) -> IResult<&str, ConditionalStatementBody> {
let (s, _) = symbol("(")(s)?;
let (s, x) = cond_predicate(s)?;
let (s, _) = symbol(")")(s)?;
let (s, y) = statement_or_null(s)?;
Ok((
s,
ConditionalStatementBody {
predicate: x,
statement: y,
},
))
}
pub fn unique_priority(s: &str) -> IResult<&str, UniquePriority> {
alt((
map(symbol("unique0"), |_| UniquePriority::Unique0),
map(symbol("unique"), |_| UniquePriority::Unique),
map(symbol("priority"), |_| UniquePriority::Priority),
))(s)
}
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 }))
}
pub fn expression_or_cond_pattern(s: &str) -> IResult<&str, ExpressionOrCondPattern> {
alt((
map(expression, |x| ExpressionOrCondPattern::Expression(x)),
map(cond_pattern, |x| ExpressionOrCondPattern::CondPattern(x)),
))(s)
}
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,
},
))
}

View File

@ -45,45 +45,57 @@ pub fn continuous_assign(s: &str) -> IResult<&str, ContinuousAssign> {
}
pub fn continuous_assign_net(s: &str) -> IResult<&str, ContinuousAssign> {
let (s, drive_strength) = opt(drive_strength)(s)?;
let (s, delay3) = opt(delay3)(s)?;
let (s, list) = many1(net_assignment)(s)?;
let (s, x) = opt(drive_strength)(s)?;
let (s, y) = opt(delay3)(s)?;
let (s, z) = many1(net_assignment)(s)?;
Ok((
s,
ContinuousAssign::Net(ContinuousAssignNet {
drive_strength,
delay3,
list,
drive_strength: x,
delay3: y,
list: z,
}),
))
}
pub fn continuous_assign_variable(s: &str) -> IResult<&str, ContinuousAssign> {
let (s, delay_control) = opt(delay_control)(s)?;
let (s, list) = many1(variable_assignment)(s)?;
let (s, x) = opt(delay_control)(s)?;
let (s, y) = many1(variable_assignment)(s)?;
Ok((
s,
ContinuousAssign::Variable(ContinuousAssignVariable {
delay_control,
list,
delay_control: x,
list: y,
}),
))
}
pub fn net_alias(s: &str) -> IResult<&str, NetAlias> {
let (s, _) = symbol("alias")(s)?;
let (s, lvalue) = net_lvalue(s)?;
let (s, rvalue) = many1(preceded(symbol("="), net_lvalue))(s)?;
let (s, x) = net_lvalue(s)?;
let (s, y) = many1(preceded(symbol("="), net_lvalue))(s)?;
Ok((s, NetAlias { lvalue, rvalue }))
Ok((
s,
NetAlias {
lvalue: x,
rvalue: y,
},
))
}
pub fn net_assignment(s: &str) -> IResult<&str, NetAssignment> {
let (s, lvalue) = net_lvalue(s)?;
let (s, x) = net_lvalue(s)?;
let (s, _) = symbol("=")(s)?;
let (s, rvalue) = expression(s)?;
let (s, y) = expression(s)?;
Ok((s, NetAssignment { lvalue, rvalue }))
Ok((
s,
NetAssignment {
lvalue: x,
rvalue: y,
},
))
}

View File

@ -1,6 +1,16 @@
pub mod case_statements;
pub mod conditional_statements;
pub mod continuous_assignment_and_net_alias_statements;
pub mod parallel_and_sequential_blocks;
pub mod procedual_blocks_and_assignments;
pub mod patterns;
pub mod procedural_blocks_and_assignments;
pub mod statements;
pub mod timing_control_statements;
pub use case_statements::*;
pub use conditional_statements::*;
pub use continuous_assignment_and_net_alias_statements::*;
pub use parallel_and_sequential_blocks::*;
pub use procedual_blocks_and_assignments::*;
pub use patterns::*;
pub use procedural_blocks_and_assignments::*;
pub use statements::*;
pub use timing_control_statements::*;

View File

@ -53,51 +53,51 @@ pub fn action_block(s: &str) -> IResult<&str, ActionBlock> {
}
pub fn action_block_else(s: &str) -> IResult<&str, ActionBlock> {
let (s, statement) = opt(statement)(s)?;
let (s, x) = opt(statement)(s)?;
let (s, _) = symbol("else")(s)?;
let (s, else_statement) = statement_or_null(s)?;
let (s, y) = statement_or_null(s)?;
Ok((
s,
ActionBlock::Else(ActionBlockElse {
statement,
else_statement,
statement: x,
else_statement: y,
}),
))
}
pub fn seq_block(s: &str) -> IResult<&str, SeqBlock> {
let (s, _) = symbol("begin")(s)?;
let (s, beg_identifier) = opt(preceded(symbol(":"), block_identifier))(s)?;
let (s, declaration) = many0(block_item_declaration)(s)?;
let (s, statement) = many0(statement_or_null)(s)?;
let (s, x) = opt(preceded(symbol(":"), block_identifier))(s)?;
let (s, y) = many0(block_item_declaration)(s)?;
let (s, z) = many0(statement_or_null)(s)?;
let (s, _) = symbol("end")(s)?;
let (s, end_identifier) = opt(preceded(symbol(":"), block_identifier))(s)?;
let (s, v) = opt(preceded(symbol(":"), block_identifier))(s)?;
Ok((
s,
SeqBlock {
beg_identifier,
declaration,
statement,
end_identifier,
beg_identifier: x,
declaration: y,
statement: z,
end_identifier: v,
},
))
}
pub fn par_block(s: &str) -> IResult<&str, ParBlock> {
let (s, _) = symbol("fork")(s)?;
let (s, beg_identifier) = opt(preceded(symbol(":"), block_identifier))(s)?;
let (s, declaration) = many0(block_item_declaration)(s)?;
let (s, statement) = many0(statement_or_null)(s)?;
let (s, keyword) = join_keyword(s)?;
let (s, end_identifier) = opt(preceded(symbol(":"), block_identifier))(s)?;
let (s, x) = opt(preceded(symbol(":"), block_identifier))(s)?;
let (s, y) = many0(block_item_declaration)(s)?;
let (s, z) = many0(statement_or_null)(s)?;
let (s, v) = join_keyword(s)?;
let (s, w) = opt(preceded(symbol(":"), block_identifier))(s)?;
Ok((
s,
ParBlock {
beg_identifier,
declaration,
statement,
keyword,
end_identifier,
beg_identifier: x,
declaration: y,
statement: z,
keyword: v,
end_identifier: w,
},
))
}

View File

@ -0,0 +1,237 @@
use crate::parser::*;
use nom::branch::*;
use nom::combinator::*;
use nom::multi::*;
use nom::sequence::*;
use nom::IResult;
// -----------------------------------------------------------------------------
#[derive(Debug)]
pub enum Pattern<'a> {
VariableIdentifier(Box<Identifier<'a>>),
Asterisk,
ConstantExpression(Box<ConstantExpression<'a>>),
Tagged(Box<(Identifier<'a>, Option<Pattern<'a>>)>),
Pattern(Box<Vec<Pattern<'a>>>),
MemberPattern(Box<Vec<(Identifier<'a>, Pattern<'a>)>>),
}
#[derive(Debug)]
pub enum AssignmentPattern<'a> {
Expression(Vec<Expression<'a>>),
StructurePatternKey(Vec<(StructurePatternKey<'a>, Expression<'a>)>),
ArrayPatternKey(Vec<(ArrayPatternKey<'a>, Expression<'a>)>),
ConstantExpression((ConstantExpression<'a>, Vec<Expression<'a>>)),
}
#[derive(Debug)]
pub enum StructurePatternKey<'a> {
Identifier(Identifier<'a>),
PatternKey(AssignmentPatternKey<'a>),
}
#[derive(Debug)]
pub enum ArrayPatternKey<'a> {
Expression(ConstantExpression<'a>),
PatternKey(AssignmentPatternKey<'a>),
}
#[derive(Debug)]
pub enum AssignmentPatternKey<'a> {
SimpleType(SimpleType<'a>),
Default,
}
#[derive(Debug)]
pub struct AssignmentPatternExpression<'a> {
pub r#type: Option<AssignmentPatternExpressionType<'a>>,
pub pattern: AssignmentPattern<'a>,
}
#[derive(Debug)]
pub enum AssignmentPatternExpressionType<'a> {
Type(ScopedIdentifier<'a>),
Parameter(ScopedIdentifier<'a>),
IntegerAtom(IntegerAtomType<'a>),
TypeReference(TypeReference<'a>),
}
#[derive(Debug)]
pub struct AssignmentPatternNetLvalue<'a> {
pub lvalue: Vec<NetLvalue<'a>>,
}
#[derive(Debug)]
pub struct AssignmentPatternVariableLvalue<'a> {
pub lvalue: Vec<VariableLvalue<'a>>,
}
// -----------------------------------------------------------------------------
pub fn pattern(s: &str) -> IResult<&str, Pattern> {
alt((
map(preceded(symbol("."), variable_identifier), |x| {
Pattern::VariableIdentifier(Box::new(x))
}),
map(symbol(".*"), |_| Pattern::Asterisk),
map(constant_expression, |x| {
Pattern::ConstantExpression(Box::new(x))
}),
map(
preceded(symbol("tagged"), pair(member_identifier, opt(pattern))),
|x| Pattern::Tagged(Box::new(x)),
),
map(
delimited(
symbol("'{"),
separated_nonempty_list(symbol(","), pattern),
symbol("}"),
),
|x| Pattern::Pattern(Box::new(x)),
),
map(
delimited(
symbol("'{"),
separated_nonempty_list(
symbol(","),
pair(member_identifier, preceded(symbol(":"), pattern)),
),
symbol("}"),
),
|x| Pattern::MemberPattern(Box::new(x)),
),
))(s)
}
pub fn assignment_pattern(s: &str) -> IResult<&str, AssignmentPattern> {
alt((
map(
delimited(
symbol("'{"),
separated_nonempty_list(symbol(","), expression),
symbol("}"),
),
|x| AssignmentPattern::Expression(x),
),
map(
delimited(
symbol("'{"),
separated_nonempty_list(
symbol(","),
pair(structure_pattern_key, preceded(symbol(":"), expression)),
),
symbol("}"),
),
|x| AssignmentPattern::StructurePatternKey(x),
),
map(
delimited(
symbol("'{"),
separated_nonempty_list(
symbol(","),
pair(array_pattern_key, preceded(symbol(":"), expression)),
),
symbol("}"),
),
|x| AssignmentPattern::ArrayPatternKey(x),
),
map(
delimited(
symbol("'{"),
pair(
constant_expression,
delimited(
symbol("{"),
separated_nonempty_list(symbol(","), expression),
symbol("}"),
),
),
symbol("}"),
),
|x| AssignmentPattern::ConstantExpression(x),
),
))(s)
}
pub fn structure_pattern_key(s: &str) -> IResult<&str, StructurePatternKey> {
alt((
map(member_identifier, |x| StructurePatternKey::Identifier(x)),
map(assignment_pattern_key, |x| {
StructurePatternKey::PatternKey(x)
}),
))(s)
}
pub fn array_pattern_key(s: &str) -> IResult<&str, ArrayPatternKey> {
alt((
map(constant_expression, |x| ArrayPatternKey::Expression(x)),
map(assignment_pattern_key, |x| ArrayPatternKey::PatternKey(x)),
))(s)
}
pub fn assignment_pattern_key(s: &str) -> IResult<&str, AssignmentPatternKey> {
alt((
map(simple_type, |x| AssignmentPatternKey::SimpleType(x)),
map(symbol("default"), |_| AssignmentPatternKey::Default),
))(s)
}
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,
},
))
}
pub fn assignment_pattern_expression_type(
s: &str,
) -> IResult<&str, AssignmentPatternExpressionType> {
alt((
map(ps_type_identifier, |x| {
AssignmentPatternExpressionType::Type(x)
}),
map(ps_parameter_identifier, |x| {
AssignmentPatternExpressionType::Parameter(x)
}),
map(integer_atom_type, |x| {
AssignmentPatternExpressionType::IntegerAtom(x)
}),
map(type_reference, |x| {
AssignmentPatternExpressionType::TypeReference(x)
}),
))(s)
}
pub fn constant_assignment_pattern_expression(
s: &str,
) -> IResult<&str, AssignmentPatternExpression> {
assignment_pattern_expression(s)
}
pub fn assignment_pattern_net_lvalue(s: &str) -> IResult<&str, AssignmentPatternNetLvalue> {
let (s, x) = delimited(
symbol("'{"),
separated_nonempty_list(symbol(","), net_lvalue),
symbol("}"),
)(s)?;
Ok((s, AssignmentPatternNetLvalue { lvalue: x }))
}
pub fn assignment_pattern_variable_lvalue(
s: &str,
) -> IResult<&str, AssignmentPatternVariableLvalue> {
let (s, x) = delimited(
symbol("'{"),
separated_nonempty_list(symbol(","), variable_lvalue),
symbol("}"),
)(s)?;
Ok((s, AssignmentPatternVariableLvalue { lvalue: x }))
}
// -----------------------------------------------------------------------------

View File

@ -27,7 +27,7 @@ pub enum AlwaysKeyword {
#[derive(Debug)]
pub struct FinalConstruct<'a> {
pub statement: FunctionStatement<'a>,
pub statement: Statement<'a>,
}
#[derive(Debug)]
@ -74,7 +74,7 @@ pub struct NonblockingAssignment<'a> {
}
#[derive(Debug)]
pub enum ProcedualContinuousAssignment<'a> {
pub enum ProceduralContinuousAssignment<'a> {
Assign(VariableAssignment<'a>),
Deassign(VariableLvalue<'a>),
ForceVariable(VariableAssignment<'a>),
@ -93,14 +93,20 @@ pub struct VariableAssignment<'a> {
pub fn initial_construct(s: &str) -> IResult<&str, InitialConstruct> {
let (s, _) = symbol("initial")(s)?;
let (s, statement) = statement_or_null(s)?;
Ok((s, InitialConstruct { statement }))
let (s, x) = statement_or_null(s)?;
Ok((s, InitialConstruct { statement: x }))
}
pub fn always_construct(s: &str) -> IResult<&str, AlwaysConstruct> {
let (s, keyword) = always_keyword(s)?;
let (s, statement) = statement(s)?;
Ok((s, AlwaysConstruct { keyword, statement }))
let (s, x) = always_keyword(s)?;
let (s, y) = statement(s)?;
Ok((
s,
AlwaysConstruct {
keyword: x,
statement: y,
},
))
}
pub fn always_keyword(s: &str) -> IResult<&str, AlwaysKeyword> {
@ -114,8 +120,8 @@ 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, statement) = function_statement(s)?;
Ok((s, FinalConstruct { statement }))
let (s, x) = function_statement(s)?;
Ok((s, FinalConstruct { statement: x }))
}
pub fn blocking_assignment(s: &str) -> IResult<&str, BlockingAssignment> {
@ -128,61 +134,64 @@ pub fn blocking_assignment(s: &str) -> IResult<&str, BlockingAssignment> {
}
pub fn blocking_assignment_variable(s: &str) -> IResult<&str, BlockingAssignment> {
let (s, lvalue) = variable_lvalue(s)?;
let (s, x) = variable_lvalue(s)?;
let (s, _) = symbol("=")(s)?;
let (s, control) = delay_or_event_control(s)?;
let (s, rvalue) = expression(s)?;
let (s, y) = delay_or_event_control(s)?;
let (s, z) = expression(s)?;
Ok((
s,
BlockingAssignment::Variable(BlockingAssignmentVariable {
lvalue,
control,
rvalue,
lvalue: x,
control: y,
rvalue: z,
}),
))
}
pub fn blocking_assignment_nonrange_variable(s: &str) -> IResult<&str, BlockingAssignment> {
let (s, lvalue) = nonrange_variable_lvalue(s)?;
let (s, x) = nonrange_variable_lvalue(s)?;
let (s, _) = symbol("=")(s)?;
let (s, rvalue) = dynamic_array_new(s)?;
let (s, y) = dynamic_array_new(s)?;
Ok((
s,
BlockingAssignment::NonrangeVariable(BlockingAssignmentNonrangeVariable { lvalue, rvalue }),
BlockingAssignment::NonrangeVariable(BlockingAssignmentNonrangeVariable {
lvalue: x,
rvalue: y,
}),
))
}
pub fn blocking_assignment_hierarchical_variable(s: &str) -> IResult<&str, BlockingAssignment> {
let (s, scope) = opt(alt((
let (s, x) = opt(alt((
terminated(implicit_class_handle, symbol(".")),
class_scope,
package_scope,
)))(s)?;
let (s, lvalue) = hierarchical_variable_identifier(s)?;
let (s, select) = select(s)?;
let (s, y) = hierarchical_variable_identifier(s)?;
let (s, z) = select(s)?;
let (s, _) = symbol("=")(s)?;
let (s, rvalue) = class_new(s)?;
let (s, v) = class_new(s)?;
Ok((
s,
BlockingAssignment::HierarchicalVariable(BlockingAssignmentHierarchicalVariable {
scope,
lvalue,
select,
rvalue,
scope: x,
lvalue: y,
select: z,
rvalue: v,
}),
))
}
pub fn operator_assignment(s: &str) -> IResult<&str, OperatorAssignment> {
let (s, lvalue) = variable_lvalue(s)?;
let (s, operator) = assignment_operator(s)?;
let (s, rvalue) = expression(s)?;
let (s, x) = variable_lvalue(s)?;
let (s, y) = assignment_operator(s)?;
let (s, z) = expression(s)?;
Ok((
s,
OperatorAssignment {
lvalue,
operator,
rvalue,
lvalue: x,
operator: y,
rvalue: z,
},
))
}
@ -206,46 +215,52 @@ pub fn assignment_operator(s: &str) -> IResult<&str, Operator> {
}
pub fn nonblocking_assignment(s: &str) -> IResult<&str, NonblockingAssignment> {
let (s, lvalue) = variable_lvalue(s)?;
let (s, x) = variable_lvalue(s)?;
let (s, _) = symbol("<=")(s)?;
let (s, control) = opt(delay_or_event_control)(s)?;
let (s, rvalue) = expression(s)?;
let (s, y) = opt(delay_or_event_control)(s)?;
let (s, z) = expression(s)?;
Ok((
s,
NonblockingAssignment {
lvalue,
control,
rvalue,
lvalue: x,
control: y,
rvalue: z,
},
))
}
pub fn procedual_continuous_assignment(s: &str) -> IResult<&str, ProcedualContinuousAssignment> {
pub fn procedural_continuous_assignment(s: &str) -> IResult<&str, ProceduralContinuousAssignment> {
alt((
map(preceded(symbol("assign"), variable_assignment), |x| {
ProcedualContinuousAssignment::Assign(x)
ProceduralContinuousAssignment::Assign(x)
}),
map(preceded(symbol("deassign"), variable_lvalue), |x| {
ProcedualContinuousAssignment::Deassign(x)
ProceduralContinuousAssignment::Deassign(x)
}),
map(preceded(symbol("force"), variable_assignment), |x| {
ProcedualContinuousAssignment::ForceVariable(x)
ProceduralContinuousAssignment::ForceVariable(x)
}),
map(preceded(symbol("force"), net_assignment), |x| {
ProcedualContinuousAssignment::ForceNet(x)
ProceduralContinuousAssignment::ForceNet(x)
}),
map(preceded(symbol("release"), variable_lvalue), |x| {
ProcedualContinuousAssignment::ReleaseVariable(x)
ProceduralContinuousAssignment::ReleaseVariable(x)
}),
map(preceded(symbol("release"), net_lvalue), |x| {
ProcedualContinuousAssignment::ReleaseNet(x)
ProceduralContinuousAssignment::ReleaseNet(x)
}),
))(s)
}
pub fn variable_assignment(s: &str) -> IResult<&str, VariableAssignment> {
let (s, lvalue) = variable_lvalue(s)?;
let (s, x) = variable_lvalue(s)?;
let (s, _) = symbol("=")(s)?;
let (s, rvalue) = expression(s)?;
Ok((s, VariableAssignment { lvalue, rvalue }))
let (s, y) = expression(s)?;
Ok((
s,
VariableAssignment {
lvalue: x,
rvalue: y,
},
))
}

View File

@ -0,0 +1,142 @@
use crate::parser::*;
use nom::branch::*;
use nom::combinator::*;
use nom::multi::*;
use nom::sequence::*;
use nom::IResult;
// -----------------------------------------------------------------------------
#[derive(Debug)]
pub enum StatementOrNull<'a> {
Statement(Statement<'a>),
Attribute(Vec<AttributeInstance<'a>>),
}
#[derive(Debug)]
pub struct Statement<'a> {
pub identifier: Option<Identifier<'a>>,
pub attribute: Vec<AttributeInstance<'a>>,
pub item: StatementItem<'a>,
}
#[derive(Debug)]
pub enum StatementItem<'a> {
BlockingAssignment(Box<BlockingAssignment<'a>>),
NonblockingAssignment(Box<NonblockingAssignment<'a>>),
ProceduralContinuousAssignment(Box<ProceduralContinuousAssignment<'a>>),
CaseStatement(Box<CaseStatement<'a>>),
ConditionalStatement(Box<ConditionalStatement<'a>>),
IncOrDecExpression(Box<IncOrDecExpression<'a>>),
SubroutineCallStatement(Box<SubroutineCallStatement<'a>>),
DisableStatement(Box<DisableStatement<'a>>),
EventTrigger(Box<EventTrigger<'a>>),
LoopStatement(Box<LoopStatement<'a>>),
JumpStatement(Box<JumpStatement<'a>>),
ParBlock(Box<ParBlock<'a>>),
ProceduralTimingControlStatement(Box<ProceduralTimingControlStatement<'a>>),
SeqBlock(Box<SeqBlock<'a>>),
WaitStatement(Box<WaitStatement<'a>>),
ProceduralAssertionStatement(Box<ProceduralAssertionStatement<'a>>),
ClockingDrive(Box<ClockingDrive<'a>>),
RandsequenceStatement(Box<RandsequenceStatement<'a>>),
RandcaseStatement(Box<RandcaseStatement<'a>>),
ExpectPropertyStatement(Box<ExpectPropertyStatement<'a>>),
}
// -----------------------------------------------------------------------------
pub fn statement_or_null(s: &str) -> IResult<&str, StatementOrNull> {
alt((
map(statement, |x| StatementOrNull::Statement(x)),
map(terminated(many0(attribute_instance), symbol(";")), |x| {
StatementOrNull::Attribute(x)
}),
))(s)
}
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,
},
))
}
pub fn statement_item(s: &str) -> IResult<&str, StatementItem> {
alt((
map(terminated(blocking_assignment, symbol(";")), |x| {
StatementItem::BlockingAssignment(Box::new(x))
}),
map(terminated(nonblocking_assignment, symbol(";")), |x| {
StatementItem::NonblockingAssignment(Box::new(x))
}),
map(
terminated(procedural_continuous_assignment, symbol(";")),
|x| StatementItem::ProceduralContinuousAssignment(Box::new(x)),
),
map(case_statement, |x| {
StatementItem::CaseStatement(Box::new(x))
}),
map(conditional_statement, |x| {
StatementItem::ConditionalStatement(Box::new(x))
}),
map(terminated(inc_or_dec_expression, symbol(";")), |x| {
StatementItem::IncOrDecExpression(Box::new(x))
}),
map(subroutine_call_statement, |x| {
StatementItem::SubroutineCallStatement(Box::new(x))
}),
map(disable_statement, |x| {
StatementItem::DisableStatement(Box::new(x))
}),
map(event_trigger, |x| StatementItem::EventTrigger(Box::new(x))),
map(loop_statement, |x| {
StatementItem::LoopStatement(Box::new(x))
}),
map(jump_statement, |x| {
StatementItem::JumpStatement(Box::new(x))
}),
map(par_block, |x| StatementItem::ParBlock(Box::new(x))),
map(procedural_timing_control_statement, |x| {
StatementItem::ProceduralTimingControlStatement(Box::new(x))
}),
map(seq_block, |x| StatementItem::SeqBlock(Box::new(x))),
map(wait_statement, |x| {
StatementItem::WaitStatement(Box::new(x))
}),
map(procedural_assertion_statement, |x| {
StatementItem::ProceduralAssertionStatement(Box::new(x))
}),
map(terminated(clocking_drive, symbol(";")), |x| {
StatementItem::ClockingDrive(Box::new(x))
}),
map(randsequence_statement, |x| {
StatementItem::RandsequenceStatement(Box::new(x))
}),
map(randcase_statement, |x| {
StatementItem::RandcaseStatement(Box::new(x))
}),
map(expect_property_statement, |x| {
StatementItem::ExpectPropertyStatement(Box::new(x))
}),
))(s)
}
pub fn function_statement(s: &str) -> IResult<&str, Statement> {
statement(s)
}
pub fn function_statement_or_null(s: &str) -> IResult<&str, StatementOrNull> {
statement_or_null(s)
}
pub fn variable_identifier_list(s: &str) -> IResult<&str, Vec<Identifier>> {
separated_nonempty_list(symbol(","), variable_identifier)(s)
}

View File

@ -0,0 +1,410 @@
use crate::parser::*;
use nom::branch::*;
use nom::combinator::*;
use nom::multi::*;
use nom::sequence::*;
use nom::IResult;
// -----------------------------------------------------------------------------
#[derive(Debug)]
pub struct ProceduralTimingControlStatement<'a> {
pub control: ProceduralTimingControl<'a>,
pub statement: StatementOrNull<'a>,
}
#[derive(Debug)]
pub enum DelayOrEventControl<'a> {
Delay(DelayControl<'a>),
Event(EventControl<'a>),
Repeat(DelayOrEventControlRepeat<'a>),
}
#[derive(Debug)]
pub struct DelayOrEventControlRepeat<'a> {
pub expression: Expression<'a>,
pub control: EventControl<'a>,
}
#[derive(Debug)]
pub enum DelayControl<'a> {
Delay(DelayValue<'a>),
Mintypmax(MintypmaxExpression<'a>),
}
#[derive(Debug)]
pub enum EventControl<'a> {
EventIdentifier(HierarchicalIdentifier<'a>),
EventExpression(EventExpression<'a>),
Asterisk,
SequenceIdentifier(ScopedIdentifier<'a>),
}
#[derive(Debug)]
pub enum EventExpression<'a> {
Expression(Box<EventExpressionExpression<'a>>),
Sequence(Box<EventExpressionSequence<'a>>),
Or(Box<(EventExpression<'a>, EventExpression<'a>)>),
Comma(Box<(EventExpression<'a>, EventExpression<'a>)>),
Paren(Box<EventExpression<'a>>),
}
#[derive(Debug)]
pub struct EventExpressionExpression<'a> {
pub edge: Option<EdgeIdentifier<'a>>,
pub expression: Expression<'a>,
pub iff: Option<Expression<'a>>,
}
#[derive(Debug)]
pub struct EventExpressionSequence<'a> {
pub instance: SequenceInstance<'a>,
pub iff: Option<Expression<'a>>,
}
#[derive(Debug)]
pub enum ProceduralTimingControl<'a> {
DelayControl(DelayControl<'a>),
EventControl(EventControl<'a>),
CycleDelay(CycleDelay<'a>),
}
#[derive(Debug)]
pub enum JumpStatement<'a> {
Return(JumpStatementReturn<'a>),
Break,
Continue,
}
#[derive(Debug)]
pub struct JumpStatementReturn<'a> {
pub expression: Option<Expression<'a>>,
}
#[derive(Debug)]
pub enum WaitStatement<'a> {
Wait(WaitStatementWait<'a>),
Fork,
Order(WaitStatementOrder<'a>),
}
#[derive(Debug)]
pub struct WaitStatementWait<'a> {
pub expression: Expression<'a>,
pub statement: StatementOrNull<'a>,
}
#[derive(Debug)]
pub struct WaitStatementOrder<'a> {
pub identifier: Vec<HierarchicalIdentifier<'a>>,
pub block: ActionBlock<'a>,
}
#[derive(Debug)]
pub enum EventTrigger<'a> {
Named(EventTriggerNamed<'a>),
Nonblocking(EventTriggerNonblocking<'a>),
}
#[derive(Debug)]
pub struct EventTriggerNamed<'a> {
pub identifier: HierarchicalIdentifier<'a>,
}
#[derive(Debug)]
pub struct EventTriggerNonblocking<'a> {
pub control: Option<DelayOrEventControl<'a>>,
pub identifier: HierarchicalIdentifier<'a>,
}
#[derive(Debug)]
pub enum DisableStatement<'a> {
Task(HierarchicalIdentifier<'a>),
Block(HierarchicalIdentifier<'a>),
Fork,
}
// -----------------------------------------------------------------------------
pub fn procedural_timing_control_statement(
s: &str,
) -> IResult<&str, ProceduralTimingControlStatement> {
let (s, x) = procedural_timing_control(s)?;
let (s, y) = statement_or_null(s)?;
Ok((
s,
ProceduralTimingControlStatement {
control: x,
statement: y,
},
))
}
pub fn delay_or_event_control(s: &str) -> IResult<&str, DelayOrEventControl> {
alt((
map(delay_control, |x| DelayOrEventControl::Delay(x)),
map(event_control, |x| DelayOrEventControl::Event(x)),
delay_or_event_control_repeat,
))(s)
}
pub fn delay_or_event_control_repeat(s: &str) -> IResult<&str, DelayOrEventControl> {
let (s, _) = symbol("repeat")(s)?;
let (s, _) = symbol("(")(s)?;
let (s, x) = expression(s)?;
let (s, _) = symbol(")")(s)?;
let (s, y) = event_control(s)?;
Ok((
s,
DelayOrEventControl::Repeat(DelayOrEventControlRepeat {
expression: x,
control: y,
}),
))
}
pub fn delay_control(s: &str) -> IResult<&str, DelayControl> {
alt((delay_control_delay, delay_control_mintypmax))(s)
}
pub fn delay_control_delay(s: &str) -> IResult<&str, DelayControl> {
let (s, _) = symbol("#")(s)?;
let (s, x) = delay_value(s)?;
Ok((s, DelayControl::Delay(x)))
}
pub fn delay_control_mintypmax(s: &str) -> IResult<&str, DelayControl> {
let (s, _) = symbol("#")(s)?;
let (s, _) = symbol("(")(s)?;
let (s, x) = mintypmax_expression(s)?;
let (s, _) = symbol(")")(s)?;
Ok((s, DelayControl::Mintypmax(x)))
}
pub fn event_control(s: &str) -> IResult<&str, EventControl> {
alt((
event_control_event_identifier,
event_control_event_expression,
event_control_asterisk,
event_control_sequence_identifier,
))(s)
}
pub fn event_control_event_identifier(s: &str) -> IResult<&str, EventControl> {
let (s, _) = symbol("@")(s)?;
let (s, x) = hierarchical_event_identifier(s)?;
Ok((s, EventControl::EventIdentifier(x)))
}
pub fn event_control_event_expression(s: &str) -> IResult<&str, EventControl> {
let (s, _) = symbol("@")(s)?;
let (s, _) = symbol("(")(s)?;
let (s, x) = event_expression(s)?;
let (s, _) = symbol(")")(s)?;
Ok((s, EventControl::EventExpression(x)))
}
pub fn event_control_asterisk(s: &str) -> IResult<&str, EventControl> {
let (s, _) = alt((symbol("@*"), preceded(symbol("@"), symbol("(*)"))))(s)?;
Ok((s, EventControl::Asterisk))
}
pub fn event_control_sequence_identifier(s: &str) -> IResult<&str, EventControl> {
let (s, _) = symbol("@")(s)?;
let (s, x) = ps_or_hierarchical_sequence_identifier(s)?;
Ok((s, EventControl::SequenceIdentifier(x)))
}
pub fn event_expression(s: &str) -> IResult<&str, EventExpression> {
alt((
event_expression_expression,
event_expression_sequence,
event_expression_or,
event_expression_comma,
event_expression_paren,
))(s)
}
pub fn event_expression_expression(s: &str) -> IResult<&str, EventExpression> {
let (s, x) = opt(edge_identifier)(s)?;
let (s, y) = expression(s)?;
let (s, z) = opt(preceded(symbol("iff"), expression))(s)?;
Ok((
s,
EventExpression::Expression(Box::new(EventExpressionExpression {
edge: x,
expression: y,
iff: z,
})),
))
}
pub fn event_expression_sequence(s: &str) -> IResult<&str, EventExpression> {
let (s, x) = sequence_instance(s)?;
let (s, y) = opt(preceded(symbol("iff"), expression))(s)?;
Ok((
s,
EventExpression::Sequence(Box::new(EventExpressionSequence {
instance: x,
iff: y,
})),
))
}
pub fn event_expression_or(s: &str) -> IResult<&str, EventExpression> {
let (s, x) = event_expression(s)?;
let (s, _) = symbol("or")(s)?;
let (s, y) = event_expression(s)?;
Ok((s, EventExpression::Or(Box::new((x, y)))))
}
pub fn event_expression_comma(s: &str) -> IResult<&str, EventExpression> {
let (s, x) = event_expression(s)?;
let (s, _) = symbol(",")(s)?;
let (s, y) = event_expression(s)?;
Ok((s, EventExpression::Comma(Box::new((x, y)))))
}
pub fn event_expression_paren(s: &str) -> IResult<&str, EventExpression> {
let (s, _) = symbol("(")(s)?;
let (s, x) = event_expression(s)?;
let (s, _) = symbol(")")(s)?;
Ok((s, EventExpression::Paren(Box::new(x))))
}
pub fn procedural_timing_control(s: &str) -> IResult<&str, ProceduralTimingControl> {
alt((
map(delay_control, |x| ProceduralTimingControl::DelayControl(x)),
map(event_control, |x| ProceduralTimingControl::EventControl(x)),
map(cycle_delay, |x| ProceduralTimingControl::CycleDelay(x)),
))(s)
}
pub fn jump_statement(s: &str) -> IResult<&str, JumpStatement> {
alt((
jump_statement_return,
jump_statement_break,
jump_statement_continue,
))(s)
}
pub fn jump_statement_return(s: &str) -> IResult<&str, JumpStatement> {
let (s, _) = symbol("return")(s)?;
let (s, x) = opt(expression)(s)?;
let (s, _) = symbol(";")(s)?;
Ok((
s,
JumpStatement::Return(JumpStatementReturn { expression: x }),
))
}
pub fn jump_statement_break(s: &str) -> IResult<&str, JumpStatement> {
let (s, _) = symbol("break")(s)?;
let (s, _) = symbol(";")(s)?;
Ok((s, JumpStatement::Break))
}
pub fn jump_statement_continue(s: &str) -> IResult<&str, JumpStatement> {
let (s, _) = symbol("continue")(s)?;
let (s, _) = symbol(";")(s)?;
Ok((s, JumpStatement::Continue))
}
pub fn wait_statement(s: &str) -> IResult<&str, WaitStatement> {
alt((
wait_statement_wait,
wait_statement_fork,
wait_statement_order,
))(s)
}
pub fn wait_statement_wait(s: &str) -> IResult<&str, WaitStatement> {
let (s, _) = symbol("wait")(s)?;
let (s, x) = delimited(symbol("("), expression, symbol(")"))(s)?;
let (s, y) = statement_or_null(s)?;
Ok((
s,
WaitStatement::Wait(WaitStatementWait {
expression: x,
statement: y,
}),
))
}
pub fn wait_statement_fork(s: &str) -> IResult<&str, WaitStatement> {
let (s, _) = symbol("wait")(s)?;
let (s, _) = symbol("fork")(s)?;
let (s, _) = symbol(";")(s)?;
Ok((s, WaitStatement::Fork))
}
pub fn wait_statement_order(s: &str) -> IResult<&str, WaitStatement> {
let (s, _) = symbol("wait_order")(s)?;
let (s, x) = delimited(
symbol("("),
separated_nonempty_list(symbol(","), hierarchical_identifier),
symbol(")"),
)(s)?;
let (s, y) = action_block(s)?;
Ok((
s,
WaitStatement::Order(WaitStatementOrder {
identifier: x,
block: y,
}),
))
}
pub fn event_trigger(s: &str) -> IResult<&str, EventTrigger> {
alt((event_trigger_named, event_trigger_nonblocking))(s)
}
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 })))
}
pub fn event_trigger_nonblocking(s: &str) -> IResult<&str, EventTrigger> {
let (s, _) = symbol("->>")(s)?;
let (s, x) = opt(delay_or_event_control)(s)?;
let (s, y) = hierarchical_event_identifier(s)?;
let (s, _) = symbol(";")(s)?;
Ok((
s,
EventTrigger::Nonblocking(EventTriggerNonblocking {
control: x,
identifier: y,
}),
))
}
pub fn disable_statement(s: &str) -> IResult<&str, DisableStatement> {
alt((
disable_statement_task,
disable_statement_block,
disable_statement_fork,
))(s)
}
pub fn disable_statement_task(s: &str) -> IResult<&str, DisableStatement> {
let (s, _) = symbol("disable")(s)?;
let (s, x) = hierarchical_task_identifier(s)?;
let (s, _) = symbol(";")(s)?;
Ok((s, DisableStatement::Task(x)))
}
pub fn disable_statement_block(s: &str) -> IResult<&str, DisableStatement> {
let (s, _) = symbol("disable")(s)?;
let (s, x) = hierarchical_block_identifier(s)?;
let (s, _) = symbol(";")(s)?;
Ok((s, DisableStatement::Block(x)))
}
pub fn disable_statement_fork(s: &str) -> IResult<&str, DisableStatement> {
let (s, _) = symbol("disable")(s)?;
let (s, _) = symbol("fork")(s)?;
let (s, _) = symbol(";")(s)?;
Ok((s, DisableStatement::Fork))
}

View File

@ -75,81 +75,81 @@ pub struct ArrayRangeExpression<'a> {
pub fn concatenation(s: &str) -> IResult<&str, Concatenation> {
let (s, _) = symbol("{")(s)?;
let (s, expression) = separated_nonempty_list(symbol(","), expression)(s)?;
let (s, x) = separated_nonempty_list(symbol(","), expression)(s)?;
let (s, _) = symbol("}")(s)?;
Ok((s, Concatenation { expression }))
Ok((s, Concatenation { expression: x }))
}
pub fn constant_concatenation(s: &str) -> IResult<&str, ConstantConcatenation> {
let (s, _) = symbol("{")(s)?;
let (s, expression) = separated_nonempty_list(symbol(","), constant_expression)(s)?;
let (s, x) = separated_nonempty_list(symbol(","), constant_expression)(s)?;
let (s, _) = symbol("}")(s)?;
Ok((s, ConstantConcatenation { expression }))
Ok((s, ConstantConcatenation { expression: x }))
}
pub fn constant_multiple_concatenation(s: &str) -> IResult<&str, ConstantMultipleConcatenation> {
let (s, _) = symbol("{")(s)?;
let (s, expression) = constant_expression(s)?;
let (s, concatenation) = constant_concatenation(s)?;
let (s, x) = constant_expression(s)?;
let (s, y) = constant_concatenation(s)?;
let (s, _) = symbol("}")(s)?;
Ok((
s,
ConstantMultipleConcatenation {
expression,
concatenation,
expression: x,
concatenation: y,
},
))
}
pub fn module_path_concatenation(s: &str) -> IResult<&str, ModulePathConcatenation> {
let (s, _) = symbol("{")(s)?;
let (s, expression) = separated_nonempty_list(symbol(","), module_path_expression)(s)?;
let (s, x) = separated_nonempty_list(symbol(","), module_path_expression)(s)?;
let (s, _) = symbol("}")(s)?;
Ok((s, ModulePathConcatenation { expression }))
Ok((s, ModulePathConcatenation { expression: x }))
}
pub fn module_path_multiple_concatenation(
s: &str,
) -> IResult<&str, ModulePathMultipleConcatenation> {
let (s, _) = symbol("{")(s)?;
let (s, expression) = constant_expression(s)?;
let (s, concatenation) = module_path_concatenation(s)?;
let (s, x) = constant_expression(s)?;
let (s, y) = module_path_concatenation(s)?;
let (s, _) = symbol("}")(s)?;
Ok((
s,
ModulePathMultipleConcatenation {
expression,
concatenation,
expression: x,
concatenation: y,
},
))
}
pub fn multiple_concatenation(s: &str) -> IResult<&str, MultipleConcatenation> {
let (s, _) = symbol("{")(s)?;
let (s, expression) = expression(s)?;
let (s, concatenation) = concatenation(s)?;
let (s, x) = expression(s)?;
let (s, y) = concatenation(s)?;
let (s, _) = symbol("}")(s)?;
Ok((
s,
MultipleConcatenation {
expression,
concatenation,
expression: x,
concatenation: y,
},
))
}
pub fn streaming_concatenation(s: &str) -> IResult<&str, StreamingConcatenation> {
let (s, _) = symbol("{")(s)?;
let (s, operator) = stream_operator(s)?;
let (s, size) = opt(slice_size)(s)?;
let (s, concatenation) = stream_concatenation(s)?;
let (s, x) = stream_operator(s)?;
let (s, y) = opt(slice_size)(s)?;
let (s, z) = stream_concatenation(s)?;
let (s, _) = symbol("}")(s)?;
Ok((
s,
StreamingConcatenation {
operator,
size,
concatenation,
operator: x,
size: y,
concatenation: z,
},
))
}
@ -167,37 +167,43 @@ pub fn slice_size(s: &str) -> IResult<&str, SliceSize> {
pub fn stream_concatenation(s: &str) -> IResult<&str, StreamConcatenation> {
let (s, _) = symbol("{")(s)?;
let (s, expression) = separated_nonempty_list(symbol(","), stream_expression)(s)?;
let (s, x) = separated_nonempty_list(symbol(","), stream_expression)(s)?;
let (s, _) = symbol("}")(s)?;
Ok((s, StreamConcatenation { expression }))
Ok((s, StreamConcatenation { expression: x }))
}
pub fn stream_expression(s: &str) -> IResult<&str, StreamExpression> {
let (s, expression) = expression(s)?;
let (s, with) = opt(preceded(
let (s, x) = expression(s)?;
let (s, y) = opt(preceded(
symbol("with"),
delimited(symbol("["), array_range_expression, symbol("]")),
))(s)?;
Ok((s, StreamExpression { expression, with }))
Ok((
s,
StreamExpression {
expression: x,
with: y,
},
))
}
pub fn array_range_expression(s: &str) -> IResult<&str, ArrayRangeExpression> {
let (s, arg0) = expression(s)?;
let (s, x) = opt(pair(
let (s, x) = expression(s)?;
let (s, y) = opt(pair(
alt((symbol(":"), symbol("+:"), symbol("-:"))),
expression,
))(s)?;
let (operator, arg1) = if let Some((x, y)) = x {
(Some(x), Some(y))
let (y, z) = if let Some((y, z)) = y {
(Some(y), Some(z))
} else {
(None, None)
};
Ok((
s,
ArrayRangeExpression {
arg0,
operator,
arg1,
arg0: x,
operator: y,
arg1: z,
},
))
}

View File

@ -9,9 +9,9 @@ use nom::IResult;
#[derive(Debug)]
pub enum NetLvalue<'a> {
Identifier(NetLvalueIdentifier<'a>),
Lvalue(Vec<NetLvalue<'a>>),
Pattern(NetLvaluePattern<'a>),
Identifier(Box<NetLvalueIdentifier<'a>>),
Lvalue(Box<Vec<NetLvalue<'a>>>),
Pattern(Box<NetLvaluePattern<'a>>),
}
#[derive(Debug)]
@ -28,10 +28,10 @@ pub struct NetLvaluePattern<'a> {
#[derive(Debug)]
pub enum VariableLvalue<'a> {
Identifier(VariableLvalueIdentifier<'a>),
Lvalue(Vec<VariableLvalue<'a>>),
Pattern(VariableLvaluePattern<'a>),
Concatenation(StreamingConcatenation<'a>),
Identifier(Box<VariableLvalueIdentifier<'a>>),
Lvalue(Box<Vec<VariableLvalue<'a>>>),
Pattern(Box<VariableLvaluePattern<'a>>),
Concatenation(Box<StreamingConcatenation<'a>>),
}
#[derive(Debug)]
@ -61,18 +61,27 @@ pub fn net_lvalue(s: &str) -> IResult<&str, NetLvalue> {
}
pub fn net_lvalue_identifier(s: &str) -> IResult<&str, NetLvalue> {
let (s, identifier) = ps_or_hierarchical_net_identifier(s)?;
let (s, select) = constant_select(s)?;
let (s, x) = ps_or_hierarchical_net_identifier(s)?;
let (s, y) = constant_select(s)?;
Ok((
s,
NetLvalue::Identifier(NetLvalueIdentifier { identifier, select }),
NetLvalue::Identifier(Box::new(NetLvalueIdentifier {
identifier: x,
select: y,
})),
))
}
pub fn net_lvalue_pattern(s: &str) -> IResult<&str, NetLvalue> {
let (s, r#type) = opt(assignment_pattern_expression_type)(s)?;
let (s, lvalue) = assignment_pattern_net_lvalue(s)?;
Ok((s, NetLvalue::Pattern(NetLvaluePattern { r#type, lvalue })))
let (s, x) = opt(assignment_pattern_expression_type)(s)?;
let (s, y) = assignment_pattern_net_lvalue(s)?;
Ok((
s,
NetLvalue::Pattern(Box::new(NetLvaluePattern {
r#type: x,
lvalue: y,
})),
))
}
pub fn net_lvalue_lvalue(s: &str) -> IResult<&str, NetLvalue> {
@ -87,7 +96,7 @@ pub fn net_lvalue_lvalue(s: &str) -> IResult<&str, NetLvalue> {
ret.push(y);
}
Ok((s, NetLvalue::Lvalue(ret)))
Ok((s, NetLvalue::Lvalue(Box::new(ret))))
}
pub fn variable_lvalue(s: &str) -> IResult<&str, VariableLvalue> {
@ -96,34 +105,37 @@ pub fn variable_lvalue(s: &str) -> IResult<&str, VariableLvalue> {
variable_lvalue_lvalue,
variable_lvalue_pattern,
map(streaming_concatenation, |x| {
VariableLvalue::Concatenation(x)
VariableLvalue::Concatenation(Box::new(x))
}),
))(s)
}
pub fn variable_lvalue_identifier(s: &str) -> IResult<&str, VariableLvalue> {
let (s, scope) = opt(alt((
let (s, x) = opt(alt((
terminated(implicit_class_handle, symbol(".")),
package_scope,
)))(s)?;
let (s, identifier) = hierarchical_variable_identifier(s)?;
let (s, select) = select(s)?;
let (s, y) = hierarchical_variable_identifier(s)?;
let (s, z) = select(s)?;
Ok((
s,
VariableLvalue::Identifier(VariableLvalueIdentifier {
scope,
identifier,
select,
}),
VariableLvalue::Identifier(Box::new(VariableLvalueIdentifier {
scope: x,
identifier: y,
select: z,
})),
))
}
pub fn variable_lvalue_pattern(s: &str) -> IResult<&str, VariableLvalue> {
let (s, r#type) = opt(assignment_pattern_expression_type)(s)?;
let (s, lvalue) = assignment_pattern_variable_lvalue(s)?;
let (s, x) = opt(assignment_pattern_expression_type)(s)?;
let (s, y) = assignment_pattern_variable_lvalue(s)?;
Ok((
s,
VariableLvalue::Pattern(VariableLvaluePattern { r#type, lvalue }),
VariableLvalue::Pattern(Box::new(VariableLvaluePattern {
r#type: x,
lvalue: y,
})),
))
}
@ -139,22 +151,22 @@ pub fn variable_lvalue_lvalue(s: &str) -> IResult<&str, VariableLvalue> {
ret.push(y);
}
Ok((s, VariableLvalue::Lvalue(ret)))
Ok((s, VariableLvalue::Lvalue(Box::new(ret))))
}
pub fn nonrange_variable_lvalue(s: &str) -> IResult<&str, NonrangeVariableLvalue> {
let (s, scope) = opt(alt((
let (s, x) = opt(alt((
terminated(implicit_class_handle, symbol(".")),
package_scope,
)))(s)?;
let (s, identifier) = hierarchical_variable_identifier(s)?;
let (s, select) = nonrange_select(s)?;
let (s, y) = hierarchical_variable_identifier(s)?;
let (s, z) = nonrange_select(s)?;
Ok((
s,
NonrangeVariableLvalue {
scope,
identifier,
select,
scope: x,
identifier: y,
select: z,
},
))
}

View File

@ -140,7 +140,7 @@ pub struct TaggedUnionExpression<'a> {
#[derive(Debug)]
pub struct InsideExpression<'a> {
pub expression: Expression<'a>,
pub open_range_list: OpenRangeList<'a>,
pub open_range_list: Vec<ValueRange<'a>>,
}
#[derive(Debug)]
@ -211,47 +211,47 @@ pub fn inc_or_dec_expression(s: &str) -> IResult<&str, IncOrDecExpression> {
}
pub fn inc_or_dec_expression_prefix(s: &str) -> IResult<&str, IncOrDecExpression> {
let (s, operator) = inc_or_dec_operator(s)?;
let (s, attribute) = many0(attribute_instance)(s)?;
let (s, lvalue) = variable_lvalue(s)?;
let (s, x) = inc_or_dec_operator(s)?;
let (s, y) = many0(attribute_instance)(s)?;
let (s, z) = variable_lvalue(s)?;
Ok((
s,
IncOrDecExpression::Prefix(IncOrDecExpressionPrefix {
operator,
attribute,
lvalue,
operator: x,
attribute: y,
lvalue: z,
}),
))
}
pub fn inc_or_dec_expression_suffix(s: &str) -> IResult<&str, IncOrDecExpression> {
let (s, lvalue) = variable_lvalue(s)?;
let (s, attribute) = many0(attribute_instance)(s)?;
let (s, operator) = inc_or_dec_operator(s)?;
let (s, x) = variable_lvalue(s)?;
let (s, y) = many0(attribute_instance)(s)?;
let (s, z) = inc_or_dec_operator(s)?;
Ok((
s,
IncOrDecExpression::Suffix(IncOrDecExpressionSuffix {
lvalue,
attribute,
operator,
lvalue: x,
attribute: y,
operator: z,
}),
))
}
pub fn conditional_expression(s: &str) -> IResult<&str, ConditionalExpression> {
let (s, predicate) = cond_predicate(s)?;
let (s, x) = cond_predicate(s)?;
let (s, _) = symbol("?")(s)?;
let (s, attribute) = many0(attribute_instance)(s)?;
let (s, arg0) = expression(s)?;
let (s, y) = many0(attribute_instance)(s)?;
let (s, z) = expression(s)?;
let (s, _) = symbol(":")(s)?;
let (s, arg1) = expression(s)?;
let (s, v) = expression(s)?;
Ok((
s,
ConditionalExpression {
predicate,
attribute,
arg0,
arg1,
predicate: x,
attribute: y,
arg0: z,
arg1: v,
},
))
}
@ -268,49 +268,49 @@ pub fn constant_expression(s: &str) -> IResult<&str, ConstantExpression> {
}
pub fn constant_expression_unary(s: &str) -> IResult<&str, ConstantExpression> {
let (s, operator) = unary_operator(s)?;
let (s, attribute) = many0(attribute_instance)(s)?;
let (s, arg0) = constant_primary(s)?;
let (s, x) = unary_operator(s)?;
let (s, y) = many0(attribute_instance)(s)?;
let (s, z) = constant_primary(s)?;
Ok((
s,
ConstantExpression::Unary(Box::new(ConstantExpressionUnary {
operator,
attribute,
arg0,
operator: x,
attribute: y,
arg0: z,
})),
))
}
pub fn constant_expression_binary(s: &str) -> IResult<&str, ConstantExpression> {
let (s, arg0) = constant_expression(s)?;
let (s, operator) = binary_operator(s)?;
let (s, attribute) = many0(attribute_instance)(s)?;
let (s, arg1) = constant_expression(s)?;
let (s, x) = constant_expression(s)?;
let (s, y) = binary_operator(s)?;
let (s, z) = many0(attribute_instance)(s)?;
let (s, v) = constant_expression(s)?;
Ok((
s,
ConstantExpression::Binary(Box::new(ConstantExpressionBinary {
arg0,
operator,
attribute,
arg1,
arg0: x,
operator: y,
attribute: z,
arg1: v,
})),
))
}
pub fn constant_expression_ternary(s: &str) -> IResult<&str, ConstantExpression> {
let (s, predicate) = constant_expression(s)?;
let (s, x) = constant_expression(s)?;
let (s, _) = symbol("?")(s)?;
let (s, attribute) = many0(attribute_instance)(s)?;
let (s, arg0) = constant_expression(s)?;
let (s, y) = many0(attribute_instance)(s)?;
let (s, z) = constant_expression(s)?;
let (s, _) = symbol(":")(s)?;
let (s, arg1) = constant_expression(s)?;
let (s, v) = constant_expression(s)?;
Ok((
s,
ConstantExpression::Ternary(Box::new(ConstantExpressionTernary {
predicate,
attribute,
arg0,
arg1,
predicate: x,
attribute: y,
arg0: z,
arg1: v,
})),
))
}
@ -403,57 +403,57 @@ pub fn expression(s: &str) -> IResult<&str, Expression> {
}
pub fn expression_unary(s: &str) -> IResult<&str, Expression> {
let (s, operator) = unary_operator(s)?;
let (s, attribute) = many0(attribute_instance)(s)?;
let (s, arg0) = primary(s)?;
let (s, x) = unary_operator(s)?;
let (s, y) = many0(attribute_instance)(s)?;
let (s, z) = primary(s)?;
Ok((
s,
Expression::Unary(Box::new(ExpressionUnary {
operator,
attribute,
arg0,
operator: x,
attribute: y,
arg0: z,
})),
))
}
pub fn expression_binary(s: &str) -> IResult<&str, Expression> {
let (s, arg0) = expression(s)?;
let (s, operator) = binary_operator(s)?;
let (s, attribute) = many0(attribute_instance)(s)?;
let (s, arg1) = expression(s)?;
let (s, x) = expression(s)?;
let (s, y) = binary_operator(s)?;
let (s, z) = many0(attribute_instance)(s)?;
let (s, v) = expression(s)?;
Ok((
s,
Expression::Binary(Box::new(ExpressionBinary {
arg0,
operator,
attribute,
arg1,
arg0: x,
operator: y,
attribute: z,
arg1: v,
})),
))
}
pub fn tagged_union_expression(s: &str) -> IResult<&str, TaggedUnionExpression> {
let (s, _) = symbol("tagged")(s)?;
let (s, identifier) = member_identifier(s)?;
let (s, expression) = opt(expression)(s)?;
let (s, x) = member_identifier(s)?;
let (s, y) = opt(expression)(s)?;
Ok((
s,
TaggedUnionExpression {
identifier,
expression,
identifier: x,
expression: y,
},
))
}
pub fn inside_expression(s: &str) -> IResult<&str, InsideExpression> {
let (s, expression) = expression(s)?;
let (s, x) = expression(s)?;
let (s, _) = symbol("inside")(s)?;
let (s, open_range_list) = delimited(symbol("{"), open_range_list, symbol("}"))(s)?;
let (s, y) = delimited(symbol("{"), open_range_list, symbol("}"))(s)?;
Ok((
s,
InsideExpression {
expression,
open_range_list,
expression: x,
open_range_list: y,
},
))
}
@ -493,19 +493,19 @@ pub fn mintypmax_expression_ternary(s: &str) -> IResult<&str, MintypmaxExpressio
pub fn module_path_conditional_expression(
s: &str,
) -> IResult<&str, ModulePathConditionalExpression> {
let (s, predicate) = module_path_expression(s)?;
let (s, x) = module_path_expression(s)?;
let (s, _) = symbol("?")(s)?;
let (s, attribute) = many0(attribute_instance)(s)?;
let (s, arg0) = module_path_expression(s)?;
let (s, y) = many0(attribute_instance)(s)?;
let (s, z) = module_path_expression(s)?;
let (s, _) = symbol(":")(s)?;
let (s, arg1) = module_path_expression(s)?;
let (s, v) = module_path_expression(s)?;
Ok((
s,
ModulePathConditionalExpression {
predicate,
attribute,
arg0,
arg1,
predicate: x,
attribute: y,
arg0: z,
arg1: v,
},
))
}
@ -524,31 +524,31 @@ pub fn module_path_expression(s: &str) -> IResult<&str, ModulePathExpression> {
}
pub fn module_path_expression_unary(s: &str) -> IResult<&str, ModulePathExpression> {
let (s, operator) = unary_module_path_operator(s)?;
let (s, attribute) = many0(attribute_instance)(s)?;
let (s, arg0) = module_path_primary(s)?;
let (s, x) = unary_module_path_operator(s)?;
let (s, y) = many0(attribute_instance)(s)?;
let (s, z) = module_path_primary(s)?;
Ok((
s,
ModulePathExpression::Unary(Box::new(ModulePathExpressionUnary {
operator,
attribute,
arg0,
operator: x,
attribute: y,
arg0: z,
})),
))
}
pub fn module_path_expression_binary(s: &str) -> IResult<&str, ModulePathExpression> {
let (s, arg0) = module_path_expression(s)?;
let (s, operator) = binary_module_path_operator(s)?;
let (s, attribute) = many0(attribute_instance)(s)?;
let (s, arg1) = module_path_expression(s)?;
let (s, x) = module_path_expression(s)?;
let (s, y) = binary_module_path_operator(s)?;
let (s, z) = many0(attribute_instance)(s)?;
let (s, v) = module_path_expression(s)?;
Ok((
s,
ModulePathExpression::Binary(Box::new(ModulePathExpressionBinary {
arg0,
operator,
attribute,
arg1,
arg0: x,
operator: y,
attribute: z,
arg1: v,
})),
))
}

View File

@ -91,7 +91,7 @@ pub fn integral_number(s: &str) -> IResult<&str, Number> {
}
pub fn decimal_number(s: &str) -> IResult<&str, IntegralNumber> {
let (s, (size, decimal_base, decimal_value)) = tuple((
let (s, (x, y, z)) = tuple((
opt(size),
decimal_base,
alt((unsigned_number, x_number, z_number)),
@ -99,9 +99,9 @@ pub fn decimal_number(s: &str) -> IResult<&str, IntegralNumber> {
Ok((
s,
IntegralNumber::DecimalNumber(DecimalNumber {
size,
decimal_base,
decimal_value,
size: x,
decimal_base: y,
decimal_value: z,
}),
))
}
@ -112,37 +112,37 @@ pub fn integral_unsigned_number(s: &str) -> IResult<&str, IntegralNumber> {
}
pub fn binary_number(s: &str) -> IResult<&str, IntegralNumber> {
let (s, (size, binary_base, binary_value)) = tuple((opt(size), binary_base, binary_value))(s)?;
let (s, (x, y, z)) = tuple((opt(size), binary_base, binary_value))(s)?;
Ok((
s,
IntegralNumber::BinaryNumber(BinaryNumber {
size,
binary_base,
binary_value,
size: x,
binary_base: y,
binary_value: z,
}),
))
}
pub fn octal_number(s: &str) -> IResult<&str, IntegralNumber> {
let (s, (size, octal_base, octal_value)) = tuple((opt(size), octal_base, octal_value))(s)?;
let (s, (x, y, z)) = tuple((opt(size), octal_base, octal_value))(s)?;
Ok((
s,
IntegralNumber::OctalNumber(OctalNumber {
size,
octal_base,
octal_value,
size: x,
octal_base: y,
octal_value: z,
}),
))
}
pub fn hex_number(s: &str) -> IResult<&str, IntegralNumber> {
let (s, (size, hex_base, hex_value)) = tuple((opt(size), hex_base, hex_value))(s)?;
let (s, (x, y, z)) = tuple((opt(size), hex_base, hex_value))(s)?;
Ok((
s,
IntegralNumber::HexNumber(HexNumber {
size,
hex_base,
hex_value,
size: x,
hex_base: y,
hex_value: z,
}),
))
}
@ -164,34 +164,31 @@ pub fn real_number(s: &str) -> IResult<&str, Number> {
}
pub fn fixed_point_number(s: &str) -> IResult<&str, RealNumber> {
let (s, (integer_value, _, fraction_value)) =
tuple((unsigned_number, symbol("."), unsigned_number))(s)?;
let (s, (x, _, y)) = tuple((unsigned_number, symbol("."), unsigned_number))(s)?;
Ok((
s,
RealNumber::FixedPointNumber(FixedPointNumber {
integer_value,
fraction_value,
integer_value: x,
fraction_value: y,
}),
))
}
pub fn floating_point_number(s: &str) -> IResult<&str, RealNumber> {
let (s, integer_value) = unsigned_number(s)?;
let (s, fraction_value) = opt(tuple((symbol("."), unsigned_number)))(s)?;
let (s, exponent) = alt((symbol("e"), symbol("E")))(s)?;
let (s, sign) = opt(alt((symbol("+"), symbol("-"))))(s)?;
let (s, exponent_value) = unsigned_number(s)?;
let fraction_value = fraction_value.and_then(|(_, y)| Some(y));
let (s, x) = unsigned_number(s)?;
let (s, y) = opt(preceded(symbol("."), unsigned_number))(s)?;
let (s, z) = alt((symbol("e"), symbol("E")))(s)?;
let (s, v) = opt(alt((symbol("+"), symbol("-"))))(s)?;
let (s, w) = unsigned_number(s)?;
Ok((
s,
RealNumber::FloatingPointNumber(FloatingPointNumber {
integer_value,
fraction_value,
exponent,
sign,
exponent_value,
integer_value: x,
fraction_value: y,
exponent: z,
sign: v,
exponent_value: w,
}),
))
}

View File

@ -21,7 +21,7 @@ pub enum ConstantPrimary<'a> {
LetExpression(LetExpression<'a>),
MintypmaxExpression(ConstantMintypmaxExpression<'a>),
Cast(ConstantCast<'a>),
AssignmentPatternExpression(ConstantAssignmentPatternExpression<'a>),
AssignmentPatternExpression(AssignmentPatternExpression<'a>),
TypeReference(TypeReference<'a>),
Null,
}
@ -233,48 +233,60 @@ pub fn constant_primary(s: &str) -> IResult<&str, ConstantPrimary> {
}
pub fn constant_primary_ps_parameter(s: &str) -> IResult<&str, ConstantPrimary> {
let (s, identifier) = ps_parameter_identifier(s)?;
let (s, select) = constant_select(s)?;
let (s, x) = ps_parameter_identifier(s)?;
let (s, y) = constant_select(s)?;
Ok((
s,
ConstantPrimary::PsParameter(ConstantPrimaryPsParameter { identifier, select }),
ConstantPrimary::PsParameter(ConstantPrimaryPsParameter {
identifier: x,
select: y,
}),
))
}
pub fn constant_primary_specparam(s: &str) -> IResult<&str, ConstantPrimary> {
let (s, identifier) = specparam_identifier(s)?;
let (s, range) = opt(delimited(
let (s, x) = specparam_identifier(s)?;
let (s, y) = opt(delimited(
symbol("["),
constant_range_expression,
symbol("]"),
))(s)?;
Ok((
s,
ConstantPrimary::Specparam(ConstantPrimarySpecparam { identifier, range }),
ConstantPrimary::Specparam(ConstantPrimarySpecparam {
identifier: x,
range: y,
}),
))
}
pub fn constant_primary_formal_port(s: &str) -> IResult<&str, ConstantPrimary> {
let (s, identifier) = formal_port_identifier(s)?;
let (s, select) = constant_select(s)?;
let (s, x) = formal_port_identifier(s)?;
let (s, y) = constant_select(s)?;
Ok((
s,
ConstantPrimary::FormalPort(ConstantPrimaryFormalPort { identifier, select }),
ConstantPrimary::FormalPort(ConstantPrimaryFormalPort {
identifier: x,
select: y,
}),
))
}
pub fn constant_primary_enum(s: &str) -> IResult<&str, ConstantPrimary> {
let (s, scope) = alt((package_scope, class_scope))(s)?;
let (s, identifier) = enum_identifier(s)?;
let (s, x) = alt((package_scope, class_scope))(s)?;
let (s, y) = enum_identifier(s)?;
Ok((
s,
ConstantPrimary::Enum(ConstantPrimaryEnum { scope, identifier }),
ConstantPrimary::Enum(ConstantPrimaryEnum {
scope: x,
identifier: y,
}),
))
}
pub fn constant_primary_concatenation(s: &str) -> IResult<&str, ConstantPrimary> {
let (s, concatenation) = constant_concatenation(s)?;
let (s, range) = opt(delimited(
let (s, x) = constant_concatenation(s)?;
let (s, y) = opt(delimited(
symbol("["),
constant_range_expression,
symbol("]"),
@ -282,15 +294,15 @@ pub fn constant_primary_concatenation(s: &str) -> IResult<&str, ConstantPrimary>
Ok((
s,
ConstantPrimary::Concatenation(ConstantPrimaryConcatenation {
concatenation,
range,
concatenation: x,
range: y,
}),
))
}
pub fn constant_primary_multiple_concatenation(s: &str) -> IResult<&str, ConstantPrimary> {
let (s, concatenation) = constant_multiple_concatenation(s)?;
let (s, range) = opt(delimited(
let (s, x) = constant_multiple_concatenation(s)?;
let (s, y) = opt(delimited(
symbol("["),
constant_range_expression,
symbol("]"),
@ -298,8 +310,8 @@ pub fn constant_primary_multiple_concatenation(s: &str) -> IResult<&str, Constan
Ok((
s,
ConstantPrimary::MultipleConcatenation(ConstantPrimaryMultipleConcatenation {
concatenation,
range,
concatenation: x,
range: y,
}),
))
}
@ -360,39 +372,39 @@ pub fn primary(s: &str) -> IResult<&str, Primary> {
}
pub fn primary_hierarchical(s: &str) -> IResult<&str, Primary> {
let (s, qualifier) = opt(primary_hierarchical_qualifier)(s)?;
let (s, identifier) = hierarchical_identifier(s)?;
let (s, select) = select(s)?;
let (s, x) = opt(primary_hierarchical_qualifier)(s)?;
let (s, y) = hierarchical_identifier(s)?;
let (s, z) = select(s)?;
Ok((
s,
Primary::Hierarchical(PrimaryHierarchical {
qualifier,
identifier,
select,
qualifier: x,
identifier: y,
select: z,
}),
))
}
pub fn primary_concatenation(s: &str) -> IResult<&str, Primary> {
let (s, concatenation) = concatenation(s)?;
let (s, range) = opt(range_expression)(s)?;
let (s, x) = concatenation(s)?;
let (s, y) = opt(range_expression)(s)?;
Ok((
s,
Primary::Concatenation(PrimaryConcatenation {
concatenation,
range,
concatenation: x,
range: y,
}),
))
}
pub fn primary_multiple_concatenation(s: &str) -> IResult<&str, Primary> {
let (s, concatenation) = multiple_concatenation(s)?;
let (s, range) = opt(range_expression)(s)?;
let (s, x) = multiple_concatenation(s)?;
let (s, y) = opt(range_expression)(s)?;
Ok((
s,
Primary::MultipleConcatenation(PrimaryMultipleConcatenation {
concatenation,
range,
concatenation: x,
range: y,
}),
))
}
@ -409,16 +421,16 @@ pub fn primary_hierarchical_qualifier(s: &str) -> IResult<&str, PrimaryHierarchi
}
pub fn class_qualifier(s: &str) -> IResult<&str, ClassQualifier> {
let (s, local) = opt(symbol("local::"))(s)?;
let (s, scope) = opt(alt((
let (s, x) = opt(symbol("local::"))(s)?;
let (s, y) = opt(alt((
terminated(implicit_class_handle, symbol(".")),
class_scope,
)))(s)?;
Ok((
s,
ClassQualifier {
local: local.is_some(),
scope,
local: x.is_some(),
scope: y,
},
))
}
@ -446,20 +458,20 @@ pub fn time_literal(s: &str) -> IResult<&str, TimeLiteral> {
}
pub fn unsigned_time_literal(s: &str) -> IResult<&str, TimeLiteral> {
let (s, number) = unsigned_number(s)?;
let (s, unit) = time_unit(s)?;
let (s, x) = unsigned_number(s)?;
let (s, y) = time_unit(s)?;
Ok((
s,
TimeLiteral::UnsignedTimeLiteral(UnsignedTimeLiteral { number, unit }),
TimeLiteral::UnsignedTimeLiteral(UnsignedTimeLiteral { number: x, unit: y }),
))
}
pub fn fixed_point_time_literal(s: &str) -> IResult<&str, TimeLiteral> {
let (s, number) = fixed_point_number(s)?;
let (s, unit) = time_unit(s)?;
let (s, x) = fixed_point_number(s)?;
let (s, y) = time_unit(s)?;
Ok((
s,
TimeLiteral::FixedPointTimeLiteral(FixedPointTimeLiteral { number, unit }),
TimeLiteral::FixedPointTimeLiteral(FixedPointTimeLiteral { number: x, unit: y }),
))
}
@ -501,15 +513,18 @@ pub fn bit_select(s: &str) -> IResult<&str, Vec<Expression>> {
}
pub fn select(s: &str) -> IResult<&str, Select> {
let (s, member) = opt(pair(
let (s, x) = opt(pair(
many0(preceded(symbol("."), pair(member_identifier, bit_select))),
preceded(symbol("."), member_identifier),
))(s)?;
let (s, bit_select) = bit_select(s)?;
let (s, part_select_range) = opt(delimited(symbol("["), part_select_range, symbol("]")))(s)?;
let (s, y) = bit_select(s)?;
let (s, z) = opt(delimited(symbol("["), part_select_range, symbol("]")))(s)?;
let member = if let Some((upper, identifier)) = member {
Some(SelectMember { upper, identifier })
let x = if let Some((x, y)) = x {
Some(SelectMember {
upper: x,
identifier: y,
})
} else {
None
};
@ -517,22 +532,25 @@ pub fn select(s: &str) -> IResult<&str, Select> {
Ok((
s,
Select {
member,
bit_select,
part_select_range,
member: x,
bit_select: y,
part_select_range: z,
},
))
}
pub fn nonrange_select(s: &str) -> IResult<&str, Select> {
let (s, member) = opt(pair(
let (s, x) = opt(pair(
many0(preceded(symbol("."), pair(member_identifier, bit_select))),
preceded(symbol("."), member_identifier),
))(s)?;
let (s, bit_select) = bit_select(s)?;
let (s, y) = bit_select(s)?;
let member = if let Some((upper, identifier)) = member {
Some(SelectMember { upper, identifier })
let x = if let Some((x, y)) = x {
Some(SelectMember {
upper: x,
identifier: y,
})
} else {
None
};
@ -540,8 +558,8 @@ pub fn nonrange_select(s: &str) -> IResult<&str, Select> {
Ok((
s,
Select {
member,
bit_select,
member: x,
bit_select: y,
part_select_range: None,
},
))
@ -552,19 +570,22 @@ pub fn constant_bit_select(s: &str) -> IResult<&str, Vec<ConstantExpression>> {
}
pub fn constant_select(s: &str) -> IResult<&str, ConstantSelect> {
let (s, member) = opt(pair(
let (s, x) = opt(pair(
many0(preceded(symbol("."), pair(member_identifier, bit_select))),
preceded(symbol("."), member_identifier),
))(s)?;
let (s, bit_select) = constant_bit_select(s)?;
let (s, part_select_range) = opt(delimited(
let (s, y) = constant_bit_select(s)?;
let (s, z) = opt(delimited(
symbol("["),
constant_part_select_range,
symbol("]"),
))(s)?;
let member = if let Some((upper, identifier)) = member {
Some(SelectMember { upper, identifier })
let x = if let Some((x, y)) = x {
Some(SelectMember {
upper: x,
identifier: y,
})
} else {
None
};
@ -572,18 +593,24 @@ pub fn constant_select(s: &str) -> IResult<&str, ConstantSelect> {
Ok((
s,
ConstantSelect {
member,
bit_select,
part_select_range,
member: x,
bit_select: y,
part_select_range: z,
},
))
}
pub fn constant_cast(s: &str) -> IResult<&str, ConstantCast> {
let (s, r#type) = casting_type(s)?;
let (s, x) = casting_type(s)?;
let (s, _) = symbol("'")(s)?;
let (s, expression) = delimited(symbol("("), constant_expression, symbol(")"))(s)?;
Ok((s, ConstantCast { r#type, expression }))
let (s, y) = delimited(symbol("("), constant_expression, symbol(")"))(s)?;
Ok((
s,
ConstantCast {
r#type: x,
expression: y,
},
))
}
pub fn constant_let_expression(s: &str) -> IResult<&str, LetExpression> {
@ -591,10 +618,16 @@ pub fn constant_let_expression(s: &str) -> IResult<&str, LetExpression> {
}
pub fn cast(s: &str) -> IResult<&str, Cast> {
let (s, r#type) = casting_type(s)?;
let (s, x) = casting_type(s)?;
let (s, _) = symbol("'")(s)?;
let (s, expression) = delimited(symbol("("), expression, symbol(")"))(s)?;
Ok((s, Cast { r#type, expression }))
let (s, y) = delimited(symbol("("), expression, symbol(")"))(s)?;
Ok((
s,
Cast {
r#type: x,
expression: y,
},
))
}
// -----------------------------------------------------------------------------

View File

@ -96,15 +96,15 @@ pub fn constant_function_call(s: &str) -> IResult<&str, SubroutineCall> {
}
pub fn tf_call(s: &str) -> IResult<&str, TfCall> {
let (s, identifier) = ps_or_hierarchical_tf_identifier(s)?;
let (s, attribute) = many0(attribute_instance)(s)?;
let (s, argument) = opt(delimited(symbol("("), list_of_arguments, symbol(")")))(s)?;
let (s, x) = ps_or_hierarchical_tf_identifier(s)?;
let (s, y) = many0(attribute_instance)(s)?;
let (s, z) = opt(delimited(symbol("("), list_of_arguments, symbol(")")))(s)?;
Ok((
s,
TfCall {
identifier,
attribute,
argument,
identifier: x,
attribute: y,
argument: z,
},
))
}
@ -118,13 +118,13 @@ pub fn system_tf_call(s: &str) -> IResult<&str, SystemTfCall> {
}
pub fn system_tf_call_list_of_arguments(s: &str) -> IResult<&str, SystemTfCall> {
let (s, identifier) = system_tf_identifier(s)?;
let (s, argument) = opt(delimited(symbol("("), list_of_arguments, symbol(")")))(s)?;
let (s, x) = system_tf_identifier(s)?;
let (s, y) = opt(delimited(symbol("("), list_of_arguments, symbol(")")))(s)?;
Ok((
s,
SystemTfCall {
identifier,
argument,
identifier: x,
argument: y,
data_type: None,
expression: None,
clocking_event: None,
@ -133,45 +133,38 @@ pub fn system_tf_call_list_of_arguments(s: &str) -> IResult<&str, SystemTfCall>
}
pub fn system_tf_call_data_type(s: &str) -> IResult<&str, SystemTfCall> {
let (s, identifier) = system_tf_identifier(s)?;
let (s, x) = system_tf_identifier(s)?;
let (s, _) = symbol("(")(s)?;
let (s, data_type) = data_type(s)?;
let (s, expression) = preceded(symbol(","), expression)(s)?;
let (s, y) = data_type(s)?;
let (s, z) = preceded(symbol(","), expression)(s)?;
let (s, _) = symbol(")")(s)?;
let data_type = Some(data_type);
let expression = Some(vec![expression]);
Ok((
s,
SystemTfCall {
identifier,
identifier: x,
argument: None,
data_type,
expression,
data_type: Some(y),
expression: Some(vec![z]),
clocking_event: None,
},
))
}
pub fn system_tf_call_clocking_event(s: &str) -> IResult<&str, SystemTfCall> {
let (s, identifier) = system_tf_identifier(s)?;
let (s, x) = system_tf_identifier(s)?;
let (s, _) = symbol("(")(s)?;
let (s, expression) = separated_nonempty_list(symbol(","), expression)(s)?;
let (s, clocking_event) = opt(preceded(symbol(","), opt(clocking_event)))(s)?;
let (s, y) = separated_nonempty_list(symbol(","), expression)(s)?;
let (s, z) = opt(preceded(symbol(","), opt(clocking_event)))(s)?;
let (s, _) = symbol(")")(s)?;
let expression = Some(expression);
let clocking_event = if let Some(Some(x)) = clocking_event {
Some(x)
} else {
None
};
let z = if let Some(Some(z)) = z { Some(z) } else { None };
Ok((
s,
SystemTfCall {
identifier,
identifier: x,
argument: None,
data_type: None,
expression,
clocking_event,
expression: Some(y),
clocking_event: z,
},
))
}
@ -194,23 +187,29 @@ pub fn function_subroutine_call(s: &str) -> IResult<&str, SubroutineCall> {
}
pub fn list_of_arguments(s: &str) -> IResult<&str, ListOfArguments> {
let (s, unnamed) = separated_list(symbol(","), expression)(s)?;
let (s, named) = separated_list(
let (s, x) = separated_list(symbol(","), expression)(s)?;
let (s, y) = separated_list(
symbol(","),
pair(
preceded(symbol("."), identifier),
delimited(symbol("("), opt(expression), symbol(")")),
),
)(s)?;
Ok((s, ListOfArguments { unnamed, named }))
Ok((
s,
ListOfArguments {
unnamed: x,
named: y,
},
))
}
pub fn method_call(s: &str) -> IResult<&str, MethodCall> {
let (s, root) = method_call_root(s)?;
let (s, x) = method_call_root(s)?;
let (s, _) = symbol(".")(s)?;
let (s, body) = method_call_body(s)?;
let (s, y) = method_call_body(s)?;
Ok((s, MethodCall { root, body }))
Ok((s, MethodCall { root: x, body: y }))
}
pub fn method_call_body(s: &str) -> IResult<&str, MethodCallBody> {
@ -218,15 +217,15 @@ pub fn method_call_body(s: &str) -> IResult<&str, MethodCallBody> {
}
pub fn method_call_body_user(s: &str) -> IResult<&str, MethodCallBody> {
let (s, identifier) = method_identifier(s)?;
let (s, attribute) = many0(attribute_instance)(s)?;
let (s, argument) = opt(delimited(symbol("("), list_of_arguments, symbol(")")))(s)?;
let (s, x) = method_identifier(s)?;
let (s, y) = many0(attribute_instance)(s)?;
let (s, z) = opt(delimited(symbol("("), list_of_arguments, symbol(")")))(s)?;
Ok((
s,
MethodCallBody::User(MethodCallBodyUser {
identifier,
attribute,
argument,
identifier: x,
attribute: y,
argument: z,
}),
))
}
@ -239,28 +238,28 @@ pub fn built_in_method_call(s: &str) -> IResult<&str, MethodCallBody> {
}
pub fn array_manipulation_call(s: &str) -> IResult<&str, ArrayManipulationCall> {
let (s, name) = array_method_name(s)?;
let (s, attribute) = many0(attribute_instance)(s)?;
let (s, argument) = opt(delimited(symbol("("), list_of_arguments, symbol(")")))(s)?;
let (s, with) = opt(preceded(
let (s, x) = array_method_name(s)?;
let (s, y) = many0(attribute_instance)(s)?;
let (s, z) = opt(delimited(symbol("("), list_of_arguments, symbol(")")))(s)?;
let (s, w) = opt(preceded(
symbol("with"),
delimited(symbol("("), expression, symbol(")")),
))(s)?;
Ok((
s,
ArrayManipulationCall {
name,
attribute,
argument,
with,
name: x,
attribute: y,
argument: z,
with: w,
},
))
}
pub fn randomize_call(s: &str) -> IResult<&str, RandomizeCall> {
let (s, _) = symbol("randomize")(s)?;
let (s, attribute) = many0(attribute_instance)(s)?;
let (s, argument) = opt(delimited(
let (s, x) = many0(attribute_instance)(s)?;
let (s, y) = opt(delimited(
symbol("("),
opt(alt((
variable_identifier_list,
@ -268,28 +267,24 @@ pub fn randomize_call(s: &str) -> IResult<&str, RandomizeCall> {
))),
symbol(")"),
))(s)?;
let (s, with) = opt(tuple((
let (s, z) = opt(tuple((
symbol("with"),
opt(delimited(symbol("("), opt(identifier_list), symbol(")"))),
constraint_block,
)))(s)?;
let argument = if let Some(Some(x)) = argument {
x
} else {
vec![]
};
let (with, constraint_block) = if let Some((_, Some(Some(x)), y)) = with {
(x, Some(y))
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))
} else {
(vec![], None)
};
Ok((
s,
RandomizeCall {
attribute,
argument,
with,
constraint_block,
attribute: x,
argument: y,
with: z,
constraint_block: w,
},
))
}

View File

@ -21,15 +21,21 @@ pub struct AttrSpec<'a> {
pub fn attribute_instance(s: &str) -> IResult<&str, AttributeInstance> {
let (s, _) = symbol("(*")(s)?;
let (s, attr_spec) = separated_nonempty_list(symbol(","), attr_spec)(s)?;
let (s, x) = separated_nonempty_list(symbol(","), attr_spec)(s)?;
let (s, _) = symbol("*)")(s)?;
Ok((s, AttributeInstance { attr_spec }))
Ok((s, AttributeInstance { attr_spec: x }))
}
pub fn attr_spec(s: &str) -> IResult<&str, AttrSpec> {
let (s, attr_name) = identifier(s)?;
let (s, rvalue) = opt(preceded(symbol("="), constant_expression))(s)?;
Ok((s, AttrSpec { attr_name, rvalue }))
let (s, x) = identifier(s)?;
let (s, y) = opt(preceded(symbol("="), constant_expression))(s)?;
Ok((
s,
AttrSpec {
attr_name: x,
rvalue: y,
},
))
}
// -----------------------------------------------------------------------------

View File

@ -192,28 +192,26 @@ pub fn hierarchical_event_identifier(s: &str) -> IResult<&str, HierarchicalIdent
}
pub fn hierarchy(s: &str) -> IResult<&str, Hierarchy> {
let (s, identifier) = identifier(s)?;
let (s, constant_bit_select) = constant_bit_select(s)?;
let (s, x) = identifier(s)?;
let (s, y) = constant_bit_select(s)?;
let (s, _) = symbol(".")(s)?;
let constant_bit_select = Some(constant_bit_select);
Ok((
s,
Hierarchy {
identifier,
constant_bit_select,
identifier: x,
constant_bit_select: Some(y),
},
))
}
pub fn hierarchical_identifier(s: &str) -> IResult<&str, HierarchicalIdentifier> {
let (s, x) = opt(terminated(symbol("$root"), symbol(".")))(s)?;
let (s, mut hierarchy) = many0(hierarchy)(s)?;
let (s, identifier) = identifier(s)?;
let (s, mut y) = many0(hierarchy)(s)?;
let (s, z) = identifier(s)?;
if let Some(x) = x {
hierarchy.insert(
y.insert(
0,
Hierarchy {
identifier: Identifier { raw: x },
@ -225,8 +223,8 @@ pub fn hierarchical_identifier(s: &str) -> IResult<&str, HierarchicalIdentifier>
Ok((
s,
HierarchicalIdentifier {
hierarchy,
identifier,
hierarchy: y,
identifier: z,
},
))
}
@ -351,81 +349,136 @@ pub fn property_identifier(s: &str) -> IResult<&str, Identifier> {
}
pub fn ps_class_identifier(s: &str) -> IResult<&str, ScopedIdentifier> {
let (s, scope) = opt(package_scope)(s)?;
let (s, identifier) = class_identifier(s)?;
let identifier = identifier.into();
Ok((s, ScopedIdentifier { scope, identifier }))
let (s, x) = opt(package_scope)(s)?;
let (s, y) = class_identifier(s)?;
Ok((
s,
ScopedIdentifier {
scope: x,
identifier: y.into(),
},
))
}
pub fn ps_covergroup_identifier(s: &str) -> IResult<&str, ScopedIdentifier> {
let (s, scope) = opt(package_scope)(s)?;
let (s, identifier) = covergroup_identifier(s)?;
let identifier = identifier.into();
Ok((s, ScopedIdentifier { scope, identifier }))
let (s, x) = opt(package_scope)(s)?;
let (s, y) = covergroup_identifier(s)?;
Ok((
s,
ScopedIdentifier {
scope: x,
identifier: y.into(),
},
))
}
pub fn ps_checker_identifier(s: &str) -> IResult<&str, ScopedIdentifier> {
let (s, scope) = opt(package_scope)(s)?;
let (s, identifier) = checker_identifier(s)?;
let identifier = identifier.into();
Ok((s, ScopedIdentifier { scope, identifier }))
let (s, x) = opt(package_scope)(s)?;
let (s, y) = checker_identifier(s)?;
Ok((
s,
ScopedIdentifier {
scope: x,
identifier: y.into(),
},
))
}
pub fn ps_identifier(s: &str) -> IResult<&str, ScopedIdentifier> {
let (s, scope) = opt(package_scope)(s)?;
let (s, identifier) = identifier(s)?;
let identifier = identifier.into();
Ok((s, ScopedIdentifier { scope, identifier }))
let (s, x) = opt(package_scope)(s)?;
let (s, y) = identifier(s)?;
Ok((
s,
ScopedIdentifier {
scope: x,
identifier: y.into(),
},
))
}
pub fn ps_or_hierarchical_array_identifier(s: &str) -> IResult<&str, ScopedIdentifier> {
let (s, scope) = opt(alt((
let (s, x) = opt(alt((
terminated(implicit_class_handle, symbol(".")),
class_scope,
package_scope,
)))(s)?;
let (s, identifier) = hierarchical_array_identifier(s)?;
Ok((s, ScopedIdentifier { scope, identifier }))
let (s, y) = hierarchical_array_identifier(s)?;
Ok((
s,
ScopedIdentifier {
scope: x,
identifier: y,
},
))
}
pub fn ps_or_hierarchical_net_identifier(s: &str) -> IResult<&str, ScopedIdentifier> {
let (s, scope) = opt(package_scope)(s)?;
let (s, identifier) = alt((
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, identifier }))
Ok((
s,
ScopedIdentifier {
scope: x,
identifier: y,
},
))
}
pub fn ps_or_hierarchical_property_identifier(s: &str) -> IResult<&str, ScopedIdentifier> {
let (s, scope) = opt(package_scope)(s)?;
let (s, identifier) = alt((
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, identifier }))
Ok((
s,
ScopedIdentifier {
scope: x,
identifier: y,
},
))
}
pub fn ps_or_hierarchical_sequence_identifier(s: &str) -> IResult<&str, ScopedIdentifier> {
let (s, scope) = opt(package_scope)(s)?;
let (s, identifier) = alt((
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, identifier }))
Ok((
s,
ScopedIdentifier {
scope: x,
identifier: y,
},
))
}
pub fn ps_or_hierarchical_tf_identifier(s: &str) -> IResult<&str, ScopedIdentifier> {
let (s, scope) = opt(package_scope)(s)?;
let (s, identifier) = alt((map(tf_identifier, |x| x.into()), hierarchical_tf_identifier))(s)?;
Ok((s, ScopedIdentifier { scope, identifier }))
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_parameter_identifier(s: &str) -> IResult<&str, ScopedIdentifier> {
let (s, scope) = opt(alt((package_scope, class_scope, generate_block_scope)))(s)?;
let (s, identifier) = parameter_identifier(s)?;
let identifier = identifier.into();
Ok((s, ScopedIdentifier { scope, identifier }))
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 generate_block_scope(s: &str) -> IResult<&str, Scope> {
@ -436,10 +489,10 @@ pub fn generate_block_scope(s: &str) -> IResult<&str, Scope> {
)))(s)?;
let mut ret = Vec::new();
for (identifier, constant_expression, _) in x {
for (x, y, _) in x {
ret.push(GenerateBlockScope {
identifier,
constant_expression,
identifier: x,
constant_expression: y,
});
}
@ -447,16 +500,21 @@ pub fn generate_block_scope(s: &str) -> IResult<&str, Scope> {
}
pub fn ps_type_identifier(s: &str) -> IResult<&str, ScopedIdentifier> {
let (s, scope) = opt(alt((
let (s, x) = opt(alt((
map(terminated(symbol("local"), symbol("::")), |_| {
Scope::LocalScope
}),
package_scope,
class_scope,
)))(s)?;
let (s, identifier) = type_identifier(s)?;
let identifier = identifier.into();
Ok((s, ScopedIdentifier { scope, identifier }))
let (s, y) = type_identifier(s)?;
Ok((
s,
ScopedIdentifier {
scope: x,
identifier: y.into(),
},
))
}
pub fn sequence_identifier(s: &str) -> IResult<&str, Identifier> {

View File

@ -33,56 +33,21 @@ pub struct LetExpression<'a> {
pub raw: Vec<&'a str>,
}
#[derive(Debug)]
pub struct ConstantAssignmentPatternExpression<'a> {
pub raw: Vec<&'a str>,
}
#[derive(Debug)]
pub struct TypeReference<'a> {
pub raw: Vec<&'a str>,
}
#[derive(Debug)]
pub struct AssignmentPatternExpression<'a> {
pub raw: Vec<&'a str>,
}
#[derive(Debug)]
pub struct SequenceMethodCall<'a> {
pub raw: Vec<&'a str>,
}
#[derive(Debug)]
pub struct AssignmentPatternExpressionType<'a> {
pub raw: Vec<&'a str>,
}
#[derive(Debug)]
pub struct AssignmentPatternNetLvalue<'a> {
pub raw: Vec<&'a str>,
}
#[derive(Debug)]
pub struct AssignmentPatternVariableLvalue<'a> {
pub raw: Vec<&'a str>,
}
#[derive(Debug)]
pub struct CondPredicate<'a> {
pub raw: Vec<&'a str>,
}
#[derive(Debug)]
pub struct DataType<'a> {
pub raw: Vec<&'a str>,
}
#[derive(Debug)]
pub struct OpenRangeList<'a> {
pub raw: Vec<&'a str>,
}
#[derive(Debug)]
pub struct ClockingEvent<'a> {
pub raw: Vec<&'a str>,
@ -108,31 +73,6 @@ pub struct Delay3<'a> {
pub raw: Vec<&'a str>,
}
#[derive(Debug)]
pub struct DelayControl<'a> {
pub raw: Vec<&'a str>,
}
#[derive(Debug)]
pub struct StatementOrNull<'a> {
pub raw: Vec<&'a str>,
}
#[derive(Debug)]
pub struct Statement<'a> {
pub raw: Vec<&'a str>,
}
#[derive(Debug)]
pub struct FunctionStatement<'a> {
pub raw: Vec<&'a str>,
}
#[derive(Debug)]
pub struct DelayOrEventControl<'a> {
pub raw: Vec<&'a str>,
}
#[derive(Debug)]
pub struct DynamicArrayNew<'a> {
pub raw: Vec<&'a str>,
@ -148,6 +88,61 @@ pub struct BlockItemDeclaration<'a> {
pub raw: Vec<&'a str>,
}
#[derive(Debug)]
pub struct SubroutineCallStatement<'a> {
pub raw: Vec<&'a str>,
}
#[derive(Debug)]
pub struct LoopStatement<'a> {
pub raw: Vec<&'a str>,
}
#[derive(Debug)]
pub struct ProceduralAssertionStatement<'a> {
pub raw: Vec<&'a str>,
}
#[derive(Debug)]
pub struct ClockingDrive<'a> {
pub raw: Vec<&'a str>,
}
#[derive(Debug)]
pub struct RandsequenceStatement<'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 CycleDelay<'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>,
}
pub fn class_scope(s: &str) -> IResult<&str, Scope> {
Ok((s, Scope::ClassScope))
}
@ -160,52 +155,18 @@ pub fn let_expression(s: &str) -> IResult<&str, LetExpression> {
Ok((s, LetExpression { raw: vec![] }))
}
pub fn constant_assignment_pattern_expression(
s: &str,
) -> IResult<&str, ConstantAssignmentPatternExpression> {
Ok((s, ConstantAssignmentPatternExpression { raw: vec![] }))
}
pub fn type_reference(s: &str) -> IResult<&str, TypeReference> {
Ok((s, TypeReference { raw: vec![] }))
}
pub fn assignment_pattern_expression(s: &str) -> IResult<&str, AssignmentPatternExpression> {
Ok((s, AssignmentPatternExpression { raw: vec![] }))
}
pub fn sequence_method_call(s: &str) -> IResult<&str, SequenceMethodCall> {
Ok((s, SequenceMethodCall { raw: vec![] }))
}
pub fn assignment_pattern_expression_type(
s: &str,
) -> IResult<&str, AssignmentPatternExpressionType> {
Ok((s, AssignmentPatternExpressionType { raw: vec![] }))
}
pub fn assignment_pattern_net_lvalue(s: &str) -> IResult<&str, AssignmentPatternNetLvalue> {
Ok((s, AssignmentPatternNetLvalue { raw: vec![] }))
}
pub fn assignment_pattern_variable_lvalue(
s: &str,
) -> IResult<&str, AssignmentPatternVariableLvalue> {
Ok((s, AssignmentPatternVariableLvalue { raw: vec![] }))
}
pub fn cond_predicate(s: &str) -> IResult<&str, CondPredicate> {
Ok((s, CondPredicate { raw: vec![] }))
}
pub fn data_type(s: &str) -> IResult<&str, DataType> {
Ok((s, DataType { raw: vec![] }))
}
pub fn open_range_list(s: &str) -> IResult<&str, OpenRangeList> {
Ok((s, OpenRangeList { raw: vec![] }))
}
pub fn clocking_event(s: &str) -> IResult<&str, ClockingEvent> {
Ok((s, ClockingEvent { raw: vec![] }))
}
@ -214,10 +175,6 @@ pub fn constraint_block(s: &str) -> IResult<&str, ConstraintBlock> {
Ok((s, ConstraintBlock { raw: vec![] }))
}
pub fn variable_identifier_list(s: &str) -> IResult<&str, Vec<Identifier>> {
Ok((s, vec![]))
}
pub fn identifier_list(s: &str) -> IResult<&str, Vec<Identifier>> {
Ok((s, vec![]))
}
@ -234,26 +191,6 @@ pub fn delay3(s: &str) -> IResult<&str, Delay3> {
Ok((s, Delay3 { raw: vec![] }))
}
pub fn delay_control(s: &str) -> IResult<&str, DelayControl> {
Ok((s, DelayControl { raw: vec![] }))
}
pub fn statement_or_null(s: &str) -> IResult<&str, StatementOrNull> {
Ok((s, StatementOrNull { raw: vec![] }))
}
pub fn statement(s: &str) -> IResult<&str, Statement> {
Ok((s, Statement { raw: vec![] }))
}
pub fn function_statement(s: &str) -> IResult<&str, FunctionStatement> {
Ok((s, FunctionStatement { raw: vec![] }))
}
pub fn delay_or_event_control(s: &str) -> IResult<&str, DelayOrEventControl> {
Ok((s, DelayOrEventControl { raw: vec![] }))
}
pub fn dynamic_array_new(s: &str) -> IResult<&str, DynamicArrayNew> {
Ok((s, DynamicArrayNew { raw: vec![] }))
}
@ -265,3 +202,47 @@ pub fn class_new(s: &str) -> IResult<&str, ClassNew> {
pub fn block_item_declaration(s: &str) -> IResult<&str, BlockItemDeclaration> {
Ok((s, BlockItemDeclaration { raw: vec![] }))
}
pub fn subroutine_call_statement(s: &str) -> IResult<&str, SubroutineCallStatement> {
Ok((s, SubroutineCallStatement { raw: vec![] }))
}
pub fn loop_statement(s: &str) -> IResult<&str, LoopStatement> {
Ok((s, LoopStatement { raw: vec![] }))
}
pub fn procedural_assertion_statement(s: &str) -> IResult<&str, ProceduralAssertionStatement> {
Ok((s, ProceduralAssertionStatement { raw: vec![] }))
}
pub fn clocking_drive(s: &str) -> IResult<&str, ClockingDrive> {
Ok((s, ClockingDrive { raw: vec![] }))
}
pub fn randsequence_statement(s: &str) -> IResult<&str, RandsequenceStatement> {
Ok((s, RandsequenceStatement { 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 cycle_delay(s: &str) -> IResult<&str, CycleDelay> {
Ok((s, CycleDelay { 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![] }))
}