stud 0.0.13 → 0.0.14
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/LICENSE +14 -0
- data/lib/stud/buffer.rb +13 -13
- data/lib/stud/temporary.rb +47 -0
- data/lib/stud/time.rb +37 -0
- data/lib/stud/time/format.rb +1323 -0
- data/lib/stud/time/format.tt +236 -0
- data/lib/stud/with.rb +22 -0
- metadata +29 -25
data/LICENSE
CHANGED
@@ -0,0 +1,14 @@
|
|
1
|
+
Copyright 2012-2013 Jordan Sissel and contributors.
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
14
|
+
|
data/lib/stud/buffer.rb
CHANGED
@@ -3,12 +3,12 @@ module Stud
|
|
3
3
|
# @author {Alex Dean}[http://github.com/alexdean]
|
4
4
|
#
|
5
5
|
# Implements a generic framework for accepting events which are later flushed
|
6
|
-
# in batches. Flushing
|
6
|
+
# in batches. Flushing occurs whenever +:max_items+ or +:max_interval+ (seconds)
|
7
7
|
# has been reached.
|
8
8
|
#
|
9
|
-
# Including class must implement +flush+, which will be called with all
|
10
|
-
# items either when the output buffer fills (+:max_items+) or
|
11
|
-
# of time (+:max_interval+) passes.
|
9
|
+
# Including class must implement +flush+, which will be called with all
|
10
|
+
# accumulated items either when the output buffer fills (+:max_items+) or
|
11
|
+
# when a fixed amount of time (+:max_interval+) passes.
|
12
12
|
#
|
13
13
|
# == batch_receive and flush
|
14
14
|
# General receive/flush can be implemented in one of two ways.
|
@@ -59,9 +59,9 @@ module Stud
|
|
59
59
|
# the moment.
|
60
60
|
#
|
61
61
|
# == final flush
|
62
|
-
# Including class should call <code>buffer_flush(:final => true)</code>
|
63
|
-
# shutdown routine (after the last call to buffer_receive)
|
64
|
-
# accumulated messages are flushed.
|
62
|
+
# Including class should call <code>buffer_flush(:final => true)</code>
|
63
|
+
# during a teardown/shutdown routine (after the last call to buffer_receive)
|
64
|
+
# to ensure that all accumulated messages are flushed.
|
65
65
|
module Buffer
|
66
66
|
|
67
67
|
public
|
@@ -105,7 +105,7 @@ module Stud
|
|
105
105
|
:flush_mutex => Mutex.new,
|
106
106
|
|
107
107
|
# data for timed flushes
|
108
|
-
:last_flush => Time.now
|
108
|
+
:last_flush => Time.now,
|
109
109
|
:timer => Thread.new do
|
110
110
|
loop do
|
111
111
|
sleep(@buffer_config[:max_interval])
|
@@ -191,7 +191,7 @@ module Stud
|
|
191
191
|
items_flushed = 0
|
192
192
|
|
193
193
|
begin
|
194
|
-
time_since_last_flush = Time.now
|
194
|
+
time_since_last_flush = (Time.now - @buffer_state[:last_flush])
|
195
195
|
|
196
196
|
return 0 if @buffer_state[:pending_count] == 0
|
197
197
|
return 0 if (!force) &&
|
@@ -216,9 +216,9 @@ module Stud
|
|
216
216
|
@buffer_state[:outgoing_items].each do |group, events|
|
217
217
|
begin
|
218
218
|
if group.nil?
|
219
|
-
flush(events)
|
219
|
+
flush(events,final)
|
220
220
|
else
|
221
|
-
flush(events, group)
|
221
|
+
flush(events, group, final)
|
222
222
|
end
|
223
223
|
|
224
224
|
@buffer_state[:outgoing_items].delete(group)
|
@@ -241,14 +241,14 @@ module Stud
|
|
241
241
|
sleep 1
|
242
242
|
retry
|
243
243
|
end
|
244
|
-
@buffer_state[:last_flush] = Time.now
|
244
|
+
@buffer_state[:last_flush] = Time.now
|
245
245
|
end
|
246
246
|
|
247
247
|
ensure
|
248
248
|
@buffer_state[:flush_mutex].unlock
|
249
249
|
end
|
250
250
|
|
251
|
-
items_flushed
|
251
|
+
return items_flushed
|
252
252
|
end
|
253
253
|
|
254
254
|
private
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require "securerandom" # for uuid generation
|
2
|
+
require "fileutils"
|
3
|
+
|
4
|
+
module Stud
|
5
|
+
module Temporary
|
6
|
+
# Returns a string for a randomly-generated temporary path.
|
7
|
+
#
|
8
|
+
# This does not create any files.
|
9
|
+
def pathname(prefix="")
|
10
|
+
root = ENV["TMP"] || ENV["TMPDIR"] || ENV["TEMP"] || "/tmp"
|
11
|
+
return File.join(root, "#{prefix}-#{SecureRandom.uuid}")
|
12
|
+
end
|
13
|
+
|
14
|
+
# Return a File handle to a randomly-generated path.
|
15
|
+
#
|
16
|
+
# Any arguments beyond the first (prefix) argument will be
|
17
|
+
# given to File.new.
|
18
|
+
#
|
19
|
+
# If no file args are given, the default file mode is "w+"
|
20
|
+
def file(prefix="", *args, &block)
|
21
|
+
args << "w+" if args.empty?
|
22
|
+
return File.new(pathname(prefix), *args)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Make a temporary directory.
|
26
|
+
#
|
27
|
+
# If given a block, the directory path is given to the block. WHen the
|
28
|
+
# block finishes, the directory and all its contents will be deleted.
|
29
|
+
#
|
30
|
+
# If no block given, it will return the path to a newly created directory.
|
31
|
+
# You are responsible for then cleaning up.
|
32
|
+
def directory(prefix="", &block)
|
33
|
+
path = pathname(prefix)
|
34
|
+
Dir.mkdir(path)
|
35
|
+
|
36
|
+
if block_given?
|
37
|
+
block.call(path)
|
38
|
+
FileUtils.rm_r(path)
|
39
|
+
else
|
40
|
+
return path
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end # module Temporary
|
44
|
+
|
45
|
+
extend self
|
46
|
+
end # module Stud
|
47
|
+
|
data/lib/stud/time.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
module Stud
|
2
|
+
module Time
|
3
|
+
# The following table is copied from joda-time's docs
|
4
|
+
# http://joda-time.sourceforge.net/apidocs/org/joda/time/format/DateTimeFormat.html
|
5
|
+
# Symbol Meaning Presentation Examples
|
6
|
+
# ------ ------- ------------ -------
|
7
|
+
# G era text AD
|
8
|
+
# C century of era (>=0) number 20
|
9
|
+
# Y year of era (>=0) year 1996
|
10
|
+
|
11
|
+
# x weekyear year 1996
|
12
|
+
# w week of weekyear number 27
|
13
|
+
# e day of week number 2
|
14
|
+
# E day of week text Tuesday; Tue
|
15
|
+
|
16
|
+
# y year year 1996
|
17
|
+
# D day of year number 189
|
18
|
+
# M month of year month July; Jul; 07
|
19
|
+
# d day of month number 10
|
20
|
+
|
21
|
+
# a halfday of day text PM
|
22
|
+
# K hour of halfday (0~11) number 0
|
23
|
+
# h clockhour of halfday (1~12) number 12
|
24
|
+
|
25
|
+
# H hour of day (0~23) number 0
|
26
|
+
# k clockhour of day (1~24) number 24
|
27
|
+
# m minute of hour number 30
|
28
|
+
# s second of minute number 55
|
29
|
+
# S fraction of second number 978
|
30
|
+
|
31
|
+
# z time zone text Pacific Standard Time; PST
|
32
|
+
# Z time zone offset/id zone -0800; -08:00; America/Los_Angeles
|
33
|
+
|
34
|
+
# ' escape for text delimiter
|
35
|
+
# '' single quote literal '
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,1323 @@
|
|
1
|
+
# Autogenerated from a Treetop grammar. Edits may be lost.
|
2
|
+
|
3
|
+
|
4
|
+
module StudTimeFormat
|
5
|
+
include Treetop::Runtime
|
6
|
+
|
7
|
+
def root
|
8
|
+
@root ||= :format
|
9
|
+
end
|
10
|
+
|
11
|
+
module Format0
|
12
|
+
def compile
|
13
|
+
return %Q<lambda do |t|
|
14
|
+
return [
|
15
|
+
#{elements.collect(&:compile).join(",\n ")}
|
16
|
+
].join("")
|
17
|
+
end>
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def _nt_format
|
22
|
+
start_index = index
|
23
|
+
if node_cache[:format].has_key?(index)
|
24
|
+
cached = node_cache[:format][index]
|
25
|
+
if cached
|
26
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
27
|
+
@index = cached.interval.end
|
28
|
+
end
|
29
|
+
return cached
|
30
|
+
end
|
31
|
+
|
32
|
+
s0, i0 = [], index
|
33
|
+
loop do
|
34
|
+
i1 = index
|
35
|
+
r2 = _nt_time
|
36
|
+
if r2
|
37
|
+
r1 = r2
|
38
|
+
else
|
39
|
+
r3 = _nt_text
|
40
|
+
if r3
|
41
|
+
r1 = r3
|
42
|
+
else
|
43
|
+
@index = i1
|
44
|
+
r1 = nil
|
45
|
+
end
|
46
|
+
end
|
47
|
+
if r1
|
48
|
+
s0 << r1
|
49
|
+
else
|
50
|
+
break
|
51
|
+
end
|
52
|
+
end
|
53
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
54
|
+
r0.extend(Format0)
|
55
|
+
|
56
|
+
node_cache[:format][start_index] = r0
|
57
|
+
|
58
|
+
r0
|
59
|
+
end
|
60
|
+
|
61
|
+
def _nt_time
|
62
|
+
start_index = index
|
63
|
+
if node_cache[:time].has_key?(index)
|
64
|
+
cached = node_cache[:time][index]
|
65
|
+
if cached
|
66
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
67
|
+
@index = cached.interval.end
|
68
|
+
end
|
69
|
+
return cached
|
70
|
+
end
|
71
|
+
|
72
|
+
i0 = index
|
73
|
+
r1 = _nt_era
|
74
|
+
if r1
|
75
|
+
r0 = r1
|
76
|
+
else
|
77
|
+
r2 = _nt_century_of_era
|
78
|
+
if r2
|
79
|
+
r0 = r2
|
80
|
+
else
|
81
|
+
r3 = _nt_year_of_era
|
82
|
+
if r3
|
83
|
+
r0 = r3
|
84
|
+
else
|
85
|
+
r4 = _nt_weekyear
|
86
|
+
if r4
|
87
|
+
r0 = r4
|
88
|
+
else
|
89
|
+
r5 = _nt_week_of_weekyear
|
90
|
+
if r5
|
91
|
+
r0 = r5
|
92
|
+
else
|
93
|
+
r6 = _nt_day_of_week_number
|
94
|
+
if r6
|
95
|
+
r0 = r6
|
96
|
+
else
|
97
|
+
r7 = _nt_day_of_week_text
|
98
|
+
if r7
|
99
|
+
r0 = r7
|
100
|
+
else
|
101
|
+
r8 = _nt_year
|
102
|
+
if r8
|
103
|
+
r0 = r8
|
104
|
+
else
|
105
|
+
r9 = _nt_day_of_year
|
106
|
+
if r9
|
107
|
+
r0 = r9
|
108
|
+
else
|
109
|
+
r10 = _nt_month_of_year
|
110
|
+
if r10
|
111
|
+
r0 = r10
|
112
|
+
else
|
113
|
+
r11 = _nt_day_of_month
|
114
|
+
if r11
|
115
|
+
r0 = r11
|
116
|
+
else
|
117
|
+
r12 = _nt_halfday_of_day
|
118
|
+
if r12
|
119
|
+
r0 = r12
|
120
|
+
else
|
121
|
+
r13 = _nt_hour_of_halfday
|
122
|
+
if r13
|
123
|
+
r0 = r13
|
124
|
+
else
|
125
|
+
r14 = _nt_clockhour_of_halfday
|
126
|
+
if r14
|
127
|
+
r0 = r14
|
128
|
+
else
|
129
|
+
r15 = _nt_hour_of_day
|
130
|
+
if r15
|
131
|
+
r0 = r15
|
132
|
+
else
|
133
|
+
r16 = _nt_clockhour_of_day
|
134
|
+
if r16
|
135
|
+
r0 = r16
|
136
|
+
else
|
137
|
+
r17 = _nt_minute_of_hour
|
138
|
+
if r17
|
139
|
+
r0 = r17
|
140
|
+
else
|
141
|
+
r18 = _nt_second_of_minute
|
142
|
+
if r18
|
143
|
+
r0 = r18
|
144
|
+
else
|
145
|
+
r19 = _nt_fraction_of_second
|
146
|
+
if r19
|
147
|
+
r0 = r19
|
148
|
+
else
|
149
|
+
r20 = _nt_time_zone_text
|
150
|
+
if r20
|
151
|
+
r0 = r20
|
152
|
+
else
|
153
|
+
r21 = _nt_time_zone_offset_or_id
|
154
|
+
if r21
|
155
|
+
r0 = r21
|
156
|
+
else
|
157
|
+
@index = i0
|
158
|
+
r0 = nil
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
node_cache[:time][start_index] = r0
|
182
|
+
|
183
|
+
r0
|
184
|
+
end
|
185
|
+
|
186
|
+
def _nt_text
|
187
|
+
start_index = index
|
188
|
+
if node_cache[:text].has_key?(index)
|
189
|
+
cached = node_cache[:text][index]
|
190
|
+
if cached
|
191
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
192
|
+
@index = cached.interval.end
|
193
|
+
end
|
194
|
+
return cached
|
195
|
+
end
|
196
|
+
|
197
|
+
i0 = index
|
198
|
+
r1 = _nt_string
|
199
|
+
if r1
|
200
|
+
r0 = r1
|
201
|
+
else
|
202
|
+
r2 = _nt_symbol
|
203
|
+
if r2
|
204
|
+
r0 = r2
|
205
|
+
else
|
206
|
+
@index = i0
|
207
|
+
r0 = nil
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
node_cache[:text][start_index] = r0
|
212
|
+
|
213
|
+
r0
|
214
|
+
end
|
215
|
+
|
216
|
+
module String0
|
217
|
+
def content
|
218
|
+
elements[1]
|
219
|
+
end
|
220
|
+
|
221
|
+
end
|
222
|
+
|
223
|
+
module String1
|
224
|
+
def compile
|
225
|
+
if content.text_value.length == 0
|
226
|
+
return %Q<"'">
|
227
|
+
else
|
228
|
+
return %Q<"#{content.text_value}">
|
229
|
+
end
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
def _nt_string
|
234
|
+
start_index = index
|
235
|
+
if node_cache[:string].has_key?(index)
|
236
|
+
cached = node_cache[:string][index]
|
237
|
+
if cached
|
238
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
239
|
+
@index = cached.interval.end
|
240
|
+
end
|
241
|
+
return cached
|
242
|
+
end
|
243
|
+
|
244
|
+
i0, s0 = index, []
|
245
|
+
if has_terminal?("'", false, index)
|
246
|
+
r1 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
247
|
+
@index += 1
|
248
|
+
else
|
249
|
+
terminal_parse_failure("'")
|
250
|
+
r1 = nil
|
251
|
+
end
|
252
|
+
s0 << r1
|
253
|
+
if r1
|
254
|
+
s2, i2 = [], index
|
255
|
+
loop do
|
256
|
+
if has_terminal?('\G[^\']', true, index)
|
257
|
+
r3 = true
|
258
|
+
@index += 1
|
259
|
+
else
|
260
|
+
r3 = nil
|
261
|
+
end
|
262
|
+
if r3
|
263
|
+
s2 << r3
|
264
|
+
else
|
265
|
+
break
|
266
|
+
end
|
267
|
+
end
|
268
|
+
r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
|
269
|
+
s0 << r2
|
270
|
+
if r2
|
271
|
+
if has_terminal?("'", false, index)
|
272
|
+
r4 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
273
|
+
@index += 1
|
274
|
+
else
|
275
|
+
terminal_parse_failure("'")
|
276
|
+
r4 = nil
|
277
|
+
end
|
278
|
+
s0 << r4
|
279
|
+
end
|
280
|
+
end
|
281
|
+
if s0.last
|
282
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
283
|
+
r0.extend(String0)
|
284
|
+
r0.extend(String1)
|
285
|
+
else
|
286
|
+
@index = i0
|
287
|
+
r0 = nil
|
288
|
+
end
|
289
|
+
|
290
|
+
node_cache[:string][start_index] = r0
|
291
|
+
|
292
|
+
r0
|
293
|
+
end
|
294
|
+
|
295
|
+
module Symbol0
|
296
|
+
def compile
|
297
|
+
return %<"#{text_value}">
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
def _nt_symbol
|
302
|
+
start_index = index
|
303
|
+
if node_cache[:symbol].has_key?(index)
|
304
|
+
cached = node_cache[:symbol][index]
|
305
|
+
if cached
|
306
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
307
|
+
@index = cached.interval.end
|
308
|
+
end
|
309
|
+
return cached
|
310
|
+
end
|
311
|
+
|
312
|
+
s0, i0 = [], index
|
313
|
+
loop do
|
314
|
+
if has_terminal?('\G[^A-Za-z\']', true, index)
|
315
|
+
r1 = true
|
316
|
+
@index += 1
|
317
|
+
else
|
318
|
+
r1 = nil
|
319
|
+
end
|
320
|
+
if r1
|
321
|
+
s0 << r1
|
322
|
+
else
|
323
|
+
break
|
324
|
+
end
|
325
|
+
end
|
326
|
+
if s0.empty?
|
327
|
+
@index = i0
|
328
|
+
r0 = nil
|
329
|
+
else
|
330
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
331
|
+
r0.extend(Symbol0)
|
332
|
+
end
|
333
|
+
|
334
|
+
node_cache[:symbol][start_index] = r0
|
335
|
+
|
336
|
+
r0
|
337
|
+
end
|
338
|
+
|
339
|
+
module QuoteChar0
|
340
|
+
def compile
|
341
|
+
return %Q("'")
|
342
|
+
end
|
343
|
+
end
|
344
|
+
|
345
|
+
def _nt_quote_char
|
346
|
+
start_index = index
|
347
|
+
if node_cache[:quote_char].has_key?(index)
|
348
|
+
cached = node_cache[:quote_char][index]
|
349
|
+
if cached
|
350
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
351
|
+
@index = cached.interval.end
|
352
|
+
end
|
353
|
+
return cached
|
354
|
+
end
|
355
|
+
|
356
|
+
if has_terminal?("''", false, index)
|
357
|
+
r0 = instantiate_node(SyntaxNode,input, index...(index + 2))
|
358
|
+
r0.extend(QuoteChar0)
|
359
|
+
@index += 2
|
360
|
+
else
|
361
|
+
terminal_parse_failure("''")
|
362
|
+
r0 = nil
|
363
|
+
end
|
364
|
+
|
365
|
+
node_cache[:quote_char][start_index] = r0
|
366
|
+
|
367
|
+
r0
|
368
|
+
end
|
369
|
+
|
370
|
+
def _nt_era
|
371
|
+
start_index = index
|
372
|
+
if node_cache[:era].has_key?(index)
|
373
|
+
cached = node_cache[:era][index]
|
374
|
+
if cached
|
375
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
376
|
+
@index = cached.interval.end
|
377
|
+
end
|
378
|
+
return cached
|
379
|
+
end
|
380
|
+
|
381
|
+
s0, i0 = [], index
|
382
|
+
loop do
|
383
|
+
if has_terminal?("G", false, index)
|
384
|
+
r1 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
385
|
+
@index += 1
|
386
|
+
else
|
387
|
+
terminal_parse_failure("G")
|
388
|
+
r1 = nil
|
389
|
+
end
|
390
|
+
if r1
|
391
|
+
s0 << r1
|
392
|
+
else
|
393
|
+
break
|
394
|
+
end
|
395
|
+
end
|
396
|
+
if s0.empty?
|
397
|
+
@index = i0
|
398
|
+
r0 = nil
|
399
|
+
else
|
400
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
401
|
+
end
|
402
|
+
|
403
|
+
node_cache[:era][start_index] = r0
|
404
|
+
|
405
|
+
r0
|
406
|
+
end
|
407
|
+
|
408
|
+
module CenturyOfEra0
|
409
|
+
def compile
|
410
|
+
# TODO(sissel): support eras? I don't really care myself.
|
411
|
+
return "AD"
|
412
|
+
end
|
413
|
+
end
|
414
|
+
|
415
|
+
def _nt_century_of_era
|
416
|
+
start_index = index
|
417
|
+
if node_cache[:century_of_era].has_key?(index)
|
418
|
+
cached = node_cache[:century_of_era][index]
|
419
|
+
if cached
|
420
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
421
|
+
@index = cached.interval.end
|
422
|
+
end
|
423
|
+
return cached
|
424
|
+
end
|
425
|
+
|
426
|
+
s0, i0 = [], index
|
427
|
+
loop do
|
428
|
+
if has_terminal?("C", false, index)
|
429
|
+
r1 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
430
|
+
@index += 1
|
431
|
+
else
|
432
|
+
terminal_parse_failure("C")
|
433
|
+
r1 = nil
|
434
|
+
end
|
435
|
+
if r1
|
436
|
+
s0 << r1
|
437
|
+
else
|
438
|
+
break
|
439
|
+
end
|
440
|
+
end
|
441
|
+
if s0.empty?
|
442
|
+
@index = i0
|
443
|
+
r0 = nil
|
444
|
+
else
|
445
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
446
|
+
r0.extend(CenturyOfEra0)
|
447
|
+
end
|
448
|
+
|
449
|
+
node_cache[:century_of_era][start_index] = r0
|
450
|
+
|
451
|
+
r0
|
452
|
+
end
|
453
|
+
|
454
|
+
module YearOfEra0
|
455
|
+
def compile
|
456
|
+
# No 'era' support, so year is just year.
|
457
|
+
return case text_value.length
|
458
|
+
when 2 then "t.year % 100"
|
459
|
+
else "t.year"
|
460
|
+
end
|
461
|
+
end
|
462
|
+
end
|
463
|
+
|
464
|
+
def _nt_year_of_era
|
465
|
+
start_index = index
|
466
|
+
if node_cache[:year_of_era].has_key?(index)
|
467
|
+
cached = node_cache[:year_of_era][index]
|
468
|
+
if cached
|
469
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
470
|
+
@index = cached.interval.end
|
471
|
+
end
|
472
|
+
return cached
|
473
|
+
end
|
474
|
+
|
475
|
+
i0 = index
|
476
|
+
s1, i1 = [], index
|
477
|
+
loop do
|
478
|
+
if has_terminal?("Y", false, index)
|
479
|
+
r2 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
480
|
+
@index += 1
|
481
|
+
else
|
482
|
+
terminal_parse_failure("Y")
|
483
|
+
r2 = nil
|
484
|
+
end
|
485
|
+
if r2
|
486
|
+
s1 << r2
|
487
|
+
else
|
488
|
+
break
|
489
|
+
end
|
490
|
+
end
|
491
|
+
if s1.empty?
|
492
|
+
@index = i1
|
493
|
+
r1 = nil
|
494
|
+
else
|
495
|
+
r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
|
496
|
+
end
|
497
|
+
if r1
|
498
|
+
r0 = r1
|
499
|
+
r0.extend(YearOfEra0)
|
500
|
+
else
|
501
|
+
r3 = _nt_weekyear
|
502
|
+
if r3
|
503
|
+
r0 = r3
|
504
|
+
r0.extend(YearOfEra0)
|
505
|
+
else
|
506
|
+
r4 = _nt_year
|
507
|
+
if r4
|
508
|
+
r0 = r4
|
509
|
+
r0.extend(YearOfEra0)
|
510
|
+
else
|
511
|
+
@index = i0
|
512
|
+
r0 = nil
|
513
|
+
end
|
514
|
+
end
|
515
|
+
end
|
516
|
+
|
517
|
+
node_cache[:year_of_era][start_index] = r0
|
518
|
+
|
519
|
+
r0
|
520
|
+
end
|
521
|
+
|
522
|
+
def _nt_weekyear
|
523
|
+
start_index = index
|
524
|
+
if node_cache[:weekyear].has_key?(index)
|
525
|
+
cached = node_cache[:weekyear][index]
|
526
|
+
if cached
|
527
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
528
|
+
@index = cached.interval.end
|
529
|
+
end
|
530
|
+
return cached
|
531
|
+
end
|
532
|
+
|
533
|
+
s0, i0 = [], index
|
534
|
+
loop do
|
535
|
+
if has_terminal?("x", false, index)
|
536
|
+
r1 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
537
|
+
@index += 1
|
538
|
+
else
|
539
|
+
terminal_parse_failure("x")
|
540
|
+
r1 = nil
|
541
|
+
end
|
542
|
+
if r1
|
543
|
+
s0 << r1
|
544
|
+
else
|
545
|
+
break
|
546
|
+
end
|
547
|
+
end
|
548
|
+
if s0.empty?
|
549
|
+
@index = i0
|
550
|
+
r0 = nil
|
551
|
+
else
|
552
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
553
|
+
end
|
554
|
+
|
555
|
+
node_cache[:weekyear][start_index] = r0
|
556
|
+
|
557
|
+
r0
|
558
|
+
end
|
559
|
+
|
560
|
+
module WeekOfWeekyear0
|
561
|
+
def compile
|
562
|
+
return "(t.yday / 7) + 1"
|
563
|
+
end
|
564
|
+
end
|
565
|
+
|
566
|
+
def _nt_week_of_weekyear
|
567
|
+
start_index = index
|
568
|
+
if node_cache[:week_of_weekyear].has_key?(index)
|
569
|
+
cached = node_cache[:week_of_weekyear][index]
|
570
|
+
if cached
|
571
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
572
|
+
@index = cached.interval.end
|
573
|
+
end
|
574
|
+
return cached
|
575
|
+
end
|
576
|
+
|
577
|
+
s0, i0 = [], index
|
578
|
+
loop do
|
579
|
+
if has_terminal?("w", false, index)
|
580
|
+
r1 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
581
|
+
@index += 1
|
582
|
+
else
|
583
|
+
terminal_parse_failure("w")
|
584
|
+
r1 = nil
|
585
|
+
end
|
586
|
+
if r1
|
587
|
+
s0 << r1
|
588
|
+
else
|
589
|
+
break
|
590
|
+
end
|
591
|
+
end
|
592
|
+
if s0.empty?
|
593
|
+
@index = i0
|
594
|
+
r0 = nil
|
595
|
+
else
|
596
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
597
|
+
r0.extend(WeekOfWeekyear0)
|
598
|
+
end
|
599
|
+
|
600
|
+
node_cache[:week_of_weekyear][start_index] = r0
|
601
|
+
|
602
|
+
r0
|
603
|
+
end
|
604
|
+
|
605
|
+
module DayOfWeekNumber0
|
606
|
+
def compile
|
607
|
+
return "t.wday"
|
608
|
+
end
|
609
|
+
end
|
610
|
+
|
611
|
+
def _nt_day_of_week_number
|
612
|
+
start_index = index
|
613
|
+
if node_cache[:day_of_week_number].has_key?(index)
|
614
|
+
cached = node_cache[:day_of_week_number][index]
|
615
|
+
if cached
|
616
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
617
|
+
@index = cached.interval.end
|
618
|
+
end
|
619
|
+
return cached
|
620
|
+
end
|
621
|
+
|
622
|
+
s0, i0 = [], index
|
623
|
+
loop do
|
624
|
+
if has_terminal?("e", false, index)
|
625
|
+
r1 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
626
|
+
@index += 1
|
627
|
+
else
|
628
|
+
terminal_parse_failure("e")
|
629
|
+
r1 = nil
|
630
|
+
end
|
631
|
+
if r1
|
632
|
+
s0 << r1
|
633
|
+
else
|
634
|
+
break
|
635
|
+
end
|
636
|
+
end
|
637
|
+
if s0.empty?
|
638
|
+
@index = i0
|
639
|
+
r0 = nil
|
640
|
+
else
|
641
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
642
|
+
r0.extend(DayOfWeekNumber0)
|
643
|
+
end
|
644
|
+
|
645
|
+
node_cache[:day_of_week_number][start_index] = r0
|
646
|
+
|
647
|
+
r0
|
648
|
+
end
|
649
|
+
|
650
|
+
module DayOfWeekText0
|
651
|
+
def compile
|
652
|
+
if text_value.length < 4
|
653
|
+
return %Q<t.strftime("%a")>
|
654
|
+
end
|
655
|
+
return %Q<t.strftime("%A")>
|
656
|
+
end
|
657
|
+
end
|
658
|
+
|
659
|
+
def _nt_day_of_week_text
|
660
|
+
start_index = index
|
661
|
+
if node_cache[:day_of_week_text].has_key?(index)
|
662
|
+
cached = node_cache[:day_of_week_text][index]
|
663
|
+
if cached
|
664
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
665
|
+
@index = cached.interval.end
|
666
|
+
end
|
667
|
+
return cached
|
668
|
+
end
|
669
|
+
|
670
|
+
s0, i0 = [], index
|
671
|
+
loop do
|
672
|
+
if has_terminal?("E", false, index)
|
673
|
+
r1 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
674
|
+
@index += 1
|
675
|
+
else
|
676
|
+
terminal_parse_failure("E")
|
677
|
+
r1 = nil
|
678
|
+
end
|
679
|
+
if r1
|
680
|
+
s0 << r1
|
681
|
+
else
|
682
|
+
break
|
683
|
+
end
|
684
|
+
end
|
685
|
+
if s0.empty?
|
686
|
+
@index = i0
|
687
|
+
r0 = nil
|
688
|
+
else
|
689
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
690
|
+
r0.extend(DayOfWeekText0)
|
691
|
+
end
|
692
|
+
|
693
|
+
node_cache[:day_of_week_text][start_index] = r0
|
694
|
+
|
695
|
+
r0
|
696
|
+
end
|
697
|
+
|
698
|
+
def _nt_year
|
699
|
+
start_index = index
|
700
|
+
if node_cache[:year].has_key?(index)
|
701
|
+
cached = node_cache[:year][index]
|
702
|
+
if cached
|
703
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
704
|
+
@index = cached.interval.end
|
705
|
+
end
|
706
|
+
return cached
|
707
|
+
end
|
708
|
+
|
709
|
+
s0, i0 = [], index
|
710
|
+
loop do
|
711
|
+
if has_terminal?("y", false, index)
|
712
|
+
r1 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
713
|
+
@index += 1
|
714
|
+
else
|
715
|
+
terminal_parse_failure("y")
|
716
|
+
r1 = nil
|
717
|
+
end
|
718
|
+
if r1
|
719
|
+
s0 << r1
|
720
|
+
else
|
721
|
+
break
|
722
|
+
end
|
723
|
+
end
|
724
|
+
if s0.empty?
|
725
|
+
@index = i0
|
726
|
+
r0 = nil
|
727
|
+
else
|
728
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
729
|
+
end
|
730
|
+
|
731
|
+
node_cache[:year][start_index] = r0
|
732
|
+
|
733
|
+
r0
|
734
|
+
end
|
735
|
+
|
736
|
+
module DayOfYear0
|
737
|
+
def compile
|
738
|
+
return %Q<t.yday>
|
739
|
+
end
|
740
|
+
end
|
741
|
+
|
742
|
+
def _nt_day_of_year
|
743
|
+
start_index = index
|
744
|
+
if node_cache[:day_of_year].has_key?(index)
|
745
|
+
cached = node_cache[:day_of_year][index]
|
746
|
+
if cached
|
747
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
748
|
+
@index = cached.interval.end
|
749
|
+
end
|
750
|
+
return cached
|
751
|
+
end
|
752
|
+
|
753
|
+
s0, i0 = [], index
|
754
|
+
loop do
|
755
|
+
if has_terminal?("D", false, index)
|
756
|
+
r1 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
757
|
+
@index += 1
|
758
|
+
else
|
759
|
+
terminal_parse_failure("D")
|
760
|
+
r1 = nil
|
761
|
+
end
|
762
|
+
if r1
|
763
|
+
s0 << r1
|
764
|
+
else
|
765
|
+
break
|
766
|
+
end
|
767
|
+
end
|
768
|
+
if s0.empty?
|
769
|
+
@index = i0
|
770
|
+
r0 = nil
|
771
|
+
else
|
772
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
773
|
+
r0.extend(DayOfYear0)
|
774
|
+
end
|
775
|
+
|
776
|
+
node_cache[:day_of_year][start_index] = r0
|
777
|
+
|
778
|
+
r0
|
779
|
+
end
|
780
|
+
|
781
|
+
module MonthOfYear0
|
782
|
+
def compile
|
783
|
+
return case text_value.length
|
784
|
+
when 1..2 then %Q<sprintf("%0#{text_value.length}d", t.month)>
|
785
|
+
when 3 then %Q<t.strftime("%b")>
|
786
|
+
else %Q<t.strftime("%B")>
|
787
|
+
end
|
788
|
+
end
|
789
|
+
end
|
790
|
+
|
791
|
+
def _nt_month_of_year
|
792
|
+
start_index = index
|
793
|
+
if node_cache[:month_of_year].has_key?(index)
|
794
|
+
cached = node_cache[:month_of_year][index]
|
795
|
+
if cached
|
796
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
797
|
+
@index = cached.interval.end
|
798
|
+
end
|
799
|
+
return cached
|
800
|
+
end
|
801
|
+
|
802
|
+
s0, i0 = [], index
|
803
|
+
loop do
|
804
|
+
if has_terminal?("M", false, index)
|
805
|
+
r1 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
806
|
+
@index += 1
|
807
|
+
else
|
808
|
+
terminal_parse_failure("M")
|
809
|
+
r1 = nil
|
810
|
+
end
|
811
|
+
if r1
|
812
|
+
s0 << r1
|
813
|
+
else
|
814
|
+
break
|
815
|
+
end
|
816
|
+
end
|
817
|
+
if s0.empty?
|
818
|
+
@index = i0
|
819
|
+
r0 = nil
|
820
|
+
else
|
821
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
822
|
+
r0.extend(MonthOfYear0)
|
823
|
+
end
|
824
|
+
|
825
|
+
node_cache[:month_of_year][start_index] = r0
|
826
|
+
|
827
|
+
r0
|
828
|
+
end
|
829
|
+
|
830
|
+
module DayOfMonth0
|
831
|
+
def compile
|
832
|
+
return %Q<t.strftime("%0#{text_value.length}d")>
|
833
|
+
end
|
834
|
+
end
|
835
|
+
|
836
|
+
def _nt_day_of_month
|
837
|
+
start_index = index
|
838
|
+
if node_cache[:day_of_month].has_key?(index)
|
839
|
+
cached = node_cache[:day_of_month][index]
|
840
|
+
if cached
|
841
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
842
|
+
@index = cached.interval.end
|
843
|
+
end
|
844
|
+
return cached
|
845
|
+
end
|
846
|
+
|
847
|
+
s0, i0 = [], index
|
848
|
+
loop do
|
849
|
+
if has_terminal?("d", false, index)
|
850
|
+
r1 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
851
|
+
@index += 1
|
852
|
+
else
|
853
|
+
terminal_parse_failure("d")
|
854
|
+
r1 = nil
|
855
|
+
end
|
856
|
+
if r1
|
857
|
+
s0 << r1
|
858
|
+
else
|
859
|
+
break
|
860
|
+
end
|
861
|
+
end
|
862
|
+
if s0.empty?
|
863
|
+
@index = i0
|
864
|
+
r0 = nil
|
865
|
+
else
|
866
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
867
|
+
r0.extend(DayOfMonth0)
|
868
|
+
end
|
869
|
+
|
870
|
+
node_cache[:day_of_month][start_index] = r0
|
871
|
+
|
872
|
+
r0
|
873
|
+
end
|
874
|
+
|
875
|
+
module HalfdayOfDay0
|
876
|
+
def compile
|
877
|
+
return %Q<t.strftime("%p")>
|
878
|
+
end
|
879
|
+
end
|
880
|
+
|
881
|
+
def _nt_halfday_of_day
|
882
|
+
start_index = index
|
883
|
+
if node_cache[:halfday_of_day].has_key?(index)
|
884
|
+
cached = node_cache[:halfday_of_day][index]
|
885
|
+
if cached
|
886
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
887
|
+
@index = cached.interval.end
|
888
|
+
end
|
889
|
+
return cached
|
890
|
+
end
|
891
|
+
|
892
|
+
s0, i0 = [], index
|
893
|
+
loop do
|
894
|
+
if has_terminal?("a", false, index)
|
895
|
+
r1 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
896
|
+
@index += 1
|
897
|
+
else
|
898
|
+
terminal_parse_failure("a")
|
899
|
+
r1 = nil
|
900
|
+
end
|
901
|
+
if r1
|
902
|
+
s0 << r1
|
903
|
+
else
|
904
|
+
break
|
905
|
+
end
|
906
|
+
end
|
907
|
+
if s0.empty?
|
908
|
+
@index = i0
|
909
|
+
r0 = nil
|
910
|
+
else
|
911
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
912
|
+
r0.extend(HalfdayOfDay0)
|
913
|
+
end
|
914
|
+
|
915
|
+
node_cache[:halfday_of_day][start_index] = r0
|
916
|
+
|
917
|
+
r0
|
918
|
+
end
|
919
|
+
|
920
|
+
module HourOfHalfday0
|
921
|
+
def compile
|
922
|
+
return %Q<t.strftime("%I")>
|
923
|
+
end
|
924
|
+
end
|
925
|
+
|
926
|
+
def _nt_hour_of_halfday
|
927
|
+
start_index = index
|
928
|
+
if node_cache[:hour_of_halfday].has_key?(index)
|
929
|
+
cached = node_cache[:hour_of_halfday][index]
|
930
|
+
if cached
|
931
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
932
|
+
@index = cached.interval.end
|
933
|
+
end
|
934
|
+
return cached
|
935
|
+
end
|
936
|
+
|
937
|
+
s0, i0 = [], index
|
938
|
+
loop do
|
939
|
+
if has_terminal?("K", false, index)
|
940
|
+
r1 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
941
|
+
@index += 1
|
942
|
+
else
|
943
|
+
terminal_parse_failure("K")
|
944
|
+
r1 = nil
|
945
|
+
end
|
946
|
+
if r1
|
947
|
+
s0 << r1
|
948
|
+
else
|
949
|
+
break
|
950
|
+
end
|
951
|
+
end
|
952
|
+
if s0.empty?
|
953
|
+
@index = i0
|
954
|
+
r0 = nil
|
955
|
+
else
|
956
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
957
|
+
r0.extend(HourOfHalfday0)
|
958
|
+
end
|
959
|
+
|
960
|
+
node_cache[:hour_of_halfday][start_index] = r0
|
961
|
+
|
962
|
+
r0
|
963
|
+
end
|
964
|
+
|
965
|
+
module ClockhourOfHalfday0
|
966
|
+
def compile
|
967
|
+
return %Q<sprintf("%0#{text_value.length}d", t.hour / 12)>
|
968
|
+
end
|
969
|
+
end
|
970
|
+
|
971
|
+
def _nt_clockhour_of_halfday
|
972
|
+
start_index = index
|
973
|
+
if node_cache[:clockhour_of_halfday].has_key?(index)
|
974
|
+
cached = node_cache[:clockhour_of_halfday][index]
|
975
|
+
if cached
|
976
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
977
|
+
@index = cached.interval.end
|
978
|
+
end
|
979
|
+
return cached
|
980
|
+
end
|
981
|
+
|
982
|
+
s0, i0 = [], index
|
983
|
+
loop do
|
984
|
+
if has_terminal?("h", false, index)
|
985
|
+
r1 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
986
|
+
@index += 1
|
987
|
+
else
|
988
|
+
terminal_parse_failure("h")
|
989
|
+
r1 = nil
|
990
|
+
end
|
991
|
+
if r1
|
992
|
+
s0 << r1
|
993
|
+
else
|
994
|
+
break
|
995
|
+
end
|
996
|
+
end
|
997
|
+
if s0.empty?
|
998
|
+
@index = i0
|
999
|
+
r0 = nil
|
1000
|
+
else
|
1001
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
1002
|
+
r0.extend(ClockhourOfHalfday0)
|
1003
|
+
end
|
1004
|
+
|
1005
|
+
node_cache[:clockhour_of_halfday][start_index] = r0
|
1006
|
+
|
1007
|
+
r0
|
1008
|
+
end
|
1009
|
+
|
1010
|
+
module HourOfDay0
|
1011
|
+
def compile
|
1012
|
+
return %Q<sprintf("%0#{text_value.length}d", t.hour)>
|
1013
|
+
end
|
1014
|
+
end
|
1015
|
+
|
1016
|
+
def _nt_hour_of_day
|
1017
|
+
start_index = index
|
1018
|
+
if node_cache[:hour_of_day].has_key?(index)
|
1019
|
+
cached = node_cache[:hour_of_day][index]
|
1020
|
+
if cached
|
1021
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
1022
|
+
@index = cached.interval.end
|
1023
|
+
end
|
1024
|
+
return cached
|
1025
|
+
end
|
1026
|
+
|
1027
|
+
s0, i0 = [], index
|
1028
|
+
loop do
|
1029
|
+
if has_terminal?("H", false, index)
|
1030
|
+
r1 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
1031
|
+
@index += 1
|
1032
|
+
else
|
1033
|
+
terminal_parse_failure("H")
|
1034
|
+
r1 = nil
|
1035
|
+
end
|
1036
|
+
if r1
|
1037
|
+
s0 << r1
|
1038
|
+
else
|
1039
|
+
break
|
1040
|
+
end
|
1041
|
+
end
|
1042
|
+
if s0.empty?
|
1043
|
+
@index = i0
|
1044
|
+
r0 = nil
|
1045
|
+
else
|
1046
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
1047
|
+
r0.extend(HourOfDay0)
|
1048
|
+
end
|
1049
|
+
|
1050
|
+
node_cache[:hour_of_day][start_index] = r0
|
1051
|
+
|
1052
|
+
r0
|
1053
|
+
end
|
1054
|
+
|
1055
|
+
module ClockhourOfDay0
|
1056
|
+
def compile
|
1057
|
+
return %Q<sprintf("%0#{text_value.length}d", t.hour + 1)>
|
1058
|
+
end
|
1059
|
+
end
|
1060
|
+
|
1061
|
+
def _nt_clockhour_of_day
|
1062
|
+
start_index = index
|
1063
|
+
if node_cache[:clockhour_of_day].has_key?(index)
|
1064
|
+
cached = node_cache[:clockhour_of_day][index]
|
1065
|
+
if cached
|
1066
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
1067
|
+
@index = cached.interval.end
|
1068
|
+
end
|
1069
|
+
return cached
|
1070
|
+
end
|
1071
|
+
|
1072
|
+
s0, i0 = [], index
|
1073
|
+
loop do
|
1074
|
+
if has_terminal?("k", false, index)
|
1075
|
+
r1 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
1076
|
+
@index += 1
|
1077
|
+
else
|
1078
|
+
terminal_parse_failure("k")
|
1079
|
+
r1 = nil
|
1080
|
+
end
|
1081
|
+
if r1
|
1082
|
+
s0 << r1
|
1083
|
+
else
|
1084
|
+
break
|
1085
|
+
end
|
1086
|
+
end
|
1087
|
+
if s0.empty?
|
1088
|
+
@index = i0
|
1089
|
+
r0 = nil
|
1090
|
+
else
|
1091
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
1092
|
+
r0.extend(ClockhourOfDay0)
|
1093
|
+
end
|
1094
|
+
|
1095
|
+
node_cache[:clockhour_of_day][start_index] = r0
|
1096
|
+
|
1097
|
+
r0
|
1098
|
+
end
|
1099
|
+
|
1100
|
+
module MinuteOfHour0
|
1101
|
+
def compile
|
1102
|
+
return %Q<sprintf("%0#{text_value.length}d", t.min)>
|
1103
|
+
end
|
1104
|
+
end
|
1105
|
+
|
1106
|
+
def _nt_minute_of_hour
|
1107
|
+
start_index = index
|
1108
|
+
if node_cache[:minute_of_hour].has_key?(index)
|
1109
|
+
cached = node_cache[:minute_of_hour][index]
|
1110
|
+
if cached
|
1111
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
1112
|
+
@index = cached.interval.end
|
1113
|
+
end
|
1114
|
+
return cached
|
1115
|
+
end
|
1116
|
+
|
1117
|
+
s0, i0 = [], index
|
1118
|
+
loop do
|
1119
|
+
if has_terminal?("m", false, index)
|
1120
|
+
r1 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
1121
|
+
@index += 1
|
1122
|
+
else
|
1123
|
+
terminal_parse_failure("m")
|
1124
|
+
r1 = nil
|
1125
|
+
end
|
1126
|
+
if r1
|
1127
|
+
s0 << r1
|
1128
|
+
else
|
1129
|
+
break
|
1130
|
+
end
|
1131
|
+
end
|
1132
|
+
if s0.empty?
|
1133
|
+
@index = i0
|
1134
|
+
r0 = nil
|
1135
|
+
else
|
1136
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
1137
|
+
r0.extend(MinuteOfHour0)
|
1138
|
+
end
|
1139
|
+
|
1140
|
+
node_cache[:minute_of_hour][start_index] = r0
|
1141
|
+
|
1142
|
+
r0
|
1143
|
+
end
|
1144
|
+
|
1145
|
+
module SecondOfMinute0
|
1146
|
+
def compile
|
1147
|
+
return %Q<sprintf("%0#{text_value.length}d", t.sec)>
|
1148
|
+
end
|
1149
|
+
end
|
1150
|
+
|
1151
|
+
def _nt_second_of_minute
|
1152
|
+
start_index = index
|
1153
|
+
if node_cache[:second_of_minute].has_key?(index)
|
1154
|
+
cached = node_cache[:second_of_minute][index]
|
1155
|
+
if cached
|
1156
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
1157
|
+
@index = cached.interval.end
|
1158
|
+
end
|
1159
|
+
return cached
|
1160
|
+
end
|
1161
|
+
|
1162
|
+
s0, i0 = [], index
|
1163
|
+
loop do
|
1164
|
+
if has_terminal?("s", false, index)
|
1165
|
+
r1 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
1166
|
+
@index += 1
|
1167
|
+
else
|
1168
|
+
terminal_parse_failure("s")
|
1169
|
+
r1 = nil
|
1170
|
+
end
|
1171
|
+
if r1
|
1172
|
+
s0 << r1
|
1173
|
+
else
|
1174
|
+
break
|
1175
|
+
end
|
1176
|
+
end
|
1177
|
+
if s0.empty?
|
1178
|
+
@index = i0
|
1179
|
+
r0 = nil
|
1180
|
+
else
|
1181
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
1182
|
+
r0.extend(SecondOfMinute0)
|
1183
|
+
end
|
1184
|
+
|
1185
|
+
node_cache[:second_of_minute][start_index] = r0
|
1186
|
+
|
1187
|
+
r0
|
1188
|
+
end
|
1189
|
+
|
1190
|
+
module FractionOfSecond0
|
1191
|
+
def compile
|
1192
|
+
return %Q<sprintf("%0#{text_value.length}d", t.nsec / (10 ** (9 - #{text_value.length})))>
|
1193
|
+
end
|
1194
|
+
end
|
1195
|
+
|
1196
|
+
def _nt_fraction_of_second
|
1197
|
+
start_index = index
|
1198
|
+
if node_cache[:fraction_of_second].has_key?(index)
|
1199
|
+
cached = node_cache[:fraction_of_second][index]
|
1200
|
+
if cached
|
1201
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
1202
|
+
@index = cached.interval.end
|
1203
|
+
end
|
1204
|
+
return cached
|
1205
|
+
end
|
1206
|
+
|
1207
|
+
s0, i0 = [], index
|
1208
|
+
loop do
|
1209
|
+
if has_terminal?("S", false, index)
|
1210
|
+
r1 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
1211
|
+
@index += 1
|
1212
|
+
else
|
1213
|
+
terminal_parse_failure("S")
|
1214
|
+
r1 = nil
|
1215
|
+
end
|
1216
|
+
if r1
|
1217
|
+
s0 << r1
|
1218
|
+
else
|
1219
|
+
break
|
1220
|
+
end
|
1221
|
+
end
|
1222
|
+
if s0.empty?
|
1223
|
+
@index = i0
|
1224
|
+
r0 = nil
|
1225
|
+
else
|
1226
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
1227
|
+
r0.extend(FractionOfSecond0)
|
1228
|
+
end
|
1229
|
+
|
1230
|
+
node_cache[:fraction_of_second][start_index] = r0
|
1231
|
+
|
1232
|
+
r0
|
1233
|
+
end
|
1234
|
+
|
1235
|
+
def _nt_time_zone_text
|
1236
|
+
start_index = index
|
1237
|
+
if node_cache[:time_zone_text].has_key?(index)
|
1238
|
+
cached = node_cache[:time_zone_text][index]
|
1239
|
+
if cached
|
1240
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
1241
|
+
@index = cached.interval.end
|
1242
|
+
end
|
1243
|
+
return cached
|
1244
|
+
end
|
1245
|
+
|
1246
|
+
s0, i0 = [], index
|
1247
|
+
loop do
|
1248
|
+
if has_terminal?("z", false, index)
|
1249
|
+
r1 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
1250
|
+
@index += 1
|
1251
|
+
else
|
1252
|
+
terminal_parse_failure("z")
|
1253
|
+
r1 = nil
|
1254
|
+
end
|
1255
|
+
if r1
|
1256
|
+
s0 << r1
|
1257
|
+
else
|
1258
|
+
break
|
1259
|
+
end
|
1260
|
+
end
|
1261
|
+
if s0.empty?
|
1262
|
+
@index = i0
|
1263
|
+
r0 = nil
|
1264
|
+
else
|
1265
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
1266
|
+
end
|
1267
|
+
|
1268
|
+
node_cache[:time_zone_text][start_index] = r0
|
1269
|
+
|
1270
|
+
r0
|
1271
|
+
end
|
1272
|
+
|
1273
|
+
module TimeZoneOffsetOrId0
|
1274
|
+
def compile
|
1275
|
+
return %Q<sprintf("%+05d", t.gmtoff / 36)>
|
1276
|
+
end
|
1277
|
+
end
|
1278
|
+
|
1279
|
+
def _nt_time_zone_offset_or_id
|
1280
|
+
start_index = index
|
1281
|
+
if node_cache[:time_zone_offset_or_id].has_key?(index)
|
1282
|
+
cached = node_cache[:time_zone_offset_or_id][index]
|
1283
|
+
if cached
|
1284
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
1285
|
+
@index = cached.interval.end
|
1286
|
+
end
|
1287
|
+
return cached
|
1288
|
+
end
|
1289
|
+
|
1290
|
+
s0, i0 = [], index
|
1291
|
+
loop do
|
1292
|
+
if has_terminal?("Z", false, index)
|
1293
|
+
r1 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
1294
|
+
@index += 1
|
1295
|
+
else
|
1296
|
+
terminal_parse_failure("Z")
|
1297
|
+
r1 = nil
|
1298
|
+
end
|
1299
|
+
if r1
|
1300
|
+
s0 << r1
|
1301
|
+
else
|
1302
|
+
break
|
1303
|
+
end
|
1304
|
+
end
|
1305
|
+
if s0.empty?
|
1306
|
+
@index = i0
|
1307
|
+
r0 = nil
|
1308
|
+
else
|
1309
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
1310
|
+
r0.extend(TimeZoneOffsetOrId0)
|
1311
|
+
end
|
1312
|
+
|
1313
|
+
node_cache[:time_zone_offset_or_id][start_index] = r0
|
1314
|
+
|
1315
|
+
r0
|
1316
|
+
end
|
1317
|
+
|
1318
|
+
end
|
1319
|
+
|
1320
|
+
class StudTimeFormatParser < Treetop::Runtime::CompiledParser
|
1321
|
+
include StudTimeFormat
|
1322
|
+
end
|
1323
|
+
|