Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Aug 6, 2023
1 parent dfd4f48 commit c97f567
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 200 deletions.
7 changes: 5 additions & 2 deletions action.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
shlex "github.com/rsteube/carapace-shlex"
"github.com/rsteube/carapace/internal/cache"
"github.com/rsteube/carapace/internal/common"
"github.com/rsteube/carapace/internal/lexer"
pkgcache "github.com/rsteube/carapace/pkg/cache"
"github.com/rsteube/carapace/pkg/style"
pkgtraverse "github.com/rsteube/carapace/pkg/traverse"
Expand Down Expand Up @@ -277,11 +276,15 @@ func (a Action) SplitP() Action {

func (a Action) split(pipelines bool) Action {
return ActionCallback(func(c Context) Action {
tokens, err := lexer.Split(c.Value, pipelines)
tokens, err := shlex.Split(c.Value)
if err != nil {
return ActionMessage(err.Error())
}

if pipelines {
tokens = tokens.CurrentPipeline()
}

context := NewContext(tokens.Strings()...)
current := tokens.CurrentToken()
prefix := c.Value[:current.Index]
Expand Down
16 changes: 0 additions & 16 deletions internal/lexer/lexer.go

This file was deleted.

169 changes: 0 additions & 169 deletions internal/lexer/lexer_test.go

This file was deleted.

32 changes: 19 additions & 13 deletions internal/shell/nushell/patch.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
package nushell

import (
"strings"

"github.com/rsteube/carapace-shlex"
)

// Patch uses the lexer to parse and patch given arguments which
// are currently passed unprocessed to the completion function.
//
// see https://www.nushell.sh/book/working_with_strings.html
func Patch(args []string) []string {
// TODO
// for index, arg := range args {
// if len(arg) == 0 {
// continue
// }
for index, arg := range args {
if len(arg) == 0 {
continue
}

// switch arg[0] {
// case '"', "'"[0]:
// if tokenset, err := lexer.Split(arg, false); err == nil {
// args[index] = tokenset.Tokens[0]
// }
// case '`':
// args[index] = strings.Trim(arg, "`")
// }
// }
switch arg[0] {
case '"', "'"[0]:
if tokens, err := shlex.Split(arg); err == nil {
args[index] = (*tokens)[0].Value
}
case '`':
args[index] = strings.Trim(arg, "`")
}
}
return args
}

0 comments on commit c97f567

Please sign in to comment.