diff --git a/analyzer/analyzer.go b/analyzer/analyzer.go index 1004f3c..6723681 100644 --- a/analyzer/analyzer.go +++ b/analyzer/analyzer.go @@ -85,6 +85,11 @@ func (analyzer *AnalysisOperation) fetchSection ( analyzer.currentPosition = where analyzer.currentSection = parsedSection + defer func () { + analyzer.currentPosition = previousPosition + analyzer.currentSection = previousSection + } () + // TODO: analyze section. have analysis methods work on currentPosition // and currentSection. // @@ -94,15 +99,14 @@ func (analyzer *AnalysisOperation) fetchSection ( // scenarios. switch parsedSection.Kind() { case parser.SectionKindType: - case parser.SectionKindObjt: + section, err = analyzer.analyzeTypeSection() + if err != nil { return} case parser.SectionKindEnum: case parser.SectionKindFace: case parser.SectionKindData: case parser.SectionKindFunc: } - analyzer.currentPosition = previousPosition - analyzer.currentSection = previousSection return } diff --git a/analyzer/primitives.go b/analyzer/primitives.go index 248a47e..5ea516a 100644 --- a/analyzer/primitives.go +++ b/analyzer/primitives.go @@ -16,7 +16,7 @@ var PrimitiveObjt = createPrimitive("Objt", Type {}) var PrimitiveFace = createPrimitive("Face", Type {}) var BuiltInString = createPrimitive("String", Type { - actual: PrimitiveU8, + actual: PrimitiveU32, kind: TypeKindVariableArray, }) diff --git a/analyzer/type-section.go b/analyzer/type-section.go index 4e8f6de..2c5b907 100644 --- a/analyzer/type-section.go +++ b/analyzer/type-section.go @@ -1,9 +1,13 @@ package analyzer +import "git.tebibyte.media/arf/arf/types" +import "git.tebibyte.media/arf/arf/parser" +import "git.tebibyte.media/arf/arf/infoerr" + // TypeSection represents a type definition section. type TypeSection struct { sectionBase - inherits Type + what Type complete bool } @@ -16,6 +20,27 @@ func (section TypeSection) Kind () (kind SectionKind) { // ToString returns all data stored within the type section, in string form. func (section TypeSection) ToString (indent int) (output string) { output += doIndent(indent, "typeSection ", section.where.ToString(), "\n") - output += section.inherits.ToString(indent + 1) + output += section.what.ToString(indent + 1) + return +} + +// analyzeTypeSection analyzes a type section. +func (analyzer AnalysisOperation) analyzeTypeSection () ( + section Section, + err error, +) { + inputSection := analyzer.currentSection.(parser.TypeSection) + if inputSection.Permission() == types.PermissionReadWrite { + err = inputSection.NewError ( + "rw permission not understood in this context, try ro", + infoerr.ErrorKindError) + } + + outputSection := TypeSection { } + outputSection.where = analyzer.currentPosition + + outputSection.what, err = analyzer.analyzeType(inputSection.Type()) + + outputSection.complete = true return } diff --git a/analyzer/type-section_test.go b/analyzer/type-section_test.go new file mode 100644 index 0000000..a8d441d --- /dev/null +++ b/analyzer/type-section_test.go @@ -0,0 +1,11 @@ +package analyzer + +import "testing" + +func TestTypeSection (test *testing.T) { + checkTree ("../tests/analyzer/typeSection", false, +` +typeSection ../tests/analyzer/typeSection.basicInt + type basic Int +`, test) +} diff --git a/tests/analyzer/type/main.arf b/tests/analyzer/typeSection/main.arf similarity index 100% rename from tests/analyzer/type/main.arf rename to tests/analyzer/typeSection/main.arf