aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/shell/state.go
diff options
context:
space:
mode:
authorJP Appel <jeanpierre.appel01@gmail.com>2025-06-28 01:15:44 -0400
committerJP Appel <jeanpierre.appel01@gmail.com>2025-06-28 01:15:44 -0400
commitb6d1375c7bdf0f06eb32f1273ad5fd4f7c0e5673 (patch)
tree07b6bcfa994ed5273dea6d7d2d9491bf1fe91c94 /pkg/shell/state.go
parent468b14ea9e60698a3340aa1f1f53794834dafe9f (diff)
Add leveld optimization wrapper
Diffstat (limited to 'pkg/shell/state.go')
-rw-r--r--pkg/shell/state.go91
1 files changed, 17 insertions, 74 deletions
diff --git a/pkg/shell/state.go b/pkg/shell/state.go
index bd7ecc8..5acdaf1 100644
--- a/pkg/shell/state.go
+++ b/pkg/shell/state.go
@@ -1,9 +1,7 @@
package shell
import (
- "errors"
"fmt"
- "os"
"strings"
"github.com/jpappel/atlas/pkg/query"
@@ -17,6 +15,7 @@ const (
VAL_STRING
VAL_TOKENS
VAL_CLAUSE
+ VAL_ARTIFACT
)
type Value struct {
@@ -38,6 +37,8 @@ func (t ValueType) String() string {
return "Tokens"
case VAL_CLAUSE:
return "Clause"
+ case VAL_ARTIFACT:
+ return "Compilation Artifact"
default:
return "Unkown"
}
@@ -48,27 +49,33 @@ func (v Value) String() string {
case VAL_INT:
i, ok := v.Val.(int)
if !ok {
- return "Corrupted Type (expected int)"
+ panic("Corrupted Type (expected int)")
}
return fmt.Sprint(i)
case VAL_STRING:
s, ok := v.Val.(string)
if !ok {
- return "Corrupted Type (expected string)"
+ panic("Corrupted Type (expected string)")
}
return s
case VAL_TOKENS:
ts, ok := v.Val.([]query.Token)
if !ok {
- return "Corrupted Type (expected []query.Token)"
+ panic("Corrupted Type (expected []query.Token)")
}
return query.TokensStringify(ts)
case VAL_CLAUSE:
- rootClause, ok := v.Val.(*query.Clause)
+ clause, ok := v.Val.(*query.Clause)
if !ok {
- return "Corrupted Type (expected *query.Clause)"
+ panic("Corrupted Type (expected *query.Clause)")
}
- return rootClause.String()
+ return clause.String()
+ case VAL_ARTIFACT:
+ artifact, ok := v.Val.(query.CompilationArtifact)
+ if !ok {
+ panic("Corrupted Type (expected query.CompilationArtifact)")
+ }
+ return artifact.String()
case VAL_INVALID:
return "Invalid"
}
@@ -92,6 +99,8 @@ func (s State) String() string {
b.WriteString(" Tokens")
case VAL_CLAUSE:
b.WriteString(" Clause")
+ case VAL_ARTIFACT:
+ b.WriteString(" Artifact")
default:
fmt.Fprintf(&b, " Unknown (%d)", v.Val)
}
@@ -100,69 +109,3 @@ func (s State) String() string {
return b.String()
}
-
-func (s State) CmdTokenize(input string) (Value, bool) {
- if len(input) == 0 {
- return Value{}, false
- }
-
- var rawQuery string
- if input[0] == '`' {
- rawQuery = input[1:]
- } else {
- variable, ok := s[input]
- if !ok {
- fmt.Fprintln(os.Stderr, "Cannot tokenize: no variable with name", input)
- return Value{}, false
- } else if variable.Type != VAL_STRING {
- fmt.Fprintln(os.Stderr, "Cannot tokenize: variable is not a string")
- return Value{}, false
- }
-
- rawQuery, ok = variable.Val.(string)
- if !ok {
- fmt.Fprintln(os.Stderr, "Cannot tokenize: type corruption")
- fmt.Fprintln(os.Stderr, "Type corruption, expected string")
- panic("Type corruption")
- }
- }
- tokens := query.Lex(rawQuery)
- return Value{VAL_TOKENS, tokens}, true
-}
-
-func (s State) CmdParse(args string) (Value, error) {
- if len(args) == 0 {
- return Value{}, errors.New("no arguments for parse")
- }
-
- var tokens []query.Token
- if tokenizeArgs, found := strings.CutPrefix(args, "tokenize "); found {
- val, ok := s.CmdTokenize(tokenizeArgs)
- if !ok {
- return Value{}, errors.New("error occured during tokenization")
- }
- tokens = val.Val.([]query.Token)
- } else {
- variable, ok := s[args]
- if !ok {
- fmt.Fprintln(os.Stderr, "Cannot parse: no variable with name", args)
- return Value{}, errors.New("variable does not exist")
- } else if variable.Type != VAL_TOKENS {
- fmt.Fprintln(os.Stderr, "Cannot parse: variable is not []query.Tokens")
- return Value{}, errors.New("bad variable type")
- }
-
- tokens, ok = variable.Val.([]query.Token)
- if !ok {
- fmt.Fprintln(os.Stderr, "Cannot parse: type corruption")
- fmt.Fprintln(os.Stderr, "Type corruption, expected []query.Tokens")
- panic("Type corruption")
- }
- }
-
- clause, err := query.Parse(tokens)
- if err != nil {
- return Value{}, err
- }
- return Value{VAL_CLAUSE, *clause}, err
-}