// This file is generated from scan_tokens.rl. DO NOT EDIT.
%%{
- # (except you are actually in scan_tokens.rl here, so edit away!)
+ # (except when you are actually in scan_tokens.rl here, so edit away!)
machine hcltok;
write data;
}%%
func scanTokens(data []byte, filename string, start hcl.Pos, mode scanMode) []Token {
+ stripData := stripUTF8BOM(data)
+ start.Byte += len(data) - len(stripData)
+ data = stripData
+
f := &tokenAccum{
- Filename: filename,
- Bytes: data,
- Pos: start,
+ Filename: filename,
+ Bytes: data,
+ Pos: start,
+ StartByte: start.Byte,
}
%%{
Ident = (ID_Start | '_') (ID_Continue | '-')*;
# Symbols that just represent themselves are handled as a single rule.
- SelfToken = "[" | "]" | "(" | ")" | "." | "," | "*" | "/" | "%" | "+" | "-" | "=" | "<" | ">" | "!" | "?" | ":" | "\n" | "&" | "|" | "~" | "^" | ";" | "`";
+ SelfToken = "[" | "]" | "(" | ")" | "." | "," | "*" | "/" | "%" | "+" | "-" | "=" | "<" | ">" | "!" | "?" | ":" | "\n" | "&" | "|" | "~" | "^" | ";" | "`" | "'";
EqualOp = "==";
NotEqual = "!=";
BeginHeredocTmpl = '<<' ('-')? Ident Newline;
Comment = (
- ("#" (any - EndOfLine)* EndOfLine) |
- ("//" (any - EndOfLine)* EndOfLine) |
- ("/*" any* "*/")
+ # The :>> operator in these is a "finish-guarded concatenation",
+ # which terminates the sequence on its left when it completes
+ # the sequence on its right.
+ # In the single-line comment cases this is allowing us to make
+ # the trailing EndOfLine optional while still having the overall
+ # pattern terminate. In the multi-line case it ensures that
+ # the first comment in the file ends at the first */, rather than
+ # gobbling up all of the "any*" until the _final_ */ in the file.
+ ("#" (any - EndOfLine)* :>> EndOfLine?) |
+ ("//" (any - EndOfLine)* :>> EndOfLine?) |
+ ("/*" any* :>> "*/")
);
# Note: hclwrite assumes that only ASCII spaces appear between tokens,
TemplateInterp = "${" ("~")?;
TemplateControl = "%{" ("~")?;
EndStringTmpl = '"';
- StringLiteralChars = (AnyUTF8 - ("\r"|"\n"));
+ NewlineChars = ("\r"|"\n");
+ NewlineCharsSeq = NewlineChars+;
+ StringLiteralChars = (AnyUTF8 - NewlineChars);
+ TemplateIgnoredNonBrace = (^'{' %{ fhold; });
+ TemplateNotInterp = '$' (TemplateIgnoredNonBrace | TemplateInterp);
+ TemplateNotControl = '%' (TemplateIgnoredNonBrace | TemplateControl);
+ QuotedStringLiteralWithEsc = ('\\' StringLiteralChars) | (StringLiteralChars - ("$" | '%' | '"' | "\\"));
TemplateStringLiteral = (
- ('$' ^'{' %{ fhold; }) |
- ('%' ^'{' %{ fhold; }) |
- ('\\' StringLiteralChars) |
- (StringLiteralChars - ("$" | '%' | '"'))
- )+;
+ (TemplateNotInterp) |
+ (TemplateNotControl) |
+ (QuotedStringLiteralWithEsc)+
+ );
HeredocStringLiteral = (
- ('$' ^'{' %{ fhold; }) |
- ('%' ^'{' %{ fhold; }) |
- (StringLiteralChars - ("$" | '%'))
- )*;
+ (TemplateNotInterp) |
+ (TemplateNotControl) |
+ (StringLiteralChars - ("$" | '%'))*
+ );
BareStringLiteral = (
- ('$' ^'{') |
- ('%' ^'{') |
- (StringLiteralChars - ("$" | '%'))
- )* Newline?;
+ (TemplateNotInterp) |
+ (TemplateNotControl) |
+ (StringLiteralChars - ("$" | '%'))*
+ ) Newline?;
stringTemplate := |*
TemplateInterp => beginTemplateInterp;
TemplateControl => beginTemplateControl;
EndStringTmpl => endStringTemplate;
TemplateStringLiteral => { token(TokenQuotedLit); };
+ NewlineCharsSeq => { token(TokenQuotedNewline); };
AnyUTF8 => { token(TokenInvalid); };
BrokenUTF8 => { token(TokenBadUTF8); };
*|;