Compare commits

...

2 Commits

Author SHA1 Message Date
Sasha Koshka befe371e4f What is anything anymore 2022-10-24 01:16:07 -04:00
Sasha Koshka dfa7d31163 Methods do not collide and are properly retrievable 2022-10-23 02:24:34 -04:00
6 changed files with 59 additions and 11 deletions

View File

@ -58,7 +58,7 @@ func (analyzer *analysisOperation) analyze () (err error) {
for !sections.End() {
_, err = analyzer.fetchSection(locator {
modulePath: analyzer.modulePath,
name: sections.Value().Name(),
name: sections.Key(),
})
if err != nil { return err }
sections.Next()
@ -93,7 +93,7 @@ func (analyzer *analysisOperation) fetchSection (
return
}
var parsedSection = tree.LookupSection(where.name)
var parsedSection = tree.LookupSection("", where.name)
if parsedSection == nil {
section = nil
return

View File

@ -1,5 +1,31 @@
package analyzer
import "git.tebibyte.media/arf/arf/parser"
// Block represents a scoped block of phrases.
type Block struct {
locatable
phrases []Phrase
// TODO: create a scope struct and embed it
}
func (block Block) ToString (indent int) (output string) {
output += doIndent(indent, "block\n")
// TODO: variables
// TODO: phrases
return
}
// analyzeBlock analyzes a scoped block of phrases.
// TODO: have a way to "start out" with a list of variables for things like
// arguments, and declarations inside of control flow statements
func (analyzer *analysisOperation) analyzeBlock (
inputBlock parser.Block,
) (
block Block,
err error,
) {
return
}

View File

@ -7,7 +7,8 @@ import "git.tebibyte.media/arf/arf/infoerr"
// FuncSection represents a type definition section.
type FuncSection struct {
sectionBase
external bool
root Block
external bool
}
// ToString returns all data stored within the function section, in string form.
@ -18,7 +19,7 @@ func (section FuncSection) ToString (indent int) (output string) {
output += "\n"
// TODO: arguments
// TODO: root block
output += section.root.ToString(indent + 1)
return
}
@ -53,6 +54,8 @@ func (analyzer *analysisOperation) analyzeFuncSection () (
outputSection.external = true
} else {
outputSection.root, err = analyzer.analyzeBlock(inputSection.Root())
if err != nil { return }
// TODO: analyze root block if not nil
}

View File

@ -3,8 +3,17 @@ 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) {
// 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 (
receiver string,
name string,
) (
section Section,
) {
if receiver != "" {
name = receiver + "_" + name
}
section = tree.sections[name]
return
}

View File

@ -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
}

View File

@ -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
---