pub(crate) mod lex;
mod parse;
mod print;
use core::fmt;
pub use parse::ParseOptions;
pub use print::{Display, PrintOptions};
#[derive(Clone, PartialEq, Eq, Debug)]
#[non_exhaustive]
pub struct SyntaxError {
pub message: String,
pub start: usize,
pub end: usize,
}
impl SyntaxError {
pub(crate) fn new(message: &str, start: usize, end: usize) -> Self {
SyntaxError {
message: message.to_string(),
start,
end,
}
}
}
impl fmt::Display for SyntaxError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"{} (at bytes {}..{})",
self.message, self.start, self.end
)
}
}
impl std::error::Error for SyntaxError {}
pub(crate) const FUNCTIONS: &[&str] = &[
"udiv",
"urem",
"sdiv",
"srem",
"rotl",
"rotr",
"umulhi",
"smulhi",
"pdep",
"pext",
"popcnt",
"clz",
"ctz",
"bswap",
"bitrev",
"zext",
"sext",
"trunc",
"extract",
"concat",
"select",
"umin",
"umax",
"smin",
"smax",
"andn",
"orn",
"xnor",
"abs",
"add_carry",
"sub_borrow",
"sadd_overflow",
"ssub_overflow",
"add_sat_u",
"add_sat_s",
"sub_sat_u",
"sub_sat_s",
];
pub(crate) const RULE_WORDS: &[&str] = &[
"ones",
"zero",
"one",
"smin_lit",
"smax_lit",
"lowmask",
"bit",
"proves",
"zero_bits",
"one_bits",
"nonzero",
"disjoint",
"is_pow2",
"is_lowmask",
"is_shifted_mask",
];
pub(crate) fn is_reserved(s: &str) -> bool {
matches!(s, "let" | "true" | "false")
|| FUNCTIONS.contains(&s)
|| RULE_WORDS.contains(&s)
|| s.starts_with("fp.")
}