bibtex-ruby 1.3.1 → 1.3.2

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/History.txt CHANGED
@@ -1,3 +1,9 @@
1
+ === 1.3.2
2
+
3
+ * Fixed numeric keys issue
4
+ * Fixed CiteProc/CSL date export
5
+ * Implemented BibTeX month value conversion
6
+
1
7
  === 1.3.1
2
8
 
3
9
  * Added CiteProc/CSL export format
data/Manifest CHANGED
@@ -15,6 +15,8 @@ features
15
15
  features/bibtex.feature
16
16
  features/entries.feature
17
17
  features/issues
18
+ features/issues/number_keys.feature
19
+ features/issues/parse_months.feature
18
20
  features/issues/slash_keys.feature
19
21
  features/names.feature
20
22
  features/preambles.feature
@@ -0,0 +1,45 @@
1
+ Feature: Keys containing '/' symbols
2
+ As a hacker who works with bibliographies
3
+ I want to parse BibTeX entries with keys starting with numbers
4
+ Because they frequently occur in key naming schemes
5
+
6
+ Scenario: Two entries with keys starting with a number
7
+ When I parse the following file:
8
+ """
9
+ @misc{2008knowledge,
10
+ Date-Added = {2011-04-24 17:41:02 -0400},
11
+ Date-Modified = {2011-04-27 20:13:35 -0400},
12
+ Howpublished = {http://oro.open.ac.uk/11766/},
13
+ Month = sep,
14
+ Note = {Knowledge Cartography is the discipline of mapping intellectual {landscapes.The} focus of this book is on the process by which manually crafting interactive, hypertextual maps clarifies one’s own understanding, as well as communicating {it.The} authors see mapping software as a set of visual tools for reading and writing in a networked age. In an information ocean, the primary challenge is to find meaningful patterns around which we can weave plausible narratives. Maps of concepts, discussions and arguments make the connections between ideas tangible and disputable. With 17 chapters from the leading researchers and practitioners, the reader will find the current state–of-the-art in the field. Part 1 focuses on educational applications in schools and universities, before Part 2 turns to applications in professional communities},
15
+ Shorttitle = {Knowledge Cartography},
16
+ Title = {Knowledge Cartography: Software tools and mapping techniques},
17
+ Type = {Edited Book},
18
+ Url = {http://oro.open.ac.uk/11766/},
19
+ Year = {2008},
20
+ Bdsk-File-1 = {YnBsaXN0MDDUAQIDBAUIJidUJHRvcFgkb2JqZWN0c1gkdmVyc2lvblkkYXJjaGl2ZXLRBgdUcm9vdIABqAkKFRYXGyIjVSRudWxs0wsMDQ4RFFpOUy5vYmplY3RzV05TLmtleXNWJGNsYXNzog8QgASABqISE4ACgAOAB1lhbGlhc0RhdGFccmVsYXRpdmVQYXRo0hgNGRpXTlMuZGF0YU8RAXwAAAAAAXwAAgAABEhvbWUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMmm5vlIKwAAABLivBEyMDA4a25vd2xlZGdlLnBkZgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEtx5ydoOuQAAAAAAAAAAAAIAAwAACQAAAAAAAAAAAAAAAAAAAAAHQmliZGVzawAAEAAIAADJpx85AAAAEQAIAADJ2kb5AAAAAQAMABLivAAAAF8AAABXAAIALkhvbWU6c3RpYW46RG9jdW1lbnRzOkJpYmRlc2s6MjAwOGtub3dsZWRnZS5wZGYADgAkABEAMgAwADAAOABrAG4AbwB3AGwAZQBkAGcAZQAuAHAAZABmAA8ACgAEAEgAbwBtAGUAEgAqL3N0aWFuL0RvY3VtZW50cy9CaWJkZXNrLzIwMDhrbm93bGVkZ2UucGRmABMADS9Wb2x1bWVzL0hvbWUAABUAAgAT//8AAIAF0hwdHh9YJGNsYXNzZXNaJGNsYXNzbmFtZaMfICFdTlNNdXRhYmxlRGF0YVZOU0RhdGFYTlNPYmplY3RfECkuLi8uLi9Eb2N1bWVudHMvQmliZGVzay8yMDA4a25vd2xlZGdlLnBkZtIcHSQloiUhXE5TRGljdGlvbmFyeRIAAYagXxAPTlNLZXllZEFyY2hpdmVyAAgAEQAWAB8AKAAyADUAOgA8AEUASwBSAF0AZQBsAG8AcQBzAHYAeAB6AHwAhgCTAJgAoAIgAiICJwIwAjsCPwJNAlQCXQKJAo4CkQKeAqMAAAAAAAACAQAAAAAAAAAoAAAAAAAAAAAAAAAAAAACtQ==}}
21
+
22
+ @misc{2007proceedings,
23
+ Date-Added = {2011-04-24 17:34:26 -0400},
24
+ Date-Modified = {2011-04-27 20:13:35 -0400},
25
+ Howpublished = {http://oro.open.ac.uk/9275/},
26
+ Month = oct,
27
+ Note = {Proceedings {ICPW'07:} 2nd International Conference on the Pragmatic Web, 22-23 Oct. 2007, Tilburg: {NL}},
28
+ Shorttitle = {Proceedings {ICPW'07}},
29
+ Title = {Proceedings {ICPW'07:} 2nd International Conference on the Pragmatic Web, 22-23 Oct. 2007, Tilburg: {NL}},
30
+ Type = {Edited Book},
31
+ Url = {http://oro.open.ac.uk/9275/},
32
+ Year = {2007},
33
+ Bdsk-File-1 = {YnBsaXN0MDDUAQIDBAUIJidUJHRvcFgkb2JqZWN0c1gkdmVyc2lvblkkYXJjaGl2ZXLRBgdUcm9vdIABqAkKFRYXGyIjVSRudWxs0wsMDQ4RFFpOUy5vYmplY3RzV05TLmtleXNWJGNsYXNzog8QgASABqISE4ACgAOAB1lhbGlhc0RhdGFccmVsYXRpdmVQYXRo0hgNGRpXTlMuZGF0YU8RAYQAAAAAAYQAAgAABEhvbWUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMmm5vlIKwAAABLivBMyMDA3cHJvY2VlZGluZ3MucGRmAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEuYBydoPoVBERiAAAAAAAAIAAwAACQAAAAAAAAAAAAAAAAAAAAAHQmliZGVzawAAEAAIAADJpx85AAAAEQAIAADJ2kfhAAAAAQAMABLivAAAAF8AAABXAAIAMEhvbWU6c3RpYW46RG9jdW1lbnRzOkJpYmRlc2s6MjAwN3Byb2NlZWRpbmdzLnBkZgAOACgAEwAyADAAMAA3AHAAcgBvAGMAZQBlAGQAaQBuAGcAcwAuAHAAZABmAA8ACgAEAEgAbwBtAGUAEgAsL3N0aWFuL0RvY3VtZW50cy9CaWJkZXNrLzIwMDdwcm9jZWVkaW5ncy5wZGYAEwANL1ZvbHVtZXMvSG9tZQAAFQACABP//wAAgAXSHB0eH1gkY2xhc3Nlc1okY2xhc3NuYW1lox8gIV1OU011dGFibGVEYXRhVk5TRGF0YVhOU09iamVjdF8QKy4uLy4uL0RvY3VtZW50cy9CaWJkZXNrLzIwMDdwcm9jZWVkaW5ncy5wZGbSHB0kJaIlIVxOU0RpY3Rpb25hcnkSAAGGoF8QD05TS2V5ZWRBcmNoaXZlcgAIABEAFgAfACgAMgA1ADoAPABFAEsAUgBdAGUAbABvAHEAcwB2AHgAegB8AIYAkwCYAKACKAIqAi8COAJDAkcCVQJcAmUCkwKYApsCqAKtAAAAAAAAAgEAAAAAAAAAKAAAAAAAAAAAAAAAAAAAAr8=}}
34
+ """
35
+ Then my bibliography should contain a misc with id "2008knowledge"
36
+ And my bibliography should contain a misc with id "2007proceedings"
37
+
38
+ Scenario: An entry with a number-only key
39
+ When I parse the following file:
40
+ """
41
+ @book{2011,
42
+ Title = {Test}
43
+ }
44
+ """
45
+ Then my bibliography should contain a book with id "2011"
@@ -0,0 +1,23 @@
1
+ Feature: Keys containing '/' symbols
2
+ As a hacker who works with bibliographies
3
+ I want to export BibTeX entries to the CiteProc format
4
+
5
+ Scenario: An entry taken from the DBLP
6
+ When I parse the following file:
7
+ """
8
+ @article{DBLP:journals/dq/RossinK99,
9
+ author = {Donald F. Rossin and
10
+ Barbara D. Klein},
11
+ title = {Data Errors in Neural Network and Linear Regression Models:
12
+ An Experimental Comparison},
13
+ journal = {Data Quality Journal},
14
+ volume = {5},
15
+ month = sep,
16
+ year = {1999},
17
+ ee = {http://www.dataquality.com/999KR.htm},
18
+ bibsource = {DBLP, http://dblp.uni-trier.de}
19
+ }
20
+ """
21
+ Then my bibliography should contain these articles:
22
+ | issued |
23
+ | {"date-parts"=>[[1999, 9]]} |
@@ -52,11 +52,17 @@ Then /^my bibliography should contain the following numbers of elements:$/ do |t
52
52
  end
53
53
  end
54
54
 
55
- Then /^my bibliography should contain an entry with key "([^"]*)"$/ do |key|
55
+ Then /^my bibliography should contain an entry with (?:key|id) "([^"]*)"$/ do |key|
56
56
  refute_nil @bibliography[key.to_s]
57
57
  end
58
58
 
59
- Then /^my bibliography should not contain an entry with key "([^"]*)"$/ do |key|
59
+ Then /^my bibliography should contain an entry with (?:key|id) "([^"]*)" and a?n? (\w+) value of "([^"]*)"$/ do |key,field,value|
60
+ refute_nil @bibliography[key.to_s]
61
+ assert_equal value, @bibliography[key.to_s][field].to_s
62
+ end
63
+
64
+
65
+ Then /^my bibliography should not contain an entry with (?:key|id) "([^"]*)"$/ do |key|
60
66
  assert_nil @bibliography[key.to_sym]
61
67
  end
62
68
 
@@ -44,7 +44,7 @@ module BibTeX
44
44
  #
45
45
  def open(path, options = {})
46
46
  b = parse(Kernel.open(path).read, options)
47
- return b unless block_given?
47
+ return b unless !b.nil? and block_given?
48
48
 
49
49
  begin
50
50
  yield b
@@ -56,7 +56,8 @@ module BibTeX
56
56
  # Parses the given string and returns a corresponding Bibliography instance.
57
57
  def parse(bibtex, options = {})
58
58
  b = Parser.new(options).parse(bibtex)
59
- b.parse_names unless options[:parse_names] == false
59
+ b.parse_names unless b.nil? || options[:parse_names] == false
60
+ b.parse_months unless b.nil? || options[:parse_months] == false
60
61
  b
61
62
  end
62
63
 
@@ -119,6 +120,11 @@ module BibTeX
119
120
  self
120
121
  end
121
122
 
123
+ def parse_months
124
+ q('@entry') { |e| e.parse_month }
125
+ self
126
+ end
127
+
122
128
  #
123
129
  # Deletes an object, or a list of objects from the bibliography.
124
130
  # If a list of objects is to be deleted, you can either supply the list
data/lib/bibtex/bibtex.y CHANGED
@@ -70,6 +70,7 @@ rule
70
70
 
71
71
  key : NAME { result = val[0] }
72
72
  | NUMBER { result = val[0] }
73
+ | NUMBER NAME { result = val[0,2].join }
73
74
 
74
75
  assignments : assignment { result = val[0] }
75
76
  | assignments COMMA assignment { result.merge!(val[2]) }
@@ -125,8 +126,8 @@ require 'bibtex/lexer'
125
126
  end
126
127
 
127
128
  def on_error(tid, val, vstack)
128
- #raise(ParseError, "Failed to parse BibTeX on value %s (%s) %s" % [val.inspect, token_to_str(tid) || '?', vstack.inspect])
129
129
  Log.error("Failed to parse BibTeX on value %s (%s) %s" % [val.inspect, token_to_str(tid) || '?', vstack.inspect])
130
+ #raise(ParseError, "Failed to parse BibTeX on value %s (%s) %s" % [val.inspect, token_to_str(tid) || '?', vstack.inspect])
130
131
  end
131
132
 
132
133
  # -*- racc -*-
@@ -29,7 +29,12 @@ module BibTeX
29
29
 
30
30
  # Returns an array of BibTeX elements.
31
31
  def self.parse(string, options = {})
32
- BibTeX::Parser.new(options).parse(string).data
32
+ elements = BibTeX::Parser.new(options).parse(string).data
33
+ elements.each do |e|
34
+ e.parse_names unless !e.respond_to?(:parse_names) || options[:parse_names] == false
35
+ e.parse_month unless !e.respond_to?(:parse_month) || options[:parse_months] == false
36
+ end
37
+ elements
33
38
  end
34
39
 
35
40
  # Returns a string containing the object's content.
data/lib/bibtex/entry.rb CHANGED
@@ -44,10 +44,23 @@ module BibTeX
44
44
  :unpublished => [:author,:title,:note]
45
45
  }).freeze
46
46
 
47
- NAME_FIELDS = [:author, :editor, :translator].freeze
48
- DATE_FIELDS = [:year].freeze
47
+ NAME_FIELDS = [:author,:editor,:translator].freeze
48
+ DATE_FIELDS = [:year,:month].freeze
49
+
50
+ MONTHS = [:jan,:feb,:mar,:apr,:may,:jun,:jul,:aug,:sep,:oct,:nov,:dec].freeze
49
51
 
50
- CSL_FIELDS = Hash.new {|h,k|k}.merge(Hash[*%w{
52
+ MONTHS_FILTER = Hash.new do |h,k|
53
+ case k.to_s.strip
54
+ when /^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/i
55
+ h[k] = Value.new(k.to_s[0,3].downcase.to_sym)
56
+ when /^\d\d?$/
57
+ h[k] = Value.new(MONTHS[k.to_i - 1] || k)
58
+ else
59
+ h[k] = Value.new(k)
60
+ end
61
+ end
62
+
63
+ CSL_FILTER = Hash.new {|h,k|k}.merge(Hash[*%w{
51
64
  date issued
52
65
  isbn ISBN
53
66
  booktitle container-title
@@ -61,6 +74,18 @@ module BibTeX
61
74
  year issued
62
75
  }.map(&:intern)]).freeze
63
76
 
77
+ CSL_FIELDS = %w{ abstract annote archive archive_location archive-place
78
+ authority call-number chapter-number citation-label citation-number
79
+ collection-title container-title DOI edition event event-place
80
+ first-reference-note-number genre ISBN issue jurisdiction keyword locator
81
+ medium note number number-of-pages number-of-volumes original-publisher
82
+ original-publisher-place original-title page page-first publisher
83
+ publisher-place references section status title URL version volume
84
+ year-suffix accessed container event-date issued original-date
85
+ author editor translator recipient interviewer publisher composer
86
+ original-publisher original-author container-author collection-editor
87
+ }.map(&:intern).freeze
88
+
64
89
  CSL_TYPES = Hash.new {|h,k|k}.merge(Hash[*%w{
65
90
  booklet pamphlet
66
91
  conference paper-conference
@@ -223,6 +248,17 @@ module BibTeX
223
248
  self
224
249
  end
225
250
 
251
+ def month=(month)
252
+ @fields[:month] = MONTHS_FILTER[month]
253
+ end
254
+
255
+ def parse_month
256
+ @fields[:month] = MONTHS_FILTER[@fields[:month]] if @fields.has_key?(:month)
257
+ self
258
+ end
259
+
260
+ alias :parse_months :parse_month
261
+
226
262
  # Parses all name values of the entry. Tries to replace and join the
227
263
  # value prior to parsing.
228
264
  def parse_names
@@ -259,11 +295,20 @@ module BibTeX
259
295
  options[:quotes] ||= []
260
296
  hash = { 'id' => key.to_s, 'type' => CSL_TYPES[type].to_s }
261
297
  each_pair do |k,v|
262
- hash[CSL_FIELDS[k].to_s] = k == :year ? v.to_date : v.to_citeproc(options)
298
+ hash[CSL_FILTER[k].to_s] = v.to_citeproc(options) unless DATE_FIELDS.include?(k)
263
299
  end
300
+ hash['issued'] = citeproc_date
264
301
  hash
265
302
  end
266
303
 
304
+ def issued
305
+ m = MONTHS.find_index(@fields[:month] && @fields[:month].v)
306
+ m = m + 1 unless m.nil?
307
+ { 'date-parts' => [[@fields[:year],m].compact.map(&:to_i)] }
308
+ end
309
+
310
+ alias :citeproc_date :issued
311
+
267
312
  def to_xml(options = {})
268
313
  require 'rexml/document'
269
314
 
data/lib/bibtex/error.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  module BibTeX
2
+
3
+ class ParseError < StandardError; end
2
4
 
3
5
  #
4
6
  # Represents a lexical or syntactical error.
@@ -29,12 +29,13 @@ rule 24 entry: entry_head RBRACE
29
29
  rule 25 entry_head: NAME LBRACE key COMMA
30
30
  rule 26 key: NAME
31
31
  rule 27 key: NUMBER
32
- rule 28 assignments: assignment
33
- rule 29 assignments: assignments COMMA assignment
34
- rule 30 assignment: NAME EQ value
35
- rule 31 value: string_value
36
- rule 32 value: NUMBER
37
- rule 33 value: LBRACE content RBRACE
32
+ rule 28 key: NUMBER NAME
33
+ rule 29 assignments: assignment
34
+ rule 30 assignments: assignments COMMA assignment
35
+ rule 31 assignment: NAME EQ value
36
+ rule 32 value: string_value
37
+ rule 33 value: NUMBER
38
+ rule 34 value: LBRACE content RBRACE
38
39
 
39
40
  ------- Symbols -------
40
41
 
@@ -68,10 +69,10 @@ rule 33 value: LBRACE content RBRACE
68
69
  on right: 11
69
70
  on left : 22 23 24
70
71
  content (26)
71
- on right: 12 33
72
+ on right: 12 34
72
73
  on left : 13 14
73
74
  string_value (27)
74
- on right: 15 17 19 31
75
+ on right: 15 17 19 32
75
76
  on left : 18 19
76
77
  string_assignment (28)
77
78
  on right: 16
@@ -83,34 +84,34 @@ rule 33 value: LBRACE content RBRACE
83
84
  on right: 22 23 24
84
85
  on left : 25
85
86
  assignments (31)
86
- on right: 22 23 29
87
- on left : 28 29
87
+ on right: 22 23 30
88
+ on left : 29 30
88
89
  key (32)
89
90
  on right: 25
90
- on left : 26 27
91
+ on left : 26 27 28
91
92
  assignment (33)
92
- on right: 28 29
93
- on left : 30
93
+ on right: 29 30
94
+ on left : 31
94
95
  value (34)
95
- on right: 30
96
- on left : 31 32 33
96
+ on right: 31
97
+ on left : 32 33 34
97
98
 
98
99
  **Terminals, with rules where they appear
99
100
 
100
101
  $end (0)
101
102
  error (1)
102
103
  AT (2) 5
103
- COMMA (3) 23 25 29
104
+ COMMA (3) 23 25 30
104
105
  COMMENT (4) 12
105
106
  CONTENT (5) 14
106
107
  ERROR (6) 7
107
- EQ (7) 17 30
108
- LBRACE (8) 12 15 16 25 33
108
+ EQ (7) 17 31
109
+ LBRACE (8) 12 15 16 25 34
109
110
  META_CONTENT (9) 6
110
- NAME (10) 17 20 25 26 30
111
- NUMBER (11) 27 32
111
+ NAME (10) 17 20 25 26 28 31
112
+ NUMBER (11) 27 28 33
112
113
  PREAMBLE (12) 15
113
- RBRACE (13) 12 15 16 22 23 24 33
114
+ RBRACE (13) 12 15 16 22 23 24 34
114
115
  SHARP (14) 19
115
116
  STRING (15) 16
116
117
  STRING_LITERAL (16) 21
@@ -309,7 +310,7 @@ state 23
309
310
 
310
311
  22) entry : entry_head assignments _ RBRACE
311
312
  23) entry : entry_head assignments _ COMMA RBRACE
312
- 29) assignments : assignments _ COMMA assignment
313
+ 30) assignments : assignments _ COMMA assignment
313
314
 
314
315
  COMMA shift, and go to state 37
315
316
  RBRACE shift, and go to state 36
@@ -324,14 +325,14 @@ state 24
324
325
 
325
326
  state 25
326
327
 
327
- 28) assignments : assignment _
328
+ 29) assignments : assignment _
328
329
 
329
- $default reduce using rule 28 (assignments)
330
+ $default reduce using rule 29 (assignments)
330
331
 
331
332
 
332
333
  state 26
333
334
 
334
- 30) assignment : NAME _ EQ value
335
+ 31) assignment : NAME _ EQ value
335
336
 
336
337
  EQ shift, and go to state 38
337
338
 
@@ -413,7 +414,7 @@ state 36
413
414
  state 37
414
415
 
415
416
  23) entry : entry_head assignments COMMA _ RBRACE
416
- 29) assignments : assignments COMMA _ assignment
417
+ 30) assignments : assignments COMMA _ assignment
417
418
 
418
419
  NAME shift, and go to state 26
419
420
  RBRACE shift, and go to state 47
@@ -422,7 +423,7 @@ state 37
422
423
 
423
424
  state 38
424
425
 
425
- 30) assignment : NAME EQ _ value
426
+ 31) assignment : NAME EQ _ value
426
427
 
427
428
  LBRACE shift, and go to state 52
428
429
  NAME shift, and go to state 32
@@ -450,7 +451,9 @@ state 40
450
451
  state 41
451
452
 
452
453
  27) key : NUMBER _
454
+ 28) key : NUMBER _ NAME
453
455
 
456
+ NAME shift, and go to state 54
454
457
  $default reduce using rule 27 (key)
455
458
 
456
459
 
@@ -475,7 +478,7 @@ state 44
475
478
  NAME shift, and go to state 32
476
479
  STRING_LITERAL shift, and go to state 33
477
480
 
478
- string_literal go to state 54
481
+ string_literal go to state 55
479
482
 
480
483
  state 45
481
484
 
@@ -491,7 +494,7 @@ state 46
491
494
  NAME shift, and go to state 32
492
495
  STRING_LITERAL shift, and go to state 33
493
496
 
494
- string_value go to state 55
497
+ string_value go to state 56
495
498
  string_literal go to state 31
496
499
 
497
500
  state 47
@@ -503,42 +506,42 @@ state 47
503
506
 
504
507
  state 48
505
508
 
506
- 29) assignments : assignments COMMA assignment _
509
+ 30) assignments : assignments COMMA assignment _
507
510
 
508
- $default reduce using rule 29 (assignments)
511
+ $default reduce using rule 30 (assignments)
509
512
 
510
513
 
511
514
  state 49
512
515
 
513
516
  19) string_value : string_value _ SHARP string_literal
514
- 31) value : string_value _
517
+ 32) value : string_value _
515
518
 
516
519
  SHARP shift, and go to state 44
517
- $default reduce using rule 31 (value)
520
+ $default reduce using rule 32 (value)
518
521
 
519
522
 
520
523
  state 50
521
524
 
522
- 30) assignment : NAME EQ value _
525
+ 31) assignment : NAME EQ value _
523
526
 
524
- $default reduce using rule 30 (assignment)
527
+ $default reduce using rule 31 (assignment)
525
528
 
526
529
 
527
530
  state 51
528
531
 
529
- 32) value : NUMBER _
532
+ 33) value : NUMBER _
530
533
 
531
- $default reduce using rule 32 (value)
534
+ $default reduce using rule 33 (value)
532
535
 
533
536
 
534
537
  state 52
535
538
 
536
- 33) value : LBRACE _ content RBRACE
539
+ 34) value : LBRACE _ content RBRACE
537
540
 
538
541
  CONTENT shift, and go to state 29
539
542
  $default reduce using rule 13 (content)
540
543
 
541
- content go to state 56
544
+ content go to state 57
542
545
 
543
546
  state 53
544
547
 
@@ -549,12 +552,19 @@ state 53
549
552
 
550
553
  state 54
551
554
 
555
+ 28) key : NUMBER NAME _
556
+
557
+ $default reduce using rule 28 (key)
558
+
559
+
560
+ state 55
561
+
552
562
  19) string_value : string_value SHARP string_literal _
553
563
 
554
564
  $default reduce using rule 19 (string_value)
555
565
 
556
566
 
557
- state 55
567
+ state 56
558
568
 
559
569
  17) string_assignment : NAME EQ string_value _
560
570
  19) string_value : string_value _ SHARP string_literal
@@ -563,16 +573,16 @@ state 55
563
573
  $default reduce using rule 17 (string_assignment)
564
574
 
565
575
 
566
- state 56
576
+ state 57
567
577
 
568
- 33) value : LBRACE content _ RBRACE
578
+ 34) value : LBRACE content _ RBRACE
569
579
 
570
- RBRACE shift, and go to state 57
580
+ RBRACE shift, and go to state 58
571
581
 
572
582
 
573
- state 57
583
+ state 58
574
584
 
575
- 33) value : LBRACE content RBRACE _
585
+ 34) value : LBRACE content RBRACE _
576
586
 
577
- $default reduce using rule 33 (value)
587
+ $default reduce using rule 34 (value)
578
588
 
data/lib/bibtex/parser.rb CHANGED
@@ -11,7 +11,7 @@ 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', 89)
14
+ module_eval(<<'...end bibtex.y/module_eval...', 'bibtex.y', 90)
15
15
 
16
16
  attr_reader :lexer
17
17
 
@@ -51,8 +51,8 @@ module_eval(<<'...end bibtex.y/module_eval...', 'bibtex.y', 89)
51
51
  end
52
52
 
53
53
  def on_error(tid, val, vstack)
54
- #raise(ParseError, "Failed to parse BibTeX on value %s (%s) %s" % [val.inspect, token_to_str(tid) || '?', vstack.inspect])
55
54
  Log.error("Failed to parse BibTeX on value %s (%s) %s" % [val.inspect, token_to_str(tid) || '?', vstack.inspect])
55
+ #raise(ParseError, "Failed to parse BibTeX on value %s (%s) %s" % [val.inspect, token_to_str(tid) || '?', vstack.inspect])
56
56
  end
57
57
 
58
58
  # -*- racc -*-
@@ -60,40 +60,40 @@ module_eval(<<'...end bibtex.y/module_eval...', 'bibtex.y', 89)
60
60
  ##### State transition tables begin ###
61
61
 
62
62
  racc_action_table = [
63
- 14, 52, 37, 32, 51, 38, 18, 32, 15, 33,
63
+ 14, 52, 37, 32, 51, 35, 18, 32, 15, 33,
64
64
  4, 16, 36, 33, 6, 4, 29, 5, 32, 6,
65
- 32, 35, 5, 27, 33, 26, 33, 26, 24, 42,
66
- 47, 40, 41, 43, 44, 22, 45, 46, 21, 20,
67
- 53, 19, 7, 44, 29, 44, 57 ]
65
+ 32, 38, 5, 27, 33, 26, 33, 26, 47, 42,
66
+ 24, 43, 44, 40, 41, 22, 45, 46, 21, 20,
67
+ 53, 54, 19, 7, 44, 29, 44, 58 ]
68
68
 
69
69
  racc_action_check = [
70
- 4, 38, 23, 38, 38, 26, 4, 46, 4, 38,
71
- 2, 4, 23, 46, 2, 0, 20, 2, 44, 0,
72
- 21, 22, 0, 18, 44, 17, 21, 37, 17, 28,
73
- 37, 27, 27, 30, 30, 16, 34, 35, 15, 14,
74
- 39, 7, 1, 49, 52, 55, 56 ]
70
+ 4, 38, 23, 38, 38, 22, 4, 46, 4, 38,
71
+ 2, 4, 23, 46, 2, 0, 20, 2, 21, 0,
72
+ 44, 26, 0, 18, 21, 37, 44, 17, 37, 28,
73
+ 17, 30, 30, 27, 27, 16, 34, 35, 15, 14,
74
+ 39, 41, 7, 1, 49, 52, 56, 57 ]
75
75
 
76
76
  racc_action_pointer = [
77
- 13, 42, 8, nil, -4, nil, nil, 41, nil, nil,
78
- nil, nil, nil, nil, 31, 30, 27, 15, 15, nil,
79
- 11, 10, 11, -1, nil, nil, -2, 21, 16, nil,
80
- 20, nil, nil, nil, 23, 30, nil, 17, -7, 37,
81
- nil, nil, nil, nil, 8, nil, -3, nil, nil, 29,
82
- nil, nil, 39, nil, nil, 31, 33, nil ]
77
+ 13, 43, 8, nil, -4, nil, nil, 42, nil, nil,
78
+ nil, nil, nil, nil, 31, 30, 27, 17, 15, nil,
79
+ 11, 8, -5, -1, nil, nil, 14, 23, 16, nil,
80
+ 18, nil, nil, nil, 23, 30, nil, 15, -7, 37,
81
+ nil, 31, nil, nil, 10, nil, -3, nil, nil, 30,
82
+ nil, nil, 40, nil, nil, nil, 32, 34, nil ]
83
83
 
84
84
  racc_action_default = [
85
- -1, -34, -2, -3, -34, -6, -7, -34, -4, -5,
86
- -8, -9, -10, -11, -34, -34, -34, -34, -34, 58,
87
- -13, -34, -34, -34, -24, -28, -34, -34, -34, -14,
88
- -34, -18, -20, -21, -34, -34, -22, -34, -34, -34,
89
- -26, -27, -12, -15, -34, -16, -34, -23, -29, -31,
90
- -30, -32, -13, -25, -19, -17, -34, -33 ]
85
+ -1, -35, -2, -3, -35, -6, -7, -35, -4, -5,
86
+ -8, -9, -10, -11, -35, -35, -35, -35, -35, 59,
87
+ -13, -35, -35, -35, -24, -29, -35, -35, -35, -14,
88
+ -35, -18, -20, -21, -35, -35, -22, -35, -35, -35,
89
+ -26, -27, -12, -15, -35, -16, -35, -23, -30, -32,
90
+ -31, -33, -13, -25, -28, -19, -17, -35, -34 ]
91
91
 
92
92
  racc_goto_table = [
93
93
  28, 30, 25, 3, 1, 8, 11, 12, 13, 10,
94
- 9, 34, 54, 17, 23, 39, 2, 50, 49, nil,
95
- nil, nil, 48, nil, nil, nil, 55, nil, nil, nil,
96
- nil, nil, 56 ]
94
+ 9, 34, 55, 17, 23, 39, 2, 50, 49, nil,
95
+ nil, nil, 48, nil, nil, nil, 56, nil, nil, nil,
96
+ nil, nil, 57 ]
97
97
 
98
98
  racc_goto_check = [
99
99
  9, 10, 16, 3, 1, 3, 6, 7, 8, 5,
@@ -138,16 +138,17 @@ racc_reduce_table = [
138
138
  4, 30, :_reduce_25,
139
139
  1, 32, :_reduce_26,
140
140
  1, 32, :_reduce_27,
141
- 1, 31, :_reduce_28,
142
- 3, 31, :_reduce_29,
143
- 3, 33, :_reduce_30,
144
- 1, 34, :_reduce_31,
141
+ 2, 32, :_reduce_28,
142
+ 1, 31, :_reduce_29,
143
+ 3, 31, :_reduce_30,
144
+ 3, 33, :_reduce_31,
145
145
  1, 34, :_reduce_32,
146
- 3, 34, :_reduce_33 ]
146
+ 1, 34, :_reduce_33,
147
+ 3, 34, :_reduce_34 ]
147
148
 
148
- racc_reduce_n = 34
149
+ racc_reduce_n = 35
149
150
 
150
- racc_shift_n = 58
151
+ racc_shift_n = 59
151
152
 
152
153
  racc_token_table = {
153
154
  false => 0,
@@ -420,30 +421,30 @@ module_eval(<<'.,.,', 'bibtex.y', 71)
420
421
  end
421
422
  .,.,
422
423
 
423
- module_eval(<<'.,.,', 'bibtex.y', 73)
424
+ module_eval(<<'.,.,', 'bibtex.y', 72)
424
425
  def _reduce_28(val, _values, result)
425
- result = val[0]
426
+ result = val[0,2].join
426
427
  result
427
428
  end
428
429
  .,.,
429
430
 
430
431
  module_eval(<<'.,.,', 'bibtex.y', 74)
431
432
  def _reduce_29(val, _values, result)
432
- result.merge!(val[2])
433
+ result = val[0]
433
434
  result
434
435
  end
435
436
  .,.,
436
437
 
437
- module_eval(<<'.,.,', 'bibtex.y', 76)
438
+ module_eval(<<'.,.,', 'bibtex.y', 75)
438
439
  def _reduce_30(val, _values, result)
439
- result = { val[0].downcase.to_sym => val[2] }
440
+ result.merge!(val[2])
440
441
  result
441
442
  end
442
443
  .,.,
443
444
 
444
- module_eval(<<'.,.,', 'bibtex.y', 78)
445
+ module_eval(<<'.,.,', 'bibtex.y', 77)
445
446
  def _reduce_31(val, _values, result)
446
- result = val[0]
447
+ result = { val[0].downcase.to_sym => val[2] }
447
448
  result
448
449
  end
449
450
  .,.,
@@ -457,6 +458,13 @@ module_eval(<<'.,.,', 'bibtex.y', 79)
457
458
 
458
459
  module_eval(<<'.,.,', 'bibtex.y', 80)
459
460
  def _reduce_33(val, _values, result)
461
+ result = val[0]
462
+ result
463
+ end
464
+ .,.,
465
+
466
+ module_eval(<<'.,.,', 'bibtex.y', 81)
467
+ def _reduce_34(val, _values, result)
460
468
  result = val[1]
461
469
  result
462
470
  end
@@ -18,6 +18,6 @@
18
18
 
19
19
  module BibTeX
20
20
  module Version
21
- STRING = '1.3.1'.freeze
21
+ STRING = '1.3.2'.freeze
22
22
  end
23
23
  end
@@ -9,6 +9,39 @@ module BibTeX
9
9
  end
10
10
  end
11
11
 
12
+ context 'month conversion' do
13
+ setup do
14
+ @entry = Entry.new
15
+ end
16
+
17
+ [[:jan,'January'], [:feb,'February'], [:sep,'September']].each do |m|
18
+ should 'convert english months' do
19
+ @entry.month = m[1]
20
+ assert_equal m[0], @entry.month.v
21
+ end
22
+ end
23
+
24
+ [[:jan,:jan], [:feb,:feb], [:sep,:sep]].each do |m|
25
+ should 'convert bibtex abbreviations' do
26
+ @entry.month = m[1]
27
+ assert_equal m[0], @entry.month.v
28
+ end
29
+ end
30
+
31
+ [[:jan,1], [:feb,2], [:sep,9]].each do |m|
32
+ should 'convert numbers' do
33
+ @entry.month = m[1]
34
+ assert_equal m[0], @entry.month.v
35
+ end
36
+ should 'convert numbers when parsing' do
37
+ @entry = Entry.parse("@misc{id, month = #{m[1]}}")[0]
38
+ assert_equal m[0], @entry.month.v
39
+ end
40
+ end
41
+
42
+ end
43
+
44
+
12
45
  context 'given an entry' do
13
46
  setup do
14
47
  @entry = Entry.new do |e|
@@ -18,6 +51,7 @@ module BibTeX
18
51
  e.author = 'Herman Melville'
19
52
  e.publisher = 'Penguin'
20
53
  e.address = 'New York'
54
+ e.month = 'Nov'
21
55
  e.year = 1993
22
56
  e.parse_names
23
57
  end
@@ -33,7 +67,7 @@ module BibTeX
33
67
  e = @entry.to_citeproc
34
68
  assert_equal 'book', e['type']
35
69
  assert_equal 'New York', e['publisher-place']
36
- assert_equal [1993], e['issued']['date-parts'][0]
70
+ assert_equal [1993,11], e['issued']['date-parts'][0]
37
71
  assert_equal 1, e['author'].length
38
72
  assert_equal 'Herman', e['author'][0]['given']
39
73
  assert_equal 'Melville', e['author'][0]['family']
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: bibtex-ruby
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.3.1
5
+ version: 1.3.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Sylvester Keil
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-05-14 00:00:00 +02:00
13
+ date: 2011-05-21 00:00:00 +02:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -102,6 +102,8 @@ files:
102
102
  - examples/markdown.bib
103
103
  - features/bibtex.feature
104
104
  - features/entries.feature
105
+ - features/issues/number_keys.feature
106
+ - features/issues/parse_months.feature
105
107
  - features/issues/slash_keys.feature
106
108
  - features/names.feature
107
109
  - features/preambles.feature