Implemented assert keyword
This commit is contained in:
10
src/build/ast/Assert.go
Normal file
10
src/build/ast/Assert.go
Normal file
@ -0,0 +1,10 @@
|
||||
package ast
|
||||
|
||||
import (
|
||||
"git.akyoto.dev/cli/q/src/build/expression"
|
||||
)
|
||||
|
||||
// Assert represents a condition that must be true, otherwise the program stops.
|
||||
type Assert struct {
|
||||
Condition *expression.Expression
|
||||
}
|
@ -35,6 +35,15 @@ func toASTNode(tokens token.List, buffer []byte) (Node, error) {
|
||||
return &Return{Value: value}, nil
|
||||
}
|
||||
|
||||
if tokens[0].Kind == token.Assert {
|
||||
if len(tokens) == 1 {
|
||||
return nil, errors.New(errors.MissingExpression, nil, tokens[0].End())
|
||||
}
|
||||
|
||||
condition := expression.Parse(tokens[1:])
|
||||
return &Assert{Condition: condition}, nil
|
||||
}
|
||||
|
||||
if keywordHasBlock(tokens[0].Kind) {
|
||||
blockStart := tokens.IndexKind(token.BlockStart)
|
||||
blockEnd := tokens.LastIndexKind(token.BlockEnd)
|
||||
|
Reference in New Issue
Block a user