Skip to content

Commit

Permalink
Set brackets on TypeList in parser (#448)
Browse files Browse the repository at this point in the history
Add a setter for brackets on `TypeList` and set them in the parser.
  • Loading branch information
doriable authored Feb 12, 2025
1 parent 8408f3f commit 95835d8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
8 changes: 7 additions & 1 deletion experimental/ast/type_generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ func (d TypeList) Brackets() token.Token {
return d.raw.brackets.In(d.Context())
}

// SetBrackets sets the token tree for the brackets wrapping the argument list.
func (d TypeList) SetBrackets(brackets token.Token) {
d.Context().Nodes().panicIfNotOurs(brackets)
d.raw.brackets = brackets.ID()
}

// Len implements [seq.Indexer].
func (d TypeList) Len() int {
if d.IsZero() {
Expand All @@ -140,7 +146,7 @@ func (d TypeList) At(n int) TypeAny {
return newTypeAny(d.Context(), d.raw.args[n].Value)
}

// At implements [seq.Setter].
// SetAt implements [seq.Setter].
func (d TypeList) SetAt(n int, ty TypeAny) {
d.Context().Nodes().panicIfNotOurs(ty)
d.raw.args[n].Value = ty.raw
Expand Down
1 change: 1 addition & 0 deletions experimental/parser/parse_decl.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ func parseRange(p *parser, c *token.Cursor) ast.DeclRange {

// parseTypeList parses a type list out of a bracket token.
func parseTypeList(p *parser, parens token.Token, types ast.TypeList, in taxa.Noun) {
types.SetBrackets(parens)
delimited[ast.TypeAny]{
p: p,
c: parens.Children(),
Expand Down

0 comments on commit 95835d8

Please # to comment.