module Drudge::Parsers

Public Instance Methods

arg(name, expected = value(/.*/)) click to toggle source

parses a single argument with the provided name

# File lib/drudge/parsers.rb, line 31
def arg(name, expected = value(/.*/))
  expected.mapv                 { |a| [:arg, a] }
          .with_failure_message { |msg| "#{msg} for <#{name}>" }
          .describe "<#{name}>"
end
command(name) click to toggle source

parses a command

# File lib/drudge/parsers.rb, line 38
def command(name)
  value(name.to_s, eos_failure_msg: "expected a command",
                   failure_msg: -> ((_, val)) { "unknown command '#{val}'" })
    .mapv { |v| [:arg, v] }
    .describe(name.to_s)
end
eos(message = "Expected end-of-command") click to toggle source

matches the end of the stream

Calls superclass method Drudge::Parsers::Primitives#eos
# File lib/drudge/parsers.rb, line 26
def eos(message = "Expected end-of-command")
  super
end
parser_mixin() click to toggle source
# File lib/drudge/parsers.rb, line 45
def parser_mixin
  ArgumentParser
end
value(expected = /.*/, eos_failure_msg: "expected a value", failure_msg: -> ((_, value)) { "' click to toggle source

returns a parser that matches a :val on the input expected is compared to the input using === (i.e. you can use it as a matcher for all sorts of things)

# File lib/drudge/parsers.rb, line 13
def value(expected = /.*/, 
          eos_failure_msg: "expected a value", 
          failure_msg:     -> ((_, value)) { "'#{value}' doesn't match #{expected}" })

  accept(-> ((kind, value)) { kind == :val && expected === value },
           eos_failure_msg: eos_failure_msg,
           failure_msg: failure_msg )
    .mapv { |_, value| value }
    .describe expected.to_s

end