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

Added BibTeX Lexer #1360

Merged
merged 14 commits into from Jun 1, 2020
Merged

Added BibTeX Lexer #1360

merged 14 commits into from Jun 1, 2020

Conversation

alexlihengwang
Copy link
Contributor

@alexlihengwang alexlihengwang commented Nov 14, 2019

BibTeX Lexer based on PrismJS-BibTeX.

This fixes #1357.

@pyrmont pyrmont self-assigned this Nov 14, 2019
@pyrmont pyrmont added the needs-review The PR needs to be reviewed label Nov 14, 2019
@alexlihengwang
Copy link
Contributor Author

Hello, I have rewritten the lexer and added the missing demo file.

@pyrmont
Copy link
Contributor

pyrmont commented Nov 15, 2019

@alexlihengwang Thanks :) Will try to get to this over the weekend!

lib/rouge/lexers/bibtex.rb Outdated Show resolved Hide resolved
@pyrmont pyrmont added author-action The PR has been reviewed but action by the author is needed and removed needs-review The PR needs to be reviewed labels Dec 18, 2019
Copy link
Contributor

@pyrmont pyrmont left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR submission and sorry it's taken a bit of time to get to reviewing! I hope the comments all make sense but please feel free to ask if something is a bit inexplicable :)

lib/rouge/lexers/bibtex.rb Outdated Show resolved Hide resolved
lib/rouge/lexers/bibtex.rb Show resolved Hide resolved
lib/rouge/lexers/bibtex.rb Show resolved Hide resolved
spec/visual/samples/bibtex Outdated Show resolved Hide resolved
@pyrmont
Copy link
Contributor

pyrmont commented Apr 7, 2020

@alexlihengwang Have you had a chance to look at the comments I made in December?

@pyrmont
Copy link
Contributor

pyrmont commented Apr 7, 2020

Also pinging @ph03 given you filed the original issue. Perhaps you can answer some of the questions above.

@alexpovel
Copy link

Having BibTeX support in rouge would allow for syntax highlighting in GitLab, which led me to this PR.

I know nothing of Ruby, little about bib(la)tex but a thing or two about LaTeX in general. Therefore, I won't be able to help with code, but maybe still give you some useful pointers.

The following is based on biblatex, whose documentation in PDF format is here, the source of which is on GitHub. The "official" bib example file is probably a good body for testing.

biblatex uses biber as its back-end processing tool, and here it says that biber in turn relies on btparse, a C library. The latter is documented really well here. biblatex is the de-facto current standard, so relying on what they are relying on should be safe. The Synopsis of bt_language has this to say:

# Lexical grammar, mode 1: top-level
AT                    \@
NEWLINE               \n
COMMENT               \%~[\n]*\n
WHITESPACE            [\ \r\t]+
JUNK                  ~[\@\n\ \r\t]+

# Lexical grammar, mode 2: in-entry
NEWLINE               \n
COMMENT               \%~[\n]*\n
WHITESPACE            [\ \r\t]+
NUMBER                [0-9]+
NAME                  [a-z0-9\!\$\&\*\+\-\.\/\:\;\<\>\?\[\]\^\_\`\|]+
LBRACE                \{
RBRACE                \}
LPAREN                \(
RPAREN                \)
EQUALS                =
HASH                  \#
COMMA                 ,
QUOTE                 \"

Regarding your comments for the PR, @pyrmont , two things are shown there: numbers are indeed only [0-9]+, or [\d]+ (like in pygments, as referenced in the original issue).

As a side-note, it also says:

One of the problems with BibTeX is that there is no formal specification of the language. This means that users exploring the arcane corners of the language are largely on their own, and programmers implementing their own parsers are completely on their own---except for observing the behaviour of the original implementation.

Ouch... anyway.


Escaping quotes with \" does not seem to be how it is done, see here. In the example file linked above, \" occurs to create German umlauts, aka for turning {\"U}ber into Über in the output (when there's no UTF8...). In bt_language.pod as linked above, it says:

" always starts a string, regardless of context.

@pyrmont
Copy link
Contributor

pyrmont commented May 30, 2020

I think this is good to merge. I'll leave it for a couple more days in case there is any additional feedback.

Thanks a lot for providing the information you did, @alexpovel. That was very helpful!

@pyrmont pyrmont added needs-review The PR needs to be reviewed and removed author-action The PR has been reviewed but action by the author is needed labels May 30, 2020
@alexpovel
Copy link

Oh that was a pleasant resolve then, thanks @pyrmont ! Glad I could clear things up, after @alexlihengwang implemented everything.

@pyrmont pyrmont merged commit 85e1a4a into rouge-ruby:master Jun 1, 2020
@pyrmont
Copy link
Contributor

pyrmont commented Jun 1, 2020

@alexlihengwang @alexpovel Thanks to both of you for your help on this. This will be part of the next version of Rouge, v3.20.0. That will be pushed to RubyGems on Tuesday 9 June 🎉 Thanks again!

@pyrmont pyrmont removed the needs-review The PR needs to be reviewed label Jun 1, 2020
@alexlihengwang
Copy link
Contributor Author

Thanks for the help @alexpovel @pyrmont

mattt pushed a commit to NSHipster/rouge that referenced this pull request May 19, 2021
This commit adds a lexer for BibTeX.

Co-authored-by: Alex Liheng Wang <alw1@GS17003.SP.CS.CMU.EDU>
Co-authored-by: Michael Camilleri <mike@inqk.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for BibTeX
3 participants