| 234 | } |
| 235 | |
| 236 | func parseOption(optionDescription string) *pattern { |
| 237 | optionDescription = strings.TrimSpace(optionDescription) |
| 238 | options, _, description := stringPartition(optionDescription, " ") |
| 239 | options = strings.Replace(options, ",", " ", -1) |
| 240 | options = strings.Replace(options, "=", " ", -1) |
| 241 | |
| 242 | short := "" |
| 243 | long := "" |
| 244 | argcount := 0 |
| 245 | var value interface{} |
| 246 | value = false |
| 247 | |
| 248 | reDefault := regexp.MustCompile(`(?i)\[default: (.*)\]`) |
| 249 | for _, s := range strings.Fields(options) { |
| 250 | if strings.HasPrefix(s, "--") { |
| 251 | long = s |
| 252 | } else if strings.HasPrefix(s, "-") { |
| 253 | short = s |
| 254 | } else { |
| 255 | argcount = 1 |
| 256 | } |
| 257 | if argcount > 0 { |
| 258 | matched := reDefault.FindAllStringSubmatch(description, -1) |
| 259 | if len(matched) > 0 { |
| 260 | value = matched[0][1] |
| 261 | } else { |
| 262 | value = nil |
| 263 | } |
| 264 | } |
| 265 | } |
| 266 | return newOption(short, long, argcount, value) |
| 267 | } |
| 268 | |
| 269 | func parseExpr(tokens *tokenList, options *patternList) (patternList, error) { |
| 270 | // expr ::= seq ( '|' seq )* ; |