From 7a2720533362fb65372dde3a64a6b798209ddff6 Mon Sep 17 00:00:00 2001 From: dalance Date: Wed, 17 Jul 2019 18:42:46 +0900 Subject: [PATCH] Add MaybeRecursive attr --- .../behavioral_statements/case_statements.rs | 10 ++-- .../conditional_statements.rs | 4 +- ...ous_assignment_and_net_alias_statements.rs | 6 +- .../looping_statements.rs | 4 +- .../procedural_blocks_and_assignments.rs | 10 ++-- .../behavioral_statements/randsequence.rs | 2 +- .../behavioral_statements/statements.rs | 2 +- .../timing_control_statements.rs | 6 +- .../declarations/assertion_declarations.rs | 52 +++++++++--------- .../declarations/block_item_declarations.rs | 2 +- .../declarations/covergroup_declarations.rs | 22 ++++---- src/parser/declarations/let_declarations.rs | 2 +- src/parser/expressions/concatenations.rs | 8 +-- .../expressions/expression_leftside_values.rs | 41 ++++++++++++++ src/parser/expressions/expressions.rs | 28 +++++----- src/parser/expressions/primaries.rs | 6 +- src/parser/expressions/subroutine_calls.rs | 4 +- .../instantiations/checker_instantiation.rs | 4 +- .../instantiations/generated_instantiation.rs | 2 +- .../instantiations/module_instantiation.rs | 6 +- src/parser/source_text/constraints.rs | 8 +-- src/parser/source_text/interface_items.rs | 2 +- src/parser/source_text/module_items.rs | 2 +- .../module_parameters_and_ports.rs | 2 +- src/parser/source_text/program_items.rs | 2 +- .../source_text/system_verilog_source_text.rs | 2 +- sv-parser-derive/src/lib.rs | 55 +++++++++++++------ 27 files changed, 178 insertions(+), 116 deletions(-) diff --git a/src/parser/behavioral_statements/case_statements.rs b/src/parser/behavioral_statements/case_statements.rs index bff796b..6e80352 100644 --- a/src/parser/behavioral_statements/case_statements.rs +++ b/src/parser/behavioral_statements/case_statements.rs @@ -226,7 +226,7 @@ pub fn case_item(s: Span) -> IResult { ))(s) } -#[parser] +#[parser(MaybeRecursive)] pub fn case_item_nondefault(s: Span) -> IResult { let (s, a) = list(symbol(","), case_item_expression)(s)?; let (s, b) = symbol(":")(s)?; @@ -253,7 +253,7 @@ pub fn case_pattern_item(s: Span) -> IResult { ))(s) } -#[parser] +#[parser(MaybeRecursive)] pub fn case_pattern_item_nondefault(s: Span) -> IResult { let (s, a) = pattern(s)?; let (s, b) = opt(pair(symbol("&&&"), expression))(s)?; @@ -275,7 +275,7 @@ pub fn case_inside_item(s: Span) -> IResult { ))(s) } -#[parser] +#[parser(MaybeRecursive)] pub fn case_inside_item_nondefault(s: Span) -> IResult { let (s, a) = open_range_list(s)?; let (s, b) = symbol(":")(s)?; @@ -306,7 +306,7 @@ pub fn randcase_statement(s: Span) -> IResult { )) } -#[parser] +#[parser(MaybeRecursive)] pub fn randcase_item(s: Span) -> IResult { let (s, a) = expression(s)?; let (s, b) = symbol(":")(s)?; @@ -314,7 +314,7 @@ pub fn randcase_item(s: Span) -> IResult { Ok((s, RandcaseItem { nodes: (a, b, c) })) } -#[parser] +#[parser(MaybeRecursive)] pub fn open_range_list(s: Span) -> IResult { let (s, a) = list(symbol(","), open_value_range)(s)?; Ok((s, OpenRangeList { nodes: (a,) })) diff --git a/src/parser/behavioral_statements/conditional_statements.rs b/src/parser/behavioral_statements/conditional_statements.rs index 72d1783..9e6b933 100644 --- a/src/parser/behavioral_statements/conditional_statements.rs +++ b/src/parser/behavioral_statements/conditional_statements.rs @@ -81,7 +81,7 @@ pub fn unique_priority(s: Span) -> IResult { ))(s) } -#[parser] +#[parser(MaybeRecursive)] pub fn cond_predicate(s: Span) -> IResult { let (s, a) = list(symbol("&&&"), expression_or_cond_pattern)(s)?; Ok((s, CondPredicate { nodes: (a,) })) @@ -95,7 +95,7 @@ pub fn expression_or_cond_pattern(s: Span) -> IResult IResult { let (s, a) = expression(s)?; let (s, b) = symbol("matches")(s)?; diff --git a/src/parser/behavioral_statements/continuous_assignment_and_net_alias_statements.rs b/src/parser/behavioral_statements/continuous_assignment_and_net_alias_statements.rs index f91dca3..bf8214b 100644 --- a/src/parser/behavioral_statements/continuous_assignment_and_net_alias_statements.rs +++ b/src/parser/behavioral_statements/continuous_assignment_and_net_alias_statements.rs @@ -97,13 +97,13 @@ pub fn continuous_assign_variable(s: Span) -> IResult { )) } -#[parser] +#[parser(MaybeRecursive)] pub fn list_of_net_assignments(s: Span) -> IResult { let (s, a) = list(symbol(","), net_assignment)(s)?; Ok((s, ListOfNetAssignments { nodes: (a,) })) } -#[parser] +#[parser(MaybeRecursive)] pub fn list_of_variable_assignments(s: Span) -> IResult { let (s, a) = list(symbol(","), variable_assignment)(s)?; Ok((s, ListOfVariableAssignments { nodes: (a,) })) @@ -125,7 +125,7 @@ pub fn net_alias(s: Span) -> IResult { )) } -#[parser] +#[parser(MaybeRecursive)] pub fn net_assignment(s: Span) -> IResult { let (s, a) = net_lvalue(s)?; let (s, b) = symbol("=")(s)?; diff --git a/src/parser/behavioral_statements/looping_statements.rs b/src/parser/behavioral_statements/looping_statements.rs index f1fe216..61132ab 100644 --- a/src/parser/behavioral_statements/looping_statements.rs +++ b/src/parser/behavioral_statements/looping_statements.rs @@ -217,7 +217,7 @@ pub fn for_initialization(s: Span) -> IResult { ))(s) } -#[parser] +#[parser(MaybeRecursive)] pub fn for_initialization_declaration(s: Span) -> IResult { let (s, a) = list(symbol(","), for_variable_declaration)(s)?; Ok(( @@ -243,7 +243,7 @@ pub fn var(s: Span) -> IResult { Ok((s, Var { nodes: (a,) })) } -#[parser] +#[parser(MaybeRecursive)] pub fn for_step(s: Span) -> IResult { let (s, a) = list(symbol(","), for_step_assignment)(s)?; Ok((s, ForStep { nodes: (a,) })) diff --git a/src/parser/behavioral_statements/procedural_blocks_and_assignments.rs b/src/parser/behavioral_statements/procedural_blocks_and_assignments.rs index d6d943b..f0ecdc0 100644 --- a/src/parser/behavioral_statements/procedural_blocks_and_assignments.rs +++ b/src/parser/behavioral_statements/procedural_blocks_and_assignments.rs @@ -173,7 +173,7 @@ pub fn blocking_assignment(s: Span) -> IResult { ))(s) } -#[parser] +#[parser(MaybeRecursive)] pub fn blocking_assignment_variable(s: Span) -> IResult { let (s, a) = variable_lvalue(s)?; let (s, b) = symbol("=")(s)?; @@ -187,7 +187,7 @@ pub fn blocking_assignment_variable(s: Span) -> IResult IResult { let (s, a) = nonrange_variable_lvalue(s)?; let (s, b) = symbol("=")(s)?; @@ -215,7 +215,7 @@ pub fn blocking_assignment_hierarchical_variable(s: Span) -> IResult IResult { let (s, a) = variable_lvalue(s)?; let (s, b) = assignment_operator(s)?; @@ -242,7 +242,7 @@ pub fn assignment_operator(s: Span) -> IResult { ))(s) } -#[parser] +#[parser(MaybeRecursive)] pub fn nonblocking_assignment(s: Span) -> IResult { let (s, a) = variable_lvalue(s)?; let (s, b) = symbol("<=")(s)?; @@ -352,7 +352,7 @@ pub fn procedural_continuous_assignment_release_net( )) } -#[parser] +#[parser(MaybeRecursive)] pub fn variable_assignment(s: Span) -> IResult { let (s, a) = variable_lvalue(s)?; let (s, b) = symbol("=")(s)?; diff --git a/src/parser/behavioral_statements/randsequence.rs b/src/parser/behavioral_statements/randsequence.rs index 2a251d9..7898b10 100644 --- a/src/parser/behavioral_statements/randsequence.rs +++ b/src/parser/behavioral_statements/randsequence.rs @@ -307,7 +307,7 @@ pub fn rs_case_item(s: Span) -> IResult { alt((rs_case_item_nondefault, rs_case_item_default))(s) } -#[parser] +#[parser(MaybeRecursive)] pub fn rs_case_item_nondefault(s: Span) -> IResult { let (s, a) = list(symbol(","), case_item_expression)(s)?; let (s, b) = symbol(":")(s)?; diff --git a/src/parser/behavioral_statements/statements.rs b/src/parser/behavioral_statements/statements.rs index 6cd02ca..4da95e4 100644 --- a/src/parser/behavioral_statements/statements.rs +++ b/src/parser/behavioral_statements/statements.rs @@ -93,7 +93,7 @@ pub fn statement_or_null_attribute(s: Span) -> IResult { )) } -#[parser] +#[parser(MaybeRecursive)] pub fn statement(s: Span) -> IResult { let (s, a) = opt(pair(block_identifier, symbol(":")))(s)?; let (s, b) = many0(attribute_instance)(s)?; diff --git a/src/parser/behavioral_statements/timing_control_statements.rs b/src/parser/behavioral_statements/timing_control_statements.rs index 6613250..e31dff9 100644 --- a/src/parser/behavioral_statements/timing_control_statements.rs +++ b/src/parser/behavioral_statements/timing_control_statements.rs @@ -334,7 +334,7 @@ pub fn event_expression(s: Span) -> IResult { ))(s) } -#[parser] +#[parser(MaybeRecursive)] pub fn event_expression_expression(s: Span) -> IResult { let (s, a) = opt(edge_identifier)(s)?; let (s, b) = expression(s)?; @@ -355,7 +355,7 @@ pub fn event_expression_sequence(s: Span) -> IResult { )) } -#[parser] +#[parser(MaybeRecursive)] pub fn event_expression_or(s: Span) -> IResult { let (s, a) = event_expression(s)?; let (s, b) = symbol("or")(s)?; @@ -366,7 +366,7 @@ pub fn event_expression_or(s: Span) -> IResult { )) } -#[parser] +#[parser(MaybeRecursive)] pub fn event_expression_comma(s: Span) -> IResult { let (s, a) = event_expression(s)?; let (s, b) = symbol(",")(s)?; diff --git a/src/parser/declarations/assertion_declarations.rs b/src/parser/declarations/assertion_declarations.rs index cac1c0c..3a98563 100644 --- a/src/parser/declarations/assertion_declarations.rs +++ b/src/parser/declarations/assertion_declarations.rs @@ -898,7 +898,7 @@ pub fn property_list_of_arguments(s: Span) -> IResult IResult { let (s, a) = list(symbol(","), opt(property_actual_arg))(s)?; let (s, b) = many0(tuple(( @@ -1007,7 +1007,7 @@ pub fn property_formal_type(s: Span) -> IResult { ))(s) } -#[parser] +#[parser(MaybeRecursive)] pub fn property_spec(s: Span) -> IResult { let (s, a) = opt(clocking_event)(s)?; let (s, b) = opt(triple( @@ -1101,7 +1101,7 @@ pub fn property_expr_not(s: Span) -> IResult { )) } -#[parser] +#[parser(MaybeRecursive)] pub fn property_expr_or(s: Span) -> IResult { let (s, a) = property_expr(s)?; let (s, b) = symbol("or")(s)?; @@ -1112,7 +1112,7 @@ pub fn property_expr_or(s: Span) -> IResult { )) } -#[parser] +#[parser(MaybeRecursive)] pub fn property_expr_and(s: Span) -> IResult { let (s, a) = property_expr(s)?; let (s, b) = symbol("and")(s)?; @@ -1123,7 +1123,7 @@ pub fn property_expr_and(s: Span) -> IResult { )) } -#[parser] +#[parser(MaybeRecursive)] pub fn property_expr_implication_overlapped(s: Span) -> IResult { let (s, a) = sequence_expr(s)?; let (s, b) = symbol("|->")(s)?; @@ -1136,7 +1136,7 @@ pub fn property_expr_implication_overlapped(s: Span) -> IResult IResult { let (s, a) = sequence_expr(s)?; let (s, b) = symbol("|=>")(s)?; @@ -1178,7 +1178,7 @@ pub fn property_expr_case(s: Span) -> IResult { )) } -#[parser] +#[parser(MaybeRecursive)] pub fn property_expr_followed_by_overlapped(s: Span) -> IResult { let (s, a) = sequence_expr(s)?; let (s, b) = symbol("#-#")(s)?; @@ -1191,7 +1191,7 @@ pub fn property_expr_followed_by_overlapped(s: Span) -> IResult IResult { let (s, a) = sequence_expr(s)?; let (s, b) = symbol("#=#")(s)?; @@ -1270,7 +1270,7 @@ pub fn property_expr_s_eventually(s: Span) -> IResult { )) } -#[parser] +#[parser(MaybeRecursive)] pub fn property_expr_until(s: Span) -> IResult { let (s, a) = property_expr(s)?; let (s, b) = symbol("until")(s)?; @@ -1281,7 +1281,7 @@ pub fn property_expr_until(s: Span) -> IResult { )) } -#[parser] +#[parser(MaybeRecursive)] pub fn property_expr_s_until(s: Span) -> IResult { let (s, a) = property_expr(s)?; let (s, b) = symbol("s_until")(s)?; @@ -1292,7 +1292,7 @@ pub fn property_expr_s_until(s: Span) -> IResult { )) } -#[parser] +#[parser(MaybeRecursive)] pub fn property_expr_until_with(s: Span) -> IResult { let (s, a) = property_expr(s)?; let (s, b) = symbol("until_with")(s)?; @@ -1303,7 +1303,7 @@ pub fn property_expr_until_with(s: Span) -> IResult { )) } -#[parser] +#[parser(MaybeRecursive)] pub fn property_expr_s_until_with(s: Span) -> IResult { let (s, a) = property_expr(s)?; let (s, b) = symbol("s_until_with")(s)?; @@ -1314,7 +1314,7 @@ pub fn property_expr_s_until_with(s: Span) -> IResult { )) } -#[parser] +#[parser(MaybeRecursive)] pub fn property_expr_implies(s: Span) -> IResult { let (s, a) = property_expr(s)?; let (s, b) = symbol("implies")(s)?; @@ -1325,7 +1325,7 @@ pub fn property_expr_implies(s: Span) -> IResult { )) } -#[parser] +#[parser(MaybeRecursive)] pub fn property_expr_iff(s: Span) -> IResult { let (s, a) = property_expr(s)?; let (s, b) = symbol("iff")(s)?; @@ -1395,7 +1395,7 @@ pub fn property_case_item(s: Span) -> IResult { alt((property_case_item_nondefault, property_case_item_default))(s) } -#[parser] +#[parser(MaybeRecursive)] pub fn property_case_item_nondefault(s: Span) -> IResult { let (s, a) = list(symbol(","), expression_or_dist)(s)?; let (s, b) = symbol(":")(s)?; @@ -1513,7 +1513,7 @@ pub fn sequence_expr_cycle_delay_expr(s: Span) -> IResult { )) } -#[parser] +#[parser(MaybeRecursive)] pub fn sequence_expr_expr_cycle_delay_expr(s: Span) -> IResult { let (s, a) = sequence_expr(s)?; let (s, b) = cycle_delay_range(s)?; @@ -1527,7 +1527,7 @@ pub fn sequence_expr_expr_cycle_delay_expr(s: Span) -> IResult IResult { let (s, a) = expression_or_dist(s)?; let (s, b) = opt(boolean_abbrev)(s)?; @@ -1560,7 +1560,7 @@ pub fn sequence_expr_paren(s: Span) -> IResult { )) } -#[parser] +#[parser(MaybeRecursive)] pub fn sequence_expr_and(s: Span) -> IResult { let (s, a) = sequence_expr(s)?; let (s, b) = symbol("and")(s)?; @@ -1571,7 +1571,7 @@ pub fn sequence_expr_and(s: Span) -> IResult { )) } -#[parser] +#[parser(MaybeRecursive)] pub fn sequence_expr_intersect(s: Span) -> IResult { let (s, a) = sequence_expr(s)?; let (s, b) = symbol("intersect")(s)?; @@ -1582,7 +1582,7 @@ pub fn sequence_expr_intersect(s: Span) -> IResult { )) } -#[parser] +#[parser(MaybeRecursive)] pub fn sequence_expr_or(s: Span) -> IResult { let (s, a) = sequence_expr(s)?; let (s, b) = symbol("or")(s)?; @@ -1606,7 +1606,7 @@ pub fn sequence_expr_first_match(s: Span) -> IResult { )) } -#[parser] +#[parser(MaybeRecursive)] pub fn sequence_expr_throughout(s: Span) -> IResult { let (s, a) = expression_or_dist(s)?; let (s, b) = symbol("throughout")(s)?; @@ -1617,7 +1617,7 @@ pub fn sequence_expr_throughout(s: Span) -> IResult { )) } -#[parser] +#[parser(MaybeRecursive)] pub fn sequence_expr_within(s: Span) -> IResult { let (s, a) = sequence_expr(s)?; let (s, b) = symbol("within")(s)?; @@ -1724,7 +1724,7 @@ pub fn sequence_list_of_arguments(s: Span) -> IResult IResult { let (s, a) = list(symbol(","), opt(sequence_actual_arg))(s)?; let (s, b) = many0(tuple(( @@ -1848,7 +1848,7 @@ pub fn cycle_delay_const_range_expression( ))(s) } -#[parser] +#[parser(MaybeRecursive)] pub fn cycle_delay_const_range_expression_binary( s: Span, ) -> IResult { @@ -1863,7 +1863,7 @@ pub fn cycle_delay_const_range_expression_binary( )) } -#[parser] +#[parser(MaybeRecursive)] pub fn cycle_delay_const_range_expression_dollar( s: Span, ) -> IResult { @@ -1878,7 +1878,7 @@ pub fn cycle_delay_const_range_expression_dollar( )) } -#[parser] +#[parser(MaybeRecursive)] pub fn expression_or_dist(s: Span) -> IResult { let (s, a) = expression(s)?; let (s, b) = opt(pair(symbol("dist"), brace(dist_list)))(s)?; diff --git a/src/parser/declarations/block_item_declarations.rs b/src/parser/declarations/block_item_declarations.rs index df8ce96..e820799 100644 --- a/src/parser/declarations/block_item_declarations.rs +++ b/src/parser/declarations/block_item_declarations.rs @@ -54,7 +54,7 @@ pub fn block_item_declaration(s: Span) -> IResult { ))(s) } -#[parser] +#[parser(MaybeRecursive)] pub fn block_item_declaration_data(s: Span) -> IResult { let (s, a) = many0(attribute_instance)(s)?; let (s, b) = data_declaration(s)?; diff --git a/src/parser/declarations/covergroup_declarations.rs b/src/parser/declarations/covergroup_declarations.rs index d33a00f..0736eb7 100644 --- a/src/parser/declarations/covergroup_declarations.rs +++ b/src/parser/declarations/covergroup_declarations.rs @@ -647,7 +647,7 @@ pub fn block_event_expression(s: Span) -> IResult { ))(s) } -#[parser] +#[parser(MaybeRecursive)] pub fn block_event_expression_or(s: Span) -> IResult { let (s, a) = block_event_expression(s)?; let (s, b) = symbol("or")(s)?; @@ -891,7 +891,7 @@ pub fn trans_list(s: Span) -> IResult { Ok((s, TransList { nodes: (a,) })) } -#[parser] +#[parser(MaybeRecursive)] pub fn trans_set(s: Span) -> IResult { let (s, a) = list(symbol("=>"), trans_range_list)(s)?; Ok((s, TransSet { nodes: (a,) })) @@ -907,7 +907,7 @@ pub fn trans_range_list(s: Span) -> IResult { ))(s) } -#[parser] +#[parser(MaybeRecursive)] pub fn trans_range_list_asterisk(s: Span) -> IResult { let (s, a) = trans_item(s)?; let (s, b) = bracket(pair(symbol("*"), repeat_range))(s)?; @@ -917,7 +917,7 @@ pub fn trans_range_list_asterisk(s: Span) -> IResult { )) } -#[parser] +#[parser(MaybeRecursive)] pub fn trans_range_list_arrow(s: Span) -> IResult { let (s, a) = trans_item(s)?; let (s, b) = bracket(pair(symbol("->"), repeat_range))(s)?; @@ -927,7 +927,7 @@ pub fn trans_range_list_arrow(s: Span) -> IResult { )) } -#[parser] +#[parser(MaybeRecursive)] pub fn trans_range_list_equal(s: Span) -> IResult { let (s, a) = trans_item(s)?; let (s, b) = bracket(pair(symbol("="), repeat_range))(s)?; @@ -953,7 +953,7 @@ pub fn repeat_range(s: Span) -> IResult { ))(s) } -#[parser] +#[parser(MaybeRecursive)] pub fn repeat_range_binary(s: Span) -> IResult { let (s, a) = covergroup_expression(s)?; let (s, b) = symbol(":")(s)?; @@ -1089,7 +1089,7 @@ pub fn select_expression_not(s: Span) -> IResult { )) } -#[parser] +#[parser(MaybeRecursive)] pub fn select_expression_and(s: Span) -> IResult { let (s, a) = select_expression(s)?; let (s, b) = symbol("&&")(s)?; @@ -1100,7 +1100,7 @@ pub fn select_expression_and(s: Span) -> IResult { )) } -#[parser] +#[parser(MaybeRecursive)] pub fn select_expression_or(s: Span) -> IResult { let (s, a) = select_expression(s)?; let (s, b) = symbol("||")(s)?; @@ -1120,7 +1120,7 @@ pub fn select_expression_paren(s: Span) -> IResult { )) } -#[parser] +#[parser(MaybeRecursive)] pub fn select_expression_with(s: Span) -> IResult { let (s, a) = select_expression(s)?; let (s, b) = symbol("with")(s)?; @@ -1134,7 +1134,7 @@ pub fn select_expression_with(s: Span) -> IResult { )) } -#[parser] +#[parser(MaybeRecursive)] pub fn select_expression_cross_set(s: Span) -> IResult { let (s, a) = cross_set_expression(s)?; let (s, b) = opt(pair(symbol("matches"), integer_covergroup_expression))(s)?; @@ -1172,7 +1172,7 @@ pub fn bins_expression_cover_point(s: Span) -> IResult { )) } -#[parser] +#[parser(MaybeRecursive)] pub fn covergroup_range_list(s: Span) -> IResult { let (s, a) = list(symbol(","), covergroup_value_range)(s)?; Ok((s, CovergroupRangeList { nodes: (a,) })) diff --git a/src/parser/declarations/let_declarations.rs b/src/parser/declarations/let_declarations.rs index 36b14c0..f16703e 100644 --- a/src/parser/declarations/let_declarations.rs +++ b/src/parser/declarations/let_declarations.rs @@ -162,7 +162,7 @@ pub fn let_list_of_arguments(s: Span) -> IResult { alt((let_list_of_arguments_ordered, let_list_of_arguments_named))(s) } -#[parser] +#[parser(MaybeRecursive)] pub fn let_list_of_arguments_ordered(s: Span) -> IResult { let (s, a) = list(symbol(","), opt(let_actual_arg))(s)?; let (s, b) = many0(tuple(( diff --git a/src/parser/expressions/concatenations.rs b/src/parser/expressions/concatenations.rs index 77be227..8536dc9 100644 --- a/src/parser/expressions/concatenations.rs +++ b/src/parser/expressions/concatenations.rs @@ -175,7 +175,7 @@ pub fn stream_concatenation(s: Span) -> IResult { Ok((s, StreamConcatenation { nodes: (a,) })) } -#[parser] +#[parser(MaybeRecursive)] pub fn stream_expression(s: Span) -> IResult { let (s, a) = expression(s)?; let (s, b) = opt(pair(symbol("with"), bracket(array_range_expression)))(s)?; @@ -192,7 +192,7 @@ pub fn array_range_expression(s: Span) -> IResult { ))(s) } -#[parser] +#[parser(MaybeRecursive)] pub fn array_range_expression_colon(s: Span) -> IResult { let (s, a) = expression(s)?; let (s, b) = symbol(":")(s)?; @@ -203,7 +203,7 @@ pub fn array_range_expression_colon(s: Span) -> IResult IResult { let (s, a) = expression(s)?; let (s, b) = symbol("+:")(s)?; @@ -214,7 +214,7 @@ pub fn array_range_expression_plus_colon(s: Span) -> IResult IResult { let (s, a) = expression(s)?; let (s, b) = symbol("-:")(s)?; diff --git a/src/parser/expressions/expression_leftside_values.rs b/src/parser/expressions/expression_leftside_values.rs index 9d86e0a..5c9859a 100644 --- a/src/parser/expressions/expression_leftside_values.rs +++ b/src/parser/expressions/expression_leftside_values.rs @@ -156,6 +156,41 @@ pub fn nonrange_variable_lvalue(s: Span) -> IResult { + Expr(Box>), + Term(ExprTerm<'a>), +} + +#[derive(Debug, Node)] +pub struct ExprExpr<'a> { + pub nodes: (Expr<'a>, Symbol<'a>, Expr<'a>), +} + +#[derive(Debug, Node)] +pub struct ExprTerm<'a> { + pub nodes: (Identifier<'a>,), +} + +#[parser] +pub fn expr(s: Span) -> IResult { + alt((expr_expr, expr_term))(s) +} + +#[parser(MaybeRecursive)] +pub fn expr_expr(s: Span) -> IResult { + let (s, a) = expr(s)?; + let (s, b) = symbol("+")(s)?; + let (s, c) = expr(s)?; + Ok((s, Expr::Expr(Box::new(ExprExpr { nodes: (a, b, c) })))) +} + +#[parser] +pub fn expr_term(s: Span) -> IResult { + let (s, a) = identifier(s)?; + Ok((s, Expr::Term(ExprTerm { nodes: (a,) }))) +} + // ----------------------------------------------------------------------------- #[cfg(test)] @@ -184,4 +219,10 @@ mod tests { //parser_test!(nonrange_variable_lvalue, "A[][2][3]", Ok((_, _))); //parser_test!(nonrange_variable_lvalue, "A[][]", Ok((_, _))); } + + #[test] + fn test_expr() { + parser_test!(expr, "A", Ok((_, _))); + parser_test!(expr, "A+B", Ok((_, _))); + } } diff --git a/src/parser/expressions/expressions.rs b/src/parser/expressions/expressions.rs index e5e34a4..4706eb9 100644 --- a/src/parser/expressions/expressions.rs +++ b/src/parser/expressions/expressions.rs @@ -295,7 +295,7 @@ pub fn inc_or_dec_expression_prefix(s: Span) -> IResult IResult { let (s, a) = variable_lvalue(s)?; let (s, b) = many0(attribute_instance)(s)?; @@ -306,7 +306,7 @@ pub fn inc_or_dec_expression_suffix(s: Span) -> IResult IResult { let (s, a) = cond_predicate(s)?; let (s, b) = symbol("?")(s)?; @@ -345,7 +345,7 @@ pub fn constant_expression_unary(s: Span) -> IResult { )) } -#[parser] +#[parser(MaybeRecursive)] pub fn constant_expression_binary(s: Span) -> IResult { let (s, a) = constant_expression(s)?; let (s, b) = binary_operator(s)?; @@ -359,7 +359,7 @@ pub fn constant_expression_binary(s: Span) -> IResult )) } -#[parser] +#[parser(MaybeRecursive)] pub fn constant_expression_ternary(s: Span) -> IResult { let (s, a) = constant_expression(s)?; let (s, b) = symbol("?")(s)?; @@ -385,7 +385,7 @@ pub fn constant_mintypmax_expression(s: Span) -> IResult IResult { @@ -448,7 +448,7 @@ pub fn constant_part_select_range(s: Span) -> IResult IResult { let (s, a) = constant_expression(s)?; let (s, b) = symbol(":")(s)?; @@ -456,7 +456,7 @@ pub fn constant_range(s: Span) -> IResult { Ok((s, ConstantRange { nodes: (a, b, c) })) } -#[parser] +#[parser(MaybeRecursive)] pub fn constant_indexed_range(s: Span) -> IResult { let (s, a) = constant_expression(s)?; let (s, b) = alt((symbol("+:"), symbol("-:")))(s)?; @@ -506,7 +506,7 @@ pub fn expression_operator_assignment(s: Span) -> IResult { )) } -#[parser] +#[parser(MaybeRecursive)] pub fn expression_binary(s: Span) -> IResult { let (s, a) = expression(s)?; let (s, b) = binary_operator(s)?; @@ -528,7 +528,7 @@ pub fn tagged_union_expression(s: Span) -> IResult Ok((s, TaggedUnionExpression { nodes: (a, b, c) })) } -#[parser] +#[parser(MaybeRecursive)] pub fn inside_expression(s: Span) -> IResult { let (s, a) = expression(s)?; let (s, b) = symbol("inside")(s)?; @@ -558,7 +558,7 @@ pub fn mintypmax_expression(s: Span) -> IResult { ))(s) } -#[parser] +#[parser(MaybeRecursive)] pub fn mintypmax_expression_ternary(s: Span) -> IResult { let (s, a) = expression(s)?; let (s, b) = symbol(":")(s)?; @@ -573,7 +573,7 @@ pub fn mintypmax_expression_ternary(s: Span) -> IResult IResult { @@ -616,7 +616,7 @@ pub fn module_path_expression_unary(s: Span) -> IResult IResult { let (s, a) = module_path_expression(s)?; let (s, b) = binary_module_path_operator(s)?; @@ -640,7 +640,7 @@ pub fn module_path_mintypmax_expression(s: Span) -> IResult IResult { @@ -665,7 +665,7 @@ pub fn part_select_range(s: Span) -> IResult { ))(s) } -#[parser] +#[parser(MaybeRecursive)] pub fn indexed_range(s: Span) -> IResult { let (s, a) = expression(s)?; let (s, b) = alt((symbol("+:"), symbol("-:")))(s)?; diff --git a/src/parser/expressions/primaries.rs b/src/parser/expressions/primaries.rs index e7d8a73..29c0ee7 100644 --- a/src/parser/expressions/primaries.rs +++ b/src/parser/expressions/primaries.rs @@ -466,7 +466,7 @@ pub fn class_qualifier_or_package_scope(s: Span) -> IResult IResult { let (s, a) = opt(local)(s)?; let (s, b) = opt(implicit_class_handle_or_class_scope)(s)?; @@ -589,7 +589,7 @@ pub fn constant_select(s: Span) -> IResult { Ok((s, ConstantSelect { nodes: (a, b, c) })) } -#[parser] +#[parser(MaybeRecursive)] pub fn constant_cast(s: Span) -> IResult { let (s, a) = casting_type(s)?; let (s, b) = symbol("'")(s)?; @@ -603,7 +603,7 @@ pub fn constant_let_expression(s: Span) -> IResult Ok((s, ConstantLetExpression { nodes: (a,) })) } -#[parser] +#[parser(MaybeRecursive)] pub fn cast(s: Span) -> IResult { let (s, a) = casting_type(s)?; let (s, b) = symbol("'")(s)?; diff --git a/src/parser/expressions/subroutine_calls.rs b/src/parser/expressions/subroutine_calls.rs index f16b3ed..98bf8bb 100644 --- a/src/parser/expressions/subroutine_calls.rs +++ b/src/parser/expressions/subroutine_calls.rs @@ -272,7 +272,7 @@ pub fn list_of_arguments(s: Span) -> IResult { alt((list_of_arguments_ordered, list_of_arguments_named))(s) } -#[parser] +#[parser(MaybeRecursive)] pub fn list_of_arguments_ordered(s: Span) -> IResult { let (s, a) = list(symbol(","), opt(expression))(s)?; let (s, b) = many0(tuple(( @@ -306,7 +306,7 @@ pub fn list_of_arguments_named(s: Span) -> IResult { )) } -#[parser] +#[parser(MaybeRecursive)] pub fn method_call(s: Span) -> IResult { let (s, a) = method_call_root(s)?; let (s, b) = symbol(".")(s)?; diff --git a/src/parser/instantiations/checker_instantiation.rs b/src/parser/instantiations/checker_instantiation.rs index ce1a1ce..ed951c1 100644 --- a/src/parser/instantiations/checker_instantiation.rs +++ b/src/parser/instantiations/checker_instantiation.rs @@ -83,7 +83,7 @@ pub fn list_of_checker_port_connections(s: Span) -> IResult IResult { @@ -105,7 +105,7 @@ pub fn list_of_checker_port_connections_named( )) } -#[parser] +#[parser(MaybeRecursive)] pub fn ordered_checker_port_connection(s: Span) -> IResult { let (s, x) = many0(attribute_instance)(s)?; let (s, y) = opt(property_actual_arg)(s)?; diff --git a/src/parser/instantiations/generated_instantiation.rs b/src/parser/instantiations/generated_instantiation.rs index 0ff5ee3..751f2cf 100644 --- a/src/parser/instantiations/generated_instantiation.rs +++ b/src/parser/instantiations/generated_instantiation.rs @@ -266,7 +266,7 @@ pub fn case_generate_item(s: Span) -> IResult { alt((case_generate_item_nondefault, case_generate_item_default))(s) } -#[parser] +#[parser(MaybeRecursive)] pub fn case_generate_item_nondefault(s: Span) -> IResult { let (s, a) = list(symbol(","), constant_expression)(s)?; let (s, b) = symbol(":")(s)?; diff --git a/src/parser/instantiations/module_instantiation.rs b/src/parser/instantiations/module_instantiation.rs index b44e978..9194ede 100644 --- a/src/parser/instantiations/module_instantiation.rs +++ b/src/parser/instantiations/module_instantiation.rs @@ -141,7 +141,7 @@ pub fn list_of_parameter_assignments(s: Span) -> IResult IResult { let (s, a) = list(symbol(","), ordered_parameter_assignment)(s)?; Ok(( @@ -195,7 +195,7 @@ pub fn list_of_port_connections(s: Span) -> IResult ))(s) } -#[parser] +#[parser(MaybeRecursive)] pub fn list_of_port_connections_ordered(s: Span) -> IResult { let (s, a) = list(symbol(","), ordered_port_connection)(s)?; Ok(( @@ -213,7 +213,7 @@ pub fn list_of_port_connections_named(s: Span) -> IResult IResult { let (s, x) = many0(attribute_instance)(s)?; let (s, y) = opt(expression)(s)?; diff --git a/src/parser/source_text/constraints.rs b/src/parser/source_text/constraints.rs index cc0059b..8572e8a 100644 --- a/src/parser/source_text/constraints.rs +++ b/src/parser/source_text/constraints.rs @@ -270,7 +270,7 @@ pub fn constraint_expression(s: Span) -> IResult { ))(s) } -#[parser] +#[parser(MaybeRecursive)] pub fn constraint_expression_expression(s: Span) -> IResult { let (s, a) = opt(soft)(s)?; let (s, b) = expression_or_dist(s)?; @@ -287,7 +287,7 @@ pub fn soft(s: Span) -> IResult { Ok((s, Soft { nodes: (a,) })) } -#[parser] +#[parser(MaybeRecursive)] pub fn constraint_expression_arrow(s: Span) -> IResult { let (s, a) = expression(s)?; let (s, b) = symbol("->")(s)?; @@ -363,13 +363,13 @@ pub fn constraint_set_brace(s: Span) -> IResult { Ok((s, ConstraintSet::Brace(ConstraintSetBrace { nodes: (a,) }))) } -#[parser] +#[parser(MaybeRecursive)] pub fn dist_list(s: Span) -> IResult { let (s, a) = list(symbol(","), dist_item)(s)?; Ok((s, DistList { nodes: (a,) })) } -#[parser] +#[parser(MaybeRecursive)] pub fn dist_item(s: Span) -> IResult { let (s, a) = value_range(s)?; let (s, b) = opt(dist_weight)(s)?; diff --git a/src/parser/source_text/interface_items.rs b/src/parser/source_text/interface_items.rs index 653a0e6..e7c3962 100644 --- a/src/parser/source_text/interface_items.rs +++ b/src/parser/source_text/interface_items.rs @@ -66,7 +66,7 @@ pub fn interface_or_generate_item(s: Span) -> IResult IResult { let (s, a) = many0(attribute_instance)(s)?; let (s, b) = module_common_item(s)?; diff --git a/src/parser/source_text/module_items.rs b/src/parser/source_text/module_items.rs index d21dc72..8b13766 100644 --- a/src/parser/source_text/module_items.rs +++ b/src/parser/source_text/module_items.rs @@ -374,7 +374,7 @@ pub fn module_or_generate_item_module(s: Span) -> IResult IResult { let (s, a) = many0(attribute_instance)(s)?; let (s, b) = module_common_item(s)?; diff --git a/src/parser/source_text/module_parameters_and_ports.rs b/src/parser/source_text/module_parameters_and_ports.rs index b053db2..74d19f8 100644 --- a/src/parser/source_text/module_parameters_and_ports.rs +++ b/src/parser/source_text/module_parameters_and_ports.rs @@ -373,7 +373,7 @@ pub fn port(s: Span) -> IResult { alt((port_non_named, port_named))(s) } -#[parser] +#[parser(MaybeRecursive)] pub fn port_non_named(s: Span) -> IResult { let (s, a) = opt(port_expression)(s)?; Ok((s, Port::NonNamed(PortNonNamed { nodes: (a,) }))) diff --git a/src/parser/source_text/program_items.rs b/src/parser/source_text/program_items.rs index 878760c..0396bcf 100644 --- a/src/parser/source_text/program_items.rs +++ b/src/parser/source_text/program_items.rs @@ -102,7 +102,7 @@ pub fn non_port_program_item_assign(s: Span) -> IResult IResult { let (s, a) = many0(attribute_instance)(s)?; let (s, b) = module_or_generate_item_declaration(s)?; diff --git a/src/parser/source_text/system_verilog_source_text.rs b/src/parser/source_text/system_verilog_source_text.rs index 43e157c..4b69c0d 100644 --- a/src/parser/source_text/system_verilog_source_text.rs +++ b/src/parser/source_text/system_verilog_source_text.rs @@ -460,7 +460,7 @@ pub fn description(s: Span) -> IResult { ))(s) } -#[parser] +#[parser(MaybeRecursive)] pub fn description_package_item(s: Span) -> IResult { let (s, a) = many0(attribute_instance)(s)?; let (s, b) = package_item(s)?; diff --git a/sv-parser-derive/src/lib.rs b/sv-parser-derive/src/lib.rs index 616d31e..f992dfb 100644 --- a/sv-parser-derive/src/lib.rs +++ b/sv-parser-derive/src/lib.rs @@ -4,7 +4,10 @@ extern crate proc_macro; use crate::proc_macro::TokenStream; use quote::quote; -use syn::{self, parse_macro_input, ItemFn}; +use syn::Data::{Enum, Struct}; +use syn::{ + self, parse_macro_input, AttributeArgs, DeriveInput, Expr, ItemFn, Meta, NestedMeta, Stmt, +}; #[proc_macro_derive(Node)] pub fn node_derive(input: TokenStream) -> TokenStream { @@ -12,11 +15,11 @@ pub fn node_derive(input: TokenStream) -> TokenStream { impl_node(&ast) } -fn impl_node(ast: &syn::DeriveInput) -> TokenStream { +fn impl_node(ast: &DeriveInput) -> TokenStream { let name = &ast.ident; let next = match ast.data { - syn::Data::Enum(ref data) => { + Enum(ref data) => { let mut items = quote! {}; for v in &data.variants { let ident = &v.ident; @@ -35,7 +38,7 @@ fn impl_node(ast: &syn::DeriveInput) -> TokenStream { } } } - syn::Data::Struct(_) => { + Struct(_) => { quote! { (&(self.nodes)).into() } @@ -79,9 +82,9 @@ pub fn any_node_derive(input: TokenStream) -> TokenStream { impl_any_node(&ast) } -fn impl_any_node(ast: &syn::DeriveInput) -> TokenStream { +fn impl_any_node(ast: &DeriveInput) -> TokenStream { let ref data = match ast.data { - syn::Data::Enum(ref data) => data, + Enum(ref data) => data, _ => unreachable!(), }; @@ -111,12 +114,15 @@ fn impl_any_node(ast: &syn::DeriveInput) -> TokenStream { } #[proc_macro_attribute] -pub fn parser(_attr: TokenStream, item: TokenStream) -> TokenStream { +pub fn parser(attr: TokenStream, item: TokenStream) -> TokenStream { + let attr = parse_macro_input!(attr as AttributeArgs); let item = parse_macro_input!(item as ItemFn); - impl_parser(&item) + impl_parser(&attr, &item) } -fn impl_parser(item: &syn::ItemFn) -> TokenStream { +fn impl_parser(attr: &AttributeArgs, item: &ItemFn) -> TokenStream { + let (maybe_recursive,) = impl_parser_attribute(attr); + let ident = &item.ident; let mut item = item.clone(); @@ -126,7 +132,7 @@ fn impl_parser(item: &syn::ItemFn) -> TokenStream { } }; let tracer: TokenStream = tracer.into(); - let tracer = parse_macro_input!(tracer as syn::Stmt); + let tracer = parse_macro_input!(tracer as Stmt); let checker = quote! { if thread_context::PARSER_INDEX.with(|p| { @@ -143,7 +149,7 @@ fn impl_parser(item: &syn::ItemFn) -> TokenStream { } }; let checker: TokenStream = checker.into(); - let checker = parse_macro_input!(checker as syn::Stmt); + let checker = parse_macro_input!(checker as Stmt); let before = quote! { let s = thread_context::PARSER_INDEX.with(|p| { @@ -158,7 +164,7 @@ fn impl_parser(item: &syn::ItemFn) -> TokenStream { }); }; let before: TokenStream = before.into(); - let before = parse_macro_input!(before as syn::Stmt); + let before = parse_macro_input!(before as Stmt); let mut body = quote! {}; for s in &item.block.stmts { @@ -171,19 +177,21 @@ fn impl_parser(item: &syn::ItemFn) -> TokenStream { let (s, ret) = { #body }?; }; let body: TokenStream = body.into(); - let body = parse_macro_input!(body as syn::Stmt); + let body = parse_macro_input!(body as Stmt); let after = quote! { Ok((clear_bit(s), ret)) }; let after: TokenStream = after.into(); - let after = parse_macro_input!(after as syn::Expr); - let after = syn::Stmt::Expr(after); + let after = parse_macro_input!(after as Expr); + let after = Stmt::Expr(after); item.block.stmts.clear(); item.block.stmts.push(tracer); - item.block.stmts.push(checker); - item.block.stmts.push(before); + if maybe_recursive { + item.block.stmts.push(checker); + item.block.stmts.push(before); + } item.block.stmts.push(body); item.block.stmts.push(after); @@ -192,3 +200,16 @@ fn impl_parser(item: &syn::ItemFn) -> TokenStream { }; gen.into() } + +fn impl_parser_attribute(attr: &AttributeArgs) -> (bool,) { + let mut maybe_recursive = false; + + for a in attr { + match a { + NestedMeta::Meta(Meta::Word(x)) if x == "MaybeRecursive" => maybe_recursive = true, + _ => panic!(), + } + } + + (maybe_recursive,) +}