diff options
| author | Marc Vertes <mvertes@free.fr> | 2023-11-13 09:34:56 +0100 |
|---|---|---|
| committer | Marc Vertes <mvertes@free.fr> | 2023-11-13 09:34:56 +0100 |
| commit | 2eab5877e1c634db872b595dd2414f4031ae4eb5 (patch) | |
| tree | 66cf2f71f0e449ee629d684b4f9fe30d7bf1d61f /parser/type.go | |
| parent | 1977ce7c976cbbd5bd0de1d479a0abe269e62f3d (diff) | |
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.
Diffstat (limited to 'parser/type.go')
| -rw-r--r-- | parser/type.go | 31 |
1 files changed, 16 insertions, 15 deletions
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 } |
