Methods do not collide and are properly retrievable
This commit is contained in:
parent
5641220986
commit
dfa7d31163
@ -3,7 +3,8 @@ 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.
|
||||
// does not exist, nil is returned. If a method is being searched for, the type
|
||||
// name of its receiver should be passed. If not, it should just be left blank.
|
||||
func (tree SyntaxTree) LookupSection (name string) (section Section) {
|
||||
section = tree.sections[name]
|
||||
return
|
||||
|
@ -53,7 +53,17 @@ func (parser *parsingOperation) parseBody () (err error) {
|
||||
// addSection adds a section to the tree, ensuring it has a unique name within
|
||||
// the module.
|
||||
func (tree *SyntaxTree) addSection (section Section) (err error) {
|
||||
_, exists := tree.sections[section.Name()]
|
||||
index := section.Name()
|
||||
|
||||
funcSection, isFuncSection := section.(FuncSection)
|
||||
if isFuncSection {
|
||||
receiver := funcSection.receiver
|
||||
if receiver != nil {
|
||||
index = receiver.what.points.name.trail[0] + "_" + index
|
||||
}
|
||||
}
|
||||
|
||||
_, exists := tree.sections[index]
|
||||
if exists {
|
||||
err = section.NewError (
|
||||
"cannot have multiple sections with the same name",
|
||||
@ -61,6 +71,6 @@ func (tree *SyntaxTree) addSection (section Section) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
tree.sections[section.Name()] = section
|
||||
tree.sections[index] = section
|
||||
return
|
||||
}
|
||||
|
@ -6,13 +6,13 @@ func TestFunc (test *testing.T) {
|
||||
checkTree ("../tests/parser/func", false,
|
||||
`:arf
|
||||
---
|
||||
func ro aBasicExternal
|
||||
func ro bMethod
|
||||
@ bird:{Bird}
|
||||
> someInput:Int:mut
|
||||
< someOutput:Int 4
|
||||
---
|
||||
external
|
||||
func ro bMethod
|
||||
@ bird:{Bird}
|
||||
func ro aBasicExternal
|
||||
> someInput:Int:mut
|
||||
< someOutput:Int 4
|
||||
---
|
||||
|
Reference in New Issue
Block a user