Class: Riml::Compiler

Inherits:
Object
  • Object
show all
Defined in:
lib/riml/compiler.rb

Defined Under Namespace

Modules: CompilerAccessible Classes: AssignNodeVisitor, BinaryOperatorNodeVisitor, CallNodeVisitor, CatchNodeVisitor, ClassDefinitionNodeVisitor, DefNodeVisitor, DictGetBracketNodeVisitor, DictGetDotNodeVisitor, DrillDownVisitor, ElseNodeVisitor, ElseifNodeVisitor, EstablishScopeVisitor, ExplicitCallNodeVisitor, ForNodeVisitor, GetCurlyBraceNameNodeVisitor, GetSpecialVariableNodeVisitor, GetVariableByScopeAndDictNameNodeVisitor, GetVariableNodeVisitor, IfNodeVisitor, ListOrDictGetNodeVisitor, ListUnpackNodeVisitor, LiteralNodeVisitor, MultiAssignNodeVisitor, NodesVisitor, ReturnNodeVisitor, RimlFileCommandNodeVisitor, ScopedVisitor, StringLiteralConcatNodeVisitor, TernaryOperatorNodeVisitor, TryNodeVisitor, UnaryOperatorNodeVisitor, UnletVariableNodeVisitor, Visitor, WhileNodeVisitor, WrapInParensNodeVisitor

Constant Summary collapse

UnlessNodeVisitor =
IfNodeVisitor
UntilNodeVisitor =
WhileNodeVisitor
SublistNodeVisitor =
NodesVisitor
TrueNodeVisitor =
LiteralNodeVisitor
FalseNodeVisitor =
LiteralNodeVisitor
NumberNodeVisitor =
LiteralNodeVisitor
StringNodeVisitor =
LiteralNodeVisitor
RegexpNodeVisitor =
LiteralNodeVisitor
ExLiteralNodeVisitor =
LiteralNodeVisitor
ListNodeVisitor =
LiteralNodeVisitor
DictionaryNodeVisitor =
LiteralNodeVisitor
ScopeModifierLiteralNodeVisitor =
LiteralNodeVisitor
FinishNodeVisitor =
LiteralNodeVisitor
ContinueNodeVisitor =
LiteralNodeVisitor
BreakNodeVisitor =
LiteralNodeVisitor

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#optionsObject

compiler options



12
13
14
# File 'lib/riml/compiler.rb', line 12

def options
  @options ||= {}
end

#parserObject

Returns the value of attribute parser.



7
8
9
# File 'lib/riml/compiler.rb', line 7

def parser
  @parser
end

Instance Method Details

#compile(root_node) ⇒ Object

compiles nodes into output code



791
792
793
794
795
796
# File 'lib/riml/compiler.rb', line 791

def compile(root_node)
  root_node.extend CompilerAccessible
  root_node.current_compiler = self
  root_node.accept(NodesVisitor.new)
  root_node.compiled_output
end

#compile_include(file_basepath, file_fullpath) ⇒ Object



779
780
781
782
783
784
785
786
787
788
# File 'lib/riml/compiler.rb', line 779

def compile_include(file_basepath, file_fullpath)
  return if included_files_compiled.include?(file_basepath)
  Riml.include_cache.fetch(file_basepath) do
    source = File.read(file_fullpath)
    root_node = parser.parse(source, parser.ast_rewriter, file_basepath, true)
    included_files_compiled << file_basepath
    output = compile(root_node)
    (Riml::INCLUDE_COMMENT_FMT % file_basepath) + output
  end
end

#compile_queueObject



767
768
769
# File 'lib/riml/compiler.rb', line 767

def compile_queue
  @compile_queue ||= []
end

#included_files_compiledObject



775
776
777
# File 'lib/riml/compiler.rb', line 775

def included_files_compiled
  @included_files_compiled ||= []
end

#output_dirObject



16
17
18
# File 'lib/riml/compiler.rb', line 16

def output_dir
  options[:output_dir]
end

#readableObject



20
21
22
# File 'lib/riml/compiler.rb', line 20

def readable
  options.has_key?(:readable) and options[:readable]
end

#sourced_files_compiledObject



771
772
773
# File 'lib/riml/compiler.rb', line 771

def sourced_files_compiled
  @sourced_files_compiled ||= []
end