Skip to content

Allows braces on citekey#151

Closed
mapreal19 wants to merge 5 commits intomasterfrom
mario/feat/allow-braces-citekey
Closed

Allows braces on citekey#151
mapreal19 wants to merge 5 commits intomasterfrom
mario/feat/allow-braces-citekey

Conversation

@mapreal19
Copy link
Collaborator

@mapreal19 mapreal19 commented Jul 19, 2021

Closes #150

@mapreal19
Copy link
Collaborator Author

mapreal19 commented Jul 19, 2021

@inukshuk this is what I attempted to fix #150 but is breaking other tests. This is the right direction?

@mapreal19
Copy link
Collaborator Author

Travis not running tests? Shall we move it to Github Actions?

@inukshuk
Copy link
Owner

I was thinking to only change the lexer pattern for the parser to accept braces; we shouldn't strip them off the key, because it would be unexpected for the parser to alter the contents (this would have to go into some kind of optional filter, e.g., normalize_keys or something like that, but I don't think that it's necessary)

Yes, I think we're still configured for travis-ci.org which has been suspended and moving to Github Actions would be desirable. I'll open an issue for it.

@mapreal19
Copy link
Collaborator Author

ok! I'll help with CI first

@mapreal19 mapreal19 force-pushed the mario/feat/allow-braces-citekey branch from 5a3c5f1 to 074da38 Compare July 21, 2021 08:14
@mapreal19
Copy link
Collaborator Author

@inukshuk you can see the failing tests. Any idea of why including the braces in the regex pattern is breaking those tests?

@inukshuk
Copy link
Owner

Hm, for some reason adding the braces seems to make the key pattern match even beyond the final comma -- it's not obvious on a quick glance why that would happen. I'll have to take a closer look.

@mapreal19
Copy link
Collaborator Author

@inukshuk worth pursuing this issue?

@inukshuk
Copy link
Owner

Sure. Maybe it's just that the pattern is thrown off because the - is treated as a range delimiter because it's not at the end of the group anymore. Does it work if you escape the minus or move it back to immediately in front of the closing bracket?

@mapreal19 mapreal19 self-assigned this Nov 22, 2024
@mapreal19 mapreal19 force-pushed the mario/feat/allow-braces-citekey branch from 074da38 to caf2253 Compare November 22, 2024 19:48
@mapreal19
Copy link
Collaborator Author

I tried that but still one test that fails

@mapreal19 mapreal19 requested a review from Copilot July 19, 2025 15:38
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for allowing braces in BibTeX citation keys, which expands the valid character set for cite-key parsing.

  • Updates lexer regex patterns to include curly braces as valid characters in citation keys
  • Refactors key parsing logic into a dedicated method for better code organization
  • Adds comprehensive test coverage for the new brace support functionality

Reviewed Changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 1 comment.

File Description
lib/bibtex/lexer.rb Updates regex patterns to allow braces in keys and refactors key parsing into separate method
test/bibtex/test_lexer.rb Adds test for brace support and updates test syntax to modern Minitest format
test/test_bibtex.rb Enhances existing tests with better error message validation and updated test data
Gemfile Adds logger dependency
Comments suppressed due to low confidence (1)

test/test_bibtex.rb:119
*

        @article{foo, },

gemspec

gem 'json', '~>2.0', platforms: %i[mri_18 jruby]
gem 'logger'
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added to fix this warning:

warning: logger was loaded from the standard library, but will no longer be part of the default gems starting from Ruby 3.5.0.

Timeout.timeout(2) do
BibTeX.parse(<<EOF, allow_missing_keys: true)
@article{},
@article{foo, },
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is the test that was failing, I couldn't find a proper way of fixing. Using an alternative test case here works.

@mapreal19 mapreal19 requested a review from inukshuk July 19, 2025 15:43
@mapreal19
Copy link
Collaborator Author

@inukshuk can you check again when having some time? I gave it another try

@mapreal19 mapreal19 changed the title feat: allows braces on citekey Allows braces on citekey Jul 19, 2025
inukshuk added a commit that referenced this pull request Jul 20, 2025
inukshuk added a commit that referenced this pull request Jul 20, 2025
Obviously this can't work with optional keys.

Closes #150 #151
@inukshuk
Copy link
Owner

inukshuk commented Jul 20, 2025

You can't allow braces with optional keys, otherwise for an entry like:

@article{}

It will parse the closing brace as the key.

I added the braces to the default pattern for mandatory keys, but I remain doubtful that it's a good practice to use braces in keys. I'm not sure if it's valid or if there is useful reason to define bibtex entries with only a key and nothing else, because that would also not work for exampe:

@article{myid}

Because it would also add the closing brace to the key.

So, personally, I'd be in favor of leaving the default pattern as is. Overwrite the pattern locally to support braces.

@inukshuk inukshuk closed this Jul 20, 2025
@mapreal19
Copy link
Collaborator Author

Thanks @inukshuk!

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.

Braces in citekey

2 participants