Module: PuppetX::Augeas::Util::Parser
- Defined in:
- vendor_modules/augeas_core/lib/puppet_x/augeas/util/parser.rb
Overview
Container for helpers to parse user provided data contained in manifests.
Constant Summary collapse
- TOKEN_ARRAY_CLOSE =
%r{\s*\]\s*}.freeze
- TOKEN_ARRAY_OPEN =
%r{\s*\[\s*}.freeze
- TOKEN_ARRAY_SEPARATOR =
%r{\s*,\s*}.freeze
- TOKEN_CLOSE_CURLY =
%r|}|.freeze
- TOKEN_DOUBLE_QUOTE =
%r{"}.freeze
- TOKEN_DOUBLE_QUOTE_ESCAPED_CHAR =
%r{\\(["\\abtnvfres0-7xu])}.freeze
- TOKEN_DOUBLE_QUOTE_UNESCAPED_CHAR =
%r{[^"\\]}.freeze
- TOKEN_HEX_CHAR =
%r{[0-9a-fA-F]{1,2}}.freeze
- TOKEN_OCTAL_CHAR =
%r{[0-7]{1,3}}.freeze
- TOKEN_OPEN_CURLY =
%r|{|.freeze
- TOKEN_SINGLE_QUOTE =
%r{'}.freeze
- TOKEN_SINGLE_QUOTE_ESCAPED_CHAR =
%r{\\(['\\])}.freeze
- TOKEN_SINGLE_QUOTE_UNESCAPED_CHAR =
%r{[^'\\]}.freeze
- TOKEN_SPACE =
%r{\s}.freeze
- TOKEN_UNICODE_LONG_HEX_CHAR =
%r{[0-9a-fA-F]{1,6}}.freeze
- TOKEN_UNICODE_SHORT_HEX_CHAR =
%r{[0-9a-fA-F]{4}}.freeze
Instance Method Summary collapse
-
#parse_to_array(string) ⇒ Array<String>
Parse a string into the (nearly) equivalent Ruby array.
Instance Method Details
#parse_to_array(string) ⇒ Array<String>
Parse a string into the (nearly) equivalent Ruby array. This only handles arrays with string members (double-, or single-quoted), and does not support the full quite of escape sequences that Ruby allows in double-quoted strings.
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'vendor_modules/augeas_core/lib/puppet_x/augeas/util/parser.rb', line 36 def parse_to_array(string) s = StringScanner.new(string) match = array_open(s) raise "Unexpected character in array at: #{s.rest}" if match.nil? array_content = array_values(s) match = array_close(s) raise "Unexpected character in array at: #{s.rest}" if match.nil? || !s.empty? array_content end |