diff options
author | obscuren <geffobscura@gmail.com> | 2014-04-12 12:13:42 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-04-12 12:13:42 +0800 |
commit | 086acd122b59071255b0c1cfae569748b1d7427a (patch) | |
tree | 6ff564b1720298085ad89de53a2b4e4f0db21ca7 /ethutil | |
parent | 116516158da637cde50d27d600db6661732fc402 (diff) | |
download | dexon-086acd122b59071255b0c1cfae569748b1d7427a.tar.gz dexon-086acd122b59071255b0c1cfae569748b1d7427a.tar.zst dexon-086acd122b59071255b0c1cfae569748b1d7427a.zip |
Added pre processing of script data
Diffstat (limited to 'ethutil')
-rw-r--r-- | ethutil/parsing.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/ethutil/parsing.go b/ethutil/parsing.go index 278414982..328704cae 100644 --- a/ethutil/parsing.go +++ b/ethutil/parsing.go @@ -3,6 +3,7 @@ package ethutil import ( _ "fmt" "math/big" + "regexp" ) // Op codes @@ -132,3 +133,33 @@ func Assemble(instructions ...interface{}) (script []byte) { return } + +/* +Prepocessing function that takes init and main apart: +init() { + // something +} + +main() { + // main something +} +*/ +func PreProcess(data string) (mainInput, initInput string) { + reg := "\\(\\)\\s*{([\\d\\w\\W\\n\\s]+?)}" + mainReg := regexp.MustCompile("main" + reg) + initReg := regexp.MustCompile("init" + reg) + + main := mainReg.FindStringSubmatch(data) + if len(main) > 0 { + mainInput = main[1] + } else { + mainInput = data + } + + init := initReg.FindStringSubmatch(data) + if len(init) > 0 { + initInput = init[1] + } + + return +} |