Remove sp

This commit is contained in:
dalance 2019-07-04 17:20:50 +09:00
parent 024f2f736f
commit 2ad5ce7015
12 changed files with 395 additions and 352 deletions

View File

@ -1,7 +1,6 @@
use crate::expressions::*;
use crate::identifiers::*;
use crate::util::*;
use nom::bytes::complete::*;
use nom::combinator::*;
use nom::multi::*;
use nom::sequence::*;
@ -23,15 +22,15 @@ pub struct AttrSpec<'a> {
// -----------------------------------------------------------------------------
pub fn attribute_instance(s: &str) -> IResult<&str, AttributeInstance> {
let (s, _) = tag("(*")(s)?;
let (s, attr_spec) = separated_nonempty_list(sp(tag(",")), sp(attr_spec))(s)?;
let (s, _) = sp(tag("*)"))(s)?;
let (s, _) = symbol("(*")(s)?;
let (s, attr_spec) = separated_nonempty_list(symbol(","), attr_spec)(s)?;
let (s, _) = symbol("*)")(s)?;
Ok((s, AttributeInstance { attr_spec }))
}
pub fn attr_spec(s: &str) -> IResult<&str, AttrSpec> {
let (s, attr_name) = identifier(s)?;
let (s, rvalue) = opt(preceded(sp(tag("=")), sp(constant_expression)))(s)?;
let (s, rvalue) = opt(preceded(symbol("="), constant_expression))(s)?;
Ok((s, AttrSpec { attr_name, rvalue }))
}

View File

@ -6,7 +6,7 @@ use nom::IResult;
#[derive(Debug)]
pub struct Comment<'a> {
pub raw: Vec<&'a str>,
pub raw: &'a str,
}
// -----------------------------------------------------------------------------
@ -18,7 +18,7 @@ pub fn comment(s: &str) -> IResult<&str, Comment> {
pub fn one_line_comment(s: &str) -> IResult<&str, Comment> {
let (s, x) = tag("//")(s)?;
let (s, y) = is_not("\n")(s)?;
let raw = vec![x, y];
let raw = str_concat::concat(x, y).unwrap();
Ok((s, Comment { raw }))
}
@ -26,7 +26,8 @@ pub fn block_comment(s: &str) -> IResult<&str, Comment> {
let (s, x) = tag("/*")(s)?;
let (s, y) = is_not("*/")(s)?;
let (s, z) = tag("*/")(s)?;
let raw = vec![x, y, z];
let raw = str_concat::concat(x, y).unwrap();
let raw = str_concat::concat(raw, z).unwrap();
Ok((s, Comment { raw }))
}
@ -41,11 +42,11 @@ mod tests {
fn test() {
assert_eq!(
format!("{:?}", all_consuming(comment)("// comment")),
"Ok((\"\", Comment { raw: [\"//\", \" comment\"] }))"
"Ok((\"\", Comment { raw: \"// comment\" }))"
);
assert_eq!(
format!("{:?}", all_consuming(comment)("/* comment\n\n */")),
"Ok((\"\", Comment { raw: [\"/*\", \" comment\\n\\n \", \"*/\"] }))"
"Ok((\"\", Comment { raw: \"/* comment\\n\\n */\" }))"
);
}
}

View File

@ -1,7 +1,6 @@
use crate::expressions::*;
use crate::util::*;
use nom::branch::*;
use nom::bytes::complete::*;
use nom::combinator::*;
use nom::multi::*;
use nom::sequence::*;
@ -76,24 +75,24 @@ pub struct ArrayRangeExpression<'a> {
// -----------------------------------------------------------------------------
pub fn concatenation(s: &str) -> IResult<&str, Concatenation> {
let (s, _) = tag("{")(s)?;
let (s, expression) = separated_nonempty_list(sp(tag(",")), sp(expression))(s)?;
let (s, _) = sp(tag("}"))(s)?;
let (s, _) = symbol("{")(s)?;
let (s, expression) = separated_nonempty_list(symbol(","), expression)(s)?;
let (s, _) = symbol("}")(s)?;
Ok((s, Concatenation { expression }))
}
pub fn constant_concatenation(s: &str) -> IResult<&str, ConstantConcatenation> {
let (s, _) = tag("{")(s)?;
let (s, expression) = separated_nonempty_list(sp(tag(",")), sp(constant_expression))(s)?;
let (s, _) = sp(tag("}"))(s)?;
let (s, _) = symbol("{")(s)?;
let (s, expression) = separated_nonempty_list(symbol(","), constant_expression)(s)?;
let (s, _) = symbol("}")(s)?;
Ok((s, ConstantConcatenation { expression }))
}
pub fn constant_multiple_concatenation(s: &str) -> IResult<&str, ConstantMultipleConcatenation> {
let (s, _) = tag("{")(s)?;
let (s, expression) = sp(constant_expression)(s)?;
let (s, concatenation) = sp(constant_concatenation)(s)?;
let (s, _) = sp(tag("}"))(s)?;
let (s, _) = symbol("{")(s)?;
let (s, expression) = constant_expression(s)?;
let (s, concatenation) = constant_concatenation(s)?;
let (s, _) = symbol("}")(s)?;
Ok((
s,
ConstantMultipleConcatenation {
@ -104,19 +103,19 @@ pub fn constant_multiple_concatenation(s: &str) -> IResult<&str, ConstantMultipl
}
pub fn module_path_concatenation(s: &str) -> IResult<&str, ModulePathConcatenation> {
let (s, _) = tag("{")(s)?;
let (s, expression) = separated_nonempty_list(sp(tag(",")), sp(module_path_expression))(s)?;
let (s, _) = sp(tag("}"))(s)?;
let (s, _) = symbol("{")(s)?;
let (s, expression) = separated_nonempty_list(symbol(","), module_path_expression)(s)?;
let (s, _) = symbol("}")(s)?;
Ok((s, ModulePathConcatenation { expression }))
}
pub fn module_path_multiple_concatenation(
s: &str,
) -> IResult<&str, ModulePathMultipleConcatenation> {
let (s, _) = tag("{")(s)?;
let (s, expression) = sp(constant_expression)(s)?;
let (s, concatenation) = sp(module_path_concatenation)(s)?;
let (s, _) = sp(tag("}"))(s)?;
let (s, _) = symbol("{")(s)?;
let (s, expression) = constant_expression(s)?;
let (s, concatenation) = module_path_concatenation(s)?;
let (s, _) = symbol("}")(s)?;
Ok((
s,
ModulePathMultipleConcatenation {
@ -127,10 +126,10 @@ pub fn module_path_multiple_concatenation(
}
pub fn multiple_concatenation(s: &str) -> IResult<&str, MultipleConcatenation> {
let (s, _) = tag("{")(s)?;
let (s, expression) = sp(expression)(s)?;
let (s, concatenation) = sp(concatenation)(s)?;
let (s, _) = sp(tag("}"))(s)?;
let (s, _) = symbol("{")(s)?;
let (s, expression) = expression(s)?;
let (s, concatenation) = concatenation(s)?;
let (s, _) = symbol("}")(s)?;
Ok((
s,
MultipleConcatenation {
@ -141,11 +140,11 @@ pub fn multiple_concatenation(s: &str) -> IResult<&str, MultipleConcatenation> {
}
pub fn streaming_concatenation(s: &str) -> IResult<&str, StreamingConcatenation> {
let (s, _) = tag("{")(s)?;
let (s, operator) = sp(stream_operator)(s)?;
let (s, size) = opt(sp(slice_size))(s)?;
let (s, concatenation) = sp(stream_concatenation)(s)?;
let (s, _) = sp(tag("}"))(s)?;
let (s, _) = symbol("{")(s)?;
let (s, operator) = stream_operator(s)?;
let (s, size) = opt(slice_size)(s)?;
let (s, concatenation) = stream_concatenation(s)?;
let (s, _) = symbol("}")(s)?;
Ok((
s,
StreamingConcatenation {
@ -157,7 +156,7 @@ pub fn streaming_concatenation(s: &str) -> IResult<&str, StreamingConcatenation>
}
pub fn stream_operator(s: &str) -> IResult<&str, &str> {
alt((tag(">>"), tag("<<")))(s)
alt((symbol(">>"), symbol("<<")))(s)
}
pub fn slice_size(s: &str) -> IResult<&str, SliceSize> {
@ -168,17 +167,17 @@ pub fn slice_size(s: &str) -> IResult<&str, SliceSize> {
}
pub fn stream_concatenation(s: &str) -> IResult<&str, StreamConcatenation> {
let (s, _) = tag("{")(s)?;
let (s, expression) = separated_nonempty_list(sp(tag(",")), sp(stream_expression))(s)?;
let (s, _) = sp(tag("}"))(s)?;
let (s, _) = symbol("{")(s)?;
let (s, expression) = separated_nonempty_list(symbol(","), stream_expression)(s)?;
let (s, _) = symbol("}")(s)?;
Ok((s, StreamConcatenation { expression }))
}
pub fn stream_expression(s: &str) -> IResult<&str, StreamExpression> {
let (s, expression) = expression(s)?;
let (s, with) = opt(preceded(
sp(tag("with")),
delimited(sp(tag("[")), array_range_expression, sp(tag("]"))),
symbol("with"),
delimited(symbol("["), array_range_expression, symbol("]")),
))(s)?;
Ok((s, StreamExpression { expression, with }))
}
@ -186,8 +185,8 @@ pub fn stream_expression(s: &str) -> IResult<&str, StreamExpression> {
pub fn array_range_expression(s: &str) -> IResult<&str, ArrayRangeExpression> {
let (s, arg0) = expression(s)?;
let (s, x) = opt(pair(
alt((sp(tag(":")), sp(tag("+:")), sp(tag("-:")))),
sp(expression),
alt((symbol(":"), symbol("+:"), symbol("-:"))),
expression,
))(s)?;
let (operator, arg1) = if let Some((x, y)) = x {
(Some(x), Some(y))
@ -205,8 +204,8 @@ pub fn array_range_expression(s: &str) -> IResult<&str, ArrayRangeExpression> {
}
pub fn empty_unpacked_array_concatenation(s: &str) -> IResult<&str, ()> {
let (s, _) = tag("{")(s)?;
let (s, _) = sp(tag("}"))(s)?;
let (s, _) = symbol("{")(s)?;
let (s, _) = symbol("}")(s)?;
Ok((s, ()))
}

View File

@ -5,7 +5,6 @@ use crate::operators::*;
use crate::primaries::*;
use crate::util::*;
use nom::branch::*;
use nom::bytes::complete::*;
use nom::combinator::*;
use nom::multi::*;
use nom::sequence::*;
@ -218,8 +217,8 @@ pub fn inc_or_dec_expression(s: &str) -> IResult<&str, IncOrDecExpression> {
pub fn inc_or_dec_expression_prefix(s: &str) -> IResult<&str, IncOrDecExpression> {
let (s, operator) = inc_or_dec_operator(s)?;
let (s, attribute) = many0(sp(attribute_instance))(s)?;
let (s, lvalue) = sp(variable_lvalue)(s)?;
let (s, attribute) = many0(attribute_instance)(s)?;
let (s, lvalue) = variable_lvalue(s)?;
Ok((
s,
IncOrDecExpression::Prefix(IncOrDecExpressionPrefix {
@ -232,8 +231,8 @@ pub fn inc_or_dec_expression_prefix(s: &str) -> IResult<&str, IncOrDecExpression
pub fn inc_or_dec_expression_suffix(s: &str) -> IResult<&str, IncOrDecExpression> {
let (s, lvalue) = variable_lvalue(s)?;
let (s, attribute) = many0(sp(attribute_instance))(s)?;
let (s, operator) = sp(inc_or_dec_operator)(s)?;
let (s, attribute) = many0(attribute_instance)(s)?;
let (s, operator) = inc_or_dec_operator(s)?;
Ok((
s,
IncOrDecExpression::Suffix(IncOrDecExpressionSuffix {
@ -246,11 +245,11 @@ pub fn inc_or_dec_expression_suffix(s: &str) -> IResult<&str, IncOrDecExpression
pub fn conditional_expression(s: &str) -> IResult<&str, ConditionalExpression> {
let (s, predicate) = cond_predicate(s)?;
let (s, _) = sp(tag("?"))(s)?;
let (s, attribute) = many0(sp(attribute_instance))(s)?;
let (s, arg0) = sp(expression)(s)?;
let (s, _) = sp(tag(":"))(s)?;
let (s, arg1) = sp(expression)(s)?;
let (s, _) = symbol("?")(s)?;
let (s, attribute) = many0(attribute_instance)(s)?;
let (s, arg0) = expression(s)?;
let (s, _) = symbol(":")(s)?;
let (s, arg1) = expression(s)?;
Ok((
s,
ConditionalExpression {
@ -275,8 +274,8 @@ pub fn constant_expression(s: &str) -> IResult<&str, ConstantExpression> {
pub fn constant_expression_unary(s: &str) -> IResult<&str, ConstantExpression> {
let (s, operator) = unary_operator(s)?;
let (s, attribute) = many0(sp(attribute_instance))(s)?;
let (s, arg0) = sp(constant_primary)(s)?;
let (s, attribute) = many0(attribute_instance)(s)?;
let (s, arg0) = constant_primary(s)?;
Ok((
s,
ConstantExpression::Unary(Box::new(ConstantExpressionUnary {
@ -289,9 +288,9 @@ pub fn constant_expression_unary(s: &str) -> IResult<&str, ConstantExpression> {
pub fn constant_expression_binary(s: &str) -> IResult<&str, ConstantExpression> {
let (s, arg0) = constant_expression(s)?;
let (s, operator) = sp(binary_operator)(s)?;
let (s, attribute) = many0(sp(attribute_instance))(s)?;
let (s, arg1) = sp(constant_expression)(s)?;
let (s, operator) = binary_operator(s)?;
let (s, attribute) = many0(attribute_instance)(s)?;
let (s, arg1) = constant_expression(s)?;
Ok((
s,
ConstantExpression::Binary(Box::new(ConstantExpressionBinary {
@ -305,11 +304,11 @@ pub fn constant_expression_binary(s: &str) -> IResult<&str, ConstantExpression>
pub fn constant_expression_ternary(s: &str) -> IResult<&str, ConstantExpression> {
let (s, predicate) = constant_expression(s)?;
let (s, _) = sp(tag("?"))(s)?;
let (s, attribute) = many0(sp(attribute_instance))(s)?;
let (s, _) = symbol("?")(s)?;
let (s, attribute) = many0(attribute_instance)(s)?;
let (s, arg0) = constant_expression(s)?;
let (s, _) = sp(tag(":"))(s)?;
let (s, arg1) = sp(constant_expression)(s)?;
let (s, _) = symbol(":")(s)?;
let (s, arg1) = constant_expression(s)?;
Ok((
s,
ConstantExpression::Ternary(Box::new(ConstantExpressionTernary {
@ -334,16 +333,16 @@ pub fn constant_mintypmax_expression_ternary(
s: &str,
) -> IResult<&str, ConstantMintypmaxExpression> {
let (s, x) = constant_expression(s)?;
let (s, _) = sp(tag(":"))(s)?;
let (s, y) = sp(constant_expression)(s)?;
let (s, _) = sp(tag(":"))(s)?;
let (s, z) = sp(constant_expression)(s)?;
let (s, _) = symbol(":")(s)?;
let (s, y) = constant_expression(s)?;
let (s, _) = symbol(":")(s)?;
let (s, z) = constant_expression(s)?;
Ok((s, ConstantMintypmaxExpression::Ternary((x, y, z))))
}
pub fn constant_param_expression(s: &str) -> IResult<&str, ConstantParamExpression> {
alt((
map(tag("$"), |_| ConstantParamExpression::Dollar),
map(symbol("$"), |_| ConstantParamExpression::Dollar),
map(constant_mintypmax_expression, |x| {
ConstantParamExpression::Mintypmax(x)
}),
@ -353,7 +352,7 @@ pub fn constant_param_expression(s: &str) -> IResult<&str, ConstantParamExpressi
pub fn param_expression(s: &str) -> IResult<&str, ParamExpression> {
alt((
map(tag("$"), |_| ParamExpression::Dollar),
map(symbol("$"), |_| ParamExpression::Dollar),
map(mintypmax_expression, |x| ParamExpression::Mintypmax(x)),
map(data_type, |x| ParamExpression::DataType(x)),
))(s)
@ -376,15 +375,15 @@ pub fn constant_part_select_range(s: &str) -> IResult<&str, ConstantPartSelectRa
pub fn constant_range(s: &str) -> IResult<&str, ConstantPartSelectRange> {
let (s, x) = constant_expression(s)?;
let (s, _) = sp(tag(":"))(s)?;
let (s, y) = sp(constant_expression)(s)?;
let (s, _) = symbol(":")(s)?;
let (s, y) = constant_expression(s)?;
Ok((s, ConstantPartSelectRange::Range((x, y))))
}
pub fn constant_indexed_range(s: &str) -> IResult<&str, ConstantPartSelectRange> {
let (s, x) = constant_expression(s)?;
let (s, y) = sp(alt((tag("+:"), tag("-:"))))(s)?;
let (s, z) = sp(constant_expression)(s)?;
let (s, y) = alt((symbol("+:"), symbol("-:")))(s)?;
let (s, z) = constant_expression(s)?;
Ok((s, ConstantPartSelectRange::IndexedRange((x, y, z))))
}
@ -394,7 +393,7 @@ pub fn expression(s: &str) -> IResult<&str, Expression> {
expression_unary,
map(inc_or_dec_expression, |x| Expression::IncOrDec(Box::new(x))),
map(
delimited(tag("("), sp(operator_assignment), sp(tag(")"))),
delimited(symbol("("), operator_assignment, symbol(")")),
|x| Expression::Assignment(Box::new(x)),
),
expression_binary,
@ -410,8 +409,8 @@ pub fn expression(s: &str) -> IResult<&str, Expression> {
pub fn expression_unary(s: &str) -> IResult<&str, Expression> {
let (s, operator) = unary_operator(s)?;
let (s, attribute) = many0(sp(attribute_instance))(s)?;
let (s, arg0) = sp(primary)(s)?;
let (s, attribute) = many0(attribute_instance)(s)?;
let (s, arg0) = primary(s)?;
Ok((
s,
Expression::Unary(Box::new(ExpressionUnary {
@ -424,9 +423,9 @@ pub fn expression_unary(s: &str) -> IResult<&str, Expression> {
pub fn expression_binary(s: &str) -> IResult<&str, Expression> {
let (s, arg0) = expression(s)?;
let (s, operator) = sp(binary_operator)(s)?;
let (s, attribute) = many0(sp(attribute_instance))(s)?;
let (s, arg1) = sp(expression)(s)?;
let (s, operator) = binary_operator(s)?;
let (s, attribute) = many0(attribute_instance)(s)?;
let (s, arg1) = expression(s)?;
Ok((
s,
Expression::Binary(Box::new(ExpressionBinary {
@ -439,9 +438,9 @@ pub fn expression_binary(s: &str) -> IResult<&str, Expression> {
}
pub fn tagged_union_expression(s: &str) -> IResult<&str, TaggedUnionExpression> {
let (s, _) = tag("tagged")(s)?;
let (s, identifier) = sp(member_identifier)(s)?;
let (s, expression) = opt(sp(expression))(s)?;
let (s, _) = symbol("tagged")(s)?;
let (s, identifier) = member_identifier(s)?;
let (s, expression) = opt(expression)(s)?;
Ok((
s,
TaggedUnionExpression {
@ -453,8 +452,8 @@ pub fn tagged_union_expression(s: &str) -> IResult<&str, TaggedUnionExpression>
pub fn inside_expression(s: &str) -> IResult<&str, InsideExpression> {
let (s, expression) = expression(s)?;
let (s, _) = sp(tag("inside"))(s)?;
let (s, open_range_list) = delimited(sp(tag("{")), sp(open_range_list), sp(tag("}")))(s)?;
let (s, _) = symbol("inside")(s)?;
let (s, open_range_list) = delimited(symbol("{"), open_range_list, symbol("}"))(s)?;
Ok((
s,
InsideExpression {
@ -472,11 +471,11 @@ pub fn value_range(s: &str) -> IResult<&str, ValueRange> {
}
pub fn value_range_binary(s: &str) -> IResult<&str, ValueRange> {
let (s, _) = tag("[")(s)?;
let (s, x) = sp(expression)(s)?;
let (s, _) = sp(tag(":"))(s)?;
let (s, y) = sp(expression)(s)?;
let (s, _) = sp(tag("]"))(s)?;
let (s, _) = symbol("[")(s)?;
let (s, x) = expression(s)?;
let (s, _) = symbol(":")(s)?;
let (s, y) = expression(s)?;
let (s, _) = symbol("]")(s)?;
Ok((s, ValueRange::Binary((x, y))))
}
@ -489,10 +488,10 @@ pub fn mintypmax_expression(s: &str) -> IResult<&str, MintypmaxExpression> {
pub fn mintypmax_expression_ternary(s: &str) -> IResult<&str, MintypmaxExpression> {
let (s, x) = expression(s)?;
let (s, _) = sp(tag(":"))(s)?;
let (s, y) = sp(expression)(s)?;
let (s, _) = sp(tag(":"))(s)?;
let (s, z) = sp(expression)(s)?;
let (s, _) = symbol(":")(s)?;
let (s, y) = expression(s)?;
let (s, _) = symbol(":")(s)?;
let (s, z) = expression(s)?;
Ok((s, MintypmaxExpression::Ternary((x, y, z))))
}
@ -500,11 +499,11 @@ pub fn module_path_conditional_expression(
s: &str,
) -> IResult<&str, ModulePathConditionalExpression> {
let (s, predicate) = module_path_expression(s)?;
let (s, _) = sp(tag("?"))(s)?;
let (s, attribute) = many0(sp(attribute_instance))(s)?;
let (s, arg0) = sp(module_path_expression)(s)?;
let (s, _) = sp(tag(":"))(s)?;
let (s, arg1) = sp(module_path_expression)(s)?;
let (s, _) = symbol("?")(s)?;
let (s, attribute) = many0(attribute_instance)(s)?;
let (s, arg0) = module_path_expression(s)?;
let (s, _) = symbol(":")(s)?;
let (s, arg1) = module_path_expression(s)?;
Ok((
s,
ModulePathConditionalExpression {
@ -531,8 +530,8 @@ pub fn module_path_expression(s: &str) -> IResult<&str, ModulePathExpression> {
pub fn module_path_expression_unary(s: &str) -> IResult<&str, ModulePathExpression> {
let (s, operator) = unary_module_path_operator(s)?;
let (s, attribute) = many0(sp(attribute_instance))(s)?;
let (s, arg0) = sp(module_path_primary)(s)?;
let (s, attribute) = many0(attribute_instance)(s)?;
let (s, arg0) = module_path_primary(s)?;
Ok((
s,
ModulePathExpression::Unary(Box::new(ModulePathExpressionUnary {
@ -545,9 +544,9 @@ pub fn module_path_expression_unary(s: &str) -> IResult<&str, ModulePathExpressi
pub fn module_path_expression_binary(s: &str) -> IResult<&str, ModulePathExpression> {
let (s, arg0) = module_path_expression(s)?;
let (s, operator) = sp(binary_module_path_operator)(s)?;
let (s, attribute) = many0(sp(attribute_instance))(s)?;
let (s, arg1) = sp(module_path_expression)(s)?;
let (s, operator) = binary_module_path_operator(s)?;
let (s, attribute) = many0(attribute_instance)(s)?;
let (s, arg1) = module_path_expression(s)?;
Ok((
s,
ModulePathExpression::Binary(Box::new(ModulePathExpressionBinary {
@ -572,10 +571,10 @@ pub fn module_path_mintypmax_expression_ternary(
s: &str,
) -> IResult<&str, ModulePathMintypmaxExpression> {
let (s, x) = module_path_expression(s)?;
let (s, _) = sp(tag(":"))(s)?;
let (s, y) = sp(module_path_expression)(s)?;
let (s, _) = sp(tag(":"))(s)?;
let (s, z) = sp(module_path_expression)(s)?;
let (s, _) = symbol(":")(s)?;
let (s, y) = module_path_expression(s)?;
let (s, _) = symbol(":")(s)?;
let (s, z) = module_path_expression(s)?;
Ok((s, ModulePathMintypmaxExpression::Ternary((x, y, z))))
}
@ -585,15 +584,15 @@ pub fn part_select_range(s: &str) -> IResult<&str, PartSelectRange> {
pub fn range(s: &str) -> IResult<&str, PartSelectRange> {
let (s, x) = constant_expression(s)?;
let (s, _) = sp(tag(":"))(s)?;
let (s, y) = sp(constant_expression)(s)?;
let (s, _) = symbol(":")(s)?;
let (s, y) = constant_expression(s)?;
Ok((s, PartSelectRange::Range((x, y))))
}
pub fn indexed_range(s: &str) -> IResult<&str, PartSelectRange> {
let (s, x) = expression(s)?;
let (s, y) = sp(alt((tag("+:"), tag("-:"))))(s)?;
let (s, z) = sp(constant_expression)(s)?;
let (s, y) = alt((symbol("+:"), symbol("-:")))(s)?;
let (s, z) = constant_expression(s)?;
Ok((s, PartSelectRange::IndexedRange((x, y, z))))
}

View File

@ -76,6 +76,10 @@ pub fn bin_identifier(s: &str) -> IResult<&str, Identifier> {
}
pub fn c_identifier(s: &str) -> IResult<&str, Identifier> {
ws(c_identifier_impl)(s)
}
pub fn c_identifier_impl(s: &str) -> IResult<&str, Identifier> {
let (s, x) = is_a(AZ_)(s)?;
let (s, y) = opt(is_a(AZ09_))(s)?;
let raw = if let Some(y) = y {
@ -143,6 +147,10 @@ pub fn enum_identifier(s: &str) -> IResult<&str, Identifier> {
}
pub fn escaped_identifier(s: &str) -> IResult<&str, Identifier> {
ws(escaped_identifier_impl)(s)
}
pub fn escaped_identifier_impl(s: &str) -> IResult<&str, Identifier> {
let (s, x) = tag("\\")(s)?;
let (s, y) = is_not(" \t\r\n")(s)?;
Ok((
@ -187,8 +195,8 @@ pub fn hierarchical_event_identifier(s: &str) -> IResult<&str, HierarchicalIdent
pub fn hierarchy(s: &str) -> IResult<&str, Hierarchy> {
let (s, identifier) = identifier(s)?;
let (s, constant_bit_select) = sp(constant_bit_select)(s)?;
let (s, _) = sp(tag("."))(s)?;
let (s, constant_bit_select) = constant_bit_select(s)?;
let (s, _) = symbol(".")(s)?;
let constant_bit_select = Some(constant_bit_select);
@ -202,9 +210,9 @@ pub fn hierarchy(s: &str) -> IResult<&str, Hierarchy> {
}
pub fn hierarchical_identifier(s: &str) -> IResult<&str, HierarchicalIdentifier> {
let (s, x) = opt(terminated(tag("$root"), sp(tag("."))))(s)?;
let (s, x) = opt(terminated(symbol("$root"), symbol(".")))(s)?;
let (s, mut hierarchy) = many0(hierarchy)(s)?;
let (s, identifier) = sp(identifier)(s)?;
let (s, identifier) = identifier(s)?;
if let Some(x) = x {
hierarchy.insert(
@ -315,8 +323,11 @@ pub fn package_identifier(s: &str) -> IResult<&str, Identifier> {
pub fn package_scope(s: &str) -> IResult<&str, Scope> {
let (s, x) = alt((
terminated(package_identifier, sp(tag("::"))),
terminated(map(tag("$unit"), |x| Identifier { raw: x }), sp(tag("::"))),
terminated(package_identifier, symbol("::")),
terminated(
map(symbol("$unit"), |x| Identifier { raw: x }),
symbol("::"),
),
))(s)?;
Ok((s, Scope::PackageScope(x)))
}
@ -343,47 +354,47 @@ pub fn property_identifier(s: &str) -> IResult<&str, Identifier> {
pub fn ps_class_identifier(s: &str) -> IResult<&str, ScopedIdentifier> {
let (s, scope) = opt(package_scope)(s)?;
let (s, identifier) = sp(class_identifier)(s)?;
let (s, identifier) = class_identifier(s)?;
let identifier = identifier.into();
Ok((s, ScopedIdentifier { scope, identifier }))
}
pub fn ps_covergroup_identifier(s: &str) -> IResult<&str, ScopedIdentifier> {
let (s, scope) = opt(package_scope)(s)?;
let (s, identifier) = sp(covergroup_identifier)(s)?;
let (s, identifier) = covergroup_identifier(s)?;
let identifier = identifier.into();
Ok((s, ScopedIdentifier { scope, identifier }))
}
pub fn ps_checker_identifier(s: &str) -> IResult<&str, ScopedIdentifier> {
let (s, scope) = opt(package_scope)(s)?;
let (s, identifier) = sp(checker_identifier)(s)?;
let (s, identifier) = checker_identifier(s)?;
let identifier = identifier.into();
Ok((s, ScopedIdentifier { scope, identifier }))
}
pub fn ps_identifier(s: &str) -> IResult<&str, ScopedIdentifier> {
let (s, scope) = opt(package_scope)(s)?;
let (s, identifier) = sp(identifier)(s)?;
let (s, identifier) = identifier(s)?;
let identifier = identifier.into();
Ok((s, ScopedIdentifier { scope, identifier }))
}
pub fn ps_or_hierarchical_array_identifier(s: &str) -> IResult<&str, ScopedIdentifier> {
let (s, scope) = opt(alt((
terminated(implicit_class_handle, sp(tag("."))),
terminated(implicit_class_handle, symbol(".")),
class_scope,
package_scope,
)))(s)?;
let (s, identifier) = sp(hierarchical_array_identifier)(s)?;
let (s, identifier) = hierarchical_array_identifier(s)?;
Ok((s, ScopedIdentifier { scope, identifier }))
}
pub fn ps_or_hierarchical_net_identifier(s: &str) -> IResult<&str, ScopedIdentifier> {
let (s, scope) = opt(package_scope)(s)?;
let (s, identifier) = alt((
map(sp(net_identifier), |x| x.into()),
sp(hierarchical_net_identifier),
map(net_identifier, |x| x.into()),
hierarchical_net_identifier,
))(s)?;
Ok((s, ScopedIdentifier { scope, identifier }))
}
@ -391,8 +402,8 @@ pub fn ps_or_hierarchical_net_identifier(s: &str) -> IResult<&str, ScopedIdentif
pub fn ps_or_hierarchical_property_identifier(s: &str) -> IResult<&str, ScopedIdentifier> {
let (s, scope) = opt(package_scope)(s)?;
let (s, identifier) = alt((
map(sp(property_identifier), |x| x.into()),
sp(hierarchical_property_identifier),
map(property_identifier, |x| x.into()),
hierarchical_property_identifier,
))(s)?;
Ok((s, ScopedIdentifier { scope, identifier }))
}
@ -400,37 +411,30 @@ pub fn ps_or_hierarchical_property_identifier(s: &str) -> IResult<&str, ScopedId
pub fn ps_or_hierarchical_sequence_identifier(s: &str) -> IResult<&str, ScopedIdentifier> {
let (s, scope) = opt(package_scope)(s)?;
let (s, identifier) = alt((
map(sp(sequence_identifier), |x| x.into()),
sp(hierarchical_sequence_identifier),
map(sequence_identifier, |x| x.into()),
hierarchical_sequence_identifier,
))(s)?;
Ok((s, ScopedIdentifier { scope, identifier }))
}
pub fn ps_or_hierarchical_tf_identifier(s: &str) -> IResult<&str, ScopedIdentifier> {
let (s, scope) = opt(package_scope)(s)?;
let (s, identifier) = alt((
map(sp(tf_identifier), |x| x.into()),
sp(hierarchical_tf_identifier),
))(s)?;
let (s, identifier) = alt((map(tf_identifier, |x| x.into()), hierarchical_tf_identifier))(s)?;
Ok((s, ScopedIdentifier { scope, identifier }))
}
pub fn ps_parameter_identifier(s: &str) -> IResult<&str, ScopedIdentifier> {
let (s, scope) = opt(alt((package_scope, class_scope, generate_block_scope)))(s)?;
let (s, identifier) = sp(parameter_identifier)(s)?;
let (s, identifier) = parameter_identifier(s)?;
let identifier = identifier.into();
Ok((s, ScopedIdentifier { scope, identifier }))
}
pub fn generate_block_scope(s: &str) -> IResult<&str, Scope> {
let (s, x) = many0(tuple((
sp(generate_block_identifier),
opt(delimited(
sp(tag("[")),
sp(constant_expression),
sp(tag("]")),
)),
sp(tag(".")),
generate_block_identifier,
opt(delimited(symbol("["), constant_expression, symbol("]"))),
symbol("."),
)))(s)?;
let mut ret = Vec::new();
@ -446,13 +450,13 @@ pub fn generate_block_scope(s: &str) -> IResult<&str, Scope> {
pub fn ps_type_identifier(s: &str) -> IResult<&str, ScopedIdentifier> {
let (s, scope) = opt(alt((
map(terminated(tag("local"), sp(tag("::"))), |_| {
map(terminated(symbol("local"), symbol("::")), |_| {
Scope::LocalScope
}),
package_scope,
class_scope,
)))(s)?;
let (s, identifier) = sp(type_identifier)(s)?;
let (s, identifier) = type_identifier(s)?;
let identifier = identifier.into();
Ok((s, ScopedIdentifier { scope, identifier }))
}
@ -466,6 +470,10 @@ pub fn signal_identifier(s: &str) -> IResult<&str, Identifier> {
}
pub fn simple_identifier(s: &str) -> IResult<&str, Identifier> {
ws(simple_identifier_impl)(s)
}
pub fn simple_identifier_impl(s: &str) -> IResult<&str, Identifier> {
let (s, x) = is_a(AZ_)(s)?;
let (s, y) = opt(is_a(AZ09_DOLLAR))(s)?;
let raw = if let Some(y) = y {
@ -481,6 +489,10 @@ pub fn specparam_identifier(s: &str) -> IResult<&str, Identifier> {
}
pub fn system_tf_identifier(s: &str) -> IResult<&str, Identifier> {
ws(system_tf_identifier_impl)(s)
}
pub fn system_tf_identifier_impl(s: &str) -> IResult<&str, Identifier> {
let (s, x) = tag("$")(s)?;
let (s, y) = is_a(AZ09_DOLLAR)(s)?;
Ok((

View File

@ -3,7 +3,6 @@ use crate::identifiers::*;
use crate::primaries::*;
use crate::util::*;
use nom::branch::*;
use nom::bytes::complete::*;
use nom::combinator::*;
use nom::multi::*;
use nom::sequence::*;
@ -66,7 +65,7 @@ pub fn net_lvalue(s: &str) -> IResult<&str, NetLvalue> {
pub fn net_lvalue_identifier(s: &str) -> IResult<&str, NetLvalue> {
let (s, identifier) = ps_or_hierarchical_net_identifier(s)?;
let (s, select) = sp(constant_select)(s)?;
let (s, select) = constant_select(s)?;
Ok((
s,
NetLvalue::Identifier(NetLvalueIdentifier { identifier, select }),
@ -75,15 +74,15 @@ pub fn net_lvalue_identifier(s: &str) -> IResult<&str, NetLvalue> {
pub fn net_lvalue_pattern(s: &str) -> IResult<&str, NetLvalue> {
let (s, r#type) = opt(assignment_pattern_expression_type)(s)?;
let (s, lvalue) = sp(assignment_pattern_net_lvalue)(s)?;
let (s, lvalue) = assignment_pattern_net_lvalue(s)?;
Ok((s, NetLvalue::Pattern(NetLvaluePattern { r#type, lvalue })))
}
pub fn net_lvalue_lvalue(s: &str) -> IResult<&str, NetLvalue> {
let (s, _) = tag("{")(s)?;
let (s, x) = sp(net_lvalue)(s)?;
let (s, y) = many0(preceded(sp(tag(",")), sp(net_lvalue)))(s)?;
let (s, _) = tag("}")(s)?;
let (s, _) = symbol("{")(s)?;
let (s, x) = net_lvalue(s)?;
let (s, y) = many0(preceded(symbol(","), net_lvalue))(s)?;
let (s, _) = symbol("}")(s)?;
let mut ret = Vec::new();
ret.push(x);
@ -107,11 +106,11 @@ pub fn variable_lvalue(s: &str) -> IResult<&str, VariableLvalue> {
pub fn variable_lvalue_identifier(s: &str) -> IResult<&str, VariableLvalue> {
let (s, scope) = opt(alt((
terminated(implicit_class_handle, sp(tag("."))),
terminated(implicit_class_handle, symbol(".")),
package_scope,
)))(s)?;
let (s, identifier) = sp(hierarchical_variable_identifier)(s)?;
let (s, select) = sp(select)(s)?;
let (s, identifier) = hierarchical_variable_identifier(s)?;
let (s, select) = select(s)?;
Ok((
s,
VariableLvalue::Identifier(VariableLvalueIdentifier {
@ -124,7 +123,7 @@ pub fn variable_lvalue_identifier(s: &str) -> IResult<&str, VariableLvalue> {
pub fn variable_lvalue_pattern(s: &str) -> IResult<&str, VariableLvalue> {
let (s, r#type) = opt(assignment_pattern_expression_type)(s)?;
let (s, lvalue) = sp(assignment_pattern_variable_lvalue)(s)?;
let (s, lvalue) = assignment_pattern_variable_lvalue(s)?;
Ok((
s,
VariableLvalue::Pattern(VariableLvaluePattern { r#type, lvalue }),
@ -132,10 +131,10 @@ pub fn variable_lvalue_pattern(s: &str) -> IResult<&str, VariableLvalue> {
}
pub fn variable_lvalue_lvalue(s: &str) -> IResult<&str, VariableLvalue> {
let (s, _) = tag("{")(s)?;
let (s, x) = sp(variable_lvalue)(s)?;
let (s, y) = many0(preceded(sp(tag(",")), sp(variable_lvalue)))(s)?;
let (s, _) = tag("}")(s)?;
let (s, _) = symbol("{")(s)?;
let (s, x) = variable_lvalue(s)?;
let (s, y) = many0(preceded(symbol(","), variable_lvalue))(s)?;
let (s, _) = symbol("}")(s)?;
let mut ret = Vec::new();
ret.push(x);
@ -148,11 +147,11 @@ pub fn variable_lvalue_lvalue(s: &str) -> IResult<&str, VariableLvalue> {
pub fn nonrange_variable_lvalue(s: &str) -> IResult<&str, NonrangeVariableLvalue> {
let (s, scope) = opt(alt((
terminated(implicit_class_handle, sp(tag("."))),
terminated(implicit_class_handle, symbol(".")),
package_scope,
)))(s)?;
let (s, identifier) = sp(hierarchical_variable_identifier)(s)?;
let (s, select) = sp(nonrange_select)(s)?;
let (s, identifier) = hierarchical_variable_identifier(s)?;
let (s, select) = nonrange_select(s)?;
Ok((
s,
NonrangeVariableLvalue {

View File

@ -93,8 +93,8 @@ pub fn integral_number(s: &str) -> IResult<&str, Number> {
pub fn decimal_number(s: &str) -> IResult<&str, IntegralNumber> {
let (s, (size, decimal_base, decimal_value)) = tuple((
opt(size),
sp(decimal_base),
sp(alt((unsigned_number, x_number, z_number))),
decimal_base,
alt((unsigned_number, x_number, z_number)),
))(s)?;
Ok((
s,
@ -112,8 +112,7 @@ pub fn integral_unsigned_number(s: &str) -> IResult<&str, IntegralNumber> {
}
pub fn binary_number(s: &str) -> IResult<&str, IntegralNumber> {
let (s, (size, binary_base, binary_value)) =
tuple((opt(size), sp(binary_base), sp(binary_value)))(s)?;
let (s, (size, binary_base, binary_value)) = tuple((opt(size), binary_base, binary_value))(s)?;
Ok((
s,
IntegralNumber::BinaryNumber(BinaryNumber {
@ -125,8 +124,7 @@ pub fn binary_number(s: &str) -> IResult<&str, IntegralNumber> {
}
pub fn octal_number(s: &str) -> IResult<&str, IntegralNumber> {
let (s, (size, octal_base, octal_value)) =
tuple((opt(size), sp(octal_base), sp(octal_value)))(s)?;
let (s, (size, octal_base, octal_value)) = tuple((opt(size), octal_base, octal_value))(s)?;
Ok((
s,
IntegralNumber::OctalNumber(OctalNumber {
@ -138,7 +136,7 @@ pub fn octal_number(s: &str) -> IResult<&str, IntegralNumber> {
}
pub fn hex_number(s: &str) -> IResult<&str, IntegralNumber> {
let (s, (size, hex_base, hex_value)) = tuple((opt(size), sp(hex_base), sp(hex_value)))(s)?;
let (s, (size, hex_base, hex_value)) = tuple((opt(size), hex_base, hex_value))(s)?;
Ok((
s,
IntegralNumber::HexNumber(HexNumber {
@ -150,6 +148,10 @@ pub fn hex_number(s: &str) -> IResult<&str, IntegralNumber> {
}
pub fn size(s: &str) -> IResult<&str, &str> {
ws(size_impl)(s)
}
pub fn size_impl(s: &str) -> IResult<&str, &str> {
let (s, x) = is_a("123456789")(s)?;
fold_many0(alt((tag("_"), digit1)), x, |acc, item| {
str_concat::concat(acc, item).unwrap()
@ -163,7 +165,7 @@ pub fn real_number(s: &str) -> IResult<&str, Number> {
pub fn fixed_point_number(s: &str) -> IResult<&str, RealNumber> {
let (s, (integer_value, _, fraction_value)) =
tuple((unsigned_number, tag("."), unsigned_number))(s)?;
tuple((unsigned_number, symbol("."), unsigned_number))(s)?;
Ok((
s,
RealNumber::FixedPointNumber(FixedPointNumber {
@ -175,9 +177,9 @@ pub fn fixed_point_number(s: &str) -> IResult<&str, RealNumber> {
pub fn floating_point_number(s: &str) -> IResult<&str, RealNumber> {
let (s, integer_value) = unsigned_number(s)?;
let (s, fraction_value) = opt(tuple((tag("."), unsigned_number)))(s)?;
let (s, exponent) = alt((tag("e"), tag("E")))(s)?;
let (s, sign) = opt(alt((tag("+"), tag("-"))))(s)?;
let (s, fraction_value) = opt(tuple((symbol("."), unsigned_number)))(s)?;
let (s, exponent) = alt((symbol("e"), symbol("E")))(s)?;
let (s, sign) = opt(alt((symbol("+"), symbol("-"))))(s)?;
let (s, exponent_value) = unsigned_number(s)?;
let fraction_value = fraction_value.and_then(|(_, y)| Some(y));
@ -195,6 +197,10 @@ pub fn floating_point_number(s: &str) -> IResult<&str, RealNumber> {
}
pub fn unsigned_number(s: &str) -> IResult<&str, &str> {
ws(unsigned_number_impl)(s)
}
pub fn unsigned_number_impl(s: &str) -> IResult<&str, &str> {
let (s, x) = digit1(s)?;
fold_many0(alt((tag("_"), digit1)), x, |acc, item| {
str_concat::concat(acc, item).unwrap()
@ -202,6 +208,10 @@ pub fn unsigned_number(s: &str) -> IResult<&str, &str> {
}
pub fn binary_value(s: &str) -> IResult<&str, &str> {
ws(binary_value_impl)(s)
}
pub fn binary_value_impl(s: &str) -> IResult<&str, &str> {
let (s, x) = is_a("01xXzZ?")(s)?;
fold_many0(alt((tag("_"), is_a("01xXzZ?"))), x, |acc, item| {
str_concat::concat(acc, item).unwrap()
@ -209,6 +219,10 @@ pub fn binary_value(s: &str) -> IResult<&str, &str> {
}
pub fn octal_value(s: &str) -> IResult<&str, &str> {
ws(octal_value_impl)(s)
}
pub fn octal_value_impl(s: &str) -> IResult<&str, &str> {
let (s, x) = is_a("01234567xXzZ?")(s)?;
fold_many0(alt((tag("_"), is_a("01234567xXzZ?"))), x, |acc, item| {
str_concat::concat(acc, item).unwrap()
@ -216,6 +230,10 @@ pub fn octal_value(s: &str) -> IResult<&str, &str> {
}
pub fn hex_value(s: &str) -> IResult<&str, &str> {
ws(hex_value_impl)(s)
}
pub fn hex_value_impl(s: &str) -> IResult<&str, &str> {
let (s, x) = is_a("0123456789abcdefABCDEFxXzZ?")(s)?;
fold_many0(
alt((tag("_"), is_a("0123456789abcdefABCDEFxXzZ?"))),
@ -225,22 +243,42 @@ pub fn hex_value(s: &str) -> IResult<&str, &str> {
}
pub fn decimal_base(s: &str) -> IResult<&str, &str> {
ws(decimal_base_impl)(s)
}
pub fn decimal_base_impl(s: &str) -> IResult<&str, &str> {
alt((tag_no_case("'d"), tag_no_case("'sd")))(s)
}
pub fn binary_base(s: &str) -> IResult<&str, &str> {
ws(binary_base_impl)(s)
}
pub fn binary_base_impl(s: &str) -> IResult<&str, &str> {
alt((tag_no_case("'b"), tag_no_case("'sb")))(s)
}
pub fn octal_base(s: &str) -> IResult<&str, &str> {
ws(octal_base_impl)(s)
}
pub fn octal_base_impl(s: &str) -> IResult<&str, &str> {
alt((tag_no_case("'o"), tag_no_case("'so")))(s)
}
pub fn hex_base(s: &str) -> IResult<&str, &str> {
ws(hex_base_impl)(s)
}
pub fn hex_base_impl(s: &str) -> IResult<&str, &str> {
alt((tag_no_case("'h"), tag_no_case("'sh")))(s)
}
pub fn x_number(s: &str) -> IResult<&str, &str> {
ws(x_number_impl)(s)
}
pub fn x_number_impl(s: &str) -> IResult<&str, &str> {
let (s, x) = tag_no_case("x")(s)?;
fold_many0(alt((tag("_"), is_a("_"))), x, |acc, item| {
str_concat::concat(acc, item).unwrap()
@ -248,6 +286,10 @@ pub fn x_number(s: &str) -> IResult<&str, &str> {
}
pub fn z_number(s: &str) -> IResult<&str, &str> {
ws(z_number_impl)(s)
}
pub fn z_number_impl(s: &str) -> IResult<&str, &str> {
let (s, x) = alt((tag_no_case("z"), tag("?")))(s)?;
fold_many0(alt((tag("_"), is_a("_"))), x, |acc, item| {
str_concat::concat(acc, item).unwrap()
@ -255,7 +297,7 @@ pub fn z_number(s: &str) -> IResult<&str, &str> {
}
pub fn unbased_unsized_literal(s: &str) -> IResult<&str, &str> {
alt((tag("'0"), tag("'1"), tag("'z"), tag("'x")))(s)
alt((symbol("'0"), symbol("'1"), symbol("'z"), symbol("'x")))(s)
}
// -----------------------------------------------------------------------------

View File

@ -1,5 +1,5 @@
use crate::util::*;
use nom::branch::*;
use nom::bytes::complete::*;
use nom::IResult;
// -----------------------------------------------------------------------------
@ -13,17 +13,17 @@ pub struct Operator<'a> {
pub fn unary_operator(s: &str) -> IResult<&str, Operator> {
let (s, raw) = alt((
tag("+"),
tag("-"),
tag("!"),
tag("&"),
tag("|"),
tag("~&"),
tag("~|"),
tag("~^"),
tag("^~"),
tag("^"),
tag("~"),
symbol("+"),
symbol("-"),
symbol("!"),
symbol("&"),
symbol("|"),
symbol("~&"),
symbol("~|"),
symbol("~^"),
symbol("^~"),
symbol("^"),
symbol("~"),
))(s)?;
Ok((s, Operator { raw }))
}
@ -31,73 +31,73 @@ pub fn unary_operator(s: &str) -> IResult<&str, Operator> {
pub fn binary_operator(s: &str) -> IResult<&str, Operator> {
let (s, raw) = alt((
alt((
tag("+"),
tag("-"),
tag("**"),
tag("*"),
tag("/"),
tag("%"),
tag("==="),
tag("==?"),
tag("=="),
tag("!=="),
tag("!=?"),
tag("!="),
tag("&&"),
tag("||"),
symbol("+"),
symbol("-"),
symbol("**"),
symbol("*"),
symbol("/"),
symbol("%"),
symbol("==="),
symbol("==?"),
symbol("=="),
symbol("!=="),
symbol("!=?"),
symbol("!="),
symbol("&&"),
symbol("||"),
)),
alt((
tag("&"),
tag("|"),
tag("^~"),
tag("^"),
tag("~^"),
tag(">>>"),
tag(">>"),
tag("<<<"),
tag("<<"),
tag("->"),
tag("<->"),
tag("<="),
tag("<"),
tag(">="),
tag(">"),
symbol("&"),
symbol("|"),
symbol("^~"),
symbol("^"),
symbol("~^"),
symbol(">>>"),
symbol(">>"),
symbol("<<<"),
symbol("<<"),
symbol("->"),
symbol("<->"),
symbol("<="),
symbol("<"),
symbol(">="),
symbol(">"),
)),
))(s)?;
Ok((s, Operator { raw }))
}
pub fn inc_or_dec_operator(s: &str) -> IResult<&str, Operator> {
let (s, raw) = alt((tag("++"), tag("--")))(s)?;
let (s, raw) = alt((symbol("++"), symbol("--")))(s)?;
Ok((s, Operator { raw }))
}
pub fn unary_module_path_operator(s: &str) -> IResult<&str, Operator> {
let (s, raw) = alt((
tag("!"),
tag("&"),
tag("|"),
tag("~&"),
tag("~|"),
tag("~^"),
tag("^~"),
tag("^"),
tag("~"),
symbol("!"),
symbol("&"),
symbol("|"),
symbol("~&"),
symbol("~|"),
symbol("~^"),
symbol("^~"),
symbol("^"),
symbol("~"),
))(s)?;
Ok((s, Operator { raw }))
}
pub fn binary_module_path_operator(s: &str) -> IResult<&str, Operator> {
let (s, raw) = alt((
tag("=="),
tag("!="),
tag("&&"),
tag("||"),
tag("&"),
tag("|"),
tag("^~"),
tag("^"),
tag("~^"),
symbol("=="),
symbol("!="),
symbol("&&"),
symbol("||"),
symbol("&"),
symbol("|"),
symbol("^~"),
symbol("^"),
symbol("~^"),
))(s)?;
Ok((s, Operator { raw }))
}

View File

@ -6,7 +6,6 @@ use crate::strings::*;
use crate::subroutine_calls::*;
use crate::util::*;
use nom::branch::*;
use nom::bytes::complete::*;
use nom::combinator::*;
use nom::multi::*;
use nom::sequence::*;
@ -214,7 +213,7 @@ pub struct ConstantCast<'a> {
pub fn constant_primary(s: &str) -> IResult<&str, ConstantPrimary> {
alt((
map(tag("null"), |_| ConstantPrimary::Null),
map(symbol("null"), |_| ConstantPrimary::Null),
map(primary_literal, |x| ConstantPrimary::PrimaryLiteral(x)),
constant_primary_ps_parameter,
constant_primary_specparam,
@ -228,7 +227,7 @@ pub fn constant_primary(s: &str) -> IResult<&str, ConstantPrimary> {
ConstantPrimary::LetExpression(x)
}),
map(
delimited(tag("("), sp(constant_mintypmax_expression), sp(tag(")"))),
delimited(symbol("("), constant_mintypmax_expression, symbol(")")),
|x| ConstantPrimary::MintypmaxExpression(x),
),
map(constant_cast, |x| ConstantPrimary::Cast(x)),
@ -241,7 +240,7 @@ pub fn constant_primary(s: &str) -> IResult<&str, ConstantPrimary> {
pub fn constant_primary_ps_parameter(s: &str) -> IResult<&str, ConstantPrimary> {
let (s, identifier) = ps_parameter_identifier(s)?;
let (s, select) = sp(constant_select)(s)?;
let (s, select) = constant_select(s)?;
Ok((
s,
ConstantPrimary::PsParameter(ConstantPrimaryPsParameter { identifier, select }),
@ -251,9 +250,9 @@ pub fn constant_primary_ps_parameter(s: &str) -> IResult<&str, ConstantPrimary>
pub fn constant_primary_specparam(s: &str) -> IResult<&str, ConstantPrimary> {
let (s, identifier) = specparam_identifier(s)?;
let (s, range) = opt(delimited(
sp(tag("[")),
sp(constant_range_expression),
sp(tag("]")),
symbol("["),
constant_range_expression,
symbol("]"),
))(s)?;
Ok((
s,
@ -263,7 +262,7 @@ pub fn constant_primary_specparam(s: &str) -> IResult<&str, ConstantPrimary> {
pub fn constant_primary_formal_port(s: &str) -> IResult<&str, ConstantPrimary> {
let (s, identifier) = formal_port_identifier(s)?;
let (s, select) = sp(constant_select)(s)?;
let (s, select) = constant_select(s)?;
Ok((
s,
ConstantPrimary::FormalPort(ConstantPrimaryFormalPort { identifier, select }),
@ -272,7 +271,7 @@ pub fn constant_primary_formal_port(s: &str) -> IResult<&str, ConstantPrimary> {
pub fn constant_primary_enum(s: &str) -> IResult<&str, ConstantPrimary> {
let (s, scope) = alt((package_scope, class_scope))(s)?;
let (s, identifier) = sp(enum_identifier)(s)?;
let (s, identifier) = enum_identifier(s)?;
Ok((
s,
ConstantPrimary::Enum(ConstantPrimaryEnum { scope, identifier }),
@ -282,9 +281,9 @@ pub fn constant_primary_enum(s: &str) -> IResult<&str, ConstantPrimary> {
pub fn constant_primary_concatenation(s: &str) -> IResult<&str, ConstantPrimary> {
let (s, concatenation) = constant_concatenation(s)?;
let (s, range) = opt(delimited(
sp(tag("[")),
sp(constant_range_expression),
sp(tag("]")),
symbol("["),
constant_range_expression,
symbol("]"),
))(s)?;
Ok((
s,
@ -298,9 +297,9 @@ pub fn constant_primary_concatenation(s: &str) -> IResult<&str, ConstantPrimary>
pub fn constant_primary_multiple_concatenation(s: &str) -> IResult<&str, ConstantPrimary> {
let (s, concatenation) = constant_multiple_concatenation(s)?;
let (s, range) = opt(delimited(
sp(tag("[")),
sp(constant_range_expression),
sp(tag("]")),
symbol("["),
constant_range_expression,
symbol("]"),
))(s)?;
Ok((
s,
@ -312,7 +311,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(tag("("), sp(constant_mintypmax_expression), sp(tag(")")))(s)?;
let (s, x) = delimited(symbol("("), constant_mintypmax_expression, symbol(")"))(s)?;
Ok((s, ConstantPrimary::MintypmaxExpression(x)))
}
@ -330,7 +329,7 @@ pub fn module_path_primary(s: &str) -> IResult<&str, ModulePathPrimary> {
ModulePathPrimary::FunctionSubroutineCall(x)
}),
map(
delimited(tag("("), sp(module_path_mintypmax_expression), sp(tag(")"))),
delimited(symbol("("), module_path_mintypmax_expression, symbol(")")),
|x| ModulePathPrimary::ModulePathMintypmaxExpression(x),
),
))(s)
@ -349,7 +348,7 @@ pub fn primary(s: &str) -> IResult<&str, Primary> {
}),
map(let_expression, |x| Primary::LetExpression(x)),
map(
delimited(tag("("), sp(mintypmax_expression), sp(tag(")"))),
delimited(symbol("("), mintypmax_expression, symbol(")")),
|x| Primary::MintypmaxExpression(x),
),
map(cast, |x| Primary::Cast(x)),
@ -360,16 +359,16 @@ pub fn primary(s: &str) -> IResult<&str, Primary> {
Primary::StreamingConcatenation(x)
}),
map(sequence_method_call, |x| Primary::SequenceMethodCall(x)),
map(tag("this"), |_| Primary::This),
map(tag("$"), |_| Primary::Dollar),
map(tag("null"), |_| Primary::Null),
map(symbol("this"), |_| Primary::This),
map(symbol("$"), |_| Primary::Dollar),
map(symbol("null"), |_| Primary::Null),
))(s)
}
pub fn primary_hierarchical(s: &str) -> IResult<&str, Primary> {
let (s, qualifier) = opt(primary_hierarchical_qualifier)(s)?;
let (s, identifier) = sp(hierarchical_identifier)(s)?;
let (s, select) = sp(select)(s)?;
let (s, identifier) = hierarchical_identifier(s)?;
let (s, select) = select(s)?;
Ok((
s,
Primary::Hierarchical(PrimaryHierarchical {
@ -382,7 +381,7 @@ pub fn primary_hierarchical(s: &str) -> IResult<&str, Primary> {
pub fn primary_concatenation(s: &str) -> IResult<&str, Primary> {
let (s, concatenation) = concatenation(s)?;
let (s, range) = opt(sp(range_expression))(s)?;
let (s, range) = opt(range_expression)(s)?;
Ok((
s,
Primary::Concatenation(PrimaryConcatenation {
@ -394,7 +393,7 @@ pub fn primary_concatenation(s: &str) -> IResult<&str, Primary> {
pub fn primary_multiple_concatenation(s: &str) -> IResult<&str, Primary> {
let (s, concatenation) = multiple_concatenation(s)?;
let (s, range) = opt(sp(range_expression))(s)?;
let (s, range) = opt(range_expression)(s)?;
Ok((
s,
Primary::MultipleConcatenation(PrimaryMultipleConcatenation {
@ -416,10 +415,10 @@ pub fn primary_hierarchical_qualifier(s: &str) -> IResult<&str, PrimaryHierarchi
}
pub fn class_qualifier(s: &str) -> IResult<&str, ClassQualifier> {
let (s, local) = opt(tag("local::"))(s)?;
let (s, local) = opt(symbol("local::"))(s)?;
let (s, scope) = opt(alt((
terminated(sp(implicit_class_handle), sp(tag("."))),
sp(class_scope),
terminated(implicit_class_handle, symbol(".")),
class_scope,
)))(s)?;
Ok((
s,
@ -454,7 +453,7 @@ pub fn time_literal(s: &str) -> IResult<&str, TimeLiteral> {
pub fn unsigned_time_literal(s: &str) -> IResult<&str, TimeLiteral> {
let (s, number) = unsigned_number(s)?;
let (s, unit) = sp(time_unit)(s)?;
let (s, unit) = time_unit(s)?;
Ok((
s,
TimeLiteral::UnsignedTimeLiteral(UnsignedTimeLiteral { number, unit }),
@ -463,7 +462,7 @@ pub fn unsigned_time_literal(s: &str) -> IResult<&str, TimeLiteral> {
pub fn fixed_point_time_literal(s: &str) -> IResult<&str, TimeLiteral> {
let (s, number) = fixed_point_number(s)?;
let (s, unit) = sp(time_unit)(s)?;
let (s, unit) = time_unit(s)?;
Ok((
s,
TimeLiteral::FixedPointTimeLiteral(FixedPointTimeLiteral { number, unit }),
@ -472,12 +471,12 @@ pub fn fixed_point_time_literal(s: &str) -> IResult<&str, TimeLiteral> {
pub fn time_unit(s: &str) -> IResult<&str, TimeUnit> {
let (s, x) = alt((
tag("s"),
tag("ms"),
tag("us"),
tag("ns"),
tag("ps"),
tag("fs"),
symbol("s"),
symbol("ms"),
symbol("us"),
symbol("ns"),
symbol("ps"),
symbol("fs"),
))(s)?;
let unit = match x {
"s" => TimeUnit::S,
@ -493,30 +492,27 @@ pub fn time_unit(s: &str) -> IResult<&str, TimeUnit> {
pub fn implicit_class_handle(s: &str) -> IResult<&str, Scope> {
let (s, x) = alt((
map(tuple((tag("this"), sp(tag(".")), sp(tag("super")))), |_| {
ImplicitClassHandle::ThisSuper
}),
map(tag("this"), |_| ImplicitClassHandle::This),
map(tag("super"), |_| ImplicitClassHandle::Super),
map(
tuple((symbol("this"), symbol("."), symbol("super"))),
|_| ImplicitClassHandle::ThisSuper,
),
map(symbol("this"), |_| ImplicitClassHandle::This),
map(symbol("super"), |_| ImplicitClassHandle::Super),
))(s)?;
Ok((s, Scope::ImplicitClassHandle(x)))
}
pub fn bit_select(s: &str) -> IResult<&str, Vec<Expression>> {
many0(delimited(sp(tag("[")), sp(expression), sp(tag("]"))))(s)
many0(delimited(symbol("["), expression, symbol("]")))(s)
}
pub fn select(s: &str) -> IResult<&str, Select> {
let (s, member) = opt(pair(
many0(preceded(
sp(tag(".")),
pair(sp(member_identifier), sp(bit_select)),
)),
preceded(sp(tag(".")), sp(member_identifier)),
many0(preceded(symbol("."), pair(member_identifier, bit_select))),
preceded(symbol("."), member_identifier),
))(s)?;
let (s, bit_select) = sp(bit_select)(s)?;
let (s, part_select_range) =
opt(delimited(sp(tag("[")), sp(part_select_range), sp(tag("]"))))(s)?;
let (s, bit_select) = bit_select(s)?;
let (s, part_select_range) = opt(delimited(symbol("["), part_select_range, symbol("]")))(s)?;
let member = if let Some((upper, identifier)) = member {
Some(SelectMember { upper, identifier })
@ -536,13 +532,10 @@ pub fn select(s: &str) -> IResult<&str, Select> {
pub fn nonrange_select(s: &str) -> IResult<&str, Select> {
let (s, member) = opt(pair(
many0(preceded(
sp(tag(".")),
pair(sp(member_identifier), sp(bit_select)),
)),
preceded(sp(tag(".")), sp(member_identifier)),
many0(preceded(symbol("."), pair(member_identifier, bit_select))),
preceded(symbol("."), member_identifier),
))(s)?;
let (s, bit_select) = sp(bit_select)(s)?;
let (s, bit_select) = bit_select(s)?;
let member = if let Some((upper, identifier)) = member {
Some(SelectMember { upper, identifier })
@ -561,26 +554,19 @@ pub fn nonrange_select(s: &str) -> IResult<&str, Select> {
}
pub fn constant_bit_select(s: &str) -> IResult<&str, Vec<ConstantExpression>> {
many0(delimited(
sp(tag("[")),
sp(constant_expression),
sp(tag("]")),
))(s)
many0(delimited(symbol("["), constant_expression, symbol("]")))(s)
}
pub fn constant_select(s: &str) -> IResult<&str, ConstantSelect> {
let (s, member) = opt(pair(
many0(preceded(
sp(tag(".")),
pair(sp(member_identifier), sp(bit_select)),
)),
preceded(sp(tag(".")), sp(member_identifier)),
many0(preceded(symbol("."), pair(member_identifier, bit_select))),
preceded(symbol("."), member_identifier),
))(s)?;
let (s, bit_select) = sp(constant_bit_select)(s)?;
let (s, bit_select) = constant_bit_select(s)?;
let (s, part_select_range) = opt(delimited(
sp(tag("[")),
sp(constant_part_select_range),
sp(tag("]")),
symbol("["),
constant_part_select_range,
symbol("]"),
))(s)?;
let member = if let Some((upper, identifier)) = member {
@ -601,8 +587,8 @@ pub fn constant_select(s: &str) -> IResult<&str, ConstantSelect> {
pub fn constant_cast(s: &str) -> IResult<&str, ConstantCast> {
let (s, r#type) = casting_type(s)?;
let (s, _) = sp(tag("'"))(s)?;
let (s, expression) = delimited(sp(tag("(")), sp(constant_expression), sp(tag(")")))(s)?;
let (s, _) = symbol("'")(s)?;
let (s, expression) = delimited(symbol("("), constant_expression, symbol(")"))(s)?;
Ok((s, ConstantCast { r#type, expression }))
}
@ -612,8 +598,8 @@ pub fn constant_let_expression(s: &str) -> IResult<&str, LetExpression> {
pub fn cast(s: &str) -> IResult<&str, Cast> {
let (s, r#type) = casting_type(s)?;
let (s, _) = sp(tag("'"))(s)?;
let (s, expression) = delimited(sp(tag("(")), sp(expression), sp(tag(")")))(s)?;
let (s, _) = symbol("'")(s)?;
let (s, expression) = delimited(symbol("("), expression, symbol(")"))(s)?;
Ok((s, Cast { r#type, expression }))
}

View File

@ -1,3 +1,4 @@
use crate::util::*;
use nom::bytes::complete::*;
use nom::combinator::*;
use nom::multi::*;
@ -14,6 +15,10 @@ pub struct StringLiteral<'a> {
// -----------------------------------------------------------------------------
pub fn string_literal(s: &str) -> IResult<&str, StringLiteral> {
ws(string_literal_impl)(s)
}
pub fn string_literal_impl(s: &str) -> IResult<&str, StringLiteral> {
let (s, _) = tag("\"")(s)?;
let (s, x) = many1(pair(is_not("\\\""), opt(pair(tag("\\"), take(1usize)))))(s)?;
let (s, _) = tag("\"")(s)?;

View File

@ -4,7 +4,6 @@ use crate::identifiers::*;
use crate::primaries::*;
use crate::util::*;
use nom::branch::*;
use nom::bytes::complete::*;
use nom::combinator::*;
use nom::multi::*;
use nom::sequence::*;
@ -102,8 +101,8 @@ pub fn constant_function_call(s: &str) -> IResult<&str, SubroutineCall> {
pub fn tf_call(s: &str) -> IResult<&str, TfCall> {
let (s, identifier) = ps_or_hierarchical_tf_identifier(s)?;
let (s, attribute) = many0(sp(attribute_instance))(s)?;
let (s, argument) = opt(delimited(sp(tag("(")), sp(list_of_arguments), sp(tag(")"))))(s)?;
let (s, attribute) = many0(attribute_instance)(s)?;
let (s, argument) = opt(delimited(symbol("("), list_of_arguments, symbol(")")))(s)?;
Ok((
s,
TfCall {
@ -124,7 +123,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, identifier) = system_tf_identifier(s)?;
let (s, argument) = opt(delimited(sp(tag("(")), sp(list_of_arguments), sp(tag(")"))))(s)?;
let (s, argument) = opt(delimited(symbol("("), list_of_arguments, symbol(")")))(s)?;
Ok((
s,
SystemTfCall {
@ -139,10 +138,10 @@ pub fn system_tf_call_list_of_arguments(s: &str) -> IResult<&str, SystemTfCall>
pub fn system_tf_call_data_type(s: &str) -> IResult<&str, SystemTfCall> {
let (s, identifier) = system_tf_identifier(s)?;
let (s, _) = sp(tag("("))(s)?;
let (s, data_type) = sp(data_type)(s)?;
let (s, expression) = sp(preceded(sp(tag(",")), expression))(s)?;
let (s, _) = sp(tag(")"))(s)?;
let (s, _) = symbol("(")(s)?;
let (s, data_type) = data_type(s)?;
let (s, expression) = preceded(symbol(","), expression)(s)?;
let (s, _) = symbol(")")(s)?;
let data_type = Some(data_type);
let expression = Some(vec![expression]);
Ok((
@ -159,10 +158,10 @@ pub fn system_tf_call_data_type(s: &str) -> IResult<&str, SystemTfCall> {
pub fn system_tf_call_clocking_event(s: &str) -> IResult<&str, SystemTfCall> {
let (s, identifier) = system_tf_identifier(s)?;
let (s, _) = sp(tag("("))(s)?;
let (s, expression) = separated_nonempty_list(sp(tag(",")), sp(expression))(s)?;
let (s, clocking_event) = opt(preceded(sp(tag(",")), opt(sp(clocking_event))))(s)?;
let (s, _) = sp(tag(")"))(s)?;
let (s, _) = symbol("(")(s)?;
let (s, expression) = separated_nonempty_list(symbol(","), expression)(s)?;
let (s, clocking_event) = opt(preceded(symbol(","), opt(clocking_event)))(s)?;
let (s, _) = symbol(")")(s)?;
let expression = Some(expression);
let clocking_event = if let Some(Some(x)) = clocking_event {
Some(x)
@ -187,7 +186,7 @@ pub fn subroutine_call(s: &str) -> IResult<&str, SubroutineCall> {
map(system_tf_call, |x| SubroutineCall::SystemTf(Box::new(x))),
map(method_call, |x| SubroutineCall::Method(Box::new(x))),
map(
tuple((tag("std"), sp(tag("::")), randomize_call)),
tuple((symbol("std"), symbol("::"), randomize_call)),
|(_, _, x)| SubroutineCall::StdRandomize(Box::new(x)),
),
map(randomize_call, |x| SubroutineCall::Randomize(Box::new(x))),
@ -199,12 +198,12 @@ pub fn function_subroutine_call(s: &str) -> IResult<&str, SubroutineCall> {
}
pub fn list_of_arguments(s: &str) -> IResult<&str, ListOfArguments> {
let (s, unnamed) = separated_list(sp(tag(",")), sp(expression))(s)?;
let (s, unnamed) = separated_list(symbol(","), expression)(s)?;
let (s, named) = separated_list(
sp(tag(",")),
symbol(","),
pair(
preceded(tag("."), identifier),
delimited(sp(tag("(")), opt(sp(expression)), sp(tag(")"))),
preceded(symbol("."), identifier),
delimited(symbol("("), opt(expression), symbol(")")),
),
)(s)?;
Ok((s, ListOfArguments { unnamed, named }))
@ -212,7 +211,7 @@ pub fn list_of_arguments(s: &str) -> IResult<&str, ListOfArguments> {
pub fn method_call(s: &str) -> IResult<&str, MethodCall> {
let (s, root) = method_call_root(s)?;
let (s, _) = sp(tag("."))(s)?;
let (s, _) = symbol(".")(s)?;
let (s, body) = method_call_body(s)?;
Ok((s, MethodCall { root, body }))
@ -224,8 +223,8 @@ pub fn method_call_body(s: &str) -> IResult<&str, MethodCallBody> {
pub fn method_call_body_user(s: &str) -> IResult<&str, MethodCallBody> {
let (s, identifier) = method_identifier(s)?;
let (s, attribute) = many0(sp(attribute_instance))(s)?;
let (s, argument) = opt(delimited(sp(tag("(")), sp(list_of_arguments), sp(tag(")"))))(s)?;
let (s, attribute) = many0(attribute_instance)(s)?;
let (s, argument) = opt(delimited(symbol("("), list_of_arguments, symbol(")")))(s)?;
Ok((
s,
MethodCallBody::User(MethodCallBodyUser {
@ -245,11 +244,11 @@ pub fn built_in_method_call(s: &str) -> IResult<&str, MethodCallBody> {
pub fn array_manipulation_call(s: &str) -> IResult<&str, ArrayManipulationCall> {
let (s, name) = array_method_name(s)?;
let (s, attribute) = many0(sp(attribute_instance))(s)?;
let (s, argument) = opt(delimited(sp(tag("(")), sp(list_of_arguments), sp(tag(")"))))(s)?;
let (s, attribute) = many0(attribute_instance)(s)?;
let (s, argument) = opt(delimited(symbol("("), list_of_arguments, symbol(")")))(s)?;
let (s, with) = opt(preceded(
sp(tag("with")),
delimited(sp(tag("(")), sp(expression), sp(tag(")"))),
symbol("with"),
delimited(symbol("("), expression, symbol(")")),
))(s)?;
Ok((
s,
@ -263,23 +262,19 @@ pub fn array_manipulation_call(s: &str) -> IResult<&str, ArrayManipulationCall>
}
pub fn randomize_call(s: &str) -> IResult<&str, RandomizeCall> {
let (s, _) = tag("randomize")(s)?;
let (s, attribute) = many0(sp(attribute_instance))(s)?;
let (s, _) = symbol("randomize")(s)?;
let (s, attribute) = many0(attribute_instance)(s)?;
let (s, argument) = opt(delimited(
sp(tag("(")),
symbol("("),
opt(alt((
sp(variable_identifier_list),
map(sp(tag("null")), |_| vec![]),
variable_identifier_list,
map(symbol("null"), |_| vec![]),
))),
sp(tag(")")),
symbol(")"),
))(s)?;
let (s, with) = opt(tuple((
sp(tag("with")),
opt(delimited(
sp(tag("(")),
opt(sp(identifier_list)),
sp(tag(")")),
)),
symbol("with"),
opt(delimited(symbol("("), opt(identifier_list), symbol(")"))),
constraint_block,
)))(s)?;
let argument = if let Some(Some(x)) = argument {
@ -314,10 +309,10 @@ pub fn method_call_root(s: &str) -> IResult<&str, MethodCallRoot> {
pub fn array_method_name(s: &str) -> IResult<&str, ArrayMethodName> {
alt((
map(tag("unique"), |_| ArrayMethodName::Unique),
map(tag("and"), |_| ArrayMethodName::And),
map(tag("or"), |_| ArrayMethodName::Or),
map(tag("xor"), |_| ArrayMethodName::Xor),
map(symbol("unique"), |_| ArrayMethodName::Unique),
map(symbol("and"), |_| ArrayMethodName::And),
map(symbol("or"), |_| ArrayMethodName::Or),
map(symbol("xor"), |_| ArrayMethodName::Xor),
map(method_identifier, |x| ArrayMethodName::Identifier(x)),
))(s)
}

View File

@ -1,20 +1,26 @@
use crate::identifiers::*;
use nom::bytes::complete::*;
use nom::character::complete::*;
use nom::IResult;
// -----------------------------------------------------------------------------
pub fn sp<'a, O, F>(f: F) -> impl Fn(&'a str) -> IResult<&'a str, O>
pub fn ws<'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, _) = space0(s)?;
let (s, x) = f(s)?;
let (s, _) = space0(s)?;
Ok((s, x))
}
}
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)
}
// -----------------------------------------------------------------------------
#[derive(Debug)]