Skip to content

Commit

Permalink
refactor: extracts parse_key
Browse files Browse the repository at this point in the history
- do not remove braces
- fixes test helper
  • Loading branch information
mapreal19 committed Jul 21, 2021
1 parent 2c191ef commit 074da38
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions lib/bibtex/lexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -302,23 +302,26 @@ def enter_object
@mode = @active_object = :entry
push [:NAME, @scanner.matched]

# TODO: DRY - try to parse key
if @scanner.scan(Lexer.patterns[:lbrace])
@brace_level += 1
push([:LBRACE, '{'])
@mode = :content if @brace_level > 1 || @brace_level == 1 && active?(:comment)

if @scanner.scan(Lexer.patterns[allow_missing_keys? ? :optional_key : :key])
key = @scanner.matched.chop.strip.tr('{}', '')
push [:KEY, key]
end
parse_key
end

else
error_unexpected_object
end
end

def parse_key
return unless @scanner.scan(Lexer.patterns[allow_missing_keys? ? :optional_key : :key])

key = @scanner.matched.chop.strip
push [:KEY, key]
end

# Called when parser leaves a BibTeX object.
def leave_object
@mode = :meta
Expand Down
2 changes: 1 addition & 1 deletion test/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
end

begin
if RUBY_PLATFORM < 'java'
if RUBY_PLATFORM == 'java'
require 'debug'
Debugger.start
else
Expand Down

0 comments on commit 074da38

Please sign in to comment.