SourceString returns the string that was parsed in this expression.
(source []byte)
| 121 | |
| 122 | // SourceString returns the string that was parsed in this expression. |
| 123 | func (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. |
| 159 | func (expr *Expression) String(source []byte) string { |