Refactoring

This commit is contained in:
dalance 2019-07-12 15:18:56 +09:00
parent c84ba8638b
commit c06ff35e87
22 changed files with 1044 additions and 564 deletions

View File

@ -49,11 +49,11 @@ A parser library for System Verilog.
| behavioral_statements | procedural_blocks_and_assignments | x | x | | | behavioral_statements | procedural_blocks_and_assignments | x | x | |
| behavioral_statements | parallel_and_sequential_blocks | x | x | | | behavioral_statements | parallel_and_sequential_blocks | x | x | |
| behavioral_statements | statements | x | x | | | behavioral_statements | statements | x | x | |
| behavioral_statements | timing_control_statements | | | | | behavioral_statements | timing_control_statements | x | x | |
| behavioral_statements | conditional_statements | | | | | behavioral_statements | conditional_statements | x | x | |
| behavioral_statements | case_statements | | | | | behavioral_statements | case_statements | x | x | |
| behavioral_statements | patterns | | | | | behavioral_statements | patterns | x | x | |
| behavioral_statements | looping_statements | | | | | behavioral_statements | looping_statements | x | x | |
| behavioral_statements | subroutine_call_statements | x | x | | | behavioral_statements | subroutine_call_statements | x | x | |
| behavioral_statements | assertion_statements | | | | | behavioral_statements | assertion_statements | | | |
| behavioral_statements | clocking_block | | | | | behavioral_statements | clocking_block | | | |

View File

@ -1,3 +1,4 @@
use crate::ast::*;
use crate::parser::*; use crate::parser::*;
use nom::branch::*; use nom::branch::*;
use nom::combinator::*; use nom::combinator::*;
@ -17,38 +18,51 @@ pub enum CaseStatement<'a> {
#[derive(Debug)] #[derive(Debug)]
pub struct CaseStatementNormal<'a> { pub struct CaseStatementNormal<'a> {
pub nodes: ( pub nodes: (
Option<UniquePriority>, Option<UniquePriority<'a>>,
CaseKeyword, CaseKeyword<'a>,
Expression<'a>, Paren<'a, CaseExpression<'a>>,
CaseItem<'a>,
Vec<CaseItem<'a>>, Vec<CaseItem<'a>>,
Symbol<'a>,
), ),
} }
#[derive(Debug)] #[derive(Debug)]
pub struct CaseStatementMatches<'a> { pub struct CaseStatementMatches<'a> {
pub nodes: ( pub nodes: (
Option<UniquePriority>, Option<UniquePriority<'a>>,
CaseKeyword, CaseKeyword<'a>,
Expression<'a>, Paren<'a, CaseExpression<'a>>,
Symbol<'a>,
CasePatternItem<'a>,
Vec<CasePatternItem<'a>>, Vec<CasePatternItem<'a>>,
Symbol<'a>,
), ),
} }
#[derive(Debug)] #[derive(Debug)]
pub struct CaseStatementInside<'a> { pub struct CaseStatementInside<'a> {
pub nodes: ( pub nodes: (
Option<UniquePriority>, Option<UniquePriority<'a>>,
CaseKeyword, Symbol<'a>,
Expression<'a>, Paren<'a, CaseExpression<'a>>,
Symbol<'a>,
CaseInsideItem<'a>,
Vec<CaseInsideItem<'a>>, Vec<CaseInsideItem<'a>>,
Symbol<'a>,
), ),
} }
#[derive(Debug, Node)]
pub enum CaseKeyword<'a> {
Case(Symbol<'a>),
Casez(Symbol<'a>),
Casex(Symbol<'a>),
}
#[derive(Debug)] #[derive(Debug)]
pub enum CaseKeyword { pub struct CaseExpression<'a> {
Case, pub nodes: (Expression<'a>,),
Casez,
Casex,
} }
#[derive(Debug)] #[derive(Debug)]
@ -57,55 +71,74 @@ pub enum CaseItem<'a> {
Default(CaseItemDefault<'a>), Default(CaseItemDefault<'a>),
} }
#[derive(Debug)]
pub struct CaseItemNondefault<'a> {
pub nodes: (
List<Symbol<'a>, CaseItemExpression<'a>>,
Symbol<'a>,
StatementOrNull<'a>,
),
}
#[derive(Debug)]
pub struct CaseItemDefault<'a> {
pub nodes: (Symbol<'a>, Option<Symbol<'a>>, StatementOrNull<'a>),
}
#[derive(Debug)] #[derive(Debug)]
pub enum CasePatternItem<'a> { pub enum CasePatternItem<'a> {
NonDefault(CasePatternItemNondefault<'a>), NonDefault(CasePatternItemNondefault<'a>),
Default(CaseItemDefault<'a>), Default(CaseItemDefault<'a>),
} }
#[derive(Debug)]
pub struct CasePatternItemNondefault<'a> {
pub nodes: (
Pattern<'a>,
Option<(Symbol<'a>, Expression<'a>)>,
Symbol<'a>,
StatementOrNull<'a>,
),
}
#[derive(Debug)] #[derive(Debug)]
pub enum CaseInsideItem<'a> { pub enum CaseInsideItem<'a> {
NonDefault(CaseInsideItemNondefault<'a>), NonDefault(CaseInsideItemNondefault<'a>),
Default(CaseItemDefault<'a>), Default(CaseItemDefault<'a>),
} }
#[derive(Debug)]
pub struct CaseItemDefault<'a> {
pub nodes: (StatementOrNull<'a>,),
}
#[derive(Debug)]
pub struct CaseItemNondefault<'a> {
pub nodes: (Vec<Expression<'a>>, StatementOrNull<'a>),
}
#[derive(Debug)]
pub struct CasePatternItemNondefault<'a> {
pub nodes: (Pattern<'a>, Option<Expression<'a>>, StatementOrNull<'a>),
}
#[derive(Debug)] #[derive(Debug)]
pub struct CaseInsideItemNondefault<'a> { pub struct CaseInsideItemNondefault<'a> {
pub nodes: (Vec<ValueRange<'a>>, StatementOrNull<'a>), pub nodes: (OpenRangeList<'a>, Symbol<'a>, StatementOrNull<'a>),
}
#[derive(Debug)]
pub struct CaseItemExpression<'a> {
pub nodes: (Expression<'a>,),
} }
#[derive(Debug)] #[derive(Debug)]
pub struct RandcaseStatement<'a> { pub struct RandcaseStatement<'a> {
pub nodes: (Vec<RandcaseItem<'a>>,), pub nodes: (
Symbol<'a>,
RandcaseItem<'a>,
Vec<RandcaseItem<'a>>,
Symbol<'a>,
),
} }
#[derive(Debug)] #[derive(Debug)]
pub struct RandcaseItem<'a> { pub struct RandcaseItem<'a> {
pub nodes: (Expression<'a>, StatementOrNull<'a>), pub nodes: (Expression<'a>, Symbol<'a>, StatementOrNull<'a>),
} }
#[derive(Debug)] #[derive(Debug)]
pub struct OpenRangeList<'a> { pub struct OpenRangeList<'a> {
pub nodes: (Vec<OpenRangeValue<'a>>,), pub nodes: (List<Symbol<'a>, OpenValueRange<'a>>,),
} }
#[derive(Debug)] #[derive(Debug)]
pub struct OpenRangeValue<'a> { pub struct OpenValueRange<'a> {
pub nodes: (ValueRange<'a>,), pub nodes: (ValueRange<'a>,),
} }
@ -120,65 +153,63 @@ pub fn case_statement(s: Span) -> IResult<Span, CaseStatement> {
} }
pub fn case_statement_normal(s: Span) -> IResult<Span, CaseStatement> { pub fn case_statement_normal(s: Span) -> IResult<Span, CaseStatement> {
let (s, x) = opt(unique_priority)(s)?; let (s, a) = opt(unique_priority)(s)?;
let (s, y) = case_keyword(s)?; let (s, b) = case_keyword(s)?;
let (s, _) = symbol("(")(s)?; let (s, c) = paren2(case_expression)(s)?;
let (s, z) = case_expression(s)?; let (s, d) = case_item(s)?;
let (s, _) = symbol(")")(s)?; let (s, e) = many0(case_item)(s)?;
let (s, v) = many1(case_item)(s)?; let (s, f) = symbol("endcase")(s)?;
let (s, _) = symbol("endcase")(s)?;
Ok(( Ok((
s, s,
CaseStatement::Normal(CaseStatementNormal { CaseStatement::Normal(CaseStatementNormal {
nodes: (x, y, z, v), nodes: (a, b, c, d, e, f),
}), }),
)) ))
} }
pub fn case_statement_matches(s: Span) -> IResult<Span, CaseStatement> { pub fn case_statement_matches(s: Span) -> IResult<Span, CaseStatement> {
let (s, x) = opt(unique_priority)(s)?; let (s, a) = opt(unique_priority)(s)?;
let (s, y) = case_keyword(s)?; let (s, b) = case_keyword(s)?;
let (s, _) = symbol("(")(s)?; let (s, c) = paren2(case_expression)(s)?;
let (s, z) = case_expression(s)?; let (s, d) = symbol("matches")(s)?;
let (s, _) = symbol(")")(s)?; let (s, e) = case_pattern_item(s)?;
let (s, _) = symbol("matches")(s)?; let (s, f) = many0(case_pattern_item)(s)?;
let (s, v) = many1(case_pattern_item)(s)?; let (s, g) = symbol("endcase")(s)?;
let (s, _) = symbol("endcase")(s)?;
Ok(( Ok((
s, s,
CaseStatement::Matches(CaseStatementMatches { CaseStatement::Matches(CaseStatementMatches {
nodes: (x, y, z, v), nodes: (a, b, c, d, e, f, g),
}), }),
)) ))
} }
pub fn case_statement_inside(s: Span) -> IResult<Span, CaseStatement> { pub fn case_statement_inside(s: Span) -> IResult<Span, CaseStatement> {
let (s, x) = opt(unique_priority)(s)?; let (s, a) = opt(unique_priority)(s)?;
let (s, y) = case_keyword(s)?; let (s, b) = symbol("case")(s)?;
let (s, _) = symbol("(")(s)?; let (s, c) = paren2(case_expression)(s)?;
let (s, z) = case_expression(s)?; let (s, d) = symbol("inside")(s)?;
let (s, _) = symbol(")")(s)?; let (s, e) = case_inside_item(s)?;
let (s, _) = symbol("inside")(s)?; let (s, f) = many0(case_inside_item)(s)?;
let (s, v) = many1(case_inside_item)(s)?; let (s, g) = symbol("endcase")(s)?;
let (s, _) = symbol("endcase")(s)?;
Ok(( Ok((
s, s,
CaseStatement::Inside(CaseStatementInside { CaseStatement::Inside(CaseStatementInside {
nodes: (x, y, z, v), nodes: (a, b, c, d, e, f, g),
}), }),
)) ))
} }
pub fn case_keyword(s: Span) -> IResult<Span, CaseKeyword> { pub fn case_keyword(s: Span) -> IResult<Span, CaseKeyword> {
alt(( alt((
map(symbol("casez"), |_| CaseKeyword::Casez), map(symbol("casez"), |x| CaseKeyword::Casez(x)),
map(symbol("casex"), |_| CaseKeyword::Casex), map(symbol("casex"), |x| CaseKeyword::Casex(x)),
map(symbol("case"), |_| CaseKeyword::Case), map(symbol("case"), |x| CaseKeyword::Case(x)),
))(s) ))(s)
} }
pub fn case_expression(s: Span) -> IResult<Span, Expression> { pub fn case_expression(s: Span) -> IResult<Span, CaseExpression> {
expression(s) let (s, a) = expression(s)?;
Ok((s, CaseExpression { nodes: (a,) }))
} }
pub fn case_item(s: Span) -> IResult<Span, CaseItem> { pub fn case_item(s: Span) -> IResult<Span, CaseItem> {
@ -189,20 +220,20 @@ pub fn case_item(s: Span) -> IResult<Span, CaseItem> {
} }
pub fn case_item_nondefault(s: Span) -> IResult<Span, CaseItem> { pub fn case_item_nondefault(s: Span) -> IResult<Span, CaseItem> {
let (s, x) = separated_nonempty_list(symbol(","), case_item_expression)(s)?; let (s, a) = list(symbol(","), case_item_expression)(s)?;
let (s, _) = symbol(":")(s)?; let (s, b) = symbol(":")(s)?;
let (s, y) = statement_or_null(s)?; let (s, c) = statement_or_null(s)?;
Ok(( Ok((
s, s,
CaseItem::NonDefault(CaseItemNondefault { nodes: (x, y) }), CaseItem::NonDefault(CaseItemNondefault { nodes: (a, b, c) }),
)) ))
} }
pub fn case_item_default(s: Span) -> IResult<Span, CaseItemDefault> { pub fn case_item_default(s: Span) -> IResult<Span, CaseItemDefault> {
let (s, _) = symbol("default")(s)?; let (s, a) = symbol("default")(s)?;
let (s, _) = opt(symbol(":"))(s)?; let (s, b) = opt(symbol(":"))(s)?;
let (s, x) = statement_or_null(s)?; let (s, c) = statement_or_null(s)?;
Ok((s, CaseItemDefault { nodes: (x,) })) Ok((s, CaseItemDefault { nodes: (a, b, c) }))
} }
pub fn case_pattern_item(s: Span) -> IResult<Span, CasePatternItem> { pub fn case_pattern_item(s: Span) -> IResult<Span, CasePatternItem> {
@ -213,13 +244,15 @@ pub fn case_pattern_item(s: Span) -> IResult<Span, CasePatternItem> {
} }
pub fn case_pattern_item_nondefault(s: Span) -> IResult<Span, CasePatternItem> { pub fn case_pattern_item_nondefault(s: Span) -> IResult<Span, CasePatternItem> {
let (s, x) = pattern(s)?; let (s, a) = pattern(s)?;
let (s, y) = opt(preceded(symbol("&&&"), expression))(s)?; let (s, b) = opt(pair(symbol("&&&"), expression))(s)?;
let (s, _) = symbol(":")(s)?; let (s, c) = symbol(":")(s)?;
let (s, z) = statement_or_null(s)?; let (s, d) = statement_or_null(s)?;
Ok(( Ok((
s, s,
CasePatternItem::NonDefault(CasePatternItemNondefault { nodes: (x, y, z) }), CasePatternItem::NonDefault(CasePatternItemNondefault {
nodes: (a, b, c, d),
}),
)) ))
} }
@ -231,37 +264,46 @@ pub fn case_inside_item(s: Span) -> IResult<Span, CaseInsideItem> {
} }
pub fn case_inside_item_nondefault(s: Span) -> IResult<Span, CaseInsideItem> { pub fn case_inside_item_nondefault(s: Span) -> IResult<Span, CaseInsideItem> {
let (s, x) = open_range_list(s)?; let (s, a) = open_range_list(s)?;
let (s, _) = symbol(":")(s)?; let (s, b) = symbol(":")(s)?;
let (s, y) = statement_or_null(s)?; let (s, c) = statement_or_null(s)?;
Ok(( Ok((
s, s,
CaseInsideItem::NonDefault(CaseInsideItemNondefault { nodes: (x, y) }), CaseInsideItem::NonDefault(CaseInsideItemNondefault { nodes: (a, b, c) }),
)) ))
} }
pub fn case_item_expression(s: Span) -> IResult<Span, Expression> { pub fn case_item_expression(s: Span) -> IResult<Span, CaseItemExpression> {
expression(s) let (s, a) = expression(s)?;
Ok((s, CaseItemExpression { nodes: (a,) }))
} }
pub fn randcase_statement(s: Span) -> IResult<Span, RandcaseStatement> { pub fn randcase_statement(s: Span) -> IResult<Span, RandcaseStatement> {
let (s, _) = symbol("randcase")(s)?; let (s, a) = symbol("randcase")(s)?;
let (s, x) = many1(randcase_item)(s)?; let (s, b) = randcase_item(s)?;
let (s, _) = symbol("endcase")(s)?; let (s, c) = many0(randcase_item)(s)?;
Ok((s, RandcaseStatement { nodes: (x,) })) let (s, d) = symbol("endcase")(s)?;
Ok((
s,
RandcaseStatement {
nodes: (a, b, c, d),
},
))
} }
pub fn randcase_item(s: Span) -> IResult<Span, RandcaseItem> { pub fn randcase_item(s: Span) -> IResult<Span, RandcaseItem> {
let (s, x) = expression(s)?; let (s, a) = expression(s)?;
let (s, _) = symbol(":")(s)?; let (s, b) = symbol(":")(s)?;
let (s, y) = statement_or_null(s)?; let (s, c) = statement_or_null(s)?;
Ok((s, RandcaseItem { nodes: (x, y) })) Ok((s, RandcaseItem { nodes: (a, b, c) }))
} }
pub fn open_range_list(s: Span) -> IResult<Span, Vec<ValueRange>> { pub fn open_range_list(s: Span) -> IResult<Span, OpenRangeList> {
separated_nonempty_list(symbol(","), open_value_range)(s) let (s, a) = list(symbol(","), open_value_range)(s)?;
Ok((s, OpenRangeList { nodes: (a,) }))
} }
pub fn open_value_range(s: Span) -> IResult<Span, ValueRange> { pub fn open_value_range(s: Span) -> IResult<Span, OpenValueRange> {
value_range(s) let (s, a) = value_range(s)?;
Ok((s, OpenValueRange { nodes: (a,) }))
} }

View File

@ -1,3 +1,4 @@
use crate::ast::*;
use crate::parser::*; use crate::parser::*;
use nom::branch::*; use nom::branch::*;
use nom::combinator::*; use nom::combinator::*;
@ -10,28 +11,30 @@ use nom::IResult;
#[derive(Debug)] #[derive(Debug)]
pub struct ConditionalStatement<'a> { pub struct ConditionalStatement<'a> {
pub nodes: ( pub nodes: (
Option<UniquePriority>, Option<UniquePriority<'a>>,
ConditionalStatementBody<'a>, Symbol<'a>,
Vec<ConditionalStatementBody<'a>>, Paren<'a, CondPredicate<'a>>,
Option<StatementOrNull<'a>>, StatementOrNull<'a>,
Vec<(
Symbol<'a>,
Symbol<'a>,
Paren<'a, CondPredicate<'a>>,
StatementOrNull<'a>,
)>,
Option<(Symbol<'a>, StatementOrNull<'a>)>,
), ),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub enum UniquePriority { pub enum UniquePriority<'a> {
Unique, Unique(Symbol<'a>),
Unique0, Unique0(Symbol<'a>),
Priority, Priority(Symbol<'a>),
}
#[derive(Debug)]
pub struct ConditionalStatementBody<'a> {
pub nodes: (CondPredicate<'a>, StatementOrNull<'a>),
} }
#[derive(Debug)] #[derive(Debug)]
pub struct CondPredicate<'a> { pub struct CondPredicate<'a> {
pub nodes: (Vec<ExpressionOrCondPattern<'a>>,), pub nodes: (List<Symbol<'a>, ExpressionOrCondPattern<'a>>,),
} }
#[derive(Debug)] #[derive(Debug)]
@ -42,49 +45,43 @@ pub enum ExpressionOrCondPattern<'a> {
#[derive(Debug)] #[derive(Debug)]
pub struct CondPattern<'a> { pub struct CondPattern<'a> {
pub nodes: (Expression<'a>, Pattern<'a>), pub nodes: (Expression<'a>, Symbol<'a>, Pattern<'a>),
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
pub fn conditional_statement(s: Span) -> IResult<Span, ConditionalStatement> { pub fn conditional_statement(s: Span) -> IResult<Span, ConditionalStatement> {
let (s, x) = opt(unique_priority)(s)?; let (s, a) = opt(unique_priority)(s)?;
let (s, _) = symbol("if")(s)?; let (s, b) = symbol("if")(s)?;
let (s, y) = conditional_statement_body(s)?; let (s, c) = paren2(cond_predicate)(s)?;
let (s, z) = many0(preceded( let (s, d) = statement_or_null(s)?;
pair(symbol("else"), symbol("if")), let (s, e) = many0(tuple((
conditional_statement_body, symbol("else"),
))(s)?; symbol("if"),
let (s, v) = opt(preceded(symbol("else"), statement_or_null))(s)?; paren2(cond_predicate),
statement_or_null,
)))(s)?;
let (s, f) = opt(pair(symbol("else"), statement_or_null))(s)?;
Ok(( Ok((
s, s,
ConditionalStatement { ConditionalStatement {
nodes: (x, y, z, v), nodes: (a, b, c, d, e, f),
}, },
)) ))
} }
pub fn conditional_statement_body(s: Span) -> IResult<Span, 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 { nodes: (x, y) }))
}
pub fn unique_priority(s: Span) -> IResult<Span, UniquePriority> { pub fn unique_priority(s: Span) -> IResult<Span, UniquePriority> {
alt(( alt((
map(symbol("unique0"), |_| UniquePriority::Unique0), map(symbol("unique0"), |x| UniquePriority::Unique0(x)),
map(symbol("unique"), |_| UniquePriority::Unique), map(symbol("unique"), |x| UniquePriority::Unique(x)),
map(symbol("priority"), |_| UniquePriority::Priority), map(symbol("priority"), |x| UniquePriority::Priority(x)),
))(s) ))(s)
} }
pub fn cond_predicate(s: Span) -> IResult<Span, CondPredicate> { pub fn cond_predicate(s: Span) -> IResult<Span, CondPredicate> {
let (s, x) = separated_nonempty_list(symbol("&&&"), expression_or_cond_pattern)(s)?; let (s, a) = list(symbol("&&&"), expression_or_cond_pattern)(s)?;
Ok((s, CondPredicate { nodes: (x,) })) Ok((s, CondPredicate { nodes: (a,) }))
} }
pub fn expression_or_cond_pattern(s: Span) -> IResult<Span, ExpressionOrCondPattern> { pub fn expression_or_cond_pattern(s: Span) -> IResult<Span, ExpressionOrCondPattern> {
@ -95,8 +92,8 @@ pub fn expression_or_cond_pattern(s: Span) -> IResult<Span, ExpressionOrCondPatt
} }
pub fn cond_pattern(s: Span) -> IResult<Span, CondPattern> { pub fn cond_pattern(s: Span) -> IResult<Span, CondPattern> {
let (s, x) = expression(s)?; let (s, a) = expression(s)?;
let (s, _) = symbol("matches")(s)?; let (s, b) = symbol("matches")(s)?;
let (s, y) = pattern(s)?; let (s, c) = pattern(s)?;
Ok((s, CondPattern { nodes: (x, y) })) Ok((s, CondPattern { nodes: (a, b, c) }))
} }

View File

@ -1,7 +1,7 @@
use crate::ast::*;
use crate::parser::*; use crate::parser::*;
use nom::branch::*; use nom::branch::*;
use nom::combinator::*; use nom::combinator::*;
use nom::multi::*;
use nom::sequence::*; use nom::sequence::*;
use nom::IResult; use nom::IResult;
@ -19,60 +19,92 @@ pub enum LoopStatement<'a> {
#[derive(Debug)] #[derive(Debug)]
pub struct LoopStatementForever<'a> { pub struct LoopStatementForever<'a> {
pub nodes: (StatementOrNull<'a>,), pub nodes: (Symbol<'a>, StatementOrNull<'a>),
} }
#[derive(Debug)] #[derive(Debug)]
pub struct LoopStatementRepeat<'a> { pub struct LoopStatementRepeat<'a> {
pub nodes: (Expression<'a>, StatementOrNull<'a>), pub nodes: (Symbol<'a>, Paren<'a, Expression<'a>>, StatementOrNull<'a>),
} }
#[derive(Debug)] #[derive(Debug)]
pub struct LoopStatementWhile<'a> { pub struct LoopStatementWhile<'a> {
pub nodes: (Expression<'a>, StatementOrNull<'a>), pub nodes: (Symbol<'a>, Paren<'a, Expression<'a>>, StatementOrNull<'a>),
} }
#[derive(Debug)] #[derive(Debug)]
pub struct LoopStatementFor<'a> { pub struct LoopStatementFor<'a> {
pub nodes: ( pub nodes: (
Option<ForInitialization<'a>>, Symbol<'a>,
Option<Expression<'a>>, Paren<
Option<Vec<ForStepAssignment<'a>>>, 'a,
(
Option<ForInitialization<'a>>,
Symbol<'a>,
Option<Expression<'a>>,
Symbol<'a>,
Option<ForStep<'a>>,
),
>,
StatementOrNull<'a>, StatementOrNull<'a>,
), ),
} }
#[derive(Debug)] #[derive(Debug)]
pub struct LoopStatementDoWhile<'a> { pub struct LoopStatementDoWhile<'a> {
pub nodes: (StatementOrNull<'a>, Expression<'a>), pub nodes: (
Symbol<'a>,
StatementOrNull<'a>,
Symbol<'a>,
Paren<'a, Expression<'a>>,
Symbol<'a>,
),
} }
#[derive(Debug)] #[derive(Debug)]
pub struct LoopStatementForeach<'a> { pub struct LoopStatementForeach<'a> {
pub nodes: ( pub nodes: (
PsOrHierarchicalArrayIdentifier<'a>, Symbol<'a>,
LoopVariables<'a>, Paren<
'a,
(
PsOrHierarchicalArrayIdentifier<'a>,
Bracket<'a, LoopVariables<'a>>,
),
>,
Statement<'a>, Statement<'a>,
), ),
} }
#[derive(Debug)] #[derive(Debug)]
pub enum ForInitialization<'a> { pub enum ForInitialization<'a> {
Assignment(ListOfVariableAssignments<'a>), ListOfVariableAssignments(ListOfVariableAssignments<'a>),
Declaration(Vec<ForVariableDeclaration<'a>>), Declaration(ForInitializationDeclaration<'a>),
}
#[derive(Debug)]
pub struct ForInitializationDeclaration<'a> {
pub nodes: (List<Symbol<'a>, ForVariableDeclaration<'a>>,),
} }
#[derive(Debug)] #[derive(Debug)]
pub struct ForVariableDeclaration<'a> { pub struct ForVariableDeclaration<'a> {
pub nodes: ( pub nodes: (
Option<Var>, Option<Var<'a>>,
DataType<'a>, DataType<'a>,
Vec<(VariableIdentifier<'a>, Expression<'a>)>, List<Symbol<'a>, (VariableIdentifier<'a>, Symbol<'a>, Expression<'a>)>,
), ),
} }
#[derive(Debug, Node)]
pub struct Var<'a> {
pub nodes: (Symbol<'a>,),
}
#[derive(Debug)] #[derive(Debug)]
pub struct Var {} pub struct ForStep<'a> {
pub nodes: (List<Symbol<'a>, ForStepAssignment<'a>>,),
}
#[derive(Debug)] #[derive(Debug)]
pub enum ForStepAssignment<'a> { pub enum ForStepAssignment<'a> {
@ -83,7 +115,7 @@ pub enum ForStepAssignment<'a> {
#[derive(Debug)] #[derive(Debug)]
pub struct LoopVariables<'a> { pub struct LoopVariables<'a> {
pub nodes: (Vec<Option<IndexVariableIdentifier<'a>>>,), pub nodes: (List<Symbol<'a>, Option<IndexVariableIdentifier<'a>>>,),
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -100,114 +132,109 @@ pub fn loop_statement(s: Span) -> IResult<Span, LoopStatement> {
} }
pub fn loop_statement_forever(s: Span) -> IResult<Span, LoopStatement> { pub fn loop_statement_forever(s: Span) -> IResult<Span, LoopStatement> {
let (s, _) = symbol("forever")(s)?; let (s, a) = symbol("forever")(s)?;
let (s, x) = statement_or_null(s)?; let (s, b) = statement_or_null(s)?;
Ok(( Ok((
s, s,
LoopStatement::Forever(LoopStatementForever { nodes: (x,) }), LoopStatement::Forever(LoopStatementForever { nodes: (a, b) }),
)) ))
} }
pub fn loop_statement_repeat(s: Span) -> IResult<Span, LoopStatement> { pub fn loop_statement_repeat(s: Span) -> IResult<Span, LoopStatement> {
let (s, _) = symbol("repeat")(s)?; let (s, a) = symbol("repeat")(s)?;
let (s, _) = symbol("(")(s)?; let (s, b) = paren2(expression)(s)?;
let (s, x) = expression(s)?; let (s, c) = statement_or_null(s)?;
let (s, _) = symbol(")")(s)?;
let (s, y) = statement_or_null(s)?;
Ok(( Ok((
s, s,
LoopStatement::Repeat(LoopStatementRepeat { nodes: (x, y) }), LoopStatement::Repeat(LoopStatementRepeat { nodes: (a, b, c) }),
)) ))
} }
pub fn loop_statement_while(s: Span) -> IResult<Span, LoopStatement> { pub fn loop_statement_while(s: Span) -> IResult<Span, LoopStatement> {
let (s, _) = symbol("while")(s)?; let (s, a) = symbol("while")(s)?;
let (s, _) = symbol("(")(s)?; let (s, b) = paren2(expression)(s)?;
let (s, x) = expression(s)?; let (s, c) = statement_or_null(s)?;
let (s, _) = symbol(")")(s)?;
let (s, y) = statement_or_null(s)?;
Ok(( Ok((
s, s,
LoopStatement::While(LoopStatementWhile { nodes: (x, y) }), LoopStatement::While(LoopStatementWhile { nodes: (a, b, c) }),
)) ))
} }
pub fn loop_statement_for(s: Span) -> IResult<Span, LoopStatement> { pub fn loop_statement_for(s: Span) -> IResult<Span, LoopStatement> {
let (s, _) = symbol("for")(s)?; let (s, a) = symbol("for")(s)?;
let (s, _) = symbol("(")(s)?; let (s, b) = paren2(tuple((
let (s, x) = opt(for_initialization)(s)?; opt(for_initialization),
let (s, _) = symbol(";")(s)?; symbol(":"),
let (s, y) = opt(expression)(s)?; opt(expression),
let (s, _) = symbol(";")(s)?; symbol(":"),
let (s, z) = opt(for_step)(s)?; opt(for_step),
let (s, _) = symbol(")")(s)?; )))(s)?;
let (s, v) = statement_or_null(s)?; let (s, c) = statement_or_null(s)?;
Ok((s, LoopStatement::For(LoopStatementFor { nodes: (a, b, c) })))
}
pub fn loop_statement_do_while(s: Span) -> IResult<Span, LoopStatement> {
let (s, a) = symbol("do")(s)?;
let (s, b) = statement_or_null(s)?;
let (s, c) = symbol("while")(s)?;
let (s, d) = paren2(expression)(s)?;
let (s, e) = symbol(";")(s)?;
Ok(( Ok((
s, s,
LoopStatement::For(LoopStatementFor { LoopStatement::DoWhile(LoopStatementDoWhile {
nodes: (x, y, z, v), nodes: (a, b, c, d, e),
}), }),
)) ))
} }
pub fn loop_statement_do_while(s: Span) -> IResult<Span, LoopStatement> {
let (s, _) = symbol("do")(s)?;
let (s, x) = statement_or_null(s)?;
let (s, _) = symbol("while")(s)?;
let (s, _) = symbol("(")(s)?;
let (s, y) = expression(s)?;
let (s, _) = symbol(")")(s)?;
let (s, _) = symbol(";")(s)?;
Ok((
s,
LoopStatement::DoWhile(LoopStatementDoWhile { nodes: (x, y) }),
))
}
pub fn loop_statement_foreach(s: Span) -> IResult<Span, LoopStatement> { pub fn loop_statement_foreach(s: Span) -> IResult<Span, LoopStatement> {
let (s, _) = symbol("foreach")(s)?; let (s, a) = symbol("foreach")(s)?;
let (s, _) = symbol("(")(s)?; let (s, b) = paren2(pair(
let (s, x) = ps_or_hierarchical_array_identifier(s)?; ps_or_hierarchical_array_identifier,
let (s, _) = symbol("[")(s)?; bracket2(loop_variables),
let (s, y) = loop_variables(s)?; ))(s)?;
let (s, _) = symbol("]")(s)?; let (s, c) = statement(s)?;
let (s, _) = symbol(")")(s)?;
let (s, z) = statement(s)?;
Ok(( Ok((
s, s,
LoopStatement::Foreach(LoopStatementForeach { nodes: (x, y, z) }), LoopStatement::Foreach(LoopStatementForeach { nodes: (a, b, c) }),
)) ))
} }
pub fn for_initialization(s: Span) -> IResult<Span, ForInitialization> { pub fn for_initialization(s: Span) -> IResult<Span, ForInitialization> {
alt(( alt((
map(list_of_variable_assignments, |x| { map(list_of_variable_assignments, |x| {
ForInitialization::Assignment(x) ForInitialization::ListOfVariableAssignments(x)
}), }),
map( for_initialization_declaration,
separated_nonempty_list(symbol(","), for_variable_declaration),
|x| ForInitialization::Declaration(x),
),
))(s) ))(s)
} }
pub fn for_variable_declaration(s: Span) -> IResult<Span, ForVariableDeclaration> { pub fn for_initialization_declaration(s: Span) -> IResult<Span, ForInitialization> {
let (s, x) = opt(symbol("var"))(s)?; let (s, a) = list(symbol(","), for_variable_declaration)(s)?;
let (s, y) = data_type(s)?;
let (s, z) = separated_nonempty_list(
symbol(","),
pair(variable_identifier, preceded(symbol("="), expression)),
)(s)?;
Ok(( Ok((
s, s,
ForVariableDeclaration { ForInitialization::Declaration(ForInitializationDeclaration { nodes: (a,) }),
nodes: (x.map(|_| Var {}), y, z),
},
)) ))
} }
pub fn for_step(s: Span) -> IResult<Span, Vec<ForStepAssignment>> { pub fn for_variable_declaration(s: Span) -> IResult<Span, ForVariableDeclaration> {
separated_nonempty_list(symbol(","), for_step_assignment)(s) let (s, a) = opt(var)(s)?;
let (s, b) = data_type(s)?;
let (s, c) = list(
symbol(","),
triple(variable_identifier, symbol("="), expression),
)(s)?;
Ok((s, ForVariableDeclaration { nodes: (a, b, c) }))
}
pub fn var(s: Span) -> IResult<Span, Var> {
let (s, a) = symbol("var")(s)?;
Ok((s, Var { nodes: (a,) }))
}
pub fn for_step(s: Span) -> IResult<Span, ForStep> {
let (s, a) = list(symbol(","), for_step_assignment)(s)?;
Ok((s, ForStep { nodes: (a,) }))
} }
pub fn for_step_assignment(s: Span) -> IResult<Span, ForStepAssignment> { pub fn for_step_assignment(s: Span) -> IResult<Span, ForStepAssignment> {
@ -225,8 +252,8 @@ pub fn for_step_assignment(s: Span) -> IResult<Span, ForStepAssignment> {
} }
pub fn loop_variables(s: Span) -> IResult<Span, LoopVariables> { pub fn loop_variables(s: Span) -> IResult<Span, LoopVariables> {
let (s, x) = separated_nonempty_list(symbol(","), opt(index_variable_identifier))(s)?; let (s, a) = list(symbol(","), opt(index_variable_identifier))(s)?;
Ok((s, LoopVariables { nodes: (x,) })) Ok((s, LoopVariables { nodes: (a,) }))
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------

View File

@ -1,7 +1,7 @@
use crate::ast::*;
use crate::parser::*; use crate::parser::*;
use nom::branch::*; use nom::branch::*;
use nom::combinator::*; use nom::combinator::*;
use nom::multi::*;
use nom::sequence::*; use nom::sequence::*;
use nom::IResult; use nom::IResult;
@ -9,38 +9,94 @@ use nom::IResult;
#[derive(Debug)] #[derive(Debug)]
pub enum Pattern<'a> { pub enum Pattern<'a> {
VariableIdentifier(Box<VariableIdentifier<'a>>), Variable(Box<PatternVariable<'a>>),
Asterisk, Asterisk(Symbol<'a>),
ConstantExpression(Box<ConstantExpression<'a>>), ConstantExpression(Box<ConstantExpression<'a>>),
Tagged(Box<(MemberIdentifier<'a>, Option<Pattern<'a>>)>), Tagged(Box<PatternTagged<'a>>),
Pattern(Box<Vec<Pattern<'a>>>), List(Box<PatternList<'a>>),
MemberPattern(Box<Vec<(MemberIdentifier<'a>, Pattern<'a>)>>), IdentifierList(Box<PatternIdentifierList<'a>>),
}
#[derive(Debug, Node)]
pub struct PatternVariable<'a> {
pub nodes: (Symbol<'a>, VariableIdentifier<'a>),
}
#[derive(Debug)]
pub struct PatternTagged<'a> {
pub nodes: (Symbol<'a>, MemberIdentifier<'a>, Option<Pattern<'a>>),
}
#[derive(Debug)]
pub struct PatternList<'a> {
pub nodes: (ApostropheBrace<'a, List<Symbol<'a>, Pattern<'a>>>,),
}
#[derive(Debug)]
pub struct PatternIdentifierList<'a> {
pub nodes:
(ApostropheBrace<'a, List<Symbol<'a>, (MemberIdentifier<'a>, Symbol<'a>, Pattern<'a>)>>,),
} }
#[derive(Debug)] #[derive(Debug)]
pub enum AssignmentPattern<'a> { pub enum AssignmentPattern<'a> {
Expression(Vec<Expression<'a>>), List(AssignmentPatternList<'a>),
StructurePatternKey(Vec<(StructurePatternKey<'a>, Expression<'a>)>), Structure(AssignmentPatternStructure<'a>),
ArrayPatternKey(Vec<(ArrayPatternKey<'a>, Expression<'a>)>), Array(AssignmentPatternArray<'a>),
ConstantExpression((ConstantExpression<'a>, Vec<Expression<'a>>)), Repeat(AssignmentPatternRepeat<'a>),
}
#[derive(Debug)]
pub struct AssignmentPatternList<'a> {
pub nodes: (ApostropheBrace<'a, List<Symbol<'a>, Expression<'a>>>,),
}
#[derive(Debug)]
pub struct AssignmentPatternStructure<'a> {
pub nodes: (
ApostropheBrace<
'a,
List<Symbol<'a>, (StructurePatternKey<'a>, Symbol<'a>, Expression<'a>)>,
>,
),
}
#[derive(Debug)]
pub struct AssignmentPatternArray<'a> {
pub nodes: (
ApostropheBrace<'a, List<Symbol<'a>, (ArrayPatternKey<'a>, Symbol<'a>, Expression<'a>)>>,
),
}
#[derive(Debug)]
pub struct AssignmentPatternRepeat<'a> {
pub nodes: (
ApostropheBrace<
'a,
(
ConstantExpression<'a>,
Brace<'a, List<Symbol<'a>, Expression<'a>>>,
),
>,
),
} }
#[derive(Debug)] #[derive(Debug)]
pub enum StructurePatternKey<'a> { pub enum StructurePatternKey<'a> {
Identifier(MemberIdentifier<'a>), MemberIdentifier(MemberIdentifier<'a>),
PatternKey(AssignmentPatternKey<'a>), AssignmentPatternKey(AssignmentPatternKey<'a>),
} }
#[derive(Debug)] #[derive(Debug)]
pub enum ArrayPatternKey<'a> { pub enum ArrayPatternKey<'a> {
Expression(ConstantExpression<'a>), ConstantExpression(ConstantExpression<'a>),
PatternKey(AssignmentPatternKey<'a>), AssignmentPatternKey(AssignmentPatternKey<'a>),
} }
#[derive(Debug)] #[derive(Debug)]
pub enum AssignmentPatternKey<'a> { pub enum AssignmentPatternKey<'a> {
SimpleType(SimpleType<'a>), SimpleType(SimpleType<'a>),
Default, Default(Symbol<'a>),
} }
#[derive(Debug)] #[derive(Debug)]
@ -53,9 +109,9 @@ pub struct AssignmentPatternExpression<'a> {
#[derive(Debug)] #[derive(Debug)]
pub enum AssignmentPatternExpressionType<'a> { pub enum AssignmentPatternExpressionType<'a> {
Type(PsTypeIdentifier<'a>), PsTypeIdentifier(PsTypeIdentifier<'a>),
Parameter(PsParameterIdentifier<'a>), PsParameterIdentifier(PsParameterIdentifier<'a>),
IntegerAtom(IntegerAtomType), IntegerAtomType(IntegerAtomType),
TypeReference(TypeReference<'a>), TypeReference(TypeReference<'a>),
} }
@ -66,100 +122,147 @@ pub struct ConstantAssignmentPatternExpression<'a> {
#[derive(Debug)] #[derive(Debug)]
pub struct AssignmentPatternNetLvalue<'a> { pub struct AssignmentPatternNetLvalue<'a> {
pub nodes: (Vec<NetLvalue<'a>>,), pub nodes: (ApostropheBrace<'a, List<Symbol<'a>, NetLvalue<'a>>>,),
} }
#[derive(Debug)] #[derive(Debug)]
pub struct AssignmentPatternVariableLvalue<'a> { pub struct AssignmentPatternVariableLvalue<'a> {
pub nodes: (Vec<VariableLvalue<'a>>,), pub nodes: (ApostropheBrace<'a, List<Symbol<'a>, VariableLvalue<'a>>>,),
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
pub fn pattern(s: Span) -> IResult<Span, Pattern> { pub fn pattern(s: Span) -> IResult<Span, Pattern> {
alt(( alt((
map(preceded(symbol("."), variable_identifier), |x| { pattern_variable,
Pattern::VariableIdentifier(Box::new(x)) map(symbol(".*"), |x| Pattern::Asterisk(x)),
}),
map(symbol(".*"), |_| Pattern::Asterisk),
map(constant_expression, |x| { map(constant_expression, |x| {
Pattern::ConstantExpression(Box::new(x)) Pattern::ConstantExpression(Box::new(x))
}), }),
map( pattern_tagged,
preceded(symbol("tagged"), pair(member_identifier, opt(pattern))), pattern_list,
|x| Pattern::Tagged(Box::new(x)), pattern_identifier_list,
),
map(
apostrophe_brace(separated_nonempty_list(symbol(","), pattern)),
|x| Pattern::Pattern(Box::new(x)),
),
map(
apostrophe_brace(separated_nonempty_list(
symbol(","),
pair(member_identifier, preceded(symbol(":"), pattern)),
)),
|x| Pattern::MemberPattern(Box::new(x)),
),
))(s) ))(s)
} }
pub fn pattern_variable(s: Span) -> IResult<Span, Pattern> {
let (s, a) = symbol(".")(s)?;
let (s, b) = variable_identifier(s)?;
Ok((
s,
Pattern::Variable(Box::new(PatternVariable { nodes: (a, b) })),
))
}
pub fn pattern_tagged(s: Span) -> IResult<Span, Pattern> {
let (s, a) = symbol("tagged")(s)?;
let (s, b) = member_identifier(s)?;
let (s, c) = opt(pattern)(s)?;
Ok((
s,
Pattern::Tagged(Box::new(PatternTagged { nodes: (a, b, c) })),
))
}
pub fn pattern_list(s: Span) -> IResult<Span, Pattern> {
let (s, a) = apostrophe_brace2(list(symbol(","), pattern))(s)?;
Ok((s, Pattern::List(Box::new(PatternList { nodes: (a,) }))))
}
pub fn pattern_identifier_list(s: Span) -> IResult<Span, Pattern> {
let (s, a) = apostrophe_brace2(list(
symbol(","),
triple(member_identifier, symbol(":"), pattern),
))(s)?;
Ok((
s,
Pattern::IdentifierList(Box::new(PatternIdentifierList { nodes: (a,) })),
))
}
pub fn assignment_pattern(s: Span) -> IResult<Span, AssignmentPattern> { pub fn assignment_pattern(s: Span) -> IResult<Span, AssignmentPattern> {
alt(( alt((
map( assignment_pattern_list,
apostrophe_brace(separated_nonempty_list(symbol(","), expression)), assignment_pattern_structure,
|x| AssignmentPattern::Expression(x), assignment_pattern_array,
), assignment_pattern_repeat,
map(
apostrophe_brace(separated_nonempty_list(
symbol(","),
pair(structure_pattern_key, preceded(symbol(":"), expression)),
)),
|x| AssignmentPattern::StructurePatternKey(x),
),
map(
apostrophe_brace(separated_nonempty_list(
symbol(","),
pair(array_pattern_key, preceded(symbol(":"), expression)),
)),
|x| AssignmentPattern::ArrayPatternKey(x),
),
map(
apostrophe_brace(pair(
constant_expression,
brace(separated_nonempty_list(symbol(","), expression)),
)),
|x| AssignmentPattern::ConstantExpression(x),
),
))(s) ))(s)
} }
pub fn assignment_pattern_list(s: Span) -> IResult<Span, AssignmentPattern> {
let (s, a) = apostrophe_brace2(list(symbol(","), expression))(s)?;
Ok((
s,
AssignmentPattern::List(AssignmentPatternList { nodes: (a,) }),
))
}
pub fn assignment_pattern_structure(s: Span) -> IResult<Span, AssignmentPattern> {
let (s, a) = apostrophe_brace2(list(
symbol(","),
triple(structure_pattern_key, symbol(":"), expression),
))(s)?;
Ok((
s,
AssignmentPattern::Structure(AssignmentPatternStructure { nodes: (a,) }),
))
}
pub fn assignment_pattern_array(s: Span) -> IResult<Span, AssignmentPattern> {
let (s, a) = apostrophe_brace2(list(
symbol(","),
triple(array_pattern_key, symbol(":"), expression),
))(s)?;
Ok((
s,
AssignmentPattern::Array(AssignmentPatternArray { nodes: (a,) }),
))
}
pub fn assignment_pattern_repeat(s: Span) -> IResult<Span, AssignmentPattern> {
let (s, a) = apostrophe_brace2(pair(
constant_expression,
brace2(list(symbol(","), expression)),
))(s)?;
Ok((
s,
AssignmentPattern::Repeat(AssignmentPatternRepeat { nodes: (a,) }),
))
}
pub fn structure_pattern_key(s: Span) -> IResult<Span, StructurePatternKey> { pub fn structure_pattern_key(s: Span) -> IResult<Span, StructurePatternKey> {
alt(( alt((
map(member_identifier, |x| StructurePatternKey::Identifier(x)), map(member_identifier, |x| {
StructurePatternKey::MemberIdentifier(x)
}),
map(assignment_pattern_key, |x| { map(assignment_pattern_key, |x| {
StructurePatternKey::PatternKey(x) StructurePatternKey::AssignmentPatternKey(x)
}), }),
))(s) ))(s)
} }
pub fn array_pattern_key(s: Span) -> IResult<Span, ArrayPatternKey> { pub fn array_pattern_key(s: Span) -> IResult<Span, ArrayPatternKey> {
alt(( alt((
map(constant_expression, |x| ArrayPatternKey::Expression(x)), map(constant_expression, |x| {
map(assignment_pattern_key, |x| ArrayPatternKey::PatternKey(x)), ArrayPatternKey::ConstantExpression(x)
}),
map(assignment_pattern_key, |x| {
ArrayPatternKey::AssignmentPatternKey(x)
}),
))(s) ))(s)
} }
pub fn assignment_pattern_key(s: Span) -> IResult<Span, AssignmentPatternKey> { pub fn assignment_pattern_key(s: Span) -> IResult<Span, AssignmentPatternKey> {
alt(( alt((
map(simple_type, |x| AssignmentPatternKey::SimpleType(x)), map(simple_type, |x| AssignmentPatternKey::SimpleType(x)),
map(symbol("default"), |_| AssignmentPatternKey::Default), map(symbol("default"), |x| AssignmentPatternKey::Default(x)),
))(s) ))(s)
} }
pub fn assignment_pattern_expression(s: Span) -> IResult<Span, AssignmentPatternExpression> { pub fn assignment_pattern_expression(s: Span) -> IResult<Span, AssignmentPatternExpression> {
let (s, x) = opt(assignment_pattern_expression_type)(s)?; let (s, a) = opt(assignment_pattern_expression_type)(s)?;
let (s, y) = assignment_pattern(s)?; let (s, b) = assignment_pattern(s)?;
Ok((s, AssignmentPatternExpression { nodes: (x, y) })) Ok((s, AssignmentPatternExpression { nodes: (a, b) }))
} }
pub fn assignment_pattern_expression_type( pub fn assignment_pattern_expression_type(
@ -167,13 +270,13 @@ pub fn assignment_pattern_expression_type(
) -> IResult<Span, AssignmentPatternExpressionType> { ) -> IResult<Span, AssignmentPatternExpressionType> {
alt(( alt((
map(ps_type_identifier, |x| { map(ps_type_identifier, |x| {
AssignmentPatternExpressionType::Type(x) AssignmentPatternExpressionType::PsTypeIdentifier(x)
}), }),
map(ps_parameter_identifier, |x| { map(ps_parameter_identifier, |x| {
AssignmentPatternExpressionType::Parameter(x) AssignmentPatternExpressionType::PsParameterIdentifier(x)
}), }),
map(integer_atom_type, |x| { map(integer_atom_type, |x| {
AssignmentPatternExpressionType::IntegerAtom(x) AssignmentPatternExpressionType::IntegerAtomType(x)
}), }),
map(type_reference, |x| { map(type_reference, |x| {
AssignmentPatternExpressionType::TypeReference(x) AssignmentPatternExpressionType::TypeReference(x)
@ -189,15 +292,15 @@ pub fn constant_assignment_pattern_expression(
} }
pub fn assignment_pattern_net_lvalue(s: Span) -> IResult<Span, AssignmentPatternNetLvalue> { pub fn assignment_pattern_net_lvalue(s: Span) -> IResult<Span, AssignmentPatternNetLvalue> {
let (s, x) = apostrophe_brace(separated_nonempty_list(symbol(","), net_lvalue))(s)?; let (s, a) = apostrophe_brace2(list(symbol(","), net_lvalue))(s)?;
Ok((s, AssignmentPatternNetLvalue { nodes: (x,) })) Ok((s, AssignmentPatternNetLvalue { nodes: (a,) }))
} }
pub fn assignment_pattern_variable_lvalue( pub fn assignment_pattern_variable_lvalue(
s: Span, s: Span,
) -> IResult<Span, AssignmentPatternVariableLvalue> { ) -> IResult<Span, AssignmentPatternVariableLvalue> {
let (s, x) = apostrophe_brace(separated_nonempty_list(symbol(","), variable_lvalue))(s)?; let (s, a) = apostrophe_brace2(list(symbol(","), variable_lvalue))(s)?;
Ok((s, AssignmentPatternVariableLvalue { nodes: (x,) })) Ok((s, AssignmentPatternVariableLvalue { nodes: (a,) }))
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------

View File

@ -79,7 +79,7 @@ pub struct RsRepeat<'a> {
#[derive(Debug)] #[derive(Debug)]
pub struct RsCase<'a> { pub struct RsCase<'a> {
pub nodes: (Expression<'a>, Vec<RsCaseItem<'a>>), pub nodes: (CaseExpression<'a>, Vec<RsCaseItem<'a>>),
} }
#[derive(Debug)] #[derive(Debug)]
@ -95,7 +95,7 @@ pub struct RsCaseItemDefault<'a> {
#[derive(Debug)] #[derive(Debug)]
pub struct RsCaseItemNondefault<'a> { pub struct RsCaseItemNondefault<'a> {
pub nodes: (Vec<Expression<'a>>, ProductionItem<'a>), pub nodes: (Vec<CaseItemExpression<'a>>, ProductionItem<'a>),
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------

View File

@ -1,7 +1,7 @@
use crate::ast::*;
use crate::parser::*; use crate::parser::*;
use nom::branch::*; use nom::branch::*;
use nom::combinator::*; use nom::combinator::*;
use nom::multi::*;
use nom::sequence::*; use nom::sequence::*;
use nom::IResult; use nom::IResult;
@ -21,30 +21,66 @@ pub enum DelayOrEventControl<'a> {
#[derive(Debug)] #[derive(Debug)]
pub struct DelayOrEventControlRepeat<'a> { pub struct DelayOrEventControlRepeat<'a> {
pub nodes: (Expression<'a>, EventControl<'a>), pub nodes: (Symbol<'a>, Paren<'a, Expression<'a>>, EventControl<'a>),
} }
#[derive(Debug)] #[derive(Debug)]
pub enum DelayControl<'a> { pub enum DelayControl<'a> {
Delay(DelayValue<'a>), Delay(DelayControlDelay<'a>),
Mintypmax(MintypmaxExpression<'a>), Mintypmax(DelayControlMintypmax<'a>),
}
#[derive(Debug, Node)]
pub struct DelayControlDelay<'a> {
pub nodes: (Symbol<'a>, DelayValue<'a>),
}
#[derive(Debug)]
pub struct DelayControlMintypmax<'a> {
pub nodes: (Symbol<'a>, Paren<'a, MintypmaxExpression<'a>>),
} }
#[derive(Debug)] #[derive(Debug)]
pub enum EventControl<'a> { pub enum EventControl<'a> {
EventIdentifier(HierarchicalEventIdentifier<'a>), EventIdentifier(EventControlEventIdentifier<'a>),
EventExpression(EventExpression<'a>), EventExpression(EventControlEventExpression<'a>),
Asterisk, Asterisk(EventControlAsterisk<'a>),
SequenceIdentifier(PsOrHierarchicalSequenceIdentifier<'a>), ParenAsterisk(EventControlParenAsterisk<'a>),
SequenceIdentifier(EventControlSequenceIdentifier<'a>),
}
#[derive(Debug)]
pub struct EventControlEventIdentifier<'a> {
pub nodes: (Symbol<'a>, HierarchicalEventIdentifier<'a>),
}
#[derive(Debug)]
pub struct EventControlEventExpression<'a> {
pub nodes: (Symbol<'a>, Paren<'a, EventExpression<'a>>),
}
#[derive(Debug, Node)]
pub struct EventControlAsterisk<'a> {
pub nodes: (Symbol<'a>,),
}
#[derive(Debug, Node)]
pub struct EventControlParenAsterisk<'a> {
pub nodes: (Symbol<'a>, Paren<'a, Symbol<'a>>),
}
#[derive(Debug)]
pub struct EventControlSequenceIdentifier<'a> {
pub nodes: (Symbol<'a>, PsOrHierarchicalSequenceIdentifier<'a>),
} }
#[derive(Debug)] #[derive(Debug)]
pub enum EventExpression<'a> { pub enum EventExpression<'a> {
Expression(Box<EventExpressionExpression<'a>>), Expression(Box<EventExpressionExpression<'a>>),
Sequence(Box<EventExpressionSequence<'a>>), Sequence(Box<EventExpressionSequence<'a>>),
Or(Box<(EventExpression<'a>, EventExpression<'a>)>), Or(Box<EventExpressionOr<'a>>),
Comma(Box<(EventExpression<'a>, EventExpression<'a>)>), Comma(Box<EventExpressionComma<'a>>),
Paren(Box<EventExpression<'a>>), Paren(Box<EventExpressionParen<'a>>),
} }
#[derive(Debug)] #[derive(Debug)]
@ -52,13 +88,28 @@ pub struct EventExpressionExpression<'a> {
pub nodes: ( pub nodes: (
Option<EdgeIdentifier<'a>>, Option<EdgeIdentifier<'a>>,
Expression<'a>, Expression<'a>,
Option<Expression<'a>>, Option<(Symbol<'a>, Expression<'a>)>,
), ),
} }
#[derive(Debug)] #[derive(Debug)]
pub struct EventExpressionSequence<'a> { pub struct EventExpressionSequence<'a> {
pub nodes: (SequenceInstance<'a>, Option<Expression<'a>>), pub nodes: (SequenceInstance<'a>, Option<(Symbol<'a>, Expression<'a>)>),
}
#[derive(Debug)]
pub struct EventExpressionOr<'a> {
pub nodes: (EventExpression<'a>, Symbol<'a>, EventExpression<'a>),
}
#[derive(Debug)]
pub struct EventExpressionComma<'a> {
pub nodes: (EventExpression<'a>, Symbol<'a>, EventExpression<'a>),
}
#[derive(Debug)]
pub struct EventExpressionParen<'a> {
pub nodes: (Paren<'a, EventExpression<'a>>,),
} }
#[derive(Debug)] #[derive(Debug)]
@ -71,30 +122,49 @@ pub enum ProceduralTimingControl<'a> {
#[derive(Debug)] #[derive(Debug)]
pub enum JumpStatement<'a> { pub enum JumpStatement<'a> {
Return(JumpStatementReturn<'a>), Return(JumpStatementReturn<'a>),
Break, Break(JumpStatementBreak<'a>),
Continue, Continue(JumpStatementContinue<'a>),
} }
#[derive(Debug)] #[derive(Debug)]
pub struct JumpStatementReturn<'a> { pub struct JumpStatementReturn<'a> {
pub nodes: (Option<Expression<'a>>,), pub nodes: (Symbol<'a>, Option<Expression<'a>>, Symbol<'a>),
}
#[derive(Debug, Node)]
pub struct JumpStatementBreak<'a> {
pub nodes: (Symbol<'a>, Symbol<'a>),
}
#[derive(Debug, Node)]
pub struct JumpStatementContinue<'a> {
pub nodes: (Symbol<'a>, Symbol<'a>),
} }
#[derive(Debug)] #[derive(Debug)]
pub enum WaitStatement<'a> { pub enum WaitStatement<'a> {
Wait(WaitStatementWait<'a>), Wait(WaitStatementWait<'a>),
Fork, Fork(WaitStatementFork<'a>),
Order(WaitStatementOrder<'a>), Order(WaitStatementOrder<'a>),
} }
#[derive(Debug)] #[derive(Debug)]
pub struct WaitStatementWait<'a> { pub struct WaitStatementWait<'a> {
pub nodes: (Expression<'a>, StatementOrNull<'a>), pub nodes: (Symbol<'a>, Paren<'a, Expression<'a>>, StatementOrNull<'a>),
}
#[derive(Debug, Node)]
pub struct WaitStatementFork<'a> {
pub nodes: (Symbol<'a>, Symbol<'a>, Symbol<'a>),
} }
#[derive(Debug)] #[derive(Debug)]
pub struct WaitStatementOrder<'a> { pub struct WaitStatementOrder<'a> {
pub nodes: (Vec<HierarchicalIdentifier<'a>>, ActionBlock<'a>), pub nodes: (
Symbol<'a>,
Paren<'a, List<Symbol<'a>, HierarchicalIdentifier<'a>>>,
ActionBlock<'a>,
),
} }
#[derive(Debug)] #[derive(Debug)]
@ -105,22 +175,39 @@ pub enum EventTrigger<'a> {
#[derive(Debug)] #[derive(Debug)]
pub struct EventTriggerNamed<'a> { pub struct EventTriggerNamed<'a> {
pub nodes: (HierarchicalEventIdentifier<'a>,), pub nodes: (Symbol<'a>, HierarchicalEventIdentifier<'a>, Symbol<'a>),
} }
#[derive(Debug)] #[derive(Debug)]
pub struct EventTriggerNonblocking<'a> { pub struct EventTriggerNonblocking<'a> {
pub nodes: ( pub nodes: (
Symbol<'a>,
Option<DelayOrEventControl<'a>>, Option<DelayOrEventControl<'a>>,
HierarchicalEventIdentifier<'a>, HierarchicalEventIdentifier<'a>,
Symbol<'a>,
), ),
} }
#[derive(Debug)] #[derive(Debug)]
pub enum DisableStatement<'a> { pub enum DisableStatement<'a> {
Task(HierarchicalTaskIdentifier<'a>), Task(DisableStatementTask<'a>),
Block(HierarchicalBlockIdentifier<'a>), Block(DisableStatementBlock<'a>),
Fork, Fork(DisableStatementFork<'a>),
}
#[derive(Debug)]
pub struct DisableStatementTask<'a> {
pub nodes: (Symbol<'a>, HierarchicalTaskIdentifier<'a>, Symbol<'a>),
}
#[derive(Debug)]
pub struct DisableStatementBlock<'a> {
pub nodes: (Symbol<'a>, HierarchicalBlockIdentifier<'a>, Symbol<'a>),
}
#[derive(Debug, Node)]
pub struct DisableStatementFork<'a> {
pub nodes: (Symbol<'a>, Symbol<'a>, Symbol<'a>),
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -128,9 +215,9 @@ pub enum DisableStatement<'a> {
pub fn procedural_timing_control_statement( pub fn procedural_timing_control_statement(
s: Span, s: Span,
) -> IResult<Span, ProceduralTimingControlStatement> { ) -> IResult<Span, ProceduralTimingControlStatement> {
let (s, x) = procedural_timing_control(s)?; let (s, a) = procedural_timing_control(s)?;
let (s, y) = statement_or_null(s)?; let (s, b) = statement_or_null(s)?;
Ok((s, ProceduralTimingControlStatement { nodes: (x, y) })) Ok((s, ProceduralTimingControlStatement { nodes: (a, b) }))
} }
pub fn delay_or_event_control(s: Span) -> IResult<Span, DelayOrEventControl> { pub fn delay_or_event_control(s: Span) -> IResult<Span, DelayOrEventControl> {
@ -142,14 +229,12 @@ pub fn delay_or_event_control(s: Span) -> IResult<Span, DelayOrEventControl> {
} }
pub fn delay_or_event_control_repeat(s: Span) -> IResult<Span, DelayOrEventControl> { pub fn delay_or_event_control_repeat(s: Span) -> IResult<Span, DelayOrEventControl> {
let (s, _) = symbol("repeat")(s)?; let (s, a) = symbol("repeat")(s)?;
let (s, _) = symbol("(")(s)?; let (s, b) = paren2(expression)(s)?;
let (s, x) = expression(s)?; let (s, c) = event_control(s)?;
let (s, _) = symbol(")")(s)?;
let (s, y) = event_control(s)?;
Ok(( Ok((
s, s,
DelayOrEventControl::Repeat(DelayOrEventControlRepeat { nodes: (x, y) }), DelayOrEventControl::Repeat(DelayOrEventControlRepeat { nodes: (a, b, c) }),
)) ))
} }
@ -158,17 +243,18 @@ pub fn delay_control(s: Span) -> IResult<Span, DelayControl> {
} }
pub fn delay_control_delay(s: Span) -> IResult<Span, DelayControl> { pub fn delay_control_delay(s: Span) -> IResult<Span, DelayControl> {
let (s, _) = symbol("#")(s)?; let (s, a) = symbol("#")(s)?;
let (s, x) = delay_value(s)?; let (s, b) = delay_value(s)?;
Ok((s, DelayControl::Delay(x))) Ok((s, DelayControl::Delay(DelayControlDelay { nodes: (a, b) })))
} }
pub fn delay_control_mintypmax(s: Span) -> IResult<Span, DelayControl> { pub fn delay_control_mintypmax(s: Span) -> IResult<Span, DelayControl> {
let (s, _) = symbol("#")(s)?; let (s, a) = symbol("#")(s)?;
let (s, _) = symbol("(")(s)?; let (s, b) = paren2(mintypmax_expression)(s)?;
let (s, x) = mintypmax_expression(s)?; Ok((
let (s, _) = symbol(")")(s)?; s,
Ok((s, DelayControl::Mintypmax(x))) DelayControl::Mintypmax(DelayControlMintypmax { nodes: (a, b) }),
))
} }
pub fn event_control(s: Span) -> IResult<Span, EventControl> { pub fn event_control(s: Span) -> IResult<Span, EventControl> {
@ -176,33 +262,53 @@ pub fn event_control(s: Span) -> IResult<Span, EventControl> {
event_control_event_identifier, event_control_event_identifier,
event_control_event_expression, event_control_event_expression,
event_control_asterisk, event_control_asterisk,
event_control_paren_asterisk,
event_control_sequence_identifier, event_control_sequence_identifier,
))(s) ))(s)
} }
pub fn event_control_event_identifier(s: Span) -> IResult<Span, EventControl> { pub fn event_control_event_identifier(s: Span) -> IResult<Span, EventControl> {
let (s, _) = symbol("@")(s)?; let (s, a) = symbol("@")(s)?;
let (s, x) = hierarchical_event_identifier(s)?; let (s, b) = hierarchical_event_identifier(s)?;
Ok((s, EventControl::EventIdentifier(x))) Ok((
s,
EventControl::EventIdentifier(EventControlEventIdentifier { nodes: (a, b) }),
))
} }
pub fn event_control_event_expression(s: Span) -> IResult<Span, EventControl> { pub fn event_control_event_expression(s: Span) -> IResult<Span, EventControl> {
let (s, _) = symbol("@")(s)?; let (s, a) = symbol("@")(s)?;
let (s, _) = symbol("(")(s)?; let (s, b) = paren2(event_expression)(s)?;
let (s, x) = event_expression(s)?; Ok((
let (s, _) = symbol(")")(s)?; s,
Ok((s, EventControl::EventExpression(x))) EventControl::EventExpression(EventControlEventExpression { nodes: (a, b) }),
))
} }
pub fn event_control_asterisk(s: Span) -> IResult<Span, EventControl> { pub fn event_control_asterisk(s: Span) -> IResult<Span, EventControl> {
let (s, _) = alt((symbol("@*"), preceded(symbol("@"), symbol("(*)"))))(s)?; let (s, a) = symbol("@*")(s)?;
Ok((s, EventControl::Asterisk)) Ok((
s,
EventControl::Asterisk(EventControlAsterisk { nodes: (a,) }),
))
}
pub fn event_control_paren_asterisk(s: Span) -> IResult<Span, EventControl> {
let (s, a) = symbol("@")(s)?;
let (s, b) = paren2(symbol("*"))(s)?;
Ok((
s,
EventControl::ParenAsterisk(EventControlParenAsterisk { nodes: (a, b) }),
))
} }
pub fn event_control_sequence_identifier(s: Span) -> IResult<Span, EventControl> { pub fn event_control_sequence_identifier(s: Span) -> IResult<Span, EventControl> {
let (s, _) = symbol("@")(s)?; let (s, a) = symbol("@")(s)?;
let (s, x) = ps_or_hierarchical_sequence_identifier(s)?; let (s, b) = ps_or_hierarchical_sequence_identifier(s)?;
Ok((s, EventControl::SequenceIdentifier(x))) Ok((
s,
EventControl::SequenceIdentifier(EventControlSequenceIdentifier { nodes: (a, b) }),
))
} }
pub fn event_expression(s: Span) -> IResult<Span, EventExpression> { pub fn event_expression(s: Span) -> IResult<Span, EventExpression> {
@ -216,43 +322,50 @@ pub fn event_expression(s: Span) -> IResult<Span, EventExpression> {
} }
pub fn event_expression_expression(s: Span) -> IResult<Span, EventExpression> { pub fn event_expression_expression(s: Span) -> IResult<Span, EventExpression> {
let (s, x) = opt(edge_identifier)(s)?; let (s, a) = opt(edge_identifier)(s)?;
let (s, y) = expression(s)?; let (s, b) = expression(s)?;
let (s, z) = opt(preceded(symbol("iff"), expression))(s)?; let (s, c) = opt(pair(symbol("iff"), expression))(s)?;
Ok(( Ok((
s, s,
EventExpression::Expression(Box::new(EventExpressionExpression { nodes: (x, y, z) })), EventExpression::Expression(Box::new(EventExpressionExpression { nodes: (a, b, c) })),
)) ))
} }
pub fn event_expression_sequence(s: Span) -> IResult<Span, EventExpression> { pub fn event_expression_sequence(s: Span) -> IResult<Span, EventExpression> {
let (s, x) = sequence_instance(s)?; let (s, a) = sequence_instance(s)?;
let (s, y) = opt(preceded(symbol("iff"), expression))(s)?; let (s, b) = opt(pair(symbol("iff"), expression))(s)?;
Ok(( Ok((
s, s,
EventExpression::Sequence(Box::new(EventExpressionSequence { nodes: (x, y) })), EventExpression::Sequence(Box::new(EventExpressionSequence { nodes: (a, b) })),
)) ))
} }
pub fn event_expression_or(s: Span) -> IResult<Span, EventExpression> { pub fn event_expression_or(s: Span) -> IResult<Span, EventExpression> {
let (s, x) = event_expression(s)?; let (s, a) = event_expression(s)?;
let (s, _) = symbol("or")(s)?; let (s, b) = symbol("or")(s)?;
let (s, y) = event_expression(s)?; let (s, c) = event_expression(s)?;
Ok((s, EventExpression::Or(Box::new((x, y))))) Ok((
s,
EventExpression::Or(Box::new(EventExpressionOr { nodes: (a, b, c) })),
))
} }
pub fn event_expression_comma(s: Span) -> IResult<Span, EventExpression> { pub fn event_expression_comma(s: Span) -> IResult<Span, EventExpression> {
let (s, x) = event_expression(s)?; let (s, a) = event_expression(s)?;
let (s, _) = symbol(",")(s)?; let (s, b) = symbol(",")(s)?;
let (s, y) = event_expression(s)?; let (s, c) = event_expression(s)?;
Ok((s, EventExpression::Comma(Box::new((x, y))))) Ok((
s,
EventExpression::Comma(Box::new(EventExpressionComma { nodes: (a, b, c) })),
))
} }
pub fn event_expression_paren(s: Span) -> IResult<Span, EventExpression> { pub fn event_expression_paren(s: Span) -> IResult<Span, EventExpression> {
let (s, _) = symbol("(")(s)?; let (s, a) = paren2(event_expression)(s)?;
let (s, x) = event_expression(s)?; Ok((
let (s, _) = symbol(")")(s)?; s,
Ok((s, EventExpression::Paren(Box::new(x)))) EventExpression::Paren(Box::new(EventExpressionParen { nodes: (a,) })),
))
} }
pub fn procedural_timing_control(s: Span) -> IResult<Span, ProceduralTimingControl> { pub fn procedural_timing_control(s: Span) -> IResult<Span, ProceduralTimingControl> {
@ -272,25 +385,31 @@ pub fn jump_statement(s: Span) -> IResult<Span, JumpStatement> {
} }
pub fn jump_statement_return(s: Span) -> IResult<Span, JumpStatement> { pub fn jump_statement_return(s: Span) -> IResult<Span, JumpStatement> {
let (s, _) = symbol("return")(s)?; let (s, a) = symbol("return")(s)?;
let (s, x) = opt(expression)(s)?; let (s, b) = opt(expression)(s)?;
let (s, _) = symbol(";")(s)?; let (s, c) = symbol(";")(s)?;
Ok(( Ok((
s, s,
JumpStatement::Return(JumpStatementReturn { nodes: (x,) }), JumpStatement::Return(JumpStatementReturn { nodes: (a, b, c) }),
)) ))
} }
pub fn jump_statement_break(s: Span) -> IResult<Span, JumpStatement> { pub fn jump_statement_break(s: Span) -> IResult<Span, JumpStatement> {
let (s, _) = symbol("break")(s)?; let (s, a) = symbol("break")(s)?;
let (s, _) = symbol(";")(s)?; let (s, b) = symbol(";")(s)?;
Ok((s, JumpStatement::Break)) Ok((
s,
JumpStatement::Break(JumpStatementBreak { nodes: (a, b) }),
))
} }
pub fn jump_statement_continue(s: Span) -> IResult<Span, JumpStatement> { pub fn jump_statement_continue(s: Span) -> IResult<Span, JumpStatement> {
let (s, _) = symbol("continue")(s)?; let (s, a) = symbol("continue")(s)?;
let (s, _) = symbol(";")(s)?; let (s, b) = symbol(";")(s)?;
Ok((s, JumpStatement::Continue)) Ok((
s,
JumpStatement::Continue(JumpStatementContinue { nodes: (a, b) }),
))
} }
pub fn wait_statement(s: Span) -> IResult<Span, WaitStatement> { pub fn wait_statement(s: Span) -> IResult<Span, WaitStatement> {
@ -302,29 +421,32 @@ pub fn wait_statement(s: Span) -> IResult<Span, WaitStatement> {
} }
pub fn wait_statement_wait(s: Span) -> IResult<Span, WaitStatement> { pub fn wait_statement_wait(s: Span) -> IResult<Span, WaitStatement> {
let (s, _) = symbol("wait")(s)?; let (s, a) = symbol("wait")(s)?;
let (s, x) = paren(expression)(s)?; let (s, b) = paren2(expression)(s)?;
let (s, y) = statement_or_null(s)?; let (s, c) = statement_or_null(s)?;
Ok((s, WaitStatement::Wait(WaitStatementWait { nodes: (x, y) }))) Ok((
s,
WaitStatement::Wait(WaitStatementWait { nodes: (a, b, c) }),
))
} }
pub fn wait_statement_fork(s: Span) -> IResult<Span, WaitStatement> { pub fn wait_statement_fork(s: Span) -> IResult<Span, WaitStatement> {
let (s, _) = symbol("wait")(s)?; let (s, a) = symbol("wait")(s)?;
let (s, _) = symbol("fork")(s)?; let (s, b) = symbol("fork")(s)?;
let (s, _) = symbol(";")(s)?; let (s, c) = symbol(";")(s)?;
Ok((s, WaitStatement::Fork)) Ok((
s,
WaitStatement::Fork(WaitStatementFork { nodes: (a, b, c) }),
))
} }
pub fn wait_statement_order(s: Span) -> IResult<Span, WaitStatement> { pub fn wait_statement_order(s: Span) -> IResult<Span, WaitStatement> {
let (s, _) = symbol("wait_order")(s)?; let (s, a) = symbol("wait_order")(s)?;
let (s, x) = paren(separated_nonempty_list( let (s, b) = paren2(list(symbol(","), hierarchical_identifier))(s)?;
symbol(","), let (s, c) = action_block(s)?;
hierarchical_identifier,
))(s)?;
let (s, y) = action_block(s)?;
Ok(( Ok((
s, s,
WaitStatement::Order(WaitStatementOrder { nodes: (x, y) }), WaitStatement::Order(WaitStatementOrder { nodes: (a, b, c) }),
)) ))
} }
@ -333,20 +455,25 @@ pub fn event_trigger(s: Span) -> IResult<Span, EventTrigger> {
} }
pub fn event_trigger_named(s: Span) -> IResult<Span, EventTrigger> { pub fn event_trigger_named(s: Span) -> IResult<Span, EventTrigger> {
let (s, _) = symbol("->")(s)?; let (s, a) = symbol("->")(s)?;
let (s, x) = hierarchical_event_identifier(s)?; let (s, b) = hierarchical_event_identifier(s)?;
let (s, _) = symbol(";")(s)?; let (s, c) = symbol(";")(s)?;
Ok((s, EventTrigger::Named(EventTriggerNamed { nodes: (x,) }))) Ok((
s,
EventTrigger::Named(EventTriggerNamed { nodes: (a, b, c) }),
))
} }
pub fn event_trigger_nonblocking(s: Span) -> IResult<Span, EventTrigger> { pub fn event_trigger_nonblocking(s: Span) -> IResult<Span, EventTrigger> {
let (s, _) = symbol("->>")(s)?; let (s, a) = symbol("->>")(s)?;
let (s, x) = opt(delay_or_event_control)(s)?; let (s, b) = opt(delay_or_event_control)(s)?;
let (s, y) = hierarchical_event_identifier(s)?; let (s, c) = hierarchical_event_identifier(s)?;
let (s, _) = symbol(";")(s)?; let (s, d) = symbol(";")(s)?;
Ok(( Ok((
s, s,
EventTrigger::Nonblocking(EventTriggerNonblocking { nodes: (x, y) }), EventTrigger::Nonblocking(EventTriggerNonblocking {
nodes: (a, b, c, d),
}),
)) ))
} }
@ -359,22 +486,31 @@ pub fn disable_statement(s: Span) -> IResult<Span, DisableStatement> {
} }
pub fn disable_statement_task(s: Span) -> IResult<Span, DisableStatement> { pub fn disable_statement_task(s: Span) -> IResult<Span, DisableStatement> {
let (s, _) = symbol("disable")(s)?; let (s, a) = symbol("disable")(s)?;
let (s, x) = hierarchical_task_identifier(s)?; let (s, b) = hierarchical_task_identifier(s)?;
let (s, _) = symbol(";")(s)?; let (s, c) = symbol(";")(s)?;
Ok((s, DisableStatement::Task(x))) Ok((
s,
DisableStatement::Task(DisableStatementTask { nodes: (a, b, c) }),
))
} }
pub fn disable_statement_block(s: Span) -> IResult<Span, DisableStatement> { pub fn disable_statement_block(s: Span) -> IResult<Span, DisableStatement> {
let (s, _) = symbol("disable")(s)?; let (s, a) = symbol("disable")(s)?;
let (s, x) = hierarchical_block_identifier(s)?; let (s, b) = hierarchical_block_identifier(s)?;
let (s, _) = symbol(";")(s)?; let (s, c) = symbol(";")(s)?;
Ok((s, DisableStatement::Block(x))) Ok((
s,
DisableStatement::Block(DisableStatementBlock { nodes: (a, b, c) }),
))
} }
pub fn disable_statement_fork(s: Span) -> IResult<Span, DisableStatement> { pub fn disable_statement_fork(s: Span) -> IResult<Span, DisableStatement> {
let (s, _) = symbol("disable")(s)?; let (s, a) = symbol("disable")(s)?;
let (s, _) = symbol("fork")(s)?; let (s, b) = symbol("fork")(s)?;
let (s, _) = symbol(";")(s)?; let (s, c) = symbol(";")(s)?;
Ok((s, DisableStatement::Fork)) Ok((
s,
DisableStatement::Fork(DisableStatementFork { nodes: (a, b, c) }),
))
} }

View File

@ -1,3 +1,4 @@
use crate::ast::*;
use crate::parser::*; use crate::parser::*;
//use nom::branch::*; //use nom::branch::*;
//use nom::combinator::*; //use nom::combinator::*;
@ -12,7 +13,7 @@ pub enum Delay3<'a> {
Mintypmax(Delay3Mintypmax<'a>), Mintypmax(Delay3Mintypmax<'a>),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct Delay3Single<'a> { pub struct Delay3Single<'a> {
pub nodes: (Symbol<'a>, DelayValue<'a>), pub nodes: (Symbol<'a>, DelayValue<'a>),
} }
@ -37,7 +38,7 @@ pub enum Delay2<'a> {
Mintypmax(Delay2Mintypmax<'a>), Mintypmax(Delay2Mintypmax<'a>),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct Delay2Single<'a> { pub struct Delay2Single<'a> {
pub nodes: (Symbol<'a>, DelayValue<'a>), pub nodes: (Symbol<'a>, DelayValue<'a>),
} }
@ -50,7 +51,7 @@ pub struct Delay2Mintypmax<'a> {
), ),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub enum DelayValue<'a> { pub enum DelayValue<'a> {
UnsignedNumber(UnsignedNumber<'a>), UnsignedNumber(UnsignedNumber<'a>),
RealNumber(RealNumber<'a>), RealNumber(RealNumber<'a>),

View File

@ -62,7 +62,7 @@ pub struct TfPortItem<'a> {
pub nodes: ( pub nodes: (
Vec<AttributeInstance<'a>>, Vec<AttributeInstance<'a>>,
Option<TfPortDirection>, Option<TfPortDirection>,
Option<Var>, Option<Var<'a>>,
DataTypeOrImplicit<'a>, DataTypeOrImplicit<'a>,
Option<( Option<(
Identifier<'a>, Identifier<'a>,
@ -83,7 +83,7 @@ pub struct TfPortDeclaration<'a> {
pub nodes: ( pub nodes: (
Vec<AttributeInstance<'a>>, Vec<AttributeInstance<'a>>,
TfPortDirection, TfPortDirection,
Option<Var>, Option<Var<'a>>,
DataTypeOrImplicit<'a>, DataTypeOrImplicit<'a>,
ListOfTfVariableIdentifiers<'a>, ListOfTfVariableIdentifiers<'a>,
), ),

View File

@ -9,7 +9,7 @@ use nom::IResult;
pub enum NetLvalue<'a> { pub enum NetLvalue<'a> {
Identifier(NetLvalueIdentifier<'a>), Identifier(NetLvalueIdentifier<'a>),
Lvalue(Box<NetLvalueLvalue<'a>>), Lvalue(Box<NetLvalueLvalue<'a>>),
Pattern(NetLvaluePattern<'a>), Pattern(Box<NetLvaluePattern<'a>>),
} }
#[derive(Debug)] #[derive(Debug)]
@ -34,7 +34,7 @@ pub struct NetLvaluePattern<'a> {
pub enum VariableLvalue<'a> { pub enum VariableLvalue<'a> {
Identifier(VariableLvalueIdentifier<'a>), Identifier(VariableLvalueIdentifier<'a>),
Lvalue(Box<VariableLvalueLvalue<'a>>), Lvalue(Box<VariableLvalueLvalue<'a>>),
Pattern(VariableLvaluePattern<'a>), Pattern(Box<VariableLvaluePattern<'a>>),
StreamingConcatenation(StreamingConcatenation<'a>), StreamingConcatenation(StreamingConcatenation<'a>),
} }
@ -87,7 +87,10 @@ pub fn net_lvalue_identifier(s: Span) -> IResult<Span, NetLvalue> {
pub fn net_lvalue_pattern(s: Span) -> IResult<Span, NetLvalue> { pub fn net_lvalue_pattern(s: Span) -> IResult<Span, NetLvalue> {
let (s, a) = opt(assignment_pattern_expression_type)(s)?; let (s, a) = opt(assignment_pattern_expression_type)(s)?;
let (s, b) = assignment_pattern_net_lvalue(s)?; let (s, b) = assignment_pattern_net_lvalue(s)?;
Ok((s, NetLvalue::Pattern(NetLvaluePattern { nodes: (a, b) }))) Ok((
s,
NetLvalue::Pattern(Box::new(NetLvaluePattern { nodes: (a, b) })),
))
} }
pub fn net_lvalue_lvalue(s: Span) -> IResult<Span, NetLvalue> { pub fn net_lvalue_lvalue(s: Span) -> IResult<Span, NetLvalue> {
@ -124,7 +127,7 @@ pub fn variable_lvalue_pattern(s: Span) -> IResult<Span, VariableLvalue> {
let (s, b) = assignment_pattern_variable_lvalue(s)?; let (s, b) = assignment_pattern_variable_lvalue(s)?;
Ok(( Ok((
s, s,
VariableLvalue::Pattern(VariableLvaluePattern { nodes: (a, b) }), VariableLvalue::Pattern(Box::new(VariableLvaluePattern { nodes: (a, b) })),
)) ))
} }

View File

@ -1,4 +1,3 @@
use crate::ast::*;
use crate::parser::*; use crate::parser::*;
use nom::branch::*; use nom::branch::*;
use nom::combinator::*; use nom::combinator::*;
@ -174,7 +173,7 @@ pub struct TaggedUnionExpression<'a> {
#[derive(Debug)] #[derive(Debug)]
pub struct InsideExpression<'a> { pub struct InsideExpression<'a> {
pub nodes: (Expression<'a>, Symbol<'a>, Brace<'a, Vec<ValueRange<'a>>>), pub nodes: (Expression<'a>, Symbol<'a>, Brace<'a, OpenRangeList<'a>>),
} }
#[derive(Debug)] #[derive(Debug)]

View File

@ -1,30 +1,31 @@
use crate::ast::*;
use crate::parser::*; use crate::parser::*;
use nom::branch::*; use nom::branch::*;
use nom::IResult; use nom::IResult;
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#[derive(Debug)] #[derive(Debug, Node)]
pub struct UnaryOperator<'a> { pub struct UnaryOperator<'a> {
pub nodes: (Symbol<'a>,), pub nodes: (Symbol<'a>,),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct BinaryOperator<'a> { pub struct BinaryOperator<'a> {
pub nodes: (Symbol<'a>,), pub nodes: (Symbol<'a>,),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct IncOrDecOperator<'a> { pub struct IncOrDecOperator<'a> {
pub nodes: (Symbol<'a>,), pub nodes: (Symbol<'a>,),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct UnaryModulePathOperator<'a> { pub struct UnaryModulePathOperator<'a> {
pub nodes: (Symbol<'a>,), pub nodes: (Symbol<'a>,),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct BinaryModulePathOperator<'a> { pub struct BinaryModulePathOperator<'a> {
pub nodes: (Symbol<'a>,), pub nodes: (Symbol<'a>,),
} }

View File

@ -1,3 +1,4 @@
use crate::ast::*;
use crate::parser::*; use crate::parser::*;
use nom::branch::*; use nom::branch::*;
use nom::combinator::*; use nom::combinator::*;
@ -144,11 +145,6 @@ pub struct ClassQualifier<'a> {
), ),
} }
#[derive(Debug)]
pub struct Local<'a> {
pub nodes: (Symbol<'a>,),
}
#[derive(Debug)] #[derive(Debug)]
pub enum RangeExpression<'a> { pub enum RangeExpression<'a> {
Expression(Expression<'a>), Expression(Expression<'a>),
@ -163,23 +159,23 @@ pub enum PrimaryLiteral<'a> {
StringLiteral(StringLiteral<'a>), StringLiteral(StringLiteral<'a>),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub enum TimeLiteral<'a> { pub enum TimeLiteral<'a> {
Unsigned(TimeLiteralUnsigned<'a>), Unsigned(TimeLiteralUnsigned<'a>),
FixedPoint(TimeLiteralFixedPoint<'a>), FixedPoint(TimeLiteralFixedPoint<'a>),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct TimeLiteralUnsigned<'a> { pub struct TimeLiteralUnsigned<'a> {
pub nodes: (UnsignedNumber<'a>, TimeUnit<'a>), pub nodes: (UnsignedNumber<'a>, TimeUnit<'a>),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct TimeLiteralFixedPoint<'a> { pub struct TimeLiteralFixedPoint<'a> {
pub nodes: (FixedPointNumber<'a>, TimeUnit<'a>), pub nodes: (FixedPointNumber<'a>, TimeUnit<'a>),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub enum TimeUnit<'a> { pub enum TimeUnit<'a> {
S(Symbol<'a>), S(Symbol<'a>),
MS(Symbol<'a>), MS(Symbol<'a>),
@ -189,7 +185,7 @@ pub enum TimeUnit<'a> {
FS(Symbol<'a>), FS(Symbol<'a>),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub enum ImplicitClassHandle<'a> { pub enum ImplicitClassHandle<'a> {
This(Symbol<'a>), This(Symbol<'a>),
Super(Symbol<'a>), Super(Symbol<'a>),
@ -267,6 +263,7 @@ pub struct Cast<'a> {
pub fn constant_primary(s: Span) -> IResult<Span, ConstantPrimary> { pub fn constant_primary(s: Span) -> IResult<Span, ConstantPrimary> {
alt(( alt((
map(symbol("null"), |x| ConstantPrimary::Null(x)),
map(primary_literal, |x| ConstantPrimary::PrimaryLiteral(x)), map(primary_literal, |x| ConstantPrimary::PrimaryLiteral(x)),
constant_primary_ps_parameter, constant_primary_ps_parameter,
constant_primary_specparam, constant_primary_specparam,
@ -287,7 +284,6 @@ pub fn constant_primary(s: Span) -> IResult<Span, ConstantPrimary> {
ConstantPrimary::ConstantAssignmentPatternExpression(x) ConstantPrimary::ConstantAssignmentPatternExpression(x)
}), }),
map(type_reference, |x| ConstantPrimary::TypeReference(x)), map(type_reference, |x| ConstantPrimary::TypeReference(x)),
map(symbol("null"), |x| ConstantPrimary::Null(x)),
))(s) ))(s)
} }
@ -382,6 +378,9 @@ pub fn module_path_primary_mintypmax_expression(s: Span) -> IResult<Span, Module
pub fn primary(s: Span) -> IResult<Span, Primary> { pub fn primary(s: Span) -> IResult<Span, Primary> {
alt(( alt((
map(symbol("this"), |x| Primary::This(x)),
map(symbol("$"), |x| Primary::Dollar(x)),
map(symbol("null"), |x| Primary::Null(x)),
map(primary_literal, |x| Primary::PrimaryLiteral(x)), map(primary_literal, |x| Primary::PrimaryLiteral(x)),
primary_hierarchical, primary_hierarchical,
map(empty_unpacked_array_concatenation, |x| { map(empty_unpacked_array_concatenation, |x| {
@ -401,9 +400,6 @@ pub fn primary(s: Span) -> IResult<Span, Primary> {
Primary::StreamingConcatenation(x) Primary::StreamingConcatenation(x)
}), }),
map(sequence_method_call, |x| Primary::SequenceMethodCall(x)), map(sequence_method_call, |x| Primary::SequenceMethodCall(x)),
map(symbol("this"), |x| Primary::This(x)),
map(symbol("$"), |x| Primary::Dollar(x)),
map(symbol("null"), |x| Primary::Null(x)),
))(s) ))(s)
} }
@ -455,14 +451,9 @@ pub fn class_qualifier_or_package_scope(s: Span) -> IResult<Span, ClassQualifier
} }
pub fn class_qualifier(s: Span) -> IResult<Span, ClassQualifier> { pub fn class_qualifier(s: Span) -> IResult<Span, ClassQualifier> {
let (s, a) = opt(symbol("local::"))(s)?; let (s, a) = opt(local)(s)?;
let (s, b) = opt(implicit_class_handle_or_class_scope)(s)?; let (s, b) = opt(implicit_class_handle_or_class_scope)(s)?;
Ok(( Ok((s, ClassQualifier { nodes: (a, b) }))
s,
ClassQualifier {
nodes: (a.map(|x| Local { nodes: (x,) }), b),
},
))
} }
pub fn range_expression(s: Span) -> IResult<Span, RangeExpression> { pub fn range_expression(s: Span) -> IResult<Span, RangeExpression> {

View File

@ -1,3 +1,4 @@
use crate::ast::*;
use crate::parser::*; use crate::parser::*;
use nom::bytes::complete::*; use nom::bytes::complete::*;
use nom::combinator::*; use nom::combinator::*;
@ -7,7 +8,7 @@ use nom::IResult;
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#[derive(Debug)] #[derive(Debug, Node)]
pub struct StringLiteral<'a> { pub struct StringLiteral<'a> {
pub nodes: (Span<'a>, Vec<WhiteSpace<'a>>), pub nodes: (Span<'a>, Vec<WhiteSpace<'a>>),
} }

View File

@ -1,4 +1,3 @@
use crate::ast::*;
use crate::parser::*; use crate::parser::*;
use nom::combinator::*; use nom::combinator::*;
use nom::sequence::*; use nom::sequence::*;

View File

@ -3,9 +3,9 @@ use crate::parser::*;
use nom::branch::*; use nom::branch::*;
use nom::bytes::complete::*; use nom::bytes::complete::*;
use nom::combinator::*; use nom::combinator::*;
use nom::error::*; use nom::multi::*;
use nom::sequence::*; use nom::sequence::*;
use nom::{Err, IResult}; use nom::IResult;
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -13,122 +13,122 @@ const AZ_: &str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_";
const AZ09_: &str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"; const AZ09_: &str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_";
const AZ09_DOLLAR: &str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_$"; const AZ09_DOLLAR: &str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_$";
#[derive(Debug)] #[derive(Debug, Node)]
pub struct ArrayIdentifier<'a> { pub struct ArrayIdentifier<'a> {
pub nodes: (Identifier<'a>,), pub nodes: (Identifier<'a>,),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct BlockIdentifier<'a> { pub struct BlockIdentifier<'a> {
pub nodes: (Identifier<'a>,), pub nodes: (Identifier<'a>,),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct BinIdentifier<'a> { pub struct BinIdentifier<'a> {
pub nodes: (Identifier<'a>,), pub nodes: (Identifier<'a>,),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct CIdentifier<'a> { pub struct CIdentifier<'a> {
pub nodes: (Span<'a>, Vec<WhiteSpace<'a>>), pub nodes: (Span<'a>, Vec<WhiteSpace<'a>>),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct CellIdentifier<'a> { pub struct CellIdentifier<'a> {
pub nodes: (Identifier<'a>,), pub nodes: (Identifier<'a>,),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct CheckerIdentifier<'a> { pub struct CheckerIdentifier<'a> {
pub nodes: (Identifier<'a>,), pub nodes: (Identifier<'a>,),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct ClassIdentifier<'a> { pub struct ClassIdentifier<'a> {
pub nodes: (Identifier<'a>,), pub nodes: (Identifier<'a>,),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct ClassVariableIdentifier<'a> { pub struct ClassVariableIdentifier<'a> {
pub nodes: (VariableIdentifier<'a>,), pub nodes: (VariableIdentifier<'a>,),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct ClockingIdentifier<'a> { pub struct ClockingIdentifier<'a> {
pub nodes: (Identifier<'a>,), pub nodes: (Identifier<'a>,),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct ConfigIdentifier<'a> { pub struct ConfigIdentifier<'a> {
pub nodes: (Identifier<'a>,), pub nodes: (Identifier<'a>,),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct ConstIdentifier<'a> { pub struct ConstIdentifier<'a> {
pub nodes: (Identifier<'a>,), pub nodes: (Identifier<'a>,),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct ConstraintIdentifier<'a> { pub struct ConstraintIdentifier<'a> {
pub nodes: (Identifier<'a>,), pub nodes: (Identifier<'a>,),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct CovergroupIdentifier<'a> { pub struct CovergroupIdentifier<'a> {
pub nodes: (Identifier<'a>,), pub nodes: (Identifier<'a>,),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct CovergroupVariableIdentifier<'a> { pub struct CovergroupVariableIdentifier<'a> {
pub nodes: (VariableIdentifier<'a>,), pub nodes: (VariableIdentifier<'a>,),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct CoverPointIdentifier<'a> { pub struct CoverPointIdentifier<'a> {
pub nodes: (Identifier<'a>,), pub nodes: (Identifier<'a>,),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct CrossIdentifier<'a> { pub struct CrossIdentifier<'a> {
pub nodes: (Identifier<'a>,), pub nodes: (Identifier<'a>,),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct DynamicArrayVariableIdentifier<'a> { pub struct DynamicArrayVariableIdentifier<'a> {
pub nodes: (VariableIdentifier<'a>,), pub nodes: (VariableIdentifier<'a>,),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct EnumIdentifier<'a> { pub struct EnumIdentifier<'a> {
pub nodes: (Identifier<'a>,), pub nodes: (Identifier<'a>,),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct EscapedIdentifier<'a> { pub struct EscapedIdentifier<'a> {
pub nodes: (Span<'a>, Vec<WhiteSpace<'a>>), pub nodes: (Span<'a>, Vec<WhiteSpace<'a>>),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct FormalIdentifier<'a> { pub struct FormalIdentifier<'a> {
pub nodes: (Identifier<'a>,), pub nodes: (Identifier<'a>,),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct FormalPortIdentifier<'a> { pub struct FormalPortIdentifier<'a> {
pub nodes: (Identifier<'a>,), pub nodes: (Identifier<'a>,),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct FunctionIdentifier<'a> { pub struct FunctionIdentifier<'a> {
pub nodes: (Identifier<'a>,), pub nodes: (Identifier<'a>,),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct GenerateBlockIdentifier<'a> { pub struct GenerateBlockIdentifier<'a> {
pub nodes: (Identifier<'a>,), pub nodes: (Identifier<'a>,),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct GenvarIdentifier<'a> { pub struct GenvarIdentifier<'a> {
pub nodes: (Identifier<'a>,), pub nodes: (Identifier<'a>,),
} }
@ -151,14 +151,16 @@ pub struct HierarchicalEventIdentifier<'a> {
#[derive(Debug)] #[derive(Debug)]
pub struct HierarchicalIdentifier<'a> { pub struct HierarchicalIdentifier<'a> {
pub nodes: ( pub nodes: (
Option<Root>, Option<Root<'a>>,
Vec<(Identifier<'a>, ConstantBitSelect<'a>)>, Vec<(Identifier<'a>, ConstantBitSelect<'a>, Symbol<'a>)>,
Identifier<'a>, Identifier<'a>,
), ),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct Root {} pub struct Root<'a> {
pub nodes: (Symbol<'a>, Symbol<'a>),
}
#[derive(Debug)] #[derive(Debug)]
pub struct HierarchicalNetIdentifier<'a> { pub struct HierarchicalNetIdentifier<'a> {
@ -195,134 +197,144 @@ pub struct HierarchicalVariableIdentifier<'a> {
pub nodes: (HierarchicalIdentifier<'a>,), pub nodes: (HierarchicalIdentifier<'a>,),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub enum Identifier<'a> { pub enum Identifier<'a> {
SimpleIdentifier(SimpleIdentifier<'a>), SimpleIdentifier(SimpleIdentifier<'a>),
EscapedIdentifier(EscapedIdentifier<'a>), EscapedIdentifier(EscapedIdentifier<'a>),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct IndexVariableIdentifier<'a> { pub struct IndexVariableIdentifier<'a> {
pub nodes: (Identifier<'a>,), pub nodes: (Identifier<'a>,),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct InterfaceIdentifier<'a> { pub struct InterfaceIdentifier<'a> {
pub nodes: (Identifier<'a>,), pub nodes: (Identifier<'a>,),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct InterfaceInstanceIdentifier<'a> { pub struct InterfaceInstanceIdentifier<'a> {
pub nodes: (Identifier<'a>,), pub nodes: (Identifier<'a>,),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct InoutPortIdentifier<'a> { pub struct InoutPortIdentifier<'a> {
pub nodes: (Identifier<'a>,), pub nodes: (Identifier<'a>,),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct InputPortIdentifier<'a> { pub struct InputPortIdentifier<'a> {
pub nodes: (Identifier<'a>,), pub nodes: (Identifier<'a>,),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct InstanceIdentifier<'a> { pub struct InstanceIdentifier<'a> {
pub nodes: (Identifier<'a>,), pub nodes: (Identifier<'a>,),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct LibraryIdentifier<'a> { pub struct LibraryIdentifier<'a> {
pub nodes: (Identifier<'a>,), pub nodes: (Identifier<'a>,),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct MemberIdentifier<'a> { pub struct MemberIdentifier<'a> {
pub nodes: (Identifier<'a>,), pub nodes: (Identifier<'a>,),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct MethodIdentifier<'a> { pub struct MethodIdentifier<'a> {
pub nodes: (Identifier<'a>,), pub nodes: (Identifier<'a>,),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct ModportIdentifier<'a> { pub struct ModportIdentifier<'a> {
pub nodes: (Identifier<'a>,), pub nodes: (Identifier<'a>,),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct ModuleIdentifier<'a> { pub struct ModuleIdentifier<'a> {
pub nodes: (Identifier<'a>,), pub nodes: (Identifier<'a>,),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct NetIdentifier<'a> { pub struct NetIdentifier<'a> {
pub nodes: (Identifier<'a>,), pub nodes: (Identifier<'a>,),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct NetTypeIdentifier<'a> { pub struct NetTypeIdentifier<'a> {
pub nodes: (Identifier<'a>,), pub nodes: (Identifier<'a>,),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct OutputPortIdentifier<'a> { pub struct OutputPortIdentifier<'a> {
pub nodes: (Identifier<'a>,), pub nodes: (Identifier<'a>,),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct PackageIdentifier<'a> { pub struct PackageIdentifier<'a> {
pub nodes: (Identifier<'a>,), pub nodes: (Identifier<'a>,),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub enum PackageScope<'a> { pub enum PackageScope<'a> {
PackageIdentifier(PackageIdentifier<'a>), Package(PackageScopePackage<'a>),
Unit, Unit(Unit<'a>),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct PackageScopePackage<'a> {
pub nodes: (PackageIdentifier<'a>, Symbol<'a>),
}
#[derive(Debug, Node)]
pub struct Unit<'a> {
pub nodes: (Symbol<'a>, Symbol<'a>),
}
#[derive(Debug, Node)]
pub struct ParameterIdentifier<'a> { pub struct ParameterIdentifier<'a> {
pub nodes: (Identifier<'a>,), pub nodes: (Identifier<'a>,),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct PortIdentifier<'a> { pub struct PortIdentifier<'a> {
pub nodes: (Identifier<'a>,), pub nodes: (Identifier<'a>,),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct ProductionIdentifier<'a> { pub struct ProductionIdentifier<'a> {
pub nodes: (Identifier<'a>,), pub nodes: (Identifier<'a>,),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct ProgramIdentifier<'a> { pub struct ProgramIdentifier<'a> {
pub nodes: (Identifier<'a>,), pub nodes: (Identifier<'a>,),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct PropertyIdentifier<'a> { pub struct PropertyIdentifier<'a> {
pub nodes: (Identifier<'a>,), pub nodes: (Identifier<'a>,),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct PsClassIdentifier<'a> { pub struct PsClassIdentifier<'a> {
pub nodes: (Option<PackageScope<'a>>, ClassIdentifier<'a>), pub nodes: (Option<PackageScope<'a>>, ClassIdentifier<'a>),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct PsCovergroupIdentifier<'a> { pub struct PsCovergroupIdentifier<'a> {
pub nodes: (Option<PackageScope<'a>>, CovergroupIdentifier<'a>), pub nodes: (Option<PackageScope<'a>>, CovergroupIdentifier<'a>),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct PsCheckerIdentifier<'a> { pub struct PsCheckerIdentifier<'a> {
pub nodes: (Option<PackageScope<'a>>, CheckerIdentifier<'a>), pub nodes: (Option<PackageScope<'a>>, CheckerIdentifier<'a>),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct PsIdentifier<'a> { pub struct PsIdentifier<'a> {
pub nodes: (Option<PackageScope<'a>>, Identifier<'a>), pub nodes: (Option<PackageScope<'a>>, Identifier<'a>),
} }
@ -338,10 +350,10 @@ pub struct PsOrHierarchicalArrayIdentifier<'a> {
#[derive(Debug)] #[derive(Debug)]
pub enum PsOrHierarchicalNetIdentifier<'a> { pub enum PsOrHierarchicalNetIdentifier<'a> {
PackageScope(PsOrHierarchicalNetIdentifierPackageScope<'a>), PackageScope(PsOrHierarchicalNetIdentifierPackageScope<'a>),
Hierarchical(PsOrHierarchicalNetIdentifierHierarchical<'a>), HierarchicalNetIdentifier(HierarchicalNetIdentifier<'a>),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct PsOrHierarchicalNetIdentifierPackageScope<'a> { pub struct PsOrHierarchicalNetIdentifierPackageScope<'a> {
pub nodes: (Option<PackageScope<'a>>, NetIdentifier<'a>), pub nodes: (Option<PackageScope<'a>>, NetIdentifier<'a>),
} }
@ -354,7 +366,7 @@ pub struct PsOrHierarchicalNetIdentifierHierarchical<'a> {
#[derive(Debug)] #[derive(Debug)]
pub enum PsOrHierarchicalPropertyIdentifier<'a> { pub enum PsOrHierarchicalPropertyIdentifier<'a> {
PackageScope(PsOrHierarchicalPropertyIdentifierPackageScope<'a>), PackageScope(PsOrHierarchicalPropertyIdentifierPackageScope<'a>),
Hierarchical(PsOrHierarchicalPropertyIdentifierHierarchical<'a>), HierarchicalPropertyIdentifier(HierarchicalPropertyIdentifier<'a>),
} }
#[derive(Debug)] #[derive(Debug)]
@ -370,7 +382,7 @@ pub struct PsOrHierarchicalPropertyIdentifierHierarchical<'a> {
#[derive(Debug)] #[derive(Debug)]
pub enum PsOrHierarchicalSequenceIdentifier<'a> { pub enum PsOrHierarchicalSequenceIdentifier<'a> {
PackageScope(PsOrHierarchicalSequenceIdentifierPackageScope<'a>), PackageScope(PsOrHierarchicalSequenceIdentifierPackageScope<'a>),
Hierarchical(PsOrHierarchicalSequenceIdentifierHierarchical<'a>), HierarchicalSequenceIdentifier(HierarchicalSequenceIdentifier<'a>),
} }
#[derive(Debug)] #[derive(Debug)]
@ -386,7 +398,7 @@ pub struct PsOrHierarchicalSequenceIdentifierHierarchical<'a> {
#[derive(Debug)] #[derive(Debug)]
pub enum PsOrHierarchicalTfIdentifier<'a> { pub enum PsOrHierarchicalTfIdentifier<'a> {
PackageScope(PsOrHierarchicalTfIdentifierPackageScope<'a>), PackageScope(PsOrHierarchicalTfIdentifierPackageScope<'a>),
Hierarchical(PsOrHierarchicalTfIdentifierHierarchical<'a>), HierarchicalTfIdentifier(HierarchicalTfIdentifier<'a>),
} }
#[derive(Debug)] #[derive(Debug)]
@ -416,7 +428,11 @@ pub struct PsParameterIdentifierScope<'a> {
#[derive(Debug)] #[derive(Debug)]
pub struct PsParameterIdentifierGenerate<'a> { pub struct PsParameterIdentifierGenerate<'a> {
pub nodes: ( pub nodes: (
Vec<(GenerateBlockIdentifier<'a>, Option<ConstantExpression<'a>>)>, Vec<(
GenerateBlockIdentifier<'a>,
Option<Bracket<'a, ConstantExpression<'a>>>,
Symbol<'a>,
)>,
ParameterIdentifier<'a>, ParameterIdentifier<'a>,
), ),
} }
@ -431,67 +447,72 @@ pub struct PsTypeIdentifier<'a> {
#[derive(Debug)] #[derive(Debug)]
pub enum LocalOrPackageScopeOrClassScope<'a> { pub enum LocalOrPackageScopeOrClassScope<'a> {
Local, Local(Local<'a>),
PackageScope(PackageScope<'a>), PackageScope(PackageScope<'a>),
ClassScope(ClassScope<'a>), ClassScope(ClassScope<'a>),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct Local<'a> {
pub nodes: (Symbol<'a>, Symbol<'a>),
}
#[derive(Debug, Node)]
pub struct SequenceIdentifier<'a> { pub struct SequenceIdentifier<'a> {
pub nodes: (Identifier<'a>,), pub nodes: (Identifier<'a>,),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct SignalIdentifier<'a> { pub struct SignalIdentifier<'a> {
pub nodes: (Identifier<'a>,), pub nodes: (Identifier<'a>,),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct SimpleIdentifier<'a> { pub struct SimpleIdentifier<'a> {
pub nodes: (Span<'a>, Vec<WhiteSpace<'a>>), pub nodes: (Span<'a>, Vec<WhiteSpace<'a>>),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct SpecparamIdentifier<'a> { pub struct SpecparamIdentifier<'a> {
pub nodes: (Identifier<'a>,), pub nodes: (Identifier<'a>,),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct SystemTfIdentifier<'a> { pub struct SystemTfIdentifier<'a> {
pub nodes: (Span<'a>, Vec<WhiteSpace<'a>>), pub nodes: (Span<'a>, Vec<WhiteSpace<'a>>),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct TaskIdentifier<'a> { pub struct TaskIdentifier<'a> {
pub nodes: (Identifier<'a>,), pub nodes: (Identifier<'a>,),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct TfIdentifier<'a> { pub struct TfIdentifier<'a> {
pub nodes: (Identifier<'a>,), pub nodes: (Identifier<'a>,),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct TerminalIdentifier<'a> { pub struct TerminalIdentifier<'a> {
pub nodes: (Identifier<'a>,), pub nodes: (Identifier<'a>,),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct TopmoduleIdentifier<'a> { pub struct TopmoduleIdentifier<'a> {
pub nodes: (Identifier<'a>,), pub nodes: (Identifier<'a>,),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct TypeIdentifier<'a> { pub struct TypeIdentifier<'a> {
pub nodes: (Identifier<'a>,), pub nodes: (Identifier<'a>,),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct UdpIdentifier<'a> { pub struct UdpIdentifier<'a> {
pub nodes: (Identifier<'a>,), pub nodes: (Identifier<'a>,),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct VariableIdentifier<'a> { pub struct VariableIdentifier<'a> {
pub nodes: (Identifier<'a>,), pub nodes: (Identifier<'a>,),
} }
@ -677,7 +698,16 @@ pub fn hierarchical_event_identifier(s: Span) -> IResult<Span, HierarchicalEvent
} }
pub fn hierarchical_identifier(s: Span) -> IResult<Span, HierarchicalIdentifier> { pub fn hierarchical_identifier(s: Span) -> IResult<Span, HierarchicalIdentifier> {
Err(Err::Error(make_error(s, ErrorKind::Fix))) let (s, a) = opt(root)(s)?;
let (s, b) = many0(triple(identifier, constant_bit_select, symbol(".")))(s)?;
let (s, c) = identifier(s)?;
Ok((s, HierarchicalIdentifier { nodes: (a, b, c) }))
}
pub fn root(s: Span) -> IResult<Span, Root> {
let (s, a) = symbol("$root")(s)?;
let (s, b) = symbol(".")(s)?;
Ok((s, Root { nodes: (a, b) }))
} }
pub fn hierarchical_net_identifier(s: Span) -> IResult<Span, HierarchicalNetIdentifier> { pub fn hierarchical_net_identifier(s: Span) -> IResult<Span, HierarchicalNetIdentifier> {
@ -800,7 +830,22 @@ pub fn package_identifier(s: Span) -> IResult<Span, PackageIdentifier> {
} }
pub fn package_scope(s: Span) -> IResult<Span, PackageScope> { pub fn package_scope(s: Span) -> IResult<Span, PackageScope> {
Err(Err::Error(make_error(s, ErrorKind::Fix))) alt((package_scope_package, map(unit, |x| PackageScope::Unit(x))))(s)
}
pub fn package_scope_package(s: Span) -> IResult<Span, PackageScope> {
let (s, a) = package_identifier(s)?;
let (s, b) = symbol("::")(s)?;
Ok((
s,
PackageScope::Package(PackageScopePackage { nodes: (a, b) }),
))
}
pub fn unit(s: Span) -> IResult<Span, Unit> {
let (s, a) = symbol("$unit")(s)?;
let (s, b) = symbol("::")(s)?;
Ok((s, Unit { nodes: (a, b) }))
} }
pub fn parameter_identifier(s: Span) -> IResult<Span, ParameterIdentifier> { pub fn parameter_identifier(s: Span) -> IResult<Span, ParameterIdentifier> {
@ -829,53 +874,162 @@ pub fn property_identifier(s: Span) -> IResult<Span, PropertyIdentifier> {
} }
pub fn ps_class_identifier(s: Span) -> IResult<Span, PsClassIdentifier> { pub fn ps_class_identifier(s: Span) -> IResult<Span, PsClassIdentifier> {
Err(Err::Error(make_error(s, ErrorKind::Fix))) let (s, a) = opt(package_scope)(s)?;
let (s, b) = class_identifier(s)?;
Ok((s, PsClassIdentifier { nodes: (a, b) }))
} }
pub fn ps_covergroup_identifier(s: Span) -> IResult<Span, PsCovergroupIdentifier> { pub fn ps_covergroup_identifier(s: Span) -> IResult<Span, PsCovergroupIdentifier> {
Err(Err::Error(make_error(s, ErrorKind::Fix))) let (s, a) = opt(package_scope)(s)?;
let (s, b) = covergroup_identifier(s)?;
Ok((s, PsCovergroupIdentifier { nodes: (a, b) }))
} }
pub fn ps_checker_identifier(s: Span) -> IResult<Span, PsCheckerIdentifier> { pub fn ps_checker_identifier(s: Span) -> IResult<Span, PsCheckerIdentifier> {
Err(Err::Error(make_error(s, ErrorKind::Fix))) let (s, a) = opt(package_scope)(s)?;
let (s, b) = checker_identifier(s)?;
Ok((s, PsCheckerIdentifier { nodes: (a, b) }))
} }
pub fn ps_identifier(s: Span) -> IResult<Span, PsIdentifier> { pub fn ps_identifier(s: Span) -> IResult<Span, PsIdentifier> {
Err(Err::Error(make_error(s, ErrorKind::Fix))) let (s, a) = opt(package_scope)(s)?;
let (s, b) = identifier(s)?;
Ok((s, PsIdentifier { nodes: (a, b) }))
} }
pub fn ps_or_hierarchical_array_identifier( pub fn ps_or_hierarchical_array_identifier(
s: Span, s: Span,
) -> IResult<Span, PsOrHierarchicalArrayIdentifier> { ) -> IResult<Span, PsOrHierarchicalArrayIdentifier> {
Err(Err::Error(make_error(s, ErrorKind::Fix))) let (s, a) = opt(implicit_class_handle_or_class_scope_or_package_scope)(s)?;
let (s, b) = hierarchical_array_identifier(s)?;
Ok((s, PsOrHierarchicalArrayIdentifier { nodes: (a, b) }))
} }
pub fn ps_or_hierarchical_net_identifier(s: Span) -> IResult<Span, PsOrHierarchicalNetIdentifier> { pub fn ps_or_hierarchical_net_identifier(s: Span) -> IResult<Span, PsOrHierarchicalNetIdentifier> {
Err(Err::Error(make_error(s, ErrorKind::Fix))) alt((
ps_or_hierarchical_net_identifier_package_scope,
map(hierarchical_net_identifier, |x| {
PsOrHierarchicalNetIdentifier::HierarchicalNetIdentifier(x)
}),
))(s)
}
pub fn ps_or_hierarchical_net_identifier_package_scope(
s: Span,
) -> IResult<Span, PsOrHierarchicalNetIdentifier> {
let (s, a) = opt(package_scope)(s)?;
let (s, b) = net_identifier(s)?;
Ok((
s,
PsOrHierarchicalNetIdentifier::PackageScope(PsOrHierarchicalNetIdentifierPackageScope {
nodes: (a, b),
}),
))
} }
pub fn ps_or_hierarchical_property_identifier( pub fn ps_or_hierarchical_property_identifier(
s: Span, s: Span,
) -> IResult<Span, PsOrHierarchicalPropertyIdentifier> { ) -> IResult<Span, PsOrHierarchicalPropertyIdentifier> {
Err(Err::Error(make_error(s, ErrorKind::Fix))) alt((
ps_or_hierarchical_property_identifier_package_scope,
map(hierarchical_property_identifier, |x| {
PsOrHierarchicalPropertyIdentifier::HierarchicalPropertyIdentifier(x)
}),
))(s)
}
pub fn ps_or_hierarchical_property_identifier_package_scope(
s: Span,
) -> IResult<Span, PsOrHierarchicalPropertyIdentifier> {
let (s, a) = opt(package_scope)(s)?;
let (s, b) = property_identifier(s)?;
Ok((
s,
PsOrHierarchicalPropertyIdentifier::PackageScope(
PsOrHierarchicalPropertyIdentifierPackageScope { nodes: (a, b) },
),
))
} }
pub fn ps_or_hierarchical_sequence_identifier( pub fn ps_or_hierarchical_sequence_identifier(
s: Span, s: Span,
) -> IResult<Span, PsOrHierarchicalSequenceIdentifier> { ) -> IResult<Span, PsOrHierarchicalSequenceIdentifier> {
Err(Err::Error(make_error(s, ErrorKind::Fix))) alt((
ps_or_hierarchical_sequence_identifier_package_scope,
map(hierarchical_sequence_identifier, |x| {
PsOrHierarchicalSequenceIdentifier::HierarchicalSequenceIdentifier(x)
}),
))(s)
}
pub fn ps_or_hierarchical_sequence_identifier_package_scope(
s: Span,
) -> IResult<Span, PsOrHierarchicalSequenceIdentifier> {
let (s, a) = opt(package_scope)(s)?;
let (s, b) = sequence_identifier(s)?;
Ok((
s,
PsOrHierarchicalSequenceIdentifier::PackageScope(
PsOrHierarchicalSequenceIdentifierPackageScope { nodes: (a, b) },
),
))
} }
pub fn ps_or_hierarchical_tf_identifier(s: Span) -> IResult<Span, PsOrHierarchicalTfIdentifier> { pub fn ps_or_hierarchical_tf_identifier(s: Span) -> IResult<Span, PsOrHierarchicalTfIdentifier> {
Err(Err::Error(make_error(s, ErrorKind::Fix))) alt((
ps_or_hierarchical_tf_identifier_package_scope,
map(hierarchical_tf_identifier, |x| {
PsOrHierarchicalTfIdentifier::HierarchicalTfIdentifier(x)
}),
))(s)
}
pub fn ps_or_hierarchical_tf_identifier_package_scope(
s: Span,
) -> IResult<Span, PsOrHierarchicalTfIdentifier> {
let (s, a) = opt(package_scope)(s)?;
let (s, b) = tf_identifier(s)?;
Ok((
s,
PsOrHierarchicalTfIdentifier::PackageScope(PsOrHierarchicalTfIdentifierPackageScope {
nodes: (a, b),
}),
))
} }
pub fn ps_parameter_identifier(s: Span) -> IResult<Span, PsParameterIdentifier> { pub fn ps_parameter_identifier(s: Span) -> IResult<Span, PsParameterIdentifier> {
Err(Err::Error(make_error(s, ErrorKind::Fix))) alt((
ps_parameter_identifier_scope,
ps_parameter_identifier_generate,
))(s)
}
pub fn ps_parameter_identifier_scope(s: Span) -> IResult<Span, PsParameterIdentifier> {
let (s, a) = opt(package_scope_or_class_scope)(s)?;
let (s, b) = parameter_identifier(s)?;
Ok((
s,
PsParameterIdentifier::Scope(PsParameterIdentifierScope { nodes: (a, b) }),
))
}
pub fn ps_parameter_identifier_generate(s: Span) -> IResult<Span, PsParameterIdentifier> {
let (s, a) = many0(triple(
generate_block_identifier,
opt(bracket2(constant_expression)),
symbol("."),
))(s)?;
let (s, b) = parameter_identifier(s)?;
Ok((
s,
PsParameterIdentifier::Generate(PsParameterIdentifierGenerate { nodes: (a, b) }),
))
} }
pub fn ps_type_identifier(s: Span) -> IResult<Span, PsTypeIdentifier> { pub fn ps_type_identifier(s: Span) -> IResult<Span, PsTypeIdentifier> {
Err(Err::Error(make_error(s, ErrorKind::Fix))) let (s, a) = opt(local_or_package_scope_or_class_scope)(s)?;
let (s, b) = type_identifier(s)?;
Ok((s, PsTypeIdentifier { nodes: (a, b) }))
} }
pub fn sequence_identifier(s: Span) -> IResult<Span, SequenceIdentifier> { pub fn sequence_identifier(s: Span) -> IResult<Span, SequenceIdentifier> {
@ -1005,6 +1159,26 @@ pub fn package_scope_or_class_scope(s: Span) -> IResult<Span, PackageScopeOrClas
))(s) ))(s)
} }
pub fn local_or_package_scope_or_class_scope(
s: Span,
) -> IResult<Span, LocalOrPackageScopeOrClassScope> {
alt((
map(local, |x| LocalOrPackageScopeOrClassScope::Local(x)),
map(package_scope, |x| {
LocalOrPackageScopeOrClassScope::PackageScope(x)
}),
map(class_scope, |x| {
LocalOrPackageScopeOrClassScope::ClassScope(x)
}),
))(s)
}
pub fn local(s: Span) -> IResult<Span, Local> {
let (s, a) = symbol("local")(s)?;
let (s, b) = symbol("::")(s)?;
Ok((s, Local { nodes: (a, b) }))
}
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#[cfg(test)] #[cfg(test)]

View File

@ -1,3 +1,4 @@
use crate::ast::*;
use crate::parser::*; use crate::parser::*;
//use nom::branch::*; //use nom::branch::*;
//use nom::combinator::*; //use nom::combinator::*;
@ -6,7 +7,7 @@ use nom::{Err, IResult};
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#[derive(Debug)] #[derive(Debug, Node)]
pub struct GateInstantiation<'a> { pub struct GateInstantiation<'a> {
pub nodes: (Identifier<'a>,), pub nodes: (Identifier<'a>,),
} }

View File

@ -1,3 +1,4 @@
use crate::ast::*;
use crate::parser::*; use crate::parser::*;
//use nom::branch::*; //use nom::branch::*;
//use nom::combinator::*; //use nom::combinator::*;
@ -6,7 +7,7 @@ use nom::{Err, IResult};
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#[derive(Debug)] #[derive(Debug, Node)]
pub struct SpecifyBlock<'a> { pub struct SpecifyBlock<'a> {
pub nodes: (Identifier<'a>,), pub nodes: (Identifier<'a>,),
} }

View File

@ -1,3 +1,4 @@
use crate::ast::*;
use crate::parser::*; use crate::parser::*;
//use nom::branch::*; //use nom::branch::*;
//use nom::combinator::*; //use nom::combinator::*;
@ -16,26 +17,26 @@ pub struct SpecifyOutputTerminalDescriptor<'a> {
pub nodes: (OutputIdentifier<'a>, Option<ConstantRangeExpression<'a>>), pub nodes: (OutputIdentifier<'a>, Option<ConstantRangeExpression<'a>>),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub enum InputIdentifier<'a> { pub enum InputIdentifier<'a> {
InputPortIdentifier(InputPortIdentifier<'a>), InputPortIdentifier(InputPortIdentifier<'a>),
InoutPortIdentifier(InoutPortIdentifier<'a>), InoutPortIdentifier(InoutPortIdentifier<'a>),
Interface(InputIdentifierInterface<'a>), Interface(InputIdentifierInterface<'a>),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct InputIdentifierInterface<'a> { pub struct InputIdentifierInterface<'a> {
pub nodes: (InterfaceIdentifier<'a>, PortIdentifier<'a>), pub nodes: (InterfaceIdentifier<'a>, PortIdentifier<'a>),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub enum OutputIdentifier<'a> { pub enum OutputIdentifier<'a> {
OutputPortIdentifier(OutputPortIdentifier<'a>), OutputPortIdentifier(OutputPortIdentifier<'a>),
InoutPortIdentifier(InoutPortIdentifier<'a>), InoutPortIdentifier(InoutPortIdentifier<'a>),
Interface(OutputIdentifierInterface<'a>), Interface(OutputIdentifierInterface<'a>),
} }
#[derive(Debug)] #[derive(Debug, Node)]
pub struct OutputIdentifierInterface<'a> { pub struct OutputIdentifierInterface<'a> {
pub nodes: (InterfaceIdentifier<'a>, PortIdentifier<'a>), pub nodes: (InterfaceIdentifier<'a>, PortIdentifier<'a>),
} }

View File

@ -1,3 +1,4 @@
use crate::ast::*;
use crate::parser::*; use crate::parser::*;
//use nom::branch::*; //use nom::branch::*;
//use nom::combinator::*; //use nom::combinator::*;
@ -6,7 +7,7 @@ use nom::{Err, IResult};
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#[derive(Debug)] #[derive(Debug, Node)]
pub struct EdgeIdentifier<'a> { pub struct EdgeIdentifier<'a> {
pub nodes: (Identifier<'a>,), pub nodes: (Identifier<'a>,),
} }

View File

@ -1,3 +1,4 @@
use crate::ast::*;
use crate::parser::*; use crate::parser::*;
//use nom::branch::*; //use nom::branch::*;
//use nom::combinator::*; //use nom::combinator::*;
@ -6,7 +7,7 @@ use nom::{Err, IResult};
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#[derive(Debug)] #[derive(Debug, Node)]
pub struct UdpDeclaration<'a> { pub struct UdpDeclaration<'a> {
pub nodes: (Identifier<'a>,), pub nodes: (Identifier<'a>,),
} }

View File

@ -1,3 +1,4 @@
use crate::ast::*;
use crate::parser::*; use crate::parser::*;
//use nom::branch::*; //use nom::branch::*;
//use nom::combinator::*; //use nom::combinator::*;
@ -6,7 +7,7 @@ use nom::{Err, IResult};
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#[derive(Debug)] #[derive(Debug, Node)]
pub struct UdpInstantiation<'a> { pub struct UdpInstantiation<'a> {
pub nodes: (Identifier<'a>,), pub nodes: (Identifier<'a>,),
} }