36 lines
797 B
Go
36 lines
797 B
Go
package build
|
|
|
|
import (
|
|
"git.akyoto.dev/cli/q/src/build/expression"
|
|
"git.akyoto.dev/cli/q/src/build/token"
|
|
"git.akyoto.dev/cli/q/src/errors"
|
|
)
|
|
|
|
// CompileInstruction compiles a single instruction.
|
|
func (f *Function) CompileInstruction(instruction token.List) error {
|
|
if instruction[0].Kind == token.Keyword {
|
|
return f.CompileKeyword(instruction)
|
|
}
|
|
|
|
expr := expression.Parse(instruction)
|
|
|
|
if expr == nil {
|
|
return nil
|
|
}
|
|
|
|
defer expr.Close()
|
|
|
|
switch true {
|
|
case isVariableDefinition(expr):
|
|
return f.CompileVariableDefinition(expr)
|
|
|
|
case isAssignment(expr):
|
|
return f.CompileAssignment(expr)
|
|
|
|
case isFunctionCall(expr):
|
|
return f.CompileFunctionCall(expr)
|
|
|
|
default:
|
|
return errors.New(&errors.InvalidInstruction{Instruction: expr.Token.Text()}, f.File, expr.Token.Position)
|
|
}
|
|
}
|