aboutsummaryrefslogtreecommitdiffstats
path: root/ethutil
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-04-23 17:51:04 +0800
committerobscuren <geffobscura@gmail.com>2014-04-23 17:51:04 +0800
commit3a9a252f6e44abb0f45f57a46c0fa91e2f73c545 (patch)
tree677575939c8f22c30a9601c205450a0d5b98c3ab /ethutil
parent61cd1594b52514244efcb47bd93722aaec0fe456 (diff)
downloadgo-tangerine-3a9a252f6e44abb0f45f57a46c0fa91e2f73c545.tar.gz
go-tangerine-3a9a252f6e44abb0f45f57a46c0fa91e2f73c545.tar.zst
go-tangerine-3a9a252f6e44abb0f45f57a46c0fa91e2f73c545.zip
Fixed minor issue with gas and added state object init
Diffstat (limited to 'ethutil')
-rw-r--r--ethutil/parsing.go49
-rw-r--r--ethutil/parsing_test.go41
2 files changed, 67 insertions, 23 deletions
diff --git a/ethutil/parsing.go b/ethutil/parsing.go
index 328704cae..9775cf328 100644
--- a/ethutil/parsing.go
+++ b/ethutil/parsing.go
@@ -3,7 +3,7 @@ package ethutil
import (
_ "fmt"
"math/big"
- "regexp"
+ _ "regexp"
)
// Op codes
@@ -143,7 +143,6 @@ init() {
main() {
// main something
}
-*/
func PreProcess(data string) (mainInput, initInput string) {
reg := "\\(\\)\\s*{([\\d\\w\\W\\n\\s]+?)}"
mainReg := regexp.MustCompile("main" + reg)
@@ -163,3 +162,49 @@ func PreProcess(data string) (mainInput, initInput string) {
return
}
+*/
+
+// Very, very dumb parser. Heed no attention :-)
+func FindFor(blockMatcher, input string) string {
+ curCount := -1
+ length := len(blockMatcher)
+ matchfst := rune(blockMatcher[0])
+ var currStr string
+
+ for i, run := range input {
+ // Find init
+ if curCount == -1 && run == matchfst && input[i:i+length] == blockMatcher {
+ curCount = 0
+ } else if curCount > -1 {
+ if run == '{' {
+ curCount++
+ if curCount == 1 {
+ continue
+ }
+ } else if run == '}' {
+ curCount--
+ if curCount == 0 {
+ // we are done
+ curCount = -1
+ break
+ }
+ }
+
+ if curCount > 0 {
+ currStr += string(run)
+ }
+ }
+ }
+
+ return currStr
+}
+
+func PreProcess(data string) (mainInput, initInput string) {
+ mainInput = FindFor("main", data)
+ if mainInput == "" {
+ mainInput = data
+ }
+ initInput = FindFor("init", data)
+
+ return
+}
diff --git a/ethutil/parsing_test.go b/ethutil/parsing_test.go
index 6b59777e6..a9ad347dd 100644
--- a/ethutil/parsing_test.go
+++ b/ethutil/parsing_test.go
@@ -1,32 +1,31 @@
package ethutil
-/*
import (
- "math"
+ "fmt"
"testing"
)
-func TestCompile(t *testing.T) {
- instr, err := CompileInstr("PUSH")
-
- if err != nil {
- t.Error("Failed compiling instruction")
+func TestPreProcess(t *testing.T) {
+ main, init := PreProcess(`
+ init {
+ // init
+ if a > b {
+ if {
+ }
+ }
}
- calc := (48 + 0*256 + 0*int64(math.Pow(256, 2)))
- if BigD(instr).Int64() != calc {
- t.Error("Expected", calc, ", got:", instr)
+ main {
+ // main
+ if a > b {
+ if c > d {
+ }
+ }
}
-}
-
-func TestValidInstr(t *testing.T) {
- op, args, err := Instr("68163")
- if err != nil {
- t.Error("Error decoding instruction")
- }
-
-}
+ `)
-func TestInvalidInstr(t *testing.T) {
+ fmt.Println("main")
+ fmt.Println(main)
+ fmt.Println("init")
+ fmt.Println(init)
}
-*/