Sha256: 8dc78dac8f9465a5f6a62aa057ae97fbadd5b111efe8895ac824d46938dc3793

Contents?: true

Size: 947 Bytes

Versions: 6757

Compression:

Stored size: 947 Bytes

Contents

module AST
  # This simple module is very useful in the cases where one needs
  # to define deeply nested ASTs from Ruby code, for example, in
  # tests. It should be used like this:
  #
  #     describe YourLanguage::AST do
  #       include Sexp
  #
  #       it "should correctly parse expressions" do
  #         YourLanguage.parse("1 + 2 * 3").should ==
  #             s(:add,
  #               s(:integer, 1),
  #               s(:multiply,
  #                 s(:integer, 2),
  #                 s(:integer, 3)))
  #       end
  #     end
  #
  # This way the amount of boilerplate code is greatly reduced.
  module Sexp
    # Creates a {Node} with type `type` and children `children`.
    # Note that the resulting node is of the type AST::Node and not a
    # subclass.
    # This would not pose a problem with comparisons, as {Node#==}
    # ignores metadata.
    def s(type, *children)
      Node.new(type, children)
    end
  end
end

Version data entries

6,757 entries across 6,748 versions & 52 rubygems

Version Path
cybrid_api_bank_ruby-0.122.24 vendor/bundle/ruby/3.3.0/gems/ast-2.4.2/lib/ast/sexp.rb
cybrid_api_id_ruby-0.122.24 vendor/bundle/ruby/3.3.0/gems/ast-2.4.2/lib/ast/sexp.rb
cybrid_api_bank_ruby-0.122.23 vendor/bundle/ruby/3.3.0/gems/ast-2.4.2/lib/ast/sexp.rb
cybrid_api_id_ruby-0.122.23 vendor/bundle/ruby/3.3.0/gems/ast-2.4.2/lib/ast/sexp.rb
cybrid_api_organization_ruby-0.122.23 vendor/bundle/ruby/3.3.0/gems/ast-2.4.2/lib/ast/sexp.rb
cybrid_api_bank_ruby-0.122.22 vendor/bundle/ruby/3.3.0/gems/ast-2.4.2/lib/ast/sexp.rb
cybrid_api_id_ruby-0.122.22 vendor/bundle/ruby/3.3.0/gems/ast-2.4.2/lib/ast/sexp.rb
cybrid_api_organization_ruby-0.122.22 vendor/bundle/ruby/3.3.0/gems/ast-2.4.2/lib/ast/sexp.rb
cybrid_api_bank_ruby-0.122.20 vendor/bundle/ruby/3.3.0/gems/ast-2.4.2/lib/ast/sexp.rb
cybrid_api_organization_ruby-0.122.20 vendor/bundle/ruby/3.3.0/gems/ast-2.4.2/lib/ast/sexp.rb
cybrid_api_id_ruby-0.122.20 vendor/bundle/ruby/3.3.0/gems/ast-2.4.2/lib/ast/sexp.rb
cybrid_api_bank_ruby-0.122.18 vendor/bundle/ruby/3.3.0/gems/ast-2.4.2/lib/ast/sexp.rb
cybrid_api_id_ruby-0.122.18 vendor/bundle/ruby/3.3.0/gems/ast-2.4.2/lib/ast/sexp.rb
cybrid_api_organization_ruby-0.122.18 vendor/bundle/ruby/3.3.0/gems/ast-2.4.2/lib/ast/sexp.rb
cybrid_api_id_ruby-0.122.17 vendor/bundle/ruby/3.3.0/gems/ast-2.4.2/lib/ast/sexp.rb
cybrid_api_bank_ruby-0.122.17 vendor/bundle/ruby/3.3.0/gems/ast-2.4.2/lib/ast/sexp.rb
cybrid_api_organization_ruby-0.122.17 vendor/bundle/ruby/3.3.0/gems/ast-2.4.2/lib/ast/sexp.rb
cybrid_api_bank_ruby-0.122.16 vendor/bundle/ruby/3.3.0/gems/ast-2.4.2/lib/ast/sexp.rb
cybrid_api_organization_ruby-0.122.16 vendor/bundle/ruby/3.3.0/gems/ast-2.4.2/lib/ast/sexp.rb
cybrid_api_id_ruby-0.122.16 vendor/bundle/ruby/3.3.0/gems/ast-2.4.2/lib/ast/sexp.rb