This commit is contained in:
parent
dbc865ee67
commit
562c839835
37 changed files with 742 additions and 45 deletions
68
src/scanner/scanExtern.go
Normal file
68
src/scanner/scanExtern.go
Normal file
|
@ -0,0 +1,68 @@
|
|||
package scanner
|
||||
|
||||
import (
|
||||
"git.urbach.dev/cli/q/src/errors"
|
||||
"git.urbach.dev/cli/q/src/fs"
|
||||
"git.urbach.dev/cli/q/src/token"
|
||||
)
|
||||
|
||||
// scanExtern scans a block of external libraries.
|
||||
func (s *scanner) scanExtern(file *fs.File, tokens token.List, i int) (int, error) {
|
||||
i++
|
||||
|
||||
if tokens[i].Kind != token.BlockStart {
|
||||
return i, errors.New(MissingBlockStart, file, tokens[i].Position)
|
||||
}
|
||||
|
||||
for i < len(tokens) {
|
||||
switch tokens[i].Kind {
|
||||
case token.Identifier:
|
||||
var err error
|
||||
i, err = s.scanExternLibrary(file, tokens, i)
|
||||
|
||||
if err != nil {
|
||||
return i, err
|
||||
}
|
||||
|
||||
case token.BlockEnd:
|
||||
return i, nil
|
||||
}
|
||||
|
||||
i++
|
||||
}
|
||||
|
||||
return i, errors.New(MissingBlockEnd, file, tokens[i].Position)
|
||||
}
|
||||
|
||||
// scanExternLibrary scans a block of external function declarations.
|
||||
func (s *scanner) scanExternLibrary(file *fs.File, tokens token.List, i int) (int, error) {
|
||||
dllName := tokens[i].String(file.Bytes)
|
||||
i++
|
||||
|
||||
if tokens[i].Kind != token.BlockStart {
|
||||
return i, errors.New(MissingBlockStart, file, tokens[i].Position)
|
||||
}
|
||||
|
||||
i++
|
||||
|
||||
for i < len(tokens) {
|
||||
switch tokens[i].Kind {
|
||||
case token.Identifier:
|
||||
function, j, err := scanSignature(file, dllName, tokens, i, token.NewLine)
|
||||
|
||||
if err != nil {
|
||||
return j, err
|
||||
}
|
||||
|
||||
i = j
|
||||
s.functions <- function
|
||||
|
||||
case token.BlockEnd:
|
||||
return i, nil
|
||||
}
|
||||
|
||||
i++
|
||||
}
|
||||
|
||||
return i, errors.New(MissingBlockEnd, file, tokens[i].Position)
|
||||
}
|
|
@ -33,6 +33,8 @@ func (s *scanner) scanFile(path string, pkg string) error {
|
|||
case token.Comment:
|
||||
case token.Identifier:
|
||||
i, err = s.scanFunction(file, tokens, i)
|
||||
case token.Extern:
|
||||
i, err = s.scanExtern(file, tokens, i)
|
||||
case token.Import:
|
||||
i, err = s.scanImport(file, tokens, i)
|
||||
case token.EOF:
|
||||
|
|
|
@ -11,7 +11,7 @@ import (
|
|||
|
||||
// scanFunction scans a function.
|
||||
func (s *scanner) scanFunction(file *fs.File, tokens token.List, i int) (int, error) {
|
||||
function, i, err := scanSignature(file, tokens, i, token.BlockStart)
|
||||
function, i, err := scanSignature(file, file.Package, tokens, i, token.BlockStart)
|
||||
|
||||
if err != nil {
|
||||
return i, err
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
)
|
||||
|
||||
// scanSignature scans only the function signature without the body.
|
||||
func scanSignature(file *fs.File, tokens token.List, i int, delimiter token.Kind) (*core.Function, int, error) {
|
||||
func scanSignature(file *fs.File, pkg string, tokens token.List, i int, delimiter token.Kind) (*core.Function, int, error) {
|
||||
var (
|
||||
groupLevel = 0
|
||||
nameStart = i
|
||||
|
@ -83,7 +83,7 @@ func scanSignature(file *fs.File, tokens token.List, i int, delimiter token.Kind
|
|||
}
|
||||
|
||||
name := tokens[nameStart].String(file.Bytes)
|
||||
function := core.NewFunction(name, file)
|
||||
function := core.NewFunction(name, pkg, file)
|
||||
parameters := tokens[inputStart:inputEnd]
|
||||
|
||||
for param := range parameters.Split {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue