Module: CEML::Instructions
- Includes:
- Lexer, Treetop::Runtime
- Included in:
- InstructionsParser, Scripts
- Defined in:
- lib/ceml/instructions.rb,
lib/ceml/tt/instructions.rb
Defined Under Namespace
Modules: AskStmt0, AskStmt1, AssignStmt0, Instruction0, TellStmt0
Instance Method Summary collapse
- #_nt_ask_stmt ⇒ Object
- #_nt_assign_stmt ⇒ Object
- #_nt_instruction ⇒ Object
- #_nt_instructions ⇒ Object
- #_nt_tell_stmt ⇒ Object
- #asks(roles) ⇒ Object
- #for(roles) ⇒ Object
- #roles ⇒ Object
- #root ⇒ Object
- #tell(roles) ⇒ Object
- #validate!(allowed_roles) ⇒ Object
Methods included from Lexer
#_nt_comment, #_nt_eol, #_nt_id, #_nt_nl, #_nt_number, #_nt_text, #_nt_ws
Instance Method Details
#_nt_ask_stmt ⇒ Object
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 |
# File 'lib/ceml/tt/instructions.rb', line 302 def _nt_ask_stmt start_index = index if node_cache[:ask_stmt].has_key?(index) cached = node_cache[:ask_stmt][index] @index = cached.interval.end if cached return cached end i0, s0 = index, [] if has_terminal?('ask', false, index) r1 = instantiate_node(SyntaxNode,input, index...(index + 3)) @index += 3 else terminal_parse_failure('ask') r1 = nil end s0 << r1 if r1 r2 = _nt_ws s0 << r2 if r2 r3 = _nt_id s0 << r3 if r3 i5, s5 = index, [] r6 = _nt_ws s5 << r6 if r6 if has_terminal?('re', false, index) r7 = instantiate_node(SyntaxNode,input, index...(index + 2)) @index += 2 else terminal_parse_failure('re') r7 = nil end s5 << r7 if r7 r8 = _nt_ws s5 << r8 if r8 r9 = _nt_id s5 << r9 end end end if s5.last r5 = instantiate_node(SyntaxNode,input, i5...index, s5) r5.extend(AskStmt0) else @index = i5 r5 = nil end if r5 r4 = r5 else r4 = instantiate_node(SyntaxNode,input, index...index) end s0 << r4 if r4 if has_terminal?(':', false, index) r10 = instantiate_node(SyntaxNode,input, index...(index + 1)) @index += 1 else terminal_parse_failure(':') r10 = nil end s0 << r10 if r10 r12 = _nt_ws if r12 r11 = r12 else r11 = instantiate_node(SyntaxNode,input, index...index) end s0 << r11 if r11 r13 = _nt_text s0 << r13 if r13 r14 = _nt_nl s0 << r14 end end end end end end end if s0.last r0 = instantiate_node(SyntaxNode,input, i0...index, s0) r0.extend(AskStmt1) else @index = i0 r0 = nil end node_cache[:ask_stmt][start_index] = r0 r0 end |
#_nt_assign_stmt ⇒ Object
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 |
# File 'lib/ceml/tt/instructions.rb', line 201 def _nt_assign_stmt start_index = index if node_cache[:assign_stmt].has_key?(index) cached = node_cache[:assign_stmt][index] @index = cached.interval.end if cached return cached end i0, s0 = index, [] if has_terminal?('assign', false, index) r1 = instantiate_node(SyntaxNode,input, index...(index + 6)) @index += 6 else terminal_parse_failure('assign') r1 = nil end s0 << r1 if r1 r2 = _nt_ws s0 << r2 if r2 r3 = _nt_id s0 << r3 if r3 if has_terminal?(':', false, index) r4 = instantiate_node(SyntaxNode,input, index...(index + 1)) @index += 1 else terminal_parse_failure(':') r4 = nil end s0 << r4 if r4 r6 = _nt_ws if r6 r5 = r6 else r5 = instantiate_node(SyntaxNode,input, index...index) end s0 << r5 if r5 r7 = _nt_text s0 << r7 if r7 r8 = _nt_nl s0 << r8 end end end end end end if s0.last r0 = instantiate_node(SyntaxNode,input, i0...index, s0) r0.extend(AssignStmt0) else @index = i0 r0 = nil end node_cache[:assign_stmt][start_index] = r0 r0 end |
#_nt_instruction ⇒ Object
65 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 |
# File 'lib/ceml/tt/instructions.rb', line 65 def _nt_instruction start_index = index if node_cache[:instruction].has_key?(index) cached = node_cache[:instruction][index] @index = cached.interval.end if cached return cached end i0 = index r1 = _nt_ask_stmt if r1 r0 = r1 r0.extend(Instruction0) else r2 = _nt_tell_stmt if r2 r0 = r2 r0.extend(Instruction0) else r3 = _nt_assign_stmt if r3 r0 = r3 r0.extend(Instruction0) else @index = i0 r0 = nil end end end node_cache[:instruction][start_index] = r0 r0 end |
#_nt_instructions ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/ceml/tt/instructions.rb', line 14 def _nt_instructions start_index = index if node_cache[:instructions].has_key?(index) cached = node_cache[:instructions][index] @index = cached.interval.end if cached return cached end s0, i0 = [], index loop do r1 = _nt_instruction if r1 s0 << r1 else break end end if s0.empty? @index = i0 r0 = nil else r0 = instantiate_node(Instructions,input, i0...index, s0) end node_cache[:instructions][start_index] = r0 r0 end |
#_nt_tell_stmt ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/ceml/tt/instructions.rb', line 118 def _nt_tell_stmt start_index = index if node_cache[:tell_stmt].has_key?(index) cached = node_cache[:tell_stmt][index] @index = cached.interval.end if cached return cached end i0, s0 = index, [] if has_terminal?('tell', false, index) r1 = instantiate_node(SyntaxNode,input, index...(index + 4)) @index += 4 else terminal_parse_failure('tell') r1 = nil end s0 << r1 if r1 r2 = _nt_ws s0 << r2 if r2 r3 = _nt_id s0 << r3 if r3 if has_terminal?(':', false, index) r4 = instantiate_node(SyntaxNode,input, index...(index + 1)) @index += 1 else terminal_parse_failure(':') r4 = nil end s0 << r4 if r4 r6 = _nt_ws if r6 r5 = r6 else r5 = instantiate_node(SyntaxNode,input, index...index) end s0 << r5 if r5 r7 = _nt_text s0 << r7 if r7 r8 = _nt_nl s0 << r8 end end end end end end if s0.last r0 = instantiate_node(SyntaxNode,input, i0...index, s0) r0.extend(TellStmt0) else @index = i0 r0 = nil end node_cache[:tell_stmt][start_index] = r0 r0 end |
#asks(roles) ⇒ Object
19 20 21 22 23 |
# File 'lib/ceml/instructions.rb', line 19 def asks(roles) elements.select do |s| s.text_value =~ /^ask/ && roles.include?(s.role.to_sym) end end |
#for(roles) ⇒ Object
15 16 17 |
# File 'lib/ceml/instructions.rb', line 15 def for(roles) elements.select{ |s| roles.include?(s.role.to_sym) } end |
#roles ⇒ Object
11 12 13 |
# File 'lib/ceml/instructions.rb', line 11 def roles elements.map{ |s| s.role.to_sym }.uniq end |
#root ⇒ Object
8 9 10 |
# File 'lib/ceml/tt/instructions.rb', line 8 def root @root || :instructions end |
#tell(roles) ⇒ Object
25 26 27 28 29 |
# File 'lib/ceml/instructions.rb', line 25 def tell(roles) ss = elements.select{ |s| s.text_value =~ /^tell/ && roles.include?(s.role.to_sym) } raise "multiple assignments for role: #{role}" if ss.size > 1 ss.first end |
#validate!(allowed_roles) ⇒ Object
3 4 5 6 7 8 9 |
# File 'lib/ceml/instructions.rb', line 3 def validate!(allowed_roles) extra_roles = roles - allowed_roles raise "unrecognized rolenames: #{extra_roles.inspect}" unless extra_roles.empty? # max one tell per role roles.each{ |r| tell([r]) } end |