aboutsummaryrefslogtreecommitdiffstats
path: root/core/vm/sqlvm/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'core/vm/sqlvm/cmd')
-rw-r--r--core/vm/sqlvm/cmd/ast-printer/main.go5
-rw-r--r--core/vm/sqlvm/cmd/pigeon-gofmt/main.go12
2 files changed, 14 insertions, 3 deletions
diff --git a/core/vm/sqlvm/cmd/ast-printer/main.go b/core/vm/sqlvm/cmd/ast-printer/main.go
index 86a742909..33710f2b0 100644
--- a/core/vm/sqlvm/cmd/ast-printer/main.go
+++ b/core/vm/sqlvm/cmd/ast-printer/main.go
@@ -15,11 +15,12 @@ func main() {
flag.Parse()
- n, err := parser.Parse([]byte(flag.Arg(0)))
+ s := []byte(flag.Arg(0))
+ n, err := parser.Parse(s)
fmt.Printf("detail: %t\n", detail)
if err != nil {
fmt.Fprintf(os.Stderr, "err:\n%+v\n", err)
os.Exit(1)
}
- ast.PrintAST(os.Stdout, n, " ", detail)
+ ast.PrintAST(os.Stdout, n, s, " ", detail)
}
diff --git a/core/vm/sqlvm/cmd/pigeon-gofmt/main.go b/core/vm/sqlvm/cmd/pigeon-gofmt/main.go
index 08623d5f8..141bf132c 100644
--- a/core/vm/sqlvm/cmd/pigeon-gofmt/main.go
+++ b/core/vm/sqlvm/cmd/pigeon-gofmt/main.go
@@ -124,6 +124,7 @@ func (b *buffer) skipSection(opening, closing, escape rune,
func pegFormat(src []byte) ([]byte, error) {
b := newBuffer(src)
+ indent := 0
for {
r, err := b.nextRune()
@@ -139,6 +140,10 @@ func pegFormat(src []byte) ([]byte, error) {
}
switch r {
+ case '\n':
+ indent = 0
+ case '\t':
+ indent++
case '/':
r, err = b.nextRune()
if err != nil {
@@ -211,7 +216,12 @@ func pegFormat(src []byte) ([]byte, error) {
return nil, err
}
} else {
- _, err = b.out.Write(formatted[1:])
+ formatted = formatted[1:]
+ pattern := []byte{'\n'}
+ replacement := append([]byte{'\n'},
+ bytes.Repeat([]byte{'\t'}, indent)...)
+ formatted = bytes.Replace(formatted, pattern, replacement, -1)
+ _, err = b.out.Write(formatted)
if err != nil {
return nil, err
}