mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-07 09:05:55 +00:00
Merge branch 'master' into allow-backslash-cr-in-pql-strings
This commit is contained in:
commit
0c0709eb20
1 changed files with 19 additions and 9 deletions
|
|
@ -4,7 +4,9 @@ package pql
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"math"
|
||||
"os"
|
||||
"sort"
|
||||
"strconv"
|
||||
)
|
||||
|
|
@ -210,7 +212,7 @@ type node32 struct {
|
|||
up, next *node32
|
||||
}
|
||||
|
||||
func (node *node32) print(pretty bool, buffer string) {
|
||||
func (node *node32) print(w io.Writer, pretty bool, buffer string) {
|
||||
var print func(node *node32, depth int)
|
||||
print = func(node *node32, depth int) {
|
||||
for node != nil {
|
||||
|
|
@ -220,9 +222,9 @@ func (node *node32) print(pretty bool, buffer string) {
|
|||
rule := rul3s[node.pegRule]
|
||||
quote := strconv.Quote(string(([]rune(buffer)[node.begin:node.end])))
|
||||
if !pretty {
|
||||
fmt.Printf("%v %v\n", rule, quote)
|
||||
fmt.Fprintf(w, "%v %v\n", rule, quote)
|
||||
} else {
|
||||
fmt.Printf("\x1B[34m%v\x1B[m %v\n", rule, quote)
|
||||
fmt.Fprintf(w, "\x1B[34m%v\x1B[m %v\n", rule, quote)
|
||||
}
|
||||
if node.up != nil {
|
||||
print(node.up, depth+1)
|
||||
|
|
@ -233,12 +235,12 @@ func (node *node32) print(pretty bool, buffer string) {
|
|||
print(node, 0)
|
||||
}
|
||||
|
||||
func (node *node32) Print(buffer string) {
|
||||
node.print(false, buffer)
|
||||
func (node *node32) Print(w io.Writer, buffer string) {
|
||||
node.print(w, false, buffer)
|
||||
}
|
||||
|
||||
func (node *node32) PrettyPrint(buffer string) {
|
||||
node.print(true, buffer)
|
||||
func (node *node32) PrettyPrint(w io.Writer, buffer string) {
|
||||
node.print(w, true, buffer)
|
||||
}
|
||||
|
||||
type tokens32 struct {
|
||||
|
|
@ -281,11 +283,15 @@ func (t *tokens32) AST() *node32 {
|
|||
}
|
||||
|
||||
func (t *tokens32) PrintSyntaxTree(buffer string) {
|
||||
t.AST().Print(buffer)
|
||||
t.AST().Print(os.Stdout, buffer)
|
||||
}
|
||||
|
||||
func (t *tokens32) WriteSyntaxTree(w io.Writer, buffer string) {
|
||||
t.AST().Print(w, buffer)
|
||||
}
|
||||
|
||||
func (t *tokens32) PrettyPrintSyntaxTree(buffer string) {
|
||||
t.AST().PrettyPrint(buffer)
|
||||
t.AST().PrettyPrint(os.Stdout, buffer)
|
||||
}
|
||||
|
||||
func (t *tokens32) Add(rule pegRule, begin, end, index uint32) {
|
||||
|
|
@ -393,6 +399,10 @@ func (p *PQL) PrintSyntaxTree() {
|
|||
}
|
||||
}
|
||||
|
||||
func (p *PQL) WriteSyntaxTree(w io.Writer) {
|
||||
p.tokens32.WriteSyntaxTree(w, p.Buffer)
|
||||
}
|
||||
|
||||
func (p *PQL) Execute() {
|
||||
buffer, _buffer, text, begin, end := p.Buffer, p.buffer, "", 0, 0
|
||||
for _, token := range p.Tokens() {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue