Refactoring
This commit is contained in:
parent
c84ba8638b
commit
c06ff35e87
10
README.md
10
README.md
@ -49,11 +49,11 @@ A parser library for System Verilog.
|
||||
| behavioral_statements | procedural_blocks_and_assignments | x | x | |
|
||||
| behavioral_statements | parallel_and_sequential_blocks | x | x | |
|
||||
| behavioral_statements | statements | x | x | |
|
||||
| behavioral_statements | timing_control_statements | | | |
|
||||
| behavioral_statements | conditional_statements | | | |
|
||||
| behavioral_statements | case_statements | | | |
|
||||
| behavioral_statements | patterns | | | |
|
||||
| behavioral_statements | looping_statements | | | |
|
||||
| behavioral_statements | timing_control_statements | x | x | |
|
||||
| behavioral_statements | conditional_statements | x | x | |
|
||||
| behavioral_statements | case_statements | x | x | |
|
||||
| behavioral_statements | patterns | x | x | |
|
||||
| behavioral_statements | looping_statements | x | x | |
|
||||
| behavioral_statements | subroutine_call_statements | x | x | |
|
||||
| behavioral_statements | assertion_statements | | | |
|
||||
| behavioral_statements | clocking_block | | | |
|
||||
|
@ -1,3 +1,4 @@
|
||||
use crate::ast::*;
|
||||
use crate::parser::*;
|
||||
use nom::branch::*;
|
||||
use nom::combinator::*;
|
||||
@ -17,38 +18,51 @@ pub enum CaseStatement<'a> {
|
||||
#[derive(Debug)]
|
||||
pub struct CaseStatementNormal<'a> {
|
||||
pub nodes: (
|
||||
Option<UniquePriority>,
|
||||
CaseKeyword,
|
||||
Expression<'a>,
|
||||
Option<UniquePriority<'a>>,
|
||||
CaseKeyword<'a>,
|
||||
Paren<'a, CaseExpression<'a>>,
|
||||
CaseItem<'a>,
|
||||
Vec<CaseItem<'a>>,
|
||||
Symbol<'a>,
|
||||
),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct CaseStatementMatches<'a> {
|
||||
pub nodes: (
|
||||
Option<UniquePriority>,
|
||||
CaseKeyword,
|
||||
Expression<'a>,
|
||||
Option<UniquePriority<'a>>,
|
||||
CaseKeyword<'a>,
|
||||
Paren<'a, CaseExpression<'a>>,
|
||||
Symbol<'a>,
|
||||
CasePatternItem<'a>,
|
||||
Vec<CasePatternItem<'a>>,
|
||||
Symbol<'a>,
|
||||
),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct CaseStatementInside<'a> {
|
||||
pub nodes: (
|
||||
Option<UniquePriority>,
|
||||
CaseKeyword,
|
||||
Expression<'a>,
|
||||
Option<UniquePriority<'a>>,
|
||||
Symbol<'a>,
|
||||
Paren<'a, CaseExpression<'a>>,
|
||||
Symbol<'a>,
|
||||
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)]
|
||||
pub enum CaseKeyword {
|
||||
Case,
|
||||
Casez,
|
||||
Casex,
|
||||
pub struct CaseExpression<'a> {
|
||||
pub nodes: (Expression<'a>,),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@ -57,55 +71,74 @@ pub enum CaseItem<'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)]
|
||||
pub enum CasePatternItem<'a> {
|
||||
NonDefault(CasePatternItemNondefault<'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)]
|
||||
pub enum CaseInsideItem<'a> {
|
||||
NonDefault(CaseInsideItemNondefault<'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)]
|
||||
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)]
|
||||
pub struct RandcaseStatement<'a> {
|
||||
pub nodes: (Vec<RandcaseItem<'a>>,),
|
||||
pub nodes: (
|
||||
Symbol<'a>,
|
||||
RandcaseItem<'a>,
|
||||
Vec<RandcaseItem<'a>>,
|
||||
Symbol<'a>,
|
||||
),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct RandcaseItem<'a> {
|
||||
pub nodes: (Expression<'a>, StatementOrNull<'a>),
|
||||
pub nodes: (Expression<'a>, Symbol<'a>, StatementOrNull<'a>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct OpenRangeList<'a> {
|
||||
pub nodes: (Vec<OpenRangeValue<'a>>,),
|
||||
pub nodes: (List<Symbol<'a>, OpenValueRange<'a>>,),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct OpenRangeValue<'a> {
|
||||
pub struct OpenValueRange<'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> {
|
||||
let (s, x) = opt(unique_priority)(s)?;
|
||||
let (s, y) = case_keyword(s)?;
|
||||
let (s, _) = symbol("(")(s)?;
|
||||
let (s, z) = case_expression(s)?;
|
||||
let (s, _) = symbol(")")(s)?;
|
||||
let (s, v) = many1(case_item)(s)?;
|
||||
let (s, _) = symbol("endcase")(s)?;
|
||||
let (s, a) = opt(unique_priority)(s)?;
|
||||
let (s, b) = case_keyword(s)?;
|
||||
let (s, c) = paren2(case_expression)(s)?;
|
||||
let (s, d) = case_item(s)?;
|
||||
let (s, e) = many0(case_item)(s)?;
|
||||
let (s, f) = symbol("endcase")(s)?;
|
||||
Ok((
|
||||
s,
|
||||
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> {
|
||||
let (s, x) = opt(unique_priority)(s)?;
|
||||
let (s, y) = case_keyword(s)?;
|
||||
let (s, _) = symbol("(")(s)?;
|
||||
let (s, z) = case_expression(s)?;
|
||||
let (s, _) = symbol(")")(s)?;
|
||||
let (s, _) = symbol("matches")(s)?;
|
||||
let (s, v) = many1(case_pattern_item)(s)?;
|
||||
let (s, _) = symbol("endcase")(s)?;
|
||||
let (s, a) = opt(unique_priority)(s)?;
|
||||
let (s, b) = case_keyword(s)?;
|
||||
let (s, c) = paren2(case_expression)(s)?;
|
||||
let (s, d) = symbol("matches")(s)?;
|
||||
let (s, e) = case_pattern_item(s)?;
|
||||
let (s, f) = many0(case_pattern_item)(s)?;
|
||||
let (s, g) = symbol("endcase")(s)?;
|
||||
Ok((
|
||||
s,
|
||||
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> {
|
||||
let (s, x) = opt(unique_priority)(s)?;
|
||||
let (s, y) = case_keyword(s)?;
|
||||
let (s, _) = symbol("(")(s)?;
|
||||
let (s, z) = case_expression(s)?;
|
||||
let (s, _) = symbol(")")(s)?;
|
||||
let (s, _) = symbol("inside")(s)?;
|
||||
let (s, v) = many1(case_inside_item)(s)?;
|
||||
let (s, _) = symbol("endcase")(s)?;
|
||||
let (s, a) = opt(unique_priority)(s)?;
|
||||
let (s, b) = symbol("case")(s)?;
|
||||
let (s, c) = paren2(case_expression)(s)?;
|
||||
let (s, d) = symbol("inside")(s)?;
|
||||
let (s, e) = case_inside_item(s)?;
|
||||
let (s, f) = many0(case_inside_item)(s)?;
|
||||
let (s, g) = symbol("endcase")(s)?;
|
||||
Ok((
|
||||
s,
|
||||
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> {
|
||||
alt((
|
||||
map(symbol("casez"), |_| CaseKeyword::Casez),
|
||||
map(symbol("casex"), |_| CaseKeyword::Casex),
|
||||
map(symbol("case"), |_| CaseKeyword::Case),
|
||||
map(symbol("casez"), |x| CaseKeyword::Casez(x)),
|
||||
map(symbol("casex"), |x| CaseKeyword::Casex(x)),
|
||||
map(symbol("case"), |x| CaseKeyword::Case(x)),
|
||||
))(s)
|
||||
}
|
||||
|
||||
pub fn case_expression(s: Span) -> IResult<Span, Expression> {
|
||||
expression(s)
|
||||
pub fn case_expression(s: Span) -> IResult<Span, CaseExpression> {
|
||||
let (s, a) = expression(s)?;
|
||||
Ok((s, CaseExpression { nodes: (a,) }))
|
||||
}
|
||||
|
||||
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> {
|
||||
let (s, x) = separated_nonempty_list(symbol(","), case_item_expression)(s)?;
|
||||
let (s, _) = symbol(":")(s)?;
|
||||
let (s, y) = statement_or_null(s)?;
|
||||
let (s, a) = list(symbol(","), case_item_expression)(s)?;
|
||||
let (s, b) = symbol(":")(s)?;
|
||||
let (s, c) = statement_or_null(s)?;
|
||||
Ok((
|
||||
s,
|
||||
CaseItem::NonDefault(CaseItemNondefault { nodes: (x, y) }),
|
||||
CaseItem::NonDefault(CaseItemNondefault { nodes: (a, b, c) }),
|
||||
))
|
||||
}
|
||||
|
||||
pub fn case_item_default(s: Span) -> IResult<Span, CaseItemDefault> {
|
||||
let (s, _) = symbol("default")(s)?;
|
||||
let (s, _) = opt(symbol(":"))(s)?;
|
||||
let (s, x) = statement_or_null(s)?;
|
||||
Ok((s, CaseItemDefault { nodes: (x,) }))
|
||||
let (s, a) = symbol("default")(s)?;
|
||||
let (s, b) = opt(symbol(":"))(s)?;
|
||||
let (s, c) = statement_or_null(s)?;
|
||||
Ok((s, CaseItemDefault { nodes: (a, b, c) }))
|
||||
}
|
||||
|
||||
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> {
|
||||
let (s, x) = pattern(s)?;
|
||||
let (s, y) = opt(preceded(symbol("&&&"), expression))(s)?;
|
||||
let (s, _) = symbol(":")(s)?;
|
||||
let (s, z) = statement_or_null(s)?;
|
||||
let (s, a) = pattern(s)?;
|
||||
let (s, b) = opt(pair(symbol("&&&"), expression))(s)?;
|
||||
let (s, c) = symbol(":")(s)?;
|
||||
let (s, d) = statement_or_null(s)?;
|
||||
Ok((
|
||||
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> {
|
||||
let (s, x) = open_range_list(s)?;
|
||||
let (s, _) = symbol(":")(s)?;
|
||||
let (s, y) = statement_or_null(s)?;
|
||||
let (s, a) = open_range_list(s)?;
|
||||
let (s, b) = symbol(":")(s)?;
|
||||
let (s, c) = statement_or_null(s)?;
|
||||
Ok((
|
||||
s,
|
||||
CaseInsideItem::NonDefault(CaseInsideItemNondefault { nodes: (x, y) }),
|
||||
CaseInsideItem::NonDefault(CaseInsideItemNondefault { nodes: (a, b, c) }),
|
||||
))
|
||||
}
|
||||
|
||||
pub fn case_item_expression(s: Span) -> IResult<Span, Expression> {
|
||||
expression(s)
|
||||
pub fn case_item_expression(s: Span) -> IResult<Span, CaseItemExpression> {
|
||||
let (s, a) = expression(s)?;
|
||||
Ok((s, CaseItemExpression { nodes: (a,) }))
|
||||
}
|
||||
|
||||
pub fn randcase_statement(s: Span) -> IResult<Span, RandcaseStatement> {
|
||||
let (s, _) = symbol("randcase")(s)?;
|
||||
let (s, x) = many1(randcase_item)(s)?;
|
||||
let (s, _) = symbol("endcase")(s)?;
|
||||
Ok((s, RandcaseStatement { nodes: (x,) }))
|
||||
let (s, a) = symbol("randcase")(s)?;
|
||||
let (s, b) = randcase_item(s)?;
|
||||
let (s, c) = many0(randcase_item)(s)?;
|
||||
let (s, d) = symbol("endcase")(s)?;
|
||||
Ok((
|
||||
s,
|
||||
RandcaseStatement {
|
||||
nodes: (a, b, c, d),
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
pub fn randcase_item(s: Span) -> IResult<Span, RandcaseItem> {
|
||||
let (s, x) = expression(s)?;
|
||||
let (s, _) = symbol(":")(s)?;
|
||||
let (s, y) = statement_or_null(s)?;
|
||||
Ok((s, RandcaseItem { nodes: (x, y) }))
|
||||
let (s, a) = expression(s)?;
|
||||
let (s, b) = symbol(":")(s)?;
|
||||
let (s, c) = statement_or_null(s)?;
|
||||
Ok((s, RandcaseItem { nodes: (a, b, c) }))
|
||||
}
|
||||
|
||||
pub fn open_range_list(s: Span) -> IResult<Span, Vec<ValueRange>> {
|
||||
separated_nonempty_list(symbol(","), open_value_range)(s)
|
||||
pub fn open_range_list(s: Span) -> IResult<Span, OpenRangeList> {
|
||||
let (s, a) = list(symbol(","), open_value_range)(s)?;
|
||||
Ok((s, OpenRangeList { nodes: (a,) }))
|
||||
}
|
||||
|
||||
pub fn open_value_range(s: Span) -> IResult<Span, ValueRange> {
|
||||
value_range(s)
|
||||
pub fn open_value_range(s: Span) -> IResult<Span, OpenValueRange> {
|
||||
let (s, a) = value_range(s)?;
|
||||
Ok((s, OpenValueRange { nodes: (a,) }))
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
use crate::ast::*;
|
||||
use crate::parser::*;
|
||||
use nom::branch::*;
|
||||
use nom::combinator::*;
|
||||
@ -10,28 +11,30 @@ use nom::IResult;
|
||||
#[derive(Debug)]
|
||||
pub struct ConditionalStatement<'a> {
|
||||
pub nodes: (
|
||||
Option<UniquePriority>,
|
||||
ConditionalStatementBody<'a>,
|
||||
Vec<ConditionalStatementBody<'a>>,
|
||||
Option<StatementOrNull<'a>>,
|
||||
Option<UniquePriority<'a>>,
|
||||
Symbol<'a>,
|
||||
Paren<'a, CondPredicate<'a>>,
|
||||
StatementOrNull<'a>,
|
||||
Vec<(
|
||||
Symbol<'a>,
|
||||
Symbol<'a>,
|
||||
Paren<'a, CondPredicate<'a>>,
|
||||
StatementOrNull<'a>,
|
||||
)>,
|
||||
Option<(Symbol<'a>, StatementOrNull<'a>)>,
|
||||
),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum UniquePriority {
|
||||
Unique,
|
||||
Unique0,
|
||||
Priority,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ConditionalStatementBody<'a> {
|
||||
pub nodes: (CondPredicate<'a>, StatementOrNull<'a>),
|
||||
#[derive(Debug, Node)]
|
||||
pub enum UniquePriority<'a> {
|
||||
Unique(Symbol<'a>),
|
||||
Unique0(Symbol<'a>),
|
||||
Priority(Symbol<'a>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct CondPredicate<'a> {
|
||||
pub nodes: (Vec<ExpressionOrCondPattern<'a>>,),
|
||||
pub nodes: (List<Symbol<'a>, ExpressionOrCondPattern<'a>>,),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@ -42,49 +45,43 @@ pub enum ExpressionOrCondPattern<'a> {
|
||||
|
||||
#[derive(Debug)]
|
||||
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> {
|
||||
let (s, x) = opt(unique_priority)(s)?;
|
||||
let (s, _) = symbol("if")(s)?;
|
||||
let (s, y) = conditional_statement_body(s)?;
|
||||
let (s, z) = many0(preceded(
|
||||
pair(symbol("else"), symbol("if")),
|
||||
conditional_statement_body,
|
||||
))(s)?;
|
||||
let (s, v) = opt(preceded(symbol("else"), statement_or_null))(s)?;
|
||||
let (s, a) = opt(unique_priority)(s)?;
|
||||
let (s, b) = symbol("if")(s)?;
|
||||
let (s, c) = paren2(cond_predicate)(s)?;
|
||||
let (s, d) = statement_or_null(s)?;
|
||||
let (s, e) = many0(tuple((
|
||||
symbol("else"),
|
||||
symbol("if"),
|
||||
paren2(cond_predicate),
|
||||
statement_or_null,
|
||||
)))(s)?;
|
||||
let (s, f) = opt(pair(symbol("else"), statement_or_null))(s)?;
|
||||
|
||||
Ok((
|
||||
s,
|
||||
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> {
|
||||
alt((
|
||||
map(symbol("unique0"), |_| UniquePriority::Unique0),
|
||||
map(symbol("unique"), |_| UniquePriority::Unique),
|
||||
map(symbol("priority"), |_| UniquePriority::Priority),
|
||||
map(symbol("unique0"), |x| UniquePriority::Unique0(x)),
|
||||
map(symbol("unique"), |x| UniquePriority::Unique(x)),
|
||||
map(symbol("priority"), |x| UniquePriority::Priority(x)),
|
||||
))(s)
|
||||
}
|
||||
|
||||
pub fn cond_predicate(s: Span) -> IResult<Span, CondPredicate> {
|
||||
let (s, x) = separated_nonempty_list(symbol("&&&"), expression_or_cond_pattern)(s)?;
|
||||
Ok((s, CondPredicate { nodes: (x,) }))
|
||||
let (s, a) = list(symbol("&&&"), expression_or_cond_pattern)(s)?;
|
||||
Ok((s, CondPredicate { nodes: (a,) }))
|
||||
}
|
||||
|
||||
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> {
|
||||
let (s, x) = expression(s)?;
|
||||
let (s, _) = symbol("matches")(s)?;
|
||||
let (s, y) = pattern(s)?;
|
||||
Ok((s, CondPattern { nodes: (x, y) }))
|
||||
let (s, a) = expression(s)?;
|
||||
let (s, b) = symbol("matches")(s)?;
|
||||
let (s, c) = pattern(s)?;
|
||||
Ok((s, CondPattern { nodes: (a, b, c) }))
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
use crate::ast::*;
|
||||
use crate::parser::*;
|
||||
use nom::branch::*;
|
||||
use nom::combinator::*;
|
||||
use nom::multi::*;
|
||||
use nom::sequence::*;
|
||||
use nom::IResult;
|
||||
|
||||
@ -19,60 +19,92 @@ pub enum LoopStatement<'a> {
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct LoopStatementForever<'a> {
|
||||
pub nodes: (StatementOrNull<'a>,),
|
||||
pub nodes: (Symbol<'a>, StatementOrNull<'a>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct LoopStatementRepeat<'a> {
|
||||
pub nodes: (Expression<'a>, StatementOrNull<'a>),
|
||||
pub nodes: (Symbol<'a>, Paren<'a, Expression<'a>>, StatementOrNull<'a>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct LoopStatementWhile<'a> {
|
||||
pub nodes: (Expression<'a>, StatementOrNull<'a>),
|
||||
pub nodes: (Symbol<'a>, Paren<'a, Expression<'a>>, StatementOrNull<'a>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct LoopStatementFor<'a> {
|
||||
pub nodes: (
|
||||
Option<ForInitialization<'a>>,
|
||||
Option<Expression<'a>>,
|
||||
Option<Vec<ForStepAssignment<'a>>>,
|
||||
Symbol<'a>,
|
||||
Paren<
|
||||
'a,
|
||||
(
|
||||
Option<ForInitialization<'a>>,
|
||||
Symbol<'a>,
|
||||
Option<Expression<'a>>,
|
||||
Symbol<'a>,
|
||||
Option<ForStep<'a>>,
|
||||
),
|
||||
>,
|
||||
StatementOrNull<'a>,
|
||||
),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
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)]
|
||||
pub struct LoopStatementForeach<'a> {
|
||||
pub nodes: (
|
||||
PsOrHierarchicalArrayIdentifier<'a>,
|
||||
LoopVariables<'a>,
|
||||
Symbol<'a>,
|
||||
Paren<
|
||||
'a,
|
||||
(
|
||||
PsOrHierarchicalArrayIdentifier<'a>,
|
||||
Bracket<'a, LoopVariables<'a>>,
|
||||
),
|
||||
>,
|
||||
Statement<'a>,
|
||||
),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum ForInitialization<'a> {
|
||||
Assignment(ListOfVariableAssignments<'a>),
|
||||
Declaration(Vec<ForVariableDeclaration<'a>>),
|
||||
ListOfVariableAssignments(ListOfVariableAssignments<'a>),
|
||||
Declaration(ForInitializationDeclaration<'a>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ForInitializationDeclaration<'a> {
|
||||
pub nodes: (List<Symbol<'a>, ForVariableDeclaration<'a>>,),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ForVariableDeclaration<'a> {
|
||||
pub nodes: (
|
||||
Option<Var>,
|
||||
Option<Var<'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)]
|
||||
pub struct Var {}
|
||||
pub struct ForStep<'a> {
|
||||
pub nodes: (List<Symbol<'a>, ForStepAssignment<'a>>,),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum ForStepAssignment<'a> {
|
||||
@ -83,7 +115,7 @@ pub enum ForStepAssignment<'a> {
|
||||
|
||||
#[derive(Debug)]
|
||||
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> {
|
||||
let (s, _) = symbol("forever")(s)?;
|
||||
let (s, x) = statement_or_null(s)?;
|
||||
let (s, a) = symbol("forever")(s)?;
|
||||
let (s, b) = statement_or_null(s)?;
|
||||
Ok((
|
||||
s,
|
||||
LoopStatement::Forever(LoopStatementForever { nodes: (x,) }),
|
||||
LoopStatement::Forever(LoopStatementForever { nodes: (a, b) }),
|
||||
))
|
||||
}
|
||||
|
||||
pub fn loop_statement_repeat(s: Span) -> IResult<Span, LoopStatement> {
|
||||
let (s, _) = symbol("repeat")(s)?;
|
||||
let (s, _) = symbol("(")(s)?;
|
||||
let (s, x) = expression(s)?;
|
||||
let (s, _) = symbol(")")(s)?;
|
||||
let (s, y) = statement_or_null(s)?;
|
||||
let (s, a) = symbol("repeat")(s)?;
|
||||
let (s, b) = paren2(expression)(s)?;
|
||||
let (s, c) = statement_or_null(s)?;
|
||||
Ok((
|
||||
s,
|
||||
LoopStatement::Repeat(LoopStatementRepeat { nodes: (x, y) }),
|
||||
LoopStatement::Repeat(LoopStatementRepeat { nodes: (a, b, c) }),
|
||||
))
|
||||
}
|
||||
|
||||
pub fn loop_statement_while(s: Span) -> IResult<Span, LoopStatement> {
|
||||
let (s, _) = symbol("while")(s)?;
|
||||
let (s, _) = symbol("(")(s)?;
|
||||
let (s, x) = expression(s)?;
|
||||
let (s, _) = symbol(")")(s)?;
|
||||
let (s, y) = statement_or_null(s)?;
|
||||
let (s, a) = symbol("while")(s)?;
|
||||
let (s, b) = paren2(expression)(s)?;
|
||||
let (s, c) = statement_or_null(s)?;
|
||||
Ok((
|
||||
s,
|
||||
LoopStatement::While(LoopStatementWhile { nodes: (x, y) }),
|
||||
LoopStatement::While(LoopStatementWhile { nodes: (a, b, c) }),
|
||||
))
|
||||
}
|
||||
|
||||
pub fn loop_statement_for(s: Span) -> IResult<Span, LoopStatement> {
|
||||
let (s, _) = symbol("for")(s)?;
|
||||
let (s, _) = symbol("(")(s)?;
|
||||
let (s, x) = opt(for_initialization)(s)?;
|
||||
let (s, _) = symbol(";")(s)?;
|
||||
let (s, y) = opt(expression)(s)?;
|
||||
let (s, _) = symbol(";")(s)?;
|
||||
let (s, z) = opt(for_step)(s)?;
|
||||
let (s, _) = symbol(")")(s)?;
|
||||
let (s, v) = statement_or_null(s)?;
|
||||
let (s, a) = symbol("for")(s)?;
|
||||
let (s, b) = paren2(tuple((
|
||||
opt(for_initialization),
|
||||
symbol(":"),
|
||||
opt(expression),
|
||||
symbol(":"),
|
||||
opt(for_step),
|
||||
)))(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((
|
||||
s,
|
||||
LoopStatement::For(LoopStatementFor {
|
||||
nodes: (x, y, z, v),
|
||||
LoopStatement::DoWhile(LoopStatementDoWhile {
|
||||
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> {
|
||||
let (s, _) = symbol("foreach")(s)?;
|
||||
let (s, _) = symbol("(")(s)?;
|
||||
let (s, x) = ps_or_hierarchical_array_identifier(s)?;
|
||||
let (s, _) = symbol("[")(s)?;
|
||||
let (s, y) = loop_variables(s)?;
|
||||
let (s, _) = symbol("]")(s)?;
|
||||
let (s, _) = symbol(")")(s)?;
|
||||
let (s, z) = statement(s)?;
|
||||
let (s, a) = symbol("foreach")(s)?;
|
||||
let (s, b) = paren2(pair(
|
||||
ps_or_hierarchical_array_identifier,
|
||||
bracket2(loop_variables),
|
||||
))(s)?;
|
||||
let (s, c) = statement(s)?;
|
||||
Ok((
|
||||
s,
|
||||
LoopStatement::Foreach(LoopStatementForeach { nodes: (x, y, z) }),
|
||||
LoopStatement::Foreach(LoopStatementForeach { nodes: (a, b, c) }),
|
||||
))
|
||||
}
|
||||
|
||||
pub fn for_initialization(s: Span) -> IResult<Span, ForInitialization> {
|
||||
alt((
|
||||
map(list_of_variable_assignments, |x| {
|
||||
ForInitialization::Assignment(x)
|
||||
ForInitialization::ListOfVariableAssignments(x)
|
||||
}),
|
||||
map(
|
||||
separated_nonempty_list(symbol(","), for_variable_declaration),
|
||||
|x| ForInitialization::Declaration(x),
|
||||
),
|
||||
for_initialization_declaration,
|
||||
))(s)
|
||||
}
|
||||
|
||||
pub fn for_variable_declaration(s: Span) -> IResult<Span, ForVariableDeclaration> {
|
||||
let (s, x) = opt(symbol("var"))(s)?;
|
||||
let (s, y) = data_type(s)?;
|
||||
let (s, z) = separated_nonempty_list(
|
||||
symbol(","),
|
||||
pair(variable_identifier, preceded(symbol("="), expression)),
|
||||
)(s)?;
|
||||
pub fn for_initialization_declaration(s: Span) -> IResult<Span, ForInitialization> {
|
||||
let (s, a) = list(symbol(","), for_variable_declaration)(s)?;
|
||||
Ok((
|
||||
s,
|
||||
ForVariableDeclaration {
|
||||
nodes: (x.map(|_| Var {}), y, z),
|
||||
},
|
||||
ForInitialization::Declaration(ForInitializationDeclaration { nodes: (a,) }),
|
||||
))
|
||||
}
|
||||
|
||||
pub fn for_step(s: Span) -> IResult<Span, Vec<ForStepAssignment>> {
|
||||
separated_nonempty_list(symbol(","), for_step_assignment)(s)
|
||||
pub fn for_variable_declaration(s: Span) -> IResult<Span, ForVariableDeclaration> {
|
||||
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> {
|
||||
@ -225,8 +252,8 @@ pub fn for_step_assignment(s: Span) -> IResult<Span, ForStepAssignment> {
|
||||
}
|
||||
|
||||
pub fn loop_variables(s: Span) -> IResult<Span, LoopVariables> {
|
||||
let (s, x) = separated_nonempty_list(symbol(","), opt(index_variable_identifier))(s)?;
|
||||
Ok((s, LoopVariables { nodes: (x,) }))
|
||||
let (s, a) = list(symbol(","), opt(index_variable_identifier))(s)?;
|
||||
Ok((s, LoopVariables { nodes: (a,) }))
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
@ -1,7 +1,7 @@
|
||||
use crate::ast::*;
|
||||
use crate::parser::*;
|
||||
use nom::branch::*;
|
||||
use nom::combinator::*;
|
||||
use nom::multi::*;
|
||||
use nom::sequence::*;
|
||||
use nom::IResult;
|
||||
|
||||
@ -9,38 +9,94 @@ use nom::IResult;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Pattern<'a> {
|
||||
VariableIdentifier(Box<VariableIdentifier<'a>>),
|
||||
Asterisk,
|
||||
Variable(Box<PatternVariable<'a>>),
|
||||
Asterisk(Symbol<'a>),
|
||||
ConstantExpression(Box<ConstantExpression<'a>>),
|
||||
Tagged(Box<(MemberIdentifier<'a>, Option<Pattern<'a>>)>),
|
||||
Pattern(Box<Vec<Pattern<'a>>>),
|
||||
MemberPattern(Box<Vec<(MemberIdentifier<'a>, Pattern<'a>)>>),
|
||||
Tagged(Box<PatternTagged<'a>>),
|
||||
List(Box<PatternList<'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)]
|
||||
pub enum AssignmentPattern<'a> {
|
||||
Expression(Vec<Expression<'a>>),
|
||||
StructurePatternKey(Vec<(StructurePatternKey<'a>, Expression<'a>)>),
|
||||
ArrayPatternKey(Vec<(ArrayPatternKey<'a>, Expression<'a>)>),
|
||||
ConstantExpression((ConstantExpression<'a>, Vec<Expression<'a>>)),
|
||||
List(AssignmentPatternList<'a>),
|
||||
Structure(AssignmentPatternStructure<'a>),
|
||||
Array(AssignmentPatternArray<'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)]
|
||||
pub enum StructurePatternKey<'a> {
|
||||
Identifier(MemberIdentifier<'a>),
|
||||
PatternKey(AssignmentPatternKey<'a>),
|
||||
MemberIdentifier(MemberIdentifier<'a>),
|
||||
AssignmentPatternKey(AssignmentPatternKey<'a>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum ArrayPatternKey<'a> {
|
||||
Expression(ConstantExpression<'a>),
|
||||
PatternKey(AssignmentPatternKey<'a>),
|
||||
ConstantExpression(ConstantExpression<'a>),
|
||||
AssignmentPatternKey(AssignmentPatternKey<'a>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum AssignmentPatternKey<'a> {
|
||||
SimpleType(SimpleType<'a>),
|
||||
Default,
|
||||
Default(Symbol<'a>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@ -53,9 +109,9 @@ pub struct AssignmentPatternExpression<'a> {
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum AssignmentPatternExpressionType<'a> {
|
||||
Type(PsTypeIdentifier<'a>),
|
||||
Parameter(PsParameterIdentifier<'a>),
|
||||
IntegerAtom(IntegerAtomType),
|
||||
PsTypeIdentifier(PsTypeIdentifier<'a>),
|
||||
PsParameterIdentifier(PsParameterIdentifier<'a>),
|
||||
IntegerAtomType(IntegerAtomType),
|
||||
TypeReference(TypeReference<'a>),
|
||||
}
|
||||
|
||||
@ -66,100 +122,147 @@ pub struct ConstantAssignmentPatternExpression<'a> {
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct AssignmentPatternNetLvalue<'a> {
|
||||
pub nodes: (Vec<NetLvalue<'a>>,),
|
||||
pub nodes: (ApostropheBrace<'a, List<Symbol<'a>, NetLvalue<'a>>>,),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
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> {
|
||||
alt((
|
||||
map(preceded(symbol("."), variable_identifier), |x| {
|
||||
Pattern::VariableIdentifier(Box::new(x))
|
||||
}),
|
||||
map(symbol(".*"), |_| Pattern::Asterisk),
|
||||
pattern_variable,
|
||||
map(symbol(".*"), |x| Pattern::Asterisk(x)),
|
||||
map(constant_expression, |x| {
|
||||
Pattern::ConstantExpression(Box::new(x))
|
||||
}),
|
||||
map(
|
||||
preceded(symbol("tagged"), pair(member_identifier, opt(pattern))),
|
||||
|x| Pattern::Tagged(Box::new(x)),
|
||||
),
|
||||
map(
|
||||
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)),
|
||||
),
|
||||
pattern_tagged,
|
||||
pattern_list,
|
||||
pattern_identifier_list,
|
||||
))(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> {
|
||||
alt((
|
||||
map(
|
||||
apostrophe_brace(separated_nonempty_list(symbol(","), expression)),
|
||||
|x| AssignmentPattern::Expression(x),
|
||||
),
|
||||
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),
|
||||
),
|
||||
assignment_pattern_list,
|
||||
assignment_pattern_structure,
|
||||
assignment_pattern_array,
|
||||
assignment_pattern_repeat,
|
||||
))(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> {
|
||||
alt((
|
||||
map(member_identifier, |x| StructurePatternKey::Identifier(x)),
|
||||
map(member_identifier, |x| {
|
||||
StructurePatternKey::MemberIdentifier(x)
|
||||
}),
|
||||
map(assignment_pattern_key, |x| {
|
||||
StructurePatternKey::PatternKey(x)
|
||||
StructurePatternKey::AssignmentPatternKey(x)
|
||||
}),
|
||||
))(s)
|
||||
}
|
||||
|
||||
pub fn array_pattern_key(s: Span) -> IResult<Span, ArrayPatternKey> {
|
||||
alt((
|
||||
map(constant_expression, |x| ArrayPatternKey::Expression(x)),
|
||||
map(assignment_pattern_key, |x| ArrayPatternKey::PatternKey(x)),
|
||||
map(constant_expression, |x| {
|
||||
ArrayPatternKey::ConstantExpression(x)
|
||||
}),
|
||||
map(assignment_pattern_key, |x| {
|
||||
ArrayPatternKey::AssignmentPatternKey(x)
|
||||
}),
|
||||
))(s)
|
||||
}
|
||||
|
||||
pub fn assignment_pattern_key(s: Span) -> IResult<Span, AssignmentPatternKey> {
|
||||
alt((
|
||||
map(simple_type, |x| AssignmentPatternKey::SimpleType(x)),
|
||||
map(symbol("default"), |_| AssignmentPatternKey::Default),
|
||||
map(symbol("default"), |x| AssignmentPatternKey::Default(x)),
|
||||
))(s)
|
||||
}
|
||||
|
||||
pub fn assignment_pattern_expression(s: Span) -> IResult<Span, AssignmentPatternExpression> {
|
||||
let (s, x) = opt(assignment_pattern_expression_type)(s)?;
|
||||
let (s, y) = assignment_pattern(s)?;
|
||||
Ok((s, AssignmentPatternExpression { nodes: (x, y) }))
|
||||
let (s, a) = opt(assignment_pattern_expression_type)(s)?;
|
||||
let (s, b) = assignment_pattern(s)?;
|
||||
Ok((s, AssignmentPatternExpression { nodes: (a, b) }))
|
||||
}
|
||||
|
||||
pub fn assignment_pattern_expression_type(
|
||||
@ -167,13 +270,13 @@ pub fn assignment_pattern_expression_type(
|
||||
) -> IResult<Span, AssignmentPatternExpressionType> {
|
||||
alt((
|
||||
map(ps_type_identifier, |x| {
|
||||
AssignmentPatternExpressionType::Type(x)
|
||||
AssignmentPatternExpressionType::PsTypeIdentifier(x)
|
||||
}),
|
||||
map(ps_parameter_identifier, |x| {
|
||||
AssignmentPatternExpressionType::Parameter(x)
|
||||
AssignmentPatternExpressionType::PsParameterIdentifier(x)
|
||||
}),
|
||||
map(integer_atom_type, |x| {
|
||||
AssignmentPatternExpressionType::IntegerAtom(x)
|
||||
AssignmentPatternExpressionType::IntegerAtomType(x)
|
||||
}),
|
||||
map(type_reference, |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> {
|
||||
let (s, x) = apostrophe_brace(separated_nonempty_list(symbol(","), net_lvalue))(s)?;
|
||||
Ok((s, AssignmentPatternNetLvalue { nodes: (x,) }))
|
||||
let (s, a) = apostrophe_brace2(list(symbol(","), net_lvalue))(s)?;
|
||||
Ok((s, AssignmentPatternNetLvalue { nodes: (a,) }))
|
||||
}
|
||||
|
||||
pub fn assignment_pattern_variable_lvalue(
|
||||
s: Span,
|
||||
) -> IResult<Span, AssignmentPatternVariableLvalue> {
|
||||
let (s, x) = apostrophe_brace(separated_nonempty_list(symbol(","), variable_lvalue))(s)?;
|
||||
Ok((s, AssignmentPatternVariableLvalue { nodes: (x,) }))
|
||||
let (s, a) = apostrophe_brace2(list(symbol(","), variable_lvalue))(s)?;
|
||||
Ok((s, AssignmentPatternVariableLvalue { nodes: (a,) }))
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
@ -79,7 +79,7 @@ pub struct RsRepeat<'a> {
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct RsCase<'a> {
|
||||
pub nodes: (Expression<'a>, Vec<RsCaseItem<'a>>),
|
||||
pub nodes: (CaseExpression<'a>, Vec<RsCaseItem<'a>>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@ -95,7 +95,7 @@ pub struct RsCaseItemDefault<'a> {
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct RsCaseItemNondefault<'a> {
|
||||
pub nodes: (Vec<Expression<'a>>, ProductionItem<'a>),
|
||||
pub nodes: (Vec<CaseItemExpression<'a>>, ProductionItem<'a>),
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
@ -1,7 +1,7 @@
|
||||
use crate::ast::*;
|
||||
use crate::parser::*;
|
||||
use nom::branch::*;
|
||||
use nom::combinator::*;
|
||||
use nom::multi::*;
|
||||
use nom::sequence::*;
|
||||
use nom::IResult;
|
||||
|
||||
@ -21,30 +21,66 @@ pub enum DelayOrEventControl<'a> {
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct DelayOrEventControlRepeat<'a> {
|
||||
pub nodes: (Expression<'a>, EventControl<'a>),
|
||||
pub nodes: (Symbol<'a>, Paren<'a, Expression<'a>>, EventControl<'a>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum DelayControl<'a> {
|
||||
Delay(DelayValue<'a>),
|
||||
Mintypmax(MintypmaxExpression<'a>),
|
||||
Delay(DelayControlDelay<'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)]
|
||||
pub enum EventControl<'a> {
|
||||
EventIdentifier(HierarchicalEventIdentifier<'a>),
|
||||
EventExpression(EventExpression<'a>),
|
||||
Asterisk,
|
||||
SequenceIdentifier(PsOrHierarchicalSequenceIdentifier<'a>),
|
||||
EventIdentifier(EventControlEventIdentifier<'a>),
|
||||
EventExpression(EventControlEventExpression<'a>),
|
||||
Asterisk(EventControlAsterisk<'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)]
|
||||
pub enum EventExpression<'a> {
|
||||
Expression(Box<EventExpressionExpression<'a>>),
|
||||
Sequence(Box<EventExpressionSequence<'a>>),
|
||||
Or(Box<(EventExpression<'a>, EventExpression<'a>)>),
|
||||
Comma(Box<(EventExpression<'a>, EventExpression<'a>)>),
|
||||
Paren(Box<EventExpression<'a>>),
|
||||
Or(Box<EventExpressionOr<'a>>),
|
||||
Comma(Box<EventExpressionComma<'a>>),
|
||||
Paren(Box<EventExpressionParen<'a>>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@ -52,13 +88,28 @@ pub struct EventExpressionExpression<'a> {
|
||||
pub nodes: (
|
||||
Option<EdgeIdentifier<'a>>,
|
||||
Expression<'a>,
|
||||
Option<Expression<'a>>,
|
||||
Option<(Symbol<'a>, Expression<'a>)>,
|
||||
),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
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)]
|
||||
@ -71,30 +122,49 @@ pub enum ProceduralTimingControl<'a> {
|
||||
#[derive(Debug)]
|
||||
pub enum JumpStatement<'a> {
|
||||
Return(JumpStatementReturn<'a>),
|
||||
Break,
|
||||
Continue,
|
||||
Break(JumpStatementBreak<'a>),
|
||||
Continue(JumpStatementContinue<'a>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
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)]
|
||||
pub enum WaitStatement<'a> {
|
||||
Wait(WaitStatementWait<'a>),
|
||||
Fork,
|
||||
Fork(WaitStatementFork<'a>),
|
||||
Order(WaitStatementOrder<'a>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
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)]
|
||||
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)]
|
||||
@ -105,22 +175,39 @@ pub enum EventTrigger<'a> {
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct EventTriggerNamed<'a> {
|
||||
pub nodes: (HierarchicalEventIdentifier<'a>,),
|
||||
pub nodes: (Symbol<'a>, HierarchicalEventIdentifier<'a>, Symbol<'a>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct EventTriggerNonblocking<'a> {
|
||||
pub nodes: (
|
||||
Symbol<'a>,
|
||||
Option<DelayOrEventControl<'a>>,
|
||||
HierarchicalEventIdentifier<'a>,
|
||||
Symbol<'a>,
|
||||
),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum DisableStatement<'a> {
|
||||
Task(HierarchicalTaskIdentifier<'a>),
|
||||
Block(HierarchicalBlockIdentifier<'a>),
|
||||
Fork,
|
||||
Task(DisableStatementTask<'a>),
|
||||
Block(DisableStatementBlock<'a>),
|
||||
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(
|
||||
s: Span,
|
||||
) -> IResult<Span, ProceduralTimingControlStatement> {
|
||||
let (s, x) = procedural_timing_control(s)?;
|
||||
let (s, y) = statement_or_null(s)?;
|
||||
Ok((s, ProceduralTimingControlStatement { nodes: (x, y) }))
|
||||
let (s, a) = procedural_timing_control(s)?;
|
||||
let (s, b) = statement_or_null(s)?;
|
||||
Ok((s, ProceduralTimingControlStatement { nodes: (a, b) }))
|
||||
}
|
||||
|
||||
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> {
|
||||
let (s, _) = symbol("repeat")(s)?;
|
||||
let (s, _) = symbol("(")(s)?;
|
||||
let (s, x) = expression(s)?;
|
||||
let (s, _) = symbol(")")(s)?;
|
||||
let (s, y) = event_control(s)?;
|
||||
let (s, a) = symbol("repeat")(s)?;
|
||||
let (s, b) = paren2(expression)(s)?;
|
||||
let (s, c) = event_control(s)?;
|
||||
Ok((
|
||||
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> {
|
||||
let (s, _) = symbol("#")(s)?;
|
||||
let (s, x) = delay_value(s)?;
|
||||
Ok((s, DelayControl::Delay(x)))
|
||||
let (s, a) = symbol("#")(s)?;
|
||||
let (s, b) = delay_value(s)?;
|
||||
Ok((s, DelayControl::Delay(DelayControlDelay { nodes: (a, b) })))
|
||||
}
|
||||
|
||||
pub fn delay_control_mintypmax(s: Span) -> IResult<Span, DelayControl> {
|
||||
let (s, _) = symbol("#")(s)?;
|
||||
let (s, _) = symbol("(")(s)?;
|
||||
let (s, x) = mintypmax_expression(s)?;
|
||||
let (s, _) = symbol(")")(s)?;
|
||||
Ok((s, DelayControl::Mintypmax(x)))
|
||||
let (s, a) = symbol("#")(s)?;
|
||||
let (s, b) = paren2(mintypmax_expression)(s)?;
|
||||
Ok((
|
||||
s,
|
||||
DelayControl::Mintypmax(DelayControlMintypmax { nodes: (a, b) }),
|
||||
))
|
||||
}
|
||||
|
||||
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_expression,
|
||||
event_control_asterisk,
|
||||
event_control_paren_asterisk,
|
||||
event_control_sequence_identifier,
|
||||
))(s)
|
||||
}
|
||||
|
||||
pub fn event_control_event_identifier(s: Span) -> IResult<Span, EventControl> {
|
||||
let (s, _) = symbol("@")(s)?;
|
||||
let (s, x) = hierarchical_event_identifier(s)?;
|
||||
Ok((s, EventControl::EventIdentifier(x)))
|
||||
let (s, a) = symbol("@")(s)?;
|
||||
let (s, b) = hierarchical_event_identifier(s)?;
|
||||
Ok((
|
||||
s,
|
||||
EventControl::EventIdentifier(EventControlEventIdentifier { nodes: (a, b) }),
|
||||
))
|
||||
}
|
||||
|
||||
pub fn event_control_event_expression(s: Span) -> IResult<Span, EventControl> {
|
||||
let (s, _) = symbol("@")(s)?;
|
||||
let (s, _) = symbol("(")(s)?;
|
||||
let (s, x) = event_expression(s)?;
|
||||
let (s, _) = symbol(")")(s)?;
|
||||
Ok((s, EventControl::EventExpression(x)))
|
||||
let (s, a) = symbol("@")(s)?;
|
||||
let (s, b) = paren2(event_expression)(s)?;
|
||||
Ok((
|
||||
s,
|
||||
EventControl::EventExpression(EventControlEventExpression { nodes: (a, b) }),
|
||||
))
|
||||
}
|
||||
|
||||
pub fn event_control_asterisk(s: Span) -> IResult<Span, EventControl> {
|
||||
let (s, _) = alt((symbol("@*"), preceded(symbol("@"), symbol("(*)"))))(s)?;
|
||||
Ok((s, EventControl::Asterisk))
|
||||
let (s, a) = symbol("@*")(s)?;
|
||||
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> {
|
||||
let (s, _) = symbol("@")(s)?;
|
||||
let (s, x) = ps_or_hierarchical_sequence_identifier(s)?;
|
||||
Ok((s, EventControl::SequenceIdentifier(x)))
|
||||
let (s, a) = symbol("@")(s)?;
|
||||
let (s, b) = ps_or_hierarchical_sequence_identifier(s)?;
|
||||
Ok((
|
||||
s,
|
||||
EventControl::SequenceIdentifier(EventControlSequenceIdentifier { nodes: (a, b) }),
|
||||
))
|
||||
}
|
||||
|
||||
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> {
|
||||
let (s, x) = opt(edge_identifier)(s)?;
|
||||
let (s, y) = expression(s)?;
|
||||
let (s, z) = opt(preceded(symbol("iff"), expression))(s)?;
|
||||
let (s, a) = opt(edge_identifier)(s)?;
|
||||
let (s, b) = expression(s)?;
|
||||
let (s, c) = opt(pair(symbol("iff"), expression))(s)?;
|
||||
Ok((
|
||||
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> {
|
||||
let (s, x) = sequence_instance(s)?;
|
||||
let (s, y) = opt(preceded(symbol("iff"), expression))(s)?;
|
||||
let (s, a) = sequence_instance(s)?;
|
||||
let (s, b) = opt(pair(symbol("iff"), expression))(s)?;
|
||||
Ok((
|
||||
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> {
|
||||
let (s, x) = event_expression(s)?;
|
||||
let (s, _) = symbol("or")(s)?;
|
||||
let (s, y) = event_expression(s)?;
|
||||
Ok((s, EventExpression::Or(Box::new((x, y)))))
|
||||
let (s, a) = event_expression(s)?;
|
||||
let (s, b) = symbol("or")(s)?;
|
||||
let (s, c) = event_expression(s)?;
|
||||
Ok((
|
||||
s,
|
||||
EventExpression::Or(Box::new(EventExpressionOr { nodes: (a, b, c) })),
|
||||
))
|
||||
}
|
||||
|
||||
pub fn event_expression_comma(s: Span) -> IResult<Span, EventExpression> {
|
||||
let (s, x) = event_expression(s)?;
|
||||
let (s, _) = symbol(",")(s)?;
|
||||
let (s, y) = event_expression(s)?;
|
||||
Ok((s, EventExpression::Comma(Box::new((x, y)))))
|
||||
let (s, a) = event_expression(s)?;
|
||||
let (s, b) = symbol(",")(s)?;
|
||||
let (s, c) = event_expression(s)?;
|
||||
Ok((
|
||||
s,
|
||||
EventExpression::Comma(Box::new(EventExpressionComma { nodes: (a, b, c) })),
|
||||
))
|
||||
}
|
||||
|
||||
pub fn event_expression_paren(s: Span) -> IResult<Span, EventExpression> {
|
||||
let (s, _) = symbol("(")(s)?;
|
||||
let (s, x) = event_expression(s)?;
|
||||
let (s, _) = symbol(")")(s)?;
|
||||
Ok((s, EventExpression::Paren(Box::new(x))))
|
||||
let (s, a) = paren2(event_expression)(s)?;
|
||||
Ok((
|
||||
s,
|
||||
EventExpression::Paren(Box::new(EventExpressionParen { nodes: (a,) })),
|
||||
))
|
||||
}
|
||||
|
||||
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> {
|
||||
let (s, _) = symbol("return")(s)?;
|
||||
let (s, x) = opt(expression)(s)?;
|
||||
let (s, _) = symbol(";")(s)?;
|
||||
let (s, a) = symbol("return")(s)?;
|
||||
let (s, b) = opt(expression)(s)?;
|
||||
let (s, c) = symbol(";")(s)?;
|
||||
Ok((
|
||||
s,
|
||||
JumpStatement::Return(JumpStatementReturn { nodes: (x,) }),
|
||||
JumpStatement::Return(JumpStatementReturn { nodes: (a, b, c) }),
|
||||
))
|
||||
}
|
||||
|
||||
pub fn jump_statement_break(s: Span) -> IResult<Span, JumpStatement> {
|
||||
let (s, _) = symbol("break")(s)?;
|
||||
let (s, _) = symbol(";")(s)?;
|
||||
Ok((s, JumpStatement::Break))
|
||||
let (s, a) = symbol("break")(s)?;
|
||||
let (s, b) = symbol(";")(s)?;
|
||||
Ok((
|
||||
s,
|
||||
JumpStatement::Break(JumpStatementBreak { nodes: (a, b) }),
|
||||
))
|
||||
}
|
||||
|
||||
pub fn jump_statement_continue(s: Span) -> IResult<Span, JumpStatement> {
|
||||
let (s, _) = symbol("continue")(s)?;
|
||||
let (s, _) = symbol(";")(s)?;
|
||||
Ok((s, JumpStatement::Continue))
|
||||
let (s, a) = symbol("continue")(s)?;
|
||||
let (s, b) = symbol(";")(s)?;
|
||||
Ok((
|
||||
s,
|
||||
JumpStatement::Continue(JumpStatementContinue { nodes: (a, b) }),
|
||||
))
|
||||
}
|
||||
|
||||
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> {
|
||||
let (s, _) = symbol("wait")(s)?;
|
||||
let (s, x) = paren(expression)(s)?;
|
||||
let (s, y) = statement_or_null(s)?;
|
||||
Ok((s, WaitStatement::Wait(WaitStatementWait { nodes: (x, y) })))
|
||||
let (s, a) = symbol("wait")(s)?;
|
||||
let (s, b) = paren2(expression)(s)?;
|
||||
let (s, c) = statement_or_null(s)?;
|
||||
Ok((
|
||||
s,
|
||||
WaitStatement::Wait(WaitStatementWait { nodes: (a, b, c) }),
|
||||
))
|
||||
}
|
||||
|
||||
pub fn wait_statement_fork(s: Span) -> IResult<Span, WaitStatement> {
|
||||
let (s, _) = symbol("wait")(s)?;
|
||||
let (s, _) = symbol("fork")(s)?;
|
||||
let (s, _) = symbol(";")(s)?;
|
||||
Ok((s, WaitStatement::Fork))
|
||||
let (s, a) = symbol("wait")(s)?;
|
||||
let (s, b) = symbol("fork")(s)?;
|
||||
let (s, c) = symbol(";")(s)?;
|
||||
Ok((
|
||||
s,
|
||||
WaitStatement::Fork(WaitStatementFork { nodes: (a, b, c) }),
|
||||
))
|
||||
}
|
||||
|
||||
pub fn wait_statement_order(s: Span) -> IResult<Span, WaitStatement> {
|
||||
let (s, _) = symbol("wait_order")(s)?;
|
||||
let (s, x) = paren(separated_nonempty_list(
|
||||
symbol(","),
|
||||
hierarchical_identifier,
|
||||
))(s)?;
|
||||
let (s, y) = action_block(s)?;
|
||||
let (s, a) = symbol("wait_order")(s)?;
|
||||
let (s, b) = paren2(list(symbol(","), hierarchical_identifier))(s)?;
|
||||
let (s, c) = action_block(s)?;
|
||||
Ok((
|
||||
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> {
|
||||
let (s, _) = symbol("->")(s)?;
|
||||
let (s, x) = hierarchical_event_identifier(s)?;
|
||||
let (s, _) = symbol(";")(s)?;
|
||||
Ok((s, EventTrigger::Named(EventTriggerNamed { nodes: (x,) })))
|
||||
let (s, a) = symbol("->")(s)?;
|
||||
let (s, b) = hierarchical_event_identifier(s)?;
|
||||
let (s, c) = symbol(";")(s)?;
|
||||
Ok((
|
||||
s,
|
||||
EventTrigger::Named(EventTriggerNamed { nodes: (a, b, c) }),
|
||||
))
|
||||
}
|
||||
|
||||
pub fn event_trigger_nonblocking(s: Span) -> IResult<Span, EventTrigger> {
|
||||
let (s, _) = symbol("->>")(s)?;
|
||||
let (s, x) = opt(delay_or_event_control)(s)?;
|
||||
let (s, y) = hierarchical_event_identifier(s)?;
|
||||
let (s, _) = symbol(";")(s)?;
|
||||
let (s, a) = symbol("->>")(s)?;
|
||||
let (s, b) = opt(delay_or_event_control)(s)?;
|
||||
let (s, c) = hierarchical_event_identifier(s)?;
|
||||
let (s, d) = symbol(";")(s)?;
|
||||
Ok((
|
||||
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> {
|
||||
let (s, _) = symbol("disable")(s)?;
|
||||
let (s, x) = hierarchical_task_identifier(s)?;
|
||||
let (s, _) = symbol(";")(s)?;
|
||||
Ok((s, DisableStatement::Task(x)))
|
||||
let (s, a) = symbol("disable")(s)?;
|
||||
let (s, b) = hierarchical_task_identifier(s)?;
|
||||
let (s, c) = symbol(";")(s)?;
|
||||
Ok((
|
||||
s,
|
||||
DisableStatement::Task(DisableStatementTask { nodes: (a, b, c) }),
|
||||
))
|
||||
}
|
||||
|
||||
pub fn disable_statement_block(s: Span) -> IResult<Span, DisableStatement> {
|
||||
let (s, _) = symbol("disable")(s)?;
|
||||
let (s, x) = hierarchical_block_identifier(s)?;
|
||||
let (s, _) = symbol(";")(s)?;
|
||||
Ok((s, DisableStatement::Block(x)))
|
||||
let (s, a) = symbol("disable")(s)?;
|
||||
let (s, b) = hierarchical_block_identifier(s)?;
|
||||
let (s, c) = symbol(";")(s)?;
|
||||
Ok((
|
||||
s,
|
||||
DisableStatement::Block(DisableStatementBlock { nodes: (a, b, c) }),
|
||||
))
|
||||
}
|
||||
|
||||
pub fn disable_statement_fork(s: Span) -> IResult<Span, DisableStatement> {
|
||||
let (s, _) = symbol("disable")(s)?;
|
||||
let (s, _) = symbol("fork")(s)?;
|
||||
let (s, _) = symbol(";")(s)?;
|
||||
Ok((s, DisableStatement::Fork))
|
||||
let (s, a) = symbol("disable")(s)?;
|
||||
let (s, b) = symbol("fork")(s)?;
|
||||
let (s, c) = symbol(";")(s)?;
|
||||
Ok((
|
||||
s,
|
||||
DisableStatement::Fork(DisableStatementFork { nodes: (a, b, c) }),
|
||||
))
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
use crate::ast::*;
|
||||
use crate::parser::*;
|
||||
//use nom::branch::*;
|
||||
//use nom::combinator::*;
|
||||
@ -12,7 +13,7 @@ pub enum Delay3<'a> {
|
||||
Mintypmax(Delay3Mintypmax<'a>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct Delay3Single<'a> {
|
||||
pub nodes: (Symbol<'a>, DelayValue<'a>),
|
||||
}
|
||||
@ -37,7 +38,7 @@ pub enum Delay2<'a> {
|
||||
Mintypmax(Delay2Mintypmax<'a>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct Delay2Single<'a> {
|
||||
pub nodes: (Symbol<'a>, DelayValue<'a>),
|
||||
}
|
||||
@ -50,7 +51,7 @@ pub struct Delay2Mintypmax<'a> {
|
||||
),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub enum DelayValue<'a> {
|
||||
UnsignedNumber(UnsignedNumber<'a>),
|
||||
RealNumber(RealNumber<'a>),
|
||||
|
@ -62,7 +62,7 @@ pub struct TfPortItem<'a> {
|
||||
pub nodes: (
|
||||
Vec<AttributeInstance<'a>>,
|
||||
Option<TfPortDirection>,
|
||||
Option<Var>,
|
||||
Option<Var<'a>>,
|
||||
DataTypeOrImplicit<'a>,
|
||||
Option<(
|
||||
Identifier<'a>,
|
||||
@ -83,7 +83,7 @@ pub struct TfPortDeclaration<'a> {
|
||||
pub nodes: (
|
||||
Vec<AttributeInstance<'a>>,
|
||||
TfPortDirection,
|
||||
Option<Var>,
|
||||
Option<Var<'a>>,
|
||||
DataTypeOrImplicit<'a>,
|
||||
ListOfTfVariableIdentifiers<'a>,
|
||||
),
|
||||
|
@ -9,7 +9,7 @@ use nom::IResult;
|
||||
pub enum NetLvalue<'a> {
|
||||
Identifier(NetLvalueIdentifier<'a>),
|
||||
Lvalue(Box<NetLvalueLvalue<'a>>),
|
||||
Pattern(NetLvaluePattern<'a>),
|
||||
Pattern(Box<NetLvaluePattern<'a>>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@ -34,7 +34,7 @@ pub struct NetLvaluePattern<'a> {
|
||||
pub enum VariableLvalue<'a> {
|
||||
Identifier(VariableLvalueIdentifier<'a>),
|
||||
Lvalue(Box<VariableLvalueLvalue<'a>>),
|
||||
Pattern(VariableLvaluePattern<'a>),
|
||||
Pattern(Box<VariableLvaluePattern<'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> {
|
||||
let (s, a) = opt(assignment_pattern_expression_type)(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> {
|
||||
@ -124,7 +127,7 @@ pub fn variable_lvalue_pattern(s: Span) -> IResult<Span, VariableLvalue> {
|
||||
let (s, b) = assignment_pattern_variable_lvalue(s)?;
|
||||
Ok((
|
||||
s,
|
||||
VariableLvalue::Pattern(VariableLvaluePattern { nodes: (a, b) }),
|
||||
VariableLvalue::Pattern(Box::new(VariableLvaluePattern { nodes: (a, b) })),
|
||||
))
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,3 @@
|
||||
use crate::ast::*;
|
||||
use crate::parser::*;
|
||||
use nom::branch::*;
|
||||
use nom::combinator::*;
|
||||
@ -174,7 +173,7 @@ pub struct TaggedUnionExpression<'a> {
|
||||
|
||||
#[derive(Debug)]
|
||||
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)]
|
||||
|
@ -1,30 +1,31 @@
|
||||
use crate::ast::*;
|
||||
use crate::parser::*;
|
||||
use nom::branch::*;
|
||||
use nom::IResult;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct UnaryOperator<'a> {
|
||||
pub nodes: (Symbol<'a>,),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct BinaryOperator<'a> {
|
||||
pub nodes: (Symbol<'a>,),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct IncOrDecOperator<'a> {
|
||||
pub nodes: (Symbol<'a>,),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct UnaryModulePathOperator<'a> {
|
||||
pub nodes: (Symbol<'a>,),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct BinaryModulePathOperator<'a> {
|
||||
pub nodes: (Symbol<'a>,),
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
use crate::ast::*;
|
||||
use crate::parser::*;
|
||||
use nom::branch::*;
|
||||
use nom::combinator::*;
|
||||
@ -144,11 +145,6 @@ pub struct ClassQualifier<'a> {
|
||||
),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Local<'a> {
|
||||
pub nodes: (Symbol<'a>,),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum RangeExpression<'a> {
|
||||
Expression(Expression<'a>),
|
||||
@ -163,23 +159,23 @@ pub enum PrimaryLiteral<'a> {
|
||||
StringLiteral(StringLiteral<'a>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub enum TimeLiteral<'a> {
|
||||
Unsigned(TimeLiteralUnsigned<'a>),
|
||||
FixedPoint(TimeLiteralFixedPoint<'a>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct TimeLiteralUnsigned<'a> {
|
||||
pub nodes: (UnsignedNumber<'a>, TimeUnit<'a>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct TimeLiteralFixedPoint<'a> {
|
||||
pub nodes: (FixedPointNumber<'a>, TimeUnit<'a>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub enum TimeUnit<'a> {
|
||||
S(Symbol<'a>),
|
||||
MS(Symbol<'a>),
|
||||
@ -189,7 +185,7 @@ pub enum TimeUnit<'a> {
|
||||
FS(Symbol<'a>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub enum ImplicitClassHandle<'a> {
|
||||
This(Symbol<'a>),
|
||||
Super(Symbol<'a>),
|
||||
@ -267,6 +263,7 @@ pub struct Cast<'a> {
|
||||
|
||||
pub fn constant_primary(s: Span) -> IResult<Span, ConstantPrimary> {
|
||||
alt((
|
||||
map(symbol("null"), |x| ConstantPrimary::Null(x)),
|
||||
map(primary_literal, |x| ConstantPrimary::PrimaryLiteral(x)),
|
||||
constant_primary_ps_parameter,
|
||||
constant_primary_specparam,
|
||||
@ -287,7 +284,6 @@ pub fn constant_primary(s: Span) -> IResult<Span, ConstantPrimary> {
|
||||
ConstantPrimary::ConstantAssignmentPatternExpression(x)
|
||||
}),
|
||||
map(type_reference, |x| ConstantPrimary::TypeReference(x)),
|
||||
map(symbol("null"), |x| ConstantPrimary::Null(x)),
|
||||
))(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> {
|
||||
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)),
|
||||
primary_hierarchical,
|
||||
map(empty_unpacked_array_concatenation, |x| {
|
||||
@ -401,9 +400,6 @@ pub fn primary(s: Span) -> IResult<Span, Primary> {
|
||||
Primary::StreamingConcatenation(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)
|
||||
}
|
||||
|
||||
@ -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> {
|
||||
let (s, a) = opt(symbol("local::"))(s)?;
|
||||
let (s, a) = opt(local)(s)?;
|
||||
let (s, b) = opt(implicit_class_handle_or_class_scope)(s)?;
|
||||
Ok((
|
||||
s,
|
||||
ClassQualifier {
|
||||
nodes: (a.map(|x| Local { nodes: (x,) }), b),
|
||||
},
|
||||
))
|
||||
Ok((s, ClassQualifier { nodes: (a, b) }))
|
||||
}
|
||||
|
||||
pub fn range_expression(s: Span) -> IResult<Span, RangeExpression> {
|
||||
|
@ -1,3 +1,4 @@
|
||||
use crate::ast::*;
|
||||
use crate::parser::*;
|
||||
use nom::bytes::complete::*;
|
||||
use nom::combinator::*;
|
||||
@ -7,7 +8,7 @@ use nom::IResult;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct StringLiteral<'a> {
|
||||
pub nodes: (Span<'a>, Vec<WhiteSpace<'a>>),
|
||||
}
|
||||
|
@ -1,4 +1,3 @@
|
||||
use crate::ast::*;
|
||||
use crate::parser::*;
|
||||
use nom::combinator::*;
|
||||
use nom::sequence::*;
|
||||
|
@ -3,9 +3,9 @@ use crate::parser::*;
|
||||
use nom::branch::*;
|
||||
use nom::bytes::complete::*;
|
||||
use nom::combinator::*;
|
||||
use nom::error::*;
|
||||
use nom::multi::*;
|
||||
use nom::sequence::*;
|
||||
use nom::{Err, IResult};
|
||||
use nom::IResult;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
@ -13,122 +13,122 @@ const AZ_: &str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_";
|
||||
const AZ09_: &str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_";
|
||||
const AZ09_DOLLAR: &str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_$";
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct ArrayIdentifier<'a> {
|
||||
pub nodes: (Identifier<'a>,),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct BlockIdentifier<'a> {
|
||||
pub nodes: (Identifier<'a>,),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct BinIdentifier<'a> {
|
||||
pub nodes: (Identifier<'a>,),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct CIdentifier<'a> {
|
||||
pub nodes: (Span<'a>, Vec<WhiteSpace<'a>>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct CellIdentifier<'a> {
|
||||
pub nodes: (Identifier<'a>,),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct CheckerIdentifier<'a> {
|
||||
pub nodes: (Identifier<'a>,),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct ClassIdentifier<'a> {
|
||||
pub nodes: (Identifier<'a>,),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct ClassVariableIdentifier<'a> {
|
||||
pub nodes: (VariableIdentifier<'a>,),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct ClockingIdentifier<'a> {
|
||||
pub nodes: (Identifier<'a>,),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct ConfigIdentifier<'a> {
|
||||
pub nodes: (Identifier<'a>,),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct ConstIdentifier<'a> {
|
||||
pub nodes: (Identifier<'a>,),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct ConstraintIdentifier<'a> {
|
||||
pub nodes: (Identifier<'a>,),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct CovergroupIdentifier<'a> {
|
||||
pub nodes: (Identifier<'a>,),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct CovergroupVariableIdentifier<'a> {
|
||||
pub nodes: (VariableIdentifier<'a>,),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct CoverPointIdentifier<'a> {
|
||||
pub nodes: (Identifier<'a>,),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct CrossIdentifier<'a> {
|
||||
pub nodes: (Identifier<'a>,),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct DynamicArrayVariableIdentifier<'a> {
|
||||
pub nodes: (VariableIdentifier<'a>,),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct EnumIdentifier<'a> {
|
||||
pub nodes: (Identifier<'a>,),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct EscapedIdentifier<'a> {
|
||||
pub nodes: (Span<'a>, Vec<WhiteSpace<'a>>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct FormalIdentifier<'a> {
|
||||
pub nodes: (Identifier<'a>,),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct FormalPortIdentifier<'a> {
|
||||
pub nodes: (Identifier<'a>,),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct FunctionIdentifier<'a> {
|
||||
pub nodes: (Identifier<'a>,),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct GenerateBlockIdentifier<'a> {
|
||||
pub nodes: (Identifier<'a>,),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct GenvarIdentifier<'a> {
|
||||
pub nodes: (Identifier<'a>,),
|
||||
}
|
||||
@ -151,14 +151,16 @@ pub struct HierarchicalEventIdentifier<'a> {
|
||||
#[derive(Debug)]
|
||||
pub struct HierarchicalIdentifier<'a> {
|
||||
pub nodes: (
|
||||
Option<Root>,
|
||||
Vec<(Identifier<'a>, ConstantBitSelect<'a>)>,
|
||||
Option<Root<'a>>,
|
||||
Vec<(Identifier<'a>, ConstantBitSelect<'a>, Symbol<'a>)>,
|
||||
Identifier<'a>,
|
||||
),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Root {}
|
||||
#[derive(Debug, Node)]
|
||||
pub struct Root<'a> {
|
||||
pub nodes: (Symbol<'a>, Symbol<'a>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct HierarchicalNetIdentifier<'a> {
|
||||
@ -195,134 +197,144 @@ pub struct HierarchicalVariableIdentifier<'a> {
|
||||
pub nodes: (HierarchicalIdentifier<'a>,),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub enum Identifier<'a> {
|
||||
SimpleIdentifier(SimpleIdentifier<'a>),
|
||||
EscapedIdentifier(EscapedIdentifier<'a>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct IndexVariableIdentifier<'a> {
|
||||
pub nodes: (Identifier<'a>,),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct InterfaceIdentifier<'a> {
|
||||
pub nodes: (Identifier<'a>,),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct InterfaceInstanceIdentifier<'a> {
|
||||
pub nodes: (Identifier<'a>,),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct InoutPortIdentifier<'a> {
|
||||
pub nodes: (Identifier<'a>,),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct InputPortIdentifier<'a> {
|
||||
pub nodes: (Identifier<'a>,),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct InstanceIdentifier<'a> {
|
||||
pub nodes: (Identifier<'a>,),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct LibraryIdentifier<'a> {
|
||||
pub nodes: (Identifier<'a>,),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct MemberIdentifier<'a> {
|
||||
pub nodes: (Identifier<'a>,),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct MethodIdentifier<'a> {
|
||||
pub nodes: (Identifier<'a>,),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct ModportIdentifier<'a> {
|
||||
pub nodes: (Identifier<'a>,),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct ModuleIdentifier<'a> {
|
||||
pub nodes: (Identifier<'a>,),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct NetIdentifier<'a> {
|
||||
pub nodes: (Identifier<'a>,),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct NetTypeIdentifier<'a> {
|
||||
pub nodes: (Identifier<'a>,),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct OutputPortIdentifier<'a> {
|
||||
pub nodes: (Identifier<'a>,),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct PackageIdentifier<'a> {
|
||||
pub nodes: (Identifier<'a>,),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub enum PackageScope<'a> {
|
||||
PackageIdentifier(PackageIdentifier<'a>),
|
||||
Unit,
|
||||
Package(PackageScopePackage<'a>),
|
||||
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 nodes: (Identifier<'a>,),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct PortIdentifier<'a> {
|
||||
pub nodes: (Identifier<'a>,),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct ProductionIdentifier<'a> {
|
||||
pub nodes: (Identifier<'a>,),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct ProgramIdentifier<'a> {
|
||||
pub nodes: (Identifier<'a>,),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct PropertyIdentifier<'a> {
|
||||
pub nodes: (Identifier<'a>,),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct PsClassIdentifier<'a> {
|
||||
pub nodes: (Option<PackageScope<'a>>, ClassIdentifier<'a>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct PsCovergroupIdentifier<'a> {
|
||||
pub nodes: (Option<PackageScope<'a>>, CovergroupIdentifier<'a>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct PsCheckerIdentifier<'a> {
|
||||
pub nodes: (Option<PackageScope<'a>>, CheckerIdentifier<'a>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct PsIdentifier<'a> {
|
||||
pub nodes: (Option<PackageScope<'a>>, Identifier<'a>),
|
||||
}
|
||||
@ -338,10 +350,10 @@ pub struct PsOrHierarchicalArrayIdentifier<'a> {
|
||||
#[derive(Debug)]
|
||||
pub enum PsOrHierarchicalNetIdentifier<'a> {
|
||||
PackageScope(PsOrHierarchicalNetIdentifierPackageScope<'a>),
|
||||
Hierarchical(PsOrHierarchicalNetIdentifierHierarchical<'a>),
|
||||
HierarchicalNetIdentifier(HierarchicalNetIdentifier<'a>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct PsOrHierarchicalNetIdentifierPackageScope<'a> {
|
||||
pub nodes: (Option<PackageScope<'a>>, NetIdentifier<'a>),
|
||||
}
|
||||
@ -354,7 +366,7 @@ pub struct PsOrHierarchicalNetIdentifierHierarchical<'a> {
|
||||
#[derive(Debug)]
|
||||
pub enum PsOrHierarchicalPropertyIdentifier<'a> {
|
||||
PackageScope(PsOrHierarchicalPropertyIdentifierPackageScope<'a>),
|
||||
Hierarchical(PsOrHierarchicalPropertyIdentifierHierarchical<'a>),
|
||||
HierarchicalPropertyIdentifier(HierarchicalPropertyIdentifier<'a>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@ -370,7 +382,7 @@ pub struct PsOrHierarchicalPropertyIdentifierHierarchical<'a> {
|
||||
#[derive(Debug)]
|
||||
pub enum PsOrHierarchicalSequenceIdentifier<'a> {
|
||||
PackageScope(PsOrHierarchicalSequenceIdentifierPackageScope<'a>),
|
||||
Hierarchical(PsOrHierarchicalSequenceIdentifierHierarchical<'a>),
|
||||
HierarchicalSequenceIdentifier(HierarchicalSequenceIdentifier<'a>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@ -386,7 +398,7 @@ pub struct PsOrHierarchicalSequenceIdentifierHierarchical<'a> {
|
||||
#[derive(Debug)]
|
||||
pub enum PsOrHierarchicalTfIdentifier<'a> {
|
||||
PackageScope(PsOrHierarchicalTfIdentifierPackageScope<'a>),
|
||||
Hierarchical(PsOrHierarchicalTfIdentifierHierarchical<'a>),
|
||||
HierarchicalTfIdentifier(HierarchicalTfIdentifier<'a>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@ -416,7 +428,11 @@ pub struct PsParameterIdentifierScope<'a> {
|
||||
#[derive(Debug)]
|
||||
pub struct PsParameterIdentifierGenerate<'a> {
|
||||
pub nodes: (
|
||||
Vec<(GenerateBlockIdentifier<'a>, Option<ConstantExpression<'a>>)>,
|
||||
Vec<(
|
||||
GenerateBlockIdentifier<'a>,
|
||||
Option<Bracket<'a, ConstantExpression<'a>>>,
|
||||
Symbol<'a>,
|
||||
)>,
|
||||
ParameterIdentifier<'a>,
|
||||
),
|
||||
}
|
||||
@ -431,67 +447,72 @@ pub struct PsTypeIdentifier<'a> {
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum LocalOrPackageScopeOrClassScope<'a> {
|
||||
Local,
|
||||
Local(Local<'a>),
|
||||
PackageScope(PackageScope<'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 nodes: (Identifier<'a>,),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct SignalIdentifier<'a> {
|
||||
pub nodes: (Identifier<'a>,),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct SimpleIdentifier<'a> {
|
||||
pub nodes: (Span<'a>, Vec<WhiteSpace<'a>>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct SpecparamIdentifier<'a> {
|
||||
pub nodes: (Identifier<'a>,),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct SystemTfIdentifier<'a> {
|
||||
pub nodes: (Span<'a>, Vec<WhiteSpace<'a>>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct TaskIdentifier<'a> {
|
||||
pub nodes: (Identifier<'a>,),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct TfIdentifier<'a> {
|
||||
pub nodes: (Identifier<'a>,),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct TerminalIdentifier<'a> {
|
||||
pub nodes: (Identifier<'a>,),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct TopmoduleIdentifier<'a> {
|
||||
pub nodes: (Identifier<'a>,),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct TypeIdentifier<'a> {
|
||||
pub nodes: (Identifier<'a>,),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct UdpIdentifier<'a> {
|
||||
pub nodes: (Identifier<'a>,),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct VariableIdentifier<'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> {
|
||||
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> {
|
||||
@ -800,7 +830,22 @@ pub fn package_identifier(s: Span) -> IResult<Span, PackageIdentifier> {
|
||||
}
|
||||
|
||||
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> {
|
||||
@ -829,53 +874,162 @@ pub fn property_identifier(s: Span) -> IResult<Span, PropertyIdentifier> {
|
||||
}
|
||||
|
||||
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> {
|
||||
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> {
|
||||
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> {
|
||||
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(
|
||||
s: Span,
|
||||
) -> 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> {
|
||||
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(
|
||||
s: Span,
|
||||
) -> 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(
|
||||
s: Span,
|
||||
) -> 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> {
|
||||
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> {
|
||||
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> {
|
||||
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> {
|
||||
@ -1005,6 +1159,26 @@ pub fn package_scope_or_class_scope(s: Span) -> IResult<Span, PackageScopeOrClas
|
||||
))(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)]
|
||||
|
@ -1,3 +1,4 @@
|
||||
use crate::ast::*;
|
||||
use crate::parser::*;
|
||||
//use nom::branch::*;
|
||||
//use nom::combinator::*;
|
||||
@ -6,7 +7,7 @@ use nom::{Err, IResult};
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct GateInstantiation<'a> {
|
||||
pub nodes: (Identifier<'a>,),
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
use crate::ast::*;
|
||||
use crate::parser::*;
|
||||
//use nom::branch::*;
|
||||
//use nom::combinator::*;
|
||||
@ -6,7 +7,7 @@ use nom::{Err, IResult};
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct SpecifyBlock<'a> {
|
||||
pub nodes: (Identifier<'a>,),
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
use crate::ast::*;
|
||||
use crate::parser::*;
|
||||
//use nom::branch::*;
|
||||
//use nom::combinator::*;
|
||||
@ -16,26 +17,26 @@ pub struct SpecifyOutputTerminalDescriptor<'a> {
|
||||
pub nodes: (OutputIdentifier<'a>, Option<ConstantRangeExpression<'a>>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub enum InputIdentifier<'a> {
|
||||
InputPortIdentifier(InputPortIdentifier<'a>),
|
||||
InoutPortIdentifier(InoutPortIdentifier<'a>),
|
||||
Interface(InputIdentifierInterface<'a>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct InputIdentifierInterface<'a> {
|
||||
pub nodes: (InterfaceIdentifier<'a>, PortIdentifier<'a>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub enum OutputIdentifier<'a> {
|
||||
OutputPortIdentifier(OutputPortIdentifier<'a>),
|
||||
InoutPortIdentifier(InoutPortIdentifier<'a>),
|
||||
Interface(OutputIdentifierInterface<'a>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct OutputIdentifierInterface<'a> {
|
||||
pub nodes: (InterfaceIdentifier<'a>, PortIdentifier<'a>),
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
use crate::ast::*;
|
||||
use crate::parser::*;
|
||||
//use nom::branch::*;
|
||||
//use nom::combinator::*;
|
||||
@ -6,7 +7,7 @@ use nom::{Err, IResult};
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct EdgeIdentifier<'a> {
|
||||
pub nodes: (Identifier<'a>,),
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
use crate::ast::*;
|
||||
use crate::parser::*;
|
||||
//use nom::branch::*;
|
||||
//use nom::combinator::*;
|
||||
@ -6,7 +7,7 @@ use nom::{Err, IResult};
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct UdpDeclaration<'a> {
|
||||
pub nodes: (Identifier<'a>,),
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
use crate::ast::*;
|
||||
use crate::parser::*;
|
||||
//use nom::branch::*;
|
||||
//use nom::combinator::*;
|
||||
@ -6,7 +7,7 @@ use nom::{Err, IResult};
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Node)]
|
||||
pub struct UdpInstantiation<'a> {
|
||||
pub nodes: (Identifier<'a>,),
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user