Skip to content

Commit 2eda7e9

Browse files
edmocostaevan-bradleyTylerHelmuth
authored
[pkg/ottl] Refactor grammar validation to use the AST visitor and combining errors (#35728)
Co-authored-by: Evan Bradley <[email protected]> Co-authored-by: Tyler Helmuth <[email protected]>
1 parent ecf9538 commit 2eda7e9

File tree

4 files changed

+235
-246
lines changed

4 files changed

+235
-246
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: enhancement
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: pkg/ottl
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: "Parsing invalid statements and conditions now prints all errors instead of just the first one found."
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [35728]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: [user]

pkg/ottl/functions.go

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,7 @@ func buildOriginalText(path *path) string {
3333
for i, f := range path.Fields {
3434
builder.WriteString(f.Name)
3535
if len(f.Keys) > 0 {
36-
for _, k := range f.Keys {
37-
builder.WriteString("[")
38-
if k.Int != nil {
39-
builder.WriteString(strconv.FormatInt(*k.Int, 10))
40-
}
41-
if k.String != nil {
42-
builder.WriteString(*k.String)
43-
}
44-
builder.WriteString("]")
45-
}
36+
builder.WriteString(buildOriginalKeysText(f.Keys))
4637
}
4738
if i != len(path.Fields)-1 {
4839
builder.WriteString(".")
@@ -51,6 +42,23 @@ func buildOriginalText(path *path) string {
5142
return builder.String()
5243
}
5344

45+
func buildOriginalKeysText(keys []key) string {
46+
var builder strings.Builder
47+
if len(keys) > 0 {
48+
for _, k := range keys {
49+
builder.WriteString("[")
50+
if k.Int != nil {
51+
builder.WriteString(strconv.FormatInt(*k.Int, 10))
52+
}
53+
if k.String != nil {
54+
builder.WriteString(*k.String)
55+
}
56+
builder.WriteString("]")
57+
}
58+
}
59+
return builder.String()
60+
}
61+
5462
func (p *Parser[K]) newPath(path *path) (*basePath[K], error) {
5563
if len(path.Fields) == 0 {
5664
return nil, fmt.Errorf("cannot make a path from zero fields")

0 commit comments

Comments
 (0)