bibtex-ruby 2.0.10 → 2.0.11

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.

data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bibtex-ruby (2.0.10)
4
+ bibtex-ruby (2.0.11)
5
5
  latex-decode (>= 0.0.6)
6
6
  multi_json (~> 1.3)
7
7
 
@@ -40,7 +40,7 @@ GEM
40
40
  linecache (0.46)
41
41
  rbx-require-relative (> 0.0.4)
42
42
  minitest (2.11.3)
43
- multi_json (1.3.4)
43
+ multi_json (1.3.5)
44
44
  mynyml-redgreen (0.7.1)
45
45
  term-ansicolor (>= 1.0.4)
46
46
  racc (1.4.8)
data/History.txt CHANGED
@@ -1,3 +1,8 @@
1
+ 2.0.11 / 2012-05-23
2
+ ===================
3
+
4
+ * Added :allow_missing_keys option (thanks to @jrochkind)
5
+
1
6
  2.0.9 / 2012-05-15
2
7
  ==================
3
8
 
@@ -317,7 +317,7 @@ module BibTeX
317
317
 
318
318
  # group names together
319
319
  names.each do |name|
320
- group = groups[name.sort_order(:initials => true).gsub(/\s+/, '')]
320
+ group = groups[name.sort_order(:initials => true).gsub(/\s+/, '').downcase]
321
321
  group[:names] << name
322
322
 
323
323
  if group[:prototype].nil? || group[:prototype].first.to_s.length < name.first.to_s.length
data/lib/bibtex/bibtex.y CHANGED
@@ -23,7 +23,7 @@
23
23
 
24
24
  class BibTeX::Parser
25
25
 
26
- token AT COMMA COMMENT CONTENT ERROR EQ LBRACE META_CONTENT
26
+ token AT COMMA COMMENT CONTENT ERROR EQ LBRACE META_CONTENT KEY
27
27
  NAME NUMBER PREAMBLE RBRACE SHARP STRING STRING_LITERAL
28
28
 
29
29
  expect 0
@@ -67,12 +67,11 @@ rule
67
67
  | entry_head assignments COMMA RBRACE { result = val[0] << val[1] }
68
68
  | entry_head RBRACE { result = val[0] }
69
69
 
70
- entry_head : NAME LBRACE key COMMA { result = BibTeX::Entry.new(:type => val[0].downcase.to_sym, :key => val[2]) }
71
-
72
- key : NAME { result = val[0] }
73
- | NUMBER { result = val[0] }
74
- | NUMBER NAME { result = val[0,2].join }
70
+ entry_head : NAME LBRACE opt_key { result = BibTeX::Entry.new(:type => val[0].downcase.to_sym, :key => val[2]) }
75
71
 
72
+ opt_key : { missing_key }
73
+ | KEY
74
+
76
75
  assignments : assignment { result = val[0] }
77
76
  | assignments COMMA assignment { result.merge!(val[2]) }
78
77
 
@@ -90,29 +89,47 @@ require 'bibtex/lexer'
90
89
 
91
90
  attr_reader :lexer, :options
92
91
 
93
- DEFAULTS = { :include => [:errors], :debug => ENV['DEBUG'] == true }.freeze
92
+ @defaults = {
93
+ :include => [:errors],
94
+ :allow_missing_keys => false,
95
+ :debug => false
96
+ }.freeze
97
+
98
+ class << self
99
+ attr_reader :defaults
100
+ end
94
101
 
95
102
  def initialize(options = {})
96
- @options = DEFAULTS.merge(options)
103
+ @options = Parser.defaults.merge(options)
97
104
  @lexer = Lexer.new(@options)
98
105
  end
99
106
 
100
107
  def parse(input)
101
108
  @yydebug = debug?
102
- @lexer.analyse(input)
103
-
109
+
110
+ lexer.analyse(input)
104
111
  do_parse
105
112
  #yyparse(@lexer,:each)
106
113
  end
107
114
 
108
115
  def next_token
109
- @lexer.next_token
116
+ lexer.next_token
110
117
  end
111
118
 
112
119
  def debug?
113
- @options[:debug] == true
120
+ options[:debug] || ENV['DEBUG']
114
121
  end
115
-
122
+
123
+ def allow_missing_keys?
124
+ options[:allow_missing_keys]
125
+ end
126
+
127
+ def missing_key
128
+ unless allow_missing_keys?
129
+ raise ParseError, "Failed to parse BibTeX entry: cite-key missing"
130
+ end
131
+ end
132
+
116
133
  def on_error(tid, val, vstack)
117
134
  message =
118
135
  "Failed to parse BibTeX on value #{val.inspect} (#{token_to_str(tid) || '?'}) #{ vstack.inspect}"
data/lib/bibtex/lexer.rb CHANGED
@@ -34,30 +34,33 @@ module BibTeX
34
34
  @defaults = {
35
35
  :include => [:errors],
36
36
  :strict => true,
37
+ :allow_missing_keys => false,
37
38
  :strip => true
38
39
  }.freeze
39
40
 
40
41
  # Patterns Cache (#37: MacRuby does not cache regular expressions)
41
42
  @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
43
+ :space => /[\s]+/o,
44
+ :lbrace => /\s*\{/o,
45
+ :rbrace => /\s*\}\s*/o,
46
+ :braces => /\{|\}/o,
47
+ :eq => /\s*=\s*/o,
48
+ :comma => /\s*,\s*/o,
49
+ :number => /\d+/o,
50
+ :name => /[[:alpha:]\d\/:_!$\?\.%&\*-]+/io,
51
+ :quote => /\s*"/o,
52
+ :unquote => /[\{\}"]/o,
53
+ :sharp => /\s*#\s*/o,
54
+ :object => /@/o,
55
+ :period => /./o,
56
+ :strict_next => /@[\t ]*/o,
57
+ :next => /(^|\n)[\t ]*@[\t ]*/o,
58
+ :entry => /[a-z\d:_!\.$%&*-]+/io,
59
+ :string => /string/io,
60
+ :comment => /comment/io,
61
+ :preamble => /preamble/io,
62
+ :key => /[[:alpha:]\d \/:_!$\?\.%&\*-]+,/io,
63
+ :optional_key => /[[:alpha:]\d \/:_!$\?\.%&\*-]+*,/io
61
64
  }.freeze
62
65
 
63
66
  MODE = Hash.new(:meta).merge({
@@ -127,7 +130,13 @@ module BibTeX
127
130
  end
128
131
 
129
132
  # Returns true if the lexer is currently in strict mode.
130
- def strict?; !!(@options[:strict]); end
133
+ def strict?
134
+ !!@options[:strict]
135
+ end
136
+
137
+ def allow_missing_keys?
138
+ !!@options[:allow_missing_keys]
139
+ end
131
140
 
132
141
  def strip_line_breaks?
133
142
  !!options[:strip] && !active?(:comment)
@@ -174,7 +183,6 @@ module BibTeX
174
183
 
175
184
  def parse_bibtex
176
185
  case
177
- when @scanner.scan(Lexer.patterns[:space])
178
186
  when @scanner.scan(Lexer.patterns[:lbrace])
179
187
  @brace_level += 1
180
188
  push([:LBRACE,'{'])
@@ -198,6 +206,8 @@ module BibTeX
198
206
  push([:SHARP,'#'])
199
207
  when @scanner.scan(Lexer.patterns[:object])
200
208
  enter_object
209
+ when @scanner.scan(Lexer.patterns[:space])
210
+ # skip
201
211
  when @scanner.scan(Lexer.patterns[:period])
202
212
  error_unexpected_token
203
213
  end
@@ -290,9 +300,21 @@ module BibTeX
290
300
  when @scanner.scan(Lexer.patterns[:entry])
291
301
  @mode = @active_object = :entry
292
302
  push [:NAME, @scanner.matched]
303
+
304
+ # TODO: DRY - try to parse key
305
+ if @scanner.scan(Lexer.patterns[:lbrace])
306
+ @brace_level += 1
307
+ push([:LBRACE,'{'])
308
+ @mode = :content if @brace_level > 1 || @brace_level == 1 && active?(:comment)
309
+
310
+ if @scanner.scan(Lexer.patterns[allow_missing_keys? ? :optional_key : :key])
311
+ push [:KEY, @scanner.matched.chop.strip]
312
+ end
313
+ end
314
+
293
315
  else
294
316
  error_unexpected_object
295
- end
317
+ end
296
318
  end
297
319
 
298
320
  # Called when parser leaves a BibTeX object.
data/lib/bibtex/parser.rb CHANGED
@@ -11,33 +11,51 @@ require 'bibtex/lexer'
11
11
  module BibTeX
12
12
  class Parser < Racc::Parser
13
13
 
14
- module_eval(<<'...end bibtex.y/module_eval...', 'bibtex.y', 90)
14
+ module_eval(<<'...end bibtex.y/module_eval...', 'bibtex.y', 89)
15
15
 
16
16
  attr_reader :lexer, :options
17
17
 
18
- DEFAULTS = { :include => [:errors], :debug => ENV['DEBUG'] == true }.freeze
18
+ @defaults = {
19
+ :include => [:errors],
20
+ :allow_missing_keys => false,
21
+ :debug => false
22
+ }.freeze
23
+
24
+ class << self
25
+ attr_reader :defaults
26
+ end
19
27
 
20
28
  def initialize(options = {})
21
- @options = DEFAULTS.merge(options)
29
+ @options = Parser.defaults.merge(options)
22
30
  @lexer = Lexer.new(@options)
23
31
  end
24
32
 
25
33
  def parse(input)
26
34
  @yydebug = debug?
27
- @lexer.analyse(input)
28
-
35
+
36
+ lexer.analyse(input)
29
37
  do_parse
30
38
  #yyparse(@lexer,:each)
31
39
  end
32
40
 
33
41
  def next_token
34
- @lexer.next_token
42
+ lexer.next_token
35
43
  end
36
44
 
37
45
  def debug?
38
- @options[:debug] == true
46
+ options[:debug] || ENV['DEBUG']
47
+ end
48
+
49
+ def allow_missing_keys?
50
+ options[:allow_missing_keys]
51
+ end
52
+
53
+ def missing_key
54
+ unless allow_missing_keys?
55
+ raise ParseError, "Failed to parse BibTeX entry: cite-key missing"
56
+ end
39
57
  end
40
-
58
+
41
59
  def on_error(tid, val, vstack)
42
60
  message =
43
61
  "Failed to parse BibTeX on value #{val.inspect} (#{token_to_str(tid) || '?'}) #{ vstack.inspect}"
@@ -51,50 +69,48 @@ module_eval(<<'...end bibtex.y/module_eval...', 'bibtex.y', 90)
51
69
  ##### State transition tables begin ###
52
70
 
53
71
  racc_action_table = [
54
- 14, 33, 38, 32, 36, 33, 18, 32, 15, 34,
55
- 29, 16, 37, 34, 33, 33, 32, 32, 53, 39,
56
- 4, 4, 34, 34, 6, 6, 26, 5, 5, 24,
57
- 26, 44, 45, 49, 41, 42, 27, 43, 22, 29,
58
- 47, 48, 21, 20, 54, 55, 19, 57, 7, 45,
59
- 45 ]
72
+ 14, 33, 38, 26, 32, 33, 24, 18, 32, 15,
73
+ 34, 39, 16, 37, 34, 33, 33, 36, 32, 32,
74
+ 52, 27, 4, 4, 34, 34, 6, 6, 26, 5,
75
+ 5, 48, 43, 44, 29, 41, 42, 22, 29, 46,
76
+ 47, 21, 20, 19, 54, 7, 44, 44 ]
60
77
 
61
78
  racc_action_check = [
62
- 4, 21, 23, 21, 22, 48, 4, 48, 4, 21,
63
- 20, 4, 23, 48, 45, 39, 45, 39, 39, 26,
64
- 0, 2, 45, 39, 0, 2, 17, 0, 2, 17,
65
- 38, 30, 30, 38, 27, 27, 18, 28, 16, 33,
66
- 35, 36, 15, 14, 40, 42, 7, 46, 1, 51,
67
- 58 ]
79
+ 4, 21, 23, 17, 21, 47, 17, 4, 47, 4,
80
+ 21, 26, 4, 23, 47, 44, 39, 22, 44, 39,
81
+ 39, 18, 0, 2, 44, 39, 0, 2, 38, 0,
82
+ 2, 38, 30, 30, 20, 27, 28, 16, 33, 35,
83
+ 36, 15, 14, 7, 45, 1, 50, 55 ]
68
84
 
69
85
  racc_action_pointer = [
70
- 18, 48, 19, nil, -4, nil, nil, 46, nil, nil,
71
- nil, nil, nil, nil, 35, 34, 30, 16, 28, nil,
72
- 5, -7, -6, -1, nil, nil, 12, 24, 24, nil,
73
- 18, nil, nil, 34, nil, 27, 34, nil, 20, 7,
74
- 41, nil, 35, nil, nil, 6, 34, nil, -3, nil,
75
- nil, 35, nil, nil, nil, nil, nil, nil, 36 ]
86
+ 20, 45, 21, nil, -4, nil, nil, 43, nil, nil,
87
+ nil, nil, nil, nil, 34, 33, 29, -8, 13, nil,
88
+ 29, -7, 6, -1, nil, nil, 4, 25, 22, nil,
89
+ 18, nil, nil, 33, nil, 25, 33, nil, 17, 8,
90
+ nil, nil, nil, nil, 7, 30, nil, -3, nil, nil,
91
+ 31, nil, nil, nil, nil, 32 ]
76
92
 
77
93
  racc_action_default = [
78
- -1, -35, -2, -3, -35, -6, -7, -35, -4, -5,
79
- -8, -9, -10, -11, -35, -35, -35, -35, -35, 59,
80
- -13, -35, -35, -35, -25, -30, -35, -35, -35, -14,
81
- -35, -18, -20, -13, -22, -35, -35, -23, -35, -35,
82
- -35, -27, -28, -12, -15, -35, -35, -16, -35, -24,
83
- -31, -33, -32, -34, -26, -29, -19, -21, -17 ]
94
+ -1, -34, -2, -3, -34, -6, -7, -34, -4, -5,
95
+ -8, -9, -10, -11, -34, -34, -34, -34, -34, 56,
96
+ -13, -34, -34, -34, -25, -29, -34, -27, -34, -14,
97
+ -34, -18, -20, -13, -22, -34, -34, -23, -34, -34,
98
+ -26, -28, -12, -15, -34, -34, -16, -34, -24, -30,
99
+ -32, -31, -33, -19, -21, -17 ]
84
100
 
85
101
  racc_goto_table = [
86
102
  30, 25, 28, 3, 1, 8, 11, 12, 13, 10,
87
- 9, 35, 56, 17, 23, 46, 40, 2, 51, 52,
88
- nil, nil, 50, nil, nil, nil, nil, 58 ]
103
+ 9, 35, 53, 17, 23, 45, 40, 2, 50, 51,
104
+ nil, nil, 49, nil, nil, nil, 55 ]
89
105
 
90
106
  racc_goto_check = [
91
107
  10, 16, 9, 3, 1, 3, 6, 7, 8, 5,
92
108
  4, 11, 12, 13, 14, 9, 15, 2, 10, 17,
93
- nil, nil, 16, nil, nil, nil, nil, 10 ]
109
+ nil, nil, 16, nil, nil, nil, 10 ]
94
110
 
95
111
  racc_goto_pointer = [
96
112
  nil, 4, 17, 3, 6, 5, 2, 3, 4, -18,
97
- -21, -11, -33, 9, -3, -11, -16, -20 ]
113
+ -21, -11, -32, 9, -3, -11, -16, -20 ]
98
114
 
99
115
  racc_goto_default = [
100
116
  nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
@@ -102,44 +118,43 @@ racc_goto_default = [
102
118
 
103
119
  racc_reduce_table = [
104
120
  0, 0, :racc_error,
105
- 0, 18, :_reduce_1,
106
- 1, 18, :_reduce_2,
107
- 1, 19, :_reduce_3,
108
- 2, 19, :_reduce_4,
109
- 2, 20, :_reduce_5,
110
- 1, 20, :_reduce_6,
111
- 1, 20, :_reduce_7,
112
- 1, 21, :_reduce_8,
113
- 1, 21, :_reduce_9,
114
- 1, 21, :_reduce_10,
115
- 1, 21, :_reduce_11,
116
- 4, 22, :_reduce_12,
117
- 0, 26, :_reduce_13,
118
- 1, 26, :_reduce_14,
119
- 4, 24, :_reduce_15,
120
- 4, 23, :_reduce_16,
121
- 3, 28, :_reduce_17,
122
- 1, 27, :_reduce_18,
123
- 3, 27, :_reduce_19,
124
- 1, 29, :_reduce_20,
125
- 3, 29, :_reduce_21,
126
- 1, 29, :_reduce_22,
127
- 3, 25, :_reduce_23,
128
- 4, 25, :_reduce_24,
129
- 2, 25, :_reduce_25,
130
- 4, 30, :_reduce_26,
131
- 1, 32, :_reduce_27,
132
- 1, 32, :_reduce_28,
133
- 2, 32, :_reduce_29,
134
- 1, 31, :_reduce_30,
135
- 3, 31, :_reduce_31,
136
- 3, 33, :_reduce_32,
137
- 1, 34, :_reduce_33,
138
- 1, 34, :_reduce_34 ]
139
-
140
- racc_reduce_n = 35
141
-
142
- racc_shift_n = 59
121
+ 0, 19, :_reduce_1,
122
+ 1, 19, :_reduce_2,
123
+ 1, 20, :_reduce_3,
124
+ 2, 20, :_reduce_4,
125
+ 2, 21, :_reduce_5,
126
+ 1, 21, :_reduce_6,
127
+ 1, 21, :_reduce_7,
128
+ 1, 22, :_reduce_8,
129
+ 1, 22, :_reduce_9,
130
+ 1, 22, :_reduce_10,
131
+ 1, 22, :_reduce_11,
132
+ 4, 23, :_reduce_12,
133
+ 0, 27, :_reduce_13,
134
+ 1, 27, :_reduce_14,
135
+ 4, 25, :_reduce_15,
136
+ 4, 24, :_reduce_16,
137
+ 3, 29, :_reduce_17,
138
+ 1, 28, :_reduce_18,
139
+ 3, 28, :_reduce_19,
140
+ 1, 30, :_reduce_20,
141
+ 3, 30, :_reduce_21,
142
+ 1, 30, :_reduce_22,
143
+ 3, 26, :_reduce_23,
144
+ 4, 26, :_reduce_24,
145
+ 2, 26, :_reduce_25,
146
+ 3, 31, :_reduce_26,
147
+ 0, 33, :_reduce_27,
148
+ 1, 33, :_reduce_none,
149
+ 1, 32, :_reduce_29,
150
+ 3, 32, :_reduce_30,
151
+ 3, 34, :_reduce_31,
152
+ 1, 35, :_reduce_32,
153
+ 1, 35, :_reduce_33 ]
154
+
155
+ racc_reduce_n = 34
156
+
157
+ racc_shift_n = 56
143
158
 
144
159
  racc_token_table = {
145
160
  false => 0,
@@ -152,15 +167,16 @@ racc_token_table = {
152
167
  :EQ => 7,
153
168
  :LBRACE => 8,
154
169
  :META_CONTENT => 9,
155
- :NAME => 10,
156
- :NUMBER => 11,
157
- :PREAMBLE => 12,
158
- :RBRACE => 13,
159
- :SHARP => 14,
160
- :STRING => 15,
161
- :STRING_LITERAL => 16 }
170
+ :KEY => 10,
171
+ :NAME => 11,
172
+ :NUMBER => 12,
173
+ :PREAMBLE => 13,
174
+ :RBRACE => 14,
175
+ :SHARP => 15,
176
+ :STRING => 16,
177
+ :STRING_LITERAL => 17 }
162
178
 
163
- racc_nt_base = 17
179
+ racc_nt_base = 18
164
180
 
165
181
  racc_use_result_var = true
166
182
 
@@ -191,6 +207,7 @@ Racc_token_to_s_table = [
191
207
  "EQ",
192
208
  "LBRACE",
193
209
  "META_CONTENT",
210
+ "KEY",
194
211
  "NAME",
195
212
  "NUMBER",
196
213
  "PREAMBLE",
@@ -213,7 +230,7 @@ Racc_token_to_s_table = [
213
230
  "string_literal",
214
231
  "entry_head",
215
232
  "assignments",
216
- "key",
233
+ "opt_key",
217
234
  "assignment",
218
235
  "value" ]
219
236
 
@@ -407,42 +424,37 @@ module_eval(<<'.,.,', 'bibtex.y', 69)
407
424
 
408
425
  module_eval(<<'.,.,', 'bibtex.y', 71)
409
426
  def _reduce_27(val, _values, result)
410
- result = val[0]
427
+ missing_key
411
428
  result
412
429
  end
413
430
  .,.,
414
431
 
415
- module_eval(<<'.,.,', 'bibtex.y', 72)
416
- def _reduce_28(val, _values, result)
417
- result = val[0]
418
- result
419
- end
420
- .,.,
432
+ # reduce 28 omitted
421
433
 
422
- module_eval(<<'.,.,', 'bibtex.y', 73)
434
+ module_eval(<<'.,.,', 'bibtex.y', 74)
423
435
  def _reduce_29(val, _values, result)
424
- result = val[0,2].join
436
+ result = val[0]
425
437
  result
426
438
  end
427
439
  .,.,
428
440
 
429
441
  module_eval(<<'.,.,', 'bibtex.y', 75)
430
442
  def _reduce_30(val, _values, result)
431
- result = val[0]
443
+ result.merge!(val[2])
432
444
  result
433
445
  end
434
446
  .,.,
435
447
 
436
- module_eval(<<'.,.,', 'bibtex.y', 76)
448
+ module_eval(<<'.,.,', 'bibtex.y', 77)
437
449
  def _reduce_31(val, _values, result)
438
- result.merge!(val[2])
450
+ result = { val[0].downcase.to_sym => val[2] }
439
451
  result
440
452
  end
441
453
  .,.,
442
454
 
443
- module_eval(<<'.,.,', 'bibtex.y', 78)
455
+ module_eval(<<'.,.,', 'bibtex.y', 79)
444
456
  def _reduce_32(val, _values, result)
445
- result = { val[0].downcase.to_sym => val[2] }
457
+ result = val[0]
446
458
  result
447
459
  end
448
460
  .,.,
@@ -454,13 +466,6 @@ module_eval(<<'.,.,', 'bibtex.y', 80)
454
466
  end
455
467
  .,.,
456
468
 
457
- module_eval(<<'.,.,', 'bibtex.y', 81)
458
- def _reduce_34(val, _values, result)
459
- result = val[0]
460
- result
461
- end
462
- .,.,
463
-
464
469
  def _reduce_none(val, _values, result)
465
470
  val[0]
466
471
  end
@@ -18,6 +18,6 @@
18
18
 
19
19
  module BibTeX
20
20
  module Version
21
- STRING = '2.0.10'.freeze
21
+ STRING = '2.0.11'.freeze
22
22
  end
23
23
  end
@@ -17,5 +17,8 @@ module BibTeX
17
17
  [:STRING_LITERAL, 'foo bar']
18
18
  end
19
19
 
20
+ it 'matches KEY tokens' do
21
+ Lexer.new.analyse("@misc{foo, }").symbols.must_be :==, [:AT, :NAME, :LBRACE, :KEY, :RBRACE, false]
22
+ end
20
23
  end
21
24
  end
@@ -40,44 +40,58 @@ module BibTeX
40
40
  end
41
41
  end
42
42
 
43
- describe 'key parsing' do
44
- it 'handles whitespace in keys' do
43
+ describe 'key parsing' do
44
+ it 'handles whitespace in keys' do
45
45
  input = "@Misc{George Martin06,title = {FEAST FOR CROWS}}"
46
46
  bib = Parser.new(:debug => false, :strict => false).parse(input)
47
47
  assert_equal "George Martin06", bib.first.key
48
48
  assert bib[:"George Martin06"]
49
49
  end
50
+
51
+ it 'fails when there is no cite-key' do
52
+ input = "@misc{title = {Crime and Punishment}}"
53
+ assert_raises ParseError do
54
+ Parser.new(:debug => false, :strict => false).parse(input)
55
+ end
56
+ end
57
+
58
+ it 'tolerates missing key with :allow_missing_keys set' do
59
+ input = "@misc{title = {Crime and Punishment}}"
60
+ assert_equal :misc, Parser.new({
61
+ :debug => false, :strict => false, :allow_missing_keys => true
62
+ }).parse(input)[0].type
63
+ end
50
64
  end
51
-
52
- describe 'backslashes and escape sequences' do
53
-
54
- it 'leaves backslashes intact' do
55
- Parser.new.parse(%q(@misc{key, title = "a backslash: \"}))[0].title.must_be :==, 'a backslash: \\'
56
- end
57
-
58
- it 'parses LaTeX escaped quotes {"}' do
59
- Parser.new.parse(%q(@misc{key, title = "{"}"}))[0].title.must_be :==, '{"}'
60
- end
61
-
62
- it 'parses complex LaTeX markup' do
63
- b = Parser.new.parse(<<-END)[0]
64
- @book{proust_1996,
65
- address = {Paris},
66
- author = {Proust, Jo\\"{e}lle},
67
- booktitle = {Perception et Intermodalit\\'{e}: Approches Actuelles De La Question De Molyneux},
68
- editor = {Proust, Jo\\"{e}lle},
69
- keywords = {Perception; Molyneux's Problem},
70
- publisher = {Presses Universitaires de France},
71
- title = {Perception et Intermodalit\\'{e}: Approches Actuelles De La Question De Molyneux},
72
- year = {1996}
73
- }
74
- END
75
- b.booktitle.must_be :==, "Perception et Intermodalit\\'{e}: Approches Actuelles De La Question De Molyneux"
76
- b.editor.must_be :==, 'Proust, Jo\"{e}lle'
77
- end
78
-
79
- end
80
-
65
+
66
+ describe 'backslashes and escape sequences' do
67
+
68
+ it 'leaves backslashes intact' do
69
+ Parser.new.parse(%q(@misc{key, title = "a backslash: \"}))[0].title.must_be :==, 'a backslash: \\'
70
+ end
71
+
72
+ it 'parses LaTeX escaped quotes {"}' do
73
+ Parser.new.parse(%q(@misc{key, title = "{"}"}))[0].title.must_be :==, '{"}'
74
+ end
75
+
76
+ it 'parses complex LaTeX markup' do
77
+ b = Parser.new.parse(<<-END)[0]
78
+ @book{proust_1996,
79
+ address = {Paris},
80
+ author = {Proust, Jo\\"{e}lle},
81
+ booktitle = {Perception et Intermodalit\\'{e}: Approches Actuelles De La Question De Molyneux},
82
+ editor = {Proust, Jo\\"{e}lle},
83
+ keywords = {Perception; Molyneux's Problem},
84
+ publisher = {Presses Universitaires de France},
85
+ title = {Perception et Intermodalit\\'{e}: Approches Actuelles De La Question De Molyneux},
86
+ year = {1996}
87
+ }
88
+ END
89
+ b.booktitle.must_be :==, "Perception et Intermodalit\\'{e}: Approches Actuelles De La Question De Molyneux"
90
+ b.editor.must_be :==, 'Proust, Jo\"{e}lle'
91
+ end
92
+
93
+ end
94
+
81
95
  describe 'given a set of explicit and implicit comments' do
82
96
  before do
83
97
  @bib = Parser.new(:debug => false, :include => [:meta_content]).parse(File.read(Test.fixtures(:comment)))
@@ -129,26 +143,26 @@ module BibTeX
129
143
 
130
144
  end
131
145
 
132
- describe 'given an entry with missing commas between fields' do
133
- before do
134
- @level = BibTeX.log.level
135
- BibTeX.log.level = Logger::FATAL
136
- end
137
-
138
- after do
139
- BibTeX.log.level = @level
140
- end
141
-
142
- it 'raises a parser error' do
143
- lambda {
144
- Parser.new.parse <<-END
145
- @book{book1,
146
- title = "Parse error because"
147
- author = "comma missing between title and author"
148
- }
149
- END
150
- }.must_raise(ParseError)
151
- end
152
- end
146
+ describe 'given an entry with missing commas between fields' do
147
+ before do
148
+ @level = BibTeX.log.level
149
+ BibTeX.log.level = Logger::FATAL
150
+ end
151
+
152
+ after do
153
+ BibTeX.log.level = @level
154
+ end
155
+
156
+ it 'raises a parser error' do
157
+ lambda {
158
+ Parser.new.parse <<-END
159
+ @book{book1,
160
+ title = "Parse error because"
161
+ author = "comma missing between title and author"
162
+ }
163
+ END
164
+ }.must_raise(ParseError)
165
+ end
166
+ end
153
167
  end
154
168
  end
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.10
4
+ version: 2.0.11
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: 2012-05-15 00:00:00.000000000 Z
12
+ date: 2012-05-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: latex-decode
16
- requirement: &70295937490600 !ruby/object:Gem::Requirement
16
+ requirement: &70315022871540 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.0.6
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70295937490600
24
+ version_requirements: *70315022871540
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: multi_json
27
- requirement: &70295937489320 !ruby/object:Gem::Requirement
27
+ requirement: &70315022871020 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '1.3'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70295937489320
35
+ version_requirements: *70315022871020
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &70295937488260 !ruby/object:Gem::Requirement
38
+ requirement: &70315022870540 !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: *70295937488260
46
+ version_requirements: *70315022870540
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: racc
49
- requirement: &70295937487620 !ruby/object:Gem::Requirement
49
+ requirement: &70315022870060 !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: *70295937487620
57
+ version_requirements: *70315022870060
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rdoc
60
- requirement: &70295937487140 !ruby/object:Gem::Requirement
60
+ requirement: &70315022869580 !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: *70295937487140
68
+ version_requirements: *70315022869580
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
@@ -180,18 +180,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
180
180
  - - ! '>='
181
181
  - !ruby/object:Gem::Version
182
182
  version: '0'
183
- segments:
184
- - 0
185
- hash: -1420866145453124737
186
183
  required_rubygems_version: !ruby/object:Gem::Requirement
187
184
  none: false
188
185
  requirements:
189
186
  - - ! '>='
190
187
  - !ruby/object:Gem::Version
191
188
  version: '0'
192
- segments:
193
- - 0
194
- hash: -1420866145453124737
195
189
  requirements: []
196
190
  rubyforge_project:
197
191
  rubygems_version: 1.8.10
@@ -212,3 +206,4 @@ test_files:
212
206
  - test/bibtex/test_value.rb
213
207
  - test/test_bibtex.rb
214
208
  - test/test_export.rb
209
+ has_rdoc: