Format files properly again
I forgot to include the includes and time zone commands
This commit is contained in:
parent
d7df47eba4
commit
2c7aa78d08
5 changed files with 72 additions and 23 deletions
|
|
@ -329,7 +329,7 @@ pub enum Command {
|
|||
#[derive(Debug)]
|
||||
pub struct File {
|
||||
pub name: PathBuf,
|
||||
pub includes: Vec<PathBuf>,
|
||||
pub includes: Vec<String>,
|
||||
pub timezone: Option<String>,
|
||||
pub commands: Vec<Command>,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -273,14 +273,28 @@ impl fmt::Display for Command {
|
|||
|
||||
impl fmt::Display for File {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let mut commands = self.commands.iter();
|
||||
if let Some(command) = commands.next() {
|
||||
write!(f, "{}", command)?;
|
||||
for command in commands {
|
||||
writeln!(f)?;
|
||||
write!(f, "{}", command)?;
|
||||
}
|
||||
let mut empty = true;
|
||||
for include in &self.includes {
|
||||
writeln!(f, "INCLUDE {}", include)?;
|
||||
empty = false;
|
||||
}
|
||||
|
||||
if let Some(tz) = &self.timezone {
|
||||
if !empty {
|
||||
writeln!(f)?;
|
||||
}
|
||||
writeln!(f, "TIMEZONE {}", tz)?;
|
||||
empty = false;
|
||||
}
|
||||
|
||||
for command in &self.commands {
|
||||
if !empty {
|
||||
writeln!(f)?;
|
||||
}
|
||||
write!(f, "{}", command)?;
|
||||
empty = false;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -706,12 +706,7 @@ fn parse_command(p: Pair<Rule>, file: &mut File) -> Result<()> {
|
|||
|
||||
let p = p.into_inner().next().unwrap();
|
||||
match p.as_rule() {
|
||||
Rule::include => {
|
||||
// Since we've successfully opened the file, its name can't be the
|
||||
// root directory or empty string and must thus have a parent.
|
||||
let parent = file.name.parent().unwrap();
|
||||
file.includes.push(parent.join(parse_include(p)));
|
||||
}
|
||||
Rule::include => file.includes.push(parse_include(p)),
|
||||
Rule::timezone => match file.timezone {
|
||||
None => file.timezone = Some(parse_timezone(p)),
|
||||
Some(_) => fail(p.as_span(), "cannot set timezone multiple times")?,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue