(tokens *tokenList, options *patternList)
| 317 | } |
| 318 | |
| 319 | func parseAtom(tokens *tokenList, options *patternList) (patternList, error) { |
| 320 | // atom ::= '(' expr ')' | '[' expr ']' | 'options' | long | shorts | argument | command ; |
| 321 | tok := tokens.current() |
| 322 | result := patternList{} |
| 323 | if tokens.current().match(false, "(", "[") { |
| 324 | tokens.move() |
| 325 | var matching string |
| 326 | pl, err := parseExpr(tokens, options) |
| 327 | if err != nil { |
| 328 | return nil, err |
| 329 | } |
| 330 | if tok.eq("(") { |
| 331 | matching = ")" |
| 332 | result = patternList{newRequired(pl...)} |
| 333 | } else if tok.eq("[") { |
| 334 | matching = "]" |
| 335 | result = patternList{newOptional(pl...)} |
| 336 | } |
| 337 | moved := tokens.move() |
| 338 | if !moved.eq(matching) { |
| 339 | return nil, tokens.errorFunc("unmatched '%s', expected: '%s' got: '%s'", tok, matching, moved) |
| 340 | } |
| 341 | return result, nil |
| 342 | } else if tok.eq("options") { |
| 343 | tokens.move() |
| 344 | return patternList{newOptionsShortcut()}, nil |
| 345 | } else if tok.hasPrefix("--") && !tok.eq("--") { |
| 346 | return parseLong(tokens, options) |
| 347 | } else if tok.hasPrefix("-") && !tok.eq("-") && !tok.eq("--") { |
| 348 | return parseShorts(tokens, options) |
| 349 | } else if tok.hasPrefix("<") && tok.hasSuffix(">") || tok.isUpper() { |
| 350 | return patternList{newArgument(tokens.move().String(), nil)}, nil |
| 351 | } |
| 352 | return patternList{newCommand(tokens.move().String(), false)}, nil |
| 353 | } |
| 354 | |
| 355 | func parseLong(tokens *tokenList, options *patternList) (patternList, error) { |
| 356 | // long ::= '--' chars [ ( ' ' | '=' ) chars ] ; |
no test coverage detected