Reorganized functions
This commit is contained in:
parent
ef7deb30b7
commit
3b29d4cdee
5 changed files with 99 additions and 86 deletions
36
src/build/Instruction.go
Normal file
36
src/build/Instruction.go
Normal file
|
@ -0,0 +1,36 @@
|
|||
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)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue