Skip to content

Instantly share code, notes, and snippets.

@ddemaree
Created April 1, 2009 00:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ddemaree/88486 to your computer and use it in GitHub Desktop.
Save ddemaree/88486 to your computer and use it in GitHub Desktop.
# line 1 "src/parser.rl"
#
# THIS FILE IS NONSENSE. IT IS GENERATED BY RAGEL, AND IS NOT
# MEANT TO BE HUMAN READABLE CODE. BEST TO JUST SHRUG YOUR
# SHOULDERS AND MOVE ON. ALL THAT MATTERS IS THAT YOU CAN CALL
#
# Ticktock::Parser._parse(string)
#
# TO TRANSLATE A STRING IN TICKTOCK MESSAGE FORMAT INTO
# A PARAMS HASH.
#
class Ticktock::Parser
class ParseError < ::SyntaxError; end
class << self
# line 149 "src/parser.rl"
def _parse(input) #:nodoc:
data = input + ' '
# line 28 "app/models/ticktock/parser.rb"
class << self
attr_accessor :_hello_actions
private :_hello_actions, :_hello_actions=
end
self._hello_actions = [
0, 1, 0, 1, 3, 1, 5, 1,
7, 1, 8, 1, 16, 1, 17, 1,
18, 1, 20, 2, 1, 2, 2, 1,
3, 2, 1, 4, 2, 1, 5, 2,
1, 6, 2, 1, 7, 2, 1, 9,
2, 1, 11, 2, 1, 12, 2, 1,
13, 2, 10, 0, 2, 15, 19, 2,
17, 19, 2, 18, 19, 3, 0, 1,
9, 3, 1, 11, 14, 3, 1, 13,
14, 3, 10, 0, 15, 3, 15, 19,
0, 3, 19, 1, 3, 4, 1, 11,
14, 3, 4, 1, 11, 14, 7, 4,
1, 13, 14, 3, 4, 1, 13, 14,
7
]
class << self
attr_accessor :_hello_key_offsets
private :_hello_key_offsets, :_hello_key_offsets=
end
self._hello_key_offsets = [
0, 0, 18, 23, 27, 37, 38, 39,
41, 47, 52, 53, 54, 64, 71, 79,
86, 92, 99, 106, 111, 117, 123, 133,
142, 149, 156, 164, 166, 168, 171, 173,
175, 178, 189, 199, 208, 218, 225, 232,
238, 245, 252, 257, 268, 275, 280, 281,
282, 284, 285, 286, 299, 306, 311, 312,
313, 315, 316, 317, 331, 343, 351, 358,
366, 373, 379, 386, 393, 398, 404, 410,
416, 425, 433, 440, 446, 453, 460, 466,
473, 480, 485, 494, 500, 505, 508, 510,
513, 515, 516, 518, 520, 522, 523, 524,
525, 529, 532, 534, 535, 537, 539, 540,
542, 544, 546, 550, 552, 553, 554, 555,
561, 567, 572, 586, 600, 613, 618, 618,
623, 628
]
class << self
attr_accessor :_hello_trans_keys
private :_hello_trans_keys, :_hello_trans_keys=
end
self._hello_trans_keys = [
0, 32, 33, 34, 35, 39, 40, 49,
50, 58, 64, 100, 48, 57, 65, 90,
97, 122, 0, 32, 34, 41, 58, 65,
90, 97, 122, 0, 32, 45, 95, 48,
57, 65, 90, 97, 122, 34, 34, 0,
32, 58, 64, 32, 35, 39, 40, 0,
32, 34, 41, 58, 39, 39, 0, 32,
34, 41, 47, 58, 104, 109, 48, 57,
0, 32, 34, 41, 58, 48, 57, 0,
32, 34, 41, 47, 58, 48, 57, 0,
32, 34, 41, 49, 50, 58, 0, 32,
34, 41, 57, 58, 0, 32, 34, 41,
58, 48, 57, 0, 32, 34, 41, 58,
48, 57, 0, 32, 34, 41, 58, 0,
32, 34, 41, 48, 58, 0, 32, 34,
41, 47, 58, 0, 32, 34, 41, 47,
58, 104, 109, 48, 57, 0, 32, 34,
41, 58, 104, 109, 48, 57, 0, 32,
34, 41, 58, 48, 57, 0, 32, 34,
41, 58, 48, 57, 0, 32, 34, 41,
58, 109, 48, 57, 48, 57, 48, 57,
0, 32, 58, 48, 57, 48, 57, 0,
32, 58, 0, 32, 34, 41, 47, 57,
58, 104, 109, 48, 56, 0, 32, 34,
41, 47, 58, 104, 109, 48, 57, 0,
32, 34, 41, 58, 104, 109, 48, 57,
0, 32, 34, 41, 45, 58, 104, 109,
48, 57, 0, 32, 34, 41, 58, 48,
57, 0, 32, 34, 41, 58, 48, 57,
0, 32, 34, 41, 45, 58, 0, 32,
34, 41, 58, 48, 57, 0, 32, 34,
41, 58, 48, 57, 0, 32, 34, 41,
58, 0, 32, 34, 41, 47, 48, 58,
104, 109, 49, 57, 34, 39, 40, 58,
64, 32, 35, 0, 32, 34, 41, 58,
34, 34, 0, 32, 39, 39, 0, 32,
34, 41, 45, 58, 95, 48, 57, 65,
90, 97, 122, 34, 39, 40, 58, 64,
32, 35, 0, 32, 34, 41, 58, 34,
34, 0, 32, 39, 39, 0, 32, 34,
41, 45, 58, 95, 97, 48, 57, 65,
90, 98, 122, 34, 39, 40, 49, 50,
58, 64, 100, 32, 35, 48, 57, 0,
32, 34, 41, 47, 58, 48, 57, 0,
32, 34, 41, 58, 48, 57, 0, 32,
34, 41, 47, 58, 48, 57, 0, 32,
34, 41, 49, 50, 58, 0, 32, 34,
41, 57, 58, 0, 32, 34, 41, 58,
48, 57, 0, 32, 34, 41, 58, 48,
57, 0, 32, 34, 41, 58, 0, 32,
34, 41, 48, 58, 0, 32, 34, 41,
47, 58, 0, 32, 34, 41, 47, 58,
0, 32, 34, 41, 47, 57, 58, 48,
56, 0, 32, 34, 41, 47, 58, 48,
57, 0, 32, 34, 41, 58, 48, 57,
0, 32, 34, 41, 45, 58, 0, 32,
34, 41, 58, 48, 57, 0, 32, 34,
41, 58, 48, 57, 0, 32, 34, 41,
45, 58, 0, 32, 34, 41, 58, 48,
57, 0, 32, 34, 41, 58, 48, 57,
0, 32, 34, 41, 58, 0, 32, 34,
41, 47, 48, 58, 49, 57, 0, 32,
34, 41, 58, 97, 49, 50, 100, 48,
57, 47, 48, 57, 48, 57, 47, 48,
57, 49, 50, 57, 48, 57, 48, 57,
0, 32, 48, 47, 47, 47, 57, 48,
56, 47, 48, 57, 48, 57, 45, 48,
57, 48, 57, 45, 48, 57, 48, 57,
0, 32, 47, 48, 49, 57, 58, 97,
116, 101, 58, 0, 32, 34, 41, 58,
116, 0, 32, 34, 41, 58, 101, 0,
32, 34, 41, 58, 0, 32, 34, 41,
45, 58, 95, 116, 48, 57, 65, 90,
97, 122, 0, 32, 34, 41, 45, 58,
95, 101, 48, 57, 65, 90, 97, 122,
0, 32, 34, 41, 45, 58, 95, 48,
57, 65, 90, 97, 122, 0, 32, 34,
41, 58, 0, 32, 34, 41, 58, 0,
32, 34, 41, 58, 0, 32, 34, 41,
58, 0
]
class << self
attr_accessor :_hello_single_lengths
private :_hello_single_lengths, :_hello_single_lengths=
end
self._hello_single_lengths = [
0, 12, 5, 0, 4, 1, 1, 2,
2, 5, 1, 1, 8, 5, 6, 7,
6, 5, 5, 5, 6, 6, 8, 7,
5, 5, 6, 0, 0, 3, 0, 0,
3, 9, 8, 7, 8, 5, 5, 6,
5, 5, 5, 9, 5, 5, 1, 1,
2, 1, 1, 7, 5, 5, 1, 1,
2, 1, 1, 8, 8, 6, 5, 6,
7, 6, 5, 5, 5, 6, 6, 6,
7, 6, 5, 6, 5, 5, 6, 5,
5, 5, 7, 6, 3, 1, 0, 1,
2, 1, 0, 0, 2, 1, 1, 1,
2, 1, 0, 1, 0, 0, 1, 0,
0, 2, 2, 2, 1, 1, 1, 6,
6, 5, 8, 8, 7, 5, 0, 5,
5, 5
]
class << self
attr_accessor :_hello_range_lengths
private :_hello_range_lengths, :_hello_range_lengths=
end
self._hello_range_lengths = [
0, 3, 0, 2, 3, 0, 0, 0,
2, 0, 0, 0, 1, 1, 1, 0,
0, 1, 1, 0, 0, 0, 1, 1,
1, 1, 1, 1, 1, 0, 1, 1,
0, 1, 1, 1, 1, 1, 1, 0,
1, 1, 0, 1, 1, 0, 0, 0,
0, 0, 0, 3, 1, 0, 0, 0,
0, 0, 0, 3, 2, 1, 1, 1,
0, 0, 1, 1, 0, 0, 0, 0,
1, 1, 1, 0, 1, 1, 0, 1,
1, 0, 1, 0, 1, 1, 1, 1,
0, 0, 1, 1, 0, 0, 0, 0,
1, 1, 1, 0, 1, 1, 0, 1,
1, 0, 1, 0, 0, 0, 0, 0,
0, 0, 3, 3, 3, 0, 0, 0,
0, 0
]
class << self
attr_accessor :_hello_index_offsets
private :_hello_index_offsets, :_hello_index_offsets=
end
self._hello_index_offsets = [
0, 0, 16, 22, 25, 33, 35, 37,
40, 45, 51, 53, 55, 65, 72, 80,
88, 95, 102, 109, 115, 122, 129, 139,
148, 155, 162, 170, 172, 174, 178, 180,
182, 186, 197, 207, 216, 226, 233, 240,
247, 254, 261, 267, 278, 285, 291, 293,
295, 298, 300, 302, 313, 320, 326, 328,
330, 333, 335, 337, 349, 360, 368, 375,
383, 391, 398, 405, 412, 418, 425, 432,
439, 448, 456, 463, 470, 477, 484, 491,
498, 505, 511, 520, 527, 532, 535, 537,
540, 543, 545, 547, 549, 552, 554, 556,
558, 562, 565, 567, 569, 571, 573, 575,
577, 579, 582, 586, 589, 591, 593, 595,
602, 609, 615, 627, 639, 650, 656, 657,
663, 669
]
class << self
attr_accessor :_hello_trans_targs
private :_hello_trans_targs, :_hello_trans_targs=
end
self._hello_trans_targs = [
117, 1, 3, 5, 8, 10, 0, 33,
43, 0, 44, 59, 12, 51, 51, 2,
117, 1, 0, 0, 0, 2, 4, 4,
0, 118, 1, 4, 4, 4, 4, 4,
0, 7, 6, 7, 6, 118, 1, 0,
0, 0, 0, 0, 9, 119, 1, 0,
0, 0, 9, 7, 11, 7, 11, 117,
1, 0, 0, 13, 27, 24, 25, 22,
2, 117, 1, 0, 0, 0, 14, 2,
117, 1, 0, 0, 15, 0, 21, 2,
117, 1, 0, 0, 16, 20, 0, 2,
117, 1, 0, 0, 17, 0, 2, 117,
1, 0, 0, 0, 18, 2, 117, 1,
0, 0, 0, 19, 2, 117, 1, 0,
0, 0, 2, 117, 1, 0, 0, 17,
0, 2, 117, 1, 0, 0, 15, 0,
2, 117, 1, 0, 0, 13, 27, 24,
25, 23, 2, 117, 1, 0, 0, 0,
24, 25, 23, 2, 117, 1, 0, 0,
0, 23, 2, 117, 1, 0, 0, 0,
26, 2, 117, 1, 0, 0, 0, 25,
26, 2, 28, 0, 29, 0, 118, 1,
30, 0, 31, 0, 32, 0, 118, 1,
30, 0, 117, 1, 0, 0, 13, 34,
27, 24, 25, 22, 2, 117, 1, 0,
0, 13, 27, 24, 25, 35, 2, 117,
1, 0, 0, 0, 24, 25, 36, 2,
117, 1, 0, 0, 37, 0, 24, 25,
23, 2, 117, 1, 0, 0, 0, 38,
2, 117, 1, 0, 0, 0, 39, 2,
117, 1, 0, 0, 40, 0, 2, 117,
1, 0, 0, 0, 41, 2, 117, 1,
0, 0, 0, 42, 2, 117, 1, 0,
0, 0, 2, 117, 1, 0, 0, 13,
34, 27, 24, 25, 22, 2, 46, 49,
0, 0, 0, 0, 45, 120, 1, 0,
0, 0, 45, 48, 47, 48, 47, 118,
1, 0, 48, 50, 48, 50, 117, 1,
0, 0, 51, 52, 51, 51, 51, 51,
2, 54, 57, 0, 0, 0, 0, 53,
121, 1, 0, 0, 0, 53, 56, 55,
56, 55, 118, 1, 0, 56, 58, 56,
58, 117, 1, 0, 0, 51, 60, 51,
114, 51, 51, 51, 2, 54, 57, 0,
72, 82, 0, 0, 83, 0, 61, 53,
121, 1, 0, 0, 62, 0, 71, 53,
121, 1, 0, 0, 0, 63, 53, 121,
1, 0, 0, 64, 0, 70, 53, 121,
1, 0, 0, 65, 69, 0, 53, 121,
1, 0, 0, 66, 0, 53, 121, 1,
0, 0, 0, 67, 53, 121, 1, 0,
0, 0, 68, 53, 121, 1, 0, 0,
0, 53, 121, 1, 0, 0, 66, 0,
53, 121, 1, 0, 0, 64, 0, 53,
121, 1, 0, 0, 62, 0, 53, 121,
1, 0, 0, 62, 73, 0, 71, 53,
121, 1, 0, 0, 62, 0, 74, 53,
121, 1, 0, 0, 0, 75, 53, 121,
1, 0, 0, 76, 0, 53, 121, 1,
0, 0, 0, 77, 53, 121, 1, 0,
0, 0, 78, 53, 121, 1, 0, 0,
79, 0, 53, 121, 1, 0, 0, 0,
80, 53, 121, 1, 0, 0, 0, 81,
53, 121, 1, 0, 0, 0, 53, 121,
1, 0, 0, 62, 73, 0, 71, 53,
121, 1, 0, 0, 84, 111, 53, 96,
106, 107, 85, 0, 86, 95, 0, 87,
0, 88, 94, 0, 89, 93, 0, 90,
0, 91, 0, 92, 0, 118, 1, 0,
90, 0, 88, 0, 86, 0, 86, 97,
95, 0, 86, 98, 0, 99, 0, 100,
0, 101, 0, 102, 0, 103, 0, 104,
0, 105, 0, 118, 1, 0, 86, 97,
95, 0, 84, 108, 0, 109, 0, 110,
0, 84, 0, 121, 1, 0, 0, 0,
112, 53, 121, 1, 0, 0, 0, 113,
53, 121, 1, 0, 0, 84, 53, 117,
1, 0, 0, 51, 52, 51, 115, 51,
51, 51, 2, 117, 1, 0, 0, 51,
52, 51, 116, 51, 51, 51, 2, 117,
1, 0, 0, 51, 60, 51, 51, 51,
51, 2, 117, 1, 0, 0, 0, 2,
0, 119, 1, 0, 0, 0, 9, 120,
1, 0, 0, 0, 45, 121, 1, 0,
0, 0, 53, 0
]
class << self
attr_accessor :_hello_trans_actions
private :_hello_trans_actions, :_hello_trans_actions=
end
self._hello_trans_actions = [
77, 52, 0, 9, 0, 9, 17, 73,
73, 17, 0, 49, 73, 1, 1, 1,
22, 22, 17, 17, 17, 0, 1, 1,
0, 31, 31, 0, 0, 0, 0, 0,
17, 61, 1, 37, 0, 3, 3, 17,
0, 0, 0, 0, 1, 25, 25, 17,
17, 17, 0, 61, 1, 37, 0, 22,
22, 17, 17, 43, 11, 11, 13, 0,
0, 22, 22, 17, 17, 17, 1, 0,
22, 22, 17, 17, 46, 17, 0, 0,
22, 22, 17, 17, 1, 1, 17, 0,
22, 22, 17, 17, 0, 17, 0, 22,
22, 17, 17, 17, 0, 0, 22, 22,
17, 17, 17, 0, 0, 85, 85, 17,
17, 17, 0, 22, 22, 17, 17, 0,
17, 0, 22, 22, 17, 17, 46, 17,
0, 22, 22, 17, 17, 43, 11, 11,
13, 0, 0, 22, 22, 17, 17, 17,
11, 13, 0, 0, 81, 81, 17, 17,
17, 1, 0, 81, 81, 17, 17, 17,
1, 0, 22, 22, 17, 17, 17, 13,
0, 0, 1, 0, 0, 0, 55, 55,
13, 17, 1, 0, 0, 0, 58, 58,
15, 17, 22, 22, 17, 17, 43, 0,
11, 11, 13, 0, 0, 22, 22, 17,
17, 43, 11, 11, 13, 0, 0, 22,
22, 17, 17, 17, 11, 13, 0, 0,
22, 22, 17, 17, 40, 17, 11, 13,
0, 0, 22, 22, 17, 17, 17, 1,
0, 22, 22, 17, 17, 17, 0, 0,
22, 22, 17, 17, 43, 17, 0, 22,
22, 17, 17, 17, 1, 0, 22, 22,
17, 17, 17, 0, 0, 95, 95, 17,
17, 17, 0, 22, 22, 17, 17, 43,
0, 11, 11, 13, 0, 0, 9, 9,
0, 0, 0, 0, 1, 28, 28, 17,
17, 17, 0, 61, 1, 37, 0, 5,
5, 17, 61, 1, 37, 0, 22, 22,
17, 17, 0, 19, 0, 0, 0, 0,
0, 9, 9, 0, 0, 0, 0, 1,
34, 34, 17, 17, 17, 0, 61, 1,
37, 0, 7, 7, 17, 61, 1, 37,
0, 22, 22, 17, 17, 0, 19, 0,
0, 0, 0, 0, 0, 9, 9, 0,
1, 1, 0, 0, 1, 0, 1, 1,
34, 34, 17, 17, 43, 17, 0, 0,
34, 34, 17, 17, 17, 1, 0, 34,
34, 17, 17, 46, 17, 0, 0, 34,
34, 17, 17, 1, 1, 17, 0, 34,
34, 17, 17, 0, 17, 0, 34, 34,
17, 17, 17, 0, 0, 34, 34, 17,
17, 17, 0, 0, 90, 90, 17, 17,
17, 0, 34, 34, 17, 17, 0, 17,
0, 34, 34, 17, 17, 46, 17, 0,
34, 34, 17, 17, 43, 17, 0, 34,
34, 17, 17, 43, 0, 17, 0, 0,
34, 34, 17, 17, 43, 17, 0, 0,
34, 34, 17, 17, 17, 0, 0, 34,
34, 17, 17, 40, 17, 0, 34, 34,
17, 17, 17, 1, 0, 34, 34, 17,
17, 17, 0, 0, 34, 34, 17, 17,
43, 17, 0, 34, 34, 17, 17, 17,
1, 0, 34, 34, 17, 17, 17, 0,
0, 100, 100, 17, 17, 17, 0, 34,
34, 17, 17, 43, 0, 17, 0, 0,
34, 34, 17, 17, 0, 0, 0, 1,
1, 0, 1, 0, 43, 0, 0, 1,
0, 46, 0, 0, 1, 1, 0, 0,
0, 0, 0, 0, 0, 65, 65, 17,
0, 0, 46, 0, 43, 0, 43, 0,
0, 0, 43, 0, 0, 0, 0, 40,
0, 1, 0, 0, 0, 43, 0, 1,
0, 0, 0, 69, 69, 17, 43, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 34, 34, 17, 17, 17,
0, 0, 34, 34, 17, 17, 17, 0,
0, 34, 34, 17, 17, 0, 0, 22,
22, 17, 17, 0, 19, 0, 0, 0,
0, 0, 0, 22, 22, 17, 17, 0,
19, 0, 0, 0, 0, 0, 0, 22,
22, 17, 17, 0, 19, 0, 0, 0,
0, 0, 22, 22, 17, 17, 17, 0,
0, 25, 25, 17, 17, 17, 0, 28,
28, 17, 17, 17, 0, 34, 34, 17,
17, 17, 0, 0
]
class << self
attr_accessor :_hello_eof_actions
private :_hello_eof_actions, :_hello_eof_actions=
end
self._hello_eof_actions = [
0, 17, 17, 0, 17, 0, 0, 17,
0, 17, 0, 0, 17, 17, 17, 17,
17, 17, 17, 17, 17, 17, 17, 17,
17, 17, 17, 0, 0, 17, 0, 0,
17, 17, 17, 17, 17, 17, 17, 17,
17, 17, 17, 17, 0, 17, 0, 0,
17, 0, 0, 17, 0, 17, 0, 0,
17, 0, 0, 17, 0, 17, 17, 17,
17, 17, 17, 17, 17, 17, 17, 17,
17, 17, 17, 17, 17, 17, 17, 17,
17, 17, 17, 17, 0, 0, 0, 0,
0, 0, 0, 0, 17, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 17, 0, 0, 0, 0, 0, 17,
17, 17, 17, 17, 17, 0, 0, 0,
0, 0
]
class << self
attr_accessor :hello_start
end
self.hello_start = 1;
class << self
attr_accessor :hello_first_final
end
self.hello_first_final = 117;
class << self
attr_accessor :hello_error
end
self.hello_error = 0;
class << self
attr_accessor :hello_en_main
end
self.hello_en_main = 1;
# line 154 "src/parser.rl"
p = 0
eof = nil
word = nil
pe = data.length
key = nil
tokstart = nil
results = {}
values = []
quotes = 0
date = {}
dt_comps = []
body = ""
# line 472 "app/models/ticktock/parser.rb"
begin
p ||= 0
pe ||= data.length
cs = hello_start
end
# line 170 "src/parser.rl"
# line 481 "app/models/ticktock/parser.rb"
begin
_klen, _trans, _keys, _acts, _nacts = nil
_goto_level = 0
_resume = 10
_eof_trans = 15
_again = 20
_test_eof = 30
_out = 40
while true
_trigger_goto = false
if _goto_level <= 0
if p == pe
_goto_level = _test_eof
next
end
if cs == 0
_goto_level = _out
next
end
end
if _goto_level <= _resume
_keys = _hello_key_offsets[cs]
_trans = _hello_index_offsets[cs]
_klen = _hello_single_lengths[cs]
_break_match = false
begin
if _klen > 0
_lower = _keys
_upper = _keys + _klen - 1
loop do
break if _upper < _lower
_mid = _lower + ( (_upper - _lower) >> 1 )
if data[p] < _hello_trans_keys[_mid]
_upper = _mid - 1
elsif data[p] > _hello_trans_keys[_mid]
_lower = _mid + 1
else
_trans += (_mid - _keys)
_break_match = true
break
end
end # loop
break if _break_match
_keys += _klen
_trans += _klen
end
_klen = _hello_range_lengths[cs]
if _klen > 0
_lower = _keys
_upper = _keys + (_klen << 1) - 2
loop do
break if _upper < _lower
_mid = _lower + (((_upper-_lower) >> 1) & ~1)
if data[p] < _hello_trans_keys[_mid]
_upper = _mid - 2
elsif data[p] > _hello_trans_keys[_mid+1]
_lower = _mid + 2
else
_trans += ((_mid - _keys) >> 1)
_break_match = true
break
end
end # loop
break if _break_match
_trans += _klen
end
end while false
cs = _hello_trans_targs[_trans]
if _hello_trans_actions[_trans] != 0
_acts = _hello_trans_actions[_trans]
_nacts = _hello_actions[_acts]
_acts += 1
while _nacts > 0
_nacts -= 1
_acts += 1
case _hello_actions[_acts - 1]
when 0 then
# line 21 "src/parser.rl"
begin
tokstart = p;
end
# line 21 "src/parser.rl"
when 1 then
# line 25 "src/parser.rl"
begin
word = data[tokstart..p-1]
end
# line 25 "src/parser.rl"
when 2 then
# line 29 "src/parser.rl"
begin
key = word
results[key] ||= []
end
# line 29 "src/parser.rl"
when 3 then
# line 38 "src/parser.rl"
begin
body << (word + ' ')
end
# line 38 "src/parser.rl"
when 4 then
# line 42 "src/parser.rl"
begin
(results['tags'] ||= []) << word
body << ('#' + word + ' ')
end
# line 42 "src/parser.rl"
when 5 then
# line 47 "src/parser.rl"
begin
results['subject'] = word
end
# line 47 "src/parser.rl"
when 6 then
# line 51 "src/parser.rl"
begin
results[word] = true
end
# line 51 "src/parser.rl"
when 7 then
# line 55 "src/parser.rl"
begin
(results[key || :default] ||= []) << word
end
# line 55 "src/parser.rl"
when 8 then
# line 59 "src/parser.rl"
begin
quotes += 1 end
# line 59 "src/parser.rl"
when 9 then
# line 60 "src/parser.rl"
begin
quotes -= 1 end
# line 60 "src/parser.rl"
when 10 then
# line 73 "src/parser.rl"
begin
results["date"] ||= {} end
# line 73 "src/parser.rl"
when 11 then
# line 74 "src/parser.rl"
begin
results["date"]["year"] = word; end
# line 74 "src/parser.rl"
when 12 then
# line 75 "src/parser.rl"
begin
results["date"]["month"] = word; end
# line 75 "src/parser.rl"
when 13 then
# line 76 "src/parser.rl"
begin
results["date"]["day"] = word; end
# line 76 "src/parser.rl"
when 14 then
# line 78 "src/parser.rl"
begin
date = results["date"]
m, d, y = date["month"].to_i,
date["day"].to_i,
(date["year"] || Date.today.year).to_i
results["date"] = Date.civil(y,m,d)
end
# line 78 "src/parser.rl"
when 15 then
# line 103 "src/parser.rl"
begin
results["duration"] ||= {} end
# line 103 "src/parser.rl"
when 16 then
# line 104 "src/parser.rl"
begin
results["duration"]["h"] = data[tokstart..p-1] end
# line 104 "src/parser.rl"
when 17 then
# line 105 "src/parser.rl"
begin
results["duration"]["m"] = data[tokstart..p-1] end
# line 105 "src/parser.rl"
when 18 then
# line 106 "src/parser.rl"
begin
results["duration"]["s"] = data[tokstart..p-1] end
# line 106 "src/parser.rl"
when 19 then
# line 108 "src/parser.rl"
begin
begin
dur = results["duration"]
h, m, s = (dur["h"]||0).to_i, (dur["m"]||0).to_i, (dur["s"]||0).to_i
ts = 0
ts += h * 3600
ts += m * 60
ts += s
results["duration"] = ts
rescue => @e
results["duration"] = dur.inspect
end
end
# line 108 "src/parser.rl"
when 20 then
# line 147 "src/parser.rl"
begin
raise ParseError, "At offset #{p}, near: '#{data[p,10]}'" end
# line 147 "src/parser.rl"
# line 706 "app/models/ticktock/parser.rb"
end # action switch
end
end
if _trigger_goto
next
end
end
if _goto_level <= _again
if cs == 0
_goto_level = _out
next
end
p += 1
if p != pe
_goto_level = _resume
next
end
end
if _goto_level <= _test_eof
if p == eof
__acts = _hello_eof_actions[cs]
__nacts = _hello_actions[__acts]
__acts += 1
while __nacts > 0
__nacts -= 1
__acts += 1
case _hello_actions[__acts - 1]
when 20 then
# line 147 "src/parser.rl"
begin
raise ParseError, "At offset #{p}, near: '#{data[p,10]}'" end
# line 147 "src/parser.rl"
# line 739 "app/models/ticktock/parser.rb"
end # eof action switch
end
if _trigger_goto
next
end
end
end
if _goto_level <= _out
break
end
end
end
# line 171 "src/parser.rl"
unless quotes.zero?
raise ParseError, "Unclosed quotes"
end
# Do some very minor normalization #
results["body"] = body.strip.gsub(/ +/," ")
#results["date"] = Date.today if results["date"] == {}
#results["duration"] = nil if results["duration"] == 0
results
end
end
end
#
# THIS FILE IS NONSENSE. IT IS GENERATED BY RAGEL, AND IS NOT
# MEANT TO BE HUMAN READABLE CODE. BEST TO JUST SHRUG YOUR
# SHOULDERS AND MOVE ON. ALL THAT MATTERS IS THAT YOU CAN CALL
#
# Ticktock::Parser._parse(string)
#
# TO TRANSLATE A STRING IN TICKTOCK MESSAGE FORMAT INTO
# A PARAMS HASH.
#
class Ticktock::Parser
class ParseError < ::SyntaxError; end
class << self
%%{
machine hello;
action start {
tokstart = p;
}
action word {
word = data[tokstart..p-1]
}
action key {
key = word
results[key] ||= []
}
action default {
key = nil
}
action body {
body << (word + ' ')
}
action tag {
(results['tags'] ||= []) << word
body << ('#' + word + ' ')
}
action project {
results['subject'] = word
}
action flag {
results[word] = true
}
action value {
(results[key || :default] ||= []) << word
}
action quote { quotes += 1 }
action unquote { quotes -= 1 }
# Alphanumeric/text matchers #
bareword = ( [^ '"(:#@!] . [^ "):]* ) > start % word ; # allow apostrophes
dquoted = '"' @ quote ( [^"]* > start % word ) :>> '"' @ unquote;
squoted = '\'' @ quote ( [^']* > start % word ) :>> '\'' @ unquote;
anyword = dquoted | squoted | bareword ;
# Excludes nonalphanumeric chars
keyword = (alpha [0-9a-zA-Z_\-]*) > start % word ;
# Date/time matchers #
action initdate { results["date"] ||= {} }
action setyear { results["date"]["year"] = word; }
action setmonth { results["date"]["month"] = word; }
action setday { results["date"]["day"] = word; }
action compiledate {
date = results["date"]
m, d, y = date["month"].to_i,
date["day"].to_i,
(date["year"] || Date.today.year).to_i
results["date"] = Date.civil(y,m,d)
}
datekw = 'd:' | 'date:' ;
datestring_h = datekw* > initdate
((('19'|'20') [0-9]{2}) > start % word % setyear '-'
([0-9]{2}) > start % word % setmonth '-'
([0-9]{2}) > start % word % setday )
% compiledate ;
datestring_s = datekw* > initdate
([0-9]{1,2} > start % word % setmonth '/'
[0-9]{1,2} > start % word % setday '/'
(('19'|'20')[0-9]{2}) > start % word % setyear )
% compiledate ;
datestring = datestring_s | datestring_h ;
action inittime { results["duration"] ||= {} }
action sethours { results["duration"]["h"] = data[tokstart..p-1] }
action setminutes { results["duration"]["m"] = data[tokstart..p-1] }
action setseconds { results["duration"]["s"] = data[tokstart..p-1] }
action compiletime {
begin
dur = results["duration"]
h, m, s = (dur["h"]||0).to_i, (dur["m"]||0).to_i, (dur["s"]||0).to_i
ts = 0
ts += h * 3600
ts += m * 60
ts += s
results["duration"] = ts
rescue => @e
results["duration"] = dur.inspect
end
}
duration_c = '' > inittime
[0-9]{1,2} > start % sethours ':'
[0-9]{2} > start % setminutes
(':' ([0-9]{2}) > start % setseconds)*
% compiletime ;
duration_s = '' > inittime
(([0-9]+ > start % sethours) 'h')*
(([0-9]+ > start % setminutes) 'm')*
:>> '' % compiletime ;
timestring = duration_c | duration_s;
bodyword = anyword % body ;
pair = keyword % key ':' anyword % value ;
hashtag = '#' (bareword) % tag ;
atproject = '@' (anyword) % project ;
bang = '!' (keyword) % flag ;
param = (datestring | timestring | hashtag | bang | atproject | pair | bodyword);
params = param (' '+ param)*;
main := ' '* params? ' '* 0
@!{ raise ParseError, "At offset #{p}, near: '#{data[p,10]}'" };
}%%
def _parse(input) #:nodoc:
data = input + ' '
%% write data;
p = 0
eof = nil
word = nil
pe = data.length
key = nil
tokstart = nil
results = {}
values = []
quotes = 0
date = {}
dt_comps = []
body = ""
%% write init;
%% write exec;
unless quotes.zero?
raise ParseError, "Unclosed quotes"
end
# Do some very minor normalization #
results["body"] = body.strip.gsub(/ +/," ")
#results["date"] = Date.today if results["date"] == {}
#results["duration"] = nil if results["duration"] == 0
results
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment