Add paren/brace/bracket
This commit is contained in:
parent
a96769c02e
commit
616bd9d98f
@ -145,13 +145,9 @@ pub fn clocking_event(s: &str) -> IResult<&str, ClockingEvent> {
|
||||
map(preceded(symbol("@"), identifier), |x| {
|
||||
ClockingEvent::Identifier(x)
|
||||
}),
|
||||
map(
|
||||
preceded(
|
||||
symbol("@"),
|
||||
delimited(symbol("("), event_expression, symbol(")")),
|
||||
),
|
||||
|x| ClockingEvent::Expression(x),
|
||||
),
|
||||
map(preceded(symbol("@"), paren(event_expression)), |x| {
|
||||
ClockingEvent::Expression(x)
|
||||
}),
|
||||
))(s)
|
||||
}
|
||||
|
||||
@ -310,13 +306,9 @@ pub fn cycle_delay(s: &str) -> IResult<&str, CycleDelay> {
|
||||
map(preceded(symbol("##"), identifier), |x| {
|
||||
CycleDelay::Identifier(x)
|
||||
}),
|
||||
map(
|
||||
preceded(
|
||||
symbol("##"),
|
||||
delimited(symbol("("), expression, symbol(")")),
|
||||
),
|
||||
|x| CycleDelay::Expression(x),
|
||||
),
|
||||
map(preceded(symbol("##"), paren(expression)), |x| {
|
||||
CycleDelay::Expression(x)
|
||||
}),
|
||||
))(s)
|
||||
}
|
||||
|
||||
|
@ -83,22 +83,14 @@ pub fn pattern(s: &str) -> IResult<&str, Pattern> {
|
||||
|x| Pattern::Tagged(Box::new(x)),
|
||||
),
|
||||
map(
|
||||
delimited(
|
||||
symbol("'{"),
|
||||
separated_nonempty_list(symbol(","), pattern),
|
||||
symbol("}"),
|
||||
),
|
||||
apostrophe_brace(separated_nonempty_list(symbol(","), pattern)),
|
||||
|x| Pattern::Pattern(Box::new(x)),
|
||||
),
|
||||
map(
|
||||
delimited(
|
||||
symbol("'{"),
|
||||
separated_nonempty_list(
|
||||
apostrophe_brace(separated_nonempty_list(
|
||||
symbol(","),
|
||||
pair(member_identifier, preceded(symbol(":"), pattern)),
|
||||
),
|
||||
symbol("}"),
|
||||
),
|
||||
)),
|
||||
|x| Pattern::MemberPattern(Box::new(x)),
|
||||
),
|
||||
))(s)
|
||||
@ -107,48 +99,28 @@ pub fn pattern(s: &str) -> IResult<&str, Pattern> {
|
||||
pub fn assignment_pattern(s: &str) -> IResult<&str, AssignmentPattern> {
|
||||
alt((
|
||||
map(
|
||||
delimited(
|
||||
symbol("'{"),
|
||||
separated_nonempty_list(symbol(","), expression),
|
||||
symbol("}"),
|
||||
),
|
||||
apostrophe_brace(separated_nonempty_list(symbol(","), expression)),
|
||||
|x| AssignmentPattern::Expression(x),
|
||||
),
|
||||
map(
|
||||
delimited(
|
||||
symbol("'{"),
|
||||
separated_nonempty_list(
|
||||
apostrophe_brace(separated_nonempty_list(
|
||||
symbol(","),
|
||||
pair(structure_pattern_key, preceded(symbol(":"), expression)),
|
||||
),
|
||||
symbol("}"),
|
||||
),
|
||||
)),
|
||||
|x| AssignmentPattern::StructurePatternKey(x),
|
||||
),
|
||||
map(
|
||||
delimited(
|
||||
symbol("'{"),
|
||||
separated_nonempty_list(
|
||||
apostrophe_brace(separated_nonempty_list(
|
||||
symbol(","),
|
||||
pair(array_pattern_key, preceded(symbol(":"), expression)),
|
||||
),
|
||||
symbol("}"),
|
||||
),
|
||||
)),
|
||||
|x| AssignmentPattern::ArrayPatternKey(x),
|
||||
),
|
||||
map(
|
||||
delimited(
|
||||
symbol("'{"),
|
||||
pair(
|
||||
apostrophe_brace(pair(
|
||||
constant_expression,
|
||||
delimited(
|
||||
symbol("{"),
|
||||
separated_nonempty_list(symbol(","), expression),
|
||||
symbol("}"),
|
||||
),
|
||||
),
|
||||
symbol("}"),
|
||||
),
|
||||
brace(separated_nonempty_list(symbol(","), expression)),
|
||||
)),
|
||||
|x| AssignmentPattern::ConstantExpression(x),
|
||||
),
|
||||
))(s)
|
||||
@ -215,22 +187,14 @@ pub fn constant_assignment_pattern_expression(
|
||||
}
|
||||
|
||||
pub fn assignment_pattern_net_lvalue(s: &str) -> IResult<&str, AssignmentPatternNetLvalue> {
|
||||
let (s, x) = delimited(
|
||||
symbol("'{"),
|
||||
separated_nonempty_list(symbol(","), net_lvalue),
|
||||
symbol("}"),
|
||||
)(s)?;
|
||||
let (s, x) = apostrophe_brace(separated_nonempty_list(symbol(","), net_lvalue))(s)?;
|
||||
Ok((s, AssignmentPatternNetLvalue { lvalue: x }))
|
||||
}
|
||||
|
||||
pub fn assignment_pattern_variable_lvalue(
|
||||
s: &str,
|
||||
) -> IResult<&str, AssignmentPatternVariableLvalue> {
|
||||
let (s, x) = delimited(
|
||||
symbol("'{"),
|
||||
separated_nonempty_list(symbol(","), variable_lvalue),
|
||||
symbol("}"),
|
||||
)(s)?;
|
||||
let (s, x) = apostrophe_brace(separated_nonempty_list(symbol(","), variable_lvalue))(s)?;
|
||||
Ok((s, AssignmentPatternVariableLvalue { lvalue: x }))
|
||||
}
|
||||
|
||||
|
@ -119,7 +119,7 @@ pub fn randsequence_statement(s: &str) -> IResult<&str, RandsequenceStatement> {
|
||||
pub fn production(s: &str) -> IResult<&str, Production> {
|
||||
let (s, x) = opt(data_type_or_void)(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, v) = separated_nonempty_list(symbol("|"), rs_rule)(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> {
|
||||
let (s, _) = symbol("rand")(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, z) = many1(production_item)(s)?;
|
||||
|
||||
@ -183,9 +183,7 @@ pub fn weight_specification(s: &str) -> IResult<&str, WeightSpecification> {
|
||||
alt((
|
||||
map(integral_number, |x| WeightSpecification::Number(x)),
|
||||
map(ps_identifier, |x| WeightSpecification::Identifier(x)),
|
||||
map(delimited(symbol("("), expression, symbol(")")), |x| {
|
||||
WeightSpecification::Expression(x)
|
||||
}),
|
||||
map(paren(expression), |x| WeightSpecification::Expression(x)),
|
||||
))(s)
|
||||
}
|
||||
|
||||
@ -215,7 +213,7 @@ pub fn rs_prod(s: &str) -> IResult<&str, RsProd> {
|
||||
|
||||
pub fn production_item(s: &str) -> IResult<&str, ProductionItem> {
|
||||
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((
|
||||
s,
|
||||
ProductionItem {
|
||||
@ -227,7 +225,7 @@ pub fn production_item(s: &str) -> IResult<&str, ProductionItem> {
|
||||
|
||||
pub fn rs_if_else(s: &str) -> IResult<&str, RsIfElse> {
|
||||
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, z) = opt(preceded(symbol("else"), production_item))(s)?;
|
||||
Ok((
|
||||
@ -242,7 +240,7 @@ pub fn rs_if_else(s: &str) -> IResult<&str, RsIfElse> {
|
||||
|
||||
pub fn rs_repeat(s: &str) -> IResult<&str, RsRepeat> {
|
||||
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)?;
|
||||
Ok((
|
||||
s,
|
||||
@ -255,7 +253,7 @@ pub fn rs_repeat(s: &str) -> IResult<&str, RsRepeat> {
|
||||
|
||||
pub fn rs_case(s: &str) -> IResult<&str, RsCase> {
|
||||
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)?;
|
||||
Ok((
|
||||
s,
|
||||
|
@ -320,7 +320,7 @@ pub fn wait_statement(s: &str) -> IResult<&str, WaitStatement> {
|
||||
|
||||
pub fn wait_statement_wait(s: &str) -> IResult<&str, WaitStatement> {
|
||||
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)?;
|
||||
Ok((
|
||||
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> {
|
||||
let (s, _) = symbol("wait_order")(s)?;
|
||||
let (s, x) = delimited(
|
||||
symbol("("),
|
||||
separated_nonempty_list(symbol(","), hierarchical_identifier),
|
||||
symbol(")"),
|
||||
)(s)?;
|
||||
let (s, x) = paren(separated_nonempty_list(
|
||||
symbol(","),
|
||||
hierarchical_identifier,
|
||||
))(s)?;
|
||||
let (s, y) = action_block(s)?;
|
||||
Ok((
|
||||
s,
|
||||
|
@ -74,16 +74,12 @@ pub struct ArrayRangeExpression<'a> {
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
pub fn concatenation(s: &str) -> IResult<&str, Concatenation> {
|
||||
let (s, _) = symbol("{")(s)?;
|
||||
let (s, x) = separated_nonempty_list(symbol(","), expression)(s)?;
|
||||
let (s, _) = symbol("}")(s)?;
|
||||
let (s, x) = brace(separated_nonempty_list(symbol(","), expression))(s)?;
|
||||
Ok((s, Concatenation { expression: x }))
|
||||
}
|
||||
|
||||
pub fn constant_concatenation(s: &str) -> IResult<&str, ConstantConcatenation> {
|
||||
let (s, _) = symbol("{")(s)?;
|
||||
let (s, x) = separated_nonempty_list(symbol(","), constant_expression)(s)?;
|
||||
let (s, _) = symbol("}")(s)?;
|
||||
let (s, x) = brace(separated_nonempty_list(symbol(","), constant_expression))(s)?;
|
||||
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> {
|
||||
let (s, _) = symbol("{")(s)?;
|
||||
let (s, x) = separated_nonempty_list(symbol(","), module_path_expression)(s)?;
|
||||
let (s, _) = symbol("}")(s)?;
|
||||
let (s, x) = brace(separated_nonempty_list(symbol(","), module_path_expression))(s)?;
|
||||
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> {
|
||||
let (s, _) = symbol("{")(s)?;
|
||||
let (s, x) = separated_nonempty_list(symbol(","), stream_expression)(s)?;
|
||||
let (s, _) = symbol("}")(s)?;
|
||||
let (s, x) = brace(separated_nonempty_list(symbol(","), stream_expression))(s)?;
|
||||
Ok((s, StreamConcatenation { expression: x }))
|
||||
}
|
||||
|
||||
pub fn stream_expression(s: &str) -> IResult<&str, StreamExpression> {
|
||||
let (s, x) = expression(s)?;
|
||||
let (s, y) = opt(preceded(
|
||||
symbol("with"),
|
||||
delimited(symbol("["), array_range_expression, symbol("]")),
|
||||
))(s)?;
|
||||
let (s, y) = opt(preceded(symbol("with"), bracket(array_range_expression)))(s)?;
|
||||
Ok((
|
||||
s,
|
||||
StreamExpression {
|
||||
|
@ -2,7 +2,6 @@ use crate::parser::*;
|
||||
use nom::branch::*;
|
||||
use nom::combinator::*;
|
||||
use nom::multi::*;
|
||||
use nom::sequence::*;
|
||||
use nom::IResult;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
@ -387,10 +386,9 @@ pub fn expression(s: &str) -> IResult<&str, Expression> {
|
||||
map(primary, |x| Expression::Nullary(Box::new(x))),
|
||||
expression_unary,
|
||||
map(inc_or_dec_expression, |x| Expression::IncOrDec(Box::new(x))),
|
||||
map(
|
||||
delimited(symbol("("), operator_assignment, symbol(")")),
|
||||
|x| Expression::Assignment(Box::new(x)),
|
||||
),
|
||||
map(paren(operator_assignment), |x| {
|
||||
Expression::Assignment(Box::new(x))
|
||||
}),
|
||||
expression_binary,
|
||||
map(conditional_expression, |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> {
|
||||
let (s, x) = expression(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((
|
||||
s,
|
||||
InsideExpression {
|
||||
|
@ -220,10 +220,9 @@ pub fn constant_primary(s: &str) -> IResult<&str, ConstantPrimary> {
|
||||
map(constant_let_expression, |x| {
|
||||
ConstantPrimary::LetExpression(x)
|
||||
}),
|
||||
map(
|
||||
delimited(symbol("("), constant_mintypmax_expression, symbol(")")),
|
||||
|x| ConstantPrimary::MintypmaxExpression(x),
|
||||
),
|
||||
map(paren(constant_mintypmax_expression), |x| {
|
||||
ConstantPrimary::MintypmaxExpression(x)
|
||||
}),
|
||||
map(constant_cast, |x| ConstantPrimary::Cast(x)),
|
||||
map(constant_assignment_pattern_expression, |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> {
|
||||
let (s, x) = specparam_identifier(s)?;
|
||||
let (s, y) = opt(delimited(
|
||||
symbol("["),
|
||||
constant_range_expression,
|
||||
symbol("]"),
|
||||
))(s)?;
|
||||
let (s, y) = opt(bracket(constant_range_expression))(s)?;
|
||||
Ok((
|
||||
s,
|
||||
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> {
|
||||
let (s, x) = constant_concatenation(s)?;
|
||||
let (s, y) = opt(delimited(
|
||||
symbol("["),
|
||||
constant_range_expression,
|
||||
symbol("]"),
|
||||
))(s)?;
|
||||
let (s, y) = opt(bracket(constant_range_expression))(s)?;
|
||||
Ok((
|
||||
s,
|
||||
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> {
|
||||
let (s, x) = constant_multiple_concatenation(s)?;
|
||||
let (s, y) = opt(delimited(
|
||||
symbol("["),
|
||||
constant_range_expression,
|
||||
symbol("]"),
|
||||
))(s)?;
|
||||
let (s, y) = opt(bracket(constant_range_expression))(s)?;
|
||||
Ok((
|
||||
s,
|
||||
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> {
|
||||
let (s, x) = delimited(symbol("("), constant_mintypmax_expression, symbol(")"))(s)?;
|
||||
let (s, x) = paren(constant_mintypmax_expression)(s)?;
|
||||
Ok((s, ConstantPrimary::MintypmaxExpression(x)))
|
||||
}
|
||||
|
||||
@ -334,10 +321,9 @@ pub fn module_path_primary(s: &str) -> IResult<&str, ModulePathPrimary> {
|
||||
map(function_subroutine_call, |x| {
|
||||
ModulePathPrimary::FunctionSubroutineCall(x)
|
||||
}),
|
||||
map(
|
||||
delimited(symbol("("), module_path_mintypmax_expression, symbol(")")),
|
||||
|x| ModulePathPrimary::ModulePathMintypmaxExpression(x),
|
||||
),
|
||||
map(paren(module_path_mintypmax_expression), |x| {
|
||||
ModulePathPrimary::ModulePathMintypmaxExpression(x)
|
||||
}),
|
||||
))(s)
|
||||
}
|
||||
|
||||
@ -353,10 +339,9 @@ pub fn primary(s: &str) -> IResult<&str, Primary> {
|
||||
Primary::FunctionSubroutineCall(x)
|
||||
}),
|
||||
map(let_expression, |x| Primary::LetExpression(x)),
|
||||
map(
|
||||
delimited(symbol("("), mintypmax_expression, symbol(")")),
|
||||
|x| Primary::MintypmaxExpression(x),
|
||||
),
|
||||
map(paren(mintypmax_expression), |x| {
|
||||
Primary::MintypmaxExpression(x)
|
||||
}),
|
||||
map(cast, |x| Primary::Cast(x)),
|
||||
map(assignment_pattern_expression, |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>> {
|
||||
many0(delimited(symbol("["), expression, symbol("]")))(s)
|
||||
many0(bracket(expression))(s)
|
||||
}
|
||||
|
||||
pub fn select(s: &str) -> IResult<&str, Select> {
|
||||
@ -518,7 +503,7 @@ pub fn select(s: &str) -> IResult<&str, Select> {
|
||||
preceded(symbol("."), member_identifier),
|
||||
))(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 {
|
||||
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>> {
|
||||
many0(delimited(symbol("["), constant_expression, symbol("]")))(s)
|
||||
many0(bracket(constant_expression))(s)
|
||||
}
|
||||
|
||||
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),
|
||||
))(s)?;
|
||||
let (s, y) = constant_bit_select(s)?;
|
||||
let (s, z) = opt(delimited(
|
||||
symbol("["),
|
||||
constant_part_select_range,
|
||||
symbol("]"),
|
||||
))(s)?;
|
||||
let (s, z) = opt(bracket(constant_part_select_range))(s)?;
|
||||
|
||||
let x = if let Some((x, y)) = x {
|
||||
Some(SelectMember {
|
||||
@ -603,7 +584,7 @@ pub fn constant_select(s: &str) -> IResult<&str, ConstantSelect> {
|
||||
pub fn constant_cast(s: &str) -> IResult<&str, ConstantCast> {
|
||||
let (s, x) = casting_type(s)?;
|
||||
let (s, _) = symbol("'")(s)?;
|
||||
let (s, y) = delimited(symbol("("), constant_expression, symbol(")"))(s)?;
|
||||
let (s, y) = paren(constant_expression)(s)?;
|
||||
Ok((
|
||||
s,
|
||||
ConstantCast {
|
||||
@ -620,7 +601,7 @@ pub fn constant_let_expression(s: &str) -> IResult<&str, LetExpression> {
|
||||
pub fn cast(s: &str) -> IResult<&str, Cast> {
|
||||
let (s, x) = casting_type(s)?;
|
||||
let (s, _) = symbol("'")(s)?;
|
||||
let (s, y) = delimited(symbol("("), expression, symbol(")"))(s)?;
|
||||
let (s, y) = paren(expression)(s)?;
|
||||
Ok((
|
||||
s,
|
||||
Cast {
|
||||
|
@ -98,7 +98,7 @@ pub fn constant_function_call(s: &str) -> IResult<&str, SubroutineCall> {
|
||||
pub fn tf_call(s: &str) -> IResult<&str, TfCall> {
|
||||
let (s, x) = ps_or_hierarchical_tf_identifier(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((
|
||||
s,
|
||||
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> {
|
||||
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((
|
||||
s,
|
||||
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, y) = separated_list(
|
||||
symbol(","),
|
||||
pair(
|
||||
preceded(symbol("."), identifier),
|
||||
delimited(symbol("("), opt(expression), symbol(")")),
|
||||
),
|
||||
pair(preceded(symbol("."), identifier), paren(opt(expression))),
|
||||
)(s)?;
|
||||
Ok((
|
||||
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> {
|
||||
let (s, x) = method_identifier(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((
|
||||
s,
|
||||
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> {
|
||||
let (s, x) = array_method_name(s)?;
|
||||
let (s, y) = many0(attribute_instance)(s)?;
|
||||
let (s, z) = opt(delimited(symbol("("), list_of_arguments, symbol(")")))(s)?;
|
||||
let (s, w) = opt(preceded(
|
||||
symbol("with"),
|
||||
delimited(symbol("("), expression, symbol(")")),
|
||||
))(s)?;
|
||||
let (s, z) = opt(paren(list_of_arguments))(s)?;
|
||||
let (s, w) = opt(preceded(symbol("with"), paren(expression)))(s)?;
|
||||
Ok((
|
||||
s,
|
||||
ArrayManipulationCall {
|
||||
@ -259,17 +253,13 @@ pub fn array_manipulation_call(s: &str) -> IResult<&str, ArrayManipulationCall>
|
||||
pub fn randomize_call(s: &str) -> IResult<&str, RandomizeCall> {
|
||||
let (s, _) = symbol("randomize")(s)?;
|
||||
let (s, x) = many0(attribute_instance)(s)?;
|
||||
let (s, y) = opt(delimited(
|
||||
symbol("("),
|
||||
opt(alt((
|
||||
let (s, y) = opt(paren(opt(alt((
|
||||
variable_identifier_list,
|
||||
map(symbol("null"), |_| vec![]),
|
||||
))),
|
||||
symbol(")"),
|
||||
))(s)?;
|
||||
)))))(s)?;
|
||||
let (s, z) = opt(tuple((
|
||||
symbol("with"),
|
||||
opt(delimited(symbol("("), opt(identifier_list), symbol(")"))),
|
||||
opt(paren(opt(identifier_list))),
|
||||
constraint_block,
|
||||
)))(s)?;
|
||||
let y = if let Some(Some(y)) = y { y } else { vec![] };
|
||||
|
@ -484,7 +484,7 @@ pub fn ps_parameter_identifier(s: &str) -> IResult<&str, ScopedIdentifier> {
|
||||
pub fn generate_block_scope(s: &str) -> IResult<&str, Scope> {
|
||||
let (s, x) = many0(tuple((
|
||||
generate_block_identifier,
|
||||
opt(delimited(symbol("["), constant_expression, symbol("]"))),
|
||||
opt(bracket(constant_expression)),
|
||||
symbol("."),
|
||||
)))(s)?;
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
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)]
|
||||
|
Loading…
x
Reference in New Issue
Block a user