From ed4c9aa0d2a4e1d5c9560de80db1d8ed92f8c7cc Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Thu, 29 Sep 2022 17:34:51 -0400 Subject: [PATCH] Iterator actually advances now --- analyzer/argument.go | 13 ++---------- analyzer/type-section.go | 30 ++++++++++++++++++++++++++- analyzer/type.go | 32 +---------------------------- parser/type.go | 2 -- tests/analyzer/typeSection/main.arf | 2 +- types/iterator.go | 2 +- 6 files changed, 34 insertions(+), 47 deletions(-) diff --git a/analyzer/argument.go b/analyzer/argument.go index 5537f03..654c731 100644 --- a/analyzer/argument.go +++ b/analyzer/argument.go @@ -29,8 +29,7 @@ func (analyzer AnalysisOperation) analyzeArgument ( ) { switch inputArgument.Kind() { case parser.ArgumentKindNil: - panic ( - "invalid state: attempt to analyze nil argument") + panic("invalid state: attempt to analyze nil argument") case parser.ArgumentKindPhrase: // TODO @@ -41,10 +40,7 @@ func (analyzer AnalysisOperation) analyzeArgument ( case parser.ArgumentKindSubscript: // TODO - case parser.ArgumentKindObjectDefaultValues: - // TODO - - case parser.ArgumentKindArrayDefaultValues: + case parser.ArgumentKindList: // TODO case parser.ArgumentKindIdentifier: @@ -67,11 +63,6 @@ func (analyzer AnalysisOperation) analyzeArgument ( case parser.ArgumentKindRune: outputArgument = RuneLiteral(inputArgument.Value().(rune)) - - case parser.ArgumentKindOperator: - panic ( - "invalid state: attempt to analyze operator argument " + - "directly") } return } diff --git a/analyzer/type-section.go b/analyzer/type-section.go index 4198fe7..f1568d1 100644 --- a/analyzer/type-section.go +++ b/analyzer/type-section.go @@ -9,6 +9,33 @@ type TypeSection struct { sectionBase what Type complete bool + // TODO: do not add members from parent type. instead have a member + // function to discern whether this type contains a particular member, + // and have it recurse all the way up the family tree. it will be the + // translator's job to worry about what members are placed where. + members []ObjectMember +} + +// ObjectMember is a member of an object type. +type ObjectMember struct { + name string + + // even if there is a private permission in another module, we still + // need to include it in the semantic analysis because we need to know + // how many members objects have. + permission types.Permission + + what Type +} + +func (member ObjectMember) ToString (indent int) (output string) { + output += doIndent ( + indent, + member.name, " ", + member.permission.ToString(), + "\n") + output += member.what.ToString(indent + 1) + return } // ToString returns all data stored within the type section, in string form. @@ -26,7 +53,8 @@ func (analyzer AnalysisOperation) analyzeTypeSection () ( inputSection := analyzer.currentSection.(parser.TypeSection) if inputSection.Permission() == types.PermissionReadWrite { err = inputSection.NewError ( - "rw permission not understood in this context, try ro", + "read-write (rw) permission not understood in this " + + "context, try read-only (ro)", infoerr.ErrorKindError) } diff --git a/analyzer/type.go b/analyzer/type.go index a038309..f5df3e1 100644 --- a/analyzer/type.go +++ b/analyzer/type.go @@ -1,6 +1,6 @@ package analyzer -import "git.tebibyte.media/arf/arf/types" +// import "git.tebibyte.media/arf/arf/types" import "git.tebibyte.media/arf/arf/parser" import "git.tebibyte.media/arf/arf/infoerr" @@ -21,28 +21,6 @@ const ( TypeKindObject ) -// ObjectMember is a member of an object type. -type ObjectMember struct { - name string - - // even if there is a private permission in another module, we still - // need to include it in the semantic analysis because we need to know - // how many members objects have. - permission types.Permission - - what Type -} - -func (member ObjectMember) ToString (indent int) (output string) { - output += doIndent ( - indent, - member.name, " ", - member.permission.ToString(), - "\n") - output += member.what.ToString(indent + 1) - return -} - // Type represents a description of a type. It must eventually point to a // TypeSection. type Type struct { @@ -57,14 +35,6 @@ type Type struct { // of whatever the type is. even if the type is a variable length array. // because literally why not. length uint64 - - // this is only applicable for a TypeKindObject where new members are - // defined. - // TODO: do not add members from parent type. instead have a member - // function to discern whether this type contains a particular member, - // and have it recurse all the way up the family tree. it will be the - // translator's job to worry about what members are placed where. - members []ObjectMember } // ToString returns all data stored within the type, in string form. diff --git a/parser/type.go b/parser/type.go index 292ec32..fae0dd0 100644 --- a/parser/type.go +++ b/parser/type.go @@ -69,8 +69,6 @@ func (parser *ParsingOperation) parseTypeSection () ( section.members = append(section.members, member) if err != nil { return } } - - return } // parseTypeSectionMember parses a type section member variable. diff --git a/tests/analyzer/typeSection/main.arf b/tests/analyzer/typeSection/main.arf index 9858c4d..cceaf8c 100644 --- a/tests/analyzer/typeSection/main.arf +++ b/tests/analyzer/typeSection/main.arf @@ -1,4 +1,4 @@ :arf --- -type basicInt:Int:<5> +type ro basicInt:Int 5 diff --git a/types/iterator.go b/types/iterator.go index acc8cc2..a227068 100644 --- a/types/iterator.go +++ b/types/iterator.go @@ -39,7 +39,7 @@ func (iterator Iterator[VALUE_TYPE]) Value () (value VALUE_TYPE) { } // Next advances the iterator by 1. -func (iterator Iterator[VALUE_TYPE]) Next () { +func (iterator *Iterator[VALUE_TYPE]) Next () { iterator.index ++ }