Module: Infoboxer::Parser::Util
- Included in:
- Infoboxer::Parser
- Defined in:
- lib/infoboxer/parser/util.rb
Constant Summary collapse
- FORMATTING =
/( '{2,5} | # bold, italic \[\[ | # link {{ | # template \[[a-z]+:\/\/ | # external link <nowiki[^>]*> | # reference <ref[^>]*> | # nowiki < # HTML tag )/x
- INLINE_EOL =
%r[(?= # if we have ahead... (not scanned, just checked </ref> | # <ref> closed }} # or template closed )]x
Instance Attribute Summary collapse
-
#re ⇒ Object
readonly
Returns the value of attribute re.
Instance Method Summary collapse
Instance Attribute Details
#re ⇒ Object (readonly)
Returns the value of attribute re.
5 6 7 |
# File 'lib/infoboxer/parser/util.rb', line 5 def re @re end |
Instance Method Details
#guarded_loop ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'lib/infoboxer/parser/util.rb', line 61 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 ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/infoboxer/parser/util.rb', line 23 def make_regexps { file_prefix: /(#{@context.traits.file_prefix.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) } } end |
#parse_params(str) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/infoboxer/parser/util.rb', line 36 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(/['"]/) if q value = scan.scan_until(/#{q}/).sub(q, '') else value = scan.scan_until(/\s|$/) end params[name.to_sym] = value else params[name.to_sym] = name end end params end |