Cleared particple code from parser
This commit is contained in:
parent
c323715505
commit
126bec1fc9
|
@ -3,81 +3,13 @@ package parser
|
|||
import "io"
|
||||
import "os"
|
||||
import "fmt"
|
||||
import "github.com/alecthomas/participle/v2"
|
||||
import "git.tebibyte.media/sashakoshka/fspl/lexer"
|
||||
import "git.tebibyte.media/sashakoshka/fspl/entity"
|
||||
import flexer "git.tebibyte.media/sashakoshka/fspl/lexer"
|
||||
|
||||
var parser = participle.MustBuild[Tree] (
|
||||
participle.Union[entity.TopLevel] (
|
||||
new(entity.Function),
|
||||
new(entity.Typedef),
|
||||
new(entity.Method)),
|
||||
participle.Union[entity.Type] (
|
||||
new(entity.TypeNamed),
|
||||
new(entity.TypePointer),
|
||||
new(entity.TypeInterface),
|
||||
new(entity.TypeStruct),
|
||||
new(entity.TypeArray),
|
||||
new(entity.TypeSlice)),
|
||||
participle.Union[entity.Expression] (
|
||||
new(entity.LiteralInt),
|
||||
new(entity.LiteralFloat),
|
||||
new(entity.LiteralString),
|
||||
new(entity.LiteralArray),
|
||||
new(entity.LiteralStruct),
|
||||
new(entity.LiteralBoolean),
|
||||
new(entity.LiteralNil),
|
||||
new(entity.Break),
|
||||
new(entity.Return),
|
||||
new(entity.IfElse),
|
||||
new(entity.Loop),
|
||||
new(entity.MethodCall),
|
||||
new(entity.MemberAccess),
|
||||
new(entity.Declaration),
|
||||
new(entity.Subscript),
|
||||
new(entity.Slice),
|
||||
new(entity.Length),
|
||||
new(entity.Dereference),
|
||||
new(entity.Reference),
|
||||
new(entity.ValueCast),
|
||||
new(entity.BitCast),
|
||||
new(entity.Operation),
|
||||
new(entity.Call),
|
||||
new(entity.Variable),
|
||||
new(entity.Block)),
|
||||
participle.Union[entity.Statement] (
|
||||
new(entity.LiteralInt),
|
||||
new(entity.LiteralFloat),
|
||||
new(entity.LiteralArray),
|
||||
new(entity.LiteralStruct),
|
||||
new(entity.LiteralBoolean),
|
||||
new(entity.LiteralNil),
|
||||
new(entity.Break),
|
||||
new(entity.Return),
|
||||
new(entity.Assignment),
|
||||
new(entity.IfElse),
|
||||
new(entity.Loop),
|
||||
new(entity.MethodCall),
|
||||
new(entity.MemberAccess),
|
||||
new(entity.Declaration),
|
||||
new(entity.Subscript),
|
||||
new(entity.Slice),
|
||||
new(entity.Length),
|
||||
new(entity.Dereference),
|
||||
new(entity.Reference),
|
||||
new(entity.ValueCast),
|
||||
new(entity.BitCast),
|
||||
new(entity.Operation),
|
||||
new(entity.Call),
|
||||
new(entity.Variable),
|
||||
new(entity.Block)),
|
||||
participle.UseLookahead(participle.MaxLookahead),
|
||||
participle.Lexer(flexer.NewDefinition()))
|
||||
|
||||
// Tree represents a parsed abstract syntax tree. It has no constructor and its
|
||||
// zero value can be used safely.
|
||||
type Tree struct {
|
||||
Declarations []entity.TopLevel `parser:" @@* "`
|
||||
Declarations []entity.TopLevel
|
||||
}
|
||||
|
||||
func (this *Tree) String () string {
|
||||
|
@ -91,11 +23,8 @@ func (this *Tree) String () string {
|
|||
|
||||
// Parse parses the contents of the given io.Reader into the tree.
|
||||
func (this *Tree) Parse (name string, file io.Reader) error {
|
||||
parsed, err := parser.Parse(name, file)
|
||||
if parsed != nil {
|
||||
this.Declarations = append(this.Declarations, parsed.Declarations...)
|
||||
}
|
||||
return err
|
||||
// TODO
|
||||
return nil
|
||||
}
|
||||
|
||||
// ParseFile parses the contents of the given file into the tree.
|
||||
|
|
Loading…
Reference in New Issue