(s string, skipTransformations []string, allowUnsafeHints bool)
| 35 | } |
| 36 | |
| 37 | func parseInternal(s string, skipTransformations []string, allowUnsafeHints bool) (expr *RootExpr, err error) { |
| 38 | defer func() { |
| 39 | if r := recover(); r != nil { |
| 40 | var ok bool |
| 41 | if err, ok = r.(error); ok { |
| 42 | var parseErr *ParseError |
| 43 | if errors.As(err, &parseErr) { |
| 44 | return |
| 45 | } |
| 46 | err = newParseError(err.Error(), 0, 0) |
| 47 | } |
| 48 | } |
| 49 | }() |
| 50 | l := lexer{ |
| 51 | parser: yyNewParser().(*yyParserImpl), |
| 52 | } |
| 53 | l.Init(strings.NewReader(s)) |
| 54 | l.Scanner.Error = func(_ *scanner.Scanner, msg string) { |
| 55 | l.Error(msg) |
| 56 | } |
| 57 | e := l.parser.Parse(&l) |
| 58 | if len(l.errs) > 0 { |
| 59 | return nil, l.errs[0] |
| 60 | } |
| 61 | if e != 0 { |
| 62 | return nil, fmt.Errorf("unknown parse error: %d", e) |
| 63 | } |
| 64 | |
| 65 | if transformations, ok := l.expr.Hints.GetStringSlice(HintSkipASTTransformations, allowUnsafeHints); ok { |
| 66 | for _, name := range transformations { |
| 67 | name = strings.TrimSpace(name) |
| 68 | if name != "" && !slices.Contains(skipTransformations, name) { |
| 69 | skipTransformations = append(skipTransformations, name) |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | l.expr = ApplyASTRewrites(l.expr, skipTransformations) |
| 75 | if l.expr.OptimizationCount > 0 { |
| 76 | level.Debug(log.Logger).Log("msg", "optimize AST for TraceQL query", "query", s, "optimizedQuery", l.expr.String(), "optimizationCount", l.expr.OptimizationCount) |
| 77 | } |
| 78 | |
| 79 | return l.expr, nil |
| 80 | } |
| 81 | |
| 82 | // warning: ParseIdentifier is used to parse filter policies in pkg/spanfilter/config/config.go |
| 83 | // if changed, it can break existing config. |
no test coverage detected