Class: WLang::Compiler
- Inherits:
-
Object
show all
- Defined in:
- lib/wlang/compiler.rb,
lib/wlang/compiler/filter.rb,
lib/wlang/compiler/autospacing.rb,
lib/wlang/compiler/to_ruby_code.rb,
lib/wlang/compiler/static_merger.rb,
lib/wlang/compiler/dialect_enforcer.rb,
lib/wlang/compiler/proc_call_removal.rb,
lib/wlang/compiler/strconcat_flattener.rb,
lib/wlang/compiler/to_ruby_abstraction.rb
Overview
Provides the wlang compiler which works on the following AST abstractions:
- :template, the root element [:template, [:fn, ...]]
- :fn, a concrete function [:fn, code]
- :wlang, a high-order function [:wlang, symbols, [:fn, ..], [:fn, ...], ...]
- :strconcat, concatenation [:strconcat, [...], [...], [...]]
- :modulo, modulation [:modulo, dialect, [:fn, ...]]
- :static, constant text [:static, "..."]
Defined Under Namespace
Classes: Autospacing, DialectEnforcer, Filter, ProcCallRemoval, StaticMerger, StrconcatFlattener, ToRubyAbstraction, ToRubyCode
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(dialect) ⇒ Compiler
Returns a new instance of Compiler.
25
26
27
|
# File 'lib/wlang/compiler.rb', line 25
def initialize(dialect)
@dialect = dialect
end
|
Instance Attribute Details
#dialect ⇒ Object
Returns the value of attribute dialect.
23
24
25
|
# File 'lib/wlang/compiler.rb', line 23
def dialect
@dialect
end
|
Instance Method Details
#engine(generate_code = true) ⇒ Object
#options ⇒ Object
29
30
31
|
# File 'lib/wlang/compiler.rb', line 29
def options
dialect.options
end
|
#parser(engine = Class.new(Temple::Engine)) ⇒ Object
#to_ast(source) ⇒ Object
46
47
48
|
# File 'lib/wlang/compiler.rb', line 46
def to_ast(source)
parser.new.call(source)
end
|
#to_ruby_code(source) ⇒ Object
42
43
44
|
# File 'lib/wlang/compiler.rb', line 42
def to_ruby_code(source)
engine.call(source)
end
|
#to_ruby_proc(source) ⇒ Object
33
34
35
36
37
38
39
40
|
# File 'lib/wlang/compiler.rb', line 33
def to_ruby_proc(source)
source = eval(to_ruby_code(source), TOPLEVEL_BINDING)
if String===source
Proc.new{|d,buf| buf << source}
else
source
end
end
|