implement-modules #43

Closed
sashakoshka wants to merge 502 commits from implement-modules into main
2 changed files with 31 additions and 5 deletions
Showing only changes of commit 1bf47a9ebe - Show all commits

View File

@ -10,7 +10,7 @@
| | +Star =LiteralArray
| | +Dot =LiteralStruct
|
| +LBracket | +Ident =Call *
| +LBracket | +Ident =Call
| | | 'break' =Break
| | | 'return' =Return
| |

View File

@ -108,7 +108,7 @@ func (this *Parser) parseExpressionRootLBracketIdent (pos errors.Position) (enti
switch name {
case "break", "return": return this.parseReturnOrBreakCore(pos)
default: // TODO return this.parseCallCore(pos)
default: return this.parseCallCore(pos)
}
panic(this.bug())
}
@ -119,17 +119,17 @@ func (this *Parser) parseReturnOrBreakCore (pos errors.Position) (entity.Express
name := this.value()
err = this.expectNextDesc (
"Expression or Call end",
"Expression or end of " + name,
appendCopy(startTokensExpression, lexer.RBracket)...)
if err != nil { return nil, err }
var value entity.Expression
if this.token.Is(startTokensExpression...) {
// startTokensExpression...: return/break expression
// startTokensExpression...: value expression
value, err = this.parseExpression()
if err != nil { return nil, err }
}
err = this.expectDesc("Call end", lexer.RBracket)
err = this.expectDesc("end of " + name, lexer.RBracket)
if err != nil { return nil, err }
pos = pos.Union(this.pos())
this.next()
@ -149,6 +149,32 @@ func (this *Parser) parseReturnOrBreakCore (pos errors.Position) (entity.Express
panic(this.bug())
}
func (this *Parser) parseCallCore (pos errors.Position) (*entity.Call, error) {
err := this.expect(lexer.Ident)
if err != nil { return nil, err }
call := &entity.Call {
Position: pos,
Name: this.value(),
}
this.next()
for {
err = this.expectDesc (
"Expression or Call end",
appendCopy(startTokensExpression, lexer.RBracket)...)
if err != nil { return nil, err }
if this.token.Is(lexer.RBracket) { break }
argument, err := this.parseExpression()
if err != nil { return nil, err }
call.Arguments = append(call.Arguments, argument)
}
call.Position = call.Position.Union(this.pos())
this.next()
return call, nil
}
var valuesOperator = []string {
"++", "+", "--", "-", "*", "/", "%", "!!", "||", "&&", "^^",
"!", "|", "&", "^", "<<", ">>", "<", ">", "<=", ">=", "=",