Import upstream version 2.0.3
Debian Janitor
1 year, 7 months ago
0 | 0 | # |
1 | 1 | # DO NOT MODIFY!!!! |
2 | # This file is automatically generated by Racc 1.4.16.pre.1 | |
3 | # from Racc grammer file "". | |
2 | # This file is automatically generated by Racc 1.6.0 | |
3 | # from Racc grammar file "". | |
4 | 4 | # |
5 | 5 | |
6 | 6 | require 'racc/parser.rb' |
9 | 9 | ##### State transition tables begin ### |
10 | 10 | |
11 | 11 | racc_action_table = [ |
12 | 2, 17, 11, 31, 12, 31, 13, 79, 14, 40, | |
13 | 41, 80, 15, 16, 8, 71, 72, 10, 27, 29, | |
14 | 32, 29, 59, 60, 61, 62, 58, 55, 52, 53, | |
15 | 54, 56, 57, 46, 33, 34, 10, 59, 60, 61, | |
16 | 62, 58, 55, 52, 53, 54, 56, 57, 46, 35, | |
17 | 36, 10, 59, 60, 61, 62, 58, 55, 52, 53, | |
18 | 54, 56, 57, 46, 37, 38, 10, 59, 60, 61, | |
19 | 62, 58, 55, 52, 53, 54, 56, 57, 46, 43, | |
20 | 68, 10, 59, 60, 61, 62, 58, 55, 52, 53, | |
21 | 54, 56, 57, 46, nil, nil, 10, 59, 60, 61, | |
22 | 62, 58, 55, 52, 53, 54, 56, 57, 46, nil, | |
23 | nil, 10, 59, 60, 61, 62, 58, 55, 52, 53, | |
24 | 54, 56, 57, 46, nil, nil, 10, 59, 60, 61, | |
25 | 62, 58, 55, 52, 53, 54, 56, 57, 46, 75, | |
26 | nil, 10, 59, 60, 61, 62, 58, 55, 52, 53, | |
27 | 54, 56, 57, 46, 75, 21, 10, 22, nil, 23, | |
28 | nil, 24, nil, nil, nil, 25, 26, 21, 19, 22, | |
29 | nil, 23, nil, 24, nil, nil, nil, 25, 26, nil, | |
30 | 19 ] | |
12 | 2, 45, 16, 56, 17, 44, 18, 55, 23, 19, | |
13 | 20, 14, 21, 22, 8, 4, 10, 36, 16, 12, | |
14 | 17, 48, 18, 46, 47, 19, 20, 42, 21, 22, | |
15 | 50, 51, 87, 86, 39, 54, 39, 72, 73, 74, | |
16 | 75, 70, 71, 67, 68, 65, 66, 69, 78, nil, | |
17 | 59, nil, nil, 12, 72, 73, 74, 75, 70, 71, | |
18 | 67, 68, 65, 66, 69, nil, nil, 59, nil, nil, | |
19 | 12, 72, 73, 74, 75, 70, 71, 67, 68, 65, | |
20 | 66, 69, 91, nil, 59, 89, nil, 12, 72, 73, | |
21 | 74, 75, 70, 71, 67, 68, 65, 66, 69, 91, | |
22 | nil, 59, 89, nil, 12, 72, 73, 74, 75, 70, | |
23 | 71, 67, 68, 65, 66, 69, 91, nil, 59, 89, | |
24 | nil, 12, 72, 73, 74, 75, 70, 71, 67, 68, | |
25 | 65, 66, 69, 91, nil, 59, 89, 29, 12, 30, | |
26 | nil, 31, nil, nil, 32, 33, 27, 34, 35, 29, | |
27 | nil, 30, 25, 31, nil, nil, 32, 33, 81, 34, | |
28 | 35, 16, nil, 17, 25, 18, nil, nil, 19, 20, | |
29 | 77, 21, 22, 16, nil, 17, nil, 18, nil, nil, | |
30 | 19, 20, 42, 21, 22, 16, nil, 17, nil, 18, | |
31 | nil, nil, 19, 20, 85, 21, 22, 95, nil, nil, | |
32 | 93, nil, nil, nil, 94 ] | |
31 | 33 | |
32 | 34 | racc_action_check = [ |
33 | 1, 2, 1, 9, 1, 72, 1, 76, 1, 20, | |
34 | 20, 76, 1, 1, 1, 42, 42, 1, 8, 9, | |
35 | 11, 72, 32, 32, 32, 32, 32, 32, 32, 32, | |
36 | 32, 32, 32, 32, 12, 13, 32, 33, 33, 33, | |
37 | 33, 33, 33, 33, 33, 33, 33, 33, 33, 14, | |
38 | 15, 33, 34, 34, 34, 34, 34, 34, 34, 34, | |
39 | 34, 34, 34, 34, 16, 19, 34, 35, 35, 35, | |
40 | 35, 35, 35, 35, 35, 35, 35, 35, 35, 30, | |
41 | 40, 35, 36, 36, 36, 36, 36, 36, 36, 36, | |
42 | 36, 36, 36, 36, nil, nil, 36, 37, 37, 37, | |
43 | 37, 37, 37, 37, 37, 37, 37, 37, 37, nil, | |
44 | nil, 37, 43, 43, 43, 43, 43, 43, 43, 43, | |
45 | 43, 43, 43, 43, nil, nil, 43, 45, 45, 45, | |
46 | 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, | |
47 | nil, 45, 80, 80, 80, 80, 80, 80, 80, 80, | |
48 | 80, 80, 80, 80, 80, 7, 80, 7, nil, 7, | |
49 | nil, 7, nil, nil, nil, 7, 7, 41, 7, 41, | |
50 | nil, 41, nil, 41, nil, nil, nil, 41, 41, nil, | |
51 | 41 ] | |
35 | 1, 13, 1, 41, 1, 13, 1, 41, 2, 1, | |
36 | 1, 1, 1, 1, 1, 1, 1, 10, 11, 1, | |
37 | 11, 25, 11, 24, 24, 11, 11, 11, 11, 11, | |
38 | 26, 26, 57, 57, 38, 40, 11, 44, 44, 44, | |
39 | 44, 44, 44, 44, 44, 44, 44, 44, 50, nil, | |
40 | 44, nil, nil, 44, 55, 55, 55, 55, 55, 55, | |
41 | 55, 55, 55, 55, 55, nil, nil, 55, nil, nil, | |
42 | 55, 58, 58, 58, 58, 58, 58, 58, 58, 58, | |
43 | 58, 58, 58, nil, 58, 58, nil, 58, 91, 91, | |
44 | 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, | |
45 | nil, 91, 91, nil, 91, 94, 94, 94, 94, 94, | |
46 | 94, 94, 94, 94, 94, 94, 94, nil, 94, 94, | |
47 | nil, 94, 95, 95, 95, 95, 95, 95, 95, 95, | |
48 | 95, 95, 95, 95, nil, 95, 95, 9, 95, 9, | |
49 | nil, 9, nil, nil, 9, 9, 9, 9, 9, 51, | |
50 | nil, 51, 9, 51, nil, nil, 51, 51, 51, 51, | |
51 | 51, 45, nil, 45, 51, 45, nil, nil, 45, 45, | |
52 | 45, 45, 45, 54, nil, 54, nil, 54, nil, nil, | |
53 | 54, 54, 54, 54, 54, 56, nil, 56, nil, 56, | |
54 | nil, nil, 56, 56, 56, 56, 56, 90, nil, nil, | |
55 | 90, nil, nil, nil, 90 ] | |
52 | 56 | |
53 | 57 | racc_action_pointer = [ |
54 | nil, 0, 1, nil, nil, nil, nil, 153, 4, 1, | |
55 | nil, 0, 14, 15, 29, 30, 44, nil, nil, 50, | |
56 | -6, nil, nil, nil, nil, nil, nil, nil, nil, nil, | |
57 | 59, nil, 19, 34, 49, 64, 79, 94, nil, nil, | |
58 | 65, 165, -3, 109, nil, 124, nil, nil, nil, nil, | |
58 | nil, 0, 8, nil, nil, nil, nil, nil, nil, 135, | |
59 | 1, 16, nil, -17, nil, nil, nil, nil, nil, nil, | |
60 | nil, nil, nil, nil, 9, 4, 13, nil, nil, nil, | |
61 | nil, nil, nil, nil, nil, nil, nil, nil, 14, nil, | |
62 | 14, -15, nil, nil, 34, 159, nil, nil, nil, nil, | |
63 | 31, 147, nil, nil, 171, 51, 183, 18, 68, nil, | |
59 | 64 | nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, |
60 | 65 | nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, |
61 | nil, nil, 3, nil, nil, nil, -8, nil, nil, nil, | |
62 | 139, nil ] | |
66 | nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, | |
67 | 183, 85, nil, nil, 102, 119, nil, nil, nil ] | |
63 | 68 | |
64 | 69 | racc_action_default = [ |
65 | -1, -58, -58, -2, -3, -4, -5, -58, -8, -58, | |
66 | -22, -58, -58, -58, -58, -58, -58, 82, -6, -10, | |
67 | -58, -15, -16, -17, -18, -19, -20, -7, -21, -23, | |
68 | -58, -27, -46, -46, -46, -46, -46, -46, -9, -11, | |
69 | -13, -58, -58, -46, -29, -46, -40, -41, -42, -43, | |
70 | -44, -45, -47, -48, -49, -50, -51, -52, -53, -54, | |
71 | -55, -56, -57, -30, -31, -32, -33, -34, -12, -14, | |
72 | -24, -25, -58, -28, -35, -36, -58, -26, -37, -38, | |
73 | -46, -39 ] | |
70 | -1, -79, -79, -2, -3, -4, -5, -6, -7, -79, | |
71 | -11, -79, -31, -79, -45, -46, -47, -48, -49, -50, | |
72 | -51, -52, -53, 99, -79, -13, -79, -20, -21, -22, | |
73 | -23, -24, -25, -26, -27, -28, -10, -29, -79, -32, | |
74 | -33, -79, -39, -40, -67, -79, -8, -9, -12, -14, | |
75 | -16, -79, -30, -34, -79, -67, -79, -79, -67, -61, | |
76 | -62, -63, -64, -65, -66, -68, -69, -70, -71, -72, | |
77 | -73, -74, -75, -76, -77, -78, -43, -44, -15, -17, | |
78 | -18, -19, -35, -36, -37, -38, -41, -42, -54, -55, | |
79 | -79, -67, -56, -58, -67, -67, -57, -59, -60 ] | |
74 | 80 | |
75 | 81 | racc_goto_table = [ |
76 | 28, 74, 1, 18, 44, 63, 64, 65, 66, 67, | |
77 | 3, 4, 5, 6, 7, 73, 39, 42, 70, 78, | |
82 | 15, 24, 38, 88, 28, 37, 57, 1, 3, 5, | |
83 | 6, 7, 9, 49, 53, 13, 92, 83, nil, nil, | |
78 | 84 | nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, |
79 | nil, nil, nil, nil, nil, nil, 81, 69, nil, nil, | |
85 | nil, nil, 52, nil, nil, nil, 96, nil, nil, 97, | |
86 | 98, nil, nil, 79, 76, 82, 80, nil, nil, nil, | |
87 | nil, nil, nil, nil, nil, 84 ] | |
88 | ||
89 | racc_goto_check = [ | |
90 | 18, 7, 13, 22, 10, 12, 17, 1, 2, 3, | |
91 | 4, 5, 6, 9, 15, 19, 23, 17, nil, nil, | |
80 | 92 | nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, |
81 | nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, | |
82 | nil, nil, nil, 77 ] | |
83 | ||
84 | racc_goto_check = [ | |
85 | 11, 18, 1, 7, 15, 15, 15, 15, 15, 15, | |
86 | 2, 3, 4, 5, 6, 15, 9, 13, 14, 19, | |
87 | nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, | |
88 | nil, nil, nil, nil, nil, nil, 18, 7, nil, nil, | |
89 | nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, | |
90 | nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, | |
91 | nil, nil, nil, 11 ] | |
93 | nil, nil, 12, nil, nil, nil, 22, nil, nil, 22, | |
94 | 22, nil, nil, 7, 18, 13, 10, nil, nil, nil, | |
95 | nil, nil, nil, nil, nil, 18 ] | |
92 | 96 | |
93 | 97 | racc_goto_pointer = [ |
94 | nil, 2, 9, 10, 11, 12, 13, -4, nil, -4, | |
95 | nil, -9, nil, -13, -24, -28, nil, nil, -44, -57, | |
96 | nil, nil, nil ] | |
98 | nil, 7, 7, 8, 9, 10, 11, -8, nil, -13, | |
99 | -5, nil, -6, -9, nil, -26, nil, -38, -1, 14, | |
100 | nil, nil, -55, -74, nil, nil, nil ] | |
97 | 101 | |
98 | 102 | racc_goto_default = [ |
99 | nil, nil, nil, nil, nil, 49, nil, nil, 20, nil, | |
100 | 9, nil, 30, nil, nil, 76, 48, 45, nil, nil, | |
101 | 47, 50, 51 ] | |
103 | nil, nil, nil, nil, nil, 62, nil, nil, 26, nil, | |
104 | nil, 11, nil, nil, 40, nil, 41, 90, 43, nil, | |
105 | 61, 58, nil, nil, 60, 63, 64 ] | |
102 | 106 | |
103 | 107 | racc_reduce_table = [ |
104 | 108 | 0, 0, :racc_error, |
105 | 0, 22, :_reduce_none, | |
106 | 2, 22, :_reduce_none, | |
107 | 1, 23, :_reduce_none, | |
108 | 1, 23, :_reduce_none, | |
109 | 1, 23, :_reduce_none, | |
109 | 0, 24, :_reduce_none, | |
110 | 110 | 2, 24, :_reduce_none, |
111 | 2, 27, :_reduce_7, | |
112 | 1, 27, :_reduce_8, | |
113 | 2, 28, :_reduce_9, | |
114 | 1, 28, :_reduce_10, | |
115 | 2, 28, :_reduce_none, | |
111 | 2, 24, :_reduce_none, | |
112 | 1, 25, :_reduce_none, | |
113 | 1, 25, :_reduce_none, | |
114 | 1, 25, :_reduce_none, | |
115 | 1, 25, :_reduce_none, | |
116 | 3, 26, :_reduce_none, | |
117 | 3, 26, :_reduce_none, | |
118 | 2, 29, :_reduce_10, | |
119 | 1, 29, :_reduce_11, | |
116 | 120 | 2, 30, :_reduce_12, |
117 | 121 | 1, 30, :_reduce_13, |
118 | 122 | 2, 30, :_reduce_none, |
119 | 1, 29, :_reduce_15, | |
120 | 1, 29, :_reduce_16, | |
121 | 1, 29, :_reduce_17, | |
122 | 1, 29, :_reduce_18, | |
123 | 1, 29, :_reduce_19, | |
124 | 1, 29, :_reduce_20, | |
125 | 2, 26, :_reduce_none, | |
126 | 1, 31, :_reduce_22, | |
127 | 1, 32, :_reduce_23, | |
128 | 3, 32, :_reduce_none, | |
129 | 1, 35, :_reduce_25, | |
130 | 2, 35, :_reduce_none, | |
131 | 1, 33, :_reduce_27, | |
132 | 2, 34, :_reduce_none, | |
133 | 3, 25, :_reduce_29, | |
134 | 3, 25, :_reduce_30, | |
135 | 3, 25, :_reduce_31, | |
136 | 3, 25, :_reduce_32, | |
137 | 3, 25, :_reduce_33, | |
138 | 3, 25, :_reduce_34, | |
139 | 2, 37, :_reduce_none, | |
140 | 1, 39, :_reduce_36, | |
141 | 2, 39, :_reduce_none, | |
142 | 1, 40, :_reduce_38, | |
143 | 2, 40, :_reduce_none, | |
144 | 1, 38, :_reduce_40, | |
145 | 1, 36, :_reduce_41, | |
123 | 2, 32, :_reduce_15, | |
124 | 1, 32, :_reduce_16, | |
125 | 2, 32, :_reduce_none, | |
126 | 3, 31, :_reduce_18, | |
127 | 3, 31, :_reduce_19, | |
128 | 1, 31, :_reduce_20, | |
129 | 1, 31, :_reduce_21, | |
130 | 1, 33, :_reduce_none, | |
131 | 1, 33, :_reduce_23, | |
132 | 1, 33, :_reduce_none, | |
133 | 1, 33, :_reduce_none, | |
134 | 1, 33, :_reduce_none, | |
135 | 1, 33, :_reduce_none, | |
136 | 1, 33, :_reduce_none, | |
137 | 2, 28, :_reduce_none, | |
138 | 3, 28, :_reduce_none, | |
139 | 1, 34, :_reduce_31, | |
140 | 1, 35, :_reduce_32, | |
146 | 141 | 1, 36, :_reduce_none, |
147 | 1, 36, :_reduce_none, | |
142 | 2, 36, :_reduce_none, | |
143 | 2, 38, :_reduce_none, | |
144 | 3, 37, :_reduce_36, | |
145 | 3, 39, :_reduce_37, | |
146 | 3, 39, :_reduce_38, | |
147 | 1, 39, :_reduce_39, | |
148 | 1, 39, :_reduce_40, | |
149 | 4, 27, :_reduce_41, | |
150 | 4, 27, :_reduce_42, | |
151 | 3, 42, :_reduce_43, | |
152 | 3, 42, :_reduce_44, | |
153 | 1, 42, :_reduce_45, | |
154 | 1, 42, :_reduce_46, | |
155 | 1, 41, :_reduce_none, | |
156 | 1, 41, :_reduce_48, | |
148 | 157 | 1, 41, :_reduce_none, |
149 | 158 | 1, 41, :_reduce_none, |
150 | 0, 43, :_reduce_none, | |
151 | 1, 43, :_reduce_47, | |
152 | 1, 43, :_reduce_48, | |
153 | 1, 43, :_reduce_49, | |
154 | 1, 43, :_reduce_50, | |
155 | 1, 43, :_reduce_51, | |
156 | 1, 43, :_reduce_52, | |
157 | 1, 43, :_reduce_53, | |
158 | 1, 42, :_reduce_54, | |
159 | 1, 42, :_reduce_55, | |
160 | 1, 42, :_reduce_56, | |
161 | 1, 42, :_reduce_57 ] | |
162 | ||
163 | racc_reduce_n = 58 | |
164 | ||
165 | racc_shift_n = 82 | |
159 | 1, 41, :_reduce_none, | |
160 | 1, 41, :_reduce_none, | |
161 | 1, 41, :_reduce_none, | |
162 | 2, 43, :_reduce_none, | |
163 | 1, 45, :_reduce_55, | |
164 | 2, 45, :_reduce_none, | |
165 | 2, 45, :_reduce_none, | |
166 | 1, 46, :_reduce_58, | |
167 | 2, 46, :_reduce_none, | |
168 | 2, 46, :_reduce_none, | |
169 | 1, 44, :_reduce_61, | |
170 | 1, 40, :_reduce_62, | |
171 | 1, 40, :_reduce_none, | |
172 | 1, 40, :_reduce_none, | |
173 | 1, 47, :_reduce_none, | |
174 | 1, 47, :_reduce_none, | |
175 | 0, 49, :_reduce_none, | |
176 | 1, 49, :_reduce_68, | |
177 | 1, 49, :_reduce_69, | |
178 | 1, 49, :_reduce_70, | |
179 | 1, 49, :_reduce_71, | |
180 | 1, 49, :_reduce_72, | |
181 | 1, 49, :_reduce_73, | |
182 | 1, 49, :_reduce_74, | |
183 | 1, 48, :_reduce_75, | |
184 | 1, 48, :_reduce_76, | |
185 | 1, 48, :_reduce_77, | |
186 | 1, 48, :_reduce_78 ] | |
187 | ||
188 | racc_reduce_n = 79 | |
189 | ||
190 | racc_shift_n = 99 | |
166 | 191 | |
167 | 192 | racc_token_table = { |
168 | 193 | false => 0, |
173 | 198 | :STRING_LITERAL_MULTI => 5, |
174 | 199 | :STRING_LITERAL => 6, |
175 | 200 | :DATETIME => 7, |
176 | :INTEGER => 8, | |
177 | :FLOAT => 9, | |
178 | :FLOAT_INF => 10, | |
179 | :FLOAT_NAN => 11, | |
180 | :TRUE => 12, | |
181 | :FALSE => 13, | |
182 | "[" => 14, | |
183 | "]" => 15, | |
184 | "." => 16, | |
185 | "{" => 17, | |
186 | "}" => 18, | |
187 | "," => 19, | |
188 | "=" => 20 } | |
189 | ||
190 | racc_nt_base = 21 | |
201 | :LOCAL_TIME => 8, | |
202 | :INTEGER => 9, | |
203 | :NON_DEC_INTEGER => 10, | |
204 | :FLOAT => 11, | |
205 | :FLOAT_KEYWORD => 12, | |
206 | :BOOLEAN => 13, | |
207 | :NEWLINE => 14, | |
208 | :EOS => 15, | |
209 | "[" => 16, | |
210 | "]" => 17, | |
211 | "." => 18, | |
212 | "{" => 19, | |
213 | "}" => 20, | |
214 | "," => 21, | |
215 | "=" => 22 } | |
216 | ||
217 | racc_nt_base = 23 | |
191 | 218 | |
192 | 219 | racc_use_result_var = true |
193 | 220 | |
216 | 243 | "STRING_LITERAL_MULTI", |
217 | 244 | "STRING_LITERAL", |
218 | 245 | "DATETIME", |
246 | "LOCAL_TIME", | |
219 | 247 | "INTEGER", |
248 | "NON_DEC_INTEGER", | |
220 | 249 | "FLOAT", |
221 | "FLOAT_INF", | |
222 | "FLOAT_NAN", | |
223 | "TRUE", | |
224 | "FALSE", | |
250 | "FLOAT_KEYWORD", | |
251 | "BOOLEAN", | |
252 | "NEWLINE", | |
253 | "EOS", | |
225 | 254 | "\"[\"", |
226 | 255 | "\"]\"", |
227 | 256 | "\".\"", |
239 | 268 | "table_continued", |
240 | 269 | "table_identifier", |
241 | 270 | "table_next", |
271 | "table_identifier_component", | |
242 | 272 | "inline_table_start", |
273 | "inline_table_end", | |
243 | 274 | "inline_continued", |
275 | "inline_assignment", | |
276 | "inline_next", | |
244 | 277 | "inline_assignment_key", |
245 | "inline_assignment_value", | |
246 | "inline_next", | |
247 | 278 | "value", |
279 | "assignment_key_component", | |
280 | "assignment_key", | |
248 | 281 | "array", |
249 | 282 | "start_array", |
250 | 283 | "array_continued", |
271 | 304 | |
272 | 305 | # reduce 6 omitted |
273 | 306 | |
274 | module_eval(<<'.,.,', 'parser.y', 15) | |
275 | def _reduce_7(val, _values, result) | |
307 | # reduce 7 omitted | |
308 | ||
309 | # reduce 8 omitted | |
310 | ||
311 | # reduce 9 omitted | |
312 | ||
313 | module_eval(<<'.,.,', 'parser.y', 18) | |
314 | def _reduce_10(val, _values, result) | |
276 | 315 | @handler.start_(:array_of_tables) |
277 | 316 | result |
278 | 317 | end |
279 | 318 | .,., |
280 | 319 | |
281 | module_eval(<<'.,.,', 'parser.y', 16) | |
282 | def _reduce_8(val, _values, result) | |
320 | module_eval(<<'.,.,', 'parser.y', 19) | |
321 | def _reduce_11(val, _values, result) | |
283 | 322 | @handler.start_(:table) |
284 | 323 | result |
285 | 324 | end |
286 | 325 | .,., |
287 | 326 | |
288 | module_eval(<<'.,.,', 'parser.y', 19) | |
289 | def _reduce_9(val, _values, result) | |
290 | array = @handler.end_(:array_of_tables); @handler.set_context(array, is_array_of_tables: true) | |
291 | result | |
292 | end | |
293 | .,., | |
294 | ||
295 | module_eval(<<'.,.,', 'parser.y', 20) | |
296 | def _reduce_10(val, _values, result) | |
297 | array = @handler.end_(:table); @handler.set_context(array) | |
298 | result | |
299 | end | |
300 | .,., | |
301 | ||
302 | # reduce 11 omitted | |
303 | ||
304 | module_eval(<<'.,.,', 'parser.y', 24) | |
327 | module_eval(<<'.,.,', 'parser.y', 22) | |
305 | 328 | def _reduce_12(val, _values, result) |
306 | 329 | array = @handler.end_(:array_of_tables); @handler.set_context(array, is_array_of_tables: true) |
307 | 330 | result |
308 | 331 | end |
309 | 332 | .,., |
310 | 333 | |
311 | module_eval(<<'.,.,', 'parser.y', 25) | |
334 | module_eval(<<'.,.,', 'parser.y', 23) | |
312 | 335 | def _reduce_13(val, _values, result) |
313 | 336 | array = @handler.end_(:table); @handler.set_context(array) |
314 | 337 | result |
317 | 340 | |
318 | 341 | # reduce 14 omitted |
319 | 342 | |
320 | module_eval(<<'.,.,', 'parser.y', 29) | |
343 | module_eval(<<'.,.,', 'parser.y', 27) | |
321 | 344 | def _reduce_15(val, _values, result) |
322 | @handler.push(val[0]) | |
323 | result | |
324 | end | |
325 | .,., | |
326 | ||
327 | module_eval(<<'.,.,', 'parser.y', 30) | |
345 | array = @handler.end_(:array_of_tables); @handler.set_context(array, is_array_of_tables: true) | |
346 | result | |
347 | end | |
348 | .,., | |
349 | ||
350 | module_eval(<<'.,.,', 'parser.y', 28) | |
328 | 351 | def _reduce_16(val, _values, result) |
329 | @handler.push(val[0]) | |
330 | result | |
331 | end | |
332 | .,., | |
333 | ||
334 | module_eval(<<'.,.,', 'parser.y', 31) | |
335 | def _reduce_17(val, _values, result) | |
336 | @handler.push(val[0]) | |
337 | result | |
338 | end | |
339 | .,., | |
352 | array = @handler.end_(:table); @handler.set_context(array) | |
353 | result | |
354 | end | |
355 | .,., | |
356 | ||
357 | # reduce 17 omitted | |
340 | 358 | |
341 | 359 | module_eval(<<'.,.,', 'parser.y', 32) |
342 | 360 | def _reduce_18(val, _values, result) |
343 | @handler.push(val[0]) | |
361 | @handler.push(val[2]) | |
344 | 362 | result |
345 | 363 | end |
346 | 364 | .,., |
347 | 365 | |
348 | 366 | module_eval(<<'.,.,', 'parser.y', 33) |
349 | 367 | def _reduce_19(val, _values, result) |
368 | val[2].split('.').each { |k| @handler.push(k) } | |
369 | result | |
370 | end | |
371 | .,., | |
372 | ||
373 | module_eval(<<'.,.,', 'parser.y', 35) | |
374 | def _reduce_20(val, _values, result) | |
375 | keys = val[0].split('.') | |
376 | @handler.start_(:table) | |
377 | keys.each { |key| @handler.push(key) } | |
378 | ||
379 | result | |
380 | end | |
381 | .,., | |
382 | ||
383 | module_eval(<<'.,.,', 'parser.y', 39) | |
384 | def _reduce_21(val, _values, result) | |
350 | 385 | @handler.push(val[0]) |
351 | 386 | result |
352 | 387 | end |
353 | 388 | .,., |
354 | 389 | |
355 | module_eval(<<'.,.,', 'parser.y', 34) | |
356 | def _reduce_20(val, _values, result) | |
357 | @handler.push(val[0]) | |
358 | result | |
359 | end | |
360 | .,., | |
361 | ||
362 | # reduce 21 omitted | |
363 | ||
364 | module_eval(<<'.,.,', 'parser.y', 40) | |
365 | def _reduce_22(val, _values, result) | |
366 | @handler.start_(:inline) | |
367 | result | |
368 | end | |
369 | .,., | |
390 | # reduce 22 omitted | |
370 | 391 | |
371 | 392 | module_eval(<<'.,.,', 'parser.y', 43) |
372 | 393 | def _reduce_23(val, _values, result) |
373 | array = @handler.end_(:inline); @handler.push(Hash[*array]) | |
394 | result = StringUtils.replace_escaped_chars(val[0]) | |
374 | 395 | result |
375 | 396 | end |
376 | 397 | .,., |
377 | 398 | |
378 | 399 | # reduce 24 omitted |
379 | 400 | |
380 | module_eval(<<'.,.,', 'parser.y', 48) | |
381 | def _reduce_25(val, _values, result) | |
401 | # reduce 25 omitted | |
402 | ||
403 | # reduce 26 omitted | |
404 | ||
405 | # reduce 27 omitted | |
406 | ||
407 | # reduce 28 omitted | |
408 | ||
409 | # reduce 29 omitted | |
410 | ||
411 | # reduce 30 omitted | |
412 | ||
413 | module_eval(<<'.,.,', 'parser.y', 55) | |
414 | def _reduce_31(val, _values, result) | |
415 | @handler.start_(:inline) | |
416 | result | |
417 | end | |
418 | .,., | |
419 | ||
420 | module_eval(<<'.,.,', 'parser.y', 59) | |
421 | def _reduce_32(val, _values, result) | |
382 | 422 | array = @handler.end_(:inline) |
383 | array.map!.with_index{ |n,i| i.even? ? n.to_sym : n } if @handler.symbolize_keys | |
384 | @handler.push(Hash[*array]) | |
385 | ||
386 | result | |
387 | end | |
388 | .,., | |
389 | ||
390 | # reduce 26 omitted | |
391 | ||
392 | module_eval(<<'.,.,', 'parser.y', 55) | |
393 | def _reduce_27(val, _values, result) | |
394 | @handler.push(val[0]) | |
395 | result | |
396 | end | |
397 | .,., | |
398 | ||
399 | # reduce 28 omitted | |
400 | ||
401 | module_eval(<<'.,.,', 'parser.y', 61) | |
402 | def _reduce_29(val, _values, result) | |
403 | @handler.assign(val[0]) | |
404 | result | |
405 | end | |
406 | .,., | |
407 | ||
408 | module_eval(<<'.,.,', 'parser.y', 62) | |
409 | def _reduce_30(val, _values, result) | |
410 | @handler.assign(val[0]) | |
411 | result | |
412 | end | |
413 | .,., | |
414 | ||
415 | module_eval(<<'.,.,', 'parser.y', 63) | |
416 | def _reduce_31(val, _values, result) | |
417 | @handler.assign(val[0]) | |
418 | result | |
419 | end | |
420 | .,., | |
421 | ||
422 | module_eval(<<'.,.,', 'parser.y', 64) | |
423 | def _reduce_32(val, _values, result) | |
424 | @handler.assign(val[0]) | |
425 | result | |
426 | end | |
427 | .,., | |
428 | ||
429 | module_eval(<<'.,.,', 'parser.y', 65) | |
430 | def _reduce_33(val, _values, result) | |
431 | @handler.assign(val[0]) | |
432 | result | |
433 | end | |
434 | .,., | |
435 | ||
436 | module_eval(<<'.,.,', 'parser.y', 66) | |
437 | def _reduce_34(val, _values, result) | |
438 | @handler.assign(val[0]) | |
439 | result | |
440 | end | |
441 | .,., | |
423 | @handler.push_inline(array) | |
424 | ||
425 | result | |
426 | end | |
427 | .,., | |
428 | ||
429 | # reduce 33 omitted | |
430 | ||
431 | # reduce 34 omitted | |
442 | 432 | |
443 | 433 | # reduce 35 omitted |
444 | 434 | |
445 | 435 | module_eval(<<'.,.,', 'parser.y', 72) |
446 | 436 | def _reduce_36(val, _values, result) |
447 | array = @handler.end_(:array); @handler.push(array) | |
448 | result | |
449 | end | |
450 | .,., | |
451 | ||
452 | # reduce 37 omitted | |
453 | ||
454 | module_eval(<<'.,.,', 'parser.y', 76) | |
437 | keys = @handler.end_(:inline_keys) | |
438 | @handler.push(keys) | |
439 | ||
440 | result | |
441 | end | |
442 | .,., | |
443 | ||
444 | module_eval(<<'.,.,', 'parser.y', 78) | |
445 | def _reduce_37(val, _values, result) | |
446 | @handler.push(val[2]) | |
447 | ||
448 | result | |
449 | end | |
450 | .,., | |
451 | ||
452 | module_eval(<<'.,.,', 'parser.y', 80) | |
455 | 453 | def _reduce_38(val, _values, result) |
456 | array = @handler.end_(:array); @handler.push(array) | |
457 | result | |
458 | end | |
459 | .,., | |
460 | ||
461 | # reduce 39 omitted | |
462 | ||
463 | module_eval(<<'.,.,', 'parser.y', 80) | |
454 | val[2].split('.').each { |k| @handler.push(k) } | |
455 | result | |
456 | end | |
457 | .,., | |
458 | ||
459 | module_eval(<<'.,.,', 'parser.y', 82) | |
460 | def _reduce_39(val, _values, result) | |
461 | keys = val[0].split('.') | |
462 | @handler.start_(:inline_keys) | |
463 | keys.each { |key| @handler.push(key) } | |
464 | ||
465 | result | |
466 | end | |
467 | .,., | |
468 | ||
469 | module_eval(<<'.,.,', 'parser.y', 87) | |
464 | 470 | def _reduce_40(val, _values, result) |
471 | @handler.start_(:inline_keys) | |
472 | @handler.push(val[0]) | |
473 | ||
474 | result | |
475 | end | |
476 | .,., | |
477 | ||
478 | module_eval(<<'.,.,', 'parser.y', 93) | |
479 | def _reduce_41(val, _values, result) | |
480 | keys = @handler.end_(:keys) | |
481 | value = keys.pop | |
482 | @handler.validate_value(value) | |
483 | @handler.push(value) | |
484 | @handler.assign(keys) | |
485 | ||
486 | result | |
487 | end | |
488 | .,., | |
489 | ||
490 | module_eval(<<'.,.,', 'parser.y', 100) | |
491 | def _reduce_42(val, _values, result) | |
492 | keys = @handler.end_(:keys) | |
493 | value = keys.pop | |
494 | @handler.validate_value(value) | |
495 | @handler.push(value) | |
496 | @handler.assign(keys) | |
497 | ||
498 | result | |
499 | end | |
500 | .,., | |
501 | ||
502 | module_eval(<<'.,.,', 'parser.y', 108) | |
503 | def _reduce_43(val, _values, result) | |
504 | @handler.push(val[2]) | |
505 | result | |
506 | end | |
507 | .,., | |
508 | ||
509 | module_eval(<<'.,.,', 'parser.y', 109) | |
510 | def _reduce_44(val, _values, result) | |
511 | val[2].split('.').each { |k| @handler.push(k) } | |
512 | result | |
513 | end | |
514 | .,., | |
515 | ||
516 | module_eval(<<'.,.,', 'parser.y', 111) | |
517 | def _reduce_45(val, _values, result) | |
518 | keys = val[0].split('.') | |
519 | @handler.start_(:keys) | |
520 | keys.each { |key| @handler.push(key) } | |
521 | ||
522 | result | |
523 | end | |
524 | .,., | |
525 | ||
526 | module_eval(<<'.,.,', 'parser.y', 115) | |
527 | def _reduce_46(val, _values, result) | |
528 | @handler.start_(:keys); @handler.push(val[0]) | |
529 | result | |
530 | end | |
531 | .,., | |
532 | ||
533 | # reduce 47 omitted | |
534 | ||
535 | module_eval(<<'.,.,', 'parser.y', 119) | |
536 | def _reduce_48(val, _values, result) | |
537 | result = StringUtils.replace_escaped_chars(val[0]) | |
538 | result | |
539 | end | |
540 | .,., | |
541 | ||
542 | # reduce 49 omitted | |
543 | ||
544 | # reduce 50 omitted | |
545 | ||
546 | # reduce 51 omitted | |
547 | ||
548 | # reduce 52 omitted | |
549 | ||
550 | # reduce 53 omitted | |
551 | ||
552 | # reduce 54 omitted | |
553 | ||
554 | module_eval(<<'.,.,', 'parser.y', 130) | |
555 | def _reduce_55(val, _values, result) | |
556 | array = @handler.end_(:array); @handler.push(array.compact) | |
557 | result | |
558 | end | |
559 | .,., | |
560 | ||
561 | # reduce 56 omitted | |
562 | ||
563 | # reduce 57 omitted | |
564 | ||
565 | module_eval(<<'.,.,', 'parser.y', 135) | |
566 | def _reduce_58(val, _values, result) | |
567 | array = @handler.end_(:array); @handler.push(array.compact) | |
568 | result | |
569 | end | |
570 | .,., | |
571 | ||
572 | # reduce 59 omitted | |
573 | ||
574 | # reduce 60 omitted | |
575 | ||
576 | module_eval(<<'.,.,', 'parser.y', 140) | |
577 | def _reduce_61(val, _values, result) | |
465 | 578 | @handler.start_(:array) |
466 | 579 | result |
467 | 580 | end |
468 | 581 | .,., |
469 | 582 | |
470 | module_eval(<<'.,.,', 'parser.y', 83) | |
471 | def _reduce_41(val, _values, result) | |
583 | module_eval(<<'.,.,', 'parser.y', 143) | |
584 | def _reduce_62(val, _values, result) | |
472 | 585 | @handler.push(val[0]) |
473 | 586 | result |
474 | 587 | end |
475 | 588 | .,., |
476 | 589 | |
477 | # reduce 42 omitted | |
478 | ||
479 | # reduce 43 omitted | |
480 | ||
481 | # reduce 44 omitted | |
482 | ||
483 | # reduce 45 omitted | |
484 | ||
485 | # reduce 46 omitted | |
486 | ||
487 | module_eval(<<'.,.,', 'parser.y', 92) | |
488 | def _reduce_47(val, _values, result) | |
590 | # reduce 63 omitted | |
591 | ||
592 | # reduce 64 omitted | |
593 | ||
594 | # reduce 65 omitted | |
595 | ||
596 | # reduce 66 omitted | |
597 | ||
598 | # reduce 67 omitted | |
599 | ||
600 | module_eval(<<'.,.,', 'parser.y', 152) | |
601 | def _reduce_68(val, _values, result) | |
489 | 602 | result = val[0].to_f |
490 | 603 | result |
491 | 604 | end |
492 | 605 | .,., |
493 | 606 | |
494 | module_eval(<<'.,.,', 'parser.y', 93) | |
495 | def _reduce_48(val, _values, result) | |
496 | result = (val[0][0] == '-' ? -1 : 1) * Float::INFINITY | |
497 | result | |
498 | end | |
499 | .,., | |
500 | ||
501 | module_eval(<<'.,.,', 'parser.y', 94) | |
502 | def _reduce_49(val, _values, result) | |
503 | result = Float::NAN | |
504 | result | |
505 | end | |
506 | .,., | |
507 | ||
508 | module_eval(<<'.,.,', 'parser.y', 95) | |
509 | def _reduce_50(val, _values, result) | |
607 | module_eval(<<'.,.,', 'parser.y', 154) | |
608 | def _reduce_69(val, _values, result) | |
609 | v = val[0] | |
610 | result = if v.end_with?('nan') | |
611 | Float::NAN | |
612 | else | |
613 | (v[0] == '-' ? -1 : 1) * Float::INFINITY | |
614 | end | |
615 | ||
616 | result | |
617 | end | |
618 | .,., | |
619 | ||
620 | module_eval(<<'.,.,', 'parser.y', 161) | |
621 | def _reduce_70(val, _values, result) | |
510 | 622 | result = val[0].to_i |
511 | 623 | result |
512 | 624 | end |
513 | 625 | .,., |
514 | 626 | |
515 | module_eval(<<'.,.,', 'parser.y', 96) | |
516 | def _reduce_51(val, _values, result) | |
517 | result = true | |
518 | result | |
519 | end | |
520 | .,., | |
521 | ||
522 | module_eval(<<'.,.,', 'parser.y', 97) | |
523 | def _reduce_52(val, _values, result) | |
524 | result = false | |
525 | result | |
526 | end | |
527 | .,., | |
528 | ||
529 | module_eval(<<'.,.,', 'parser.y', 98) | |
530 | def _reduce_53(val, _values, result) | |
531 | result = Time.new(*val[0]) | |
532 | result | |
533 | end | |
534 | .,., | |
535 | ||
536 | module_eval(<<'.,.,', 'parser.y', 101) | |
537 | def _reduce_54(val, _values, result) | |
627 | module_eval(<<'.,.,', 'parser.y', 163) | |
628 | def _reduce_71(val, _values, result) | |
629 | base = case val[0][1] | |
630 | when "x" then 16 | |
631 | when "o" then 8 | |
632 | when "b" then 2 | |
633 | end | |
634 | result = val[0].to_i(base) | |
635 | ||
636 | result | |
637 | end | |
638 | .,., | |
639 | ||
640 | module_eval(<<'.,.,', 'parser.y', 170) | |
641 | def _reduce_72(val, _values, result) | |
642 | result = val[0] == 'true' ? true : false | |
643 | result | |
644 | end | |
645 | .,., | |
646 | ||
647 | module_eval(<<'.,.,', 'parser.y', 172) | |
648 | def _reduce_73(val, _values, result) | |
649 | v = val[0] | |
650 | result = if v[6].nil? | |
651 | if v[4].nil? | |
652 | LocalDate.new(v[0], v[1], v[2]) | |
653 | else | |
654 | LocalDateTime.new(v[0], v[1], v[2], v[3] || 0, v[4] || 0, v[5].to_f) | |
655 | end | |
656 | else | |
657 | # Patch for 24:00:00 which Ruby parses | |
658 | if v[3].to_i == 24 && v[4].to_i == 0 && v[5].to_i == 0 | |
659 | v[3] = (v[3].to_i + 1).to_s | |
660 | end | |
661 | ||
662 | Time.new(v[0], v[1], v[2], v[3] || 0, v[4] || 0, v[5].to_f, v[6]) | |
663 | end | |
664 | ||
665 | result | |
666 | end | |
667 | .,., | |
668 | ||
669 | module_eval(<<'.,.,', 'parser.y', 188) | |
670 | def _reduce_74(val, _values, result) | |
671 | result = LocalTime.new(*val[0]) | |
672 | result | |
673 | end | |
674 | .,., | |
675 | ||
676 | module_eval(<<'.,.,', 'parser.y', 191) | |
677 | def _reduce_75(val, _values, result) | |
538 | 678 | result = StringUtils.replace_escaped_chars(StringUtils.multiline_replacements(val[0])) |
539 | 679 | result |
540 | 680 | end |
541 | 681 | .,., |
542 | 682 | |
543 | module_eval(<<'.,.,', 'parser.y', 102) | |
544 | def _reduce_55(val, _values, result) | |
683 | module_eval(<<'.,.,', 'parser.y', 192) | |
684 | def _reduce_76(val, _values, result) | |
545 | 685 | result = StringUtils.replace_escaped_chars(val[0]) |
546 | 686 | result |
547 | 687 | end |
548 | 688 | .,., |
549 | 689 | |
550 | module_eval(<<'.,.,', 'parser.y', 103) | |
551 | def _reduce_56(val, _values, result) | |
690 | module_eval(<<'.,.,', 'parser.y', 193) | |
691 | def _reduce_77(val, _values, result) | |
552 | 692 | result = StringUtils.strip_spaces(val[0]) |
553 | 693 | result |
554 | 694 | end |
555 | 695 | .,., |
556 | 696 | |
557 | module_eval(<<'.,.,', 'parser.y', 104) | |
558 | def _reduce_57(val, _values, result) | |
697 | module_eval(<<'.,.,', 'parser.y', 194) | |
698 | def _reduce_78(val, _values, result) | |
559 | 699 | result = val[0] |
560 | 700 | result |
561 | 701 | end |
6 | 6 | @current = @output |
7 | 7 | @stack = [] |
8 | 8 | @array_names = [] |
9 | @current_table = [] | |
10 | @keys = Keys.new | |
9 | 11 | @symbolize_keys = options[:symbolize_keys] |
10 | 12 | end |
11 | 13 | |
12 | 14 | def set_context(identifiers, is_array_of_tables: false) |
15 | if identifiers.empty? | |
16 | raise ParseError, 'Array needs a name' | |
17 | end | |
18 | ||
19 | @current_table = identifiers.dup | |
20 | @keys.add_table_key identifiers, is_array_of_tables | |
13 | 21 | @current = @output |
14 | 22 | |
15 | 23 | deal_with_array_of_tables(identifiers, is_array_of_tables) do |identifierz| |
16 | 24 | identifierz.each do |k| |
17 | 25 | k = k.to_sym if @symbolize_keys |
18 | 26 | if @current[k].is_a?(Array) |
19 | @current[k] << {} if @current[k].empty? | |
20 | 27 | @current = @current[k].last |
21 | 28 | else |
22 | 29 | @current[k] ||= {} |
27 | 34 | end |
28 | 35 | |
29 | 36 | def deal_with_array_of_tables(identifiers, is_array_of_tables) |
30 | identifiers.map!{|n| n.gsub("\"", '')} | |
31 | 37 | stringified_identifier = identifiers.join('.') |
32 | 38 | |
33 | 39 | if is_array_of_tables |
42 | 48 | if is_array_of_tables |
43 | 49 | last_identifier = last_identifier.to_sym if @symbolize_keys |
44 | 50 | @current[last_identifier] ||= [] |
51 | raise ParseError, "Cannot use key #{last_identifier} for both table and array at once" unless @current[last_identifier].respond_to?(:<<) | |
45 | 52 | @current[last_identifier] << {} |
46 | 53 | @current = @current[last_identifier].last |
47 | 54 | end |
48 | 55 | end |
49 | 56 | |
50 | 57 | def assign(k) |
51 | k = k.to_sym if @symbolize_keys | |
52 | @current[k] = @stack.pop | |
58 | @keys.add_pair_key k, @current_table | |
59 | current = @current | |
60 | while key = k.shift | |
61 | key = key.to_sym if @symbolize_keys | |
62 | current = assign_key_path(current, key, k.empty?) | |
63 | end | |
53 | 64 | end |
54 | 65 | |
55 | 66 | def push(o) |
56 | 67 | @stack << o |
68 | end | |
69 | ||
70 | def push_inline(inline_arrays) | |
71 | merged_inline = {} | |
72 | ||
73 | inline_arrays.each do |inline_array| | |
74 | current = merged_inline | |
75 | value = inline_array.pop | |
76 | inline_array.each_with_index do |inline_key, inline_index| | |
77 | inline_key = inline_key.to_sym if @symbolize_keys | |
78 | last_key = inline_index == inline_array.size - 1 | |
79 | ||
80 | if last_key | |
81 | if current[inline_key].nil? | |
82 | current[inline_key] = value | |
83 | else | |
84 | raise Key::KeyConflict, "Inline key #{inline_key} is already used" | |
85 | end | |
86 | else | |
87 | current[inline_key] ||= {} | |
88 | current = current[inline_key] | |
89 | end | |
90 | end | |
91 | end | |
92 | ||
93 | push(merged_inline) | |
57 | 94 | end |
58 | 95 | |
59 | 96 | def start_(type) |
63 | 100 | def end_(type) |
64 | 101 | array = [] |
65 | 102 | while (value = @stack.pop) != [type] |
66 | raise ParseError, 'Unclosed table' if value.nil? | |
103 | raise ParseError, 'Unclosed table' if @stack.empty? | |
67 | 104 | array.unshift(value) |
68 | 105 | end |
69 | 106 | array |
107 | end | |
108 | ||
109 | def validate_value(value) | |
110 | if value.nil? | |
111 | raise ParseError, 'Value must be present' | |
112 | end | |
113 | end | |
114 | ||
115 | private | |
116 | ||
117 | def assign_key_path(current, key, key_emptied) | |
118 | if key_emptied | |
119 | ||
120 | raise ParseError, "Cannot overwrite value with key #{key}" unless current.kind_of?(Hash) | |
121 | current[key] = @stack.pop | |
122 | return current | |
123 | end | |
124 | current[key] ||= {} | |
125 | current = current[key] | |
126 | current | |
127 | end | |
128 | end | |
129 | ||
130 | class Keys | |
131 | def initialize | |
132 | @keys = {} | |
133 | end | |
134 | ||
135 | def add_table_key(keys, is_array_of_tables = false) | |
136 | self << [keys, [], is_array_of_tables] | |
137 | end | |
138 | ||
139 | def add_pair_key(keys, context) | |
140 | self << [context, keys, false] | |
141 | end | |
142 | ||
143 | def <<(keys) | |
144 | table_keys, pair_keys, is_array_of_tables = keys | |
145 | current = @keys | |
146 | current = append_table_keys(current, table_keys, pair_keys.empty?, is_array_of_tables) | |
147 | append_pair_keys(current, pair_keys, table_keys.empty?, is_array_of_tables) | |
148 | end | |
149 | ||
150 | private | |
151 | ||
152 | def append_table_keys(current, table_keys, pair_keys_empty, is_array_of_tables) | |
153 | table_keys.each_with_index do |key, index| | |
154 | declared = (index == table_keys.length - 1) && pair_keys_empty | |
155 | if index == 0 | |
156 | current = find_or_create_first_table_key(current, key, declared, is_array_of_tables) | |
157 | else | |
158 | current = current << [key, :table, declared, is_array_of_tables] | |
159 | end | |
160 | end | |
161 | ||
162 | current.clear_children if is_array_of_tables | |
163 | current | |
164 | end | |
165 | ||
166 | def find_or_create_first_table_key(current, key, declared, is_array_of_tables) | |
167 | existed = current[key] | |
168 | if existed && existed.type == :pair | |
169 | raise Key::KeyConflict, "Key #{key} is already used as #{existed.type} key" | |
170 | end | |
171 | if existed && existed.declared? && declared && ! is_array_of_tables | |
172 | raise Key::KeyConflict, "Key #{key} is already used" | |
173 | end | |
174 | k = existed || Key.new(key, :table, declared) | |
175 | current[key] = k | |
176 | k | |
177 | end | |
178 | ||
179 | def append_pair_keys(current, pair_keys, table_keys_empty, is_array_of_tables) | |
180 | pair_keys.each_with_index do |key, index| | |
181 | declared = index == pair_keys.length - 1 | |
182 | if index == 0 && table_keys_empty | |
183 | current = find_or_create_first_pair_key(current, key, declared, table_keys_empty) | |
184 | else | |
185 | key = current << [key, :pair, declared, is_array_of_tables] | |
186 | current = key | |
187 | end | |
188 | end | |
189 | end | |
190 | ||
191 | def find_or_create_first_pair_key(current, key, declared, table_keys_empty) | |
192 | existed = current[key] | |
193 | if existed && (existed.type == :pair) && declared && table_keys_empty | |
194 | raise Key::KeyConflict, "Key #{key} is already used" | |
195 | end | |
196 | k = Key.new(key, :pair, declared) | |
197 | current[key] = k | |
198 | k | |
199 | end | |
200 | end | |
201 | ||
202 | class Key | |
203 | class KeyConflict < ParseError; end | |
204 | ||
205 | attr_reader :key, :type | |
206 | ||
207 | def initialize(key, type, declared = false) | |
208 | @key = key | |
209 | @type = type | |
210 | @declared = declared | |
211 | @children = {} | |
212 | end | |
213 | ||
214 | def declared? | |
215 | @declared | |
216 | end | |
217 | ||
218 | def <<(key_type_declared) | |
219 | key, type, declared, is_array_of_tables = key_type_declared | |
220 | existed = @children[key] | |
221 | validate_already_declared_as_different_key(type, declared, existed) | |
222 | validate_already_declared_as_non_array_table(type, is_array_of_tables, declared, existed) | |
223 | validate_path_already_created_as_different_type(type, declared, existed) | |
224 | validate_path_already_declared_as_different_type(type, declared, existed) | |
225 | validate_already_declared_as_same_key(declared, existed) | |
226 | @children[key] = existed || self.class.new(key, type, declared) | |
227 | end | |
228 | ||
229 | def clear_children | |
230 | @children.clear | |
231 | end | |
232 | ||
233 | private | |
234 | ||
235 | def validate_already_declared_as_different_key(type, declared, existed) | |
236 | if existed && existed.declared? && existed.type != type | |
237 | raise KeyConflict, "Key #{existed.key} is already used as #{existed.type} key" | |
238 | end | |
239 | end | |
240 | ||
241 | def validate_already_declared_as_non_array_table(type, is_array_of_tables, declared, existed) | |
242 | if declared && type == :table && existed && existed.declared? && ! is_array_of_tables | |
243 | raise KeyConflict, "Key #{existed.key} is already used" | |
244 | end | |
245 | end | |
246 | ||
247 | def validate_path_already_created_as_different_type(type, declared, existed) | |
248 | if declared && (type == :table) && existed && (existed.type == :pair) && (! existed.declared?) | |
249 | raise KeyConflict, "Key #{existed.key} is already used as #{existed.type} key" | |
250 | end | |
251 | end | |
252 | ||
253 | def validate_path_already_declared_as_different_type(type, declared, existed) | |
254 | if ! declared && (type == :pair) && existed && (existed.type == :pair) && existed.declared? | |
255 | raise KeyConflict, "Key #{key} is already used as #{type} key" | |
256 | end | |
257 | end | |
258 | ||
259 | def validate_already_declared_as_same_key(declared, existed) | |
260 | if existed && ! existed.declared? && declared | |
261 | raise KeyConflict, "Key #{existed.key} is already used as #{existed.type} key" | |
262 | end | |
70 | 263 | end |
71 | 264 | end |
72 | 265 | end |
0 | require 'forwardable' | |
1 | ||
2 | module Tomlrb | |
3 | class LocalDate | |
4 | extend Forwardable | |
5 | ||
6 | def_delegators :@time, :year, :month, :day | |
7 | ||
8 | def initialize(year, month, day) | |
9 | @time = Time.new(year, month, day, 0, 0, 0, '-00:00') | |
10 | end | |
11 | ||
12 | # @param offset see {LocalDateTime#to_time} | |
13 | # @return [Time] 00:00:00 of the date | |
14 | def to_time(offset='-00:00') | |
15 | return @time if offset == '-00:00' | |
16 | Time.new(year, month, day, 0, 0, 0, offset) | |
17 | end | |
18 | ||
19 | def to_s | |
20 | @time.strftime('%F') | |
21 | end | |
22 | ||
23 | def ==(other) | |
24 | other.kind_of?(self.class) && | |
25 | to_time == other.to_time | |
26 | end | |
27 | ||
28 | def inspect | |
29 | "#<#{self.class}: #{to_s}>" | |
30 | end | |
31 | end | |
32 | end |
0 | require 'forwardable' | |
1 | ||
2 | module Tomlrb | |
3 | class LocalDateTime | |
4 | extend Forwardable | |
5 | ||
6 | def_delegators :@time, :year, :month, :day, :hour, :min, :sec, :usec, :nsec | |
7 | ||
8 | def initialize(year, month, day, hour, min, sec) # rubocop:disable Metrics/ParameterLists | |
9 | @time = Time.new(year, month, day, hour, min, sec, '-00:00') | |
10 | @sec = sec | |
11 | end | |
12 | ||
13 | # @param offset [String, Symbol, Numeric, nil] time zone offset. | |
14 | # * when +String+, must be '+HH:MM' format, '-HH:MM' format, 'UTC', 'A'..'I' or 'K'..'Z'. Arguments excluding '+-HH:MM' are supporeted at Ruby >= 2.7.0 | |
15 | # * when +Symbol+, must be +:dst+(for summar time for local) or +:std+(for standard time). | |
16 | # * when +Numeric+, it is time zone offset in second. | |
17 | # * when +nil+, local time zone offset is used. | |
18 | # @return [Time] | |
19 | def to_time(offset='-00:00') | |
20 | return @time if offset == '-00:00' | |
21 | Time.new(year, month, day, hour, min, @sec, offset) | |
22 | end | |
23 | ||
24 | def to_s | |
25 | frac = (@sec - sec) | |
26 | frac_str = frac == 0 ? '' : "#{frac.to_s[1..-1]}" | |
27 | @time.strftime("%FT%T") << frac_str | |
28 | end | |
29 | ||
30 | def ==(other) | |
31 | other.kind_of?(self.class) && | |
32 | to_time == other.to_time | |
33 | end | |
34 | ||
35 | def inspect | |
36 | "#<#{self.class}: #{to_s}>" | |
37 | end | |
38 | end | |
39 | end |
0 | require 'forwardable' | |
1 | ||
2 | module Tomlrb | |
3 | class LocalTime | |
4 | extend Forwardable | |
5 | ||
6 | def_delegators :@time, :hour, :min, :sec, :usec, :nsec | |
7 | ||
8 | def initialize(hour, min, sec) | |
9 | @time = Time.new(0, 1, 1, hour, min, sec, '-00:00') | |
10 | @sec = sec | |
11 | end | |
12 | ||
13 | # @param year [Integer] | |
14 | # @param month [Integer] | |
15 | # @param day [Integer] | |
16 | # @param offset see {LocalDateTime#to_time} | |
17 | # @return [Time] the time of the date specified by params | |
18 | def to_time(year, month, day, offset='-00:00') | |
19 | Time.new(year, month, day, hour, min, @sec, offset) | |
20 | end | |
21 | ||
22 | def to_s | |
23 | frac = (@sec - sec) | |
24 | frac_str = frac == 0 ? '' : "#{frac.to_s[1..-1]}" | |
25 | @time.strftime("%T") << frac_str | |
26 | end | |
27 | ||
28 | def ==(other) | |
29 | other.kind_of?(self.class) && | |
30 | @time == other.to_time(0, 1, 1) | |
31 | end | |
32 | ||
33 | def inspect | |
34 | "#<#{self.class}: #{to_s}>" | |
35 | end | |
36 | end | |
37 | end |
0 | 0 | class Tomlrb::GeneratedParser |
1 | token IDENTIFIER STRING_MULTI STRING_BASIC STRING_LITERAL_MULTI STRING_LITERAL DATETIME INTEGER FLOAT FLOAT_INF FLOAT_NAN TRUE FALSE | |
1 | token IDENTIFIER STRING_MULTI STRING_BASIC STRING_LITERAL_MULTI STRING_LITERAL DATETIME LOCAL_TIME INTEGER NON_DEC_INTEGER FLOAT FLOAT_KEYWORD BOOLEAN NEWLINE EOS | |
2 | 2 | rule |
3 | 3 | expressions |
4 | 4 | | expressions expression |
5 | | expressions EOS | |
5 | 6 | ; |
6 | 7 | expression |
7 | 8 | : table |
8 | 9 | | assignment |
9 | 10 | | inline_table |
11 | | NEWLINE | |
10 | 12 | ; |
11 | 13 | table |
12 | : table_start table_continued | |
14 | : table_start table_continued NEWLINE | |
15 | | table_start table_continued EOS | |
13 | 16 | ; |
14 | 17 | table_start |
15 | 18 | : '[' '[' { @handler.start_(:array_of_tables) } |
26 | 29 | | '.' table_continued |
27 | 30 | ; |
28 | 31 | table_identifier |
29 | : IDENTIFIER { @handler.push(val[0]) } | |
30 | | STRING_BASIC { @handler.push(val[0]) } | |
31 | | STRING_LITERAL { @handler.push(val[0]) } | |
32 | | INTEGER { @handler.push(val[0]) } | |
33 | | TRUE { @handler.push(val[0]) } | |
34 | | FALSE { @handler.push(val[0]) } | |
32 | : table_identifier '.' table_identifier_component { @handler.push(val[2]) } | |
33 | | table_identifier '.' FLOAT { val[2].split('.').each { |k| @handler.push(k) } } | |
34 | | FLOAT { | |
35 | keys = val[0].split('.') | |
36 | @handler.start_(:table) | |
37 | keys.each { |key| @handler.push(key) } | |
38 | } | |
39 | | table_identifier_component { @handler.push(val[0]) } | |
40 | ; | |
41 | table_identifier_component | |
42 | : IDENTIFIER | |
43 | | STRING_BASIC { result = StringUtils.replace_escaped_chars(val[0]) } | |
44 | | STRING_LITERAL | |
45 | | INTEGER | |
46 | | NON_DEC_INTEGER | |
47 | | FLOAT_KEYWORD | |
48 | | BOOLEAN | |
35 | 49 | ; |
36 | 50 | inline_table |
37 | : inline_table_start inline_continued | |
51 | : inline_table_start inline_table_end | |
52 | | inline_table_start inline_continued inline_table_end | |
38 | 53 | ; |
39 | 54 | inline_table_start |
40 | 55 | : '{' { @handler.start_(:inline) } |
41 | 56 | ; |
57 | inline_table_end | |
58 | : '}' { | |
59 | array = @handler.end_(:inline) | |
60 | @handler.push_inline(array) | |
61 | } | |
62 | ; | |
42 | 63 | inline_continued |
43 | : '}' { array = @handler.end_(:inline); @handler.push(Hash[*array]) } | |
44 | | inline_assignment_key inline_assignment_value inline_next | |
64 | : inline_assignment | |
65 | | inline_assignment inline_next | |
45 | 66 | ; |
46 | 67 | inline_next |
47 | : '}' { | |
48 | array = @handler.end_(:inline) | |
49 | array.map!.with_index{ |n,i| i.even? ? n.to_sym : n } if @handler.symbolize_keys | |
50 | @handler.push(Hash[*array]) | |
68 | : ',' inline_continued | |
69 | ; | |
70 | inline_assignment | |
71 | : inline_assignment_key '=' value { | |
72 | keys = @handler.end_(:inline_keys) | |
73 | @handler.push(keys) | |
51 | 74 | } |
52 | | ',' inline_continued | |
53 | 75 | ; |
54 | 76 | inline_assignment_key |
55 | : IDENTIFIER { @handler.push(val[0]) } | |
56 | ; | |
57 | inline_assignment_value | |
58 | : '=' value | |
77 | : inline_assignment_key '.' assignment_key_component { | |
78 | @handler.push(val[2]) | |
79 | } | |
80 | | inline_assignment_key '.' FLOAT { val[2].split('.').each { |k| @handler.push(k) } } | |
81 | | FLOAT { | |
82 | keys = val[0].split('.') | |
83 | @handler.start_(:inline_keys) | |
84 | keys.each { |key| @handler.push(key) } | |
85 | } | |
86 | | assignment_key_component { | |
87 | @handler.start_(:inline_keys) | |
88 | @handler.push(val[0]) | |
89 | } | |
59 | 90 | ; |
60 | 91 | assignment |
61 | : IDENTIFIER '=' value { @handler.assign(val[0]) } | |
62 | | STRING_BASIC '=' value { @handler.assign(val[0]) } | |
63 | | STRING_LITERAL '=' value { @handler.assign(val[0]) } | |
64 | | INTEGER '=' value { @handler.assign(val[0]) } | |
65 | | TRUE '=' value { @handler.assign(val[0]) } | |
66 | | FALSE '=' value { @handler.assign(val[0]) } | |
92 | : assignment_key '=' value EOS { | |
93 | keys = @handler.end_(:keys) | |
94 | value = keys.pop | |
95 | @handler.validate_value(value) | |
96 | @handler.push(value) | |
97 | @handler.assign(keys) | |
98 | } | |
99 | | assignment_key '=' value NEWLINE { | |
100 | keys = @handler.end_(:keys) | |
101 | value = keys.pop | |
102 | @handler.validate_value(value) | |
103 | @handler.push(value) | |
104 | @handler.assign(keys) | |
105 | } | |
106 | ; | |
107 | assignment_key | |
108 | : assignment_key '.' assignment_key_component { @handler.push(val[2]) } | |
109 | | assignment_key '.' FLOAT { val[2].split('.').each { |k| @handler.push(k) } } | |
110 | | FLOAT { | |
111 | keys = val[0].split('.') | |
112 | @handler.start_(:keys) | |
113 | keys.each { |key| @handler.push(key) } | |
114 | } | |
115 | | assignment_key_component { @handler.start_(:keys); @handler.push(val[0]) } | |
116 | ; | |
117 | assignment_key_component | |
118 | : IDENTIFIER | |
119 | | STRING_BASIC { result = StringUtils.replace_escaped_chars(val[0]) } | |
120 | | STRING_LITERAL | |
121 | | INTEGER | |
122 | | NON_DEC_INTEGER | |
123 | | FLOAT_KEYWORD | |
124 | | BOOLEAN | |
67 | 125 | ; |
68 | 126 | array |
69 | 127 | : start_array array_continued |
70 | 128 | ; |
71 | 129 | array_continued |
72 | : ']' { array = @handler.end_(:array); @handler.push(array) } | |
130 | : ']' { array = @handler.end_(:array); @handler.push(array.compact) } | |
73 | 131 | | value array_next |
132 | | NEWLINE array_continued | |
74 | 133 | ; |
75 | 134 | array_next |
76 | : ']' { array = @handler.end_(:array); @handler.push(array) } | |
135 | : ']' { array = @handler.end_(:array); @handler.push(array.compact) } | |
77 | 136 | | ',' array_continued |
137 | | NEWLINE array_continued | |
78 | 138 | ; |
79 | 139 | start_array |
80 | 140 | : '[' { @handler.start_(:array) } |
90 | 150 | ; |
91 | 151 | literal |
92 | 152 | | FLOAT { result = val[0].to_f } |
93 | | FLOAT_INF { result = (val[0][0] == '-' ? -1 : 1) * Float::INFINITY } | |
94 | | FLOAT_NAN { result = Float::NAN } | |
153 | | FLOAT_KEYWORD { | |
154 | v = val[0] | |
155 | result = if v.end_with?('nan') | |
156 | Float::NAN | |
157 | else | |
158 | (v[0] == '-' ? -1 : 1) * Float::INFINITY | |
159 | end | |
160 | } | |
95 | 161 | | INTEGER { result = val[0].to_i } |
96 | | TRUE { result = true } | |
97 | | FALSE { result = false } | |
98 | | DATETIME { result = Time.new(*val[0])} | |
162 | | NON_DEC_INTEGER { | |
163 | base = case val[0][1] | |
164 | when "x" then 16 | |
165 | when "o" then 8 | |
166 | when "b" then 2 | |
167 | end | |
168 | result = val[0].to_i(base) | |
169 | } | |
170 | | BOOLEAN { result = val[0] == 'true' ? true : false } | |
171 | | DATETIME { | |
172 | v = val[0] | |
173 | result = if v[6].nil? | |
174 | if v[4].nil? | |
175 | LocalDate.new(v[0], v[1], v[2]) | |
176 | else | |
177 | LocalDateTime.new(v[0], v[1], v[2], v[3] || 0, v[4] || 0, v[5].to_f) | |
178 | end | |
179 | else | |
180 | # Patch for 24:00:00 which Ruby parses | |
181 | if v[3].to_i == 24 && v[4].to_i == 0 && v[5].to_i == 0 | |
182 | v[3] = (v[3].to_i + 1).to_s | |
183 | end | |
184 | ||
185 | Time.new(v[0], v[1], v[2], v[3] || 0, v[4] || 0, v[5].to_f, v[6]) | |
186 | end | |
187 | } | |
188 | | LOCAL_TIME { result = LocalTime.new(*val[0]) } | |
99 | 189 | ; |
100 | 190 | string |
101 | 191 | : STRING_MULTI { result = StringUtils.replace_escaped_chars(StringUtils.multiline_replacements(val[0])) } |
1 | 1 | |
2 | 2 | module Tomlrb |
3 | 3 | class Scanner |
4 | COMMENT = /#.*/ | |
4 | COMMENT = /#[^\u0000-\u0008\u000A-\u001F\u007F]*/ | |
5 | 5 | IDENTIFIER = /[A-Za-z0-9_-]+/ |
6 | SPACE = /[ \t\r\n]/ | |
7 | STRING_BASIC = /(["])(?:\\?.)*?\1/ | |
8 | STRING_MULTI = /"{3}([\s\S]*?"{3,4})/m | |
9 | STRING_LITERAL = /(['])(?:\\?.)*?\1/ | |
10 | STRING_LITERAL_MULTI = /'{3}([\s\S]*?'{3})/m | |
6 | SPACE = /[ \t]/ | |
7 | NEWLINE = /(?:[ \t]*(?:\r?\n)[ \t]*)+/ | |
8 | STRING_BASIC = /(["])(?:\\?[^\u0000-\u0008\u000A-\u001F\u007F])*?\1/ | |
9 | STRING_MULTI = /"{3}([^\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F]*?(?<!\\)"{3,5})/m | |
10 | STRING_LITERAL = /(['])(?:\\?[^\u0000-\u0008\u000A-\u001F\u007F])*?\1/ | |
11 | STRING_LITERAL_MULTI = /'{3}([^\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F]*?'{3,5})/m | |
11 | 12 | DATETIME = /(-?\d{4})-(\d{2})-(\d{2})(?:(?:t|\s)(\d{2}):(\d{2}):(\d{2}(?:\.\d+)?))?(z|[-+]\d{2}:\d{2})?/i |
12 | FLOAT = /[+-]?(?:[0-9_]+\.[0-9_]*|\d+(?=[eE]))(?:[eE][+-]?[0-9_]+)?/ | |
13 | FLOAT_INF = /[+-]?inf/ | |
14 | FLOAT_NAN = /[+-]?nan/ | |
13 | LOCAL_TIME = /(\d{2}):(\d{2}):(\d{2}(?:\.\d+)?)/ | |
14 | FLOAT = /[+-]?(?:(?:\d|[1-9](?:_?\d)*)\.\d(?:_?\d)*|\d+(?=[eE]))(?:[eE][+-]?[0-9]+(_[0-9])*[0-9]*)?(?!\w)/ | |
15 | FLOAT_KEYWORD = /[+-]?(?:inf|nan)\b/ | |
15 | 16 | INTEGER = /[+-]?([1-9](_?\d)*|0)(?![A-Za-z0-9_-]+)/ |
16 | TRUE = /true/ | |
17 | FALSE = /false/ | |
17 | NON_DEC_INTEGER = /0(?:x[0-9A-Fa-f]+(?:_[0-9A-Fa-f])*[0-9A-Fa-f]*|o[0-7]+(?:_[0-7])*[0-7]*|b[01]+(?:_[01])*[01]*)/ | |
18 | BOOLEAN = /true|false/ | |
19 | SPACED_ARRAY_OF_TABLES_START = /^\[[ \t]+\[(#{IDENTIFIER}|#{STRING_BASIC}|#{STRING_LITERAL}|#{INTEGER}|#{NON_DEC_INTEGER}|#{FLOAT_KEYWORD}|#{BOOLEAN})\]\]$/ | |
20 | SPACED_ARRAY_OF_TABLES_END = /^\[\[(#{IDENTIFIER}|#{STRING_BASIC}|#{STRING_LITERAL}|#{INTEGER}|#{NON_DEC_INTEGER}|#{FLOAT_KEYWORD}|#{BOOLEAN})\][ \t]+\]$/ | |
21 | SPACED_ARRAY_OF_TABLES_BOTH = /^\[[ \t]+\[(#{IDENTIFIER}|#{STRING_BASIC}|#{STRING_LITERAL}|#{INTEGER}|#{NON_DEC_INTEGER}|#{FLOAT_KEYWORD}|#{BOOLEAN})\][ \t]+\]$/ | |
18 | 22 | |
19 | 23 | def initialize(io) |
20 | 24 | @ss = StringScanner.new(io.read) |
25 | @eos = false | |
21 | 26 | end |
22 | 27 | |
23 | 28 | def next_token |
24 | return if @ss.eos? | |
25 | ||
26 | 29 | case |
30 | when @ss.scan(NEWLINE) then [:NEWLINE, nil] | |
31 | when @ss.scan(SPACED_ARRAY_OF_TABLES_START) then raise ParseError.new("Array of tables has spaces in starting brackets") | |
32 | when @ss.scan(SPACED_ARRAY_OF_TABLES_END) then raise ParseError.new("Array of tables has spaces in ending brackets") | |
33 | when @ss.scan(SPACED_ARRAY_OF_TABLES_BOTH) then raise ParseError.new("Array of tables has spaces in starting and ending brackets") | |
27 | 34 | when @ss.scan(SPACE) then next_token |
28 | 35 | when @ss.scan(COMMENT) then next_token |
29 | 36 | when @ss.scan(DATETIME) then process_datetime |
37 | when @ss.scan(LOCAL_TIME) then process_local_time | |
30 | 38 | when text = @ss.scan(STRING_MULTI) then [:STRING_MULTI, text[3..-4]] |
31 | 39 | when text = @ss.scan(STRING_BASIC) then [:STRING_BASIC, text[1..-2]] |
32 | 40 | when text = @ss.scan(STRING_LITERAL_MULTI) then [:STRING_LITERAL_MULTI, text[3..-4]] |
33 | 41 | when text = @ss.scan(STRING_LITERAL) then [:STRING_LITERAL, text[1..-2]] |
34 | 42 | when text = @ss.scan(FLOAT) then [:FLOAT, text] |
35 | when text = @ss.scan(FLOAT_INF) then [:FLOAT_INF, text] | |
36 | when text = @ss.scan(FLOAT_NAN) then [:FLOAT_NAN, text] | |
43 | when text = @ss.scan(FLOAT_KEYWORD) then [:FLOAT_KEYWORD, text] | |
37 | 44 | when text = @ss.scan(INTEGER) then [:INTEGER, text] |
38 | when text = @ss.scan(TRUE) then [:TRUE, text] | |
39 | when text = @ss.scan(FALSE) then [:FALSE, text] | |
45 | when text = @ss.scan(NON_DEC_INTEGER) then [:NON_DEC_INTEGER, text] | |
46 | when text = @ss.scan(BOOLEAN) then [:BOOLEAN, text] | |
40 | 47 | when text = @ss.scan(IDENTIFIER) then [:IDENTIFIER, text] |
41 | else | |
42 | x = @ss.getch | |
43 | [x, x] | |
48 | when @ss.eos? then process_eos | |
49 | else x = @ss.getch; [x, x] | |
44 | 50 | end |
45 | 51 | end |
46 | 52 | |
47 | 53 | def process_datetime |
48 | if @ss[7].nil? | |
49 | offset = '+00:00' | |
50 | else | |
51 | offset = @ss[7].gsub('Z', '+00:00') | |
54 | if @ss[7] | |
55 | offset = @ss[7].gsub(/[zZ]/, '+00:00') | |
52 | 56 | end |
53 | args = [@ss[1], @ss[2], @ss[3], @ss[4] || 0, @ss[5] || 0, @ss[6].to_f, offset] | |
57 | args = [@ss[1], @ss[2], @ss[3], @ss[4], @ss[5], @ss[6], offset] | |
54 | 58 | [:DATETIME, args] |
59 | end | |
60 | ||
61 | def process_local_time | |
62 | args = [@ss[1], @ss[2], @ss[3].to_f] | |
63 | [:LOCAL_TIME, args] | |
64 | end | |
65 | ||
66 | def process_eos | |
67 | return if @eos | |
68 | ||
69 | @eos = true | |
70 | [:EOS, nil] | |
55 | 71 | end |
56 | 72 | end |
57 | 73 | end |
11 | 11 | }.freeze |
12 | 12 | |
13 | 13 | def self.multiline_replacements(str) |
14 | strip_spaces(str).gsub(/\\\n\s+/, '') | |
14 | strip_spaces(str).gsub(/\\+\s*\n\s*/) {|matched| | |
15 | if matched.match(/\\+/)[0].length.odd? | |
16 | matched.gsub(/\\\s*\n\s*/, '') | |
17 | else | |
18 | matched | |
19 | end | |
20 | } | |
15 | 21 | end |
16 | 22 | |
17 | 23 | def self.replace_escaped_chars(str) |
0 | 0 | require 'time' |
1 | 1 | require 'stringio' |
2 | 2 | require "tomlrb/version" |
3 | require 'tomlrb/local_date_time' | |
4 | require 'tomlrb/local_date' | |
5 | require 'tomlrb/local_time' | |
3 | 6 | require 'tomlrb/string_utils' |
4 | 7 | require "tomlrb/scanner" |
5 | 8 | require "tomlrb/parser" |
1 | 1 | # This file has been automatically generated by gem2tgz # |
2 | 2 | ######################################################### |
3 | 3 | # -*- encoding: utf-8 -*- |
4 | # stub: tomlrb 1.3.0 ruby lib | |
4 | # stub: tomlrb 2.0.3 ruby lib | |
5 | 5 | |
6 | 6 | Gem::Specification.new do |s| |
7 | 7 | s.name = "tomlrb".freeze |
8 | s.version = "1.3.0" | |
8 | s.version = "2.0.3" | |
9 | 9 | |
10 | 10 | s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version= |
11 | 11 | s.require_paths = ["lib".freeze] |
12 | 12 | s.authors = ["Francois Bernier".freeze] |
13 | s.date = "2020-03-19" | |
13 | s.date = "2022-05-28" | |
14 | 14 | s.description = "A racc based toml parser".freeze |
15 | 15 | s.email = ["frankbernier@gmail.com".freeze] |
16 | s.files = ["LICENSE.txt".freeze, "lib/tomlrb.rb".freeze, "lib/tomlrb/generated_parser.rb".freeze, "lib/tomlrb/handler.rb".freeze, "lib/tomlrb/parser.rb".freeze, "lib/tomlrb/parser.y".freeze, "lib/tomlrb/scanner.rb".freeze, "lib/tomlrb/string_utils.rb".freeze, "lib/tomlrb/version.rb".freeze] | |
16 | s.files = ["LICENSE.txt".freeze, "lib/tomlrb.rb".freeze, "lib/tomlrb/generated_parser.rb".freeze, "lib/tomlrb/handler.rb".freeze, "lib/tomlrb/local_date.rb".freeze, "lib/tomlrb/local_date_time.rb".freeze, "lib/tomlrb/local_time.rb".freeze, "lib/tomlrb/parser.rb".freeze, "lib/tomlrb/parser.y".freeze, "lib/tomlrb/scanner.rb".freeze, "lib/tomlrb/string_utils.rb".freeze, "lib/tomlrb/version.rb".freeze] | |
17 | 17 | s.homepage = "https://github.com/fbernier/tomlrb".freeze |
18 | 18 | s.licenses = ["MIT".freeze] |
19 | 19 | s.required_ruby_version = Gem::Requirement.new(">= 2.0".freeze) |
20 | s.rubygems_version = "2.5.2.1".freeze | |
20 | s.rubygems_version = "3.2.5".freeze | |
21 | 21 | s.summary = "A racc based toml parser".freeze |
22 | ||
23 | if s.respond_to? :specification_version then | |
24 | s.specification_version = 4 | |
25 | end | |
26 | ||
27 | if s.respond_to? :add_runtime_dependency then | |
28 | s.add_development_dependency(%q<psych>.freeze, ["~> 4"]) | |
29 | else | |
30 | s.add_dependency(%q<psych>.freeze, ["~> 4"]) | |
31 | end | |
22 | 32 | end |