Skip to content

Commit 900ff68

Browse files
committed
Allow importing hyphenated packages with underscores, bump to v1.2.2
Packages with hyphens in their name (e.g. ccl-testpkg) are now also registered under the underscore variant (ccl_testpkg), since hyphens are not valid in identifiers.
1 parent 93e8414 commit 900ff68

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

ccolon/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
"github.com/TRC-Loop/ccolon/vm"
1818
)
1919

20-
const version = "1.2.1"
20+
const version = "1.2.2"
2121

2222
func main() {
2323
if len(os.Args) < 2 {

ccolon/pkg/loader.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"os"
77
"path/filepath"
8+
"strings"
89

910
"github.com/TRC-Loop/ccolon/compiler"
1011
"github.com/TRC-Loop/ccolon/vm"
@@ -115,6 +116,12 @@ func LoadPackages(machine *vm.VM, compileSource func(string) (*compiler.FuncObje
115116
}
116117

117118
machine.RegisterModule(m.Name, mod)
119+
// Also register under underscore alias so packages with
120+
// hyphens can be imported using underscores (e.g. ccl_testpkg
121+
// for ccl-testpkg), since "-" is not valid in identifiers.
122+
if strings.Contains(m.Name, "-") {
123+
machine.RegisterModule(strings.ReplaceAll(m.Name, "-", "_"), mod)
124+
}
118125
}
119126
}
120127
}

0 commit comments

Comments
 (0)