bibtex-ruby 4.0.8 → 4.0.9

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of bibtex-ruby might be problematic. Click here for more details.

@@ -1,17 +1,17 @@
1
1
  #--
2
2
  # BibTeX-Ruby
3
- # Copyright (C) 2010-2014 Sylvester Keil <sylvester.keil.or.at>
4
- #
3
+ # Copyright (C) 2010-2015 Sylvester Keil <sylvester.keil.or.at>
4
+ #
5
5
  # This program is free software: you can redistribute it and/or modify
6
6
  # it under the terms of the GNU General Public License as published by
7
7
  # the Free Software Foundation, either version 3 of the License, or
8
8
  # (at your option) any later version.
9
- #
9
+ #
10
10
  # This program is distributed in the hope that it will be useful,
11
11
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
12
  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
13
  # GNU General Public License for more details.
14
- #
14
+ #
15
15
  # You should have received a copy of the GNU General Public License
16
16
  # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
17
  #++
@@ -23,16 +23,16 @@ module BibTeX
23
23
  # A BibTeX Names value is an ordered list of name values.
24
24
  class Names < Value
25
25
  include Enumerable
26
-
26
+
27
27
  def_delegators :@tokens, :each, :sort
28
-
28
+
29
29
  def self.parse(string)
30
30
  new(NameParser.new.parse(string))
31
31
  rescue => e
32
32
  BibTeX.log.info(e.message)
33
33
  nil
34
34
  end
35
-
35
+
36
36
  def initialize(*arguments)
37
37
  @tokens = []
38
38
  arguments.flatten.compact.each do |argument|
@@ -43,15 +43,15 @@ module BibTeX
43
43
  def replace(*arguments)
44
44
  self
45
45
  end
46
-
46
+
47
47
  def join
48
48
  self
49
49
  end
50
-
50
+
51
51
  def value(options = {})
52
52
  @tokens.map { |n| n.to_s(options) }.join(' and ')
53
53
  end
54
-
54
+
55
55
  def to_s(options = {})
56
56
  return value unless options.has_key?(:quotes)
57
57
  q = [options[:quotes]].flatten
@@ -61,30 +61,30 @@ module BibTeX
61
61
  def name?
62
62
  true
63
63
  end
64
-
64
+
65
65
  def numeric?
66
66
  false
67
67
  end
68
-
68
+
69
69
  def atomic?
70
70
  true
71
71
  end
72
-
72
+
73
73
  alias names? name?
74
74
  alias symbol? numeric?
75
-
75
+
76
76
  def to_name
77
77
  self
78
78
  end
79
-
79
+
80
80
  def to_citeproc(options = {})
81
81
  map { |n| n.to_citeproc(options) }
82
82
  end
83
-
83
+
84
84
  def strip_braces
85
85
  gsub!(/\{|\}/,'')
86
86
  end
87
-
87
+
88
88
  def add(name)
89
89
  case
90
90
  when name.is_a?(Name)
@@ -96,10 +96,10 @@ module BibTeX
96
96
  end
97
97
  self
98
98
  end
99
-
99
+
100
100
  alias << add
101
101
  alias push add
102
-
102
+
103
103
  [:convert!, :rename_if, :rename_unless, :extend_initials].each do |method_id|
104
104
  define_method(method_id) do |*arguments|
105
105
  tokens.each { |t| t.send(method_id, *arguments) }
@@ -110,7 +110,7 @@ module BibTeX
110
110
  def <=>(other)
111
111
  other.respond_to?(:to_a) ? to_a <=> other.to_a : super
112
112
  end
113
-
113
+
114
114
  end
115
115
 
116
116
  # A Name comprises individual name parts (first, last, prefix and suffix),
@@ -118,46 +118,46 @@ module BibTeX
118
118
  class Name < Struct.new(:first, :last, :prefix, :suffix)
119
119
  extend Forwardable
120
120
  include Comparable
121
-
121
+
122
122
  BibTeXML = {
123
123
  :first => :first,
124
124
  :last => :last,
125
125
  :prefix => :prelast,
126
126
  :suffix => :lineage
127
127
  }.freeze
128
-
128
+
129
129
  def_delegators :to_s, :=~, :===,
130
130
  *String.instance_methods(false).reject { |m| m =~ /^\W|to_s|replace|each|first|last|!$/ }
131
-
132
- class << self
131
+
132
+ class << self
133
133
  def parse(string)
134
134
  [NameParser.new.parse(string)].flatten[0]
135
135
  end
136
-
136
+
137
137
  # Returns true if thing looks like a name.
138
138
  # Actually converts thing to a string and tries to parse it.
139
139
  def looks_like?(thing)
140
140
  thing.respond_to?(:to_s) && [Name.new.parse(string)].flatten.compact.empty?
141
141
  end
142
142
  end
143
-
143
+
144
144
  def initialize(attributes = {})
145
145
  set(attributes)
146
146
  end
147
-
147
+
148
148
  def initalize_copy(other)
149
149
  each_pair { |k,v| self[k] = v.dup }
150
150
  end
151
-
151
+
152
152
  # Set the name tokens to the values defined in the passed-in hash.
153
153
  def set(attributes = {})
154
154
  attributes.each_pair do |key, value|
155
155
  send("#{key}=", value) if respond_to?(key)
156
156
  end
157
-
157
+
158
158
  self
159
159
  end
160
-
160
+
161
161
  def blank?
162
162
  to_a.compact.empty?
163
163
  end
@@ -174,7 +174,7 @@ module BibTeX
174
174
  token.gsub!(/\b([[:upper:]]\.)([[:upper:]][[:lower:]]+)/, '\1 \2')
175
175
  token
176
176
  end
177
-
177
+
178
178
  # Returns true if the first name consists solely of initials.
179
179
  def initials?
180
180
  !(first.nil? || first.empty? || first.to_s =~ /[[:alpha:]]{2,}[^\.]/)
@@ -192,7 +192,7 @@ module BibTeX
192
192
  end
193
193
  end
194
194
  end
195
-
195
+
196
196
  # Renames the tokens according to the passed-in attributes if all of the
197
197
  # conditions match or if the given block returns true.
198
198
  def rename_if(attributes, conditions = {})
@@ -203,10 +203,10 @@ module BibTeX
203
203
  respond_to?(key) && send(key) == value
204
204
  end
205
205
  end
206
-
206
+
207
207
  self
208
208
  end
209
-
209
+
210
210
  def rename_unless(attributes, conditions = {})
211
211
  if block_given?
212
212
  set(attributes) unless yield self
@@ -215,10 +215,10 @@ module BibTeX
215
215
  respond_to?(key) && send(key) == value
216
216
  end
217
217
  end
218
-
218
+
219
219
  self
220
220
  end
221
-
221
+
222
222
  # call-seq:
223
223
  # name.display_order #=> 'Edgar Allen Poe'
224
224
  # name.display_order :initials => true #=> 'E.A. Poe'
@@ -227,9 +227,9 @@ module BibTeX
227
227
  def display_order(options = {})
228
228
  [options[:initials] ? initials : first, prefix, last, suffix].compact.join(' ')
229
229
  end
230
-
230
+
231
231
  alias display display_order
232
-
232
+
233
233
  # call-seq:
234
234
  # name.sort_order #=> 'Poe, Edgar Allen'
235
235
  # name.sort_order :initials => true #=> 'Poe, E.A.'
@@ -238,19 +238,19 @@ module BibTeX
238
238
  def sort_order(options = {})
239
239
  [[prefix, last].compact.join(' '), suffix, options[:initials] ? initials : first].compact.join(', ')
240
240
  end
241
-
241
+
242
242
  alias to_s sort_order
243
-
243
+
244
244
  def <=>(other)
245
245
  other.is_a?(Name) ? sort_order <=> other.sort_order : super
246
246
  end
247
-
247
+
248
248
  def to_hash
249
249
  Hash[each_pair.to_a]
250
250
  end
251
251
 
252
252
  def to_xml
253
- require 'rexml/document'
253
+ require 'rexml/document'
254
254
  xml = REXML::Element.new('bibtex:person')
255
255
 
256
256
  each_pair do |part, text|
@@ -260,10 +260,10 @@ module BibTeX
260
260
  xml.add_element(element)
261
261
  end
262
262
  end
263
-
263
+
264
264
  xml
265
265
  end
266
-
266
+
267
267
  [:strip!, :upcase!, :downcase!, :sub!, :gsub!, :chop!, :chomp!, :rstrip!].each do |method_id|
268
268
  define_method(method_id) do |*arguments, &block|
269
269
  each do |part|
@@ -272,11 +272,11 @@ module BibTeX
272
272
  self
273
273
  end
274
274
  end
275
-
275
+
276
276
  def convert(*filters)
277
277
  dup.convert!(*filters)
278
278
  end
279
-
279
+
280
280
  def convert!(*filters)
281
281
  filters.flatten.each do |filter|
282
282
 
@@ -287,10 +287,10 @@ module BibTeX
287
287
  self[k] = f.apply(v) unless v.nil?
288
288
  end
289
289
  end
290
-
290
+
291
291
  self
292
292
  end
293
-
293
+
294
294
  def to_citeproc(options = {})
295
295
  hash = {}
296
296
  hash['family'] = family unless family.nil?
@@ -299,15 +299,15 @@ module BibTeX
299
299
  hash[options[:particle] || 'non-dropping-particle'] = prefix unless prefix.nil?
300
300
  hash
301
301
  end
302
-
302
+
303
303
  alias family last
304
- alias family= last=
304
+ alias family= last=
305
305
  alias given first
306
306
  alias given= first=
307
307
  alias jr suffix
308
308
  alias jr= suffix=
309
309
  alias von prefix
310
- alias von= prefix=
311
-
310
+ alias von= prefix=
311
+
312
312
  end
313
313
  end
@@ -14,48 +14,48 @@ module BibTeX
14
14
  module_eval(<<'...end bibtex.y/module_eval...', 'bibtex.y', 89)
15
15
 
16
16
  attr_reader :lexer, :options
17
-
17
+
18
18
  @defaults = {
19
19
  :include => [:errors],
20
20
  :allow_missing_keys => false,
21
21
  :debug => false
22
22
  }.freeze
23
-
23
+
24
24
  class << self
25
25
  attr_reader :defaults
26
26
  end
27
-
27
+
28
28
  def initialize(options = {})
29
29
  @options = Parser.defaults.merge(options)
30
30
  @lexer = Lexer.new(@options)
31
31
  end
32
32
 
33
33
  def parse(input)
34
- @yydebug = debug?
34
+ @yydebug = debug?
35
35
 
36
- lexer.analyse(input)
36
+ lexer.analyse(input)
37
37
  do_parse
38
38
  #yyparse(@lexer,:each)
39
39
  end
40
-
40
+
41
41
  def next_token
42
42
  lexer.next_token
43
43
  end
44
-
44
+
45
45
  def debug?
46
46
  options[:debug] || ENV['DEBUG']
47
47
  end
48
-
48
+
49
49
  def allow_missing_keys?
50
50
  options[:allow_missing_keys]
51
51
  end
52
-
52
+
53
53
  def missing_key
54
54
  unless allow_missing_keys?
55
55
  raise ParseError, "Failed to parse BibTeX entry: cite-key missing"
56
56
  end
57
57
  end
58
-
58
+
59
59
  def on_error(tid, val, vstack)
60
60
  message =
61
61
  "Failed to parse BibTeX on value #{val.inspect} (#{token_to_str(tid) || '?'}) #{ vstack.inspect}"
@@ -242,189 +242,189 @@ Racc_debug_parser = false
242
242
 
243
243
  module_eval(<<'.,.,', 'bibtex.y', 32)
244
244
  def _reduce_1(val, _values, result)
245
- result = BibTeX::Bibliography.new(@options)
245
+ result = BibTeX::Bibliography.new(@options)
246
246
  result
247
247
  end
248
248
  .,.,
249
249
 
250
250
  module_eval(<<'.,.,', 'bibtex.y', 33)
251
251
  def _reduce_2(val, _values, result)
252
- result = val[0]
252
+ result = val[0]
253
253
  result
254
254
  end
255
255
  .,.,
256
256
 
257
257
  module_eval(<<'.,.,', 'bibtex.y', 35)
258
258
  def _reduce_3(val, _values, result)
259
- result = BibTeX::Bibliography.new(@options) << val[0]
259
+ result = BibTeX::Bibliography.new(@options) << val[0]
260
260
  result
261
261
  end
262
262
  .,.,
263
263
 
264
264
  module_eval(<<'.,.,', 'bibtex.y', 36)
265
265
  def _reduce_4(val, _values, result)
266
- result << val[1]
266
+ result << val[1]
267
267
  result
268
268
  end
269
269
  .,.,
270
270
 
271
271
  module_eval(<<'.,.,', 'bibtex.y', 38)
272
272
  def _reduce_5(val, _values, result)
273
- result = val[1]
273
+ result = val[1]
274
274
  result
275
275
  end
276
276
  .,.,
277
277
 
278
278
  module_eval(<<'.,.,', 'bibtex.y', 39)
279
279
  def _reduce_6(val, _values, result)
280
- result = BibTeX::MetaContent.new(val[0])
280
+ result = BibTeX::MetaContent.new(val[0])
281
281
  result
282
282
  end
283
283
  .,.,
284
284
 
285
285
  module_eval(<<'.,.,', 'bibtex.y', 40)
286
286
  def _reduce_7(val, _values, result)
287
- result = BibTeX::Error.new(val[0])
287
+ result = BibTeX::Error.new(val[0])
288
288
  result
289
289
  end
290
290
  .,.,
291
291
 
292
292
  module_eval(<<'.,.,', 'bibtex.y', 42)
293
293
  def _reduce_8(val, _values, result)
294
- result = val[0]
294
+ result = val[0]
295
295
  result
296
296
  end
297
297
  .,.,
298
298
 
299
299
  module_eval(<<'.,.,', 'bibtex.y', 43)
300
300
  def _reduce_9(val, _values, result)
301
- result = val[0]
301
+ result = val[0]
302
302
  result
303
303
  end
304
304
  .,.,
305
305
 
306
306
  module_eval(<<'.,.,', 'bibtex.y', 44)
307
307
  def _reduce_10(val, _values, result)
308
- result = val[0]
308
+ result = val[0]
309
309
  result
310
310
  end
311
311
  .,.,
312
312
 
313
313
  module_eval(<<'.,.,', 'bibtex.y', 45)
314
314
  def _reduce_11(val, _values, result)
315
- result = val[0]
315
+ result = val[0]
316
316
  result
317
317
  end
318
318
  .,.,
319
319
 
320
320
  module_eval(<<'.,.,', 'bibtex.y', 47)
321
321
  def _reduce_12(val, _values, result)
322
- result = BibTeX::Comment.new(val[2])
322
+ result = BibTeX::Comment.new(val[2])
323
323
  result
324
324
  end
325
325
  .,.,
326
326
 
327
327
  module_eval(<<'.,.,', 'bibtex.y', 49)
328
328
  def _reduce_13(val, _values, result)
329
- result = ''
329
+ result = ''
330
330
  result
331
331
  end
332
332
  .,.,
333
333
 
334
334
  module_eval(<<'.,.,', 'bibtex.y', 50)
335
335
  def _reduce_14(val, _values, result)
336
- result = val[0]
336
+ result = val[0]
337
337
  result
338
338
  end
339
339
  .,.,
340
340
 
341
341
  module_eval(<<'.,.,', 'bibtex.y', 52)
342
342
  def _reduce_15(val, _values, result)
343
- result = BibTeX::Preamble.new(val[2])
343
+ result = BibTeX::Preamble.new(val[2])
344
344
  result
345
345
  end
346
346
  .,.,
347
347
 
348
348
  module_eval(<<'.,.,', 'bibtex.y', 54)
349
349
  def _reduce_16(val, _values, result)
350
- result = BibTeX::String.new(val[2][0],val[2][1]);
350
+ result = BibTeX::String.new(val[2][0],val[2][1]);
351
351
  result
352
352
  end
353
353
  .,.,
354
354
 
355
355
  module_eval(<<'.,.,', 'bibtex.y', 56)
356
356
  def _reduce_17(val, _values, result)
357
- result = [val[0].downcase.to_sym, val[2]]
357
+ result = [val[0].downcase.to_sym, val[2]]
358
358
  result
359
359
  end
360
360
  .,.,
361
361
 
362
362
  module_eval(<<'.,.,', 'bibtex.y', 58)
363
363
  def _reduce_18(val, _values, result)
364
- result = [val[0]]
364
+ result = [val[0]]
365
365
  result
366
366
  end
367
367
  .,.,
368
368
 
369
369
  module_eval(<<'.,.,', 'bibtex.y', 59)
370
370
  def _reduce_19(val, _values, result)
371
- result << val[2]
371
+ result << val[2]
372
372
  result
373
373
  end
374
374
  .,.,
375
375
 
376
376
  module_eval(<<'.,.,', 'bibtex.y', 61)
377
377
  def _reduce_20(val, _values, result)
378
- result = val[0].downcase.to_sym
378
+ result = val[0].downcase.to_sym
379
379
  result
380
380
  end
381
381
  .,.,
382
382
 
383
383
  module_eval(<<'.,.,', 'bibtex.y', 62)
384
384
  def _reduce_21(val, _values, result)
385
- result = val[1]
385
+ result = val[1]
386
386
  result
387
387
  end
388
388
  .,.,
389
389
 
390
390
  module_eval(<<'.,.,', 'bibtex.y', 63)
391
391
  def _reduce_22(val, _values, result)
392
- result = val[0]
392
+ result = val[0]
393
393
  result
394
394
  end
395
395
  .,.,
396
396
 
397
397
  module_eval(<<'.,.,', 'bibtex.y', 65)
398
398
  def _reduce_23(val, _values, result)
399
- result = val[0] << val[1]
399
+ result = val[0] << val[1]
400
400
  result
401
401
  end
402
402
  .,.,
403
403
 
404
404
  module_eval(<<'.,.,', 'bibtex.y', 66)
405
405
  def _reduce_24(val, _values, result)
406
- result = val[0] << val[1]
406
+ result = val[0] << val[1]
407
407
  result
408
408
  end
409
409
  .,.,
410
410
 
411
411
  module_eval(<<'.,.,', 'bibtex.y', 67)
412
412
  def _reduce_25(val, _values, result)
413
- result = val[0]
413
+ result = val[0]
414
414
  result
415
415
  end
416
416
  .,.,
417
417
 
418
418
  module_eval(<<'.,.,', 'bibtex.y', 69)
419
419
  def _reduce_26(val, _values, result)
420
- result = BibTeX::Entry.new(:bibtex_type => val[0].downcase.to_sym, :bibtex_key => val[2])
420
+ result = BibTeX::Entry.new(:bibtex_type => val[0].downcase.to_sym, :bibtex_key => val[2])
421
421
  result
422
422
  end
423
423
  .,.,
424
424
 
425
425
  module_eval(<<'.,.,', 'bibtex.y', 71)
426
426
  def _reduce_27(val, _values, result)
427
- missing_key
427
+ missing_key
428
428
  result
429
429
  end
430
430
  .,.,
@@ -433,35 +433,35 @@ module_eval(<<'.,.,', 'bibtex.y', 71)
433
433
 
434
434
  module_eval(<<'.,.,', 'bibtex.y', 74)
435
435
  def _reduce_29(val, _values, result)
436
- result = val[0]
436
+ result = val[0]
437
437
  result
438
438
  end
439
439
  .,.,
440
440
 
441
441
  module_eval(<<'.,.,', 'bibtex.y', 75)
442
442
  def _reduce_30(val, _values, result)
443
- result.merge!(val[2])
443
+ result.merge!(val[2])
444
444
  result
445
445
  end
446
446
  .,.,
447
447
 
448
448
  module_eval(<<'.,.,', 'bibtex.y', 77)
449
449
  def _reduce_31(val, _values, result)
450
- result = { val[0].downcase.to_sym => val[2] }
450
+ result = { val[0].downcase.to_sym => val[2] }
451
451
  result
452
452
  end
453
453
  .,.,
454
454
 
455
455
  module_eval(<<'.,.,', 'bibtex.y', 79)
456
456
  def _reduce_32(val, _values, result)
457
- result = val[0]
457
+ result = val[0]
458
458
  result
459
459
  end
460
460
  .,.,
461
461
 
462
462
  module_eval(<<'.,.,', 'bibtex.y', 80)
463
463
  def _reduce_33(val, _values, result)
464
- result = val[0]
464
+ result = val[0]
465
465
  result
466
466
  end
467
467
  .,.,