lib/infoboxer/parser/context.rb in infoboxer-0.3.2 vs lib/infoboxer/parser/context.rb in infoboxer-0.3.3
- old
+ new
@@ -1,10 +1,10 @@
require 'strscan'
module Infoboxer
class Parser
- class Context
+ class Context # rubocop:disable Metrics/ClassLength
attr_reader :lineno
attr_reader :traits
def initialize(text, traits = nil)
@lines = text
@@ -126,11 +126,17 @@
res
end
# state inspection
def matched_inline?(re)
- re.nil? ? (matched.empty? && eol?) : matched =~ re
+ if re.nil?
+ matched.empty? && eol?
+ elsif re.inspect.start_with?('/^') # was it REALLY at the beginning of the line?..
+ @scanner.pos == matched.length && matched =~ re
+ else
+ matched =~ re
+ end
end
def matched?(re)
re && matched =~ re
end
@@ -140,9 +146,15 @@
end
# basic services
def fail!(text)
fail(ParsingError, "#{text} at line #{@lineno}:\n\t#{current}")
+ end
+
+ def unscan_matched!
+ return unless @matched
+ @scanner.pos -= @matched.size
+ @rest = nil
end
private
# we do hard use of #matched and #rest, its wiser to memoize them