This commit is contained in:
Shawn Smith 2016-08-15 13:02:39 +09:00
parent ce6abff517
commit 75853f5901
7 changed files with 158 additions and 158 deletions

View File

@ -38,7 +38,7 @@ func (self Contains) Index(s string) (int, []int) {
}
segments := acquireSegments(len(s) + 1)
for i, _ := range s {
for i := range s {
segments = append(segments, offset+i)
}

View File

@ -17,15 +17,15 @@ func TestAppendMerge(t *testing.T) {
}{
{
[2][]int{
[]int{0, 6, 7},
[]int{0, 1, 3},
{0, 6, 7},
{0, 1, 3},
},
[]int{0, 1, 3, 6, 7},
},
{
[2][]int{
[]int{0, 1, 3, 6, 7},
[]int{0, 1, 10},
{0, 1, 3, 6, 7},
{0, 1, 10},
},
[]int{0, 1, 3, 6, 7, 10},
},

View File

@ -15,7 +15,7 @@ func NewMax(l int) Max {
func (self Max) Match(s string) bool {
var l int
for _ = range s {
for range s {
l += 1
if l > self.Limit {
return false

View File

@ -15,7 +15,7 @@ func NewMin(l int) Min {
func (self Min) Match(s string) bool {
var l int
for _ = range s {
for range s {
l += 1
if l >= self.Limit {
return true

View File

@ -43,7 +43,7 @@ func (self Row) matchAll(s string) bool {
func (self Row) lenOk(s string) bool {
var i int
for _ = range s {
for range s {
i++
if i >= self.RunesLength {
return true

View File

@ -28,8 +28,8 @@ func TestParseString(t *testing.T) {
{
//pattern: "abc",
tokens: []lexer.Token{
lexer.Token{lexer.Text, "abc"},
lexer.Token{lexer.EOF, ""},
{lexer.Text, "abc"},
{lexer.EOF, ""},
},
tree: NewNode(KindPattern, nil,
NewNode(KindText, Text{Text: "abc"}),
@ -38,10 +38,10 @@ func TestParseString(t *testing.T) {
{
//pattern: "a*c",
tokens: []lexer.Token{
lexer.Token{lexer.Text, "a"},
lexer.Token{lexer.Any, "*"},
lexer.Token{lexer.Text, "c"},
lexer.Token{lexer.EOF, ""},
{lexer.Text, "a"},
{lexer.Any, "*"},
{lexer.Text, "c"},
{lexer.EOF, ""},
},
tree: NewNode(KindPattern, nil,
NewNode(KindText, Text{Text: "a"}),
@ -52,10 +52,10 @@ func TestParseString(t *testing.T) {
{
//pattern: "a**c",
tokens: []lexer.Token{
lexer.Token{lexer.Text, "a"},
lexer.Token{lexer.Super, "**"},
lexer.Token{lexer.Text, "c"},
lexer.Token{lexer.EOF, ""},
{lexer.Text, "a"},
{lexer.Super, "**"},
{lexer.Text, "c"},
{lexer.EOF, ""},
},
tree: NewNode(KindPattern, nil,
NewNode(KindText, Text{Text: "a"}),
@ -66,10 +66,10 @@ func TestParseString(t *testing.T) {
{
//pattern: "a?c",
tokens: []lexer.Token{
lexer.Token{lexer.Text, "a"},
lexer.Token{lexer.Single, "?"},
lexer.Token{lexer.Text, "c"},
lexer.Token{lexer.EOF, ""},
{lexer.Text, "a"},
{lexer.Single, "?"},
{lexer.Text, "c"},
{lexer.EOF, ""},
},
tree: NewNode(KindPattern, nil,
NewNode(KindText, Text{Text: "a"}),
@ -80,13 +80,13 @@ func TestParseString(t *testing.T) {
{
//pattern: "[!a-z]",
tokens: []lexer.Token{
lexer.Token{lexer.RangeOpen, "["},
lexer.Token{lexer.Not, "!"},
lexer.Token{lexer.RangeLo, "a"},
lexer.Token{lexer.RangeBetween, "-"},
lexer.Token{lexer.RangeHi, "z"},
lexer.Token{lexer.RangeClose, "]"},
lexer.Token{lexer.EOF, ""},
{lexer.RangeOpen, "["},
{lexer.Not, "!"},
{lexer.RangeLo, "a"},
{lexer.RangeBetween, "-"},
{lexer.RangeHi, "z"},
{lexer.RangeClose, "]"},
{lexer.EOF, ""},
},
tree: NewNode(KindPattern, nil,
NewNode(KindRange, Range{Lo: 'a', Hi: 'z', Not: true}),
@ -95,10 +95,10 @@ func TestParseString(t *testing.T) {
{
//pattern: "[az]",
tokens: []lexer.Token{
lexer.Token{lexer.RangeOpen, "["},
lexer.Token{lexer.Text, "az"},
lexer.Token{lexer.RangeClose, "]"},
lexer.Token{lexer.EOF, ""},
{lexer.RangeOpen, "["},
{lexer.Text, "az"},
{lexer.RangeClose, "]"},
{lexer.EOF, ""},
},
tree: NewNode(KindPattern, nil,
NewNode(KindList, List{Chars: "az"}),
@ -107,12 +107,12 @@ func TestParseString(t *testing.T) {
{
//pattern: "{a,z}",
tokens: []lexer.Token{
lexer.Token{lexer.TermsOpen, "{"},
lexer.Token{lexer.Text, "a"},
lexer.Token{lexer.Separator, ","},
lexer.Token{lexer.Text, "z"},
lexer.Token{lexer.TermsClose, "}"},
lexer.Token{lexer.EOF, ""},
{lexer.TermsOpen, "{"},
{lexer.Text, "a"},
{lexer.Separator, ","},
{lexer.Text, "z"},
{lexer.TermsClose, "}"},
{lexer.EOF, ""},
},
tree: NewNode(KindPattern, nil,
NewNode(KindAnyOf, nil,
@ -128,14 +128,14 @@ func TestParseString(t *testing.T) {
{
//pattern: "/{z,ab}*",
tokens: []lexer.Token{
lexer.Token{lexer.Text, "/"},
lexer.Token{lexer.TermsOpen, "{"},
lexer.Token{lexer.Text, "z"},
lexer.Token{lexer.Separator, ","},
lexer.Token{lexer.Text, "ab"},
lexer.Token{lexer.TermsClose, "}"},
lexer.Token{lexer.Any, "*"},
lexer.Token{lexer.EOF, ""},
{lexer.Text, "/"},
{lexer.TermsOpen, "{"},
{lexer.Text, "z"},
{lexer.Separator, ","},
{lexer.Text, "ab"},
{lexer.TermsClose, "}"},
{lexer.Any, "*"},
{lexer.EOF, ""},
},
tree: NewNode(KindPattern, nil,
NewNode(KindText, Text{Text: "/"}),
@ -153,29 +153,29 @@ func TestParseString(t *testing.T) {
{
//pattern: "{a,{x,y},?,[a-z],[!qwe]}",
tokens: []lexer.Token{
lexer.Token{lexer.TermsOpen, "{"},
lexer.Token{lexer.Text, "a"},
lexer.Token{lexer.Separator, ","},
lexer.Token{lexer.TermsOpen, "{"},
lexer.Token{lexer.Text, "x"},
lexer.Token{lexer.Separator, ","},
lexer.Token{lexer.Text, "y"},
lexer.Token{lexer.TermsClose, "}"},
lexer.Token{lexer.Separator, ","},
lexer.Token{lexer.Single, "?"},
lexer.Token{lexer.Separator, ","},
lexer.Token{lexer.RangeOpen, "["},
lexer.Token{lexer.RangeLo, "a"},
lexer.Token{lexer.RangeBetween, "-"},
lexer.Token{lexer.RangeHi, "z"},
lexer.Token{lexer.RangeClose, "]"},
lexer.Token{lexer.Separator, ","},
lexer.Token{lexer.RangeOpen, "["},
lexer.Token{lexer.Not, "!"},
lexer.Token{lexer.Text, "qwe"},
lexer.Token{lexer.RangeClose, "]"},
lexer.Token{lexer.TermsClose, "}"},
lexer.Token{lexer.EOF, ""},
{lexer.TermsOpen, "{"},
{lexer.Text, "a"},
{lexer.Separator, ","},
{lexer.TermsOpen, "{"},
{lexer.Text, "x"},
{lexer.Separator, ","},
{lexer.Text, "y"},
{lexer.TermsClose, "}"},
{lexer.Separator, ","},
{lexer.Single, "?"},
{lexer.Separator, ","},
{lexer.RangeOpen, "["},
{lexer.RangeLo, "a"},
{lexer.RangeBetween, "-"},
{lexer.RangeHi, "z"},
{lexer.RangeClose, "]"},
{lexer.Separator, ","},
{lexer.RangeOpen, "["},
{lexer.Not, "!"},
{lexer.Text, "qwe"},
{lexer.RangeClose, "]"},
{lexer.TermsClose, "}"},
{lexer.EOF, ""},
},
tree: NewNode(KindPattern, nil,
NewNode(KindAnyOf, nil,

View File

@ -12,169 +12,169 @@ func TestLexGood(t *testing.T) {
{
pattern: "",
items: []Token{
Token{EOF, ""},
{EOF, ""},
},
},
{
pattern: "hello",
items: []Token{
Token{Text, "hello"},
Token{EOF, ""},
{Text, "hello"},
{EOF, ""},
},
},
{
pattern: "/{rate,[0-9]]}*",
items: []Token{
Token{Text, "/"},
Token{TermsOpen, "{"},
Token{Text, "rate"},
Token{Separator, ","},
Token{RangeOpen, "["},
Token{RangeLo, "0"},
Token{RangeBetween, "-"},
Token{RangeHi, "9"},
Token{RangeClose, "]"},
Token{Text, "]"},
Token{TermsClose, "}"},
Token{Any, "*"},
Token{EOF, ""},
{Text, "/"},
{TermsOpen, "{"},
{Text, "rate"},
{Separator, ","},
{RangeOpen, "["},
{RangeLo, "0"},
{RangeBetween, "-"},
{RangeHi, "9"},
{RangeClose, "]"},
{Text, "]"},
{TermsClose, "}"},
{Any, "*"},
{EOF, ""},
},
},
{
pattern: "hello,world",
items: []Token{
Token{Text, "hello,world"},
Token{EOF, ""},
{Text, "hello,world"},
{EOF, ""},
},
},
{
pattern: "hello\\,world",
items: []Token{
Token{Text, "hello,world"},
Token{EOF, ""},
{Text, "hello,world"},
{EOF, ""},
},
},
{
pattern: "hello\\{world",
items: []Token{
Token{Text, "hello{world"},
Token{EOF, ""},
{Text, "hello{world"},
{EOF, ""},
},
},
{
pattern: "hello?",
items: []Token{
Token{Text, "hello"},
Token{Single, "?"},
Token{EOF, ""},
{Text, "hello"},
{Single, "?"},
{EOF, ""},
},
},
{
pattern: "hellof*",
items: []Token{
Token{Text, "hellof"},
Token{Any, "*"},
Token{EOF, ""},
{Text, "hellof"},
{Any, "*"},
{EOF, ""},
},
},
{
pattern: "hello**",
items: []Token{
Token{Text, "hello"},
Token{Super, "**"},
Token{EOF, ""},
{Text, "hello"},
{Super, "**"},
{EOF, ""},
},
},
{
pattern: "[日-語]",
items: []Token{
Token{RangeOpen, "["},
Token{RangeLo, "日"},
Token{RangeBetween, "-"},
Token{RangeHi, "語"},
Token{RangeClose, "]"},
Token{EOF, ""},
{RangeOpen, "["},
{RangeLo, "日"},
{RangeBetween, "-"},
{RangeHi, "語"},
{RangeClose, "]"},
{EOF, ""},
},
},
{
pattern: "[!日-語]",
items: []Token{
Token{RangeOpen, "["},
Token{Not, "!"},
Token{RangeLo, "日"},
Token{RangeBetween, "-"},
Token{RangeHi, "語"},
Token{RangeClose, "]"},
Token{EOF, ""},
{RangeOpen, "["},
{Not, "!"},
{RangeLo, "日"},
{RangeBetween, "-"},
{RangeHi, "語"},
{RangeClose, "]"},
{EOF, ""},
},
},
{
pattern: "[日本語]",
items: []Token{
Token{RangeOpen, "["},
Token{Text, "日本語"},
Token{RangeClose, "]"},
Token{EOF, ""},
{RangeOpen, "["},
{Text, "日本語"},
{RangeClose, "]"},
{EOF, ""},
},
},
{
pattern: "[!日本語]",
items: []Token{
Token{RangeOpen, "["},
Token{Not, "!"},
Token{Text, "日本語"},
Token{RangeClose, "]"},
Token{EOF, ""},
{RangeOpen, "["},
{Not, "!"},
{Text, "日本語"},
{RangeClose, "]"},
{EOF, ""},
},
},
{
pattern: "{a,b}",
items: []Token{
Token{TermsOpen, "{"},
Token{Text, "a"},
Token{Separator, ","},
Token{Text, "b"},
Token{TermsClose, "}"},
Token{EOF, ""},
{TermsOpen, "{"},
{Text, "a"},
{Separator, ","},
{Text, "b"},
{TermsClose, "}"},
{EOF, ""},
},
},
{
pattern: "/{z,ab}*",
items: []Token{
Token{Text, "/"},
Token{TermsOpen, "{"},
Token{Text, "z"},
Token{Separator, ","},
Token{Text, "ab"},
Token{TermsClose, "}"},
Token{Any, "*"},
Token{EOF, ""},
{Text, "/"},
{TermsOpen, "{"},
{Text, "z"},
{Separator, ","},
{Text, "ab"},
{TermsClose, "}"},
{Any, "*"},
{EOF, ""},
},
},
{
pattern: "{[!日-語],*,?,{a,b,\\c}}",
items: []Token{
Token{TermsOpen, "{"},
Token{RangeOpen, "["},
Token{Not, "!"},
Token{RangeLo, "日"},
Token{RangeBetween, "-"},
Token{RangeHi, "語"},
Token{RangeClose, "]"},
Token{Separator, ","},
Token{Any, "*"},
Token{Separator, ","},
Token{Single, "?"},
Token{Separator, ","},
Token{TermsOpen, "{"},
Token{Text, "a"},
Token{Separator, ","},
Token{Text, "b"},
Token{Separator, ","},
Token{Text, "c"},
Token{TermsClose, "}"},
Token{TermsClose, "}"},
Token{EOF, ""},
{TermsOpen, "{"},
{RangeOpen, "["},
{Not, "!"},
{RangeLo, "日"},
{RangeBetween, "-"},
{RangeHi, "語"},
{RangeClose, "]"},
{Separator, ","},
{Any, "*"},
{Separator, ","},
{Single, "?"},
{Separator, ","},
{TermsOpen, "{"},
{Text, "a"},
{Separator, ","},
{Text, "b"},
{Separator, ","},
{Text, "c"},
{TermsClose, "}"},
{TermsClose, "}"},
{EOF, ""},
},
},
} {