File: macro.rb

package info (click to toggle)
mikutter 5.1.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,780 kB
  • sloc: ruby: 22,912; sh: 186; makefile: 21
file content (26 lines) | stat: -rw-r--r-- 663 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# -*- coding: utf-8 -*-
require_relative 'atom'

module MIKU
  class Macro
    include Atom
    def initialize(args, list)
      @args = args
      @list = list
    end

    def macro_expand(*args)
      if not(args.is_a? StaticCode) and args.car.is_a?(StaticCode)
        args.extend(StaticCode).staticcode_copy_info(args.car.staticcode_dump) end
      scope = MIKU::SymbolTable.new.miracle_binding(@args, args)
      # @args.zip(args){ |k, v|
      #   scope[k] = [v] }
      @list.inject(nil){ |last, operator|
        scope[:last] = last
        miku(operator, scope) } end

    def inspect
      "<macro #{@args.inspect} #{@list.inspect}>"
    end
  end
end