-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(deepql): add initial setup for deepql
- Loading branch information
Showing
11 changed files
with
1,764 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package ql | ||
|
||
import "errors" | ||
|
||
type RootExpr struct { | ||
trigger *trigger | ||
command *command | ||
} | ||
|
||
func (e RootExpr) validate() error { | ||
var errs []error | ||
if e.trigger != nil && e.command != nil { | ||
return errors.New("fatal error: cannot define a trigger and a command") | ||
} | ||
if e.trigger != nil { | ||
err := e.trigger.validate() | ||
if err != nil { | ||
errs = append(errs, err) | ||
} | ||
} | ||
if e.command != nil { | ||
err := e.command.validate() | ||
if err != nil { | ||
errs = append(errs, err) | ||
} | ||
} | ||
|
||
if len(errs) > 0 { | ||
return errors.Join(errs...) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Copyright (C) 2024 Intergral GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package ql | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
) | ||
|
||
const ( | ||
list = "list" | ||
deleteType = "delete" | ||
) | ||
|
||
var ( | ||
commandTypes = map[string]int{ | ||
list: COMMAND, | ||
deleteType: COMMAND, | ||
} | ||
) | ||
|
||
type command struct { | ||
command string | ||
|
||
file string | ||
id string | ||
|
||
errors []error | ||
} | ||
|
||
func (c *command) validate() error { | ||
if len(c.errors) > 0 { | ||
return errors.Join(c.errors...) | ||
} | ||
return nil | ||
} | ||
|
||
func newCommand(typ string, opts []configOption) command { | ||
var cmd command | ||
switch typ { | ||
case list: | ||
cmd = command{command: list} | ||
case deleteType: | ||
cmd = command{command: deleteType} | ||
} | ||
|
||
for _, cfg := range opts { | ||
err := cfg.apply(&cmd) | ||
if err != nil { | ||
cmd.errors = append(cmd.errors, err) | ||
} | ||
} | ||
|
||
return cmd | ||
} | ||
|
||
func applyFuncForCommand(lhs string) func(c *configOption, cmd *command) error { | ||
switch lhs { | ||
case "file": | ||
return func(c *configOption, cmd *command) error { | ||
cmd.file = c.rhs.S | ||
return nil | ||
} | ||
case "id": | ||
return func(c *configOption, cmd *command) error { | ||
cmd.id = c.rhs.S | ||
return nil | ||
} | ||
} | ||
return func(c *configOption, cmd *command) error { | ||
return errors.New(fmt.Sprintf("parse error unrecognized option: %s", lhs)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright (C) 2024 Intergral GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package ql | ||
|
||
import "strings" | ||
|
||
type configOption struct { | ||
op Operator | ||
lhs string | ||
rhs Static | ||
fnc func(c *configOption, target interface{}) error | ||
} | ||
|
||
func (c *configOption) apply(cfg interface{}) error { | ||
return c.fnc(c, cfg) | ||
} | ||
|
||
func newConfigOption(op Operator, lhs string, rhs Static) configOption { | ||
return configOption{ | ||
op: op, | ||
lhs: lhs, | ||
rhs: rhs, | ||
fnc: applyFuncFor(lhs), | ||
} | ||
} | ||
|
||
func applyFuncFor(lhs string) func(c *configOption, tri interface{}) error { | ||
return func(c *configOption, tri interface{}) error { | ||
if v, ok := tri.(*trigger); ok { | ||
return applyFuncForTrigger(lhs)(c, v) | ||
} | ||
|
||
if v, ok := tri.(*command); ok { | ||
return applyFuncForCommand(lhs)(c, v) | ||
} | ||
|
||
return nil | ||
} | ||
} | ||
|
||
func stripPrefix(lhs string, s string) string { | ||
after, _ := strings.CutPrefix(lhs, s) | ||
return after | ||
} |
Oops, something went wrong.