Skip to content

Commit

Permalink
Merge pull request #2231 from alixander/reserve-unquoted-string
Browse files Browse the repository at this point in the history
reserved keywords must be unquoted
  • Loading branch information
alixander authored Nov 24, 2024
2 parents a27f46b + 1ecadc5 commit db687ab
Show file tree
Hide file tree
Showing 210 changed files with 13,425 additions and 2,053 deletions.
1 change: 1 addition & 0 deletions ci/release/changelogs/next.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#### Improvements 🧹

- Composition: links pointing to own board are purged [#2203](https://github.com/terrastruct/d2/pull/2203)
- Syntax: reserved keywords must be unquoted [#2231](https://github.com/terrastruct/d2/pull/2231)

#### Bugfixes ⛑️

Expand Down
27 changes: 24 additions & 3 deletions d2ast/d2ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ type String interface {
SetString(string)
Copy() String
_string()
IsUnquoted() bool
}

var _ String = &UnquotedString{}
Expand Down Expand Up @@ -611,6 +612,11 @@ func (s *DoubleQuotedString) _string() {}
func (s *SingleQuotedString) _string() {}
func (s *BlockString) _string() {}

func (s *UnquotedString) IsUnquoted() bool { return true }
func (s *DoubleQuotedString) IsUnquoted() bool { return false }
func (s *SingleQuotedString) IsUnquoted() bool { return false }
func (s *BlockString) IsUnquoted() bool { return false }

type Comment struct {
Range Range `json:"range"`
Value string `json:"value"`
Expand Down Expand Up @@ -1059,7 +1065,22 @@ func MakeKeyPath(a []string) *KeyPath {
return kp
}

func (kp *KeyPath) IDA() (ida []string) {
func MakeKeyPathString(a []String) *KeyPath {
kp := &KeyPath{}
for _, el := range a {
kp.Path = append(kp.Path, MakeValueBox(RawString(el.ScalarString(), true)).StringBox())
}
return kp
}

func (kp *KeyPath) IDA() (ida []String) {
for _, el := range kp.Path {
ida = append(ida, el.Unbox())
}
return ida
}

func (kp *KeyPath) StringIDA() (ida []string) {
for _, el := range kp.Path {
ida = append(ida, el.Unbox().ScalarString())
}
Expand Down Expand Up @@ -1572,9 +1593,9 @@ func (s *Substitution) IDA() (ida []string) {
return ida
}

func (i *Import) IDA() (ida []string) {
func (i *Import) IDA() (ida []String) {
for _, el := range i.Path[1:] {
ida = append(ida, el.Unbox().ScalarString())
ida = append(ida, el.Unbox())
}
return ida
}
Expand Down
2 changes: 1 addition & 1 deletion d2cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ func Run(ctx context.Context, ms *xmain.State) (err error) {
if err != nil {
return xmain.UsageErrorf("invalid target: %s", *targetFlag)
}
boardPath = key.IDA()
boardPath = key.StringIDA()
}

ctx, cancel := timelib.WithTimeout(ctx, time.Minute*2)
Expand Down
Loading

0 comments on commit db687ab

Please sign in to comment.