module Infoboxer::Parser::Util

Constants

FORMATTING
INLINE_EOL
INLINE_EOL_BRACK
INLINE_EOL_BRACK2

FIXME: ok, NOW it's officially ridiculous

Attributes

re[R]

Public Instance Methods

guarded_loop() { || ... } click to toggle source
# File lib/infoboxer/parser/util.rb, line 80
def guarded_loop
  loop do
    pos_before = @context.lineno, @context.colno
    yield
    pos_after = @context.lineno, @context.colno
    pos_after == pos_before and
      @context.fail!("Infinite loop on position #{pos_after.last}")
  end
end
make_regexps() click to toggle source
# File lib/infoboxer/parser/util.rb, line 40
def make_regexps
  {
    file_namespace: /(#{@context.traits.file_namespace.join('|')}):/,
    formatting: FORMATTING,
    inline_until_cache: Hash.new { |h, r|
      h[r] = Regexp.union(*[r, FORMATTING, /$/].compact.uniq)
    },
    short_inline_until_cache: Hash.new { |h, r|
      h[r] = Regexp.union(*[r, INLINE_EOL, FORMATTING, /$/].compact.uniq)
    },
    short_inline_until_cache_brackets: Hash.new { |h, r|
      h[r] = Regexp.union(*[r, INLINE_EOL_BRACK, FORMATTING, /$/].compact.uniq)
    },
    short_inline_until_cache_brackets2: Hash.new { |h, r|
      h[r] = Regexp.union(*[r, INLINE_EOL_BRACK2, FORMATTING, /$/].compact.uniq)
    }
  }
end
parse_params(str) click to toggle source
# File lib/infoboxer/parser/util.rb, line 59
def parse_params(str)
  return {} unless str

  scan = StringScanner.new(str)
  params = {}
  loop do
    scan.skip(/\s*/)
    name = scan.scan(/[^ \t=]+/) or break
    scan.skip(/\s*/)
    if scan.peek(1) == '='
      scan.skip(/=\s*/)
      q = scan.scan(/['"]/)
      value = q ? scan.scan_until(/#{q}|$/).sub(q, '') : scan.scan_until(/\s|$/)
      params[name.to_sym] = value
    else
      params[name.to_sym] = name
    end
  end
  params
end