hashicorp / hashicorp/hcl

Underscore characters may start an identifier

Open
#690 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
Go
Stars
5.8k
Forks
657
Avg merge
20h 36m
Merged PRs (30d)
6

Description

Via https://github.com/SublimeText/Terraform/issues/43, it was brought to my attention that apparently underscore characters (`_` U+005F) are allowed to start an identifier, whereas the current spec does not say so.

https://github.com/hashicorp/hcl/blob/360ae579460fab69e9939599af85c8f255a59007/hclsyntax/spec.md?plain=1#L90-L111

As cited, the spec specifically only allows characters in the `ID_Start` Unicode property, which is defined as:

> ID_Start characters are derived from the Unicode General_Category of uppercase letters, lowercase letters, titlecase letters, modifier letters, other letters, letter numbers, plus `Other_ID_Start`, minus `Pattern_Syntax` and `Pattern_White_Space` code points.
>
> In UnicodeSet notation:
> `[\p{L}\p{Nl}\p{Other_ID_Start}-\p{Pattern_Syntax}-\p{Pattern_White_Space}]`

None of these properties include the underscore character. (It is, however, included in `ID_Continue` through `Pc`.)

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the identifier rules in hclsyntax/spec.md at the linked lines, then compare them with the implementation behavior for identifiers beginning with underscore. Determine whether the specification or parser behavior is authoritative; done means the documented rule and accepted syntax agree, with a focused regression test if the implementation changes.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.