aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/zclconf/go-cty/cty/function/stdlib/format_fsm.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/zclconf/go-cty/cty/function/stdlib/format_fsm.go')
-rw-r--r--vendor/github.com/zclconf/go-cty/cty/function/stdlib/format_fsm.go358
1 files changed, 358 insertions, 0 deletions
diff --git a/vendor/github.com/zclconf/go-cty/cty/function/stdlib/format_fsm.go b/vendor/github.com/zclconf/go-cty/cty/function/stdlib/format_fsm.go
new file mode 100644
index 0000000..86876ba
--- /dev/null
+++ b/vendor/github.com/zclconf/go-cty/cty/function/stdlib/format_fsm.go
@@ -0,0 +1,358 @@
1// line 1 "format_fsm.rl"
2// This file is generated from format_fsm.rl. DO NOT EDIT.
3
4// line 5 "format_fsm.rl"
5
6package stdlib
7
8import (
9 "bytes"
10 "fmt"
11 "unicode/utf8"
12
13 "github.com/zclconf/go-cty/cty"
14)
15
16// line 20 "format_fsm.go"
17var _formatfsm_actions []byte = []byte{
18 0, 1, 0, 1, 1, 1, 2, 1, 4,
19 1, 5, 1, 6, 1, 7, 1, 8,
20 1, 9, 1, 10, 1, 11, 1, 14,
21 1, 16, 1, 17, 1, 18, 2, 3,
22 4, 2, 12, 10, 2, 12, 16, 2,
23 12, 18, 2, 13, 14, 2, 15, 10,
24 2, 15, 18,
25}
26
27var _formatfsm_key_offsets []byte = []byte{
28 0, 0, 14, 27, 34, 36, 39, 43,
29 51,
30}
31
32var _formatfsm_trans_keys []byte = []byte{
33 32, 35, 37, 43, 45, 46, 48, 91,
34 49, 57, 65, 90, 97, 122, 32, 35,
35 43, 45, 46, 48, 91, 49, 57, 65,
36 90, 97, 122, 91, 48, 57, 65, 90,
37 97, 122, 49, 57, 93, 48, 57, 65,
38 90, 97, 122, 46, 91, 48, 57, 65,
39 90, 97, 122, 37,
40}
41
42var _formatfsm_single_lengths []byte = []byte{
43 0, 8, 7, 1, 0, 1, 0, 2,
44 1,
45}
46
47var _formatfsm_range_lengths []byte = []byte{
48 0, 3, 3, 3, 1, 1, 2, 3,
49 0,
50}
51
52var _formatfsm_index_offsets []byte = []byte{
53 0, 0, 12, 23, 28, 30, 33, 36,
54 42,
55}
56
57var _formatfsm_indicies []byte = []byte{
58 1, 2, 3, 4, 5, 6, 7, 10,
59 8, 9, 9, 0, 1, 2, 4, 5,
60 6, 7, 10, 8, 9, 9, 0, 13,
61 11, 12, 12, 0, 14, 0, 15, 14,
62 0, 9, 9, 0, 16, 19, 17, 18,
63 18, 0, 20, 3,
64}
65
66var _formatfsm_trans_targs []byte = []byte{
67 0, 2, 2, 8, 2, 2, 3, 2,
68 7, 8, 4, 3, 8, 4, 5, 6,
69 3, 7, 8, 4, 1,
70}
71
72var _formatfsm_trans_actions []byte = []byte{
73 7, 17, 9, 3, 15, 13, 25, 11,
74 43, 29, 19, 27, 49, 46, 21, 0,
75 37, 23, 40, 34, 1,
76}
77
78var _formatfsm_eof_actions []byte = []byte{
79 0, 31, 31, 31, 31, 31, 31, 31,
80 5,
81}
82
83const formatfsm_start int = 8
84const formatfsm_first_final int = 8
85const formatfsm_error int = 0
86
87const formatfsm_en_main int = 8
88
89// line 19 "format_fsm.rl"
90
91func formatFSM(format string, a []cty.Value) (string, error) {
92 var buf bytes.Buffer
93 data := format
94 nextArg := 1 // arg numbers are 1-based
95 var verb formatVerb
96
97 // line 153 "format_fsm.rl"
98
99 // Ragel state
100 p := 0 // "Pointer" into data
101 pe := len(data) // End-of-data "pointer"
102 cs := 0 // current state (will be initialized by ragel-generated code)
103 ts := 0
104 te := 0
105 eof := pe
106
107 // Keep Go compiler happy even if generated code doesn't use these
108 _ = ts
109 _ = te
110 _ = eof
111
112 // line 121 "format_fsm.go"
113 {
114 cs = formatfsm_start
115 }
116
117 // line 126 "format_fsm.go"
118 {
119 var _klen int
120 var _trans int
121 var _acts int
122 var _nacts uint
123 var _keys int
124 if p == pe {
125 goto _test_eof
126 }
127 if cs == 0 {
128 goto _out
129 }
130 _resume:
131 _keys = int(_formatfsm_key_offsets[cs])
132 _trans = int(_formatfsm_index_offsets[cs])
133
134 _klen = int(_formatfsm_single_lengths[cs])
135 if _klen > 0 {
136 _lower := int(_keys)
137 var _mid int
138 _upper := int(_keys + _klen - 1)
139 for {
140 if _upper < _lower {
141 break
142 }
143
144 _mid = _lower + ((_upper - _lower) >> 1)
145 switch {
146 case data[p] < _formatfsm_trans_keys[_mid]:
147 _upper = _mid - 1
148 case data[p] > _formatfsm_trans_keys[_mid]:
149 _lower = _mid + 1
150 default:
151 _trans += int(_mid - int(_keys))
152 goto _match
153 }
154 }
155 _keys += _klen
156 _trans += _klen
157 }
158
159 _klen = int(_formatfsm_range_lengths[cs])
160 if _klen > 0 {
161 _lower := int(_keys)
162 var _mid int
163 _upper := int(_keys + (_klen << 1) - 2)
164 for {
165 if _upper < _lower {
166 break
167 }
168
169 _mid = _lower + (((_upper - _lower) >> 1) & ^1)
170 switch {
171 case data[p] < _formatfsm_trans_keys[_mid]:
172 _upper = _mid - 2
173 case data[p] > _formatfsm_trans_keys[_mid+1]:
174 _lower = _mid + 2
175 default:
176 _trans += int((_mid - int(_keys)) >> 1)
177 goto _match
178 }
179 }
180 _trans += _klen
181 }
182
183 _match:
184 _trans = int(_formatfsm_indicies[_trans])
185 cs = int(_formatfsm_trans_targs[_trans])
186
187 if _formatfsm_trans_actions[_trans] == 0 {
188 goto _again
189 }
190
191 _acts = int(_formatfsm_trans_actions[_trans])
192 _nacts = uint(_formatfsm_actions[_acts])
193 _acts++
194 for ; _nacts > 0; _nacts-- {
195 _acts++
196 switch _formatfsm_actions[_acts-1] {
197 case 0:
198 // line 29 "format_fsm.rl"
199
200 verb = formatVerb{
201 ArgNum: nextArg,
202 Prec: -1,
203 Width: -1,
204 }
205 ts = p
206
207 case 1:
208 // line 38 "format_fsm.rl"
209
210 buf.WriteByte(data[p])
211
212 case 4:
213 // line 49 "format_fsm.rl"
214
215 // We'll try to slurp a whole UTF-8 sequence here, to give the user
216 // better feedback.
217 r, _ := utf8.DecodeRuneInString(data[p:])
218 return buf.String(), fmt.Errorf("unrecognized format character %q at offset %d", r, p)
219
220 case 5:
221 // line 56 "format_fsm.rl"
222
223 verb.Sharp = true
224
225 case 6:
226 // line 59 "format_fsm.rl"
227
228 verb.Zero = true
229
230 case 7:
231 // line 62 "format_fsm.rl"
232
233 verb.Minus = true
234
235 case 8:
236 // line 65 "format_fsm.rl"
237
238 verb.Plus = true
239
240 case 9:
241 // line 68 "format_fsm.rl"
242
243 verb.Space = true
244
245 case 10:
246 // line 72 "format_fsm.rl"
247
248 verb.ArgNum = 0
249
250 case 11:
251 // line 75 "format_fsm.rl"
252
253 verb.ArgNum = (10 * verb.ArgNum) + (int(data[p]) - '0')
254
255 case 12:
256 // line 79 "format_fsm.rl"
257
258 verb.HasWidth = true
259
260 case 13:
261 // line 82 "format_fsm.rl"
262
263 verb.Width = 0
264
265 case 14:
266 // line 85 "format_fsm.rl"
267
268 verb.Width = (10 * verb.Width) + (int(data[p]) - '0')
269
270 case 15:
271 // line 89 "format_fsm.rl"
272
273 verb.HasPrec = true
274
275 case 16:
276 // line 92 "format_fsm.rl"
277
278 verb.Prec = 0
279
280 case 17:
281 // line 95 "format_fsm.rl"
282
283 verb.Prec = (10 * verb.Prec) + (int(data[p]) - '0')
284
285 case 18:
286 // line 99 "format_fsm.rl"
287
288 verb.Mode = rune(data[p])
289 te = p + 1
290 verb.Raw = data[ts:te]
291 verb.Offset = ts
292
293 err := formatAppend(&verb, &buf, a)
294 if err != nil {
295 return buf.String(), err
296 }
297 nextArg = verb.ArgNum + 1
298
299 // line 324 "format_fsm.go"
300 }
301 }
302
303 _again:
304 if cs == 0 {
305 goto _out
306 }
307 p++
308 if p != pe {
309 goto _resume
310 }
311 _test_eof:
312 {
313 }
314 if p == eof {
315 __acts := _formatfsm_eof_actions[cs]
316 __nacts := uint(_formatfsm_actions[__acts])
317 __acts++
318 for ; __nacts > 0; __nacts-- {
319 __acts++
320 switch _formatfsm_actions[__acts-1] {
321 case 2:
322 // line 42 "format_fsm.rl"
323
324 case 3:
325 // line 45 "format_fsm.rl"
326
327 return buf.String(), fmt.Errorf("invalid format string starting at offset %d", p)
328
329 case 4:
330 // line 49 "format_fsm.rl"
331
332 // We'll try to slurp a whole UTF-8 sequence here, to give the user
333 // better feedback.
334 r, _ := utf8.DecodeRuneInString(data[p:])
335 return buf.String(), fmt.Errorf("unrecognized format character %q at offset %d", r, p)
336
337 // line 363 "format_fsm.go"
338 }
339 }
340 }
341
342 _out:
343 {
344 }
345 }
346
347 // line 171 "format_fsm.rl"
348
349 // If we fall out here without being in a final state then we've
350 // encountered something that the scanner can't match, which should
351 // be impossible (the scanner matches all bytes _somehow_) but we'll
352 // flag it anyway rather than just losing data from the end.
353 if cs < formatfsm_first_final {
354 return buf.String(), fmt.Errorf("extraneous characters beginning at offset %i", p)
355 }
356
357 return buf.String(), nil
358}