()
| 137 | } |
| 138 | |
| 139 | func (bl *blockLabels) Current() []string { |
| 140 | labelNames := make([]string, 0, len(bl.items)) |
| 141 | list := bl.items.List() |
| 142 | |
| 143 | for _, label := range list { |
| 144 | switch labelObj := label.content.(type) { |
| 145 | case *identifier: |
| 146 | if labelObj.token.Type == hclsyntax.TokenIdent { |
| 147 | labelString := string(labelObj.token.Bytes) |
| 148 | labelNames = append(labelNames, labelString) |
| 149 | } |
| 150 | |
| 151 | case *quoted: |
| 152 | tokens := labelObj.tokens |
| 153 | if len(tokens) == 3 && |
| 154 | tokens[0].Type == hclsyntax.TokenOQuote && |
| 155 | tokens[1].Type == hclsyntax.TokenQuotedLit && |
| 156 | tokens[2].Type == hclsyntax.TokenCQuote { |
| 157 | // Note that TokenQuotedLit may contain escape sequences. |
| 158 | labelString, diags := hclsyntax.ParseStringLiteralToken(tokens[1].asHCLSyntax()) |
| 159 | |
| 160 | // If parsing the string literal returns error diagnostics |
| 161 | // then we can just assume the label doesn't match, because it's invalid in some way. |
| 162 | if !diags.HasErrors() { |
| 163 | labelNames = append(labelNames, labelString) |
| 164 | } |
| 165 | } else if len(tokens) == 2 && |
| 166 | tokens[0].Type == hclsyntax.TokenOQuote && |
| 167 | tokens[1].Type == hclsyntax.TokenCQuote { |
| 168 | // An open quote followed immediately by a closing quote is a |
| 169 | // valid but unusual blank string label. |
| 170 | labelNames = append(labelNames, "") |
| 171 | } |
| 172 | |
| 173 | default: |
| 174 | // If neither of the previous cases are true (should be impossible) |
| 175 | // then we can just ignore it, because it's invalid too. |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | return labelNames |
| 180 | } |
no test coverage detected