Removed many cringe pass-by-references
This commit is contained in:
parent
f3c72f8f30
commit
691df94ef4
@ -3,8 +3,6 @@ package parser
|
|||||||
import "git.tebibyte.media/arf/arf/lexer"
|
import "git.tebibyte.media/arf/arf/lexer"
|
||||||
import "git.tebibyte.media/arf/arf/infoerr"
|
import "git.tebibyte.media/arf/arf/infoerr"
|
||||||
|
|
||||||
// TODO: parser must ensure that these names are unique
|
|
||||||
|
|
||||||
// parse body parses the body of an arf file, after the metadata header.
|
// parse body parses the body of an arf file, after the metadata header.
|
||||||
func (parser *ParsingOperation) parseBody () (err error) {
|
func (parser *ParsingOperation) parseBody () (err error) {
|
||||||
for {
|
for {
|
||||||
|
@ -5,13 +5,12 @@ import "git.tebibyte.media/arf/arf/lexer"
|
|||||||
|
|
||||||
// parseData parses a data section.
|
// parseData parses a data section.
|
||||||
func (parser *ParsingOperation) parseDataSection () (
|
func (parser *ParsingOperation) parseDataSection () (
|
||||||
section *DataSection,
|
section DataSection,
|
||||||
err error,
|
err error,
|
||||||
) {
|
) {
|
||||||
err = parser.expect(lexer.TokenKindName)
|
err = parser.expect(lexer.TokenKindName)
|
||||||
if err != nil { return }
|
if err != nil { return }
|
||||||
|
|
||||||
section = &DataSection { }
|
|
||||||
section.location = parser.token.Location()
|
section.location = parser.token.Location()
|
||||||
|
|
||||||
err = parser.nextToken(lexer.TokenKindPermission)
|
err = parser.nextToken(lexer.TokenKindPermission)
|
||||||
|
@ -6,13 +6,12 @@ import "git.tebibyte.media/arf/arf/infoerr"
|
|||||||
|
|
||||||
// parseEnumSection parses an enumerated type section.
|
// parseEnumSection parses an enumerated type section.
|
||||||
func (parser *ParsingOperation) parseEnumSection () (
|
func (parser *ParsingOperation) parseEnumSection () (
|
||||||
section *EnumSection,
|
section EnumSection,
|
||||||
err error,
|
err error,
|
||||||
) {
|
) {
|
||||||
err = parser.expect(lexer.TokenKindName)
|
err = parser.expect(lexer.TokenKindName)
|
||||||
if err != nil { return }
|
if err != nil { return }
|
||||||
|
|
||||||
section = &EnumSection { }
|
|
||||||
section.location = parser.token.Location()
|
section.location = parser.token.Location()
|
||||||
|
|
||||||
// get permission
|
// get permission
|
||||||
@ -38,7 +37,7 @@ func (parser *ParsingOperation) parseEnumSection () (
|
|||||||
if err != nil { return }
|
if err != nil { return }
|
||||||
|
|
||||||
// parse members
|
// parse members
|
||||||
err = parser.parseEnumMembers(section)
|
err = parser.parseEnumMembers(§ion)
|
||||||
if err != nil { return }
|
if err != nil { return }
|
||||||
|
|
||||||
if len(section.members) == 0 {
|
if len(section.members) == 0 {
|
||||||
|
@ -6,16 +6,14 @@ import "git.tebibyte.media/arf/arf/infoerr"
|
|||||||
|
|
||||||
// parseFaceSection parses an interface section.
|
// parseFaceSection parses an interface section.
|
||||||
func (parser *ParsingOperation) parseFaceSection () (
|
func (parser *ParsingOperation) parseFaceSection () (
|
||||||
section *FaceSection,
|
section FaceSection,
|
||||||
err error,
|
err error,
|
||||||
) {
|
) {
|
||||||
err = parser.expect(lexer.TokenKindName)
|
err = parser.expect(lexer.TokenKindName)
|
||||||
if err != nil { return }
|
if err != nil { return }
|
||||||
|
|
||||||
section = &FaceSection {
|
section.behaviors = make(map[string] FaceBehavior)
|
||||||
behaviors: make(map[string] FaceBehavior),
|
section.location = parser.token.Location()
|
||||||
}
|
|
||||||
section.location = parser.token.Location()
|
|
||||||
|
|
||||||
// get permission
|
// get permission
|
||||||
err = parser.nextToken(lexer.TokenKindPermission)
|
err = parser.nextToken(lexer.TokenKindPermission)
|
||||||
|
@ -6,13 +6,12 @@ import "git.tebibyte.media/arf/arf/infoerr"
|
|||||||
|
|
||||||
// parseFunc parses a function section.
|
// parseFunc parses a function section.
|
||||||
func (parser *ParsingOperation) parseFuncSection () (
|
func (parser *ParsingOperation) parseFuncSection () (
|
||||||
section *FuncSection,
|
section FuncSection,
|
||||||
err error,
|
err error,
|
||||||
) {
|
) {
|
||||||
err = parser.expect(lexer.TokenKindName)
|
err = parser.expect(lexer.TokenKindName)
|
||||||
if err != nil { return }
|
if err != nil { return }
|
||||||
|
|
||||||
section = &FuncSection { }
|
|
||||||
section.location = parser.token.Location()
|
section.location = parser.token.Location()
|
||||||
|
|
||||||
// get permission
|
// get permission
|
||||||
@ -30,7 +29,7 @@ func (parser *ParsingOperation) parseFuncSection () (
|
|||||||
if err != nil { return }
|
if err != nil { return }
|
||||||
err = parser.nextToken()
|
err = parser.nextToken()
|
||||||
if err != nil { return }
|
if err != nil { return }
|
||||||
err = parser.parseFuncArguments(section)
|
err = parser.parseFuncArguments(§ion)
|
||||||
if err != nil { return }
|
if err != nil { return }
|
||||||
|
|
||||||
// check to see if the function is external
|
// check to see if the function is external
|
||||||
|
@ -7,13 +7,12 @@ import "git.tebibyte.media/arf/arf/infoerr"
|
|||||||
// parseObjtSection parses an object type definition. This allows for structured
|
// parseObjtSection parses an object type definition. This allows for structured
|
||||||
// types to be defined, and for member variables to be added and overridden.
|
// types to be defined, and for member variables to be added and overridden.
|
||||||
func (parser *ParsingOperation) parseObjtSection () (
|
func (parser *ParsingOperation) parseObjtSection () (
|
||||||
section *ObjtSection,
|
section ObjtSection,
|
||||||
err error,
|
err error,
|
||||||
) {
|
) {
|
||||||
err = parser.expect(lexer.TokenKindName)
|
err = parser.expect(lexer.TokenKindName)
|
||||||
if err != nil { return }
|
if err != nil { return }
|
||||||
|
|
||||||
section = &ObjtSection { }
|
|
||||||
section.location = parser.token.Location()
|
section.location = parser.token.Location()
|
||||||
|
|
||||||
// get permission
|
// get permission
|
||||||
@ -39,7 +38,7 @@ func (parser *ParsingOperation) parseObjtSection () (
|
|||||||
if err != nil { return }
|
if err != nil { return }
|
||||||
|
|
||||||
// parse members
|
// parse members
|
||||||
err = parser.parseObjtMembers(section)
|
err = parser.parseObjtMembers(§ion)
|
||||||
if err != nil { return }
|
if err != nil { return }
|
||||||
|
|
||||||
if len(section.members) == 0 {
|
if len(section.members) == 0 {
|
||||||
|
@ -30,7 +30,7 @@ func sortMapKeysAlphabetically[KEY_TYPE any] (
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tree *SyntaxTree) ToString (indent int) (output string) {
|
func (tree SyntaxTree) ToString (indent int) (output string) {
|
||||||
output += doIndent(indent, ":arf\n")
|
output += doIndent(indent, ":arf\n")
|
||||||
|
|
||||||
if tree.author != "" {
|
if tree.author != "" {
|
||||||
@ -66,7 +66,7 @@ func (identifier Identifier) ToString () (output string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (what *Type) ToString () (output string) {
|
func (what Type) ToString () (output string) {
|
||||||
if what.kind == TypeKindBasic {
|
if what.kind == TypeKindBasic {
|
||||||
output += what.name.ToString()
|
output += what.name.ToString()
|
||||||
} else {
|
} else {
|
||||||
@ -130,7 +130,7 @@ func (values ArrayInitializationValues) ToString (
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (argument *Argument) ToString (indent int, breakLine bool) (output string) {
|
func (argument Argument) ToString (indent int, breakLine bool) (output string) {
|
||||||
if !breakLine { indent = 0 }
|
if !breakLine { indent = 0 }
|
||||||
if argument.kind == ArgumentKindNil {
|
if argument.kind == ArgumentKindNil {
|
||||||
output += "NIL-ARGUMENT"
|
output += "NIL-ARGUMENT"
|
||||||
@ -255,7 +255,7 @@ func (argument *Argument) ToString (indent int, breakLine bool) (output string)
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (section *DataSection) ToString (indent int) (output string) {
|
func (section DataSection) ToString (indent int) (output string) {
|
||||||
output += doIndent (
|
output += doIndent (
|
||||||
indent,
|
indent,
|
||||||
"data ",
|
"data ",
|
||||||
@ -279,7 +279,7 @@ func (section *DataSection) ToString (indent int) (output string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (section *TypeSection) ToString (indent int) (output string) {
|
func (section TypeSection) ToString (indent int) (output string) {
|
||||||
output += doIndent (
|
output += doIndent (
|
||||||
indent,
|
indent,
|
||||||
"type ",
|
"type ",
|
||||||
@ -331,7 +331,7 @@ func (member ObjtMember) ToString (indent int) (output string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (section *ObjtSection) ToString (indent int) (output string) {
|
func (section ObjtSection) ToString (indent int) (output string) {
|
||||||
output += doIndent (
|
output += doIndent (
|
||||||
indent,
|
indent,
|
||||||
"objt ",
|
"objt ",
|
||||||
@ -345,7 +345,7 @@ func (section *ObjtSection) ToString (indent int) (output string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (section *EnumSection) ToString (indent int) (output string) {
|
func (section EnumSection) ToString (indent int) (output string) {
|
||||||
output += doIndent (
|
output += doIndent (
|
||||||
indent,
|
indent,
|
||||||
"enum ",
|
"enum ",
|
||||||
@ -373,7 +373,7 @@ func (section *EnumSection) ToString (indent int) (output string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (section *FaceSection) ToString (indent int) (output string) {
|
func (section FaceSection) ToString (indent int) (output string) {
|
||||||
output += doIndent (
|
output += doIndent (
|
||||||
indent,
|
indent,
|
||||||
"face ",
|
"face ",
|
||||||
@ -388,7 +388,7 @@ func (section *FaceSection) ToString (indent int) (output string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (behavior *FaceBehavior) ToString (indent int) (output string) {
|
func (behavior FaceBehavior) ToString (indent int) (output string) {
|
||||||
output += doIndent(indent, behavior.name, "\n")
|
output += doIndent(indent, behavior.name, "\n")
|
||||||
|
|
||||||
for _, inputItem := range behavior.inputs {
|
for _, inputItem := range behavior.inputs {
|
||||||
@ -455,7 +455,7 @@ func (funcOutput FuncOutput) ToString () (output string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (section *FuncSection) ToString (indent int) (output string) {
|
func (section FuncSection) ToString (indent int) (output string) {
|
||||||
output += doIndent (
|
output += doIndent (
|
||||||
indent,
|
indent,
|
||||||
"func ",
|
"func ",
|
||||||
|
@ -171,8 +171,7 @@ type DataSection struct {
|
|||||||
nameable
|
nameable
|
||||||
typeable
|
typeable
|
||||||
permissionable
|
permissionable
|
||||||
|
valuable
|
||||||
value Argument
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TypeSection represents a blind type definition.
|
// TypeSection represents a blind type definition.
|
||||||
@ -202,7 +201,7 @@ type ObjtSection struct {
|
|||||||
permissionable
|
permissionable
|
||||||
inherits Identifier
|
inherits Identifier
|
||||||
|
|
||||||
members []ObjtMember
|
members []ObjtMember
|
||||||
}
|
}
|
||||||
|
|
||||||
// EnumMember represents a member of an enum section.
|
// EnumMember represents a member of an enum section.
|
||||||
|
@ -6,13 +6,12 @@ import "git.tebibyte.media/arf/arf/lexer"
|
|||||||
// parseTypeSection parses a blind type definition, meaning it can inherit from
|
// parseTypeSection parses a blind type definition, meaning it can inherit from
|
||||||
// anything including primitives, but cannot define structure.
|
// anything including primitives, but cannot define structure.
|
||||||
func (parser *ParsingOperation) parseTypeSection () (
|
func (parser *ParsingOperation) parseTypeSection () (
|
||||||
section *TypeSection,
|
section TypeSection,
|
||||||
err error,
|
err error,
|
||||||
) {
|
) {
|
||||||
err = parser.expect(lexer.TokenKindName)
|
err = parser.expect(lexer.TokenKindName)
|
||||||
if err != nil { return }
|
if err != nil { return }
|
||||||
|
|
||||||
section = &TypeSection { }
|
|
||||||
section.location = parser.token.Location()
|
section.location = parser.token.Location()
|
||||||
|
|
||||||
// get permission
|
// get permission
|
||||||
|
Reference in New Issue
Block a user