MCPcopy Create free account
hub / github.com/docopt/docopt.go / tokenListFromPattern

Function tokenListFromPattern

docopt.go:501–518  ·  view source on GitHub ↗
(source string)

Source from the content-addressed store, hash-verified

499}
500
501func tokenListFromPattern(source string) *tokenList {
502 p := regexp.MustCompile(`([\[\]\(\)\|]|\.\.\.)`)
503 source = p.ReplaceAllString(source, ` $1 `)
504 p = regexp.MustCompile(`\s+|(\S*<.*?>)`)
505 split := p.Split(source, -1)
506 match := p.FindAllStringSubmatch(source, -1)
507 var result []string
508 l := len(split)
509 for i := 0; i < l; i++ {
510 if len(split[i]) > 0 {
511 result = append(result, split[i])
512 }
513 if i < l-1 && len(match[i][1]) > 0 {
514 result = append(result, match[i][1])
515 }
516 }
517 return newTokenList(result, errorLanguage)
518}
519
520func formalUsage(section string) (string, error) {
521 _, _, section = stringPartition(section, ":") // drop "usage:"

Callers 1

parsePatternFunction · 0.85

Calls 1

newTokenListFunction · 0.85

Tested by

no test coverage detected