Re-organize the position of parsing functions in expression.go
This commit is contained in:
parent
a0a155c7e6
commit
5fad8a79dd
@ -152,42 +152,6 @@ func (this *Parser) parseExpressionRootLBracketIdent (pos errors.Position) (enti
|
|||||||
panic(this.bug())
|
panic(this.bug())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Parser) parseReturnOrBreakCore (pos errors.Position) (entity.Expression, error) {
|
|
||||||
err := this.expectValue(lexer.Ident, "break", "return")
|
|
||||||
if err != nil { return nil, err }
|
|
||||||
name := this.value()
|
|
||||||
|
|
||||||
err = this.expectNextDesc (
|
|
||||||
"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...: value expression
|
|
||||||
value, err = this.parseExpression()
|
|
||||||
if err != nil { return nil, err }
|
|
||||||
}
|
|
||||||
|
|
||||||
err = this.expectDesc("end of " + name, lexer.RBracket)
|
|
||||||
if err != nil { return nil, err }
|
|
||||||
pos = pos.Union(this.pos())
|
|
||||||
this.next()
|
|
||||||
|
|
||||||
switch name {
|
|
||||||
case "break":
|
|
||||||
return &entity.Break {
|
|
||||||
Position: pos,
|
|
||||||
Value: value,
|
|
||||||
}, nil
|
|
||||||
case "return":
|
|
||||||
return &entity.Return {
|
|
||||||
Position: pos,
|
|
||||||
Value: value,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
panic(this.bug())
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *Parser) parseDereferenceOrSubscriptCore (pos errors.Position) (entity.Expression, error) {
|
func (this *Parser) parseDereferenceOrSubscriptCore (pos errors.Position) (entity.Expression, error) {
|
||||||
err := this.expect(lexer.Dot)
|
err := this.expect(lexer.Dot)
|
||||||
if err != nil { return nil, err }
|
if err != nil { return nil, err }
|
||||||
@ -228,6 +192,64 @@ 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",
|
||||||
|
lexer.Symbol,
|
||||||
|
appendCopy(valuesOperator, "\\", "#", "@", "~", "~~")...)
|
||||||
|
if err != nil { return nil, err }
|
||||||
|
|
||||||
|
switch this.value() {
|
||||||
|
case "\\": // TODO
|
||||||
|
case "#": // TODO
|
||||||
|
case "@": // TODO
|
||||||
|
case "~": // TODO
|
||||||
|
case "~~": // TODO
|
||||||
|
default: // TODO
|
||||||
|
}
|
||||||
|
panic(this.bug())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *Parser) parseReturnOrBreakCore (pos errors.Position) (entity.Expression, error) {
|
||||||
|
err := this.expectValue(lexer.Ident, "break", "return")
|
||||||
|
if err != nil { return nil, err }
|
||||||
|
name := this.value()
|
||||||
|
|
||||||
|
err = this.expectNextDesc (
|
||||||
|
"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...: value expression
|
||||||
|
value, err = this.parseExpression()
|
||||||
|
if err != nil { return nil, err }
|
||||||
|
}
|
||||||
|
|
||||||
|
err = this.expectDesc("end of " + name, lexer.RBracket)
|
||||||
|
if err != nil { return nil, err }
|
||||||
|
pos = pos.Union(this.pos())
|
||||||
|
this.next()
|
||||||
|
|
||||||
|
switch name {
|
||||||
|
case "break":
|
||||||
|
return &entity.Break {
|
||||||
|
Position: pos,
|
||||||
|
Value: value,
|
||||||
|
}, nil
|
||||||
|
case "return":
|
||||||
|
return &entity.Return {
|
||||||
|
Position: pos,
|
||||||
|
Value: value,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
panic(this.bug())
|
||||||
|
}
|
||||||
|
|
||||||
func (this *Parser) parseCallCore (pos errors.Position) (*entity.Call, error) {
|
func (this *Parser) parseCallCore (pos errors.Position) (*entity.Call, error) {
|
||||||
err := this.expect(lexer.Ident)
|
err := this.expect(lexer.Ident)
|
||||||
@ -255,29 +277,6 @@ func (this *Parser) parseCallCore (pos errors.Position) (*entity.Call, error) {
|
|||||||
return call, nil
|
return call, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var valuesOperator = []string {
|
|
||||||
"++", "+", "--", "-", "*", "/", "%", "!!", "||", "&&", "^^",
|
|
||||||
"!", "|", "&", "^", "<<", ">>", "<", ">", "<=", ">=", "=",
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *Parser) parseExpressionRootLBracketSymbol (pos errors.Position) (entity.Expression, error) {
|
|
||||||
err := this.expectValueDesc (
|
|
||||||
"Symbol",
|
|
||||||
lexer.Symbol,
|
|
||||||
appendCopy(valuesOperator, "\\", "#", "@", "~", "~~")...)
|
|
||||||
if err != nil { return nil, err }
|
|
||||||
|
|
||||||
switch this.value() {
|
|
||||||
case "\\": // TODO
|
|
||||||
case "#": // TODO
|
|
||||||
case "@": // TODO
|
|
||||||
case "~": // TODO
|
|
||||||
case "~~": // TODO
|
|
||||||
default: // TODO
|
|
||||||
}
|
|
||||||
panic(this.bug())
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *Parser) parseBlock () (*entity.Block, error) {
|
func (this *Parser) parseBlock () (*entity.Block, error) {
|
||||||
err := this.expectDesc("Block", lexer.LBrace)
|
err := this.expectDesc("Block", lexer.LBrace)
|
||||||
if err != nil { return nil, err }
|
if err != nil { return nil, err }
|
||||||
|
Loading…
Reference in New Issue
Block a user