implement-modules #43
@ -4,6 +4,7 @@ import "io"
|
||||
import "fmt"
|
||||
import "github.com/google/uuid"
|
||||
import "git.tebibyte.media/sashakoshka/fspl/lexer"
|
||||
import "git.tebibyte.media/sashakoshka/fspl/errors"
|
||||
import "git.tebibyte.media/sashakoshka/fspl/parser"
|
||||
import "git.tebibyte.media/sashakoshka/fspl/entity"
|
||||
|
||||
@ -31,6 +32,7 @@ func (this *Tree) Parse (lx lexer.Lexer) error {
|
||||
return parser.parseInto(this)
|
||||
}
|
||||
|
||||
// AddDirective adds a metadata directive to the tree.
|
||||
func (this *Tree) AddDirective (directive entity.Directive) {
|
||||
switch directive := directive.(type) {
|
||||
case *entity.Dependency:
|
||||
@ -65,6 +67,68 @@ func (this *treeParser) parse () error {
|
||||
err := this.Next()
|
||||
if err != nil { return err }
|
||||
|
||||
// TODO
|
||||
// String: UUID
|
||||
err = this.Expect(lexer.String)
|
||||
if err != nil { return err }
|
||||
id, err := uuid.Parse(this.Value())
|
||||
if err != nil {
|
||||
return errors.Errorf(this.Pos(), "%v", err.Error())
|
||||
}
|
||||
this.tree.UUID = id
|
||||
this.Next()
|
||||
|
||||
// parse directives
|
||||
for !this.EOF() {
|
||||
err := this.parseDirective()
|
||||
if err != nil { return err }
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (this *treeParser) bug () string {
|
||||
return fmt.Sprintln (
|
||||
"Bug detected in the compiler!\n" +
|
||||
"The metadata parser has taken an unexpected control path.",
|
||||
"This could be due to an un-implemented feature.\n" +
|
||||
"Please submit a report with this info and stack trace to:",
|
||||
"https://git.tebibyte.media/sashakoshka/fspl/issues\n" +
|
||||
"The token being parsed was:", this.Token)
|
||||
}
|
||||
|
||||
func (this *treeParser) parseDirective () error {
|
||||
err := this.ExpectValueDesc("directive", lexer.Symbol, "+")
|
||||
if err != nil { return err }
|
||||
|
||||
var directive entity.Directive
|
||||
switch this.Value() {
|
||||
case "+":
|
||||
// Symbol "+": Dependency
|
||||
directive, err = this.parseDependency()
|
||||
if err != nil { return err }
|
||||
default: panic(this.bug())
|
||||
}
|
||||
this.tree.AddDirective(directive)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (this *treeParser) parseDependency () (*entity.Dependency, error) {
|
||||
err := this.ExpectValueDesc("dependency", lexer.Symbol, "+")
|
||||
if err != nil { return nil, err }
|
||||
|
||||
err = this.ExpectNextDesc("address", lexer.String)
|
||||
if err != nil { return nil, err }
|
||||
dependency := &entity.Dependency {
|
||||
Position: this.Pos(),
|
||||
Address: entity.Address(this.Value()),
|
||||
}
|
||||
|
||||
this.Next()
|
||||
if this.Is(lexer.Ident) {
|
||||
// Ident: Nickname
|
||||
dependency.Nickname = this.Value()
|
||||
this.Next()
|
||||
}
|
||||
|
||||
return dependency, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user