Class: Repper::Token
- Inherits:
-
Struct
- Object
- Struct
- Repper::Token
- Defined in:
- lib/repper/token.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#level ⇒ Object
Returns the value of attribute level.
-
#subtype ⇒ Object
Returns the value of attribute subtype.
-
#text ⇒ Object
Returns the value of attribute text.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #annotation ⇒ Object
- #comment? ⇒ Boolean
- #indented_text ⇒ Object
- #inlined_text ⇒ Object
- #whitespace? ⇒ Boolean
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id
2 3 4 |
# File 'lib/repper/token.rb', line 2 def id @id end |
#level ⇒ Object
Returns the value of attribute level
2 3 4 |
# File 'lib/repper/token.rb', line 2 def level @level end |
#subtype ⇒ Object
Returns the value of attribute subtype
2 3 4 |
# File 'lib/repper/token.rb', line 2 def subtype @subtype end |
#text ⇒ Object
Returns the value of attribute text
2 3 4 |
# File 'lib/repper/token.rb', line 2 def text @text end |
#type ⇒ Object
Returns the value of attribute type
2 3 4 |
# File 'lib/repper/token.rb', line 2 def type @type end |
Instance Method Details
#annotation ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/repper/token.rb', line 25 def annotation case [type, subtype] in [_, :root] nil in [_, :alternation | :comment | :condition | :intersection | :range => subtype] subtype in [:conditional | :free_space => type, _] type in [:group, :capture | :named] "capture group #{id}" in [:meta, :dot] 'match-all' in [:keep, :mark] 'keep-mark lookbehind' in [type, subtype] [subtype, type].uniq.join(' ') end.to_s.tr('_', ' ') end |
#comment? ⇒ Boolean
21 22 23 |
# File 'lib/repper/token.rb', line 21 def comment? subtype == :comment end |
#indented_text ⇒ Object
3 4 5 |
# File 'lib/repper/token.rb', line 3 def indented_text "#{' ' * level}#{inlined_text}" end |
#inlined_text ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'lib/repper/token.rb', line 7 def inlined_text if comment? text.strip else text .gsub(/(?<!\\) /, '\\ ') .gsub(/[\n\r\t\v]/) { |ws| ws.inspect.delete(?") } end end |
#whitespace? ⇒ Boolean
17 18 19 |
# File 'lib/repper/token.rb', line 17 def whitespace? subtype == :whitespace end |