diff options
Diffstat (limited to 'vendor/github.com/hashicorp/hcl2/hcl/hclsyntax/scan_tokens.rl')
-rw-r--r-- | vendor/github.com/hashicorp/hcl2/hcl/hclsyntax/scan_tokens.rl | 63 |
1 files changed, 41 insertions, 22 deletions
diff --git a/vendor/github.com/hashicorp/hcl2/hcl/hclsyntax/scan_tokens.rl b/vendor/github.com/hashicorp/hcl2/hcl/hclsyntax/scan_tokens.rl index 83ef65b..4443dc4 100644 --- a/vendor/github.com/hashicorp/hcl2/hcl/hclsyntax/scan_tokens.rl +++ b/vendor/github.com/hashicorp/hcl2/hcl/hclsyntax/scan_tokens.rl | |||
@@ -9,17 +9,22 @@ import ( | |||
9 | 9 | ||
10 | // This file is generated from scan_tokens.rl. DO NOT EDIT. | 10 | // This file is generated from scan_tokens.rl. DO NOT EDIT. |
11 | %%{ | 11 | %%{ |
12 | # (except you are actually in scan_tokens.rl here, so edit away!) | 12 | # (except when you are actually in scan_tokens.rl here, so edit away!) |
13 | 13 | ||
14 | machine hcltok; | 14 | machine hcltok; |
15 | write data; | 15 | write data; |
16 | }%% | 16 | }%% |
17 | 17 | ||
18 | func scanTokens(data []byte, filename string, start hcl.Pos, mode scanMode) []Token { | 18 | func scanTokens(data []byte, filename string, start hcl.Pos, mode scanMode) []Token { |
19 | stripData := stripUTF8BOM(data) | ||
20 | start.Byte += len(data) - len(stripData) | ||
21 | data = stripData | ||
22 | |||
19 | f := &tokenAccum{ | 23 | f := &tokenAccum{ |
20 | Filename: filename, | 24 | Filename: filename, |
21 | Bytes: data, | 25 | Bytes: data, |
22 | Pos: start, | 26 | Pos: start, |
27 | StartByte: start.Byte, | ||
23 | } | 28 | } |
24 | 29 | ||
25 | %%{ | 30 | %%{ |
@@ -39,7 +44,7 @@ func scanTokens(data []byte, filename string, start hcl.Pos, mode scanMode) []To | |||
39 | Ident = (ID_Start | '_') (ID_Continue | '-')*; | 44 | Ident = (ID_Start | '_') (ID_Continue | '-')*; |
40 | 45 | ||
41 | # Symbols that just represent themselves are handled as a single rule. | 46 | # Symbols that just represent themselves are handled as a single rule. |
42 | SelfToken = "[" | "]" | "(" | ")" | "." | "," | "*" | "/" | "%" | "+" | "-" | "=" | "<" | ">" | "!" | "?" | ":" | "\n" | "&" | "|" | "~" | "^" | ";" | "`"; | 47 | SelfToken = "[" | "]" | "(" | ")" | "." | "," | "*" | "/" | "%" | "+" | "-" | "=" | "<" | ">" | "!" | "?" | ":" | "\n" | "&" | "|" | "~" | "^" | ";" | "`" | "'"; |
43 | 48 | ||
44 | EqualOp = "=="; | 49 | EqualOp = "=="; |
45 | NotEqual = "!="; | 50 | NotEqual = "!="; |
@@ -58,9 +63,17 @@ func scanTokens(data []byte, filename string, start hcl.Pos, mode scanMode) []To | |||
58 | BeginHeredocTmpl = '<<' ('-')? Ident Newline; | 63 | BeginHeredocTmpl = '<<' ('-')? Ident Newline; |
59 | 64 | ||
60 | Comment = ( | 65 | Comment = ( |
61 | ("#" (any - EndOfLine)* EndOfLine) | | 66 | # The :>> operator in these is a "finish-guarded concatenation", |
62 | ("//" (any - EndOfLine)* EndOfLine) | | 67 | # which terminates the sequence on its left when it completes |
63 | ("/*" any* "*/") | 68 | # the sequence on its right. |
69 | # In the single-line comment cases this is allowing us to make | ||
70 | # the trailing EndOfLine optional while still having the overall | ||
71 | # pattern terminate. In the multi-line case it ensures that | ||
72 | # the first comment in the file ends at the first */, rather than | ||
73 | # gobbling up all of the "any*" until the _final_ */ in the file. | ||
74 | ("#" (any - EndOfLine)* :>> EndOfLine?) | | ||
75 | ("//" (any - EndOfLine)* :>> EndOfLine?) | | ||
76 | ("/*" any* :>> "*/") | ||
64 | ); | 77 | ); |
65 | 78 | ||
66 | # Note: hclwrite assumes that only ASCII spaces appear between tokens, | 79 | # Note: hclwrite assumes that only ASCII spaces appear between tokens, |
@@ -213,29 +226,35 @@ func scanTokens(data []byte, filename string, start hcl.Pos, mode scanMode) []To | |||
213 | TemplateInterp = "${" ("~")?; | 226 | TemplateInterp = "${" ("~")?; |
214 | TemplateControl = "%{" ("~")?; | 227 | TemplateControl = "%{" ("~")?; |
215 | EndStringTmpl = '"'; | 228 | EndStringTmpl = '"'; |
216 | StringLiteralChars = (AnyUTF8 - ("\r"|"\n")); | 229 | NewlineChars = ("\r"|"\n"); |
230 | NewlineCharsSeq = NewlineChars+; | ||
231 | StringLiteralChars = (AnyUTF8 - NewlineChars); | ||
232 | TemplateIgnoredNonBrace = (^'{' %{ fhold; }); | ||
233 | TemplateNotInterp = '$' (TemplateIgnoredNonBrace | TemplateInterp); | ||
234 | TemplateNotControl = '%' (TemplateIgnoredNonBrace | TemplateControl); | ||
235 | QuotedStringLiteralWithEsc = ('\\' StringLiteralChars) | (StringLiteralChars - ("$" | '%' | '"' | "\\")); | ||
217 | TemplateStringLiteral = ( | 236 | TemplateStringLiteral = ( |
218 | ('$' ^'{' %{ fhold; }) | | 237 | (TemplateNotInterp) | |
219 | ('%' ^'{' %{ fhold; }) | | 238 | (TemplateNotControl) | |
220 | ('\\' StringLiteralChars) | | 239 | (QuotedStringLiteralWithEsc)+ |
221 | (StringLiteralChars - ("$" | '%' | '"')) | 240 | ); |
222 | )+; | ||
223 | HeredocStringLiteral = ( | 241 | HeredocStringLiteral = ( |
224 | ('$' ^'{' %{ fhold; }) | | 242 | (TemplateNotInterp) | |
225 | ('%' ^'{' %{ fhold; }) | | 243 | (TemplateNotControl) | |
226 | (StringLiteralChars - ("$" | '%')) | 244 | (StringLiteralChars - ("$" | '%'))* |
227 | )*; | 245 | ); |
228 | BareStringLiteral = ( | 246 | BareStringLiteral = ( |
229 | ('$' ^'{') | | 247 | (TemplateNotInterp) | |
230 | ('%' ^'{') | | 248 | (TemplateNotControl) | |
231 | (StringLiteralChars - ("$" | '%')) | 249 | (StringLiteralChars - ("$" | '%'))* |
232 | )* Newline?; | 250 | ) Newline?; |
233 | 251 | ||
234 | stringTemplate := |* | 252 | stringTemplate := |* |
235 | TemplateInterp => beginTemplateInterp; | 253 | TemplateInterp => beginTemplateInterp; |
236 | TemplateControl => beginTemplateControl; | 254 | TemplateControl => beginTemplateControl; |
237 | EndStringTmpl => endStringTemplate; | 255 | EndStringTmpl => endStringTemplate; |
238 | TemplateStringLiteral => { token(TokenQuotedLit); }; | 256 | TemplateStringLiteral => { token(TokenQuotedLit); }; |
257 | NewlineCharsSeq => { token(TokenQuotedNewline); }; | ||
239 | AnyUTF8 => { token(TokenInvalid); }; | 258 | AnyUTF8 => { token(TokenInvalid); }; |
240 | BrokenUTF8 => { token(TokenBadUTF8); }; | 259 | BrokenUTF8 => { token(TokenBadUTF8); }; |
241 | *|; | 260 | *|; |