Moved AST generation to its own package
This commit is contained in:
parent
8453273d73
commit
2d045759f2
8 changed files with 172 additions and 171 deletions
|
@ -5,9 +5,9 @@ import (
|
|||
|
||||
"git.akyoto.dev/cli/q/src/build/ast"
|
||||
"git.akyoto.dev/cli/q/src/build/config"
|
||||
"git.akyoto.dev/cli/q/src/build/expression"
|
||||
"git.akyoto.dev/cli/q/src/build/fs"
|
||||
"git.akyoto.dev/cli/q/src/build/token"
|
||||
"git.akyoto.dev/cli/q/src/errors"
|
||||
)
|
||||
|
||||
// Function represents a function.
|
||||
|
@ -28,9 +28,10 @@ func (f *Function) Compile() {
|
|||
|
||||
// CompileTokens compiles a token list.
|
||||
func (f *Function) CompileTokens(tokens token.List) error {
|
||||
tree, err := f.toAST(tokens)
|
||||
tree, err := ast.Parse(tokens)
|
||||
|
||||
if err != nil {
|
||||
err.(*errors.Error).File = f.File
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -95,36 +96,3 @@ func (f *Function) String() string {
|
|||
func (f *Function) Wait() {
|
||||
<-f.finished
|
||||
}
|
||||
|
||||
// identifierExists returns true if the identifier has been defined.
|
||||
func (f *Function) identifierExists(name string) bool {
|
||||
_, exists := f.variables[name]
|
||||
|
||||
if exists {
|
||||
return true
|
||||
}
|
||||
|
||||
_, exists = f.definitions[name]
|
||||
|
||||
if exists {
|
||||
return true
|
||||
}
|
||||
|
||||
_, exists = f.functions[name]
|
||||
return exists
|
||||
}
|
||||
|
||||
// isAssignment returns true if the expression is an assignment.
|
||||
func isAssignment(expr *expression.Expression) bool {
|
||||
return expr.Token.Kind == token.Operator && expr.Token.Bytes[len(expr.Token.Bytes)-1] == '='
|
||||
}
|
||||
|
||||
// isFunctionCall returns true if the expression is a function call.
|
||||
func isFunctionCall(expr *expression.Expression) bool {
|
||||
return expr.Token.Kind == token.Operator && expr.Token.Text() == "λ"
|
||||
}
|
||||
|
||||
// isVariableDefinition returns true if the expression is a variable definition.
|
||||
func isVariableDefinition(expr *expression.Expression) bool {
|
||||
return expr.Token.Kind == token.Operator && expr.Token.Text() == ":="
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue