Class: Rsec::Fail

Inherits:
Binary
  • Object
show all
Defined in:
lib/rsec/parsers/misc.rb

Overview

set expect tokens for parsing error in ctx<br/> if left failed, the error would be registered

Instance Attribute Summary

Attributes inherited from Binary

#left, #right

Attributes included from Parser

#name

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Parser

#&, #*, #<<, #>>, #^, #cached, #eof, #fail, #inspect, #join, #map, #maybe, #parse, #parse!, #star, #|

Class Method Details

.[](left, tokens) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/rsec/parsers/misc.rb', line 15

def Fail.[] left, tokens
  # TODO mutex
  if @mask_bit > 1000
    raise "You've created too many fail parsers, If it is your intention, call Rsec::Fail.reset when previous expect settings can be thrown away."
  end
  parser = super(left, (1<<@mask_bit))
  @token_table[@mask_bit] = tokens
  @mask_bit += 1
  parser
end

.get_tokens(mask) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/rsec/parsers/misc.rb', line 32

def Fail.get_tokens mask
  res = []
  @token_table.each_with_index do |tokens, idx|
    next unless tokens
    if (mask & (1<<idx)) > 0
      res += tokens
    end
  end
  res.uniq!
  res
end

.resetObject



26
27
28
29
# File 'lib/rsec/parsers/misc.rb', line 26

def Fail.reset
  @mask_bit = 0
  @token_table = []
end

Instance Method Details

#_parse(ctx) ⇒ Object



44
45
46
47
48
# File 'lib/rsec/parsers/misc.rb', line 44

def _parse ctx
  res = left()._parse ctx
  ctx.on_fail right if INVALID[res]
  res
end