Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

41 lines (38 sloc) 1.07 kB
class Optitron
class Tokenizer
attr_reader :tokens
def initialize(parser, opts)
@parser, @opts = parser, opts
tokenize
end
Value = Struct.new(:lit)
Named = Struct.new(:name)
NamedWithValue = Struct.new(:name, :value)
def tokenize
unless @tokens
@tokens = @opts.map do |t|
case t
when /^--([^-][^=]+)=([^=]+)$/ then NamedWithValue.new($1, $2)
when /^--([^-][^=]+)$/ then NamedWithValue.new($1, nil)
when /^-(.*)/ then find_names_values($1)
else Value.new(t)
end
end
@tokens.flatten!
end
end
def find_names_values(short)
toks = []
letters = short.split('')
while !letters.empty?
let = letters.shift
toks << Named.new(let)
if @parser.short_opts[let] && !@parser.short_opts[let].boolean? && !letters.empty?
toks << Value.new(letters.join)
letters.clear
end
end
toks
end
end
end
Jump to Line
Something went wrong with that request. Please try again.