Module: Liquidscript::Compiler::ICR::Directives::InstanceMethods

Extended by:
Forwardable
Defined in:
lib/liquidscript/compiler/icr/directives.rb

Instance Method Summary collapse

Instance Method Details

#define_directive(name, body) ⇒ Object



37
38
39
# File 'lib/liquidscript/compiler/icr/directives.rb', line 37

def define_directive(name, body)
  directives[name] = Base::Callable.new(nil, body, "")
end

#directive_allow(*args) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/liquidscript/compiler/icr/directives.rb', line 41

def directive_allow(*args)
  args.each do |a|
    top.context.set(a.value.intern).hidden!
  end

  nil
end

#directive_cvar(*args) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/liquidscript/compiler/icr/directives.rb', line 49

def directive_cvar(*args)
  args.each do |a|
    top.context.set(a.value.intern, :class => true).hidden!
  end

  nil
end

#directive_include(file) ⇒ Object

Raises:

  • (LoadError)


62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/liquidscript/compiler/icr/directives.rb', line 62

def directive_include(file)
  file_name = file[1]
  path = include_paths.find do |part|
    File.file?(File.join(part, file_name))
  end

  raise LoadError,
    "cannot load such file -- #{file}" unless path

  full_path = File.join(path, file_name)
  f         = File.open(full_path)
  scanner   = Scanner::Liquidscript.new(f.read, full_path)
  compiler  = Compiler::ICR.new(scanner)
  compiler.top.parent = top
  compiler.top.context.delegate!
  compiler.compile
end

#directive_include_path(*paths) ⇒ Object



80
81
82
83
# File 'lib/liquidscript/compiler/icr/directives.rb', line 80

def directive_include_path(*paths)
  include_paths.push(*paths.map(&:value))
  nil
end

#directive_strictObject



85
86
87
88
89
# File 'lib/liquidscript/compiler/icr/directives.rb', line 85

def directive_strict
  top.[:strict] = true

  nil
end

#directive_todo(comment) ⇒ Object



57
58
59
60
# File 'lib/liquidscript/compiler/icr/directives.rb', line 57

def directive_todo(comment)
  $stderr.puts "TODO (file: #{@scanner.file}): #{comment[1]}"
  nil
end

#directivesObject



33
34
35
# File 'lib/liquidscript/compiler/icr/directives.rb', line 33

def directives
  @_directives ||= self.class.directives.dup
end

#handle_directive(directive) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/liquidscript/compiler/icr/directives.rb', line 21

def handle_directive(directive)
  command, args = directive[:command], directive[:arguments]

  callable = directives.fetch(command)

  callable.bind = self
  callable.call(*args)

rescue KeyError
  raise UnknownDirectiveError.new(command)
end