Skip to content
Myr

Rewrite bind spec parser

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Junegunn Choi · committed by Junegunn Choi · parent 1a97617 · Browse files · 2 files+53 added−13 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+53 added−13 removed

  • other:+53 added−13 removed

2 files+53 added−13 removed

modified:man/man1/fzf.1+2 added
1047 unmodified lines
1048that case, you can use any of the following alternative notations to avoid1049parse errors.10501051 \fBaction-name[...]\fR1052 \fBaction-name{...}\fR1053 \fBaction-name<...>\fR1054 \fBaction-name~...~\fR1055 \fBaction-name!...!\fR1056 \fBaction-name@...@\fR1057 \fBaction-name#...#\fR
107 unmodified lines
modified:src/options.go+51 added-13 removed
887 unmodified lines
888 escapedPlus = 2889)890891func init() {892 // Backreferences are not supported.893 // "~!@#$%^&*;/|".each_char.map { |c| Regexp.escape(c) }.map { |c| "#{c}[^#{c}]*#{c}" }.join('|')892 executeRegexp = regexp.MustCompile(895 `(?si)[:+](execute(?:-multi|-silent)?|reload|preview|change-query|change-prompt|change-preview-window|change-preview|(?:re|un)bind):.+|[:+](execute(?:-multi|-silent)?|reload|preview|change-query|change-prompt|change-preview-window|change-preview|(?:re|un)bind)(\([^)]*\)|\[[^\]]*\]|~[^~]*~|![^!]*!|@[^@]*@|\#[^\#]*\#|\$[^\$]*\$|%[^%]*%|\^[^\^]*\^|&[^&]*&|\*[^\*]*\*|;[^;]*;|/[^/]*/|\|[^\|]*\|)`)893 `(?si)[:+](execute(?:-multi|-silent)?|reload|preview|change-query|change-prompt|change-preview-window|change-preview|(?:re|un)bind)`)894 splitRegexp = regexp.MustCompile("[,:]+")895 actionNameRegexp = regexp.MustCompile("(?i)^[a-z-]+")896}897898func maskActionContents(action string) string {901 masked := executeRegexp.ReplaceAllStringFunc(action, func(src string) string {902 prefix := src[:1] + actionNameRegexp.FindString(src[1:])903 return prefix + "(" + strings.Repeat(" ", len(src)-len(prefix)-2) + ")"904 })899 masked := ""900Loop:901 for len(action) > 0 {902 loc := executeRegexp.FindStringIndex(action)903 if loc == nil {904 masked += action905 break906 }907 masked += action[:loc[1]]908 action = action[loc[1]:]909 if len(action) == 0 {910 break911 }912 cs := string(action[0])913 ce := ")"914 switch action[0] {915 case ':':916 masked += strings.Repeat(" ", len(action))917 break Loop918 case '(':919 ce = ")"920 case '{':921 ce = "}"922 case '[':923 ce = "]"924 case '<':925 ce = ">"926 case '~', '!', '@', '#', '$', '%', '^', '&', '*', ';', '/', '|':927 ce = string(cs)928 default:929 continue930 }931 cs = regexp.QuoteMeta(cs)932 ce = regexp.QuoteMeta(ce)933934 // @$ or @+935 loc = regexp.MustCompile(fmt.Sprintf(`^%s.*?(%s[+,]|%s$)`, cs, ce, ce)).FindStringIndex(action)936 if loc == nil {937 masked += action938 break939 }940 // Keep + or , at the end941 masked += strings.Repeat(" ", loc[1]-1) + action[loc[1]-1:loc[1]]942 action = action[loc[1]:]943 }944 masked = strings.Replace(masked, "::", string([]rune{escapedColon, ':'}), -1)945 masked = strings.Replace(masked, ",:", string([]rune{escapedComma, ':'}), -1)946 masked = strings.Replace(masked, "+:", string([]rune{escapedPlus, ':'}), -1)947 return masked
220 unmodified lines
1168 }1169}11701171func isExecuteAction(str string) actionType {1133 matches := executeRegexp.FindAllStringSubmatch(":"+str, -1)1134 if matches == nil || len(matches) != 1 || len(matches[0][0]) != len(str)+1 {1172 masked := maskActionContents(":" + str)[1:]1173 if masked == str {1174 // Not masked1175 return actIgnore1176 }1137 prefix := matches[0][1]1138 if len(prefix) == 0 {1139 prefix = matches[0][2]1140 }11771178 prefix := actionNameRegexp.FindString(str)1179 switch prefix {1180 case "reload":1181 return actReload1182 case "unbind":
784 unmodified lines