Less gooooo!

This commit is contained in:
Sasha Koshka 2022-09-29 18:09:52 -04:00
parent ed4c9aa0d2
commit bb4a5472e1
4 changed files with 26 additions and 4 deletions

View File

@ -157,6 +157,20 @@ func (analyzer *AnalysisOperation) fetchSectionFromIdentifier (
return
}
// addSection adds a section to the analyzer's section table. If a section with
// that name already exists, it panics because the parser should not have given
// that to us.
func (analyzer *AnalysisOperation) addSection (section Section) {
_, exists := analyzer.sectionTable[section.locator()]
if exists {
panic (
"invalid state: duplicate section " +
section.locator().ToString())
}
analyzer.sectionTable[section.locator()] = section
return
}
func doIndent (indent int, input ...any) (output string) {
for index := 0; index < indent; index ++ {
output += "\t"

View File

@ -33,6 +33,7 @@ type Section interface {
Complete () (complete bool)
ModulePath () (path string)
ModuleName () (path string)
locator () (where locator)
// Must be implemented by each individual section
ToString (indent int) (output string)
@ -67,3 +68,8 @@ func (section sectionBase) Complete () (complete bool) {
complete = section.complete
return
}
func (section sectionBase) locator () (where locator) {
where = section.where
return
}

View File

@ -50,6 +50,11 @@ func (analyzer AnalysisOperation) analyzeTypeSection () (
section Section,
err error,
) {
outputSection := TypeSection { }
outputSection.where = analyzer.currentPosition
section = outputSection
analyzer.addSection(section)
inputSection := analyzer.currentSection.(parser.TypeSection)
if inputSection.Permission() == types.PermissionReadWrite {
err = inputSection.NewError (
@ -58,9 +63,6 @@ func (analyzer AnalysisOperation) analyzeTypeSection () (
infoerr.ErrorKindError)
}
outputSection := TypeSection { }
outputSection.where = analyzer.currentPosition
outputSection.what, err = analyzer.analyzeType(inputSection.Type())
if err != nil { return }

View File

@ -76,7 +76,7 @@ func (analyzer AnalysisOperation) analyzeType (
err error,
) {
outputType.mutable = inputType.Mutable()
if outputType.length < 1 {
if inputType.Length() < 1 {
err = inputType.NewError (
"cannot specify a length of zero",
infoerr.ErrorKindError)