-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtypeName.go
46 lines (37 loc) · 1004 Bytes
/
typeName.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package solparser
import (
"github.com/uji/solparser/ast"
"github.com/uji/solparser/token"
)
func (p *Parser) ParseTypeName() (ast.TypeName, error) {
tkn, err := p.lexer.Peek()
if err != nil {
return nil, err
}
switch tkn.Type {
case token.Address, token.String, token.Bytes, token.Fixed, token.Bool:
return p.ParseElementaryTypeName()
}
return nil, token.NewPosError(tkn.Position, "not found type-name.")
}
func (p *Parser) ParseElementaryTypeName() (ast.TypeName, error) {
tkn, err := p.lexer.Scan()
if err != nil {
return nil, err
}
if tkn.Type == token.Address {
tkn2, err := p.lexer.Peek()
if err != nil {
return nil, err
}
if tkn2.Type == token.Payable {
p.lexer.Scan()
return ast.ElementaryTypeName{&tkn, &tkn2}, nil
}
}
switch tkn.Type {
case token.Address, token.String, token.Bytes, token.Fixed, token.Bool:
return ast.ElementaryTypeName{&tkn}, nil
}
return nil, token.NewPosError(tkn.Position, "not found elementary type name keyword.")
}