Skip to content

Commit

Permalink
extract: escape ~ in package names
Browse files Browse the repository at this point in the history
consider packages from git.sr.ht, the user namespace is prefixed with `~`

so running something like `yaegi extract git.sr.ht/~emersion/scfg`

was producing syntax errors with `~` in identifiers. and also `~` in filenames which worked but probably best not to have it there either

thanks!
  • Loading branch information
sentriz committed Mar 27, 2023
1 parent 20c8f5e commit 8de3add
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cmd/yaegi/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func extractCmd(arg []string) error {
ext.Include = strings.Split(include, ",")
}

r := strings.NewReplacer("/", "-", ".", "_")
r := strings.NewReplacer("/", "-", ".", "_", "~", "_")

for _, pkgIdent := range args {
var buf bytes.Buffer
Expand Down
2 changes: 1 addition & 1 deletion extract/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func matchList(name string, list []string) (match bool, err error) {

func (e *Extractor) genContent(importPath string, p *types.Package) ([]byte, error) {
prefix := "_" + importPath + "_"
prefix = strings.NewReplacer("/", "_", "-", "_", ".", "_").Replace(prefix)
prefix = strings.NewReplacer("/", "_", "-", "_", ".", "_", "~", "_").Replace(prefix)

typ := map[string]string{}
val := map[string]Val{}
Expand Down

0 comments on commit 8de3add

Please sign in to comment.