Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions pkg/lang/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,26 @@ func CreatePersistentTreeSetWithComparator(comparator IFn, keys ISeq) interface{
}

func NewSet(vals ...interface{}) *Set {
set, err := NewSet2(vals...)
if err != nil {
panic(err)
}
return set
}

func NewSet2(vals ...interface{}) (*Set, error) {
// check for duplicates
for i := 0; i < len(vals); i++ {
for j := i + 1; j < len(vals); j++ {
if Equiv(vals[i], vals[j]) {
panic(NewIllegalArgumentError(fmt.Sprintf("duplicate key: %v", vals[i])))
return nil, NewIllegalArgumentError(fmt.Sprintf("duplicate key: %v", vals[i]))
}
}
}

return &Set{
vals: vals,
}
}, nil
}

var (
Expand Down
12 changes: 10 additions & 2 deletions pkg/lang/symbol.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package lang

import (
"fmt"
"regexp"
"strings"
)

Expand All @@ -11,6 +12,10 @@ type Symbol struct {
name string
}

var (
symbolRegex = regexp.MustCompile(`^(?:[^0-9/].*/)?(?:/|[^0-9/][^/]*)$`)
)

// NewSymbol creates a new symbol.
func NewSymbol(s string) *Symbol {
ns, name := "", s
Expand Down Expand Up @@ -83,6 +88,9 @@ func isValidSymbol(ns, name string) bool {
} else {
full = ns + "/" + name
}
if !symbolRegex.MatchString(full) {
return false
}

// early special case for the division operator /
if full == "/" {
Expand All @@ -97,11 +105,11 @@ func isValidSymbol(ns, name string) bool {
// empty namespace
return false
}
if strings.HasSuffix(name, ":") {
if strings.HasSuffix(name, ":") || strings.HasSuffix(ns, ":") {
// name ends with a colon (match clojure)
return false
}
if strings.Contains(name, "::") {
if strings.Contains(full, "::") {
// name contains double colon
//
// NB: clojure reader rejects this, but clojure.core/symbol
Expand Down
6 changes: 6 additions & 0 deletions pkg/reader/clj_conformance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ func FuzzCLJConformance(f *testing.F) {
if err != nil {
f.Fatal(err)
}

// skip any files that contain the string ";; skip-clj"
if strings.Contains(string(data), ";; skip-clj") {
continue
}

f.Add(string(data))
}

Expand Down
Loading