pub fn new(value: T, rest: TokenSlice, warnings: Diagnostics) -> Self {
Self {
value,
- rest: rest,
+ rest,
diagnostics: warnings,
}
}
pub fn ok(value: T, rest: TokenSlice) -> Self {
Self {
value,
- rest: rest,
+ rest,
diagnostics: Diagnostics::default(),
}
}
write!(f, "Subcommands[")?;
for (index, item) in self.0.iter().enumerate() {
if index > 0 {
- write!(f, ",\n")?;
+ writeln!(f, ",")?;
}
write!(f, "{item:?}")?;
}
}
}
-impl<'a> FromTokens for Identifier {
+impl FromTokens for Identifier {
fn from_tokens(input: &TokenSlice) -> ParseResult<Self>
where
Self: Sized,
}
}
-impl<'a> FromTokens for String {
+impl FromTokens for String {
fn from_tokens(input: &TokenSlice) -> ParseResult<Self>
where
Self: Sized,
}
static COMMANDS: OnceLock<Vec<Command>> = OnceLock::new();
- COMMANDS.get_or_init(|| new_commands()).as_slice()
+ COMMANDS.get_or_init(new_commands).as_slice()
}
fn parse_command_word(lexer: &mut TokenSlice, s: &mut String, n: usize) -> bool {
fn parse_command_name(
lexer: &mut TokenSlice,
- error: &Box<dyn Fn(Diagnostic)>,
+ error: &dyn Fn(Diagnostic),
) -> Result<(&'static Command, usize), ()> {
let mut s = String::new();
let mut word = 0;
}
}
-fn parse_in_state(mut lexer: TokenSlice, error: &Box<dyn Fn(Diagnostic)>, _state: State) {
+fn parse_in_state(mut lexer: TokenSlice, error: &dyn Fn(Diagnostic), _state: State) {
match lexer.get_token(0) {
None | Some(Token::End) => (),
_ => match parse_command_name(&mut lexer, error) {
}
}
-pub fn parse_command(lexer: TokenSlice, error: &Box<dyn Fn(Diagnostic)>) {
+pub fn parse_command(lexer: TokenSlice, error: &dyn Fn(Diagnostic)) {
parse_in_state(lexer, error, State::Initial)
}
pub struct Context<'a> {
- error: &'a Box<dyn Fn(Diagnostic)>,
+ error: &'a dyn Fn(Diagnostic),
lexer: TokenSlice,
command_name: Option<&'static str>,
}
impl Hash for Value {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
match self {
- Value::Number(number) => number.map(|x| OrderedFloat(x)).hash(state),
+ Value::Number(number) => number.map(OrderedFloat).hash(state),
Value::String(string) => string.hash(state),
}
}
pub fn as_string(&self) -> Option<&[u8]> {
match self {
Value::Number(_) => None,
- Value::String(s) => Some(&*s),
+ Value::String(s) => Some(s),
}
}
}
};
use std::rc::Rc;
+#[derive(Default)]
pub struct Engine;
impl Engine {
}
}
-impl<'a, 'b> Display for DisplayValue<'a, 'b> {
+impl Display for DisplayValue<'_, '_> {
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
let number = match self.value {
Value::Number(number) => *number,
'y' => {
let epoch = self.settings.epoch.0;
let offset = date.year() - epoch;
- if offset < 0 || offset > 99 {
+ if !(0..=99).contains(&offset) {
return self.overflow(f);
}
write!(&mut output, "{:02}", date.year().abs() % 100).unwrap();
}
break;
}
- c if n == 1 => output.push(c as char),
+ c if n == 1 => output.push(c),
_ => unreachable!(),
}
}
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
let mut n = self.0;
while n > 0 {
- static ZEROS: &'static str = "0000000000000000000000000000000000000000";
+ static ZEROS: &str = "0000000000000000000000000000000000000000";
let chunk = n.min(ZEROS.len());
f.write_str(&ZEROS[..chunk])?;
n -= chunk;
}
fn allocate_space(want: usize, capacity: usize, used: &mut usize) -> bool {
- if *used + want <= capacity as usize {
+ if *used + want <= capacity {
*used += want;
true
} else {
input
}
- if p.strip_prefix(&*style.prefix.s) {
+ if p.strip_prefix(&style.prefix.s) {
p.strip_ws();
}
let sign = p.strip_one_of(&['-', '+']).inspect(|_| p.strip_ws());
- if sign.is_some() && p.strip_prefix(&*style.prefix.s) {
+ if sign.is_some() && p.strip_prefix(&style.prefix.s) {
p.strip_ws();
}
let integer = p.advance(strip_integer(p.0, style.grouping.map(char::from)));
} else {
(None, "")
};
- if p.strip_prefix(&*style.suffix.s) {
+ if p.strip_prefix(&style.suffix.s) {
p.strip_ws();
}
fn parse_bcd(input: &[u8]) -> Result<u128, ParseErrorKind> {
let mut value = 0;
- for byte in input.into_iter().copied() {
+ for byte in input.iter().copied() {
let hi = nibble(byte >> 4)?;
let lo = nibble(byte & 0x0f)?;
value = value * 100 + hi * 10 + lo;
fn parse_rbhex(&self, input: &str) -> Result<Value, ParseErrorKind> {
self.parse_hex(input)
- .map(|value| Value::Number(value.map(|number| f64::from_bits(number))))
+ .map(|value| Value::Number(value.map(f64::from_bits)))
}
fn parse_date(&self, input: &str) -> Result<Value, ParseErrorKind> {
Ok(Value::Number(Some(time_date)))
}
- fn parse_minute_second<'b>(&self, p: &mut StrParser<'b>) -> Result<f64, ParseErrorKind> {
+ fn parse_minute_second(&self, p: &mut StrParser<'_>) -> Result<f64, ParseErrorKind> {
let minute = parse_int::<i32>(p)?;
if self.format.type_ != Type::MTime && !(0..=59).contains(&minute) {
return Err(ParseErrorKind::InvalidMinute(minute));
Negative,
}
-fn parse_trailer<'a>(p: &mut StrParser<'a>) -> Result<(), ParseErrorKind> {
+fn parse_trailer(p: &mut StrParser<'_>) -> Result<(), ParseErrorKind> {
p.strip_ws();
if p.0.is_empty() {
Ok(())
}
}
-fn parse_sign<'a>(p: &mut StrParser<'a>, sign: Option<Sign>) -> Sign {
+fn parse_sign(p: &mut StrParser<'_>, sign: Option<Sign>) -> Sign {
if let Some(sign) = sign {
sign
} else if p.strip_one_of(&['-', '+']) == Some('-') {
}
}
-fn parse_time<'a>(p: &mut StrParser<'a>) -> Result<f64, ParseErrorKind> {
+fn parse_time(p: &mut StrParser<'_>) -> Result<f64, ParseErrorKind> {
let number = parse_int::<i32>(p)?;
if number < 0 {
return Err(ParseErrorKind::DateSyntax);
Ok(number as f64)
}
-fn parse_day<'a>(p: &mut StrParser<'a>) -> Result<i32, ParseErrorKind> {
+fn parse_day(p: &mut StrParser<'_>) -> Result<i32, ParseErrorKind> {
let day = parse_int::<i32>(p)?;
if (1..=31).contains(&day) {
Ok(day)
}
}
-fn parse_yday<'a>(p: &mut StrParser<'a>) -> Result<i32, ParseErrorKind> {
+fn parse_yday(p: &mut StrParser<'_>) -> Result<i32, ParseErrorKind> {
let Some(s) = p.0.get(..3) else {
return Err(ParseErrorKind::InvalidYDayLen);
};
Ok(yday)
}
-fn parse_month<'a>(p: &mut StrParser<'a>) -> Result<i32, ParseErrorKind> {
+fn parse_month(p: &mut StrParser<'_>) -> Result<i32, ParseErrorKind> {
if p.0.starts_with(|c: char| c.is_ascii_digit()) {
let month = parse_int(p)?;
if (1..=12).contains(&month) {
Err(ParseErrorKind::InvalidMonth)
}
-fn parse_weekday<'a>(p: &mut StrParser<'a>) -> Result<i32, ParseErrorKind> {
+fn parse_weekday(p: &mut StrParser<'_>) -> Result<i32, ParseErrorKind> {
static WEEKDAY_NAMES: [&str; 7] = ["su", "mo", "tu", "we", "th", "fr", "sa"];
let name = p.strip_matches(|c| c.is_ascii_alphabetic());
name.get(..2)
.ok_or(ParseErrorKind::InvalidWeekdayName)
}
-fn parse_quarter<'a>(p: &mut StrParser<'a>) -> Result<i32, ParseErrorKind> {
+fn parse_quarter(p: &mut StrParser<'_>) -> Result<i32, ParseErrorKind> {
match parse_int(p)? {
quarter @ 1..=4 => Ok((quarter - 1) * 3 + 1),
other => Err(ParseErrorKind::InvalidQuarter(other)),
}
}
-fn parse_week<'a>(p: &mut StrParser<'a>) -> Result<i32, ParseErrorKind> {
+fn parse_week(p: &mut StrParser<'_>) -> Result<i32, ParseErrorKind> {
match parse_int(p)? {
week @ 1..=53 => Ok((week - 1) * 7 + 1),
other => Err(ParseErrorKind::InvalidWeek(other)),
}
}
-fn parse_time_delimiter<'a>(p: &mut StrParser<'a>) -> Result<(), ParseErrorKind> {
+fn parse_time_delimiter(p: &mut StrParser<'_>) -> Result<(), ParseErrorKind> {
let delimiter = p.strip_matches(|c| c == ':' || c.is_ascii_whitespace());
if !delimiter.is_empty() {
Ok(())
}
}
-fn parse_date_delimiter<'a>(p: &mut StrParser<'a>) -> Result<(), ParseErrorKind> {
+fn parse_date_delimiter(p: &mut StrParser<'_>) -> Result<(), ParseErrorKind> {
let delimiter = p
.strip_matches(|c| c == '-' || c == '/' || c == '.' || c == ',' || c.is_ascii_whitespace());
if !delimiter.is_empty() {
None
}
-fn parse_year<'a>(
- p: &mut StrParser<'a>,
+fn parse_year(
+ p: &mut StrParser<'_>,
settings: &Settings,
max_digits: usize,
) -> Result<i32, ParseErrorKind> {
Ok(settings.epoch.apply(year))
}
-fn parse_int<'a, T>(p: &mut StrParser<'a>) -> Result<T, ParseErrorKind>
+fn parse_int<'a, T>(p: &mut StrParser<'_>) -> Result<T, ParseErrorKind>
where
T: FromStr,
{
}
'm' => {
let m = self.date.month as usize - 1;
- static ROMAN: [&'static str; 12] = [
+ static ROMAN: [&str; 12] = [
"i", "ii", "iii", "iv", "v", "vi", "vii", "viii", "ix", "x", "xi",
"xii",
];
- static ENGLISH: [&'static str; 12] = [
+ static ENGLISH: [&str; 12] = [
"january",
"february",
"march",
}
}
-pub const COMMAND_NAMES: &'static [&'static str] = &[
+pub const COMMAND_NAMES: &[&str] = &[
"2SLS",
"ACF",
"ADD DOCUMENT",
ParserState::Arg
};
}
+ } else if self.args.iter().any(|arg| arg.is_none()) {
+ self.state = ParserState::Keyword;
} else {
- if self.args.iter().any(|arg| arg.is_none()) {
- self.state = ParserState::Keyword;
- } else {
- self.finished();
- }
+ self.finished();
}
}
}
}
let l1 = span.start.line;
let l2 = span.end.line;
- if let (Some(c1), Some(c2)) = (span.start.column, span.end.column) {
- if l2 > l1 {
- write!(f, "{l1}.{c1}-{l2}.{}", c2 - 1)?;
- } else {
- write!(f, "{l1}.{c1}-{}", c2 - 1)?;
- }
- } else {
- if l2 > l1 {
- write!(f, "{l1}-{l2}")?;
- } else {
- write!(f, "{l1}")?;
- }
+ match (span.start.column.zip(span.end.column), l2 > l1) {
+ (Some((c1, c2)), true) => write!(f, "{l1}.{c1}-{l2}.{}", c2 - 1)?,
+ (Some((c1, c2)), false) => write!(f, "{l1}.{c1}-{}", c2 - 1)?,
+ (None, true) => write!(f, "{l1}-{l2}")?,
+ (None, false) => write!(f, "{l1}")?,
}
}
Ok(())
self.hide_all_labels = true;
self
}
- fn build(mut self) -> Dimension {
+ fn build(self) -> Dimension {
let mut leaves = Vec::with_capacity(self.len);
let root = self.root.build(None, &mut leaves);
Dimension {
self.push(value);
self
}
- pub fn with_label_hidden(mut self) -> Self {
+ pub fn with_label_hidden(self) -> Self {
self.with_show_label(false)
}
- pub fn with_label_shown(mut self) -> Self {
+ pub fn with_label_shown(self) -> Self {
self.with_show_label(true)
}
pub fn with_show_label(mut self, show_label: bool) -> Self {
dimensions: Vec::with_capacity(self.dimensions.len()),
});
for d in self.dimensions {
- let axis = d.axis;
- let label_position = if axis == Axis3::Y && table.corner_text.is_none() {
- self.look.row_label_position
- } else {
- LabelPosition::Nested
- };
- let d = d.build();
- axes[axis].dimensions.push(dimensions.len());
- dimensions.push(d);
+ axes[d.axis].dimensions.push(dimensions.len());
+ dimensions.push(d.build());
}
table.dimensions = dimensions;
table.axes = axes;
emphasis: true,
width,
min_hbreak: 20,
- box_chars: &*&UNICODE_BOX,
+ box_chars: &*UNICODE_BOX,
n_objects: 0,
params: Params {
size: Coord2::new(width, usize::MAX),