extractSourceText extracts original text from a parse rule match. Preserves original whitespace if possible.
(ctx antlr.ParserRuleContext)
| 163 | // extractSourceText extracts original text from a parse rule match. |
| 164 | // Preserves original whitespace if possible. |
| 165 | func extractSourceText(ctx antlr.ParserRuleContext) string { |
| 166 | if ctx.GetStart() == nil || ctx.GetStop() == nil || |
| 167 | ctx.GetStart().GetStart() < 0 || ctx.GetStop().GetStop() < 0 { |
| 168 | // fallback to the normalized parse |
| 169 | return ctx.GetText() |
| 170 | } |
| 171 | s, e := ctx.GetStart().GetStart(), ctx.GetStop().GetStop() |
| 172 | return ctx.GetStart().GetInputStream().GetText(s, e) |
| 173 | } |
| 174 | |
| 175 | // Parse parses a repl command line into a command object. This provides |
| 176 | // the normalized command name plus any parsed parameters (e.g. variable names |