From 2eab5877e1c634db872b595dd2414f4031ae4eb5 Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Mon, 13 Nov 2023 09:34:56 +0100 Subject: parser: initial support for type declarations. The parsing logic for type declarations is there. Note that no tokens are produced, only symbols. The different type kinds will be added next. --- parser/type.go | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) (limited to 'parser/type.go') diff --git a/parser/type.go b/parser/type.go index 00aedc8..41bcfe1 100644 --- a/parser/type.go +++ b/parser/type.go @@ -3,17 +3,28 @@ package parser import ( "errors" "fmt" - "log" "reflect" "strings" "github.com/gnolang/parscan/lang" ) -// ParseType parses a list of tokens defining a type expresssion and returns +type typeFlag int + +const ( + parseTypeIn typeFlag = iota + parseTypeOut + parseTypeVar + parseTypeType +) + +var ( + missingTypeError = errors.New("Missing type") +) + +// ParseTypeExpr parses a list of tokens defining a type expresssion and returns // the corresponding runtime type or an error. -func (p *Parser) ParseType(in Tokens) (typ reflect.Type, err error) { - log.Println("ParseType", in) +func (p *Parser) ParseTypeExpr(in Tokens) (typ reflect.Type, err error) { switch in[0].Id { case lang.Func: // Get argument and return token positions depending on function pattern: @@ -65,16 +76,6 @@ func (p *Parser) ParseType(in Tokens) (typ reflect.Type, err error) { return typ, err } -type typeFlag int - -const ( - parseTypeIn typeFlag = iota - parseTypeOut - parseTypeVar -) - -var missingTypeError = errors.New("Missing type") - // parseParamTypes parses a list of comma separated typed parameters and returns a list of // runtime types. Implicit parameter names and types are supported. func (p *Parser) parseParamTypes(in Tokens, flag typeFlag) (types []reflect.Type, vars []string, err error) { @@ -101,7 +102,7 @@ func (p *Parser) parseParamTypes(in Tokens, flag typeFlag) (types []reflect.Type continue } } - typ, err := p.ParseType(t) + typ, err := p.ParseTypeExpr(t) if err != nil { return nil, nil, err } -- cgit v1.2.3