Parse namespaced function calls
This commit is contained in:
parent
823cb44406
commit
8ec3649637
@ -7,12 +7,13 @@ import "git.tebibyte.media/sashakoshka/fspl/entity"
|
||||
// Expression decision tree flow:
|
||||
//
|
||||
// | +Ident =Variable
|
||||
// | | 'true' =LiteralBoolean
|
||||
// | | 'false' =LiteralBoolean
|
||||
// | | 'nil' =LiteralNil
|
||||
// | | 'if' =IfElse
|
||||
// | | 'loop' =Loop
|
||||
// | | +Colon =Declaration
|
||||
// | | 'true' =LiteralBoolean
|
||||
// | | 'false' =LiteralBoolean
|
||||
// | | 'nil' =LiteralNil
|
||||
// | | 'if' =IfElse
|
||||
// | | 'loop' =Loop
|
||||
// | | +Colon =Declaration
|
||||
// | | +DoubleColon =Call
|
||||
// |
|
||||
// | +LParen X
|
||||
// | | +Star =LiteralArray
|
||||
@ -145,13 +146,33 @@ func (this *Parser) parseExpressionRootIdent () (entity.Expression, error) {
|
||||
err := this.expect(lexer.Ident)
|
||||
if err != nil { return nil, err }
|
||||
name := this.value()
|
||||
pos := this.pos()
|
||||
|
||||
switch name {
|
||||
case "true", "false": return this.parseLiteralBoolean ()
|
||||
case "nil": return this.parseLiteralNil()
|
||||
case "if": return this.parseIfElse()
|
||||
case "loop": return this.parseLoop()
|
||||
default: return this.parseVariableOrDeclaration()
|
||||
default:
|
||||
println(this.token.String())
|
||||
this.next()
|
||||
switch this.kind() {
|
||||
case lexer.Colon:
|
||||
// Colon: declaration
|
||||
return this.parseDeclarationCore(pos, name)
|
||||
case lexer.DoubleColon:
|
||||
// DoubleColon: call
|
||||
err := this.expectNext(lexer.LBracket)
|
||||
if err != nil { return nil, err }
|
||||
this.next()
|
||||
return this.parseCallCore(pos, name)
|
||||
default:
|
||||
// *: variable
|
||||
return &entity.Variable {
|
||||
Position: pos,
|
||||
Name: name,
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
panic(this.bug())
|
||||
}
|
||||
@ -192,7 +213,7 @@ func (this *Parser) parseExpressionRootLBracketIdent (pos errors.Position) (enti
|
||||
|
||||
switch name {
|
||||
case "break", "return": return this.parseReturnOrBreakCore(pos)
|
||||
default: return this.parseCallCore(pos)
|
||||
default: return this.parseCallCore(pos, "")
|
||||
}
|
||||
panic(this.bug())
|
||||
}
|
||||
@ -254,11 +275,12 @@ func (this *Parser) parseExpressionRootLBracketSymbol (pos errors.Position) (ent
|
||||
panic(this.bug())
|
||||
}
|
||||
|
||||
func (this *Parser) parseCallCore (pos errors.Position) (*entity.Call, error) {
|
||||
func (this *Parser) parseCallCore (pos errors.Position, module string) (*entity.Call, error) {
|
||||
err := this.expect(lexer.Ident)
|
||||
if err != nil { return nil, err }
|
||||
call := &entity.Call {
|
||||
Position: pos,
|
||||
Module: module,
|
||||
Name: this.value(),
|
||||
}
|
||||
this.next()
|
||||
@ -541,23 +563,6 @@ func (this *Parser) parseDeclarationCore (pos errors.Position, name string) (*en
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (this *Parser) parseVariableOrDeclaration () (entity.Expression, error) {
|
||||
err := this.expectDesc("variable or declaration", lexer.Ident)
|
||||
if err != nil { return nil, err }
|
||||
|
||||
variable := &entity.Variable {
|
||||
Position: this.pos(),
|
||||
Name: this.value(),
|
||||
}
|
||||
|
||||
this.next()
|
||||
if this.token.Is(lexer.Colon) {
|
||||
return this.parseDeclarationCore(variable.Position, variable.Name)
|
||||
} else {
|
||||
return variable, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (this *Parser) parseIfElse () (*entity.IfElse, error) {
|
||||
err := this.expectValue(lexer.Ident, "if")
|
||||
if err != nil { return nil, err }
|
||||
|
Loading…
Reference in New Issue
Block a user