Class: Argstring::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/argstring/parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(separator: Config::WHITESPACE_SEPARATOR_SENTINEL, escape: "\\", assignment: ["="], enclosers: Config::DEFAULT_ENCLOSERS, duplicates: :last, flags: true, positional: true) ⇒ Parser

Returns a new instance of Parser.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/argstring/parser.rb', line 5

def initialize(separator: Config::WHITESPACE_SEPARATOR_SENTINEL, escape: "\\", assignment: ["="], enclosers: Config::DEFAULT_ENCLOSERS, duplicates: :last, flags: true, positional: true)
	@config = Config.new(
		separator: separator,
		escape: escape,
		assignment: assignment,
		enclosers: enclosers,
		duplicates: duplicates,
		flags: flags,
		positional: positional
	)

	@segmenter = Lexer::Segmenter.new(@config)
	@assignment_finder = Lexer::AssignmentFinder.new(@config)
	@token_parser = Lexer::TokenParser.new(@config)
end

Instance Method Details

#parse(argstring) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/argstring/parser.rb', line 21

def parse(argstring)
	result = parse_internal(argstring.to_s)
	unless result.valid?
		warn("Argstring: #{result.error_messages.join('; ')}")
	end
	result
end