Skip to content

Commit c6b2dcc

Browse files
authored
Add fix for missing IDs (#41)
* Add fix for missing IDs * Refactor * Update go mod --------- Co-authored-by: Tony Meehan <[email protected]>
1 parent df2593e commit c6b2dcc

File tree

3 files changed

+16
-23
lines changed

3 files changed

+16
-23
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ require (
3030
require (
3131
github.com/cqroot/prompt v0.9.4
3232
github.com/fatih/color v1.18.0
33-
github.com/prequel-dev/prequel-compiler v0.0.11
33+
github.com/prequel-dev/prequel-compiler v0.0.14
3434
github.com/spf13/cobra v1.8.1
3535
github.com/spf13/viper v1.20.1
3636
gopkg.in/yaml.v2 v2.4.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRI
214214
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
215215
github.com/posener/complete v1.2.3 h1:NP0eAhjcjImqslEwo/1hq7gpajME0fTLTezBKDqfXqo=
216216
github.com/posener/complete v1.2.3/go.mod h1:WZIdtGGp+qx0sLrYKtIRAruyNpv6hFCicSgv7Sy7s/s=
217-
github.com/prequel-dev/prequel-compiler v0.0.11 h1:SC9XYv41TiPqQvIXbgKPBmlH5XSSQVqlKgkqwjBF9Vw=
218-
github.com/prequel-dev/prequel-compiler v0.0.11/go.mod h1:PBk0LDu2xSMVC+Qq0/1C5XXls3KyO5rIYGI4wcoLScE=
217+
github.com/prequel-dev/prequel-compiler v0.0.14 h1:ZeynQysKhfQspY4KPPEiYVvbsCHCfWUEXk5pvEnAZ9Y=
218+
github.com/prequel-dev/prequel-compiler v0.0.14/go.mod h1:PBk0LDu2xSMVC+Qq0/1C5XXls3KyO5rIYGI4wcoLScE=
219219
github.com/prequel-dev/prequel-logmatch v0.0.13 h1:cPKs1FbhfDyPevGkEOVEud+HZT7r385a+ZumWvBlmQw=
220220
github.com/prequel-dev/prequel-logmatch v0.0.13/go.mod h1:Dpfd/79s8vMCmIdmNQ5kC8WAvw/XjOd2z6wEIe3Lkck=
221221
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=

internal/pkg/engine/engine.go

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"github.com/prequel-dev/prequel-compiler/pkg/compiler"
2121
"github.com/prequel-dev/prequel-compiler/pkg/datasrc"
2222
"github.com/prequel-dev/prequel-compiler/pkg/parser"
23-
"github.com/prequel-dev/prequel-compiler/pkg/pqerr"
2423
"github.com/prequel-dev/prequel-compiler/pkg/schema"
2524
"github.com/prequel-dev/prequel-logmatch/pkg/entry"
2625
lm "github.com/prequel-dev/prequel-logmatch/pkg/match"
@@ -93,8 +92,6 @@ func compileRuleTree(cf compiler.RuntimeI, tree *parser.TreeT) (compiler.ObjsT,
9392
func compileRulePath(cf compiler.RuntimeI, rp utils.RulePathT) (compiler.ObjsT, *parser.RulesT, error) {
9493
var (
9594
rs *parser.RulesT
96-
tree *parser.TreeT
97-
nodeObjs compiler.ObjsT
9895
rdrOpts = make([]utils.ReaderOptT, 0)
9996
parseOpts = make([]parser.ParseOptT, 0)
10097
err error
@@ -116,28 +113,12 @@ func compileRulePath(cf compiler.RuntimeI, rp utils.RulePathT) (compiler.ObjsT,
116113
return nil, nil, err
117114
}
118115

119-
if tree, err = parser.ParseRules(rs, parseOpts); err != nil {
120-
return nil, nil, err
121-
}
122-
123-
log.Info().Int("cres", len(rs.Rules)).Msg("Parsed rules")
124-
for _, rule := range rs.Rules {
125-
log.Info().Str("id", rule.Metadata.Id).Str("cre", rule.Cre.Id).Msg("Rule")
126-
}
127-
128-
nodeObjs, err = compileRuleTree(cf, tree)
129-
if err != nil {
130-
return nil, nil, pqerr.WithFile(err, rp.Path)
131-
}
132-
133-
return nodeObjs, rs, nil
116+
return doCompileRule(cf, rs, parseOpts)
134117
}
135118

136119
func compileRule(cf compiler.RuntimeI, data []byte) (compiler.ObjsT, *parser.RulesT, error) {
137120
var (
138121
rules *parser.RulesT
139-
tree *parser.TreeT
140-
nodeObjs compiler.ObjsT
141122
rdrOpts = make([]utils.ReaderOptT, 0)
142123
parseOpts = make([]parser.ParseOptT, 0)
143124
err error
@@ -152,6 +133,17 @@ func compileRule(cf compiler.RuntimeI, data []byte) (compiler.ObjsT, *parser.Rul
152133
return nil, nil, err
153134
}
154135

136+
return doCompileRule(cf, rules, parseOpts)
137+
}
138+
139+
func doCompileRule(cf compiler.RuntimeI, rules *parser.RulesT, parseOpts []parser.ParseOptT) (compiler.ObjsT, *parser.RulesT, error) {
140+
141+
var (
142+
tree *parser.TreeT
143+
nodeObjs compiler.ObjsT
144+
err error
145+
)
146+
155147
if tree, err = parser.ParseRules(rules, parseOpts); err != nil {
156148
log.Error().Err(err).Msg("Failed to parse rules")
157149
return nil, nil, err
@@ -162,6 +154,7 @@ func compileRule(cf compiler.RuntimeI, data []byte) (compiler.ObjsT, *parser.Rul
162154
log.Info().Str("id", rule.Metadata.Id).Str("cre", rule.Cre.Id).Msg("Rule")
163155
}
164156

157+
// Add missing IDs
165158
for i := range rules.Rules {
166159
var r = &rules.Rules[i]
167160
if r.Metadata.Id == "" {

0 commit comments

Comments
 (0)