diff options
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.go | 74 |
1 files changed, 45 insertions, 29 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 index 86876ba..32b1ac9 100644 --- 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 | |||
@@ -11,9 +11,10 @@ import ( | |||
11 | "unicode/utf8" | 11 | "unicode/utf8" |
12 | 12 | ||
13 | "github.com/zclconf/go-cty/cty" | 13 | "github.com/zclconf/go-cty/cty" |
14 | "github.com/zclconf/go-cty/cty/function" | ||
14 | ) | 15 | ) |
15 | 16 | ||
16 | // line 20 "format_fsm.go" | 17 | // line 21 "format_fsm.go" |
17 | var _formatfsm_actions []byte = []byte{ | 18 | var _formatfsm_actions []byte = []byte{ |
18 | 0, 1, 0, 1, 1, 1, 2, 1, 4, | 19 | 0, 1, 0, 1, 1, 1, 2, 1, 4, |
19 | 1, 5, 1, 6, 1, 7, 1, 8, | 20 | 1, 5, 1, 6, 1, 7, 1, 8, |
@@ -86,15 +87,16 @@ const formatfsm_error int = 0 | |||
86 | 87 | ||
87 | const formatfsm_en_main int = 8 | 88 | const formatfsm_en_main int = 8 |
88 | 89 | ||
89 | // line 19 "format_fsm.rl" | 90 | // line 20 "format_fsm.rl" |
90 | 91 | ||
91 | func formatFSM(format string, a []cty.Value) (string, error) { | 92 | func formatFSM(format string, a []cty.Value) (string, error) { |
92 | var buf bytes.Buffer | 93 | var buf bytes.Buffer |
93 | data := format | 94 | data := format |
94 | nextArg := 1 // arg numbers are 1-based | 95 | nextArg := 1 // arg numbers are 1-based |
95 | var verb formatVerb | 96 | var verb formatVerb |
97 | highestArgIdx := 0 // zero means "none", since arg numbers are 1-based | ||
96 | 98 | ||
97 | // line 153 "format_fsm.rl" | 99 | // line 159 "format_fsm.rl" |
98 | 100 | ||
99 | // Ragel state | 101 | // Ragel state |
100 | p := 0 // "Pointer" into data | 102 | p := 0 // "Pointer" into data |
@@ -109,12 +111,12 @@ func formatFSM(format string, a []cty.Value) (string, error) { | |||
109 | _ = te | 111 | _ = te |
110 | _ = eof | 112 | _ = eof |
111 | 113 | ||
112 | // line 121 "format_fsm.go" | 114 | // line 123 "format_fsm.go" |
113 | { | 115 | { |
114 | cs = formatfsm_start | 116 | cs = formatfsm_start |
115 | } | 117 | } |
116 | 118 | ||
117 | // line 126 "format_fsm.go" | 119 | // line 128 "format_fsm.go" |
118 | { | 120 | { |
119 | var _klen int | 121 | var _klen int |
120 | var _trans int | 122 | var _trans int |
@@ -195,7 +197,7 @@ func formatFSM(format string, a []cty.Value) (string, error) { | |||
195 | _acts++ | 197 | _acts++ |
196 | switch _formatfsm_actions[_acts-1] { | 198 | switch _formatfsm_actions[_acts-1] { |
197 | case 0: | 199 | case 0: |
198 | // line 29 "format_fsm.rl" | 200 | // line 31 "format_fsm.rl" |
199 | 201 | ||
200 | verb = formatVerb{ | 202 | verb = formatVerb{ |
201 | ArgNum: nextArg, | 203 | ArgNum: nextArg, |
@@ -205,12 +207,12 @@ func formatFSM(format string, a []cty.Value) (string, error) { | |||
205 | ts = p | 207 | ts = p |
206 | 208 | ||
207 | case 1: | 209 | case 1: |
208 | // line 38 "format_fsm.rl" | 210 | // line 40 "format_fsm.rl" |
209 | 211 | ||
210 | buf.WriteByte(data[p]) | 212 | buf.WriteByte(data[p]) |
211 | 213 | ||
212 | case 4: | 214 | case 4: |
213 | // line 49 "format_fsm.rl" | 215 | // line 51 "format_fsm.rl" |
214 | 216 | ||
215 | // We'll try to slurp a whole UTF-8 sequence here, to give the user | 217 | // We'll try to slurp a whole UTF-8 sequence here, to give the user |
216 | // better feedback. | 218 | // better feedback. |
@@ -218,85 +220,89 @@ func formatFSM(format string, a []cty.Value) (string, error) { | |||
218 | return buf.String(), fmt.Errorf("unrecognized format character %q at offset %d", r, p) | 220 | return buf.String(), fmt.Errorf("unrecognized format character %q at offset %d", r, p) |
219 | 221 | ||
220 | case 5: | 222 | case 5: |
221 | // line 56 "format_fsm.rl" | 223 | // line 58 "format_fsm.rl" |
222 | 224 | ||
223 | verb.Sharp = true | 225 | verb.Sharp = true |
224 | 226 | ||
225 | case 6: | 227 | case 6: |
226 | // line 59 "format_fsm.rl" | 228 | // line 61 "format_fsm.rl" |
227 | 229 | ||
228 | verb.Zero = true | 230 | verb.Zero = true |
229 | 231 | ||
230 | case 7: | 232 | case 7: |
231 | // line 62 "format_fsm.rl" | 233 | // line 64 "format_fsm.rl" |
232 | 234 | ||
233 | verb.Minus = true | 235 | verb.Minus = true |
234 | 236 | ||
235 | case 8: | 237 | case 8: |
236 | // line 65 "format_fsm.rl" | 238 | // line 67 "format_fsm.rl" |
237 | 239 | ||
238 | verb.Plus = true | 240 | verb.Plus = true |
239 | 241 | ||
240 | case 9: | 242 | case 9: |
241 | // line 68 "format_fsm.rl" | 243 | // line 70 "format_fsm.rl" |
242 | 244 | ||
243 | verb.Space = true | 245 | verb.Space = true |
244 | 246 | ||
245 | case 10: | 247 | case 10: |
246 | // line 72 "format_fsm.rl" | 248 | // line 74 "format_fsm.rl" |
247 | 249 | ||
248 | verb.ArgNum = 0 | 250 | verb.ArgNum = 0 |
249 | 251 | ||
250 | case 11: | 252 | case 11: |
251 | // line 75 "format_fsm.rl" | 253 | // line 77 "format_fsm.rl" |
252 | 254 | ||
253 | verb.ArgNum = (10 * verb.ArgNum) + (int(data[p]) - '0') | 255 | verb.ArgNum = (10 * verb.ArgNum) + (int(data[p]) - '0') |
254 | 256 | ||
255 | case 12: | 257 | case 12: |
256 | // line 79 "format_fsm.rl" | 258 | // line 81 "format_fsm.rl" |
257 | 259 | ||
258 | verb.HasWidth = true | 260 | verb.HasWidth = true |
259 | 261 | ||
260 | case 13: | 262 | case 13: |
261 | // line 82 "format_fsm.rl" | 263 | // line 84 "format_fsm.rl" |
262 | 264 | ||
263 | verb.Width = 0 | 265 | verb.Width = 0 |
264 | 266 | ||
265 | case 14: | 267 | case 14: |
266 | // line 85 "format_fsm.rl" | 268 | // line 87 "format_fsm.rl" |
267 | 269 | ||
268 | verb.Width = (10 * verb.Width) + (int(data[p]) - '0') | 270 | verb.Width = (10 * verb.Width) + (int(data[p]) - '0') |
269 | 271 | ||
270 | case 15: | 272 | case 15: |
271 | // line 89 "format_fsm.rl" | 273 | // line 91 "format_fsm.rl" |
272 | 274 | ||
273 | verb.HasPrec = true | 275 | verb.HasPrec = true |
274 | 276 | ||
275 | case 16: | 277 | case 16: |
276 | // line 92 "format_fsm.rl" | 278 | // line 94 "format_fsm.rl" |
277 | 279 | ||
278 | verb.Prec = 0 | 280 | verb.Prec = 0 |
279 | 281 | ||
280 | case 17: | 282 | case 17: |
281 | // line 95 "format_fsm.rl" | 283 | // line 97 "format_fsm.rl" |
282 | 284 | ||
283 | verb.Prec = (10 * verb.Prec) + (int(data[p]) - '0') | 285 | verb.Prec = (10 * verb.Prec) + (int(data[p]) - '0') |
284 | 286 | ||
285 | case 18: | 287 | case 18: |
286 | // line 99 "format_fsm.rl" | 288 | // line 101 "format_fsm.rl" |
287 | 289 | ||
288 | verb.Mode = rune(data[p]) | 290 | verb.Mode = rune(data[p]) |
289 | te = p + 1 | 291 | te = p + 1 |
290 | verb.Raw = data[ts:te] | 292 | verb.Raw = data[ts:te] |
291 | verb.Offset = ts | 293 | verb.Offset = ts |
292 | 294 | ||
295 | if verb.ArgNum > highestArgIdx { | ||
296 | highestArgIdx = verb.ArgNum | ||
297 | } | ||
298 | |||
293 | err := formatAppend(&verb, &buf, a) | 299 | err := formatAppend(&verb, &buf, a) |
294 | if err != nil { | 300 | if err != nil { |
295 | return buf.String(), err | 301 | return buf.String(), err |
296 | } | 302 | } |
297 | nextArg = verb.ArgNum + 1 | 303 | nextArg = verb.ArgNum + 1 |
298 | 304 | ||
299 | // line 324 "format_fsm.go" | 305 | // line 330 "format_fsm.go" |
300 | } | 306 | } |
301 | } | 307 | } |
302 | 308 | ||
@@ -319,22 +325,22 @@ func formatFSM(format string, a []cty.Value) (string, error) { | |||
319 | __acts++ | 325 | __acts++ |
320 | switch _formatfsm_actions[__acts-1] { | 326 | switch _formatfsm_actions[__acts-1] { |
321 | case 2: | 327 | case 2: |
322 | // line 42 "format_fsm.rl" | 328 | // line 44 "format_fsm.rl" |
323 | 329 | ||
324 | case 3: | 330 | case 3: |
325 | // line 45 "format_fsm.rl" | 331 | // line 47 "format_fsm.rl" |
326 | 332 | ||
327 | return buf.String(), fmt.Errorf("invalid format string starting at offset %d", p) | 333 | return buf.String(), fmt.Errorf("invalid format string starting at offset %d", p) |
328 | 334 | ||
329 | case 4: | 335 | case 4: |
330 | // line 49 "format_fsm.rl" | 336 | // line 51 "format_fsm.rl" |
331 | 337 | ||
332 | // We'll try to slurp a whole UTF-8 sequence here, to give the user | 338 | // We'll try to slurp a whole UTF-8 sequence here, to give the user |
333 | // better feedback. | 339 | // better feedback. |
334 | r, _ := utf8.DecodeRuneInString(data[p:]) | 340 | r, _ := utf8.DecodeRuneInString(data[p:]) |
335 | return buf.String(), fmt.Errorf("unrecognized format character %q at offset %d", r, p) | 341 | return buf.String(), fmt.Errorf("unrecognized format character %q at offset %d", r, p) |
336 | 342 | ||
337 | // line 363 "format_fsm.go" | 343 | // line 369 "format_fsm.go" |
338 | } | 344 | } |
339 | } | 345 | } |
340 | } | 346 | } |
@@ -344,14 +350,24 @@ func formatFSM(format string, a []cty.Value) (string, error) { | |||
344 | } | 350 | } |
345 | } | 351 | } |
346 | 352 | ||
347 | // line 171 "format_fsm.rl" | 353 | // line 177 "format_fsm.rl" |
348 | 354 | ||
349 | // If we fall out here without being in a final state then we've | 355 | // 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 | 356 | // encountered something that the scanner can't match, which should |
351 | // be impossible (the scanner matches all bytes _somehow_) but we'll | 357 | // be impossible (the scanner matches all bytes _somehow_) but we'll |
352 | // flag it anyway rather than just losing data from the end. | 358 | // flag it anyway rather than just losing data from the end. |
353 | if cs < formatfsm_first_final { | 359 | if cs < formatfsm_first_final { |
354 | return buf.String(), fmt.Errorf("extraneous characters beginning at offset %i", p) | 360 | return buf.String(), fmt.Errorf("extraneous characters beginning at offset %d", p) |
361 | } | ||
362 | |||
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") | ||
369 | } | ||
370 | return buf.String(), function.NewArgErrorf(firstBad, "too many arguments; only %d used by format string", highestArgIdx) | ||
355 | } | 371 | } |
356 | 372 | ||
357 | return buf.String(), nil | 373 | return buf.String(), nil |