From 319ed789bf49384b32b787a8d9f9fa59496143e2 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Sun, 4 Sep 2022 23:47:56 -0400 Subject: [PATCH] Added accessors to ArrayInitializationValues --- parser/accessors.go | 30 +++++++++++++++++++++++++++++- parser/misc.go | 23 +++++++++++++++++++++++ types/iterator.go | 4 ++-- 3 files changed, 54 insertions(+), 3 deletions(-) diff --git a/parser/accessors.go b/parser/accessors.go index 3a207ce..4c32ea0 100644 --- a/parser/accessors.go +++ b/parser/accessors.go @@ -1,12 +1,20 @@ package parser +import "git.tebibyte.media/arf/arf/types" + // LookupSection looks returns the section under the give name. If the section // does not exist, nil is returned. -func (tree *SyntaxTree) LookupSection (name string) (section Section) { +func (tree SyntaxTree) LookupSection (name string) (section Section) { section = tree.sections[name] return } +// Sections returns an iterator for the tree's sections +func (tree SyntaxTree) Sections () (iterator types.Iterator[Section]) { + iterator = types.NewIterator(tree.sections) + return +} + // Kind returns the section's kind (SectionKindType). func (section TypeSection) Kind () (kind SectionKind) { kind = SectionKindType @@ -93,3 +101,23 @@ func (what Type) Points () (points Type) { } return } + +// Values returns an iterator for the initialization values +func (values ObjectInitializationValues) Sections () ( + iterator types.Iterator[Argument], +) { + iterator = types.NewIterator(values.attributes) + return +} + +// Length returns the amount of values +func (values ArrayInitializationValues) Length () (length int) { + length = len(values.values) + return +} + +// Item returns the value at index +func (values ArrayInitializationValues) Value (index int) (value Argument) { + value = values.values[index] + return +} diff --git a/parser/misc.go b/parser/misc.go index 121df15..9ccc17c 100644 --- a/parser/misc.go +++ b/parser/misc.go @@ -3,6 +3,29 @@ package parser import "git.tebibyte.media/arf/arf/lexer" import "git.tebibyte.media/arf/arf/infoerr" +// TODO: need to come up with another syntax for bitfields, and use that syntax +// for fixed-length arrays. the problem is, we cant use {} for those kinds of +// arrays because they aren't pointers under the hood and that goes against the +// arf design goals in a nasty ugly way, and not only that. but the :mut type +// qualifier is meaningless on fixed length arrays now. the bit field syntax +// solves both of these problems very gracefully. but now, the problem is coming +// up with new bit field syntax. implementing this change is extremely +// necessary, for it will supercharge the coherency of the language and make it +// way more awesome. +// +// this new syntax cannot conflict with arguments, so it cannot have any +// tokens that begin those. basically all symbol tokens are on the table here. +// some ideas: +// +// ro member:Type ~ 4 +// ro member:Type & 4 <- i like this one because binary &. so intuitive. +// ro member:Type % 4 +// ro member:Type | 4 +// ro member:Type ! 4 +// ro member:Type (4) <- this looks phenomenal, but it needs new tokens not +// used anywhere else, and it would be mildly annoying +// to parse. + // parseType parses a type notation of the form Name, {Name}, etc. func (parser *ParsingOperation) parseType () (what Type, err error) { err = parser.expect(lexer.TokenKindName, lexer.TokenKindLBrace) diff --git a/types/iterator.go b/types/iterator.go index 0dc72f7..acc8cc2 100644 --- a/types/iterator.go +++ b/types/iterator.go @@ -43,8 +43,8 @@ func (iterator Iterator[VALUE_TYPE]) Next () { iterator.index ++ } -// AtEnd returns whether the iterator has reached the end of the map. -func (iterator Iterator[VALUE_TYPE]) AtEnd () (atEnd bool) { +// End returns whether the iterator has reached the end of the map. +func (iterator Iterator[VALUE_TYPE]) End () (atEnd bool) { atEnd = iterator.index >= len(iterator.keys) || iterator.index < 0 return }