Skip to content

Commit

Permalink
Run "cargo fmt"
Browse files Browse the repository at this point in the history
  • Loading branch information
pfoerster committed Mar 24, 2024
1 parent a06002f commit 1d0844b
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 21 deletions.
23 changes: 14 additions & 9 deletions crates/base-db/src/data.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub struct BibtexEntryType<'a> {
pub name: &'a str,
pub category: BibtexEntryTypeCategory,
pub documentation: Option<&'a str>,
pub name: &'a str,
pub category: BibtexEntryTypeCategory,
pub documentation: Option<&'a str>,
}

#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)]
Expand All @@ -18,23 +18,28 @@ pub enum BibtexEntryTypeCategory {

#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub struct BibtexFieldType<'a> {
pub name: &'a str,
pub documentation: &'a str,
pub name: &'a str,
pub documentation: &'a str,
}

impl<'a> BibtexEntryType<'a> {
pub fn find(name: &str) -> Option<Self> {
BIBTEX_ENTRY_TYPES.iter().find(|ty| ty.name.eq_ignore_ascii_case(name)).copied()
BIBTEX_ENTRY_TYPES
.iter()
.find(|ty| ty.name.eq_ignore_ascii_case(name))
.copied()
}
}

impl<'a> BibtexFieldType<'a> {
pub fn find(name: &str) -> Option<Self> {
BIBTEX_FIELD_TYPES.iter().find(|ty| ty.name.eq_ignore_ascii_case(name)).copied()
BIBTEX_FIELD_TYPES
.iter()
.find(|ty| ty.name.eq_ignore_ascii_case(name))
.copied()
}
}


pub static BIBTEX_ENTRY_TYPES: &[BibtexEntryType<'static>] = &[
BibtexEntryType {
name: "@preamble",
Expand Down Expand Up @@ -887,5 +892,5 @@ pub static BIBTEX_FIELD_TYPES: &[BibtexFieldType<'static>] = &[
BibtexFieldType {
name: "school",
documentation: "An alias for `institution`, provided for BibTeX compatibility. The `institution` field is used by traditional BibTeX for technical reports whereas the `school` field holds the institution associated with theses. The `biblatex` package employs the generic field name `institution` in both cases.",
}
}
];
8 changes: 4 additions & 4 deletions crates/base-db/src/semantics/bib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use bibtex_utils::field::text::TextFieldData;
use itertools::Itertools;
use rowan::{ast::AstNode, TextRange};
use syntax::bibtex::{self, HasName, HasType, HasValue};
use rustc_hash::FxHashMap;
use syntax::bibtex::{self, HasName, HasType, HasValue};

use crate::data::{BibtexEntryType, BibtexEntryTypeCategory};

Expand Down Expand Up @@ -33,9 +33,9 @@ impl Semantics {
let category = BibtexEntryType::find(type_token.text())
.map_or(BibtexEntryTypeCategory::Misc, |ty| ty.category);

let field_values = entry
.fields()
.filter_map(|field| Some(TextFieldData::parse(&field.value()?, &self.expanded_defs)?.text));
let field_values = entry.fields().filter_map(|field| {
Some(TextFieldData::parse(&field.value()?, &self.expanded_defs)?.text)
});

let keywords = [name.text().into(), type_token.text().into()]
.into_iter()
Expand Down
2 changes: 1 addition & 1 deletion crates/bibtex-utils/src/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ pub mod number;
pub mod text;

/// A cache used to accelerate related field parses.
pub type FieldParseCache = FxHashMap<String, String>;
pub type FieldParseCache = FxHashMap<String, String>;
4 changes: 2 additions & 2 deletions crates/bibtex-utils/src/field/text.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use rowan::{ast::AstNode, NodeOrToken};

use syntax::bibtex::{
Accent, Command, CurlyGroup, HasAccentName, HasCommandName, HasName, HasWord, Join,
Literal, QuoteGroup, SyntaxKind::*, SyntaxToken, Value,
Accent, Command, CurlyGroup, HasAccentName, HasCommandName, HasName, HasWord, Join, Literal,
QuoteGroup, SyntaxKind::*, SyntaxToken, Value,
};

use super::FieldParseCache;
Expand Down
30 changes: 25 additions & 5 deletions crates/citeproc/src/entry.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use base_db::semantics::bib::Semantics;
use bibtex_utils::field::{
author::{AuthorField, AuthorFieldData},
date::{DateField, DateFieldData},
number::{NumberField, NumberFieldData},
text::{TextField, TextFieldData},
FieldParseCache,
};
use base_db::semantics::bib::Semantics;
use rustc_hash::FxHashMap;
use syntax::bibtex::{Entry, Field, HasName, HasType, HasValue, Value};

Expand Down Expand Up @@ -133,28 +133,48 @@ impl EntryData {
.or_else(|| self.parse_text_field(name, &value, expanded_defs))
}

fn parse_author_field(&mut self, name: &str, value: &Value, expanded_defs: &FieldParseCache) -> Option<()> {
fn parse_author_field(
&mut self,
name: &str,
value: &Value,
expanded_defs: &FieldParseCache,
) -> Option<()> {
let name = AuthorField::parse(name)?;
let data = AuthorFieldData::parse(value, expanded_defs)?;
self.author.insert(name, data);
Some(())
}

fn parse_date_field(&mut self, name: &str, value: &Value, expanded_defs: &FieldParseCache) -> Option<()> {
fn parse_date_field(
&mut self,
name: &str,
value: &Value,
expanded_defs: &FieldParseCache,
) -> Option<()> {
let name = DateField::parse(name)?;
let data = DateFieldData::parse(value, expanded_defs)?;
self.date.insert(name, data);
Some(())
}

fn parse_number_field(&mut self, name: &str, value: &Value, expanded_defs: &FieldParseCache) -> Option<()> {
fn parse_number_field(
&mut self,
name: &str,
value: &Value,
expanded_defs: &FieldParseCache,
) -> Option<()> {
let name = NumberField::parse(name)?;
let data = NumberFieldData::parse(value, expanded_defs)?;
self.number.insert(name, data);
Some(())
}

fn parse_text_field(&mut self, name: &str, value: &Value, expanded_defs: &FieldParseCache) -> Option<()> {
fn parse_text_field(
&mut self,
name: &str,
value: &Value,
expanded_defs: &FieldParseCache,
) -> Option<()> {
let name = TextField::parse(name).unwrap_or(TextField::Unknown);
let data = TextFieldData::parse(value, expanded_defs)?;
self.text.insert(name, data);
Expand Down

0 comments on commit 1d0844b

Please sign in to comment.