Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions evaluator/evaluator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,36 @@ func TestTraitMethodLookup(t *testing.T) {
`,
expected: 30,
},
{
name: "comma-separated traits",
input: `
trait First {
function first() {
return 1
}
}

trait Second {
function second() {
return 2
}
}

trait Third {
function third() {
return 3
}
}

class Thing {
use First, Second, Third
}

t = Thing.new()
t.first() + t.second() + t.third()
`,
expected: 6,
},
}

for _, tt := range tests {
Expand Down
13 changes: 12 additions & 1 deletion parser/use.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,19 @@ func (parser *Parser) useExpression() ast.ExpressionNode {
}

identifier := &ast.Identifier{Token: parser.currentToken, Value: parser.currentToken.Lexeme}

use.Traits = append(use.Traits, identifier)

for parser.nextTokenIs(token.COMMA) {
parser.readToken() // consume comma

if !parser.expectNextTokenIs(token.IDENTIFIER) {
return nil
}

identifier := &ast.Identifier{Token: parser.currentToken, Value: parser.currentToken.Lexeme}

use.Traits = append(use.Traits, identifier)
}

return use
}