forked from mirror/glob
repo fixes
This commit is contained in:
parent
e7a84e9525
commit
bb6a74629b
|
@ -3,12 +3,13 @@ package main
|
|||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/gobwas/glob"
|
||||
"github.com/gobwas/glob/match"
|
||||
"github.com/gobwas/glob/match/debug"
|
||||
"os"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
|
||||
"git.internal/re/glob"
|
||||
"git.internal/re/glob/match"
|
||||
"git.internal/re/glob/match/debug"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
|
@ -3,11 +3,12 @@ package main
|
|||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/gobwas/glob"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
"unicode/utf8"
|
||||
|
||||
"git.internal/re/glob"
|
||||
)
|
||||
|
||||
func benchString(r testing.BenchmarkResult) string {
|
||||
|
|
|
@ -7,9 +7,9 @@ import (
|
|||
"fmt"
|
||||
"reflect"
|
||||
|
||||
"github.com/gobwas/glob/match"
|
||||
"github.com/gobwas/glob/syntax/ast"
|
||||
"github.com/gobwas/glob/util/runes"
|
||||
"git.internal/re/glob/match"
|
||||
"git.internal/re/glob/syntax/ast"
|
||||
"git.internal/re/glob/util/runes"
|
||||
)
|
||||
|
||||
func optimizeMatcher(matcher match.Matcher) match.Matcher {
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
package compiler
|
||||
|
||||
import (
|
||||
"github.com/gobwas/glob/match"
|
||||
"github.com/gobwas/glob/match/debug"
|
||||
"github.com/gobwas/glob/syntax/ast"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"git.internal/re/glob/match"
|
||||
"git.internal/re/glob/match/debug"
|
||||
"git.internal/re/glob/syntax/ast"
|
||||
)
|
||||
|
||||
var separators = []rune{'.'}
|
||||
|
|
43
glob.go
43
glob.go
|
@ -1,8 +1,8 @@
|
|||
package glob
|
||||
|
||||
import (
|
||||
"github.com/gobwas/glob/compiler"
|
||||
"github.com/gobwas/glob/syntax"
|
||||
"git.internal/re/glob/compiler"
|
||||
"git.internal/re/glob/syntax"
|
||||
)
|
||||
|
||||
// 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.
|
||||
// The pattern syntax is:
|
||||
//
|
||||
// pattern:
|
||||
// { term }
|
||||
// pattern:
|
||||
// { term }
|
||||
//
|
||||
// term:
|
||||
// `*` matches any sequence of non-separator characters
|
||||
// `**` matches any sequence of characters
|
||||
// `?` matches any single non-separator character
|
||||
// `[` [ `!` ] { character-range } `]`
|
||||
// character class (must be non-empty)
|
||||
// `{` pattern-list `}`
|
||||
// pattern alternatives
|
||||
// c matches character c (c != `*`, `**`, `?`, `\`, `[`, `{`, `}`)
|
||||
// `\` c matches character c
|
||||
// term:
|
||||
// `*` matches any sequence of non-separator characters
|
||||
// `**` matches any sequence of characters
|
||||
// `?` matches any single non-separator character
|
||||
// `[` [ `!` ] { character-range } `]`
|
||||
// character class (must be non-empty)
|
||||
// `{` pattern-list `}`
|
||||
// pattern alternatives
|
||||
// c matches character c (c != `*`, `**`, `?`, `\`, `[`, `{`, `}`)
|
||||
// `\` c matches character c
|
||||
//
|
||||
// character-range:
|
||||
// c matches character c (c != `\\`, `-`, `]`)
|
||||
// `\` c matches character c
|
||||
// lo `-` hi matches character c for lo <= c <= hi
|
||||
//
|
||||
// pattern-list:
|
||||
// pattern { `,` pattern }
|
||||
// comma-separated (without spaces) patterns
|
||||
// character-range:
|
||||
// c matches character c (c != `\\`, `-`, `]`)
|
||||
// `\` c matches character c
|
||||
// lo `-` hi matches character c for lo <= c <= hi
|
||||
//
|
||||
// pattern-list:
|
||||
// pattern { `,` pattern }
|
||||
// comma-separated (without spaces) patterns
|
||||
func Compile(pattern string, separators ...rune) (Glob, error) {
|
||||
ast, err := syntax.Parse(pattern)
|
||||
if err != nil {
|
||||
|
|
|
@ -2,7 +2,8 @@ package match
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gobwas/glob/util/strings"
|
||||
|
||||
"git.internal/re/glob/util/strings"
|
||||
)
|
||||
|
||||
type Any struct {
|
||||
|
|
|
@ -3,8 +3,9 @@ package debug
|
|||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"github.com/gobwas/glob/match"
|
||||
"math/rand"
|
||||
|
||||
"git.internal/re/glob/match"
|
||||
)
|
||||
|
||||
func Graphviz(pattern string, m match.Matcher) string {
|
||||
|
|
|
@ -2,8 +2,9 @@ package match
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gobwas/glob/util/runes"
|
||||
"unicode/utf8"
|
||||
|
||||
"git.internal/re/glob/util/runes"
|
||||
)
|
||||
|
||||
type List struct {
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"strings"
|
||||
"unicode/utf8"
|
||||
|
||||
sutil "github.com/gobwas/glob/util/strings"
|
||||
sutil "git.internal/re/glob/util/strings"
|
||||
)
|
||||
|
||||
type PrefixAny struct {
|
||||
|
|
|
@ -2,8 +2,9 @@ package match
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gobwas/glob/util/runes"
|
||||
"unicode/utf8"
|
||||
|
||||
"git.internal/re/glob/util/runes"
|
||||
)
|
||||
|
||||
// single represents ?
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"fmt"
|
||||
"strings"
|
||||
|
||||
sutil "github.com/gobwas/glob/util/strings"
|
||||
sutil "git.internal/re/glob/util/strings"
|
||||
)
|
||||
|
||||
type SuffixAny struct {
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
## Install
|
||||
|
||||
```shell
|
||||
go get github.com/gobwas/glob
|
||||
go get git.internal/re/glob
|
||||
```
|
||||
|
||||
## Example
|
||||
|
@ -16,7 +16,7 @@
|
|||
|
||||
package main
|
||||
|
||||
import "github.com/gobwas/glob"
|
||||
import "git.internal/re/glob"
|
||||
|
||||
func main() {
|
||||
var g glob.Glob
|
||||
|
@ -137,8 +137,8 @@ Pattern | Fixture | Match | Speed (ns/op)
|
|||
`^ab.*ef$` | `abcdef` | `true` | 375
|
||||
`^ab.*ef$` | `af` | `false` | 145
|
||||
|
||||
[godoc-image]: https://godoc.org/github.com/gobwas/glob?status.svg
|
||||
[godoc-url]: https://godoc.org/github.com/gobwas/glob
|
||||
[godoc-image]: https://godoc.org/git.internal/re/glob?status.svg
|
||||
[godoc-url]: https://godoc.org/git.internal/re/glob
|
||||
[travis-image]: https://travis-ci.org/gobwas/glob.svg?branch=master
|
||||
[travis-url]: https://travis-ci.org/gobwas/glob
|
||||
|
||||
|
|
|
@ -3,8 +3,9 @@ package ast
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/gobwas/glob/syntax/lexer"
|
||||
"unicode/utf8"
|
||||
|
||||
"git.internal/re/glob/syntax/lexer"
|
||||
)
|
||||
|
||||
type Lexer interface {
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/gobwas/glob/syntax/lexer"
|
||||
"git.internal/re/glob/syntax/lexer"
|
||||
)
|
||||
|
||||
type stubLexer struct {
|
||||
|
@ -27,7 +27,7 @@ func TestParseString(t *testing.T) {
|
|||
tree *Node
|
||||
}{
|
||||
{
|
||||
//pattern: "abc",
|
||||
// pattern: "abc",
|
||||
tokens: []lexer.Token{
|
||||
{lexer.Text, "abc"},
|
||||
{lexer.EOF, ""},
|
||||
|
@ -37,7 +37,7 @@ func TestParseString(t *testing.T) {
|
|||
),
|
||||
},
|
||||
{
|
||||
//pattern: "a*c",
|
||||
// pattern: "a*c",
|
||||
tokens: []lexer.Token{
|
||||
{lexer.Text, "a"},
|
||||
{lexer.Any, "*"},
|
||||
|
@ -51,7 +51,7 @@ func TestParseString(t *testing.T) {
|
|||
),
|
||||
},
|
||||
{
|
||||
//pattern: "a**c",
|
||||
// pattern: "a**c",
|
||||
tokens: []lexer.Token{
|
||||
{lexer.Text, "a"},
|
||||
{lexer.Super, "**"},
|
||||
|
@ -65,7 +65,7 @@ func TestParseString(t *testing.T) {
|
|||
),
|
||||
},
|
||||
{
|
||||
//pattern: "a?c",
|
||||
// pattern: "a?c",
|
||||
tokens: []lexer.Token{
|
||||
{lexer.Text, "a"},
|
||||
{lexer.Single, "?"},
|
||||
|
@ -79,7 +79,7 @@ func TestParseString(t *testing.T) {
|
|||
),
|
||||
},
|
||||
{
|
||||
//pattern: "[!a-z]",
|
||||
// pattern: "[!a-z]",
|
||||
tokens: []lexer.Token{
|
||||
{lexer.RangeOpen, "["},
|
||||
{lexer.Not, "!"},
|
||||
|
@ -94,7 +94,7 @@ func TestParseString(t *testing.T) {
|
|||
),
|
||||
},
|
||||
{
|
||||
//pattern: "[az]",
|
||||
// pattern: "[az]",
|
||||
tokens: []lexer.Token{
|
||||
{lexer.RangeOpen, "["},
|
||||
{lexer.Text, "az"},
|
||||
|
@ -106,7 +106,7 @@ func TestParseString(t *testing.T) {
|
|||
),
|
||||
},
|
||||
{
|
||||
//pattern: "{a,z}",
|
||||
// pattern: "{a,z}",
|
||||
tokens: []lexer.Token{
|
||||
{lexer.TermsOpen, "{"},
|
||||
{lexer.Text, "a"},
|
||||
|
@ -127,7 +127,7 @@ func TestParseString(t *testing.T) {
|
|||
),
|
||||
},
|
||||
{
|
||||
//pattern: "/{z,ab}*",
|
||||
// pattern: "/{z,ab}*",
|
||||
tokens: []lexer.Token{
|
||||
{lexer.Text, "/"},
|
||||
{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{
|
||||
{lexer.TermsOpen, "{"},
|
||||
{lexer.Text, "a"},
|
||||
|
|
|
@ -3,8 +3,9 @@ package lexer
|
|||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"github.com/gobwas/glob/util/runes"
|
||||
"unicode/utf8"
|
||||
|
||||
"git.internal/re/glob/util/runes"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -146,8 +147,10 @@ func (l *lexer) termsLeave() {
|
|||
l.termsLevel--
|
||||
}
|
||||
|
||||
var inTextBreakers = []rune{char_single, char_any, char_range_open, char_terms_open}
|
||||
var inTermsBreakers = append(inTextBreakers, char_terms_close, char_comma)
|
||||
var (
|
||||
inTextBreakers = []rune{char_single, char_any, char_range_open, char_terms_open}
|
||||
inTermsBreakers = append(inTextBreakers, char_terms_close, char_comma)
|
||||
)
|
||||
|
||||
func (l *lexer) fetchItem() {
|
||||
r := l.read()
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package syntax
|
||||
|
||||
import (
|
||||
"github.com/gobwas/glob/syntax/ast"
|
||||
"github.com/gobwas/glob/syntax/lexer"
|
||||
"git.internal/re/glob/syntax/ast"
|
||||
"git.internal/re/glob/syntax/lexer"
|
||||
)
|
||||
|
||||
func Parse(s string) (*ast.Node, error) {
|
||||
|
|
Loading…
Reference in New Issue