hclsyntax: permit tabs and treat them like spaces

We inherited a restriction from an early zcl prototype here, but it's
far too strict to prohibit tabs entirely and so we'll accept them and
just treat them as spaces for column-counting purposes.

Tabs are still not _advised_, since they add extra complexity for problems
like generating annotated source code snippets (can't necessarily know
how large the tab stop is going to be) or doing surgical updates to
existing source files. The canonical formatting applied by hclwrite's
Format function will still eliminate all tabs, imposing the canonical
style of two spaces per indent level.

This fixes #2.
This commit is contained in:
Martin Atkins 2018-01-27 09:30:36 -08:00
parent 88bf362f0c
commit f0bf2b15ae
3 changed files with 298 additions and 315 deletions

View File

@ -1010,12 +1010,12 @@ block "valid" {}
{
` `,
2, // tabs not allowed, and body item is required here
0, // the tab character is treated as a single whitespace character
&Body{
Attributes: Attributes{},
Blocks: Blocks{},
SrcRange: hcl.Range{
Start: hcl.Pos{Line: 1, Column: 1, Byte: 0},
Start: hcl.Pos{Line: 1, Column: 2, Byte: 1},
End: hcl.Pos{Line: 1, Column: 2, Byte: 1},
},
EndRange: hcl.Range{

File diff suppressed because it is too large Load Diff

View File

@ -1264,14 +1264,6 @@ EOF
{
"\t\t",
[]Token{
{
Type: TokenTabs,
Bytes: []byte{0x09, 0x09},
Range: hcl.Range{
Start: hcl.Pos{Byte: 0, Line: 1, Column: 1},
End: hcl.Pos{Byte: 2, Line: 1, Column: 3},
},
},
{
Type: TokenEOF,
Bytes: []byte{},