|
|
@ -16,6 +16,7 @@ import (
|
|
|
|
const CONCAT rune = '~'
|
|
|
|
const CONCAT rune = '~'
|
|
|
|
|
|
|
|
|
|
|
|
var notDotChars []rune
|
|
|
|
var notDotChars []rune
|
|
|
|
|
|
|
|
var caseInsensitiveFlag *bool // Whether we are running in case-insensitive mode
|
|
|
|
|
|
|
|
|
|
|
|
func isOperator(c rune) bool {
|
|
|
|
func isOperator(c rune) bool {
|
|
|
|
if c == '+' || c == '?' || c == '*' || c == '|' || c == CONCAT {
|
|
|
|
if c == '+' || c == '?' || c == '*' || c == '|' || c == CONCAT {
|
|
|
@ -155,7 +156,11 @@ func shuntingYard(re string) []postfixNode {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
c := re_postfix[i]
|
|
|
|
c := re_postfix[i]
|
|
|
|
if isNormalChar(c) {
|
|
|
|
if isNormalChar(c) {
|
|
|
|
outQueue = append(outQueue, newPostfixNode(c))
|
|
|
|
if *caseInsensitiveFlag {
|
|
|
|
|
|
|
|
outQueue = append(outQueue, newPostfixNode(allCases(c)...))
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
outQueue = append(outQueue, newPostfixNode(c))
|
|
|
|
|
|
|
|
}
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Escape character
|
|
|
|
// Escape character
|
|
|
@ -501,6 +506,7 @@ func main() {
|
|
|
|
lineFlag := flag.Bool("l", false, "Only print lines with a match (or with no matches, if -v is enabled). Similar to grep's default.")
|
|
|
|
lineFlag := flag.Bool("l", false, "Only print lines with a match (or with no matches, if -v is enabled). Similar to grep's default.")
|
|
|
|
multiLineFlag := flag.Bool("t", false, "Multi-line mode. Treats newline just like any character.")
|
|
|
|
multiLineFlag := flag.Bool("t", false, "Multi-line mode. Treats newline just like any character.")
|
|
|
|
printMatchesFlag := flag.Bool("p", false, "Prints start and end index of each match. Can only be used with '-t' for multi-line mode.")
|
|
|
|
printMatchesFlag := flag.Bool("p", false, "Prints start and end index of each match. Can only be used with '-t' for multi-line mode.")
|
|
|
|
|
|
|
|
caseInsensitiveFlag = flag.Bool("i", false, "Case-insensitive. Disregard the case of all characters.")
|
|
|
|
flag.Parse()
|
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
|
|
|
|
// In multi-line mode, 'dot' metacharacter also matches newline
|
|
|
|
// In multi-line mode, 'dot' metacharacter also matches newline
|
|
|
|