mirror of
https://github.com/latex-lsp/texlab.git
synced 2025-08-04 02:39:21 +00:00
Remove dependency to strum crate
This commit is contained in:
parent
2b4e4c73b6
commit
c09e3bcbb8
7 changed files with 134 additions and 59 deletions
|
@ -13,7 +13,6 @@ isocountry = "0.3.2"
|
|||
itertools = "0.10.5"
|
||||
rowan = "0.15.11"
|
||||
rustc-hash = "1.1.0"
|
||||
strum = { version = "0.24.1", features = ["derive"] }
|
||||
syntax = { path = "../syntax" }
|
||||
titlecase = "2.2.1"
|
||||
unicode-normalization = "0.1.22"
|
||||
|
|
|
@ -1,7 +1,4 @@
|
|||
use std::str::FromStr;
|
||||
|
||||
use rustc_hash::FxHashMap;
|
||||
use strum::EnumString;
|
||||
use syntax::bibtex::{Entry, Field, HasName, HasType, HasValue, Value};
|
||||
|
||||
use super::field::{
|
||||
|
@ -11,8 +8,7 @@ use super::field::{
|
|||
text::{TextField, TextFieldData},
|
||||
};
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Hash, EnumString)]
|
||||
#[strum(ascii_case_insensitive)]
|
||||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Hash)]
|
||||
pub enum EntryKind {
|
||||
Article,
|
||||
Book,
|
||||
|
@ -51,6 +47,48 @@ pub enum EntryKind {
|
|||
Unknown,
|
||||
}
|
||||
|
||||
impl EntryKind {
|
||||
pub fn parse(input: &str) -> Self {
|
||||
match input.to_ascii_lowercase().as_str() {
|
||||
"article" => Self::Article,
|
||||
"book" => Self::Book,
|
||||
"mvbook" => Self::MVBook,
|
||||
"inbook" => Self::InBook,
|
||||
"bookinbook" => Self::BookInBook,
|
||||
"suppbook" => Self::SuppBook,
|
||||
"booklet" => Self::Booklet,
|
||||
"collection" => Self::Collection,
|
||||
"mvcollection" => Self::MVCollection,
|
||||
"incollection" => Self::InCollection,
|
||||
"suppcollection" => Self::SuppCollection,
|
||||
"dataset" => Self::DataSet,
|
||||
"manual" => Self::Manual,
|
||||
"misc" => Self::Misc,
|
||||
"online" => Self::Online,
|
||||
"electronic" => Self::Electronic,
|
||||
"www" => Self::Www,
|
||||
"patent" => Self::Patent,
|
||||
"periodical" => Self::Periodical,
|
||||
"suppperiodical" => Self::SuppPeriodical,
|
||||
"proceedings" => Self::Proceedings,
|
||||
"mvproceedings" => Self::MVProceedings,
|
||||
"inproceedings" => Self::InProceedings,
|
||||
"conference" => Self::Conference,
|
||||
"reference" => Self::Reference,
|
||||
"mvreference" => Self::MVReference,
|
||||
"inreference" => Self::InReference,
|
||||
"report" => Self::Report,
|
||||
"set" => Self::Set,
|
||||
"software" => Self::Software,
|
||||
"thesis" => Self::Thesis,
|
||||
"masterthesis" => Self::MasterThesis,
|
||||
"phdthesis" => Self::PhdThesis,
|
||||
"techreport" => Self::TechReport,
|
||||
_ => Self::Unknown,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for EntryKind {
|
||||
fn default() -> Self {
|
||||
Self::Unknown
|
||||
|
@ -69,10 +107,9 @@ pub struct EntryData {
|
|||
impl From<&Entry> for EntryData {
|
||||
fn from(entry: &Entry) -> Self {
|
||||
let mut data = EntryData {
|
||||
kind: entry
|
||||
.type_token()
|
||||
.and_then(|token| EntryKind::from_str(&token.text()[1..]).ok())
|
||||
.unwrap_or(EntryKind::Unknown),
|
||||
kind: entry.type_token().map_or(EntryKind::Unknown, |token| {
|
||||
EntryKind::parse(&token.text()[1..])
|
||||
}),
|
||||
..EntryData::default()
|
||||
};
|
||||
|
||||
|
|
|
@ -1,14 +1,12 @@
|
|||
use std::{borrow::Cow, fmt, str::FromStr};
|
||||
use std::{borrow::Cow, fmt};
|
||||
|
||||
use human_name::Name;
|
||||
use itertools::Itertools;
|
||||
use strum::EnumString;
|
||||
use syntax::bibtex::Value;
|
||||
|
||||
use super::text::TextFieldData;
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Hash, EnumString)]
|
||||
#[strum(ascii_case_insensitive)]
|
||||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Hash)]
|
||||
pub enum AuthorField {
|
||||
Afterword,
|
||||
Annotator,
|
||||
|
@ -25,7 +23,20 @@ pub enum AuthorField {
|
|||
|
||||
impl AuthorField {
|
||||
pub fn parse(input: &str) -> Option<Self> {
|
||||
Self::from_str(input).ok()
|
||||
Some(match input.to_ascii_lowercase().as_str() {
|
||||
"afterword" => Self::Afterword,
|
||||
"annotator" => Self::Annotator,
|
||||
"author" => Self::Author,
|
||||
"commentator" => Self::Commentator,
|
||||
"editor" => Self::Editor,
|
||||
"editora" => Self::EditorA,
|
||||
"editorb" => Self::EditorB,
|
||||
"editorc" => Self::EditorC,
|
||||
"foreword" => Self::Foreword,
|
||||
"introduction" => Self::Introduction,
|
||||
"translator" => Self::Translator,
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,13 +1,11 @@
|
|||
use std::{fmt, ops::Add, str::FromStr};
|
||||
|
||||
use chrono::{Datelike, Month, NaiveDate};
|
||||
use strum::EnumString;
|
||||
use syntax::bibtex::Value;
|
||||
|
||||
use super::text::TextFieldData;
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Hash, EnumString)]
|
||||
#[strum(ascii_case_insensitive)]
|
||||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Hash)]
|
||||
pub enum DateField {
|
||||
Date,
|
||||
EventDate,
|
||||
|
@ -18,7 +16,14 @@ pub enum DateField {
|
|||
|
||||
impl DateField {
|
||||
pub fn parse(input: &str) -> Option<Self> {
|
||||
Self::from_str(input).ok()
|
||||
Some(match input.to_ascii_lowercase().as_str() {
|
||||
"date" => Self::Date,
|
||||
"eventdate" => Self::EventDate,
|
||||
"month" => Self::Month,
|
||||
"urldate" => Self::UrlDate,
|
||||
"year" => Self::Year,
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
use std::{fmt, str::FromStr};
|
||||
use std::fmt;
|
||||
|
||||
use strum::EnumString;
|
||||
use syntax::bibtex::Value;
|
||||
|
||||
use super::text::TextFieldData;
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Hash, EnumString)]
|
||||
#[strum(ascii_case_insensitive)]
|
||||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Hash)]
|
||||
pub enum NumberField {
|
||||
Edition,
|
||||
Number,
|
||||
|
@ -19,7 +17,16 @@ pub enum NumberField {
|
|||
|
||||
impl NumberField {
|
||||
pub fn parse(input: &str) -> Option<Self> {
|
||||
Self::from_str(input).ok()
|
||||
Some(match input.to_ascii_lowercase().as_str() {
|
||||
"edition" => Self::Edition,
|
||||
"number" => Self::Number,
|
||||
"pages" => Self::Pages,
|
||||
"pagetotal" => Self::PageTotal,
|
||||
"part" => Self::Part,
|
||||
"volume" => Self::Volume,
|
||||
"volumes" => Self::Volumes,
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,16 +1,12 @@
|
|||
use std::str::FromStr;
|
||||
|
||||
use rowan::{ast::AstNode, NodeOrToken};
|
||||
use rustc_hash::FxHashSet;
|
||||
use strum::EnumString;
|
||||
|
||||
use syntax::bibtex::{
|
||||
Accent, Command, CurlyGroup, HasAccentName, HasCommandName, HasName, HasValue, HasWord, Join,
|
||||
Literal, QuoteGroup, Root, SyntaxKind::*, SyntaxToken, Value,
|
||||
};
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Hash, EnumString)]
|
||||
#[strum(ascii_case_insensitive)]
|
||||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Hash)]
|
||||
pub enum TextField {
|
||||
Abstract,
|
||||
Addendum,
|
||||
|
@ -63,7 +59,56 @@ pub enum TextField {
|
|||
|
||||
impl TextField {
|
||||
pub fn parse(input: &str) -> Option<Self> {
|
||||
Self::from_str(input).ok()
|
||||
Some(match input.to_ascii_lowercase().as_str() {
|
||||
"abstract" => Self::Abstract,
|
||||
"addendum" => Self::Addendum,
|
||||
"booksubtitle" => Self::BookSubtitle,
|
||||
"booktitle" => Self::BookTitle,
|
||||
"booktitleaddon" => Self::BookTitleAddon,
|
||||
"chapter" => Self::Chapter,
|
||||
"doi" => Self::Doi,
|
||||
"editortype" => Self::EditorType,
|
||||
"editortypea" => Self::EditorTypeA,
|
||||
"editortypeb" => Self::EditorTypeB,
|
||||
"editortypec" => Self::EditorTypeC,
|
||||
"eid" => Self::Eid,
|
||||
"eprint" => Self::Eprint,
|
||||
"eprintclass" => Self::EprintClass,
|
||||
"eprinttype" => Self::EprintType,
|
||||
"eventtitle" => Self::EventTitle,
|
||||
"eventtitleaddon" => Self::EventTitleAddon,
|
||||
"holder" => Self::Holder,
|
||||
"howpublished" => Self::HowPublished,
|
||||
"isbn" => Self::Isbn,
|
||||
"issn" => Self::Issn,
|
||||
"issue" => Self::Issue,
|
||||
"issuesubtitle" => Self::IssueSubtitle,
|
||||
"issuetitle" => Self::IssueTitle,
|
||||
"issuetitleaddon" => Self::IssueTitleAddon,
|
||||
"journal" => Self::Journal,
|
||||
"journalsubtitle" => Self::JournalSubtitle,
|
||||
"journaltitle" => Self::JournalTitle,
|
||||
"journaltitleaddon" => Self::JournalTitleAddon,
|
||||
"language" => Self::Language,
|
||||
"location" => Self::Location,
|
||||
"maintitle" => Self::MainTitle,
|
||||
"mainsubtitle" => Self::MainSubtitle,
|
||||
"maintitleaddon" => Self::MainTitleAddon,
|
||||
"note" => Self::Note,
|
||||
"origlanguage" => Self::OrigLanguage,
|
||||
"publisher" => Self::Publisher,
|
||||
"pubstate" => Self::Pubstate,
|
||||
"series" => Self::Series,
|
||||
"subtitle" => Self::Subtitle,
|
||||
"title" => Self::Title,
|
||||
"titleaddon" => Self::TitleAddon,
|
||||
"type" => Self::Type,
|
||||
"unknown" => Self::Unknown,
|
||||
"url" => Self::Url,
|
||||
"venue" => Self::Venue,
|
||||
"version" => Self::Version,
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue