Analyzer attempts to find the source of types

This commit is contained in:
Sasha Koshka 2022-09-29 22:54:32 -04:00
parent 1300f87cb5
commit d117e2727c
4 changed files with 30 additions and 8 deletions

View File

@ -127,13 +127,12 @@ func (analyzer *AnalysisOperation) fetchSectionFromIdentifier (
bitten parser.Identifier,
err error,
) {
bitten = which
item := bitten.Bite()
item, bitten := which.Bite()
path, exists := analyzer.currentTree.ResolveRequire(item)
if exists {
// we have our module path, so get the section name
item = bitten.Bite()
item, bitten = bitten.Bite()
} else {
// that wasn't a module name, so the module path must be the our
// current one

View File

@ -52,7 +52,8 @@ func (analyzer AnalysisOperation) analyzeTypeSection () (
) {
outputSection := TypeSection { }
outputSection.where = analyzer.currentPosition
section = outputSection
section = &outputSection
analyzer.addSection(section)
inputSection := analyzer.currentSection.(parser.TypeSection)
@ -66,6 +67,9 @@ func (analyzer AnalysisOperation) analyzeTypeSection () (
outputSection.what, err = analyzer.analyzeType(inputSection.Type())
if err != nil { return }
// TODO: analyze members
outputSection.complete = true
return
}

View File

@ -89,6 +89,18 @@ func (analyzer AnalysisOperation) analyzeType (
var points Type
points, err = analyzer.analyzeType(inputType.Points())
outputType.points = &points
} else {
var bitten parser.Identifier
outputType.actual,
bitten,
err = analyzer.fetchSectionFromIdentifier(inputType.Name())
if bitten.Length() > 0 {
err = bitten.NewError(
"cannot use member selection in this context",
infoerr.ErrorKindError)
return
}
}
// TODO

View File

@ -35,10 +35,17 @@ func (identifier Identifier) Item (index int) (item string) {
return
}
// Bite removes the first item from the identifier and returns it.
func (identifier *Identifier) Bite () (item string) {
item = identifier.trail[0]
identifier.trail = identifier.trail[1:]
// Bite returns the first item of an identifier, and a copy of that identifier
// with that item removed. If there is nothing left to bite off, this method
// panics.
func (identifier Identifier) Bite () (item string, bitten Identifier) {
if len(identifier.trail) < 1 {
panic ("trying to bite an empty identifier")
}
bitten = identifier
item = bitten.trail[0]
bitten.trail = bitten.trail[1:]
return
}