bibtex-ruby 1.2.1 → 1.3.0
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 +6 -1
- data/Gemfile.lock +48 -5
- data/History.txt +16 -1
- data/Manifest +43 -19
- data/README.md +178 -167
- data/Rakefile +26 -5
- data/auto.watchr +6 -0
- data/bibtex-ruby.gemspec +8 -5
- data/examples/bib2html.rb +28 -18
- data/features/bibtex.feature +96 -0
- data/features/entries.feature +67 -0
- data/features/issues/slash_keys.feature +21 -0
- data/features/names.feature +72 -0
- data/features/preambles.feature +27 -0
- data/features/query.feature +56 -0
- data/features/replacement.feature +68 -0
- data/features/step_definitions/bibtex_steps.rb +74 -0
- data/features/step_definitions/name_steps.rb +13 -0
- data/features/strings.feature +52 -0
- data/features/support/env.rb +7 -0
- data/lib/bibtex.rb +5 -1
- data/lib/bibtex/bibliography.rb +218 -95
- data/lib/bibtex/bibtex.y +18 -15
- data/lib/bibtex/elements.rb +130 -136
- data/lib/bibtex/entry.rb +133 -69
- data/lib/bibtex/extensions.rb +0 -35
- data/lib/bibtex/lexer.rb +9 -9
- data/lib/bibtex/name_parser.output +464 -0
- data/lib/bibtex/name_parser.rb +490 -0
- data/lib/bibtex/names.rb +162 -0
- data/lib/bibtex/names.y +196 -0
- data/lib/bibtex/parser.output +5 -5
- data/lib/bibtex/parser.rb +19 -16
- data/lib/bibtex/replaceable.rb +52 -0
- data/lib/bibtex/utilities.rb +23 -5
- data/lib/bibtex/value.rb +201 -0
- data/lib/bibtex/version.rb +1 -1
- data/test/benchmark.rb +52 -0
- data/test/bibtex/test_bibliography.rb +141 -0
- data/test/bibtex/test_elements.rb +40 -0
- data/test/bibtex/test_entry.rb +99 -0
- data/test/bibtex/test_names.rb +23 -0
- data/test/bibtex/test_parser.rb +79 -0
- data/test/bibtex/test_string.rb +83 -0
- data/test/bibtex/test_utilities.rb +34 -0
- data/test/bibtex/test_value.rb +70 -0
- data/test/{bib/10_bibdesk.bib → fixtures/bibdesk.bib} +1 -1
- data/test/{bib/05_comment.bib → fixtures/comment.bib} +0 -0
- data/test/{bib/08_decoret.bib → fixtures/decoret.bib} +0 -0
- data/test/{bib/00_empty.bib → fixtures/empty.bib} +0 -0
- data/test/{bib/07_entry.bib → fixtures/entry.bib} +0 -0
- data/test/{bib/09_errors.bib → fixtures/errors.bib} +0 -0
- data/test/{bib/01_no_bibtex.bib → fixtures/no_bibtex.bib} +0 -0
- data/test/{bib/06_preamble.bib → fixtures/preamble.bib} +1 -1
- data/test/{bib/11_roundtrip.bib → fixtures/roundtrip.bib} +1 -1
- data/test/helper.rb +17 -2
- data/test/test_bibtex.rb +87 -93
- data/test/test_export.rb +18 -22
- metadata +85 -30
- data/test/bib/02_string.bib +0 -1
- data/test/bib/03_string.bib +0 -25
- data/test/bib/04_string_replacement.bib +0 -16
- data/test/test_comment.rb +0 -21
- data/test/test_entry.rb +0 -98
- data/test/test_preamble.rb +0 -39
- data/test/test_string.rb +0 -97
- data/test/test_utilities.rb +0 -36
@@ -0,0 +1,490 @@
|
|
1
|
+
#
|
2
|
+
# DO NOT MODIFY!!!!
|
3
|
+
# This file is automatically generated by Racc 1.4.6
|
4
|
+
# from Racc grammer file "".
|
5
|
+
#
|
6
|
+
|
7
|
+
require 'racc/parser.rb'
|
8
|
+
|
9
|
+
require 'strscan'
|
10
|
+
|
11
|
+
module BibTeX
|
12
|
+
class NameParser < Racc::Parser
|
13
|
+
|
14
|
+
module_eval(<<'...end names.y/module_eval...', 'names.y', 80)
|
15
|
+
|
16
|
+
def initialize(options = {})
|
17
|
+
self.options.merge!(options)
|
18
|
+
end
|
19
|
+
|
20
|
+
def options
|
21
|
+
@options ||= { :debug => ENV['DEBUG'] == true }
|
22
|
+
end
|
23
|
+
|
24
|
+
def parse(input)
|
25
|
+
@yydebug = options[:debug]
|
26
|
+
scan(input)
|
27
|
+
do_parse
|
28
|
+
end
|
29
|
+
|
30
|
+
def next_token
|
31
|
+
@stack.shift
|
32
|
+
end
|
33
|
+
|
34
|
+
def on_error(tid, val, vstack)
|
35
|
+
BibTeX.log.error("Failed to parse BibTeX Name on value %s (%s) %s" % [val.inspect, token_to_str(tid) || '?', vstack.inspect])
|
36
|
+
end
|
37
|
+
|
38
|
+
def scan(input)
|
39
|
+
@src = StringScanner.new(input)
|
40
|
+
@brace_level = 0
|
41
|
+
@stack = []
|
42
|
+
@word = [:PWORD,'']
|
43
|
+
do_scan
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def do_scan
|
49
|
+
until @src.eos?
|
50
|
+
case
|
51
|
+
when @src.scan(/,?\s+and\s+/io)
|
52
|
+
push_word
|
53
|
+
@stack.push([:AND,@src.matched])
|
54
|
+
|
55
|
+
when @src.scan(/[\t\r\n\s]+/o)
|
56
|
+
push_word
|
57
|
+
|
58
|
+
when @src.scan(/,/o)
|
59
|
+
push_word
|
60
|
+
@stack.push([:COMMA,@src.matched])
|
61
|
+
|
62
|
+
when @src.scan(/[[:lower:]][^\t\r\n\s\{\}\d\\,]*/o)
|
63
|
+
is_lowercase
|
64
|
+
@word[1] << @src.matched
|
65
|
+
|
66
|
+
when @src.scan(/[[:upper:]][^\t\r\n\s\{\}\d\\,]*/o)
|
67
|
+
is_uppercase
|
68
|
+
@word[1] << @src.matched
|
69
|
+
|
70
|
+
when @src.scan(/(\d|\\.)+/o)
|
71
|
+
@word[1] << @src.matched
|
72
|
+
|
73
|
+
when @src.scan(/\{/o)
|
74
|
+
scan_literal(@src.matched)
|
75
|
+
|
76
|
+
when @src.scan(/\}/o)
|
77
|
+
error_unbalanced
|
78
|
+
|
79
|
+
when @src.scan(/./o)
|
80
|
+
@word[1] << @src.matched
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
push_word
|
85
|
+
@stack
|
86
|
+
end
|
87
|
+
|
88
|
+
def push_word
|
89
|
+
unless @word[1].empty?
|
90
|
+
@stack.push(@word)
|
91
|
+
@word = [:PWORD,'']
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def is_lowercase
|
96
|
+
@word[0] = :LWORD if @word[0] == :PWORD
|
97
|
+
end
|
98
|
+
|
99
|
+
def is_uppercase
|
100
|
+
@word[0] = :UWORD if @word[0] == :PWORD
|
101
|
+
end
|
102
|
+
|
103
|
+
def scan_literal(content = '')
|
104
|
+
@brace_level += 1
|
105
|
+
content << @src.scan_until(/[^\\][\{\}]/o).to_s # TODO accept empty braces {}
|
106
|
+
case @src.matched
|
107
|
+
when /\{/
|
108
|
+
scan_braced_expression(content)
|
109
|
+
when /\}/
|
110
|
+
@brace_level -= 1
|
111
|
+
if @brace_level >= 0
|
112
|
+
@word[1] << content
|
113
|
+
else
|
114
|
+
error_unbalanced
|
115
|
+
end
|
116
|
+
else
|
117
|
+
error_unbalanced
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def error_unexpected
|
122
|
+
@stack.push [:ERROR,@src.matched]
|
123
|
+
BibTeX.log.warn("NameParser: unexpected token `#{@src.matched}' at position #{@src.pos}; brace level #{@brace_level}.")
|
124
|
+
end
|
125
|
+
|
126
|
+
def error_unbalanced
|
127
|
+
@stack.push [:ERROR,'}']
|
128
|
+
BibTeX.log.warn("NameParser: unbalanced braces at position #{@src.pos}; brace level #{@brace_level}.")
|
129
|
+
end
|
130
|
+
|
131
|
+
# -*- racc -*-
|
132
|
+
...end names.y/module_eval...
|
133
|
+
##### State transition tables begin ###
|
134
|
+
|
135
|
+
racc_action_table = [
|
136
|
+
-13, -28, -10, -13, -30, 24, -13, -28, -29, -13,
|
137
|
+
-30, -28, 19, -9, -29, 36, 14, -28, -11, 22,
|
138
|
+
35, 23, 22, 20, 23, 11, 18, 12, 33, 32,
|
139
|
+
34, 22, 35, 23, 22, 26, 23, 33, 32, 34,
|
140
|
+
33, 32, 34, 11, 7, 12, 11, 7, 12, 13 ]
|
141
|
+
|
142
|
+
racc_action_check = [
|
143
|
+
20, 18, 20, 26, 12, 13, 20, 18, 11, 26,
|
144
|
+
12, 7, 6, 7, 11, 29, 2, 7, 21, 21,
|
145
|
+
21, 21, 8, 8, 8, 5, 5, 5, 31, 31,
|
146
|
+
31, 27, 27, 27, 16, 16, 16, 36, 36, 36,
|
147
|
+
19, 19, 19, 0, 0, 0, 14, 14, 14, 1 ]
|
148
|
+
|
149
|
+
racc_action_pointer = [
|
150
|
+
40, 49, 10, nil, nil, 22, 10, 11, 19, nil,
|
151
|
+
nil, 8, 4, 5, 43, nil, 31, nil, 1, 37,
|
152
|
+
0, 16, nil, nil, nil, nil, 3, 28, nil, 13,
|
153
|
+
nil, 25, nil, nil, nil, nil, 34, nil, nil ]
|
154
|
+
|
155
|
+
racc_action_default = [
|
156
|
+
-1, -31, -2, -3, -5, -8, -31, -21, -31, -12,
|
157
|
+
-17, -19, -20, -31, -31, -6, -31, -18, -21, -26,
|
158
|
+
-23, -14, -19, -20, 39, -4, -23, -14, -7, -15,
|
159
|
+
-24, -27, -28, -29, -30, -22, -26, -25, -16 ]
|
160
|
+
|
161
|
+
racc_goto_table = [
|
162
|
+
17, 29, 30, 3, 21, 28, 16, 15, 2, 1,
|
163
|
+
nil, nil, 27, nil, 37, nil, 17, 25, 38, 30,
|
164
|
+
nil, nil, 17 ]
|
165
|
+
|
166
|
+
racc_goto_check = [
|
167
|
+
11, 10, 9, 3, 5, 7, 8, 4, 2, 1,
|
168
|
+
nil, nil, 5, nil, 9, nil, 11, 3, 10, 9,
|
169
|
+
nil, nil, 11 ]
|
170
|
+
|
171
|
+
racc_goto_pointer = [
|
172
|
+
nil, 9, 8, 3, 2, -4, nil, -14, 1, -17,
|
173
|
+
-18, -5, nil ]
|
174
|
+
|
175
|
+
racc_goto_default = [
|
176
|
+
nil, nil, nil, nil, 4, 5, 6, nil, 8, 9,
|
177
|
+
nil, 10, 31 ]
|
178
|
+
|
179
|
+
racc_reduce_table = [
|
180
|
+
0, 0, :racc_error,
|
181
|
+
0, 9, :_reduce_1,
|
182
|
+
1, 9, :_reduce_2,
|
183
|
+
1, 10, :_reduce_3,
|
184
|
+
3, 10, :_reduce_4,
|
185
|
+
1, 11, :_reduce_5,
|
186
|
+
2, 11, :_reduce_6,
|
187
|
+
3, 11, :_reduce_7,
|
188
|
+
1, 14, :_reduce_8,
|
189
|
+
1, 14, :_reduce_9,
|
190
|
+
2, 14, :_reduce_10,
|
191
|
+
2, 14, :_reduce_11,
|
192
|
+
1, 12, :_reduce_12,
|
193
|
+
2, 12, :_reduce_13,
|
194
|
+
2, 12, :_reduce_14,
|
195
|
+
1, 15, :_reduce_15,
|
196
|
+
3, 15, :_reduce_16,
|
197
|
+
1, 13, :_reduce_17,
|
198
|
+
2, 13, :_reduce_18,
|
199
|
+
1, 19, :_reduce_19,
|
200
|
+
1, 19, :_reduce_20,
|
201
|
+
1, 16, :_reduce_21,
|
202
|
+
3, 16, :_reduce_22,
|
203
|
+
2, 16, :_reduce_23,
|
204
|
+
1, 20, :_reduce_24,
|
205
|
+
2, 20, :_reduce_25,
|
206
|
+
0, 18, :_reduce_26,
|
207
|
+
1, 18, :_reduce_27,
|
208
|
+
1, 17, :_reduce_28,
|
209
|
+
1, 17, :_reduce_29,
|
210
|
+
1, 17, :_reduce_30 ]
|
211
|
+
|
212
|
+
racc_reduce_n = 31
|
213
|
+
|
214
|
+
racc_shift_n = 39
|
215
|
+
|
216
|
+
racc_token_table = {
|
217
|
+
false => 0,
|
218
|
+
:error => 1,
|
219
|
+
:COMMA => 2,
|
220
|
+
:UWORD => 3,
|
221
|
+
:LWORD => 4,
|
222
|
+
:PWORD => 5,
|
223
|
+
:AND => 6,
|
224
|
+
:ERROR => 7 }
|
225
|
+
|
226
|
+
racc_nt_base = 8
|
227
|
+
|
228
|
+
racc_use_result_var = true
|
229
|
+
|
230
|
+
Racc_arg = [
|
231
|
+
racc_action_table,
|
232
|
+
racc_action_check,
|
233
|
+
racc_action_default,
|
234
|
+
racc_action_pointer,
|
235
|
+
racc_goto_table,
|
236
|
+
racc_goto_check,
|
237
|
+
racc_goto_default,
|
238
|
+
racc_goto_pointer,
|
239
|
+
racc_nt_base,
|
240
|
+
racc_reduce_table,
|
241
|
+
racc_token_table,
|
242
|
+
racc_shift_n,
|
243
|
+
racc_reduce_n,
|
244
|
+
racc_use_result_var ]
|
245
|
+
|
246
|
+
Racc_token_to_s_table = [
|
247
|
+
"$end",
|
248
|
+
"error",
|
249
|
+
"COMMA",
|
250
|
+
"UWORD",
|
251
|
+
"LWORD",
|
252
|
+
"PWORD",
|
253
|
+
"AND",
|
254
|
+
"ERROR",
|
255
|
+
"$start",
|
256
|
+
"result",
|
257
|
+
"names",
|
258
|
+
"name",
|
259
|
+
"last",
|
260
|
+
"u_words",
|
261
|
+
"sort",
|
262
|
+
"first",
|
263
|
+
"von",
|
264
|
+
"word",
|
265
|
+
"opt_words",
|
266
|
+
"u_word",
|
267
|
+
"words" ]
|
268
|
+
|
269
|
+
Racc_debug_parser = false
|
270
|
+
|
271
|
+
##### State transition tables end #####
|
272
|
+
|
273
|
+
# reduce 0 omitted
|
274
|
+
|
275
|
+
module_eval(<<'.,.,', 'names.y', 31)
|
276
|
+
def _reduce_1(val, _values, result)
|
277
|
+
result = []
|
278
|
+
result
|
279
|
+
end
|
280
|
+
.,.,
|
281
|
+
|
282
|
+
module_eval(<<'.,.,', 'names.y', 32)
|
283
|
+
def _reduce_2(val, _values, result)
|
284
|
+
result = val[0]
|
285
|
+
result
|
286
|
+
end
|
287
|
+
.,.,
|
288
|
+
|
289
|
+
module_eval(<<'.,.,', 'names.y', 34)
|
290
|
+
def _reduce_3(val, _values, result)
|
291
|
+
result = [val[0]]
|
292
|
+
result
|
293
|
+
end
|
294
|
+
.,.,
|
295
|
+
|
296
|
+
module_eval(<<'.,.,', 'names.y', 35)
|
297
|
+
def _reduce_4(val, _values, result)
|
298
|
+
result << val[2]
|
299
|
+
result
|
300
|
+
end
|
301
|
+
.,.,
|
302
|
+
|
303
|
+
module_eval(<<'.,.,', 'names.y', 37)
|
304
|
+
def _reduce_5(val, _values, result)
|
305
|
+
result = Name.new(:von => val[0][0], :last => val[0][1])
|
306
|
+
result
|
307
|
+
end
|
308
|
+
.,.,
|
309
|
+
|
310
|
+
module_eval(<<'.,.,', 'names.y', 38)
|
311
|
+
def _reduce_6(val, _values, result)
|
312
|
+
result = Name.new(:first => val[0], :von => val[1][0], :last => val[1][1])
|
313
|
+
result
|
314
|
+
end
|
315
|
+
.,.,
|
316
|
+
|
317
|
+
module_eval(<<'.,.,', 'names.y', 39)
|
318
|
+
def _reduce_7(val, _values, result)
|
319
|
+
result = Name.new(:von => val[0][0], :last => val[0][1], :jr => val[2][0], :first => val[2][1])
|
320
|
+
result
|
321
|
+
end
|
322
|
+
.,.,
|
323
|
+
|
324
|
+
module_eval(<<'.,.,', 'names.y', 41)
|
325
|
+
def _reduce_8(val, _values, result)
|
326
|
+
result = [nil,val[0]]
|
327
|
+
result
|
328
|
+
end
|
329
|
+
.,.,
|
330
|
+
|
331
|
+
module_eval(<<'.,.,', 'names.y', 42)
|
332
|
+
def _reduce_9(val, _values, result)
|
333
|
+
result = [nil,val[0]]
|
334
|
+
result
|
335
|
+
end
|
336
|
+
.,.,
|
337
|
+
|
338
|
+
module_eval(<<'.,.,', 'names.y', 43)
|
339
|
+
def _reduce_10(val, _values, result)
|
340
|
+
result = [val[0],val[1]]
|
341
|
+
result
|
342
|
+
end
|
343
|
+
.,.,
|
344
|
+
|
345
|
+
module_eval(<<'.,.,', 'names.y', 44)
|
346
|
+
def _reduce_11(val, _values, result)
|
347
|
+
result = [val[0],val[1]]
|
348
|
+
result
|
349
|
+
end
|
350
|
+
.,.,
|
351
|
+
|
352
|
+
module_eval(<<'.,.,', 'names.y', 46)
|
353
|
+
def _reduce_12(val, _values, result)
|
354
|
+
result = [nil,val[0]]
|
355
|
+
result
|
356
|
+
end
|
357
|
+
.,.,
|
358
|
+
|
359
|
+
module_eval(<<'.,.,', 'names.y', 47)
|
360
|
+
def _reduce_13(val, _values, result)
|
361
|
+
result = [val[0],val[1]]
|
362
|
+
result
|
363
|
+
end
|
364
|
+
.,.,
|
365
|
+
|
366
|
+
module_eval(<<'.,.,', 'names.y', 48)
|
367
|
+
def _reduce_14(val, _values, result)
|
368
|
+
result = [val[0],val[1]]
|
369
|
+
result
|
370
|
+
end
|
371
|
+
.,.,
|
372
|
+
|
373
|
+
module_eval(<<'.,.,', 'names.y', 50)
|
374
|
+
def _reduce_15(val, _values, result)
|
375
|
+
result = [nil,val[0]]
|
376
|
+
result
|
377
|
+
end
|
378
|
+
.,.,
|
379
|
+
|
380
|
+
module_eval(<<'.,.,', 'names.y', 51)
|
381
|
+
def _reduce_16(val, _values, result)
|
382
|
+
result = [val[0],val[2]]
|
383
|
+
result
|
384
|
+
end
|
385
|
+
.,.,
|
386
|
+
|
387
|
+
module_eval(<<'.,.,', 'names.y', 53)
|
388
|
+
def _reduce_17(val, _values, result)
|
389
|
+
result = val[0]
|
390
|
+
result
|
391
|
+
end
|
392
|
+
.,.,
|
393
|
+
|
394
|
+
module_eval(<<'.,.,', 'names.y', 54)
|
395
|
+
def _reduce_18(val, _values, result)
|
396
|
+
result = val[0,2].join(' ')
|
397
|
+
result
|
398
|
+
end
|
399
|
+
.,.,
|
400
|
+
|
401
|
+
module_eval(<<'.,.,', 'names.y', 56)
|
402
|
+
def _reduce_19(val, _values, result)
|
403
|
+
result = val[0]
|
404
|
+
result
|
405
|
+
end
|
406
|
+
.,.,
|
407
|
+
|
408
|
+
module_eval(<<'.,.,', 'names.y', 57)
|
409
|
+
def _reduce_20(val, _values, result)
|
410
|
+
result = val[0]
|
411
|
+
result
|
412
|
+
end
|
413
|
+
.,.,
|
414
|
+
|
415
|
+
module_eval(<<'.,.,', 'names.y', 59)
|
416
|
+
def _reduce_21(val, _values, result)
|
417
|
+
result = val[0]
|
418
|
+
result
|
419
|
+
end
|
420
|
+
.,.,
|
421
|
+
|
422
|
+
module_eval(<<'.,.,', 'names.y', 60)
|
423
|
+
def _reduce_22(val, _values, result)
|
424
|
+
result = val[0,3].join(' ')
|
425
|
+
result
|
426
|
+
end
|
427
|
+
.,.,
|
428
|
+
|
429
|
+
module_eval(<<'.,.,', 'names.y', 61)
|
430
|
+
def _reduce_23(val, _values, result)
|
431
|
+
result = val[0,2].join(' ')
|
432
|
+
result
|
433
|
+
end
|
434
|
+
.,.,
|
435
|
+
|
436
|
+
module_eval(<<'.,.,', 'names.y', 63)
|
437
|
+
def _reduce_24(val, _values, result)
|
438
|
+
result = val[0]
|
439
|
+
result
|
440
|
+
end
|
441
|
+
.,.,
|
442
|
+
|
443
|
+
module_eval(<<'.,.,', 'names.y', 64)
|
444
|
+
def _reduce_25(val, _values, result)
|
445
|
+
result = val[0,2].join(' ')
|
446
|
+
result
|
447
|
+
end
|
448
|
+
.,.,
|
449
|
+
|
450
|
+
module_eval(<<'.,.,', 'names.y', 66)
|
451
|
+
def _reduce_26(val, _values, result)
|
452
|
+
result = nil
|
453
|
+
result
|
454
|
+
end
|
455
|
+
.,.,
|
456
|
+
|
457
|
+
module_eval(<<'.,.,', 'names.y', 67)
|
458
|
+
def _reduce_27(val, _values, result)
|
459
|
+
result = val[0]
|
460
|
+
result
|
461
|
+
end
|
462
|
+
.,.,
|
463
|
+
|
464
|
+
module_eval(<<'.,.,', 'names.y', 69)
|
465
|
+
def _reduce_28(val, _values, result)
|
466
|
+
result = val[0]
|
467
|
+
result
|
468
|
+
end
|
469
|
+
.,.,
|
470
|
+
|
471
|
+
module_eval(<<'.,.,', 'names.y', 70)
|
472
|
+
def _reduce_29(val, _values, result)
|
473
|
+
result = val[0]
|
474
|
+
result
|
475
|
+
end
|
476
|
+
.,.,
|
477
|
+
|
478
|
+
module_eval(<<'.,.,', 'names.y', 71)
|
479
|
+
def _reduce_30(val, _values, result)
|
480
|
+
result = val[0]
|
481
|
+
result
|
482
|
+
end
|
483
|
+
.,.,
|
484
|
+
|
485
|
+
def _reduce_none(val, _values, result)
|
486
|
+
val[0]
|
487
|
+
end
|
488
|
+
|
489
|
+
end # class NameParser
|
490
|
+
end # module BibTeX
|