Refactor numbers
This commit is contained in:
parent
4b4b78be49
commit
0e88bda969
@ -96,7 +96,7 @@ pub struct ClockingDrive<'a> {
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum CycleDelay<'a> {
|
pub enum CycleDelay<'a> {
|
||||||
Number(Number<'a>),
|
IntegralNumber(IntegralNumber<'a>),
|
||||||
Identifier(Identifier<'a>),
|
Identifier(Identifier<'a>),
|
||||||
Expression(Expression<'a>),
|
Expression(Expression<'a>),
|
||||||
}
|
}
|
||||||
@ -280,7 +280,7 @@ pub fn clocking_drive(s: &str) -> IResult<&str, ClockingDrive> {
|
|||||||
pub fn cycle_delay(s: &str) -> IResult<&str, CycleDelay> {
|
pub fn cycle_delay(s: &str) -> IResult<&str, CycleDelay> {
|
||||||
alt((
|
alt((
|
||||||
map(preceded(symbol("##"), integral_number), |x| {
|
map(preceded(symbol("##"), integral_number), |x| {
|
||||||
CycleDelay::Number(x)
|
CycleDelay::IntegralNumber(x)
|
||||||
}),
|
}),
|
||||||
map(preceded(symbol("##"), identifier), |x| {
|
map(preceded(symbol("##"), identifier), |x| {
|
||||||
CycleDelay::Identifier(x)
|
CycleDelay::Identifier(x)
|
||||||
|
@ -39,8 +39,8 @@ pub enum RsProductionList<'a> {
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum WeightSpecification<'a> {
|
pub enum WeightSpecification<'a> {
|
||||||
Number(Number<'a>),
|
IntegralNumber(IntegralNumber<'a>),
|
||||||
Identifier(PsIdentifier<'a>),
|
PsIdentifier(PsIdentifier<'a>),
|
||||||
Expression(Expression<'a>),
|
Expression(Expression<'a>),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,8 +165,8 @@ pub fn rs_production_list_join(s: &str) -> IResult<&str, RsProductionList> {
|
|||||||
|
|
||||||
pub fn weight_specification(s: &str) -> IResult<&str, WeightSpecification> {
|
pub fn weight_specification(s: &str) -> IResult<&str, WeightSpecification> {
|
||||||
alt((
|
alt((
|
||||||
map(integral_number, |x| WeightSpecification::Number(x)),
|
map(integral_number, |x| WeightSpecification::IntegralNumber(x)),
|
||||||
map(ps_identifier, |x| WeightSpecification::Identifier(x)),
|
map(ps_identifier, |x| WeightSpecification::PsIdentifier(x)),
|
||||||
map(paren(expression), |x| WeightSpecification::Expression(x)),
|
map(paren(expression), |x| WeightSpecification::Expression(x)),
|
||||||
))(s)
|
))(s)
|
||||||
}
|
}
|
||||||
|
@ -218,7 +218,7 @@ pub enum ModulePathMintypmaxExpression<'a> {
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum PartSelectRange<'a> {
|
pub enum PartSelectRange<'a> {
|
||||||
Range((ConstantExpression<'a>, ConstantExpression<'a>)),
|
Range((ConstantExpression<'a>, ConstantExpression<'a>)),
|
||||||
IndexedRange((Expression<'a>, &'a str, ConstantExpression<'a>)),
|
IndexedRange((Expression<'a>, Symbol<'a>, ConstantExpression<'a>)),
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
@ -21,241 +21,392 @@ pub enum IntegralNumber<'a> {
|
|||||||
OctalNumber(OctalNumber<'a>),
|
OctalNumber(OctalNumber<'a>),
|
||||||
BinaryNumber(BinaryNumber<'a>),
|
BinaryNumber(BinaryNumber<'a>),
|
||||||
HexNumber(HexNumber<'a>),
|
HexNumber(HexNumber<'a>),
|
||||||
UnsignedNumber(&'a str),
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum DecimalNumber<'a> {
|
||||||
|
UnsignedNumber(UnsignedNumber<'a>),
|
||||||
|
BaseUnsigned(DecimalNumberBaseUnsigned<'a>),
|
||||||
|
BaseXNumber(DecimalNumberBaseXNumber<'a>),
|
||||||
|
BaseZNumber(DecimalNumberBaseZNumber<'a>),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct DecimalNumberBaseUnsigned<'a> {
|
||||||
|
pub nodes: (Option<Size<'a>>, DecimalBase<'a>, UnsignedNumber<'a>),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct DecimalNumberBaseXNumber<'a> {
|
||||||
|
pub nodes: (Option<Size<'a>>, DecimalBase<'a>, XNumber<'a>),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct DecimalNumberBaseZNumber<'a> {
|
||||||
|
pub nodes: (Option<Size<'a>>, DecimalBase<'a>, ZNumber<'a>),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct BinaryNumber<'a> {
|
||||||
|
pub nodes: (Option<Size<'a>>, BinaryBase<'a>, BinaryValue<'a>),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct OctalNumber<'a> {
|
||||||
|
pub nodes: (Option<Size<'a>>, OctalBase<'a>, OctalValue<'a>),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct HexNumber<'a> {
|
||||||
|
pub nodes: (Option<Size<'a>>, HexBase<'a>, HexValue<'a>),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum Sign<'a> {
|
||||||
|
Plus(Symbol<'a>),
|
||||||
|
Minus(Symbol<'a>),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct Size<'a> {
|
||||||
|
pub nodes: (NonZeroUnsignedNumber<'a>,),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct NonZeroUnsignedNumber<'a> {
|
||||||
|
pub nodes: (&'a str,),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum RealNumber<'a> {
|
pub enum RealNumber<'a> {
|
||||||
FixedPointNumber(FixedPointNumber<'a>),
|
FixedPointNumber(FixedPointNumber<'a>),
|
||||||
FloatingPointNumber(FloatingPointNumber<'a>),
|
Floating(RealNumberFloating<'a>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct DecimalNumber<'a> {
|
pub struct RealNumberFloating<'a> {
|
||||||
pub nodes: (Option<&'a str>, &'a str, &'a str),
|
pub nodes: (
|
||||||
}
|
UnsignedNumber<'a>,
|
||||||
|
Option<(Symbol<'a>, UnsignedNumber<'a>)>,
|
||||||
#[derive(Debug)]
|
Exp<'a>,
|
||||||
pub struct BinaryNumber<'a> {
|
Option<Sign<'a>>,
|
||||||
pub nodes: (Option<&'a str>, &'a str, &'a str),
|
UnsignedNumber<'a>,
|
||||||
}
|
),
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct OctalNumber<'a> {
|
|
||||||
pub nodes: (Option<&'a str>, &'a str, &'a str),
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct HexNumber<'a> {
|
|
||||||
pub nodes: (Option<&'a str>, &'a str, &'a str),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct FixedPointNumber<'a> {
|
pub struct FixedPointNumber<'a> {
|
||||||
pub nodes: (&'a str, &'a str),
|
pub nodes: (UnsignedNumber<'a>, Symbol<'a>, UnsignedNumber<'a>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct FloatingPointNumber<'a> {
|
pub struct Exp<'a> {
|
||||||
pub nodes: (&'a str, Option<&'a str>, &'a str, Option<&'a str>, &'a str),
|
pub nodes: (Symbol<'a>,),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct UnsignedNumber<'a> {
|
||||||
|
pub nodes: (&'a str,),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct BinaryValue<'a> {
|
||||||
|
pub nodes: (&'a str,),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct OctalValue<'a> {
|
||||||
|
pub nodes: (&'a str,),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct HexValue<'a> {
|
||||||
|
pub nodes: (&'a str,),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct DecimalBase<'a> {
|
||||||
|
pub nodes: (&'a str,),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct BinaryBase<'a> {
|
||||||
|
pub nodes: (&'a str,),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct OctalBase<'a> {
|
||||||
|
pub nodes: (&'a str,),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct HexBase<'a> {
|
||||||
|
pub nodes: (&'a str,),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct XNumber<'a> {
|
||||||
|
pub nodes: (&'a str,),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct ZNumber<'a> {
|
||||||
|
pub nodes: (&'a str,),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct UnbasedUnsizedLiteral<'a> {
|
||||||
|
pub nodes: (Symbol<'a>,),
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
pub fn number(s: &str) -> IResult<&str, Number> {
|
pub fn number(s: &str) -> IResult<&str, Number> {
|
||||||
alt((real_number, integral_number))(s)
|
alt((
|
||||||
|
map(real_number, |x| Number::RealNumber(x)),
|
||||||
|
map(integral_number, |x| Number::IntegralNumber(x)),
|
||||||
|
))(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn integral_number(s: &str) -> IResult<&str, Number> {
|
pub fn integral_number(s: &str) -> IResult<&str, IntegralNumber> {
|
||||||
let (s, x) = alt((
|
alt((
|
||||||
octal_number,
|
map(octal_number, |x| IntegralNumber::OctalNumber(x)),
|
||||||
binary_number,
|
map(binary_number, |x| IntegralNumber::BinaryNumber(x)),
|
||||||
hex_number,
|
map(hex_number, |x| IntegralNumber::HexNumber(x)),
|
||||||
decimal_number,
|
map(decimal_number, |x| IntegralNumber::DecimalNumber(x)),
|
||||||
integral_unsigned_number,
|
))(s)
|
||||||
))(s)?;
|
|
||||||
Ok((s, Number::IntegralNumber(x)))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn decimal_number(s: &str) -> IResult<&str, IntegralNumber> {
|
pub fn decimal_number(s: &str) -> IResult<&str, DecimalNumber> {
|
||||||
let (s, (x, y, z)) = tuple((
|
alt((
|
||||||
opt(size),
|
map(unsigned_number, |x| DecimalNumber::UnsignedNumber(x)),
|
||||||
decimal_base,
|
decimal_number_base_unsigned,
|
||||||
alt((unsigned_number, x_number, z_number)),
|
decimal_number_base_x_number,
|
||||||
))(s)?;
|
decimal_number_base_z_number,
|
||||||
|
))(s)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn decimal_number_base_unsigned(s: &str) -> IResult<&str, DecimalNumber> {
|
||||||
|
let (s, a) = opt(size)(s)?;
|
||||||
|
let (s, b) = decimal_base(s)?;
|
||||||
|
let (s, c) = unsigned_number(s)?;
|
||||||
Ok((
|
Ok((
|
||||||
s,
|
s,
|
||||||
IntegralNumber::DecimalNumber(DecimalNumber { nodes: (x, y, z) }),
|
DecimalNumber::BaseUnsigned(DecimalNumberBaseUnsigned { nodes: (a, b, c) }),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn integral_unsigned_number(s: &str) -> IResult<&str, IntegralNumber> {
|
pub fn decimal_number_base_x_number(s: &str) -> IResult<&str, DecimalNumber> {
|
||||||
let (s, x) = unsigned_number(s)?;
|
let (s, a) = opt(size)(s)?;
|
||||||
Ok((s, IntegralNumber::UnsignedNumber(x)))
|
let (s, b) = decimal_base(s)?;
|
||||||
}
|
let (s, c) = x_number(s)?;
|
||||||
|
|
||||||
pub fn binary_number(s: &str) -> IResult<&str, IntegralNumber> {
|
|
||||||
let (s, (x, y, z)) = tuple((opt(size), binary_base, binary_value))(s)?;
|
|
||||||
Ok((
|
Ok((
|
||||||
s,
|
s,
|
||||||
IntegralNumber::BinaryNumber(BinaryNumber { nodes: (x, y, z) }),
|
DecimalNumber::BaseXNumber(DecimalNumberBaseXNumber { nodes: (a, b, c) }),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn octal_number(s: &str) -> IResult<&str, IntegralNumber> {
|
pub fn decimal_number_base_z_number(s: &str) -> IResult<&str, DecimalNumber> {
|
||||||
let (s, (x, y, z)) = tuple((opt(size), octal_base, octal_value))(s)?;
|
let (s, a) = opt(size)(s)?;
|
||||||
|
let (s, b) = decimal_base(s)?;
|
||||||
|
let (s, c) = z_number(s)?;
|
||||||
Ok((
|
Ok((
|
||||||
s,
|
s,
|
||||||
IntegralNumber::OctalNumber(OctalNumber { nodes: (x, y, z) }),
|
DecimalNumber::BaseZNumber(DecimalNumberBaseZNumber { nodes: (a, b, c) }),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn hex_number(s: &str) -> IResult<&str, IntegralNumber> {
|
pub fn binary_number(s: &str) -> IResult<&str, BinaryNumber> {
|
||||||
let (s, (x, y, z)) = tuple((opt(size), hex_base, hex_value))(s)?;
|
let (s, a) = opt(size)(s)?;
|
||||||
Ok((s, IntegralNumber::HexNumber(HexNumber { nodes: (x, y, z) })))
|
let (s, b) = binary_base(s)?;
|
||||||
|
let (s, c) = binary_value(s)?;
|
||||||
|
Ok((s, BinaryNumber { nodes: (a, b, c) }))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn size(s: &str) -> IResult<&str, &str> {
|
pub fn octal_number(s: &str) -> IResult<&str, OctalNumber> {
|
||||||
ws(size_impl)(s)
|
let (s, a) = opt(size)(s)?;
|
||||||
|
let (s, b) = octal_base(s)?;
|
||||||
|
let (s, c) = octal_value(s)?;
|
||||||
|
Ok((s, OctalNumber { nodes: (a, b, c) }))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn size_impl(s: &str) -> IResult<&str, &str> {
|
pub fn hex_number(s: &str) -> IResult<&str, HexNumber> {
|
||||||
let (s, x) = is_a("123456789")(s)?;
|
let (s, a) = opt(size)(s)?;
|
||||||
fold_many0(alt((tag("_"), digit1)), x, |acc, item| {
|
let (s, b) = hex_base(s)?;
|
||||||
|
let (s, c) = hex_value(s)?;
|
||||||
|
Ok((s, HexNumber { nodes: (a, b, c) }))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn sign(s: &str) -> IResult<&str, Sign> {
|
||||||
|
alt((
|
||||||
|
map(symbol("+"), |x| Sign::Plus(x)),
|
||||||
|
map(symbol("-"), |x| Sign::Minus(x)),
|
||||||
|
))(s)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn size(s: &str) -> IResult<&str, Size> {
|
||||||
|
let (s, a) = non_zero_unsigned_number(s)?;
|
||||||
|
Ok((s, Size { nodes: (a,) }))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn non_zero_unsigned_number(s: &str) -> IResult<&str, NonZeroUnsignedNumber> {
|
||||||
|
let (s, a) = ws(non_zero_unsigned_number_impl)(s)?;
|
||||||
|
Ok((s, NonZeroUnsignedNumber { nodes: (a,) }))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn non_zero_unsigned_number_impl(s: &str) -> IResult<&str, &str> {
|
||||||
|
let (s, a) = is_a("123456789")(s)?;
|
||||||
|
fold_many0(alt((tag("_"), digit1)), a, |acc, item| {
|
||||||
str_concat::concat(acc, item).unwrap()
|
str_concat::concat(acc, item).unwrap()
|
||||||
})(s)
|
})(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn real_number(s: &str) -> IResult<&str, Number> {
|
pub fn real_number(s: &str) -> IResult<&str, RealNumber> {
|
||||||
let (s, x) = alt((floating_point_number, fixed_point_number))(s)?;
|
alt((
|
||||||
Ok((s, Number::RealNumber(x)))
|
real_number_floating,
|
||||||
|
map(fixed_point_number, |x| RealNumber::FixedPointNumber(x)),
|
||||||
|
))(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fixed_point_number(s: &str) -> IResult<&str, RealNumber> {
|
pub fn real_number_floating(s: &str) -> IResult<&str, RealNumber> {
|
||||||
let (s, (x, _, y)) = tuple((unsigned_number, symbol("."), unsigned_number))(s)?;
|
let (s, a) = unsigned_number(s)?;
|
||||||
|
let (s, b) = opt(pair(symbol("."), unsigned_number))(s)?;
|
||||||
|
let (s, c) = exp(s)?;
|
||||||
|
let (s, d) = opt(sign)(s)?;
|
||||||
|
let (s, e) = unsigned_number(s)?;
|
||||||
Ok((
|
Ok((
|
||||||
s,
|
s,
|
||||||
RealNumber::FixedPointNumber(FixedPointNumber { nodes: (x, y) }),
|
RealNumber::Floating(RealNumberFloating {
|
||||||
))
|
nodes: (a, b, c, d, e),
|
||||||
}
|
|
||||||
|
|
||||||
pub fn floating_point_number(s: &str) -> IResult<&str, RealNumber> {
|
|
||||||
let (s, x) = unsigned_number(s)?;
|
|
||||||
let (s, y) = opt(preceded(symbol("."), unsigned_number))(s)?;
|
|
||||||
let (s, z) = alt((symbol("e"), symbol("E")))(s)?;
|
|
||||||
let (s, v) = opt(alt((symbol("+"), symbol("-"))))(s)?;
|
|
||||||
let (s, w) = unsigned_number(s)?;
|
|
||||||
|
|
||||||
Ok((
|
|
||||||
s,
|
|
||||||
RealNumber::FloatingPointNumber(FloatingPointNumber {
|
|
||||||
nodes: (x, y, z, v, w),
|
|
||||||
}),
|
}),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn unsigned_number(s: &str) -> IResult<&str, &str> {
|
pub fn fixed_point_number(s: &str) -> IResult<&str, FixedPointNumber> {
|
||||||
ws(unsigned_number_impl)(s)
|
let (s, a) = unsigned_number(s)?;
|
||||||
|
let (s, b) = map(tag("."), |x| Symbol { nodes: (x,) })(s)?;;
|
||||||
|
let (s, c) = unsigned_number(s)?;
|
||||||
|
Ok((s, FixedPointNumber { nodes: (a, b, c) }))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn exp(s: &str) -> IResult<&str, Exp> {
|
||||||
|
let (s, a) = alt((symbol("e"), symbol("E")))(s)?;
|
||||||
|
Ok((s, Exp { nodes: (a,) }))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn unsigned_number(s: &str) -> IResult<&str, UnsignedNumber> {
|
||||||
|
let (s, a) = ws(unsigned_number_impl)(s)?;
|
||||||
|
Ok((s, UnsignedNumber { nodes: (a,) }))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn unsigned_number_impl(s: &str) -> IResult<&str, &str> {
|
pub fn unsigned_number_impl(s: &str) -> IResult<&str, &str> {
|
||||||
let (s, x) = digit1(s)?;
|
let (s, a) = digit1(s)?;
|
||||||
fold_many0(alt((tag("_"), digit1)), x, |acc, item| {
|
fold_many0(alt((tag("_"), digit1)), a, |acc, item| {
|
||||||
str_concat::concat(acc, item).unwrap()
|
str_concat::concat(acc, item).unwrap()
|
||||||
})(s)
|
})(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn binary_value(s: &str) -> IResult<&str, &str> {
|
pub fn binary_value(s: &str) -> IResult<&str, BinaryValue> {
|
||||||
ws(binary_value_impl)(s)
|
let (s, a) = ws(binary_value_impl)(s)?;
|
||||||
|
Ok((s, BinaryValue { nodes: (a,) }))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn binary_value_impl(s: &str) -> IResult<&str, &str> {
|
pub fn binary_value_impl(s: &str) -> IResult<&str, &str> {
|
||||||
let (s, x) = is_a("01xXzZ?")(s)?;
|
let (s, a) = is_a("01xXzZ?")(s)?;
|
||||||
fold_many0(alt((tag("_"), is_a("01xXzZ?"))), x, |acc, item| {
|
fold_many0(alt((tag("_"), is_a("01xXzZ?"))), a, |acc, item| {
|
||||||
str_concat::concat(acc, item).unwrap()
|
str_concat::concat(acc, item).unwrap()
|
||||||
})(s)
|
})(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn octal_value(s: &str) -> IResult<&str, &str> {
|
pub fn octal_value(s: &str) -> IResult<&str, OctalValue> {
|
||||||
ws(octal_value_impl)(s)
|
let (s, a) = ws(octal_value_impl)(s)?;
|
||||||
|
Ok((s, OctalValue { nodes: (a,) }))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn octal_value_impl(s: &str) -> IResult<&str, &str> {
|
pub fn octal_value_impl(s: &str) -> IResult<&str, &str> {
|
||||||
let (s, x) = is_a("01234567xXzZ?")(s)?;
|
let (s, a) = is_a("01234567xXzZ?")(s)?;
|
||||||
fold_many0(alt((tag("_"), is_a("01234567xXzZ?"))), x, |acc, item| {
|
fold_many0(alt((tag("_"), is_a("01234567xXzZ?"))), a, |acc, item| {
|
||||||
str_concat::concat(acc, item).unwrap()
|
str_concat::concat(acc, item).unwrap()
|
||||||
})(s)
|
})(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn hex_value(s: &str) -> IResult<&str, &str> {
|
pub fn hex_value(s: &str) -> IResult<&str, HexValue> {
|
||||||
ws(hex_value_impl)(s)
|
let (s, a) = ws(hex_value_impl)(s)?;
|
||||||
|
Ok((s, HexValue { nodes: (a,) }))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn hex_value_impl(s: &str) -> IResult<&str, &str> {
|
pub fn hex_value_impl(s: &str) -> IResult<&str, &str> {
|
||||||
let (s, x) = is_a("0123456789abcdefABCDEFxXzZ?")(s)?;
|
let (s, a) = is_a("0123456789abcdefABCDEFxXzZ?")(s)?;
|
||||||
fold_many0(
|
fold_many0(
|
||||||
alt((tag("_"), is_a("0123456789abcdefABCDEFxXzZ?"))),
|
alt((tag("_"), is_a("0123456789abcdefABCDEFxXzZ?"))),
|
||||||
x,
|
a,
|
||||||
|acc, item| str_concat::concat(acc, item).unwrap(),
|
|acc, item| str_concat::concat(acc, item).unwrap(),
|
||||||
)(s)
|
)(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn decimal_base(s: &str) -> IResult<&str, &str> {
|
pub fn decimal_base(s: &str) -> IResult<&str, DecimalBase> {
|
||||||
ws(decimal_base_impl)(s)
|
let (s, a) = ws(decimal_base_impl)(s)?;
|
||||||
|
Ok((s, DecimalBase { nodes: (a,) }))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn decimal_base_impl(s: &str) -> IResult<&str, &str> {
|
pub fn decimal_base_impl(s: &str) -> IResult<&str, &str> {
|
||||||
alt((tag_no_case("'d"), tag_no_case("'sd")))(s)
|
alt((tag_no_case("'d"), tag_no_case("'sd")))(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn binary_base(s: &str) -> IResult<&str, &str> {
|
pub fn binary_base(s: &str) -> IResult<&str, BinaryBase> {
|
||||||
ws(binary_base_impl)(s)
|
let (s, a) = ws(binary_base_impl)(s)?;
|
||||||
|
Ok((s, BinaryBase { nodes: (a,) }))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn binary_base_impl(s: &str) -> IResult<&str, &str> {
|
pub fn binary_base_impl(s: &str) -> IResult<&str, &str> {
|
||||||
alt((tag_no_case("'b"), tag_no_case("'sb")))(s)
|
alt((tag_no_case("'b"), tag_no_case("'sb")))(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn octal_base(s: &str) -> IResult<&str, &str> {
|
pub fn octal_base(s: &str) -> IResult<&str, OctalBase> {
|
||||||
ws(octal_base_impl)(s)
|
let (s, a) = ws(octal_base_impl)(s)?;
|
||||||
|
Ok((s, OctalBase { nodes: (a,) }))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn octal_base_impl(s: &str) -> IResult<&str, &str> {
|
pub fn octal_base_impl(s: &str) -> IResult<&str, &str> {
|
||||||
alt((tag_no_case("'o"), tag_no_case("'so")))(s)
|
alt((tag_no_case("'o"), tag_no_case("'so")))(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn hex_base(s: &str) -> IResult<&str, &str> {
|
pub fn hex_base(s: &str) -> IResult<&str, HexBase> {
|
||||||
ws(hex_base_impl)(s)
|
let (s, a) = ws(hex_base_impl)(s)?;
|
||||||
|
Ok((s, HexBase { nodes: (a,) }))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn hex_base_impl(s: &str) -> IResult<&str, &str> {
|
pub fn hex_base_impl(s: &str) -> IResult<&str, &str> {
|
||||||
alt((tag_no_case("'h"), tag_no_case("'sh")))(s)
|
alt((tag_no_case("'h"), tag_no_case("'sh")))(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn x_number(s: &str) -> IResult<&str, &str> {
|
pub fn x_number(s: &str) -> IResult<&str, XNumber> {
|
||||||
ws(x_number_impl)(s)
|
let (s, a) = ws(x_number_impl)(s)?;
|
||||||
|
Ok((s, XNumber { nodes: (a,) }))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn x_number_impl(s: &str) -> IResult<&str, &str> {
|
pub fn x_number_impl(s: &str) -> IResult<&str, &str> {
|
||||||
let (s, x) = tag_no_case("x")(s)?;
|
let (s, a) = tag_no_case("x")(s)?;
|
||||||
fold_many0(alt((tag("_"), is_a("_"))), x, |acc, item| {
|
fold_many0(alt((tag("_"), is_a("_"))), a, |acc, item| {
|
||||||
str_concat::concat(acc, item).unwrap()
|
str_concat::concat(acc, item).unwrap()
|
||||||
})(s)
|
})(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn z_number(s: &str) -> IResult<&str, &str> {
|
pub fn z_number(s: &str) -> IResult<&str, ZNumber> {
|
||||||
ws(z_number_impl)(s)
|
let (s, a) = ws(z_number_impl)(s)?;
|
||||||
|
Ok((s, ZNumber { nodes: (a,) }))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn z_number_impl(s: &str) -> IResult<&str, &str> {
|
pub fn z_number_impl(s: &str) -> IResult<&str, &str> {
|
||||||
let (s, x) = alt((tag_no_case("z"), tag("?")))(s)?;
|
let (s, a) = alt((tag_no_case("z"), tag("?")))(s)?;
|
||||||
fold_many0(alt((tag("_"), is_a("_"))), x, |acc, item| {
|
fold_many0(alt((tag("_"), is_a("_"))), a, |acc, item| {
|
||||||
str_concat::concat(acc, item).unwrap()
|
str_concat::concat(acc, item).unwrap()
|
||||||
})(s)
|
})(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn unbased_unsized_literal(s: &str) -> IResult<&str, &str> {
|
pub fn unbased_unsized_literal(s: &str) -> IResult<&str, UnbasedUnsizedLiteral> {
|
||||||
alt((symbol("'0"), symbol("'1"), symbol("'z"), symbol("'x")))(s)
|
let (s, a) = alt((symbol("'0"), symbol("'1"), symbol("'z"), symbol("'x")))(s)?;
|
||||||
|
Ok((s, UnbasedUnsizedLiteral { nodes: (a,) }))
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
@ -6,13 +6,13 @@ use nom::IResult;
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Operator<'a> {
|
pub struct Operator<'a> {
|
||||||
pub nodes: (&'a str,),
|
pub nodes: (Symbol<'a>,),
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
pub fn unary_operator(s: &str) -> IResult<&str, Operator> {
|
pub fn unary_operator(s: &str) -> IResult<&str, Operator> {
|
||||||
let (s, x) = alt((
|
let (s, a) = alt((
|
||||||
symbol("+"),
|
symbol("+"),
|
||||||
symbol("-"),
|
symbol("-"),
|
||||||
symbol("!"),
|
symbol("!"),
|
||||||
@ -25,11 +25,11 @@ pub fn unary_operator(s: &str) -> IResult<&str, Operator> {
|
|||||||
symbol("^"),
|
symbol("^"),
|
||||||
symbol("~"),
|
symbol("~"),
|
||||||
))(s)?;
|
))(s)?;
|
||||||
Ok((s, Operator { nodes: (x,) }))
|
Ok((s, Operator { nodes: (a,) }))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn binary_operator(s: &str) -> IResult<&str, Operator> {
|
pub fn binary_operator(s: &str) -> IResult<&str, Operator> {
|
||||||
let (s, x) = alt((
|
let (s, a) = alt((
|
||||||
alt((
|
alt((
|
||||||
symbol("+"),
|
symbol("+"),
|
||||||
symbol("-"),
|
symbol("-"),
|
||||||
@ -64,16 +64,16 @@ pub fn binary_operator(s: &str) -> IResult<&str, Operator> {
|
|||||||
symbol(">"),
|
symbol(">"),
|
||||||
)),
|
)),
|
||||||
))(s)?;
|
))(s)?;
|
||||||
Ok((s, Operator { nodes: (x,) }))
|
Ok((s, Operator { nodes: (a,) }))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn inc_or_dec_operator(s: &str) -> IResult<&str, Operator> {
|
pub fn inc_or_dec_operator(s: &str) -> IResult<&str, Operator> {
|
||||||
let (s, x) = alt((symbol("++"), symbol("--")))(s)?;
|
let (s, a) = alt((symbol("++"), symbol("--")))(s)?;
|
||||||
Ok((s, Operator { nodes: (x,) }))
|
Ok((s, Operator { nodes: (a,) }))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn unary_module_path_operator(s: &str) -> IResult<&str, Operator> {
|
pub fn unary_module_path_operator(s: &str) -> IResult<&str, Operator> {
|
||||||
let (s, x) = alt((
|
let (s, a) = alt((
|
||||||
symbol("!"),
|
symbol("!"),
|
||||||
symbol("&"),
|
symbol("&"),
|
||||||
symbol("|"),
|
symbol("|"),
|
||||||
@ -84,11 +84,11 @@ pub fn unary_module_path_operator(s: &str) -> IResult<&str, Operator> {
|
|||||||
symbol("^"),
|
symbol("^"),
|
||||||
symbol("~"),
|
symbol("~"),
|
||||||
))(s)?;
|
))(s)?;
|
||||||
Ok((s, Operator { nodes: (x,) }))
|
Ok((s, Operator { nodes: (a,) }))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn binary_module_path_operator(s: &str) -> IResult<&str, Operator> {
|
pub fn binary_module_path_operator(s: &str) -> IResult<&str, Operator> {
|
||||||
let (s, x) = alt((
|
let (s, a) = alt((
|
||||||
symbol("=="),
|
symbol("=="),
|
||||||
symbol("!="),
|
symbol("!="),
|
||||||
symbol("&&"),
|
symbol("&&"),
|
||||||
@ -99,7 +99,7 @@ pub fn binary_module_path_operator(s: &str) -> IResult<&str, Operator> {
|
|||||||
symbol("^"),
|
symbol("^"),
|
||||||
symbol("~^"),
|
symbol("~^"),
|
||||||
))(s)?;
|
))(s)?;
|
||||||
Ok((s, Operator { nodes: (x,) }))
|
Ok((s, Operator { nodes: (a,) }))
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
@ -134,7 +134,7 @@ pub enum RangeExpression<'a> {
|
|||||||
pub enum PrimaryLiteral<'a> {
|
pub enum PrimaryLiteral<'a> {
|
||||||
Number(Number<'a>),
|
Number(Number<'a>),
|
||||||
TimeLiteral(TimeLiteral<'a>),
|
TimeLiteral(TimeLiteral<'a>),
|
||||||
UnbasedUnsizedLiteral(&'a str),
|
UnbasedUnsizedLiteral(UnbasedUnsizedLiteral<'a>),
|
||||||
StringLiteral(StringLiteral<'a>),
|
StringLiteral(StringLiteral<'a>),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,13 +145,13 @@ pub enum TimeLiteral<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum TimeUnit {
|
pub enum TimeUnit<'a> {
|
||||||
S,
|
S(Symbol<'a>),
|
||||||
MS,
|
MS(Symbol<'a>),
|
||||||
US,
|
US(Symbol<'a>),
|
||||||
NS,
|
NS(Symbol<'a>),
|
||||||
PS,
|
PS(Symbol<'a>),
|
||||||
FS,
|
FS(Symbol<'a>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -168,12 +168,12 @@ pub struct BitSelect<'a> {
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct UnsignedTimeLiteral<'a> {
|
pub struct UnsignedTimeLiteral<'a> {
|
||||||
pub nodes: (&'a str, TimeUnit),
|
pub nodes: (UnsignedNumber<'a>, TimeUnit<'a>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct FixedPointTimeLiteral<'a> {
|
pub struct FixedPointTimeLiteral<'a> {
|
||||||
pub nodes: (RealNumber<'a>, TimeUnit),
|
pub nodes: (FixedPointNumber<'a>, TimeUnit<'a>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -445,24 +445,14 @@ pub fn fixed_point_time_literal(s: &str) -> IResult<&str, TimeLiteral> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn time_unit(s: &str) -> IResult<&str, TimeUnit> {
|
pub fn time_unit(s: &str) -> IResult<&str, TimeUnit> {
|
||||||
let (s, x) = alt((
|
alt((
|
||||||
symbol("s"),
|
map(symbol("s"), |x| TimeUnit::S(x)),
|
||||||
symbol("ms"),
|
map(symbol("ms"), |x| TimeUnit::MS(x)),
|
||||||
symbol("us"),
|
map(symbol("us"), |x| TimeUnit::US(x)),
|
||||||
symbol("ns"),
|
map(symbol("ns"), |x| TimeUnit::NS(x)),
|
||||||
symbol("ps"),
|
map(symbol("ps"), |x| TimeUnit::PS(x)),
|
||||||
symbol("fs"),
|
map(symbol("fs"), |x| TimeUnit::FS(x)),
|
||||||
))(s)?;
|
))(s)
|
||||||
let unit = match x {
|
|
||||||
"s" => TimeUnit::S,
|
|
||||||
"ms" => TimeUnit::MS,
|
|
||||||
"us" => TimeUnit::US,
|
|
||||||
"ns" => TimeUnit::NS,
|
|
||||||
"ps" => TimeUnit::PS,
|
|
||||||
"fs" => TimeUnit::FS,
|
|
||||||
_ => unreachable!(),
|
|
||||||
};
|
|
||||||
Ok((s, unit))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn implicit_class_handle(s: &str) -> IResult<&str, ImplicitClassHandle> {
|
pub fn implicit_class_handle(s: &str) -> IResult<&str, ImplicitClassHandle> {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
use crate::parser::*;
|
use crate::parser::*;
|
||||||
use nom::bytes::complete::*;
|
use nom::bytes::complete::*;
|
||||||
use nom::character::complete::*;
|
use nom::character::complete::*;
|
||||||
|
use nom::combinator::*;
|
||||||
use nom::IResult;
|
use nom::IResult;
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
@ -17,8 +18,8 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn symbol<'a>(t: &'a str) -> impl Fn(&'a str) -> IResult<&'a str, &'a str> {
|
pub fn symbol<'a>(t: &'a str) -> impl Fn(&'a str) -> IResult<&'a str, Symbol<'a>> {
|
||||||
move |s: &'a str| ws(tag(t.clone()))(s)
|
move |s: &'a str| ws(map(tag(t.clone()), |x| Symbol { nodes: (x,) }))(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn paren<'a, O, F>(f: F) -> impl Fn(&'a str) -> IResult<&'a str, O>
|
pub fn paren<'a, O, F>(f: F) -> impl Fn(&'a str) -> IResult<&'a str, O>
|
||||||
@ -69,6 +70,11 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct Symbol<'a> {
|
||||||
|
pub nodes: (&'a str,),
|
||||||
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user