syntax-tree-accessors #2
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user