module SON

based on github.com/aleksandergurin/simple-object-notation

Thanks to Aleksander Gurin

Constants

DOUBLE_QUOTE
SHELL_COMMENT

Public Class Methods

convert( text ) click to toggle source
# File lib/json/next/parser/son.rb, line 31
def self.convert( text )

  # text is the SON string to convert.

  text = strip_comments( text )    ## pass 1
  text = JSON::Next::Commata.convert( text )  ## pass 2 - auto-add (missing optional) commas
  text
end
parse( text ) click to toggle source
# File lib/json/next/parser/son.rb, line 41
def self.parse( text )
  JSON.parse( self.convert( text ) )
end
strip_comments( text ) click to toggle source
# File lib/json/next/parser/son.rb, line 16
def self.strip_comments( text )   ## pass 1
  text.gsub( /#{DOUBLE_QUOTE}|#{SHELL_COMMENT}/ox ) do |match|
     ## puts "match: >>#{match}<< : #{match.class.name}"
     if match[0] == ?#    ## comments start with #
       ## puts "!!! removing comments"
       ''    ## remove / strip comments
     else
       match
     end
   end
end