@@ -11,15 +11,11 @@ import (
1111)
1212
1313const (
14- TokenOpenParens = 1
15- TokenCloseParens = 2
16- TokenOpenBracket = 3
17- TokenCloseBracket = 4
18- TokenComma = 5
19- TokenEvent = 6
20- TokenFunction = 7
21- TokenIndexed = 8
22- TokenScalarTypeName = 9
14+ TokenOpenParens = 1
15+ TokenCloseParens = 2
16+ TokenOpenBracket = 3
17+ TokenCloseBracket = 4
18+ TokenComma = 5
2319)
2420
2521var (
@@ -49,18 +45,21 @@ var (
4945 DefineTokens (TokenOpenBracket , []string {"[" }).
5046 DefineTokens (TokenCloseBracket , []string {"]" }).
5147 DefineTokens (TokenComma , []string {"," }).
52- DefineTokens (TokenEvent , []string {"event" }).
53- DefineTokens (TokenFunction , []string {"function" }).
54- DefineTokens (TokenIndexed , []string {"indexed" }).
55- DefineTokens (TokenScalarTypeName , SCALAR_TYPENAMES ).
5648 AllowKeywordSymbols ([]rune {'_' }, []rune {'$' , '_' , '0' , '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' })
5749)
5850
51+ func isEventToken (t * tokenizer.Token ) bool { return t .IsKeyword () && t .ValueString () == "event" }
52+ func isFunctionToken (t * tokenizer.Token ) bool { return t .IsKeyword () && t .ValueString () == "function" }
53+ func isIndexedToken (t * tokenizer.Token ) bool { return t .IsKeyword () && t .ValueString () == "indexed" }
54+ func isScalarTypeName (t * tokenizer.Token ) bool {
55+ return lo .Contains (SCALAR_TYPENAMES , t .ValueString ())
56+ }
57+
5958func ParseEvent (s string ) (eth_abi.Event , error ) {
6059 var stream = tknz .ParseString (s )
6160 defer stream .Close ()
6261
63- if ! stream .CurrentToken (). Is ( TokenEvent ) {
62+ if ! isEventToken ( stream .CurrentToken ()) {
6463 return eth_abi.Event {}, fmt .Errorf ("event fullsig must start with keyword 'event': %s" , s )
6564 }
6665
@@ -87,7 +86,7 @@ func ParseMethod(s string) (eth_abi.Method, error) {
8786 var stream = tknz .ParseString (s )
8887 defer stream .Close ()
8988
90- if ! stream .CurrentToken (). Is ( TokenFunction ) {
89+ if ! isFunctionToken ( stream .CurrentToken ()) {
9190 return eth_abi.Method {}, fmt .Errorf ("function fullsig must start with keyword 'function': %s" , s )
9291 }
9392
@@ -160,7 +159,7 @@ func parseArgument(stream *tokenizer.Stream) (eth_abi.ArgumentMarshaling, error)
160159 )
161160
162161 switch {
163- case stream .CurrentToken (). Is ( TokenScalarTypeName ):
162+ case isScalarTypeName ( stream .CurrentToken ()):
164163 res .Type = stream .CurrentToken ().ValueString ()
165164 stream .GoNext ()
166165 case stream .CurrentToken ().Is (TokenOpenParens ):
@@ -184,7 +183,7 @@ func parseArgument(stream *tokenizer.Stream) (eth_abi.ArgumentMarshaling, error)
184183 res .Type = res .Type + s
185184 }
186185
187- if stream .CurrentToken (). Is ( TokenIndexed ) {
186+ if isIndexedToken ( stream .CurrentToken ()) {
188187 res .Indexed = true
189188 stream .GoNext ()
190189 }
0 commit comments