Class: Sexpistol

Inherits:
Object
  • Object
show all
Defined in:
lib/sexpistol.rb,
lib/sexpistol/parser.rb,
lib/sexpistol/version.rb,
lib/sexpistol/s_expression_array.rb

Defined Under Namespace

Classes: Parser, SExpressionArray

Constant Summary collapse

VERSION =
'0.1.2'

Class Method Summary collapse

Class Method Details

.parse(string, parse_ruby_keyword_literals: false) ⇒ Object


9
10
11
# File 'lib/sexpistol.rb', line 9

def parse(string, parse_ruby_keyword_literals: false)
  Sexpistol::Parser.new(string, parse_ruby_keyword_literals).parse
end

.to_sexp(data, scheme_compatability: false) ⇒ Object


13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/sexpistol.rb', line 13

def to_sexp(data, scheme_compatability: false)
  data = convert_scheme_literals(data) if scheme_compatability

  return "\"#{data}\"" if data.is_a?(String)
  return data.to_s unless data.is_a?(Array)

  if data.is_a?(SExpressionArray)
    data.map { |x| to_sexp(x, scheme_compatability: scheme_compatability) }.join(' ')
  else
    "(#{data.map { |x| to_sexp(x, scheme_compatability: scheme_compatability) }.join(' ')})"
  end
end