aboutsummaryrefslogtreecommitdiffstats
path: root/ethutil
diff options
context:
space:
mode:
Diffstat (limited to 'ethutil')
-rw-r--r--ethutil/parsing.go31
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
+}