diff options
Diffstat (limited to 'vendor/github.com/hashicorp/hcl2/hcl/hclsyntax/scan_string_lit.rl')
-rw-r--r-- | vendor/github.com/hashicorp/hcl2/hcl/hclsyntax/scan_string_lit.rl | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/vendor/github.com/hashicorp/hcl2/hcl/hclsyntax/scan_string_lit.rl b/vendor/github.com/hashicorp/hcl2/hcl/hclsyntax/scan_string_lit.rl new file mode 100644 index 0000000..f8ac117 --- /dev/null +++ b/vendor/github.com/hashicorp/hcl2/hcl/hclsyntax/scan_string_lit.rl | |||
@@ -0,0 +1,105 @@ | |||
1 | |||
2 | package hclsyntax | ||
3 | |||
4 | // This file is generated from scan_string_lit.rl. DO NOT EDIT. | ||
5 | %%{ | ||
6 | # (except you are actually in scan_string_lit.rl here, so edit away!) | ||
7 | |||
8 | machine hclstrtok; | ||
9 | write data; | ||
10 | }%% | ||
11 | |||
12 | func scanStringLit(data []byte, quoted bool) [][]byte { | ||
13 | var ret [][]byte | ||
14 | |||
15 | %%{ | ||
16 | include UnicodeDerived "unicode_derived.rl"; | ||
17 | |||
18 | UTF8Cont = 0x80 .. 0xBF; | ||
19 | AnyUTF8 = ( | ||
20 | 0x00..0x7F | | ||
21 | 0xC0..0xDF . UTF8Cont | | ||
22 | 0xE0..0xEF . UTF8Cont . UTF8Cont | | ||
23 | 0xF0..0xF7 . UTF8Cont . UTF8Cont . UTF8Cont | ||
24 | ); | ||
25 | BadUTF8 = any - AnyUTF8; | ||
26 | |||
27 | Hex = ('0'..'9' | 'a'..'f' | 'A'..'F'); | ||
28 | |||
29 | # Our goal with this patterns is to capture user intent as best as | ||
30 | # possible, even if the input is invalid. The caller will then verify | ||
31 | # whether each token is valid and generate suitable error messages | ||
32 | # if not. | ||
33 | UnicodeEscapeShort = "\\u" . Hex{0,4}; | ||
34 | UnicodeEscapeLong = "\\U" . Hex{0,8}; | ||
35 | UnicodeEscape = (UnicodeEscapeShort | UnicodeEscapeLong); | ||
36 | SimpleEscape = "\\" . (AnyUTF8 - ('U'|'u'))?; | ||
37 | TemplateEscape = ("$" . ("$" . ("{"?))?) | ("%" . ("%" . ("{"?))?); | ||
38 | Newline = ("\r\n" | "\r" | "\n"); | ||
39 | |||
40 | action Begin { | ||
41 | // If te is behind p then we've skipped over some literal | ||
42 | // characters which we must now return. | ||
43 | if te < p { | ||
44 | ret = append(ret, data[te:p]) | ||
45 | } | ||
46 | ts = p; | ||
47 | } | ||
48 | action End { | ||
49 | te = p; | ||
50 | ret = append(ret, data[ts:te]); | ||
51 | } | ||
52 | |||
53 | QuotedToken = (UnicodeEscape | SimpleEscape | TemplateEscape | Newline) >Begin %End; | ||
54 | UnquotedToken = (TemplateEscape | Newline) >Begin %End; | ||
55 | QuotedLiteral = (any - ("\\" | "$" | "%" | "\r" | "\n")); | ||
56 | UnquotedLiteral = (any - ("$" | "%" | "\r" | "\n")); | ||
57 | |||
58 | quoted := (QuotedToken | QuotedLiteral)**; | ||
59 | unquoted := (UnquotedToken | UnquotedLiteral)**; | ||
60 | |||
61 | }%% | ||
62 | |||
63 | // Ragel state | ||
64 | p := 0 // "Pointer" into data | ||
65 | pe := len(data) // End-of-data "pointer" | ||
66 | ts := 0 | ||
67 | te := 0 | ||
68 | eof := pe | ||
69 | |||
70 | var cs int // current state | ||
71 | switch { | ||
72 | case quoted: | ||
73 | cs = hclstrtok_en_quoted | ||
74 | default: | ||
75 | cs = hclstrtok_en_unquoted | ||
76 | } | ||
77 | |||
78 | // Make Go compiler happy | ||
79 | _ = ts | ||
80 | _ = eof | ||
81 | |||
82 | /*token := func () { | ||
83 | ret = append(ret, data[ts:te]) | ||
84 | }*/ | ||
85 | |||
86 | %%{ | ||
87 | write init nocs; | ||
88 | write exec; | ||
89 | }%% | ||
90 | |||
91 | if te < p { | ||
92 | // Collect any leftover literal characters at the end of the input | ||
93 | ret = append(ret, data[te:p]) | ||
94 | } | ||
95 | |||
96 | // If we fall out here without being in a final state then we've | ||
97 | // encountered something that the scanner can't match, which should | ||
98 | // be impossible (the scanner matches all bytes _somehow_) but we'll | ||
99 | // tolerate it and let the caller deal with it. | ||
100 | if cs < hclstrtok_first_final { | ||
101 | ret = append(ret, data[p:len(data)]) | ||
102 | } | ||
103 | |||
104 | return ret | ||
105 | } | ||