Sha256: 0cda1aad7b3f0d6d0b4a2ad0b56c95d2ef48f85877727ba448221e6e35b0c7fd

Contents?: true

Size: 1.32 KB

Versions: 1

Compression:

Stored size: 1.32 KB

Contents

module Liquidscript
  module Compiler
    class ICR
      module Classes

        def compile_class
          shift :class
          name = shift :identifier
          body = _compile_class_body

          set name
          code :class, name, body
        end

        def compile_module
          shift :module
          name = shift :identifier
          body = _compile_class_body(true)

          set name
          code :module, name, body
        end

        def _compile_class_body(mod = false)
          shift :lbrack

          components = []

          compile_object = action do
            components << [
              _compile_class_body_key(mod),
              compile_expression
            ]
          end

          loop do
            expect :rbrack => action.end_loop,
            :comma         => action.shift,
            :module        => action { components << compile_module },
            :class         => action { components << compile_class  },
            [:identifier, :dstring] => compile_object
          end

          components
        end

        def _compile_class_body_key(mod)
          item = shift :identifier, :dstring

          item = compile_property(item) if item.type == :identifier &&
            peek?(:prop) && mod

          shift :colon
          item
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
liquidscript-0.0.1 lib/liquidscript/compiler/icr/classes.rb