implement-modules #43
@ -30,7 +30,7 @@ import "git.tebibyte.media/sashakoshka/fspl/entity"
|
||||
// | | '@' =Reference *
|
||||
// | | '~' =ValueCast *
|
||||
// | | '~~' =BitCast *
|
||||
// | | OPERATOR =Operation *
|
||||
// | | OPERATOR =Operation
|
||||
// |
|
||||
// | +LBrace =Block
|
||||
// | +Int =LiteralInt
|
||||
@ -192,17 +192,12 @@ func (this *Parser) parseDereferenceOrSubscriptCore (pos errors.Position) (entit
|
||||
}
|
||||
}
|
||||
|
||||
var valuesOperator = []string {
|
||||
"++", "+", "--", "-", "*", "/", "%", "!!", "||", "&&", "^^",
|
||||
"!", "|", "&", "^", "<<", ">>", "<", ">", "<=", ">=", "=",
|
||||
}
|
||||
|
||||
func (this *Parser) parseExpressionRootLBracketSymbol (pos errors.Position) (entity.Expression, error) {
|
||||
err := this.expectValueDesc (
|
||||
"Symbol",
|
||||
err := this.expectValue (
|
||||
lexer.Symbol,
|
||||
appendCopy(valuesOperator, "\\", "#", "@", "~", "~~")...)
|
||||
if err != nil { return nil, err }
|
||||
println("after")
|
||||
|
||||
switch this.value() {
|
||||
case "\\": // TODO
|
||||
@ -210,11 +205,37 @@ func (this *Parser) parseExpressionRootLBracketSymbol (pos errors.Position) (ent
|
||||
case "@": // TODO
|
||||
case "~": // TODO
|
||||
case "~~": // TODO
|
||||
default: // TODO
|
||||
default: return this.parseOperationCore(pos)
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
func (this *Parser) parseReturnOrBreakCore (pos errors.Position) (entity.Expression, error) {
|
||||
err := this.expectValue(lexer.Ident, "break", "return")
|
||||
if err != nil { return nil, err }
|
||||
@ -251,30 +272,35 @@ 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)
|
||||
var valuesOperator = []string {
|
||||
"++", "+", "--", "-", "*", "/", "%", "!!", "||", "&&", "^^",
|
||||
"!", "|", "&", "^", "<<", ">>", "<", ">", "<=", ">=", "=",
|
||||
}
|
||||
|
||||
func (this *Parser) parseOperationCore (pos errors.Position) (*entity.Operation, error) {
|
||||
err := this.expectValue(lexer.Symbol, valuesOperator...)
|
||||
if err != nil { return nil, err }
|
||||
call := &entity.Call {
|
||||
operation := &entity.Operation {
|
||||
Position: pos,
|
||||
Name: this.value(),
|
||||
Operator: entity.OperatorFromString(this.value()),
|
||||
}
|
||||
this.next()
|
||||
|
||||
for {
|
||||
err = this.expectDesc (
|
||||
"expression or call end",
|
||||
"expression or operation 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)
|
||||
operation.Arguments = append(operation.Arguments, argument)
|
||||
}
|
||||
call.Position = call.Position.Union(this.pos())
|
||||
operation.Position = operation.Position.Union(this.pos())
|
||||
this.next()
|
||||
|
||||
return call, nil
|
||||
return operation, nil
|
||||
}
|
||||
|
||||
func (this *Parser) parseBlock () (*entity.Block, error) {
|
||||
|
Loading…
Reference in New Issue
Block a user