Parse Reference

class DefaultParser

The standard parser.

var options : [Option]
var name : String
init(name: String, options: [Option])

Creates the standard parser

Parameters:
  • name – A name for this parser. This is used in help.
  • options – The options for this parser.
extension DefaultParser : Parser
func _parse(_: [String])throws → ParseResult
var shortHelp : String
var longHelp : String
protocol Parser

This is the protocol that all Parsers conform to. If you actually want an implementation, try DefaultParser .

func _parse(_: [String])throws → ParseResult

Implement parsing logic here. Don’t call this function directly, instead call .parse

var name : String
var shortHelp : String

A short description to help the user understand how to use the parser

var longHelp : String

A longer, potentially multi-line description of how to use the parser

func handlesArguments(_: [String]) → Bool

Determines if the parser handles the arguments. The default implementation attempts a parse, and returns false if the parse fails. - discussion: This is used inside the CommandParser to indicate whether the command matches the input. That way if the command matches, but some argument fails, we return an error to the user from the parser that handled the arguments.

func underlyingParser(_: [String]) → Parser
Returns:the best parser candidate for the given arguments. The default implementation returns the receiver.
Note:With metaparsers, returning a child object here may yield better error/help messages.
extension Parser
func parseArguments() → ParseResult?

Parse the arguments from the environment, displaying error and usage information to the user on a parse error.

func handlesArguments(_: [String]) → Bool
protocol Parser

This is the protocol that all Parsers conform to. If you actually want an implementation, try DefaultParser .

func _parse(_: [String])throws → ParseResult

Implement parsing logic here. Don’t call this function directly, instead call .parse

var name : String
var shortHelp : String

A short description to help the user understand how to use the parser

var longHelp : String

A longer, potentially multi-line description of how to use the parser

func handlesArguments(_: [String]) → Bool

Determines if the parser handles the arguments. The default implementation attempts a parse, and returns false if the parse fails. - discussion: This is used inside the CommandParser to indicate whether the command matches the input. That way if the command matches, but some argument fails, we return an error to the user from the parser that handled the arguments.

func underlyingParser(_: [String]) → Parser
Returns:the best parser candidate for the given arguments. The default implementation returns the receiver.
Note:With metaparsers, returning a child object here may yield better error/help messages.
extension Parser
func parseArguments() → ParseResult?

Parse the arguments from the environment, displaying error and usage information to the user on a parse error.

func handlesArguments(_: [String]) → Bool
struct ParseResult

A type that holds the result of the parse. The result is subscriptable.

Note:It’s recommended that you use strngly-typed keys where possible. Thus you could create
enum StringlyTyped: String {
    case MyKey = "MyKey"
    case MyKey2 = "MyKey2"
}

and then

parseResult[StronglyTyped.MyKey.rawValue]

This way you ensure you don’t have typos in your parsing logic.