Module: CEML::BasicInstruction

Defined in:
lib/ceml/lang/basic_instruction.rb

Instance Method Summary collapse

Instance Method Details

#bytecodeObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ceml/lang/basic_instruction.rb', line 31

def bytecode
    code = []
    code.concat case cmd
    when :record;  [[roles, :answered_q,      {:key  => key}]]
    when :set;     [[roles, :set,             {:key  => key, :value => text_block}]]
    when :pick;    [[roles, :pick,            {:key  => key, :value => text_block}]]
    when :ask;     [[roles, :ask_q,           {:text => text_block, :q => key}],
                    [roles, :answered_q,      {:key  => key}]]
    when :tell;    [[roles, :send_msg,        {:text => text_block}]]
    when :assign;  [[roles, :assign,          {:text => text_block}],
                    [roles, :complete_assign, {:text => text_block}]]
    when :release; [[roles, :release,         {:cond => cond}]]
    when :sync;    [[roles, :sync,            {:role => role}]]
    end
    code
end

#cmdObject



26
# File 'lib/ceml/lang/basic_instruction.rb', line 26

def cmd;  text_value.split.first.to_sym; end

#condObject



27
28
29
# File 'lib/ceml/lang/basic_instruction.rb', line 27

def cond
    (!respond_to?(:condition) || condition.empty?) ? nil : condition.value
end

#keyObject



25
# File 'lib/ceml/lang/basic_instruction.rb', line 25

def key;   var || text_block; end

#roleObject

TODO: bug right here def role; id.respond_to?(:text_value) && id.text_value.to_sym || :none; end



6
7
8
9
10
11
12
# File 'lib/ceml/lang/basic_instruction.rb', line 6

def role;
  if id.respond_to?(:text_value)
    id.text_value.to_sym
  else
    raise "holy fuck"
  end
end

#rolesObject



14
15
16
# File 'lib/ceml/lang/basic_instruction.rb', line 14

def roles
  [role]
end

#text_blockObject



18
19
20
# File 'lib/ceml/lang/basic_instruction.rb', line 18

def text_block
  defined?(:text) && text.text_value
end

#varObject



21
22
23
24
# File 'lib/ceml/lang/basic_instruction.rb', line 21

def var
    return varname.text_value if cmd == :record or cmd == :set or cmd == :release
    (!respond_to?(:about) || about.empty?) ? nil : about.varname.text_value;
end