Sha256: f3683b11cb108eecae979a72b8d01740e3001da5747dcc61e514a1ec4cf37091

Contents?: true

Size: 553 Bytes

Versions: 21

Compression:

Stored size: 553 Bytes

Contents

require 'sexpistol'
module ATP
  class Parser < Sexpistol
    def initialize
      self.ruby_keyword_literals = true
    end

    def string_to_ast(string)
      to_sexp(parse_string(string))
    end

    def to_sexp(ast_array)
      children = ast_array.map do |item|
        if  item.is_a?(Array)
          to_sexp(item)
        else
          item
        end
      end
      type = children.shift
      return type if type.is_a?(ATP::AST::Node)
      type = type.to_s.gsub('-', '_').to_sym
      ATP::AST::Node.new(type, children)
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
atp-1.1.3 lib/atp/parser.rb
atp-1.1.2 lib/atp/parser.rb
atp-1.1.1 lib/atp/parser.rb
atp-1.1.0 lib/atp/parser.rb
atp-1.0.0 lib/atp/parser.rb
atp-0.8.0 lib/atp/parser.rb
atp-0.7.0 lib/atp/parser.rb
atp-0.6.0 lib/atp/parser.rb
atp-0.5.4 lib/atp/parser.rb
atp-0.5.3 lib/atp/parser.rb
atp-0.5.0 lib/atp/parser.rb
atp-0.4.3 lib/atp/parser.rb
atp-0.4.2 lib/atp/parser.rb
atp-0.4.1 lib/atp/parser.rb
atp-0.4.0 lib/atp/parser.rb
atp-0.3.3 lib/atp/parser.rb
atp-0.3.2 lib/atp/parser.rb
atp-0.3.1 lib/atp/parser.rb
atp-0.3.0 lib/atp/parser.rb
atp-0.2.1 lib/atp/parser.rb