bibtex-ruby 2.0.4 → 2.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile CHANGED
@@ -2,7 +2,7 @@ source :rubygems
2
2
  gemspec
3
3
 
4
4
  group :debug do
5
- gem 'ruby-debug19', :require => 'ruby-debug', :platforms => [:mri_19]
5
+ gem 'debugger', :platforms => [:mri_19]
6
6
  gem 'ruby-debug', :platforms => [:mri_18]
7
7
  gem 'rbx-trepanning', :platforms => [:rbx]
8
8
  end
@@ -16,5 +16,5 @@ end
16
16
 
17
17
  group :profile do
18
18
  gem 'ruby-prof', ['~>0.10'], :platforms => [:mri_19, :mri_19]
19
- gem 'gnuplot', ['~>2.3']
19
+ gem 'gnuplot', ['~>2.4']
20
20
  end
data/Gemfile.lock CHANGED
@@ -1,71 +1,67 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bibtex-ruby (2.0.4)
4
+ bibtex-ruby (2.0.5)
5
5
  latex-decode (>= 0.0.6)
6
- multi_json (~> 1.0)
6
+ multi_json (~> 1.3)
7
7
 
8
8
  GEM
9
9
  remote: http://rubygems.org/
10
10
  specs:
11
- archive-tar-minitar (0.5.2)
12
11
  autowatchr (0.1.5)
13
12
  watchr
14
13
  builder (3.0.0)
15
- columnize (0.3.4)
16
- cucumber (1.0.2)
14
+ coderay (1.0.5)
15
+ columnize (0.3.6)
16
+ cucumber (1.1.9)
17
17
  builder (>= 2.1.2)
18
18
  diff-lcs (>= 1.1.2)
19
- gherkin (~> 2.4.5)
19
+ gherkin (~> 2.9.0)
20
20
  json (>= 1.4.6)
21
- term-ansicolor (>= 1.0.5)
22
- diff-lcs (1.1.2)
23
- gherkin (2.4.18)
21
+ term-ansicolor (>= 1.0.6)
22
+ debugger (1.0.0)
23
+ columnize (>= 0.3.1)
24
+ debugger-linecache
25
+ debugger-ruby_core_source
26
+ debugger-linecache (1.0.1)
27
+ debugger-ruby_core_source
28
+ debugger-ruby_core_source (1.0.1)
29
+ diff-lcs (1.1.3)
30
+ gherkin (2.9.0)
24
31
  json (>= 1.4.6)
25
- gherkin (2.4.18-java)
32
+ gherkin (2.9.0-java)
26
33
  json (>= 1.4.6)
27
- gnuplot (2.3.6)
28
- json (1.5.4)
29
- json (1.5.4-java)
30
- latex-decode (0.0.10)
34
+ gnuplot (2.4.1)
35
+ json (1.6.5)
36
+ json (1.6.5-java)
37
+ latex-decode (0.0.12)
31
38
  unicode (~> 0.4)
32
39
  linecache (0.46)
33
40
  rbx-require-relative (> 0.0.4)
34
- linecache19 (0.5.12)
35
- ruby_core_source (>= 0.1.4)
36
- minitest (2.3.1)
37
- multi_json (1.0.4)
41
+ minitest (2.11.3)
42
+ multi_json (1.3.2)
38
43
  mynyml-redgreen (0.7.1)
39
44
  term-ansicolor (>= 1.0.4)
40
- racc (1.4.6)
41
- rake (0.9.2)
45
+ racc (1.4.8)
46
+ rake (0.9.2.2)
42
47
  rbx-linecache (1.3)
43
48
  rbx-require-relative
44
- rbx-require-relative (0.0.5)
45
- rbx-trepanning (1.8.7)
49
+ rbx-require-relative (0.0.9)
50
+ rbx-trepanning (0.1.0)
51
+ coderay (>= 1.0)
46
52
  columnize
47
- diff-lcs
48
- rbx-linecache (~> 1.2)
53
+ rbx-linecache (~> 1.3)
49
54
  rbx-require-relative (>= 0.0.4)
50
- rdoc (3.9.1)
55
+ rdoc (3.12)
56
+ json (~> 1.4)
51
57
  ruby-debug (0.10.4)
52
58
  columnize (>= 0.1)
53
59
  ruby-debug-base (~> 0.10.4.0)
54
60
  ruby-debug-base (0.10.4)
55
61
  linecache (>= 0.3)
56
- ruby-debug-base19 (0.11.25)
57
- columnize (>= 0.3.1)
58
- linecache19 (>= 0.5.11)
59
- ruby_core_source (>= 0.1.4)
60
- ruby-debug19 (0.11.6)
61
- columnize (>= 0.3.1)
62
- linecache19 (>= 0.5.11)
63
- ruby-debug-base19 (>= 0.11.19)
64
62
  ruby-prof (0.10.8)
65
- ruby_core_source (0.1.5)
66
- archive-tar-minitar (>= 0.5.2)
67
- term-ansicolor (1.0.5)
68
- unicode (0.4.0)
63
+ term-ansicolor (1.0.7)
64
+ unicode (0.4.2)
69
65
  watchr (0.7)
70
66
 
71
67
  PLATFORMS
@@ -76,7 +72,8 @@ DEPENDENCIES
76
72
  autowatchr (~> 0.1)
77
73
  bibtex-ruby!
78
74
  cucumber (~> 1.0)
79
- gnuplot (~> 2.3)
75
+ debugger
76
+ gnuplot (~> 2.4)
80
77
  minitest
81
78
  mynyml-redgreen (~> 0.7)
82
79
  racc (~> 1.4)
@@ -84,5 +81,4 @@ DEPENDENCIES
84
81
  rbx-trepanning
85
82
  rdoc (~> 3.9)
86
83
  ruby-debug
87
- ruby-debug19
88
84
  ruby-prof (~> 0.10)
data/History.txt CHANGED
@@ -1,3 +1,9 @@
1
+ 2.0.5 /
2
+
3
+ * Fixed Entry#dup (@JLimperg)
4
+ * Implemented explicit caching of regular expressions (for MacRuby)
5
+ * Switched to new MultiJson API
6
+
1
7
  2.0.4 / 2011-12-20
2
8
  ==================
3
9
 
data/Manifest CHANGED
@@ -19,6 +19,7 @@ features/issues/braced_strings.feature
19
19
  features/issues/crossref.feature
20
20
  features/issues/latex_filter.feature
21
21
  features/issues/multiline_strings.feature
22
+ features/issues/name_parsing.feature
22
23
  features/issues/number_keys.feature
23
24
  features/issues/parse_months.feature
24
25
  features/issues/slash_keys.feature
@@ -82,6 +83,8 @@ test/fixtures/no_bibtex.bib
82
83
  test/fixtures/preamble.bib
83
84
  test/fixtures/roundtrip.bib
84
85
  test/helper.rb
86
+ test/macruby.d
87
+ test/macruby.rb
85
88
  test/profile.rb
86
89
  test/test_bibtex.rb
87
90
  test/test_export.rb
data/bibtex-ruby.gemspec CHANGED
@@ -26,7 +26,7 @@ Gem::Specification.new do |s|
26
26
  END_DESCRIPTION
27
27
 
28
28
  s.add_runtime_dependency('latex-decode', ['>=0.0.6'])
29
- s.add_runtime_dependency('multi_json', ['~>1.0'])
29
+ s.add_runtime_dependency('multi_json', ['~>1.3'])
30
30
 
31
31
  s.add_development_dependency('rake', ['~>0.9'])
32
32
  s.add_development_dependency('racc', ['~>1.4'])
data/examples/bib2html.rb CHANGED
@@ -34,4 +34,4 @@ rescue LoadError
34
34
  exit
35
35
  end
36
36
 
37
- puts Redcarpet.new(content.join).to_html
37
+ puts Redcarpet::Markdown.new(Redcarpet::Render::HTML).render(content.join)
@@ -0,0 +1,19 @@
1
+ Feature: BibTeX Names
2
+ As a hacker who works with bibliographies
3
+ I want to be able to access individual parts of names in a BibTeX file
4
+
5
+ Scenario Outline: Name Parsing
6
+ When I parse the name "<name>"
7
+ Then the parts should be:
8
+ | first | von | last | jr |
9
+ | <first> | <von> | <last> | <jr> |
10
+
11
+ @names @issue-46
12
+ Scenarios: Names with LaTeX commands
13
+ | name | first | von | last | jr |
14
+ | G{\\"u}rkan, G. | G. | | G{\\"u}rkan | |
15
+ | {\"O}zge, A. | A. | | {\"O}zge | |
16
+ | Yonca Ozge, A. | A. | | Yonca Ozge | |
17
+ | Yonca \"Ozge, A. | A. | | Yonca \"Ozge | |
18
+ | Yonca Özge, A. | A. | | Yonca Özge | |
19
+ | Yonca {\"O}Zge, A. | A. | | Yonca {\"O}Zge | |
@@ -8,7 +8,7 @@ Feature: BibTeX Names
8
8
  | first | von | last | jr |
9
9
  | <first> | <von> | <last> | <jr> |
10
10
 
11
- @display
11
+ @names @display
12
12
  Scenarios: Decoret test suite (display order)
13
13
  | name | first | von | last | jr |
14
14
  | AA BB | AA | | BB | |
@@ -32,7 +32,7 @@ Feature: BibTeX Names
32
32
  | AA bb {cc} DD | AA | bb | {cc} DD | |
33
33
  | AA {bb} CC | AA {bb} | | CC | |
34
34
 
35
- @sort
35
+ @names @sort
36
36
  Scenarios: Decoret test suite (sort order)
37
37
  | name | first | von | last | jr |
38
38
  | bb CC, AA | AA | bb | CC | |
@@ -46,7 +46,7 @@ Feature: BibTeX Names
46
46
  | CC dd BB, AA | AA | CC dd | BB | |
47
47
  | BB, AA | AA | | BB | |
48
48
 
49
- @sort
49
+ @names @sort
50
50
  Scenarios: Long von parts
51
51
  | name | first | von | last | jr |
52
52
  | bb cc dd CC, AA | AA | bb cc dd | CC | |
@@ -54,7 +54,7 @@ Feature: BibTeX Names
54
54
  | BB cc dd CC, AA | AA | BB cc dd | CC | |
55
55
  | BB CC dd CC, AA | AA | BB CC dd | CC | |
56
56
 
57
-
57
+ @names
58
58
  Scenarios: Decoret further remarks
59
59
  | name | first | von | last | jr |
60
60
  # | Paul \'Emile Victor | Paul \'Emile | | Victor | |
@@ -69,6 +69,7 @@ Feature: BibTeX Names
69
69
  | Dominique {G}alouzeau de Villepin | Dominique | {G}alouzeau de | Villepin | |
70
70
  | Galouzeau {de} Villepin, Dominique | Dominique | | Galouzeau {de} Villepin | |
71
71
 
72
+ @names
72
73
  Scenarios: Some actual names
73
74
  | name | first | von | last | jr |
74
75
  | John Paul Jones | John Paul | | Jones | |
@@ -316,7 +316,7 @@ module BibTeX
316
316
 
317
317
  # Returns a JSON representation of the bibliography.
318
318
  def to_json(options = {})
319
- MultiJson.encode(to_a(options))
319
+ MultiJson.dump(to_a(options))
320
320
  end
321
321
 
322
322
  # Returns a CiteProc JSON representation of the bibliography. Only BibTeX enrties are exported.
@@ -124,7 +124,7 @@ module BibTeX
124
124
  end
125
125
 
126
126
  def to_json(options = {})
127
- MultiJson.encode(to_hash(options))
127
+ MultiJson.dump(to_hash(options))
128
128
  end
129
129
 
130
130
  def to_xml(options = {})
data/lib/bibtex/entry.rb CHANGED
@@ -335,9 +335,10 @@ module BibTeX
335
335
  # add(:author, "Edgar A. Poe", :title, "The Raven")
336
336
  # add([:author, "Edgar A. Poe", :title, "The Raven"])
337
337
  # add(:author => "Edgar A. Poe", :title => "The Raven")
338
+ # add(:author => Names.new(Name.new(:first => 'Edgar A.', :last => 'Poe')))
338
339
  def add(*arguments)
339
340
  Hash[*arguments.flatten].each_pair do |name, value|
340
- fields[name.to_sym] = Value.new(value)
341
+ fields[name.to_sym] = Value.create(value)
341
342
  end
342
343
 
343
344
  self
@@ -374,7 +375,9 @@ module BibTeX
374
375
  end
375
376
 
376
377
  if bibliography.options.has_key?(:filter)
377
- convert!(bibliography.options[:filter])
378
+ [*bibliography.options[:filter]].each do |filter|
379
+ convert!(filter)
380
+ end
378
381
  end
379
382
 
380
383
  self
data/lib/bibtex/lexer.rb CHANGED
@@ -37,6 +37,29 @@ module BibTeX
37
37
  :strip => true
38
38
  }.freeze
39
39
 
40
+ # Patterns Cache (#37: MacRuby does not cache regular expressions)
41
+ @patterns = {
42
+ :space => /[\s]+/o,
43
+ :lbrace => /\{/o,
44
+ :rbrace => /\}/o,
45
+ :braces => /\{|\}/o,
46
+ :eq => /=/o,
47
+ :comma => /,/o,
48
+ :number => /\d+/o,
49
+ :name => /[[:alpha:]\d \/:_!$\.%&*-]+/io,
50
+ :quote => /"/o,
51
+ :unquote => /[\{\}"]/o,
52
+ :sharp => /#/o,
53
+ :object => /@/o,
54
+ :period => /./o,
55
+ :strict_next => /@[\t ]*/o,
56
+ :next => /(^|\n)[\t ]*@[\t ]*/o,
57
+ :entry => /[a-z\d:_!\.$%&*-]+/io,
58
+ :string => /string/io,
59
+ :comment => /comment/io,
60
+ :preamble => /preamble/io
61
+ }.freeze
62
+
40
63
  MODE = Hash.new(:meta).merge({
41
64
  :bibtex => :bibtex, :entry => :bibtex,
42
65
  :string => :bibtex, :preamble => :bibtex,
@@ -45,7 +68,7 @@ module BibTeX
45
68
  }).freeze
46
69
 
47
70
  class << self
48
- attr_accessor :defaults
71
+ attr_reader :defaults, :patterns
49
72
  end
50
73
 
51
74
  #
@@ -151,37 +174,37 @@ module BibTeX
151
174
 
152
175
  def parse_bibtex
153
176
  case
154
- when @scanner.scan(/[\s]+/o)
155
- when @scanner.scan(/\{/o)
177
+ when @scanner.scan(Lexer.patterns[:space])
178
+ when @scanner.scan(Lexer.patterns[:lbrace])
156
179
  @brace_level += 1
157
180
  push([:LBRACE,'{'])
158
181
  @mode = :content if @brace_level > 1 || @brace_level == 1 && active?(:comment)
159
- when @scanner.scan(/\}/o)
182
+ when @scanner.scan(Lexer.patterns[:rbrace])
160
183
  @brace_level -= 1
161
184
  push([:RBRACE,'}'])
162
185
  return leave_object if @brace_level == 0
163
186
  return error_unbalanced_braces if @brace_level < 0
164
- when @scanner.scan( /=/o)
187
+ when @scanner.scan(Lexer.patterns[:eq])
165
188
  push([:EQ,'='])
166
- when @scanner.scan(/,/o)
189
+ when @scanner.scan(Lexer.patterns[:comma])
167
190
  push([:COMMA,','])
168
- when @scanner.scan(/\d+/o)
191
+ when @scanner.scan(Lexer.patterns[:number])
169
192
  push([:NUMBER,@scanner.matched])
170
- when @scanner.scan(/[[:alpha:]\d \/:_!$\.%&*-]+/io)
193
+ when @scanner.scan(Lexer.patterns[:name])
171
194
  push([:NAME,@scanner.matched.rstrip])
172
- when @scanner.scan(/"/o)
195
+ when @scanner.scan(Lexer.patterns[:quote])
173
196
  @mode = :literal
174
- when @scanner.scan(/#/o)
197
+ when @scanner.scan(Lexer.patterns[:sharp])
175
198
  push([:SHARP,'#'])
176
- when @scanner.scan(/@/o)
199
+ when @scanner.scan(Lexer.patterns[:object])
177
200
  enter_object
178
- when @scanner.scan(/./o)
201
+ when @scanner.scan(Lexer.patterns[:period])
179
202
  error_unexpected_token
180
203
  end
181
204
  end
182
205
 
183
206
  def parse_meta
184
- match = @scanner.scan_until(strict? ? /@[\t ]*/o : /(^|\n)[\t ]*@[\t ]*/o)
207
+ match = @scanner.scan_until(Lexer.patterns[strict? ? :strict_next : :next])
185
208
  if @scanner.matched
186
209
  push([:META_CONTENT,match.chop])
187
210
  enter_object
@@ -192,7 +215,7 @@ module BibTeX
192
215
  end
193
216
 
194
217
  def parse_content
195
- match = @scanner.scan_until(/\{|\}/o)
218
+ match = @scanner.scan_until(Lexer.patterns[:braces])
196
219
  case @scanner.matched
197
220
  when '{'
198
221
  @brace_level += 1
@@ -222,7 +245,7 @@ module BibTeX
222
245
  end
223
246
 
224
247
  def parse_literal
225
- match = @scanner.scan_until(/[\{\}"]/o)
248
+ match = @scanner.scan_until(Lexer.patterns[:unquote])
226
249
  case @scanner.matched
227
250
  when '{'
228
251
  @brace_level += 1
@@ -255,16 +278,16 @@ module BibTeX
255
278
  push [:AT,'@']
256
279
 
257
280
  case
258
- when @scanner.scan(/string/io)
281
+ when @scanner.scan(Lexer.patterns[:string])
259
282
  @mode = @active_object = :string
260
283
  push [:STRING, @scanner.matched]
261
- when @scanner.scan(/preamble/io)
284
+ when @scanner.scan(Lexer.patterns[:preamble])
262
285
  @mode = @active_object = :preamble
263
286
  push [:PREAMBLE, @scanner.matched]
264
- when @scanner.scan(/comment/io)
287
+ when @scanner.scan(Lexer.patterns[:comment])
265
288
  @mode = @active_object = :comment
266
289
  push [:COMMENT, @scanner.matched]
267
- when @scanner.scan(/[a-z\d:_!\.$%&*-]+/io)
290
+ when @scanner.scan(Lexer.patterns[:entry])
268
291
  @mode = @active_object = :entry
269
292
  push [:NAME, @scanner.matched]
270
293
  else
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # DO NOT MODIFY!!!!
3
- # This file is automatically generated by Racc 1.4.6
3
+ # This file is automatically generated by Racc 1.4.8
4
4
  # from Racc grammer file "".
5
5
  #
6
6
 
@@ -13,6 +13,24 @@ module BibTeX
13
13
 
14
14
  module_eval(<<'...end names.y/module_eval...', 'names.y', 94)
15
15
 
16
+ # Patterns Cache (#37: MacRuby does not cache regular expressions)
17
+ @patterns = {
18
+ :and => /,?\s+and\s+/io,
19
+ :space => /[\t\r\n\s]+/o,
20
+ :comma => /,/o,
21
+ :lower => /[[:lower:]][^\t\r\n\s\{\}\d\\,]*/o,
22
+ :upper => /[[:upper:]][^\t\r\n\s\{\}\d\\,]*/o,
23
+ :symbols => /(\d|\\.)+/o,
24
+ :lbrace => /\{/o,
25
+ :rbrace => /\}/o,
26
+ :period => /./o,
27
+ :braces => /[\{\}]/o
28
+ }.freeze
29
+
30
+ class << self
31
+ attr_reader :patterns
32
+ end
33
+
16
34
  def initialize(options = {})
17
35
  self.options.merge!(options)
18
36
  end
@@ -48,36 +66,36 @@ module_eval(<<'...end names.y/module_eval...', 'names.y', 94)
48
66
  def do_scan
49
67
  until @src.eos?
50
68
  case
51
- when @src.scan(/,?\s+and\s+/io)
69
+ when @src.scan(NameParser.patterns[:and])
52
70
  push_word
53
71
  @stack.push([:AND,@src.matched])
54
72
 
55
- when @src.scan(/[\t\r\n\s]+/o)
73
+ when @src.scan(NameParser.patterns[:space])
56
74
  push_word
57
75
 
58
- when @src.scan(/,/o)
76
+ when @src.scan(NameParser.patterns[:comma])
59
77
  push_word
60
78
  @stack.push([:COMMA,@src.matched])
61
79
 
62
- when @src.scan(/[[:lower:]][^\t\r\n\s\{\}\d\\,]*/o)
80
+ when @src.scan(NameParser.patterns[:lower])
63
81
  is_lowercase
64
82
  @word[1] << @src.matched
65
83
 
66
- when @src.scan(/[[:upper:]][^\t\r\n\s\{\}\d\\,]*/o)
84
+ when @src.scan(NameParser.patterns[:upper])
67
85
  is_uppercase
68
86
  @word[1] << @src.matched
69
87
 
70
- when @src.scan(/(\d|\\.)+/o)
88
+ when @src.scan(NameParser.patterns[:symbols])
71
89
  @word[1] << @src.matched
72
90
 
73
- when @src.scan(/\{/o)
91
+ when @src.scan(NameParser.patterns[:lbrace])
74
92
  @word[1] << @src.matched
75
93
  scan_literal
76
94
 
77
- when @src.scan(/\}/o)
95
+ when @src.scan(NameParser.patterns[:rbrace])
78
96
  error_unbalanced
79
97
 
80
- when @src.scan(/./o)
98
+ when @src.scan(NameParser.patterns[:period])
81
99
  @word[1] << @src.matched
82
100
  end
83
101
  end
@@ -105,7 +123,7 @@ module_eval(<<'...end names.y/module_eval...', 'names.y', 94)
105
123
  @brace_level = 1
106
124
 
107
125
  while @brace_level > 0
108
- @word[1] << @src.scan_until(/[\{\}]/o).to_s
126
+ @word[1] << @src.scan_until(NameParser.patterns[:braces]).to_s
109
127
 
110
128
  case @src.matched
111
129
  when '{'
data/lib/bibtex/names.y CHANGED
@@ -92,6 +92,24 @@ require 'strscan'
92
92
 
93
93
  ---- inner
94
94
 
95
+ # Patterns Cache (#37: MacRuby does not cache regular expressions)
96
+ @patterns = {
97
+ :and => /,?\s+and\s+/io,
98
+ :space => /[\t\r\n\s]+/o,
99
+ :comma => /,/o,
100
+ :lower => /[[:lower:]][^\t\r\n\s\{\}\d\\,]*/o,
101
+ :upper => /[[:upper:]][^\t\r\n\s\{\}\d\\,]*/o,
102
+ :symbols => /(\d|\\.)+/o,
103
+ :lbrace => /\{/o,
104
+ :rbrace => /\}/o,
105
+ :period => /./o,
106
+ :braces => /[\{\}]/o
107
+ }.freeze
108
+
109
+ class << self
110
+ attr_reader :patterns
111
+ end
112
+
95
113
  def initialize(options = {})
96
114
  self.options.merge!(options)
97
115
  end
@@ -127,36 +145,36 @@ require 'strscan'
127
145
  def do_scan
128
146
  until @src.eos?
129
147
  case
130
- when @src.scan(/,?\s+and\s+/io)
148
+ when @src.scan(NameParser.patterns[:and])
131
149
  push_word
132
150
  @stack.push([:AND,@src.matched])
133
151
 
134
- when @src.scan(/[\t\r\n\s]+/o)
152
+ when @src.scan(NameParser.patterns[:space])
135
153
  push_word
136
154
 
137
- when @src.scan(/,/o)
155
+ when @src.scan(NameParser.patterns[:comma])
138
156
  push_word
139
157
  @stack.push([:COMMA,@src.matched])
140
158
 
141
- when @src.scan(/[[:lower:]][^\t\r\n\s\{\}\d\\,]*/o)
159
+ when @src.scan(NameParser.patterns[:lower])
142
160
  is_lowercase
143
161
  @word[1] << @src.matched
144
162
 
145
- when @src.scan(/[[:upper:]][^\t\r\n\s\{\}\d\\,]*/o)
163
+ when @src.scan(NameParser.patterns[:upper])
146
164
  is_uppercase
147
165
  @word[1] << @src.matched
148
166
 
149
- when @src.scan(/(\d|\\.)+/o)
167
+ when @src.scan(NameParser.patterns[:symbols])
150
168
  @word[1] << @src.matched
151
169
 
152
- when @src.scan(/\{/o)
170
+ when @src.scan(NameParser.patterns[:lbrace])
153
171
  @word[1] << @src.matched
154
172
  scan_literal
155
173
 
156
- when @src.scan(/\}/o)
174
+ when @src.scan(NameParser.patterns[:rbrace])
157
175
  error_unbalanced
158
176
 
159
- when @src.scan(/./o)
177
+ when @src.scan(NameParser.patterns[:period])
160
178
  @word[1] << @src.matched
161
179
  end
162
180
  end
@@ -184,7 +202,7 @@ require 'strscan'
184
202
  @brace_level = 1
185
203
 
186
204
  while @brace_level > 0
187
- @word[1] << @src.scan_until(/[\{\}]/o).to_s
205
+ @word[1] << @src.scan_until(NameParser.patterns[:braces]).to_s
188
206
 
189
207
  case @src.matched
190
208
  when '{'
data/lib/bibtex/parser.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # DO NOT MODIFY!!!!
3
- # This file is automatically generated by Racc 1.4.6
3
+ # This file is automatically generated by Racc 1.4.8
4
4
  # from Racc grammer file "".
5
5
  #
6
6
 
data/lib/bibtex/value.rb CHANGED
@@ -55,6 +55,16 @@ module BibTeX
55
55
  def_delegators :to_s, :=~, :===, *String.instance_methods(false).reject { |m| m =~ /^\W|^length$|^dup$|!$/ }
56
56
  def_delegators :@tokens, :[], :length
57
57
  def_delegator :@tokens, :each, :each_token
58
+
59
+ # call-seq:
60
+ # create(other) => other.dup
61
+ # create(*args) => Value.new(args)
62
+ #
63
+ # Duplicates a +Value+ object (or an object of any subclass of +Value+),
64
+ # or initializes a new one.
65
+ def self.create(*args)
66
+ args[0].class < Value && args.size == 1 ? args[0].dup : Value.new(args)
67
+ end
58
68
 
59
69
  def initialize(*arguments)
60
70
  @tokens = []
@@ -248,4 +258,4 @@ module BibTeX
248
258
 
249
259
  end
250
260
 
251
- end
261
+ end
@@ -18,6 +18,6 @@
18
18
 
19
19
  module BibTeX
20
20
  module Version
21
- STRING = '2.0.4'.freeze
21
+ STRING = '2.0.5'.freeze
22
22
  end
23
23
  end
data/test/benchmark.rb CHANGED
@@ -1,8 +1,10 @@
1
- require File.expand_path('../../lib/bibtex.rb', __FILE__)
1
+ # ruby -Ilib -rrubygems test/benchmark.rb
2
2
 
3
3
  require 'benchmark'
4
4
  include Benchmark
5
5
 
6
+ require 'bibtex'
7
+
6
8
  # data = File.open(BibTeX::Test.fixtures(:benchmark)).read
7
9
 
8
10
  input = <<-END
@@ -19,8 +21,8 @@ input = <<-END
19
21
  }
20
22
  END
21
23
 
22
- n, k = 1001, 20
23
- # lexer = BibTeX::Lexer.new
24
+ n, k = 31, 10
25
+ lexer = BibTeX::Lexer.new
24
26
  # parser = BibTeX::Parser.new
25
27
 
26
28
  f = []
@@ -35,18 +37,18 @@ Benchmark.benchmark((" "*15) + CAPTION, 7, format, '%14s:' % 'sum(f)', '%14s:' %
35
37
 
36
38
  f << b.report('%14s:' % "f(#{i})") do
37
39
  i.times do
38
- # lexer.data = input
39
- # lexer.analyse
40
- BibTeX::Parser.new.parse(input)
40
+ lexer.data = input
41
+ lexer.analyse
42
+ # BibTeX::Parser.new.parse(input)
41
43
  end
42
44
  end
43
45
 
44
46
  data = input * i
45
47
 
46
48
  g << b.report('%14s:' % "g(#{i})") do
47
- # lexer.data = data
48
- # lexer.analyse
49
- BibTeX::Parser.new.parse(data)
49
+ lexer.data = data
50
+ lexer.analyse
51
+ # BibTeX::Parser.new.parse(data)
50
52
  end
51
53
 
52
54
  end
@@ -54,29 +56,29 @@ Benchmark.benchmark((" "*15) + CAPTION, 7, format, '%14s:' % 'sum(f)', '%14s:' %
54
56
  [f.inject(:+), g.inject(:+)]
55
57
  end
56
58
 
57
- require 'gnuplot'
58
-
59
- f = f.map(&:total)
60
- g = g.map(&:total)
61
-
62
- x = 1.step(n,k).to_a
63
-
64
- Gnuplot.open do |gp|
65
- Gnuplot::Plot.new(gp) do |plot|
66
-
67
- plot.title 'BibTeX-Ruby Benchmark'
68
- plot.ylabel 't'
69
- plot.xlabel 'n'
70
-
71
- plot.data << Gnuplot::DataSet.new([x,f]) do |ds|
72
- ds.with = 'linespoints'
73
- ds.title = 'f'
74
- end
75
-
76
- plot.data << Gnuplot::DataSet.new([x,g]) do |ds|
77
- ds.with = 'linespoints'
78
- ds.title = 'g'
79
- end
80
-
81
- end
82
- end
59
+ # require 'gnuplot'
60
+ #
61
+ # f = f.map(&:total)
62
+ # g = g.map(&:total)
63
+ #
64
+ # x = 1.step(n,k).to_a
65
+ #
66
+ # Gnuplot.open do |gp|
67
+ # Gnuplot::Plot.new(gp) do |plot|
68
+ #
69
+ # plot.title 'BibTeX-Ruby Benchmark'
70
+ # plot.ylabel 't'
71
+ # plot.xlabel 'n'
72
+ #
73
+ # plot.data << Gnuplot::DataSet.new([x,f]) do |ds|
74
+ # ds.with = 'linespoints'
75
+ # ds.title = 'f'
76
+ # end
77
+ #
78
+ # plot.data << Gnuplot::DataSet.new([x,g]) do |ds|
79
+ # ds.with = 'linespoints'
80
+ # ds.title = 'g'
81
+ # end
82
+ #
83
+ # end
84
+ # end
@@ -34,6 +34,10 @@ module BibTeX
34
34
  it 'accepts filters' do
35
35
  Bibliography.parse("@misc{k, title = {\\''u}}", :filter => 'latex')[0].title.must_be :==, 'ü'
36
36
  end
37
+
38
+ it 'accepts filters in an array' do
39
+ Bibliography.parse("@misc{k, title = {\\''u}}", :filter => ['latex'])[0].title.must_be :==, 'ü'
40
+ end
37
41
  end
38
42
 
39
43
  describe 'given a populated biliography' do
@@ -11,6 +11,14 @@ module BibTeX
11
11
  end
12
12
  end
13
13
 
14
+ describe '#add' do
15
+ it 'preserves BibTeX::Names (and other subclasses of BibTeX::Value)' do
16
+ e = Entry.new
17
+ e.add(:author, Names.new(Name.new(:first => 'first_name')))
18
+ assert_equal e[:author].class, Names
19
+ end
20
+ end
21
+
14
22
  describe 'cross-references' do
15
23
  it 'has no cross-reference by default' do
16
24
  assert_equal false, Entry.new.has_cross_reference?
@@ -452,4 +460,4 @@ module BibTeX
452
460
  end
453
461
 
454
462
  end
455
- end
463
+ end
@@ -2,6 +2,20 @@ require 'helper.rb'
2
2
 
3
3
  module BibTeX
4
4
  class ValueTest < MiniTest::Spec
5
+
6
+ describe "::create" do
7
+ it "should return a duplicate when called with a Value subclass" do
8
+ val = Value.new('value')
9
+ names = Names.new(Name.new(:first => 'first_name'))
10
+
11
+ assert_equal val.dup, Value.create(val)
12
+ assert_equal names.dup, Value.create(names)
13
+ end
14
+
15
+ it "should return a new Value object when called with other arguments" do
16
+ assert_equal Value.new('value'), Value.create('value')
17
+ end
18
+ end
5
19
 
6
20
  describe "when empty" do
7
21
  it "should be equal to an empty string" do
@@ -132,4 +146,4 @@ module BibTeX
132
146
  end
133
147
 
134
148
  end
135
- end
149
+ end
data/test/macruby.d ADDED
@@ -0,0 +1,21 @@
1
+ /* time.d */
2
+
3
+ #pragma D option quiet
4
+
5
+ macruby$target:::method-entry
6
+ {
7
+ self->starttime = walltimestamp / 1000;
8
+ }
9
+
10
+ macruby$target:::method-return
11
+ {
12
+ @invoked_time[copyinstr(arg0), copyinstr(arg1)] = sum((walltimestamp / 1000) - self->starttime);
13
+ }
14
+
15
+ END
16
+ {
17
+ printf("\n");
18
+ printf("%-10s %-15s %s\n", "CLASS", "METHOD", "TOTAL TIME µsec");
19
+ printf("--------------------------------------------------------------------------------\n");
20
+ printa("%-10s %-15s %@d\n", @invoked_time);
21
+ }
data/test/macruby.rb ADDED
@@ -0,0 +1,22 @@
1
+
2
+ # sudo dtrace -qs test/macruby.d -c "macruby -Ilib -rrubygems test/macruby.rb"
3
+
4
+ require 'bibtex'
5
+
6
+ input = <<-END
7
+ @book{pickaxe,
8
+ Address = {Raleigh, North Carolina},
9
+ Author = {Thomas, Dave, and Fowler, Chad, and Hunt, Andy},
10
+ Date-Added = {2010-08-05 09:54:07 +0200},
11
+ Date-Modified = {2010-08-05 10:07:01 +0200},
12
+ Keywords = {ruby},
13
+ Publisher = {The Pragmatic Bookshelf},
14
+ Series = {The Facets of Ruby},
15
+ Title = {Programming Ruby 1.9: The Pragmatic Programmer's Guide},
16
+ Year = {2009}
17
+ }
18
+ END
19
+
20
+ lexer = BibTeX::Lexer.new
21
+ lexer.data = input * 100
22
+ lexer.analyse
data/test/test_export.rb CHANGED
@@ -22,7 +22,7 @@ module BibTeX
22
22
 
23
23
  def test_json
24
24
  bib = BibTeX::Bibliography.open(Test.fixtures(:bibdesk), :debug => false)
25
- json = MultiJson.decode(bib.to_json)
25
+ json = MultiJson.load(bib.to_json)
26
26
  refute_nil(json)
27
27
  assert_equal(3, json.length)
28
28
  assert_equal(%w[ dragon pickaxe rails], json.map { |y| y['key'] }.sort)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bibtex-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.4
4
+ version: 2.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-20 00:00:00.000000000 Z
12
+ date: 2012-04-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: latex-decode
16
- requirement: &70168043749560 !ruby/object:Gem::Requirement
16
+ requirement: &70347703840520 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,21 +21,21 @@ dependencies:
21
21
  version: 0.0.6
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70168043749560
24
+ version_requirements: *70347703840520
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: multi_json
27
- requirement: &70168043749040 !ruby/object:Gem::Requirement
27
+ requirement: &70347703829060 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
31
31
  - !ruby/object:Gem::Version
32
- version: '1.0'
32
+ version: '1.3'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70168043749040
35
+ version_requirements: *70347703829060
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &70168043748560 !ruby/object:Gem::Requirement
38
+ requirement: &70347703826940 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0.9'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70168043748560
46
+ version_requirements: *70347703826940
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: racc
49
- requirement: &70168043748080 !ruby/object:Gem::Requirement
49
+ requirement: &70347703825800 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '1.4'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70168043748080
57
+ version_requirements: *70347703825800
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rdoc
60
- requirement: &70168043747580 !ruby/object:Gem::Requirement
60
+ requirement: &70347703823800 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '3.9'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70168043747580
68
+ version_requirements: *70347703823800
69
69
  description: ! "\t\tBibTeX-Ruby is the Rubyist's swiss-army-knife for all things BibTeX.
70
70
  It\n includes a parser for all common BibTeX objects (@string, @preamble,\n @comment
71
71
  and regular entries) and a sophisticated name parser that\n tokenizes correctly
@@ -99,6 +99,7 @@ files:
99
99
  - features/issues/crossref.feature
100
100
  - features/issues/latex_filter.feature
101
101
  - features/issues/multiline_strings.feature
102
+ - features/issues/name_parsing.feature
102
103
  - features/issues/number_keys.feature
103
104
  - features/issues/parse_months.feature
104
105
  - features/issues/slash_keys.feature
@@ -154,6 +155,8 @@ files:
154
155
  - test/fixtures/preamble.bib
155
156
  - test/fixtures/roundtrip.bib
156
157
  - test/helper.rb
158
+ - test/macruby.d
159
+ - test/macruby.rb
157
160
  - test/profile.rb
158
161
  - test/test_bibtex.rb
159
162
  - test/test_export.rb
@@ -177,12 +180,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
177
180
  - - ! '>='
178
181
  - !ruby/object:Gem::Version
179
182
  version: '0'
183
+ segments:
184
+ - 0
185
+ hash: -230691617197525967
180
186
  required_rubygems_version: !ruby/object:Gem::Requirement
181
187
  none: false
182
188
  requirements:
183
189
  - - ! '>='
184
190
  - !ruby/object:Gem::Version
185
191
  version: '0'
192
+ segments:
193
+ - 0
194
+ hash: -230691617197525967
186
195
  requirements: []
187
196
  rubyforge_project:
188
197
  rubygems_version: 1.8.10