Class: WLang::Compiler::Autospacing

Inherits:
Filter
  • Object
show all
Defined in:
lib/wlang/compiler/autospacing.rb

Defined Under Namespace

Classes: RightStrip, Unindent

Instance Method Summary collapse

Methods included from Filter::ClassMethods

#recurse_on

Methods included from Filter::InstanceMethods

#recurse

Instance Method Details

#on_strconcat(*exps) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/wlang/compiler/autospacing.rb', line 5

def on_strconcat(*exps)
  optimized = []
  exps.each_with_index do |exp,i|
    optimized[i] = call(exp)
    if exp.first == :wlang and multiline?(exp) and i != 0
      optimized[i-1] = RightStrip.new.call(optimized[i-1])
    end
  end
  [:strconcat] + optimized
end

#on_wlang(symbols, *fns) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/wlang/compiler/autospacing.rb', line 16

def on_wlang(symbols, *fns)
  fns.inject [:wlang, symbols] do |rw,fn|
    if multiline?(fn)
      fn = Unindent.new.call(fn)
      fn = RightStrip.new.call(fn)
    end
    rw << call(fn)
  end
end