Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: first version of library #2

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions crates/etalia/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ exclude = [
"benches",
]

[dependencies]
chrono = "0.4.31"
thiserror = "1.0.50"
url = "2.5.0"

[dev-dependencies]
criterion = { version = "0.5.1", features = ["html_reports"] }
iai = "0.1.0"
Expand Down
21 changes: 21 additions & 0 deletions crates/etalia/src/errors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use crate::lir::LirToken;
use crate::mir::MirTokenStream;

#[derive(Debug, Clone, PartialEq, Eq)]

Check warning on line 4 in crates/etalia/src/errors.rs

View check run for this annotation

Codecov / codecov/patch

crates/etalia/src/errors.rs#L4

Added line #L4 was not covered by tests
pub struct ParseError {
pub kind: ParseErrorKind,
pub idx: usize,
}

impl ParseError {
pub fn new(kind: ParseErrorKind, idx: usize) -> Self {
Self { kind, idx }
}

Check warning on line 13 in crates/etalia/src/errors.rs

View check run for this annotation

Codecov / codecov/patch

crates/etalia/src/errors.rs#L11-L13

Added lines #L11 - L13 were not covered by tests
}

#[derive(Debug, Clone, PartialEq, Eq)]

Check warning on line 16 in crates/etalia/src/errors.rs

View check run for this annotation

Codecov / codecov/patch

crates/etalia/src/errors.rs#L16

Added line #L16 was not covered by tests
pub enum ParseErrorKind {
Date(chrono::ParseError),
UnbalancedDelim(MirTokenStream, LirToken),
UnrecognizedSymbol(char),
}
109 changes: 109 additions & 0 deletions crates/etalia/src/hir.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
use std::fmt::{Display, Formatter, Result as FmtResult};
use std::ops::RangeInclusive;
use url::Url;

#[derive(Debug, Clone, PartialEq, Eq)]

Check warning on line 5 in crates/etalia/src/hir.rs

View check run for this annotation

Codecov / codecov/patch

crates/etalia/src/hir.rs#L5

Added line #L5 was not covered by tests
pub struct Citation {
pub authors: Vec<Individual>,
pub number: SequencedNumber,
pub publisher: String,
pub publication_datetime: CitationDate,
pub contributors: Vec<Individual>,
pub title_source: String,
pub title_container: String,
pub location: Location,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]

Check warning on line 17 in crates/etalia/src/hir.rs

View check run for this annotation

Codecov / codecov/patch

crates/etalia/src/hir.rs#L17

Added line #L17 was not covered by tests
pub struct SequencedNumber {
pub parent: u32,
pub child: u32,
}

#[derive(Debug, Clone, PartialEq, Eq)]

Check warning on line 23 in crates/etalia/src/hir.rs

View check run for this annotation

Codecov / codecov/patch

crates/etalia/src/hir.rs#L23

Added line #L23 was not covered by tests
pub enum CitationDate {
Y(i32),
YM(i32, u32),
YMD(i32, u32, u32),
}

#[derive(Debug, Clone, PartialEq, Eq)]

Check warning on line 30 in crates/etalia/src/hir.rs

View check run for this annotation

Codecov / codecov/patch

crates/etalia/src/hir.rs#L30

Added line #L30 was not covered by tests
pub struct Individual {
pub kind: IndividualKind,
pub name: String,
}

impl Individual {
pub const fn new(kind: IndividualKind, name: String) -> Self {
Self { kind, name }
}

Check warning on line 39 in crates/etalia/src/hir.rs

View check run for this annotation

Codecov / codecov/patch

crates/etalia/src/hir.rs#L37-L39

Added lines #L37 - L39 were not covered by tests

pub const fn author(name: String) -> Self {
Self::new(IndividualKind::Author, name)
}

Check warning on line 43 in crates/etalia/src/hir.rs

View check run for this annotation

Codecov / codecov/patch

crates/etalia/src/hir.rs#L41-L43

Added lines #L41 - L43 were not covered by tests

pub const fn editor(name: String) -> Self {
Self::new(IndividualKind::Editor, name)
}

Check warning on line 47 in crates/etalia/src/hir.rs

View check run for this annotation

Codecov / codecov/patch

crates/etalia/src/hir.rs#L45-L47

Added lines #L45 - L47 were not covered by tests

pub const fn contributor(name: String) -> Self {
Self::new(IndividualKind::Contributor, name)
}

Check warning on line 51 in crates/etalia/src/hir.rs

View check run for this annotation

Codecov / codecov/patch

crates/etalia/src/hir.rs#L49-L51

Added lines #L49 - L51 were not covered by tests

pub const fn translator(name: String) -> Self {
Self::new(IndividualKind::Translator, name)
}

Check warning on line 55 in crates/etalia/src/hir.rs

View check run for this annotation

Codecov / codecov/patch

crates/etalia/src/hir.rs#L53-L55

Added lines #L53 - L55 were not covered by tests

pub const fn is_author(&self) -> bool {
matches!(self.kind, IndividualKind::Author)
}

Check warning on line 59 in crates/etalia/src/hir.rs

View check run for this annotation

Codecov / codecov/patch

crates/etalia/src/hir.rs#L57-L59

Added lines #L57 - L59 were not covered by tests

pub const fn is_editor(&self) -> bool {
matches!(self.kind, IndividualKind::Editor)
}

Check warning on line 63 in crates/etalia/src/hir.rs

View check run for this annotation

Codecov / codecov/patch

crates/etalia/src/hir.rs#L61-L63

Added lines #L61 - L63 were not covered by tests

pub const fn is_contributor(&self) -> bool {
matches!(self.kind, IndividualKind::Contributor)
}

Check warning on line 67 in crates/etalia/src/hir.rs

View check run for this annotation

Codecov / codecov/patch

crates/etalia/src/hir.rs#L65-L67

Added lines #L65 - L67 were not covered by tests

pub const fn is_translator(&self) -> bool {
matches!(self.kind, IndividualKind::Translator)
}

Check warning on line 71 in crates/etalia/src/hir.rs

View check run for this annotation

Codecov / codecov/patch

crates/etalia/src/hir.rs#L69-L71

Added lines #L69 - L71 were not covered by tests
}

#[derive(Debug, Clone, PartialEq, Eq)]

Check warning on line 74 in crates/etalia/src/hir.rs

View check run for this annotation

Codecov / codecov/patch

crates/etalia/src/hir.rs#L74

Added line #L74 was not covered by tests
pub enum IndividualKind {
Author,
Editor,
Contributor,
Translator,
Other(String),
}

#[derive(Debug, Clone, PartialEq, Eq)]

Check warning on line 83 in crates/etalia/src/hir.rs

View check run for this annotation

Codecov / codecov/patch

crates/etalia/src/hir.rs#L83

Added line #L83 was not covered by tests
pub enum Location {
Url(Url),
Page(Page),
Place(String),
}

#[derive(Debug, Clone, PartialEq, Eq)]

Check warning on line 90 in crates/etalia/src/hir.rs

View check run for this annotation

Codecov / codecov/patch

crates/etalia/src/hir.rs#L90

Added line #L90 was not covered by tests
pub enum Page {
FromTo(RangeInclusive<u32>),
At(u32),
}

impl Page {
pub const fn is_range(&self) -> bool {
matches!(self, Self::FromTo(_))
}

Check warning on line 99 in crates/etalia/src/hir.rs

View check run for this annotation

Codecov / codecov/patch

crates/etalia/src/hir.rs#L97-L99

Added lines #L97 - L99 were not covered by tests
}

impl Display for Page {
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
match self {
Self::FromTo(r) => write!(f, "{}-{}", r.start(), r.end()),
Self::At(i) => write!(f, "{}", i),

Check warning on line 106 in crates/etalia/src/hir.rs

View check run for this annotation

Codecov / codecov/patch

crates/etalia/src/hir.rs#L103-L106

Added lines #L103 - L106 were not covered by tests
}
}

Check warning on line 108 in crates/etalia/src/hir.rs

View check run for this annotation

Codecov / codecov/patch

crates/etalia/src/hir.rs#L108

Added line #L108 was not covered by tests
}
34 changes: 15 additions & 19 deletions crates/etalia/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
#[doc = include_str!("../README.md")]
#![allow(dead_code)]
#![allow(unused_mut)]
#![allow(unused_variables)]

/// Say hi to someone! <3
pub fn greet(name: &str) -> String {
format!("Hello {}!", name)
}
mod errors;
pub mod hir;
pub mod lir;
pub mod mir;
mod symbol;
pub mod visitors;

#[cfg(test)]
mod tests {
use crate::greet;

#[test]
fn greet_bob() {
assert_eq!(greet("Bob"), String::from("Hello Bob!"));
}

#[test]
fn greet_the_world() {
assert_eq!(greet("World"), String::from("Hello World!"));
}
}
pub use errors::*;
pub use hir::*;
pub use lir::*;
pub use mir::*;
pub use symbol::*;
pub use visitors::*;
Loading