Skip to content

Commit

Permalink
Fixes #135 cjk character issue (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
pointlander authored Nov 27, 2024
1 parent f029247 commit 3c7184a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
6 changes: 3 additions & 3 deletions buildinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package main

const (
// VERSION is the version of peg
VERSION = "unknown"
VERSION = ""
// BUILDTIME is the build time of peg
BUILDTIME = "2024-02-26T12:28:35"
BUILDTIME = "2024-11-27T19:39:27"
// COMMIT is the commit hash of peg
COMMIT = "a4f5c509ba3254cae4204db9c02d36ca2f733d53"
COMMIT = "f02924709a94d2f169ee1dd5f9cee0277aed4edd"
// IS_TAGGED is there a version
IS_TAGGED = false
)
2 changes: 1 addition & 1 deletion peg.peg.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions peg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,23 @@ Begin <- Begin 'x'
}
}

func TestCJKCharacter(t *testing.T) {
buffer := `
package main
type DiceExprParser Peg {
}
Expr <- 'CJK' / '汉字' / 'test'
`
p := &Peg{Tree: tree.New(false, true, false), Buffer: buffer}
p.Init(Size(1 << 15))
err := p.Parse()
if err != nil {
t.Fatal("cjk character test failed")
}
}

var files = [...]string{
"peg.peg",
"grammars/c/c.peg",
Expand Down
3 changes: 2 additions & 1 deletion tree/peg.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"strconv"
"strings"
"text/template"
"unicode"

"github.com/pointlander/peg/set"
)
Expand Down Expand Up @@ -1124,7 +1125,7 @@ func (t *Tree) Compile(file string, args []string, out io.Writer) (err error) {
ordered.PushBack(element.Copy())
} else {
class := &node{Type: TypeUnorderedAlternate}
for d := 0; d < 256; d++ {
for d := 0; d < unicode.MaxRune; d++ {
if properties[c].s.Has(rune(d)) {
class.PushBack(&node{Type: TypeCharacter, string: string(rune(d))})
}
Expand Down

0 comments on commit 3c7184a

Please sign in to comment.