Module: CEML
- Extended by:
- CEML
- Included in:
- CEML
- Defined in:
- lib/ceml.rb,
lib/ceml.rb,
lib/ceml/driver.rb,
lib/ceml/processor.rb,
lib/ceml/recognizer.rb,
lib/ceml/lang/script.rb,
lib/ceml/models/cast.rb,
lib/ceml/models/queue.rb,
lib/ceml/lang/tt/lexer.rb,
lib/ceml/models/bundle.rb,
lib/ceml/models/player.rb,
lib/ceml/lang/tt/casting.rb,
lib/ceml/lang/tt/scripts.rb,
lib/ceml/models/castable.rb,
lib/ceml/models/incident.rb,
lib/ceml/models/casting_pool.rb,
lib/ceml/models/waiting_room.rb,
lib/ceml/lang/tt/instructions.rb,
lib/ceml/models/casting_tokens.rb,
lib/ceml/models/incident_model.rb,
lib/ceml/lang/basic_instruction.rb,
lib/ceml/lang/casting_statement.rb,
lib/ceml/models/incident_role_slot.rb,
lib/ceml/lang/instruction_statements.rb
Defined Under Namespace
Modules: BasicInstruction, Casting, CastingStatement, CastingTokens, InstructionStatements, Instructions, Lexer, Script, Scripts
Classes: Audition, Bundle, Cast, Castable, CastingParser, CastingPool, Circle, Driver, Incident, IncidentModel, IncidentRoleSlot, InstructionsParser, LexerParser, Player, Processor, Queue, Recognizer, RoleSpec, ScriptsParser, Tagspec, WaitingRoom
Constant Summary
collapse
- PLAYER_THREAD_FIELDS =
[ :pc, :continue_at, :synced ]
Instance Attribute Summary collapse
Instance Method Summary
collapse
Instance Attribute Details
#tells ⇒ Object
Returns the value of attribute tells.
13
14
15
|
# File 'lib/ceml.rb', line 13
def tells
@tells
end
|
Instance Method Details
#capture_log ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/ceml.rb', line 21
def capture_log
log = ""
err = nil
prev_io, @log_io = @log_io, StringIO.new(log)
yield
rescue Exception => err
@log_io.puts "\nERROR: #{err}\n\n\n"
ensure
@log_io = prev_io
return err, log
end
|
#clock ⇒ Object
14
|
# File 'lib/ceml.rb', line 14
def clock; Time.now.utc.to_i + @extra_seconds; end
|
#dur(n, unit) ⇒ Object
16
17
18
19
|
# File 'lib/ceml.rb', line 16
def dur(n, unit)
n * case unit
when /^h/; 60*60; when /^mi/; 60; else 1; end
end
|
#incr_clock(s) ⇒ Object
15
|
# File 'lib/ceml.rb', line 15
def incr_clock(s); @extra_seconds += s; end
|
#log(lvl, msg) ⇒ Object
33
34
35
36
37
38
|
# File 'lib/ceml.rb', line 33
def log lvl, msg
if lvl > 1
msg = " #{msg}"
end
@log_io.puts msg
end
|
#parse(what, string) ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/ceml.rb', line 42
def parse(what, string)
string = string.dup
what = case what
when :script then :free_script
when :scripts then :free_scripts
else what
end
result = nil
ScriptsParser.new.tap do |parser|
result = parser.parse(string, :root => what)
raise "parse failed: \n#{parser.failure_reason}" unless result
case what
when :free_scripts
raise "no scripts found" unless result.scripts.list
result = result.scripts.list
result.each{ |s| s.validate! }
when :free_script
result = result.script
result.validate!
end
end
result
end
|
#test(test, p = CEML::Processor) ⇒ Object
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/ceml.rb', line 66
def test test, p = CEML::Processor
scripts, test = test.split("\n---\n")
s = CEML.parse(:scripts, scripts).map(&:castable)
bundle_id = gen_code @tells = Hash.new{ |h,k| h[k] = [] }
p.set_bundle(bundle_id, s)
p.reset_bundle(bundle_id)
pl = Set.new
CEML.capture_log do
test.each_line do |line|
line = line.strip
next if line =~ /^#/ or line =~ /^\s*$/
CEML.log 1, "#{line}"
case line
when /^(\w+) *< *(.*)$/
player_id, msg = $1, $2
heard = tells[player_id].shift
next if msg.empty? and !heard
raise "Expected silence from #{player_id}, got #{heard}" if msg.empty? and heard
raise "Expected #{player_id} < #{msg}, got silence" if !msg.empty? and !heard
heard = (heard||={})[:msg] || (heard||={})[:q] || ''
raise "Expected #{player_id} < #{msg}, got #{heard}" unless heard =~ /#{msg}/
next
when /^(\w+) *> *(.*)$/
player_id, msg = $1, $2
player = {:id => player_id, :received => msg }
if !pl.include?(player_id)
player[:tags] = ['new']
p.reset_player(bundle_id, player_id)
pl << player_id
end
player[:recognized] = CEML::Recognizer.recognize(msg)
p.ping(bundle_id, player)
when /^\((\d+)\s*(\w+)\)$/
CEML.incr_clock CEML.dur($1.to_i, $2)
p.run_latest
end
p.run
end
end
end
|