Parser now has something of a concept of modules
This commit is contained in:
parent
89500ec5ef
commit
c69091898a
|
@ -37,7 +37,7 @@ func testReaderErr (
|
|||
test.Error("lexer returned error:", err)
|
||||
return
|
||||
}
|
||||
err = ast.Parse(lx)
|
||||
err = ast.Parse(fsplParser.UnitInfo { }, lx)
|
||||
if err != nil {
|
||||
test.Error("parser returned error:", err)
|
||||
return
|
||||
|
@ -81,7 +81,7 @@ func testReader (test *testing.T, inputs ...io.Reader) {
|
|||
test.Error("lexer returned error:", err)
|
||||
return
|
||||
}
|
||||
err = ast.Parse(lx)
|
||||
err = ast.Parse(fsplParser.UnitInfo { }, lx)
|
||||
if err != nil {
|
||||
test.Error("parser returned error:", err)
|
||||
return
|
||||
|
|
|
@ -15,7 +15,7 @@ func testString (test *testing.T, correct string, input string) {
|
|||
test.Error("lexer returned error:", err)
|
||||
return
|
||||
}
|
||||
err = ast.Parse(lx)
|
||||
err = ast.Parse(fsplParser.UnitInfo { }, lx)
|
||||
if err != nil && err != io.EOF{
|
||||
test.Error("parser returned error:", err)
|
||||
return
|
||||
|
|
|
@ -9,7 +9,9 @@ import "git.tebibyte.media/sashakoshka/fspl/parser"
|
|||
// a tree.
|
||||
type treeParser struct {
|
||||
parser.Parser
|
||||
tree *Tree
|
||||
tree *Tree
|
||||
info UnitInfo
|
||||
skim bool
|
||||
}
|
||||
|
||||
// newParser creates a new parser that parses the output of the given lexer.
|
||||
|
|
|
@ -14,7 +14,7 @@ func testString (test *testing.T, correct string, input string) {
|
|||
test.Error("lexer returned error:\n" + errors.Format(err))
|
||||
return
|
||||
}
|
||||
err = ast.Parse(lx)
|
||||
err = ast.Parse(UnitInfo { }, lx)
|
||||
if err != nil && err != io.EOF{
|
||||
test.Error("parser returned error:\n" + errors.Format(err))
|
||||
return
|
||||
|
|
|
@ -1,9 +1,17 @@
|
|||
package fsplParser
|
||||
|
||||
import "fmt"
|
||||
import "github.com/google/uuid"
|
||||
import "git.tebibyte.media/sashakoshka/fspl/lexer"
|
||||
import "git.tebibyte.media/sashakoshka/fspl/entity"
|
||||
|
||||
// UnitInfo maps nicknames to unit UUIDs, and gives a UUID for the unit being
|
||||
// parsed.
|
||||
type UnitInfo struct {
|
||||
UUID uuid.UUID
|
||||
Dependencies map[string] uuid.UUID
|
||||
}
|
||||
|
||||
// Tree represents a parsed abstract syntax tree. It has no constructor and its
|
||||
// zero value can be used safely.
|
||||
type Tree struct {
|
||||
|
@ -21,10 +29,20 @@ func (this *Tree) String () string {
|
|||
return out
|
||||
}
|
||||
|
||||
|
||||
// Parse parses the output of the given lexer into the tree.
|
||||
func (this *Tree) Parse (lx lexer.Lexer) error {
|
||||
func (this *Tree) Parse (info UnitInfo, lx lexer.Lexer) error {
|
||||
parser, err := newParser(lx)
|
||||
parser.info = info
|
||||
if err != nil { return err }
|
||||
return parser.parseInto(this)
|
||||
}
|
||||
|
||||
// ParseDependency is like Parse, but does not keep code within functions and
|
||||
// methods, instead marking them as external.
|
||||
func (this *Tree) ParseDependency (info UnitInfo, lx lexer.Lexer) error {
|
||||
parser, err := newParser(lx)
|
||||
parser.skim = true
|
||||
parser.info = info
|
||||
if err != nil { return err }
|
||||
return parser.parseInto(this)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue