Implemented function scanning
All checks were successful
/ test (push) Successful in 16s

This commit is contained in:
Eduard Urbach 2025-06-19 23:31:52 +02:00
parent 9b51680af5
commit c2b8db238e
Signed by: akyoto
GPG key ID: 49226B848C78F6C8
24 changed files with 624 additions and 232 deletions

44
src/core/Function.go Normal file
View file

@ -0,0 +1,44 @@
package core
import (
"fmt"
"git.urbach.dev/cli/q/src/fs"
"git.urbach.dev/cli/q/src/token"
)
// Function is the smallest unit of code.
type Function struct {
name string
file *fs.File
Input []*Parameter
Output []*Parameter
Body token.List
}
// NewFunction creates a new function.
func NewFunction(name string, file *fs.File) *Function {
return &Function{
name: name,
file: file,
}
}
// IsExtern returns true if the function has no body.
func (f *Function) IsExtern() bool {
return f.Body == nil
}
// ResolveTypes parses the input and output types.
func (f *Function) ResolveTypes() error {
for _, param := range f.Input {
param.name = param.tokens[0].String(f.file.Bytes)
}
return nil
}
// String returns the package and function name.
func (f *Function) String() string {
return fmt.Sprintf("%s.%s", f.file.Package, f.name)
}