1 // line 1 "format_fsm.rl"
2 // This file is generated from format_fsm.rl. DO NOT EDIT.
4 // line 5 "format_fsm.rl"
13 "github.com/zclconf/go-cty/cty"
14 "github.com/zclconf/go-cty/cty/function"
17 // line 21 "format_fsm.go"
18 var _formatfsm_actions []byte = []byte{
19 0, 1, 0, 1, 1, 1, 2, 1, 4,
20 1, 5, 1, 6, 1, 7, 1, 8,
21 1, 9, 1, 10, 1, 11, 1, 14,
22 1, 16, 1, 17, 1, 18, 2, 3,
23 4, 2, 12, 10, 2, 12, 16, 2,
24 12, 18, 2, 13, 14, 2, 15, 10,
28 var _formatfsm_key_offsets []byte = []byte{
29 0, 0, 14, 27, 34, 36, 39, 43,
33 var _formatfsm_trans_keys []byte = []byte{
34 32, 35, 37, 43, 45, 46, 48, 91,
35 49, 57, 65, 90, 97, 122, 32, 35,
36 43, 45, 46, 48, 91, 49, 57, 65,
37 90, 97, 122, 91, 48, 57, 65, 90,
38 97, 122, 49, 57, 93, 48, 57, 65,
39 90, 97, 122, 46, 91, 48, 57, 65,
43 var _formatfsm_single_lengths []byte = []byte{
44 0, 8, 7, 1, 0, 1, 0, 2,
48 var _formatfsm_range_lengths []byte = []byte{
49 0, 3, 3, 3, 1, 1, 2, 3,
53 var _formatfsm_index_offsets []byte = []byte{
54 0, 0, 12, 23, 28, 30, 33, 36,
58 var _formatfsm_indicies []byte = []byte{
59 1, 2, 3, 4, 5, 6, 7, 10,
60 8, 9, 9, 0, 1, 2, 4, 5,
61 6, 7, 10, 8, 9, 9, 0, 13,
62 11, 12, 12, 0, 14, 0, 15, 14,
63 0, 9, 9, 0, 16, 19, 17, 18,
67 var _formatfsm_trans_targs []byte = []byte{
68 0, 2, 2, 8, 2, 2, 3, 2,
69 7, 8, 4, 3, 8, 4, 5, 6,
73 var _formatfsm_trans_actions []byte = []byte{
74 7, 17, 9, 3, 15, 13, 25, 11,
75 43, 29, 19, 27, 49, 46, 21, 0,
79 var _formatfsm_eof_actions []byte = []byte{
80 0, 31, 31, 31, 31, 31, 31, 31,
84 const formatfsm_start int = 8
85 const formatfsm_first_final int = 8
86 const formatfsm_error int = 0
88 const formatfsm_en_main int = 8
90 // line 20 "format_fsm.rl"
92 func formatFSM(format string, a []cty.Value) (string, error) {
95 nextArg := 1 // arg numbers are 1-based
97 highestArgIdx := 0 // zero means "none", since arg numbers are 1-based
99 // line 159 "format_fsm.rl"
102 p := 0 // "Pointer" into data
103 pe := len(data) // End-of-data "pointer"
104 cs := 0 // current state (will be initialized by ragel-generated code)
109 // Keep Go compiler happy even if generated code doesn't use these
114 // line 123 "format_fsm.go"
119 // line 128 "format_fsm.go"
133 _keys = int(_formatfsm_key_offsets[cs])
134 _trans = int(_formatfsm_index_offsets[cs])
136 _klen = int(_formatfsm_single_lengths[cs])
140 _upper := int(_keys + _klen - 1)
146 _mid = _lower + ((_upper - _lower) >> 1)
148 case data[p] < _formatfsm_trans_keys[_mid]:
150 case data[p] > _formatfsm_trans_keys[_mid]:
153 _trans += int(_mid - int(_keys))
161 _klen = int(_formatfsm_range_lengths[cs])
165 _upper := int(_keys + (_klen << 1) - 2)
171 _mid = _lower + (((_upper - _lower) >> 1) & ^1)
173 case data[p] < _formatfsm_trans_keys[_mid]:
175 case data[p] > _formatfsm_trans_keys[_mid+1]:
178 _trans += int((_mid - int(_keys)) >> 1)
186 _trans = int(_formatfsm_indicies[_trans])
187 cs = int(_formatfsm_trans_targs[_trans])
189 if _formatfsm_trans_actions[_trans] == 0 {
193 _acts = int(_formatfsm_trans_actions[_trans])
194 _nacts = uint(_formatfsm_actions[_acts])
196 for ; _nacts > 0; _nacts-- {
198 switch _formatfsm_actions[_acts-1] {
200 // line 31 "format_fsm.rl"
210 // line 40 "format_fsm.rl"
212 buf.WriteByte(data[p])
215 // line 51 "format_fsm.rl"
217 // We'll try to slurp a whole UTF-8 sequence here, to give the user
219 r, _ := utf8.DecodeRuneInString(data[p:])
220 return buf.String(), fmt.Errorf("unrecognized format character %q at offset %d", r, p)
223 // line 58 "format_fsm.rl"
228 // line 61 "format_fsm.rl"
233 // line 64 "format_fsm.rl"
238 // line 67 "format_fsm.rl"
243 // line 70 "format_fsm.rl"
248 // line 74 "format_fsm.rl"
253 // line 77 "format_fsm.rl"
255 verb.ArgNum = (10 * verb.ArgNum) + (int(data[p]) - '0')
258 // line 81 "format_fsm.rl"
263 // line 84 "format_fsm.rl"
268 // line 87 "format_fsm.rl"
270 verb.Width = (10 * verb.Width) + (int(data[p]) - '0')
273 // line 91 "format_fsm.rl"
278 // line 94 "format_fsm.rl"
283 // line 97 "format_fsm.rl"
285 verb.Prec = (10 * verb.Prec) + (int(data[p]) - '0')
288 // line 101 "format_fsm.rl"
290 verb.Mode = rune(data[p])
292 verb.Raw = data[ts:te]
295 if verb.ArgNum > highestArgIdx {
296 highestArgIdx = verb.ArgNum
299 err := formatAppend(&verb, &buf, a)
301 return buf.String(), err
303 nextArg = verb.ArgNum + 1
305 // line 330 "format_fsm.go"
321 __acts := _formatfsm_eof_actions[cs]
322 __nacts := uint(_formatfsm_actions[__acts])
324 for ; __nacts > 0; __nacts-- {
326 switch _formatfsm_actions[__acts-1] {
328 // line 44 "format_fsm.rl"
331 // line 47 "format_fsm.rl"
333 return buf.String(), fmt.Errorf("invalid format string starting at offset %d", p)
336 // line 51 "format_fsm.rl"
338 // We'll try to slurp a whole UTF-8 sequence here, to give the user
340 r, _ := utf8.DecodeRuneInString(data[p:])
341 return buf.String(), fmt.Errorf("unrecognized format character %q at offset %d", r, p)
343 // line 369 "format_fsm.go"
353 // line 177 "format_fsm.rl"
355 // If we fall out here without being in a final state then we've
356 // encountered something that the scanner can't match, which should
357 // be impossible (the scanner matches all bytes _somehow_) but we'll
358 // flag it anyway rather than just losing data from the end.
359 if cs < formatfsm_first_final {
360 return buf.String(), fmt.Errorf("extraneous characters beginning at offset %d", p)
363 if highestArgIdx < len(a) {
364 // Extraneous args are an error, to more easily detect mistakes
365 firstBad := highestArgIdx + 1
366 if highestArgIdx == 0 {
367 // Custom error message for this case
368 return buf.String(), function.NewArgErrorf(firstBad, "too many arguments; no verbs in format string")
370 return buf.String(), function.NewArgErrorf(firstBad, "too many arguments; only %d used by format string", highestArgIdx)
373 return buf.String(), nil