MCPcopy Create free account
hub / github.com/akyoto/q / SourceString

Method SourceString

src/expression/Expression.go:123–156  ·  view source on GitHub ↗

SourceString returns the string that was parsed in this expression.

(source []byte)

Source from the content-addressed store, hash-verified

121
122// SourceString returns the string that was parsed in this expression.
123func (expr *Expression) SourceString(source []byte) string {
124 region := expr.Source()
125 open := 0
126 left := token.Position(0)
127 right := token.Position(0)
128
129 for i := region.Start(); i < region.End(); i++ {
130 switch source[i] {
131 case '(':
132 open++
133 case ')':
134 if open > 0 {
135 open--
136 } else {
137 left++
138
139 for source[region.Start()-left] != '(' {
140 left++
141 }
142 }
143 }
144 }
145
146 for open > 0 {
147 for source[region.End()+right] != ')' {
148 right++
149 }
150
151 right++
152 open--
153 }
154
155 return string(source[region.Start()-left : region.End()+right])
156}
157
158// String generates a textual representation of the expression.
159func (expr *Expression) String(source []byte) string {

Callers 5

compileStoreFieldMethod · 0.80
fieldFromStructMethod · 0.80
TestSourceFunction · 0.80
TestSource2Function · 0.80
TestSource3Function · 0.80

Calls 3

SourceMethod · 0.95
StartMethod · 0.65
EndMethod · 0.65

Tested by 3

TestSourceFunction · 0.64
TestSource2Function · 0.64
TestSource3Function · 0.64