Updated parser
This commit is contained in:
parent
2be41be609
commit
4df7a8905e
|
@ -58,9 +58,9 @@ func (this *treeParser) parseExpression () (entity.Expression, error) {
|
|||
case lexer.Ident:
|
||||
// Ident: member access
|
||||
expression = &entity.MemberAccess {
|
||||
Position: pos.Union(this.Pos()),
|
||||
Source: source,
|
||||
Member: this.Value(),
|
||||
Pos: pos.Union(this.Pos()),
|
||||
Source: source,
|
||||
Member: this.Value(),
|
||||
}
|
||||
this.Next()
|
||||
|
||||
|
@ -75,7 +75,7 @@ func (this *treeParser) parseExpression () (entity.Expression, error) {
|
|||
// this control path must return, breaking out of the
|
||||
// loop.
|
||||
expression := &entity.Assignment {
|
||||
Position: pos,
|
||||
Pos: pos,
|
||||
Location: expression,
|
||||
}
|
||||
|
||||
|
@ -133,8 +133,8 @@ func (this *treeParser) parseExpressionRootIdent () (entity.Expression, error) {
|
|||
default:
|
||||
// *: variable
|
||||
return &entity.Variable {
|
||||
Position: pos,
|
||||
Name: name,
|
||||
Pos: pos,
|
||||
Name: name,
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
|
@ -200,8 +200,8 @@ func (this *treeParser) parseDereferenceOrSubscriptCore (pos errors.Position) (e
|
|||
this.Next()
|
||||
|
||||
return &entity.Dereference {
|
||||
Position: pos,
|
||||
Pointer: argument,
|
||||
Pos: pos,
|
||||
Pointer: argument,
|
||||
}, nil
|
||||
} else {
|
||||
// startTokensExpression...: subscript
|
||||
|
@ -214,9 +214,9 @@ func (this *treeParser) parseDereferenceOrSubscriptCore (pos errors.Position) (e
|
|||
this.Next()
|
||||
|
||||
return &entity.Subscript {
|
||||
Position: pos,
|
||||
Slice: argument,
|
||||
Offset: offset,
|
||||
Pos: pos,
|
||||
Slice: argument,
|
||||
Offset: offset,
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
|
@ -241,7 +241,7 @@ func (this *treeParser) parseCallCore (pos errors.Position, unitNickname string)
|
|||
err := this.Expect(lexer.Ident)
|
||||
if err != nil { return nil, err }
|
||||
call := &entity.Call {
|
||||
Position: pos,
|
||||
Pos: pos,
|
||||
UnitNickname: unitNickname,
|
||||
Name: this.Value(),
|
||||
}
|
||||
|
@ -258,7 +258,7 @@ func (this *treeParser) parseCallCore (pos errors.Position, unitNickname string)
|
|||
if err != nil { return nil, err }
|
||||
call.Arguments = append(call.Arguments, argument)
|
||||
}
|
||||
call.Position = call.Position.Union(this.Pos())
|
||||
call.Pos = call.Position().Union(this.Pos())
|
||||
this.Next()
|
||||
|
||||
return call, nil
|
||||
|
@ -270,9 +270,9 @@ func (this *treeParser) parseMethodCallCore (pos errors.Position, source entity.
|
|||
err = this.ExpectNext(lexer.Ident)
|
||||
if err != nil { return nil, err }
|
||||
call := &entity.MethodCall {
|
||||
Source: source,
|
||||
Position: pos,
|
||||
Name: this.Value(),
|
||||
Source: source,
|
||||
Pos: pos,
|
||||
Name: this.Value(),
|
||||
}
|
||||
this.Next()
|
||||
|
||||
|
@ -287,7 +287,7 @@ func (this *treeParser) parseMethodCallCore (pos errors.Position, source entity.
|
|||
if err != nil { return nil, err }
|
||||
call.Arguments = append(call.Arguments, argument)
|
||||
}
|
||||
call.Position = call.Position.Union(this.Pos())
|
||||
call.Pos = call.Position().Union(this.Pos())
|
||||
this.Next()
|
||||
|
||||
return call, nil
|
||||
|
@ -317,13 +317,13 @@ func (this *treeParser) parseReturnOrBreakCore (pos errors.Position) (entity.Exp
|
|||
switch name {
|
||||
case "break":
|
||||
return &entity.Break {
|
||||
Position: pos,
|
||||
Value: value,
|
||||
Pos: pos,
|
||||
Value: value,
|
||||
}, nil
|
||||
case "return":
|
||||
return &entity.Return {
|
||||
Position: pos,
|
||||
Value: value,
|
||||
Pos: pos,
|
||||
Value: value,
|
||||
}, nil
|
||||
}
|
||||
panic(this.bug())
|
||||
|
@ -333,7 +333,7 @@ func (this *treeParser) parseSliceCore (pos errors.Position) (*entity.Slice, err
|
|||
err := this.ExpectValue(lexer.Symbol , "\\")
|
||||
if err != nil { return nil, err }
|
||||
slice := &entity.Slice {
|
||||
Position: pos,
|
||||
Pos: pos,
|
||||
}
|
||||
|
||||
err = this.ExpectNextDesc(descriptionExpression, startTokensExpression...)
|
||||
|
@ -364,7 +364,7 @@ func (this *treeParser) parseSliceCore (pos errors.Position) (*entity.Slice, err
|
|||
|
||||
err = this.Expect(lexer.RBracket)
|
||||
if err != nil { return nil, err }
|
||||
slice.Position = slice.Position.Union(this.Pos())
|
||||
slice.Pos = slice.Position().Union(this.Pos())
|
||||
this.Next()
|
||||
|
||||
return slice, nil
|
||||
|
@ -374,7 +374,7 @@ func (this *treeParser) parseLengthCore (pos errors.Position) (*entity.Length, e
|
|||
err := this.ExpectValue(lexer.Symbol , "#")
|
||||
if err != nil { return nil, err }
|
||||
length := &entity.Length {
|
||||
Position: pos,
|
||||
Pos: pos,
|
||||
}
|
||||
|
||||
this.Next()
|
||||
|
@ -383,7 +383,7 @@ func (this *treeParser) parseLengthCore (pos errors.Position) (*entity.Length, e
|
|||
|
||||
err = this.Expect(lexer.RBracket)
|
||||
if err != nil { return nil, err }
|
||||
length.Position = length.Position.Union(this.Pos())
|
||||
length.Pos = length.Position().Union(this.Pos())
|
||||
this.Next()
|
||||
|
||||
return length, nil
|
||||
|
@ -393,7 +393,7 @@ func (this *treeParser) parseReferenceCore (pos errors.Position) (*entity.Refere
|
|||
err := this.ExpectValue(lexer.Symbol , "@")
|
||||
if err != nil { return nil, err }
|
||||
reference := &entity.Reference {
|
||||
Position: pos,
|
||||
Pos: pos,
|
||||
}
|
||||
|
||||
this.Next()
|
||||
|
@ -402,7 +402,7 @@ func (this *treeParser) parseReferenceCore (pos errors.Position) (*entity.Refere
|
|||
|
||||
err = this.Expect(lexer.RBracket)
|
||||
if err != nil { return nil, err }
|
||||
reference.Position = reference.Position.Union(this.Pos())
|
||||
reference.Pos = reference.Position().Union(this.Pos())
|
||||
this.Next()
|
||||
|
||||
return reference, nil
|
||||
|
@ -429,15 +429,15 @@ func (this *treeParser) parseValueOrBitCastCore (pos errors.Position) (entity.Ex
|
|||
switch tokValue {
|
||||
case "~":
|
||||
return &entity.ValueCast {
|
||||
Position: pos,
|
||||
Ty: ty,
|
||||
Value: value,
|
||||
Pos: pos,
|
||||
Ty: ty,
|
||||
Value: value,
|
||||
}, nil
|
||||
case "~~":
|
||||
return &entity.BitCast {
|
||||
Position: pos,
|
||||
Ty: ty,
|
||||
Value: value,
|
||||
Pos: pos,
|
||||
Ty: ty,
|
||||
Value: value,
|
||||
}, nil
|
||||
}
|
||||
panic(this.bug())
|
||||
|
@ -462,7 +462,7 @@ func (this *treeParser) parseOperationCore (pos errors.Position) (*entity.Operat
|
|||
}
|
||||
|
||||
operation := &entity.Operation {
|
||||
Position: pos,
|
||||
Pos: pos,
|
||||
Operator: entity.OperatorFromString(this.Value()),
|
||||
}
|
||||
this.Next()
|
||||
|
@ -478,7 +478,7 @@ func (this *treeParser) parseOperationCore (pos errors.Position) (*entity.Operat
|
|||
if err != nil { return nil, err }
|
||||
operation.Arguments = append(operation.Arguments, argument)
|
||||
}
|
||||
operation.Position = operation.Position.Union(this.Pos())
|
||||
operation.Pos = operation.Position().Union(this.Pos())
|
||||
this.Next()
|
||||
|
||||
return operation, nil
|
||||
|
@ -488,7 +488,7 @@ func (this *treeParser) parseBlock () (*entity.Block, error) {
|
|||
err := this.ExpectDesc("Block", lexer.LBrace)
|
||||
if err != nil { return nil, err }
|
||||
block := &entity.Block {
|
||||
Position: this.Pos(),
|
||||
Pos: this.Pos(),
|
||||
}
|
||||
this.Next()
|
||||
|
||||
|
@ -503,7 +503,7 @@ func (this *treeParser) parseBlock () (*entity.Block, error) {
|
|||
if err != nil { return nil, err }
|
||||
block.Steps = append(block.Steps, step)
|
||||
}
|
||||
block.Position = block.Position.Union(this.Pos())
|
||||
block.Pos = block.Position().Union(this.Pos())
|
||||
this.Next()
|
||||
|
||||
return block, nil
|
||||
|
@ -529,9 +529,9 @@ func (this *treeParser) parseDeclarationCore (pos errors.Position, name string)
|
|||
if err != nil { return nil, err }
|
||||
|
||||
return &entity.Declaration {
|
||||
Position: pos,
|
||||
Name: name,
|
||||
Ty: ty,
|
||||
Pos: pos,
|
||||
Name: name,
|
||||
Ty: ty,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
@ -539,7 +539,7 @@ func (this *treeParser) parseIfElse () (*entity.IfElse, error) {
|
|||
err := this.ExpectValue(lexer.Ident, "if")
|
||||
if err != nil { return nil, err }
|
||||
ifElse := &entity.IfElse {
|
||||
Position: this.Pos(),
|
||||
Pos: this.Pos(),
|
||||
}
|
||||
|
||||
err = this.ExpectNextDesc("condition", startTokensExpression...)
|
||||
|
@ -568,7 +568,7 @@ func (this *treeParser) parseMatch () (*entity.Match, error) {
|
|||
err := this.ExpectValue(lexer.Ident, "match")
|
||||
if err != nil { return nil, err }
|
||||
match := &entity.Match {
|
||||
Position: this.Pos(),
|
||||
Pos: this.Pos(),
|
||||
}
|
||||
|
||||
err = this.ExpectNextDesc(descriptionExpression, startTokensExpression...)
|
||||
|
@ -589,7 +589,7 @@ func (this *treeParser) parseCase () (*entity.Case, error) {
|
|||
err := this.ExpectValue(lexer.Symbol, "|")
|
||||
if err != nil { return nil, err }
|
||||
cas := &entity.Case {
|
||||
Position: this.Pos(),
|
||||
Pos: this.Pos(),
|
||||
}
|
||||
|
||||
this.Next()
|
||||
|
@ -611,7 +611,7 @@ func (this *treeParser) parseLoop () (*entity.Loop, error) {
|
|||
if err != nil { return nil, err }
|
||||
|
||||
return &entity.Loop {
|
||||
Position: pos,
|
||||
Body: body,
|
||||
Pos: pos,
|
||||
Body: body,
|
||||
}, nil
|
||||
}
|
||||
|
|
|
@ -13,8 +13,8 @@ func (this *treeParser) parseLiteralInt () (*entity.LiteralInt, error) {
|
|||
if err != nil { return nil, errors.Errorf(this.Pos(), err.Error()) }
|
||||
|
||||
return &entity.LiteralInt {
|
||||
Position: this.Pos(),
|
||||
Value: int(value), // TODO struct should store as int64
|
||||
Pos: this.Pos(),
|
||||
Value: int(value), // TODO struct should store as int64
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
@ -27,8 +27,8 @@ func (this *treeParser) parseLiteralFloat () (*entity.LiteralFloat, error) {
|
|||
if err != nil { return nil, errors.Errorf(this.Pos(), err.Error()) }
|
||||
|
||||
return &entity.LiteralFloat {
|
||||
Position: this.Pos(),
|
||||
Value: value,
|
||||
Pos: this.Pos(),
|
||||
Value: value,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,7 @@ func (this *treeParser) parseLiteralString () (*entity.LiteralString, error) {
|
|||
defer this.Next()
|
||||
|
||||
return &entity.LiteralString {
|
||||
Position: this.Pos(),
|
||||
Pos: this.Pos(),
|
||||
ValueUTF8: this.Value(),
|
||||
}, nil
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ func (this *treeParser) parseLiteralBoolean () (*entity.LiteralBoolean, error) {
|
|||
defer this.Next()
|
||||
|
||||
return &entity.LiteralBoolean {
|
||||
Position: this.Pos(),
|
||||
Pos: this.Pos(),
|
||||
Value: this.Value() == "true",
|
||||
}, nil
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ func (this *treeParser) parseLiteralNil () (*entity.LiteralNil, error) {
|
|||
defer this.Next()
|
||||
|
||||
return &entity.LiteralNil {
|
||||
Position: this.Pos(),
|
||||
Pos: this.Pos(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
@ -68,7 +68,7 @@ func (this *treeParser) parseLiteralArrayCore (pos errors.Position) (*entity.Lit
|
|||
err := this.Expect(lexer.Star)
|
||||
if err != nil { return nil, err }
|
||||
literal := &entity.LiteralArray {
|
||||
Position: pos,
|
||||
Pos: pos,
|
||||
}
|
||||
this.Next()
|
||||
|
||||
|
@ -83,7 +83,7 @@ func (this *treeParser) parseLiteralArrayCore (pos errors.Position) (*entity.Lit
|
|||
if err != nil { return nil, err }
|
||||
literal.Elements = append(literal.Elements, element)
|
||||
}
|
||||
literal.Position = literal.Position.Union(this.Pos())
|
||||
literal.Pos = literal.Position().Union(this.Pos())
|
||||
this.Next()
|
||||
|
||||
return literal, nil
|
||||
|
@ -93,7 +93,7 @@ func (this *treeParser) parseLiteralStructCore (pos errors.Position) (*entity.Li
|
|||
err := this.Expect(lexer.Dot)
|
||||
if err != nil { return nil, err }
|
||||
literal := &entity.LiteralStruct {
|
||||
Position: pos,
|
||||
Pos: pos,
|
||||
}
|
||||
this.Next()
|
||||
|
||||
|
@ -108,7 +108,7 @@ func (this *treeParser) parseLiteralStructCore (pos errors.Position) (*entity.Li
|
|||
if err != nil { return nil, err }
|
||||
literal.Members = append(literal.Members, member)
|
||||
}
|
||||
literal.Position = literal.Position.Union(this.Pos())
|
||||
literal.Pos = literal.Position().Union(this.Pos())
|
||||
this.Next()
|
||||
|
||||
return literal, nil
|
||||
|
|
|
@ -57,9 +57,9 @@ func (this *treeParser) parseMember () (*entity.Member, error) {
|
|||
if err != nil { return nil, err }
|
||||
|
||||
return &entity.Member {
|
||||
Position: pos,
|
||||
Name: name,
|
||||
Value: value,
|
||||
Pos: pos,
|
||||
Name: name,
|
||||
Value: value,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -86,7 +86,7 @@ func (this *treeParser) parseFunctionCore (pos errors.Position, access entity.Ac
|
|||
if err != nil { return nil, err }
|
||||
|
||||
function := &entity.Function {
|
||||
Position: pos.Union(signature.Position()),
|
||||
Pos: pos.Union(signature.Position()),
|
||||
Acc: access,
|
||||
Signature: signature,
|
||||
}
|
||||
|
@ -130,7 +130,7 @@ func (this *treeParser) parseMethodCore (pos errors.Position, access entity.Acce
|
|||
function, err := this.parseFunctionCore(pos, access)
|
||||
if err != nil { return nil, err }
|
||||
return &entity.Method {
|
||||
Position: function.Position,
|
||||
Pos: function.Position(),
|
||||
Acc: function.Acc,
|
||||
TypeName: typeName,
|
||||
Signature: function.Signature,
|
||||
|
@ -144,9 +144,9 @@ func (this *treeParser) parseTypedefCore (pos errors.Position, access entity.Acc
|
|||
ty, err := this.parseType()
|
||||
if err != nil { return nil, err }
|
||||
return &entity.Typedef {
|
||||
Position: pos,
|
||||
Acc: access,
|
||||
Name: typeName,
|
||||
Type: ty,
|
||||
Pos: pos,
|
||||
Acc: access,
|
||||
Name: typeName,
|
||||
Type: ty,
|
||||
}, nil
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ func (this *treeParser) parseInto (tree *Tree) error {
|
|||
func (this *treeParser) parse () error {
|
||||
err := this.Next()
|
||||
if err != nil { return err }
|
||||
this.tree.Position = this.Pos()
|
||||
this.tree.Pos = this.Pos()
|
||||
|
||||
// String: UUID
|
||||
err = this.Expect(lexer.String)
|
||||
|
@ -109,8 +109,8 @@ func (this *treeParser) parseDependency () (*entity.Dependency, error) {
|
|||
err = this.ExpectNextDesc("address", lexer.String)
|
||||
if err != nil { return nil, err }
|
||||
dependency := &entity.Dependency {
|
||||
Position: this.Pos(),
|
||||
Address: entity.Address(this.Value()),
|
||||
Pos: this.Pos(),
|
||||
Address: entity.Address(this.Value()),
|
||||
}
|
||||
|
||||
this.Next()
|
||||
|
|
Loading…
Reference in New Issue