Class: Coradoc::Markdown::Parser::ParsletExtras::Lookbehind
- Inherits:
-
Parslet::Atoms::Base
- Object
- Parslet::Atoms::Base
- Coradoc::Markdown::Parser::ParsletExtras::Lookbehind
- Defined in:
- lib/coradoc/markdown/parser/parslet_extras.rb
Instance Attribute Summary collapse
-
#bound_parslet ⇒ Object
readonly
Returns the value of attribute bound_parslet.
-
#number ⇒ Object
readonly
Returns the value of attribute number.
-
#positive ⇒ Object
readonly
Returns the value of attribute positive.
Instance Method Summary collapse
- #error_msgs ⇒ Object
-
#initialize(bound_parslet, number, positive: true) ⇒ Lookbehind
constructor
A new instance of Lookbehind.
- #to_s_inner(prec) ⇒ Object
- #try(source, context, consume_all) ⇒ Object
Constructor Details
#initialize(bound_parslet, number, positive: true) ⇒ Lookbehind
Returns a new instance of Lookbehind.
115 116 117 118 119 120 121 122 |
# File 'lib/coradoc/markdown/parser/parslet_extras.rb', line 115 def initialize(bound_parslet, number, positive: true) super() # Model positive and negative lookbehind by testing this flag. @positive = positive @number = number @bound_parslet = bound_parslet end |
Instance Attribute Details
#bound_parslet ⇒ Object (readonly)
Returns the value of attribute bound_parslet.
113 114 115 |
# File 'lib/coradoc/markdown/parser/parslet_extras.rb', line 113 def bound_parslet @bound_parslet end |
#number ⇒ Object (readonly)
Returns the value of attribute number.
113 114 115 |
# File 'lib/coradoc/markdown/parser/parslet_extras.rb', line 113 def number @number end |
#positive ⇒ Object (readonly)
Returns the value of attribute positive.
112 113 114 |
# File 'lib/coradoc/markdown/parser/parslet_extras.rb', line 112 def positive @positive end |
Instance Method Details
#error_msgs ⇒ Object
124 125 126 127 128 129 |
# File 'lib/coradoc/markdown/parser/parslet_extras.rb', line 124 def error_msgs @error_msgs ||= { positive: ['Input should be preceded by ', bound_parslet], negative: ['Input should not be preceded by ', bound_parslet] } end |
#to_s_inner(prec) ⇒ Object
156 157 158 159 |
# File 'lib/coradoc/markdown/parser/parslet_extras.rb', line 156 def to_s_inner(prec) @char = positive ? '&' : '!' "<#{@char}<#{number}<#{bound_parslet.to_s(prec)}" end |
#try(source, context, consume_all) ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/coradoc/markdown/parser/parslet_extras.rb', line 131 def try(source, context, consume_all) rewind_pos = source.bytepos if source.bytepos.zero? return succ(nil) unless positive return context.err_at(self, source, error_msgs[:positive], source.pos) end source.rewind(number) error_pos = source.pos success, = bound_parslet.apply(source, context, consume_all) if positive return succ(nil) if success context.err_at(self, source, error_msgs[:positive], error_pos) else return succ(nil) unless success context.err_at(self, source, error_msgs[:negative], error_pos) end ensure source.bytepos = rewind_pos end |