Class: L43Peg::Tokens
- Inherits:
-
Object
- Object
- L43Peg::Tokens
- Extended by:
- L43::OpenObject
- Defined in:
- lib/l43_peg/tokens.rb
Instance Method Summary collapse
- #debug ⇒ Object
- #drop(by = nil) ⇒ Object
- #empty? ⇒ Boolean
- #head ⇒ Object
- #head_hr(n, position: false) ⇒ Object
- #input ⇒ Object
- #match(str_or_rgx, option) ⇒ Object
- #position ⇒ Object
- #position_hr ⇒ Object
Instance Method Details
#debug ⇒ Object
15 16 17 18 19 |
# File 'lib/l43_peg/tokens.rb', line 15 def debug "Tokens<" + ["tnb:#{tnb}", "tokens:#{tokens.inspect}", "context:#{context.inspect}"].join + ">" end |
#drop(by = nil) ⇒ Object
9 10 11 12 13 |
# File 'lib/l43_peg/tokens.rb', line 9 def drop(by=nil) by = by || 1 return self if empty? self.class.new(tokens: input.drop(by), context:, tnb: tnb + by) end |
#empty? ⇒ Boolean
21 |
# File 'lib/l43_peg/tokens.rb', line 21 def empty? = tokens.empty? |
#head ⇒ Object
22 |
# File 'lib/l43_peg/tokens.rb', line 22 def head = tokens.first |
#head_hr(n, position: false) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/l43_peg/tokens.rb', line 23 def head_hr(n, position: false) if position "Tokens<[#{tokens[0..n].map(&:inspect).join(", ")}]@#{position_hr}>" else "Tokens<[#{tokens[0..n].map(&:inspect).join(", ")}]>" end end |
#input ⇒ Object
31 |
# File 'lib/l43_peg/tokens.rb', line 31 def input = tokens |
#match(str_or_rgx, option) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/l43_peg/tokens.rb', line 33 def match(str_or_rgx, option) return if empty? case str_or_rgx when String head == str_or_rgx && head when Regexp _match_rgx(str_or_rgx, option || 0) end end |
#position ⇒ Object
44 |
# File 'lib/l43_peg/tokens.rb', line 44 def position = tnb |
#position_hr ⇒ Object
45 |
# File 'lib/l43_peg/tokens.rb', line 45 def position_hr = tnb.to_s |