Skip to content

Commit

Permalink
feat(pff2): Added font parser
Browse files Browse the repository at this point in the history
  • Loading branch information
max-ishere committed Jan 27, 2024
1 parent 388d7b9 commit ef0ddd4
Show file tree
Hide file tree
Showing 5 changed files with 721 additions and 0 deletions.
314 changes: 314 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "theme-parser"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
anyhow = "1.0.79"
clap = { version = "4.4.18", features = ["derive"] }
nom = "7.1.3"
thiserror = "1.0.56"

[dev-dependencies]
test-case = "3.3.1"
35 changes: 35 additions & 0 deletions examples/pff2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//! A minimal font.pf2 parser impl that prints the parsed Rust struct
use std::fs::read;

use args::Args;
use clap::Parser as _;
use theme_parser::pff2::Parser;

mod args {
use std::path::PathBuf;

use clap::Parser;

#[derive(Parser)]
pub struct Args {
#[clap(long, short = 'f')]
pub font_file: PathBuf,
}
}

fn main() -> anyhow::Result<()> {
let args = Args::parse();

let data = read(args.font_file)?;
let font = Parser::parse(&data).unwrap().validate();

let print = format!("{font:#?}")
.split("\n")
.take(100)
.fold(String::new(), |print, line| print + line + "\n");

println!("{print}");

Ok(())
}
7 changes: 7 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
use std::rc::Rc;

#[cfg(test)]
#[macro_use]
extern crate test_case;

extern crate thiserror;

pub mod pff2;
pub mod theme_txt;

pub type OwnedSlice<T> = Rc<T>;
Loading

0 comments on commit ef0ddd4

Please sign in to comment.