Compare commits
6 Commits
e489dc4c27
...
v0.6.0
Author | SHA1 | Date | |
---|---|---|---|
980fb77114 | |||
4c4d747a9c | |||
595b86df60 | |||
5f9bab528a | |||
530564b920 | |||
02b3b469c4 |
2
Makefile
2
Makefile
@@ -8,6 +8,6 @@ vet: fmt
|
|||||||
buildLib: vet
|
buildLib: vet
|
||||||
go build -gcflags="all=-N -l" ./...
|
go build -gcflags="all=-N -l" ./...
|
||||||
buildCmd: buildLib
|
buildCmd: buildLib
|
||||||
go build -C cmd/ -gcflags="all=-N -l" -o re ./...
|
go build -C kg/ -gcflags="all=-N -l" -o kg ./...
|
||||||
test: buildCmd
|
test: buildCmd
|
||||||
go test -v ./...
|
go test -v ./...
|
||||||
|
@@ -61,6 +61,11 @@ func main() {
|
|||||||
panic("Invalid match number to print.")
|
panic("Invalid match number to print.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Enable lineFlag if lineNumFlag is enabled
|
||||||
|
if *lineNumFlag {
|
||||||
|
*lineFlag = true
|
||||||
|
}
|
||||||
|
|
||||||
// Process:
|
// Process:
|
||||||
// 1. Convert regex into postfix notation (Shunting-Yard algorithm)
|
// 1. Convert regex into postfix notation (Shunting-Yard algorithm)
|
||||||
// a. Add explicit concatenation operators to facilitate this
|
// a. Add explicit concatenation operators to facilitate this
|
||||||
@@ -68,11 +73,11 @@ func main() {
|
|||||||
// 3. Run the string against the NFA
|
// 3. Run the string against the NFA
|
||||||
|
|
||||||
if len(flag.Args()) < 1 { // flag.Args() also strips out program name
|
if len(flag.Args()) < 1 { // flag.Args() also strips out program name
|
||||||
fmt.Println("ERROR: Missing cmdline args")
|
fmt.Printf("%s: ERROR: Missing cmdline args\n", os.Args[0])
|
||||||
os.Exit(22)
|
os.Exit(22)
|
||||||
}
|
}
|
||||||
if *recursiveFlag && len(flag.Args()) < 2 { // File/Directory must be provided with '-r'
|
if *recursiveFlag && len(flag.Args()) < 2 { // File/Directory must be provided with '-r'
|
||||||
fmt.Println("ERROR: Missing cmdline args")
|
fmt.Printf("%s: ERROR: Missing cmdline args\n", os.Args[0])
|
||||||
os.Exit(22)
|
os.Exit(22)
|
||||||
}
|
}
|
||||||
var re string
|
var re string
|
||||||
@@ -87,10 +92,20 @@ func main() {
|
|||||||
for _, inputFilename := range inputFilenames {
|
for _, inputFilename := range inputFilenames {
|
||||||
inputFile, err := os.Open(inputFilename)
|
inputFile, err := os.Open(inputFilename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("%s: No such file or directory\n", flag.Args()[1])
|
fmt.Printf("%s: %s: No such file or directory\n", os.Args[0], inputFilename)
|
||||||
os.Exit(2)
|
} else {
|
||||||
|
fileStat, err := inputFile.Stat()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("%v\n", err)
|
||||||
|
os.Exit(2)
|
||||||
|
} else {
|
||||||
|
if fileStat.Mode().IsDir() {
|
||||||
|
fmt.Printf("%s: %s: Is a directory\n", os.Args[0], inputFilename)
|
||||||
|
} else {
|
||||||
|
inputFiles = append(inputFiles, inputFile)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
inputFiles = append(inputFiles, inputFile)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,6 +123,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, inputFile := range inputFiles {
|
for _, inputFile := range inputFiles {
|
||||||
|
lineNum = 0
|
||||||
reader := bufio.NewReader(inputFile)
|
reader := bufio.NewReader(inputFile)
|
||||||
linesRead = false
|
linesRead = false
|
||||||
for true {
|
for true {
|
||||||
@@ -202,7 +218,12 @@ func main() {
|
|||||||
if !(*invertFlag) && len(matchIndices) == 0 || *invertFlag && len(matchIndices) > 0 {
|
if !(*invertFlag) && len(matchIndices) == 0 || *invertFlag && len(matchIndices) > 0 {
|
||||||
continue
|
continue
|
||||||
} else {
|
} else {
|
||||||
color.New(color.FgMagenta).Fprintf(out, "%s: ", inputFile.Name()) // Print filename
|
if *recursiveFlag || len(flag.Args()) > 2 { // If we have 2 args, then we're only searching 1 file. We should only print the filename if there's more than 1 file.
|
||||||
|
color.New(color.FgMagenta).Fprintf(out, "%s:", inputFile.Name()) // Print filename
|
||||||
|
}
|
||||||
|
if *lineNumFlag {
|
||||||
|
color.New(color.FgGreen).Fprintf(out, "%d:", lineNum) // Print filename
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@@ -47,6 +47,7 @@ func (re *Reg) UnmarshalText(text []byte) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Longest makes future searches prefer the longest branch of an alternation, as opposed to the leftmost branch.
|
||||||
func (re *Reg) Longest() {
|
func (re *Reg) Longest() {
|
||||||
re.preferLongest = true
|
re.preferLongest = true
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user