Parse pointers/slices
This commit is contained in:
parent
6ad56ed4ee
commit
59e3185500
@ -1,5 +1,6 @@
|
||||
package parser
|
||||
|
||||
import "fmt"
|
||||
import "git.tebibyte.media/sashakoshka/fspl/lexer"
|
||||
import "git.tebibyte.media/sashakoshka/fspl/entity"
|
||||
|
||||
@ -13,11 +14,10 @@ var startTokensType = []lexer.TokenKind {
|
||||
}
|
||||
|
||||
func (this *Parser) parseType () (entity.Type, error) {
|
||||
println(this.token.String())
|
||||
err := this.expectDesc(descriptionType, startTokensType...)
|
||||
if err != nil { return nil, err }
|
||||
|
||||
switch this.token.Kind {
|
||||
switch this.kind() {
|
||||
case lexer.Ident:
|
||||
ident := this.token.Value
|
||||
err := this.expectNext(lexer.DoubleColon)
|
||||
@ -30,6 +30,8 @@ func (this *Parser) parseType () (entity.Type, error) {
|
||||
return this.parseTypeNamedCore("")
|
||||
|
||||
case lexer.Star:
|
||||
return this.parseTypePointerOrSlice()
|
||||
|
||||
case lexer.Int:
|
||||
case lexer.LParen:
|
||||
}
|
||||
@ -39,22 +41,42 @@ func (this *Parser) parseType () (entity.Type, error) {
|
||||
func (this *Parser) parseTypeNamedCore (module string) (entity.Type, error) {
|
||||
err := this.expect(lexer.TypeIdent)
|
||||
if err != nil { return nil, err }
|
||||
typeName := this.token.Value
|
||||
this.next()
|
||||
|
||||
defer this.next()
|
||||
return &entity.TypeNamed {
|
||||
Name: typeName,
|
||||
Position: this.pos(),
|
||||
Name: this.value(),
|
||||
Module: module,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (this *Parser) parseTypePointer () (entity.Type, error) {
|
||||
// TODO
|
||||
return nil, nil
|
||||
func (this *Parser) parseTypePointerOrSlice () (entity.Type, error) {
|
||||
err := this.expectDesc("Pointer type or Slice type", lexer.Star)
|
||||
if err != nil { return nil, err }
|
||||
start := this.pos()
|
||||
|
||||
xpc := appendCopy(startTokensType, lexer.Colon)
|
||||
fmt.Println(xpc)
|
||||
err = this.expectNextDesc("Colon or Type", xpc...)
|
||||
if err != nil { return nil, err }
|
||||
|
||||
if this.token.Is(lexer.Colon) {
|
||||
this.next()
|
||||
element, err := this.parseType()
|
||||
if err != nil { return nil, err }
|
||||
return &entity.TypeSlice {
|
||||
Position: start.Union(this.pos()),
|
||||
Element: element,
|
||||
}, nil
|
||||
} else {
|
||||
referenced, err := this.parseType()
|
||||
if err != nil { return nil, err }
|
||||
return &entity.TypePointer {
|
||||
Position: start.Union(this.pos()),
|
||||
Referenced: referenced,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (this *Parser) parseTypeSlice () (entity.Type, error) {
|
||||
// TODO
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (this *Parser) parseTypeArray () (entity.Type, error) {
|
||||
@ -86,3 +108,4 @@ func (this *Parser) parseTypeFloat () (entity.Type, error) {
|
||||
// TODO
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user