From 55a1490c18ce6745ef39a6da57df2c1a85b17c49 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Sat, 17 Sep 2022 23:40:30 -0400 Subject: [PATCH] Implemented ModuleName and added to Section interface --- analyzer/table.go | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/analyzer/table.go b/analyzer/table.go index cfe313d..55973ac 100644 --- a/analyzer/table.go +++ b/analyzer/table.go @@ -1,5 +1,7 @@ package analyzer +import "path/filepath" + // locator uniquely identifies a section in the section table. type locator struct { modulePath string @@ -38,10 +40,15 @@ const ( // Section is a semantically analyzed section. type Section interface { + // Provided by sectionBase + Name () (name string) + Complete () (complete bool) + ModulePath () (path string) + ModuleName () (path string) + + // Must be implemented by each individual section Kind () (kind SectionKind) - Name () (name string) ToString (indent int) (output string) - Complete () (complete bool) } // sectionBase is a struct that all sections must embed. @@ -57,12 +64,16 @@ func (section sectionBase) Name () (name string) { } // ModulePath returns the full path of the module the section came from. -func (section sectionBase) ModulePath () (name string) { - name = section.where.modulePath +func (section sectionBase) ModulePath () (path string) { + path = section.where.modulePath return } -// TODO: ModuleName returns the name of the module where the section came from. +// ModuleName returns the name of the module where the section came from. +func (section sectionBase) ModuleName () (name string) { + name = filepath.Base(section.where.modulePath) + return +} // Complete returns wether the section has been completed. func (section sectionBase) Complete () (complete bool) {