diff --git a/Cargo.toml b/Cargo.toml index 0c50830..d788e76 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,4 +5,3 @@ members = [ "sv-parser-parser", "sv-parser-macros", ] - diff --git a/sv-parser-macros/src/lib.rs b/sv-parser-macros/src/lib.rs index 89bfd12..fb72fb7 100644 --- a/sv-parser-macros/src/lib.rs +++ b/sv-parser-macros/src/lib.rs @@ -6,9 +6,7 @@ use crate::proc_macro::TokenStream; use quote::quote; use std::str::FromStr; use syn::Data::{Enum, Struct}; -use syn::{ - self, parse_macro_input, AttributeArgs, DeriveInput, Expr, ItemFn, Meta, NestedMeta, Stmt, -}; +use syn::{self, parse_macro_input, AttributeArgs, DeriveInput, ItemFn, Meta, NestedMeta, Stmt}; #[proc_macro_derive(Node)] pub fn node_derive(input: TokenStream) -> TokenStream { @@ -166,17 +164,11 @@ pub fn parser(attr: TokenStream, item: TokenStream) -> TokenStream { } fn impl_parser(attr: &AttributeArgs, item: &ItemFn) -> TokenStream { - let (maybe_recursive, ambiguous) = impl_parser_attribute(attr); + let ambiguous = impl_parser_attribute(attr); let trace = impl_parser_trace(&item); let trace = parse_macro_input!(trace as Stmt); - let check_recursive_flag = impl_parser_check_recursive_flag(&item); - let check_recursive_flag = parse_macro_input!(check_recursive_flag as Stmt); - - let set_recursive_flag = impl_parser_set_recursive_flag(&item); - let set_recursive_flag = parse_macro_input!(set_recursive_flag as Stmt); - let body = if ambiguous { impl_parser_body_ambiguous(&item) } else { @@ -184,24 +176,11 @@ fn impl_parser(attr: &AttributeArgs, item: &ItemFn) -> TokenStream { }; let body = parse_macro_input!(body as Stmt); - let body_unwrap = impl_parser_body_unwrap(&item); - let body_unwrap = parse_macro_input!(body_unwrap as Stmt); - - let clear_recursive_flags = impl_parser_clear_recursive_flags(&item); - let clear_recursive_flags = parse_macro_input!(clear_recursive_flags as Expr); - let clear_recursive_flags = Stmt::Expr(clear_recursive_flags); - let mut item = item.clone(); item.block.stmts.clear(); item.block.stmts.push(trace); - if maybe_recursive { - item.block.stmts.push(check_recursive_flag); - item.block.stmts.push(set_recursive_flag); - } item.block.stmts.push(body); - item.block.stmts.push(body_unwrap); - item.block.stmts.push(clear_recursive_flags); let gen = quote! { #item @@ -209,19 +188,17 @@ fn impl_parser(attr: &AttributeArgs, item: &ItemFn) -> TokenStream { gen.into() } -fn impl_parser_attribute(attr: &AttributeArgs) -> (bool, bool) { - let mut maybe_recursive = false; +fn impl_parser_attribute(attr: &AttributeArgs) -> bool { let mut ambiguous = false; for a in attr { match a { - NestedMeta::Meta(Meta::Word(x)) if x == "MaybeRecursive" => maybe_recursive = true, NestedMeta::Meta(Meta::Word(x)) if x == "Ambiguous" => ambiguous = true, _ => panic!(), } } - (maybe_recursive, ambiguous) + ambiguous } fn impl_parser_trace(item: &ItemFn) -> TokenStream { @@ -234,42 +211,6 @@ fn impl_parser_trace(item: &ItemFn) -> TokenStream { gen.into() } -fn impl_parser_check_recursive_flag(item: &ItemFn) -> TokenStream { - let ident = &item.ident; - - let gen = quote! { - if thread_context::PARSER_INDEX.with(|p| { - if let Some(i) = p.borrow_mut().get(stringify!(#ident)) { - return check_recursive_flag(s, i); - } else { - return false - } - }) { - #[cfg(feature = "trace")] - println!("{:<128} : loop detect", format!("{}{}", " ".repeat(s.extra.depth), stringify!(#ident))); - return Err(nom::Err::Error(nom::error::make_error(s, nom::error::ErrorKind::Fix))); - } - }; - gen.into() -} - -fn impl_parser_set_recursive_flag(item: &ItemFn) -> TokenStream { - let ident = &item.ident; - - let gen = quote! { - let s = thread_context::PARSER_INDEX.with(|p| { - if let Some(i) = p.borrow_mut().get(stringify!(#ident)) { - set_recursive_flag(s, i, true) - } else { - #[cfg(feature = "trace")] - println!("{:<128} : allocate failed", format!("{}{}", " ".repeat(s.extra.depth), stringify!(#ident))); - s - } - }); - }; - gen.into() -} - fn impl_parser_body(item: &ItemFn) -> TokenStream { let mut gen = quote! {}; for s in &item.block.stmts { @@ -279,7 +220,9 @@ fn impl_parser_body(item: &ItemFn) -> TokenStream { }; } let gen = quote! { - let body_ret = { #gen }; + { + #gen + } }; gen.into() } @@ -336,22 +279,10 @@ fn impl_parser_body_ambiguous(item: &ItemFn) -> TokenStream { }; let gen = quote! { - let body_ret = { #gen }; + { + #gen + } }; gen.into() } - -fn impl_parser_body_unwrap(_item: &ItemFn) -> TokenStream { - let gen = quote! { - let (s, ret) = body_ret?; - }; - gen.into() -} - -fn impl_parser_clear_recursive_flags(_item: &ItemFn) -> TokenStream { - let gen = quote! { - Ok((clear_recursive_flags(s), ret)) - }; - gen.into() -} diff --git a/sv-parser-parser/Cargo.toml b/sv-parser-parser/Cargo.toml index 2b0b1a2..199e5c5 100644 --- a/sv-parser-parser/Cargo.toml +++ b/sv-parser-parser/Cargo.toml @@ -6,11 +6,12 @@ edition = "2018" [features] default = [] -trace = [] +trace = ["sv-parser-syntaxtree/trace"] [dependencies] nom = "5.0.0" nom-packrat = "0.1.17" +nom-recursive = { path = "../../nom-recursive/nom-recursive" } str-concat = "*" sv-parser-syntaxtree = { path = "../sv-parser-syntaxtree" } sv-parser-macros = { path = "../sv-parser-macros" } diff --git a/sv-parser-parser/src/behavioral_statements/case_statements.rs b/sv-parser-parser/src/behavioral_statements/case_statements.rs index a44b94e..0575d2c 100644 --- a/sv-parser-parser/src/behavioral_statements/case_statements.rs +++ b/sv-parser-parser/src/behavioral_statements/case_statements.rs @@ -84,7 +84,8 @@ pub(crate) fn case_item(s: Span) -> IResult { ))(s) } -#[parser(MaybeRecursive)] +#[recursive_parser] +#[parser] pub(crate) fn case_item_nondefault(s: Span) -> IResult { let (s, a) = list(symbol(","), case_item_expression)(s)?; let (s, b) = symbol(":")(s)?; @@ -111,7 +112,8 @@ pub(crate) fn case_pattern_item(s: Span) -> IResult { ))(s) } -#[parser(MaybeRecursive)] +#[recursive_parser] +#[parser] pub(crate) fn case_pattern_item_nondefault(s: Span) -> IResult { let (s, a) = pattern(s)?; let (s, b) = opt(pair(symbol("&&&"), expression))(s)?; @@ -133,7 +135,8 @@ pub(crate) fn case_inside_item(s: Span) -> IResult { ))(s) } -#[parser(MaybeRecursive)] +#[recursive_parser] +#[parser] pub(crate) fn case_inside_item_nondefault(s: Span) -> IResult { let (s, a) = open_range_list(s)?; let (s, b) = symbol(":")(s)?; @@ -164,7 +167,8 @@ pub(crate) fn randcase_statement(s: Span) -> IResult { )) } -#[parser(MaybeRecursive)] +#[recursive_parser] +#[parser] pub(crate) fn randcase_item(s: Span) -> IResult { let (s, a) = expression(s)?; let (s, b) = symbol(":")(s)?; @@ -172,7 +176,8 @@ pub(crate) fn randcase_item(s: Span) -> IResult { Ok((s, RandcaseItem { nodes: (a, b, c) })) } -#[parser(MaybeRecursive)] +#[recursive_parser] +#[parser] pub(crate) fn open_range_list(s: Span) -> IResult { let (s, a) = list(symbol(","), open_value_range)(s)?; Ok((s, OpenRangeList { nodes: (a,) })) diff --git a/sv-parser-parser/src/behavioral_statements/conditional_statements.rs b/sv-parser-parser/src/behavioral_statements/conditional_statements.rs index 257e864..a7d03b7 100644 --- a/sv-parser-parser/src/behavioral_statements/conditional_statements.rs +++ b/sv-parser-parser/src/behavioral_statements/conditional_statements.rs @@ -35,7 +35,8 @@ pub(crate) fn unique_priority(s: Span) -> IResult { ))(s) } -#[parser(MaybeRecursive)] +#[recursive_parser] +#[parser] pub(crate) fn cond_predicate(s: Span) -> IResult { let (s, a) = list(symbol("&&&"), expression_or_cond_pattern)(s)?; Ok((s, CondPredicate { nodes: (a,) })) @@ -53,7 +54,8 @@ pub(crate) fn expression_or_cond_pattern(s: Span) -> IResult IResult { let (s, a) = expression(s)?; let (s, b) = keyword("matches")(s)?; diff --git a/sv-parser-parser/src/behavioral_statements/continuous_assignment_and_net_alias_statements.rs b/sv-parser-parser/src/behavioral_statements/continuous_assignment_and_net_alias_statements.rs index eb2b913..5a5f19b 100644 --- a/sv-parser-parser/src/behavioral_statements/continuous_assignment_and_net_alias_statements.rs +++ b/sv-parser-parser/src/behavioral_statements/continuous_assignment_and_net_alias_statements.rs @@ -38,13 +38,15 @@ pub(crate) fn continuous_assign_variable(s: Span) -> IResult IResult { let (s, a) = list(symbol(","), net_assignment)(s)?; Ok((s, ListOfNetAssignments { nodes: (a,) })) } -#[parser(MaybeRecursive)] +#[recursive_parser] +#[parser] pub(crate) fn list_of_variable_assignments(s: Span) -> IResult { let (s, a) = list(symbol(","), variable_assignment)(s)?; Ok((s, ListOfVariableAssignments { nodes: (a,) })) @@ -66,7 +68,8 @@ pub(crate) fn net_alias(s: Span) -> IResult { )) } -#[parser(MaybeRecursive)] +#[recursive_parser] +#[parser] pub(crate) fn net_assignment(s: Span) -> IResult { let (s, a) = net_lvalue(s)?; let (s, b) = symbol("=")(s)?; diff --git a/sv-parser-parser/src/behavioral_statements/looping_statements.rs b/sv-parser-parser/src/behavioral_statements/looping_statements.rs index 05b1cc1..bcdd733 100644 --- a/sv-parser-parser/src/behavioral_statements/looping_statements.rs +++ b/sv-parser-parser/src/behavioral_statements/looping_statements.rs @@ -102,7 +102,8 @@ pub(crate) fn for_initialization(s: Span) -> IResult { ))(s) } -#[parser(MaybeRecursive)] +#[recursive_parser] +#[parser] pub(crate) fn for_initialization_declaration(s: Span) -> IResult { let (s, a) = list(symbol(","), for_variable_declaration)(s)?; Ok(( @@ -128,7 +129,8 @@ pub(crate) fn var(s: Span) -> IResult { Ok((s, Var { nodes: (a,) })) } -#[parser(MaybeRecursive)] +#[recursive_parser] +#[parser] pub(crate) fn for_step(s: Span) -> IResult { let (s, a) = list(symbol(","), for_step_assignment)(s)?; Ok((s, ForStep { nodes: (a,) })) diff --git a/sv-parser-parser/src/behavioral_statements/procedural_blocks_and_assignments.rs b/sv-parser-parser/src/behavioral_statements/procedural_blocks_and_assignments.rs index 57e4a45..9066439 100644 --- a/sv-parser-parser/src/behavioral_statements/procedural_blocks_and_assignments.rs +++ b/sv-parser-parser/src/behavioral_statements/procedural_blocks_and_assignments.rs @@ -51,7 +51,8 @@ pub(crate) fn blocking_assignment(s: Span) -> IResult ))(s) } -#[parser(MaybeRecursive)] +#[recursive_parser] +#[parser] pub(crate) fn blocking_assignment_variable(s: Span) -> IResult { let (s, a) = variable_lvalue(s)?; let (s, b) = symbol("=")(s)?; @@ -65,7 +66,8 @@ pub(crate) fn blocking_assignment_variable(s: Span) -> IResult IResult { let (s, a) = nonrange_variable_lvalue(s)?; let (s, b) = symbol("=")(s)?; @@ -97,7 +99,8 @@ pub(crate) fn blocking_assignment_hierarchical_variable( )) } -#[parser(MaybeRecursive)] +#[recursive_parser] +#[parser] pub(crate) fn operator_assignment(s: Span) -> IResult { let (s, a) = variable_lvalue(s)?; let (s, b) = assignment_operator(s)?; @@ -124,7 +127,8 @@ pub(crate) fn assignment_operator(s: Span) -> IResult ))(s) } -#[parser(MaybeRecursive)] +#[recursive_parser] +#[parser] pub(crate) fn nonblocking_assignment(s: Span) -> IResult { let (s, a) = variable_lvalue(s)?; let (s, b) = symbol("<=")(s)?; @@ -236,7 +240,8 @@ pub(crate) fn procedural_continuous_assignment_release_net( )) } -#[parser(MaybeRecursive)] +#[recursive_parser] +#[parser] pub(crate) fn variable_assignment(s: Span) -> IResult { let (s, a) = variable_lvalue(s)?; let (s, b) = symbol("=")(s)?; diff --git a/sv-parser-parser/src/behavioral_statements/randsequence.rs b/sv-parser-parser/src/behavioral_statements/randsequence.rs index b676e02..ad2f718 100644 --- a/sv-parser-parser/src/behavioral_statements/randsequence.rs +++ b/sv-parser-parser/src/behavioral_statements/randsequence.rs @@ -163,7 +163,8 @@ pub(crate) fn rs_case_item(s: Span) -> IResult { alt((rs_case_item_nondefault, rs_case_item_default))(s) } -#[parser(MaybeRecursive)] +#[recursive_parser] +#[parser] pub(crate) 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/sv-parser-parser/src/behavioral_statements/statements.rs b/sv-parser-parser/src/behavioral_statements/statements.rs index 0e1418e..fe85fe4 100644 --- a/sv-parser-parser/src/behavioral_statements/statements.rs +++ b/sv-parser-parser/src/behavioral_statements/statements.rs @@ -20,7 +20,8 @@ pub(crate) fn statement_or_null_attribute(s: Span) -> IResult IResult { let (s, a) = opt(pair(block_identifier, symbol(":")))(s)?; let (s, b) = many0(attribute_instance)(s)?; diff --git a/sv-parser-parser/src/behavioral_statements/timing_control_statements.rs b/sv-parser-parser/src/behavioral_statements/timing_control_statements.rs index dffeb69..cd25c3e 100644 --- a/sv-parser-parser/src/behavioral_statements/timing_control_statements.rs +++ b/sv-parser-parser/src/behavioral_statements/timing_control_statements.rs @@ -129,7 +129,8 @@ pub(crate) fn event_expression(s: Span) -> IResult { ))(s) } -#[parser(MaybeRecursive)] +#[recursive_parser] +#[parser] pub(crate) fn event_expression_expression(s: Span) -> IResult { let (s, a) = opt(edge_identifier)(s)?; let (s, b) = expression(s)?; @@ -150,7 +151,8 @@ pub(crate) fn event_expression_sequence(s: Span) -> IResult IResult { let (s, a) = event_expression(s)?; let (s, b) = keyword("or")(s)?; @@ -161,7 +163,8 @@ pub(crate) fn event_expression_or(s: Span) -> IResult { )) } -#[parser(MaybeRecursive)] +#[recursive_parser] +#[parser] pub(crate) fn event_expression_comma(s: Span) -> IResult { let (s, a) = event_expression(s)?; let (s, b) = symbol(",")(s)?; diff --git a/sv-parser-parser/src/declarations/assertion_declarations.rs b/sv-parser-parser/src/declarations/assertion_declarations.rs index e3bcb59..a21ad63 100644 --- a/sv-parser-parser/src/declarations/assertion_declarations.rs +++ b/sv-parser-parser/src/declarations/assertion_declarations.rs @@ -150,7 +150,8 @@ pub(crate) fn property_list_of_arguments(s: Span) -> IResult IResult { @@ -267,7 +268,8 @@ pub(crate) fn property_formal_type(s: Span) -> IResult ))(s) } -#[parser(MaybeRecursive)] +#[recursive_parser] +#[parser] pub(crate) fn property_spec(s: Span) -> IResult { let (s, a) = opt(clocking_event)(s)?; let (s, b) = opt(triple( @@ -361,7 +363,8 @@ pub(crate) fn property_expr_not(s: Span) -> IResult { )) } -#[parser(MaybeRecursive)] +#[recursive_parser] +#[parser] pub(crate) fn property_expr_or(s: Span) -> IResult { let (s, a) = property_expr(s)?; let (s, b) = keyword("or")(s)?; @@ -372,7 +375,8 @@ pub(crate) fn property_expr_or(s: Span) -> IResult { )) } -#[parser(MaybeRecursive)] +#[recursive_parser] +#[parser] pub(crate) fn property_expr_and(s: Span) -> IResult { let (s, a) = property_expr(s)?; let (s, b) = keyword("and")(s)?; @@ -383,7 +387,8 @@ pub(crate) fn property_expr_and(s: Span) -> IResult { )) } -#[parser(MaybeRecursive)] +#[recursive_parser] +#[parser] pub(crate) fn property_expr_implication_overlapped(s: Span) -> IResult { let (s, a) = sequence_expr(s)?; let (s, b) = symbol("|->")(s)?; @@ -396,7 +401,8 @@ pub(crate) fn property_expr_implication_overlapped(s: Span) -> IResult IResult { let (s, a) = sequence_expr(s)?; let (s, b) = symbol("|=>")(s)?; @@ -438,7 +444,8 @@ pub(crate) fn property_expr_case(s: Span) -> IResult { )) } -#[parser(MaybeRecursive)] +#[recursive_parser] +#[parser] pub(crate) fn property_expr_followed_by_overlapped(s: Span) -> IResult { let (s, a) = sequence_expr(s)?; let (s, b) = symbol("#-#")(s)?; @@ -451,7 +458,8 @@ pub(crate) fn property_expr_followed_by_overlapped(s: Span) -> IResult IResult { let (s, a) = sequence_expr(s)?; let (s, b) = symbol("#=#")(s)?; @@ -530,7 +538,8 @@ pub(crate) fn property_expr_s_eventually(s: Span) -> IResult )) } -#[parser(MaybeRecursive)] +#[recursive_parser] +#[parser] pub(crate) fn property_expr_until(s: Span) -> IResult { let (s, a) = property_expr(s)?; let (s, b) = keyword("until")(s)?; @@ -541,7 +550,8 @@ pub(crate) fn property_expr_until(s: Span) -> IResult { )) } -#[parser(MaybeRecursive)] +#[recursive_parser] +#[parser] pub(crate) fn property_expr_s_until(s: Span) -> IResult { let (s, a) = property_expr(s)?; let (s, b) = keyword("s_until")(s)?; @@ -552,7 +562,8 @@ pub(crate) fn property_expr_s_until(s: Span) -> IResult { )) } -#[parser(MaybeRecursive)] +#[recursive_parser] +#[parser] pub(crate) fn property_expr_until_with(s: Span) -> IResult { let (s, a) = property_expr(s)?; let (s, b) = keyword("until_with")(s)?; @@ -563,7 +574,8 @@ pub(crate) fn property_expr_until_with(s: Span) -> IResult { )) } -#[parser(MaybeRecursive)] +#[recursive_parser] +#[parser] pub(crate) fn property_expr_s_until_with(s: Span) -> IResult { let (s, a) = property_expr(s)?; let (s, b) = keyword("s_until_with")(s)?; @@ -574,7 +586,8 @@ pub(crate) fn property_expr_s_until_with(s: Span) -> IResult )) } -#[parser(MaybeRecursive)] +#[recursive_parser] +#[parser] pub(crate) fn property_expr_implies(s: Span) -> IResult { let (s, a) = property_expr(s)?; let (s, b) = keyword("implies")(s)?; @@ -585,7 +598,8 @@ pub(crate) fn property_expr_implies(s: Span) -> IResult { )) } -#[parser(MaybeRecursive)] +#[recursive_parser] +#[parser] pub(crate) fn property_expr_iff(s: Span) -> IResult { let (s, a) = property_expr(s)?; let (s, b) = keyword("iff")(s)?; @@ -655,7 +669,8 @@ pub(crate) fn property_case_item(s: Span) -> IResult { alt((property_case_item_nondefault, property_case_item_default))(s) } -#[parser(MaybeRecursive)] +#[recursive_parser] +#[parser] pub(crate) fn property_case_item_nondefault(s: Span) -> IResult { let (s, a) = list(symbol(","), expression_or_dist)(s)?; let (s, b) = symbol(":")(s)?; @@ -783,7 +798,8 @@ pub(crate) fn sequence_expr_cycle_delay_expr(s: Span) -> IResult IResult { let (s, a) = sequence_expr(s)?; let (s, b) = cycle_delay_range(s)?; @@ -797,7 +813,8 @@ pub(crate) 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)?; @@ -830,7 +847,8 @@ pub(crate) fn sequence_expr_paren(s: Span) -> IResult { )) } -#[parser(MaybeRecursive)] +#[recursive_parser] +#[parser] pub(crate) fn sequence_expr_and(s: Span) -> IResult { let (s, a) = sequence_expr(s)?; let (s, b) = keyword("and")(s)?; @@ -841,7 +859,8 @@ pub(crate) fn sequence_expr_and(s: Span) -> IResult { )) } -#[parser(MaybeRecursive)] +#[recursive_parser] +#[parser] pub(crate) fn sequence_expr_intersect(s: Span) -> IResult { let (s, a) = sequence_expr(s)?; let (s, b) = keyword("intersect")(s)?; @@ -852,7 +871,8 @@ pub(crate) fn sequence_expr_intersect(s: Span) -> IResult { )) } -#[parser(MaybeRecursive)] +#[recursive_parser] +#[parser] pub(crate) fn sequence_expr_or(s: Span) -> IResult { let (s, a) = sequence_expr(s)?; let (s, b) = keyword("or")(s)?; @@ -876,7 +896,8 @@ pub(crate) fn sequence_expr_first_match(s: Span) -> IResult )) } -#[parser(MaybeRecursive)] +#[recursive_parser] +#[parser] pub(crate) fn sequence_expr_throughout(s: Span) -> IResult { let (s, a) = expression_or_dist(s)?; let (s, b) = keyword("throughout")(s)?; @@ -887,7 +908,8 @@ pub(crate) fn sequence_expr_throughout(s: Span) -> IResult { )) } -#[parser(MaybeRecursive)] +#[recursive_parser] +#[parser] pub(crate) fn sequence_expr_within(s: Span) -> IResult { let (s, a) = sequence_expr(s)?; let (s, b) = keyword("within")(s)?; @@ -996,7 +1018,8 @@ pub(crate) fn sequence_list_of_arguments(s: Span) -> IResult IResult { @@ -1132,7 +1155,8 @@ pub(crate) fn cycle_delay_const_range_expression( ))(s) } -#[parser(MaybeRecursive)] +#[recursive_parser] +#[parser] pub(crate) fn cycle_delay_const_range_expression_binary( s: Span, ) -> IResult { @@ -1147,7 +1171,8 @@ pub(crate) fn cycle_delay_const_range_expression_binary( )) } -#[parser(MaybeRecursive)] +#[recursive_parser] +#[parser] pub(crate) fn cycle_delay_const_range_expression_dollar( s: Span, ) -> IResult { @@ -1162,7 +1187,8 @@ pub(crate) fn cycle_delay_const_range_expression_dollar( )) } -#[parser(MaybeRecursive)] +#[recursive_parser] +#[parser] pub(crate) fn expression_or_dist(s: Span) -> IResult { let (s, a) = expression(s)?; let (s, b) = opt(pair(keyword("dist"), brace(dist_list)))(s)?; diff --git a/sv-parser-parser/src/declarations/block_item_declarations.rs b/sv-parser-parser/src/declarations/block_item_declarations.rs index c9c35b0..837367d 100644 --- a/sv-parser-parser/src/declarations/block_item_declarations.rs +++ b/sv-parser-parser/src/declarations/block_item_declarations.rs @@ -12,7 +12,8 @@ pub(crate) fn block_item_declaration(s: Span) -> IResult IResult { let (s, a) = many0(attribute_instance)(s)?; let (s, b) = data_declaration(s)?; diff --git a/sv-parser-parser/src/declarations/covergroup_declarations.rs b/sv-parser-parser/src/declarations/covergroup_declarations.rs index 596285c..821fe7b 100644 --- a/sv-parser-parser/src/declarations/covergroup_declarations.rs +++ b/sv-parser-parser/src/declarations/covergroup_declarations.rs @@ -133,7 +133,8 @@ pub(crate) fn block_event_expression(s: Span) -> IResult IResult { let (s, a) = block_event_expression(s)?; let (s, b) = keyword("or")(s)?; @@ -387,7 +388,8 @@ pub(crate) fn trans_list(s: Span) -> IResult { Ok((s, TransList { nodes: (a,) })) } -#[parser(MaybeRecursive)] +#[recursive_parser] +#[parser] pub(crate) fn trans_set(s: Span) -> IResult { let (s, a) = list(symbol("=>"), trans_range_list)(s)?; Ok((s, TransSet { nodes: (a,) })) @@ -403,7 +405,8 @@ pub(crate) fn trans_range_list(s: Span) -> IResult { ))(s) } -#[parser(MaybeRecursive)] +#[recursive_parser] +#[parser] pub(crate) fn trans_range_list_asterisk(s: Span) -> IResult { let (s, a) = trans_item(s)?; let (s, b) = bracket(pair(symbol("*"), repeat_range))(s)?; @@ -413,7 +416,8 @@ pub(crate) fn trans_range_list_asterisk(s: Span) -> IResult IResult { let (s, a) = trans_item(s)?; let (s, b) = bracket(pair(symbol("->"), repeat_range))(s)?; @@ -423,7 +427,8 @@ pub(crate) fn trans_range_list_arrow(s: Span) -> IResult { )) } -#[parser(MaybeRecursive)] +#[recursive_parser] +#[parser] pub(crate) fn trans_range_list_equal(s: Span) -> IResult { let (s, a) = trans_item(s)?; let (s, b) = bracket(pair(symbol("="), repeat_range))(s)?; @@ -449,7 +454,8 @@ pub(crate) fn repeat_range(s: Span) -> IResult { ))(s) } -#[parser(MaybeRecursive)] +#[recursive_parser] +#[parser] pub(crate) fn repeat_range_binary(s: Span) -> IResult { let (s, a) = covergroup_expression(s)?; let (s, b) = symbol(":")(s)?; @@ -594,7 +600,8 @@ pub(crate) fn select_expression_not(s: Span) -> IResult )) } -#[parser(MaybeRecursive)] +#[recursive_parser] +#[parser] pub(crate) fn select_expression_and(s: Span) -> IResult { let (s, a) = select_expression(s)?; let (s, b) = symbol("&&")(s)?; @@ -605,7 +612,8 @@ pub(crate) fn select_expression_and(s: Span) -> IResult )) } -#[parser(MaybeRecursive)] +#[recursive_parser] +#[parser] pub(crate) fn select_expression_or(s: Span) -> IResult { let (s, a) = select_expression(s)?; let (s, b) = symbol("||")(s)?; @@ -625,7 +633,8 @@ pub(crate) fn select_expression_paren(s: Span) -> IResult IResult { let (s, a) = select_expression(s)?; let (s, b) = keyword("with")(s)?; @@ -639,7 +648,8 @@ pub(crate) fn select_expression_with(s: Span) -> IResult )) } -#[parser(MaybeRecursive)] +#[recursive_parser] +#[parser] pub(crate) fn select_expression_cross_set(s: Span) -> IResult { let (s, a) = cross_set_expression(s)?; let (s, b) = opt(pair(keyword("matches"), integer_covergroup_expression))(s)?; @@ -677,7 +687,8 @@ pub(crate) fn bins_expression_cover_point(s: Span) -> IResult IResult { let (s, a) = list(symbol(","), covergroup_value_range)(s)?; Ok((s, CovergroupRangeList { nodes: (a,) })) diff --git a/sv-parser-parser/src/declarations/let_declarations.rs b/sv-parser-parser/src/declarations/let_declarations.rs index be9c312..86d70a2 100644 --- a/sv-parser-parser/src/declarations/let_declarations.rs +++ b/sv-parser-parser/src/declarations/let_declarations.rs @@ -68,7 +68,8 @@ pub(crate) fn let_list_of_arguments(s: Span) -> IResult IResult { let (s, a) = list(symbol(","), opt(let_actual_arg))(s)?; let (s, b) = many0(tuple(( diff --git a/sv-parser-parser/src/expressions/concatenations.rs b/sv-parser-parser/src/expressions/concatenations.rs index 60f2a7d..7cf9cd0 100644 --- a/sv-parser-parser/src/expressions/concatenations.rs +++ b/sv-parser-parser/src/expressions/concatenations.rs @@ -76,7 +76,8 @@ pub(crate) fn stream_concatenation(s: Span) -> IResult IResult { let (s, a) = expression(s)?; let (s, b) = opt(pair(keyword("with"), bracket(array_range_expression)))(s)?; @@ -95,7 +96,8 @@ pub(crate) fn array_range_expression(s: Span) -> IResult IResult { let (s, a) = expression(s)?; let (s, b) = symbol(":")(s)?; @@ -106,7 +108,8 @@ pub(crate) fn array_range_expression_colon(s: Span) -> IResult IResult { let (s, a) = expression(s)?; let (s, b) = symbol("+:")(s)?; @@ -119,7 +122,8 @@ pub(crate) fn array_range_expression_plus_colon(s: Span) -> IResult IResult { let (s, a) = expression(s)?; let (s, b) = symbol("-:")(s)?; diff --git a/sv-parser-parser/src/expressions/expressions.rs b/sv-parser-parser/src/expressions/expressions.rs index 43f33fd..a01c340 100644 --- a/sv-parser-parser/src/expressions/expressions.rs +++ b/sv-parser-parser/src/expressions/expressions.rs @@ -18,7 +18,8 @@ pub(crate) fn inc_or_dec_expression_prefix(s: Span) -> IResult IResult { let (s, a) = variable_lvalue(s)?; let (s, b) = many0(attribute_instance)(s)?; @@ -29,7 +30,8 @@ pub(crate) fn inc_or_dec_expression_suffix(s: Span) -> IResult IResult { let (s, a) = cond_predicate(s)?; let (s, b) = symbol("?")(s)?; @@ -69,7 +71,8 @@ pub(crate) fn constant_expression_unary(s: Span) -> IResult IResult { let (s, a) = constant_expression(s)?; let (s, b) = binary_operator(s)?; @@ -83,7 +86,8 @@ pub(crate) fn constant_expression_binary(s: Span) -> IResult IResult { let (s, a) = constant_expression(s)?; let (s, b) = symbol("?")(s)?; @@ -109,7 +113,8 @@ pub(crate) fn constant_mintypmax_expression(s: Span) -> IResult IResult { @@ -176,7 +181,8 @@ pub(crate) fn constant_part_select_range(s: Span) -> IResult IResult { let (s, a) = constant_expression(s)?; let (s, b) = symbol(":")(s)?; @@ -184,7 +190,8 @@ pub(crate) fn constant_range(s: Span) -> IResult { Ok((s, ConstantRange { nodes: (a, b, c) })) } -#[parser(MaybeRecursive)] +#[recursive_parser] +#[parser] pub(crate) fn constant_indexed_range(s: Span) -> IResult { let (s, a) = constant_expression(s)?; let (s, b) = alt((symbol("+:"), symbol("-:")))(s)?; @@ -235,7 +242,8 @@ pub(crate) fn expression_operator_assignment(s: Span) -> IResult IResult { let (s, a) = expression(s)?; let (s, b) = binary_operator(s)?; @@ -257,7 +265,8 @@ pub(crate) fn tagged_union_expression(s: Span) -> IResult IResult { let (s, a) = expression(s)?; let (s, b) = keyword("inside")(s)?; @@ -290,7 +299,8 @@ pub(crate) fn mintypmax_expression(s: Span) -> IResult IResult { let (s, a) = expression(s)?; let (s, b) = symbol(":")(s)?; @@ -305,7 +315,8 @@ pub(crate) fn mintypmax_expression_ternary(s: Span) -> IResult IResult { @@ -348,7 +359,8 @@ pub(crate) fn module_path_expression_unary(s: Span) -> IResult IResult { let (s, a) = module_path_expression(s)?; let (s, b) = binary_module_path_operator(s)?; @@ -374,7 +386,8 @@ pub(crate) fn module_path_mintypmax_expression( ))(s) } -#[parser(MaybeRecursive)] +#[recursive_parser] +#[parser] pub(crate) fn module_path_mintypmax_expression_ternary( s: Span, ) -> IResult { @@ -403,7 +416,8 @@ pub(crate) fn part_select_range(s: Span) -> IResult { ))(s) } -#[parser(MaybeRecursive)] +#[recursive_parser] +#[parser] pub(crate) fn indexed_range(s: Span) -> IResult { let (s, a) = expression(s)?; let (s, b) = alt((symbol("+:"), symbol("-:")))(s)?; diff --git a/sv-parser-parser/src/expressions/primaries.rs b/sv-parser-parser/src/expressions/primaries.rs index 5773203..c1e63bd 100644 --- a/sv-parser-parser/src/expressions/primaries.rs +++ b/sv-parser-parser/src/expressions/primaries.rs @@ -226,7 +226,8 @@ pub(crate) fn class_qualifier_or_package_scope( ))(s) } -#[parser(MaybeRecursive)] +#[recursive_parser] +#[parser] pub(crate) fn class_qualifier(s: Span) -> IResult { let (s, a) = opt(local)(s)?; let (s, b) = opt(implicit_class_handle_or_class_scope)(s)?; @@ -356,7 +357,8 @@ pub(crate) fn constant_select(s: Span) -> IResult { Ok((s, ConstantSelect { nodes: (a, b, c) })) } -#[parser(MaybeRecursive)] +#[recursive_parser] +#[parser] pub(crate) fn constant_cast(s: Span) -> IResult { let (s, a) = casting_type(s)?; let (s, b) = symbol("'")(s)?; @@ -370,7 +372,8 @@ pub(crate) fn constant_let_expression(s: Span) -> IResult IResult { let (s, a) = casting_type(s)?; let (s, b) = symbol("'")(s)?; diff --git a/sv-parser-parser/src/expressions/subroutine_calls.rs b/sv-parser-parser/src/expressions/subroutine_calls.rs index bb1b350..3fb7360 100644 --- a/sv-parser-parser/src/expressions/subroutine_calls.rs +++ b/sv-parser-parser/src/expressions/subroutine_calls.rs @@ -91,7 +91,8 @@ pub(crate) fn list_of_arguments(s: Span) -> IResult { alt((list_of_arguments_ordered, list_of_arguments_named))(s) } -#[parser(MaybeRecursive)] +#[recursive_parser] +#[parser] pub(crate) fn list_of_arguments_ordered(s: Span) -> IResult { let (s, a) = list(symbol(","), opt(expression))(s)?; let (s, b) = many0(tuple(( @@ -125,7 +126,8 @@ pub(crate) fn list_of_arguments_named(s: Span) -> IResult )) } -#[parser(MaybeRecursive)] +#[recursive_parser] +#[parser] pub(crate) fn method_call(s: Span) -> IResult { let (s, a) = method_call_root(s)?; let (s, b) = symbol(".")(s)?; diff --git a/sv-parser-parser/src/instantiations/checker_instantiation.rs b/sv-parser-parser/src/instantiations/checker_instantiation.rs index f397d66..998f0d2 100644 --- a/sv-parser-parser/src/instantiations/checker_instantiation.rs +++ b/sv-parser-parser/src/instantiations/checker_instantiation.rs @@ -26,7 +26,8 @@ pub(crate) fn list_of_checker_port_connections( ))(s) } -#[parser(MaybeRecursive)] +#[recursive_parser] +#[parser] pub(crate) fn list_of_checker_port_connections_ordered( s: Span, ) -> IResult { @@ -52,7 +53,8 @@ pub(crate) fn list_of_checker_port_connections_named( )) } -#[parser(MaybeRecursive)] +#[recursive_parser] +#[parser] pub(crate) fn ordered_checker_port_connection( s: Span, ) -> IResult { diff --git a/sv-parser-parser/src/instantiations/generated_instantiation.rs b/sv-parser-parser/src/instantiations/generated_instantiation.rs index 530bb26..5b149ac 100644 --- a/sv-parser-parser/src/instantiations/generated_instantiation.rs +++ b/sv-parser-parser/src/instantiations/generated_instantiation.rs @@ -125,7 +125,8 @@ pub(crate) fn case_generate_item(s: Span) -> IResult { alt((case_generate_item_nondefault, case_generate_item_default))(s) } -#[parser(MaybeRecursive)] +#[recursive_parser] +#[parser] pub(crate) fn case_generate_item_nondefault(s: Span) -> IResult { let (s, a) = list(symbol(","), constant_expression)(s)?; let (s, b) = symbol(":")(s)?; diff --git a/sv-parser-parser/src/instantiations/module_instantiation.rs b/sv-parser-parser/src/instantiations/module_instantiation.rs index 914f7d7..f7674ab 100644 --- a/sv-parser-parser/src/instantiations/module_instantiation.rs +++ b/sv-parser-parser/src/instantiations/module_instantiation.rs @@ -31,7 +31,8 @@ pub(crate) fn list_of_parameter_assignments(s: Span) -> IResult IResult { @@ -93,7 +94,8 @@ pub(crate) fn list_of_port_connections(s: Span) -> IResult IResult { let (s, a) = list(symbol(","), ordered_port_connection)(s)?; Ok(( @@ -111,7 +113,8 @@ pub(crate) 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/sv-parser-parser/src/lib.rs b/sv-parser-parser/src/lib.rs index 35c9f52..852a8a1 100644 --- a/sv-parser-parser/src/lib.rs +++ b/sv-parser-parser/src/lib.rs @@ -32,6 +32,7 @@ pub(crate) use nom::multi::*; pub(crate) use nom::sequence::*; pub(crate) use nom::{Err, IResult}; pub(crate) use nom_packrat::{self, packrat_parser}; +pub(crate) use nom_recursive::{recursive_parser, RecursiveTracer}; pub(crate) use sv_parser_macros::*; pub(crate) use sv_parser_syntaxtree::*; @@ -40,7 +41,7 @@ pub(crate) use sv_parser_syntaxtree::*; nom_packrat::storage!(AnyNode); pub fn parse_sv(s: &str) -> Result { - let s = Span::new_extra(s, Extra::default()); + let s = Span::new_extra(s, SpanInfo::default()); match source_text(s) { Ok((_, x)) => Ok(x), Err(_) => Err(()), @@ -48,50 +49,9 @@ pub fn parse_sv(s: &str) -> Result { } pub fn parse_lib(s: &str) -> Result { - let s = Span::new_extra(s, Extra::default()); + let s = Span::new_extra(s, SpanInfo::default()); match library_text(s) { Ok((_, x)) => Ok(x), Err(_) => Err(()), } } - -// ----------------------------------------------------------------------------- - -mod thread_context { - - use std::cell::RefCell; - use std::collections::HashMap; - use sv_parser_syntaxtree::RECURSIVE_FLAG_WORDS; - - pub struct ParserIndex { - index: HashMap<&'static str, usize>, - allocated: [u128; RECURSIVE_FLAG_WORDS], - } - - impl ParserIndex { - pub fn get(&mut self, key: &'static str) -> Option { - if let Some(x) = self.index.get(key) { - Some(*x) - } else { - for i in 0..128 * RECURSIVE_FLAG_WORDS { - let upper = i / 128; - let lower = i % 128; - if ((self.allocated[upper] >> lower) & 1) == 0 { - let val = 1u128 << lower; - let mask = !(1u128 << lower); - self.allocated[upper] = (self.allocated[upper] & mask) | val; - self.index.insert(key, i); - return Some(i); - } - } - None - } - } - } - - thread_local!( - pub static PARSER_INDEX: RefCell = { - RefCell::new(ParserIndex{index: HashMap::new(), allocated: [0;RECURSIVE_FLAG_WORDS]}) - } - ); -} diff --git a/sv-parser-parser/src/source_text/constraints.rs b/sv-parser-parser/src/source_text/constraints.rs index 715c909..cc458b6 100644 --- a/sv-parser-parser/src/source_text/constraints.rs +++ b/sv-parser-parser/src/source_text/constraints.rs @@ -81,7 +81,8 @@ pub(crate) fn constraint_expression(s: Span) -> IResult IResult { let (s, a) = opt(soft)(s)?; let (s, b) = expression_or_dist(s)?; @@ -100,7 +101,8 @@ pub(crate) fn soft(s: Span) -> IResult { Ok((s, Soft { nodes: (a,) })) } -#[parser(MaybeRecursive)] +#[recursive_parser] +#[parser] pub(crate) fn constraint_expression_arrow(s: Span) -> IResult { let (s, a) = expression(s)?; let (s, b) = symbol("->")(s)?; @@ -179,13 +181,15 @@ pub(crate) fn constraint_set_brace(s: Span) -> IResult { )) } -#[parser(MaybeRecursive)] +#[recursive_parser] +#[parser] pub(crate) fn dist_list(s: Span) -> IResult { let (s, a) = list(symbol(","), dist_item)(s)?; Ok((s, DistList { nodes: (a,) })) } -#[parser(MaybeRecursive)] +#[recursive_parser] +#[parser] pub(crate) fn dist_item(s: Span) -> IResult { let (s, a) = value_range(s)?; let (s, b) = opt(dist_weight)(s)?; diff --git a/sv-parser-parser/src/source_text/interface_items.rs b/sv-parser-parser/src/source_text/interface_items.rs index c84945e..ce83325 100644 --- a/sv-parser-parser/src/source_text/interface_items.rs +++ b/sv-parser-parser/src/source_text/interface_items.rs @@ -10,7 +10,8 @@ pub(crate) 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/sv-parser-parser/src/source_text/module_items.rs b/sv-parser-parser/src/source_text/module_items.rs index be08325..a534ce0 100644 --- a/sv-parser-parser/src/source_text/module_items.rs +++ b/sv-parser-parser/src/source_text/module_items.rs @@ -176,7 +176,8 @@ pub(crate) 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/sv-parser-parser/src/source_text/module_parameters_and_ports.rs b/sv-parser-parser/src/source_text/module_parameters_and_ports.rs index 6c5e599..a815046 100644 --- a/sv-parser-parser/src/source_text/module_parameters_and_ports.rs +++ b/sv-parser-parser/src/source_text/module_parameters_and_ports.rs @@ -165,7 +165,8 @@ pub(crate) fn port(s: Span) -> IResult { alt((port_non_named, port_named))(s) } -#[parser(MaybeRecursive)] +#[recursive_parser] +#[parser] pub(crate) fn port_non_named(s: Span) -> IResult { let (s, a) = opt(port_expression)(s)?; Ok((s, Port::NonNamed(Box::new(PortNonNamed { nodes: (a,) })))) diff --git a/sv-parser-parser/src/source_text/program_items.rs b/sv-parser-parser/src/source_text/program_items.rs index 6b9aad5..46c21e9 100644 --- a/sv-parser-parser/src/source_text/program_items.rs +++ b/sv-parser-parser/src/source_text/program_items.rs @@ -41,7 +41,8 @@ pub(crate) 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/sv-parser-parser/src/source_text/system_verilog_source_text.rs b/sv-parser-parser/src/source_text/system_verilog_source_text.rs index 8bbf20a..e2efb49 100644 --- a/sv-parser-parser/src/source_text/system_verilog_source_text.rs +++ b/sv-parser-parser/src/source_text/system_verilog_source_text.rs @@ -38,7 +38,8 @@ pub(crate) fn description(s: Span) -> IResult { ))(s) } -#[parser(MaybeRecursive)] +#[recursive_parser] +#[parser] pub(crate) 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-parser/src/tests.rs b/sv-parser-parser/src/tests.rs index 788c1af..cb7619f 100644 --- a/sv-parser-parser/src/tests.rs +++ b/sv-parser-parser/src/tests.rs @@ -4,7 +4,7 @@ use crate::*; macro_rules! test { ( $x:expr, $y:expr, $z:pat ) => { - let ret = all_consuming($x)(Span::new_extra($y, Extra::default())); + let ret = all_consuming($x)(Span::new_extra($y, SpanInfo::default())); if let $z = ret { } else { assert!(false, "{:?}", ret) diff --git a/sv-parser-parser/src/utils.rs b/sv-parser-parser/src/utils.rs index 2b01075..71dc71f 100644 --- a/sv-parser-parser/src/utils.rs +++ b/sv-parser-parser/src/utils.rs @@ -273,7 +273,7 @@ pub(crate) fn symbol<'a>(t: &'a str) -> impl Fn(Span<'a>) -> IResult, S let (s, x) = map(ws(map(tag(t.clone()), |x: Span| x.into())), |x| Symbol { nodes: x, })(s)?; - Ok((clear_recursive_flags(s), x)) + Ok((s, x)) } } @@ -288,7 +288,7 @@ pub(crate) fn keyword<'a>(t: &'a str) -> impl Fn(Span<'a>) -> IResult, )), |x| Keyword { nodes: x }, )(s)?; - Ok((clear_recursive_flags(s), x)) + Ok((s, x)) } } @@ -448,31 +448,6 @@ pub(crate) fn concat<'a>(a: Span<'a>, b: Span<'a>) -> Option> { } } -pub(crate) fn check_recursive_flag(s: Span, id: usize) -> bool { - let upper = id / 128; - let lower = id % 128; - - ((s.extra.recursive_flag[upper] >> lower) & 1) == 1 -} - -pub(crate) fn set_recursive_flag(mut s: Span, id: usize, bit: bool) -> Span { - let upper = id / 128; - let lower = id % 128; - - let val = if bit { 1u128 << lower } else { 0u128 }; - let mask = !(1u128 << lower); - - let mut recursive_flag = s.extra.recursive_flag; - recursive_flag[upper] = (recursive_flag[upper] & mask) | val; - s.extra.recursive_flag = recursive_flag; - s -} - -pub(crate) fn clear_recursive_flags(mut s: Span) -> Span { - s.extra.recursive_flag = [0; RECURSIVE_FLAG_WORDS]; - s -} - pub(crate) fn is_keyword(s: &Span) -> bool { for k in KEYWORDS { if &s.fragment == k { @@ -485,10 +460,11 @@ pub(crate) fn is_keyword(s: &Span) -> bool { #[cfg(feature = "trace")] pub(crate) fn trace<'a>(mut s: Span<'a>, name: &str) -> Span<'a> { println!( - "{:<128} : {:<4},{:>032x} : {}", + //"{:<128} : {:<4},{:>032x} : {}", + "{:<128} : {:<4} : {}", format!("{}{}", " ".repeat(s.extra.depth), name), s.offset, - s.extra.recursive_flag[0], + //s.extra.recursive_flag[0], s.fragment ); s.extra.depth += 1; diff --git a/sv-parser-syntaxtree/Cargo.toml b/sv-parser-syntaxtree/Cargo.toml index 238cb71..5c4aa05 100644 --- a/sv-parser-syntaxtree/Cargo.toml +++ b/sv-parser-syntaxtree/Cargo.toml @@ -5,9 +5,14 @@ authors = ["dalance "] edition = "2018" build = "build.rs" +[features] +default = [] +trace = [] + [dependencies] sv-parser-macros = { path = "../sv-parser-macros" } -nom_locate = { path = "../../nom_locate" } +nom_locate = { path = "../../nom_locate" } +nom-recursive = { path = "../../nom-recursive/nom-recursive" } [build-dependencies] walkdir = "2" diff --git a/sv-parser-syntaxtree/src/lib.rs b/sv-parser-syntaxtree/src/lib.rs index b10e66a..7a8b86d 100644 --- a/sv-parser-syntaxtree/src/lib.rs +++ b/sv-parser-syntaxtree/src/lib.rs @@ -23,20 +23,30 @@ pub use special_node::*; pub use specify_section::*; pub use udp_declaration_and_instantiation::*; +pub(crate) use nom_recursive::{RecursiveInfo, RecursiveTracer}; pub(crate) use sv_parser_macros::*; // ----------------------------------------------------------------------------- -pub const RECURSIVE_FLAG_WORDS: usize = 1; - -#[derive(Copy, Clone, Default, Debug, PartialEq)] -pub struct Extra { +#[derive(Clone, Copy, Debug, Default, PartialEq)] +pub struct SpanInfo { #[cfg(feature = "trace")] pub depth: usize, - pub recursive_flag: [u128; RECURSIVE_FLAG_WORDS], + pub recursive_info: RecursiveInfo, } -pub type Span<'a> = nom_locate::LocatedSpanEx<&'a str, Extra>; +pub type Span<'a> = nom_locate::LocatedSpanEx<&'a str, SpanInfo>; + +impl RecursiveTracer for SpanInfo { + fn get_info(&self) -> RecursiveInfo { + self.recursive_info + } + + fn set_info(mut self, info: RecursiveInfo) -> Self { + self.recursive_info = info; + self + } +} // ----------------------------------------------------------------------------- diff --git a/sv-parser/Cargo.toml b/sv-parser/Cargo.toml index 58273fe..820b73a 100644 --- a/sv-parser/Cargo.toml +++ b/sv-parser/Cargo.toml @@ -10,6 +10,10 @@ readme = "../README.md" description = "" edition = "2018" +[features] +default = [] +trace = ["sv-parser-parser/trace"] + [dependencies] sv-parser-syntaxtree = { path = "../sv-parser-syntaxtree" } sv-parser-parser = { path = "../sv-parser-parser" }