Skip to content

Commit

Permalink
BibLaTeX: new subparser based on BibTeX parser
Browse files Browse the repository at this point in the history
Close universal-ctags#3802.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
  • Loading branch information
masatake committed Sep 17, 2023
1 parent 90ac58e commit 786e463
Show file tree
Hide file tree
Showing 12 changed files with 352 additions and 38 deletions.
1 change: 1 addition & 0 deletions Tmain/list-subparsers-all.d/stdout-expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Ant XML base <> sub {bidirectional}
Autoconf M4 base <> sub {bidirectional}
Automake Make base <= sub {dedicated}
Bats Sh base <= sub {dedicated}
BibLaTeX BibTeX base <> sub {bidirectional}
DBusIntrospect XML base <> sub {bidirectional}
FunctionParameters Perl base <> sub {bidirectional}
GemSpec Ruby base <= sub {dedicated}
Expand Down
1 change: 1 addition & 0 deletions Units/parser-bibtex.r/bib-simple.d/args.ctags
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
--sort=no
--fields=+l
33 changes: 17 additions & 16 deletions Units/parser-bibtex.r/bib-simple.d/expected.tags
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
1957-doe_loc_ident input.bib /^@article{1957-doe_loc_ident,$/;" a
doe+rocket input.bib /^@Book{doe+rocket,$/;" b
tiny_collect input.bib /^@booklet{tiny_collect,$/;" B
1960-rocket_deep-exploration input.bib /^@conference{1960-rocket_deep-exploration,$/;" c
1961-doe-diverse_splits input.bib /^@inbook{1961-doe-diverse_splits,$/;" i
1960-doe-location_splits input.bib /^@incollection{1960-doe-location_splits,$/;" I
1959-rocket_exploration input.bib /^@INPROCEEDINGS{1959-rocket_exploration,$/;" j
man_loc_splits input.bib /^@manual{man_loc_splits,$/;" m
doe_mastersth input.bib /^@mastersthesis{doe_mastersth,$/;" M
doe_mastersth_data input.bib /^@misc{doe_mastersth_data,$/;" n
doe_phd input.bib /^@phdthesis{doe_phd,$/;" p
1960_conf_splits input.bib /^@proceedings{1960_conf_splits,$/;" P
john_doe input.bib /^@string{john_doe = "Prof. Dr. John Doe"}$/;" s
1961_splits input.bib /^@techreport{1961_splits$/;" t
xx_thoughts input.bib /^@unpublished{xx_thoughts,$/;" u
hicks:2001 input.bib /^@Book{hicks:2001,$/;" b
1957-doe_loc_ident input.bib /^@article{1957-doe_loc_ident,$/;" a language:BibTeX
doe+rocket input.bib /^@Book{doe+rocket,$/;" b language:BibTeX
tiny_collect input.bib /^@booklet{tiny_collect,$/;" B language:BibTeX
1960-rocket_deep-exploration input.bib /^@conference{1960-rocket_deep-exploration,$/;" c language:BibTeX
1961-doe-diverse_splits input.bib /^@inbook{1961-doe-diverse_splits,$/;" i language:BibTeX
1960-doe-location_splits input.bib /^@incollection{1960-doe-location_splits,$/;" I language:BibTeX
1959-rocket_exploration input.bib /^@INPROCEEDINGS{1959-rocket_exploration,$/;" j language:BibTeX
man_loc_splits input.bib /^@manual{man_loc_splits,$/;" m language:BibTeX
doe_mastersth input.bib /^@mastersthesis{doe_mastersth,$/;" M language:BibTeX
doe_mastersth_data input.bib /^@misc{doe_mastersth_data,$/;" n language:BibTeX
doe_phd input.bib /^@phdthesis{doe_phd,$/;" p language:BibTeX
1960_conf_splits input.bib /^@proceedings{1960_conf_splits,$/;" P language:BibTeX
john_doe input.bib /^@string{john_doe = "Prof. Dr. John Doe"}$/;" s language:BibTeX
1961_splits input.bib /^@techreport{1961_splits$/;" t language:BibTeX
xx_thoughts input.bib /^@unpublished{xx_thoughts,$/;" u language:BibTeX
hicks:2001 input.bib /^@Book{hicks:2001,$/;" b language:BibTeX
knuthwebsite input.bib /^@online{knuthwebsite,$/;" V language:BibLaTeX
8 changes: 8 additions & 0 deletions Units/parser-bibtex.r/bib-simple.d/input.bib
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,11 @@ @Book{hicks:2001
edition = "1st,",
isbn = "0-69-697269-4"
}

@Comment Taken fron https://ja.overleaf.com/learn/latex/Bibliography_management_with_biblatex
@online{knuthwebsite,
author = "Donald Knuth",
title = "Knuth: Computers and Typesetting",
url = "http://www-cs-faculty.stanford.edu/~uno/abcde.html",
keywords = "latex,knuth"
}
1 change: 1 addition & 0 deletions docs/news.rst
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ The following parsers have been added:
* Autoconf
* Automake
* AutoIt
* BibLaTeX *BibTeX based subparser*
* BibTeX
* Clojure
* CMake *optlib*
Expand Down
1 change: 1 addition & 0 deletions main/parsers_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
BasicParser, \
BatsParser, \
BetaParser, \
BibLaTeXParser, \
BibtexParser, \
ClojureParser, \
CMakeParser, \
Expand Down
253 changes: 253 additions & 0 deletions parsers/biblatex.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,253 @@
/*
* Copyright (c) 2023, Masatake YAMATO
*
* This source code is released for free distribution under the terms of the
* GNU General Public License version 2 or (at your option) any later version.
*
* This module contains functions for generating tags for BibLaTeX source files
* https://ftp.yz.yamagata-u.ac.jp/pub/CTAN/macros/latex/contrib/biblatex/doc/biblatex.pdf
*
*/

/*
* INCLUDE FILES
*/
#include "general.h" /* must always come first */

#include "bibtex.h"
#include "keyword.h"
#include "parse.h"
#include "read.h"

/*
* DATA DECLARATIONS
*/
struct bibLaTeXSubparser {
bibTexSubparser bib;
};

enum BibLaTeXKind {
K_ARTWORK,
K_AUDIO,
K_BIBNOTE,
K_BOOKINBOOK,
K_BOOKLET,
K_COLLECTION,
K_COMMENTARY,
K_DATASET,
K_IMAGE,
K_INTERFERENCE,
K_JURISDICTION,
K_LEGISLATION,
K_LEGAL,
K_LETTER,
K_MOVIE,
K_MUSIC,
K_MVBOOK,
K_MVCOLLECTION,
K_MVPROCEEDINGS,
K_MVREFERENCE,
K_ONLINE,
K_PATENT,
K_PERFORMANCE,
K_PERIODICAL,
K_REFERENCE,
K_REPORT,
K_REVIEW,
K_SET,
K_SOFTWARE,
K_STANDARD,
K_SUPPBOOK,
K_SUPPCOLLECTION,
K_SUPPPERIODICAL,
K_THESIS,
K_VIDEO,
K_XDATA,
};

/*
* DATA DEFINITIONS
*/
static kindDefinition BibLaTeXKinds[] = {
{ true, 'A', "artwork", "artworks" },
{ true, 'B', "audio", "audios" },
{ true, 'C', "bibnote", "bibnotes" },
{ true, 'D', "bookinbook", "bookinbooks" },
{ true, 'E', "Booklet", "Booklets" },
/* F is for reserved in main. */
{ true, 'G', "collection", "collections" },
{ true, 'H', "commentary", "commentarys" },
{ true, 'I', "dataset", "datasets" },
{ true, 'J', "image", "images" },
{ true, 'K', "interference", "interferences" },
{ true, 'L', "jurisdiction", "jurisdictions" },
{ true, 'M', "legislation", "legislations" },
{ true, 'N', "legal", "legals" },
{ true, 'O', "letter", "letters" },
{ true, 'P', "movie", "movies" },
{ true, 'Q', "music", "musics" },
{ true, 'R', "mvbook", "mvbooks" },
{ true, 'S', "mvcollection", "mvcollections" },
{ true, 'T', "mvproceedings", "mvproceedings" },
{ true, 'U', "mvreference", "mvreferences" },
{ true, 'V', "online", "onlines" },
{ true, 'W', "patent", "patents" },
/* X, Y, Z are reserved. */
/* a, b, c, d, e, f are reserved for custom[a-f]. */
{ true, 'g', "performance", "performances" },
{ true, 'h', "periodical", "periodicals" },
{ true, 'i', "reference", "references" },
{ true, 'j', "report", "reports" },
{ true, 'k', "review", "reviews" },
{ true, 'l', "set", "sets" },
{ true, 'm', "software", "software" },
{ true, 'n', "standard", "standards" },
{ true, 'o', "suppbook", "suppbooks" },
{ true, 'p', "suppcollection", "suppcollections" },
{ true, 'q', "suppperiodical", "suppperiodicals" },
{ true, 'r', "thesis", "thesis" },
{ true, 's', "video", "videos" },
{ true, 't', "xdata", "xdatas" },
/* x, y, z are reserved. */
};

static const keywordTable BibLaTeXTable [] = {
{ "artwork", K_ARTWORK },
{ "audio", K_AUDIO },
{ "bibnote", K_BIBNOTE },
{ "bookinbook", K_BOOKINBOOK },
{ "Booklet", K_BOOKLET },
{ "collection", K_COLLECTION },
{ "commentary", K_COMMENTARY },
{ "dataset", K_DATASET },
{ "image", K_IMAGE },
{ "interference", K_INTERFERENCE },
{ "jurisdiction", K_JURISDICTION },
{ "legislation", K_LEGISLATION },
{ "legal", K_LEGAL },
{ "letter", K_LETTER },
{ "movie", K_MOVIE },
{ "music", K_MUSIC },
{ "mvbook", K_MVBOOK },
{ "mvcollection", K_MVCOLLECTION },
{ "mvproceedings", K_MVPROCEEDINGS },
{ "mvreference", K_MVREFERENCE },
{ "online", K_ONLINE },
{ "patent", K_PATENT },
{ "performance", K_PERFORMANCE },
{ "periodical", K_PERIODICAL },
{ "reference", K_REFERENCE },
{ "report", K_REPORT },
{ "review", K_REVIEW },
{ "set", K_SET },
{ "software", K_SOFTWARE },
{ "standard", K_STANDARD },
{ "suppbook", K_SUPPBOOK },
{ "suppcollection", K_SUPPCOLLECTION },
{ "suppperiodical", K_SUPPPERIODICAL },
{ "thesis", K_THESIS },
{ "video", K_VIDEO },
{ "xdata", K_XDATA },
};

static langType Lang_biblatex;

/*
* FUNCTION DEFINITIONS
*/
static int isKeywordForTagging (bibTexSubparser *bibtex,
const char *string)
{
int kind = lookupKeyword (string, Lang_biblatex);
if (kind == KEYWORD_NONE)
return KIND_GHOST_INDEX;
return kind;
}

static void findBibLaTeXTags (void)
{
scheduleRunningBaseparser (RUN_DEFAULT_SUBPARSERS);
}

static struct bibLaTeXSubparser bibLaTeXSubparser = {
.bib = {
.subparser = {
.direction = SUBPARSER_BI_DIRECTION,
},
.isKeywordForTagging = isKeywordForTagging,
},
};

static void initialize (const langType language)
{
Lang_biblatex = language;
}

extern parserDefinition* BibLaTeXParser (void)
{
parserDefinition* const def = parserNew("BibLaTeX");

static parserDependency dependencies [] = {
[0] = { DEPTYPE_SUBPARSER, "BibTeX", &bibLaTeXSubparser },
};

def->dependencies = dependencies;
def->dependencyCount = ARRAY_SIZE (dependencies);

def->keywordTable = BibLaTeXTable;
def->keywordCount = ARRAY_SIZE (BibLaTeXTable);

def->kindTable = BibLaTeXKinds;
def->kindCount = ARRAY_SIZE(BibLaTeXKinds);

def->parser = findBibLaTeXTags;
def->initialize = initialize;

return def;
}

/*
(defconst biblatex-kinds '(
("artwork")
("audio")
("bibnote")
("bookinbook")
("Booklet")
("collection")
("commentary")
("dataset")
("image")
("interference")
("jurisdiction")
("legislation")
("legal")
("letter")
("movie")
("music")
("mvbook")
("mvcollection")
("mvproceedings" . t)
("mvreference")
("online")
("patent")
("performance")
("periodical")
("reference")
("report")
("review")
("set")
("software" . t)
("standard")
("suppbook")
("suppcollection")
("suppperiodical")
("thesis")
("video")
("xdata")))
(mapc (lambda (x)
;(insert (format " K_%s,\n" (upcase (car x))))
;(insert (format " { true, '', \"%s\", \"%s\" },\n" (car x) (if (cdr x) (car x) (concat (car x) "s"))))
(insert (format " { \"%s\", K_%s },\n" (car x) (upcase (car x))))
)
biblatex-kinds)
*/
Loading

0 comments on commit 786e463

Please sign in to comment.