github.com/TrueBlocks/trueblocks-core/src/apps/chifra@v0.0.0-20241022031540-b362680128f7/pkg/parser/lexer_parser.go (about) 1 package parser 2 3 import ( 4 "github.com/alecthomas/participle/v2" 5 "github.com/alecthomas/participle/v2/lexer" 6 ) 7 8 // Input syntax: 9 // 10 // - Input data: chifra state --call '0xcdba2fd40000000000000000000000000000000000000000000000000000000000007a69' 11 // - Four-byte plus params: chifra state --call '0xdeadbeef("hello", 110)' 12 // - Function name plus params: chifra state --call 'readMessage("hello", 110)' 13 14 // This defines the tokens our lexer will match on. For the SolidityIdent, see 15 // https://docs.soliditylang.org/en/v0.8.17/grammar.html#a4.SolidityLexer.Identifier 16 var ourLexer = lexer.MustSimple([]lexer.SimpleRule{ 17 // matched lexer tokens (order matters) 18 {Name: `EnsDomain`, Pattern: `([a-zA-Z0-9]+)(\.[a-zA-Z0-9]+)*\.eth`}, // TODO: this token does not handle dashes 19 {Name: `Hex`, Pattern: `0x[[:xdigit:]]+`}, 20 {Name: `String`, Pattern: `"(?:\\.|[^"])*"`}, 21 {Name: `Decimal`, Pattern: `[-+]?\d+`}, 22 {Name: `SolidityIdent`, Pattern: `[a-zA-Z$_][a-zA-Z0-9$_]*`}, 23 {Name: `whitespace`, Pattern: `\s+`}, 24 {Name: `Punctation`, Pattern: `[(),]`}, 25 }) 26 27 // This builds our parser from the lexer and some options 28 var ourParser = participle.MustBuild[ContractCall]( 29 participle.Lexer(ourLexer), 30 participle.UseLookahead(2), 31 participle.Unquote("String"), 32 )