repo fixes

This commit is contained in:
re 2022-12-12 17:24:35 +03:00
parent e7a84e9525
commit bb6a74629b
16 changed files with 68 additions and 58 deletions

View File

@ -3,12 +3,13 @@ package main
import ( import (
"flag" "flag"
"fmt" "fmt"
"github.com/gobwas/glob"
"github.com/gobwas/glob/match"
"github.com/gobwas/glob/match/debug"
"os" "os"
"strings" "strings"
"unicode/utf8" "unicode/utf8"
"git.internal/re/glob"
"git.internal/re/glob/match"
"git.internal/re/glob/match/debug"
) )
func main() { func main() {

View File

@ -3,11 +3,12 @@ package main
import ( import (
"flag" "flag"
"fmt" "fmt"
"github.com/gobwas/glob"
"os" "os"
"strings" "strings"
"testing" "testing"
"unicode/utf8" "unicode/utf8"
"git.internal/re/glob"
) )
func benchString(r testing.BenchmarkResult) string { func benchString(r testing.BenchmarkResult) string {

View File

@ -7,9 +7,9 @@ import (
"fmt" "fmt"
"reflect" "reflect"
"github.com/gobwas/glob/match" "git.internal/re/glob/match"
"github.com/gobwas/glob/syntax/ast" "git.internal/re/glob/syntax/ast"
"github.com/gobwas/glob/util/runes" "git.internal/re/glob/util/runes"
) )
func optimizeMatcher(matcher match.Matcher) match.Matcher { func optimizeMatcher(matcher match.Matcher) match.Matcher {

View File

@ -1,11 +1,12 @@
package compiler package compiler
import ( import (
"github.com/gobwas/glob/match"
"github.com/gobwas/glob/match/debug"
"github.com/gobwas/glob/syntax/ast"
"reflect" "reflect"
"testing" "testing"
"git.internal/re/glob/match"
"git.internal/re/glob/match/debug"
"git.internal/re/glob/syntax/ast"
) )
var separators = []rune{'.'} var separators = []rune{'.'}

43
glob.go
View File

@ -1,8 +1,8 @@
package glob package glob
import ( import (
"github.com/gobwas/glob/compiler" "git.internal/re/glob/compiler"
"github.com/gobwas/glob/syntax" "git.internal/re/glob/syntax"
) )
// Glob represents compiled glob pattern. // Glob represents compiled glob pattern.
@ -13,29 +13,28 @@ type Glob interface {
// Compile creates Glob for given pattern and strings (if any present after pattern) as separators. // Compile creates Glob for given pattern and strings (if any present after pattern) as separators.
// The pattern syntax is: // The pattern syntax is:
// //
// pattern: // pattern:
// { term } // { term }
// //
// term: // term:
// `*` matches any sequence of non-separator characters // `*` matches any sequence of non-separator characters
// `**` matches any sequence of characters // `**` matches any sequence of characters
// `?` matches any single non-separator character // `?` matches any single non-separator character
// `[` [ `!` ] { character-range } `]` // `[` [ `!` ] { character-range } `]`
// character class (must be non-empty) // character class (must be non-empty)
// `{` pattern-list `}` // `{` pattern-list `}`
// pattern alternatives // pattern alternatives
// c matches character c (c != `*`, `**`, `?`, `\`, `[`, `{`, `}`) // c matches character c (c != `*`, `**`, `?`, `\`, `[`, `{`, `}`)
// `\` c matches character c // `\` c matches character c
// //
// character-range: // character-range:
// c matches character c (c != `\\`, `-`, `]`) // c matches character c (c != `\\`, `-`, `]`)
// `\` c matches character c // `\` c matches character c
// lo `-` hi matches character c for lo <= c <= hi // lo `-` hi matches character c for lo <= c <= hi
//
// pattern-list:
// pattern { `,` pattern }
// comma-separated (without spaces) patterns
// //
// pattern-list:
// pattern { `,` pattern }
// comma-separated (without spaces) patterns
func Compile(pattern string, separators ...rune) (Glob, error) { func Compile(pattern string, separators ...rune) (Glob, error) {
ast, err := syntax.Parse(pattern) ast, err := syntax.Parse(pattern)
if err != nil { if err != nil {

View File

@ -2,7 +2,8 @@ package match
import ( import (
"fmt" "fmt"
"github.com/gobwas/glob/util/strings"
"git.internal/re/glob/util/strings"
) )
type Any struct { type Any struct {

View File

@ -3,8 +3,9 @@ package debug
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"github.com/gobwas/glob/match"
"math/rand" "math/rand"
"git.internal/re/glob/match"
) )
func Graphviz(pattern string, m match.Matcher) string { func Graphviz(pattern string, m match.Matcher) string {

View File

@ -2,8 +2,9 @@ package match
import ( import (
"fmt" "fmt"
"github.com/gobwas/glob/util/runes"
"unicode/utf8" "unicode/utf8"
"git.internal/re/glob/util/runes"
) )
type List struct { type List struct {

View File

@ -5,7 +5,7 @@ import (
"strings" "strings"
"unicode/utf8" "unicode/utf8"
sutil "github.com/gobwas/glob/util/strings" sutil "git.internal/re/glob/util/strings"
) )
type PrefixAny struct { type PrefixAny struct {

View File

@ -2,8 +2,9 @@ package match
import ( import (
"fmt" "fmt"
"github.com/gobwas/glob/util/runes"
"unicode/utf8" "unicode/utf8"
"git.internal/re/glob/util/runes"
) )
// single represents ? // single represents ?

View File

@ -4,7 +4,7 @@ import (
"fmt" "fmt"
"strings" "strings"
sutil "github.com/gobwas/glob/util/strings" sutil "git.internal/re/glob/util/strings"
) )
type SuffixAny struct { type SuffixAny struct {

View File

@ -7,7 +7,7 @@
## Install ## Install
```shell ```shell
go get github.com/gobwas/glob go get git.internal/re/glob
``` ```
## Example ## Example
@ -16,7 +16,7 @@
package main package main
import "github.com/gobwas/glob" import "git.internal/re/glob"
func main() { func main() {
var g glob.Glob var g glob.Glob
@ -137,8 +137,8 @@ Pattern | Fixture | Match | Speed (ns/op)
`^ab.*ef$` | `abcdef` | `true` | 375 `^ab.*ef$` | `abcdef` | `true` | 375
`^ab.*ef$` | `af` | `false` | 145 `^ab.*ef$` | `af` | `false` | 145
[godoc-image]: https://godoc.org/github.com/gobwas/glob?status.svg [godoc-image]: https://godoc.org/git.internal/re/glob?status.svg
[godoc-url]: https://godoc.org/github.com/gobwas/glob [godoc-url]: https://godoc.org/git.internal/re/glob
[travis-image]: https://travis-ci.org/gobwas/glob.svg?branch=master [travis-image]: https://travis-ci.org/gobwas/glob.svg?branch=master
[travis-url]: https://travis-ci.org/gobwas/glob [travis-url]: https://travis-ci.org/gobwas/glob

View File

@ -3,8 +3,9 @@ package ast
import ( import (
"errors" "errors"
"fmt" "fmt"
"github.com/gobwas/glob/syntax/lexer"
"unicode/utf8" "unicode/utf8"
"git.internal/re/glob/syntax/lexer"
) )
type Lexer interface { type Lexer interface {

View File

@ -4,7 +4,7 @@ import (
"reflect" "reflect"
"testing" "testing"
"github.com/gobwas/glob/syntax/lexer" "git.internal/re/glob/syntax/lexer"
) )
type stubLexer struct { type stubLexer struct {
@ -27,7 +27,7 @@ func TestParseString(t *testing.T) {
tree *Node tree *Node
}{ }{
{ {
//pattern: "abc", // pattern: "abc",
tokens: []lexer.Token{ tokens: []lexer.Token{
{lexer.Text, "abc"}, {lexer.Text, "abc"},
{lexer.EOF, ""}, {lexer.EOF, ""},
@ -37,7 +37,7 @@ func TestParseString(t *testing.T) {
), ),
}, },
{ {
//pattern: "a*c", // pattern: "a*c",
tokens: []lexer.Token{ tokens: []lexer.Token{
{lexer.Text, "a"}, {lexer.Text, "a"},
{lexer.Any, "*"}, {lexer.Any, "*"},
@ -51,7 +51,7 @@ func TestParseString(t *testing.T) {
), ),
}, },
{ {
//pattern: "a**c", // pattern: "a**c",
tokens: []lexer.Token{ tokens: []lexer.Token{
{lexer.Text, "a"}, {lexer.Text, "a"},
{lexer.Super, "**"}, {lexer.Super, "**"},
@ -65,7 +65,7 @@ func TestParseString(t *testing.T) {
), ),
}, },
{ {
//pattern: "a?c", // pattern: "a?c",
tokens: []lexer.Token{ tokens: []lexer.Token{
{lexer.Text, "a"}, {lexer.Text, "a"},
{lexer.Single, "?"}, {lexer.Single, "?"},
@ -79,7 +79,7 @@ func TestParseString(t *testing.T) {
), ),
}, },
{ {
//pattern: "[!a-z]", // pattern: "[!a-z]",
tokens: []lexer.Token{ tokens: []lexer.Token{
{lexer.RangeOpen, "["}, {lexer.RangeOpen, "["},
{lexer.Not, "!"}, {lexer.Not, "!"},
@ -94,7 +94,7 @@ func TestParseString(t *testing.T) {
), ),
}, },
{ {
//pattern: "[az]", // pattern: "[az]",
tokens: []lexer.Token{ tokens: []lexer.Token{
{lexer.RangeOpen, "["}, {lexer.RangeOpen, "["},
{lexer.Text, "az"}, {lexer.Text, "az"},
@ -106,7 +106,7 @@ func TestParseString(t *testing.T) {
), ),
}, },
{ {
//pattern: "{a,z}", // pattern: "{a,z}",
tokens: []lexer.Token{ tokens: []lexer.Token{
{lexer.TermsOpen, "{"}, {lexer.TermsOpen, "{"},
{lexer.Text, "a"}, {lexer.Text, "a"},
@ -127,7 +127,7 @@ func TestParseString(t *testing.T) {
), ),
}, },
{ {
//pattern: "/{z,ab}*", // pattern: "/{z,ab}*",
tokens: []lexer.Token{ tokens: []lexer.Token{
{lexer.Text, "/"}, {lexer.Text, "/"},
{lexer.TermsOpen, "{"}, {lexer.TermsOpen, "{"},
@ -152,7 +152,7 @@ func TestParseString(t *testing.T) {
), ),
}, },
{ {
//pattern: "{a,{x,y},?,[a-z],[!qwe]}", // pattern: "{a,{x,y},?,[a-z],[!qwe]}",
tokens: []lexer.Token{ tokens: []lexer.Token{
{lexer.TermsOpen, "{"}, {lexer.TermsOpen, "{"},
{lexer.Text, "a"}, {lexer.Text, "a"},

View File

@ -3,8 +3,9 @@ package lexer
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"github.com/gobwas/glob/util/runes"
"unicode/utf8" "unicode/utf8"
"git.internal/re/glob/util/runes"
) )
const ( const (
@ -146,8 +147,10 @@ func (l *lexer) termsLeave() {
l.termsLevel-- l.termsLevel--
} }
var inTextBreakers = []rune{char_single, char_any, char_range_open, char_terms_open} var (
var inTermsBreakers = append(inTextBreakers, char_terms_close, char_comma) inTextBreakers = []rune{char_single, char_any, char_range_open, char_terms_open}
inTermsBreakers = append(inTextBreakers, char_terms_close, char_comma)
)
func (l *lexer) fetchItem() { func (l *lexer) fetchItem() {
r := l.read() r := l.read()

View File

@ -1,8 +1,8 @@
package syntax package syntax
import ( import (
"github.com/gobwas/glob/syntax/ast" "git.internal/re/glob/syntax/ast"
"github.com/gobwas/glob/syntax/lexer" "git.internal/re/glob/syntax/lexer"
) )
func Parse(s string) (*ast.Node, error) { func Parse(s string) (*ast.Node, error) {