Add paren/brace/bracket

This commit is contained in:
dalance 2019-07-06 19:18:04 +09:00
parent a96769c02e
commit 616bd9d98f
10 changed files with 126 additions and 167 deletions

View File

@ -145,13 +145,9 @@ pub fn clocking_event(s: &str) -> IResult<&str, ClockingEvent> {
map(preceded(symbol("@"), identifier), |x| { map(preceded(symbol("@"), identifier), |x| {
ClockingEvent::Identifier(x) ClockingEvent::Identifier(x)
}), }),
map( map(preceded(symbol("@"), paren(event_expression)), |x| {
preceded( ClockingEvent::Expression(x)
symbol("@"), }),
delimited(symbol("("), event_expression, symbol(")")),
),
|x| ClockingEvent::Expression(x),
),
))(s) ))(s)
} }
@ -310,13 +306,9 @@ pub fn cycle_delay(s: &str) -> IResult<&str, CycleDelay> {
map(preceded(symbol("##"), identifier), |x| { map(preceded(symbol("##"), identifier), |x| {
CycleDelay::Identifier(x) CycleDelay::Identifier(x)
}), }),
map( map(preceded(symbol("##"), paren(expression)), |x| {
preceded( CycleDelay::Expression(x)
symbol("##"), }),
delimited(symbol("("), expression, symbol(")")),
),
|x| CycleDelay::Expression(x),
),
))(s) ))(s)
} }

View File

@ -83,22 +83,14 @@ pub fn pattern(s: &str) -> IResult<&str, Pattern> {
|x| Pattern::Tagged(Box::new(x)), |x| Pattern::Tagged(Box::new(x)),
), ),
map( map(
delimited( apostrophe_brace(separated_nonempty_list(symbol(","), pattern)),
symbol("'{"),
separated_nonempty_list(symbol(","), pattern),
symbol("}"),
),
|x| Pattern::Pattern(Box::new(x)), |x| Pattern::Pattern(Box::new(x)),
), ),
map( map(
delimited( apostrophe_brace(separated_nonempty_list(
symbol("'{"), symbol(","),
separated_nonempty_list( pair(member_identifier, preceded(symbol(":"), pattern)),
symbol(","), )),
pair(member_identifier, preceded(symbol(":"), pattern)),
),
symbol("}"),
),
|x| Pattern::MemberPattern(Box::new(x)), |x| Pattern::MemberPattern(Box::new(x)),
), ),
))(s) ))(s)
@ -107,48 +99,28 @@ pub fn pattern(s: &str) -> IResult<&str, Pattern> {
pub fn assignment_pattern(s: &str) -> IResult<&str, AssignmentPattern> { pub fn assignment_pattern(s: &str) -> IResult<&str, AssignmentPattern> {
alt(( alt((
map( map(
delimited( apostrophe_brace(separated_nonempty_list(symbol(","), expression)),
symbol("'{"),
separated_nonempty_list(symbol(","), expression),
symbol("}"),
),
|x| AssignmentPattern::Expression(x), |x| AssignmentPattern::Expression(x),
), ),
map( map(
delimited( apostrophe_brace(separated_nonempty_list(
symbol("'{"), symbol(","),
separated_nonempty_list( pair(structure_pattern_key, preceded(symbol(":"), expression)),
symbol(","), )),
pair(structure_pattern_key, preceded(symbol(":"), expression)),
),
symbol("}"),
),
|x| AssignmentPattern::StructurePatternKey(x), |x| AssignmentPattern::StructurePatternKey(x),
), ),
map( map(
delimited( apostrophe_brace(separated_nonempty_list(
symbol("'{"), symbol(","),
separated_nonempty_list( pair(array_pattern_key, preceded(symbol(":"), expression)),
symbol(","), )),
pair(array_pattern_key, preceded(symbol(":"), expression)),
),
symbol("}"),
),
|x| AssignmentPattern::ArrayPatternKey(x), |x| AssignmentPattern::ArrayPatternKey(x),
), ),
map( map(
delimited( apostrophe_brace(pair(
symbol("'{"), constant_expression,
pair( brace(separated_nonempty_list(symbol(","), expression)),
constant_expression, )),
delimited(
symbol("{"),
separated_nonempty_list(symbol(","), expression),
symbol("}"),
),
),
symbol("}"),
),
|x| AssignmentPattern::ConstantExpression(x), |x| AssignmentPattern::ConstantExpression(x),
), ),
))(s) ))(s)
@ -215,22 +187,14 @@ pub fn constant_assignment_pattern_expression(
} }
pub fn assignment_pattern_net_lvalue(s: &str) -> IResult<&str, AssignmentPatternNetLvalue> { pub fn assignment_pattern_net_lvalue(s: &str) -> IResult<&str, AssignmentPatternNetLvalue> {
let (s, x) = delimited( let (s, x) = apostrophe_brace(separated_nonempty_list(symbol(","), net_lvalue))(s)?;
symbol("'{"),
separated_nonempty_list(symbol(","), net_lvalue),
symbol("}"),
)(s)?;
Ok((s, AssignmentPatternNetLvalue { lvalue: x })) Ok((s, AssignmentPatternNetLvalue { lvalue: x }))
} }
pub fn assignment_pattern_variable_lvalue( pub fn assignment_pattern_variable_lvalue(
s: &str, s: &str,
) -> IResult<&str, AssignmentPatternVariableLvalue> { ) -> IResult<&str, AssignmentPatternVariableLvalue> {
let (s, x) = delimited( let (s, x) = apostrophe_brace(separated_nonempty_list(symbol(","), variable_lvalue))(s)?;
symbol("'{"),
separated_nonempty_list(symbol(","), variable_lvalue),
symbol("}"),
)(s)?;
Ok((s, AssignmentPatternVariableLvalue { lvalue: x })) Ok((s, AssignmentPatternVariableLvalue { lvalue: x }))
} }

View File

@ -119,7 +119,7 @@ pub fn randsequence_statement(s: &str) -> IResult<&str, RandsequenceStatement> {
pub fn production(s: &str) -> IResult<&str, Production> { pub fn production(s: &str) -> IResult<&str, Production> {
let (s, x) = opt(data_type_or_void)(s)?; let (s, x) = opt(data_type_or_void)(s)?;
let (s, y) = production_identifier(s)?; let (s, y) = production_identifier(s)?;
let (s, z) = opt(delimited(symbol("("), tf_port_list, symbol(")")))(s)?; let (s, z) = opt(paren(tf_port_list))(s)?;
let (s, _) = symbol(":")(s)?; let (s, _) = symbol(":")(s)?;
let (s, v) = separated_nonempty_list(symbol("|"), rs_rule)(s)?; let (s, v) = separated_nonempty_list(symbol("|"), rs_rule)(s)?;
let (s, _) = symbol(";")(s)?; let (s, _) = symbol(";")(s)?;
@ -168,7 +168,7 @@ pub fn rs_production_list_prod(s: &str) -> IResult<&str, RsProductionList> {
pub fn rs_production_list_join(s: &str) -> IResult<&str, RsProductionList> { pub fn rs_production_list_join(s: &str) -> IResult<&str, RsProductionList> {
let (s, _) = symbol("rand")(s)?; let (s, _) = symbol("rand")(s)?;
let (s, _) = symbol("join")(s)?; let (s, _) = symbol("join")(s)?;
let (s, x) = opt(delimited(symbol("("), expression, symbol(")")))(s)?; let (s, x) = opt(paren(expression))(s)?;
let (s, y) = production_item(s)?; let (s, y) = production_item(s)?;
let (s, z) = many1(production_item)(s)?; let (s, z) = many1(production_item)(s)?;
@ -183,9 +183,7 @@ pub fn weight_specification(s: &str) -> IResult<&str, WeightSpecification> {
alt(( alt((
map(integral_number, |x| WeightSpecification::Number(x)), map(integral_number, |x| WeightSpecification::Number(x)),
map(ps_identifier, |x| WeightSpecification::Identifier(x)), map(ps_identifier, |x| WeightSpecification::Identifier(x)),
map(delimited(symbol("("), expression, symbol(")")), |x| { map(paren(expression), |x| WeightSpecification::Expression(x)),
WeightSpecification::Expression(x)
}),
))(s) ))(s)
} }
@ -215,7 +213,7 @@ pub fn rs_prod(s: &str) -> IResult<&str, RsProd> {
pub fn production_item(s: &str) -> IResult<&str, ProductionItem> { pub fn production_item(s: &str) -> IResult<&str, ProductionItem> {
let (s, x) = production_identifier(s)?; let (s, x) = production_identifier(s)?;
let (s, y) = opt(delimited(symbol("("), list_of_arguments, symbol(")")))(s)?; let (s, y) = opt(paren(list_of_arguments))(s)?;
Ok(( Ok((
s, s,
ProductionItem { ProductionItem {
@ -227,7 +225,7 @@ pub fn production_item(s: &str) -> IResult<&str, ProductionItem> {
pub fn rs_if_else(s: &str) -> IResult<&str, RsIfElse> { pub fn rs_if_else(s: &str) -> IResult<&str, RsIfElse> {
let (s, _) = symbol("if")(s)?; let (s, _) = symbol("if")(s)?;
let (s, x) = delimited(symbol("("), expression, symbol(")"))(s)?; let (s, x) = paren(expression)(s)?;
let (s, y) = production_item(s)?; let (s, y) = production_item(s)?;
let (s, z) = opt(preceded(symbol("else"), production_item))(s)?; let (s, z) = opt(preceded(symbol("else"), production_item))(s)?;
Ok(( Ok((
@ -242,7 +240,7 @@ pub fn rs_if_else(s: &str) -> IResult<&str, RsIfElse> {
pub fn rs_repeat(s: &str) -> IResult<&str, RsRepeat> { pub fn rs_repeat(s: &str) -> IResult<&str, RsRepeat> {
let (s, _) = symbol("repeat")(s)?; let (s, _) = symbol("repeat")(s)?;
let (s, x) = delimited(symbol("("), expression, symbol(")"))(s)?; let (s, x) = paren(expression)(s)?;
let (s, y) = production_item(s)?; let (s, y) = production_item(s)?;
Ok(( Ok((
s, s,
@ -255,7 +253,7 @@ pub fn rs_repeat(s: &str) -> IResult<&str, RsRepeat> {
pub fn rs_case(s: &str) -> IResult<&str, RsCase> { pub fn rs_case(s: &str) -> IResult<&str, RsCase> {
let (s, _) = symbol("case")(s)?; let (s, _) = symbol("case")(s)?;
let (s, x) = delimited(symbol("("), case_expression, symbol(")"))(s)?; let (s, x) = paren(case_expression)(s)?;
let (s, y) = many1(rs_case_item)(s)?; let (s, y) = many1(rs_case_item)(s)?;
Ok(( Ok((
s, s,

View File

@ -320,7 +320,7 @@ pub fn wait_statement(s: &str) -> IResult<&str, WaitStatement> {
pub fn wait_statement_wait(s: &str) -> IResult<&str, WaitStatement> { pub fn wait_statement_wait(s: &str) -> IResult<&str, WaitStatement> {
let (s, _) = symbol("wait")(s)?; let (s, _) = symbol("wait")(s)?;
let (s, x) = delimited(symbol("("), expression, symbol(")"))(s)?; let (s, x) = paren(expression)(s)?;
let (s, y) = statement_or_null(s)?; let (s, y) = statement_or_null(s)?;
Ok(( Ok((
s, s,
@ -340,11 +340,10 @@ pub fn wait_statement_fork(s: &str) -> IResult<&str, WaitStatement> {
pub fn wait_statement_order(s: &str) -> IResult<&str, WaitStatement> { pub fn wait_statement_order(s: &str) -> IResult<&str, WaitStatement> {
let (s, _) = symbol("wait_order")(s)?; let (s, _) = symbol("wait_order")(s)?;
let (s, x) = delimited( let (s, x) = paren(separated_nonempty_list(
symbol("("), symbol(","),
separated_nonempty_list(symbol(","), hierarchical_identifier), hierarchical_identifier,
symbol(")"), ))(s)?;
)(s)?;
let (s, y) = action_block(s)?; let (s, y) = action_block(s)?;
Ok(( Ok((
s, s,

View File

@ -74,16 +74,12 @@ pub struct ArrayRangeExpression<'a> {
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
pub fn concatenation(s: &str) -> IResult<&str, Concatenation> { pub fn concatenation(s: &str) -> IResult<&str, Concatenation> {
let (s, _) = symbol("{")(s)?; let (s, x) = brace(separated_nonempty_list(symbol(","), expression))(s)?;
let (s, x) = separated_nonempty_list(symbol(","), expression)(s)?;
let (s, _) = symbol("}")(s)?;
Ok((s, Concatenation { expression: x })) Ok((s, Concatenation { expression: x }))
} }
pub fn constant_concatenation(s: &str) -> IResult<&str, ConstantConcatenation> { pub fn constant_concatenation(s: &str) -> IResult<&str, ConstantConcatenation> {
let (s, _) = symbol("{")(s)?; let (s, x) = brace(separated_nonempty_list(symbol(","), constant_expression))(s)?;
let (s, x) = separated_nonempty_list(symbol(","), constant_expression)(s)?;
let (s, _) = symbol("}")(s)?;
Ok((s, ConstantConcatenation { expression: x })) Ok((s, ConstantConcatenation { expression: x }))
} }
@ -102,9 +98,7 @@ pub fn constant_multiple_concatenation(s: &str) -> IResult<&str, ConstantMultipl
} }
pub fn module_path_concatenation(s: &str) -> IResult<&str, ModulePathConcatenation> { pub fn module_path_concatenation(s: &str) -> IResult<&str, ModulePathConcatenation> {
let (s, _) = symbol("{")(s)?; let (s, x) = brace(separated_nonempty_list(symbol(","), module_path_expression))(s)?;
let (s, x) = separated_nonempty_list(symbol(","), module_path_expression)(s)?;
let (s, _) = symbol("}")(s)?;
Ok((s, ModulePathConcatenation { expression: x })) Ok((s, ModulePathConcatenation { expression: x }))
} }
@ -166,18 +160,13 @@ pub fn slice_size(s: &str) -> IResult<&str, SliceSize> {
} }
pub fn stream_concatenation(s: &str) -> IResult<&str, StreamConcatenation> { pub fn stream_concatenation(s: &str) -> IResult<&str, StreamConcatenation> {
let (s, _) = symbol("{")(s)?; let (s, x) = brace(separated_nonempty_list(symbol(","), stream_expression))(s)?;
let (s, x) = separated_nonempty_list(symbol(","), stream_expression)(s)?;
let (s, _) = symbol("}")(s)?;
Ok((s, StreamConcatenation { expression: x })) Ok((s, StreamConcatenation { expression: x }))
} }
pub fn stream_expression(s: &str) -> IResult<&str, StreamExpression> { pub fn stream_expression(s: &str) -> IResult<&str, StreamExpression> {
let (s, x) = expression(s)?; let (s, x) = expression(s)?;
let (s, y) = opt(preceded( let (s, y) = opt(preceded(symbol("with"), bracket(array_range_expression)))(s)?;
symbol("with"),
delimited(symbol("["), array_range_expression, symbol("]")),
))(s)?;
Ok(( Ok((
s, s,
StreamExpression { StreamExpression {

View File

@ -2,7 +2,6 @@ use crate::parser::*;
use nom::branch::*; use nom::branch::*;
use nom::combinator::*; use nom::combinator::*;
use nom::multi::*; use nom::multi::*;
use nom::sequence::*;
use nom::IResult; use nom::IResult;
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -387,10 +386,9 @@ pub fn expression(s: &str) -> IResult<&str, Expression> {
map(primary, |x| Expression::Nullary(Box::new(x))), map(primary, |x| Expression::Nullary(Box::new(x))),
expression_unary, expression_unary,
map(inc_or_dec_expression, |x| Expression::IncOrDec(Box::new(x))), map(inc_or_dec_expression, |x| Expression::IncOrDec(Box::new(x))),
map( map(paren(operator_assignment), |x| {
delimited(symbol("("), operator_assignment, symbol(")")), Expression::Assignment(Box::new(x))
|x| Expression::Assignment(Box::new(x)), }),
),
expression_binary, expression_binary,
map(conditional_expression, |x| { map(conditional_expression, |x| {
Expression::Conditional(Box::new(x)) Expression::Conditional(Box::new(x))
@ -448,7 +446,7 @@ pub fn tagged_union_expression(s: &str) -> IResult<&str, TaggedUnionExpression>
pub fn inside_expression(s: &str) -> IResult<&str, InsideExpression> { pub fn inside_expression(s: &str) -> IResult<&str, InsideExpression> {
let (s, x) = expression(s)?; let (s, x) = expression(s)?;
let (s, _) = symbol("inside")(s)?; let (s, _) = symbol("inside")(s)?;
let (s, y) = delimited(symbol("{"), open_range_list, symbol("}"))(s)?; let (s, y) = brace(open_range_list)(s)?;
Ok(( Ok((
s, s,
InsideExpression { InsideExpression {

View File

@ -220,10 +220,9 @@ pub fn constant_primary(s: &str) -> IResult<&str, ConstantPrimary> {
map(constant_let_expression, |x| { map(constant_let_expression, |x| {
ConstantPrimary::LetExpression(x) ConstantPrimary::LetExpression(x)
}), }),
map( map(paren(constant_mintypmax_expression), |x| {
delimited(symbol("("), constant_mintypmax_expression, symbol(")")), ConstantPrimary::MintypmaxExpression(x)
|x| ConstantPrimary::MintypmaxExpression(x), }),
),
map(constant_cast, |x| ConstantPrimary::Cast(x)), map(constant_cast, |x| ConstantPrimary::Cast(x)),
map(constant_assignment_pattern_expression, |x| { map(constant_assignment_pattern_expression, |x| {
ConstantPrimary::AssignmentPatternExpression(x) ConstantPrimary::AssignmentPatternExpression(x)
@ -246,11 +245,7 @@ pub fn constant_primary_ps_parameter(s: &str) -> IResult<&str, ConstantPrimary>
pub fn constant_primary_specparam(s: &str) -> IResult<&str, ConstantPrimary> { pub fn constant_primary_specparam(s: &str) -> IResult<&str, ConstantPrimary> {
let (s, x) = specparam_identifier(s)?; let (s, x) = specparam_identifier(s)?;
let (s, y) = opt(delimited( let (s, y) = opt(bracket(constant_range_expression))(s)?;
symbol("["),
constant_range_expression,
symbol("]"),
))(s)?;
Ok(( Ok((
s, s,
ConstantPrimary::Specparam(ConstantPrimarySpecparam { ConstantPrimary::Specparam(ConstantPrimarySpecparam {
@ -286,11 +281,7 @@ pub fn constant_primary_enum(s: &str) -> IResult<&str, ConstantPrimary> {
pub fn constant_primary_concatenation(s: &str) -> IResult<&str, ConstantPrimary> { pub fn constant_primary_concatenation(s: &str) -> IResult<&str, ConstantPrimary> {
let (s, x) = constant_concatenation(s)?; let (s, x) = constant_concatenation(s)?;
let (s, y) = opt(delimited( let (s, y) = opt(bracket(constant_range_expression))(s)?;
symbol("["),
constant_range_expression,
symbol("]"),
))(s)?;
Ok(( Ok((
s, s,
ConstantPrimary::Concatenation(ConstantPrimaryConcatenation { ConstantPrimary::Concatenation(ConstantPrimaryConcatenation {
@ -302,11 +293,7 @@ pub fn constant_primary_concatenation(s: &str) -> IResult<&str, ConstantPrimary>
pub fn constant_primary_multiple_concatenation(s: &str) -> IResult<&str, ConstantPrimary> { pub fn constant_primary_multiple_concatenation(s: &str) -> IResult<&str, ConstantPrimary> {
let (s, x) = constant_multiple_concatenation(s)?; let (s, x) = constant_multiple_concatenation(s)?;
let (s, y) = opt(delimited( let (s, y) = opt(bracket(constant_range_expression))(s)?;
symbol("["),
constant_range_expression,
symbol("]"),
))(s)?;
Ok(( Ok((
s, s,
ConstantPrimary::MultipleConcatenation(ConstantPrimaryMultipleConcatenation { ConstantPrimary::MultipleConcatenation(ConstantPrimaryMultipleConcatenation {
@ -317,7 +304,7 @@ pub fn constant_primary_multiple_concatenation(s: &str) -> IResult<&str, Constan
} }
pub fn constant_primary_mintypmax_expression(s: &str) -> IResult<&str, ConstantPrimary> { pub fn constant_primary_mintypmax_expression(s: &str) -> IResult<&str, ConstantPrimary> {
let (s, x) = delimited(symbol("("), constant_mintypmax_expression, symbol(")"))(s)?; let (s, x) = paren(constant_mintypmax_expression)(s)?;
Ok((s, ConstantPrimary::MintypmaxExpression(x))) Ok((s, ConstantPrimary::MintypmaxExpression(x)))
} }
@ -334,10 +321,9 @@ pub fn module_path_primary(s: &str) -> IResult<&str, ModulePathPrimary> {
map(function_subroutine_call, |x| { map(function_subroutine_call, |x| {
ModulePathPrimary::FunctionSubroutineCall(x) ModulePathPrimary::FunctionSubroutineCall(x)
}), }),
map( map(paren(module_path_mintypmax_expression), |x| {
delimited(symbol("("), module_path_mintypmax_expression, symbol(")")), ModulePathPrimary::ModulePathMintypmaxExpression(x)
|x| ModulePathPrimary::ModulePathMintypmaxExpression(x), }),
),
))(s) ))(s)
} }
@ -353,10 +339,9 @@ pub fn primary(s: &str) -> IResult<&str, Primary> {
Primary::FunctionSubroutineCall(x) Primary::FunctionSubroutineCall(x)
}), }),
map(let_expression, |x| Primary::LetExpression(x)), map(let_expression, |x| Primary::LetExpression(x)),
map( map(paren(mintypmax_expression), |x| {
delimited(symbol("("), mintypmax_expression, symbol(")")), Primary::MintypmaxExpression(x)
|x| Primary::MintypmaxExpression(x), }),
),
map(cast, |x| Primary::Cast(x)), map(cast, |x| Primary::Cast(x)),
map(assignment_pattern_expression, |x| { map(assignment_pattern_expression, |x| {
Primary::AssignmentPatternExpression(x) Primary::AssignmentPatternExpression(x)
@ -509,7 +494,7 @@ pub fn implicit_class_handle(s: &str) -> IResult<&str, Scope> {
} }
pub fn bit_select(s: &str) -> IResult<&str, Vec<Expression>> { pub fn bit_select(s: &str) -> IResult<&str, Vec<Expression>> {
many0(delimited(symbol("["), expression, symbol("]")))(s) many0(bracket(expression))(s)
} }
pub fn select(s: &str) -> IResult<&str, Select> { pub fn select(s: &str) -> IResult<&str, Select> {
@ -518,7 +503,7 @@ pub fn select(s: &str) -> IResult<&str, Select> {
preceded(symbol("."), member_identifier), preceded(symbol("."), member_identifier),
))(s)?; ))(s)?;
let (s, y) = bit_select(s)?; let (s, y) = bit_select(s)?;
let (s, z) = opt(delimited(symbol("["), part_select_range, symbol("]")))(s)?; let (s, z) = opt(bracket(part_select_range))(s)?;
let x = if let Some((x, y)) = x { let x = if let Some((x, y)) = x {
Some(SelectMember { Some(SelectMember {
@ -566,7 +551,7 @@ pub fn nonrange_select(s: &str) -> IResult<&str, Select> {
} }
pub fn constant_bit_select(s: &str) -> IResult<&str, Vec<ConstantExpression>> { pub fn constant_bit_select(s: &str) -> IResult<&str, Vec<ConstantExpression>> {
many0(delimited(symbol("["), constant_expression, symbol("]")))(s) many0(bracket(constant_expression))(s)
} }
pub fn constant_select(s: &str) -> IResult<&str, ConstantSelect> { pub fn constant_select(s: &str) -> IResult<&str, ConstantSelect> {
@ -575,11 +560,7 @@ pub fn constant_select(s: &str) -> IResult<&str, ConstantSelect> {
preceded(symbol("."), member_identifier), preceded(symbol("."), member_identifier),
))(s)?; ))(s)?;
let (s, y) = constant_bit_select(s)?; let (s, y) = constant_bit_select(s)?;
let (s, z) = opt(delimited( let (s, z) = opt(bracket(constant_part_select_range))(s)?;
symbol("["),
constant_part_select_range,
symbol("]"),
))(s)?;
let x = if let Some((x, y)) = x { let x = if let Some((x, y)) = x {
Some(SelectMember { Some(SelectMember {
@ -603,7 +584,7 @@ pub fn constant_select(s: &str) -> IResult<&str, ConstantSelect> {
pub fn constant_cast(s: &str) -> IResult<&str, ConstantCast> { pub fn constant_cast(s: &str) -> IResult<&str, ConstantCast> {
let (s, x) = casting_type(s)?; let (s, x) = casting_type(s)?;
let (s, _) = symbol("'")(s)?; let (s, _) = symbol("'")(s)?;
let (s, y) = delimited(symbol("("), constant_expression, symbol(")"))(s)?; let (s, y) = paren(constant_expression)(s)?;
Ok(( Ok((
s, s,
ConstantCast { ConstantCast {
@ -620,7 +601,7 @@ pub fn constant_let_expression(s: &str) -> IResult<&str, LetExpression> {
pub fn cast(s: &str) -> IResult<&str, Cast> { pub fn cast(s: &str) -> IResult<&str, Cast> {
let (s, x) = casting_type(s)?; let (s, x) = casting_type(s)?;
let (s, _) = symbol("'")(s)?; let (s, _) = symbol("'")(s)?;
let (s, y) = delimited(symbol("("), expression, symbol(")"))(s)?; let (s, y) = paren(expression)(s)?;
Ok(( Ok((
s, s,
Cast { Cast {

View File

@ -98,7 +98,7 @@ pub fn constant_function_call(s: &str) -> IResult<&str, SubroutineCall> {
pub fn tf_call(s: &str) -> IResult<&str, TfCall> { pub fn tf_call(s: &str) -> IResult<&str, TfCall> {
let (s, x) = ps_or_hierarchical_tf_identifier(s)?; let (s, x) = ps_or_hierarchical_tf_identifier(s)?;
let (s, y) = many0(attribute_instance)(s)?; let (s, y) = many0(attribute_instance)(s)?;
let (s, z) = opt(delimited(symbol("("), list_of_arguments, symbol(")")))(s)?; let (s, z) = opt(paren(list_of_arguments))(s)?;
Ok(( Ok((
s, s,
TfCall { TfCall {
@ -119,7 +119,7 @@ pub fn system_tf_call(s: &str) -> IResult<&str, SystemTfCall> {
pub fn system_tf_call_list_of_arguments(s: &str) -> IResult<&str, SystemTfCall> { pub fn system_tf_call_list_of_arguments(s: &str) -> IResult<&str, SystemTfCall> {
let (s, x) = system_tf_identifier(s)?; let (s, x) = system_tf_identifier(s)?;
let (s, y) = opt(delimited(symbol("("), list_of_arguments, symbol(")")))(s)?; let (s, y) = opt(paren(list_of_arguments))(s)?;
Ok(( Ok((
s, s,
SystemTfCall { SystemTfCall {
@ -190,10 +190,7 @@ pub fn list_of_arguments(s: &str) -> IResult<&str, ListOfArguments> {
let (s, x) = separated_list(symbol(","), expression)(s)?; let (s, x) = separated_list(symbol(","), expression)(s)?;
let (s, y) = separated_list( let (s, y) = separated_list(
symbol(","), symbol(","),
pair( pair(preceded(symbol("."), identifier), paren(opt(expression))),
preceded(symbol("."), identifier),
delimited(symbol("("), opt(expression), symbol(")")),
),
)(s)?; )(s)?;
Ok(( Ok((
s, s,
@ -219,7 +216,7 @@ pub fn method_call_body(s: &str) -> IResult<&str, MethodCallBody> {
pub fn method_call_body_user(s: &str) -> IResult<&str, MethodCallBody> { pub fn method_call_body_user(s: &str) -> IResult<&str, MethodCallBody> {
let (s, x) = method_identifier(s)?; let (s, x) = method_identifier(s)?;
let (s, y) = many0(attribute_instance)(s)?; let (s, y) = many0(attribute_instance)(s)?;
let (s, z) = opt(delimited(symbol("("), list_of_arguments, symbol(")")))(s)?; let (s, z) = opt(paren(list_of_arguments))(s)?;
Ok(( Ok((
s, s,
MethodCallBody::User(MethodCallBodyUser { MethodCallBody::User(MethodCallBodyUser {
@ -240,11 +237,8 @@ pub fn built_in_method_call(s: &str) -> IResult<&str, MethodCallBody> {
pub fn array_manipulation_call(s: &str) -> IResult<&str, ArrayManipulationCall> { pub fn array_manipulation_call(s: &str) -> IResult<&str, ArrayManipulationCall> {
let (s, x) = array_method_name(s)?; let (s, x) = array_method_name(s)?;
let (s, y) = many0(attribute_instance)(s)?; let (s, y) = many0(attribute_instance)(s)?;
let (s, z) = opt(delimited(symbol("("), list_of_arguments, symbol(")")))(s)?; let (s, z) = opt(paren(list_of_arguments))(s)?;
let (s, w) = opt(preceded( let (s, w) = opt(preceded(symbol("with"), paren(expression)))(s)?;
symbol("with"),
delimited(symbol("("), expression, symbol(")")),
))(s)?;
Ok(( Ok((
s, s,
ArrayManipulationCall { ArrayManipulationCall {
@ -259,17 +253,13 @@ pub fn array_manipulation_call(s: &str) -> IResult<&str, ArrayManipulationCall>
pub fn randomize_call(s: &str) -> IResult<&str, RandomizeCall> { pub fn randomize_call(s: &str) -> IResult<&str, RandomizeCall> {
let (s, _) = symbol("randomize")(s)?; let (s, _) = symbol("randomize")(s)?;
let (s, x) = many0(attribute_instance)(s)?; let (s, x) = many0(attribute_instance)(s)?;
let (s, y) = opt(delimited( let (s, y) = opt(paren(opt(alt((
symbol("("), variable_identifier_list,
opt(alt(( map(symbol("null"), |_| vec![]),
variable_identifier_list, )))))(s)?;
map(symbol("null"), |_| vec![]),
))),
symbol(")"),
))(s)?;
let (s, z) = opt(tuple(( let (s, z) = opt(tuple((
symbol("with"), symbol("with"),
opt(delimited(symbol("("), opt(identifier_list), symbol(")"))), opt(paren(opt(identifier_list))),
constraint_block, constraint_block,
)))(s)?; )))(s)?;
let y = if let Some(Some(y)) = y { y } else { vec![] }; let y = if let Some(Some(y)) = y { y } else { vec![] };

View File

@ -484,7 +484,7 @@ pub fn ps_parameter_identifier(s: &str) -> IResult<&str, ScopedIdentifier> {
pub fn generate_block_scope(s: &str) -> IResult<&str, Scope> { pub fn generate_block_scope(s: &str) -> IResult<&str, Scope> {
let (s, x) = many0(tuple(( let (s, x) = many0(tuple((
generate_block_identifier, generate_block_identifier,
opt(delimited(symbol("["), constant_expression, symbol("]"))), opt(bracket(constant_expression)),
symbol("."), symbol("."),
)))(s)?; )))(s)?;

View File

@ -21,6 +21,54 @@ pub fn symbol<'a>(t: &'a str) -> impl Fn(&'a str) -> IResult<&'a str, &'a str> {
move |s: &'a str| ws(tag(t.clone()))(s) move |s: &'a str| ws(tag(t.clone()))(s)
} }
pub fn paren<'a, O, F>(f: F) -> impl Fn(&'a str) -> IResult<&'a str, O>
where
F: Fn(&'a str) -> IResult<&'a str, O>,
{
move |s: &'a str| {
let (s, _) = symbol("(")(s)?;
let (s, x) = f(s)?;
let (s, _) = symbol(")")(s)?;
Ok((s, x))
}
}
pub fn bracket<'a, O, F>(f: F) -> impl Fn(&'a str) -> IResult<&'a str, O>
where
F: Fn(&'a str) -> IResult<&'a str, O>,
{
move |s: &'a str| {
let (s, _) = symbol("[")(s)?;
let (s, x) = f(s)?;
let (s, _) = symbol("]")(s)?;
Ok((s, x))
}
}
pub fn brace<'a, O, F>(f: F) -> impl Fn(&'a str) -> IResult<&'a str, O>
where
F: Fn(&'a str) -> IResult<&'a str, O>,
{
move |s: &'a str| {
let (s, _) = symbol("{")(s)?;
let (s, x) = f(s)?;
let (s, _) = symbol("}")(s)?;
Ok((s, x))
}
}
pub fn apostrophe_brace<'a, O, F>(f: F) -> impl Fn(&'a str) -> IResult<&'a str, O>
where
F: Fn(&'a str) -> IResult<&'a str, O>,
{
move |s: &'a str| {
let (s, _) = symbol("'{")(s)?;
let (s, x) = f(s)?;
let (s, _) = symbol("}")(s)?;
Ok((s, x))
}
}
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#[derive(Debug)] #[derive(Debug)]