PageSourceSearch

https://lzone.de/js/vendor/asciidoctor.min.js

js lzone.de collected 2026-10-02 04:23:24 UTC 1,737,178 bytes, 47,654 lines download raw bytes

1/**
2 * @license Asciidoctor.js 3.0.3 | MIT | https://github.com/asciidoctor/asciidoctor.js
3 */
4(function(global_object) {
5  "use strict";
6
7  // @note
8  //   A few conventions for the documentation of this file:
9  //   1. Always use "//" (in contrast with "/**/")
10  //   2. The syntax used is Yardoc (yardoc.org), which is intended for Ruby (se below)
11  //   3. `@param` and `@return` types should be preceded by `JS.` when referring to
12  //      JavaScript constructors (e.g. `JS.Function`) otherwise Ruby is assumed.
13  //   4. `nil` and `null` being unambiguous refer to the respective
14  //      objects/values in Ruby and JavaScript
15  //   5. This is still WIP :) so please give feedback and suggestions on how
16  //      to improve or for alternative solutions
17  //
18  //   The way the code is digested before going through Yardoc is a secret kept
19  //   in the docs repo (https://github.com/opal/docs/tree/master).
20
21  var console;
22
23  // Detect the global object
24  if (typeof(globalThis) !== 'undefined') { global_object = globalThis; }
25  else if (typeof(global) !== 'undefined') { global_object = global; }
26  else if (typeof(window) !== 'undefined') { global_object = window; }
27
28  // Setup a dummy console object if missing
29  if (global_object.console == null) {
30    global_object.console = {};
31  }
32
33  if (typeof(global_object.console) === 'object') {
34    console = global_object.console;
35  } else {
36    console = {};
37  }
38
39  if (!('log' in console)) { console.log = function () {}; }
40  if (!('warn' in console)) { console.warn = console.log; }
41
42  if (typeof(global_object.Opal) !== 'undefined') {
43    console.warn('Opal already loaded. Loading twice can cause troubles, please fix your setup.');
44    return global_object.Opal;
45  }
46
47  var nil;
48
49  // The actual class for BasicObject
50  var BasicObject;
51
52  // The actual Object class.
53  // The leading underscore is to avoid confusion with window.Object()
54  var _Object;
55
56  // The actual Module class
57  var Module;
58
59  // The actual Class class
60  var Class;
61
62  // The Opal.Opal class (helpers etc.)
63  var _Opal;
64
65  // The Kernel module
66  var Kernel;
67
68  // The Opal object that is exposed globally
69  var Opal = global_object.Opal = {};
70
71  // This is a useful reference to global object inside ruby files
72  Opal.global = global_object;
73
74  // Configure runtime behavior with regards to require and unsupported features
75  Opal.config = {
76    missing_require_severity: 'error',        // error, warning, ignore
77    unsupported_features_severity: 'warning', // error, warning, ignore
78    experimental_features_severity: 'warning',// warning, ignore
79    enable_stack_trace: true                  // true, false
80  };
81
82  // Minify common function calls
83  var $call      = Function.prototype.call;
84  var $bind      = Function.prototype.bind;
85  var $has_own   = Object.hasOwn || $call.bind(Object.prototype.hasOwnProperty);
86  var $set_proto = Object.setPrototypeOf;
87  var $slice     = $call.bind(Array.prototype.slice);
88  var $splice    = $call.bind(Array.prototype.splice);
89
90  // Nil object id is always 4
91  var nil_id = 4;
92
93  // Generates even sequential numbers greater than 4
94  // (nil_id) to serve as unique ids for ruby objects
95  var unique_id = nil_id;
96
97  // Return next unique id
98  function $uid() {
99    unique_id += 2;
100    return unique_id;
101  };
102  Opal.uid = $uid;
103
104  // Retrieve or assign the id of an object
105  Opal.id = function(obj) {
106    if (obj.$$is_number) return (obj * 2)+1;
107    if (obj.$$id == null) {
108      $prop(obj, '$$id', $uid());
109    }
110    return obj.$$id;
111  };
112
113  // Globals table
114  var $gvars = Opal.gvars = {};
115
116  // Exit function, this should be replaced by platform specific implementation
117  // (See nodejs and chrome for examples)
118  Opal.exit = function(status) { if ($gvars.DEBUG) console.log('Exited with status '+status); };
119
120  // keeps track of exceptions for $!
121  Opal.exceptions = [];
122
123  // @private
124  // Pops an exception from the stack and updates `$!`.
125  Opal.pop_exception = function() {
126    var exception = Opal.exceptions.pop();
127    if (exception) {
128      $gvars["!"] = exception;
129      $gvars["@"] = exception.$backtrace();
130    }
131    else {
132      $gvars["!"] = $gvars["@"] = nil;
133    }
134  };
135
136  // A helper function for raising things, that gracefully degrades if necessary
137  // functionality is not yet loaded.
138  function $raise(klass, message) {
139    // Raise Exception, so we can know that something wrong is going on.
140    if (!klass) klass = Opal.Exception || Error;
141
142    if (Kernel && Kernel.$raise) {
143      if (arguments.length > 2) {
144        Kernel.$raise(klass.$new.apply(klass, $slice(arguments, 1)));
145      }
146      else {
147        Kernel.$raise(klass, message);
148      }
149    }
150    else if (!klass.$new) {
151      throw new klass(message);
152    }
153    else {
154      throw klass.$new(message);
155    }
156  }
157
158  function $prop(object, name, initialValue) {
159    if (typeof(object) === "string") {
160      // Special case for:
161      //   s = "string"
162      //   def s.m; end
163      // String class is the only class that:
164      // + compiles to JS primitive
165      // + allows method definition directly on instances
166      // numbers, true, false and null do not support it.
167      object[name] = initialValue;
168    } else {
169      Object.defineProperty(object, name, {
170        value: initialValue,
171        enumerable: false,
172        configurable: true,
173        writable: true
174      });
175    }
176  }
177
178  Opal.prop = $prop;
179
180  // @deprecated
181  Opal.defineProperty = Opal.prop;
182
183  Opal.slice = $slice;
184
185  // Helpers
186  // -----
187
188  var $truthy = Opal.truthy = function(val) {
189    return false !== val && nil !== val && undefined !== val && null !== val && (!(val instanceof Boolean) || true === val.valueOf());
190  };
191
192  Opal.falsy = function(val) {
193    return !$truthy(val);
194  };
195
196  Opal.type_error = function(object, type, method, coerced) {
197    object = object.$$class;
198
199    if (coerced && method) {
200      coerced = coerced.$$class;
201      $raise(Opal.TypeError,
202        "can't convert " + object + " into " + type +
203        " (" + object + "#" + method + " gives " + coerced + ")"
204      )
205    } else {
206      $raise(Opal.TypeError,
207        "no implicit conversion of " + object + " into " + type
208      )
209    }
210  };
211
212  Opal.coerce_to = function(object, type, method, args) {
213    var body;
214
215    if (method === 'to_int' && type === Opal.Integer && object.$$is_number)
216      return object < 0 ? Math.ceil(object) : Math.floor(object);
217
218    if (method === 'to_str' && type === Opal.String && object.$$is_string)
219      return object;
220
221    if (Opal.is_a(object, type)) return object;
222
223    // Fast path for the most common situation
224    if (object['$respond_to?'].$$pristine && object.$method_missing.$$pristine) {
225      body = object[$jsid(method)];
226      if (body == null || body.$$stub) Opal.type_error(object, type);
227      return body.apply(object, args);
228    }
229
230    if (!object['$respond_to?'](method)) {
231      Opal.type_error(object, type);
232    }
233
234    if (args == null) args = [];
235    return Opal.send(object, method, args);
236  }
237
238  Opal.respond_to = function(obj, jsid, include_all) {
239    if (obj == null || !obj.$$class) return false;
240    include_all = !!include_all;
241    var body = obj[jsid];
242
243    if (obj['$respond_to?'].$$pristine) {
244      if (typeof(body) === "function" && !body.$$stub) {
245        return true;
246      }
247      if (!obj['$respond_to_missing?'].$$pristine) {
248        return Opal.send(obj, obj['$respond_to_missing?'], [jsid.substr(1), include_all]);
249      }
250    } else {
251      return Opal.send(obj, obj['$respond_to?'], [jsid.substr(1), include_all]);
252    }
253  }
254
255  // TracePoint support
256  // ------------------
257  //
258  // Support for `TracePoint.trace(:class) do ... end`
259  Opal.trace_class = false;
260  Opal.tracers_for_class = [];
261
262  function invoke_tracers_for_class(klass_or_module) {
263    var i, ii, tracer;
264
265    for(i = 0, ii = Opal.tracers_for_class.length; i < ii; i++) {
266      tracer = Opal.tracers_for_class[i];
267      tracer.trace_object = klass_or_module;
268      tracer.block.$call(tracer);
269    }
270  }
271
272  function handle_autoload(cref, name) {
273    if (!cref.$$autoload[name].loaded) {
274      cref.$$autoload[name].loaded = true;
275      try {
276        Opal.Kernel.$require(cref.$$autoload[name].path);
277      } catch (e) {
278        cref.$$autoload[name].exception = e;
279        throw e;
280      }
281      cref.$$autoload[name].required = true;
282      if (cref.$$const[name] != null) {
283        cref.$$autoload[name].success = true;
284        return cref.$$const[name];
285      }
286    } else if (cref.$$autoload[name].loaded && !cref.$$autoload[name].required) {
287      if (cref.$$autoload[name].exception) { throw cref.$$autoload[name].exception; }
288    }
289  }
290
291  // Constants
292  // ---------
293  //
294  // For future reference:
295  // - The Rails autoloading guide (http://guides.rubyonrails.org/v5.0/autoloading_and_reloading_constants.html)
296  // - @ConradIrwin's 2012 post on “Everything you ever wanted to know about constant lookup in Ruby” (http://cirw.in/blog/constant-lookup.html)
297  //
298  // Legend of MRI concepts/names:
299  // - constant reference (cref): the module/class that acts as a namespace
300  // - nesting: the namespaces wrapping the current scope, e.g. nesting inside
301  //            `module A; module B::C; end; end` is `[B::C, A]`
302
303  // Get the constant in the scope of the current cref
304  function const_get_name(cref, name) {
305    if (cref) {
306      if (cref.$$const[name] != null) { return cref.$$const[name]; }
307      if (cref.$$autoload && cref.$$autoload[name]) {
308        return handle_autoload(cref, name);
309      }
310    }
311  }
312
313  // Walk up the nesting array looking for the constant
314  function const_lookup_nesting(nesting, name) {
315    var i, ii, constant;
316
317    if (nesting.length === 0) return;
318
319    // If the nesting is not empty the constant is looked up in its elements
320    // and in order. The ancestors of those elements are ignored.
321    for (i = 0, ii = nesting.length; i < ii; i++) {
322      constant = nesting[i].$$const[name];
323      if (constant != null) {
324        return constant;
325      } else if (nesting[i].$$autoload && nesting[i].$$autoload[name]) {
326        return handle_autoload(nesting[i], name);
327      }
328    }
329  }
330
331  // Walk up the ancestors chain looking for the constant
332  function const_lookup_ancestors(cref, name) {
333    var i, ii, ancestors;
334
335    if (cref == null) return;
336
337    ancestors = $ancestors(cref);
338
339    for (i = 0, ii = ancestors.length; i < ii; i++) {
340      if (ancestors[i].$$const && $has_own(ancestors[i].$$const, name)) {
341        return ancestors[i].$$const[name];
342      } else if (ancestors[i].$$autoload && ancestors[i].$$autoload[name]) {
343        return handle_autoload(ancestors[i], name);
344      }
345    }
346  }
347
348  // Walk up Object's ancestors chain looking for the constant,
349  // but only if cref is missing or a module.
350  function const_lookup_Object(cref, name) {
351    if (cref == null || cref.$$is_module) {
352      return const_lookup_ancestors(_Object, name);
353    }
354  }
355
356  // Call const_missing if nothing else worked
357  function const_missing(cref, name) {
358    return (cref || _Object).$const_missing(name);
359  }
360
361  // Look for the constant just in the current cref or call `#const_missing`
362  Opal.const_get_local = function(cref, name, skip_missing) {
363    var result;
364
365    if (cref == null) return;
366
367    if (cref === '::') cref = _Object;
368
369    if (!cref.$$is_module && !cref.$$is_class) {
370      $raise(Opal.TypeError, cref.toString() + " is not a class/module");
371    }
372
373    result = const_get_name(cref, name);
374    return result != null || skip_missing ? result : const_missing(cref, name);
375  };
376
377  // Look for the constant relative to a cref or call `#const_missing` (when the
378  // constant is prefixed by `::`).
379  Opal.const_get_qualified = function(cref, name, skip_missing) {
380    var result, cache, cached, current_version = Opal.const_cache_version;
381
382    if (name == null) {
383      // A shortpath for calls like ::String => $$$("String")
384      result = const_get_name(_Object, cref);
385
386      if (result != null) return result;
387      return Opal.const_get_qualified(_Object, cref, skip_missing);
388    }
389
390    if (cref == null) return;
391
392    if (cref === '::') cref = _Object;
393
394    if (!cref.$$is_module && !cref.$$is_class) {
395      $raise(Opal.TypeError, cref.toString() + " is not a class/module");
396    }
397
398    if ((cache = cref.$$const_cache) == null) {
399      $prop(cref, '$$const_cache', Object.create(null));
400      cache = cref.$$const_cache;
401    }
402    cached = cache[name];
403
404    if (cached == null || cached[0] !== current_version) {
405      ((result = const_get_name(cref, name))              != null) ||
406      ((result = const_lookup_ancestors(cref, name))      != null);
407      cache[name] = [current_version, result];
408    } else {
409      result = cached[1];
410    }
411
412    return result != null || skip_missing ? result : const_missing(cref, name);
413  };
414
415  // Initialize the top level constant cache generation counter
416  Opal.const_cache_version = 1;
417
418  // Look for the constant in the open using the current nesting and the nearest
419  // cref ancestors or call `#const_missing` (when the constant has no :: prefix).
420  Opal.const_get_relative = function(nesting, name, skip_missing) {
421    var cref = nesting[0], result, current_version = Opal.const_cache_version, cache, cached;
422
423    if ((cache = nesting.$$const_cache) == null) {
424      $prop(nesting, '$$const_cache', Object.create(null));
425      cache = nesting.$$const_cache;
426    }
427    cached = cache[name];
428
429    if (cached == null || cached[0] !== current_version) {
430      ((result = const_get_name(cref, name))              != null) ||
431      ((result = const_lookup_nesting(nesting, name))     != null) ||
432      ((result = const_lookup_ancestors(cref, name))      != null) ||
433      ((result = const_lookup_Object(cref, name))         != null);
434
435      cache[name] = [current_version, result];
436    } else {
437      result = cached[1];
438    }
439
440    return result != null || skip_missing ? result : const_missing(cref, name);
441  };
442
443  // Register the constant on a cref and opportunistically set the name of
444  // unnamed classes/modules.
445  function $const_set(cref, name, value) {
446    var new_const = true;
447
448    if (cref == null || cref === '::') cref = _Object;
449
450    if (value.$$is_a_module) {
451      if (value.$$name == null || value.$$name === nil) value.$$name = name;
452      if (value.$$base_module == null) value.$$base_module = cref;
453    }
454
455    cref.$$const = (cref.$$const || Object.create(null));
456
457    if (name in cref.$$const || ("$$autoload" in cref && name in cref.$$autoload)) {
458      new_const = false;
459    }
460
461    cref.$$const[name] = value;
462
463    // Add a short helper to navigate constants manually.
464    // @example
465    //   Opal.$$.Regexp.$$.IGNORECASE
466    cref.$$ = cref.$$const;
467
468    Opal.const_cache_version++;
469
470    // Expose top level constants onto the Opal object
471    if (cref === _Object) Opal[name] = value;
472
473    // Name new class directly onto current scope (Opal.Foo.Baz = klass)
474    $prop(cref, name, value);
475
476    if (new_const && cref.$const_added && !cref.$const_added.$$pristine) {
477      cref.$const_added(name);
478    }
479
480    return value;
481  };
482
483  Opal.const_set = $const_set;
484
485  // Get all the constants reachable from a given cref, by default will include
486  // inherited constants.
487  Opal.constants = function(cref, inherit) {
488    if (inherit == null) inherit = true;
489
490    var module, modules = [cref], i, ii, constants = {}, constant;
491
492    if (inherit) modules = modules.concat($ancestors(cref));
493    if (inherit && cref.$$is_module) modules = modules.concat([Opal.Object]).concat($ancestors(Opal.Object));
494
495    for (i = 0, ii = modules.length; i < ii; i++) {
496      module = modules[i];
497
498      // Do not show Objects constants unless we're querying Object itself
499      if (cref !== _Object && module == _Object) break;
500
501      for (constant in module.$$const) {
502        constants[constant] = true;
503      }
504      if (module.$$autoload) {
505        for (constant in module.$$autoload) {
506          constants[constant] = true;
507        }
508      }
509    }
510
511    return Object.keys(constants);
512  };
513
514  // Remove a constant from a cref.
515  Opal.const_remove = function(cref, name) {
516    Opal.const_cache_version++;
517
518    if (cref.$$const[name] != null) {
519      var old = cref.$$const[name];
520      delete cref.$$const[name];
521      return old;
522    }
523
524    if (cref.$$autoload && cref.$$autoload[name]) {
525      delete cref.$$autoload[name];
526      return nil;
527    }
528
529    $raise(Opal.NameError, "constant "+cref+"::"+cref.$name()+" not defined");
530  };
531
532  // Generates a function that is a curried const_get_relative.
533  Opal.const_get_relative_factory = function(nesting) {
534    return function(name, skip_missing) {
535      return Opal.$$(nesting, name, skip_missing);
536    }
537  }
538
539  // Setup some shortcuts to reduce compiled size
540  Opal.$$ = Opal.const_get_relative;
541  Opal.$$$ = Opal.const_get_qualified;
542  Opal.$r = Opal.const_get_relative_factory;
543
544  // Modules & Classes
545  // -----------------
546
547  // A `class Foo; end` expression in ruby is compiled to call this runtime
548  // method which either returns an existing class of the given name, or creates
549  // a new class in the given `base` scope.
550  //
551  // If a constant with the given name exists, then we check to make sure that
552  // it is a class and also that the superclasses match. If either of these
553  // fail, then we raise a `TypeError`. Note, `superclass` may be null if one
554  // was not specified in the ruby code.
555  //
556  // We pass a constructor to this method of the form `function ClassName() {}`
557  // simply so that classes show up with nicely formatted names inside debuggers
558  // in the web browser (or node/sprockets).
559  //
560  // The `scope` is the current `self` value where the class is being created
561  // from. We use this to get the scope for where the class should be created.
562  // If `scope` is an object (not a class/module), we simple get its class and
563  // use that as the scope instead.
564  //
565  // @param scope        [Object] where the class is being created
566  // @param superclass   [Class,null] superclass of the new class (may be null)
567  // @param singleton    [Boolean,null] a true value denotes we want to allocate
568  //                                    a singleton
569  //
570  // @return new [Class]  or existing ruby class
571  //
572  function $allocate_class(name, superclass, singleton) {
573    var klass;
574
575    if (superclass != null && superclass.$$bridge) {
576      // Inheritance from bridged classes requires
577      // calling original JS constructors
578      klass = function() {
579        var args = $slice(arguments),
580            self = new ($bind.apply(superclass.$$constructor, [null].concat(args)))();
581
582        // and replacing a __proto__ manually
583        $set_proto(self, klass.$$prototype);
584        return self;
585      }
586    } else {
587      klass = function(){};
588    }
589
590    if (name && name !== nil) {
591      $prop(klass, 'displayName', '::'+name);
592    }
593
594    $prop(klass, '$$name', name);
595    $prop(klass, '$$constructor', klass);
596    $prop(klass, '$$prototype', klass.prototype);
597    $prop(klass, '$$const', {});
598    $prop(klass, '$$is_class', true);
599    $prop(klass, '$$is_a_module', true);
600    $prop(klass, '$$super', superclass);
601    $prop(klass, '$$cvars', {});
602    $prop(klass, '$$own_included_modules', []);
603    $prop(klass, '$$own_prepended_modules', []);
604    $prop(klass, '$$ancestors', []);
605    $prop(klass, '$$ancestors_cache_version', null);
606    $prop(klass, '$$subclasses', []);
607
608    $prop(klass.$$prototype, '$$class', klass);
609
610    // By default if there are no singleton class methods
611    // __proto__ is Class.prototype
612    // Later singleton methods generate a singleton_class
613    // and inject it into ancestors chain
614    if (Opal.Class) {
615      $set_proto(klass, Opal.Class.prototype);
616    }
617
618    if (superclass != null) {
619      $set_proto(klass.$$prototype, superclass.$$prototype);
620
621      if (singleton !== true) {
622        // Let's not forbid GC from cleaning up our
623        // subclasses.
624        if (typeof WeakRef !== 'undefined') {
625          // First, let's clean up our array from empty objects.
626          var i, subclass, rebuilt_subclasses = [];
627          for (i = 0; i < superclass.$$subclasses.length; i++) {
628            subclass = superclass.$$subclasses[i];
629            if (subclass.deref() !== undefined) {
630              rebuilt_subclasses.push(subclass);
631            }
632          }
633          // Now, let's add our class.
634          rebuilt_subclasses.push(new WeakRef(klass));
635          superclass.$$subclasses = rebuilt_subclasses;
636        }
637        else {
638          superclass.$$subclasses.push(klass);
639        }
640      }
641
642      if (superclass.$$meta) {
643        // If superclass has metaclass then we have explicitely inherit it.
644        Opal.build_class_singleton_class(klass);
645      }
646    }
647
648    return klass;
649  };
650  Opal.allocate_class = $allocate_class;
651
652
653  function find_existing_class(scope, name) {
654    // Try to find the class in the current scope
655    var klass = const_get_name(scope, name);
656
657    // If the class exists in the scope, then we must use that
658    if (klass) {
659      // Make sure the existing constant is a class, or raise error
660      if (!klass.$$is_class) {
661        $raise(Opal.TypeError, name + " is not a class");
662      }
663
664      return klass;
665    }
666  }
667
668  function ensureSuperclassMatch(klass, superclass) {
669    if (klass.$$super !== superclass) {
670      $raise(Opal.TypeError, "superclass mismatch for class " + klass.$$name);
671    }
672  }
673
674  Opal.klass = function(scope, superclass, name) {
675    var bridged;
676
677    if (scope == null || scope == '::') {
678      // Global scope
679      scope = _Object;
680    } else if (!scope.$$is_class && !scope.$$is_module) {
681      // Scope is an object, use its class
682      scope = scope.$$class;
683    }
684
685    // If the superclass is not an Opal-generated class then we're bridging a native JS class
686    if (
687      superclass != null && (!superclass.hasOwnProperty || (
688        superclass.hasOwnProperty && !superclass.hasOwnProperty('$$is_class')
689      ))
690    ) {
691      if (superclass.constructor && superclass.constructor.name == "Function") {
692        bridged = superclass;
693        superclass = _Object;
694      } else {
695        $raise(Opal.TypeError, "superclass must be a Class (" + (
696          (superclass.constructor && (superclass.constructor.name || superclass.constructor.$$name)) ||
697          typeof(superclass)
698        ) + " given)");
699      }
700    }
701
702    var klass = find_existing_class(scope, name);
703
704    if (klass != null) {
705      if (superclass) {
706        // Make sure existing class has same superclass
707        ensureSuperclassMatch(klass, superclass);
708      }
709    }
710    else {
711      // Class doesn't exist, create a new one with given superclass...
712
713      // Not specifying a superclass means we can assume it to be Object
714      if (superclass == null) {
715        superclass = _Object;
716      }
717
718      // Create the class object (instance of Class)
719      klass = $allocate_class(name, superclass);
720      $const_set(scope, name, klass);
721
722      // Call .inherited() hook with new class on the superclass
723      if (superclass.$inherited) {
724        superclass.$inherited(klass);
725      }
726
727      if (bridged) {
728        Opal.bridge(bridged, klass);
729      }
730    }
731
732    if (Opal.trace_class) { invoke_tracers_for_class(klass); }
733
734    return klass;
735  };
736
737  // Define new module (or return existing module). The given `scope` is basically
738  // the current `self` value the `module` statement was defined in. If this is
739  // a ruby module or class, then it is used, otherwise if the scope is a ruby
740  // object then that objects real ruby class is used (e.g. if the scope is the
741  // main object, then the top level `Object` class is used as the scope).
742  //
743  // If a module of the given name is already defined in the scope, then that
744  // instance is just returned.
745  //
746  // If there is a class of the given name in the scope, then an error is
747  // generated instead (cannot have a class and module of same name in same scope).
748  //
749  // Otherwise, a new module is created in the scope with the given name, and that
750  // new instance is returned back (to be referenced at runtime).
751  //
752  // @param  scope [Module, Class] class or module this definition is inside
753  // @param  id   [String] the name of the new (or existing) module
754  //
755  // @return [Module]
756  function $allocate_module(name) {
757    var constructor = function(){};
758    var module = constructor;
759
760    if (name)
761      $prop(constructor, 'displayName', name+'.constructor');
762
763    $prop(module, '$$name', name);
764    $prop(module, '$$prototype', constructor.prototype);
765    $prop(module, '$$const', {});
766    $prop(module, '$$is_module', true);
767    $prop(module, '$$is_a_module', true);
768    $prop(module, '$$cvars', {});
769    $prop(module, '$$iclasses', []);
770    $prop(module, '$$own_included_modules', []);
771    $prop(module, '$$own_prepended_modules', []);
772    $prop(module, '$$ancestors', [module]);
773    $prop(module, '$$ancestors_cache_version', null);
774
775    $set_proto(module, Opal.Module.prototype);
776
777    return module;
778  };
779  Opal.allocate_module = $allocate_module;
780
781  function find_existing_module(scope, name) {
782    var module = const_get_name(scope, name);
783    if (module == null && scope === _Object) module = const_lookup_ancestors(_Object, name);
784
785    if (module) {
786      if (!module.$$is_module && module !== _Object) {
787        $raise(Opal.TypeError, name + " is not a module");
788      }
789    }
790
791    return module;
792  }
793
794  Opal.module = function(scope, name) {
795    var module;
796
797    if (scope == null || scope == '::') {
798      // Global scope
799      scope = _Object;
800    } else if (!scope.$$is_class && !scope.$$is_module) {
801      // Scope is an object, use its class
802      scope = scope.$$class;
803    }
804
805    module = find_existing_module(scope, name);
806
807    if (module == null) {
808      // Module doesnt exist, create a new one...
809      module = $allocate_module(name);
810      $const_set(scope, name, module);
811    }
812
813    if (Opal.trace_class) { invoke_tracers_for_class(module); }
814
815    return module;
816  };
817
818  // Return the singleton class for the passed object.
819  //
820  // If the given object alredy has a singleton class, then it will be stored on
821  // the object as the `$$meta` property. If this exists, then it is simply
822  // returned back.
823  //
824  // Otherwise, a new singleton object for the class or object is created, set on
825  // the object at `$$meta` for future use, and then returned.
826  //
827  // @param object [Object] the ruby object
828  // @return [Class] the singleton class for object
829  Opal.get_singleton_class = function(object) {
830    if (object.$$is_number) {
831      $raise(Opal.TypeError, "can't define singleton");
832    }
833    if (object.$$meta) {
834      return object.$$meta;
835    }
836
837    if (object.hasOwnProperty('$$is_class')) {
838      return Opal.build_class_singleton_class(object);
839    } else if (object.hasOwnProperty('$$is_module')) {
840      return Opal.build_module_singleton_class(object);
841    } else {
842      return Opal.build_object_singleton_class(object);
843    }
844  };
845
846  // helper to set $$meta on klass, module or instance
847  function set_meta(obj, meta) {
848    if (obj.hasOwnProperty('$$meta')) {
849      obj.$$meta = meta;
850    } else {
851      $prop(obj, '$$meta', meta);
852    }
853    if (obj.$$frozen) {
854      // If a object is frozen (sealed), freeze $$meta too.
855      // No need to inject $$meta.$$prototype in the prototype chain,
856      // as $$meta cannot be modified anyway.
857      obj.$$meta.$freeze();
858    } else {
859      $set_proto(obj, meta.$$prototype);
860    }
861  };
862
863  // Build the singleton class for an existing class. Class object are built
864  // with their singleton class already in the prototype chain and inheriting
865  // from their superclass object (up to `Class` itself).
866  //
867  // NOTE: Actually in MRI a class' singleton class inherits from its
868  // superclass' singleton class which in turn inherits from Class.
869  //
870  // @param klass [Class]
871  // @return [Class]
872  Opal.build_class_singleton_class = function(klass) {
873    if (klass.$$meta) {
874      return klass.$$meta;
875    }
876
877    // The singleton_class superclass is the singleton_class of its superclass;
878    // but BasicObject has no superclass (its `$$super` is null), thus we
879    // fallback on `Class`.
880    var superclass = klass === BasicObject ? Class : Opal.get_singleton_class(klass.$$super);
881
882    var meta = $allocate_class(null, superclass, true);
883
884    $prop(meta, '$$is_singleton', true);
885    $prop(meta, '$$singleton_of', klass);
886    set_meta(klass, meta);
887    // Restoring ClassName.class
888    $prop(klass, '$$class', Opal.Class);
889
890    return meta;
891  };
892
893  Opal.build_module_singleton_class = function(mod) {
894    if (mod.$$meta) {
895      return mod.$$meta;
896    }
897
898    var meta = $allocate_class(null, Opal.Module, true);
899
900    $prop(meta, '$$is_singleton', true);
901    $prop(meta, '$$singleton_of', mod);
902    set_meta(mod, meta);
903    // Restoring ModuleName.class
904    $prop(mod, '$$class', Opal.Module);
905
906    return meta;
907  };
908
909  // Build the singleton class for a Ruby (non class) Object.
910  //
911  // @param object [Object]
912  // @return [Class]
913  Opal.build_object_singleton_class = function(object) {
914    var superclass = object.$$class,
915        klass = $allocate_class(nil, superclass, true);
916
917    $prop(klass, '$$is_singleton', true);
918    $prop(klass, '$$singleton_of', object);
919
920    delete klass.$$prototype.$$class;
921
922    set_meta(object, klass);
923
924    return klass;
925  };
926
927  Opal.is_method = function(prop) {
928    return (prop[0] === '$' && prop[1] !== '$');
929  };
930
931  Opal.instance_methods = function(mod) {
932    var exclude = [], results = [], ancestors = $ancestors(mod);
933
934    for (var i = 0, l = ancestors.length; i < l; i++) {
935      var ancestor = ancestors[i],
936          proto = ancestor.$$prototype;
937
938      if (proto.hasOwnProperty('$$dummy')) {
939        proto = proto.$$define_methods_on;
940      }
941
942      var props = Object.getOwnPropertyNames(proto);
943
944      for (var j = 0, ll = props.length; j < ll; j++) {
945        var prop = props[j];
946
947        if (Opal.is_method(prop)) {
948          var method_name = prop.slice(1),
949              method = proto[prop];
950
951          if (method.$$stub && exclude.indexOf(method_name) === -1) {
952            exclude.push(method_name);
953          }
954
955          if (!method.$$stub && results.indexOf(method_name) === -1 && exclude.indexOf(method_name) === -1) {
956            results.push(method_name);
957          }
958        }
959      }
960    }
961
962    return results;
963  };
964
965  Opal.own_instance_methods = function(mod) {
966    var results = [],
967        proto = mod.$$prototype;
968
969    if (proto.hasOwnProperty('$$dummy')) {
970      proto = proto.$$define_methods_on;
971    }
972
973    var props = Object.getOwnPropertyNames(proto);
974
975    for (var i = 0, length = props.length; i < length; i++) {
976      var prop = props[i];
977
978      if (Opal.is_method(prop)) {
979        var method = proto[prop];
980
981        if (!method.$$stub) {
982          var method_name = prop.slice(1);
983          results.push(method_name);
984        }
985      }
986    }
987
988    return results;
989  };
990
991  Opal.methods = function(obj) {
992    return Opal.instance_methods(obj.$$meta || obj.$$class);
993  };
994
995  Opal.own_methods = function(obj) {
996    return obj.$$meta ? Opal.own_instance_methods(obj.$$meta) : [];
997  };
998
999  Opal.receiver_methods = function(obj) {
1000    var mod = Opal.get_singleton_class(obj);
1001    var singleton_methods = Opal.own_instance_methods(mod);
1002    var instance_methods = Opal.own_instance_methods(mod.$$super);
1003    return singleton_methods.concat(instance_methods);
1004  };
1005
1006  // Returns an object containing all pairs of names/values
1007  // for all class variables defined in provided +module+
1008  // and its ancestors.
1009  //
1010  // @param module [Module]
1011  // @return [Object]
1012  Opal.class_variables = function(module) {
1013    var ancestors = $ancestors(module),
1014        i, length = ancestors.length,
1015        result = {};
1016
1017    for (i = length - 1; i >= 0; i--) {
1018      var ancestor = ancestors[i];
1019
1020      for (var cvar in ancestor.$$cvars) {
1021        result[cvar] = ancestor.$$cvars[cvar];
1022      }
1023    }
1024
1025    return result;
1026  };
1027
1028  // Sets class variable with specified +name+ to +value+
1029  // in provided +module+
1030  //
1031  // @param module [Module]
1032  // @param name [String]
1033  // @param value [Object]
1034  Opal.class_variable_set = function(module, name, value) {
1035    var ancestors = $ancestors(module),
1036        i, length = ancestors.length;
1037
1038    for (i = length - 2; i >= 0; i--) {
1039      var ancestor = ancestors[i];
1040
1041      if ($has_own(ancestor.$$cvars, name)) {
1042        ancestor.$$cvars[name] = value;
1043        return value;
1044      }
1045    }
1046
1047    module.$$cvars[name] = value;
1048
1049    return value;
1050  };
1051
1052  // Gets class variable with specified +name+ from provided +module+
1053  //
1054  // @param module [Module]
1055  // @param name [String]
1056  Opal.class_variable_get = function(module, name, tolerant) {
1057    if ($has_own(module.$$cvars, name))
1058      return module.$$cvars[name];
1059
1060    var ancestors = $ancestors(module),
1061      i, length = ancestors.length;
1062
1063    for (i = 0; i < length; i++) {
1064      var ancestor = ancestors[i];
1065
1066      if ($has_own(ancestor.$$cvars, name)) {
1067        return ancestor.$$cvars[name];
1068      }
1069    }
1070
1071    if (!tolerant)
1072      $raise(Opal.NameError, 'uninitialized class variable '+name+' in '+module.$name());
1073
1074    return nil;
1075  }
1076
1077  function isRoot(proto) {
1078    return proto.hasOwnProperty('$$iclass') && proto.hasOwnProperty('$$root');
1079  }
1080
1081  function own_included_modules(module) {
1082    var result = [], mod, proto = Object.getPrototypeOf(module.$$prototype);
1083
1084    while (proto) {
1085      if (proto.hasOwnProperty('$$class')) {
1086        // superclass
1087        break;
1088      }
1089      mod = protoToModule(proto);
1090      if (mod) {
1091        result.push(mod);
1092      }
1093      proto = Object.getPrototypeOf(proto);
1094    }
1095
1096    return result;
1097  }
1098
1099  function own_prepended_modules(module) {
1100    var result = [], mod, proto = Object.getPrototypeOf(module.$$prototype);
1101
1102    if (module.$$prototype.hasOwnProperty('$$dummy')) {
1103      while (proto) {
1104        if (proto === module.$$prototype.$$define_methods_on) {
1105          break;
1106        }
1107
1108        mod = protoToModule(proto);
1109        if (mod) {
1110          result.push(mod);
1111        }
1112
1113        proto = Object.getPrototypeOf(proto);
1114      }
1115    }
1116
1117    return result;
1118  }
1119
1120
1121  // The actual inclusion of a module into a class.
1122  //
1123  // ## Class `$$parent` and `iclass`
1124  //
1125  // To handle `super` calls, every class has a `$$parent`. This parent is
1126  // used to resolve the next class for a super call. A normal class would
1127  // have this point to its superclass. However, if a class includes a module
1128  // then this would need to take into account the module. The module would
1129  // also have to then point its `$$parent` to the actual superclass. We
1130  // cannot modify modules like this, because it might be included in more
1131  // then one class. To fix this, we actually insert an `iclass` as the class'
1132  // `$$parent` which can then point to the superclass. The `iclass` acts as
1133  // a proxy to the actual module, so the `super` chain can then search it for
1134  // the required method.
1135  //
1136  // @param module [Module] the module to include
1137  // @param includer [Module] the target class to include module into
1138  // @return [null]
1139  Opal.append_features = function(module, includer) {
1140    var module_ancestors = $ancestors(module);
1141    var iclasses = [];
1142
1143    if (module_ancestors.indexOf(includer) !== -1) {
1144      $raise(Opal.ArgumentError, 'cyclic include detected');
1145    }
1146
1147    for (var i = 0, length = module_ancestors.length; i < length; i++) {
1148      var ancestor = module_ancestors[i], iclass = create_iclass(ancestor);
1149      $prop(iclass, '$$included', true);
1150      iclasses.push(iclass);
1151    }
1152    var includer_ancestors = $ancestors(includer),
1153        chain = chain_iclasses(iclasses),
1154        start_chain_after,
1155        end_chain_on;
1156
1157    if (includer_ancestors.indexOf(module) === -1) {
1158      // first time include
1159
1160      // includer -> chain.first -> ...chain... -> chain.last -> includer.parent
1161      start_chain_after = includer.$$prototype;
1162      end_chain_on = Object.getPrototypeOf(includer.$$prototype);
1163    } else {
1164      // The module has been already included,
1165      // we don't need to put it into the ancestors chain again,
1166      // but this module may have new included modules.
1167      // If it's true we need to copy them.
1168      //
1169      // The simplest way is to replace ancestors chain from
1170      //          parent
1171      //            |
1172      //   `module` iclass (has a $$root flag)
1173      //            |
1174      //   ...previos chain of module.included_modules ...
1175      //            |
1176      //  "next ancestor" (has a $$root flag or is a real class)
1177      //
1178      // to
1179      //          parent
1180      //            |
1181      //    `module` iclass (has a $$root flag)
1182      //            |
1183      //   ...regenerated chain of module.included_modules
1184      //            |
1185      //   "next ancestor" (has a $$root flag or is a real class)
1186      //
1187      // because there are no intermediate classes between `parent` and `next ancestor`.
1188      // It doesn't break any prototypes of other objects as we don't change class references.
1189
1190      var parent = includer.$$prototype, module_iclass = Object.getPrototypeOf(parent);
1191
1192      while (module_iclass != null) {
1193        if (module_iclass.$$module === module && isRoot(module_iclass)) {
1194          break;
1195        }
1196
1197        parent = module_iclass;
1198        module_iclass = Object.getPrototypeOf(module_iclass);
1199      }
1200
1201      if (module_iclass) {
1202        // module has been directly included
1203        var next_ancestor = Object.getPrototypeOf(module_iclass);
1204
1205        // skip non-root iclasses (that were recursively included)
1206        while (next_ancestor.hasOwnProperty('$$iclass') && !isRoot(next_ancestor)) {
1207          next_ancestor = Object.getPrototypeOf(next_ancestor);
1208        }
1209
1210        start_chain_after = parent;
1211        end_chain_on = next_ancestor;
1212      } else {
1213        // module has not been directly included but was in ancestor chain because it was included by another module
1214        // include it directly
1215        start_chain_after = includer.$$prototype;
1216        end_chain_on = Object.getPrototypeOf(includer.$$prototype);
1217      }
1218    }
1219
1220    $set_proto(start_chain_after, chain.first);
1221    $set_proto(chain.last, end_chain_on);
1222
1223    // recalculate own_included_modules cache
1224    includer.$$own_included_modules = own_included_modules(includer);
1225
1226    Opal.const_cache_version++;
1227  };
1228
1229  Opal.prepend_features = function(module, prepender) {
1230    // Here we change the ancestors chain from
1231    //
1232    //   prepender
1233    //      |
1234    //    parent
1235    //
1236    // to:
1237    //
1238    // dummy(prepender)
1239    //      |
1240    //  iclass(module)
1241    //      |
1242    // iclass(prepender)
1243    //      |
1244    //    parent
1245    var module_ancestors = $ancestors(module);
1246    var iclasses = [];
1247
1248    if (module_ancestors.indexOf(prepender) !== -1) {
1249      $raise(Opal.ArgumentError, 'cyclic prepend detected');
1250    }
1251
1252    for (var i = 0, length = module_ancestors.length; i < length; i++) {
1253      var ancestor = module_ancestors[i], iclass = create_iclass(ancestor);
1254      $prop(iclass, '$$prepended', true);
1255      iclasses.push(iclass);
1256    }
1257
1258    var chain = chain_iclasses(iclasses),
1259        dummy_prepender = prepender.$$prototype,
1260        previous_parent = Object.getPrototypeOf(dummy_prepender),
1261        prepender_iclass,
1262        start_chain_after,
1263        end_chain_on;
1264
1265    if (dummy_prepender.hasOwnProperty('$$dummy')) {
1266      // The module already has some prepended modules
1267      // which means that we don't need to make it "dummy"
1268      prepender_iclass = dummy_prepender.$$define_methods_on;
1269    } else {
1270      // Making the module "dummy"
1271      prepender_iclass = create_dummy_iclass(prepender);
1272      flush_methods_in(prepender);
1273      $prop(dummy_prepender, '$$dummy', true);
1274      $prop(dummy_prepender, '$$define_methods_on', prepender_iclass);
1275
1276      // Converting
1277      //   dummy(prepender) -> previous_parent
1278      // to
1279      //   dummy(prepender) -> iclass(prepender) -> previous_parent
1280      $set_proto(dummy_prepender, prepender_iclass);
1281      $set_proto(prepender_iclass, previous_parent);
1282    }
1283
1284    var prepender_ancestors = $ancestors(prepender);
1285
1286    if (prepender_ancestors.indexOf(module) === -1) {
1287      // first time prepend
1288
1289      start_chain_after = dummy_prepender;
1290
1291      // next $$root or prepender_iclass or non-$$iclass
1292      end_chain_on = Object.getPrototypeOf(dummy_prepender);
1293      while (end_chain_on != null) {
1294        if (
1295          end_chain_on.hasOwnProperty('$$root') ||
1296          end_chain_on === prepender_iclass ||
1297          !end_chain_on.hasOwnProperty('$$iclass')
1298        ) {
1299          break;
1300        }
1301
1302        end_chain_on = Object.getPrototypeOf(end_chain_on);
1303      }
1304    } else {
1305      $raise(Opal.RuntimeError, "Prepending a module multiple times is not supported");
1306    }
1307
1308    $set_proto(start_chain_after, chain.first);
1309    $set_proto(chain.last, end_chain_on);
1310
1311    // recalculate own_prepended_modules cache
1312    prepender.$$own_prepended_modules = own_prepended_modules(prepender);
1313
1314    Opal.const_cache_version++;
1315  };
1316
1317  function flush_methods_in(module) {
1318    var proto = module.$$prototype,
1319        props = Object.getOwnPropertyNames(proto);
1320
1321    for (var i = 0; i < props.length; i++) {
1322      var prop = props[i];
1323      if (Opal.is_method(prop)) {
1324        delete proto[prop];
1325      }
1326    }
1327  }
1328
1329  function create_iclass(module) {
1330    var iclass = create_dummy_iclass(module);
1331
1332    if (module.$$is_module) {
1333      module.$$iclasses.push(iclass);
1334    }
1335
1336    return iclass;
1337  }
1338
1339  // Dummy iclass doesn't receive updates when the module gets a new method.
1340  function create_dummy_iclass(module) {
1341    var iclass = {},
1342        proto = module.$$prototype;
1343
1344    if (proto.hasOwnProperty('$$dummy')) {
1345      proto = proto.$$define_methods_on;
1346    }
1347
1348    var props = Object.getOwnPropertyNames(proto),
1349        length = props.length, i;
1350
1351    for (i = 0; i < length; i++) {
1352      var prop = props[i];
1353      $prop(iclass, prop, proto[prop]);
1354    }
1355
1356    $prop(iclass, '$$iclass', true);
1357    $prop(iclass, '$$module', module);
1358
1359    return iclass;
1360  }
1361
1362  function chain_iclasses(iclasses) {
1363    var length = iclasses.length, first = iclasses[0];
1364
1365    $prop(first, '$$root', true);
1366
1367    if (length === 1) {
1368      return { first: first, last: first };
1369    }
1370
1371    var previous = first;
1372
1373    for (var i = 1; i < length; i++) {
1374      var current = iclasses[i];
1375      $set_proto(previous, current);
1376      previous = current;
1377    }
1378
1379
1380    return { first: iclasses[0], last: iclasses[length - 1] };
1381  }
1382
1383  // For performance, some core Ruby classes are toll-free bridged to their
1384  // native JavaScript counterparts (e.g. a Ruby Array is a JavaScript Array).
1385  //
1386  // This method is used to setup a native constructor (e.g. Array), to have
1387  // its prototype act like a normal Ruby class. Firstly, a new Ruby class is
1388  // created using the native constructor so that its prototype is set as the
1389  // target for the new class. Note: all bridged classes are set to inherit
1390  // from Object.
1391  //
1392  // Example:
1393  //
1394  //    Opal.bridge(self, Function);
1395  //
1396  // @param klass       [Class] the Ruby class to bridge
1397  // @param constructor [JS.Function] native JavaScript constructor to use
1398  // @return [Class] returns the passed Ruby class
1399  //
1400  Opal.bridge = function(native_klass, klass) {
1401    if (native_klass.hasOwnProperty('$$bridge')) {
1402      $raise(Opal.ArgumentError, "already bridged");
1403    }
1404
1405    // constructor is a JS function with a prototype chain like:
1406    // - constructor
1407    //   - super
1408    //
1409    // What we need to do is to inject our class (with its prototype chain)
1410    // between constructor and super. For example, after injecting ::Object
1411    // into JS String we get:
1412    //
1413    // - constructor (window.String)
1414    //   - Opal.Object
1415    //     - Opal.Kernel
1416    //       - Opal.BasicObject
1417    //         - super (window.Object)
1418    //           - null
1419    //
1420    $prop(native_klass, '$$bridge', klass);
1421    $set_proto(native_klass.prototype, (klass.$$super || Opal.Object).$$prototype);
1422    $prop(klass, '$$prototype', native_klass.prototype);
1423
1424    $prop(klass.$$prototype, '$$class', klass);
1425    $prop(klass, '$$constructor', native_klass);
1426    $prop(klass, '$$bridge', true);
1427  };
1428
1429  function protoToModule(proto) {
1430    if (proto.hasOwnProperty('$$dummy')) {
1431      return;
1432    } else if (proto.hasOwnProperty('$$iclass')) {
1433      return proto.$$module;
1434    } else if (proto.hasOwnProperty('$$class')) {
1435      return proto.$$class;
1436    }
1437  }
1438
1439  function own_ancestors(module) {
1440    return module.$$own_prepended_modules.concat([module]).concat(module.$$own_included_modules);
1441  }
1442
1443  // The Array of ancestors for a given module/class
1444  function $ancestors(module) {
1445    if (!module) { return []; }
1446
1447    if (module.$$ancestors_cache_version === Opal.const_cache_version) {
1448      return module.$$ancestors;
1449    }
1450
1451    var result = [], i, mods, length;
1452
1453    for (i = 0, mods = own_ancestors(module), length = mods.length; i < length; i++) {
1454      result.push(mods[i]);
1455    }
1456
1457    if (module.$$super) {
1458      for (i = 0, mods = $ancestors(module.$$super), length = mods.length; i < length; i++) {
1459        result.push(mods[i]);
1460      }
1461    }
1462
1463    module.$$ancestors_cache_version = Opal.const_cache_version;
1464    module.$$ancestors = result;
1465
1466    return result;
1467  };
1468  Opal.ancestors = $ancestors;
1469
1470  Opal.included_modules = function(module) {
1471    var result = [], mod = null, proto = Object.getPrototypeOf(module.$$prototype);
1472
1473    for (; proto && Object.getPrototypeOf(proto); proto = Object.getPrototypeOf(proto)) {
1474      mod = protoToModule(proto);
1475      if (mod && mod.$$is_module && proto.$$iclass && proto.$$included) {
1476        result.push(mod);
1477      }
1478    }
1479
1480    return result;
1481  };
1482
1483
1484  // Method Missing
1485  // --------------
1486
1487  // Methods stubs are used to facilitate method_missing in opal. A stub is a
1488  // placeholder function which just calls `method_missing` on the receiver.
1489  // If no method with the given name is actually defined on an object, then it
1490  // is obvious to say that the stub will be called instead, and then in turn
1491  // method_missing will be called.
1492  //
1493  // When a file in ruby gets compiled to javascript, it includes a call to
1494  // this function which adds stubs for every method name in the compiled file.
1495  // It should then be safe to assume that method_missing will work for any
1496  // method call detected.
1497  //
1498  // Method stubs are added to the BasicObject prototype, which every other
1499  // ruby object inherits, so all objects should handle method missing. A stub
1500  // is only added if the given property name (method name) is not already
1501  // defined.
1502  //
1503  // Note: all ruby methods have a `$` prefix in javascript, so all stubs will
1504  // have this prefix as well (to make this method more performant).
1505  //
1506  //    Opal.add_stubs("foo,bar,baz=");
1507  //
1508  // All stub functions will have a private `$$stub` property set to true so
1509  // that other internal methods can detect if a method is just a stub or not.
1510  // `Kernel#respond_to?` uses this property to detect a methods presence.
1511  //
1512  // @param stubs [Array] an array of method stubs to add
1513  // @return [undefined]
1514  Opal.add_stubs = function(stubs) {
1515    var proto = Opal.BasicObject.$$prototype;
1516    var stub, existing_method;
1517    stubs = stubs.split(',');
1518
1519    for (var i = 0, length = stubs.length; i < length; i++) {
1520      stub = $jsid(stubs[i]), existing_method = proto[stub];
1521
1522      if (existing_method == null || existing_method.$$stub) {
1523        Opal.add_stub_for(proto, stub);
1524      }
1525    }
1526  };
1527
1528  // Add a method_missing stub function to the given prototype for the
1529  // given name.
1530  //
1531  // @param prototype [Prototype] the target prototype
1532  // @param stub [String] stub name to add (e.g. "$foo")
1533  // @return [undefined]
1534  Opal.add_stub_for = function(prototype, stub) {
1535    // Opal.stub_for(stub) is the method_missing_stub
1536    $prop(prototype, stub, Opal.stub_for(stub));
1537  };
1538
1539  // Generate the method_missing stub for a given method name.
1540  //
1541  // @param method_name [String] The js-name of the method to stub (e.g. "$foo")
1542  // @return [undefined]
1543  Opal.stub_for = function(method_name) {
1544
1545    function method_missing_stub() {
1546      // Copy any given block onto the method_missing dispatcher
1547      this.$method_missing.$$p = method_missing_stub.$$p;
1548
1549      // Set block property to null ready for the next call (stop false-positives)
1550      method_missing_stub.$$p = null;
1551
1552      // call method missing with correct args (remove '$' prefix on method n
1552ame)
1553      var args_ary = new Array(arguments.length);
1554      for(var i = 0, l = args_ary.length; i < l; i++) { args_ary[i] = arguments[i]; }
1555
1556      return this.$method_missing.apply(this, [method_name.slice(1)].concat(args_ary));
1557    }
1558
1559    method_missing_stub.$$stub = true;
1560
1561    return method_missing_stub;
1562  };
1563
1564
1565  // Methods
1566  // -------
1567
1568  // Arity count error dispatcher for methods
1569  //
1570  // @param actual [Fixnum] number of arguments given to method
1571  // @param expected [Fixnum] expected number of arguments
1572  // @param object [Object] owner of the method +meth+
1573  // @param meth [String] method name that got wrong number of arguments
1574  // @raise [ArgumentError]
1575  Opal.ac = function(actual, expected, object, meth) {
1576    var inspect = '';
1577    if (object.$$is_a_module) {
1578      inspect += object.$$name + '.';
1579    }
1580    else {
1581      inspect += object.$$class.$$name + '#';
1582    }
1583    inspect += meth;
1584
1585    $raise(Opal.ArgumentError, '[' + inspect + '] wrong number of arguments (given ' + actual + ', expected ' + expected + ')');
1586  };
1587
1588  // Arity count error dispatcher for blocks
1589  //
1590  // @param actual [Fixnum] number of arguments given to block
1591  // @param expected [Fixnum] expected number of arguments
1592  // @param context [Object] context of the block definition
1593  // @raise [ArgumentError]
1594  Opal.block_ac = function(actual, expected, context) {
1595    var inspect = "`block in " + context + "'";
1596
1597    $raise(Opal.ArgumentError, inspect + ': wrong number of arguments (given ' + actual + ', expected ' + expected + ')');
1598  };
1599
1600  function get_ancestors(obj) {
1601    if (obj.hasOwnProperty('$$meta') && obj.$$meta !== null) {
1602      return $ancestors(obj.$$meta);
1603    } else {
1604      return $ancestors(obj.$$class);
1605    }
1606  };
1607
1608  // Super dispatcher
1609  Opal.find_super = function(obj, mid, current_func, defcheck, allow_stubs) {
1610    var jsid = $jsid(mid), ancestors, super_method;
1611
1612    ancestors = get_ancestors(obj);
1613
1614    var current_index = ancestors.indexOf(current_func.$$owner);
1615
1616    for (var i = current_index + 1; i < ancestors.length; i++) {
1617      var ancestor = ancestors[i],
1618          proto = ancestor.$$prototype;
1619
1620      if (proto.hasOwnProperty('$$dummy')) {
1621        proto = proto.$$define_methods_on;
1622      }
1623
1624      if (proto.hasOwnProperty(jsid)) {
1625        super_method = proto[jsid];
1626        break;
1627      }
1628    }
1629
1630    if (!defcheck && super_method && super_method.$$stub && obj.$method_missing.$$pristine) {
1631      // method_missing hasn't been explicitly defined
1632      $raise(Opal.NoMethodError, 'super: no superclass method `'+mid+"' for "+obj, mid);
1633    }
1634
1635    return (super_method.$$stub && !allow_stubs) ? null : super_method;
1636  };
1637
1638  // Iter dispatcher for super in a block
1639  Opal.find_block_super = function(obj, jsid, current_func, defcheck, implicit) {
1640    var call_jsid = jsid;
1641
1642    if (!current_func) {
1643      $raise(Opal.RuntimeError, "super called outside of method");
1644    }
1645
1646    if (implicit && current_func.$$define_meth) {
1647      $raise(Opal.RuntimeError,
1648        "implicit argument passing of super from method defined by define_method() is not supported. " +
1649        "Specify all arguments explicitly"
1650      );
1651    }
1652
1653    if (current_func.$$def) {
1654      call_jsid = current_func.$$jsid;
1655    }
1656
1657    return Opal.find_super(obj, call_jsid, current_func, defcheck);
1658  };
1659
1660  // @deprecated
1661  Opal.find_super_dispatcher = Opal.find_super;
1662
1663  // @deprecated
1664  Opal.find_iter_super_dispatcher = Opal.find_block_super;
1665
1666  // handles yield calls for 1 yielded arg
1667  Opal.yield1 = function(block, arg) {
1668    if (typeof(block) !== "function") {
1669      $raise(Opal.LocalJumpError, "no block given");
1670    }
1671
1672    var has_mlhs = block.$$has_top_level_mlhs_arg,
1673        has_trailing_comma = block.$$has_trailing_comma_in_args;
1674
1675    if (block.length > 1 || ((has_mlhs || has_trailing_comma) && block.length === 1)) {
1676      arg = Opal.to_ary(arg);
1677    }
1678
1679    if ((block.length > 1 || (has_trailing_comma && block.length === 1)) && arg.$$is_array) {
1680      return block.apply(null, arg);
1681    }
1682    else {
1683      return block(arg);
1684    }
1685  };
1686
1687  // handles yield for > 1 yielded arg
1688  Opal.yieldX = function(block, args) {
1689    if (typeof(block) !== "function") {
1690      $raise(Opal.LocalJumpError, "no block given");
1691    }
1692
1693    if (block.length > 1 && args.length === 1) {
1694      if (args[0].$$is_array) {
1695        return block.apply(null, args[0]);
1696      }
1697    }
1698
1699    if (!args.$$is_array) {
1700      var args_ary = new Array(args.length);
1701      for(var i = 0, l = args_ary.length; i < l; i++) { args_ary[i] = args[i]; }
1702
1703      return block.apply(null, args_ary);
1704    }
1705
1706    return block.apply(null, args);
1707  };
1708
1709  // Finds the corresponding exception match in candidates.  Each candidate can
1710  // be a value, or an array of values.  Returns null if not found.
1711  Opal.rescue = function(exception, candidates) {
1712    for (var i = 0; i < candidates.length; i++) {
1713      var candidate = candidates[i];
1714
1715      if (candidate.$$is_array) {
1716        var result = Opal.rescue(exception, candidate);
1717
1718        if (result) {
1719          return result;
1720        }
1721      }
1722      else if (candidate === Opal.JS.Error || candidate['$==='](exception)) {
1723        return candidate;
1724      }
1725    }
1726
1727    return null;
1728  };
1729
1730  Opal.is_a = function(object, klass) {
1731    if (klass != null && object.$$meta === klass || object.$$class === klass) {
1732      return true;
1733    }
1734
1735    if (object.$$is_number && klass.$$is_number_class) {
1736      return (klass.$$is_integer_class) ? (object % 1) === 0 : true;
1737    }
1738
1739    var ancestors = $ancestors(object.$$is_class ? Opal.get_singleton_class(object) : (object.$$meta || object.$$class));
1740
1741    return ancestors.indexOf(klass) !== -1;
1742  };
1743
1744  // Helpers for extracting kwsplats
1745  // Used for: { **h }
1746  Opal.to_hash = function(value) {
1747    if (value.$$is_hash) {
1748      return value;
1749    }
1750    else if (value['$respond_to?']('to_hash', true)) {
1751      var hash = value.$to_hash();
1752      if (hash.$$is_hash) {
1753        return hash;
1754      }
1755      else {
1756        $raise(Opal.TypeError, "Can't convert " + value.$$class +
1757          " to Hash (" + value.$$class + "#to_hash gives " + hash.$$class + ")");
1758      }
1759    }
1760    else {
1761      $raise(Opal.TypeError, "no implicit conversion of " + value.$$class + " into Hash");
1762    }
1763  };
1764
1765  // Helpers for implementing multiple assignment
1766  // Our code for extracting the values and assigning them only works if the
1767  // return value is a JS array.
1768  // So if we get an Array subclass, extract the wrapped JS array from it
1769
1770  // Used for: a, b = something (no splat)
1771  Opal.to_ary = function(value) {
1772    if (value.$$is_array) {
1773      return value;
1774    }
1775    else if (value['$respond_to?']('to_ary', true)) {
1776      var ary = value.$to_ary();
1777      if (ary === nil) {
1778        return [value];
1779      }
1780      else if (ary.$$is_array) {
1781        return ary;
1782      }
1783      else {
1784        $raise(Opal.TypeError, "Can't convert " + value.$$class +
1785          " to Array (" + value.$$class + "#to_ary gives " + ary.$$class + ")");
1786      }
1787    }
1788    else {
1789      return [value];
1790    }
1791  };
1792
1793  // Used for: a, b = *something (with splat)
1794  Opal.to_a = function(value) {
1795    if (value.$$is_array) {
1796      // A splatted array must be copied
1797      return value.slice();
1798    }
1799    else if (value['$respond_to?']('to_a', true)) {
1800      var ary = value.$to_a();
1801      if (ary === nil) {
1802        return [value];
1803      }
1804      else if (ary.$$is_array) {
1805        return ary;
1806      }
1807      else {
1808        $raise(Opal.TypeError, "Can't convert " + value.$$class +
1809          " to Array (" + value.$$class + "#to_a gives " + ary.$$class + ")");
1810      }
1811    }
1812    else {
1813      return [value];
1814    }
1815  };
1816
1817  // Used for extracting keyword arguments from arguments passed to
1818  // JS function. If provided +arguments+ list doesn't have a Hash
1819  // as a last item, returns a blank Hash.
1820  //
1821  // @param parameters [Array]
1822  // @return [Hash]
1823  //
1824  Opal.extract_kwargs = function(parameters) {
1825    var kwargs = parameters[parameters.length - 1];
1826    if (kwargs != null && Opal.respond_to(kwargs, '$to_hash', true)) {
1827      $splice(parameters, parameters.length - 1);
1828      return kwargs;
1829    }
1830  };
1831
1832  // Used to get a list of rest keyword arguments. Method takes the given
1833  // keyword args, i.e. the hash literal passed to the method containing all
1834  // keyword arguemnts passed to method, as well as the used args which are
1835  // the names of required and optional arguments defined. This method then
1836  // just returns all key/value pairs which have not been used, in a new
1837  // hash literal.
1838  //
1839  // @param given_args [Hash] all kwargs given to method
1840  // @param used_args [Object<String: true>] all keys used as named kwargs
1841  // @return [Hash]
1842  //
1843  Opal.kwrestargs = function(given_args, used_args) {
1844    var keys      = [],
1845        map       = {},
1846        key           ,
1847        given_map = given_args.$$smap;
1848
1849    for (key in given_map) {
1850      if (!used_args[key]) {
1851        keys.push(key);
1852        map[key] = given_map[key];
1853      }
1854    }
1855
1856    return Opal.hash2(keys, map);
1857  };
1858
1859  function apply_blockopts(block, blockopts) {
1860    if (typeof(blockopts) === 'number') {
1861      block.$$arity = blockopts;
1862    }
1863    else if (typeof(blockopts) === 'object') {
1864      Object.assign(block, blockopts);
1865    }
1866  }
1867
1868  // Optimization for a costly operation of prepending '$' to method n
1868ames
1869  var jsid_cache = {}
1870  function $jsid(name) {
1871    return jsid_cache[name] || (jsid_cache[name] = '$' + name);
1872  }
1873  Opal.jsid = $jsid;
1874
1875  // Calls passed method on a ruby object with arguments and block:
1876  //
1877  // Can take a method or a method name.
1878  //
1879  // 1. When method name gets passed it invokes it by its name
1880  //    and calls 'method_missing' when object doesn't have this method.
1881  //    Used internally by Opal to invoke method that takes a block or a splat.
1882  // 2. When method (i.e. method body) gets passed, it doesn't trigger 'method_missing'
1883  //    because it doesn't know the name of the actual method.
1884  //    Used internally by Opal to invoke 'super'.
1885  //
1886  // @example
1887  //   var my_array = [1, 2, 3, 4]
1888  //   Opal.send(my_array, 'length')                    # => 4
1889  //   Opal.send(my_array, my_array.$length)            # => 4
1890  //
1891  //   Opal.send(my_array, 'reverse!')                  # => [4, 3, 2, 1]
1892  //   Opal.send(my_array, my_array['$reverse!']')      # => [4, 3, 2, 1]
1893  //
1894  // @param recv [Object] ruby object
1895  // @param method [Function, String] method body or name of the method
1896  // @param args [Array] arguments that will be passed to the method call
1897  // @param block [Function] ruby block
1898  // @param blockopts [Object, Number] optional properties to set on the block
1899  // @return [Object] returning value of the method call
1900  Opal.send = function(recv, method, args, block, blockopts) {
1901    var body;
1902
1903    if (typeof(method) === 'function') {
1904      body = method;
1905      method = null;
1906    } else if (typeof(method) === 'string') {
1907      body = recv[$jsid(method)];
1908    } else {
1909      $raise(Opal.NameError, "Passed method should be a string or a function");
1910    }
1911
1912    return Opal.send2(recv, body, method, args, block, blockopts);
1913  };
1914
1915  Opal.send2 = function(recv, body, method, args, block, blockopts) {
1916    if (body == null && method != null && recv.$method_missing) {
1917      body = recv.$method_missing;
1918      args = [method].concat(args);
1919    }
1920
1921    apply_blockopts(block, blockopts);
1922
1923    if (typeof block === 'function') body.$$p = block;
1924    return body.apply(recv, args);
1925  };
1926
1927  Opal.refined_send = function(refinement_groups, recv, method, args, block, blockopts) {
1928    var i, j, k, ancestors, ancestor, refinements, refinement, refine_modules, refine_module, body;
1929
1930    ancestors = get_ancestors(recv);
1931
1932    // For all ancestors that there are, starting from the closest to the furthest...
1933    for (i = 0; i < ancestors.length; i++) {
1934      ancestor = Opal.id(ancestors[i]);
1935
1936      // For all refinement groups there are, starting from the closest scope to the furthest...
1937      for (j = 0; j < refinement_groups.length; j++) {
1938        refinements = refinement_groups[j];
1939
1940        // For all refinements there are, starting from the last `using` call to the furthest...
1941        for (k = refinements.length - 1; k >= 0; k--) {
1942          refinement = refinements[k];
1943          if (typeof refinement.$$refine_modules === 'undefined') continue;
1944
1945          // A single module being given as an argument of the `using` call contains multiple
1946          // refinement modules
1947          refine_modules = refinement.$$refine_modules;
1948
1949          // Does this module refine a given call for a given ancestor module?
1950          if (typeof refine_modules[ancestor] === 'undefined') continue;
1951          refine_module = refine_modules[ancestor];
1952
1953          // Does this module define a method we want to call?
1954          if (typeof refine_module.$$prototype[$jsid(method)] !== 'undefined') {
1955            body = refine_module.$$prototype[$jsid(method)];
1956            return Opal.send2(recv, body, method, args, block, blockopts);
1957          }
1958        }
1959      }
1960    }
1961
1962    return Opal.send(recv, method, args, block, blockopts);
1963  };
1964
1965  Opal.lambda = function(block, blockopts) {
1966    block.$$is_lambda = true;
1967
1968    apply_blockopts(block, blockopts);
1969
1970    return block;
1971  };
1972
1973  // Used to define methods on an object. This is a helper method, used by the
1974  // compiled source to define methods on special case objects when the compiler
1975  // can not determine the destination object, or the object is a Module
1976  // instance. This can get called by `Module#define_method` as well.
1977  //
1978  // ## Modules
1979  //
1980  // Any method defined on a module will come through this runtime helper.
1981  // The method is added to the module body, and the owner of the method is
1982  // set to be the module itself. This is used later when choosing which
1983  // method should show on a class if more than 1 included modules define
1984  // the same method. Finally, if the module is in `module_function` mode,
1985  // then the method is also defined onto the module itself.
1986  //
1987  // ## Classes
1988  //
1989  // This helper will only be called for classes when a method is being
1990  // defined indirectly; either through `Module#define_method`, or by a
1991  // literal `def` method inside an `instance_eval` or `class_eval` body. In
1992  // either case, the method is simply added to the class' prototype. A special
1993  // exception exists for `BasicObject` and `Object`. These two classes are
1994  // special because they are used in toll-free bridged classes. In each of
1995  // these two cases, extra work is required to define the methods on toll-free
1996  // bridged class' prototypes as well.
1997  //
1998  // ## Objects
1999  //
2000  // If a simple ruby object is the object, then the method is simply just
2001  // defined on the object as a singleton method. This would be the case when
2002  // a method is defined inside an `instance_eval` block.
2003  //
2004  // @param obj  [Object, Class] the actual obj to define method for
2005  // @param jsid [String] the JavaScript friendly method name (e.g. '$foo')
2006  // @param body [JS.Function] the literal JavaScript function used as method
2007  // @param blockopts [Object, Number] optional properties to set on the body
2008  // @return [null]
2009  //
2010  Opal.def = function(obj, jsid, body, blockopts) {
2011    apply_blockopts(body, blockopts);
2012
2013    // Special case for a method definition in the
2014    // top-level namespace
2015    if (obj === Opal.top) {
2016      return Opal.defn(Opal.Object, jsid, body);
2017    }
2018    // if instance_eval is invoked on a module/class, it sets inst_eval_mod
2019    else if (!obj.$$eval && obj.$$is_a_module) {
2020      return Opal.defn(obj, jsid, body);
2021    }
2022    else {
2023      return Opal.defs(obj, jsid, body);
2024    }
2025  };
2026
2027  // Define method on a module or class (see Opal.def).
2028  Opal.defn = function(module, jsid, body) {
2029    $deny_frozen_access(module);
2030
2031    body.displayName = jsid;
2032    body.$$owner = module;
2033
2034    var name = jsid.substr(1);
2035
2036    var proto = module.$$prototype;
2037    if (proto.hasOwnProperty('$$dummy')) {
2038      proto = proto.$$define_methods_on;
2039    }
2040    $prop(proto, jsid, body);
2041
2042    if (module.$$is_module) {
2043      if (module.$$module_function) {
2044        Opal.defs(module, jsid, body)
2045      }
2046
2047      for (var i = 0, iclasses = module.$$iclasses, length = iclasses.length; i < length; i++) {
2048        var iclass = iclasses[i];
2049        $prop(iclass, jsid, body);
2050      }
2051    }
2052
2053    var singleton_of = module.$$singleton_of;
2054    if (module.$method_added && !module.$method_added.$$stub && !singleton_of) {
2055      module.$method_added(name);
2056    }
2057    else if (singleton_of && singleton_of.$singleton_method_added && !singleton_of.$singleton_method_added.$$stub) {
2058      singleton_of.$singleton_method_added(name);
2059    }
2060
2061    return name;
2062  };
2063
2064  // Define a singleton method on the given object (see Opal.def).
2065  Opal.defs = function(obj, jsid, body, blockopts) {
2066    apply_blockopts(body, blockopts);
2067
2068    if (obj.$$is_string || obj.$$is_number) {
2069      $raise(Opal.TypeError, "can't define singleton");
2070    }
2071    return Opal.defn(Opal.get_singleton_class(obj), jsid, body);
2072  };
2073
2074  // Called from #remove_method.
2075  Opal.rdef = function(obj, jsid) {
2076    if (!$has_own(obj.$$prototype, jsid)) {
2077      $raise(Opal.NameError, "method '" + jsid.substr(1) + "' not defined in " + obj.$name());
2078    }
2079
2080    delete obj.$$prototype[jsid];
2081
2082    if (obj.$$is_singleton) {
2083      if (obj.$$prototype.$singleton_method_removed && !obj.$$prototype.$singleton_method_removed.$$stub) {
2084        obj.$$prototype.$singleton_method_removed(jsid.substr(1));
2085      }
2086    }
2087    else {
2088      if (obj.$method_removed && !obj.$method_removed.$$stub) {
2089        obj.$method_removed(jsid.substr(1));
2090      }
2091    }
2092  };
2093
2094  // Called from #undef_method.
2095  Opal.udef = function(obj, jsid) {
2096    if (!obj.$$prototype[jsid] || obj.$$prototype[jsid].$$stub) {
2097      $raise(Opal.NameError, "method '" + jsid.substr(1) + "' not defined in " + obj.$name());
2098    }
2099
2100    Opal.add_stub_for(obj.$$prototype, jsid);
2101
2102    if (obj.$$is_singleton) {
2103      if (obj.$$prototype.$singleton_method_undefined && !obj.$$prototype.$singleton_method_undefined.$$stub) {
2104        obj.$$prototype.$singleton_method_undefined(jsid.substr(1));
2105      }
2106    }
2107    else {
2108      if (obj.$method_undefined && !obj.$method_undefined.$$stub) {
2109        obj.$method_undefined(jsid.substr(1));
2110      }
2111    }
2112  };
2113
2114  function is_method_body(body) {
2115    return (typeof(body) === "function" && !body.$$stub);
2116  }
2117
2118  Opal.alias = function(obj, name, old) {
2119    var id     = $jsid(name),
2120        old_id = $jsid(old),
2121        body,
2122        alias;
2123
2124    // Aliasing on main means aliasing on Object...
2125    if (typeof obj.$$prototype === 'undefined') {
2126      obj = Opal.Object;
2127    }
2128
2129    body = obj.$$prototype[old_id];
2130
2131    // When running inside #instance_eval the alias refers to class methods.
2132    if (obj.$$eval) {
2133      return Opal.alias(Opal.get_singleton_class(obj), name, old);
2134    }
2135
2136    if (!is_method_body(body)) {
2137      var ancestor = obj.$$super;
2138
2139      while (typeof(body) !== "function" && ancestor) {
2140        body     = ancestor[old_id];
2141        ancestor = ancestor.$$super;
2142      }
2143
2144      if (!is_method_body(body) && obj.$$is_module) {
2145        // try to look into Object
2146        body = Opal.Object.$$prototype[old_id]
2147      }
2148
2149      if (!is_method_body(body)) {
2150        $raise(Opal.NameError, "undefined method `" + old + "' for class `" + obj.$name() + "'")
2151      }
2152    }
2153
2154    // If the body is itself an alias use the original body
2155    // to keep the max depth at 1.
2156    if (body.$$alias_of) body = body.$$alias_of;
2157
2158    // We need a wrapper because otherwise properties
2159    // would be overwritten on the original body.
2160    alias = function() {
2161      var block = alias.$$p, args, i, ii;
2162
2163      args = new Array(arguments.length);
2164      for(i = 0, ii = arguments.length; i < ii; i++) {
2165        args[i] = arguments[i];
2166      }
2167
2168      alias.$$p = null;
2169
2170      return Opal.send(this, body, args, block);
2171    };
2172
2173    // Assign the 'length' value with defineProperty because
2174    // in strict mode the property is not writable.
2175    // It doesn't work in older browsers (like Chrome 38), where
2176    // an exception is thrown breaking Opal altogether.
2177    try {
2178      Object.defineProperty(alias, 'length', { value: body.length });
2179    } catch (e) {}
2180
2181    // Try to make the browser pick the right name
2182    alias.displayName       = name;
2183
2184    alias.$$arity           = body.$$arity == null ? body.length : body.$$arity;
2185    alias.$$parameters      = body.$$parameters;
2186    alias.$$source_location = body.$$source_location;
2187    alias.$$alias_of        = body;
2188    alias.$$alias_name      = name;
2189
2190    Opal.defn(obj, id, alias);
2191
2192    return obj;
2193  };
2194
2195  Opal.alias_gvar = function(new_name, old_name) {
2196    Object.defineProperty($gvars, new_name, {
2197      configurable: true,
2198      enumerable: true,
2199      get: function() {
2200        return $gvars[old_name];
2201      },
2202      set: function(new_value) {
2203        $gvars[old_name] = new_value;
2204      }
2205    });
2206    return nil;
2207  }
2208
2209  Opal.alias_native = function(obj, name, native_name) {
2210    var id   = $jsid(name),
2211        body = obj.$$prototype[native_name];
2212
2213    if (typeof(body) !== "function" || body.$$stub) {
2214      $raise(Opal.NameError, "undefined native method `" + native_name + "' for class `" + obj.$name() + "'")
2215    }
2216
2217    Opal.defn(obj, id, body);
2218
2219    return obj;
2220  };
2221
2222
2223  // Hashes
2224  // ------
2225
2226  Opal.hash_init = function(hash) {
2227    hash.$$smap = Object.create(null);
2228    hash.$$map  = Object.create(null);
2229    hash.$$keys = [];
2230  };
2231
2232  Opal.hash_clone = function(from_hash, to_hash) {
2233    to_hash.$$none = from_hash.$$none;
2234    to_hash.$$proc = from_hash.$$proc;
2235
2236    for (var i = 0, keys = from_hash.$$keys, smap = from_hash.$$smap, len = keys.length, key, value; i < len; i++) {
2237      key = keys[i];
2238
2239      if (key.$$is_string) {
2240        value = smap[key];
2241      } else {
2242        value = key.value;
2243        key = key.key;
2244      }
2245
2246      Opal.hash_put(to_hash, key, value);
2247    }
2248  };
2249
2250  Opal.hash_put = function(hash, key, value) {
2251    if (key.$$is_string) {
2252      if (!$has_own(hash.$$smap, key)) {
2253        hash.$$keys.push(key);
2254      }
2255      hash.$$smap[key] = value;
2256      return;
2257    }
2258
2259    var key_hash, bucket, last_bucket;
2260    key_hash = hash.$$by_identity ? Opal.id(key) : key.$hash();
2261
2262    if (!$has_own(hash.$$map, key_hash)) {
2263      bucket = {key: key, key_hash: key_hash, value: value};
2264      hash.$$keys.push(bucket);
2265      hash.$$map[key_hash] = bucket;
2266      return;
2267    }
2268
2269    bucket = hash.$$map[key_hash];
2270
2271    while (bucket) {
2272      if (key === bucket.key || key['$eql?'](bucket.key)) {
2273        last_bucket = undefined;
2274        bucket.value = value;
2275        break;
2276      }
2277      last_bucket = bucket;
2278      bucket = bucket.next;
2279    }
2280
2281    if (last_bucket) {
2282      bucket = {key: key, key_hash: key_hash, value: value};
2283      hash.$$keys.push(bucket);
2284      last_bucket.next = bucket;
2285    }
2286  };
2287
2288  Opal.hash_get = function(hash, key) {
2289    if (key.$$is_string) {
2290      if ($has_own(hash.$$smap, key)) {
2291        return hash.$$smap[key];
2292      }
2293      return;
2294    }
2295
2296    var key_hash, bucket;
2297    key_hash = hash.$$by_identity ? Opal.id(key) : key.$hash();
2298
2299    if ($has_own(hash.$$map, key_hash)) {
2300      bucket = hash.$$map[key_hash];
2301
2302      while (bucket) {
2303        if (key === bucket.key || key['$eql?'](bucket.key)) {
2304          return bucket.value;
2305        }
2306        bucket = bucket.next;
2307      }
2308    }
2309  };
2310
2311  Opal.hash_delete = function(hash, key) {
2312    var i, keys = hash.$$keys, length = keys.length, value, key_tmp;
2313
2314    if (key.$$is_string) {
2315      if (typeof key !== "string") key = key.valueOf();
2316
2317      if (!$has_own(hash.$$smap, key)) {
2318        return;
2319      }
2320
2321      for (i = 0; i < length; i++) {
2322        key_tmp = keys[i];
2323
2324        if (key_tmp.$$is_string && typeof key_tmp !== "string") {
2325          key_tmp = key_tmp.valueOf();
2326        }
2327
2328        if (key_tmp === key) {
2329          keys.splice(i, 1);
2330          break;
2331        }
2332      }
2333
2334      value = hash.$$smap[key];
2335      delete hash.$$smap[key];
2336      return value;
2337    }
2338
2339    var key_hash = key.$hash();
2340
2341    if (!$has_own(hash.$$map, key_hash)) {
2342      return;
2343    }
2344
2345    var bucket = hash.$$map[key_hash], last_bucket;
2346
2347    while (bucket) {
2348      if (key === bucket.key || key['$eql?'](bucket.key)) {
2349        value = bucket.value;
2350
2351        for (i = 0; i < length; i++) {
2352          if (keys[i] === bucket) {
2353            keys.splice(i, 1);
2354            break;
2355          }
2356        }
2357
2358        if (last_bucket && bucket.next) {
2359          last_bucket.next = bucket.next;
2360        }
2361        else if (last_bucket) {
2362          delete last_bucket.next;
2363        }
2364        else if (bucket.next) {
2365          hash.$$map[key_hash] = bucket.next;
2366        }
2367        else {
2368          delete hash.$$map[key_hash];
2369        }
2370
2371        return value;
2372      }
2373      last_bucket = bucket;
2374      bucket = bucket.next;
2375    }
2376  };
2377
2378  Opal.hash_rehash = function(hash) {
2379    for (var i = 0, length = hash.$$keys.length, key_hash, bucket, last_bucket; i < length; i++) {
2380
2381      if (hash.$$keys[i].$$is_string) {
2382        continue;
2383      }
2384
2385      key_hash = hash.$$keys[i].key.$hash();
2386
2387      if (key_hash === hash.$$keys[i].key_hash) {
2388        continue;
2389      }
2390
2391      bucket = hash.$$map[hash.$$keys[i].key_hash];
2392      last_bucket = undefined;
2393
2394      while (bucket) {
2395        if (bucket === hash.$$keys[i]) {
2396          if (last_bucket && bucket.next) {
2397            last_bucket.next = bucket.next;
2398          }
2399          else if (last_bucket) {
2400            delete last_bucket.next;
2401          }
2402          else if (bucket.next) {
2403            hash.$$map[hash.$$keys[i].key_hash] = bucket.next;
2404          }
2405          else {
2406            delete hash.$$map[hash.$$keys[i].key_hash];
2407          }
2408          break;
2409        }
2410        last_bucket = bucket;
2411        bucket = bucket.next;
2412      }
2413
2414      hash.$$keys[i].key_hash = key_hash;
2415
2416      if (!$has_own(hash.$$map, key_hash)) {
2417        hash.$$map[key_hash] = hash.$$keys[i];
2418        continue;
2419      }
2420
2421      bucket = hash.$$map[key_hash];
2422      last_bucket = undefined;
2423
2424      while (bucket) {
2425        if (bucket === hash.$$keys[i]) {
2426          last_bucket = undefined;
2427          break;
2428        }
2429        last_bucket = bucket;
2430        bucket = bucket.next;
2431      }
2432
2433      if (last_bucket) {
2434        last_bucket.next = hash.$$keys[i];
2435      }
2436    }
2437  };
2438
2439  Opal.hash = function() {
2440    var arguments_length = arguments.length, args, hash, i, length, key, value;
2441
2442    if (arguments_length === 1 && arguments[0].$$is_hash) {
2443      return arguments[0];
2444    }
2445
2446    hash = new Opal.Hash();
2447    Opal.hash_init(hash);
2448
2449    if (arguments_length === 1) {
2450      args = arguments[0];
2451
2452      if (arguments[0].$$is_array) {
2453        length = args.length;
2454
2455        for (i = 0; i < length; i++) {
2456          if (args[i].length !== 2) {
2457            $raise(Opal.ArgumentError, "value not of length 2: " + args[i].$inspect());
2458          }
2459
2460          key = args[i][0];
2461          value = args[i][1];
2462
2463          Opal.hash_put(hash, key, value);
2464        }
2465
2466        return hash;
2467      }
2468      else {
2469        args = arguments[0];
2470        for (key in args) {
2471          if ($has_own(args, key)) {
2472            value = args[key];
2473
2474            Opal.hash_put(hash, key, value);
2475          }
2476        }
2477
2478        return hash;
2479      }
2480    }
2481
2482    if (arguments_length % 2 !== 0) {
2483      $raise(Opal.ArgumentError, "odd number of arguments for Hash");
2484    }
2485
2486    for (i = 0; i < arguments_length; i += 2) {
2487      key = arguments[i];
2488      value = arguments[i + 1];
2489
2490      Opal.hash_put(hash, key, value);
2491    }
2492
2493    return hash;
2494  };
2495
2496  // A faster Hash creator for hashes that just use symbols and
2497  // strings as keys. The map and keys array can be constructed at
2498  // compile time, so they are just added here by the constructor
2499  // function.
2500  //
2501  Opal.hash2 = function(keys, smap) {
2502    var hash = new Opal.Hash();
2503
2504    hash.$$smap = smap;
2505    hash.$$map  = Object.create(null);
2506    hash.$$keys = keys;
2507
2508    return hash;
2509  };
2510
2511  // Create a new range instance with first and last values, and whether the
2512  // range excludes the last value.
2513  //
2514  Opal.range = function(first, last, exc) {
2515    var range         = new Opal.Range();
2516        range.begin   = first;
2517        range.end     = last;
2518        range.excl    = exc;
2519
2520    return range;
2521  };
2522
2523  var reserved_ivar_names = [
2524    // properties
2525    "constructor", "displayName", "__count__", "__noSuchMethod__",
2526    "__parent__", "__proto__",
2527    // methods
2528    "hasOwnProperty", "valueOf"
2529  ];
2530
2531  // Get the ivar name for a given name.
2532  // Mostly adds a trailing $ to reserved names.
2533  //
2534  Opal.ivar = function(name) {
2535    if (reserved_ivar_names.indexOf(name) !== -1) {
2536      name += "$";
2537    }
2538
2539    return name;
2540  };
2541
2542  // Support for #freeze
2543  // -------------------
2544
2545  // helper that can be used from methods
2546  function $deny_frozen_access(obj) {
2547    if (obj.$$frozen) {
2548      $raise(Opal.FrozenError, "can't modify frozen " + (obj.$class()) + ": " + (obj), Opal.hash2(["receiver"], {"receiver": obj}));
2549    }
2550  };
2551  Opal.deny_frozen_access = $deny_frozen_access;
2552
2553  // common #freeze runtime support
2554  Opal.freeze = function(obj) {
2555    $prop(obj, "$$frozen", true);
2556
2557    // set $$id
2558    if (!obj.hasOwnProperty('$$id')) { $prop(obj, '$$id', $uid()); }
2559
2560    if (obj.hasOwnProperty('$$meta')) {
2561      // freeze $$meta if it has already been set
2562      obj.$$meta.$freeze();
2563    } else {
2564      // ensure $$meta can be set lazily, $$meta is frozen when set in runtime.js
2565      $prop(obj, '$$meta', null);
2566    }
2567
2568    // $$comparable is used internally and set multiple times
2569    // defining it before sealing ensures it can be modified later on
2570    if (!obj.hasOwnProperty('$$comparable')) { $prop(obj, '$$comparable', null); }
2571
2572    // seal the Object
2573    Object.seal(obj);
2574
2575    return obj;
2576  };
2577
2578  // freze props, make setters of instance variables throw FrozenError
2579  Opal.freeze_props = function(obj) {
2580    var prop, prop_type, desc;
2581
2582    for(prop in obj) {
2583      prop_type = typeof(prop);
2584
2585      // prop_type "object" here is a String(), skip $ props
2586      if ((prop_type === "string" || prop_type === "object") && prop[0] === '$') {
2587        continue;
2588      }
2589
2590      desc = Object.getOwnPropertyDescriptor(obj, prop);
2591      if (desc && desc.enumerable && desc.writable) {
2592        // create closure to retain current value as cv
2593        // for Opal 2.0 let for cv should do the trick, instead of a function
2594        (function() {
2595          // set v to undefined, as if the property is not set
2596          var cv = obj[prop];
2597          Object.defineProperty(obj, prop, {
2598            get: function() { return cv; },
2599            set: function(_val) { $deny_frozen_access(obj); },
2600            enumerable: true
2601          });
2602        })();
2603      }
2604    }
2605  };
2606
2607  // Regexps
2608  // -------
2609
2610  // Escape Regexp special chars letting the resulting string be used to build
2611  // a new Regexp.
2612  //
2613  Opal.escape_regexp = function(str) {
2614    return str.replace(/([-[\]\/{}()*+?.^$\\| ])/g, '\\$1')
2615              .replace(/[\n]/g, '\\n')
2616              .replace(/[\r]/g, '\\r')
2617              .replace(/[\f]/g, '\\f')
2618              .replace(/[\t]/g, '\\t');
2619  };
2620
2621  // Create a global Regexp from a RegExp object and cache the result
2622  // on the object itself ($$g attribute).
2623  //
2624  Opal.global_regexp = function(pattern) {
2625    if (pattern.global) {
2626      return pattern; // RegExp already has the global flag
2627    }
2628    if (pattern.$$g == null) {
2629      pattern.$$g = new RegExp(pattern.source, (pattern.multiline ? 'gm' : 'g') + (pattern.ignoreCase ? 'i' : ''));
2630    } else {
2631      pattern.$$g.lastIndex = null; // reset lastIndex property
2632    }
2633    return pattern.$$g;
2634  };
2635
2636  // Create a global multiline Regexp from a RegExp object and cache the result
2637  // on the object itself ($$gm or $$g attribute).
2638  //
2639  Opal.global_multiline_regexp = function(pattern) {
2640    var result, flags;
2641
2642    // RegExp already has the global and multiline flag
2643    if (pattern.global && pattern.multiline) return pattern;
2644
2645    flags = 'gm' + (pattern.ignoreCase ? 'i' : '');
2646    if (pattern.multiline) {
2647      // we are using the $$g attribute because the Regexp is already multiline
2648      if (pattern.$$g == null) {
2649        pattern.$$g = new RegExp(pattern.source, flags);
2650      }
2651      result = pattern.$$g;
2652    } else {
2653      if (pattern.$$gm == null) {
2654        pattern.$$gm = new RegExp(pattern.source, flags);
2655      }
2656      result = pattern.$$gm;
2657    }
2658    result.lastIndex = null; // reset lastIndex property
2659    return result;
2660  };
2661
2662  // Combine multiple regexp parts together
2663  Opal.regexp = function(parts, flags) {
2664    var part;
2665    var ignoreCase = typeof flags !== 'undefined' && flags && flags.indexOf('i') >= 0;
2666
2667    for (var i = 0, ii = parts.length; i < ii; i++) {
2668      part = parts[i];
2669      if (part instanceof RegExp) {
2670        if (part.ignoreCase !== ignoreCase)
2671          Opal.Kernel.$warn(
2672            "ignore case doesn't match for " + part.source.$inspect(),
2673            Opal.hash({uplevel: 1})
2674          )
2675
2676        part = part.source;
2677      }
2678      if (part === '') part = '(?:' + part + ')';
2679      parts[i] = part;
2680    }
2681
2682    if (flags) {
2683      return new RegExp(parts.join(''), flags);
2684    } else {
2685      return new RegExp(parts.join(''));
2686    }
2687  };
2688
2689  // Require system
2690  // --------------
2691
2692  Opal.modules         = {};
2693  Opal.loaded_features = ['corelib/runtime'];
2694  Opal.current_dir     = '.';
2695  Opal.require_table   = {'corelib/runtime': true};
2696
2697  Opal.normalize = function(path) {
2698    var parts, part, new_parts = [], SEPARATOR = '/';
2699
2700    if (Opal.current_dir !== '.') {
2701      path = Opal.current_dir.replace(/\/*$/, '/') + path;
2702    }
2703
2704    path = path.replace(/^\.\//, '');
2705    path = path.replace(/\.(rb|opal|js)$/, '');
2706    parts = path.split(SEPARATOR);
2707
2708    for (var i = 0, ii = parts.length; i < ii; i++) {
2709      part = parts[i];
2710      if (part === '') continue;
2711      (part === '..') ? new_parts.pop() : new_parts.push(part)
2712    }
2713
2714    return new_parts.join(SEPARATOR);
2715  };
2716
2717  Opal.loaded = function(paths) {
2718    var i, l, path;
2719
2720    for (i = 0, l = paths.length; i < l; i++) {
2721      path = Opal.normalize(paths[i]);
2722
2723      if (Opal.require_table[path]) {
2724        continue;
2725      }
2726
2727      Opal.loaded_features.push(path);
2728      Opal.require_table[path] = true;
2729    }
2730  };
2731
2732  Opal.load_normalized = function(path) {
2733    Opal.loaded([path]);
2734
2735    var module = Opal.modules[path];
2736
2737    if (module) {
2738      var retval = module(Opal);
2739      if (typeof Promise !== 'undefined' && retval instanceof Promise) {
2740        // A special case of require having an async top:
2741        // We will need to await it.
2742        return retval.then($return_val(true));
2743      }
2744    }
2745    else {
2746      var severity = Opal.config.missing_require_severity;
2747      var message  = 'cannot load such file -- ' + path;
2748
2749      if (severity === "error") {
2750        $raise(Opal.LoadError, message);
2751      }
2752      else if (severity === "warning") {
2753        console.warn('WARNING: LoadError: ' + message);
2754      }
2755    }
2756
2757    return true;
2758  };
2759
2760  Opal.load = function(path) {
2761    path = Opal.normalize(path);
2762
2763    return Opal.load_normalized(path);
2764  };
2765
2766  Opal.require = function(path) {
2767    path = Opal.normalize(path);
2768
2769    if (Opal.require_table[path]) {
2770      return false;
2771    }
2772
2773    return Opal.load_normalized(path);
2774  };
2775
2776
2777  // Strings
2778  // -------
2779
2780  Opal.encodings = Object.create(null);
2781
2782  // Sets the encoding on a string, will treat string literals as frozen strings
2783  // raising a FrozenError.
2784  //
2785  // @param str [String] the string on which the encoding should be set
2786  // @param name [String] the canonical name of the encoding
2787  // @param type [String] possible values are either `"encoding"`, `"internal_encoding"`, or `undefined
2788  Opal.set_encoding = function(str, name, type) {
2789    if (typeof type === "undefined") type = "encoding";
2790    if (typeof str === 'string' || str.$$frozen === true)
2791      $raise(Opal.FrozenError, "can't modify frozen String");
2792
2793    var encoding = Opal.find_encoding(name);
2794
2795    if (encoding === str[type]) { return str; }
2796
2797    str[type] = encoding;
2798
2799    return str;
2800  };
2801
2802  // Fetches the encoding for the given name or raises ArgumentError.
2803  Opal.find_encoding = function(name) {
2804    var register = Opal.encodings;
2805    var encoding = register[name] || register[name.toUpperCase()];
2806    if (!encoding) $raise(Opal.ArgumentError, "unknown encoding name - " + name);
2807    return encoding;
2808  }
2809
2810  // @returns a String object with the encoding set from a string literal
2811  Opal.enc = function(str, name) {
2812    var dup = new String(str);
2813    dup = Opal.set_encoding(dup, name);
2814    dup.internal_encoding = dup.encoding;
2815    return dup
2816  }
2817
2818  // @returns a String object with the internal encoding set to Binary
2819  Opal.binary = function(str) {
2820    var dup = new String(str);
2821    return Opal.set_encoding(dup, "binary", "internal_encoding");
2822  }
2823
2824  Opal.last_promise = null;
2825  Opal.promise_unhandled_exception = false;
2826
2827  // Run a block of code, but if it returns a Promise, don't run the next
2828  // one, but queue it.
2829  Opal.queue = function(proc) {
2830    if (Opal.last_promise) {
2831      // The async path is taken only if anything before returned a
2832      // Promise(V2).
2833      Opal.last_promise = Opal.last_promise.then(function() {
2834        if (!Opal.promise_unhandled_exception) return proc(Opal);
2835      })['catch'](function(error) {
2836        if (Opal.respond_to(error, '$full_message')) {
2837          error = error.$full_message();
2838        }
2839        console.error(error);
2840        // Abort further execution
2841        Opal.promise_unhandled_exception = true;
2842        Opal.exit(1);
2843      });
2844      return Opal.last_promise;
2845    }
2846    else {
2847      var ret = proc(Opal);
2848      if (typeof Promise === 'function' && typeof ret === 'object' && ret instanceof Promise) {
2849        Opal.last_promise = ret;
2850      }
2851      return ret;
2852    }
2853  }
2854
2855  // Operator helpers
2856  // ----------------
2857
2858  function are_both_numbers(l,r) { return typeof(l) === 'number' && typeof(r) === 'number' }
2859
2860  Opal.rb_plus   = function(l,r) { return are_both_numbers(l,r) ? l + r : l['$+'](r); }
2861  Opal.rb_minus  = function(l,r) { return are_both_numbers(l,r) ? l - r : l['$-'](r); }
2862  Opal.rb_times  = function(l,r) { return are_both_numbers(l,r) ? l * r : l['$*'](r); }
2863  Opal.rb_divide = function(l,r) { return are_both_numbers(l,r) ? l / r : l['$/'](r); }
2864  Opal.rb_lt     = function(l,r) { return are_both_numbers(l,r) ? l < r : l['$<'](r); }
2865  Opal.rb_gt     = function(l,r) { return are_both_numbers(l,r) ? l > r : l['$>'](r); }
2866  Opal.rb_le     = function(l,r) { return are_both_numbers(l,r) ? l <= r : l['$<='](r); }
2867  Opal.rb_ge     = function(l,r) { return are_both_numbers(l,r) ? l >= r : l['$>='](r); }
2868
2869  // Optimized helpers for calls like $truthy((a)['$==='](b)) -> $eqeqeq(a, b)
2870  function are_both_numbers_or_strings(lhs, rhs) {
2871    return (typeof lhs === 'number' && typeof rhs === 'number') ||
2872           (typeof lhs === 'string' && typeof rhs === 'string');
2873  }
2874
2875  function $eqeq(lhs, rhs) {
2876    return are_both_numbers_or_strings(lhs,rhs) ? lhs === rhs : $truthy((lhs)['$=='](rhs));
2877  };
2878  Opal.eqeq = $eqeq;
2879  Opal.eqeqeq = function(lhs, rhs) {
2880    return are_both_numbers_or_strings(lhs,rhs) ? lhs === rhs : $truthy((lhs)['$==='](rhs));
2881  };
2882  Opal.neqeq = function(lhs, rhs) {
2883    return are_both_numbers_or_strings(lhs,rhs) ? lhs !== rhs : $truthy((lhs)['$!='](rhs));
2884  };
2885  Opal.not = function(arg) {
2886    if (undefined === arg || null === arg || false === arg || nil === arg) return true;
2887    if (true === arg || arg['$!'].$$pristine) return false;
2888    return $truthy(arg['$!']());
2889  }
2890
2891  // Shortcuts - optimized function generators for simple kinds of functions
2892  function $return_val(arg) {
2893    return function() {
2894      return arg;
2895    }
2896  }
2897  Opal.return_val = $return_val;
2898
2899  Opal.return_self = function() {
2900    return this;
2901  }
2902  Opal.return_ivar = function(ivar) {
2903    return function() {
2904      if (this[ivar] == null) { return nil; }
2905      return this[ivar];
2906    }
2907  }
2908  Opal.assign_ivar = function(ivar) {
2909    return function(val) {
2910      $deny_frozen_access(this);
2911      return this[ivar] = val;
2912    }
2913  }
2914  Opal.assign_ivar_val = function(ivar, static_val) {
2915    return function() {
2916      $deny_frozen_access(this);
2917      return this[ivar] = static_val;
2918    }
2919  }
2920
2921  // Primitives for handling parameters
2922  Opal.ensure_kwargs = function(kwargs) {
2923    if (kwargs == null) {
2924      return Opal.hash2([], {});
2925    } else if (kwargs.$$is_hash) {
2926      return kwargs;
2927    } else {
2928      $raise(Opal.ArgumentError, 'expected kwargs');
2929    }
2930  }
2931
2932  Opal.get_kwarg = function(kwargs, key) {
2933    if (!$has_own(kwargs.$$smap, key)) {
2934      $raise(Opal.ArgumentError, 'missing keyword: '+key);
2935    }
2936    return kwargs.$$smap[key];
2937  }
2938
2939  // Arrays of size > 32 elements that contain only strings,
2940  // symbols, integers and nils are compiled as a self-extracting
2941  // string.
2942  Opal.large_array_unpack = function(str) {
2943    var array = str.split(","), length = array.length, i;
2944    for (i = 0; i < length; i++) {
2945      switch(array[i][0]) {
2946        case undefined:
2947          array[i] = nil
2948          break;
2949        case '-':
2950        case '0':
2951        case '1':
2952        case '2':
2953        case '3':
2954        case '4':
2955        case '5':
2956        case '6':
2957        case '7':
2958        case '8':
2959        case '9':
2960          array[i] = +array[i];
2961      }
2962    }
2963    return array;
2964  }
2965
2966  // Initialization
2967  // --------------
2968  Opal.BasicObject = BasicObject = $allocate_class('BasicObject', null);
2969  Opal.Object      = _Object     = $allocate_class('Object', Opal.BasicObject);
2970  Opal.Module      = Module      = $allocate_class('Module', Opal.Object);
2971  Opal.Class       = Class       = $allocate_class('Class', Opal.Module);
2972  Opal.Opal        = _Opal       = $allocate_module('Opal');
2973  Opal.Kernel      = Kernel      = $allocate_module('Kernel');
2974
2975  $set_proto(Opal.BasicObject, Opal.Class.$$prototype);
2976  $set_proto(Opal.Object, Opal.Class.$$prototype);
2977  $set_proto(Opal.Module, Opal.Class.$$prototype);
2978  $set_proto(Opal.Class, Opal.Class.$$prototype);
2979
2980  // BasicObject can reach itself, avoid const_set to skip the $$base_module logic
2981  BasicObject.$$const.BasicObject = BasicObject;
2982
2983  // Assign basic constants
2984  $const_set(_Object, "BasicObject",  BasicObject);
2985  $const_set(_Object, "Object",       _Object);
2986  $const_set(_Object, "Module",       Module);
2987  $const_set(_Object, "Class",        Class);
2988  $const_set(_Object, "Opal",         _Opal);
2989  $const_set(_Object, "Kernel",       Kernel);
2990
2991  // Fix booted classes to have correct .class value
2992  BasicObject.$$class = Class;
2993  _Object.$$class     = Class;
2994  Module.$$class      = Class;
2995  Class.$$class       = Class;
2996  _Opal.$$class       = Module;
2997  Kernel.$$class      = Module;
2998
2999  // Forward .toString() to #to_s
3000  $prop(_Object.$$prototype, 'toString', function() {
3001    var to_s = this.$to_s();
3002    if (to_s.$$is_string && typeof(to_s) === 'object') {
3003      // a string created using new String('string')
3004      return to_s.valueOf();
3005    } else {
3006      return to_s;
3007    }
3008  });
3009
3010  // Make Kernel#require immediately available as it's needed to require all the
3011  // other corelib files.
3012  $prop(_Object.$$prototype, '$require', Opal.require);
3013
3014  // Instantiate the main object
3015  Opal.top = new _Object();
3016  Opal.top.$to_s = Opal.top.$inspect = $return_val('main');
3017  Opal.top.$define_method = top_define_method;
3018
3019  // Foward calls to define_method on the top object to Object
3020  function top_define_method() {
3021    var args = $slice(arguments);
3022    var block = top_define_method.$$p;
3023    top_define_method.$$p = null;
3024    return Opal.send(_Object, 'define_method', args, block)
3025  };
3026
3027  // Nil
3028  Opal.NilClass = $allocate_class('NilClass', Opal.Object);
3029  $const_set(_Object, 'NilClass', Opal.NilClass);
3030  nil = Opal.nil = new Opal.NilClass();
3031  nil.$$id = nil_id;
3032  nil.call = nil.apply = function() { $raise(Opal.LocalJumpError, 'no block given'); };
3033  nil.$$frozen = true;
3034  nil.$$comparable = false;
3035  Object.seal(nil);
3036
3037  Opal.thrower = function(type) {
3038    var thrower = new Error('unexpected '+type);
3039    thrower.$thrower_type = type;
3040    thrower.$throw = function(value) {
3041      if (value == null) value = nil;
3042      thrower.$v = value;
3043      throw thrower;
3044    };
3045    return thrower;
3046  };
3047
3048  Opal.t_eval_return = Opal.thrower("return");
3049
3050  TypeError.$$super = Error;
3051
3052  // If enable-file-source-embed compiler option is enabled, each module loaded will add its
3053  // sources to this object
3054  Opal.file_sources = {};
3055}).call(this);
3056Opal.loaded(["corelib/runtime.js"]);
3057Opal.modules["corelib/helpers"] = function(Opal) {/* Generated by Opal 1.7.3 */
3058  var $type_error = Opal.type_error, $coerce_to = Opal.coerce_to, $module = Opal.module, $defs = Opal.defs, $slice = Opal.slice, $eqeqeq = Opal.eqeqeq, $Kernel = Opal.Kernel, $truthy = Opal.truthy, $Opal = Opal.Opal, nil = Opal.nil, $$$ = Opal.$$$;
3059
3060  Opal.add_stubs('===,raise,respond_to?,nil?,__send__,<=>,class,coerce_to!,new,to_s,__id__');
3061  return (function($base) {
3062    var self = $module($base, 'Opal');
3063
3064    
3065    
3066    $defs(self, '$bridge', function $$bridge(constructor, klass) {
3067      
3068      return Opal.bridge(constructor, klass);
3069    });
3070    $defs(self, '$coerce_to!', function $Opal_coerce_to$excl$1(object, type, method, $a) {
3071      var $post_args, args, coerced = nil;
3072
3073      
3074      $post_args = $slice(arguments, 3);
3075      args = $post_args;
3076      coerced = $coerce_to(object, type, method, args);
3077      if (!$eqeqeq(type, coerced)) {
3078        $Kernel.$raise($type_error(object, type, method, coerced))
3079      };
3080      return coerced;
3081    }, -4);
3082    $defs(self, '$coerce_to?', function $Opal_coerce_to$ques$2(object, type, method, $a) {
3083      var $post_args, args, coerced = nil;
3084
3085      
3086      $post_args = $slice(arguments, 3);
3087      args = $post_args;
3088      if (!$truthy(object['$respond_to?'](method))) {
3089        return nil
3090      };
3091      coerced = $coerce_to(object, type, method, args);
3092      if ($truthy(coerced['$nil?']())) {
3093        return nil
3094      };
3095      if (!$eqeqeq(type, coerced)) {
3096        $Kernel.$raise($type_error(object, type, method, coerced))
3097      };
3098      return coerced;
3099    }, -4);
3100    $defs(self, '$try_convert', function $$try_convert(object, type, method) {
3101      
3102      
3103      if ($eqeqeq(type, object)) {
3104        return object
3105      };
3106      if ($truthy(object['$respond_to?'](method))) {
3107        return object.$__send__(method)
3108      } else {
3109        return nil
3110      };
3111    });
3112    $defs(self, '$compare', function $$compare(a, b) {
3113      var compare = nil;
3114
3115      
3116      compare = a['$<=>'](b);
3117      if ($truthy(compare === nil)) {
3118        $Kernel.$raise($$$('ArgumentError'), "comparison of " + (a.$class()) + " with " + (b.$class()) + " failed")
3119      };
3120      return compare;
3121    });
3122    $defs(self, '$destructure', function $$destructure(args) {
3123      
3124      
3125      if (args.length == 1) {
3126        return args[0];
3127      }
3128      else if (args.$$is_array) {
3129        return args;
3130      }
3131      else {
3132        var args_ary = new Array(args.length);
3133        for(var i = 0, l = args_ary.length; i < l; i++) { args_ary[i] = args[i]; }
3134
3135        return args_ary;
3136      }
3137    
3138    });
3139    $defs(self, '$respond_to?', function $Opal_respond_to$ques$3(obj, method, include_all) {
3140      
3141      
3142      if (include_all == null) include_all = false;
3143      
3144      if (obj == null || !obj.$$class) {
3145        return false;
3146      }
3147    ;
3148      return obj['$respond_to?'](method, include_all);
3149    }, -3);
3150    $defs(self, '$instance_variable_name!', function $Opal_instance_variable_name$excl$4(name) {
3151      
3152      
3153      name = $Opal['$coerce_to!'](name, $$$('String'), "to_str");
3154      if (!$truthy(/^@[a-zA-Z_][a-zA-Z0-9_]*?$/.test(name))) {
3155        $Kernel.$raise($$$('NameError').$new("'" + (name) + "' is not allowed as an instance variable name", name))
3156      };
3157      return name;
3158    });
3159    $defs(self, '$class_variable_name!', function $Opal_class_variable_name$excl$5(name) {
3160      
3161      
3162      name = $Opal['$coerce_to!'](name, $$$('String'), "to_str");
3163      if ($truthy(name.length < 3 || name.slice(0,2) !== '@@')) {
3164        $Kernel.$raise($$$('NameError').$new("`" + (name) + "' is not allowed as a class variable name", name))
3165      };
3166      return name;
3167    });
3168    $defs(self, '$const_name?', function $Opal_const_name$ques$6(const_name) {
3169      
3170      
3171      if (typeof const_name !== 'string') {
3172        (const_name = $Opal['$coerce_to!'](const_name, $$$('String'), "to_str"))
3173      }
3174
3175      return const_name[0] === const_name[0].toUpperCase()
3176    
3177    });
3178    $defs(self, '$const_name!', function $Opal_const_name$excl$7(const_name) {
3179      var $a, self = this;
3180
3181      
3182      if ($truthy((($a = $$$('::', 'String', 'skip_raise')) ? 'constant' : nil))) {
3183        const_name = $Opal['$coerce_to!'](const_name, $$$('String'), "to_str")
3184      };
3185      
3186      if (!const_name || const_name[0] != const_name[0].toUpperCase()) {
3187        self.$raise($$$('NameError'), "wrong constant name " + (const_name))
3188      }
3189    ;
3190      return const_name;
3191    });
3192    $defs(self, '$pristine', function $$pristine(owner_class, $a) {
3193      var $post_args, method_names;
3194
3195      
3196      $post_args = $slice(arguments, 1);
3197      method_names = $post_args;
3198      
3199      var method_name, method;
3200      for (var i = method_names.length - 1; i >= 0; i--) {
3201        method_name = method_names[i];
3202        method = owner_class.$$prototype[Opal.jsid(method_name)];
3203
3204        if (method && !method.$$stub) {
3205          method.$$pristine = true;
3206        }
3207      }
3208    ;
3209      return nil;
3210    }, -2);
3211    var inspect_stack = [];
3212    return $defs(self, '$inspect', function $$inspect(value) {
3213      var e = nil;
3214
3215      
3216      ;
3217      var pushed = false;
3218      
3219      return (function() { try {
3220      try {
3221        
3222        
3223        if (value === null) {
3224          // JS null value
3225          return 'null';
3226        }
3227        else if (value === undefined) {
3228          // JS undefined value
3229          return 'undefined';
3230        }
3231        else if (typeof value.$$class === 'undefined') {
3232          // JS object / other value that is not bridged
3233          return Object.prototype.toString.apply(value);
3234        }
3235        else if (typeof value.$inspect !== 'function' || value.$inspect.$$stub) {
3236          // BasicObject and friends
3237          return "#<" + (value.$$class) + ":0x" + (value.$__id__().$to_s(16)) + ">"
3238        }
3239        else if (inspect_stack.indexOf(value.$__id__()) !== -1) {
3240          // inspect recursing inside inspect to find out about the
3241          // same object
3242          return "#<" + (value.$$class) + ":0x" + (value.$__id__().$to_s(16)) + ">"
3243        }
3244        else {
3245          // anything supporting Opal
3246          inspect_stack.push(value.$__id__());
3247          pushed = true;
3248          return value.$inspect();
3249        }
3250      ;
3251        return nil;
3252      } catch ($err) {
3253        if (Opal.rescue($err, [$$$('Exception')])) {(e = $err)
3254          try {
3255            return "#<" + (value.$$class) + ":0x" + (value.$__id__().$to_s(16)) + ">"
3256          } finally { Opal.pop_exception(); }
3257        } else { throw $err; }
3258      }
3259      } finally {
3260        if (pushed) inspect_stack.pop()
3261      }; })();;
3262    }, -1);
3263  })('::')
3264};
3265
3266Opal.modules["corelib/module"] = function(Opal) {/* Generated by Opal 1.7.3 */
3267  var $truthy = Opal.truthy, $coerce_to = Opal.coerce_to, $const_set = Opal.const_set, $Object = Opal.Object, $return_ivar = Opal.return_ivar, $assign_ivar = Opal.assign_ivar, $ivar = Opal.ivar, $deny_frozen_access = Opal.deny_frozen_access, $freeze = Opal.freeze, $prop = Opal.prop, $jsid = Opal.jsid, $klass = Opal.klass, $defs = Opal.defs, $send = Opal.send, $def = Opal.def, $eqeqeq = Opal.eqeqeq, $Module = Opal.Module, $Kernel = Opal.Kernel, $rb_lt = Opal.rb_lt, $rb_gt = Opal.rb_gt, $slice = Opal.slice, $to_a = Opal.to_a, $hash2 = Opal.hash2, $Opal = Opal.Opal, $return_val = Opal.return_val, $eqeq = Opal.eqeq, $lambda = Opal.lambda, $range = Opal.range, $send2 = Opal.send2, $find_super = Opal.find_super, $alias = Opal.alias, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$;
3268
3269  Opal.add_stubs('module_eval,to_proc,===,raise,equal?,<,>,nil?,attr_reader,attr_writer,warn,attr_accessor,const_name?,class_variable_name!,pristine,const_name!,=~,new,inject,split,const_get,==,start_with?,!~,bind,call,class,frozen?,name,append_features,included,cover?,size,merge,compile,proc,any?,prepend_features,prepended,to_s,__id__,constants,include?,copy_class_variables,copy_constants,class_exec,module_exec,inspect');
3270  
3271  (function($base, $super, $parent_nesting) {
3272    var self = $klass($base, $super, 'Module');
3273
3274    var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
3275
3276    
3277    $defs(self, '$allocate', function $$allocate() {
3278      var self = this;
3279
3280      
3281      var module = Opal.allocate_module(nil, function(){});
3282      // Link the prototype of Module subclasses
3283      if (self !== Opal.Module) Object.setPrototypeOf(module, self.$$prototype);
3284      return module;
3285    
3286    });
3287    
3288    $def(self, '$initialize', function $$initialize() {
3289      var block = $$initialize.$$p || nil, self = this;
3290
3291      $$initialize.$$p = null;
3292      
3293      ;
3294      if ((block !== nil)) {
3295        return $send(self, 'module_eval', [], block.$to_proc())
3296      } else {
3297        return nil
3298      };
3299    });
3300    
3301    $def(self, '$===', function $Module_$eq_eq_eq$1(object) {
3302      var self = this;
3303
3304      
3305      if ($truthy(object == null)) {
3306        return false
3307      };
3308      return Opal.is_a(object, self);;
3309    });
3310    
3311    $def(self, '$<', function $Module_$lt$2(other) {
3312      var self = this;
3313
3314      
3315      if (!$eqeqeq($Module, other)) {
3316        $Kernel.$raise($$$('TypeError'), "compared with non class/module")
3317      };
3318      
3319      var working = self,
3320          ancestors,
3321          i, length;
3322
3323      if (working === other) {
3324        return false;
3325      }
3326
3327      for (i = 0, ancestors = Opal.ancestors(self), length = ancestors.length; i < length; i++) {
3328        if (ancestors[i] === other) {
3329          return true;
3330        }
3331      }
3332
3333      for (i = 0, ancestors = Opal.ancestors(other), length = ancestors.length; i < length; i++) {
3334        if (ancestors[i] === self) {
3335          return false;
3336        }
3337      }
3338
3339      return nil;
3340    ;
3341    });
3342    
3343    $def(self, '$<=', function $Module_$lt_eq$3(other) {
3344      var self = this, $ret_or_1 = nil;
3345
3346      if ($truthy(($ret_or_1 = self['$equal?'](other)))) {
3347        return $ret_or_1
3348      } else {
3349        return $rb_lt(self, other)
3350      }
3351    });
3352    
3353    $def(self, '$>', function $Module_$gt$4(other) {
3354      var self = this;
3355
3356      
3357      if (!$eqeqeq($Module, other)) {
3358        $Kernel.$raise($$$('TypeError'), "compared with non class/module")
3359      };
3360      return $rb_lt(other, self);
3361    });
3362    
3363    $def(self, '$>=', function $Module_$gt_eq$5(other) {
3364      var self = this, $ret_or_1 = nil;
3365
3366      if ($truthy(($ret_or_1 = self['$equal?'](other)))) {
3367        return $ret_or_1
3368      } else {
3369        return $rb_gt(self, other)
3370      }
3371    });
3372    
3373    $def(self, '$<=>', function $Module_$lt_eq_gt$6(other) {
3374      var self = this, lt = nil;
3375
3376      
3377      
3378      if (self === other) {
3379        return 0;
3380      }
3381    ;
3382      if (!$eqeqeq($Module, other)) {
3383        return nil
3384      };
3385      lt = $rb_lt(self, other);
3386      if ($truthy(lt['$nil?']())) {
3387        return nil
3388      };
3389      if ($truthy(lt)) {
3390        return -1
3391      } else {
3392        return 1
3393      };
3394    });
3395    
3396    $def(self, '$alias_method', function $$alias_method(newname, oldname) {
3397      var self = this;
3398
3399      
3400      $deny_frozen_access(self);
3401      newname = $coerce_to(newname, $$$('String'), 'to_str');
3402      oldname = $coerce_to(oldname, $$$('String'), 'to_str');
3403      Opal.alias(self, newname, oldname);
3404      return self;
3405    });
3406    
3407    $def(self, '$alias_native', function $$alias_native(mid, jsid) {
3408      var self = this;
3409
3410      
3411      if (jsid == null) jsid = mid;
3412      $deny_frozen_access(self);
3413      Opal.alias_native(self, mid, jsid);
3414      return self;
3415    }, -2);
3416    
3417    $def(self, '$ancestors', function $$ancestors() {
3418      var self = this;
3419
3420      return Opal.ancestors(self);
3421    });
3422    
3423    $def(self, '$append_features', function $$append_features(includer) {
3424      var self = this;
3425
3426      
3427      $deny_frozen_access(includer);
3428      Opal.append_features(self, includer);
3429      return self;
3430    });
3431    
3432    $def(self, '$attr_accessor', function $$attr_accessor($a) {
3433      var $post_args, names, self = this;
3434
3435      
3436      $post_args = $slice(arguments);
3437      names = $post_args;
3438      $send(self, 'attr_reader', $to_a(names));
3439      return $send(self, 'attr_writer', $to_a(names));
3440    }, -1);
3441    
3442    $def(self, '$attr', function $$attr($a) {
3443      var $post_args, args, self = this;
3444
3445      
3446      $post_args = $slice(arguments);
3447      args = $post_args;
3448      
3449      if (args.length == 2 && (args[1] === true || args[1] === false)) {
3450        self.$warn("optional boolean argument is obsoleted", $hash2(["uplevel"], {"uplevel": 1}))
3451
3452        args[1] ? self.$attr_accessor(args[0]) : self.$attr_reader(args[0]);
3453        return nil;
3454      }
3455    ;
3456      return $send(self, 'attr_reader', $to_a(args));
3457    }, -1);
3458    
3459    $def(self, '$attr_reader', function $$attr_reader($a) {
3460      var $post_args, names, self = this;
3461
3462      
3463      $post_args = $slice(arguments);
3464      names = $post_args;
3465      
3466      $deny_frozen_access(self);
3467
3468      var proto = self.$$prototype;
3469
3470      for (var i = names.length - 1; i >= 0; i--) {
3471        var name = names[i],
3472            id   = $jsid(name),
3473            ivar = $ivar(name);
3474
3475        var body = $return_ivar(ivar);
3476
3477        // initialize the instance variable as nil
3478        Opal.prop(proto, ivar, nil);
3479
3480        body.$$parameters = [];
3481        body.$$arity = 0;
3482
3483        Opal.defn(self, id, body);
3484      }
3485    ;
3486      return nil;
3487    }, -1);
3488    
3489    $def(self, '$attr_writer', function $$attr_writer($a) {
3490      var $post_args, names, self = this;
3491
3492      
3493      $post_args = $slice(arguments);
3494      names = $post_args;
3495      
3496      $deny_frozen_access(self);
3497
3498      var proto = self.$$prototype;
3499
3500      for (var i = names.length - 1; i >= 0; i--) {
3501        var name = names[i],
3502            id   = $jsid(name + '='),
3503            ivar = $ivar(name);
3504
3505        var body = $assign_ivar(ivar)
3506
3507        body.$$parameters = [['req']];
3508        body.$$arity = 1;
3509
3510        // initialize the instance variable as nil
3511        Opal.prop(proto, ivar, nil);
3512
3513        Opal.defn(self, id, body);
3514      }
3515    ;
3516      return nil;
3517    }, -1);
3518    
3519    $def(self, '$autoload', function $$autoload(const$, path) {
3520      var self = this;
3521
3522      
3523      $deny_frozen_access(self);
3524
3525      if (!$$('Opal')['$const_name?'](const$)) {
3526        $Kernel.$raise($$$('NameError'), "autoload must be constant name: " + (const$))
3527      }
3528
3529      if (path == "") {
3530        $Kernel.$raise($$$('ArgumentError'), "empty file name")
3531      }
3532
3533      if (!self.$$const.hasOwnProperty(const$)) {
3534        if (!self.$$autoload) {
3535          self.$$autoload = {};
3536        }
3537        Opal.const_cache_version++;
3538        self.$$autoload[const$] = { path: path, loaded: false, required: false, success: false, exception: false };
3539
3540        if (self.$const_added && !self.$const_added.$$pristine) {
3541          self.$const_added(const$);
3542        }
3543      }
3544      return nil;
3545    
3546    });
3547    
3548    $def(self, '$autoload?', function $Module_autoload$ques$7(const$) {
3549      var self = this;
3550
3551      
3552      if (self.$$autoload && self.$$autoload[const$] && !self.$$autoload[const$].required && !self.$$autoload[const$].success) {
3553        return self.$$autoload[const$].path;
3554      }
3555
3556      var ancestors = self.$ancestors();
3557
3558      for (var i = 0, length = ancestors.length; i < length; i++) {
3559        if (ancestors[i].$$autoload && ancestors[i].$$autoload[const$] && !ancestors[i].$$autoload[const$].required && !ancestors[i].$$autoload[const$].success) {
3560          return ancestors[i].$$autoload[const$].path;
3561        }
3562      }
3563      return nil;
3564    
3565    });
3566    
3567    $def(self, '$class_variables', function $$class_variables() {
3568      var self = this;
3569
3570      return Object.keys(Opal.class_variables(self));
3571    });
3572    
3573    $def(self, '$class_variable_get', function $$class_variable_get(name) {
3574      var self = this;
3575
3576      
3577      name = $Opal['$class_variable_name!'](name);
3578      return Opal.class_variable_get(self, name, false);;
3579    });
3580    
3581    $def(self, '$class_variable_set', function $$class_variable_set(name, value) {
3582      var self = this;
3583
3584      
3585      $deny_frozen_access(self);
3586      name = $Opal['$class_variable_name!'](name);
3587      return Opal.class_variable_set(self, name, value);;
3588    });
3589    
3590    $def(self, '$class_variable_defined?', function $Module_class_variable_defined$ques$8(name) {
3591      var self = this;
3592
3593      
3594      name = $Opal['$class_variable_name!'](name);
3595      return Opal.class_variables(self).hasOwnProperty(name);;
3596    });
3597    
3598    $def(self, '$const_added', $return_val(nil));
3599    $Opal.$pristine(self, "const_added");
3600    
3601    $def(self, '$remove_class_variable', function $$remove_class_variable(name) {
3602      var self = this;
3603
3604      
3605      $deny_frozen_access(self);
3606      name = $Opal['$class_variable_name!'](name);
3607      
3608      if (Opal.hasOwnProperty.call(self.$$cvars, name)) {
3609        var value = self.$$cvars[name];
3610        delete self.$$cvars[name];
3611        return value;
3612      } else {
3613        $Kernel.$raise($$$('NameError'), "cannot remove " + (name) + " for " + (self))
3614      }
3615    ;
3616    });
3617    
3618    $def(self, '$constants', function $$constants(inherit) {
3619      var self = this;
3620
3621      
3622      if (inherit == null) inherit = true;
3623      return Opal.constants(self, inherit);;
3624    }, -1);
3625    $defs(self, '$constants', function $$constants(inherit) {
3626      var self = this;
3627
3628      
3629      ;
3630      
3631      if (inherit == null) {
3632        var nesting = (self.$$nesting || []).concat($Object),
3633            constant, constants = {},
3634            i, ii;
3635
3636        for(i = 0, ii = nesting.length; i < ii; i++) {
3637          for (constant in nesting[i].$$const) {
3638            constants[constant] = true;
3639          }
3640        }
3641        return Object.keys(constants);
3642      } else {
3643        return Opal.constants(self, inherit)
3644      }
3645    ;
3646    }, -1);
3647    $defs(self, '$nesting', function $$nesting() {
3648      var self = this;
3649
3650      return self.$$nesting || [];
3651    });
3652    
3653    $def(self, '$const_defined?', function $Module_const_defined$ques$9(name, inherit) {
3654      var self = this;
3655
3656      
3657      if (inherit == null) inherit = true;
3658      name = $$('Opal')['$const_name!'](name);
3659      if (!$truthy(name['$=~']($$$($Opal, 'CONST_NAME_REGEXP')))) {
3660        $Kernel.$raise($$$('NameError').$new("wrong constant name " + (name), name))
3661      };
3662      
3663      var module, modules = [self], module_constants, i, ii;
3664
3665      // Add up ancestors if inherit is true
3666      if (inherit) {
3667        modules = modules.concat(Opal.ancestors(self));
3668
3669        // Add Object's ancestors if it's a module – modules have no ancestors otherwise
3670        if (self.$$is_module) {
3671          modules = modules.concat([$Object]).concat(Opal.ancestors($Object));
3672        }
3673      }
3674
3675      for (i = 0, ii = modules.length; i < ii; i++) {
3676        module = modules[i];
3677        if (module.$$const[name] != null) { return true; }
3678        if (
3679          module.$$autoload &&
3680          module.$$autoload[name] &&
3681          !module.$$autoload[name].required &&
3682          !module.$$autoload[name].success
3683        ) {
3684          return true;
3685        }
3686      }
3687
3688      return false;
3689    ;
3690    }, -2);
3691    
3692    $def(self, '$const_get', function $$const_get(name, inherit) {
3693      var self = this;
3694
3695      
3696      if (inherit == null) inherit = true;
3697      name = $$('Opal')['$const_name!'](name);
3698      
3699      if (name.indexOf('::') === 0 && name !== '::'){
3700        name = name.slice(2);
3701      }
3702    ;
3703      if ($truthy(name.indexOf('::') != -1 && name != '::')) {
3704        return $send(name.$split("::"), 'inject', [self], function $$10(o, c){
3705          
3706          if (o == null) o = nil;
3707          if (c == null) c = nil;
3708          return o.$const_get(c);})
3709      };
3710      if (!$truthy(name['$=~']($$$($Opal, 'CONST_NAME_REGEXP')))) {
3711        $Kernel.$raise($$$('NameError').$new("wrong constant name " + (name), name))
3712      };
3713      
3714      if (inherit) {
3715        return Opal.$$([self], name);
3716      } else {
3717        return Opal.const_get_local(self, name);
3718      }
3719    ;
3720    }, -2);
3721    
3722    $def(self, '$const_missing', function $$const_missing(name) {
3723      var self = this, full_const_name = nil;
3724
3725      
3726      full_const_name = ($eqeq(self, $Object) ? (name) : ("" + (self) + "::" + (name)));
3727      return $Kernel.$raise($$$('NameError').$new("uninitialized constant " + (full_const_name), name));
3728    });
3729    
3730    $def(self, '$const_set', function $$const_set(name, value) {
3731      var self = this;
3732
3733      
3734      $deny_frozen_access(self);
3735      name = $Opal['$const_name!'](name);
3736      if (($truthy(name['$!~']($$$($Opal, 'CONST_NAME_REGEXP'))) || ($truthy(name['$start_with?']("::"))))) {
3737        $Kernel.$raise($$$('NameError').$new("wrong constant name " + (name), name))
3738      };
3739      $const_set(self, name, value);
3740      return value;
3741    });
3742    
3743    $def(self, '$public_constant', $return_val(nil));
3744    
3745    $def(self, '$define_method', function $$define_method(name, method) {
3746      var block = $$define_method.$$p || nil, self = this, $ret_or_1 = nil, $ret_or_2 = nil;
3747
3748      $$define_method.$$p = null;
3749      
3750      ;
3751      ;
3752      
3753      $deny_frozen_access(self);
3754
3755      if (method === undefined && block === nil)
3756        $Kernel.$raise($$$('ArgumentError'), "tried to create a Proc object without a block")
3757    ;
3758      block = ($truthy(($ret_or_1 = block)) ? ($ret_or_1) : ($eqeqeq($$$('Proc'), ($ret_or_2 = method)) ? (method) : ($eqeqeq($$$('Method'), $ret_or_2) ? (method.$to_proc().$$unbound) : ($eqeqeq($$$('UnboundMethod'), $ret_or_2) ? ($lambda(function $$11($a){var $post_args, args, self = $$11.$$s == null ? this : $$11.$$s, bound = nil;
3759
3760        
3761        $post_args = $slice(arguments);
3762        args = $post_args;
3763        bound = method.$bind(self);
3764        return $send(bound, 'call', $to_a(args));}, {$$arity: -1, $$s: self})) : ($Kernel.$raise($$$('TypeError'), "wrong argument type " + (block.$class()) + " (expected Proc/Method)"))))));
3765      
3766      if (typeof(Proxy) !== 'undefined') {
3767        var meta = Object.create(null)
3768
3769        block.$$proxy_target = block
3770        block = new Proxy(block, {
3771          apply: function(target, self, args) {
3772            var old_name = target.$$jsid
3773            target.$$jsid = name;
3774            try {
3775              return target.apply(self, args);
3776            } catch(e) {
3777              if (e === target.$$brk || e === target.$$ret) return e.$v;
3778              throw e;
3779            } finally {
3780              target.$$jsid = old_name
3781            }
3782          }
3783        })
3784      }
3785
3786      block.$$jsid        = name;
3787      block.$$s           = null;
3788      block.$$def         = block;
3789      block.$$define_meth = true;
3790
3791      return Opal.defn(self, $jsid(name), block);
3792    ;
3793    }, -2);
3794    
3795    $def(self, '$freeze', function $$freeze() {
3796      var self = this;
3797
3798      
3799      if ($truthy(self['$frozen?']())) {
3800        return self
3801      };
3802      
3803      if (!self.hasOwnProperty('$$base_module')) { $prop(self, '$$base_module', null); }
3804
3805      return $freeze(self);
3806    ;
3807    });
3808    
3809    $def(self, '$remove_method', function $$remove_method($a) {
3810      var $post_args, names, self = this;
3811
3812      
3813      $post_args = $slice(arguments);
3814      names = $post_args;
3815      
3816      for (var i = 0; i < names.length; i++) {
3817        var name = names[i];
3818        if (!(typeof name === "string" || name.$$is_string)) {
3819          self.$raise($$$('TypeError'), "" + (self.$name()) + " is not a symbol nor a string")
3820        }
3821        $deny_frozen_access(self);
3822
3823        Opal.rdef(self, "$" + name);
3824      }
3825    ;
3826      return self;
3827    }, -1);
3828    
3829    $def(self, '$singleton_class?', function $Module_singleton_class$ques$12() {
3830      var self = this;
3831
3832      return !!self.$$is_singleton;
3833    });
3834    
3835    $def(self, '$include', function $$include($a) {
3836      var $post_args, mods, self = this;
3837
3838      
3839      $post_args = $slice(arguments);
3840      mods = $post_args;
3841      
3842      for (var i = mods.length - 1; i >= 0; i--) {
3843        var mod = mods[i];
3844
3845        if (!mod.$$is_module) {
3846          $Kernel.$raise($$$('TypeError'), "wrong argument type " + ((mod).$class()) + " (expected Module)");
3847        }
3848
3849        (mod).$append_features(self);
3850        (mod).$included(self);
3851      }
3852    ;
3853      return self;
3854    }, -1);
3855    
3856    $def(self, '$included_modules', function $$included_modules() {
3857      var self = this;
3858
3859      return Opal.included_modules(self);
3860    });
3861    
3862    $def(self, '$include?', function $Module_include$ques$13(mod) {
3863      var self = this;
3864
3865      
3866      if (!mod.$$is_module) {
3867        $Kernel.$raise($$$('TypeError'), "wrong argument type " + ((mod).$class()) + " (expected Module)");
3868      }
3869
3870      var i, ii, mod2, ancestors = Opal.ancestors(self);
3871
3872      for (i = 0, ii = ancestors.length; i < ii; i++) {
3873        mod2 = ancestors[i];
3874        if (mod2 === mod && mod2 !== self) {
3875          return true;
3876        }
3877      }
3878
3879      return false;
3880    
3881    });
3882    
3883    $def(self, '$instance_method', function $$instance_method(name) {
3884      var self = this;
3885
3886      
3887      var meth = self.$$prototype[$jsid(name)];
3888
3889      if (!meth || meth.$$stub) {
3890        $Kernel.$raise($$$('NameError').$new("undefined method `" + (name) + "' for class `" + (self.$name()) + "'", name));
3891      }
3892
3893      return $$$('UnboundMethod').$new(self, meth.$$owner || self, meth, name);
3894    
3895    });
3896    
3897    $def(self, '$instance_methods', function $$instance_methods(include_super) {
3898      var self = this;
3899
3900      
3901      if (include_super == null) include_super = true;
3902      
3903      if ($truthy(include_super)) {
3904        return Opal.instance_methods(self);
3905      } else {
3906        return Opal.own_instance_methods(self);
3907      }
3908    ;
3909    }, -1);
3910    
3911    $def(self, '$included', $return_val(nil));
3912    
3913    $def(self, '$extended', $return_val(nil));
3914    
3915    $def(self, '$extend_object', function $$extend_object(object) {
3916      
3917      
3918      $deny_frozen_access(object);
3919      return nil;
3920    });
3921    
3922    $def(self, '$method_added', function $$method_added($a) {
3923      var $post_args, $fwd_rest;
3924
3925      
3926      $post_args = $slice(arguments);
3927      $fwd_rest = $post_args;
3928      return nil;
3929    }, -1);
3930    
3931    $def(self, '$method_removed', function $$method_removed($a) {
3932      var $post_args, $fwd_rest;
3933
3934      
3935      $post_args = $slice(arguments);
3936      $fwd_rest = $post_args;
3937      return nil;
3938    }, -1);
3939    
3940    $def(self, '$method_undefined', function $$method_undefined($a) {
3941      var $post_args, $fwd_rest;
3942
3943      
3944      $post_args = $slice(arguments);
3945      $fwd_rest = $post_args;
3946      return nil;
3947    }, -1);
3948    
3949    $def(self, '$module_eval', function $$module_eval($a) {
3950      var block = $$module_eval.$$p || nil, $post_args, args, $b, self = this, string = nil, file = nil, _lineno = nil, default_eval_options = nil, $ret_or_1 = nil, compiling_options = nil, compiled = nil;
3951
3952      $$module_eval.$$p = null;
3953      
3954      ;
3955      $post_args = $slice(arguments);
3956      args = $post_args;
3957      if (($truthy(block['$nil?']()) && ($truthy(!!Opal.compile)))) {
3958        
3959        if (!$truthy($range(1, 3, false)['$cover?'](args.$size()))) {
3960          $Kernel.$raise($$$('ArgumentError'), "wrong number of arguments (0 for 1..3)")
3961        };
3962        $b = [].concat($to_a(args)), (string = ($b[0] == null ? nil : $b[0])), (file = ($b[1] == null ? nil : $b[1])), (_lineno = ($b[2] == null ? nil : $b[2])), $b;
3963        default_eval_options = $hash2(["file", "eval"], {"file": ($truthy(($ret_or_1 = file)) ? ($ret_or_1) : ("(eval)")), "eval": true});
3964        compiling_options = Opal.hash({ arity_check: false }).$merge(default_eval_options);
3965        compiled = $Opal.$compile(string, compiling_options);
3966        block = $send($Kernel, 'proc', [], function $$14(){var self = $$14.$$s == null ? this : $$14.$$s;
3967
3968          return new Function("Opal,self", "return " + compiled)(Opal, self);}, {$$s: self});
3969      } else if ($truthy(args['$any?']())) {
3970        $Kernel.$raise($$$('ArgumentError'), "" + ("wrong number of arguments (" + (args.$size()) + " for 0)") + "\n\n  NOTE:If you want to enable passing a String argument please add \"require 'opal-parser'\" to your script\n")
3971      };
3972      
3973      var old = block.$$s,
3974          result;
3975
3976      block.$$s = null;
3977      result = block.apply(self, [self]);
3978      block.$$s = old;
3979
3980      return result;
3981    ;
3982    }, -1);
3983    
3984    $def(self, '$module_exec', function $$module_exec($a) {
3985      var block = $$module_exec.$$p || nil, $post_args, args, self = this;
3986
3987      $$module_exec.$$p = null;
3988      
3989      ;
3990      $post_args = $slice(arguments);
3991      args = $post_args;
3992      
3993      if (block === nil) {
3994        $Kernel.$raise($$$('LocalJumpError'), "no block given")
3995      }
3996
3997      var block_self = block.$$s, result;
3998
3999      block.$$s = null;
4000      result = block.apply(self, args);
4001      block.$$s = block_self;
4002
4003      return result;
4004    ;
4005    }, -1);
4006    
4007    $def(self, '$method_defined?', function $Module_method_defined$ques$15(method) {
4008      var self = this;
4009
4010      
4011      var body = self.$$prototype[$jsid(method)];
4012      return (!!body) && !body.$$stub;
4013    
4014    });
4015    
4016    $def(self, '$module_function', function $$module_function($a) {
4017      var $post_args, methods, self = this;
4018
4019      
4020      $post_args = $slice(arguments);
4021      methods = $post_args;
4022      
4023      $deny_frozen_access(self);
4024
4025      if (methods.length === 0) {
4026        self.$$module_function = true;
4027        return nil;
4028      }
4029      else {
4030        for (var i = 0, length = methods.length; i < length; i++) {
4031          var meth = methods[i],
4032              id   = $jsid(meth),
4033              func = self.$$prototype[id];
4034
4035          Opal.defs(self, id, func);
4036        }
4037        return methods.length === 1 ? methods[0] : methods;
4038      }
4039
4040      return self;
4041    ;
4042    }, -1);
4043    
4044    $def(self, '$name', function $$name() {
4045      var self = this;
4046
4047      
4048      if (self.$$full_name) {
4049        return self.$$full_name;
4050      }
4051
4052      var result = [], base = self;
4053
4054      while (base) {
4055        // Give up if any of the ancestors is unnamed
4056        if (base.$$name === nil || base.$$name == null) return nil;
4057
4058        result.unshift(base.$$name);
4059
4060        base = base.$$base_module;
4061
4062        if (base === $Object) {
4063          break;
4064        }
4065      }
4066
4067      if (result.length === 0) {
4068        return nil;
4069      }
4070
4071      return self.$$full_name = result.join('::');
4072    
4073    });
4074    
4075    $def(self, '$prepend', function $$prepend($a) {
4076      var $post_args, mods, self = this;
4077
4078      
4079      $post_args = $slice(arguments);
4080      mods = $post_args;
4081      
4082      if (mods.length === 0) {
4083        $Kernel.$raise($$$('ArgumentError'), "wrong number of arguments (given 0, expected 1+)")
4084      }
4085
4086      for (var i = mods.length - 1; i >= 0; i--) {
4087        var mod = mods[i];
4088
4089        if (!mod.$$is_module) {
4090          $Kernel.$raise($$$('TypeError'), "wrong argument type " + ((mod).$class()) + " (expected Module)");
4091        }
4092
4093        (mod).$prepend_features(self);
4094        (mod).$prepended(self);
4095      }
4096    ;
4097      return self;
4098    }, -1);
4099    
4100    $def(self, '$prepend_features', function $$prepend_features(prepender) {
4101      var self = this;
4102
4103      
4104      
4105      $deny_frozen_access(prepender);
4106
4107      if (!self.$$is_module) {
4108        $Kernel.$raise($$$('TypeError'), "wrong argument type " + (self.$class()) + " (expected Module)");
4109      }
4110
4111      Opal.prepend_features(self, prepender)
4112    ;
4113      return self;
4114    });
4115    
4116    $def(self, '$prepended', $return_val(nil));
4117    
4118    $def(self, '$remove_const', function $$remove_const(name) {
4119      var self = this;
4120
4121      
4122      $deny_frozen_access(self);
4123      return Opal.const_remove(self, name);;
4124    });
4125    
4126    $def(self, '$to_s', function $$to_s() {
4127      var self = this, $ret_or_1 = nil;
4128
4129      if ($truthy(($ret_or_1 = Opal.Module.$name.call(self)))) {
4130        return $ret_or_1
4131      } else {
4132        return "#<" + (self.$$is_module ? 'Module' : 'Class') + ":0x" + (self.$__id__().$to_s(16)) + ">"
4133      }
4134    });
4135    
4136    $def(self, '$undef_method', function $$undef_method($a) {
4137      var $post_args, names, self = this;
4138
4139      
4140      $post_args = $slice(arguments);
4141      names = $post_args;
4142      
4143      for (var i = 0; i < names.length; i++) {
4144        var name = names[i];
4145        if (!(typeof name === "string" || name.$$is_string)) {
4146          self.$raise($$$('TypeError'), "" + (self.$name()) + " is not a symbol nor a string")
4147        }
4148        $deny_frozen_access(self);
4149
4150        Opal.udef(self, "$" + names[i]);
4151      }
4152    ;
4153      return self;
4154    }, -1);
4155    
4156    $def(self, '$instance_variables', function $$instance_variables() {
4157      var self = this, consts = nil;
4158
4159      
4160      consts = (Opal.Module.$$nesting = $nesting, self.$constants());
4161      
4162      var result = [];
4163
4164      for (var name in self) {
4165        if (self.hasOwnProperty(name) && name.charAt(0) !== '$' && name !== 'constructor' && !consts['$include?'](name)) {
4166          result.push('@' + name);
4167        }
4168      }
4169
4170      return result;
4171    ;
4172    });
4173    
4174    $def(self, '$dup', function $$dup() {
4175      var $yield = $$dup.$$p || nil, self = this, copy = nil;
4176
4177      $$dup.$$p = null;
4178      
4179      copy = $send2(self, $find_super(self, 'dup', $$dup, false, true), 'dup', [], $yield);
4180      copy.$copy_class_variables(self);
4181      copy.$copy_constants(self);
4182      return copy;
4183    });
4184    
4185    $def(self, '$copy_class_variables', function $$copy_class_variables(other) {
4186      var self = this;
4187
4188      
4189      for (var name in other.$$cvars) {
4190        self.$$cvars[name] = other.$$cvars[name];
4191      }
4192    
4193    });
4194    
4195    $def(self, '$copy_constants', function $$copy_constants(other) {
4196      var self = this;
4197
4198      
4199      var name, other_constants = other.$$const;
4200
4201      for (name in other_constants) {
4202        $const_set(self, name, other_constants[name]);
4203      }
4204    
4205    });
4206    
4207    $def(self, '$refine', function $$refine(klass) {
4208      var block = $$refine.$$p || nil, $a, self = this, refinement_module = nil, m = nil, klass_id = nil;
4209
4210      $$refine.$$p = null;
4211      
4212      ;
4213      $a = [self, nil, nil], (refinement_module = $a[0]), (m = $a[1]), (klass_id = $a[2]), $a;
4214      
4215      klass_id = Opal.id(klass);
4216      if (typeof self.$$refine_modules === "undefined") {
4217        self.$$refine_modules = Object.create(null);
4218      }
4219      if (typeof self.$$refine_modules[klass_id] === "undefined") {
4220        m = self.$$refine_modules[klass_id] = $$$('Refinement').$new();
4221      }
4222      else {
4223        m = self.$$refine_modules[klass_id];
4224      }
4225      m.refinement_module = refinement_module
4226      m.refined_class = klass
4227    ;
4228      $send(m, 'class_exec', [], block.$to_proc());
4229      return m;
4230    });
4231    
4232    $def(self, '$refinements', function $$refinements() {
4233      var self = this;
4234
4235      
4236      var refine_modules = self.$$refine_modules, hash = $hash2([], {});;
4237      if (typeof refine_modules === "undefined") return hash;
4238      for (var id in refine_modules) {
4239        hash['$[]='](refine_modules[id].refined_class, refine_modules[id]);
4240      }
4241      return hash;
4242    
4243    });
4244    
4245    $def(self, '$using', function $$using(mod) {
4246      
4247      return $Kernel.$raise("Module#using is not permitted in methods")
4248    });
4249    $alias(self, "class_eval", "module_eval");
4250    $alias(self, "class_exec", "module_exec");
4251    return $alias(self, "inspect", "to_s");
4252  })('::', null, $nesting);
4253  return (function($base, $super) {
4254    var self = $klass($base, $super, 'Refinement');
4255
4256    var $proto = self.$$prototype;
4257
4258    $proto.refinement_module = $proto.refined_class = nil;
4259    
4260    self.$attr_reader("refined_class");
4261    return $def(self, '$inspect', function $$inspect() {
4262      var $yield = $$inspect.$$p || nil, self = this;
4263
4264      $$inspect.$$p = null;
4265      if ($truthy(self.refinement_module)) {
4266        return "#<refinement:" + (self.refined_class.$inspect()) + "@" + (self.refinement_module.$inspect()) + ">"
4267      } else {
4268        return $send2(self, $find_super(self, 'inspect', $$inspect, false, true), 'inspect', [], $yield)
4269      }
4270    });
4271  })('::', $Module);
4272};
4273
4274Opal.modules["corelib/class"] = function(Opal) {/* Generated by Opal 1.7.3 */
4275  var $klass = Opal.klass, $send = Opal.send, $defs = Opal.defs, $def = Opal.def, $rb_plus = Opal.rb_plus, $return_val = Opal.return_val, $slice = Opal.slice, $send2 = Opal.send2, $find_super = Opal.find_super, $Kernel = Opal.Kernel, $alias = Opal.alias, self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$;
4276
4277  Opal.add_stubs('require,class_eval,to_proc,+,subclasses,flatten,map,initialize_copy,allocate,name,to_s,raise');
4278  
4279  self.$require("corelib/module");
4280  return (function($base, $super, $parent_nesting) {
4281    var self = $klass($base, $super, 'Class');
4282
4283    var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
4284
4285    
4286    $defs(self, '$new', function $Class_new$1(superclass) {
4287      var block = $Class_new$1.$$p || nil;
4288
4289      $Class_new$1.$$p = null;
4290      
4291      ;
4292      if (superclass == null) superclass = $$('Object');
4293      
4294      if (!superclass.$$is_class) {
4295        throw Opal.TypeError.$new("superclass must be a Class");
4296      }
4297
4298      var klass = Opal.allocate_class(nil, superclass);
4299      superclass.$inherited(klass);
4300      ((block !== nil) ? ($send((klass), 'class_eval', [], block.$to_proc())) : nil)
4301      return klass;
4302    ;
4303    }, -1);
4304    
4305    $def(self, '$allocate', function $$allocate() {
4306      var self = this;
4307
4308      
4309      var obj = new self.$$constructor();
4310      obj.$$id = Opal.uid();
4311      return obj;
4312    
4313    });
4314    
4315    $def(self, '$descendants', function $$descendants() {
4316      var self = this;
4317
4318      return $rb_plus(self.$subclasses(), $send(self.$subclasses(), 'map', [], "desce
4318ndants".$to_proc()).$flatten())
4319    });
4320    
4321    $def(self, '$inherited', $return_val(nil));
4322    
4323    $def(self, '$initialize_dup', function $$initialize_dup(original) {
4324      var self = this;
4325
4326      
4327      self.$initialize_copy(original);
4328      
4329      self.$$name = null;
4330      self.$$full_name = null;
4331    ;
4332    });
4333    
4334    $def(self, '$new', function $Class_new$2($a) {
4335      var block = $Class_new$2.$$p || nil, $post_args, args, self = this;
4336
4337      $Class_new$2.$$p = null;
4338      
4339      ;
4340      $post_args = $slice(arguments);
4341      args = $post_args;
4342      
4343      var object = self.$allocate();
4344      Opal.send(object, object.$initialize, args, block);
4345      return object;
4346    ;
4347    }, -1);
4348    
4349    $def(self, '$subclasses', function $$subclasses() {
4350      var self = this;
4351
4352      
4353      if (typeof WeakRef !== 'undefined') {
4354        var i, subclass, out = [];
4355        for (i = 0; i < self.$$subclasses.length; i++) {
4356          subclass = self.$$subclasses[i].deref();
4357          if (subclass !== undefined) {
4358            out.push(subclass);
4359          }
4360        }
4361        return out;
4362      }
4363      else {
4364        return self.$$subclasses;
4365      }
4366    
4367    });
4368    
4369    $def(self, '$superclass', function $$superclass() {
4370      var self = this;
4371
4372      return self.$$super || nil;
4373    });
4374    
4375    $def(self, '$to_s', function $$to_s() {
4376      var $yield = $$to_s.$$p || nil, self = this;
4377
4378      $$to_s.$$p = null;
4379      
4380      var singleton_of = self.$$singleton_of;
4381
4382      if (singleton_of && singleton_of.$$is_a_module) {
4383        return "#<Class:" + ((singleton_of).$name()) + ">";
4384      }
4385      else if (singleton_of) {
4386        // a singleton class created from an object
4387        return "#<Class:#<" + ((singleton_of.$$class).$name()) + ":0x" + ((Opal.id(singleton_of)).$to_s(16)) + ">>";
4388      }
4389
4390      return $send2(self, $find_super(self, 'to_s', $$to_s, false, true), 'to_s', [], null);
4391    
4392    });
4393    
4394    $def(self, '$attached_object', function $$attached_object() {
4395      var self = this;
4396
4397      
4398      if (self.$$singleton_of != null) {
4399        return self.$$singleton_of;
4400      }
4401      else {
4402        $Kernel.$raise($$$('TypeError'), "`" + (self) + "' is not a singleton class")
4403      }
4404    
4405    });
4406    return $alias(self, "inspect", "to_s");
4407  })('::', null, $nesting);
4408};
4409
4410Opal.modules["corelib/basic_object"] = function(Opal) {/* Generated by Opal 1.7.3 */
4411  "use strict";
4412  var $klass = Opal.klass, $slice = Opal.slice, $def = Opal.def, $alias = Opal.alias, $return_val = Opal.return_val, $Opal = Opal.Opal, $truthy = Opal.truthy, $range = Opal.range, $Kernel = Opal.Kernel, $to_a = Opal.to_a, $hash2 = Opal.hash2, $send = Opal.send, $eqeq = Opal.eqeq, $rb_ge = Opal.rb_ge, nil = Opal.nil, $$$ = Opal.$$$;
4413
4414  Opal.add_stubs('==,raise,inspect,pristine,!,nil?,cover?,size,merge,compile,proc,[],first,>=,length,instance_variable_get,any?,new,caller');
4415  return (function($base, $super) {
4416    var self = $klass($base, $super, 'BasicObject');
4417
4418    
4419    
4420    
4421    $def(self, '$initialize', function $$initialize($a) {
4422      var $post_args, $fwd_rest;
4423
4424      
4425      $post_args = $slice(arguments);
4426      $fwd_rest = $post_args;
4427      return nil;
4428    }, -1);
4429    
4430    $def(self, '$==', function $BasicObject_$eq_eq$1(other) {
4431      var self = this;
4432
4433      return self === other;
4434    });
4435    
4436    $def(self, '$eql?', function $BasicObject_eql$ques$2(other) {
4437      var self = this;
4438
4439      return self['$=='](other)
4440    });
4441    $alias(self, "equal?", "==");
4442    
4443    $def(self, '$__id__', function $$__id__() {
4444      var self = this;
4445
4446      
4447      if (self.$$id != null) {
4448        return self.$$id;
4449      }
4450      Opal.prop(self, '$$id', Opal.uid());
4451      return self.$$id;
4452    
4453    });
4454    
4455    $def(self, '$__send__', function $$__send__(symbol, $a) {
4456      var block = $$__send__.$$p || nil, $post_args, args, self = this;
4457
4458      $$__send__.$$p = null;
4459      
4460      ;
4461      $post_args = $slice(arguments, 1);
4462      args = $post_args;
4463      
4464      if (!symbol.$$is_string) {
4465        self.$raise($$$('TypeError'), "" + (self.$inspect()) + " is not a symbol nor a string")
4466      }
4467
4468      var func = self[Opal.jsid(symbol)];
4469
4470      if (func) {
4471        if (block !== nil) {
4472          func.$$p = block;
4473        }
4474
4475        return func.apply(self, args);
4476      }
4477
4478      if (block !== nil) {
4479        self.$method_missing.$$p = block;
4480      }
4481
4482      return self.$method_missing.apply(self, [symbol].concat(args));
4483    ;
4484    }, -2);
4485    
4486    $def(self, '$!', $return_val(false));
4487    $Opal.$pristine("!");
4488    
4489    $def(self, '$!=', function $BasicObject_$not_eq$3(other) {
4490      var self = this;
4491
4492      return self['$=='](other)['$!']()
4493    });
4494    
4495    $def(self, '$instance_eval', function $$instance_eval($a) {
4496      var block = $$instance_eval.$$p || nil, $post_args, args, $b, self = this, string = nil, file = nil, _lineno = nil, default_eval_options = nil, $ret_or_1 = nil, compiling_options = nil, compiled = nil;
4497
4498      $$instance_eval.$$p = null;
4499      
4500      ;
4501      $post_args = $slice(arguments);
4502      args = $post_args;
4503      if (($truthy(block['$nil?']()) && ($truthy(!!Opal.compile)))) {
4504        
4505        if (!$truthy($range(1, 3, false)['$cover?'](args.$size()))) {
4506          $Kernel.$raise($$$('ArgumentError'), "wrong number of arguments (0 for 1..3)")
4507        };
4508        $b = [].concat($to_a(args)), (string = ($b[0] == null ? nil : $b[0])), (file = ($b[1] == null ? nil : $b[1])), (_lineno = ($b[2] == null ? nil : $b[2])), $b;
4509        default_eval_options = $hash2(["file", "eval"], {"file": ($truthy(($ret_or_1 = file)) ? ($ret_or_1) : ("(eval)")), "eval": true});
4510        compiling_options = Opal.hash({ arity_check: false }).$merge(default_eval_options);
4511        compiled = $Opal.$compile(string, compiling_options);
4512        block = $send($Kernel, 'proc', [], function $$4(){var self = $$4.$$s == null ? this : $$4.$$s;
4513
4514          return new Function("Opal,self", "return " + compiled)(Opal, self);}, {$$s: self});
4515      } else if ((($truthy(block['$nil?']()) && ($truthy($rb_ge(args.$length(), 1)))) && ($eqeq(args.$first()['$[]'](0), "@")))) {
4516        return self.$instance_variable_get(args.$first())
4517      } else if ($truthy(args['$any?']())) {
4518        $Kernel.$raise($$$('ArgumentError'), "wrong number of arguments (" + (args.$size()) + " for 0)")
4519      };
4520      
4521      var old = block.$$s,
4522          result;
4523
4524      block.$$s = null;
4525
4526      // Need to pass $$eval so that method definitions know if this is
4527      // being done on a class/module. Cannot be compiler driven since
4528      // send(:instance_eval) needs to work.
4529      if (self.$$is_a_module) {
4530        self.$$eval = true;
4531        try {
4532          result = block.call(self, self);
4533        }
4534        finally {
4535          self.$$eval = false;
4536        }
4537      }
4538      else {
4539        result = block.call(self, self);
4540      }
4541
4542      block.$$s = old;
4543
4544      return result;
4545    ;
4546    }, -1);
4547    
4548    $def(self, '$instance_exec', function $$instance_exec($a) {
4549      var block = $$instance_exec.$$p || nil, $post_args, args, self = this;
4550
4551      $$instance_exec.$$p = null;
4552      
4553      ;
4554      $post_args = $slice(arguments);
4555      args = $post_args;
4556      if (!$truthy(block)) {
4557        $Kernel.$raise($$$('ArgumentError'), "no block given")
4558      };
4559      
4560      var block_self = block.$$s,
4561          result;
4562
4563      block.$$s = null;
4564
4565      if (self.$$is_a_module) {
4566        self.$$eval = true;
4567        try {
4568          result = block.apply(self, args);
4569        }
4570        finally {
4571          self.$$eval = false;
4572        }
4573      }
4574      else {
4575        result = block.apply(self, args);
4576      }
4577
4578      block.$$s = block_self;
4579
4580      return result;
4581    ;
4582    }, -1);
4583    
4584    $def(self, '$singleton_method_added', function $$singleton_method_added($a) {
4585      var $post_args, $fwd_rest;
4586
4587      
4588      $post_args = $slice(arguments);
4589      $fwd_rest = $post_args;
4590      return nil;
4591    }, -1);
4592    
4593    $def(self, '$singleton_method_removed', function $$singleton_method_removed($a) {
4594      var $post_args, $fwd_rest;
4595
4596      
4597      $post_args = $slice(arguments);
4598      $fwd_rest = $post_args;
4599      return nil;
4600    }, -1);
4601    
4602    $def(self, '$singleton_method_undefined', function $$singleton_method_undefined($a) {
4603      var $post_args, $fwd_rest;
4604
4605      
4606      $post_args = $slice(arguments);
4607      $fwd_rest = $post_args;
4608      return nil;
4609    }, -1);
4610    
4611    $def(self, '$method_missing', function $$method_missing(symbol, $a) {
4612      var block = $$method_missing.$$p || nil, $post_args, args, self = this, inspect_result = nil;
4613
4614      $$method_missing.$$p = null;
4615      
4616      ;
4617      $post_args = $slice(arguments, 1);
4618      args = $post_args;
4619      inspect_result = $Opal.$inspect(self);
4620      return $Kernel.$raise($$$('NoMethodError').$new("undefined method `" + (symbol) + "' for " + (inspect_result), symbol, args), nil, $Kernel.$caller(1));
4621    }, -2);
4622    $Opal.$pristine(self, "method_missing");
4623    return $def(self, '$respond_to_missing?', function $BasicObject_respond_to_missing$ques$5(method_name, include_all) {
4624      
4625      
4626      if (include_all == null) include_all = false;
4627      return false;
4628    }, -2);
4629  })('::', null)
4630};
4631
4632Opal.modules["corelib/kernel"] = function(Opal) {/* Generated by Opal 1.7.3 */
4633  "use strict";
4634  var $truthy = Opal.truthy, $coerce_to = Opal.coerce_to, $respond_to = Opal.respond_to, $Opal = Opal.Opal, $deny_frozen_access = Opal.deny_frozen_access, $freeze = Opal.freeze, $freeze_props = Opal.freeze_props, $jsid = Opal.jsid, $module = Opal.module, $return_val = Opal.return_val, $def = Opal.def, $Kernel = Opal.Kernel, $gvars = Opal.gvars, $slice = Opal.slice, $send = Opal.send, $to_a = Opal.to_a, $ensure_kwargs = Opal.ensure_kwargs, $eqeq = Opal.eqeq, $hash2 = Opal.hash2, $rb_plus = Opal.rb_plus, $eqeqeq = Opal.eqeqeq, $return_self = Opal.return_self, $rb_le = Opal.rb_le, $extract_kwargs = Opal.extract_kwargs, $rb_lt = Opal.rb_lt, $Object = Opal.Object, $alias = Opal.alias, $klass = Opal.klass, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$;
4635
4636  Opal.add_stubs('!,=~,==,object_id,raise,new,class,coerce_to?,<<,map,caller,nil?,allocate,copy_instance_variables,copy_singleton_methods,initialize_clone,frozen?,freeze,initialize_copy,define_method,singleton_class,to_proc,initialize_dup,for,empty?,pop,call,append_features,extend_object,extended,gets,__id__,include?,each,instance_variables,instance_variable_get,inspect,+,to_s,instance_variable_name!,respond_to?,to_int,coerce_to!,Integer,===,enum_for,result,any?,print,format,puts,<=,length,[],readline,<,first,split,to_str,exception,backtrace,rand,respond_to_missing?,pristine,try_convert!,expand_path,join,start_with?,new_seed,srand,tag,value,open,is_a?,__send__,yield_self,include');
4637  
4638  (function($base, $parent_nesting) {
4639    var self = $module($base, 'Kernel');
4640
4641    var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
4642
4643    
4644    
4645    $def(self, '$=~', $return_val(false));
4646    
4647    $def(self, '$!~', function $Kernel_$excl_tilde$1(obj) {
4648      var self = this;
4649
4650      return self['$=~'](obj)['$!']()
4651    });
4652    
4653    $def(self, '$===', function $Kernel_$eq_eq_eq$2(other) {
4654      var self = this, $ret_or_1 = nil;
4655
4656      if ($truthy(($ret_or_1 = self.$object_id()['$=='](other.$object_id())))) {
4657        return $ret_or_1
4658      } else {
4659        return self['$=='](other)
4660      }
4661    });
4662    
4663    $def(self, '$<=>', function $Kernel_$lt_eq_gt$3(other) {
4664      var self = this;
4665
4666      
4667      // set guard for infinite recursion
4668      self.$$comparable = true;
4669
4670      var x = self['$=='](other);
4671
4672      if (x && x !== nil) {
4673        return 0;
4674      }
4675
4676      return nil;
4677    
4678    });
4679    
4680    $def(self, '$method', function $$method(name) {
4681      var self = this;
4682
4683      
4684      var meth = self[$jsid(name)];
4685
4686      if (!meth || meth.$$stub) {
4687        $Kernel.$raise($$$('NameError').$new("undefined method `" + (name) + "' for class `" + (self.$class()) + "'", name));
4688      }
4689
4690      return $$$('Method').$new(self, meth.$$owner || self.$class(), meth, name);
4691    
4692    });
4693    
4694    $def(self, '$methods', function $$methods(all) {
4695      var self = this;
4696
4697      
4698      if (all == null) all = true;
4699      
4700      if ($truthy(all)) {
4701        return Opal.methods(self);
4702      } else {
4703        return Opal.own_methods(self);
4704      }
4705    ;
4706    }, -1);
4707    
4708    $def(self, '$public_methods', function $$public_methods(all) {
4709      var self = this;
4710
4711      
4712      if (all == null) all = true;
4713      
4714      if ($truthy(all)) {
4715        return Opal.methods(self);
4716      } else {
4717        return Opal.receiver_methods(self);
4718      }
4719    ;
4720    }, -1);
4721    
4722    $def(self, '$Array', function $$Array(object) {
4723      
4724      
4725      var coerced;
4726
4727      if (object === nil) {
4728        return [];
4729      }
4730
4731      if (object.$$is_array) {
4732        return object;
4733      }
4734
4735      coerced = $Opal['$coerce_to?'](object, $$$('Array'), "to_ary");
4736      if (coerced !== nil) { return coerced; }
4737
4738      coerced = $Opal['$coerce_to?'](object, $$$('Array'), "to_a");
4739      if (coerced !== nil) { return coerced; }
4740
4741      return [object];
4742    
4743    });
4744    
4745    $def(self, '$at_exit', function $$at_exit() {
4746      var block = $$at_exit.$$p || nil, $ret_or_1 = nil;
4747      if ($gvars.__at_exit__ == null) $gvars.__at_exit__ = nil;
4748
4749      $$at_exit.$$p = null;
4750      
4751      ;
4752      $gvars.__at_exit__ = ($truthy(($ret_or_1 = $gvars.__at_exit__)) ? ($ret_or_1) : ([]));
4753      $gvars.__at_exit__['$<<'](block);
4754      return block;
4755    });
4756    
4757    $def(self, '$caller', function $$caller(start, length) {
4758      
4759      
4760      if (start == null) start = 1;
4761      if (length == null) length = nil;
4762      
4763      var stack, result;
4764
4765      stack = new Error().$backtrace();
4766      result = [];
4767
4768      for (var i = start + 1, ii = stack.length; i < ii; i++) {
4769        if (!stack[i].match(/runtime\.js/)) {
4770          result.push(stack[i]);
4771        }
4772      }
4773      if (length != nil) result = result.slice(0, length);
4774      return result;
4775    ;
4776    }, -1);
4777    
4778    $def(self, '$caller_locations', function $$caller_locations($a) {
4779      var $post_args, args, self = this;
4780
4781      
4782      $post_args = $slice(arguments);
4783      args = $post_args;
4784      return $send($send(self, 'caller', $to_a(args)), 'map', [], function $$4(loc){
4785        
4786        if (loc == null) loc = nil;
4787        return $$$($$$($$$('Thread'), 'Backtrace'), 'Location').$new(loc);});
4788    }, -1);
4789    
4790    $def(self, '$class', function $Kernel_class$5() {
4791      var self = this;
4792
4793      return self.$$class;
4794    });
4795    
4796    $def(self, '$copy_instance_variables', function $$copy_instance_variables(other) {
4797      var self = this;
4798
4799      
4800      var keys = Object.keys(other), i, ii, name;
4801      for (i = 0, ii = keys.length; i < ii; i++) {
4802        name = keys[i];
4803        if (name.charAt(0) !== '$' && other.hasOwnProperty(name)) {
4804          self[name] = other[name];
4805        }
4806      }
4807    
4808    });
4809    
4810    $def(self, '$copy_singleton_methods', function $$copy_singleton_methods(other) {
4811      var self = this;
4812
4813      
4814      var i, name, names, length;
4815
4816      if (other.hasOwnProperty('$$meta') && other.$$meta !== null) {
4817        var other_singleton_class = Opal.get_singleton_class(other);
4818        var self_singleton_class = Opal.get_singleton_class(self);
4819        names = Object.getOwnPropertyNames(other_singleton_class.$$prototype);
4820
4821        for (i = 0, length = names.length; i < length; i++) {
4822          name = names[i];
4823          if (Opal.is_method(name)) {
4824            self_singleton_class.$$prototype[name] = other_singleton_class.$$prototype[name];
4825          }
4826        }
4827
4828        self_singleton_class.$$const = Object.assign({}, other_singleton_class.$$const);
4829        Object.setPrototypeOf(
4830          self_singleton_class.$$prototype,
4831          Object.getPrototypeOf(other_singleton_class.$$prototype)
4832        );
4833      }
4834
4835      for (i = 0, names = Object.getOwnPropertyNames(other), length = names.length; i < length; i++) {
4836        name = names[i];
4837        if (name.charAt(0) === '$' && name.charAt(1) !== '$' && other.hasOwnProperty(name)) {
4838          self[name] = other[name];
4839        }
4840      }
4841    
4842    });
4843    
4844    $def(self, '$clone', function $$clone($kwargs) {
4845      var freeze, self = this, copy = nil;
4846
4847      
4848      $kwargs = $ensure_kwargs($kwargs);
4849      
4850      freeze = $kwargs.$$smap["freeze"];if (freeze == null) freeze = nil;
4851      if (!(($truthy(freeze['$nil?']()) || ($eqeq(freeze, true))) || ($eqeq(freeze, false)))) {
4852        self.$raise($$('ArgumentError'), "unexpected value for freeze: " + (freeze.$class()))
4853      };
4854      copy = self.$class().$allocate();
4855      copy.$copy_instance_variables(self);
4856      copy.$copy_singleton_methods(self);
4857      copy.$initialize_clone(self, $hash2(["freeze"], {"freeze": freeze}));
4858      if (($eqeq(freeze, true) || (($truthy(freeze['$nil?']()) && ($truthy(self['$frozen?']())))))) {
4859        copy.$freeze()
4860      };
4861      return copy;
4862    }, -1);
4863    
4864    $def(self, '$initialize_clone', function $$initialize_clone(other, $kwargs) {
4865      var freeze, self = this;
4866
4867      
4868      $kwargs = $ensure_kwargs($kwargs);
4869      
4870      freeze = $kwargs.$$smap["freeze"];if (freeze == null) freeze = nil;
4871      self.$initialize_copy(other);
4872      return self;
4873    }, -2);
4874    
4875    $def(self, '$define_singleton_method', function $$define_singleton_method(name, method) {
4876      var block = $$define_singleton_method.$$p || nil, self = this;
4877
4878      $$define_singleton_method.$$p = null;
4879      
4880      ;
4881      ;
4882      return $send(self.$singleton_class(), 'define_method', [name, method], block.$to_proc());
4883    }, -2);
4884    
4885    $def(self, '$dup', function $$dup() {
4886      var self = this, copy = nil;
4887
4888      
4889      copy = self.$class().$allocate();
4890      copy.$copy_instance_variables(self);
4891      copy.$initialize_dup(self);
4892      return copy;
4893    });
4894    
4895    $def(self, '$initialize_dup', function $$initialize_dup(other) {
4896      var self = this;
4897
4898      return self.$initialize_copy(other)
4899    });
4900    
4901    $def(self, '$enum_for', function $$enum_for($a, $b) {
4902      var block = $$enum_for.$$p || nil, $post_args, method, args, self = this;
4903
4904      $$enum_for.$$p = null;
4905      
4906      ;
4907      $post_args = $slice(arguments);
4908      
4909      if ($post_args.length > 0) method = $post_args.shift();if (method == null) method = "each";
4910      args = $post_args;
4911      return $send($$$('Enumerator'), 'for', [self, method].concat($to_a(args)), block.$to_proc());
4912    }, -1);
4913    
4914    $def(self, '$equal?', function $Kernel_equal$ques$6(other) {
4915      var self = this;
4916
4917      return self === other;
4918    });
4919    
4920    $def(self, '$exit', function $$exit(status) {
4921      var $ret_or_1 = nil, block = nil;
4922      if ($gvars.__at_exit__ == null) $gvars.__at_exit__ = nil;
4923
4924      
4925      if (status == null) status = true;
4926      $gvars.__at_exit__ = ($truthy(($ret_or_1 = $gvars.__at_exit__)) ? ($ret_or_1) : ([]));
4927      while (!($truthy($gvars.__at_exit__['$empty?']()))) {
4928      
4929        block = $gvars.__at_exit__.$pop();
4930        block.$call();
4931      };
4932      
4933      if (status.$$is_boolean) {
4934        status = status ? 0 : 1;
4935      } else {
4936        status = $coerce_to(status, $$$('Integer'), 'to_int')
4937      }
4938
4939      Opal.exit(status);
4940    ;
4941      return nil;
4942    }, -1);
4943    
4944    $def(self, '$extend', function $$extend($a) {
4945      var $post_args, mods, self = this;
4946
4947      
4948      $post_args = $slice(arguments);
4949      mods = $post_args;
4950      
4951      if (mods.length == 0) {
4952        self.$raise($$$('ArgumentError'), "wrong number of arguments (given 0, expected 1+)")
4953      }
4954
4955      $deny_frozen_access(self);
4956
4957      var singleton = self.$singleton_class();
4958
4959      for (var i = mods.length - 1; i >= 0; i--) {
4960        var mod = mods[i];
4961
4962        if (!mod.$$is_module) {
4963          $Kernel.$raise($$$('TypeError'), "wrong argument type " + ((mod).$class()) + " (expected Module)");
4964        }
4965
4966        (mod).$append_features(singleton);
4967        (mod).$extend_object(self);
4968        (mod).$extended(self);
4969      }
4970    ;
4971      return self;
4972    }, -1);
4973    
4974    $def(self, '$freeze', function $$freeze() {
4975      var self = this;
4976
4977      
4978      if ($truthy(self['$frozen?']())) {
4979        return self
4980      };
4981      
4982      if (typeof(self) === "object") {
4983        $freeze_props(self);
4984        return $freeze(self);
4985      }
4986      return self;
4987    ;
4988    });
4989    
4990    $def(self, '$frozen?', function $Kernel_frozen$ques$7() {
4991      var self = this;
4992
4993      
4994      switch (typeof(self)) {
4995      case "string":
4996      case "symbol":
4997      case "number":
4998      case "boolean":
4999        return true;
5000      case "object":
5001        return (self.$$frozen || false);
5002      default:
5003        return false;
5004      }
5005    
5006    });
5007    
5008    $def(self, '$gets', function $$gets($a) {
5009      var $post_args, args;
5010      if ($gvars.stdin == null) $gvars.stdin = nil;
5011
5012      
5013      $post_args = $slice(arguments);
5014      args = $post_args;
5015      return $send($gvars.stdin, 'gets', $to_a(args));
5016    }, -1);
5017    
5018    $def(self, '$hash', function $$hash() {
5019      var self = this;
5020
5021      return self.$__id__()
5022    });
5023    
5024    $def(self, '$initialize_copy', $return_val(nil));
5025    var inspect_stack = [];
5026    
5027    $def(self, '$inspect', function $$inspect() {
5028      var self = this, ivs = nil, id = nil, pushed = nil, e = nil;
5029
5030      return (function() { try {
5031      try {
5032        
5033        ivs = "";
5034        id = self.$__id__();
5035        if ($truthy((inspect_stack)['$include?'](id))) {
5036          ivs = " ..."
5037        } else {
5038          
5039          (inspect_stack)['$<<'](id);
5040          pushed = true;
5041          $send(self.$instance_variables(), 'each', [], function $$8(i){var self = $$8.$$s == null ? this : $$8.$$s, ivar = nil, inspect = nil;
5042
5043            
5044            if (i == null) i = nil;
5045            ivar = self.$instance_variable_get(i);
5046            inspect = $$('Opal').$inspect(ivar);
5047            return (ivs = $rb_plus(ivs, " " + (i) + "=" + (inspect)));}, {$$s: self});
5048        };
5049        return "#<" + (self.$class()) + ":0x" + (id.$to_s(16)) + (ivs) + ">";
5050      } catch ($err) {
5051        if (Opal.rescue($err, [$$('StandardError')])) {(e = $err)
5052          try {
5053            return "#<" + (self.$class()) + ":0x" + (id.$to_s(16)) + ">"
5054          } finally { Opal.pop_exception(); }
5055        } else { throw $err; }
5056      }
5057      } finally {
5058        ($truthy(pushed) ? ((inspect_stack).$pop()) : nil)
5059      }; })()
5060    });
5061    
5062    $def(self, '$instance_of?', function $Kernel_instance_of$ques$9(klass) {
5063      var self = this;
5064
5065      
5066      if (!klass.$$is_class && !klass.$$is_module) {
5067        $Kernel.$raise($$$('TypeError'), "class or module required");
5068      }
5069
5070      return self.$$class === klass;
5071    
5072    });
5073    
5074    $def(self, '$instance_variable_defined?', function $Kernel_instance_variable_defined$ques$10(name) {
5075      var self = this;
5076
5077      
5078      name = $Opal['$instance_variable_name!'](name);
5079      return Opal.hasOwnProperty.call(self, name.substr(1));;
5080    });
5081    
5082    $def(self, '$instance_variable_get', function $$instance_variable_get(name) {
5083      var self = this;
5084
5085      
5086      name = $Opal['$instance_variable_name!'](name);
5087      
5088      var ivar = self[Opal.ivar(name.substr(1))];
5089
5090      return ivar == null ? nil : ivar;
5091    ;
5092    });
5093    
5094    $def(self, '$instance_variable_set', function $$instance_variable_set(name, value) {
5095      var self = this;
5096
5097      
5098      $deny_frozen_access(self);
5099      name = $Opal['$instance_variable_name!'](name);
5100      return self[Opal.ivar(name.substr(1))] = value;;
5101    });
5102    
5103    $def(self, '$remove_instance_variable', function $$remove_instance_variable(name) {
5104      var self = this;
5105
5106      
5107      name = $Opal['$instance_variable_name!'](name);
5108      
5109      var key = Opal.ivar(name.substr(1)),
5110          val;
5111      if (self.hasOwnProperty(key)) {
5112        val = self[key];
5113        delete self[key];
5114        return val;
5115      }
5116    ;
5117      return $Kernel.$raise($$$('NameError'), "instance variable " + (name) + " not defined");
5118    });
5119    
5120    $def(self, '$instance_variables', function $$instance_variables() {
5121      var self = this;
5122
5123      
5124      var result = [], ivar;
5125
5126      for (var name in self) {
5127        if (self.hasOwnProperty(name) && name.charAt(0) !== '$') {
5128          if (name.substr(-1) === '$') {
5129            ivar = name.slice(0, name.length - 1);
5130          } else {
5131            ivar = name;
5132          }
5133          result.push('@' + ivar);
5134        }
5135      }
5136
5137      return result;
5138    
5139    });
5140    
5141    $def(self, '$Integer', function $$Integer(value, base) {
5142      
5143      
5144      ;
5145      
5146      var i, str, base_digits;
5147
5148      if (!value.$$is_string) {
5149        if (base !== undefined) {
5150          $Kernel.$raise($$$('ArgumentError'), "base specified for non string value")
5151        }
5152        if (value === nil) {
5153          $Kernel.$raise($$$('TypeError'), "can't convert nil into Integer")
5154        }
5155        if (value.$$is_number) {
5156          if (value === Infinity || value === -Infinity || isNaN(value)) {
5157            $Kernel.$raise($$$('FloatDomainError'), value)
5158          }
5159          return Math.floor(value);
5160        }
5161        if (value['$respond_to?']("to_int")) {
5162          i = value.$to_int();
5163          if (i !== nil) {
5164            return i;
5165          }
5166        }
5167        return $Opal['$coerce_to!'](value, $$$('Integer'), "to_i");
5168      }
5169
5170      if (value === "0") {
5171        return 0;
5172      }
5173
5174      if (base === undefined) {
5175        base = 0;
5176      } else {
5177        base = $coerce_to(base, $$$('Integer'), 'to_int');
5178        if (base === 1 || base < 0 || base > 36) {
5179          $Kernel.$raise($$$('ArgumentError'), "invalid radix " + (base))
5180        }
5181      }
5182
5183      str = value.toLowerCase();
5184
5185      str = str.replace(/(\d)_(?=\d)/g, '$1');
5186
5187      str = str.replace(/^(\s*[+-]?)(0[bodx]?)/, function (_, head, flag) {
5188        switch (flag) {
5189        case '0b':
5190          if (base === 0 || base === 2) {
5191            base = 2;
5192            return head;
5193          }
5194          // no-break
5195        case '0':
5196        case '0o':
5197          if (base === 0 || base === 8) {
5198            base = 8;
5199            return head;
5200          }
5201          // no-break
5202        case '0d':
5203          if (base === 0 || base === 10) {
5204            base = 10;
5205            return head;
5206          }
5207          // no-break
5208        case '0x':
5209          if (base === 0 || base === 16) {
5210            base = 16;
5211            return head;
5212          }
5213          // no-break
5214        }
5215        $Kernel.$raise($$$('ArgumentError'), "invalid value for Integer(): \"" + (value) + "\"")
5216      });
5217
5218      base = (base === 0 ? 10 : base);
5219
5220      base_digits = '0-' + (base <= 10 ? base - 1 : '9a-' + String.fromCharCode(97 + (base - 11)));
5221
5222      if (!(new RegExp('^\\s*[+-]?[' + base_digits + ']+\\s*$')).test(str)) {
5223        $Kernel.$raise($$$('ArgumentError'), "invalid value for Integer(): \"" + (value) + "\"")
5224      }
5225
5226      i = parseInt(str, base);
5227
5228      if (isNaN(i)) {
5229        $Kernel.$raise($$$('ArgumentError'), "invalid value for Integer(): \"" + (value) + "\"")
5230      }
5231
5232      return i;
5233    ;
5234    }, -2);
5235    
5236    $def(self, '$Float', function $$Float(value) {
5237      
5238      
5239      var str;
5240
5241      if (value === nil) {
5242        $Kernel.$raise($$$('TypeError'), "can't convert nil into Float")
5243      }
5244
5245      if (value.$$is_string) {
5246        str = value.toString();
5247
5248        str = str.replace(/(\d)_(?=\d)/g, '$1');
5249
5250        //Special case for hex strings only:
5251        if (/^\s*[-+]?0[xX][0-9a-fA-F]+\s*$/.test(str)) {
5252          return $Kernel.$Integer(str);
5253        }
5254
5255        if (!/^\s*[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?\s*$/.test(str)) {
5256          $Kernel.$raise($$$('ArgumentError'), "invalid value for Float(): \"" + (value) + "\"")
5257        }
5258
5259        return parseFloat(str);
5260      }
5261
5262      return $Opal['$coerce_to!'](value, $$$('Float'), "to_f");
5263    
5264    });
5265    
5266    $def(self, '$Hash', function $$Hash(arg) {
5267      
5268      
5269      if (($truthy(arg['$nil?']()) || ($eqeq(arg, [])))) {
5270        return $hash2([], {})
5271      };
5272      if ($eqeqeq($$$('Hash'), arg)) {
5273        return arg
5274      };
5275      return $Opal['$coerce_to!'](arg, $$$('Hash'), "to_hash");
5276    });
5277    
5278    $def(self, '$is_a?', function $Kernel_is_a$ques$11(klass) {
5279      var self = this;
5280
5281      
5282      if (!klass.$$is_class && !klass.$$is_module) {
5283        $Kernel.$raise($$$('TypeError'), "class or module required");
5284      }
5285
5286      return Opal.is_a(self, klass);
5287    
5288    });
5289    
5290    $def(self, '$itself', $return_self);
5291    
5292    $def(self, '$lambda', function $$lambda() {
5293      var block = $$lambda.$$p || nil;
5294
5295      $$lambda.$$p = null;
5296      
5297      ;
5298      return Opal.lambda(block);;
5299    });
5300    
5301    $def(self, '$load', function $$load(file) {
5302      
5303      
5304      file = $Opal['$coerce_to!'](file, $$$('String'), "to_str");
5305      return Opal.load(file);
5306    });
5307    
5308    $def(self, '$loop', function $$loop() {
5309      var $yield = $$loop.$$p || nil, self = this, e = nil;
5310
5311      $$loop.$$p = null;
5312      
5313      if (!($yield !== nil)) {
5314        return $send(self, 'enum_for', ["loop"], function $$12(){
5315          return $$$($$$('Float'), 'INFINITY')})
5316      };
5317      while ($truthy(true)) {
5318      
5319        try {
5320          Opal.yieldX($yield, [])
5321        } catch ($err) {
5322          if (Opal.rescue($err, [$$$('StopIteration')])) {(e = $err)
5323            try {
5324              return e.$result()
5325            } finally { Opal.pop_exception(); }
5326          } else { throw $err; }
5327        };
5328      };
5329      return self;
5330    });
5331    
5332    $def(self, '$nil?', $return_val(false));
5333    
5334    $def(self, '$printf', function $$printf($a) {
5335      var $post_args, args, self = this;
5336
5337      
5338      $post_args = $slice(arguments);
5339      args = $post_args;
5340      if ($truthy(args['$any?']())) {
5341        self.$print($send(self, 'format', $to_a(args)))
5342      };
5343      return nil;
5344    }, -1);
5345    
5346    $def(self, '$proc', function $$proc() {
5347      var block = $$proc.$$p || nil;
5348
5349      $$proc.$$p = null;
5350      
5351      ;
5352      if (!$truthy(block)) {
5353        $Kernel.$raise($$$('ArgumentError'), "tried to create Proc object without a block")
5354      };
5355      block.$$is_lambda = false;
5356      return block;
5357    });
5358    
5359    $def(self, '$puts', function $$puts($a) {
5360      var $post_args, strs;
5361      if ($gvars.stdout == null) $gvars.stdout = nil;
5362
5363      
5364      $post_args = $slice(arguments);
5365      strs = $post_args;
5366      return $send($gvars.stdout, 'puts', $to_a(strs));
5367    }, -1);
5368    
5369    $def(self, '$p', function $$p($a) {
5370      var $post_args, args;
5371
5372      
5373      $post_args = $slice(arguments);
5374      args = $post_args;
5375      $send(args, 'each', [], function $$13(obj){        if ($gvars.stdout == null) $gvars.stdout = nil;
5376
5377        
5378        if (obj == null) obj = nil;
5379        return $gvars.stdout.$puts(obj.$inspect());});
5380      if ($truthy($rb_le(args.$length(), 1))) {
5381        return args['$[]'](0)
5382      } else {
5383        return args
5384      };
5385    }, -1);
5386    
5387    $def(self, '$print', function $$print($a) {
5388      var $post_args, strs;
5389      if ($gvars.stdout == null) $gvars.stdout = nil;
5390
5391      
5392      $post_args = $slice(arguments);
5393      strs = $post_args;
5394      return $send($gvars.stdout, 'print', $to_a(strs));
5395    }, -1);
5396    
5397    $def(self, '$readline', function $$readline($a) {
5398      var $post_args, args;
5399      if ($gvars.stdin == null) $gvars.stdin = nil;
5400
5401      
5402      $post_args = $slice(arguments);
5403      args = $post_args;
5404      return $send($gvars.stdin, 'readline', $to_a(args));
5405    }, -1);
5406    
5407    $def(self, '$warn', function $$warn($a, $b) {
5408      var $post_args, $kwargs, strs, uplevel, $c, $d, self = this, location = nil;
5409      if ($gvars.VERBOSE == null) $gvars.VERBOSE = nil;
5410      if ($gvars.stderr == null) $gvars.stderr = nil;
5411
5412      
5413      $post_args = $slice(arguments);
5414      $kwargs = $extract_kwargs($post_args);
5415      $kwargs = $ensure_kwargs($kwargs);
5416      strs = $post_args;
5417      
5418      uplevel = $kwargs.$$smap["uplevel"];if (uplevel == null) uplevel = nil;
5419      if ($truthy(uplevel)) {
5420        
5421        uplevel = $Opal['$coerce_to!'](uplevel, $$$('Integer'), "to_str");
5422        if ($truthy($rb_lt(uplevel, 0))) {
5423          $Kernel.$raise($$$('ArgumentError'), "negative level (" + (uplevel) + ")")
5424        };
5425        location = ($c = ($d = self.$caller($rb_plus(uplevel, 1), 1).$first(), ($d === nil || $d == null) ? nil : $d.$split(":in `")), ($c === nil || $c == null) ? nil : $c.$first());
5426        if ($truthy(location)) {
5427          location = "" + (location) + ": "
5428        };
5429        strs = $send(strs, 'map', [], function $$14(s){
5430          
5431          if (s == null) s = nil;
5432          return "" + (location) + "warning: " + (s);});
5433      };
5434      if (($truthy($gvars.VERBOSE['$nil?']()) || ($truthy(strs['$empty?']())))) {
5435        return nil
5436      } else {
5437        return $send($gvars.stderr, 'puts', $to_a(strs))
5438      };
5439    }, -1);
5440    
5441    $def(self, '$raise', function $$raise(exception, string, backtrace) {
5442            if ($gvars["!"] == null) $gvars["!"] = nil;
5443      if ($gvars["@"] == null) $gvars["@"] = nil;
5444
5445      
5446      ;
5447      if (string == null) string = nil;
5448      if (backtrace == null) backtrace = nil;
5449      
5450      if (exception == null && $gvars["!"] !== nil) {
5451        throw $gvars["!"];
5452      }
5453      if (exception == null) {
5454        exception = $$$('RuntimeError').$new("");
5455      }
5456      else if ($respond_to(exception, '$to_str')) {
5457        exception = $$$('RuntimeError').$new(exception.$to_str());
5458      }
5459      // using respond_to? and not an undefined check to avoid method_missing matching as true
5460      else if (exception.$$is_class && $respond_to(exception, '$exception')) {
5461        exception = exception.$exception(string);
5462      }
5463      else if (exception.$$is_exception) {
5464        // exception is fine
5465      }
5466      else {
5467        exception = $$$('TypeError').$new("exception class/object expected");
5468      }
5469
5470      if (backtrace !== nil) {
5471        exception.$set_backtrace(backtrace);
5472      }
5473
5474      if ($gvars["!"] !== nil) {
5475        Opal.exceptions.push($gvars["!"]);
5476      }
5477
5478      $gvars["!"] = exception;
5479      $gvars["@"] = (exception).$backtrace();
5480
5481      throw exception;
5482    ;
5483    }, -1);
5484    
5485    $def(self, '$rand', function $$rand(max) {
5486      
5487      
5488      ;
5489      
5490      if (max === undefined) {
5491        return $$$($$$('Random'), 'DEFAULT').$rand();
5492      }
5493
5494      if (max.$$is_number) {
5495        if (max < 0) {
5496          max = Math.abs(max);
5497        }
5498
5499        if (max % 1 !== 0) {
5500          max = max.$to_i();
5501        }
5502
5503        if (max === 0) {
5504          max = undefined;
5505        }
5506      }
5507    ;
5508      return $$$($$$('Random'), 'DEFAULT').$rand(max);
5509    }, -1);
5510    
5511    $def(self, '$respond_to?', function $Kernel_respond_to$ques$15(name, include_all) {
5512      var self = this;
5513
5514      
5515      if (include_all == null) include_all = false;
5516      
5517      var body = self[$jsid(name)];
5518
5519      if (typeof(body) === "function" && !body.$$stub) {
5520        return true;
5521      }
5522
5523      if (self['$respond_to_missing?'].$$pristine === true) {
5524        return false;
5525      } else {
5526        return self['$respond_to_missing?'](name, include_all);
5527      }
5528    ;
5529    }, -2);
5530    
5531    $def(self, '$respond_to_missing?', function $Kernel_respond_to_missing$ques$16(method_name, include_all) {
5532      
5533      
5534      if (include_all == null) include_all = false;
5535      return false;
5536    }, -2);
5537    $Opal.$pristine(self, "respond_to?", "respond_to_missing?");
5538    
5539    $def(self, '$require', function $$require(file) {
5540      
5541      
5542      // As Object.require refers to Kernel.require once Kernel has been loaded the String
5543      // class may not be available yet, the coercion requires both  String and Array to be loaded.
5544      if (typeof file !== 'string' && Opal.String && Opal.Array) {
5545        (file = $Opal['$coerce_to!'](file, $$$('String'), "to_str"))
5546      }
5547      return Opal.require(file)
5548    
5549    });
5550    
5551    $def(self, '$require_relative', function $$require_relative(file) {
5552      
5553      
5554      $Opal['$try_convert!'](file, $$$('String'), "to_str");
5555      file = $$$('File').$expand_path($$$('File').$join(Opal.current_file, "..", file));
5556      return Opal.require(file);
5557    });
5558    
5559    $def(self, '$require_tree', function $$require_tree(path, $kwargs) {
5560      var autoload;
5561
5562      
5563      $kwargs = $ensure_kwargs($kwargs);
5564      
5565      autoload = $kwargs.$$smap["autoload"];if (autoload == null) autoload = false;
5566      
5567      var result = [];
5568
5569      path = $$$('File').$expand_path(path)
5570      path = Opal.normalize(path);
5571      if (path === '.') path = '';
5572      for (var name in Opal.modules) {
5573        if ((name)['$start_with?'](path)) {
5574          if(!autoload) {
5575            result.push([name, Opal.require(name)]);
5576          } else {
5577            result.push([name, true]); // do nothing, delegated to a autoloading
5578          }
5579        }
5580      }
5581
5582      return result;
5583    ;
5584    }, -2);
5585    
5586    $def(self, '$singleton_class', function $$singleton_class() {
5587      var self = this;
5588
5589      return Opal.get_singleton_class(self);
5590    });
5591    
5592    $def(self, '$sleep', function $$sleep(seconds) {
5593      
5594      
5595      if (seconds == null) seconds = nil;
5596      
5597      if (seconds === nil) {
5598        $Kernel.$raise($$$('TypeError'), "can't convert NilClass into time interval")
5599      }
5600      if (!seconds.$$is_number) {
5601        $Kernel.$raise($$$('TypeError'), "can't convert " + (seconds.$class()) + " into time interval")
5602      }
5603      if (seconds < 0) {
5604        $Kernel.$raise($$$('ArgumentError'), "time interval must be positive")
5605      }
5606      var get_time = Opal.global.performance ?
5607        function() {return performance.now()} :
5608        function() {return new Date()}
5609
5610      var t = get_time();
5611      while (get_time() - t <= seconds * 1000);
5612      return Math.round(seconds);
5613    ;
5614    }, -1);
5615    
5616    $def(self, '$srand', function $$srand(seed) {
5617      
5618      
5619      if (seed == null) seed = $$('Random').$new_seed();
5620      return $$$('Random').$srand(seed);
5621    }, -1);
5622    
5623    $def(self, '$String', function $$String(str) {
5624      var $ret_or_1 = nil;
5625
5626      if ($truthy(($ret_or_1 = $Opal['$coerce_to?'](str, $$$('String'), "to_str")))) {
5627        return $ret_or_1
5628      } else {
5629        return $Opal['$coerce_to!'](str, $$$('String'), "to_s")
5630      }
5631    });
5632    
5633    $def(self, '$tap', function $$tap() {
5634      var block = $$tap.$$p || nil, self = this;
5635
5636      $$tap.$$p = null;
5637      
5638      ;
5639      Opal.yield1(block, self);
5640      return self;
5641    });
5642    
5643    $def(self, '$to_proc', $return_self);
5644    
5645    $def(self, '$to_s', function $$to_s() {
5646      var self = this;
5647
5648      return "#<" + (self.$class()) + ":0x" + (self.$__id__().$to_s(16)) + ">"
5649    });
5650    
5651    $def(self, '$catch', function $Kernel_catch$17(tag) {
5652      var $yield = $Kernel_catch$17.$$p || nil, $ret_or_1 = nil, e = nil;
5653
5654      $Kernel_catch$17.$$p = null;
5655      
5656      if (tag == null) tag = nil;
5657      try {
5658        
5659        tag = ($truthy(($ret_or_1 = tag)) ? ($ret_or_1) : ($Object.$new()));
5660        return Opal.yield1($yield, tag);;
5661      } catch ($err) {
5662        if (Opal.rescue($err, [$$$('UncaughtThrowError')])) {(e = $err)
5663          try {
5664            
5665            if ($eqeq(e.$tag(), tag)) {
5666              return e.$value()
5667            };
5668            return $Kernel.$raise();
5669          } finally { Opal.pop_exception(); }
5670        } else { throw $err; }
5671      };
5672    }, -1);
5673    
5674    $def(self, '$throw', function $Kernel_throw$18(tag, obj) {
5675      
5676      
5677      if (obj == null) obj = nil;
5678      return $Kernel.$raise($$$('UncaughtThrowError').$new(tag, obj));
5679    }, -2);
5680    
5681    $def(self, '$open', function $$open($a) {
5682      var block = $$open.$$p || nil, $post_args, args;
5683
5684      $$open.$$p = null;
5685      
5686      ;
5687      $post_args = $slice(arguments);
5688      args = $post_args;
5689      return $send($$$('File'), 'open', $to_a(args), block.$to_proc());
5690    }, -1);
5691    
5692    $def(self, '$yield_self', function $$yield_self() {
5693      var $yield = $$yield_self.$$p || nil, self = this;
5694
5695      $$yield_self.$$p = null;
5696      
5697      if (!($yield !== nil)) {
5698        return $send(self, 'enum_for', ["yield_self"], $return_val(1))
5699      };
5700      return Opal.yield1($yield, self);;
5701    });
5702    $alias(self, "fail", "raise");
5703    $alias(self, "kind_of?", "is_a?");
5704    $alias(self, "object_id", "__id__");
5705    $alias(self, "public_send", "__send__");
5706    $alias(self, "send", "__send__");
5707    $alias(self, "then", "yield_self");
5708    return $alias(self, "to_enum", "enum_for");
5709  })('::', $nesting);
5710  return (function($base, $super) {
5711    var self = $klass($base, $super, 'Object');
5712
5713    
5714    
5715    delete $Object.$$prototype.$require;
5716    return self.$include($Kernel);
5717  })('::', null);
5718};
5719
5720Opal.modules["corelib/main"] = function(Opal) {/* Generated by Opal 1.7.3 */
5721  var $return_val = Opal.return_val, $def = Opal.def, $Object = Opal.Object, $slice = Opal.slice, $Kernel = Opal.Kernel, self = Opal.top, $nesting = [], nil = Opal.nil;
5722
5723  Opal.add_stubs('include,raise');
5724  return (function(self, $parent_nesting) {
5725    
5726    
5727    
5728    $def(self, '$to_s', $return_val("main"));
5729    
5730    $def(self, '$include', function $$include(mod) {
5731      
5732      return $Object.$include(mod)
5733    });
5734    
5735    $def(self, '$autoload', function $$autoload($a) {
5736      var $post_args, args;
5737
5738      
5739      $post_args = $slice(arguments);
5740      args = $post_args;
5741      return Opal.Object.$autoload.apply(Opal.Object, args);;
5742    }, -1);
5743    return $def(self, '$using', function $$using(mod) {
5744      
5745      return $Kernel.$raise("main.using is permitted only at toplevel")
5746    });
5747  })(Opal.get_singleton_class(self), $nesting)
5748};
5749
5750Opal.modules["corelib/error/errno"] = function(Opal) {/* Generated by Opal 1.7.3 */
5751  var $module = Opal.module, $truthy = Opal.truthy, $rb_plus = Opal.rb_plus, $send2 = Opal.send2, $find_super = Opal.find_super, $def = Opal.def, $klass = Opal.klass, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$;
5752
5753  Opal.add_stubs('+,errno,class,attr_reader');
5754  
5755  (function($base, $parent_nesting) {
5756    var self = $module($base, 'Errno');
5757
5758    var $nesting = [self].concat($parent_nesting), errors = nil, klass = nil;
5759
5760    
5761    errors = [["EINVAL", "Invalid argument", 22], ["EEXIST", "File exists", 17], ["EISDIR", "Is a directory", 21], ["EMFILE", "Too many open files", 24], ["ESPIPE", "Illegal seek", 29], ["EACCES", "Permission denied", 13], ["EPERM", "Operation not permitted", 1], ["ENOENT", "
5761No such file or directory", 2], ["ENAMETOOLONG", "File name too long", 36]];
5762    klass = nil;
5763    
5764    var i;
5765    for (i = 0; i < errors.length; i++) {
5766      (function() { // Create a closure
5767        var class_name = errors[i][0];
5768        var default_message = errors[i][1];
5769        var errno = errors[i][2];
5770
5771        klass = Opal.klass(self, Opal.SystemCallError, class_name);
5772        klass.errno = errno;
5773
5774        (function(self, $parent_nesting) {
5775      
5776      return $def(self, '$new', function $new$1(name) {
5777        var $yield = $new$1.$$p || nil, self = this, message = nil;
5778
5779        $new$1.$$p = null;
5780        
5781        if (name == null) name = nil;
5782        message = default_message;
5783        if ($truthy(name)) {
5784          message = $rb_plus(message, " - " + (name))
5785        };
5786        return $send2(self, $find_super(self, 'new', $new$1, false, true), 'new', [message], null);
5787      }, -1)
5788    })(Opal.get_singleton_class(klass), $nesting)
5789      })();
5790    }
5791  ;
5792  })('::', $nesting);
5793  return (function($base, $super, $parent_nesting) {
5794    var self = $klass($base, $super, 'SystemCallError');
5795
5796    var $nesting = [self].concat($parent_nesting);
5797
5798    
5799    
5800    $def(self, '$errno', function $$errno() {
5801      var self = this;
5802
5803      return self.$class().$errno()
5804    });
5805    return (function(self, $parent_nesting) {
5806      
5807      return self.$attr_reader("errno")
5808    })(Opal.get_singleton_class(self), $nesting);
5809  })('::', $$$('StandardError'), $nesting);
5810};
5811
5812Opal.modules["corelib/error"] = function(Opal) {/* Generated by Opal 1.7.3 */
5813  var $klass = Opal.klass, $slice = Opal.slice, $gvars = Opal.gvars, $defs = Opal.defs, $send = Opal.send, $to_a = Opal.to_a, $def = Opal.def, $truthy = Opal.truthy, $hash2 = Opal.hash2, $Kernel = Opal.Kernel, $not = Opal.not, $rb_plus = Opal.rb_plus, $eqeq = Opal.eqeq, $Object = Opal.Object, $ensure_kwargs = Opal.ensure_kwargs, $send2 = Opal.send2, $find_super = Opal.find_super, $module = Opal.module, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$;
5814
5815  Opal.add_stubs('new,map,backtrace,clone,to_s,merge,tty?,[],include?,raise,dup,empty?,!,caller,shift,+,class,join,cause,full_message,==,reverse,split,autoload,attr_reader,inspect');
5816  
5817  (function($base, $super, $parent_nesting) {
5818    var self = $klass($base, $super, 'Exception');
5819
5820    var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype;
5821
5822    $proto.message = nil;
5823    
5824    Opal.prop(self.$$prototype, '$$is_exception', true);
5825    var stack_trace_limit;
5826    Error.stackTraceLimit = 100;
5827    $defs(self, '$new', function $Exception_new$1($a) {
5828      var $post_args, args, self = this;
5829      if ($gvars["!"] == null) $gvars["!"] = nil;
5830
5831      
5832      $post_args = $slice(arguments);
5833      args = $post_args;
5834      
5835      var message   = (args.length > 0) ? args[0] : nil;
5836      var error     = new self.$$constructor(message);
5837      error.name    = self.$$name;
5838      error.message = message;
5839      error.cause   = $gvars["!"];
5840      Opal.send(error, error.$initialize, args);
5841
5842      // Error.captureStackTrace() will use .name and .toString to build the
5843      // first line of the stack trace so it must be called after the error
5844      // has been initialized.
5845      // https://nodejs.org/dist/latest-v6.x/docs/api/errors.html
5846      if (Opal.config.enable_stack_trace && Error.captureStackTrace) {
5847        // Passing Kernel.raise will cut the stack trace from that point above
5848        Error.captureStackTrace(error, stack_trace_limit);
5849      }
5850
5851      return error;
5852    ;
5853    }, -1);
5854    stack_trace_limit = self.$new;
5855    $defs(self, '$exception', function $$exception($a) {
5856      var $post_args, args, self = this;
5857
5858      
5859      $post_args = $slice(arguments);
5860      args = $post_args;
5861      return $send(self, 'new', $to_a(args));
5862    }, -1);
5863    
5864    $def(self, '$initialize', function $$initialize($a) {
5865      var $post_args, args, self = this;
5866
5867      
5868      $post_args = $slice(arguments);
5869      args = $post_args;
5870      return self.message = (args.length > 0) ? args[0] : nil;;
5871    }, -1);
5872    
5873    // Convert backtrace from any format to Ruby format
5874    function correct_backtrace(backtrace) {
5875      var new_bt = [], m;
5876
5877      for (var i = 0; i < backtrace.length; i++) {
5878        var loc = backtrace[i];
5879        if (!loc || !loc.$$is_string) {
5880          /* Do nothing */
5881        }
5882        /* Chromium format */
5883        else if ((m = loc.match(/^    at (.*?) \((.*?)\)$/))) {
5884          new_bt.push(m[2] + ":in `" + m[1] + "'");
5885        }
5886        else if ((m = loc.match(/^    at (.*?)$/))) {
5887          new_bt.push(m[1] + ":in `undefined'");
5888        }
5889        /* Node format */
5890        else if ((m = loc.match(/^  from (.*?)$/))) {
5891          new_bt.push(m[1]);
5892        }
5893        /* Mozilla/Apple format */
5894        else if ((m = loc.match(/^(.*?)@(.*?)$/))) {
5895          new_bt.push(m[2] + ':in `' + m[1] + "'");
5896        }
5897      }
5898
5899      return new_bt;
5900    }
5901  ;
5902    
5903    $def(self, '$backtrace', function $$backtrace() {
5904      var self = this;
5905
5906      
5907      if (self.backtrace) {
5908        // nil is a valid backtrace
5909        return self.backtrace;
5910      }
5911
5912      var backtrace = self.stack;
5913
5914      if (typeof(backtrace) !== 'undefined' && backtrace.$$is_string) {
5915        return self.backtrace = correct_backtrace(backtrace.split("\n"));
5916      }
5917      else if (backtrace) {
5918        return self.backtrace = correct_backtrace(backtrace);
5919      }
5920
5921      return [];
5922    
5923    });
5924    
5925    $def(self, '$backtrace_locations', function $$backtrace_locations() {
5926      var $a, self = this;
5927
5928      
5929      if (self.backtrace_locations) return self.backtrace_locations;
5930      self.backtrace_locations = ($a = self.$backtrace(), ($a === nil || $a == null) ? nil : $send($a, 'map', [], function $$2(loc){
5931        
5932        if (loc == null) loc = nil;
5933        return $$$($$$($$$('Thread'), 'Backtrace'), 'Location').$new(loc);}))
5934      return self.backtrace_locations;
5935    
5936    });
5937    
5938    $def(self, '$cause', function $$cause() {
5939      var self = this;
5940
5941      return self.cause || nil;
5942    });
5943    
5944    $def(self, '$exception', function $$exception(str) {
5945      var self = this;
5946
5947      
5948      if (str == null) str = nil;
5949      
5950      if (str === nil || self === str) {
5951        return self;
5952      }
5953
5954      var cloned = self.$clone();
5955      cloned.message = str;
5956      if (self.backtrace) cloned.backtrace = self.backtrace.$dup();
5957      cloned.stack = self.stack;
5958      cloned.cause = self.cause;
5959      return cloned;
5960    ;
5961    }, -1);
5962    
5963    $def(self, '$message', function $$message() {
5964      var self = this;
5965
5966      return self.$to_s()
5967    });
5968    
5969    $def(self, '$full_message', function $$full_message(kwargs) {
5970      var $a, $b, self = this, $ret_or_1 = nil, highlight = nil, order = nil, bold_underline = nil, bold = nil, reset = nil, bt = nil, first = nil, msg = nil;
5971      if ($gvars.stderr == null) $gvars.stderr = nil;
5972
5973      
5974      if (kwargs == null) kwargs = nil;
5975      if (!$truthy((($a = $$('Hash', 'skip_raise')) ? 'constant' : nil))) {
5976        return "" + (self.message) + "\n" + (self.stack)
5977      };
5978      kwargs = $hash2(["highlight", "order"], {"highlight": $gvars.stderr['$tty?'](), "order": "top"}).$merge(($truthy(($ret_or_1 = kwargs)) ? ($ret_or_1) : ($hash2([], {}))));
5979      $b = [kwargs['$[]']("highlight"), kwargs['$[]']("order")], (highlight = $b[0]), (order = $b[1]), $b;
5980      if (!$truthy([true, false]['$include?'](highlight))) {
5981        $Kernel.$raise($$$('ArgumentError'), "expected true or false as highlight: " + (highlight))
5982      };
5983      if (!$truthy(["top", "bottom"]['$include?'](order))) {
5984        $Kernel.$raise($$$('ArgumentError'), "expected :top or :bottom as order: " + (order))
5985      };
5986      if ($truthy(highlight)) {
5987        
5988        bold_underline = "\u001b[1;4m";
5989        bold = "\u001b[1m";
5990        reset = "\u001b[m";
5991      } else {
5992        bold_underline = (bold = (reset = ""))
5993      };
5994      bt = self.$backtrace().$dup();
5995      if (($not(bt) || ($truthy(bt['$empty?']())))) {
5996        bt = self.$caller()
5997      };
5998      first = bt.$shift();
5999      msg = "" + (first) + ": ";
6000      msg = $rb_plus(msg, "" + (bold) + (self.$to_s()) + " (" + (bold_underline) + (self.$class()) + (reset) + (bold) + ")" + (reset) + "\n");
6001      msg = $rb_plus(msg, $send(bt, 'map', [], function $$3(loc){
6002        
6003        if (loc == null) loc = nil;
6004        return "\tfrom " + (loc) + "\n";}).$join());
6005      if ($truthy(self.$cause())) {
6006        msg = $rb_plus(msg, self.$cause().$full_message($hash2(["highlight"], {"highlight": highlight})))
6007      };
6008      if ($eqeq(order, "bottom")) {
6009        
6010        msg = msg.$split("\n").$reverse().$join("\n");
6011        msg = $rb_plus("" + (bold) + "Traceback" + (reset) + " (most recent call last):\n", msg);
6012      };
6013      return msg;
6014    }, -1);
6015    
6016    $def(self, '$inspect', function $$inspect() {
6017      var self = this, as_str = nil;
6018
6019      
6020      as_str = self.$to_s();
6021      if ($truthy(as_str['$empty?']())) {
6022        return self.$class().$to_s()
6023      } else {
6024        return "#<" + (self.$class().$to_s()) + ": " + (self.$to_s()) + ">"
6025      };
6026    });
6027    
6028    $def(self, '$set_backtrace', function $$set_backtrace(backtrace) {
6029      var self = this;
6030
6031      
6032      var valid = true, i, ii;
6033
6034      if (backtrace === nil) {
6035        self.backtrace = nil;
6036        self.stack = '';
6037      } else if (backtrace.$$is_string) {
6038        self.backtrace = [backtrace];
6039        self.stack = '  from ' + backtrace;
6040      } else {
6041        if (backtrace.$$is_array) {
6042          for (i = 0, ii = backtrace.length; i < ii; i++) {
6043            if (!backtrace[i].$$is_string) {
6044              valid = false;
6045              break;
6046            }
6047          }
6048        } else {
6049          valid = false;
6050        }
6051
6052        if (valid === false) {
6053          $Kernel.$raise($$$('TypeError'), "backtrace must be Array of String")
6054        }
6055
6056        self.backtrace = backtrace;
6057        self.stack = $send((backtrace), 'map', [], function $$4(i){
6058        
6059        if (i == null) i = nil;
6060        return $rb_plus("  from ", i);}).join("\n");
6061      }
6062
6063      return backtrace;
6064    
6065    });
6066    return $def(self, '$to_s', function $$to_s() {
6067      var self = this, $ret_or_1 = nil, $ret_or_2 = nil;
6068
6069      if ($truthy(($ret_or_1 = ($truthy(($ret_or_2 = self.message)) ? (self.message.$to_s()) : ($ret_or_2))))) {
6070        return $ret_or_1
6071      } else {
6072        return self.$class().$to_s()
6073      }
6074    });
6075  })('::', Error, $nesting);
6076  $klass('::', $$$('Exception'), 'ScriptError');
6077  $klass('::', $$$('ScriptError'), 'SyntaxError');
6078  $klass('::', $$$('ScriptError'), 'LoadError');
6079  $klass('::', $$$('ScriptError'), 'NotImplementedError');
6080  $klass('::', $$$('Exception'), 'SystemExit');
6081  $klass('::', $$$('Exception'), 'NoMemoryError');
6082  $klass('::', $$$('Exception'), 'SignalException');
6083  $klass('::', $$$('SignalException'), 'Interrupt');
6084  $klass('::', $$$('Exception'), 'SecurityError');
6085  $klass('::', $$$('Exception'), 'SystemStackError');
6086  $klass('::', $$$('Exception'), 'StandardError');
6087  $klass('::', $$$('StandardError'), 'EncodingError');
6088  $klass('::', $$$('StandardError'), 'ZeroDivisionError');
6089  $klass('::', $$$('StandardError'), 'NameError');
6090  $klass('::', $$$('NameError'), 'NoMethodError');
6091  $klass('::', $$$('StandardError'), 'RuntimeError');
6092  $klass('::', $$$('RuntimeError'), 'FrozenError');
6093  $klass('::', $$$('StandardError'), 'LocalJumpError');
6094  $klass('::', $$$('StandardError'), 'TypeError');
6095  $klass('::', $$$('StandardError'), 'ArgumentError');
6096  $klass('::', $$$('ArgumentError'), 'UncaughtThrowError');
6097  $klass('::', $$$('StandardError'), 'IndexError');
6098  $klass('::', $$$('IndexError'), 'StopIteration');
6099  $klass('::', $$$('StopIteration'), 'ClosedQueueError');
6100  $klass('::', $$$('IndexError'), 'KeyError');
6101  $klass('::', $$$('StandardError'), 'RangeError');
6102  $klass('::', $$$('RangeError'), 'FloatDomainError');
6103  $klass('::', $$$('StandardError'), 'IOError');
6104  $klass('::', $$$('IOError'), 'EOFError');
6105  $klass('::', $$$('StandardError'), 'SystemCallError');
6106  $klass('::', $$$('StandardError'), 'RegexpError');
6107  $klass('::', $$$('StandardError'), 'ThreadError');
6108  $klass('::', $$$('StandardError'), 'FiberError');
6109  $Object.$autoload("Errno", "corelib/error/errno");
6110  (function($base, $super) {
6111    var self = $klass($base, $super, 'FrozenError');
6112
6113    
6114    
6115    self.$attr_reader("receiver");
6116    return $def(self, '$initialize', function $$initialize(message, $kwargs) {
6117      var receiver, $yield = $$initialize.$$p || nil, self = this;
6118
6119      $$initialize.$$p = null;
6120      
6121      $kwargs = $ensure_kwargs($kwargs);
6122      
6123      receiver = $kwargs.$$smap["receiver"];if (receiver == null) receiver = nil;
6124      $send2(self, $find_super(self, 'initialize', $$initialize, false, true), 'initialize', [message], null);
6125      return (self.receiver = receiver);
6126    }, -2);
6127  })('::', $$$('RuntimeError'));
6128  (function($base, $super) {
6129    var self = $klass($base, $super, 'UncaughtThrowError');
6130
6131    var $proto = self.$$prototype;
6132
6133    $proto.tag = nil;
6134    
6135    self.$attr_reader("tag", "value");
6136    return $def(self, '$initialize', function $$initialize(tag, value) {
6137      var $yield = $$initialize.$$p || nil, self = this;
6138
6139      $$initialize.$$p = null;
6140      
6141      if (value == null) value = nil;
6142      self.tag = tag;
6143      self.value = value;
6144      return $send2(self, $find_super(self, 'initialize', $$initialize, false, true), 'initialize', ["uncaught throw " + (self.tag.$inspect())], null);
6145    }, -2);
6146  })('::', $$$('ArgumentError'));
6147  (function($base, $super) {
6148    var self = $klass($base, $super, 'NameError');
6149
6150    
6151    
6152    self.$attr_reader("name");
6153    return $def(self, '$initialize', function $$initialize(message, name) {
6154      var $yield = $$initialize.$$p || nil, self = this;
6155
6156      $$initialize.$$p = null;
6157      
6158      if (name == null) name = nil;
6159      $send2(self, $find_super(self, 'initialize', $$initialize, false, true), 'initialize', [message], null);
6160      return (self.name = name);
6161    }, -2);
6162  })('::', null);
6163  (function($base, $super) {
6164    var self = $klass($base, $super, 'NoMethodError');
6165
6166    
6167    
6168    self.$attr_reader("args");
6169    return $def(self, '$initialize', function $$initialize(message, name, args) {
6170      var $yield = $$initialize.$$p || nil, self = this;
6171
6172      $$initialize.$$p = null;
6173      
6174      if (name == null) name = nil;
6175      if (args == null) args = [];
6176      $send2(self, $find_super(self, 'initialize', $$initialize, false, true), 'initialize', [message, name], null);
6177      return (self.args = args);
6178    }, -2);
6179  })('::', null);
6180  (function($base, $super) {
6181    var self = $klass($base, $super, 'StopIteration');
6182
6183    
6184    return self.$attr_reader("result")
6185  })('::', null);
6186  (function($base, $super) {
6187    var self = $klass($base, $super, 'KeyError');
6188
6189    var $proto = self.$$prototype;
6190
6191    $proto.receiver = $proto.key = nil;
6192    
6193    
6194    $def(self, '$initialize', function $$initialize(message, $kwargs) {
6195      var receiver, key, $yield = $$initialize.$$p || nil, self = this;
6196
6197      $$initialize.$$p = null;
6198      
6199      $kwargs = $ensure_kwargs($kwargs);
6200      
6201      receiver = $kwargs.$$smap["receiver"];if (receiver == null) receiver = nil;
6202      
6203      key = $kwargs.$$smap["key"];if (key == null) key = nil;
6204      $send2(self, $find_super(self, 'initialize', $$initialize, false, true), 'initialize', [message], null);
6205      self.receiver = receiver;
6206      return (self.key = key);
6207    }, -2);
6208    
6209    $def(self, '$receiver', function $$receiver() {
6210      var self = this, $ret_or_1 = nil;
6211
6212      if ($truthy(($ret_or_1 = self.receiver))) {
6213        return $ret_or_1
6214      } else {
6215        return $Kernel.$raise($$$('ArgumentError'), "no receiver is available")
6216      }
6217    });
6218    return $def(self, '$key', function $$key() {
6219      var self = this, $ret_or_1 = nil;
6220
6221      if ($truthy(($ret_or_1 = self.key))) {
6222        return $ret_or_1
6223      } else {
6224        return $Kernel.$raise($$$('ArgumentError'), "no key is available")
6225      }
6226    });
6227  })('::', null);
6228  return (function($base, $parent_nesting) {
6229    var self = $module($base, 'JS');
6230
6231    var $nesting = [self].concat($parent_nesting);
6232
6233    return ($klass($nesting[0], null, 'Error'), nil)
6234  })('::', $nesting);
6235};
6236
6237Opal.modules["corelib/constants"] = function(Opal) {/* Generated by Opal 1.7.3 */
6238  var $const_set = Opal.const_set, nil = Opal.nil, $$$ = Opal.$$$;
6239
6240  
6241  $const_set('::', 'RUBY_PLATFORM', "opal");
6242  $const_set('::', 'RUBY_ENGINE', "opal");
6243  $const_set('::', 'RUBY_VERSION', "3.2.0");
6244  $const_set('::', 'RUBY_ENGINE_VERSION', "1.7.3");
6245  $const_set('::', 'RUBY_RELEASE_DATE', "2023-03-23");
6246  $const_set('::', 'RUBY_PATCHLEVEL', 0);
6247  $const_set('::', 'RUBY_REVISION', "0");
6248  $const_set('::', 'RUBY_COPYRIGHT', "opal - Copyright (C) 2011-2023 Adam Beynon and the Opal contributors");
6249  return $const_set('::', 'RUBY_DESCRIPTION', "opal " + ($$$('RUBY_ENGINE_VERSION')) + " (" + ($$$('RUBY_RELEASE_DATE')) + " revision " + ($$$('RUBY_REVISION')) + ")");
6250};
6251
6252Opal.modules["opal/base"] = function(Opal) {/* Generated by Opal 1.7.3 */
6253  var $Object = Opal.Object, nil = Opal.nil;
6254
6255  Opal.add_stubs('require');
6256  
6257  $Object.$require("corelib/runtime");
6258  $Object.$require("corelib/helpers");
6259  $Object.$require("corelib/module");
6260  $Object.$require("corelib/class");
6261  $Object.$require("corelib/basic_object");
6262  $Object.$require("corelib/kernel");
6263  $Object.$require("corelib/main");
6264  $Object.$require("corelib/error");
6265  return $Object.$require("corelib/constants");
6266};
6267
6268Opal.modules["corelib/nil"] = function(Opal) {/* Generated by Opal 1.7.3 */
6269  var $klass = Opal.klass, $Kernel = Opal.Kernel, $def = Opal.def, $return_val = Opal.return_val, $ensure_kwargs = Opal.ensure_kwargs, $NilClass = Opal.NilClass, $slice = Opal.slice, $truthy = Opal.truthy, $rb_gt = Opal.rb_gt, $alias = Opal.alias, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$;
6270
6271  Opal.add_stubs('raise,name,new,>,length,Rational,to_i');
6272  return (function($base, $super, $parent_nesting) {
6273    var self = $klass($base, $super, 'NilClass');
6274
6275    var $nesting = [self].concat($parent_nesting);
6276
6277    
6278    self.$$prototype.$$meta = self;
6279    (function(self, $parent_nesting) {
6280      
6281      
6282      
6283      $def(self, '$allocate', function $$allocate() {
6284        var self = this;
6285
6286        return $Kernel.$raise($$$('TypeError'), "allocator undefined for " + (self.$name()))
6287      });
6288      
6289      
6290      Opal.udef(self, '$' + "new");;
6291      return nil;;
6292    })(Opal.get_singleton_class(self), $nesting);
6293    
6294    $def(self, '$!', $return_val(true));
6295    
6296    $def(self, '$&', $return_val(false));
6297    
6298    $def(self, '$|', function $NilClass_$$1(other) {
6299      
6300      return other !== false && other !== nil;
6301    });
6302    
6303    $def(self, '$^', function $NilClass_$$2(other) {
6304      
6305      return other !== false && other !== nil;
6306    });
6307    
6308    $def(self, '$==', function $NilClass_$eq_eq$3(other) {
6309      
6310      return other === nil;
6311    });
6312    
6313    $def(self, '$dup', $return_val(nil));
6314    
6315    $def(self, '$clone', function $$clone($kwargs) {
6316      var freeze;
6317
6318      
6319      $kwargs = $ensure_kwargs($kwargs);
6320      
6321      freeze = $kwargs.$$smap["freeze"];if (freeze == null) freeze = true;
6322      return nil;
6323    }, -1);
6324    
6325    $def(self, '$inspect', $return_val("nil"));
6326    
6327    $def(self, '$nil?', $return_val(true));
6328    
6329    $def(self, '$singleton_class', function $$singleton_class() {
6330      
6331      return $NilClass
6332    });
6333    
6334    $def(self, '$to_a', function $$to_a() {
6335      
6336      return []
6337    });
6338    
6339    $def(self, '$to_h', function $$to_h() {
6340      
6341      return Opal.hash();
6342    });
6343    
6344    $def(self, '$to_i', $return_val(0));
6345    
6346    $def(self, '$to_s', $return_val(""));
6347    
6348    $def(self, '$to_c', function $$to_c() {
6349      
6350      return $$$('Complex').$new(0, 0)
6351    });
6352    
6353    $def(self, '$rationalize', function $$rationalize($a) {
6354      var $post_args, args;
6355
6356      
6357      $post_args = $slice(arguments);
6358      args = $post_args;
6359      if ($truthy($rb_gt(args.$length(), 1))) {
6360        $Kernel.$raise($$$('ArgumentError'))
6361      };
6362      return $Kernel.$Rational(0, 1);
6363    }, -1);
6364    
6365    $def(self, '$to_r', function $$to_r() {
6366      
6367      return $Kernel.$Rational(0, 1)
6368    });
6369    
6370    $def(self, '$instance_variables', function $$instance_variables() {
6371      
6372      return []
6373    });
6374    return $alias(self, "to_f", "to_i");
6375  })('::', null, $nesting)
6376};
6377
6378Opal.modules["corelib/boolean"] = function(Opal) {/* Generated by Opal 1.7.3 */
6379  "use strict";
6380  var $klass = Opal.klass, $Kernel = Opal.Kernel, $def = Opal.def, $return_self = Opal.return_self, $ensure_kwargs = Opal.ensure_kwargs, $slice = Opal.slice, $truthy = Opal.truthy, $send2 = Opal.send2, $find_super = Opal.find_super, $to_a = Opal.to_a, $alias = Opal.alias, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$;
6381
6382  Opal.add_stubs('raise,name,==,to_s,__id__');
6383  
6384  (function($base, $super, $parent_nesting) {
6385    var self = $klass($base, $super, 'Boolean');
6386
6387    var $nesting = [self].concat($parent_nesting);
6388
6389    
6390    Opal.prop(self.$$prototype, '$$is_boolean', true);
6391    
6392    var properties = ['$$class', '$$meta'];
6393
6394    for (var i = 0; i < properties.length; i++) {
6395      Object.defineProperty(self.$$prototype, properties[i], {
6396        configurable: true,
6397        enumerable: false,
6398        get: function() {
6399          return this == true  ? Opal.TrueClass :
6400                 this == false ? Opal.FalseClass :
6401                                 Opal.Boolean;
6402        }
6403      });
6404    }
6405
6406    Object.defineProperty(self.$$prototype, "$$id", {
6407      configurable: true,
6408      enumerable: false,
6409      get: function() {
6410        return this == true  ? 2 :
6411               this == false ? 0 :
6412                               nil;
6413      }
6414    });
6415  ;
6416    (function(self, $parent_nesting) {
6417      
6418      
6419      
6420      $def(self, '$allocate', function $$allocate() {
6421        var self = this;
6422
6423        return $Kernel.$raise($$$('TypeError'), "allocator undefined for " + (self.$name()))
6424      });
6425      
6426      
6427      Opal.udef(self, '$' + "new");;
6428      return nil;;
6429    })(Opal.get_singleton_class(self), $nesting);
6430    
6431    $def(self, '$__id__', function $$__id__() {
6432      var self = this;
6433
6434      return self.valueOf() ? 2 : 0;
6435    });
6436    
6437    $def(self, '$!', function $Boolean_$excl$1() {
6438      var self = this;
6439
6440      return self != true;
6441    });
6442    
6443    $def(self, '$&', function $Boolean_$$2(other) {
6444      var self = this;
6445
6446      return (self == true) ? (other !== false && other !== nil) : false;
6447    });
6448    
6449    $def(self, '$|', function $Boolean_$$3(other) {
6450      var self = this;
6451
6452      return (self == true) ? true : (other !== false && other !== nil);
6453    });
6454    
6455    $def(self, '$^', function $Boolean_$$4(other) {
6456      var self = this;
6457
6458      return (self == true) ? (other === false || other === nil) : (other !== false && other !== nil);
6459    });
6460    
6461    $def(self, '$==', function $Boolean_$eq_eq$5(other) {
6462      var self = this;
6463
6464      return (self == true) === other.valueOf();
6465    });
6466    
6467    $def(self, '$singleton_class', function $$singleton_class() {
6468      var self = this;
6469
6470      return self.$$meta;
6471    });
6472    
6473    $def(self, '$to_s', function $$to_s() {
6474      var self = this;
6475
6476      return (self == true) ? 'true' : 'false';
6477    });
6478    
6479    $def(self, '$dup', $return_self);
6480    
6481    $def(self, '$clone', function $$clone($kwargs) {
6482      var freeze, self = this;
6483
6484      
6485      $kwargs = $ensure_kwargs($kwargs);
6486      
6487      freeze = $kwargs.$$smap["freeze"];if (freeze == null) freeze = true;
6488      return self;
6489    }, -1);
6490    
6491    $def(self, '$method_missing', function $$method_missing(method, $a) {
6492      var block = $$method_missing.$$p || nil, $post_args, args, self = this;
6493
6494      $$method_missing.$$p = null;
6495      
6496      ;
6497      $post_args = $slice(arguments, 1);
6498      args = $post_args;
6499      var body = self.$$class.$$prototype[Opal.jsid(method)];
6500      if (!$truthy(typeof body !== 'undefined' && !body.$$stub)) {
6501        $send2(self, $find_super(self, 'method_missing', $$method_missing, false, true), 'method_missing', [method].concat($to_a(args)), block)
6502      };
6503      return Opal.send(self, body, args, block);
6504    }, -2);
6505    
6506    $def(self, '$respond_to_missing?', function $Boolean_respond_to_missing$ques$6(method, _include_all) {
6507      var self = this;
6508
6509      
6510      if (_include_all == null) _include_all = false;
6511      var body = self.$$class.$$prototype[Opal.jsid(method)];
6512      return typeof body !== 'undefined' && !body.$$stub;;
6513    }, -2);
6514    $alias(self, "eql?", "==");
6515    $alias(self, "equal?", "==");
6516    $alias(self, "inspect", "to_s");
6517    return $alias(self, "object_id", "__id__");
6518  })('::', Boolean, $nesting);
6519  $klass('::', $$$('Boolean'), 'TrueClass');
6520  return ($klass('::', $$$('Boolean'), 'FalseClass'), nil);
6521};
6522
6523Opal.modules["corelib/comparable"] = function(Opal) {/* Generated by Opal 1.7.3 */
6524  var $truthy = Opal.truthy, $module = Opal.module, $rb_gt = Opal.rb_gt, $rb_lt = Opal.rb_lt, $eqeqeq = Opal.eqeqeq, $Kernel = Opal.Kernel, $def = Opal.def, nil = Opal.nil, $$$ = Opal.$$$;
6525
6526  Opal.add_stubs('>,<,===,raise,class,<=>,equal?');
6527  return (function($base) {
6528    var self = $module($base, 'Comparable');
6529
6530    var $ret_or_1 = nil;
6531
6532    
6533    
6534    function normalize(what) {
6535      if (Opal.is_a(what, Opal.Integer)) { return what; }
6536
6537      if ($rb_gt(what, 0)) { return 1; }
6538      if ($rb_lt(what, 0)) { return -1; }
6539      return 0;
6540    }
6541
6542    function fail_comparison(lhs, rhs) {
6543      var class_name;
6544      (($eqeqeq(nil, ($ret_or_1 = rhs)) || (($eqeqeq(true, $ret_or_1) || (($eqeqeq(false, $ret_or_1) || (($eqeqeq($$$('Integer'), $ret_or_1) || ($eqeqeq($$$('Float'), $ret_or_1))))))))) ? (class_name = rhs.$inspect()) : (class_name = rhs.$$class))
6545      $Kernel.$raise($$$('ArgumentError'), "comparison of " + ((lhs).$class()) + " with " + (class_name) + " failed")
6546    }
6547
6548    function cmp_or_fail(lhs, rhs) {
6549      var cmp = (lhs)['$<=>'](rhs);
6550      if (!$truthy(cmp)) fail_comparison(lhs, rhs);
6551      return normalize(cmp);
6552    }
6553  ;
6554    
6555    $def(self, '$==', function $Comparable_$eq_eq$1(other) {
6556      var self = this, cmp = nil;
6557
6558      
6559      if ($truthy(self['$equal?'](other))) {
6560        return true
6561      };
6562      
6563      if (self["$<=>"] == Opal.Kernel["$<=>"]) {
6564        return false;
6565      }
6566
6567      // check for infinite recursion
6568      if (self.$$comparable) {
6569        self.$$comparable = false;
6570        return false;
6571      }
6572    ;
6573      if (!$truthy((cmp = self['$<=>'](other)))) {
6574        return false
6575      };
6576      return normalize(cmp) == 0;;
6577    });
6578    
6579    $def(self, '$>', function $Comparable_$gt$2(other) {
6580      var self = this;
6581
6582      return cmp_or_fail(self, other) > 0;
6583    });
6584    
6585    $def(self, '$>=', function $Comparable_$gt_eq$3(other) {
6586      var self = this;
6587
6588      return cmp_or_fail(self, other) >= 0;
6589    });
6590    
6591    $def(self, '$<', function $Comparable_$lt$4(other) {
6592      var self = this;
6593
6594      return cmp_or_fail(self, other) < 0;
6595    });
6596    
6597    $def(self, '$<=', function $Comparable_$lt_eq$5(other) {
6598      var self = this;
6599
6600      return cmp_or_fail(self, other) <= 0;
6601    });
6602    
6603    $def(self, '$between?', function $Comparable_between$ques$6(min, max) {
6604      var self = this;
6605
6606      
6607      if ($rb_lt(self, min)) {
6608        return false
6609      };
6610      if ($rb_gt(self, max)) {
6611        return false
6612      };
6613      return true;
6614    });
6615    return $def(self, '$clamp', function $$clamp(min, max) {
6616      var self = this;
6617
6618      
6619      if (max == null) max = nil;
6620      
6621      var c, excl;
6622
6623      if (max === nil) {
6624        // We are dealing with a new Ruby 2.7 behaviour that we are able to
6625        // provide a single Range argument instead of 2 Comparables.
6626
6627        if (!Opal.is_a(min, Opal.Range)) {
6628          $Kernel.$raise($$$('TypeError'), "wrong argument type " + (min.$class()) + " (expected Range)")
6629        }
6630
6631        excl = min.excl;
6632        max = min.end;
6633        min = min.begin;
6634
6635        if (max !== nil && excl) {
6636          $Kernel.$raise($$$('ArgumentError'), "cannot clamp with an exclusive range")
6637        }
6638      }
6639
6640      if (min !== nil && max !== nil && cmp_or_fail(min, max) > 0) {
6641        $Kernel.$raise($$$('ArgumentError'), "min argument must be smaller than max argument")
6642      }
6643
6644      if (min !== nil) {
6645        c = cmp_or_fail(self, min);
6646
6647        if (c == 0) return self;
6648        if (c < 0) return min;
6649      }
6650
6651      if (max !== nil) {
6652        c = cmp_or_fail(self, max);
6653
6654        if (c > 0) return max;
6655      }
6656
6657      return self;
6658    ;
6659    }, -2);
6660  })('::')
6661};
6662
6663Opal.modules["corelib/regexp"] = function(Opal) {/* Generated by Opal 1.7.3 */
6664  var $coerce_to = Opal.coerce_to, $prop = Opal.prop, $freeze = Opal.freeze, $klass = Opal.klass, $const_set = Opal.const_set, $send2 = Opal.send2, $find_super = Opal.find_super, $def = Opal.def, $truthy = Opal.truthy, $gvars = Opal.gvars, $slice = Opal.slice, $Kernel = Opal.Kernel, $Opal = Opal.Opal, $alias = Opal.alias, $send = Opal.send, $hash2 = Opal.hash2, $rb_plus = Opal.rb_plus, $ensure_kwargs = Opal.ensure_kwargs, $rb_ge = Opal.rb_ge, $to_a = Opal.to_a, $eqeqeq = Opal.eqeqeq, $rb_minus = Opal.rb_minus, $return_ivar = Opal.return_ivar, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$;
6665
6666  Opal.add_stubs('nil?,[],raise,escape,options,to_str,new,join,coerce_to!,!,match,coerce_to?,begin,frozen?,uniq,map,scan,source,to_proc,transform_values,group_by,each_with_index,+,last,=~,==,attr_reader,>=,length,is_a?,include?,names,regexp,named_captures,===,captures,-,inspect,empty?,each,to_a');
6667  
6668  $klass('::', $$$('StandardError'), 'RegexpError');
6669  (function($base, $super, $parent_nesting) {
6670    var self = $klass($base, $super, 'Regexp');
6671
6672    var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
6673
6674    
6675    $const_set(self, 'IGNORECASE', 1);
6676    $const_set(self, 'EXTENDED', 2);
6677    $const_set(self, 'MULTILINE', 4);
6678    Opal.prop(self.$$prototype, '$$is_regexp', true);
6679    (function(self, $parent_nesting) {
6680      var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
6681
6682      
6683      
6684      $def(self, '$allocate', function $$allocate() {
6685        var $yield = $$allocate.$$p || nil, self = this, allocated = nil;
6686
6687        $$allocate.$$p = null;
6688        
6689        allocated = $send2(self, $find_super(self, 'allocate', $$allocate, false, true), 'allocate', [], $yield);
6690        allocated.uninitialized = true;
6691        return allocated;
6692      });
6693      
6694      $def(self, '$escape', function $$escape(string) {
6695        
6696        return Opal.escape_regexp(string);
6697      });
6698      
6699      $def(self, '$last_match', function $$last_match(n) {
6700                if ($gvars["~"] == null) $gvars["~"] = nil;
6701
6702        
6703        if (n == null) n = nil;
6704        if ($truthy(n['$nil?']())) {
6705          return $gvars["~"]
6706        } else if ($truthy($gvars["~"])) {
6707          return $gvars["~"]['$[]'](n)
6708        } else {
6709          return nil
6710        };
6711      }, -1);
6712      
6713      $def(self, '$union', function $$union($a) {
6714        var $post_args, parts, self = this;
6715
6716        
6717        $post_args = $slice(arguments);
6718        parts = $post_args;
6719        
6720        var is_first_part_array, quoted_validated, part, options, each_part_options;
6721        if (parts.length == 0) {
6722          return /(?!)/;
6723        }
6724        // return fast if there's only one element
6725        if (parts.length == 1 && parts[0].$$is_regexp) {
6726          return parts[0];
6727        }
6728        // cover the 2 arrays passed as arguments case
6729        is_first_part_array = parts[0].$$is_array;
6730        if (parts.length > 1 && is_first_part_array) {
6731          $Kernel.$raise($$$('TypeError'), "no implicit conversion of Array into String")
6732        }
6733        // deal with splat issues (related to https://github.com/opal/opal/issues/858)
6734        if (is_first_part_array) {
6735          parts = parts[0];
6736        }
6737        options = undefined;
6738        quoted_validated = [];
6739        for (var i=0; i < parts.length; i++) {
6740          part = parts[i];
6741          if (part.$$is_string) {
6742            quoted_validated.push(self.$escape(part));
6743          }
6744          else if (part.$$is_regexp) {
6745            each_part_options = (part).$options();
6746            if (options != undefined && options != each_part_options) {
6747              $Kernel.$raise($$$('TypeError'), "All expressions must use the same options")
6748            }
6749            options = each_part_options;
6750            quoted_validated.push('('+part.source+')');
6751          }
6752          else {
6753            quoted_validated.push(self.$escape((part).$to_str()));
6754          }
6755        }
6756      ;
6757        return self.$new((quoted_validated).$join("|"), options);
6758      }, -1);
6759      
6760      $def(self, '$new', function $new$1(regexp, options) {
6761        
6762        
6763        ;
6764        
6765        if (regexp.$$is_regexp) {
6766          return new RegExp(regexp);
6767        }
6768
6769        regexp = $Opal['$coerce_to!'](regexp, $$$('String'), "to_str");
6770
6771        if (regexp.charAt(regexp.length - 1) === '\\' && regexp.charAt(regexp.length - 2) !== '\\') {
6772          $Kernel.$raise($$$('RegexpError'), "too short escape sequence: /" + (regexp) + "/")
6773        }
6774
6775        regexp = regexp.replace('\\A', '^').replace('\\z', '$')
6776
6777        if (options === undefined || options['$!']()) {
6778          return new RegExp(regexp);
6779        }
6780
6781        if (options.$$is_number) {
6782          var temp = '';
6783          if ($$('IGNORECASE') & options) { temp += 'i'; }
6784          if ($$('MULTILINE')  & options) { temp += 'm'; }
6785          options = temp;
6786        }
6787        else {
6788          options = 'i';
6789        }
6790
6791        return new RegExp(regexp, options);
6792      ;
6793      }, -2);
6794      $alias(self, "compile", "new");
6795      return $alias(self, "quote", "escape");
6796    })(Opal.get_singleton_class(self), $nesting);
6797    
6798    $def(self, '$==', function $Regexp_$eq_eq$2(other) {
6799      var self = this;
6800
6801      return other instanceof RegExp && self.toString() === other.toString();
6802    });
6803    
6804    $def(self, '$===', function $Regexp_$eq_eq_eq$3(string) {
6805      var self = this;
6806
6807      return self.$match($Opal['$coerce_to?'](string, $$$('String'), "to_str")) !== nil
6808    });
6809    
6810    $def(self, '$=~', function $Regexp_$eq_tilde$4(string) {
6811      var self = this, $ret_or_1 = nil;
6812      if ($gvars["~"] == null) $gvars["~"] = nil;
6813
6814      if ($truthy(($ret_or_1 = self.$match(string)))) {
6815        return $gvars["~"].$begin(0)
6816      } else {
6817        return $ret_or_1
6818      }
6819    });
6820    
6821    $def(self, '$freeze', function $$freeze() {
6822      var self = this;
6823
6824      
6825      if ($truthy(self['$frozen?']())) {
6826        return self
6827      };
6828      
6829      if (!self.hasOwnProperty('$$g')) { $prop(self, '$$g', null); }
6830      if (!self.hasOwnProperty('$$gm')) { $prop(self, '$$gm', null); }
6831
6832      return $freeze(self);
6833    ;
6834    });
6835    
6836    $def(self, '$inspect', function $$inspect() {
6837      var self = this;
6838
6839      
6840      var regexp_format = /^\/(.*)\/([^\/]*)$/;
6841      var value = self.toString();
6842      var matches = regexp_format.exec(value);
6843      if (matches) {
6844        var regexp_pattern = matches[1];
6845        var regexp_flags = matches[2];
6846        var chars = regexp_pattern.split('');
6847        var chars_length = chars.length;
6848        var char_escaped = false;
6849        var regexp_pattern_escaped = '';
6850        for (var i = 0; i < chars_length; i++) {
6851          var current_char = chars[i];
6852          if (!char_escaped && current_char == '/') {
6853            regexp_pattern_escaped = regexp_pattern_escaped.concat('\\');
6854          }
6855          regexp_pattern_escaped = regexp_pattern_escaped.concat(current_char);
6856          if (current_char == '\\') {
6857            if (char_escaped) {
6858              // does not over escape
6859              char_escaped = false;
6860            } else {
6861              char_escaped = true;
6862            }
6863          } else {
6864            char_escaped = false;
6865          }
6866        }
6867        return '/' + regexp_pattern_escaped + '/' + regexp_flags;
6868      } else {
6869        return value;
6870      }
6871    
6872    });
6873    
6874    $def(self, '$match', function $$match(string, pos) {
6875      var block = $$match.$$p || nil, self = this;
6876      if ($gvars["~"] == null) $gvars["~"] = nil;
6877
6878      $$match.$$p = null;
6879      
6880      ;
6881      ;
6882      
6883      if (self.uninitialized) {
6884        $Kernel.$raise($$$('TypeError'), "uninitialized Regexp")
6885      }
6886
6887      if (pos === undefined) {
6888        if (string === nil) return ($gvars["~"] = nil);
6889        var m = self.exec($coerce_to(string, $$$('String'), 'to_str'));
6890        if (m) {
6891          ($gvars["~"] = $$$('MatchData').$new(self, m));
6892          return block === nil ? $gvars["~"] : Opal.yield1(block, $gvars["~"]);
6893        } else {
6894          return ($gvars["~"] = nil);
6895        }
6896      }
6897
6898      pos = $coerce_to(pos, $$$('Integer'), 'to_int');
6899
6900      if (string === nil) {
6901        return ($gvars["~"] = nil);
6902      }
6903
6904      string = $coerce_to(string, $$$('String'), 'to_str');
6905
6906      if (pos < 0) {
6907        pos += string.length;
6908        if (pos < 0) {
6909          return ($gvars["~"] = nil);
6910        }
6911      }
6912
6913      // global RegExp maintains state, so not using self/this
6914      var md, re = Opal.global_regexp(self);
6915
6916      while (true) {
6917        md = re.exec(string);
6918        if (md === null) {
6919          return ($gvars["~"] = nil);
6920        }
6921        if (md.index >= pos) {
6922          ($gvars["~"] = $$$('MatchData').$new(re, md));
6923          return block === nil ? $gvars["~"] : Opal.yield1(block, $gvars["~"]);
6924        }
6925        re.lastIndex = md.index + 1;
6926      }
6927    ;
6928    }, -2);
6929    
6930    $def(self, '$match?', function $Regexp_match$ques$5(string, pos) {
6931      var self = this;
6932
6933      
6934      ;
6935      
6936      if (self.uninitialized) {
6937        $Kernel.$raise($$$('TypeError'), "uninitialized Regexp")
6938      }
6939
6940      if (pos === undefined) {
6941        return string === nil ? false : self.test($coerce_to(string, $$$('String'), 'to_str'));
6942      }
6943
6944      pos = $coerce_to(pos, $$$('Integer'), 'to_int');
6945
6946      if (string === nil) {
6947        return false;
6948      }
6949
6950      string = $coerce_to(string, $$$('String'), 'to_str');
6951
6952      if (pos < 0) {
6953        pos += string.length;
6954        if (pos < 0) {
6955          return false;
6956        }
6957      }
6958
6959      // global RegExp maintains state, so not using self/this
6960      var md, re = Opal.global_regexp(self);
6961
6962      md = re.exec(string);
6963      if (md === null || md.index < pos) {
6964        return false;
6965      } else {
6966        return true;
6967      }
6968    ;
6969    }, -2);
6970    
6971    $def(self, '$names', function $$names() {
6972      var self = this;
6973
6974      return $send(self.$source().$scan(/\(?<(\w+)>/, $hash2(["no_matchdata"], {"no_matchdata": true})), 'map', [], "first".$to_proc()).$uniq()
6975    });
6976    
6977    $def(self, '$named_captures', function $$named_captures() {
6978      var self = this;
6979
6980      return $send($send($send(self.$source().$scan(/\(?<(\w+)>/, $hash2(["no_matchdata"], {"no_matchdata": true})), 'map', [], "first".$to_proc()).$each_with_index(), 'group_by', [], "first".$to_proc()), 'transform_values', [], function $$6(i){
6981        
6982        if (i == null) i = nil;
6983        return $send(i, 'map', [], function $$7(j){
6984          
6985          if (j == null) j = nil;
6986          return $rb_plus(j.$last(), 1);});})
6987    });
6988    
6989    $def(self, '$~', function $Regexp_$$8() {
6990      var self = this;
6991      if ($gvars._ == null) $gvars._ = nil;
6992
6993      return self['$=~']($gvars._)
6994    });
6995    
6996    $def(self, '$source', function $$source() {
6997      var self = this;
6998
6999      return self.source;
7000    });
7001    
7002    $def(self, '$options', function $$options() {
7003      var self = this;
7004
7005      
7006      if (self.uninitialized) {
7007        $Kernel.$raise($$$('TypeError'), "uninitialized Regexp")
7008      }
7009      var result = 0;
7010      // should be supported in IE6 according to https://msdn.microsoft.com/en-us/library/7f5z26w4(v=vs.94).aspx
7011      if (self.multiline) {
7012        result |= $$('MULTILINE');
7013      }
7014      if (self.ignoreCase) {
7015        result |= $$('IGNORECASE');
7016      }
7017      return result;
7018    
7019    });
7020    
7021    $def(self, '$casefold?', function $Regexp_casefold$ques$9() {
7022      var self = this;
7023
7024      return self.ignoreCase;
7025    });
7026    $alias(self, "eql?", "==");
7027    return $alias(self, "to_s", "source");
7028  })('::', RegExp, $nesting);
7029  return (function($base, $super, $parent_nesting) {
7030    var self = $klass($base, $super, 'MatchData');
7031
7032    var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype;
7033
7034    $proto.matches = nil;
7035    
7036    self.$attr_reader("post_match", "pre_match", "regexp", "string");
7037    
7038    $def(self, '$initialize', function $$initialize(regexp, match_groups, $kwargs) {
7039      var no_matchdata, self = this;
7040
7041      
7042      $kwargs = $ensure_kwargs($kwargs);
7043      
7044      no_matchdata = $kwargs.$$smap["no_matchdata"];if (no_matchdata == null) no_matchdata = false;
7045      if (!$truthy(no_matchdata)) {
7046        $gvars["~"] = self
7047      };
7048      self.regexp = regexp;
7049      self.begin = match_groups.index;
7050      self.string = match_groups.input;
7051      self.pre_match = match_groups.input.slice(0, match_groups.index);
7052      self.post_match = match_groups.input.slice(match_groups.index + match_groups[0].length);
7053      self.matches = [];
7054      
7055      for (var i = 0, length = match_groups.length; i < length; i++) {
7056        var group = match_groups[i];
7057
7058        if (group == null) {
7059          self.matches.push(nil);
7060        }
7061        else {
7062          self.matches.push(group);
7063        }
7064      }
7065    ;
7066    }, -3);
7067    
7068    $def(self, '$match', function $$match(idx) {
7069      var self = this, match = nil;
7070
7071      if ($truthy((match = self['$[]'](idx)))) {
7072        return match
7073      } else if (($truthy(idx['$is_a?']($$('Integer'))) && ($truthy($rb_ge(idx, self.$length()))))) {
7074        return $Kernel.$raise($$$('IndexError'), "index " + (idx) + " out of matches")
7075      } else {
7076        return nil
7077      }
7078    });
7079    
7080    $def(self, '$match_length', function $$match_length(idx) {
7081      var $a, self = this;
7082
7083      return ($a = self.$match(idx), ($a === nil || $a == null) ? nil : $a.$length())
7084    });
7085    
7086    $def(self, '$[]', function $MatchData_$$$10($a) {
7087      var $post_args, args, self = this;
7088
7089      
7090      $post_args = $slice(arguments);
7091      args = $post_args;
7092      
7093      if (args[0].$$is_string) {
7094        if (self.$regexp().$names()['$include?'](args['$[]'](0))['$!']()) {
7095          $Kernel.$raise($$$('IndexError'), "undefined group name reference: " + (args['$[]'](0)))
7096        }
7097        return self.$named_captures()['$[]'](args['$[]'](0))
7098      }
7099      else {
7100        return $send(self.matches, '[]', $to_a(args))
7101      }
7102    ;
7103    }, -1);
7104    
7105    $def(self, '$offset', function $$offset(n) {
7106      var self = this;
7107
7108      
7109      if (n !== 0) {
7110        $Kernel.$raise($$$('ArgumentError'), "MatchData#offset only supports 0th element")
7111      }
7112      return [self.begin, self.begin + self.matches[n].length];
7113    
7114    });
7115    
7116    $def(self, '$==', function $MatchData_$eq_eq$11(other) {
7117      var self = this, $ret_or_1 = nil, $ret_or_2 = nil, $ret_or_3 = nil, $ret_or_4 = nil;
7118
7119      
7120      if (!$eqeqeq($$$('MatchData'), other)) {
7121        return false
7122      };
7123      if ($truthy(($ret_or_1 = ($truthy(($ret_or_2 = ($truthy(($ret_or_3 = ($truthy(($ret_or_4 = self.string == other.string)) ? (self.regexp.toString() == other.regexp.toString()) : ($ret_or_4)))) ? (self.pre_match == other.pre_match) : ($ret_or_3)))) ? (self.post_match == other.post_match) : ($ret_or_2))))) {
7124        return self.begin == other.begin;
7125      } else {
7126        return $ret_or_1
7127      };
7128    });
7129    
7130    $def(self, '$begin', function $$begin(n) {
7131      var self = this;
7132
7133      
7134      if (n !== 0) {
7135        $Kernel.$raise($$$('ArgumentError'), "MatchData#begin only supports 0th element")
7136      }
7137      return self.begin;
7138    
7139    });
7140    
7141    $def(self, '$end', function $$end(n) {
7142      var self = this;
7143
7144      
7145      if (n !== 0) {
7146        $Kernel.$raise($$$('ArgumentError'), "MatchData#end only supports 0th element")
7147      }
7148      return self.begin + self.matches[n].length;
7149    
7150    });
7151    
7152    $def(self, '$captures', function $$captures() {
7153      var self = this;
7154
7155      return self.matches.slice(1)
7156    });
7157    
7158    $def(self, '$named_captures', function $$named_captures() {
7159      var self = this, matches = nil;
7160
7161      
7162      matches = self.$captures();
7163      return $send(self.$regexp().$named_captures(), 'transform_values', [], function $$12(i){
7164        
7165        if (i == null) i = nil;
7166        return matches['$[]']($rb_minus(i.$last(), 1));});
7167    });
7168    
7169    $def(self, '$names', function $$names() {
7170      var self = this;
7171
7172      return self.$regexp().$names()
7173    });
7174    
7175    $def(self, '$inspect', function $$inspect() {
7176      var self = this;
7177
7178      
7179      var str = "#<MatchData " + (self.matches[0]).$inspect();
7180
7181      if (self.$regexp().$names()['$empty?']()) {
7182        for (var i = 1, length = self.matches.length; i < length; i++) {
7183          str += " " + i + ":" + (self.matches[i]).$inspect();
7184        }
7185      }
7186      else {
7187        $send(self.$named_captures(), 'each', [], function $$13(k, v){
7188        
7189        if (k == null) k = nil;
7190        if (v == null) v = nil;
7191        return                str += " " + k + ":" + v.$inspect();})
7192      }
7193
7194      return str + ">";
7195    
7196    });
7197    
7198    $def(self, '$length', function $$length() {
7199      var self = this;
7200
7201      return self.matches.length
7202    });
7203    
7204    $def(self, '$to_a', $return_ivar("matches"));
7205    
7206    $def(self, '$to_s', function $$to_s() {
7207      var self = this;
7208
7209      return self.matches[0]
7210    });
7211    
7212    $def(self, '$values_at', function $$values_at($a) {
7213      var $post_args, args, self = this;
7214
7215      
7216      $post_args = $slice(arguments);
7217      args = $post_args;
7218      
7219      var i, a, index, values = [];
7220
7221      for (i = 0; i < args.length; i++) {
7222
7223        if (args[i].$$is_range) {
7224          a = (args[i]).$to_a();
7225          a.unshift(i, 1);
7226          Array.prototype.splice.apply(args, a);
7227        }
7228
7229        index = $Opal['$coerce_to!'](args[i], $$$('Integer'), "to_int");
7230
7231        if (index < 0) {
7232          index += self.matches.length;
7233          if (index < 0) {
7234            values.push(nil);
7235            continue;
7236          }
7237        }
7238
7239        values.push(self.matches[index]);
7240      }
7241
7242      return values;
7243    ;
7244    }, -1);
7245    $alias(self, "eql?", "==");
7246    return $alias(self, "size", "length");
7247  })($nesting[0], null, $nesting);
7248};
7249
7250Opal.modules["corelib/string"] = function(Opal) {/* Generated by Opal 1.7.3 */
7251  var $coerce_to = Opal.coerce_to, $respond_to = Opal.respond_to, $global_multiline_regexp = Opal.global_multiline_regexp, $prop = Opal.prop, $klass = Opal.klass, $def = Opal.def, $Opal = Opal.Opal, $defs = Opal.defs, $slice = Opal.slice, $send = Opal.send, $to_a = Opal.to_a, $extract_kwargs = Opal.extract_kwargs, $ensure_kwargs = Opal.ensure_kwargs, $eqeqeq = Opal.eqeqeq, $Kernel = Opal.Kernel, $truthy = Opal.truthy, $gvars = Opal.gvars, $rb_divide = Opal.rb_divide, $rb_plus = Opal.rb_plus, $eqeq = Opal.eqeq, $hash2 = Opal.hash2, $alias = Opal.alias, $const_set = Opal.const_set, self = Opal.top, $nesting = [], $$ = Opal.$r($nesting), nil = Opal.nil, $$$ = Opal.$$$;
7252
7253  Opal.add_stubs('require,include,coerce_to?,initialize,===,format,raise,respond_to?,to_s,to_str,<=>,==,=~,new,force_encoding,casecmp,empty?,ljust,ceil,/,+,rjust,floor,coerce_to!,nil?,class,copy_singleton_methods,initialize_clone,initialize_dup,enum_for,chomp,[],to_i,length,each_line,to_proc,to_a,match,match?,captures,proc,succ,escape,include?,upcase,unicode_normalize,dup,__id__,next,intern,pristine');
7254  
7255  self.$require("corelib/comparable");
7256  self.$require("corelib/regexp");
7257  (function($base, $super, $parent_nesting) {
7258    var self = $klass($base, $super, 'String');
7259
7260    var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
7261
7262    
7263    self.$include($$$('Comparable'));
7264    
7265    Opal.prop(self.$$prototype, '$$is_string', true);
7266  ;
7267    
7268    $def(self, '$__id__', function $$__id__() {
7269      var self = this;
7270
7271      return self.toString();
7272    });
7273    $defs(self, '$try_convert', function $$try_convert(what) {
7274      
7275      return $Opal['$coerce_to?'](what, $$$('String'), "to_str")
7276    });
7277    $defs(self, '$new', function $String_new$1($a) {
7278      var $post_args, args, self = this;
7279
7280      
7281      $post_args = $slice(arguments);
7282      args = $post_args;
7283      
7284      var str = args[0] || "";
7285      var opts = args[args.length-1];
7286      str = $coerce_to(str, $$$('String'), 'to_str');
7287      if (opts && opts.$$is_hash) {
7288        if (opts.$$smap.encoding) str = str.$force_encoding(opts.$$smap.encoding);
7289      }
7290      str = new self.$$constructor(str);
7291      if (!str.$initialize.$$pristine) $send((str), 'initialize', $to_a(args));
7292      return str;
7293    ;
7294    }, -1);
7295    
7296    $def(self, '$initialize', function $$initialize($a, $b) {
7297      var $post_args, $kwargs, str, encoding, capacity;
7298
7299      
7300      $post_args = $slice(arguments);
7301      $kwargs = $extract_kwargs($post_args);
7302      $kwargs = $ensure_kwargs($kwargs);
7303      
7304      if ($post_args.length > 0) str = $post_args.shift();;
7305      
7306      encoding = $kwargs.$$smap["encoding"];
7306if (encoding == null) encoding = nil;
7307      
7308      capacity = $kwargs.$$smap["capacity"];if (capacity == null) capacity = nil;
7309      return nil;
7310    }, -1);
7311    
7312    $def(self, '$%', function $String_$percent$2(data) {
7313      var self = this;
7314
7315      if ($eqeqeq($$$('Array'), data)) {
7316        return $send(self, 'format', [self].concat($to_a(data)))
7317      } else {
7318        return self.$format(self, data)
7319      }
7320    });
7321    
7322    $def(self, '$*', function $String_$$3(count) {
7323      var self = this;
7324
7325      
7326      count = $coerce_to(count, $$$('Integer'), 'to_int');
7327
7328      if (count < 0) {
7329        $Kernel.$raise($$$('ArgumentError'), "negative argument")
7330      }
7331
7332      if (count === 0) {
7333        return '';
7334      }
7335
7336      var result = '',
7337          string = self.toString();
7338
7339      // All credit for the bit-twiddling magic code below goes to Mozilla
7340      // polyfill implementation of String.prototype.repeat() posted here:
7341      // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat
7342
7343      if (string.length * count >= 1 << 28) {
7344        $Kernel.$raise($$$('RangeError'), "multiply count must not overflow maximum string size")
7345      }
7346
7347      for (;;) {
7348        if ((count & 1) === 1) {
7349          result += string;
7350        }
7351        count >>>= 1;
7352        if (count === 0) {
7353          break;
7354        }
7355        string += string;
7356      }
7357
7358      return result;
7359    
7360    });
7361    
7362    $def(self, '$+', function $String_$plus$4(other) {
7363      var self = this;
7364
7365      
7366      other = $coerce_to(other, $$$('String'), 'to_str');
7367      
7368      if (other == "" && self.$$class === Opal.String) return self;
7369      if (self == "" && other.$$class === Opal.String) return other;
7370      var out = self + other;
7371      if (self.encoding === out.encoding && other.encoding === out.encoding) return out;
7372      if (self.encoding.name === "UTF-8" || other.encoding.name === "UTF-8") return out;
7373      return Opal.enc(out, self.encoding);
7374    ;
7375    });
7376    
7377    $def(self, '$<=>', function $String_$lt_eq_gt$5(other) {
7378      var self = this;
7379
7380      if ($truthy(other['$respond_to?']("to_str"))) {
7381        
7382        other = other.$to_str().$to_s();
7383        return self > other ? 1 : (self < other ? -1 : 0);;
7384      } else {
7385        
7386        var cmp = other['$<=>'](self);
7387
7388        if (cmp === nil) {
7389          return nil;
7390        }
7391        else {
7392          return cmp > 0 ? -1 : (cmp < 0 ? 1 : 0);
7393        }
7394      
7395      }
7396    });
7397    
7398    $def(self, '$==', function $String_$eq_eq$6(other) {
7399      var self = this;
7400
7401      
7402      if (other.$$is_string) {
7403        return self.toString() === other.toString();
7404      }
7405      if ($respond_to(other, '$to_str')) {
7406        return other['$=='](self);
7407      }
7408      return false;
7409    
7410    });
7411    
7412    $def(self, '$=~', function $String_$eq_tilde$7(other) {
7413      var self = this;
7414
7415      
7416      if (other.$$is_string) {
7417        $Kernel.$raise($$$('TypeError'), "type mismatch: String given");
7418      }
7419
7420      return other['$=~'](self);
7421    
7422    });
7423    
7424    $def(self, '$[]', function $String_$$$8(index, length) {
7425      var self = this;
7426
7427      
7428      ;
7429      
7430      var size = self.length, exclude, range;
7431
7432      if (index.$$is_range) {
7433        exclude = index.excl;
7434        range   = index;
7435        length  = index.end === nil ? -1 : $coerce_to(index.end, $$$('Integer'), 'to_int');
7436        index   = index.begin === nil ? 0 : $coerce_to(index.begin, $$$('Integer'), 'to_int');
7437
7438        if (Math.abs(index) > size) {
7439          return nil;
7440        }
7441
7442        if (index < 0) {
7443          index += size;
7444        }
7445
7446        if (length < 0) {
7447          length += size;
7448        }
7449
7450        if (!exclude || range.end === nil) {
7451          length += 1;
7452        }
7453
7454        length = length - index;
7455
7456        if (length < 0) {
7457          length = 0;
7458        }
7459
7460        return self.substr(index, length);
7461      }
7462
7463
7464      if (index.$$is_string) {
7465        if (length != null) {
7466          $Kernel.$raise($$$('TypeError'))
7467        }
7468        return self.indexOf(index) !== -1 ? index : nil;
7469      }
7470
7471
7472      if (index.$$is_regexp) {
7473        var match = self.match(index);
7474
7475        if (match === null) {
7476          ($gvars["~"] = nil)
7477          return nil;
7478        }
7479
7480        ($gvars["~"] = $$$('MatchData').$new(index, match))
7481
7482        if (length == null) {
7483          return match[0];
7484        }
7485
7486        length = $coerce_to(length, $$$('Integer'), 'to_int');
7487
7488        if (length < 0 && -length < match.length) {
7489          return match[length += match.length];
7490        }
7491
7492        if (length >= 0 && length < match.length) {
7493          return match[length];
7494        }
7495
7496        return nil;
7497      }
7498
7499
7500      index = $coerce_to(index, $$$('Integer'), 'to_int');
7501
7502      if (index < 0) {
7503        index += size;
7504      }
7505
7506      if (length == null) {
7507        if (index >= size || index < 0) {
7508          return nil;
7509        }
7510        return self.substr(index, 1);
7511      }
7512
7513      length = $coerce_to(length, $$$('Integer'), 'to_int');
7514
7515      if (length < 0) {
7516        return nil;
7517      }
7518
7519      if (index > size || index < 0) {
7520        return nil;
7521      }
7522
7523      return self.substr(index, length);
7524    ;
7525    }, -2);
7526    
7527    $def(self, '$b', function $$b() {
7528      var self = this;
7529
7530      return (new String(self)).$force_encoding("binary")
7531    });
7532    
7533    $def(self, '$capitalize', function $$capitalize() {
7534      var self = this;
7535
7536      return self.charAt(0).toUpperCase() + self.substr(1).toLowerCase();
7537    });
7538    
7539    $def(self, '$casecmp', function $$casecmp(other) {
7540      var self = this;
7541
7542      
7543      if (!$truthy(other['$respond_to?']("to_str"))) {
7544        return nil
7545      };
7546      other = ($coerce_to(other, $$$('String'), 'to_str')).$to_s();
7547      
7548      var ascii_only = /^[\x00-\x7F]*$/;
7549      if (ascii_only.test(self) && ascii_only.test(other)) {
7550        self = self.toLowerCase();
7551        other = other.toLowerCase();
7552      }
7553    ;
7554      return self['$<=>'](other);
7555    });
7556    
7557    $def(self, '$casecmp?', function $String_casecmp$ques$9(other) {
7558      var self = this;
7559
7560      
7561      var cmp = self.$casecmp(other);
7562      if (cmp === nil) {
7563        return nil;
7564      } else {
7565        return cmp === 0;
7566      }
7567    
7568    });
7569    
7570    $def(self, '$center', function $$center(width, padstr) {
7571      var self = this;
7572
7573      
7574      if (padstr == null) padstr = " ";
7575      width = $coerce_to(width, $$$('Integer'), 'to_int');
7576      padstr = ($coerce_to(padstr, $$$('String'), 'to_str')).$to_s();
7577      if ($truthy(padstr['$empty?']())) {
7578        $Kernel.$raise($$$('ArgumentError'), "zero width padding")
7579      };
7580      if ($truthy(width <= self.length)) {
7581        return self
7582      };
7583      
7584      var ljustified = self.$ljust($rb_divide($rb_plus(width, self.length), 2).$ceil(), padstr),
7585          rjustified = self.$rjust($rb_divide($rb_plus(width, self.length), 2).$floor(), padstr);
7586
7587      return rjustified + ljustified.slice(self.length);
7588    ;
7589    }, -2);
7590    
7591    $def(self, '$chomp', function $$chomp(separator) {
7592      var self = this;
7593      if ($gvars["/"] == null) $gvars["/"] = nil;
7594
7595      
7596      if (separator == null) separator = $gvars["/"];
7597      if ($truthy(separator === nil || self.length === 0)) {
7598        return self
7599      };
7600      separator = $Opal['$coerce_to!'](separator, $$$('String'), "to_str").$to_s();
7601      
7602      var result;
7603
7604      if (separator === "\n") {
7605        result = self.replace(/\r?\n?$/, '');
7606      }
7607      else if (separator === "") {
7608        result = self.replace(/(\r?\n)+$/, '');
7609      }
7610      else if (self.length >= separator.length) {
7611        var tail = self.substr(self.length - separator.length, separator.length);
7612
7613        if (tail === separator) {
7614          result = self.substr(0, self.length - separator.length);
7615        }
7616      }
7617
7618      if (result != null) {
7619        return result;
7620      }
7621    ;
7622      return self;
7623    }, -1);
7624    
7625    $def(self, '$chop', function $$chop() {
7626      var self = this;
7627
7628      
7629      var length = self.length, result;
7630
7631      if (length <= 1) {
7632        result = "";
7633      } else if (self.charAt(length - 1) === "\n" && self.charAt(length - 2) === "\r") {
7634        result = self.substr(0, length - 2);
7635      } else {
7636        result = self.substr(0, length - 1);
7637      }
7638
7639      return result;
7640    
7641    });
7642    
7643    $def(self, '$chr', function $$chr() {
7644      var self = this;
7645
7646      return self.charAt(0);
7647    });
7648    
7649    $def(self, '$clone', function $$clone($kwargs) {
7650      var freeze, self = this, copy = nil;
7651
7652      
7653      $kwargs = $ensure_kwargs($kwargs);
7654      
7655      freeze = $kwargs.$$smap["freeze"];if (freeze == null) freeze = nil;
7656      if (!(($truthy(freeze['$nil?']()) || ($eqeq(freeze, true))) || ($eqeq(freeze, false)))) {
7657        self.$raise($$('ArgumentError'), "unexpected value for freeze: " + (freeze.$class()))
7658      };
7659      copy = new String(self);
7660      copy.$copy_singleton_methods(self);
7661      copy.$initialize_clone(self, $hash2(["freeze"], {"freeze": freeze}));
7662      if ($eqeq(freeze, true)) {
7663        if (!copy.$$frozen) { copy.$$frozen = true; }
7664      } else if ($truthy(freeze['$nil?']())) {
7665        if (self.$$frozen) { copy.$$frozen = true; }
7666      };
7667      return copy;
7668    }, -1);
7669    
7670    $def(self, '$dup', function $$dup() {
7671      var self = this, copy = nil;
7672
7673      
7674      copy = new String(self);
7675      copy.$initialize_dup(self);
7676      return copy;
7677    });
7678    
7679    $def(self, '$count', function $$count($a) {
7680      var $post_args, sets, self = this;
7681
7682      
7683      $post_args = $slice(arguments);
7684      sets = $post_args;
7685      
7686      if (sets.length === 0) {
7687        $Kernel.$raise($$$('ArgumentError'), "ArgumentError: wrong number of arguments (0 for 1+)")
7688      }
7689      var char_class = char_class_from_char_sets(sets);
7690      if (char_class === null) {
7691        return 0;
7692      }
7693      return self.length - self.replace(new RegExp(char_class, 'g'), '').length;
7694    ;
7695    }, -1);
7696    
7697    $def(self, '$delete', function $String_delete$10($a) {
7698      var $post_args, sets, self = this;
7699
7700      
7701      $post_args = $slice(arguments);
7702      sets = $post_args;
7703      
7704      if (sets.length === 0) {
7705        $Kernel.$raise($$$('ArgumentError'), "ArgumentError: wrong number of arguments (0 for 1+)")
7706      }
7707      var char_class = char_class_from_char_sets(sets);
7708      if (char_class === null) {
7709        return self;
7710      }
7711      return self.replace(new RegExp(char_class, 'g'), '');
7712    ;
7713    }, -1);
7714    
7715    $def(self, '$delete_prefix', function $$delete_prefix(prefix) {
7716      var self = this;
7717
7718      
7719      if (!prefix.$$is_string) {
7720        prefix = $coerce_to(prefix, $$$('String'), 'to_str');
7721      }
7722
7723      if (self.slice(0, prefix.length) === prefix) {
7724        return self.slice(prefix.length);
7725      } else {
7726        return self;
7727      }
7728    
7729    });
7730    
7731    $def(self, '$delete_suffix', function $$delete_suffix(suffix) {
7732      var self = this;
7733
7734      
7735      if (!suffix.$$is_string) {
7736        suffix = $coerce_to(suffix, $$$('String'), 'to_str');
7737      }
7738
7739      if (self.slice(self.length - suffix.length) === suffix) {
7740        return self.slice(0, self.length - suffix.length);
7741      } else {
7742        return self;
7743      }
7744    
7745    });
7746    
7747    $def(self, '$downcase', function $$downcase() {
7748      var self = this;
7749
7750      return self.toLowerCase();
7751    });
7752    
7753    $def(self, '$each_line', function $$each_line($a, $b) {
7754      var block = $$each_line.$$p || nil, $post_args, $kwargs, separator, chomp, self = this;
7755      if ($gvars["/"] == null) $gvars["/"] = nil;
7756
7757      $$each_line.$$p = null;
7758      
7759      ;
7760      $post_args = $slice(arguments);
7761      $kwargs = $extract_kwargs($post_args);
7762      $kwargs = $ensure_kwargs($kwargs);
7763      
7764      if ($post_args.length > 0) separator = $post_args.shift();if (separator == null) separator = $gvars["/"];
7765      
7766      chomp = $kwargs.$$smap["chomp"];if (chomp == null) chomp = false;
7767      if (!(block !== nil)) {
7768        return self.$enum_for("each_line", separator, $hash2(["chomp"], {"chomp": chomp}))
7769      };
7770      
7771      if (separator === nil) {
7772        Opal.yield1(block, self);
7773
7774        return self;
7775      }
7776
7777      separator = $coerce_to(separator, $$$('String'), 'to_str');
7778
7779      var a, i, n, length, chomped, trailing, splitted, value;
7780
7781      if (separator.length === 0) {
7782        for (a = self.split(/((?:\r?\n){2})(?:(?:\r?\n)*)/), i = 0, n = a.length; i < n; i += 2) {
7783          if (a[i] || a[i + 1]) {
7784            value = (a[i] || "") + (a[i + 1] || "");
7785            if (chomp) {
7786              value = (value).$chomp("\n");
7787            }
7788            Opal.yield1(block, value);
7789          }
7790        }
7791
7792        return self;
7793      }
7794
7795      chomped  = self.$chomp(separator);
7796      trailing = self.length != chomped.length;
7797      splitted = chomped.split(separator);
7798
7799      for (i = 0, length = splitted.length; i < length; i++) {
7800        value = splitted[i];
7801        if (i < length - 1 || trailing) {
7802          value += separator;
7803        }
7804        if (chomp) {
7805          value = (value).$chomp(separator);
7806        }
7807        Opal.yield1(block, value);
7808      }
7809    ;
7810      return self;
7811    }, -1);
7812    
7813    $def(self, '$empty?', function $String_empty$ques$11() {
7814      var self = this;
7815
7816      return self.length === 0;
7817    });
7818    
7819    $def(self, '$end_with?', function $String_end_with$ques$12($a) {
7820      var $post_args, suffixes, self = this;
7821
7822      
7823      $post_args = $slice(arguments);
7824      suffixes = $post_args;
7825      
7826      for (var i = 0, length = suffixes.length; i < length; i++) {
7827        var suffix = $coerce_to(suffixes[i], $$$('String'), 'to_str').$to_s();
7828
7829        if (self.length >= suffix.length &&
7830            self.substr(self.length - suffix.length, suffix.length) == suffix) {
7831          return true;
7832        }
7833      }
7834    ;
7835      return false;
7836    }, -1);
7837    
7838    $def(self, '$gsub', function $$gsub(pattern, replacement) {
7839      var block = $$gsub.$$p || nil, self = this;
7840
7841      $$gsub.$$p = null;
7842      
7843      ;
7844      ;
7845      
7846      if (replacement === undefined && block === nil) {
7847        return self.$enum_for("gsub", pattern);
7848      }
7849
7850      var result = '', match_data = nil, index = 0, match, _replacement;
7851
7852      if (pattern.$$is_regexp) {
7853        pattern = $global_multiline_regexp(pattern);
7854      } else {
7855        pattern = $coerce_to(pattern, $$$('String'), 'to_str');
7856        pattern = new RegExp(pattern.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'gm');
7857      }
7858
7859      var lastIndex;
7860      while (true) {
7861        match = pattern.exec(self);
7862
7863        if (match === null) {
7864          ($gvars["~"] = nil)
7865          result += self.slice(index);
7866          break;
7867        }
7868
7869        match_data = $$$('MatchData').$new(pattern, match);
7870
7871        if (replacement === undefined) {
7872          lastIndex = pattern.lastIndex;
7873          _replacement = block(match[0]);
7874          pattern.lastIndex = lastIndex; // save and restore lastIndex
7875        }
7876        else if (replacement.$$is_hash) {
7877          _replacement = (replacement)['$[]'](match[0]).$to_s();
7878        }
7879        else {
7880          if (!replacement.$$is_string) {
7881            replacement = $coerce_to(replacement, $$$('String'), 'to_str');
7882          }
7883          _replacement = replacement.replace(/([\\]+)([0-9+&`'])/g, function (original, slashes, command) {
7884            if (slashes.length % 2 === 0) {
7885              return original;
7886            }
7887            switch (command) {
7888            case "+":
7889              for (var i = match.length - 1; i > 0; i--) {
7890                if (match[i] !== undefined) {
7891                  return slashes.slice(1) + match[i];
7892                }
7893              }
7894              return '';
7895            case "&": return slashes.slice(1) + match[0];
7896            case "`": return slashes.slice(1) + self.slice(0, match.index);
7897            case "'": return slashes.slice(1) + self.slice(match.index + match[0].length);
7898            default:  return slashes.slice(1) + (match[command] || '');
7899            }
7900          }).replace(/\\\\/g, '\\');
7901        }
7902
7903        if (pattern.lastIndex === match.index) {
7904          result += (self.slice(index, match.index) + _replacement + (self[match.index] || ""));
7905          pattern.lastIndex += 1;
7906        }
7907        else {
7908          result += (self.slice(index, match.index) + _replacement)
7909        }
7910        index = pattern.lastIndex;
7911      }
7912
7913      ($gvars["~"] = match_data)
7914      return result;
7915    ;
7916    }, -2);
7917    
7918    $def(self, '$hash', function $$hash() {
7919      var self = this;
7920
7921      return self.toString();
7922    });
7923    
7924    $def(self, '$hex', function $$hex() {
7925      var self = this;
7926
7927      return self.$to_i(16)
7928    });
7929    
7930    $def(self, '$include?', function $String_include$ques$13(other) {
7931      var self = this;
7932
7933      
7934      if (!other.$$is_string) {
7935        other = $coerce_to(other, $$$('String'), 'to_str');
7936      }
7937      return self.indexOf(other) !== -1;
7938    
7939    });
7940    
7941    $def(self, '$index', function $$index(search, offset) {
7942      var self = this;
7943
7944      
7945      ;
7946      
7947      var index,
7948          match,
7949          regex;
7950
7951      if (offset === undefined) {
7952        offset = 0;
7953      } else {
7954        offset = $coerce_to(offset, $$$('Integer'), 'to_int');
7955        if (offset < 0) {
7956          offset += self.length;
7957          if (offset < 0) {
7958            return nil;
7959          }
7960        }
7961      }
7962
7963      if (search.$$is_regexp) {
7964        regex = $global_multiline_regexp(search);
7965        while (true) {
7966          match = regex.exec(self);
7967          if (match === null) {
7968            ($gvars["~"] = nil);
7969            index = -1;
7970            break;
7971          }
7972          if (match.index >= offset) {
7973            ($gvars["~"] = $$$('MatchData').$new(regex, match))
7974            index = match.index;
7975            break;
7976          }
7977          regex.lastIndex = match.index + 1;
7978        }
7979      } else {
7980        search = $coerce_to(search, $$$('String'), 'to_str');
7981        if (search.length === 0 && offset > self.length) {
7982          index = -1;
7983        } else {
7984          index = self.indexOf(search, offset);
7985        }
7986      }
7987
7988      return index === -1 ? nil : index;
7989    ;
7990    }, -2);
7991    
7992    $def(self, '$inspect', function $$inspect() {
7993      var self = this;
7994
7995      
7996      /* eslint-disable no-misleading-character-class */
7997      var escapable = /[\\\"\x00-\x1f\u007F-\u009F\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
7998          meta = {
7999            '\u0007': '\\a',
8000            '\u001b': '\\e',
8001            '\b': '\\b',
8002            '\t': '\\t',
8003            '\n': '\\n',
8004            '\f': '\\f',
8005            '\r': '\\r',
8006            '\v': '\\v',
8007            '"' : '\\"',
8008            '\\': '\\\\'
8009          },
8010          escaped = self.replace(escapable, function (chr) {
8011            if (meta[chr]) return meta[chr];
8012            chr = chr.charCodeAt(0);
8013            if (chr <= 0xff && (self.encoding["$binary?"]() || self.internal_encoding["$binary?"]())) {
8014              return '\\x' + ('00' + chr.toString(16).toUpperCase()).slice(-2);
8015            } else {
8016              return '\\u' + ('0000' + chr.toString(16).toUpperCase()).slice(-4);
8017            }
8018          });
8019      return '"' + escaped.replace(/\#[\$\@\{]/g, '\\$&') + '"';
8020      /* eslint-enable no-misleading-character-class */
8021    
8022    });
8023    
8024    $def(self, '$intern', function $$intern() {
8025      var self = this;
8026
8027      return self.toString();
8028    });
8029    
8030    $def(self, '$length', function $$length() {
8031      var self = this;
8032
8033      return self.length;
8034    });
8035    $alias(self, "size", "length");
8036    
8037    $def(self, '$lines', function $$lines($a, $b) {
8038      var block = $$lines.$$p || nil, $post_args, $kwargs, separator, chomp, self = this, e = nil;
8039      if ($gvars["/"] == null) $gvars["/"] = nil;
8040
8041      $$lines.$$p = null;
8042      
8043      ;
8044      $post_args = $slice(arguments);
8045      $kwargs = $extract_kwargs($post_args);
8046      $kwargs = $ensure_kwargs($kwargs);
8047      
8048      if ($post_args.length > 0) separator = $post_args.shift();if (separator == null) separator = $gvars["/"];
8049      
8050      chomp = $kwargs.$$smap["chomp"];if (chomp == null) chomp = false;
8051      e = $send(self, 'each_line', [separator, $hash2(["chomp"], {"chomp": chomp})], block.$to_proc());
8052      if ($truthy(block)) {
8053        return self
8054      } else {
8055        return e.$to_a()
8056      };
8057    }, -1);
8058    
8059    $def(self, '$ljust', function $$ljust(width, padstr) {
8060      var self = this;
8061
8062      
8063      if (padstr == null) padstr = " ";
8064      width = $coerce_to(width, $$$('Integer'), 'to_int');
8065      padstr = ($coerce_to(padstr, $$$('String'), 'to_str')).$to_s();
8066      if ($truthy(padstr['$empty?']())) {
8067        $Kernel.$raise($$$('ArgumentError'), "zero width padding")
8068      };
8069      if ($truthy(width <= self.length)) {
8070        return self
8071      };
8072      
8073      var index  = -1,
8074          result = "";
8075
8076      width -= self.length;
8077
8078      while (++index < width) {
8079        result += padstr;
8080      }
8081
8082      return self + result.slice(0, width);
8083    ;
8084    }, -2);
8085    
8086    $def(self, '$lstrip', function $$lstrip() {
8087      var self = this;
8088
8089      return self.replace(/^[\u0000\s]*/, '');
8090    });
8091    
8092    $def(self, '$ascii_only?', function $String_ascii_only$ques$14() {
8093      var self = this;
8094
8095      
8096      if (!self.encoding.ascii) return false;
8097      return /^[\x00-\x7F]*$/.test(self);
8098    
8099    });
8100    
8101    $def(self, '$match', function $$match(pattern, pos) {
8102      var block = $$match.$$p || nil, self = this;
8103
8104      $$match.$$p = null;
8105      
8106      ;
8107      ;
8108      if (($eqeqeq($$('String'), pattern) || ($truthy(pattern['$respond_to?']("to_str"))))) {
8109        pattern = $$$('Regexp').$new(pattern.$to_str())
8110      };
8111      if (!$eqeqeq($$$('Regexp'), pattern)) {
8112        $Kernel.$raise($$$('TypeError'), "wrong argument type " + (pattern.$class()) + " (expected Regexp)")
8113      };
8114      return $send(pattern, 'match', [self, pos], block.$to_proc());
8115    }, -2);
8116    
8117    $def(self, '$match?', function $String_match$ques$15(pattern, pos) {
8118      var self = this;
8119
8120      
8121      ;
8122      if (($eqeqeq($$('String'), pattern) || ($truthy(pattern['$respond_to?']("to_str"))))) {
8123        pattern = $$$('Regexp').$new(pattern.$to_str())
8124      };
8125      if (!$eqeqeq($$$('Regexp'), pattern)) {
8126        $Kernel.$raise($$$('TypeError'), "wrong argument type " + (pattern.$class()) + " (expected Regexp)")
8127      };
8128      return pattern['$match?'](self, pos);
8129    }, -2);
8130    
8131    $def(self, '$next', function $$next() {
8132      var self = this;
8133
8134      
8135      var i = self.length;
8136      if (i === 0) {
8137        return '';
8138      }
8139      var result = self;
8140      var first_alphanum_char_index = self.search(/[a-zA-Z0-9]/);
8141      var carry = false;
8142      var code;
8143      while (i--) {
8144        code = self.charCodeAt(i);
8145        if ((code >= 48 && code <= 57) ||
8146          (code >= 65 && code <= 90) ||
8147          (code >= 97 && code <= 122)) {
8148          switch (code) {
8149          case 57:
8150            carry = true;
8151            code = 48;
8152            break;
8153          case 90:
8154            carry = true;
8155            code = 65;
8156            break;
8157          case 122:
8158            carry = true;
8159            code = 97;
8160            break;
8161          default:
8162            carry = false;
8163            code += 1;
8164          }
8165        } else {
8166          if (first_alphanum_char_index === -1) {
8167            if (code === 255) {
8168              carry = true;
8169              code = 0;
8170            } else {
8171              carry = false;
8172              code += 1;
8173            }
8174          } else {
8175            carry = true;
8176          }
8177        }
8178        result = result.slice(0, i) + String.fromCharCode(code) + result.slice(i + 1);
8179        if (carry && (i === 0 || i === first_alphanum_char_index)) {
8180          switch (code) {
8181          case 65:
8182            break;
8183          case 97:
8184            break;
8185          default:
8186            code += 1;
8187          }
8188          if (i === 0) {
8189            result = String.fromCharCode(code) + result;
8190          } else {
8191            result = result.slice(0, i) + String.fromCharCode(code) + result.slice(i);
8192          }
8193          carry = false;
8194        }
8195        if (!carry) {
8196          break;
8197        }
8198      }
8199      return result;
8200    
8201    });
8202    
8203    $def(self, '$oct', function $$oct() {
8204      var self = this;
8205
8206      
8207      var result,
8208          string = self,
8209          radix = 8;
8210
8211      if (/^\s*_/.test(string)) {
8212        return 0;
8213      }
8214
8215      string = string.replace(/^(\s*[+-]?)(0[bodx]?)(.+)$/i, function (original, head, flag, tail) {
8216        switch (tail.charAt(0)) {
8217        case '+':
8218        case '-':
8219          return original;
8220        case '0':
8221          if (tail.charAt(1) === 'x' && flag === '0x') {
8222            return original;
8223          }
8224        }
8225        switch (flag) {
8226        case '0b':
8227          radix = 2;
8228          break;
8229        case '0':
8230        case '0o':
8231          radix = 8;
8232          break;
8233        case '0d':
8234          radix = 10;
8235          break;
8236        case '0x':
8237          radix = 16;
8238          break;
8239        }
8240        return head + tail;
8241      });
8242
8243      result = parseInt(string.replace(/_(?!_)/g, ''), radix);
8244      return isNaN(result) ? 0 : result;
8245    
8246    });
8247    
8248    $def(self, '$ord', function $$ord() {
8249      var self = this;
8250
8251      
8252      if (typeof self.codePointAt === "function") {
8253        return self.codePointAt(0);
8254      }
8255      else {
8256        return self.charCodeAt(0);
8257      }
8258    
8259    });
8260    
8261    $def(self, '$partition', function $$partition(sep) {
8262      var self = this;
8263
8264      
8265      var i, m;
8266
8267      if (sep.$$is_regexp) {
8268        m = sep.exec(self);
8269        if (m === null) {
8270          i = -1;
8271        } else {
8272          $$$('MatchData').$new(sep, m);
8273          sep = m[0];
8274          i = m.index;
8275        }
8276      } else {
8277        sep = $coerce_to(sep, $$$('String'), 'to_str');
8278        i = self.indexOf(sep);
8279      }
8280
8281      if (i === -1) {
8282        return [self, '', ''];
8283      }
8284
8285      return [
8286        self.slice(0, i),
8287        self.slice(i, i + sep.length),
8288        self.slice(i + sep.length)
8289      ];
8290    
8291    });
8292    
8293    $def(self, '$reverse', function $$reverse() {
8294      var self = this;
8295
8296      return self.split('').reverse().join('');
8297    });
8298    
8299    $def(self, '$rindex', function $$rindex(search, offset) {
8300      var self = this;
8301
8302      
8303      ;
8304      
8305      var i, m, r, _m;
8306
8307      if (offset === undefined) {
8308        offset = self.length;
8309      } else {
8310        offset = $coerce_to(offset, $$$('Integer'), 'to_int');
8311        if (offset < 0) {
8312          offset += self.length;
8313          if (offset < 0) {
8314            return nil;
8315          }
8316        }
8317      }
8318
8319      if (search.$$is_regexp) {
8320        m = null;
8321        r = $global_multiline_regexp(search);
8322        while (true) {
8323          _m = r.exec(self);
8324          if (_m === null || _m.index > offset) {
8325            break;
8326          }
8327          m = _m;
8328          r.lastIndex = m.index + 1;
8329        }
8330        if (m === null) {
8331          ($gvars["~"] = nil)
8332          i = -1;
8333        } else {
8334          $$$('MatchData').$new(r, m);
8335          i = m.index;
8336        }
8337      } else {
8338        search = $coerce_to(search, $$$('String'), 'to_str');
8339        i = self.lastIndexOf(search, offset);
8340      }
8341
8342      return i === -1 ? nil : i;
8343    ;
8344    }, -2);
8345    
8346    $def(self, '$rjust', function $$rjust(width, padstr) {
8347      var self = this;
8348
8349      
8350      if (padstr == null) padstr = " ";
8351      width = $coerce_to(width, $$$('Integer'), 'to_int');
8352      padstr = ($coerce_to(padstr, $$$('String'), 'to_str')).$to_s();
8353      if ($truthy(padstr['$empty?']())) {
8354        $Kernel.$raise($$$('ArgumentError'), "zero width padding")
8355      };
8356      if ($truthy(width <= self.length)) {
8357        return self
8358      };
8359      
8360      var chars     = Math.floor(width - self.length),
8361          patterns  = Math.floor(chars / padstr.length),
8362          result    = Array(patterns + 1).join(padstr),
8363          remaining = chars - result.length;
8364
8365      return result + padstr.slice(0, remaining) + self;
8366    ;
8367    }, -2);
8368    
8369    $def(self, '$rpartition', function $$rpartition(sep) {
8370      var self = this;
8371
8372      
8373      var i, m, r, _m;
8374
8375      if (sep.$$is_regexp) {
8376        m = null;
8377        r = $global_multiline_regexp(sep);
8378
8379        while (true) {
8380          _m = r.exec(self);
8381          if (_m === null) {
8382            break;
8383          }
8384          m = _m;
8385          r.lastIndex = m.index + 1;
8386        }
8387
8388        if (m === null) {
8389          i = -1;
8390        } else {
8391          $$$('MatchData').$new(r, m);
8392          sep = m[0];
8393          i = m.index;
8394        }
8395
8396      } else {
8397        sep = $coerce_to(sep, $$$('String'), 'to_str');
8398        i = self.lastIndexOf(sep);
8399      }
8400
8401      if (i === -1) {
8402        return ['', '', self];
8403      }
8404
8405      return [
8406        self.slice(0, i),
8407        self.slice(i, i + sep.length),
8408        self.slice(i + sep.length)
8409      ];
8410    
8411    });
8412    
8413    $def(self, '$rstrip', function $$rstrip() {
8414      var self = this;
8415
8416      return self.replace(/[\s\u0000]*$/, '');
8417    });
8418    
8419    $def(self, '$scan', function $$scan(pattern, $kwargs) {
8420      var block = $$scan.$$p || nil, no_matchdata, self = this;
8421
8422      $$scan.$$p = null;
8423      
8424      ;
8425      $kwargs = $ensure_kwargs($kwargs);
8426      
8427      no_matchdata = $kwargs.$$smap["no_matchdata"];if (no_matchdata == null) no_matchdata = false;
8428      
8429      var result = [],
8430          match_data = nil,
8431          match;
8432
8433      if (pattern.$$is_regexp) {
8434        pattern = $global_multiline_regexp(pattern);
8435      } else {
8436        pattern = $coerce_to(pattern, $$$('String'), 'to_str');
8437        pattern = new RegExp(pattern.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'gm');
8438      }
8439
8440      while ((match = pattern.exec(self)) != null) {
8441        match_data = $$$('MatchData').$new(pattern, match, $hash2(["no_matchdata"], {"no_matchdata": no_matchdata}));
8442        if (block === nil) {
8443          match.length == 1 ? result.push(match[0]) : result.push((match_data).$captures());
8444        } else {
8445          match.length == 1 ? Opal.yield1(block, match[0]) : Opal.yield1(block, (match_data).$captures());
8446        }
8447        if (pattern.lastIndex === match.index) {
8448          pattern.lastIndex += 1;
8449        }
8450      }
8451
8452      if (!no_matchdata) ($gvars["~"] = match_data);
8453
8454      return (block !== nil ? self : result);
8455    ;
8456    }, -2);
8457    
8458    $def(self, '$singleton_class', function $$singleton_class() {
8459      var self = this;
8460
8461      return Opal.get_singleton_class(self);
8462    });
8463    
8464    $def(self, '$split', function $$split(pattern, limit) {
8465      var self = this, $ret_or_1 = nil;
8466      if ($gvars[";"] == null) $gvars[";"] = nil;
8467
8468      
8469      ;
8470      ;
8471      
8472      if (self.length === 0) {
8473        return [];
8474      }
8475
8476      if (limit === undefined) {
8477        limit = 0;
8478      } else {
8479        limit = $Opal['$coerce_to!'](limit, $$$('Integer'), "to_int");
8480        if (limit === 1) {
8481          return [self];
8482        }
8483      }
8484
8485      if (pattern === undefined || pattern === nil) {
8486        pattern = ($truthy(($ret_or_1 = $gvars[";"])) ? ($ret_or_1) : (" "));
8487      }
8488
8489      var result = [],
8490          string = self.toString(),
8491          index = 0,
8492          match,
8493          i, ii;
8494
8495      if (pattern.$$is_regexp) {
8496        pattern = $global_multiline_regexp(pattern);
8497      } else {
8498        pattern = $coerce_to(pattern, $$$('String'), 'to_str').$to_s();
8499        if (pattern === ' ') {
8500          pattern = /\s+/gm;
8501          string = string.replace(/^\s+/, '');
8502        } else {
8503          pattern = new RegExp(pattern.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'gm');
8504        }
8505      }
8506
8507      result = string.split(pattern);
8508
8509      if (result.length === 1 && result[0] === string) {
8510        return [result[0]];
8511      }
8512
8513      while ((i = result.indexOf(undefined)) !== -1) {
8514        result.splice(i, 1);
8515      }
8516
8517      if (limit === 0) {
8518        while (result[result.length - 1] === '') {
8519          result.length -= 1;
8520        }
8521        return result;
8522      }
8523
8524      match = pattern.exec(string);
8525
8526      if (limit < 0) {
8527        if (match !== null && match[0] === '' && pattern.source.indexOf('(?=') === -1) {
8528          for (i = 0, ii = match.length; i < ii; i++) {
8529            result.push('');
8530          }
8531        }
8532        return result;
8533      }
8534
8535      if (match !== null && match[0] === '') {
8536        result.splice(limit - 1, result.length - 1, result.slice(limit - 1).join(''));
8537        return result;
8538      }
8539
8540      if (limit >= result.length) {
8541        return result;
8542      }
8543
8544      i = 0;
8545      while (match !== null) {
8546        i++;
8547        index = pattern.lastIndex;
8548        if (i + 1 === limit) {
8549          break;
8550        }
8551        match = pattern.exec(string);
8552      }
8553      result.splice(limit - 1, result.length - 1, string.slice(index));
8554      return result;
8555    ;
8556    }, -1);
8557    
8558    $def(self, '$squeeze', function $$squeeze($a) {
8559      var $post_args, sets, self = this;
8560
8561      
8562      $post_args = $slice(arguments);
8563      sets = $post_args;
8564      
8565      if (sets.length === 0) {
8566        return self.replace(/(.)\1+/g, '$1');
8567      }
8568      var char_class = char_class_from_char_sets(sets);
8569      if (char_class === null) {
8570        return self;
8571      }
8572      return self.replace(new RegExp('(' + char_class + ')\\1+', 'g'), '$1');
8573    ;
8574    }, -1);
8575    
8576    $def(self, '$start_with?', function $String_start_with$ques$16($a) {
8577      var $post_args, prefixes, self = this;
8578
8579      
8580      $post_args = $slice(arguments);
8581      prefixes = $post_args;
8582      
8583      for (var i = 0, length = prefixes.length; i < length; i++) {
8584        if (prefixes[i].$$is_regexp) {
8585          var regexp = prefixes[i];
8586          var match = regexp.exec(self);
8587
8588          if (match != null && match.index === 0) {
8589            ($gvars["~"] = $$$('MatchData').$new(regexp, match));
8590            return true;
8591          } else {
8592            ($gvars["~"] = nil)
8593          }
8594        } else {
8595          var prefix = $coerce_to(prefixes[i], $$$('String'), 'to_str').$to_s();
8596
8597          if (self.indexOf(prefix) === 0) {
8598            return true;
8599          }
8600        }
8601      }
8602
8603      return false;
8604    ;
8605    }, -1);
8606    
8607    $def(self, '$strip', function $$strip() {
8608      var self = this;
8609
8610      return self.replace(/^[\s\u0000]*|[\s\u0000]*$/g, '');
8611    });
8612    
8613    $def(self, '$sub', function $$sub(pattern, replacement) {
8614      var block = $$sub.$$p || nil, self = this;
8615
8616      $$sub.$$p = null;
8617      
8618      ;
8619      ;
8620      
8621      if (!pattern.$$is_regexp) {
8622        pattern = $coerce_to(pattern, $$$('String'), 'to_str');
8623        pattern = new RegExp(pattern.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'));
8624      }
8625
8626      var result, match = pattern.exec(self);
8627
8628      if (match === null) {
8629        ($gvars["~"] = nil)
8630        result = self.toString();
8631      } else {
8632        $$$('MatchData').$new(pattern, match)
8633
8634        if (replacement === undefined) {
8635
8636          if (block === nil) {
8637            $Kernel.$raise($$$('ArgumentError'), "wrong number of arguments (1 for 2)")
8638          }
8639          result = self.slice(0, match.index) + block(match[0]) + self.slice(match.index + match[0].length);
8640
8641        } else if (replacement.$$is_hash) {
8642
8643          result = self.slice(0, match.index) + (replacement)['$[]'](match[0]).$to_s() + self.slice(match.index + match[0].length);
8644
8645        } else {
8646
8647          replacement = $coerce_to(replacement, $$$('String'), 'to_str');
8648
8649          replacement = replacement.replace(/([\\]+)([0-9+&`'])/g, function (original, slashes, command) {
8650            if (slashes.length % 2 === 0) {
8651              return original;
8652            }
8653            switch (command) {
8654            case "+":
8655              for (var i = match.length - 1; i > 0; i--) {
8656                if (match[i] !== undefined) {
8657                  return slashes.slice(1) + match[i];
8658                }
8659              }
8660              return '';
8661            case "&": return slashes.slice(1) + match[0];
8662            case "`": return slashes.slice(1) + self.slice(0, match.index);
8663            case "'": return slashes.slice(1) + self.slice(match.index + match[0].length);
8664            default:  return slashes.slice(1) + (match[command] || '');
8665            }
8666          }).replace(/\\\\/g, '\\');
8667
8668          result = self.slice(0, match.index) + replacement + self.slice(match.index + match[0].length);
8669        }
8670      }
8671
8672      return result;
8673    ;
8674    }, -2);
8675    
8676    $def(self, '$sum', function $$sum(n) {
8677      var self = this;
8678
8679      
8680      if (n == null) n = 16;
8681      
8682      n = $coerce_to(n, $$$('Integer'), 'to_int');
8683
8684      var result = 0,
8685          length = self.length,
8686          i = 0;
8687
8688      for (; i < length; i++) {
8689        result += self.charCodeAt(i);
8690      }
8691
8692      if (n <= 0) {
8693        return result;
8694      }
8695
8696      return result & (Math.pow(2, n) - 1);
8697    ;
8698    }, -1);
8699    
8700    $def(self, '$swapcase', function $$swapcase() {
8701      var self = this;
8702
8703      
8704      var str = self.replace(/([a-z]+)|([A-Z]+)/g, function($0,$1,$2) {
8705        return $1 ? $0.toUpperCase() : $0.toLowerCase();
8706      });
8707
8708      return str;
8709    
8710    });
8711    
8712    $def(self, '$to_f', function $$to_f() {
8713      var self = this;
8714
8715      
8716      if (self.charAt(0) === '_') {
8717        return 0;
8718      }
8719
8720      var result = parseFloat(self.replace(/_/g, ''));
8721
8722      if (isNaN(result) || result == Infinity || result == -Infinity) {
8723        return 0;
8724      }
8725      else {
8726        return result;
8727      }
8728    
8729    });
8730    
8731    $def(self, '$to_i', function $$to_i(base) {
8732      var self = this;
8733
8734      
8735      if (base == null) base = 10;
8736      
8737      var result,
8738          string = self.toLowerCase(),
8739          radix = $coerce_to(base, $$$('Integer'), 'to_int');
8740
8741      if (radix === 1 || radix < 0 || radix > 36) {
8742        $Kernel.$raise($$$('ArgumentError'), "invalid radix " + (radix))
8743      }
8744
8745      if (/^\s*_/.test(string)) {
8746        return 0;
8747      }
8748
8749      string = string.replace(/^(\s*[+-]?)(0[bodx]?)(.+)$/, function (original, head, flag, tail) {
8750        switch (tail.charAt(0)) {
8751        case '+':
8752        case '-':
8753          return original;
8754        case '0':
8755          if (tail.charAt(1) === 'x' && flag === '0x' && (radix === 0 || radix === 16)) {
8756            return original;
8757          }
8758        }
8759        switch (flag) {
8760        case '0b':
8761          if (radix === 0 || radix === 2) {
8762            radix = 2;
8763            return head + tail;
8764          }
8765          break;
8766        case '0':
8767        case '0o':
8768          if (radix === 0 || radix === 8) {
8769            radix = 8;
8770            return head + tail;
8771          }
8772          break;
8773        case '0d':
8774          if (radix === 0 || radix === 10) {
8775            radix = 10;
8776            return head + tail;
8777          }
8778          break;
8779        case '0x':
8780          if (radix === 0 || radix === 16) {
8781            radix = 16;
8782            return head + tail;
8783          }
8784          break;
8785        }
8786        return original
8787      });
8788
8789      result = parseInt(string.replace(/_(?!_)/g, ''), radix);
8790      return isNaN(result) ? 0 : result;
8791    ;
8792    }, -1);
8793    
8794    $def(self, '$to_proc', function $$to_proc() {
8795      var $yield = $$to_proc.$$p || nil, self = this, method_name = nil, jsid = nil, proc = nil;
8796
8797      $$to_proc.$$p = null;
8798      
8799      method_name = self.valueOf();
8800      jsid = Opal.jsid(method_name);
8801      proc = $send($Kernel, 'proc', [], function $$17($a){var block = $$17.$$p || nil, $post_args, args;
8802
8803        $$17.$$p = null;
8804        
8805        ;
8806        $post_args = $slice(arguments);
8807        args = $post_args;
8808        
8809        if (args.length === 0) {
8810          $Kernel.$raise($$$('ArgumentError'), "no receiver given")
8811        }
8812
8813        var recv = args[0];
8814
8815        if (recv == null) recv = nil;
8816
8817        var body = recv[jsid];
8818
8819        if (!body) {
8820          body = recv.$method_missing;
8821          args[0] = method_name;
8822        } else {
8823          args = args.slice(1);
8824        }
8825
8826        if (typeof block === 'function') {
8827          body.$$p = block;
8828        }
8829
8830        if (args.length === 0) {
8831          return body.call(recv);
8832        } else {
8833          return body.apply(recv, args);
8834        }
8835      ;}, -1);
8836      proc.$$source_location = nil;
8837      return proc;
8838    });
8839    
8840    $def(self, '$to_s', function $$to_s() {
8841      var self = this;
8842
8843      return self.toString();
8844    });
8845    
8846    $def(self, '$tr', function $$tr(from, to) {
8847      var self = this;
8848
8849      
8850      from = $coerce_to(from, $$$('String'), 'to_str').$to_s();
8851      to = $coerce_to(to, $$$('String'), 'to_str').$to_s();
8852
8853      if (from.length == 0 || from === to) {
8854        return self;
8855      }
8856
8857      var i, in_range, c, ch, start, end, length;
8858      var subs = {};
8859      var from_chars = from.split('');
8860      var from_length = from_chars.length;
8861      var to_chars = to.split('');
8862      var to_length = to_chars.length;
8863
8864      var inverse = false;
8865      var global_sub = null;
8866      if (from_chars[0] === '^' && from_chars.length > 1) {
8867        inverse = true;
8868        from_chars.shift();
8869        global_sub = to_chars[to_length - 1]
8870        from_length -= 1;
8871      }
8872
8873      var from_chars_expanded = [];
8874      var last_from = null;
8875      in_range = false;
8876      for (i = 0; i < from_length; i++) {
8877        ch = from_chars[i];
8878        if (last_from == null) {
8879          last_from = ch;
8880          from_chars_expanded.push(ch);
8881        }
8882        else if (ch === '-') {
8883          if (last_from === '-') {
8884            from_chars_expanded.push('-');
8885            from_chars_expanded.push('-');
8886          }
8887          else if (i == from_length - 1) {
8888            from_chars_expanded.push('-');
8889          }
8890          else {
8891            in_range = true;
8892          }
8893        }
8894        else if (in_range) {
8895          start = last_from.charCodeAt(0);
8896          end = ch.charCodeAt(0);
8897          if (start > end) {
8898            $Kernel.$raise($$$('ArgumentError'), "invalid range \"" + (String.fromCharCode(start)) + "-" + (String.fromCharCode(end)) + "\" in string transliteration")
8899          }
8900          for (c = start + 1; c < end; c++) {
8901            from_chars_expanded.push(String.fromCharCode(c));
8902          }
8903          from_chars_expanded.push(ch);
8904          in_range = null;
8905          last_from = null;
8906        }
8907        else {
8908          from_chars_expanded.push(ch);
8909        }
8910      }
8911
8912      from_chars = from_chars_expanded;
8913      from_length = from_chars.length;
8914
8915      if (inverse) {
8916        for (i = 0; i < from_length; i++) {
8917          subs[from_chars[i]] = true;
8918        }
8919      }
8920      else {
8921        if (to_length > 0) {
8922          var to_chars_expanded = [];
8923          var last_to = null;
8924          in_range = false;
8925          for (i = 0; i < to_length; i++) {
8926            ch = to_chars[i];
8927            if (last_to == null) {
8928              last_to = ch;
8929              to_chars_expanded.push(ch);
8930            }
8931            else if (ch === '-') {
8932              if (last_to === '-') {
8933                to_chars_expanded.push('-');
8934                to_chars_expanded.push('-');
8935              }
8936              else if (i == to_length - 1) {
8937                to_chars_expanded.push('-');
8938              }
8939              else {
8940                in_range = true;
8941              }
8942            }
8943            else if (in_range) {
8944              start = last_to.charCodeAt(0);
8945              end = ch.charCodeAt(0);
8946              if (start > end) {
8947                $Kernel.$raise($$$('ArgumentError'), "invalid range \"" + (String.fromCharCode(start)) + "-" + (String.fromCharCode(end)) + "\" in string transliteration")
8948              }
8949              for (c = start + 1; c < end; c++) {
8950                to_chars_expanded.push(String.fromCharCode(c));
8951              }
8952              to_chars_expanded.push(ch);
8953              in_range = null;
8954              last_to = null;
8955            }
8956            else {
8957              to_chars_expanded.push(ch);
8958            }
8959          }
8960
8961          to_chars = to_chars_expanded;
8962          to_length = to_chars.length;
8963        }
8964
8965        var length_diff = from_length - to_length;
8966        if (length_diff > 0) {
8967          var pad_char = (to_length > 0 ? to_chars[to_length - 1] : '');
8968          for (i = 0; i < length_diff; i++) {
8969            to_chars.push(pad_char);
8970          }
8971        }
8972
8973        for (i = 0; i < from_length; i++) {
8974          subs[from_chars[i]] = to_chars[i];
8975        }
8976      }
8977
8978      var new_str = ''
8979      for (i = 0, length = self.length; i < length; i++) {
8980        ch = self.charAt(i);
8981        var sub = subs[ch];
8982        if (inverse) {
8983          new_str += (sub == null ? global_sub : ch);
8984        }
8985        else {
8986          new_str += (sub != null ? sub : ch);
8987        }
8988      }
8989      return new_str;
8990    
8991    });
8992    
8993    $def(self, '$tr_s', function $$tr_s(from, to) {
8994      var self = this;
8995
8996      
8997      from = $coerce_to(from, $$$('String'), 'to_str').$to_s();
8998      to = $coerce_to(to, $$$('String'), 'to_str').$to_s();
8999
9000      if (from.length == 0) {
9001        return self;
9002      }
9003
9004      var i, in_range, c, ch, start, end, length;
9005      var subs = {};
9006      var from_chars = from.split('');
9007      var from_length = from_chars.length;
9008      var to_chars = to.split('');
9009      var to_length = to_chars.length;
9010
9011      var inverse = false;
9012      var global_sub = null;
9013      if (from_chars[0] === '^' && from_chars.length > 1) {
9014        inverse = true;
9015        from_chars.shift();
9016        global_sub = to_chars[to_length - 1]
9017        from_length -= 1;
9018      }
9019
9020      var from_chars_expanded = [];
9021      var last_from = null;
9022      in_range = false;
9023      for (i = 0; i < from_length; i++) {
9024        ch = from_chars[i];
9025        if (last_from == null) {
9026          last_from = ch;
9027          from_chars_expanded.push(ch);
9028        }
9029        else if (ch === '-') {
9030          if (last_from === '-') {
9031            from_chars_expanded.push('-');
9032            from_chars_expanded.push('-');
9033          }
9034          else if (i == from_length - 1) {
9035            from_chars_expanded.push('-');
9036          }
9037          else {
9038            in_range = true;
9039          }
9040        }
9041        else if (in_range) {
9042          start = last_from.charCodeAt(0);
9043          end = ch.charCodeAt(0);
9044          if (start > end) {
9045            $Kernel.$raise($$$('ArgumentError'), "invalid range \"" + (String.fromCharCode(start)) + "-" + (String.fromCharCode(end)) + "\" in string transliteration")
9046          }
9047          for (c = start + 1; c < end; c++) {
9048            from_chars_expanded.push(String.fromCharCode(c));
9049          }
9050          from_chars_expanded.push(ch);
9051          in_range = null;
9052          last_from = null;
9053        }
9054        else {
9055          from_chars_expanded.push(ch);
9056        }
9057      }
9058
9059      from_chars = from_chars_expanded;
9060      from_length = from_chars.length;
9061
9062      if (inverse) {
9063        for (i = 0; i < from_length; i++) {
9064          subs[from_chars[i]] = true;
9065        }
9066      }
9067      else {
9068        if (to_length > 0) {
9069          var to_chars_expanded = [];
9070          var last_to = null;
9071          in_range = false;
9072          for (i = 0; i < to_length; i++) {
9073            ch = to_chars[i];
9074            if (last_from == null) {
9075              last_from = ch;
9076              to_chars_expanded.push(ch);
9077            }
9078            else if (ch === '-') {
9079              if (last_to === '-') {
9080                to_chars_expanded.push('-');
9081                to_chars_expanded.push('-');
9082              }
9083              else if (i == to_length - 1) {
9084                to_chars_expanded.push('-');
9085              }
9086              else {
9087                in_range = true;
9088              }
9089            }
9090            else if (in_range) {
9091              start = last_from.charCodeAt(0);
9092              end = ch.charCodeAt(0);
9093              if (start > end) {
9094                $Kernel.$raise($$$('ArgumentError'), "invalid range \"" + (String.fromCharCode(start)) + "-" + (String.fromCharCode(end)) + "\" in string transliteration")
9095              }
9096              for (c = start + 1; c < end; c++) {
9097                to_chars_expanded.push(String.fromCharCode(c));
9098              }
9099              to_chars_expanded.push(ch);
9100              in_range = null;
9101              last_from = null;
9102            }
9103            else {
9104              to_chars_expanded.push(ch);
9105            }
9106          }
9107
9108          to_chars = to_chars_expanded;
9109          to_length = to_chars.length;
9110        }
9111
9112        var length_diff = from_length - to_length;
9113        if (length_diff > 0) {
9114          var pad_char = (to_length > 0 ? to_chars[to_length - 1] : '');
9115          for (i = 0; i < length_diff; i++) {
9116            to_chars.push(pad_char);
9117          }
9118        }
9119
9120        for (i = 0; i < from_length; i++) {
9121          subs[from_chars[i]] = to_chars[i];
9122        }
9123      }
9124      var new_str = ''
9125      var last_substitute = null
9126      for (i = 0, length = self.length; i < length; i++) {
9127        ch = self.charAt(i);
9128        var sub = subs[ch]
9129        if (inverse) {
9130          if (sub == null) {
9131            if (last_substitute == null) {
9132              new_str += global_sub;
9133              last_substitute = true;
9134            }
9135          }
9136          else {
9137            new_str += ch;
9138            last_substitute = null;
9139          }
9140        }
9141        else {
9142          if (sub != null) {
9143            if (last_substitute == null || last_substitute !== sub) {
9144              new_str += sub;
9145              last_substitute = sub;
9146            }
9147          }
9148          else {
9149            new_str += ch;
9150            last_substitute = null;
9151          }
9152        }
9153      }
9154      return new_str;
9155    
9156    });
9157    
9158    $def(self, '$upcase', function $$upcase() {
9159      var self = this;
9160
9161      return self.toUpperCase();
9162    });
9163    
9164    $def(self, '$upto', function $$upto(stop, excl) {
9165      var block = $$upto.$$p || nil, self = this;
9166
9167      $$upto.$$p = null;
9168      
9169      ;
9170      if (excl == null) excl = false;
9171      if (!(block !== nil)) {
9172        return self.$enum_for("upto", stop, excl)
9173      };
9174      
9175      var a, b, s = self.toString();
9176
9177      stop = $coerce_to(stop, $$$('String'), 'to_str');
9178
9179      if (s.length === 1 && stop.length === 1) {
9180
9181        a = s.charCodeAt(0);
9182        b = stop.charCodeAt(0);
9183
9184        while (a <= b) {
9185          if (excl && a === b) {
9186            break;
9187          }
9188
9189          block(String.fromCharCode(a));
9190
9191          a += 1;
9192        }
9193
9194      } else if (parseInt(s, 10).toString() === s && parseInt(stop, 10).toString() === stop) {
9195
9196        a = parseInt(s, 10);
9197        b = parseInt(stop, 10);
9198
9199        while (a <= b) {
9200          if (excl && a === b) {
9201            break;
9202          }
9203
9204          block(a.toString());
9205
9206          a += 1;
9207        }
9208
9209      } else {
9210
9211        while (s.length <= stop.length && s <= stop) {
9212          if (excl && s === stop) {
9213            break;
9214          }
9215
9216          block(s);
9217
9218          s = (s).$succ();
9219        }
9220
9221      }
9222      return self;
9223    ;
9224    }, -2);
9225    
9226    function char_class_from_char_sets(sets) {
9227      function explode_sequences_in_character_set(set) {
9228        var result = '',
9229            i, len = set.length,
9230            curr_char,
9231            skip_next_dash,
9232            char_code_from,
9233            char_code_upto,
9234            char_code;
9235        for (i = 0; i < len; i++) {
9236          curr_char = set.charAt(i);
9237          if (curr_char === '-' && i > 0 && i < (len - 1) && !skip_next_dash) {
9238            char_code_from = set.charCodeAt(i - 1);
9239            char_code_upto = set.charCodeAt(i + 1);
9240            if (char_code_from > char_code_upto) {
9241              $Kernel.$raise($$$('ArgumentError'), "invalid range \"" + (char_code_from) + "-" + (char_code_upto) + "\" in string transliteration")
9242            }
9243            for (char_code = char_code_from + 1; char_code < char_code_upto + 1; char_code++) {
9244              result += String.fromCharCode(char_code);
9245            }
9246            skip_next_dash = true;
9247            i++;
9248          } else {
9249            skip_next_dash = (curr_char === '\\');
9250            result += curr_char;
9251          }
9252        }
9253        return result;
9254      }
9255
9256      function intersection(setA, setB) {
9257        if (setA.length === 0) {
9258          return setB;
9259        }
9260        var result = '',
9261            i, len = setA.length,
9262            chr;
9263        for (i = 0; i < len; i++) {
9264          chr = setA.charAt(i);
9265          if (setB.indexOf(chr) !== -1) {
9266            result += chr;
9267          }
9268        }
9269        return result;
9270      }
9271
9272      var i, len, set, neg, chr, tmp,
9273          pos_intersection = '',
9274          neg_intersection = '';
9275
9276      for (i = 0, len = sets.length; i < len; i++) {
9277        set = $coerce_to(sets[i], $$$('String'), 'to_str');
9278        neg = (set.charAt(0) === '^' && set.length > 1);
9279        set = explode_sequences_in_character_set(neg ? set.slice(1) : set);
9280        if (neg) {
9281          neg_intersection = intersection(neg_intersection, set);
9282        } else {
9283          pos_intersection = intersection(pos_intersection, set);
9284        }
9285      }
9286
9287      if (pos_intersection.length > 0 && neg_intersection.length > 0) {
9288        tmp = '';
9289        for (i = 0, len = pos_intersection.length; i < len; i++) {
9290          chr = pos_intersection.charAt(i);
9291          if (neg_intersection.indexOf(chr) === -1) {
9292            tmp += chr;
9293          }
9294        }
9295        pos_intersection = tmp;
9296        neg_intersection = '';
9297      }
9298
9299      if (pos_intersection.length > 0) {
9300        return '[' + $$$('Regexp').$escape(pos_intersection) + ']';
9301      }
9302
9303      if (neg_intersection.length > 0) {
9304        return '[^' + $$$('Regexp').$escape(neg_intersection) + ']';
9305      }
9306
9307      return null;
9308    }
9309  ;
9310    
9311    $def(self, '$instance_variables', function $$instance_variables() {
9312      
9313      return []
9314    });
9315    $defs(self, '$_load', function $$_load($a) {
9316      var $post_args, args, self = this;
9317
9318      
9319      $post_args = $slice(arguments);
9320      args = $post_args;
9321      return $send(self, 'new', $to_a(args));
9322    }, -1);
9323    
9324    $def(self, '$unicode_normalize', function $$unicode_normalize(form) {
9325      var self = this;
9326
9327      
9328      if (form == null) form = "nfc";
9329      if (!$truthy(["nfc", "nfd", "nfkc", "nfkd"]['$include?'](form))) {
9330        $Kernel.$raise($$$('ArgumentError'), "Invalid normalization form " + (form))
9331      };
9332      return self.normalize(form.$upcase());
9333    }, -1);
9334    
9335    $def(self, '$unicode_normalized?', function $String_unicode_normalized$ques$18(form) {
9336      var self = this;
9337
9338      
9339      if (form == null) form = "nfc";
9340      return self.$unicode_normalize(form)['$=='](self);
9341    }, -1);
9342    
9343    $def(self, '$unpack', function $$unpack(format) {
9344      
9345      return $Kernel.$raise("To use String#unpack, you must first require 'corelib/string/unpack'.")
9346    });
9347    
9348    $def(self, '$unpack1', function $$unpack1(format) {
9349      
9350      return $Kernel.$raise("To use String#unpack1, you must first require 'corelib/string/unpack'.")
9351    });
9352    
9353    $def(self, '$freeze', function $$freeze() {
9354      var self = this;
9355
9356      
9357      if (typeof self === 'string') { return self; }
9358      $prop(self, "$$frozen", true);
9359      return self;
9360    
9361    });
9362    
9363    $def(self, '$-@', function $String_$minus$$19() {
9364      var self = this;
9365
9366      
9367      if (typeof self === 'string') return self;
9368      if (self.$$frozen) return self;
9369      if (self.encoding.name == 'UTF-8' && self.internal_encoding.name == 'UTF-8') return self.toString();
9370      return self.$dup().$freeze();
9371    
9372    });
9373    
9374    $def(self, '$frozen?', function $String_frozen$ques$20() {
9375      var self = this;
9376
9377      return typeof self === 'string' || self.$$frozen === true;
9378    });
9379    $alias(self, "+@", "dup");
9380    $alias(self, "===", "==");
9381    $alias(self, "byteslice", "[]");
9382    $alias(self, "eql?", "==");
9383    $alias(self, "equal?", "===");
9384    $alias(self, "object_id", "__id__");
9385    $alias(self, "slice", "[]");
9386    $alias(self, "succ", "next");
9387    $alias(self, "to_str", "to_s");
9388    $alias(self, "to_sym", "intern");
9389    return $Opal.$pristine(self, "initialize");
9390  })('::', String, $nesting);
9391  return $const_set($nesting[0], 'Symbol', $$('String'));
9392};
9393
9394Opal.modules["corelib/enumerable"] = function(Opal) {/* Generated by Opal 1.7.3 */
9395  var $truthy = Opal.truthy, $coerce_to = Opal.coerce_to, $yield1 = Opal.yield1, $yieldX = Opal.yieldX, $deny_frozen_access = Opal.deny_frozen_access, $module = Opal.module, $send = Opal.send, $slice = Opal.slice, $to_a = Opal.to_a, $Opal = Opal.Opal, $thrower = Opal.thrower, $def = Opal.def, $Kernel = Opal.Kernel, $return_val = Opal.return_val, $rb_gt = Opal.rb_gt, $rb_times = Opal.rb_times, $rb_lt = Opal.rb_lt, $eqeq = Opal.eqeq, $rb_plus = Opal.rb_plus, $rb_minus = Opal.rb_minus, $rb_divide = Opal.rb_divide, $rb_le = Opal.rb_le, $hash2 = Opal.hash2, $lambda = Opal.lambda, $not = Opal.not, $alias = Opal.alias, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$;
9396
9397  Opal.add_stubs('each,public_send,destructure,to_enum,enumerator_size,new,yield,raise,slice_when,!,enum_for,flatten,map,to_proc,compact,to_a,warn,proc,==,nil?,respond_to?,coerce_to!,>,*,try_convert,<,+,-,ceil,/,size,select,__send__,length,<=,[],push,<<,[]=,===,inspect,<=>,first,reverse,sort,take,sort_by,compare,call,dup,sort!,map!,include?,-@,key?,values,transform_values,group_by,fetch,to_h,coerce_to?,class,zip,detect,find_all,collect_concat,collect,inject,entries');
9398  return (function($base, $parent_nesting) {
9399    var self = $module($base, 'Enumerable');
9400
9401    var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
9402
9403    
9404    
9405    function comparableForPattern(value) {
9406      if (value.length === 0) {
9407        value = [nil];
9408      }
9409
9410      if (value.length > 1) {
9411        value = [value];
9412      }
9413
9414      return value;
9415    }
9416  ;
9417    
9418    $def(self, '$all?', function $Enumerable_all$ques$1(pattern) {try { var $t_return = $thrower('return'); 
9419      var block = $Enumerable_all$ques$1.$$p || nil, self = this;
9420
9421      $Enumerable_all$ques$1.$$p = null;
9422      
9423      ;
9424      ;
9425      if ($truthy(pattern !== undefined)) {
9426        $send(self, 'each', [], function $$2($a){var $post_args, value, comparable = nil;
9427
9428          
9429          $post_args = $slice(arguments);
9430          value = $post_args;
9431          comparable = comparableForPattern(value);
9432          if ($truthy($send(pattern, 'public_send', ["==="].concat($to_a(comparable))))) {
9433            return nil
9434          } else {
9435            $t_return.$throw(false)
9436          };}, {$$arity: -1, $$ret: $t_return})
9437      } else if ((block !== nil)) {
9438        $send(self, 'each', [], function $$3($a){var $post_args, value;
9439
9440          
9441          $post_args = $slice(arguments);
9442          value = $post_args;
9443          if ($truthy(Opal.yieldX(block, $to_a(value)))) {
9444            return nil
9445          } else {
9446            $t_return.$throw(false)
9447          };}, {$$arity: -1, $$ret: $t_return})
9448      } else {
9449        $send(self, 'each', [], function $$4($a){var $post_args, value;
9450
9451          
9452          $post_args = $slice(arguments);
9453          value = $post_args;
9454          if ($truthy($Opal.$destructure(value))) {
9455            return nil
9456          } else {
9457            $t_return.$throw(false)
9458          };}, {$$arity: -1, $$ret: $t_return})
9459      };
9460      return true;} catch($e) {
9461        if ($e === $t_return) return $e.$v;
9462        throw $e;
9463      }
9464    }, -1);
9465    
9466    $def(self, '$any?', function $Enumerable_any$ques$5(pattern) {try { var $t_return = $thrower('return'); 
9467      var block = $Enumerable_any$ques$5.$$p || nil, self = this;
9468
9469      $Enumerable_any$ques$5.$$p = null;
9470      
9471      ;
9472      ;
9473      if ($truthy(pattern !== undefined)) {
9474        $send(self, 'each', [], function $$6($a){var $post_args, value, comparable = nil;
9475
9476          
9477          $post_args = $slice(arguments);
9478          value = $post_args;
9479          comparable = comparableForPattern(value);
9480          if ($truthy($send(pattern, 'public_send', ["==="].concat($to_a(comparable))))) {
9481            $t_return.$throw(true)
9482          } else {
9483            return nil
9484          };}, {$$arity: -1, $$ret: $t_return})
9485      } else if ((block !== nil)) {
9486        $send(self, 'each', [], function $$7($a){var $post_args, value;
9487
9488          
9489          $post_args = $slice(arguments);
9490          value = $post_args;
9491          if ($truthy(Opal.yieldX(block, $to_a(value)))) {
9492            $t_return.$throw(true)
9493          } else {
9494            return nil
9495          };}, {$$arity: -1, $$ret: $t_return})
9496      } else {
9497        $send(self, 'each', [], function $$8($a){var $post_args, value;
9498
9499          
9500          $post_args = $slice(arguments);
9501          value = $post_args;
9502          if ($truthy($Opal.$destructure(value))) {
9503            $t_return.$throw(true)
9504          } else {
9505            return nil
9506          };}, {$$arity: -1, $$ret: $t_return})
9507      };
9508      return false;} catch($e) {
9509        if ($e === $t_return) return $e.$v;
9510        throw $e;
9511      }
9512    }, -1);
9513    
9514    $def(self, '$chunk', function $$chunk() {
9515      var block = $$chunk.$$p || nil, self = this;
9516
9517      $$chunk.$$p = null;
9518      
9519      ;
9520      if (!(block !== nil)) {
9521        return $send(self, 'to_enum', ["chunk"], function $$9(){var self = $$9.$$s == null ? this : $$9.$$s;
9522
9523          return self.$enumerator_size()}, {$$s: self})
9524      };
9525      return $send($$$('Enumerator'), 'new', [], function $$10(yielder){var self = $$10.$$s == null ? this : $$10.$$s;
9526
9527        
9528        if (yielder == null) yielder = nil;
9529        
9530        var previous = nil, accumulate = [];
9531
9532        function releaseAccumulate() {
9533          if (accumulate.length > 0) {
9534            yielder.$yield(previous, accumulate)
9535          }
9536        }
9537
9538        self.$each.$$p = function(value) {
9539          var key = $yield1(block, value);
9540
9541          if (key === nil) {
9542            releaseAccumulate();
9543            accumulate = [];
9544            previous = nil;
9545          } else {
9546            if (previous === nil || previous === key) {
9547              accumulate.push(value);
9548            } else {
9549              releaseAccumulate();
9550              accumulate = [value];
9551            }
9552
9553            previous = key;
9554          }
9555        }
9556
9557        self.$each();
9558
9559        releaseAccumulate();
9560      ;}, {$$s: self});
9561    });
9562    
9563    $def(self, '$chunk_while', function $$chunk_while() {
9564      var block = $$chunk_while.$$p || nil, self = this;
9565
9566      $$chunk_while.$$p = null;
9567      
9568      ;
9569      if (!(block !== nil)) {
9570        $Kernel.$raise($$$('ArgumentError'), "no block given")
9571      };
9572      return $send(self, 'slice_when', [], function $$11(before, after){
9573        
9574        if (before == null) before = nil;
9575        if (after == null) after = nil;
9576        return Opal.yieldX(block, [before, after])['$!']();});
9577    });
9578    
9579    $def(self, '$collect', function $$collect() {
9580      var block = $$collect.$$p || nil, self = this;
9581
9582      $$collect.$$p = null;
9583      
9584      ;
9585      if (!(block !== nil)) {
9586        return $send(self, 'enum_for', ["collect"], function $$12(){var self = $$12.$$s == null ? this : $$12.$$s;
9587
9588          return self.$enumerator_size()}, {$$s: self})
9589      };
9590      
9591      var result = [];
9592
9593      self.$each.$$p = function() {
9594        var value = $yieldX(block, arguments);
9595
9596        result.push(value);
9597      };
9598
9599      self.$each();
9600
9601      return result;
9602    ;
9603    });
9604    
9605    $def(self, '$collect_concat', function $$collect_concat() {
9606      var block = $$collect_concat.$$p || nil, self = this;
9607
9608      $$collect_concat.$$p = null;
9609      
9610      ;
9611      if (!(block !== nil)) {
9612        return $send(self, 'enum_for', ["collect_concat"], function $$13(){var self = $$13.$$s == null ? this : $$13.$$s;
9613
9614          return self.$enumerator_size()}, {$$s: self})
9615      };
9616      return $send(self, 'map', [], block.$to_proc()).$flatten(1);
9617    });
9618    
9619    $def(self, '$compact', function $$compact() {
9620      var self = this;
9621
9622      return self.$to_a().$compact()
9623    });
9624    
9625    $def(self, '$count', function $$count(object) {
9626      var block = $$count.$$p || nil, self = this, result = nil;
9627
9628      $$count.$$p = null;
9629      
9630      ;
9631      ;
9632      result = 0;
9633      
9634      if (object != null && block !== nil) {
9635        self.$warn("warning: given block not used")
9636      }
9637    ;
9638      if ($truthy(object != null)) {
9639        block = $send($Kernel, 'proc', [], function $$14($a){var $post_args, args;
9640
9641          
9642          $post_args = $slice(arguments);
9643          args = $post_args;
9644          return $Opal.$destructure(args)['$=='](object);}, -1)
9645      } else if ($truthy(block['$nil?']())) {
9646        block = $send($Kernel, 'proc', [], $return_val(true))
9647      };
9648      $send(self, 'each', [], function $$15($a){var $post_args, args;
9649
9650        
9651        $post_args = $slice(arguments);
9652        args = $post_args;
9653        if ($truthy($yieldX(block, args))) {
9654          return result++;
9655        } else {
9656          return nil
9657        };}, -1);
9658      return result;
9659    }, -1);
9660    
9661    $def(self, '$cycle', function $$cycle(n) {
9662      var block = $$cycle.$$p || nil, self = this;
9663
9664      $$cycle.$$p = null;
9665      
9666      ;
9667      if (n == null) n = nil;
9668      if (!(block !== nil)) {
9669        return $send(self, 'enum_for', ["cycle", n], function $$16(){var self = $$16.$$s == null ? this : $$16.$$s;
9670
9671          if ($truthy(n['$nil?']())) {
9672            if ($truthy(self['$respond_to?']("size"))) {
9673              return $$$($$$('Float'), 'INFINITY')
9674            } else {
9675              return nil
9676            }
9677          } else {
9678            
9679            n = $Opal['$coerce_to!'](n, $$$('Integer'), "to_int");
9680            if ($truthy($rb_gt(n, 0))) {
9681              return $rb_times(self.$enumerator_size(), n)
9682            } else {
9683              return 0
9684            };
9685          }}, {$$s: self})
9686      };
9687      if (!$truthy(n['$nil?']())) {
9688        
9689        n = $Opal['$coerce_to!'](n, $$$('Integer'), "to_int");
9690        if ($truthy(n <= 0)) {
9691          return nil
9692        };
9693      };
9694      
9695      var all = [], i, length, value;
9696
9697      self.$each.$$p = function() {
9698        var param = $Opal.$destructure(arguments),
9699            value = $yield1(block, param);
9700
9701        all.push(param);
9702      }
9703
9704      self.$each();
9705
9706      if (all.length === 0) {
9707        return nil;
9708      }
9709
9710      if (n === nil) {
9711        while (true) {
9712          for (i = 0, length = all.length; i < length; i++) {
9713            value = $yield1(block, all[i]);
9714          }
9715        }
9716      }
9717      else {
9718        while (n > 1) {
9719          for (i = 0, length = all.length; i < length; i++) {
9720            value = $yield1(block, all[i]);
9721          }
9722
9723          n--;
9724        }
9725      }
9726    ;
9727    }, -1);
9728    
9729    $def(self, '$detect', function $$detect(ifnone) {try { var $t_return = $thrower('return'); 
9730      var block = $$detect.$$p || nil, self = this;
9731
9732      $$detect.$$p = null;
9733      
9734      ;
9735      ;
9736      if (!(block !== nil)) {
9737        return self.$enum_for("detect", ifnone)
9738      };
9739      $send(self, 'each', [], function $$17($a){var $post_args, args, value = nil;
9740
9741        
9742        $post_args = $slice(arguments);
9743        args = $post_args;
9744        value = $Opal.$destructure(args);
9745        if ($truthy(Opal.yield1(block, value))) {
9746          $t_return.$throw(value)
9747        } else {
9748          return nil
9749        };}, {$$arity: -1, $$ret: $t_return});
9750      
9751      if (ifnone !== undefined) {
9752        if (typeof(ifnone) === 'function') {
9753          return ifnone();
9754        } else {
9755          return ifnone;
9756        }
9757      }
9758    ;
9759      return nil;} catch($e) {
9760        if ($e === $t_return) return $e.$v;
9761        throw $e;
9762      }
9763    }, -1);
9764    
9765    $def(self, '$drop', function $$drop(number) {
9766      var self = this;
9767
9768      
9769      number = $coerce_to(number, $$$('Integer'), 'to_int');
9770      if ($truthy(number < 0)) {
9771        $Kernel.$raise($$$('ArgumentError'), "attempt to drop negative size")
9772      };
9773      
9774      var result  = [],
9775          current = 0;
9776
9777      self.$each.$$p = function() {
9778        if (number <= current) {
9779          result.push($Opal.$destructure(arguments));
9780        }
9781
9782        current++;
9783      };
9784
9785      self.$each()
9786
9787      return result;
9788    ;
9789    });
9790    
9791    $def(self, '$drop_while', function $$drop_while() {
9792      var block = $$drop_while.$$p || nil, self = this;
9793
9794      $$drop_while.$$p = null;
9795      
9796      ;
9797      if (!(block !== nil)) {
9798        return self.$enum_for("drop_while")
9799      };
9800      
9801      var result   = [],
9802          dropping = true;
9803
9804      self.$each.$$p = function() {
9805        var param = $Opal.$destructure(arguments);
9806
9807        if (dropping) {
9808          var value = $yield1(block, param);
9809
9810          if (!$truthy(value)) {
9811            dropping = false;
9812            result.push(param);
9813          }
9814        }
9815        else {
9816          result.push(param);
9817        }
9818      };
9819
9820      self.$each();
9821
9822      return result;
9823    ;
9824    });
9825    
9826    $def(self, '$each_cons', function $$each_cons(n) {
9827      var block = $$each_cons.$$p || nil, self = this;
9828
9829      $$each_cons.$$p = null;
9830      
9831      ;
9832      if ($truthy(arguments.length != 1)) {
9833        $Kernel.$raise($$$('ArgumentError'), "wrong number of arguments (" + (arguments.length) + " for 1)")
9834      };
9835      n = $Opal.$try_convert(n, $$$('Integer'), "to_int");
9836      if ($truthy(n <= 0)) {
9837        $Kernel.$raise($$$('ArgumentError'), "invalid size")
9838      };
9839      if (!(block !== nil)) {
9840        return $send(self, 'enum_for', ["each_cons", n], function $$18(){var self = $$18.$$s == null ? this : $$18.$$s, enum_size = nil;
9841
9842          
9843          enum_size = self.$enumerator_size();
9844          if ($truthy(enum_size['$nil?']())) {
9845            return nil
9846          } else if (($eqeq(enum_size, 0) || ($truthy($rb_lt(enum_size, n))))) {
9847            return 0
9848          } else {
9849            return $rb_plus($rb_minus(enum_size, n), 1)
9850          };}, {$$s: self})
9851      };
9852      
9853      var buffer = [];
9854
9855      self.$each.$$p = function() {
9856        var element = $Opal.$destructure(arguments);
9857        buffer.push(element);
9858        if (buffer.length > n) {
9859          buffer.shift();
9860        }
9861        if (buffer.length == n) {
9862          $yield1(block, buffer.slice(0, n));
9863        }
9864      }
9865
9866      self.$each();
9867
9868      return self;
9869    ;
9870    });
9871    
9872    $def(self, '$each_entry', function $$each_entry($a) {
9873      var block = $$each_entry.$$p || nil, $post_args, data, self = this;
9874
9875      $$each_entry.$$p = null;
9876      
9877      ;
9878      $post_args = $slice(arguments);
9879      data = $post_args;
9880      if (!(block !== nil)) {
9881        return $send(self, 'to_enum', ["each_entry"].concat($to_a(data)), function $$19(){var self = $$19.$$s == null ? this : $$19.$$s;
9882
9883          return self.$enumerator_size()}, {$$s: self})
9884      };
9885      
9886      self.$each.$$p = function() {
9887        var item = $Opal.$destructure(arguments);
9888
9889        $yield1(block, item);
9890      }
9891
9892      self.$each.apply(self, data);
9893
9894      return self;
9895    ;
9896    }, -1);
9897    
9898    $def(self, '$each_slice', function $$each_slice(n) {
9899      var block = $$each_slice.$$p || nil, self = this;
9900
9901      $$each_slice.$$p = null;
9902      
9903      ;
9904      n = $coerce_to(n, $$$('Integer'), 'to_int');
9905      if ($truthy(n <= 0)) {
9906        $Kernel.$raise($$$('ArgumentError'), "invalid slice size")
9907      };
9908      if (!(block !== nil)) {
9909        return $send(self, 'enum_for', ["each_slice", n], function $$20(){var self = $$20.$$s == null ? this : $$20.$$s;
9910
9911          if ($truthy(self['$respond_to?']("size"))) {
9912            return $rb_divide(self.$size(), n).$ceil()
9913          } else {
9914            return nil
9915          }}, {$$s: self})
9916      };
9917      
9918      var slice = []
9919
9920      self.$each.$$p = function() {
9921        var param = $Opal.$destructure(arguments);
9922
9923        slice.push(param);
9924
9925        if (slice.length === n) {
9926          $yield1(block, slice);
9927          slice = [];
9928        }
9929      };
9930
9931      self.$each();
9932
9933      // our "last" group, if smaller than n then won't have been yielded
9934      if (slice.length > 0) {
9935        $yield1(block, slice);
9936      }
9937    ;
9938      return self;
9939    });
9940    
9941    $def(self, '$each_with_index', function $$each_with_index($a) {
9942      var block = $$each_with_index.$$p || nil, $post_args, args, self = this;
9943
9944      $$each_with_index.$$p = null;
9945      
9946      ;
9947      $post_args = $slice(arguments);
9948      args = $post_args;
9949      if (!(block !== nil)) {
9950        return $send(self, 'enum_for', ["each_with_index"].concat($to_a(args)), function $$21(){var self = $$21.$$s == null ? this : $$21.$$s;
9951
9952          return self.$enumerator_size()}, {$$s: self})
9953      };
9954      
9955      var index = 0;
9956
9957      self.$each.$$p = function() {
9958        var param = $Opal.$destructure(arguments);
9959
9960        block(param, index);
9961
9962        index++;
9963      };
9964
9965      self.$each.apply(self, args);
9966    ;
9967      return self;
9968    }, -1);
9969    
9970    $def(self, '$each_with_object', function $$each_with_object(object) {
9971      var block = $$each_with_object.$$p || nil, self = this;
9972
9973      $$each_with_object.$$p = null;
9974      
9975      ;
9976      if (!(block !== nil)) {
9977        return $send(self, 'enum_for', ["each_with_object", object], function $$22(){var self = $$22.$$s == null ? this : $$22.$$s;
9978
9979          return self.$enumerator_size()}, {$$s: self})
9980      };
9981      
9982      self.$each.$$p = function() {
9983        var param = $Opal.$destructure(arguments);
9984
9985        block(param, object);
9986      };
9987
9988      self.$each();
9989    ;
9990      return object;
9991    });
9992    
9993    $def(self, '$entries', function $$entries($a) {
9994      var $post_args, args, self = this;
9995
9996      
9997      $post_args = $slice(arguments);
9998      args = $post_args;
9999      
10000      var result = [];
10001
10002      self.$each.$$p = function() {
10003        result.push($Opal.$destructure(arguments));
10004      };
10005
10006      self.$each.apply(self, args);
10007
10008      return result;
10009    ;
10010    }, -1);
10011    
10012    $def(self, '$filter_map', function $$filter_map() {
10013      var block = $$filter_map.$$p || nil, self = this;
10014
10015      $$filter_map.$$p = null;
10016      
10017      ;
10018      if (!(block !== nil)) {
10019        return $send(self, 'enum_for', ["filter_map"], function $$23(){var self = $$23.$$s == null ? this : $$23.$$s;
10020
10021          return self.$enumerator_size()}, {$$s: self})
10022      };
10023      return $send($send(self, 'map', [], block.$to_proc()), 'select', [], "itself".$to_proc());
10024    });
10025    
10026    $def(self, '$find_all', function $$find_all() {
10027      var block = $$find_all.$$p || nil, self = this;
10028
10029      $$find_all.$$p = null;
10030      
10031      ;
10032      if (!(block !== nil)) {
10033        return $send(self, 'enum_for', ["find_all"], function $$24(){var self = $$24.$$s == null ? this : $$24.$$s;
10034
10035          return self.$enumerator_size()}, {$$s: self})
10036      };
10037      
10038      var result = [];
10039
10040      self.$each.$$p = function() {
10041        var param = $Opal.$destructure(arguments),
10042            value = $yield1(block, param);
10043
10044        if ($truthy(value)) {
10045          result.push(param);
10046        }
10047      };
10048
10049      self.$each();
10050
10051      return result;
10052    ;
10053    });
10054    
10055    $def(self, '$find_index', function $$find_index(object) {try { var $t_return = $thrower('return'); 
10056      var block = $$find_index.$$p || nil, self = this, index = nil;
10057
10058      $$find_index.$$p = null;
10059      
10060      ;
10061      ;
10062      if ($truthy(object === undefined && block === nil)) {
10063        return self.$enum_for("find_index")
10064      };
10065      
10066      if (object != null && block !== nil) {
10067        self.$warn("warning: given block not used")
10068      }
10069    ;
10070      index = 0;
10071      if ($truthy(object != null)) {
10072        $send(self, 'each', [], function $$25($a){var $post_args, value;
10073
10074          
10075          $post_args = $slice(arguments);
10076          value = $post_args;
10077          if ($eqeq($Opal.$destructure(value), object)) {
10078            $t_return.$throw(index)
10079          };
10080          return index += 1;;}, {$$arity: -1, $$ret: $t_return})
10081      } else {
10082        $send(self, 'each', [], function $$26($a){var $post_args, value;
10083
10084          
10085          $post_args = $slice(arguments);
10086          value = $post_args;
10087          if ($truthy(Opal.yieldX(block, $to_a(value)))) {
10088            $t_return.$throw(index)
10089          };
10090          return index += 1;;}, {$$arity: -1, $$ret: $t_return})
10091      };
10092      return nil;} catch($e) {
10093        if ($e === $t_return) return $e.$v;
10094        throw $e;
10095      }
10096    }, -1);
10097    
10098    $def(self, '$first', function $$first(number) {try { var $t_return = $thrower('return'); 
10099      var self = this, result = nil, current = nil;
10100
10101      
10102      ;
10103      if ($truthy(number === undefined)) {
10104        return $send(self, 'each', [], function $$27(value){
10105          
10106          if (value == null) value = nil;
10107          $t_return.$throw(value);}, {$$ret: $t_return})
10108      } else {
10109        
10110        result = [];
10111        number = $coerce_to(number, $$$('Integer'), 'to_int');
10112        if ($truthy(number < 0)) {
10113          $Kernel.$raise($$$('ArgumentError'), "attempt to take negative size")
10114        };
10115        if ($truthy(number == 0)) {
10116          return []
10117        };
10118        current = 0;
10119        $send(self, 'each', [], function $$28($a){var $post_args, args;
10120
10121          
10122          $post_args = $slice(arguments);
10123          args = $post_args;
10124          result.push($Opal.$destructure(args));
10125          if ($truthy(number <= ++current)) {
10126            $t_return.$throw(result)
10127          } else {
10128            return nil
10129          };}, {$$arity: -1, $$ret: $t_return});
10130        return result;
10131      };} catch($e) {
10132        if ($e === $t_return) return $e.$v;
10133        throw $e;
10134      }
10135    }, -1);
10136    
10137    $def(self, '$grep', function $$grep(pattern) {
10138      var block = $$grep.$$p || nil, self = this, result = nil;
10139
10140      $$grep.$$p = null;
10141      
10142      ;
10143      result = [];
10144      $send(self, 'each', [], function $$29($a){var $post_args, value, cmp = nil;
10145
10146        
10147        $post_args = $slice(arguments);
10148        value = $post_args;
10149        cmp = comparableForPattern(value);
10150        if (!$truthy($send(pattern, '__send__', ["==="].concat($to_a(cmp))))) {
10151          return nil
10152        };
10153        if ((block !== nil)) {
10154          
10155          if ($truthy($rb_gt(value.$length(), 1))) {
10156            value = [value]
10157          };
10158          value = Opal.yieldX(block, $to_a(value));
10159        } else if ($truthy($rb_le(value.$length(), 1))) {
10160          value = value['$[]'](0)
10161        };
10162        return result.$push(value);}, -1);
10163      return result;
10164    });
10165    
10166    $def(self, '$grep_v', function $$grep_v(pattern) {
10167      var block = $$grep_v.$$p || nil, self = this, result = nil;
10168
10169      $$grep_v.$$p = null;
10170      
10171      ;
10172      result = [];
10173      $send(self, 'each', [], function $$30($a){var $post_args, value, cmp = nil;
10174
10175        
10176        $post_args = $slice(arguments);
10177        value = $post_args;
10178        cmp = comparableForPattern(value);
10179        if ($truthy($send(pattern, '__send__', ["==="].concat($to_a(cmp))))) {
10180          return nil
10181        };
10182        if ((block !== nil)) {
10183          
10184          if ($truthy($rb_gt(value.$length(), 1))) {
10185            value = [value]
10186          };
10187          value = Opal.yieldX(block, $to_a(value));
10188        } else if ($truthy($rb_le(value.$length(), 1))) {
10189          value = value['$[]'](0)
10190        };
10191        return result.$push(value);}, -1);
10192      return result;
10193    });
10194    
10195    $def(self, '$group_by', function $$group_by() {
10196      var block = $$group_by.$$p || nil, $a, self = this, hash = nil, $ret_or_1 = nil;
10197
10198      $$group_by.$$p = null;
10199      
10200      ;
10201      if (!(block !== nil)) {
10202        return $send(self, 'enum_for', ["group_by"], function $$31(){var self = $$31.$$s == null ? this : $$31.$$s;
10203
10204          return self.$enumerator_size()}, {$$s: self})
10205      };
10206      hash = $hash2([], {});
10207      
10208      var result;
10209
10210      self.$each.$$p = function() {
10211        var param = $Opal.$destructure(arguments),
10212            value = $yield1(block, param);
10213
10214        ($truthy(($ret_or_1 = hash['$[]'](value))) ? ($ret_or_1) : (($a = [value, []], $send(hash, '[]=', $a), $a[$a.length - 1])))['$<<'](param);
10215      }
10216
10217      self.$each();
10218
10219      if (result !== undefined) {
10220        return result;
10221      }
10222    ;
10223      return hash;
10224    });
10225    
10226    $def(self, '$include?', function $Enumerable_include$ques$32(obj) {try { var $t_return = $thrower('return'); 
10227      var self = this;
10228
10229      
10230      $send(self, 'each', [], function $$33($a){var $post_args, args;
10231
10232        
10233        $post_args = $slice(arguments);
10234        args = $post_args;
10235        if ($eqeq($Opal.$destructure(args), obj)) {
10236          $t_return.$throw(true)
10237        } else {
10238          return nil
10239        };}, {$$arity: -1, $$ret: $t_return});
10240      return false;} catch($e) {
10241        if ($e === $t_return) return $e.$v;
10242        throw $e;
10243      }
10244    });
10245    
10246    $def(self, '$inject', function $$inject(object, sym) {
10247      var block = $$inject.$$p || nil, self = this;
10248
10249      $$inject.$$p = null;
10250      
10251      ;
10252      ;
10253      ;
10254      
10255      var result = object;
10256
10257      if (block !== nil && sym === undefined) {
10258        self.$each.$$p = function() {
10259          var value = $Opal.$destructure(arguments);
10260
10261          if (result === undefined) {
10262            result = value;
10263            return;
10264          }
10265
10266          value = $yieldX(block, [result, value]);
10267
10268          result = value;
10269        };
10270      }
10271      else {
10272        if (sym === undefined) {
10273          if (!$$$('Symbol')['$==='](object)) {
10274            $Kernel.$raise($$$('TypeError'), "" + (object.$inspect()) + " is not a Symbol");
10275          }
10276
10277          sym    = object;
10278          result = undefined;
10279        }
10280
10281        self.$each.$$p = function() {
10282          var value = $Opal.$destructure(arguments);
10283
10284          if (result === undefined) {
10285            result = value;
10286            return;
10287          }
10288
10289          result = (result).$__send__(sym, value);
10290        };
10291      }
10292
10293      self.$each();
10294
10295      return result == undefined ? nil : result;
10296    ;
10297    }, -1);
10298    
10299    $def(self, '$lazy', function $$lazy() {
10300      var self = this;
10301
10302      return $send($$$($$$('Enumerator'), 'Lazy'), 'new', [self, self.$enumerator_size()], function $$34(enum$, $a){var $post_args, args;
10303
10304        
10305        if (enum$ == null) enum$ = nil;
10306        $post_args = $slice(arguments, 1);
10307        args = $post_args;
10308        return $send(enum$, 'yield', $to_a(args));}, -2)
10309    });
10310    
10311    $def(self, '$enumerator_size', function $$enumerator_size() {
10312      var self = this;
10313
10314      if ($truthy(self['$respond_to?']("size"))) {
10315        return self.$size()
10316      } else {
10317        return nil
10318      }
10319    });
10320    
10321    $def(self, '$max', function $$max(n) {
10322      var block = $$max.$$p || nil, self = this;
10323
10324      $$max.$$p = null;
10325      
10326      ;
10327      ;
10328      
10329      if (n === undefined || n === nil) {
10330        var result, value;
10331
10332        self.$each.$$p = function() {
10333          var item = $Opal.$destructure(arguments);
10334
10335          if (result === undefined) {
10336            result = item;
10337            return;
10338          }
10339
10340          if (block !== nil) {
10341            value = $yieldX(block, [item, result]);
10342          } else {
10343            value = (item)['$<=>'](result);
10344          }
10345
10346          if (value === nil) {
10347            $Kernel.$raise($$$('ArgumentError'), "comparison failed");
10348          }
10349
10350          if (value > 0) {
10351            result = item;
10352          }
10353        }
10354
10355        self.$each();
10356
10357        if (result === undefined) {
10358          return nil;
10359        } else {
10360          return result;
10361        }
10362      }
10363
10364      n = $coerce_to(n, $$$('Integer'), 'to_int');
10365    ;
10366      return $send(self, 'sort', [], block.$to_proc()).$reverse().$first(n);
10367    }, -1);
10368    
10369    $def(self, '$max_by', function $$max_by(n) {
10370      var block = $$max_by.$$p || nil, self = this;
10371
10372      $$max_by.$$p = null;
10373      
10374      ;
10375      if (n == null) n = nil;
10376      if (!$truthy(block)) {
10377        return $send(self, 'enum_for', ["max_by", n], function $$35(){var self = $$35.$$s == null ? this : $$35.$$s;
10378
10379          return self.$enumerator_size()}, {$$s: self})
10380      };
10381      if (!$truthy(n['$nil?']())) {
10382        return $send(self, 'sort_by', [], block.$to_proc()).$reverse().$take(n)
10383      };
10384      
10385      var result,
10386          by;
10387
10388      self.$each.$$p = function() {
10389        var param = $Opal.$destructure(arguments),
10390            value = $yield1(block, param);
10391
10392        if (result === undefined) {
10393          result = param;
10394          by     = value;
10395          return;
10396        }
10397
10398        if ((value)['$<=>'](by) > 0) {
10399          result = param
10400          by     = value;
10401        }
10402      };
10403
10404      self.$each();
10405
10406      return result === undefined ? nil : result;
10407    ;
10408    }, -1);
10409    
10410    $def(self, '$min', function $$min(n) {
10411      var block = $$min.$$p || nil, self = this;
10412
10413      $$min.$$p = null;
10414      
10415      ;
10416      if (n == null) n = nil;
10417      if (!$truthy(n['$nil?']())) {
10418        if ((block !== nil)) {
10419          return $send(self, 'sort', [], function $$36(a, b){
10420            
10421            if (a == null) a = nil;
10422            if (b == null) b = nil;
10423            return Opal.yieldX(block, [a, b]);;}).$take(n)
10424        } else {
10425          return self.$sort().$take(n)
10426        }
10427      };
10428      
10429      var result;
10430
10431      if (block !== nil) {
10432        self.$each.$$p = function() {
10433          var param = $Opal.$destructure(arguments);
10434
10435          if (result === undefined) {
10436            result = param;
10437            return;
10438          }
10439
10440          var value = block(param, result);
10441
10442          if (value === nil) {
10443            $Kernel.$raise($$$('ArgumentError'), "comparison failed");
10444          }
10445
10446          if (value < 0) {
10447            result = param;
10448          }
10449        };
10450      }
10451      else {
10452        self.$each.$$p = function() {
10453          var param = $Opal.$destructure(arguments);
10454
10455          if (result === undefined) {
10456            result = param;
10457            return;
10458          }
10459
10460          if ($Opal.$compare(param, result) < 0) {
10461            result = param;
10462          }
10463        };
10464      }
10465
10466      self.$each();
10467
10468      return result === undefined ? nil : result;
10469    ;
10470    }, -1);
10471    
10472    $def(self, '$min_by', function $$min_by(n) {
10473      var block = $$min_by.$$p || nil, self = this;
10474
10475      $$min_by.$$p = null;
10476      
10477      ;
10478      if (n == null) n = nil;
10479      if (!$truthy(block)) {
10480        return $send(self, 'enum_for', ["min_by", n], function $$37(){var self = $$37.$$s == null ? this : $$37.$$s;
10481
10482          return self.$enumerator_size()}, {$$s: self})
10483      };
10484      if (!$truthy(n['$nil?']())) {
10485        return $send(self, 'sort_by', [], block.$to_proc()).$take(n)
10486      };
10487      
10488      var result,
10489          by;
10490
10491      self.$each.$$p = function() {
10492        var param = $Opal.$destructure(arguments),
10493            value = $yield1(block, param);
10494
10495        if (result === undefined) {
10496          result = param;
10497          by     = value;
10498          return;
10499        }
10500
10501        if ((value)['$<=>'](by) < 0) {
10502          result = param
10503          by     = value;
10504        }
10505      };
10506
10507      self.$each();
10508
10509      return result === undefined ? nil : result;
10510    ;
10511    }, -1);
10512    
10513    $def(self, '$minmax', function $$minmax() {
10514      var block = $$minmax.$$p || nil, self = this, $ret_or_1 = nil;
10515
10516      $$minmax.$$p = null;
10517      
10518      ;
10519      block = ($truthy(($ret_or_1 = block)) ? ($ret_or_1) : ($send($Kernel, 'proc', [], function $$38(a, b){
10520        
10521        if (a == null) a = nil;
10522        if (b == null) b = nil;
10523        return a['$<=>'](b);})));
10524      
10525      var min = nil, max = nil, first_time = true;
10526
10527      self.$each.$$p = function() {
10528        var element = $Opal.$destructure(arguments);
10529        if (first_time) {
10530          min = max = element;
10531          first_time = false;
10532        } else {
10533          var min_cmp = block.$call(min, element);
10534
10535          if (min_cmp === nil) {
10536            $Kernel.$raise($$$('ArgumentError'), "comparison failed")
10537          } else if (min_cmp > 0) {
10538            min = element;
10539          }
10540
10541          var max_cmp = block.$call(max, element);
10542
10543          if (max_cmp === nil) {
10544            $Kernel.$raise($$$('ArgumentError'), "comparison failed")
10545          } else if (max_cmp < 0) {
10546            max = element;
10547          }
10548        }
10549      }
10550
10551      self.$each();
10552
10553      return [min, max];
10554    ;
10555    });
10556    
10557    $def(self, '$minmax_by', function $$minmax_by() {
10558      var block = $$minmax_by.$$p || nil, self = this;
10559
10560      $$minmax_by.$$p = null;
10561      
10562      ;
10563      if (!$truthy(block)) {
10564        return $send(self, 'enum_for', ["minmax_by"], function $$39(){var self = $$39.$$s == null ? this : $$39.$$s;
10565
10566          return self.$enumerator_size()}, {$$s: self})
10567      };
10568      
10569      var min_result = nil,
10570          max_result = nil,
10571          min_by,
10572          max_by;
10573
10574      self.$each.$$p = function() {
10575        var param = $Opal.$destructure(arguments),
10576            value = $yield1(block, param);
10577
10578        if ((min_by === undefined) || (value)['$<=>'](min_by) < 0) {
10579          min_result = param;
10580          min_by     = value;
10581        }
10582
10583        if ((max_by === undefined) || (value)['$<=>'](max_by) > 0) {
10584          max_result = param;
10585          max_by     = value;
10586        }
10587      };
10588
10589      self.$each();
10590
10591      return [min_result, max_result];
10592    ;
10593    });
10594    
10595    $def(self, '$none?', function $Enumerable_none$ques$40(pattern) {try { var $t_return = $thrower('return'); 
10596      var block = $Enumerable_none$ques$40.$$p || nil, self = this;
10597
10598      $Enumerable_none$ques$40.$$p = null;
10599      
10600      ;
10601      ;
10602      if ($truthy(pattern !== undefined)) {
10603        $send(self, 'each', [], function $$41($a){var $post_args, value, comparable = nil;
10604
10605          
10606          $post_args = $slice(arguments);
10607          value = $post_args;
10608          comparable = comparableForPattern(value);
10609          if ($truthy($send(pattern, 'public_send', ["==="].concat($to_a(comparable))))) {
10610            $t_return.$throw(false)
10611          } else {
10612            return nil
10613          };}, {$$arity: -1, $$ret: $t_return})
10614      } else if ((block !== nil)) {
10615        $send(self, 'each', [], function $$42($a){var $post_args, value;
10616
10617          
10618          $post_args = $slice(arguments);
10619          value = $post_args;
10620          if ($truthy(Opal.yieldX(block, $to_a(value)))) {
10621            $t_return.$throw(false)
10622          } else {
10623            return nil
10624          };}, {$$arity: -1, $$ret: $t_return})
10625      } else {
10626        $send(self, 'each', [], function $$43($a){var $post_args, value, item = nil;
10627
10628          
10629          $post_args = $slice(arguments);
10630          value = $post_args;
10631          item = $Opal.$destructure(value);
10632          if ($truthy(item)) {
10633            $t_return.$throw(false)
10634          } else {
10635            return nil
10636          };}, {$$arity: -1, $$ret: $t_return})
10637      };
10638      return true;} catch($e) {
10639        if ($e === $t_return) return $e.$v;
10640        throw $e;
10641      }
10642    }, -1);
10643    
10644    $def(self, '$one?', function $Enumerable_one$ques$44(pattern) {try { var $t_return = $thrower('return'); 
10645      var block = $Enumerable_one$ques$44.$$p || nil, self = this, count = nil;
10646
10647      $Enumerable_one$ques$44.$$p = null;
10648      
10649      ;
10650      ;
10651      count = 0;
10652      if ($truthy(pattern !== undefined)) {
10653        $send(self, 'each', [], function $$45($a){var $post_args, value, comparable = nil;
10654
10655          
10656          $post_args = $slice(arguments);
10657          value = $post_args;
10658          comparable = comparableForPattern(value);
10659          if ($truthy($send(pattern, 'public_send', ["==="].concat($to_a(comparable))))) {
10660            
10661            count = $rb_plus(count, 1);
10662            if ($truthy($rb_gt(count, 1))) {
10663              $t_return.$throw(false)
10664            } else {
10665              return nil
10666            };
10667          } else {
10668            return nil
10669          };}, {$$arity: -1, $$ret: $t_return})
10670      } else if ((block !== nil)) {
10671        $send(self, 'each', [], function $$46($a){var $post_args, value;
10672
10673          
10674          $post_args = $slice(arguments);
10675          value = $post_args;
10676          if (!$truthy(Opal.yieldX(block, $to_a(value)))) {
10677            return nil
10678          };
10679          count = $rb_plus(count, 1);
10680          if ($truthy($rb_gt(count, 1))) {
10681            $t_return.$throw(false)
10682          } else {
10683            return nil
10684          };}, {$$arity: -1, $$ret: $t_return})
10685      } else {
10686        $send(self, 'each', [], function $$47($a){var $post_args, value;
10687
10688          
10689          $post_args = $slice(arguments);
10690          value = $post_args;
10691          if (!$truthy($Opal.$destructure(value))) {
10692            return nil
10693          };
10694          count = $rb_plus(count, 1);
10695          if ($truthy($rb_gt(count, 1))) {
10696            $t_return.$throw(false)
10697          } else {
10698            return nil
10699          };}, {$$arity: -1, $$ret: $t_return})
10700      };
10701      return count['$=='](1);} catch($e) {
10702        if ($e === $t_return) return $e.$v;
10703        throw $e;
10704      }
10705    }, -1);
10706    
10707    $def(self, '$partition', function $$partition() {
10708      var block = $$partition.$$p || nil, self = this;
10709
10710      $$partition.$$p = null;
10711      
10712      ;
10713      if (!(block !== nil)) {
10714        return $send(self, 'enum_for', ["partition"], function $$48(){var self = $$48.$$s == null ? this : $$48.$$s;
10715
10716          return self.$enumerator_size()}, {$$s: self})
10717      };
10718      
10719      var truthy = [], falsy = [], result;
10720
10721      self.$each.$$p = function() {
10722        var param = $Opal.$destructure(arguments),
10723            value = $yield1(block, param);
10724
10725        if ($truthy(value)) {
10726          truthy.push(param);
10727        }
10728        else {
10729          falsy.push(param);
10730        }
10731      };
10732
10733      self.$each();
10734
10735      return [truthy, falsy];
10736    ;
10737    });
10738    
10739    $def(self, '$reject', function $$reject() {
10740      var block = $$reject.$$p || nil, self = this;
10741
10742      $$reject.$$p = null;
10743      
10744      ;
10745      if (!(block !== nil)) {
10746        return $send(self, 'enum_for', ["reject"], function $$49(){var self = $$49.$$s == null ? this : $$49.$$s;
10747
10748          return self.$enumerator_size()}, {$$s: self})
10749      };
10750      
10751      var result = [];
10752
10753      self.$each.$$p = function() {
10754        var param = $Opal.$destructure(arguments),
10755            value = $yield1(block, param);
10756
10757        if (!$truthy(value)) {
10758          result.push(param);
10759        }
10760      };
10761
10762      self.$each();
10763
10764      return result;
10765    ;
10766    });
10767    
10768    $def(self, '$reverse_each', function $$reverse_each() {
10769      var block = $$reverse_each.$$p || nil, self = this;
10770
10771      $$reverse_each.$$p = null;
10772      
10773      ;
10774      if (!(block !== nil)) {
10775        return $send(self, 'enum_for', ["reverse_each"], function $$50(){var self = $$50.$$s == null ? this : $$50.$$s;
10776
10777          return self.$enumerator_size()}, {$$s: self})
10778      };
10779      
10780      var result = [];
10781
10782      self.$each.$$p = function() {
10783        result.push(arguments);
10784      };
10785
10786      self.$each();
10787
10788      for (var i = result.length - 1; i >= 0; i--) {
10789        $yieldX(block, result[i]);
10790      }
10791
10792      return result;
10793    ;
10794    });
10795    
10796    $def(self, '$slice_before', function $$slice_before(pattern) {
10797      var block = $$slice_before.$$p || nil, self = this;
10798
10799      $$slice_before.$$p = null;
10800      
10801      ;
10802      ;
10803      if ($truthy(pattern === undefined && block === nil)) {
10804        $Kernel.$raise($$$('ArgumentError'), "both pattern and block are given")
10805      };
10806      if ($truthy(pattern !== undefined && block !== nil || arguments.length > 1)) {
10807        $Kernel.$raise($$$('ArgumentError'), "wrong number of arguments (" + (arguments.length) + " expected 1)")
10808      };
10809      return $send($$$('Enumerator'), 'new', [], function $$51(e){var self = $$51.$$s == null ? this : $$51.$$s;
10810
10811        
10812        if (e == null) e = nil;
10813        
10814        var slice = [];
10815
10816        if (block !== nil) {
10817          if (pattern === undefined) {
10818            self.$each.$$p = function() {
10819              var param = $Opal.$destructure(arguments),
10820                  value = $yield1(block, param);
10821
10822              if ($truthy(value) && slice.length > 0) {
10823                e['$<<'](slice);
10824                slice = [];
10825              }
10826
10827              slice.push(param);
10828            };
10829          }
10830          else {
10831            self.$each.$$p = function() {
10832              var param = $Opal.$destructure(arguments),
10833                  value = block(param, pattern.$dup());
10834
10835              if ($truthy(value) && slice.length > 0) {
10836                e['$<<'](slice);
10837                slice = [];
10838              }
10839
10840              slice.push(param);
10841            };
10842          }
10843        }
10844        else {
10845          self.$each.$$p = function() {
10846            var param = $Opal.$destructure(arguments),
10847                value = pattern['$==='](param);
10848
10849            if ($truthy(value) && slice.length > 0) {
10850              e['$<<'](slice);
10851              slice = [];
10852            }
10853
10854            slice.push(param);
10855          };
10856        }
10857
10858        self.$each();
10859
10860        if (slice.length > 0) {
10861          e['$<<'](slice);
10862        }
10863      ;}, {$$s: self});
10864    }, -1);
10865    
10866    $def(self, '$slice_after', function $$slice_after(pattern) {
10867      var block = $$slice_after.$$p || nil, self = this;
10868
10869      $$slice_after.$$p = null;
10870      
10871      ;
10872      ;
10873      if ($truthy(pattern === undefined && block === nil)) {
10874        $Kernel.$raise($$$('ArgumentError'), "both pattern and block are given")
10875      };
10876      if ($truthy(pattern !== undefined && block !== nil || arguments.length > 1)) {
10877        $Kernel.$raise($$$('ArgumentError'), "wrong number of arguments (" + (arguments.length) + " expected 1)")
10878      };
10879      if ($truthy(pattern !== undefined)) {
10880        block = $send($Kernel, 'proc', [], function $$52(e){
10881          
10882          if (e == null) e = nil;
10883          return pattern['$==='](e);})
10884      };
10885      return $send($$$('Enumerator'), 'new', [], function $$53(yielder){var self = $$53.$$s == null ? this : $$53.$$s;
10886
10887        
10888        if (yielder == null) yielder = nil;
10889        
10890        var accumulate;
10891
10892        self.$each.$$p = function() {
10893          var element = $Opal.$destructure(arguments),
10894              end_chunk = $yield1(block, element);
10895
10896          if (accumulate == null) {
10897            accumulate = [];
10898          }
10899
10900          if ($truthy(end_chunk)) {
10901            accumulate.push(element);
10902            yielder.$yield(accumulate);
10903            accumulate = null;
10904          } else {
10905            accumulate.push(element)
10906          }
10907        }
10908
10909        self.$each();
10910
10911        if (accumulate != null) {
10912          yielder.$yield(accumulate);
10913        }
10914      ;}, {$$s: self});
10915    }, -1);
10916    
10917    $def(self, '$slice_when', function $$slice_when() {
10918      var block = $$slice_when.$$p || nil, self = this;
10919
10920      $$slice_when.$$p = null;
10921      
10922      ;
10923      if (!(block !== nil)) {
10924        $Kernel.$raise($$$('ArgumentError'), "wrong number of arguments (0 for 1)")
10925      };
10926      return $send($$$('Enumerator'), 'new', [], function $$54(yielder){var self = $$54.$$s == null ? this : $$54.$$s;
10927
10928        
10929        if (yielder == null) yielder = nil;
10930        
10931        var slice = nil, last_after = nil;
10932
10933        self.$each_cons.$$p = function() {
10934          var params = $Opal.$destructure(arguments),
10935              before = params[0],
10936              after = params[1],
10937              match = $yieldX(block, [before, after]);
10938
10939          last_after = after;
10940
10941          if (slice === nil) {
10942            slice = [];
10943          }
10944
10945          if ($truthy(match)) {
10946            slice.push(before);
10947            yielder.$yield(slice);
10948            slice = [];
10949          } else {
10950            slice.push(before);
10951          }
10952        }
10953
10954        self.$each_cons(2);
10955
10956        if (slice !== nil) {
10957          slice.push(last_after);
10958          yielder.$yield(slice);
10959        }
10960      ;}, {$$s: self});
10961    });
10962    
10963    $def(self, '$sort', function $$sort() {
10964      var block = $$sort.$$p || nil, self = this, ary = nil;
10965
10966      $$sort.$$p = null;
10967      
10968      ;
10969      ary = self.$to_a();
10970      if (!(block !== nil)) {
10971        block = $lambda(function $$55(a, b){
10972          
10973          if (a == null) a = nil;
10974          if (b == null) b = nil;
10975          return a['$<=>'](b);})
10976      };
10977      return $send(ary, 'sort', [], block.$to_proc());
10978    });
10979    
10980    $def(self, '$sort_by', function $$sort_by() {
10981      var block = $$sort_by.$$p || nil, self = this, dup = nil;
10982
10983      $$sort_by.$$p = null;
10984      
10985      ;
10986      if (!(block !== nil)) {
10987        return $send(self, 'enum_for', ["sort_by"], function $$56(){var self = $$56.$$s == null ? this : $$56.$$s;
10988
10989          return self.$enumerator_size()}, {$$s: self})
10990      };
10991      dup = $send(self, 'map', [], function $$57(){var arg = nil;
10992
10993        
10994        arg = $Opal.$destructure(arguments);
10995        return [Opal.yield1(block, arg), arg];});
10996      $send(dup, 'sort!', [], function $$58(a, b){
10997        
10998        if (a == null) a = nil;
10999        if (b == null) b = nil;
11000        return (a[0])['$<=>'](b[0]);});
11001      return $send(dup, 'map!', [], function $$59(i){
11002        
11003        if (i == null) i = nil;
11004        return i[1];;});
11005    });
11006    
11007    $def(self, '$sum', function $$sum(initial) {
11008      var $yield = $$sum.$$p || nil, self = this, result = nil, compensation = nil;
11009
11010      $$sum.$$p = null;
11011      
11012      if (initial == null) initial = 0;
11013      result = initial;
11014      compensation = 0;
11015      $send(self, 'each', [], function $$60($a){var $post_args, args, item = nil, y = nil, t = nil;
11016
11017        
11018        $post_args = $slice(arguments);
11019        args = $post_args;
11020        item = (($yield !== nil) ? (Opal.yieldX($yield, $to_a(args))) : ($Opal.$destructure(args)));
11021        if (($not([$$$($$$('Float'), 'INFINITY'), $$$($$$('Float'), 'INFINITY')['$-@']()]['$include?'](item)) && ($truthy(item['$respond_to?']("-"))))) {
11022          
11023          y = $rb_minus(item, compensation);
11024          t = $rb_plus(result, y);
11025          compensation = $rb_minus($rb_minus(t, result), y);
11026          return (result = t);
11027        } else {
11028          return (result = $rb_plus(result, item))
11029        };}, -1);
11030      return result;
11031    }, -1);
11032    
11033    $def(self, '$take', function $$take(num) {
11034      var self = this;
11035
11036      return self.$first(num)
11037    });
11038    
11039    $def(self, '$take_while', function $$take_while() {try { var $t_return = $thrower('return'); 
11040      var block = $$take_while.$$p || nil, self = this, result = nil;
11041
11042      $$take_while.$$p = null;
11043      
11044      ;
11045      if (!$truthy(block)) {
11046        return self.$enum_for("take_while")
11047      };
11048      result = [];
11049      return $send(self, 'each', [], function $$61($a){var $post_args, args, value = nil;
11050
11051        
11052        $post_args = $slice(arguments);
11053        args = $post_args;
11054        value = $Opal.$destructure(args);
11055        if (!$truthy(Opal.yield1(block, value))) {
11056          $t_return.$throw(result)
11057        };
11058        return result.push(value);;}, {$$arity: -1, $$ret: $t_return});} catch($e) {
11059        if ($e === $t_return) return $e.$v;
11060        throw $e;
11061      }
11062    });
11063    
11064    $def(self, '$uniq', function $$uniq() {
11065      var block = $$uniq.$$p || nil, self = this, hash = nil;
11066
11067      $$uniq.$$p = null;
11068      
11069      ;
11070      hash = $hash2([], {});
11071      $send(self, 'each', [], function $$62($a){var $post_args, args, $b, value = nil, produced = nil;
11072
11073        
11074        $post_args = $slice(arguments);
11075        args = $post_args;
11076        value = $Opal.$destructure(args);
11077        produced = ((block !== nil) ? (Opal.yield1(block, value)) : (value));
11078        if ($truthy(hash['$key?'](produced))) {
11079          return nil
11080        } else {
11081          return ($b = [produced, value], $send(hash, '[]=', $b), $b[$b.length - 1])
11082        };}, -1);
11083      return hash.$values();
11084    });
11085    
11086    $def(self, '$tally', function $$tally(hash) {
11087      var self = this, out = nil;
11088
11089      
11090      ;
11091      if (hash && hash !== nil) { $deny_frozen_access(hash); };
11092      out = $send($send(self, 'group_by', [], "itself".$to_proc()), 'transform_values', [], "count".$to_proc());
11093      if ($truthy(hash)) {
11094        
11095        $send(out, 'each', [], function $$63(k, v){var $a;
11096
11097          
11098          if (k == null) k = nil;
11099          if (v == null) v = nil;
11100          return ($a = [k, $rb_plus(hash.$fetch(k, 0), v)], $send(hash, '[]=', $a), $a[$a.length - 1]);});
11101        return hash;
11102      } else {
11103        return out
11104      };
11105    }, -1);
11106    
11107    $def(self, '$to_h', function $$to_h($a) {
11108      var block = $$to_h.$$p || nil, $post_args, args, self = this;
11109
11110      $$to_h.$$p = null;
11111      
11112      ;
11113      $post_args = $slice(arguments);
11114      args = $post_args;
11115      if ((block !== nil)) {
11116        return $send($send(self, 'map', [], block.$to_proc()), 'to_h', $to_a(args))
11117      };
11118      
11119      var hash = $hash2([], {});
11120
11121      self.$each.$$p = function() {
11122        var param = $Opal.$destructure(arguments);
11123        var ary = $Opal['$coerce_to?'](param, $$$('Array'), "to_ary"), key, val;
11124        if (!ary.$$is_array) {
11125          $Kernel.$raise($$$('TypeError'), "wrong element type " + ((ary).$class()) + " (expected array)")
11126        }
11127        if (ary.length !== 2) {
11128          $Kernel.$raise($$$('ArgumentError'), "wrong array length (expected 2, was " + ((ary).$length()) + ")")
11129        }
11130        key = ary[0];
11131        val = ary[1];
11132
11133        Opal.hash_put(hash, key, val);
11134      };
11135
11136      self.$each.apply(self, args);
11137
11138      return hash;
11139    ;
11140    }, -1);
11141    
11142    $def(self, '$to_set', function $$to_set($a, $b) {
11143      var block = $$to_set.$$p || nil, $post_args, klass, args, self = this;
11144
11145      $$to_set.$$p = null;
11146      
11147      ;
11148      $post_args = $slice(arguments);
11149      
11150      if ($post_args.length > 0) klass = $post_args.shift();if (klass == null) klass = $$('Set');
11151      args = $post_args;
11152      return $send(klass, 'new', [self].concat($to_a(args)), block.$to_proc());
11153    }, -1);
11154    
11155    $def(self, '$zip', function $$zip($a) {
11156      var block = $$zip.$$p || nil, $post_args, others, self = this;
11157
11158      $$zip.$$p = null;
11159      
11160      ;
11161      $post_args = $slice(arguments);
11162      others = $post_args;
11163      return $send(self.$to_a(), 'zip', $to_a(others));
11164    }, -1);
11165    $alias(self, "find", "detect");
11166    $alias(self, "filter", "find_all");
11167    $alias(self, "flat_map", "collect_concat");
11168    $alias(self, "map", "collect");
11169    $alias(self, "member?", "include?");
11170    $alias(self, "reduce", "inject");
11171    $alias(self, "select", "find_all");
11172    return $alias(self, "to_a", "entries");
11173  })('::', $nesting)
11174};
11175
11176Opal.modules["corelib/enumerator/arithmetic_sequence"] = function(Opal) {/* Generated by Opal 1.7.3 */
11177  var $klass = Opal.klass, $truthy = Opal.truthy, $to_a = Opal.to_a, $eqeq = Opal.eqeq, $Kernel = Opal.Kernel, $def = Opal.def, $rb_gt = Opal.rb_gt, $rb_lt = Opal.rb_lt, $rb_le = Opal.rb_le, $rb_ge = Opal.rb_ge, $rb_plus = Opal.rb_plus, $rb_minus = Opal.rb_minus, $eqeqeq = Opal.eqeqeq, $not = Opal.not, $rb_times = Opal.rb_times, $rb_divide = Opal.rb_divide, $alias = Opal.alias, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$;
11178
11179  Opal.add_stubs('is_a?,==,raise,respond_to?,class,attr_reader,begin,end,exclude_end?,>,step,<,<=,>=,-@,_lesser_than_end?,<<,+,-,===,%,_greater_than_begin?,reverse,!,include?,*,to_i,abs,/,hash,inspect');
11180  return (function($base, $super, $parent_nesting) {
11181    var self = $klass($base, $super, 'Enumerator');
11182
11183    var $nesting = [self].concat($parent_nesting);
11184
11185    return (function($base, $super, $parent_nesting) {
11186      var self = $klass($base, $super, 'ArithmeticSequence');
11187
11188      var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype;
11189
11190      $proto.step_arg2 = $proto.receiver_num = $proto.step_arg1 = $proto.step = $proto.range = $proto.topfx = $proto.bypfx = $proto.creation_method = $proto.skipped_arg = nil;
11191      
11192      Opal.prop(self.$$prototype, '$$is_arithmetic_seq', true);
11193      var inf = Infinity;
11194      
11195      $def(self, '$initialize', function $$initialize(range, step, creation_method) {
11196        var $a, self = this, $ret_or_1 = nil;
11197
11198        
11199        ;
11200        if (creation_method == null) creation_method = "step";
11201        self.creation_method = creation_method;
11202        if ($truthy(range['$is_a?']($$$('Array')))) {
11203          
11204          $a = [].concat($to_a(range)), (self.step_arg1 = ($a[0] == null ? nil : $a[0])), (self.step_arg2 = ($a[1] == null ? nil : $a[1])), (self.topfx = ($a[2] == null ? nil : $a[2])), (self.bypfx = ($a[3] == null ? nil : $a[3])), $a;
11205          self.receiver_num = step;
11206          self.step = 1;
11207          self.range = ($truthy(self.step_arg2) ? (((self.step = self.step_arg2), Opal.Range.$new(self.receiver_num, self.step_arg1, false))) : ($truthy(self.step_arg1) ? (Opal.Range.$new(self.receiver_num, self.step_arg1, false)) : (Opal.Range.$new(self.receiver_num, nil, false))));
11208        } else {
11209          
11210          if (!$truthy(step)) {
11211            self.skipped_arg = true
11212          };
11213          $a = [range, ($truthy(($ret_or_1 = step)) ? ($ret_or_1) : (1))], (self.range = $a[0]), (self.step = $a[1]), $a;
11214        };
11215        self.object = self;
11216        if ($eqeq(self.step, 0)) {
11217          $Kernel.$raise($$('ArgumentError'), "step can't be 0")
11218        };
11219        if ($truthy(self.step['$respond_to?']("to_int"))) {
11220          return nil
11221        } else {
11222          return $Kernel.$raise($$('ArgumentError'), "" + ("no implicit conversion of " + (self.step.$class()) + " ") + "into Integer")
11223        };
11224      }, -2);
11225      self.$attr_reader("step");
11226      
11227      $def(self, '$begin', function $$begin() {
11228        var self = this;
11229
11230        return self.range.$begin()
11231      });
11232      
11233      $def(self, '$end', function $$end() {
11234        var self = this;
11235
11236        return self.range.$end()
11237      });
11238      
11239      $def(self, '$exclude_end?', function $ArithmeticSequence_exclude_end$ques$1() {
11240        var self = this;
11241
11242        return self.range['$exclude_end?']()
11243      });
11244      
11245      $def(self, '$_lesser_than_end?', function $ArithmeticSequence__lesser_than_end$ques$2(val) {
11246        var self = this, end_ = nil, $ret_or_1 = nil;
11247
11248        
11249        end_ = ($truthy(($ret_or_1 = self.$end())) ? ($ret_or_1) : (inf));
11250        if ($truthy($rb_gt(self.$step(), 0))) {
11251          if ($truthy(self['$exclude_end?']())) {
11252            return $rb_lt(val, end_)
11253          } else {
11254            return $rb_le(val, end_)
11255          }
11256        } else if ($truthy(self['$exclude_end?']())) {
11257          return $rb_gt(val, end_)
11258        } else {
11259          return $rb_ge(val, end_)
11260        };
11261      });
11262      
11263      $def(self, '$_greater_than_begin?', function $ArithmeticSequence__greater_than_begin$ques$3(val) {
11264        var self = this, begin_ = nil, $ret_or_1 = nil;
11265
11266        
11267        begin_ = ($truthy(($ret_or_1 = self.$begin())) ? ($ret_or_1) : ((inf)['$-@']()));
11268        if ($truthy($rb_gt(self.$step(), 0))) {
11269          return $rb_gt(val, begin_)
11270        } else {
11271          return $rb_lt(val, begin_)
11272        };
11273      });
11274      
11275      $def(self, '$first', function $$first(count) {
11276        var self = this, iter = nil, $ret_or_1 = nil, out = nil;
11277
11278        
11279        ;
11280        iter = ($truthy(($ret_or_1 = self.$begin())) ? ($ret_or_1) : ((inf)['$-@']()));
11281        if (!$truthy(count)) {
11282          return ($truthy(self['$_lesser_than_end?'](iter)) ? (iter) : (nil))
11283        };
11284        out = [];
11285        while ($truthy(($truthy(($ret_or_1 = self['$_lesser_than_end?'](iter))) ? ($rb_gt(count, 0)) : ($ret_or_1)))) {
11286        
11287          out['$<<'](iter);
11288          iter = $rb_plus(iter, self.$step());
11289          count = $rb_minus(count, 1);
11290        };
11291        return out;
11292      }, -1);
11293      
11294      $def(self, '$each', function $$each() {
11295        var block = $$each.$$p || nil, self = this, $ret_or_1 = nil, iter = nil;
11296
11297        $$each.$$p = null;
11298        
11299        ;
11300        if (!(block !== nil)) {
11301          return self
11302        };
11303        if ($eqeqeq(nil, ($ret_or_1 = self.$begin()))) {
11304          $Kernel.$raise($$('TypeError'), "nil can't be coerced into Integer")
11305        } else {
11306          nil
11307        };
11308        iter = ($truthy(($ret_or_1 = self.$begin())) ? ($ret_or_1) : ((inf)['$-@']()));
11309        while ($truthy(self['$_lesser_than_end?'](iter))) {
11310        
11311          Opal.yield1(block, iter);
11312          iter = $rb_plus(iter, self.$step());
11313        };
11314        return self;
11315      });
11316      
11317      $def(self, '$last', function $$last(count) {
11318        var self = this, $ret_or_1 = nil, iter = nil, out = nil;
11319
11320        
11321        ;
11322        if (($eqeqeq(inf, ($ret_or_1 = self.$end())) || ($eqeqeq((inf)['$-@'](), $ret_or_1)))) {
11323          $Kernel.$raise($$$('FloatDomainError'), self.$end())
11324        } else if ($eqeqeq(nil, $ret_or_1)) {
11325          $Kernel.$raise($$$('RangeError'), "cannot get the last element of endless arithmetic sequence")
11326        } else {
11327          nil
11328        };
11329        iter = $rb_minus(self.$end(), $rb_minus(self.$end(), self.$begin())['$%'](self.$step()));
11330        if (!$truthy(self['$_lesser_than_end?'](iter))) {
11331          iter = $rb_minus(iter, self.$step())
11332        };
11333        if (!$truthy(count)) {
11334          return ($truthy(self['$_greater_than_begin?'](iter)) ? (iter) : (nil))
11335        };
11336        out = [];
11337        while ($truthy(($truthy(($ret_or_1 = self['$_greater_than_begin?'](iter))) ? ($rb_gt(count, 0)) : ($ret_or_1)))) {
11338        
11339          out['$<<'](iter);
11340          iter = $rb_minus(iter, self.$step());
11341          count = $rb_minus(count, 1);
11342        };
11343        return out.$reverse();
11344      }, -1);
11345      
11346      $def(self, '$size', function $$size() {
11347        var self = this, step_sign = nil, iter = nil;
11348
11349        
11350        step_sign = ($truthy($rb_gt(self.$step(), 0)) ? (1) : (-1));
11351        if ($not(self['$_lesser_than_end?'](self.$begin()))) {
11352          return 0
11353        } else if ($truthy([(inf)['$-@'](), inf]['$include?'](self.$step()))) {
11354          return 1
11355        } else if (($truthy([$rb_times((inf)['$-@'](), step_sign), nil]['$include?'](self.$begin())) || ($truthy([$rb_times(inf, step_sign), nil]['$include?'](self.$end()))))) {
11356          return inf;
11357        } else {
11358          
11359          iter = $rb_minus(self.$end(), $rb_minus(self.$end(), self.$begin())['$%'](self.$step()));
11360          if (!$truthy(self['$_lesser_than_end?'](iter))) {
11361            iter = $rb_minus(iter, self.$step())
11362          };
11363          return $rb_plus($rb_divide($rb_minus(iter, self.$begin()), self.$step()).$abs().$to_i(), 1);
11364        };
11365      });
11366      
11367      $def(self, '$==', function $ArithmeticSequence_$eq_eq$4(other) {
11368        var self = this, $ret_or_1 = nil, $ret_or_2 = nil, $ret_or_3 = nil, $ret_or_4 = nil;
11369
11370        if ($truthy(($ret_or_1 = ($truthy(($ret_or_2 = ($truthy(($ret_or_3 = ($truthy(($ret_or_4 = self.$class()['$=='](other.$class()))) ? (self.$begin()['$=='](other.$begin())) : ($ret_or_4)))) ? (self.$end()['$=='](other.$end())) : ($ret_or_3)))) ? (self.$step()['$=='](other.$step())) : ($ret_or_2))))) {
11371          return self['$exclude_end?']()['$=='](other['$exclude_end?']())
11372        } else {
11373          return $ret_or_1
11374        }
11375      });
11376      
11377      $def(self, '$hash', function $$hash() {
11378        var self = this;
11379
11380        return [self.$begin(), self.$end(), self.$step(), self['$exclude_end?']()].$hash()
11381      });
11382      
11383      $def(self, '$inspect', function $$inspect() {
11384        var self = this, args = nil;
11385
11386        if ($truthy(self.receiver_num)) {
11387          
11388          args = ($truthy(self.step_arg2) ? ("(" + (self.topfx) + (self.step_arg1.$inspect()) + ", " + (self.bypfx) + (self.step_arg2.$inspect()) + ")") : ($truthy(self.step_arg1) ? ("(" + (self.topfx) + (self.step_arg1.$inspect()) + ")") : nil));
11389          return "(" + (self.receiver_num.$inspect()) + "." + (self.creation_method) + (args) + ")";
11390        } else {
11391          
11392          args = ($truthy(self.skipped_arg) ? (nil) : ("(" + (self.step) + ")"));
11393          return "((" + (self.range.$inspect()) + ")." + (self.creation_method) + (args) + ")";
11394        }
11395      });
11396      $alias(self, "===", "==");
11397      return $alias(self, "eql?", "==");
11398    })(self, self, $nesting)
11399  })('::', null, $nesting)
11400};
11401
11402Opal.modules["corelib/enumerator/chain"] = function(Opal) {/* Generated by Opal 1.7.3 */
11403  var $deny_frozen_access = Opal.deny_frozen_access, $klass = Opal.klass, $slice = Opal.slice, $def = Opal.def, $send = Opal.send, $to_a = Opal.to_a, $truthy = Opal.truthy, $rb_plus = Opal.rb_plus, $thrower = Opal.thrower, nil = Opal.nil, $$$ = Opal.$$$;
11404
11405  Opal.add_stubs('to_enum,size,each,<<,to_proc,include?,+,reverse_each,respond_to?,rewind,inspect');
11406  return (function($base, $super) {
11407    var self = $klass($base, $super, 'Enumerator');
11408
11409    
11410    return (function($base, $super) {
11411      var self = $klass($base, $super, 'Chain');
11412
11413      var $proto = self.$$prototype;
11414
11415      $proto.enums = $proto.iterated = nil;
11416      
11417      
11418      $def(self, '$initialize', function $$initialize($a) {
11419        var $post_args, enums, self = this;
11420
11421        
11422        $post_args = $slice(arguments);
11423        enums = $post_args;
11424        $deny_frozen_access(self);
11425        self.enums = enums;
11426        self.iterated = [];
11427        return (self.object = self);
11428      }, -1);
11429      
11430      $def(self, '$each', function $$each($a) {
11431        var block = $$each.$$p || nil, $post_args, args, self = this;
11432
11433        $$each.$$p = null;
11434        
11435        ;
11436        $post_args = $slice(arguments);
11437        args = $post_args;
11438        if (!(block !== nil)) {
11439          return $send(self, 'to_enum', ["each"].concat($to_a(args)), function $$1(){var self = $$1.$$s == null ? this : $$1.$$s;
11440
11441            return self.$size()}, {$$s: self})
11442        };
11443        $send(self.enums, 'each', [], function $$2(enum$){var self = $$2.$$s == null ? this : $$2.$$s;
11444          if (self.iterated == null) self.iterated = nil;
11445
11446          
11447          if (enum$ == null) enum$ = nil;
11448          self.iterated['$<<'](enum$);
11449          return $send(enum$, 'each', $to_a(args), block.$to_proc());}, {$$s: self});
11450        return self;
11451      }, -1);
11452      
11453      $def(self, '$size', function $$size($a) {try { var $t_return = $thrower('return'); 
11454        var $post_args, args, self = this, accum = nil;
11455
11456        
11457        $post_args = $slice(arguments);
11458        args = $post_args;
11459        accum = 0;
11460        $send(self.enums, 'each', [], function $$3(enum$){var size = nil;
11461
11462          
11463          if (enum$ == null) enum$ = nil;
11464          size = $send(enum$, 'size', $to_a(args));
11465          if ($truthy([nil, $$$($$$('Float'), 'INFINITY')]['$include?'](size))) {
11466            $t_return.$throw(size)
11467          };
11468          return (accum = $rb_plus(accum, size));}, {$$ret: $t_return});
11469        return accum;} catch($e) {
11470          if ($e === $t_return) return $e.$v;
11471          throw $e;
11472        }
11473      }, -1);
11474      
11475      $def(self, '$rewind', function $$rewind() {
11476        var self = this;
11477
11478        
11479        $send(self.iterated, 'reverse_each', [], function $$4(enum$){
11480          
11481          if (enum$ == null) enum$ = nil;
11482          if ($truthy(enum$['$respond_to?']("rewind"))) {
11483            return enum$.$rewind()
11484          } else {
11485            return nil
11486          };});
11487        self.iterated = [];
11488        return self;
11489      });
11490      return $def(self, '$inspect', function $$inspect() {
11491        var self = this;
11492
11493        return "#<Enumerator::Chain: " + (self.enums.$inspect()) + ">"
11494      });
11495    })(self, self)
11496  })('::', null)
11497};
11498
11499Opal.modules["corelib/enumerator/generator"] = function(Opal) {/* Generated by Opal 1.7.3 */
11500  var $deny_frozen_access = Opal.deny_frozen_access, $klass = Opal.klass, $truthy = Opal.truthy, $Kernel = Opal.Kernel, $def = Opal.def, $slice = Opal.slice, $send = Opal.send, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$;
11501
11502  Opal.add_stubs('include,raise,new,to_proc');
11503  return (function($base, $super, $parent_nesting) {
11504    var self = $klass($base, $super, 'Enumerator');
11505
11506    var $nesting = [self].concat($parent_nesting);
11507
11508    return (function($base, $super, $parent_nesting) {
11509      var self = $klass($base, $super, 'Generator');
11510
11511      var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype;
11512
11513      $proto.block = nil;
11514      
11515      self.$include($$$('Enumerable'));
11516      
11517      $def(self, '$initialize', function $$initialize() {
11518        var block = $$initialize.$$p || nil, self = this;
11519
11520        $$initialize.$$p = null;
11521        
11522        ;
11523        $deny_frozen_access(self);
11524        if (!$truthy(block)) {
11525          $Kernel.$raise($$$('LocalJumpError'), "no block given")
11526        };
11527        return (self.block = block);
11528      });
11529      return $def(self, '$each', function $$each($a) {
11530        var block = $$each.$$p || nil, $post_args, args, self = this, yielder = nil;
11531
11532        $$each.$$p = null;
11533        
11534        ;
11535        $post_args = $slice(arguments);
11536        args = $post_args;
11537        yielder = $send($$('Yielder'), 'new', [], block.$to_proc());
11538        
11539        try {
11540          args.unshift(yielder);
11541
11542          Opal.yieldX(self.block, args);
11543        }
11544        catch (e) {
11545          if (e && e.$thrower_type == "breaker") {
11546            return e.$v;
11547          }
11548          else {
11549            throw e;
11550          }
11551        }
11552      ;
11553        return self;
11554      }, -1);
11555    })($nesting[0], null, $nesting)
11556  })($nesting[0], null, $nesting)
11557};
11558
11559Opal.modules["corelib/enumerator/lazy"] = function(Opal) {/* Generated by Opal 1.7.3 */
11560  var $truthy = Opal.truthy, $coerce_to = Opal.coerce_to, $yield1 = Opal.yield1, $yieldX = Opal.yieldX, $deny_frozen_access = Opal.deny_frozen_access, $klass = Opal.klass, $slice = Opal.slice, $send2 = Opal.send2, $find_super = Opal.find_super, $to_a = Opal.to_a, $def
11560s = Opal.defs, $Kernel = Opal.Kernel, $send = Opal.send, $def = Opal.def, $return_self = Opal.return_self, $Opal = Opal.Opal, $rb_lt = Opal.rb_lt, $eqeqeq = Opal.eqeqeq, $rb_plus = Opal.rb_plus, $alias = Opal.alias, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$;
11561
11562  Opal.add_stubs('raise,each,new,enumerator_size,yield,respond_to?,try_convert,<,===,+,for,class,to_proc,destructure,inspect,to_a,find_all,collect_concat,collect,enum_for');
11563  return (function($base, $super, $parent_nesting) {
11564    var self = $klass($base, $super, 'Enumerator');
11565
11566    var $nesting = [self].concat($parent_nesting);
11567
11568    return (function($base, $super, $parent_nesting) {
11569      var self = $klass($base, $super, 'Lazy');
11570
11571      var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype;
11572
11573      $proto.enumerator = nil;
11574      
11575      $klass(self, $$$('Exception'), 'StopLazyError');
11576      $defs(self, '$for', function $Lazy_for$1(object, $a) {
11577        var $post_args, $fwd_rest, $yield = $Lazy_for$1.$$p || nil, self = this, lazy = nil;
11578
11579        $Lazy_for$1.$$p = null;
11580        
11581        $post_args = $slice(arguments, 1);
11582        $fwd_rest = $post_args;
11583        lazy = $send2(self, $find_super(self, 'for', $Lazy_for$1, false, true), 'for', [object].concat($to_a($fwd_rest)), $yield);
11584        lazy.enumerator = object;
11585        return lazy;
11586      }, -2);
11587      
11588      $def(self, '$initialize', function $$initialize(object, size) {
11589        var block = $$initialize.$$p || nil, self = this;
11590
11591        $$initialize.$$p = null;
11592        
11593        ;
11594        if (size == null) size = nil;
11595        $deny_frozen_access(self);
11596        if (!(block !== nil)) {
11597          $Kernel.$raise($$$('ArgumentError'), "tried to call lazy new without a block")
11598        };
11599        self.enumerator = object;
11600        return $send2(self, $find_super(self, 'initialize', $$initialize, false, true), 'initialize', [size], function $$2(yielder, $a){var $post_args, each_args;
11601
11602          
11603          if (yielder == null) yielder = nil;
11604          $post_args = $slice(arguments, 1);
11605          each_args = $post_args;
11606          try {
11607            return $send(object, 'each', $to_a(each_args), function $$3($b){var $post_args, args;
11608
11609              
11610              $post_args = $slice(arguments);
11611              args = $post_args;
11612              
11613            args.unshift(yielder);
11614
11615            $yieldX(block, args);
11616          ;}, -1)
11617          } catch ($err) {
11618            if (Opal.rescue($err, [$$('StopLazyError')])) {
11619              try {
11620                return nil
11621              } finally { Opal.pop_exception(); }
11622            } else { throw $err; }
11623          };}, -2);
11624      }, -2);
11625      
11626      $def(self, '$lazy', $return_self);
11627      
11628      $def(self, '$collect', function $$collect() {
11629        var block = $$collect.$$p || nil, self = this;
11630
11631        $$collect.$$p = null;
11632        
11633        ;
11634        if (!$truthy(block)) {
11635          $Kernel.$raise($$$('ArgumentError'), "tried to call lazy map without a block")
11636        };
11637        return $send($$('Lazy'), 'new', [self, self.$enumerator_size()], function $$4(enum$, $a){var $post_args, args;
11638
11639          
11640          if (enum$ == null) enum$ = nil;
11641          $post_args = $slice(arguments, 1);
11642          args = $post_args;
11643          
11644          var value = $yieldX(block, args);
11645
11646          enum$.$yield(value);
11647        ;}, -2);
11648      });
11649      
11650      $def(self, '$collect_concat', function $$collect_concat() {
11651        var block = $$collect_concat.$$p || nil, self = this;
11652
11653        $$collect_concat.$$p = null;
11654        
11655        ;
11656        if (!$truthy(block)) {
11657          $Kernel.$raise($$$('ArgumentError'), "tried to call lazy map without a block")
11658        };
11659        return $send($$('Lazy'), 'new', [self, nil], function $$5(enum$, $a){var $post_args, args;
11660
11661          
11662          if (enum$ == null) enum$ = nil;
11663          $post_args = $slice(arguments, 1);
11664          args = $post_args;
11665          
11666          var value = $yieldX(block, args);
11667
11668          if ((value)['$respond_to?']("force") && (value)['$respond_to?']("each")) {
11669            $send((value), 'each', [], function $$6(v){
11670            
11671            if (v == null) v = nil;
11672            return enum$.$yield(v);})
11673          }
11674          else {
11675            var array = $Opal.$try_convert(value, $$$('Array'), "to_ary");
11676
11677            if (array === nil) {
11678              enum$.$yield(value);
11679            }
11680            else {
11681              $send((value), 'each', [], function $$7(v){
11682            
11683            if (v == null) v = nil;
11684            return enum$.$yield(v);});
11685            }
11686          }
11687        ;}, -2);
11688      });
11689      
11690      $def(self, '$drop', function $$drop(n) {
11691        var self = this, current_size = nil, set_size = nil, dropped = nil;
11692
11693        
11694        n = $coerce_to(n, $$$('Integer'), 'to_int');
11695        if ($truthy($rb_lt(n, 0))) {
11696          $Kernel.$raise($$$('ArgumentError'), "attempt to drop negative size")
11697        };
11698        current_size = self.$enumerator_size();
11699        set_size = ($eqeqeq($$$('Integer'), current_size) ? (($truthy($rb_lt(n, current_size)) ? (n) : (current_size))) : (current_size));
11700        dropped = 0;
11701        return $send($$('Lazy'), 'new', [self, set_size], function $$8(enum$, $a){var $post_args, args;
11702
11703          
11704          if (enum$ == null) enum$ = nil;
11705          $post_args = $slice(arguments, 1);
11706          args = $post_args;
11707          if ($truthy($rb_lt(dropped, n))) {
11708            return (dropped = $rb_plus(dropped, 1))
11709          } else {
11710            return $send(enum$, 'yield', $to_a(args))
11711          };}, -2);
11712      });
11713      
11714      $def(self, '$drop_while', function $$drop_while() {
11715        var block = $$drop_while.$$p || nil, self = this, succeeding = nil;
11716
11717        $$drop_while.$$p = null;
11718        
11719        ;
11720        if (!$truthy(block)) {
11721          $Kernel.$raise($$$('ArgumentError'), "tried to call lazy drop_while without a block")
11722        };
11723        succeeding = true;
11724        return $send($$('Lazy'), 'new', [self, nil], function $$9(enum$, $a){var $post_args, args;
11725
11726          
11727          if (enum$ == null) enum$ = nil;
11728          $post_args = $slice(arguments, 1);
11729          args = $post_args;
11730          if ($truthy(succeeding)) {
11731            
11732            var value = $yieldX(block, args);
11733
11734            if (!$truthy(value)) {
11735              succeeding = false;
11736
11737              $send(enum$, 'yield', $to_a(args));
11738            }
11739          
11740          } else {
11741            return $send(enum$, 'yield', $to_a(args))
11742          };}, -2);
11743      });
11744      
11745      $def(self, '$enum_for', function $$enum_for($a, $b) {
11746        var block = $$enum_for.$$p || nil, $post_args, method, args, self = this;
11747
11748        $$enum_for.$$p = null;
11749        
11750        ;
11751        $post_args = $slice(arguments);
11752        
11753        if ($post_args.length > 0) method = $post_args.shift();if (method == null) method = "each";
11754        args = $post_args;
11755        return $send(self.$class(), 'for', [self, method].concat($to_a(args)), block.$to_proc());
11756      }, -1);
11757      
11758      $def(self, '$find_all', function $$find_all() {
11759        var block = $$find_all.$$p || nil, self = this;
11760
11761        $$find_all.$$p = null;
11762        
11763        ;
11764        if (!$truthy(block)) {
11765          $Kernel.$raise($$$('ArgumentError'), "tried to call lazy select without a block")
11766        };
11767        return $send($$('Lazy'), 'new', [self, nil], function $$10(enum$, $a){var $post_args, args;
11768
11769          
11770          if (enum$ == null) enum$ = nil;
11771          $post_args = $slice(arguments, 1);
11772          args = $post_args;
11773          
11774          var value = $yieldX(block, args);
11775
11776          if ($truthy(value)) {
11777            $send(enum$, 'yield', $to_a(args));
11778          }
11779        ;}, -2);
11780      });
11781      
11782      $def(self, '$grep', function $$grep(pattern) {
11783        var block = $$grep.$$p || nil, self = this;
11784
11785        $$grep.$$p = null;
11786        
11787        ;
11788        if ($truthy(block)) {
11789          return $send($$('Lazy'), 'new', [self, nil], function $$11(enum$, $a){var $post_args, args;
11790
11791            
11792            if (enum$ == null) enum$ = nil;
11793            $post_args = $slice(arguments, 1);
11794            args = $post_args;
11795            
11796            var param = $Opal.$destructure(args),
11797                value = pattern['$==='](param);
11798
11799            if ($truthy(value)) {
11800              value = $yield1(block, param);
11801
11802              enum$.$yield($yield1(block, param));
11803            }
11804          ;}, -2)
11805        } else {
11806          return $send($$('Lazy'), 'new', [self, nil], function $$12(enum$, $a){var $post_args, args;
11807
11808            
11809            if (enum$ == null) enum$ = nil;
11810            $post_args = $slice(arguments, 1);
11811            args = $post_args;
11812            
11813            var param = $Opal.$destructure(args),
11814                value = pattern['$==='](param);
11815
11816            if ($truthy(value)) {
11817              enum$.$yield(param);
11818            }
11819          ;}, -2)
11820        };
11821      });
11822      
11823      $def(self, '$reject', function $$reject() {
11824        var block = $$reject.$$p || nil, self = this;
11825
11826        $$reject.$$p = null;
11827        
11828        ;
11829        if (!$truthy(block)) {
11830          $Kernel.$raise($$$('ArgumentError'), "tried to call lazy reject without a block")
11831        };
11832        return $send($$('Lazy'), 'new', [self, nil], function $$13(enum$, $a){var $post_args, args;
11833
11834          
11835          if (enum$ == null) enum$ = nil;
11836          $post_args = $slice(arguments, 1);
11837          args = $post_args;
11838          
11839          var value = $yieldX(block, args);
11840
11841          if (!$truthy(value)) {
11842            $send(enum$, 'yield', $to_a(args));
11843          }
11844        ;}, -2);
11845      });
11846      
11847      $def(self, '$take', function $$take(n) {
11848        var self = this, current_size = nil, set_size = nil, taken = nil;
11849
11850        
11851        n = $coerce_to(n, $$$('Integer'), 'to_int');
11852        if ($truthy($rb_lt(n, 0))) {
11853          $Kernel.$raise($$$('ArgumentError'), "attempt to take negative size")
11854        };
11855        current_size = self.$enumerator_size();
11856        set_size = ($eqeqeq($$$('Integer'), current_size) ? (($truthy($rb_lt(n, current_size)) ? (n) : (current_size))) : (current_size));
11857        taken = 0;
11858        return $send($$('Lazy'), 'new', [self, set_size], function $$14(enum$, $a){var $post_args, args;
11859
11860          
11861          if (enum$ == null) enum$ = nil;
11862          $post_args = $slice(arguments, 1);
11863          args = $post_args;
11864          if ($truthy($rb_lt(taken, n))) {
11865            
11866            $send(enum$, 'yield', $to_a(args));
11867            return (taken = $rb_plus(taken, 1));
11868          } else {
11869            return $Kernel.$raise($$('StopLazyError'))
11870          };}, -2);
11871      });
11872      
11873      $def(self, '$take_while', function $$take_while() {
11874        var block = $$take_while.$$p || nil, self = this;
11875
11876        $$take_while.$$p = null;
11877        
11878        ;
11879        if (!$truthy(block)) {
11880          $Kernel.$raise($$$('ArgumentError'), "tried to call lazy take_while without a block")
11881        };
11882        return $send($$('Lazy'), 'new', [self, nil], function $$15(enum$, $a){var $post_args, args;
11883
11884          
11885          if (enum$ == null) enum$ = nil;
11886          $post_args = $slice(arguments, 1);
11887          args = $post_args;
11888          
11889          var value = $yieldX(block, args);
11890
11891          if ($truthy(value)) {
11892            $send(enum$, 'yield', $to_a(args));
11893          }
11894          else {
11895            $Kernel.$raise($$('StopLazyError'));
11896          }
11897        ;}, -2);
11898      });
11899      
11900      $def(self, '$inspect', function $$inspect() {
11901        var self = this;
11902
11903        return "#<" + (self.$class()) + ": " + (self.enumerator.$inspect()) + ">"
11904      });
11905      $alias(self, "force", "to_a");
11906      $alias(self, "filter", "find_all");
11907      $alias(self, "flat_map", "collect_concat");
11908      $alias(self, "map", "collect");
11909      $alias(self, "select", "find_all");
11910      return $alias(self, "to_enum", "enum_for");
11911    })(self, self, $nesting)
11912  })('::', null, $nesting)
11913};
11914
11915Opal.modules["corelib/enumerator/yielder"] = function(Opal) {/* Generated by Opal 1.7.3 */
11916  var $klass = Opal.klass, $def = Opal.def, $slice = Opal.slice, $send = Opal.send, $to_a = Opal.to_a, $nesting = [], nil = Opal.nil;
11917
11918  Opal.add_stubs('yield,proc');
11919  return (function($base, $super, $parent_nesting) {
11920    var self = $klass($base, $super, 'Enumerator');
11921
11922    var $nesting = [self].concat($parent_nesting);
11923
11924    return (function($base, $super) {
11925      var self = $klass($base, $super, 'Yielder');
11926
11927      var $proto = self.$$prototype;
11928
11929      $proto.block = nil;
11930      
11931      
11932      $def(self, '$initialize', function $$initialize() {
11933        var block = $$initialize.$$p || nil, self = this;
11934
11935        $$initialize.$$p = null;
11936        
11937        ;
11938        self.block = block;
11939        return self;
11940      });
11941      
11942      $def(self, '$yield', function $Yielder_yield$1($a) {
11943        var $post_args, values, self = this;
11944
11945        
11946        $post_args = $slice(arguments);
11947        values = $post_args;
11948        
11949        var value = Opal.yieldX(self.block, values);
11950
11951        if (value && value.$thrower_type == "break") {
11952          throw value;
11953        }
11954
11955        return value;
11956      ;
11957      }, -1);
11958      
11959      $def(self, '$<<', function $Yielder_$lt$lt$2(value) {
11960        var self = this;
11961
11962        
11963        self.$yield(value);
11964        return self;
11965      });
11966      return $def(self, '$to_proc', function $$to_proc() {
11967        var self = this;
11968
11969        return $send(self, 'proc', [], function $$3($a){var $post_args, values, self = $$3.$$s == null ? this : $$3.$$s;
11970
11971          
11972          $post_args = $slice(arguments);
11973          values = $post_args;
11974          return $send(self, 'yield', $to_a(values));}, {$$arity: -1, $$s: self})
11975      });
11976    })($nesting[0], null)
11977  })($nesting[0], null, $nesting)
11978};
11979
11980Opal.modules["corelib/enumerator"] = function(Opal) {/* Generated by Opal 1.7.3 */
11981  var $slice = Opal.slice, $coerce_to = Opal.coerce_to, $deny_frozen_access = Opal.deny_frozen_access, $klass = Opal.klass, $def
11981s = Opal.defs, $truthy = Opal.truthy, $send = Opal.send, $not = Opal.not, $def = Opal.def, $rb_plus = Opal.rb_plus, $to_a = Opal.to_a, $Opal = Opal.Opal, $send2 = Opal.send2, $find_super = Opal.find_super, $rb_ge = Opal.rb_ge, $Kernel = Opal.Kernel, $rb_le = Opal.rb_le, $alias = Opal.alias, self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$;
11982
11983  Opal.add_stubs('require,include,allocate,new,to_proc,!,respond_to?,empty?,nil?,+,class,__send__,call,enum_for,size,destructure,map,>=,length,raise,[],peek_values,<=,next_values,inspect,any?,each_with_object,autoload');
11984  
11985  self.$require("corelib/enumerable");
11986  return (function($base, $super, $parent_nesting) {
11987    var self = $klass($base, $super, 'Enumerator');
11988
11989    var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype;
11990
11991    $proto.size = $proto.args = $proto.object = $proto.method = $proto.values = $proto.cursor = nil;
11992    
11993    self.$include($$$('Enumerable'));
11994    self.$$prototype.$$is_enumerator = true;
11995    $defs(self, '$for', function $Enumerator_for$1(object, $a, $b) {
11996      var block = $Enumerator_for$1.$$p || nil, $post_args, method, args, self = this;
11997
11998      $Enumerator_for$1.$$p = null;
11999      
12000      ;
12001      $post_args = $slice(arguments, 1);
12002      
12003      if ($post_args.length > 0) method = $post_args.shift();if (method == null) method = "each";
12004      args = $post_args;
12005      
12006      var obj = self.$allocate();
12007
12008      obj.object = object;
12009      obj.size   = block;
12010      obj.method = method;
12011      obj.args   = args;
12012      obj.cursor = 0;
12013
12014      return obj;
12015    ;
12016    }, -2);
12017    
12018    $def(self, '$initialize', function $$initialize($a) {
12019      var block = $$initialize.$$p || nil, $post_args, $fwd_rest, self = this;
12020
12021      $$initialize.$$p = null;
12022      
12023      ;
12024      $post_args = $slice(arguments);
12025      $fwd_rest = $post_args;
12026      $deny_frozen_access(self);
12027      self.cursor = 0;
12028      if ($truthy(block)) {
12029        
12030        self.object = $send($$('Generator'), 'new', [], block.$to_proc());
12031        self.method = "each";
12032        self.args = [];
12033        self.size = arguments[0] || nil;
12034        if (($truthy(self.size) && ($not(self.size['$respond_to?']("call"))))) {
12035          return (self.size = $coerce_to(self.size, $$$('Integer'), 'to_int'))
12036        } else {
12037          return nil
12038        };
12039      } else {
12040        
12041        self.object = arguments[0];
12042        self.method = arguments[1] || "each";
12043        self.args = $slice(arguments, 2);
12044        return (self.size = nil);
12045      };
12046    }, -1);
12047    
12048    $def(self, '$each', function $$each($a) {
12049      var block = $$each.$$p || nil, $post_args, args, self = this;
12050
12051      $$each.$$p = null;
12052      
12053      ;
12054      $post_args = $slice(arguments);
12055      args = $post_args;
12056      if (($truthy(block['$nil?']()) && ($truthy(args['$empty?']())))) {
12057        return self
12058      };
12059      args = $rb_plus(self.args, args);
12060      if ($truthy(block['$nil?']())) {
12061        return $send(self.$class(), 'new', [self.object, self.method].concat($to_a(args)))
12062      };
12063      return $send(self.object, '__send__', [self.method].concat($to_a(args)), block.$to_proc());
12064    }, -1);
12065    
12066    $def(self, '$size', function $$size() {
12067      var self = this;
12068
12069      if ($truthy(self.size['$respond_to?']("call"))) {
12070        return $send(self.size, 'call', $to_a(self.args))
12071      } else {
12072        return self.size
12073      }
12074    });
12075    
12076    $def(self, '$with_index', function $$with_index(offset) {
12077      var block = $$with_index.$$p || nil, self = this;
12078
12079      $$with_index.$$p = null;
12080      
12081      ;
12082      if (offset == null) offset = 0;
12083      offset = ($truthy(offset) ? ($coerce_to(offset, $$$('Integer'), 'to_int')) : (0));
12084      if (!$truthy(block)) {
12085        return $send(self, 'enum_for', ["with_index", offset], function $$2(){var self = $$2.$$s == null ? this : $$2.$$s;
12086
12087          return self.$size()}, {$$s: self})
12088      };
12089      
12090      var result, index = offset;
12091
12092      self.$each.$$p = function() {
12093        var param = $Opal.$destructure(arguments),
12094            value = block(param, index);
12095
12096        index++;
12097
12098        return value;
12099      }
12100
12101      return self.$each();
12102    ;
12103    }, -1);
12104    
12105    $def(self, '$each_with_index', function $$each_with_index() {
12106      var block = $$each_with_index.$$p || nil, self = this;
12107
12108      $$each_with_index.$$p = null;
12109      
12110      ;
12111      if (!(block !== nil)) {
12112        return $send(self, 'enum_for', ["each_with_index"], function $$3(){var self = $$3.$$s == null ? this : $$3.$$s;
12113
12114          return self.$size()}, {$$s: self})
12115      };
12116      $send2(self, $find_super(self, 'each_with_index', $$each_with_index, false, true), 'each_with_index', [], block);
12117      return self.object;
12118    });
12119    
12120    $def(self, '$rewind', function $$rewind() {
12121      var self = this;
12122
12123      
12124      self.cursor = 0;
12125      return self;
12126    });
12127    
12128    $def(self, '$peek_values', function $$peek_values() {
12129      var self = this, $ret_or_1 = nil;
12130
12131      
12132      self.values = ($truthy(($ret_or_1 = self.values)) ? ($ret_or_1) : ($send(self, 'map', [], function $$4($a){var $post_args, i;
12133
12134        
12135        $post_args = $slice(arguments);
12136        i = $post_args;
12137        return i;}, -1)));
12138      if ($truthy($rb_ge(self.cursor, self.values.$length()))) {
12139        $Kernel.$raise($$$('StopIteration'), "iteration reached an end")
12140      };
12141      return self.values['$[]'](self.cursor);
12142    });
12143    
12144    $def(self, '$peek', function $$peek() {
12145      var self = this, values = nil;
12146
12147      
12148      values = self.$peek_values();
12149      if ($truthy($rb_le(values.$length(), 1))) {
12150        return values['$[]'](0)
12151      } else {
12152        return values
12153      };
12154    });
12155    
12156    $def(self, '$next_values', function $$next_values() {
12157      var self = this, out = nil;
12158
12159      
12160      out = self.$peek_values();
12161      self.cursor = $rb_plus(self.cursor, 1);
12162      return out;
12163    });
12164    
12165    $def(self, '$next', function $$next() {
12166      var self = this, values = nil;
12167
12168      
12169      values = self.$next_values();
12170      if ($truthy($rb_le(values.$length(), 1))) {
12171        return values['$[]'](0)
12172      } else {
12173        return values
12174      };
12175    });
12176    
12177    $def(self, '$feed', function $$feed(arg) {
12178      var self = this;
12179
12180      return self.$raise($$('NotImplementedError'), "Opal doesn't support Enumerator#feed")
12181    });
12182    
12183    $def(self, '$+', function $Enumerator_$plus$5(other) {
12184      var self = this;
12185
12186      return $$$($$$('Enumerator'), 'Chain').$new(self, other)
12187    });
12188    
12189    $def(self, '$inspect', function $$inspect() {
12190      var self = this, result = nil;
12191
12192      
12193      result = "#<" + (self.$class()) + ": " + (self.object.$inspect()) + ":" + (self.method);
12194      if ($truthy(self.args['$any?']())) {
12195        result = $rb_plus(result, "(" + (self.args.$inspect()['$[]']($$$('Range').$new(1, -2))) + ")")
12196      };
12197      return $rb_plus(result, ">");
12198    });
12199    $alias(self, "with_object", "each_with_object");
12200    self.$autoload("ArithmeticSequence", "corelib/enumerator/arithmetic_sequence");
12201    self.$autoload("Chain", "corelib/enumerator/chain");
12202    self.$autoload("Generator", "corelib/enumerator/generator");
12203    self.$autoload("Lazy", "corelib/enumerator/lazy");
12204    return self.$autoload("Yielder", "corelib/enumerator/yielder");
12205  })('::', null, $nesting);
12206};
12207
12208Opal.modules["corelib/numeric"] = function(Opal) {/* Generated by Opal 1.7.3 */
12209  var $klass = Opal.klass, $truthy = Opal.truthy, $Kernel = Opal.Kernel, $def = Opal.def, $to_ary = Opal.to_ary, $return_self = Opal.return_self, $rb_minus = Opal.rb_minus, $rb_times = Opal.rb_times, $rb_lt = Opal.rb_lt, $eqeq = Opal.eqeq, $rb_divide = Opal.rb_divide, $return_val = Opal.return_val, $Opal = Opal.Opal, $slice = Opal.slice, $extract_kwargs = Opal.extract_kwargs, $ensure_kwargs = Opal.ensure_kwargs, $not = Opal.not, $send = Opal.send, $rb_ge = Opal.rb_ge, $rb_le = Opal.rb_le, $rb_plus = Opal.rb_plus, $rb_gt = Opal.rb_gt, $alias = Opal.alias, self = Opal.top, nil = Opal.nil, $$$ = Opal.$$$;
12210
12211  Opal.add_stubs('require,include,instance_of?,class,Float,respond_to?,coerce,__send__,raise,equal?,-,*,div,<,-@,ceil,to_f,denominator,to_r,==,floor,/,%,Complex,zero?,numerator,abs,arg,coerce_to!,round,<=>,compare,is_a?,!,new,enum_for,to_proc,negative?,>=,<=,+,to_i,truncate,>
12211,angle,conj,imag,rect');
12212  
12213  self.$require("corelib/comparable");
12214  return (function($base, $super) {
12215    var self = $klass($base, $super, 'Numeric');
12216
12217    
12218    
12219    self.$include($$$('Comparable'));
12220    
12221    $def(self, '$coerce', function $$coerce(other) {
12222      var self = this;
12223
12224      
12225      if ($truthy(other['$instance_of?'](self.$class()))) {
12226        return [other, self]
12227      };
12228      return [$Kernel.$Float(other), $Kernel.$Float(self)];
12229    });
12230    
12231    $def(self, '$__coerced__', function $$__coerced__(method, other) {
12232      var $a, $b, self = this, a = nil, b = nil;
12233
12234      if ($truthy(other['$respond_to?']("coerce"))) {
12235        
12236        $b = other.$coerce(self), $a = $to_ary($b), (a = ($a[0] == null ? nil : $a[0])), (b = ($a[1] == null ? nil : $a[1])), $b;
12237        return a.$__send__(method, b);
12238      } else 
12239      switch (method) {
12240        case "+":
12241        case "-":
12242        case "*":
12243        case "/":
12244        case "%":
12245        case "&":
12246        case "|":
12247        case "^":
12248        case "**":
12249          return $Kernel.$raise($$$('TypeError'), "" + (other.$class()) + " can't be coerced into Numeric")
12250        case ">":
12251        case ">=":
12252        case "<":
12253        case "<=":
12254        case "<=>":
12255          return $Kernel.$raise($$$('ArgumentError'), "comparison of " + (self.$class()) + " with " + (other.$class()) + " failed")
12256        default:
12257          return nil
12258      }
12259    });
12260    
12261    $def(self, '$<=>', function $Numeric_$lt_eq_gt$1(other) {
12262      var self = this;
12263
12264      
12265      if ($truthy(self['$equal?'](other))) {
12266        return 0
12267      };
12268      return nil;
12269    });
12270    
12271    $def(self, '$+@', $return_self);
12272    
12273    $def(self, '$-@', function $Numeric_$minus$$2() {
12274      var self = this;
12275
12276      return $rb_minus(0, self)
12277    });
12278    
12279    $def(self, '$%', function $Numeric_$percent$3(other) {
12280      var self = this;
12281
12282      return $rb_minus(self, $rb_times(other, self.$div(other)))
12283    });
12284    
12285    $def(self, '$abs', function $$abs() {
12286      var self = this;
12287
12288      if ($rb_lt(self, 0)) {
12289        return self['$-@']()
12290      } else {
12291        return self
12292      }
12293    });
12294    
12295    $def(self, '$abs2', function $$abs2() {
12296      var self = this;
12297
12298      return $rb_times(self, self)
12299    });
12300    
12301    $def(self, '$angle', function $$angle() {
12302      var self = this;
12303
12304      if ($rb_lt(self, 0)) {
12305        return $$$($$$('Math'), 'PI')
12306      } else {
12307        return 0
12308      }
12309    });
12310    
12311    $def(self, '$ceil', function $$ceil(ndigits) {
12312      var self = this;
12313
12314      
12315      if (ndigits == null) ndigits = 0;
12316      return self.$to_f().$ceil(ndigits);
12317    }, -1);
12318    
12319    $def(self, '$conj', $return_self);
12320    
12321    $def(self, '$denominator', function $$denominator() {
12322      var self = this;
12323
12324      return self.$to_r().$denominator()
12325    });
12326    
12327    $def(self, '$div', function $$div(other) {
12328      var self = this;
12329
12330      
12331      if ($eqeq(other, 0)) {
12332        $Kernel.$raise($$$('ZeroDivisionError'), "divided by o")
12333      };
12334      return $rb_divide(self, other).$floor();
12335    });
12336    
12337    $def(self, '$divmod', function $$divmod(other) {
12338      var self = this;
12339
12340      return [self.$div(other), self['$%'](other)]
12341    });
12342    
12343    $def(self, '$fdiv', function $$fdiv(other) {
12344      var self = this;
12345
12346      return $rb_divide(self.$to_f(), other)
12347    });
12348    
12349    $def(self, '$floor', function $$floor(ndigits) {
12350      var self = this;
12351
12352      
12353      if (ndigits == null) ndigits = 0;
12354      return self.$to_f().$floor(ndigits);
12355    }, -1);
12356    
12357    $def(self, '$i', function $$i() {
12358      var self = this;
12359
12360      return $Kernel.$Complex(0, self)
12361    });
12362    
12363    $def(self, '$imag', $return_val(0));
12364    
12365    $def(self, '$integer?', $return_val(false));
12366    
12367    $def(self, '$nonzero?', function $Numeric_nonzero$ques$4() {
12368      var self = this;
12369
12370      if ($truthy(self['$zero?']())) {
12371        return nil
12372      } else {
12373        return self
12374      }
12375    });
12376    
12377    $def(self, '$numerator', function $$numerator() {
12378      var self = this;
12379
12380      return self.$to_r().$numerator()
12381    });
12382    
12383    $def(self, '$polar', function $$polar() {
12384      var self = this;
12385
12386      return [self.$abs(), self.$arg()]
12387    });
12388    
12389    $def(self, '$quo', function $$quo(other) {
12390      var self = this;
12391
12392      return $rb_divide($Opal['$coerce_to!'](self, $$$('Rational'), "to_r"), other)
12393    });
12394    
12395    $def(self, '$real', $return_self);
12396    
12397    $def(self, '$real?', $return_val(true));
12398    
12399    $def(self, '$rect', function $$rect() {
12400      var self = this;
12401
12402      return [self, 0]
12403    });
12404    
12405    $def(self, '$round', function $$round(digits) {
12406      var self = this;
12407
12408      
12409      ;
12410      return self.$to_f().$round(digits);
12411    }, -1);
12412    
12413    $def(self, '$step', function $$step($a, $b, $c) {
12414      var block = $$step.$$p || nil, $post_args, $kwargs, limit, step, to, by, self = this, c
12414ounter = nil;
12415
12416      $$step.$$p = null;
12417      
12418      ;
12419      $post_args = $slice(arguments);
12420      $kwargs = $extract_kwargs($post_args);
12421      $kwargs = $ensure_kwargs($kwargs);
12422      
12423      if ($post_args.length > 0) limit = $post_args.shift();;
12424      
12425      if ($post_args.length > 0) step = $post_args.shift();;
12426      
12427      to = $kwargs.$$smap["to"];;
12428      
12429      by = $kwargs.$$smap["by"];;
12430      
12431      if (limit !== undefined && to !== undefined) {
12432        $Kernel.$raise($$$('ArgumentError'), "to is given twice")
12433      }
12434
12435      if (step !== undefined && by !== undefined) {
12436        $Kernel.$raise($$$('ArgumentError'), "step is given twice")
12437      }
12438
12439      if (to !== undefined) {
12440        limit = to;
12441      }
12442
12443      if (by !== undefined) {
12444        step = by;
12445      }
12446
12447      if (limit === undefined) {
12448        limit = nil;
12449      }
12450
12451      function validateParameters() {
12452        if (step === nil) {
12453          $Kernel.$raise($$$('TypeError'), "step must be numeric")
12454        }
12455
12456        if (step != null && step['$=='](0)) {
12457          $Kernel.$raise($$$('ArgumentError'), "step can't be 0")
12458        }
12459
12460        if (step === nil || step == null) {
12461          step = 1;
12462        }
12463
12464        var sign = step['$<=>'](0);
12465
12466        if (sign === nil) {
12467          $Kernel.$raise($$$('ArgumentError'), "0 can't be coerced into " + (step.$class()))
12468        }
12469
12470        if (limit === nil || limit == null) {
12471          limit = sign > 0 ? $$$($$$('Float'), 'INFINITY') : $$$($$$('Float'), 'INFINITY')['$-@']();
12472        }
12473
12474        $Opal.$compare(self, limit)
12475      }
12476
12477      function stepFloatSize() {
12478        if ((step > 0 && self > limit) || (step < 0 && self < limit)) {
12479          return 0;
12480        } else if (step === Infinity || step === -Infinity) {
12481          return 1;
12482        } else {
12483          var abs = Math.abs, floor = Math.floor,
12484              err = (abs(self) + abs(limit) + abs(limit - self)) / abs(step) * $$$($$$('Float'), 'EPSILON');
12485
12486          if (err === Infinity || err === -Infinity) {
12487            return 0;
12488          } else {
12489            if (err > 0.5) {
12490              err = 0.5;
12491            }
12492
12493            return floor((limit - self) / step + err) + 1
12494          }
12495        }
12496      }
12497
12498      function stepSize() {
12499        validateParameters();
12500
12501        if (step === 0) {
12502          return Infinity;
12503        }
12504
12505        if (step % 1 !== 0) {
12506          return stepFloatSize();
12507        } else if ((step > 0 && self > limit) || (step < 0 && self < limit)) {
12508          return 0;
12509        } else {
12510          var ceil = Math.ceil, abs = Math.abs,
12511              lhs = abs(self - limit) + 1,
12512              rhs = abs(step);
12513
12514          return ceil(lhs / rhs);
12515        }
12516      }
12517
12518    ;
12519      if (!(block !== nil)) {
12520        if ((($not(limit) || ($truthy(limit['$is_a?']($$$('Numeric'))))) && (($not(step) || ($truthy(step['$is_a?']($$$('Numeric')))))))) {
12521          return $$$($$$('Enumerator'), 'ArithmeticSequence').$new([limit, step, ($truthy(to) ? ("to: ") : nil), ($truthy(by) ? ("by: ") : nil)], self)
12522        } else {
12523          return $send(self, 'enum_for', ["step", limit, step], (stepSize).$to_proc())
12524        }
12525      };
12526      
12527      validateParameters();
12528
12529      var isDesc = step['$negative?'](),
12530          isInf = step['$=='](0) ||
12531                  (limit === Infinity && !isDesc) ||
12532                  (limit === -Infinity && isDesc);
12533
12534      if (self.$$is_number && step.$$is_number && limit.$$is_number) {
12535        if (self % 1 === 0 && (isInf || limit % 1 === 0) && step % 1 === 0) {
12536          var value = self;
12537
12538          if (isInf) {
12539            for (;; value += step) {
12540              block(value);
12541            }
12542          } else if (isDesc) {
12543            for (; value >= limit; value += step) {
12544              block(value);
12545            }
12546          } else {
12547            for (; value <= limit; value += step) {
12548              block(value);
12549            }
12550          }
12551
12552          return self;
12553        } else {
12554          var begin = self.$to_f().valueOf();
12555          step = step.$to_f().valueOf();
12556          limit = limit.$to_f().valueOf();
12557
12558          var n = stepFloatSize();
12559
12560          if (!isFinite(step)) {
12561            if (n !== 0) block(begin);
12562          } else if (step === 0) {
12563            while (true) {
12564              block(begin);
12565            }
12566          } else {
12567            for (var i = 0; i < n; i++) {
12568              var d = i * step + self;
12569              if (step >= 0 ? limit < d : limit > d) {
12570                d = limit;
12571              }
12572              block(d);
12573            }
12574          }
12575
12576          return self;
12577        }
12578      }
12579    ;
12580      counter = self;
12581      while ($truthy(isDesc ? $rb_ge(counter, limit) : $rb_le(counter, limit))) {
12582      
12583        Opal.yield1(block, counter);
12584        counter = $rb_plus(counter, step);
12585      };
12586    }, -1);
12587    
12588    $def(self, '$to_c', function $$to_c() {
12589      var self = this;
12590
12591      return $Kernel.$Complex(self, 0)
12592    });
12593    
12594    $def(self, '$to_int', function $$to_int() {
12595      var self = this;
12596
12597      return self.$to_i()
12598    });
12599    
12600    $def(self, '$truncate', function $$truncate(ndigits) {
12601      var self = this;
12602
12603      
12604      if (ndigits == null) ndigits = 0;
12605      return self.$to_f().$truncate(ndigits);
12606    }, -1);
12607    
12608    $def(self, '$zero?', function $Numeric_zero$ques$5() {
12609      var self = this;
12610
12611      return self['$=='](0)
12612    });
12613    
12614    $def(self, '$positive?', function $Numeric_positive$ques$6() {
12615      var self = this;
12616
12617      return $rb_gt(self, 0)
12618    });
12619    
12620    $def(self, '$negative?', function $Numeric_negative$ques$7() {
12621      var self = this;
12622
12623      return $rb_lt(self, 0)
12624    });
12625    
12626    $def(self, '$dup', $return_self);
12627    
12628    $def(self, '$clone', function $$clone($kwargs) {
12629      var freeze, self = this;
12630
12631      
12632      $kwargs = $ensure_kwargs($kwargs);
12633      
12634      freeze = $kwargs.$$smap["freeze"];if (freeze == null) freeze = true;
12635      return self;
12636    }, -1);
12637    
12638    $def(self, '$finite?', $return_val(true));
12639    
12640    $def(self, '$infinite?', $return_val(nil));
12641    $alias(self, "arg", "angle");
12642    $alias(self, "conjugate", "conj");
12643    $alias(self, "imaginary", "imag");
12644    $alias(self, "magnitude", "abs");
12645    $alias(self, "modulo", "%");
12646    $alias(self, "phase", "arg");
12647    return $alias(self, "rectangular", "rect");
12648  })('::', null);
12649};
12650
12651Opal.modules["corelib/array"] = function(Opal) {/* Generated by Opal 1.7.3 */
12652  var $truthy = Opal.truthy, $falsy = Opal.falsy, $hash_ids = Opal.hash_ids, $yield1 = Opal.yield1, $hash_get = Opal.hash_get, $hash_put = Opal.hash_put, $hash_delete = Opal.hash_delete, $coerce_to = Opal.coerce_to, $respond_to = Opal.respond_to, $deny_frozen_access = Opal.deny_frozen_access, $freeze = Opal.freeze, $klass = Opal.klass, $slice = Opal.slice, $defs = Opal.defs, $Kernel = Opal.Kernel, $def = Opal.def, $Opal = Opal.Opal, $eqeqeq = Opal.eqeqeq, $hash2 = Opal.hash2, $send2 = Opal.send2, $find_super = Opal.find_super, $send = Opal.send, $rb_gt = Opal.rb_gt, $rb_times = Opal.rb_times, $eqeq = Opal.eqeq, $rb_minus = Opal.rb_minus, $to_a = Opal.to_a, $to_ary = Opal.to_ary, $gvars = Opal.gvars, $rb_ge = Opal.rb_ge, $assign_ivar = Opal.assign_ivar, $rb_lt = Opal.rb_lt, $return_self = Opal.return_self, $neqeq = Opal.neqeq, $alias = Opal.alias, self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$;
12653
12654  Opal.add_stubs('require,include,to_a,warn,raise,replace,respond_to?,to_ary,coerce_to?,===,join,to_str,hash,<=>,==,object_id,inspect,enum_for,class,bsearch_index,to_proc,nil?,coerce_to!,>,*,enumerator_size,empty?,size,map,equal?,dup,each,reduce,-,[],dig,eql?,length,exclude_end?,flatten,frozen?,__id__,&,!,intersection,to_s,new,item,max,min,>=,**,delete_if,reverse,rotate,rand,at,keep_if,shuffle!,<,sort,sort_by,!=,times,[]=,<<,uniq,|,values,is_a?,end,begin,upto,reject,push,select,select!,collect,collect!,unshift,pristine,singleton_class');
12655  
12656  self.$require("corelib/enumerable");
12657  self.$require("corelib/numeric");
12658  return (function($base, $super, $parent_nesting) {
12659    var self = $klass($base, $super, 'Array');
12660
12661    var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
12662
12663    
12664    self.$include($$$('Enumerable'));
12665    Opal.prop(self.$$prototype, '$$is_array', true);
12666    
12667    // Recent versions of V8 (> 7.1) only use an optimized implementation when Array.prototype is unmodified.
12668    // For instance, "array-splice.tq" has a "fast path" (ExtractFastJSArray, defined in "src/codegen/code-stub-assembler.cc")
12669    // but it's only enabled when "IsPrototypeInitialArrayPrototype()" is true.
12670    //
12671    // Older versions of V8 were using relatively fast JS-with-extensions code even when Array.prototype is modified:
12672    // https://github.com/v8/v8/blob/7.0.1/src/js/array.js#L599-L642
12673    //
12674    // In short, Array operations are slow in recent versions of V8 when the Array.prototype has been tampered.
12675    // So, when possible, we are using faster open-coded version to boost the performance.
12676
12677    // As of V8 8.4, depending on the size of the array, this is up to ~25x times faster than Array#shift()
12678    // Implementation is heavily inspired by: https://github.com/nodejs/node/blob/ba684805b6c0eded76e5cd89ee00328ac7a59365/lib/internal/util.js#L341-L347
12679    function shiftNoArg(list) {
12680      var r = list[0];
12681      var index = 1;
12682      var length = list.length;
12683      for (; index < length; index++) {
12684        list[index - 1] = list[index];
12685      }
12686      list.pop();
12687      return r;
12688    }
12689
12690    function toArraySubclass(obj, klass) {
12691      if (klass.$$name === Opal.Array) {
12692        return obj;
12693      } else {
12694        return klass.$allocate().$replace((obj).$to_a());
12695      }
12696    }
12697
12698    // A helper for keep_if and delete_if, filter is either Opal.truthy
12699    // or Opal.falsy.
12700    function filterIf(self, filter, block) {
12701      var value, raised = null, updated = new Array(self.length);
12702
12703      for (var i = 0, i2 = 0, length = self.length; i < length; i++) {
12704        if (!raised) {
12705          try {
12706            value = $yield1(block, self[i])
12707          } catch(error) {
12708            raised = error;
12709          }
12710        }
12711
12712        if (raised || filter(value)) {
12713          updated[i2] = self[i]
12714          i2 += 1;
12715        }
12716      }
12717
12718      if (i2 !== i) {
12719        self.splice.apply(self, [0, updated.length].concat(updated));
12720        self.splice(i2, updated.length);
12721      }
12722
12723      if (raised) throw raised;
12724    }
12725  ;
12726    $defs(self, '$[]', function $Array_$$$1($a) {
12727      var $post_args, objects, self = this;
12728
12729      
12730      $post_args = $slice(arguments);
12731      objects = $post_args;
12732      return toArraySubclass(objects, self);;
12733    }, -1);
12734    
12735    $def(self, '$initialize', function $$initialize(size, obj) {
12736      var block = $$initialize.$$p || nil, self = this;
12737
12738      $$initialize.$$p = null;
12739      
12740      ;
12741      if (size == null) size = nil;
12742      if (obj == null) obj = nil;
12743      
12744      $deny_frozen_access(self);
12745
12746      if (obj !== nil && block !== nil) {
12747        $Kernel.$warn("warning: block supersedes default value argument")
12748      }
12749
12750      if (size > $$$($$$('Integer'), 'MAX')) {
12751        $Kernel.$raise($$$('ArgumentError'), "array size too big")
12752      }
12753
12754      if (arguments.length > 2) {
12755        $Kernel.$raise($$$('ArgumentError'), "wrong number of arguments (" + (arguments.length) + " for 0..2)")
12756      }
12757
12758      if (arguments.length === 0) {
12759        self.splice(0, self.length);
12760        return self;
12761      }
12762
12763      if (arguments.length === 1) {
12764        if (size.$$is_array) {
12765          self.$replace(size.$to_a())
12766          return self;
12767        } else if (size['$respond_to?']("to_ary")) {
12768          self.$replace(size.$to_ary())
12769          return self;
12770        }
12771      }
12772
12773      size = $coerce_to(size, $$$('Integer'), 'to_int');
12774
12775      if (size < 0) {
12776        $Kernel.$raise($$$('ArgumentError'), "negative array size")
12777      }
12778
12779      self.splice(0, self.length);
12780      var i, value;
12781
12782      if (block === nil) {
12783        for (i = 0; i < size; i++) {
12784          self.push(obj);
12785        }
12786      }
12787      else {
12788        for (i = 0, value; i < size; i++) {
12789          value = block(i);
12790          self[i] = value;
12791        }
12792      }
12793
12794      return self;
12795    ;
12796    }, -1);
12797    $defs(self, '$try_convert', function $$try_convert(obj) {
12798      
12799      return $Opal['$coerce_to?'](obj, $$$('Array'), "to_ary")
12800    });
12801    
12802    $def(self, '$&', function $Array_$$2(other) {
12803      var self = this;
12804
12805      
12806      other = ($eqeqeq($$$('Array'), other) ? (other.$to_a()) : (($coerce_to(other, $$$('Array'), 'to_ary')).$to_a()));
12807      
12808      var result = [], hash = $hash2([], {}), i, length, item;
12809
12810      for (i = 0, length = other.length; i < length; i++) {
12811        $hash_put(hash, other[i], true);
12812      }
12813
12814      for (i = 0, length = self.length; i < length; i++) {
12815        item = self[i];
12816        if ($hash_delete(hash, item) !== undefined) {
12817          result.push(item);
12818        }
12819      }
12820
12821      return result;
12822    ;
12823    });
12824    
12825    $def(self, '$|', function $Array_$$3(other) {
12826      var self = this;
12827
12828      
12829      other = ($eqeqeq($$$('Array'), other) ? (other.$to_a()) : (($coerce_to(other, $$$('Array'), 'to_ary')).$to_a()));
12830      
12831      var hash = $hash2([], {}), i, length, item;
12832
12833      for (i = 0, length = self.length; i < length; i++) {
12834        $hash_put(hash, self[i], true);
12835      }
12836
12837      for (i = 0, length = other.length; i < length; i++) {
12838        $hash_put(hash, other[i], true);
12839      }
12840
12841      return hash.$keys();
12842    ;
12843    });
12844    
12845    $def(self, '$*', function $Array_$$4(other) {
12846      var self = this;
12847
12848      
12849      if ($truthy(other['$respond_to?']("to_str"))) {
12850        return self.$join(other.$to_str())
12851      };
12852      other = $coerce_to(other, $$$('Integer'), 'to_int');
12853      if ($truthy(other < 0)) {
12854        $Kernel.$raise($$$('ArgumentError'), "negative argument")
12855      };
12856      
12857      var result = [],
12858          converted = self.$to_a();
12859
12860      for (var i = 0; i < other; i++) {
12861        result = result.concat(converted);
12862      }
12863
12864      return result;
12865    ;
12866    });
12867    
12868    $def(self, '$+', function $Array_$plus$5(other) {
12869      var self = this;
12870
12871      
12872      other = ($eqeqeq($$$('Array'), other) ? (other.$to_a()) : (($coerce_to(other, $$$('Array'), 'to_ary')).$to_a()));
12873      return self.concat(other);;
12874    });
12875    
12876    $def(self, '$-', function $Array_$minus$6(other) {
12877      var self = this;
12878
12879      
12880      other = ($eqeqeq($$$('Array'), other) ? (other.$to_a()) : (($coerce_to(other, $$$('Array'), 'to_ary')).$to_a()));
12881      if ($truthy(self.length === 0)) {
12882        return []
12883      };
12884      if ($truthy(other.length === 0)) {
12885        return self.slice()
12886      };
12887      
12888      var result = [], hash = $hash2([], {}), i, length, item;
12889
12890      for (i = 0, length = other.length; i < length; i++) {
12891        $hash_put(hash, other[i], true);
12892      }
12893
12894      for (i = 0, length = self.length; i < length; i++) {
12895        item = self[i];
12896        if ($hash_get(hash, item) === undefined) {
12897          result.push(item);
12898        }
12899      }
12900
12901      return result;
12902    ;
12903    });
12904    
12905    $def(self, '$<<', function $Array_$lt$lt$7(object) {
12906      var self = this;
12907
12908      
12909      $deny_frozen_access(self);
12910      self.push(object);
12911      return self;
12912    });
12913    
12914    $def(self, '$<=>', function $Array_$lt_eq_gt$8(other) {
12915      var self = this;
12916
12917      
12918      if ($eqeqeq($$$('Array'), other)) {
12919        other = other.$to_a()
12920      } else if ($truthy(other['$respond_to?']("to_ary"))) {
12921        other = other.$to_ary().$to_a()
12922      } else {
12923        return nil
12924      };
12925      
12926      if (self.$hash() === other.$hash()) {
12927        return 0;
12928      }
12929
12930      var count = Math.min(self.length, other.length);
12931
12932      for (var i = 0; i < count; i++) {
12933        var tmp = (self[i])['$<=>'](other[i]);
12934
12935        if (tmp !== 0) {
12936          return tmp;
12937        }
12938      }
12939
12940      return (self.length)['$<=>'](other.length);
12941    ;
12942    });
12943    
12944    $def(self, '$==', function $Array_$eq_eq$9(other) {
12945      var self = this;
12946
12947      
12948      var recursed = {};
12949
12950      function _eqeq(array, other) {
12951        var i, length, a, b;
12952
12953        if (array === other)
12954          return true;
12955
12956        if (!other.$$is_array) {
12957          if ($respond_to(other, '$to_ary')) {
12958            return (other)['$=='](array);
12959          } else {
12960            return false;
12961          }
12962        }
12963
12964        if (array.$$constructor !== Array)
12965          array = (array).$to_a();
12966        if (other.$$constructor !== Array)
12967          other = (other).$to_a();
12968
12969        if (array.length !== other.length) {
12970          return false;
12971        }
12972
12973        recursed[(array).$object_id()] = true;
12974
12975        for (i = 0, length = array.length; i < length; i++) {
12976          a = array[i];
12977          b = other[i];
12978          if (a.$$is_array) {
12979            if (b.$$is_array && b.length !== a.length) {
12980              return false;
12981            }
12982            if (!recursed.hasOwnProperty((a).$object_id())) {
12983              if (!_eqeq(a, b)) {
12984                return false;
12985              }
12986            }
12987          } else {
12988            if (!(a)['$=='](b)) {
12989              return false;
12990            }
12991          }
12992        }
12993
12994        return true;
12995      }
12996
12997      return _eqeq(self, other);
12998    
12999    });
13000    
13001    function $array_slice_range(self, index) {
13002      var size = self.length,
13003          exclude, from, to, result;
13004
13005      exclude = index.excl;
13006      from    = index.begin === nil ? 0 : $coerce_to(index.begin, Opal.Integer, 'to_int');
13007      to      = index.end === nil ? -1 : $coerce_to(index.end, Opal.Integer, 'to_int');
13008
13009      if (from < 0) {
13010        from += size;
13011
13012        if (from < 0) {
13013          return nil;
13014        }
13015      }
13016
13017      if (index.excl_rev && index.begin !== nil) {
13018        from += 1;
13019      }
13020
13021      if (from > size) {
13022        return nil;
13023      }
13024
13025      if (to < 0) {
13026        to += size;
13027
13028        if (to < 0) {
13029          return [];
13030        }
13031      }
13032
13033      if (!exclude || index.end === nil) {
13034        to += 1;
13035      }
13036
13037      result = self.slice(from, to);
13038      return result;
13039    }
13040
13041    function $array_slice_arithmetic_seq(self, index) {
13042      var array, out = [], i = 0, pseudorange;
13043
13044      if (index.step < 0) {
13045        pseudorange = {
13046          begin: index.range.end,
13047          end: index.range.begin,
13048          excl: false,
13049          excl_rev: index.range.excl
13050        };
13051        array = $array_slice_range(self, pseudorange).$reverse();
13052      }
13053      else {
13054        array = $array_slice_range(self, index.range);
13055      }
13056
13057      while (i < array.length) {
13058        out.push(array[i]);
13059        i += Math.abs(index.step);
13060      }
13061
13062      return out;
13063    }
13064
13065    function $array_slice_index_length(self, index, length) {
13066      var size = self.length,
13067          exclude, from, to, result;
13068
13069      index = $coerce_to(index, Opal.Integer, 'to_int');
13070
13071      if (index < 0) {
13072        index += size;
13073
13074        if (index < 0) {
13075          return nil;
13076        }
13077      }
13078
13079      if (length === undefined) {
13080        if (index >= size || index < 0) {
13081          return nil;
13082        }
13083
13084        return self[index];
13085      }
13086      else {
13087        length = $coerce_to(length, Opal.Integer, 'to_int');
13088
13089        if (length < 0 || index > size || index < 0) {
13090          return nil;
13091        }
13092
13093        result = self.slice(index, index + length);
13094      }
13095      return result;
13096    }
13097  ;
13098    
13099    $def(self, '$[]', function $Array_$$$10(index, length) {
13100      var self = this;
13101
13102      
13103      ;
13104      
13105      if (index.$$is_range) {
13106        return $array_slice_range(self, index);
13107      }
13108      else if (index.$$is_arithmetic_seq) {
13109        return $array_slice_arithmetic_seq(self, index);
13110      }
13111      else {
13112        return $array_slice_index_length(self, index, length);
13113      }
13114    ;
13115    }, -2);
13116    
13117    $def(self, '$[]=', function $Array_$$$eq$11(index, value, extra) {
13118      var self = this, data = nil, length = nil;
13119
13120      
13121      ;
13122      $deny_frozen_access(self);
13123      data = nil;
13124      
13125      var i, size = self.length;
13126
13127      if (index.$$is_range) {
13128        if (value.$$is_array)
13129          data = value.$to_a();
13130        else if (value['$respond_to?']("to_ary"))
13131          data = value.$to_ary().$to_a();
13132        else
13133          data = [value];
13134
13135        var exclude = index.excl,
13136            from    = index.begin === nil ? 0 : $coerce_to(index.begin, Opal.Integer, 'to_int'),
13137            to      = index.end === nil ? -1 : $coerce_to(index.end, Opal.Integer, 'to_int');
13138
13139        if (from < 0) {
13140          from += size;
13141
13142          if (from < 0) {
13143            $Kernel.$raise($$$('RangeError'), "" + (index.$inspect()) + " out of range");
13144          }
13145        }
13146
13147        if (to < 0) {
13148          to += size;
13149        }
13150
13151        if (!exclude || index.end === nil) {
13152          to += 1;
13153        }
13154
13155        if (from > size) {
13156          for (i = size; i < from; i++) {
13157            self[i] = nil;
13158          }
13159        }
13160
13161        if (to < 0) {
13162          self.splice.apply(self, [from, 0].concat(data));
13163        }
13164        else {
13165          self.splice.apply(self, [from, to - from].concat(data));
13166        }
13167
13168        return value;
13169      } else {
13170        if (extra === undefined) {
13171          (length = 1)
13172        } else {
13173          length = value;
13174          value  = extra;
13175
13176          if (value.$$is_array)
13177            data = value.$to_a();
13178          else if (value['$respond_to?']("to_ary"))
13179            data = value.$to_ary().$to_a();
13180          else
13181            data = [value];
13182        }
13183
13184        var old;
13185
13186        index  = $coerce_to(index, $$$('Integer'), 'to_int');
13187        length = $coerce_to(length, $$$('Integer'), 'to_int');
13188
13189        if (index < 0) {
13190          old    = index;
13191          index += size;
13192
13193          if (index < 0) {
13194            $Kernel.$raise($$$('IndexError'), "index " + (old) + " too small for array; minimum " + (-self.length));
13195          }
13196        }
13197
13198        if (length < 0) {
13199          $Kernel.$raise($$$('IndexError'), "negative length (" + (length) + ")")
13200        }
13201
13202        if (index > size) {
13203          for (i = size; i < index; i++) {
13204            self[i] = nil;
13205          }
13206        }
13207
13208        if (extra === undefined) {
13209          self[index] = value;
13210        }
13211        else {
13212          self.splice.apply(self, [index, length].concat(data));
13213        }
13214
13215        return value;
13216      }
13217    ;
13218    }, -3);
13219    
13220    $def(self, '$any?', function $Array_any$ques$12(pattern) {
13221      var block = $Array_any$ques$12.$$p || nil, self = this;
13222
13223      $Array_any$ques$12.$$p = null;
13224      
13225      ;
13226      ;
13227      if (self.length === 0) return false;
13228      return $send2(self, $find_super(self, 'any?', $Array_any$ques$12, false, true), 'any?', [pattern], block);
13229    }, -1);
13230    
13231    $def(self, '$assoc', function $$assoc(object) {
13232      var self = this;
13233
13234      
13235      for (var i = 0, length = self.length, item; i < length; i++) {
13236        if (item = self[i], item.length && (item[0])['$=='](object)) {
13237          return item;
13238        }
13239      }
13240
13241      return nil;
13242    
13243    });
13244    
13245    $def(self, '$at', function $$at(index) {
13246      var self = this;
13247
13248      
13249      index = $coerce_to(index, $$$('Integer'), 'to_int')
13250
13251      if (index < 0) {
13252        index += self.length;
13253      }
13254
13255      if (index < 0 || index >= self.length) {
13256        return nil;
13257      }
13258
13259      return self[index];
13260    
13261    });
13262    
13263    $def(self, '$bsearch_index', function $$bsearch_index() {
13264      var block = $$bsearch_index.$$p || nil, self = this;
13265
13266      $$bsearch_index.$$p = null;
13267      
13268      ;
13269      if (!(block !== nil)) {
13270        return self.$enum_for("bsearch_index")
13271      };
13272      
13273      var min = 0,
13274          max = self.length,
13275          mid,
13276          val,
13277          ret,
13278          smaller = false,
13279          satisfied = nil;
13280
13281      while (min < max) {
13282        mid = min + Math.floor((max - min) / 2);
13283        val = self[mid];
13284        ret = $yield1(block, val);
13285
13286        if (ret === true) {
13287          satisfied = mid;
13288          smaller = true;
13289        }
13290        else if (ret === false || ret === nil) {
13291          smaller = false;
13292        }
13293        else if (ret.$$is_number) {
13294          if (ret === 0) { return mid; }
13295          smaller = (ret < 0);
13296        }
13297        else {
13298          $Kernel.$raise($$$('TypeError'), "wrong argument type " + ((ret).$class()) + " (must be numeric, true, false or nil)")
13299        }
13300
13301        if (smaller) { max = mid; } else { min = mid + 1; }
13302      }
13303
13304      return satisfied;
13305    ;
13306    });
13307    
13308    $def(self, '$bsearch', function $$bsearch() {
13309      var block = $$bsearch.$$p || nil, self = this, index = nil;
13310
13311      $$bsearch.$$p = null;
13312      
13313      ;
13314      if (!(block !== nil)) {
13315        return self.$enum_for("bsearch")
13316      };
13317      index = $send(self, 'bsearch_index', [], block.$to_proc());
13318      
13319      if (index != null && index.$$is_number) {
13320        return self[index];
13321      } else {
13322        return index;
13323      }
13324    ;
13325    });
13326    
13327    $def(self, '$cycle', function $$cycle(n) {
13328      var block = $$cycle.$$p || nil, self = this;
13329
13330      $$cycle.$$p = null;
13331      
13332      ;
13333      if (n == null) n = nil;
13334      if (!(block !== nil)) {
13335        return $send(self, 'enum_for', ["cycle", n], function $$13(){var self = $$13.$$s == null ? this : $$13.$$s;
13336
13337          if ($truthy(n['$nil?']())) {
13338            return $$$($$$('Float'), 'INFINITY')
13339          } else {
13340            
13341            n = $Opal['$coerce_to!'](n, $$$('Integer'), "to_int");
13342            if ($truthy($rb_gt(n, 0))) {
13343              return $rb_times(self.$enumerator_size(), n)
13344            } else {
13345              return 0
13346            };
13347          }}, {$$s: self})
13348      };
13349      if (($truthy(self['$empty?']()) || ($eqeq(n, 0)))) {
13350        return nil
13351      };
13352      
13353      var i, length, value;
13354
13355      if (n === nil) {
13356        while (true) {
13357          for (i = 0, length = self.length; i < length; i++) {
13358            value = $yield1(block, self[i]);
13359          }
13360        }
13361      }
13362      else {
13363        n = $Opal['$coerce_to!'](n, $$$('Integer'), "to_int");
13364        if (n <= 0) {
13365          return self;
13366        }
13367
13368        while (n > 0) {
13369          for (i = 0, length = self.length; i < length; i++) {
13370            value = $yield1(block, self[i]);
13371          }
13372
13373          n--;
13374        }
13375      }
13376    ;
13377      return self;
13378    }, -1);
13379    
13380    $def(self, '$clear', function $$clear() {
13381      var self = this;
13382
13383      
13384      $deny_frozen_access(self);
13385      self.splice(0, self.length);
13386      return self;
13387    });
13388    
13389    $def(self, '$count', function $$count(object) {
13390      var block = $$count.$$p || nil, self = this;
13391
13392      $$count.$$p = null;
13393      
13394      ;
13395      ;
13396      if (($truthy(object !== undefined) || ($truthy(block)))) {
13397        return $send2(self, $find_super(self, 'count', $$count, false, true), 'count', [object], block)
13398      } else {
13399        return self.$size()
13400      };
13401    }, -1);
13402    
13403    $def(self, '$initialize_copy', function $$initialize_copy(other) {
13404      var self = this;
13405
13406      return self.$replace(other)
13407    });
13408    
13409    $def(self, '$collect', function $$collect() {
13410      var block = $$collect.$$p || nil, self = this;
13411
13412      $$collect.$$p = null;
13413      
13414      ;
13415      if (!(block !== nil)) {
13416        return $send(self, 'enum_for', ["collect"], function $$14(){var self = $$14.$$s == null ? this : $$14.$$s;
13417
13418          return self.$size()}, {$$s: self})
13419      };
13420      
13421      var result = [];
13422
13423      for (var i = 0, length = self.length; i < length; i++) {
13424        var value = $yield1(block, self[i]);
13425        result.push(value);
13426      }
13427
13428      return result;
13429    ;
13430    });
13431    
13432    $def(self, '$collect!', function $Array_collect$excl$15() {
13433      var block = $Array_collect$excl$15.$$p || nil, self = this;
13434
13435      $Array_collect$excl$15.$$p = null;
13436      
13437      ;
13438      if (!(block !== nil)) {
13439        return $send(self, 'enum_for', ["collect!"], function $$16(){var self = $$16.$$s == null ? this : $$16.$$s;
13440
13441          return self.$size()}, {$$s: self})
13442      };
13443      
13444      $deny_frozen_access(self);
13445
13446      for (var i = 0, length = self.length; i < length; i++) {
13447        var value = $yield1(block, self[i]);
13448        self[i] = value;
13449      }
13450    ;
13451      return self;
13452    });
13453    
13454    function binomial_coefficient(n, k) {
13455      if (n === k || k === 0) {
13456        return 1;
13457      }
13458
13459      if (k > 0 && n > k) {
13460        return binomial_coefficient(n - 1, k - 1) + binomial_coefficient(n - 1, k);
13461      }
13462
13463      return 0;
13464    }
13465  ;
13466    
13467    $def(self, '$combination', function $$combination(n) {
13468      var $yield = $$combination.$$p || nil, self = this, num = nil;
13469
13470      $$combination.$$p = null;
13471      
13472      num = $Opal['$coerce_to!'](n, $$$('Integer'), "to_int");
13473      if (!($yield !== nil)) {
13474        return $send(self, 'enum_for', ["combination", num], function $$17(){var self = $$17.$$s == null ? this : $$17.$$s;
13475
13476          return binomial_coefficient(self.length, num)}, {$$s: self})
13477      };
13478      
13479      var i, length, stack, chosen, lev, done, next;
13480
13481      if (num === 0) {
13482        Opal.yield1($yield, [])
13483      } else if (num === 1) {
13484        for (i = 0, length = self.length; i < length; i++) {
13485          Opal.yield1($yield, [self[i]])
13486        }
13487      }
13488      else if (num === self.length) {
13489        Opal.yield1($yield, self.slice())
13490      }
13491      else if (num >= 0 && num < self.length) {
13492        stack = [];
13493        for (i = 0; i <= num + 1; i++) {
13494          stack.push(0);
13495        }
13496
13497        chosen = [];
13498        lev = 0;
13499        done = false;
13500        stack[0] = -1;
13501
13502        while (!done) {
13503          chosen[lev] = self[stack[lev+1]];
13504          while (lev < num - 1) {
13505            lev++;
13506            next = stack[lev+1] = stack[lev] + 1;
13507            chosen[lev] = self[next];
13508          }
13509          Opal.yield1($yield, chosen.slice())
13510          lev++;
13511          do {
13512            done = (lev === 0);
13513            stack[lev]++;
13514            lev--;
13515          } while ( stack[lev+1] + num === self.length + lev + 1 );
13516        }
13517      }
13518    ;
13519      return self;
13520    });
13521    
13522    $def(self, '$repeated_combination', function $$repeated_combination(n) {
13523      var $yield = $$repeated_combination.$$p || nil, self = this, num = nil;
13524
13525      $$repeated_combination.$$p = null;
13526      
13527      num = $Opal['$coerce_to!'](n, $$$('Integer'), "to_int");
13528      if (!($yield !== nil)) {
13529        return $send(self, 'enum_for', ["repeated_combination", num], function $$18(){var self = $$18.$$s == null ? this : $$18.$$s;
13530
13531          return binomial_coefficient(self.length + num - 1, num);}, {$$s: self})
13532      };
13533      
13534      function iterate(max, from, buffer, self) {
13535        if (buffer.length == max) {
13536          var copy = buffer.slice();
13537          Opal.yield1($yield, copy)
13538          return;
13539        }
13540        for (var i = from; i < self.length; i++) {
13541          buffer.push(self[i]);
13542          iterate(max, i, buffer, self);
13543          buffer.pop();
13544        }
13545      }
13546
13547      if (num >= 0) {
13548        iterate(num, 0, [], self);
13549      }
13550    ;
13551      return self;
13552    });
13553    
13554    $def(self, '$compact', function $$compact() {
13555      var self = this;
13556
13557      
13558      var result = [];
13559
13560      for (var i = 0, length = self.length, item; i < length; i++) {
13561        if ((item = self[i]) !== nil) {
13562          result.push(item);
13563        }
13564      }
13565
13566      return result;
13567    
13568    });
13569    
13570    $def(self, '$compact!', function $Array_compact$excl$19() {
13571      var self = this;
13572
13573      
13574      $deny_frozen_access(self);
13575
13576      var original = self.length;
13577
13578      for (var i = 0, length = self.length; i < length; i++) {
13579        if (self[i] === nil) {
13580          self.splice(i, 1);
13581
13582          length--;
13583          i--;
13584        }
13585      }
13586
13587      return self.length === original ? nil : self;
13588    
13589    });
13590    
13591    $def(self, '$concat', function $$concat($a) {
13592      var $post_args, others, self = this;
13593
13594      
13595      $post_args = $slice(arguments);
13596      others = $post_args;
13597      $deny_frozen_access(self);
13598      others = $send(others, 'map', [], function $$20(other){var self = $$20.$$s == null ? this : $$20.$$s;
13599
13600        
13601        if (other == null) other = nil;
13602        other = ($eqeqeq($$$('Array'), other) ? (other.$to_a()) : (($coerce_to(other, $$$('Array'), 'to_ary')).$to_a()));
13603        if ($truthy(other['$equal?'](self))) {
13604          other = other.$dup()
13605        };
13606        return other;}, {$$s: self});
13607      $send(others, 'each', [], function $$21(other){var self = $$21.$$s == null ? this : $$21.$$s;
13608
13609        
13610        if (other == null) other = nil;
13611        
13612        for (var i = 0, length = other.length; i < length; i++) {
13613          self.push(other[i]);
13614        }
13615      ;}, {$$s: self});
13616      return self;
13617    }, -1);
13618    
13619    $def(self, '$delete', function $Array_delete$22(object) {
13620      var $yield = $Array_delete$22.$$p || nil, self = this;
13621
13622      $Array_delete$22.$$p = null;
13623      
13624      var original = self.length;
13625
13626      for (var i = 0, length = original; i < length; i++) {
13627        if ((self[i])['$=='](object)) {
13628          $deny_frozen_access(self);
13629
13630          self.splice(i, 1);
13631
13632          length--;
13633          i--;
13634        }
13635      }
13636
13637      if (self.length === original) {
13638        if (($yield !== nil)) {
13639          return Opal.yieldX($yield, []);
13640        }
13641        return nil;
13642      }
13643      return object;
13644    
13645    });
13646    
13647    $def(self, '$delete_at', function $$delete_at(index) {
13648      var self = this;
13649
13650      
13651      $deny_frozen_access(self);
13652
13653      index = $coerce_to(index, $$$('Integer'), 'to_int');
13654
13655      if (index < 0) {
13656        index += self.length;
13657      }
13658
13659      if (index < 0 || index >= self.length) {
13660        return nil;
13661      }
13662
13663      var result = self[index];
13664
13665      self.splice(index, 1);
13666
13667      return result;
13668    
13669    });
13670    
13671    $def(self, '$delete_if', function $$delete_if() {
13672      var block = $$delete_if.$$p || nil, self = this;
13673
13674      $$delete_if.$$p = null;
13675      
13676      ;
13677      if (!(block !== nil)) {
13678        return $send(self, 'enum_for', ["delete_if"], function $$23(){var self = $$23.$$s == null ? this : $$23.$$s;
13679
13680          return self.$size()}, {$$s: self})
13681      };
13682      
13683      $deny_frozen_access(self);
13684
13685      filterIf(self, $falsy, block)
13686    ;
13687      return self;
13688    });
13689    
13690    $def(self, '$difference', function $$difference($a) {
13691      var $post_args, arrays, self = this;
13692
13693      
13694      $post_args = $slice(arguments);
13695      arrays = $post_args;
13696      return $send(arrays, 'reduce', [self.$to_a().$dup()], function $$24(a, b){
13697        
13698        if (a == null) a = nil;
13699        if (b == null) b = nil;
13700        return $rb_minus(a, b);});
13701    }, -1);
13702    
13703    $def(self, '$dig', function $$dig(idx, $a) {
13704      var $post_args, idxs, self = this, item = nil;
13705
13706      
13707      $post_args = $slice(arguments, 1);
13708      idxs = $post_args;
13709      item = self['$[]'](idx);
13710      
13711      if (item === nil || idxs.length === 0) {
13712        return item;
13713      }
13714    ;
13715      if (!$truthy(item['$respond_to?']("dig"))) {
13716        $Kernel.$raise($$$('TypeError'), "" + (item.$class()) + " does not have #dig method")
13717      };
13718      return $send(item, 'dig', $to_a(idxs));
13719    }, -2);
13720    
13721    $def(self, '$drop', function $$drop(number) {
13722      var self = this;
13723
13724      
13725      number = $coerce_to(number, $$$('Integer'), 'to_int');
13726
13727      if (number < 0) {
13728        $Kernel.$raise($$$('ArgumentError'))
13729      }
13730
13731      return self.slice(number);
13732    
13733    });
13734    
13735    $def(self, '$dup', function $$dup() {
13736      var $yield = $$dup.$$p || nil, self = this;
13737
13738      $$dup.$$p = null;
13739      
13740      
13741      if (self.$$class === Opal.Array &&
13742          self.$$class.$allocate.$$pristine &&
13743          self.$copy_instance_variables.$$pristine &&
13744          self.$initialize_dup.$$pristine) {
13745        return self.slice(0);
13746      }
13747    ;
13748      return $send2(self, $find_super(self, 'dup', $$dup, false, true), 'dup', [], $yield);
13749    });
13750    
13751    $def(self, '$each', function $$each() {
13752      var block = $$each.$$p || nil, self = this;
13753
13754      $$each.$$p = null;
13755      
13756      ;
13757      if (!(block !== nil)) {
13758        return $send(self, 'enum_for', ["each"], function $$25(){var self = $$25.$$s == null ? this : $$25.$$s;
13759
13760          return self.$size()}, {$$s: self})
13761      };
13762      
13763      for (var i = 0, length = self.length; i < length; i++) {
13764        var value = $yield1(block, self[i]);
13765      }
13766    ;
13767      return self;
13768    });
13769    
13770    $def(self, '$each_index', function $$each_index() {
13771      var block = $$each_index.$$p || nil, self = this;
13772
13773      $$each_index.$$p = null;
13774      
13775      ;
13776      if (!(block !== nil)) {
13777        return $send(self, 'enum_for', ["each_index"], function $$26(){var self = $$26.$$s == null ? this : $$26.$$s;
13778
13779          return self.$size()}, {$$s: self})
13780      };
13781      
13782      for (var i = 0, length = self.length; i < length; i++) {
13783        var value = $yield1(block, i);
13784      }
13785    ;
13786      return self;
13787    });
13788    
13789    $def(self, '$empty?', function $Array_empty$ques$27() {
13790      var self = this;
13791
13792      return self.length === 0;
13793    });
13794    
13795    $def(self, '$eql?', function $Array_eql$ques$28(other) {
13796      var self = this;
13797
13798      
13799      var recursed = {};
13800
13801      function _eql(array, other) {
13802        var i, length, a, b;
13803
13804        if (!other.$$is_array) {
13805          return false;
13806        }
13807
13808        other = other.$to_a();
13809
13810        if (array.length !== other.length) {
13811          return false;
13812        }
13813
13814        recursed[(array).$object_id()] = true;
13815
13816        for (i = 0, length = array.length; i < length; i++) {
13817          a = array[i];
13818          b = other[i];
13819          if (a.$$is_array) {
13820            if (b.$$is_array && b.length !== a.length) {
13821              return false;
13822            }
13823            if (!recursed.hasOwnProperty((a).$object_id())) {
13824              if (!_eql(a, b)) {
13825                return false;
13826              }
13827            }
13828          } else {
13829            if (!(a)['$eql?'](b)) {
13830              return false;
13831            }
13832          }
13833        }
13834
13835        return true;
13836      }
13837
13838      return _eql(self, other);
13839    
13840    });
13841    
13842    $def(self, '$fetch', function $$fetch(index, defaults) {
13843      var block = $$fetch.$$p || nil, self = this;
13844
13845      $$fetch.$$p = null;
13846      
13847      ;
13848      ;
13849      
13850      var original = index;
13851
13852      index = $coerce_to(index, $$$('Integer'), 'to_int');
13853
13854      if (index < 0) {
13855        index += self.length;
13856      }
13857
13858      if (index >= 0 && index < self.length) {
13859        return self[index];
13860      }
13861
13862      if (block !== nil && defaults != null) {
13863        self.$warn("warning: block supersedes default value argument")
13864      }
13865
13866      if (block !== nil) {
13867        return block(original);
13868      }
13869
13870      if (defaults != null) {
13871        return defaults;
13872      }
13873
13874      if (self.length === 0) {
13875        $Kernel.$raise($$$('IndexError'), "index " + (original) + " outside of array bounds: 0...0")
13876      }
13877      else {
13878        $Kernel.$raise($$$('IndexError'), "index " + (original) + " outside of array bounds: -" + (self.length) + "..." + (self.length));
13879      }
13880    ;
13881    }, -2);
13882    
13883    $def(self, '$fill', function $$fill($a) {
13884      var block = $$fill.$$p || nil, $post_args, args, $b, $c, self = this, one = nil, two = nil, obj = nil, left = nil, right = nil;
13885
13886      $$fill.$$p = null;
13887      
13888      ;
13889      $post_args = $slice(arguments);
13890      args = $post_args;
13891      
13892      $deny_frozen_access(self);
13893
13894      var i, length, value;
13895    ;
13896      if ($truthy(block)) {
13897        
13898        if ($truthy(args.length > 2)) {
13899          $Kernel.$raise($$$('ArgumentError'), "wrong number of arguments (" + (args.$length()) + " for 0..2)")
13900        };
13901        $c = args, $b = $to_ary($c), (one = ($b[0] == null ? nil : $b[0])), (two = ($b[1] == null ? nil : $b[1])), $c;
13902      } else {
13903        
13904        if ($truthy(args.length == 0)) {
13905          $Kernel.$raise($$$('ArgumentError'), "wrong number of arguments (0 for 1..3)")
13906        } else if ($truthy(args.length > 3)) {
13907          $Kernel.$raise($$$('ArgumentError'), "wrong number of arguments (" + (args.$length()) + " for 1..3)")
13908        };
13909        $c = args, $b = $to_ary($c), (obj = ($b[0] == null ? nil : $b[0])), (one = ($b[1] == null ? nil : $b[1])), (two = ($b[2] == null ? nil : $b[2])), $c;
13910      };
13911      if ($eqeqeq($$$('Range'), one)) {
13912        
13913        if ($truthy(two)) {
13914          $Kernel.$raise($$$('TypeError'), "length invalid with range")
13915        };
13916        left = one.begin === nil ? 0 : $coerce_to(one.begin, $$$('Integer'), 'to_int');
13917        if ($truthy(left < 0)) {
13918          left += this.length
13919        };
13920        if ($truthy(left < 0)) {
13921          $Kernel.$raise($$$('RangeError'), "" + (one.$inspect()) + " out of range")
13922        };
13923        right = one.end === nil ? -1 : $coerce_to(one.end, $$$('Integer'), 'to_int');
13924        if ($truthy(right < 0)) {
13925          right += this.length
13926        };
13927        if (!$truthy(one['$exclude_end?']())) {
13928          right += 1
13929        };
13930        if ($truthy(right <= left)) {
13931          return self
13932        };
13933      } else if ($truthy(one)) {
13934        
13935        left = $coerce_to(one, $$$('Integer'), 'to_int');
13936        if ($truthy(left < 0)) {
13937          left += this.length
13938        };
13939        if ($truthy(left < 0)) {
13940          left = 0
13941        };
13942        if ($truthy(two)) {
13943          
13944          right = $coerce_to(two, $$$('Integer'), 'to_int');
13945          if ($truthy(right == 0)) {
13946            return self
13947          };
13948          right += left;
13949        } else {
13950          right = this.length
13951        };
13952      } else {
13953        
13954        left = 0;
13955        right = this.length;
13956      };
13957      if ($truthy(left > this.length)) {
13958        
13959        for (i = this.length; i < right; i++) {
13960          self[i] = nil;
13961        }
13962      
13963      };
13964      if ($truthy(right > this.length)) {
13965        this.length = right
13966      };
13967      if ($truthy(block)) {
13968        
13969        for (length = this.length; left < right; left++) {
13970          value = block(left);
13971          self[left] = value;
13972        }
13973      
13974      } else {
13975        
13976        for (length = this.length; left < right; left++) {
13977          self[left] = obj;
13978        }
13979      
13980      };
13981      return self;
13982    }, -1);
13983    
13984    $def(self, '$first', function $$first(count) {
13985      var self = this;
13986
13987      
13988      ;
13989      
13990      if (count == null) {
13991        return self.length === 0 ? nil : self[0];
13992      }
13993
13994      count = $coerce_to(count, $$$('Integer'), 'to_int');
13995
13996      if (count < 0) {
13997        $Kernel.$raise($$$('ArgumentError'), "negative array size");
13998      }
13999
14000      return self.slice(0, count);
14001    ;
14002    }, -1);
14003    
14004    $def(self, '$flatten', function $$flatten(level) {
14005      var self = this;
14006
14007      
14008      ;
14009      
14010      function _flatten(array, level) {
14011        var result = [],
14012            i, length,
14013            item, ary;
14014
14015        array = (array).$to_a();
14016
14017        for (i = 0, length = array.length; i < length; i++) {
14018          item = array[i];
14019
14020          if (!$respond_to(item, '$to_ary', true)) {
14021            result.push(item);
14022            continue;
14023          }
14024
14025          ary = (item).$to_ary();
14026
14027          if (ary === nil) {
14028            result.push(item);
14029            continue;
14030          }
14031
14032          if (!ary.$$is_array) {
14033            $Kernel.$raise($$$('TypeError'));
14034          }
14035
14036          if (ary === self) {
14037            $Kernel.$raise($$$('ArgumentError'));
14038          }
14039
14040          switch (level) {
14041          case undefined:
14042            result = result.concat(_flatten(ary));
14043            break;
14044          case 0:
14045            result.push(ary);
14046            break;
14047          default:
14048            result.push.apply(result, _flatten(ary, level - 1));
14049          }
14050        }
14051        return result;
14052      }
14053
14054      if (level !== undefined) {
14055        level = $coerce_to(level, $$$('Integer'), 'to_int');
14056      }
14057
14058      return _flatten(self, level);
14059    ;
14060    }, -1);
14061    
14062    $def(self, '$flatten!', function $Array_flatten$excl$29(level) {
14063      var self = this;
14064
14065      
14066      ;
14067      
14068      $deny_frozen_access(self);
14069
14070      var flattened = self.$flatten(level);
14071
14072      if (self.length == flattened.length) {
14073        for (var i = 0, length = self.length; i < length; i++) {
14074          if (self[i] !== flattened[i]) {
14075            break;
14076          }
14077        }
14078
14079        if (i == length) {
14080          return nil;
14081        }
14082      }
14083
14084      self.$replace(flattened);
14085    ;
14086      return self;
14087    }, -1);
14088    
14089    $def(self, '$freeze', function $$freeze() {
14090      var self = this;
14091
14092      
14093      if ($truthy(self['$frozen?']())) {
14094        return self
14095      };
14096      return $freeze(self);;
14097    });
14098    
14099    $def(self, '$hash', function $$hash() {
14100      var self = this;
14101
14102      
14103      var top = ($hash_ids === undefined),
14104          result = ['A'],
14105          hash_id = self.$object_id(),
14106          item, i, key;
14107
14108      try {
14109        if (top) {
14110          $hash_ids = Object.create(null);
14111        }
14112
14113        // return early for recursive structures
14114        if ($hash_ids[hash_id]) {
14115          return 'self';
14116        }
14117
14118        for (key in $hash_ids) {
14119          item = $hash_ids[key];
14120          if (self['$eql?'](item)) {
14121            return 'self';
14122          }
14123        }
14124
14125        $hash_ids[hash_id] = self;
14126
14127        for (i = 0; i < self.length; i++) {
14128          item = self[i];
14129          result.push(item.$hash());
14130        }
14131
14132        return result.join(',');
14133      } finally {
14134        if (top) {
14135          $hash_ids = undefined;
14136        }
14137      }
14138    
14139    });
14140    
14141    $def(self, '$include?', function $Array_include$ques$30(member) {
14142      var self = this;
14143
14144      
14145      for (var i = 0, length = self.length; i < length; i++) {
14146        if ((self[i])['$=='](member)) {
14147          return true;
14148        }
14149      }
14150
14151      return false;
14152    
14153    });
14154    
14155    $def(self, '$index', function $$index(object) {
14156      var block = $$index.$$p || nil, self = this;
14157
14158      $$index.$$p = null;
14159      
14160      ;
14161      ;
14162      
14163      var i, length, value;
14164
14165      if (object != null && block !== nil) {
14166        self.$warn("warning: given block not used")
14167      }
14168
14169      if (object != null) {
14170        for (i = 0, length = self.length; i < length; i++) {
14171          if ((self[i])['$=='](object)) {
14172            return i;
14173          }
14174        }
14175      }
14176      else if (block !== nil) {
14177        for (i = 0, length = self.length; i < length; i++) {
14178          value = block(self[i]);
14179
14180          if (value !== false && value !== nil) {
14181            return i;
14182          }
14183        }
14184      }
14185      else {
14186        return self.$enum_for("index");
14187      }
14188
14189      return nil;
14190    ;
14191    }, -1);
14192    
14193    $def(self, '$insert', function $$insert(index, $a) {
14194      var $post_args, objects, self = this;
14195
14196      
14197      $post_args = $slice(arguments, 1);
14198      objects = $post_args;
14199      
14200      $deny_frozen_access(self);
14201
14202      index = $coerce_to(index, $$$('Integer'), 'to_int');
14203
14204      if (objects.length > 0) {
14205        if (index < 0) {
14206          index += self.length + 1;
14207
14208          if (index < 0) {
14209            $Kernel.$raise($$$('IndexError'), "" + (index) + " is out of bounds");
14210          }
14211        }
14212        if (index > self.length) {
14213          for (var i = self.length; i < index; i++) {
14214            self.push(nil);
14215          }
14216        }
14217
14218        self.splice.apply(self, [index, 0].concat(objects));
14219      }
14220    ;
14221      return self;
14222    }, -2);
14223    var inspect_stack = [];
14224    
14225    $def(self, '$inspect', function $$inspect() {
14226      var self = this;
14227
14228      
14229      
14230      var result = [],
14231      id = self.$__id__(),
14232      pushed = true;
14233    ;
14234      
14235      return (function() { try {
14236      
14237      
14238        if (inspect_stack.indexOf(id) !== -1) {
14239          pushed = false;
14240          return '[...]';
14241        }
14242        inspect_stack.push(id)
14243
14244        for (var i = 0, length = self.length; i < length; i++) {
14245          var item = self['$[]'](i);
14246
14247          result.push($$('Opal').$inspect(item));
14248        }
14249
14250        return '[' + result.join(', ') + ']';
14251      ;
14252      return nil;
14253      } finally {
14254        if (pushed) inspect_stack.pop()
14255      }; })();;
14256    });
14257    
14258    $def(self, '$intersection', function $$intersection($a) {
14259      var $post_args, arrays, self = this;
14260
14261      
14262      $post_args = $slice(arguments);
14263      arrays = $post_args;
14264      return $send(arrays, 'reduce', [self.$to_a().$dup()], function $$31(a, b){
14265        
14266        if (a == null) a = nil;
14267        if (b == null) b = nil;
14268        return a['$&'](b);});
14269    }, -1);
14270    
14271    $def(self, '$intersect?', function $Array_intersect$ques$32(other) {
14272      var self = this;
14273
14274      return self.$intersection(other)['$empty?']()['$!']()
14275    });
14276    
14277    $def(self, '$join', function $$join(sep) {
14278      var self = this;
14279      if ($gvars[","] == null) $gvars[","] = nil;
14280
14281      
14282      if (sep == null) sep = nil;
14283      if ($truthy(self.length === 0)) {
14284        return ""
14285      };
14286      if ($truthy(sep === nil)) {
14287        sep = $gvars[","]
14288      };
14289      
14290      var result = [];
14291      var i, length, item, tmp;
14292
14293      for (i = 0, length = self.length; i < length; i++) {
14294        item = self[i];
14295
14296        if ($respond_to(item, '$to_str')) {
14297          tmp = (item).$to_str();
14298
14299          if (tmp !== nil) {
14300            result.push((tmp).$to_s());
14301
14302            continue;
14303          }
14304        }
14305
14306        if ($respond_to(item, '$to_ary')) {
14307          tmp = (item).$to_ary();
14308
14309          if (tmp === self) {
14310            $Kernel.$raise($$$('ArgumentError'));
14311          }
14312
14313          if (tmp !== nil) {
14314            result.push((tmp).$join(sep));
14315
14316            continue;
14317          }
14318        }
14319
14320        if ($respond_to(item, '$to_s')) {
14321          tmp = (item).$to_s();
14322
14323          if (tmp !== nil) {
14324            result.push(tmp);
14325
14326            continue;
14327          }
14328        }
14329
14330        $Kernel.$raise($$$('NoMethodError').$new("" + ($$('Opal').$inspect(self.$item())) + " doesn't respond to #to_str, #to_ary or #to_s", "to_str"));
14331      }
14332
14333      if (sep === nil) {
14334        return result.join('');
14335      }
14336      else {
14337        return result.join($Opal['$coerce_to!'](sep, $$$('String'), "to_str").$to_s());
14338      }
14339    ;
14340    }, -1);
14341    
14342    $def(self, '$keep_if', function $$keep_if() {
14343      var block = $$keep_if.$$p || nil, self = this;
14344
14345      $$keep_if.$$p = null;
14346      
14347      ;
14348      if (!(block !== nil)) {
14349        return $send(self, 'enum_for', ["keep_if"], function $$33(){var self = $$33.$$s == null ? this : $$33.$$s;
14350
14351          return self.$size()}, {$$s: self})
14352      };
14353      
14354      $deny_frozen_access(self);
14355
14356      filterIf(self, $truthy, block)
14357    ;
14358      return self;
14359    });
14360    
14361    $def(self, '$last', function $$last(count) {
14362      var self = this;
14363
14364      
14365      ;
14366      
14367      if (count == null) {
14368        return self.length === 0 ? nil : self[self.length - 1];
14369      }
14370
14371      count = $coerce_to(count, $$$('Integer'), 'to_int');
14372
14373      if (count < 0) {
14374        $Kernel.$raise($$$('ArgumentError'), "negative array size");
14375      }
14376
14377      if (count > self.length) {
14378        count = self.length;
14379      }
14380
14381      return self.slice(self.length - count, self.length);
14382    ;
14383    }, -1);
14384    
14385    $def(self, '$length', function $$length() {
14386      var self = this;
14387
14388      return self.length;
14389    });
14390    
14391    $def(self, '$max', function $$max(n) {
14392      var block = $$max.$$p || nil, self = this;
14393
14394      $$max.$$p = null;
14395      
14396      ;
14397      ;
14398      return $send(self.$each(), 'max', [n], block.$to_proc());
14399    }, -1);
14400    
14401    $def(self, '$min', function $$min() {
14402      var block = $$min.$$p || nil, self = this;
14403
14404      $$min.$$p = null;
14405      
14406      ;
14407      return $send(self.$each(), 'min', [], block.$to_proc());
14408    });
14409    
14410    // Returns the product of from, from-1, ..., from - how_many + 1.
14411    function descending_factorial(from, how_many) {
14412      var count = how_many >= 0 ? 1 : 0;
14413      while (how_many) {
14414        count *= from;
14415        from--;
14416        how_many--;
14417      }
14418      return count;
14419    }
14420  ;
14421    
14422    $def(self, '$permutation', function $$permutation(num) {
14423      var block = $$permutation.$$p || nil, self = this, perm = nil, used = nil;
14424
14425      $$permutation.$$p = null;
14426      
14427      ;
14428      ;
14429      if (!(block !== nil)) {
14430        return $send(self, 'enum_for', ["permutation", num], function $$34(){var self = $$34.$$s == null ? this : $$34.$$s;
14431
14432          return descending_factorial(self.length, num === undefined ? self.length : num);}, {$$s: self})
14433      };
14434      
14435      var permute, offensive, output;
14436
14437      if (num === undefined) {
14438        num = self.length;
14439      }
14440      else {
14441        num = $coerce_to(num, $$$('Integer'), 'to_int');
14442      }
14443
14444      if (num < 0 || self.length < num) {
14445        // no permutations, yield nothing
14446      }
14447      else if (num === 0) {
14448        // exactly one permutation: the zero-length array
14449        Opal.yield1(block, [])
14450      }
14451      else if (num === 1) {
14452        // this is a special, easy case
14453        for (var i = 0; i < self.length; i++) {
14454          Opal.yield1(block, [self[i]])
14455        }
14456      }
14457      else {
14458        // this is the general case
14459        (perm = $$('Array').$new(num));
14460        (used = $$('Array').$new(self.length, false));
14461
14462        permute = function(num, perm, index, used, blk) {
14463          self = this;
14464          for(var i = 0; i < self.length; i++){
14465            if(used['$[]'](i)['$!']()) {
14466              perm[index] = i;
14467              if(index < num - 1) {
14468                used[i] = true;
14469                permute.call(self, num, perm, index + 1, used, blk);
14470                used[i] = false;
14471              }
14472              else {
14473                output = [];
14474                for (var j = 0; j < perm.length; j++) {
14475                  output.push(self[perm[j]]);
14476                }
14477                $yield1(blk, output);
14478              }
14479            }
14480          }
14481        }
14482
14483        if ((block !== nil)) {
14484          // offensive (both definitions) copy.
14485          offensive = self.slice();
14486          permute.call(offensive, num, perm, 0, used, block);
14487        }
14488        else {
14489          permute.call(self, num, perm, 0, used, block);
14490        }
14491      }
14492    ;
14493      return self;
14494    }, -1);
14495    
14496    $def(self, '$repeated_permutation', function $$repeated_permutation(n) {
14497      var $yield = $$repeated_permutation.$$p || nil, self = this, num = nil;
14498
14499      $$repeated_permutation.$$p = null;
14500      
14501      num = $Opal['$coerce_to!'](n, $$$('Integer'), "to_int");
14502      if (!($yield !== nil)) {
14503        return $send(self, 'enum_for', ["repeated_permutation", num], function $$35(){var self = $$35.$$s == null ? this : $$35.$$s;
14504
14505          if ($truthy($rb_ge(num, 0))) {
14506            return self.$size()['$**'](num)
14507          } else {
14508            return 0
14509          }}, {$$s: self})
14510      };
14511      
14512      function iterate(max, buffer, self) {
14513        if (buffer.length == max) {
14514          var copy = buffer.slice();
14515          Opal.yield1($yield, copy)
14516          return;
14517        }
14518        for (var i = 0; i < self.length; i++) {
14519          buffer.push(self[i]);
14520          iterate(max, buffer, self);
14521          buffer.pop();
14522        }
14523      }
14524
14525      iterate(num, [], self.slice());
14526    ;
14527      return self;
14528    });
14529    
14530    $def(self, '$pop', function $$pop(count) {
14531      var self = this;
14532
14533      
14534      ;
14535      $deny_frozen_access(self);
14536      if ($truthy(count === undefined)) {
14537        
14538        if ($truthy(self.length === 0)) {
14539          return nil
14540        };
14541        return self.pop();
14542      };
14543      count = $coerce_to(count, $$$('Integer'), 'to_int');
14544      if ($truthy(count < 0)) {
14545        $Kernel.$raise($$$('ArgumentError'), "negative array size")
14546      };
14547      if ($truthy(self.length === 0)) {
14548        return []
14549      };
14550      if ($truthy(count === 1)) {
14551        return [self.pop()];
14552      } else if ($truthy(count > self.length)) {
14553        return self.splice(0, self.length);
14554      } else {
14555        return self.splice(self.length - count, self.length);
14556      };
14557    }, -1);
14558    
14559    $def(self, '$product', function $$product($a) {
14560      var block = $$product.$$p || nil, $post_args, args, self = this;
14561
14562      $$product.$$p = null;
14563      
14564      ;
14565      $post_args = $slice(arguments);
14566      args = $post_args;
14567      
14568      var result = (block !== nil) ? null : [],
14569          n = args.length + 1,
14570          counters = new Array(n),
14571          lengths  = new Array(n),
14572          arrays   = new Array(n),
14573          i, m, subarray, len, resultlen = 1;
14574
14575      arrays[0] = self;
14576      for (i = 1; i < n; i++) {
14577        arrays[i] = $coerce_to(args[i - 1], $$$('Array'), 'to_ary');
14578      }
14579
14580      for (i = 0; i < n; i++) {
14581        len = arrays[i].length;
14582        if (len === 0) {
14583          return result || self;
14584        }
14585        resultlen *= len;
14586        if (resultlen > 2147483647) {
14587          $Kernel.$raise($$$('RangeError'), "too big to product")
14588        }
14589        lengths[i] = len;
14590        counters[i] = 0;
14591      }
14592
14593      outer_loop: for (;;) {
14594        subarray = [];
14595        for (i = 0; i < n; i++) {
14596          subarray.push(arrays[i][counters[i]]);
14597        }
14598        if (result) {
14599          result.push(subarray);
14600        } else {
14601          Opal.yield1(block, subarray)
14602        }
14603        m = n - 1;
14604        counters[m]++;
14605        while (counters[m] === lengths[m]) {
14606          counters[m] = 0;
14607          if (--m < 0) break outer_loop;
14608          counters[m]++;
14609        }
14610      }
14611
14612      return result || self;
14613    ;
14614    }, -1);
14615    
14616    $def(self, '$push', function $$push($a) {
14617      var $post_args, objects, self = this;
14618
14619      
14620      $post_args = $slice(arguments);
14621      objects = $post_args;
14622      
14623      $deny_frozen_access(self);
14624
14625      for (var i = 0, length = objects.length; i < length; i++) {
14626        self.push(objects[i]);
14627      }
14628    ;
14629      return self;
14630    }, -1);
14631    
14632    $def(self, '$rassoc', function $$rassoc(object) {
14633      var self = this;
14634
14635      
14636      for (var i = 0, length = self.length, item; i < length; i++) {
14637        item = self[i];
14638
14639        if (item.length && item[1] !== undefined) {
14640          if ((item[1])['$=='](object)) {
14641            return item;
14642          }
14643        }
14644      }
14645
14646      return nil;
14647    
14648    });
14649    
14650    $def(self, '$reject', function $$reject() {
14651      var block = $$reject.$$p || nil, self = this;
14652
14653      $$reject.$$p = null;
14654      
14655      ;
14656      if (!(block !== nil)) {
14657        return $send(self, 'enum_for', ["reject"], function $$36(){var self = $$36.$$s == null ? this : $$36.$$s;
14658
14659          return self.$size()}, {$$s: self})
14660      };
14661      
14662      var result = [];
14663
14664      for (var i = 0, length = self.length, value; i < length; i++) {
14665        value = block(self[i]);
14666
14667        if (value === false || value === nil) {
14668          result.push(self[i]);
14669        }
14670      }
14671      return result;
14672    ;
14673    });
14674    
14675    $def(self, '$reject!', function $Array_reject$excl$37() {
14676      var block = $Array_reject$excl$37.$$p || nil, self = this, original = nil;
14677
14678      $Array_reject$excl$37.$$p = null;
14679      
14680      ;
14681      if (!(block !== nil)) {
14682        return $send(self, 'enum_for', ["reject!"], function $$38(){var self = $$38.$$s == null ? this : $$38.$$s;
14683
14684          return self.$size()}, {$$s: self})
14685      };
14686      $deny_frozen_access(self);
14687      original = self.$length();
14688      $send(self, 'delete_if', [], block.$to_proc());
14689      if ($eqeq(self.$length(), original)) {
14690        return nil
14691      } else {
14692        return self
14693      };
14694    });
14695    
14696    $def(self, '$replace', function $$replace(other) {
14697      var self = this;
14698
14699      
14700      $deny_frozen_access(self);
14701      other = ($eqeqeq($$$('Array'), other) ? (other.$to_a()) : (($coerce_to(other, $$$('Array'), 'to_ary')).$to_a()));
14702      
14703      self.splice(0, self.length);
14704      self.push.apply(self, other);
14705    ;
14706      return self;
14707    });
14708    
14709    $def(self, '$reverse', function $$reverse() {
14710      var self = this;
14711
14712      return self.slice(0).reverse();
14713    });
14714    
14715    $def(self, '$reverse!', function $Array_reverse$excl$39() {
14716      var self = this;
14717
14718      
14719      $deny_frozen_access(self);
14720      return self.reverse();;
14721    });
14722    
14723    $def(self, '$reverse_each', function $$reverse_each() {
14724      var block = $$reverse_each.$$p || nil, self = this;
14725
14726      $$reverse_each.$$p = null;
14727      
14728      ;
14729      if (!(block !== nil)) {
14730        return $send(self, 'enum_for', ["reverse_each"], function $$40(){var self = $$40.$$s == null ? this : $$40.$$s;
14731
14732          return self.$size()}, {$$s: self})
14733      };
14734      $send(self.$reverse(), 'each', [], block.$to_proc());
14735      return self;
14736    });
14737    
14738    $def(self, '$rindex', function $$rindex(object) {
14739      var block = $$rindex.$$p || nil, self = this;
14740
14741      $$rindex.$$p = null;
14742      
14743      ;
14744      ;
14745      
14746      var i, value;
14747
14748      if (object != null && block !== nil) {
14749        self.$warn("warning: given block not used")
14750      }
14751
14752      if (object != null) {
14753        for (i = self.length - 1; i >= 0; i--) {
14754          if (i >= self.length) {
14755            break;
14756          }
14757          if ((self[i])['$=='](object)) {
14758            return i;
14759          }
14760        }
14761      }
14762      else if (block !== nil) {
14763        for (i = self.length - 1; i >= 0; i--) {
14764          if (i >= self.length) {
14765            break;
14766          }
14767
14768          value = block(self[i]);
14769
14770          if (value !== false && value !== nil) {
14771            return i;
14772          }
14773        }
14774      }
14775      else if (object == null) {
14776        return self.$enum_for("rindex");
14777      }
14778
14779      return nil;
14780    ;
14781    }, -1);
14782    
14783    $def(self, '$rotate', function $$rotate(n) {
14784      var self = this;
14785
14786      
14787      if (n == null) n = 1;
14788      
14789      var ary, idx, firstPart, lastPart;
14790
14791      n = $coerce_to(n, $$$('Integer'), 'to_int')
14792
14793      if (self.length === 1) {
14794        return self.slice();
14795      }
14796      if (self.length === 0) {
14797        return [];
14798      }
14799
14800      ary = self.slice();
14801      idx = n % ary.length;
14802
14803      firstPart = ary.slice(idx);
14804      lastPart = ary.slice(0, idx);
14805      return firstPart.concat(lastPart);
14806    ;
14807    }, -1);
14808    
14809    $def(self, '$rotate!', function $Array_rotate$excl$41(cnt) {
14810      var self = this, ary = nil;
14811
14812      
14813      if (cnt == null) cnt = 1;
14814      
14815      $deny_frozen_access(self);
14816
14817      if (self.length === 0 || self.length === 1) {
14818        return self;
14819      }
14820      cnt = $coerce_to(cnt, $$$('Integer'), 'to_int');
14821    ;
14822      ary = self.$rotate(cnt);
14823      return self.$replace(ary);
14824    }, -1);
14825    (function($base, $super) {
14826      var self = $klass($base, $super, 'SampleRandom');
14827
14828      var $proto = self.$$prototype;
14829
14830      $proto.rng = nil;
14831      
14832      
14833      $def(self, '$initialize', $assign_ivar("rng"));
14834      return $def(self, '$rand', function $$rand(size) {
14835        var self = this, random = nil;
14836
14837        
14838        random = $coerce_to(self.rng.$rand(size), $$$('Integer'), 'to_int');
14839        if ($truthy(random < 0)) {
14840          $Kernel.$raise($$$('RangeError'), "random value must be >= 0")
14841        };
14842        if (!$truthy(random < size)) {
14843          $Kernel.$raise($$$('RangeError'), "random value must be less than Array size")
14844        };
14845        return random;
14846      });
14847    })(self, null);
14848    
14849    $def(self, '$sample', function $$sample(count, options) {
14850      var self = this, o = nil, rng = nil;
14851
14852      
14853      ;
14854      ;
14855      if ($truthy(count === undefined)) {
14856        return self.$at($Kernel.$rand(self.length))
14857      };
14858      if ($truthy(options === undefined)) {
14859        if ($truthy((o = $Opal['$coerce_to?'](count, $$$('Hash'), "to_hash")))) {
14860          
14861          options = o;
14862          count = nil;
14863        } else {
14864          
14865          options = nil;
14866          count = $coerce_to(count, $$$('Integer'), 'to_int');
14867        }
14868      } else {
14869        
14870        count = $coerce_to(count, $$$('Integer'), 'to_int');
14871        options = $coerce_to(options, $$$('Hash'), 'to_hash');
14872      };
14873      if (($truthy(count) && ($truthy(count < 0)))) {
14874        $Kernel.$raise($$$('ArgumentError'), "count must be greater than 0")
14875      };
14876      if ($truthy(options)) {
14877        rng = options['$[]']("random")
14878      };
14879      rng = (($truthy(rng) && ($truthy(rng['$respond_to?']("rand")))) ? ($$('SampleRandom').$new(rng)) : ($Kernel));
14880      if (!$truthy(count)) {
14881        return self[rng.$rand(self.length)]
14882      };
14883      
14884
14885      var abandon, spin, result, i, j, k, targetIndex, oldValue;
14886
14887      if (count > self.length) {
14888        count = self.length;
14889      }
14890
14891      switch (count) {
14892        case 0:
14893          return [];
14894          break;
14895        case 1:
14896          return [self[rng.$rand(self.length)]];
14897          break;
14898        case 2:
14899          i = rng.$rand(self.length);
14900          j = rng.$rand(self.length - 1);
14901          if (i <= j) {
14902            j++;
14903          }
14904          return [self[i], self[j]];
14905          break;
14906        default:
14907          if (self.length / count > 3) {
14908            abandon = false;
14909            spin = 0;
14910
14911            result = $$('Array').$new(count);
14912            i = 1;
14913
14914            result[0] = rng.$rand(self.length);
14915            while (i < count) {
14916              k = rng.$rand(self.length);
14917              j = 0;
14918
14919              while (j < i) {
14920                while (k === result[j]) {
14921                  spin++;
14922                  if (spin > 100) {
14923                    abandon = true;
14924                    break;
14925                  }
14926                  k = rng.$rand(self.length);
14927                }
14928                if (abandon) { break; }
14929
14930                j++;
14931              }
14932
14933              if (abandon) { break; }
14934
14935              result[i] = k;
14936
14937              i++;
14938            }
14939
14940            if (!abandon) {
14941              i = 0;
14942              while (i < count) {
14943                result[i] = self[result[i]];
14944                i++;
14945              }
14946
14947              return result;
14948            }
14949          }
14950
14951          result = self.slice();
14952
14953          for (var c = 0; c < count; c++) {
14954            targetIndex = rng.$rand(self.length - c) + c;
14955            oldValue = result[c];
14956            result[c] = result[targetIndex];
14957            result[targetIndex] = oldValue;
14958          }
14959
14960          return count === self.length ? result : (result)['$[]'](0, count);
14961      }
14962    ;
14963    }, -1);
14964    
14965    $def(self, '$select', function $$select() {
14966      var block = $$select.$$p || nil, self = this;
14967
14968      $$select.$$p = null;
14969      
14970      ;
14971      if (!(block !== nil)) {
14972        return $send(self, 'enum_for', ["select"], function $$42(){var self = $$42.$$s == null ? this : $$42.$$s;
14973
14974          return self.$size()}, {$$s: self})
14975      };
14976      
14977      var result = [];
14978
14979      for (var i = 0, length = self.length, item, value; i < length; i++) {
14980        item = self[i];
14981
14982        value = $yield1(block, item);
14983
14984        if ($truthy(value)) {
14985          result.push(item);
14986        }
14987      }
14988
14989      return result;
14990    ;
14991    });
14992    
14993    $def(self, '$select!', function $Array_select$excl$43() {
14994      var block = $Array_select$excl$43.$$p || nil, self = this;
14995
14996      $Array_select$excl$43.$$p = null;
14997      
14998      ;
14999      if (!(block !== nil)) {
15000        return $send(self, 'enum_for', ["select!"], function $$44(){var self = $$44.$$s == null ? this : $$44.$$s;
15001
15002          return self.$size()}, {$$s: self})
15003      };
15004      
15005      $deny_frozen_access(self)
15006
15007      var original = self.length;
15008      $send(self, 'keep_if', [], block.$to_proc());
15009      return self.length === original ? nil : self;
15010    ;
15011    });
15012    
15013    $def(self, '$shift', function $$shift(count) {
15014      var self = this;
15015
15016      
15017      ;
15018      $deny_frozen_access(self);
15019      if ($truthy(count === undefined)) {
15020        
15021        if ($truthy(self.length === 0)) {
15022          return nil
15023        };
15024        return shiftNoArg(self);
15025      };
15026      count = $coerce_to(count, $$$('Integer'), 'to_int');
15027      if ($truthy(count < 0)) {
15028        $Kernel.$raise($$$('ArgumentError'), "negative array size")
15029      };
15030      if ($truthy(self.length === 0)) {
15031        return []
15032      };
15033      return self.splice(0, count);;
15034    }, -1);
15035    
15036    $def(self, '$shuffle', function $$shuffle(rng) {
15037      var self = this;
15038
15039      
15040      ;
15041      return self.$dup().$to_a()['$shuffle!'](rng);
15042    }, -1);
15043    
15044    $def(self, '$shuffle!', function $Array_shuffle$excl$45(rng) {
15045      var self = this;
15046
15047      
15048      ;
15049      
15050      $deny_frozen_access(self);
15051
15052      var randgen, i = self.length, j, tmp;
15053
15054      if (rng !== undefined) {
15055        rng = $Opal['$coerce_to?'](rng, $$$('Hash'), "to_hash");
15056
15057        if (rng !== nil) {
15058          rng = rng['$[]']("random");
15059
15060          if (rng !== nil && rng['$respond_to?']("rand")) {
15061            randgen = rng;
15062          }
15063        }
15064      }
15065
15066      while (i) {
15067        if (randgen) {
15068          j = randgen.$rand(i).$to_int();
15069
15070          if (j < 0) {
15071            $Kernel.$raise($$$('RangeError'), "random number too small " + (j))
15072          }
15073
15074          if (j >= i) {
15075            $Kernel.$raise($$$('RangeError'), "random number too big " + (j))
15076          }
15077        }
15078        else {
15079          j = self.$rand(i);
15080        }
15081
15082        tmp = self[--i];
15083        self[i] = self[j];
15084        self[j] = tmp;
15085      }
15086
15087      return self;
15088    ;
15089    }, -1);
15090    
15091    $def(self, '$slice!', function $Array_slice$excl$46(index, length) {
15092      var self = this, result = nil, range = nil, range_start = nil, range_end = nil, start = nil;
15093
15094      
15095      ;
15096      $deny_frozen_access(self);
15097      result = nil;
15098      if ($truthy(length === undefined)) {
15099        if ($eqeqeq($$$('Range'), index)) {
15100          
15101          range = index;
15102          result = self['$[]'](range);
15103          range_start = range.begin === nil ? 0 : $coerce_to(range.begin, $$$('Integer'), 'to_int');
15104          range_end = range.end === nil ? -1 : $coerce_to(range.end, $$$('Integer'), 'to_int');
15105          
15106          if (range_start < 0) {
15107            range_start += self.length;
15108          }
15109
15110          if (range_end < 0) {
15111            range_end += self.length;
15112          } else if (range_end >= self.length) {
15113            range_end = self.length - 1;
15114            if (range.excl) {
15115              range_end += 1;
15116            }
15117          }
15118
15119          var range_length = range_end - range_start;
15120          if (range.excl && range.end !== nil) {
15121            range_end -= 1;
15122          } else {
15123            range_length += 1;
15124          }
15125
15126          if (range_start < self.length && range_start >= 0 && range_end < self.length && range_end >= 0 && range_length > 0) {
15127            self.splice(range_start, range_length);
15128          }
15129        ;
15130        } else {
15131          
15132          start = $coerce_to(index, $$$('Integer'), 'to_int');
15133          
15134          if (start < 0) {
15135            start += self.length;
15136          }
15137
15138          if (start < 0 || start >= self.length) {
15139            return nil;
15140          }
15141
15142          result = self[start];
15143
15144          if (start === 0) {
15145            self.shift();
15146          } else {
15147            self.splice(start, 1);
15148          }
15149        ;
15150        }
15151      } else {
15152        
15153        start = $coerce_to(index, $$$('Integer'), 'to_int');
15154        length = $coerce_to(length, $$$('Integer'), 'to_int');
15155        
15156        if (length < 0) {
15157          return nil;
15158        }
15159
15160        var end = start + length;
15161
15162        result = self['$[]'](start, length);
15163
15164        if (start < 0) {
15165          start += self.length;
15166        }
15167
15168        if (start + length > self.length) {
15169          length = self.length - start;
15170        }
15171
15172        if (start < self.length && start >= 0) {
15173          self.splice(start, length);
15174        }
15175      ;
15176      };
15177      return result;
15178    }, -2);
15179    
15180    $def(self, '$sort', function $$sort() {
15181      var block = $$sort.$$p || nil, self = this;
15182
15183      $$sort.$$p = null;
15184      
15185      ;
15186      if (!$truthy(self.length > 1)) {
15187        return self
15188      };
15189      
15190      if (block === nil) {
15191        block = function(a, b) {
15192          return (a)['$<=>'](b);
15193        };
15194      }
15195
15196      return self.slice().sort(function(x, y) {
15197        var ret = block(x, y);
15198
15199        if (ret === nil) {
15200          $Kernel.$raise($$$('ArgumentError'), "comparison of " + ((x).$inspect()) + " with " + ((y).$inspect()) + " failed");
15201        }
15202
15203        return $rb_gt(ret, 0) ? 1 : ($rb_lt(ret, 0) ? -1 : 0);
15204      });
15205    ;
15206    });
15207    
15208    $def(self, '$sort!', function $Array_sort$excl$47() {
15209      var block = $Array_sort$excl$47.$$p || nil, self = this;
15210
15211      $Array_sort$excl$47.$$p = null;
15212      
15213      ;
15214      
15215      $deny_frozen_access(self)
15216
15217      var result;
15218
15219      if ((block !== nil)) {
15220        result = $send((self.slice()), 'sort', [], block.$to_proc());
15221      }
15222      else {
15223        result = (self.slice()).$sort();
15224      }
15225
15226      self.length = 0;
15227      for(var i = 0, length = result.length; i < length; i++) {
15228        self.push(result[i]);
15229      }
15230
15231      return self;
15232    ;
15233    });
15234    
15235    $def(self, '$sort_by!', function $Array_sort_by$excl$48() {
15236      var block = $Array_sort_by$excl$48.$$p || nil, self = this;
15237
15238      $Array_sort_by$excl$48.$$p = null;
15239      
15240      ;
15241      if (!(block !== nil)) {
15242        return $send(self, 'enum_for', ["sort_by!"], function $$49(){var self = $$49.$$s == null ? this : $$49.$$s;
15243
15244          return self.$size()}, {$$s: self})
15245      };
15246      $deny_frozen_access(self);
15247      return self.$replace($send(self, 'sort_by', [], block.$to_proc()));
15248    });
15249    
15250    $def(self, '$take', function $$take(count) {
15251      var self = this;
15252
15253      
15254      if (count < 0) {
15255        $Kernel.$raise($$$('ArgumentError'));
15256      }
15257
15258      return self.slice(0, count);
15259    
15260    });
15261    
15262    $def(self, '$take_while', function $$take_while() {
15263      var block = $$take_while.$$p || nil, self = this;
15264
15265      $$take_while.$$p = null;
15266      
15267      ;
15268      
15269      var result = [];
15270
15271      for (var i = 0, length = self.length, item, value; i < length; i++) {
15272        item = self[i];
15273
15274        value = block(item);
15275
15276        if (value === false || value === nil) {
15277          return result;
15278        }
15279
15280        result.push(item);
15281      }
15282
15283      return result;
15284    ;
15285    });
15286    
15287    $def(self, '$to_a', function $$to_a() {
15288      var self = this;
15289
15290      
15291      if (self.$$class === Opal.Array) {
15292        return self;
15293      }
15294      else {
15295        return Opal.Array.$new(self);
15296      }
15297    
15298    });
15299    
15300    $def(self, '$to_ary', $return_self);
15301    
15302    $def(self, '$to_h', function $$to_h() {
15303      var block = $$to_h.$$p || nil, self = this, array = nil;
15304
15305      $$to_h.$$p = null;
15306      
15307      ;
15308      array = self;
15309      if ((block !== nil)) {
15310        array = $send(array, 'map', [], block.$to_proc())
15311      };
15312      
15313      var i, len = array.length, ary, key, val, hash = $hash2([], {});
15314
15315      for (i = 0; i < len; i++) {
15316        ary = $Opal['$coerce_to?'](array[i], $$$('Array'), "to_ary");
15317        if (!ary.$$is_array) {
15318          $Kernel.$raise($$$('TypeError'), "wrong element type " + ((ary).$class()) + " at " + (i) + " (expected array)")
15319        }
15320        if (ary.length !== 2) {
15321          $Kernel.$raise($$$('ArgumentError'), "wrong array length at " + (i) + " (expected 2, was " + ((ary).$length()) + ")")
15322        }
15323        key = ary[0];
15324        val = ary[1];
15325        $hash_put(hash, key, val);
15326      }
15327
15328      return hash;
15329    ;
15330    });
15331    
15332    $def(self, '$transpose', function $$transpose() {
15333      var self = this, result = nil, max = nil;
15334
15335      
15336      if ($truthy(self['$empty?']())) {
15337        return []
15338      };
15339      result = [];
15340      max = nil;
15341      $send(self, 'each', [], function $$50(row){var $ret_or_1 = nil;
15342
15343        
15344        if (row == null) row = nil;
15345        row = ($eqeqeq($$$('Array'), row) ? (row.$to_a()) : (($coerce_to(row, $$$('Array'), 'to_ary')).$to_a()));
15346        max = ($truthy(($ret_or_1 = max)) ? ($ret_or_1) : (row.length));
15347        if ($neqeq(row.length, max)) {
15348          $Kernel.$raise($$$('IndexError'), "element size differs (" + (row.length) + " should be " + (max) + ")")
15349        };
15350        return $send((row.length), 'times', [], function $$51(i){var $a, entry = nil;
15351
15352          
15353          if (i == null) i = nil;
15354          entry = ($truthy(($ret_or_1 = result['$[]'](i))) ? ($ret_or_1) : (($a = [i, []], $send(result, '[]=', $a), $a[$a.length - 1])));
15355          return entry['$<<'](row.$at(i));});});
15356      return result;
15357    });
15358    
15359    $def(self, '$union', function $$union($a) {
15360      var $post_args, arrays, self = this;
15361
15362      
15363      $post_args = $slice(arguments);
15364      arrays = $post_args;
15365      return $send(arrays, 'reduce', [self.$uniq()], function $$52(a, b){
15366        
15367        if (a == null) a = nil;
15368        if (b == null) b = nil;
15369        return a['$|'](b);});
15370    }, -1);
15371    
15372    $def(self, '$uniq', function $$uniq() {
15373      var block = $$uniq.$$p || nil, self = this;
15374
15375      $$uniq.$$p = null;
15376      
15377      ;
15378      
15379      var hash = $hash2([], {}), i, length, item, key;
15380
15381      if (block === nil) {
15382        for (i = 0, length = self.length; i < length; i++) {
15383          item = self[i];
15384          if ($hash_get(hash, item) === undefined) {
15385            $hash_put(hash, item, item);
15386          }
15387        }
15388      }
15389      else {
15390        for (i = 0, length = self.length; i < length; i++) {
15391          item = self[i];
15392          key = $yield1(block, item);
15393          if ($hash_get(hash, key) === undefined) {
15394            $hash_put(hash, key, item);
15395          }
15396        }
15397      }
15398
15399      return (hash).$values();
15400    ;
15401    });
15402    
15403    $def(self, '$uniq!', function $Array_uniq$excl$53() {
15404      var block = $Array_uniq$excl$53.$$p || nil, self = this;
15405
15406      $Array_uniq$excl$53.$$p = null;
15407      
15408      ;
15409      
15410      $deny_frozen_access(self);
15411
15412      var original_length = self.length, hash = $hash2([], {}), i, length, item, key;
15413
15414      for (i = 0, length = original_length; i < length; i++) {
15415        item = self[i];
15416        key = (block === nil ? item : $yield1(block, item));
15417
15418        if ($hash_get(hash, key) === undefined) {
15419          $hash_put(hash, key, item);
15420          continue;
15421        }
15422
15423        self.splice(i, 1);
15424        length--;
15425        i--;
15426      }
15427
15428      return self.length === original_length ? nil : self;
15429    ;
15430    });
15431    
15432    $def(self, '$unshift', function $$unshift($a) {
15433      var $post_args, objects, self = this;
15434
15435      
15436      $post_args = $slice(arguments);
15437      objects = $post_args;
15438      
15439      $deny_frozen_access(self);
15440
15441      var selfLength = self.length
15442      var objectsLength = objects.length
15443      if (objectsLength == 0) return self;
15444      var index = selfLength - objectsLength
15445      for (var i = 0; i < objectsLength; i++) {
15446        self.push(self[index + i])
15447      }
15448      var len = selfLength - 1
15449      while (len - objectsLength >= 0) {
15450        self[len] = self[len - objectsLength]
15451        len--
15452      }
15453      for (var j = 0; j < objectsLength; j++) {
15454        self[j] = objects[j]
15455      }
15456      return self;
15457    ;
15458    }, -1);
15459    
15460    $def(self, '$values_at', function $$values_at($a) {
15461      var $post_args, args, self = this, out = nil;
15462
15463      
15464      $post_args = $slice(arguments);
15465      args = $post_args;
15466      out = [];
15467      $send(args, 'each', [], function $$54(elem){var self = $$54.$$s == null ? this : $$54.$$s, finish = nil, start = nil, i = nil;
15468
15469        
15470        if (elem == null) elem = nil;
15471        if ($truthy(elem['$is_a?']($$$('Range')))) {
15472          
15473          finish = elem.$end() === nil ? -1 : $coerce_to(elem.$end(), $$$('Integer'), 'to_int');
15474          start = elem.$begin() === nil ? 0 : $coerce_to(elem.$begin(), $$$('Integer'), 'to_int');
15475          
15476          if (start < 0) {
15477            start = start + self.length;
15478            return nil;
15479          }
15480        ;
15481          
15482          if (finish < 0) {
15483            finish = finish + self.length;
15484          }
15485          if (elem['$exclude_end?']() && elem.$end() !== nil) {
15486            finish--;
15487          }
15488          if (finish < start) {
15489            return nil;
15490          }
15491        ;
15492          return $send(start, 'upto', [finish], function $$55(i){var self = $$55.$$s == null ? this : $$55.$$s;
15493
15494            
15495            if (i == null) i = nil;
15496            return out['$<<'](self.$at(i));}, {$$s: self});
15497        } else {
15498          
15499          i = $coerce_to(elem, $$$('Integer'), 'to_int');
15500          return out['$<<'](self.$at(i));
15501        };}, {$$s: self});
15502      return out;
15503    }, -1);
15504    
15505    $def(self, '$zip', function $$zip($a) {
15506      var block = $$zip.$$p || nil, $post_args, others, self = this, $ret_or_1 = nil;
15507
15508      $$zip.$$p = null;
15509      
15510      ;
15511      $post_args = $slice(arguments);
15512      others = $post_args;
15513      
15514      var result = [], size = self.length, part, o, i, j, jj;
15515
15516      for (j = 0, jj = others.length; j < jj; j++) {
15517        o = others[j];
15518        if (o.$$is_array) {
15519          continue;
15520        }
15521        if (o.$$is_range || o.$$is_enumerator) {
15522          others[j] = o.$take(size);
15523          continue;
15524        }
15525        others[j] = ($truthy(($ret_or_1 = $Opal['$coerce_to?'](o, $$$('Array'), "to_ary"))) ? ($ret_or_1) : ($Opal['$coerce_to!'](o, $$$('Enumerator'), "to_enum", "each"))).$to_a();
15526      }
15527
15528      for (i = 0; i < size; i++) {
15529        part = [self[i]];
15530
15531        for (j = 0, jj = others.length; j < jj; j++) {
15532          o = others[j][i];
15533
15534          if (o == null) {
15535            o = nil;
15536          }
15537
15538          part[j + 1] = o;
15539        }
15540
15541        result[i] = part;
15542      }
15543
15544      if (block !== nil) {
15545        for (i = 0; i < size; i++) {
15546          Opal.yield1(block, result[i]);
15547        }
15548
15549        return nil;
15550      }
15551
15552      return result;
15553    ;
15554    }, -1);
15555    $defs(self, '$inherited', function $$inherited(klass) {
15556      
15557      
15558      klass.$$prototype.$to_a = function() {
15559        return this.slice(0, this.length);
15560      }
15561    
15562    });
15563    
15564    $def(self, '$instance_variables', function $$instance_variables() {
15565      var $yield = $$instance_variables.$$p || nil, self = this;
15566
15567      $$instance_variables.$$p = null;
15568      return $send($send2(self, $find_super(self, 'instance_variables', $$instance_variables, false, true), 'instance_variables', [], $yield), 'reject', [], function $$56(ivar){var $ret_or_1 = nil;
15569
15570        
15571        if (ivar == null) ivar = nil;
15572        if ($truthy(($ret_or_1 = /^@\d+$/.test(ivar)))) {
15573          return $ret_or_1
15574        } else {
15575          return ivar['$==']("@length")
15576        };})
15577    });
15578    
15579    $def(self, '$pack', function $$pack($a) {
15580      var $post_args, args;
15581
15582      
15583      $post_args = $slice(arguments);
15584      args = $post_args;
15585      return $Kernel.$raise("To use Array#pack, you must first require 'corelib/array/pack'.");
15586    }, -1);
15587    $alias(self, "append", "push");
15588    $alias(self, "filter", "select");
15589    $alias(self, "filter!", "select!");
15590    $alias(self, "map", "collect");
15591    $alias(self, "map!", "collect!");
15592    $alias(self, "prepend", "unshift");
15593    $alias(self, "size", "length");
15594    $alias(self, "slice", "[]");
15595    $alias(self, "to_s", "inspect");
15596    $Opal.$pristine(self.$singleton_class(), "allocate");
15597    return $Opal.$pristine(self, "copy_instance_variables", "initialize_dup");
15598  })('::', Array, $nesting);
15599};
15600
15601Opal.modules["corelib/hash"] = function(Opal) {/* Generated by Opal 1.7.3 */
15602  var $yield1 = Opal.yield1, $hash = Opal.hash, $hash_init = Opal.hash_init, $hash_get = Opal.hash_get, $hash_put = Opal.hash_put, $hash_delete = Opal.hash_delete, $deny_frozen_access = Opal.deny_frozen_access, $freeze = Opal.freeze, $klass = Opal.klass, $slice = Opal.slice, $Opal = Opal.Opal, $Kernel = Opal.Kernel, $defs = Opal.defs, $def = Opal.def, $send = Opal.send, $rb_ge = Opal.rb_ge, $rb_gt = Opal.rb_gt, $hash2 = Opal.hash2, $truthy = Opal.truthy, $to_a = Opal.to_a, $return_self = Opal.return_self, $alias = Opal.alias, self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$;
15603
15604  Opal.add_stubs('require,include,coerce_to?,[],merge!,allocate,raise,coerce_to!,each,fetch,>=,>,==,compare_by_identity,lambda?,abs,arity,enum_for,size,respond_to?,class,dig,except!,dup,delete,new,inspect,map,to_proc,flatten,frozen?,eql?,default,default_proc,default_proc=,default=,to_h,proc,clone,select,select!,has_key?,indexes,index,length,[]=,has_value?');
15605  
15606  self.$require("corelib/enumerable");
15607  return (function($base, $super, $parent_nesting) {
15608    var self = $klass($base, $super, 'Hash');
15609
15610    var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
15611
15612    
15613    self.$include($$$('Enumerable'));
15614    self.$$prototype.$$is_hash = true;
15615    $defs(self, '$[]', function $Hash_$$$1($a) {
15616      var $post_args, argv, self = this;
15617
15618      
15619      $post_args = $slice(arguments);
15620      argv = $post_args;
15621      
15622      var hash, argc = argv.length, i;
15623
15624      if (argc === 1) {
15625        hash = $Opal['$coerce_to?'](argv['$[]'](0), $$$('Hash'), "to_hash");
15626        if (hash !== nil) {
15627          return self.$allocate()['$merge!'](hash);
15628        }
15629
15630        argv = $Opal['$coerce_to?'](argv['$[]'](0), $$$('Array'), "to_ary");
15631        if (argv === nil) {
15632          $Kernel.$raise($$$('ArgumentError'), "odd number of arguments for Hash")
15633        }
15634
15635        argc = argv.length;
15636        hash = self.$allocate();
15637
15638        for (i = 0; i < argc; i++) {
15639          if (!argv[i].$$is_array) continue;
15640          switch(argv[i].length) {
15641          case 1:
15642            hash.$store(argv[i][0], nil);
15643            break;
15644          case 2:
15645            hash.$store(argv[i][0], argv[i][1]);
15646            break;
15647          default:
15648            $Kernel.$raise($$$('ArgumentError'), "invalid number of elements (" + (argv[i].length) + " for 1..2)")
15649          }
15650        }
15651
15652        return hash;
15653      }
15654
15655      if (argc % 2 !== 0) {
15656        $Kernel.$raise($$$('ArgumentError'), "odd number of arguments for Hash")
15657      }
15658
15659      hash = self.$allocate();
15660
15661      for (i = 0; i < argc; i += 2) {
15662        hash.$store(argv[i], argv[i + 1]);
15663      }
15664
15665      return hash;
15666    ;
15667    }, -1);
15668    $defs(self, '$allocate', function $$allocate() {
15669      var self = this;
15670
15671      
15672      var hash = new self.$$constructor();
15673
15674      $hash_init(hash);
15675
15676      hash.$$none = nil;
15677      hash.$$proc = nil;
15678
15679      return hash;
15680    
15681    });
15682    $defs(self, '$try_convert', function $$try_convert(obj) {
15683      
15684      return $Opal['$coerce_to?'](obj, $$$('Hash'), "to_hash")
15685    });
15686    
15687    $def(self, '$initialize', function $$initialize(defaults) {
15688      var block = $$initialize.$$p || nil, self = this;
15689
15690      $$initialize.$$p = null;
15691      
15692      ;
15693      ;
15694      
15695      $deny_frozen_access(self);
15696
15697      if (defaults !== undefined && block !== nil) {
15698        $Kernel.$raise($$$('ArgumentError'), "wrong number of arguments (1 for 0)")
15699      }
15700      self.$$none = (defaults === undefined ? nil : defaults);
15701      self.$$proc = block;
15702
15703      return self;
15704    ;
15705    }, -1);
15706    
15707    $def(self, '$==', function $Hash_$eq_eq$2(other) {
15708      var self = this;
15709
15710      
15711      if (self === other) {
15712        return true;
15713      }
15714
15715      if (!other.$$is_hash) {
15716        return false;
15717      }
15718
15719      if (self.$$keys.length !== other.$$keys.length) {
15720        return false;
15721      }
15722
15723      for (var i = 0, keys = self.$$keys, length = keys.length, key, value, other_value; i < length; i++) {
15724        key = keys[i];
15725
15726        if (key.$$is_string) {
15727          value = self.$$smap[key];
15728          other_value = other.$$smap[key];
15729        } else {
15730          value = key.value;
15731          other_value = $hash_get(other, key.key);
15732        }
15733
15734        if (other_value === undefined || !value['$eql?'](other_value)) {
15735          return false;
15736        }
15737      }
15738
15739      return true;
15740    
15741    });
15742    
15743    $def(self, '$>=', function $Hash_$gt_eq$3(other) {
15744      var self = this, result = nil;
15745
15746      
15747      other = $Opal['$coerce_to!'](other, $$$('Hash'), "to_hash");
15748      
15749      if (self.$$keys.length < other.$$keys.length) {
15750        return false
15751      }
15752    ;
15753      result = true;
15754      $send(other, 'each', [], function $$4(other_key, other_val){var self = $$4.$$s == null ? this : $$4.$$s, val = nil;
15755
15756        
15757        if (other_key == null) other_key = nil;
15758        if (other_val == null) other_val = nil;
15759        val = self.$fetch(other_key, null);
15760        
15761        if (val == null || val !== other_val) {
15762          result = false;
15763          return;
15764        }
15765      ;}, {$$s: self});
15766      return result;
15767    });
15768    
15769    $def(self, '$>', function $Hash_$gt$5(other) {
15770      var self = this;
15771
15772      
15773      other = $Opal['$coerce_to!'](other, $$$('Hash'), "to_hash");
15774      
15775      if (self.$$keys.length <= other.$$keys.length) {
15776        return false
15777      }
15778    ;
15779      return $rb_ge(self, other);
15780    });
15781    
15782    $def(self, '$<', function $Hash_$lt$6(other) {
15783      var self = this;
15784
15785      
15786      other = $Opal['$coerce_to!'](other, $$$('Hash'), "to_hash");
15787      return $rb_gt(other, self);
15788    });
15789    
15790    $def(self, '$<=', function $Hash_$lt_eq$7(other) {
15791      var self = this;
15792
15793      
15794      other = $Opal['$coerce_to!'](other, $$$('Hash'), "to_hash");
15795      return $rb_ge(other, self);
15796    });
15797    
15798    $def(self, '$[]', function $Hash_$$$8(key) {
15799      var self = this;
15800
15801      
15802      var value = $hash_get(self, key);
15803
15804      if (value !== undefined) {
15805        return value;
15806      }
15807
15808      return self.$default(key);
15809    
15810    });
15811    
15812    $def(self, '$[]=', function $Hash_$$$eq$9(key, value) {
15813      var self = this;
15814
15815      
15816      $deny_frozen_access(self);
15817
15818      $hash_put(self, key, value);
15819      return value;
15820    
15821    });
15822    
15823    $def(self, '$assoc', function $$assoc(object) {
15824      var self = this;
15825
15826      
15827      for (var i = 0, keys = self.$$keys, length = keys.length, key; i < length; i++) {
15828        key = keys[i];
15829
15830        if (key.$$is_string) {
15831          if ((key)['$=='](object)) {
15832            return [key, self.$$smap[key]];
15833          }
15834        } else {
15835          if ((key.key)['$=='](object)) {
15836            return [key.key, key.value];
15837          }
15838        }
15839      }
15840
15841      return nil;
15842    
15843    });
15844    
15845    $def(self, '$clear', function $$clear() {
15846      var self = this;
15847
15848      
15849      $deny_frozen_access(self);
15850
15851      $hash_init(self);
15852      return self;
15853    
15854    });
15855    
15856    $def(self, '$clone', function $$clone() {
15857      var self = this;
15858
15859      
15860      var hash = new self.$$class();
15861
15862      $hash_init(hash);
15863      Opal.hash_clone(self, hash);
15864
15865      return hash;
15866    
15867    });
15868    
15869    $def(self, '$compact', function $$compact() {
15870      var self = this;
15871
15872      
15873      var hash = $hash();
15874
15875      for (var i = 0, keys = self.$$keys, length = keys.length, key, value, obj; i < length; i++) {
15876        key = keys[i];
15877
15878        if (key.$$is_string) {
15879          value = self.$$smap[key];
15880        } else {
15881          value = key.value;
15882          key = key.key;
15883        }
15884
15885        if (value !== nil) {
15886          $hash_put(hash, key, value);
15887        }
15888      }
15889
15890      return hash;
15891    
15892    });
15893    
15894    $def(self, '$compact!', function $Hash_compact$excl$10() {
15895      var self = this;
15896
15897      
15898      $deny_frozen_access(self);
15899
15900      var changes_were_made = false;
15901
15902      for (var i = 0, keys = self.$$keys, length = keys.length, key, value, obj; i < length; i++) {
15903        key = keys[i];
15904
15905        if (key.$$is_string) {
15906          value = self.$$smap[key];
15907        } else {
15908          value = key.value;
15909          key = key.key;
15910        }
15911
15912        if (value === nil) {
15913          if ($hash_delete(self, key) !== undefined) {
15914            changes_were_made = true;
15915            length--;
15916            i--;
15917          }
15918        }
15919      }
15920
15921      return changes_were_made ? self : nil;
15922    
15923    });
15924    
15925    $def(self, '$compare_by_identity', function $$compare_by_identity() {
15926      var self = this;
15927
15928      
15929      $deny_frozen_access(self);
15930
15931      var i, ii, key, keys = self.$$keys, identity_hash;
15932
15933      if (self.$$by_identity) return self;
15934      if (self.$$keys.length === 0) {
15935        self.$$by_identity = true
15936        return self;
15937      }
15938
15939      identity_hash = $hash2([], {}).$compare_by_identity();
15940      for(i = 0, ii = keys.length; i < ii; i++) {
15941        key = keys[i];
15942        if (!key.$$is_string) key = key.key;
15943        $hash_put(identity_hash, key, $hash_get(self, key));
15944      }
15945
15946      self.$$by_identity = true;
15947      self.$$map = identity_hash.$$map;
15948      self.$$smap = identity_hash.$$smap;
15949      return self;
15950    
15951    });
15952    
15953    $def(self, '$compare_by_identity?', function $Hash_compare_by_identity$ques$11() {
15954      var self = this;
15955
15956      return self.$$by_identity === true;
15957    });
15958    
15959    $def(self, '$default', function $Hash_default$12(key) {
15960      var self = this;
15961
15962      
15963      ;
15964      
15965      if (key !== undefined && self.$$proc !== nil && self.$$proc !== undefined) {
15966        return self.$$proc.$call(self, key);
15967      }
15968      if (self.$$none === undefined) {
15969        return nil;
15970      }
15971      return self.$$none;
15972    ;
15973    }, -1);
15974    
15975    $def(self, '$default=', function $Hash_default$eq$13(object) {
15976      var self = this;
15977
15978      
15979      $deny_frozen_access(self);
15980
15981      self.$$proc = nil;
15982      self.$$none = object;
15983
15984      return object;
15985    
15986    });
15987    
15988    $def(self, '$default_proc', function $$default_proc() {
15989      var self = this;
15990
15991      
15992      if (self.$$proc !== undefined) {
15993        return self.$$proc;
15994      }
15995      return nil;
15996    
15997    });
15998    
15999    $def(self, '$default_proc=', function $Hash_default_proc$eq$14(default_proc) {
16000      var self = this;
16001
16002      
16003      $deny_frozen_access(self);
16004
16005      var proc = default_proc;
16006
16007      if (proc !== nil) {
16008        proc = $Opal['$coerce_to!'](proc, $$$('Proc'), "to_proc");
16009
16010        if ((proc)['$lambda?']() && (proc).$arity().$abs() !== 2) {
16011          $Kernel.$raise($$$('TypeError'), "default_proc takes two arguments");
16012        }
16013      }
16014
16015      self.$$none = nil;
16016      self.$$proc = proc;
16017
16018      return default_proc;
16019    
16020    });
16021    
16022    $def(self, '$delete', function $Hash_delete$15(key) {
16023      var block = $Hash_delete$15.$$p || nil, self = this;
16024
16025      $Hash_delete$15.$$p = null;
16026      
16027      ;
16028      
16029      $deny_frozen_access(self);
16030      var value = $hash_delete(self, key);
16031
16032      if (value !== undefined) {
16033        return value;
16034      }
16035
16036      if (block !== nil) {
16037        return Opal.yield1(block, key);
16038      }
16039
16040      return nil;
16041    ;
16042    });
16043    
16044    $def(self, '$delete_if', function $$delete_if() {
16045      var block = $$delete_if.$$p || nil, self = this;
16046
16047      $$delete_if.$$p = null;
16048      
16049      ;
16050      if (!$truthy(block)) {
16051        return $send(self, 'enum_for', ["delete_if"], function $$16(){var self = $$16.$$s == null ? this : $$16.$$s;
16052
16053          return self.$size()}, {$$s: self})
16054      };
16055      
16056      $deny_frozen_access(self);
16057
16058      for (var i = 0, keys = self.$$keys, length = keys.length, key, value, obj; i < length; i++) {
16059        key = keys[i];
16060
16061        if (key.$$is_string) {
16062          value = self.$$smap[key];
16063        } else {
16064          value = key.value;
16065          key = key.key;
16066        }
16067
16068        obj = block(key, value);
16069
16070        if (obj !== false && obj !== nil) {
16071          if ($hash_delete(self, key) !== undefined) {
16072            length--;
16073            i--;
16074          }
16075        }
16076      }
16077
16078      return self;
16079    ;
16080    });
16081    
16082    $def(self, '$dig', function $$dig(key, $a) {
16083      var $post_args, keys, self = this, item = nil;
16084
16085      
16086      $post_args = $slice(arguments, 1);
16087      keys = $post_args;
16088      item = self['$[]'](key);
16089      
16090      if (item === nil || keys.length === 0) {
16091        return item;
16092      }
16093    ;
16094      if (!$truthy(item['$respond_to?']("dig"))) {
16095        $Kernel.$raise($$$('TypeError'), "" + (item.$class()) + " does not have #dig method")
16096      };
16097      return $send(item, 'dig', $to_a(keys));
16098    }, -2);
16099    
16100    $def(self, '$each', function $$each() {
16101      var block = $$each.$$p || nil, self = this;
16102
16103      $$each.$$p = null;
16104      
16105      ;
16106      if (!$truthy(block)) {
16107        return $send(self, 'enum_for', ["each"], function $$17(){var self = $$17.$$s == null ? this : $$17.$$s;
16108
16109          return self.$size()}, {$$s: self})
16110      };
16111      
16112      for (var i = 0, keys = self.$$keys.slice(), length = keys.length, key, value; i < length; i++) {
16113        key = keys[i];
16114
16115        if (key.$$is_string) {
16116          value = self.$$smap[key];
16117        } else {
16118          value = key.value;
16119          key = key.key;
16120        }
16121
16122        $yield1(block, [key, value]);
16123      }
16124
16125      return self;
16126    ;
16127    });
16128    
16129    $def(self, '$each_key', function $$each_key() {
16130      var block = $$each_key.$$p || nil, self = this;
16131
16132      $$each_key.$$p = null;
16133      
16134      ;
16135      if (!$truthy(block)) {
16136        return $send(self, 'enum_for', ["each_key"], function $$18(){var self = $$18.$$s == null ? this : $$18.$$s;
16137
16138          return self.$size()}, {$$s: self})
16139      };
16140      
16141      for (var i = 0, keys = self.$$keys.slice(), length = keys.length, key; i < length; i++) {
16142        key = keys[i];
16143
16144        block(key.$$is_string ? key : key.key);
16145      }
16146
16147      return self;
16148    ;
16149    });
16150    
16151    $def(self, '$each_value', function $$each_value() {
16152      var block = $$each_value.$$p || nil, self = this;
16153
16154      $$each_value.$$p = null;
16155      
16156      ;
16157      if (!$truthy(block)) {
16158        return $send(self, 'enum_for', ["each_value"], function $$19(){var self = $$19.$$s == null ? this : $$19.$$s;
16159
16160          return self.$size()}, {$$s: self})
16161      };
16162      
16163      for (var i = 0, keys = self.$$keys.slice(), length = keys.length, key; i < length; i++) {
16164        key = keys[i];
16165
16166        block(key.$$is_string ? self.$$smap[key] : key.value);
16167      }
16168
16169      return self;
16170    ;
16171    });
16172    
16173    $def(self, '$empty?', function $Hash_empty$ques$20() {
16174      var self = this;
16175
16176      return self.$$keys.length === 0;
16177    });
16178    
16179    $def(self, '$except', function $$except($a) {
16180      var $post_args, keys, self = this;
16181
16182      
16183      $post_args = $slice(arguments);
16184      keys = $post_args;
16185      return $send(self.$dup(), 'except!', $to_a(keys));
16186    }, -1);
16187    
16188    $def(self, '$except!', function $Hash_except$excl$21($a) {
16189      var $post_args, keys, self = this;
16190
16191      
16192      $post_args = $slice(arguments);
16193      keys = $post_args;
16194      $send(keys, 'each', [], function $$22(key){var self = $$22.$$s == null ? this : $$22.$$s;
16195
16196        
16197        if (key == null) key = nil;
16198        return self.$delete(key);}, {$$s: self});
16199      return self;
16200    }, -1);
16201    
16202    $def(self, '$fetch', function $$fetch(key, defaults) {
16203      var block = $$fetch.$$p || nil, self = this;
16204
16205      $$fetch.$$p = null;
16206      
16207      ;
16208      ;
16209      
16210      var value = $hash_get(self, key);
16211
16212      if (value !== undefined) {
16213        return value;
16214      }
16215
16216      if (block !== nil) {
16217        return block(key);
16218      }
16219
16220      if (defaults !== undefined) {
16221        return defaults;
16222      }
16223    ;
16224      return $Kernel.$raise($$$('KeyError').$new("key not found: " + (key.$inspect()), $hash2(["key", "receiver"], {"key": key, "receiver": self})));
16225    }, -2);
16226    
16227    $def(self, '$fetch_values', function $$fetch_values($a) {
16228      var block = $$fetch_values.$$p || nil, $post_args, keys, self = this;
16229
16230      $$fetch_values.$$p = null;
16231      
16232      ;
16233      $post_args = $slice(arguments);
16234      keys = $post_args;
16235      return $send(keys, 'map', [], function $$23(key){var self = $$23.$$s == null ? this : $$23.$$s;
16236
16237        
16238        if (key == null) key = nil;
16239        return $send(self, 'fetch', [key], block.$to_proc());}, {$$s: self});
16240    }, -1);
16241    
16242    $def(self, '$flatten', function $$flatten(level) {
16243      var self = this;
16244
16245      
16246      if (level == null) level = 1;
16247      level = $Opal['$coerce_to!'](level, $$$('Integer'), "to_int");
16248      
16249      var result = [];
16250
16251      for (var i = 0, keys = self.$$keys, length = keys.length, key, value; i < length; i++) {
16252        key = keys[i];
16253
16254        if (key.$$is_string) {
16255          value = self.$$smap[key];
16256        } else {
16257          value = key.value;
16258          key = key.key;
16259        }
16260
16261        result.push(key);
16262
16263        if (value.$$is_array) {
16264          if (level === 1) {
16265            result.push(value);
16266            continue;
16267          }
16268
16269          result = result.concat((value).$flatten(level - 2));
16270          continue;
16271        }
16272
16273        result.push(value);
16274      }
16275
16276      return result;
16277    ;
16278    }, -1);
16279    
16280    $def(self, '$freeze', function $$freeze() {
16281      var self = this;
16282
16283      
16284      if ($truthy(self['$frozen?']())) {
16285        return self
16286      };
16287      return $freeze(self);;
16288    });
16289    
16290    $def(self, '$has_key?', function $Hash_has_key$ques$24(key) {
16291      var self = this;
16292
16293      return $hash_get(self, key) !== undefined;
16294    });
16295    
16296    $def(self, '$has_value?', function $Hash_has_value$ques$25(value) {
16297      var self = this;
16298
16299      
16300      for (var i = 0, keys = self.$$keys, length = keys.length, key; i < length; i++) {
16301        key = keys[i];
16302
16303        if (((key.$$is_string ? self.$$smap[key] : key.value))['$=='](value)) {
16304          return true;
16305        }
16306      }
16307
16308      return false;
16309    
16310    });
16311    
16312    $def(self, '$hash', function $$hash() {
16313      var self = this;
16314
16315      
16316      var top = (Opal.hash_ids === undefined),
16317          hash_id = self.$object_id(),
16318          result = ['Hash'],
16319          key, item;
16320
16321      try {
16322        if (top) {
16323          Opal.hash_ids = Object.create(null);
16324        }
16325
16326        if (Opal[hash_id]) {
16327          return 'self';
16328        }
16329
16330        for (key in Opal.hash_ids) {
16331          item = Opal.hash_ids[key];
16332          if (self['$eql?'](item)) {
16333            return 'self';
16334          }
16335        }
16336
16337        Opal.hash_ids[hash_id] = self;
16338
16339        for (var i = 0, keys = self.$$keys, length = keys.length; i < length; i++) {
16340          key = keys[i];
16341
16342          if (key.$$is_string) {
16343            result.push([key, self.$$smap[key].$hash()]);
16344          } else {
16345            result.push([key.key_hash, key.value.$hash()]);
16346          }
16347        }
16348
16349        return result.sort().join();
16350
16351      } finally {
16352        if (top) {
16353          Opal.hash_ids = undefined;
16354        }
16355      }
16356    
16357    });
16358    
16359    $def(self, '$index', function $$index(object) {
16360      var self = this;
16361
16362      
16363      for (var i = 0, keys = self.$$keys, length = keys.length, key, value; i < length; i++) {
16364        key = keys[i];
16365
16366        if (key.$$is_string) {
16367          value = self.$$smap[key];
16368        } else {
16369          value = key.value;
16370          key = key.key;
16371        }
16372
16373        if ((value)['$=='](object)) {
16374          return key;
16375        }
16376      }
16377
16378      return nil;
16379    
16380    });
16381    
16382    $def(self, '$indexes', function $$indexes($a) {
16383      var $post_args, args, self = this;
16384
16385      
16386      $post_args = $slice(arguments);
16387      args = $post_args;
16388      
16389      var result = [];
16390
16391      for (var i = 0, length = args.length, key, value; i < length; i++) {
16392        key = args[i];
16393        value = $hash_get(self, key);
16394
16395        if (value === undefined) {
16396          result.push(self.$default());
16397          continue;
16398        }
16399
16400        result.push(value);
16401      }
16402
16403      return result;
16404    ;
16405    }, -1);
16406    var inspect_ids;
16407    
16408    $def(self, '$inspect', function $$inspect() {
16409      var self = this;
16410
16411      
16412      
16413      var top = (inspect_ids === undefined),
16414          hash_id = self.$object_id(),
16415          result = [];
16416    ;
16417      
16418      return (function() { try {
16419      
16420      
16421        if (top) {
16422          inspect_ids = {};
16423        }
16424
16425        if (inspect_ids.hasOwnProperty(hash_id)) {
16426          return '{...}';
16427        }
16428
16429        inspect_ids[hash_id] = true;
16430
16431        for (var i = 0, keys = self.$$keys, length = keys.length, key, value; i < length; i++) {
16432          key = keys[i];
16433
16434          if (key.$$is_string) {
16435            value = self.$$smap[key];
16436          } else {
16437            value = key.value;
16438            key = key.key;
16439          }
16440
16441          key = $$('Opal').$inspect(key)
16442          value = $$('Opal').$inspect(value)
16443
16444          result.push(key + '=>' + value);
16445        }
16446
16447        return '{' + result.join(', ') + '}';
16448      ;
16449      return nil;
16450      } finally {
16451        if (top) inspect_ids = undefined
16452      }; })();;
16453    });
16454    
16455    $def(self, '$invert', function $$invert() {
16456      var self = this;
16457
16458      
16459      var hash = $hash();
16460
16461      for (var i = 0, keys = self.$$keys, length = keys.length, key, value; i < length; i++) {
16462        key = keys[i];
16463
16464        if (key.$$is_string) {
16465          value = self.$$smap[key];
16466        } else {
16467          value = key.value;
16468          key = key.key;
16469        }
16470
16471        $hash_put(hash, value, key);
16472      }
16473
16474      return hash;
16475    
16476    });
16477    
16478    $def(self, '$keep_if', function $$keep_if() {
16479      var block = $$keep_if.$$p || nil, self = this;
16480
16481      $$keep_if.$$p = null;
16482      
16483      ;
16484      if (!$truthy(block)) {
16485        return $send(self, 'enum_for', ["keep_if"], function $$26(){var self = $$26.$$s == null ? this : $$26.$$s;
16486
16487          return self.$size()}, {$$s: self})
16488      };
16489      
16490      $deny_frozen_access(self);
16491
16492      for (var i = 0, keys = self.$$keys, length = keys.length, key, value, obj; i < length; i++) {
16493        key = keys[i];
16494
16495        if (key.$$is_string) {
16496          value = self.$$smap[key];
16497        } else {
16498          value = key.value;
16499          key = key.key;
16500        }
16501
16502        obj = block(key, value);
16503
16504        if (obj === false || obj === nil) {
16505          if ($hash_delete(self, key) !== undefined) {
16506            length--;
16507            i--;
16508          }
16509        }
16510      }
16511
16512      return self;
16513    ;
16514    });
16515    
16516    $def(self, '$keys', function $$keys() {
16517      var self = this;
16518
16519      
16520      var result = [];
16521
16522      for (var i = 0, keys = self.$$keys, length = keys.length, key; i < length; i++) {
16523        key = keys[i];
16524
16525        if (key.$$is_string) {
16526          result.push(key);
16527        } else {
16528          result.push(key.key);
16529        }
16530      }
16531
16532      return result;
16533    
16534    });
16535    
16536    $def(self, '$length', function $$length() {
16537      var self = this;
16538
16539      return self.$$keys.length;
16540    });
16541    
16542    $def(self, '$merge', function $$merge($a) {
16543      var block = $$merge.$$p || nil, $post_args, others, self = this;
16544
16545      $$merge.$$p = null;
16546      
16547      ;
16548      $post_args = $slice(arguments);
16549      others = $post_args;
16550      return $send(self.$dup(), 'merge!', $to_a(others), block.$to_proc());
16551    }, -1);
16552    
16553    $def(self, '$merge!', function $Hash_merge$excl$27($a) {
16554      var block = $Hash_merge$excl$27.$$p || nil, $post_args, others, self = this;
16555
16556      $Hash_merge$excl$27.$$p = null;
16557      
16558      ;
16559      $post_args = $slice(arguments);
16560      others = $post_args;
16561      
16562      $deny_frozen_access(self);
16563      var i, j, other, other_keys, length, key, value, other_value;
16564      for (i = 0; i < others.length; ++i) {
16565        other = $Opal['$coerce_to!'](others[i], $$$('Hash'), "to_hash");
16566        other_keys = other.$$keys, length = other_keys.length;
16567
16568        if (block === nil) {
16569          for (j = 0; j < length; j++) {
16570            key = other_keys[j];
16571
16572            if (key.$$is_string) {
16573              other_value = other.$$smap[key];
16574            } else {
16575              other_value = key.value;
16576              key = key.key;
16577            }
16578
16579            $hash_put(self, key, other_value);
16580          }
16581        } else {
16582          for (j = 0; j < length; j++) {
16583            key = other_keys[j];
16584
16585            if (key.$$is_string) {
16586              other_value = other.$$smap[key];
16587            } else {
16588              other_value = key.value;
16589              key = key.key;
16590            }
16591
16592            value = $hash_get(self, key);
16593
16594            if (value === undefined) {
16595              $hash_put(self, key, other_value);
16596              continue;
16597            }
16598
16599            $hash_put(self, key, block(key, value, other_value));
16600          }
16601        }
16602      }
16603
16604      return self;
16605    ;
16606    }, -1);
16607    
16608    $def(self, '$rassoc', function $$rassoc(object) {
16609      var self = this;
16610
16611      
16612      for (var i = 0, keys = self.$$keys, length = keys.length, key, value; i < length; i++) {
16613        key = keys[i];
16614
16615        if (key.$$is_string) {
16616          value = self.$$smap[key];
16617        } else {
16618          value = key.value;
16619          key = key.key;
16620        }
16621
16622        if ((value)['$=='](object)) {
16623          return [key, value];
16624        }
16625      }
16626
16627      return nil;
16628    
16629    });
16630    
16631    $def(self, '$rehash', function $$rehash() {
16632      var self = this;
16633
16634      
16635      $deny_frozen_access(self);
16636      Opal.hash_rehash(self);
16637      return self;
16638    
16639    });
16640    
16641    $def(self, '$reject', function $$reject() {
16642      var block = $$reject.$$p || nil, self = this;
16643
16644      $$reject.$$p = null;
16645      
16646      ;
16647      if (!$truthy(block)) {
16648        return $send(self, 'enum_for', ["reject"], function $$28(){var self = $$28.$$s == null ? this : $$28.$$s;
16649
16650          return self.$size()}, {$$s: self})
16651      };
16652      
16653      var hash = $hash();
16654
16655      for (var i = 0, keys = self.$$keys, length = keys.length, key, value, obj; i < length; i++) {
16656        key = keys[i];
16657
16658        if (key.$$is_string) {
16659          value = self.$$smap[key];
16660        } else {
16661          value = key.value;
16662          key = key.key;
16663        }
16664
16665        obj = block(key, value);
16666
16667        if (obj === false || obj === nil) {
16668          $hash_put(hash, key, value);
16669        }
16670      }
16671
16672      return hash;
16673    ;
16674    });
16675    
16676    $def(self, '$reject!', function $Hash_reject$excl$29() {
16677      var block = $Hash_reject$excl$29.$$p || nil, self = this;
16678
16679      $Hash_reject$excl$29.$$p = null;
16680      
16681      ;
16682      if (!$truthy(block)) {
16683        return $send(self, 'enum_for', ["reject!"], function $$30(){var self = $$30.$$s == null ? this : $$30.$$s;
16684
16685          return self.$size()}, {$$s: self})
16686      };
16687      
16688      $deny_frozen_access(self);
16689
16690      var changes_were_made = false;
16691
16692      for (var i = 0, keys = self.$$keys, length = keys.length, key, value, obj; i < length; i++) {
16693        key = keys[i];
16694
16695        if (key.$$is_string) {
16696          value = self.$$smap[key];
16697        } else {
16698          value = key.value;
16699          key = key.key;
16700        }
16701
16702        obj = block(key, value);
16703
16704        if (obj !== false && obj !== nil) {
16705          if ($hash_delete(self, key) !== undefined) {
16706            changes_were_made = true;
16707            length--;
16708            i--;
16709          }
16710        }
16711      }
16712
16713      return changes_were_made ? self : nil;
16714    ;
16715    });
16716    
16717    $def(self, '$replace', function $$replace(other) {
16718      var self = this;
16719
16720      
16721      $deny_frozen_access(self);;
16722      other = $Opal['$coerce_to!'](other, $$$('Hash'), "to_hash");
16723      
16724      $hash_init(self);
16725
16726      for (var i = 0, other_keys = other.$$keys, length = other_keys.length, key, value, other_value; i < length; i++) {
16727        key = other_keys[i];
16728
16729        if (key.$$is_string) {
16730          other_value = other.$$smap[key];
16731        } else {
16732          other_value = key.value;
16733          key = key.key;
16734        }
16735
16736        $hash_put(self, key, other_value);
16737      }
16738    ;
16739      if ($truthy(other.$default_proc())) {
16740        self['$default_proc='](other.$default_proc())
16741      } else {
16742        self['$default='](other.$default())
16743      };
16744      return self;
16745    });
16746    
16747    $def(self, '$select', function $$select() {
16748      var block = $$select.$$p || nil, self = this;
16749
16750      $$select.$$p = null;
16751      
16752      ;
16753      if (!$truthy(block)) {
16754        return $send(self, 'enum_for', ["select"], function $$31(){var self = $$31.$$s == null ? this : $$31.$$s;
16755
16756          return self.$size()}, {$$s: self})
16757      };
16758      
16759      var hash = $hash();
16760
16761      for (var i = 0, keys = self.$$keys, length = keys.length, key, value, obj; i < length; i++) {
16762        key = keys[i];
16763
16764        if (key.$$is_string) {
16765          value = self.$$smap[key];
16766        } else {
16767          value = key.value;
16768          key = key.key;
16769        }
16770
16771        obj = block(key, value);
16772
16773        if (obj !== false && obj !== nil) {
16774          $hash_put(hash, key, value);
16775        }
16776      }
16777
16778      return hash;
16779    ;
16780    });
16781    
16782    $def(self, '$select!', function $Hash_select$excl$32() {
16783      var block = $Hash_select$excl$32.$$p || nil, self = this;
16784
16785      $Hash_select$excl$32.$$p = null;
16786      
16787      ;
16788      if (!$truthy(block)) {
16789        return $send(self, 'enum_for', ["select!"], function $$33(){var self = $$33.$$s == null ? this : $$33.$$s;
16790
16791          return self.$size()}, {$$s: self})
16792      };
16793      
16794      $deny_frozen_access(self);
16795
16796      var result = nil;
16797
16798      for (var i = 0, keys = self.$$keys, length = keys.length, key, value, obj; i < length; i++) {
16799        key = keys[i];
16800
16801        if (key.$$is_string) {
16802          value = self.$$smap[key];
16803        } else {
16804          value = key.value;
16805          key = key.key;
16806        }
16807
16808        obj = block(key, value);
16809
16810        if (obj === false || obj === nil) {
16811          if ($hash_delete(self, key) !== undefined) {
16812            length--;
16813            i--;
16814          }
16815          result = self;
16816        }
16817      }
16818
16819      return result;
16820    ;
16821    });
16822    
16823    $def(self, '$shift', function $$shift() {
16824      var self = this;
16825
16826      
16827      $deny_frozen_access(self);
16828      var keys = self.$$keys,
16829          key;
16830
16831      if (keys.length > 0) {
16832        key = keys[0];
16833
16834        key = key.$$is_string ? key : key.key;
16835
16836        return [key, $hash_delete(self, key)];
16837      }
16838
16839      return nil;
16840    
16841    });
16842    
16843    $def(self, '$slice', function $$slice($a) {
16844      var $post_args, keys, self = this;
16845
16846      
16847      $post_args = $slice(arguments);
16848      keys = $post_args;
16849      
16850      var result = $hash();
16851
16852      for (var i = 0, length = keys.length; i < length; i++) {
16853        var key = keys[i], value = $hash_get(self, key);
16854
16855        if (value !== undefined) {
16856          $hash_put(result, key, value);
16857        }
16858      }
16859
16860      return result;
16861    ;
16862    }, -1);
16863    
16864    $def(self, '$to_a', function $$to_a() {
16865      var self = this;
16866
16867      
16868      var result = [];
16869
16870      for (var i = 0, keys = self.$$keys, length = keys.length, key, value; i < length; i++) {
16871        key = keys[i];
16872
16873        if (key.$$is_string) {
16874          value = self.$$smap[key];
16875        } else {
16876          value = key.value;
16877          key = key.key;
16878        }
16879
16880        result.push([key, value]);
16881      }
16882
16883      return result;
16884    
16885    });
16886    
16887    $def(self, '$to_h', function $$to_h() {
16888      var block = $$to_h.$$p || nil, self = this;
16889
16890      $$to_h.$$p = null;
16891      
16892      ;
16893      if ((block !== nil)) {
16894        return $send(self, 'map', [], block.$to_proc()).$to_h()
16895      };
16896      
16897      if (self.$$class === Opal.Hash) {
16898        return self;
16899      }
16900
16901      var hash = new Opal.Hash();
16902
16903      $hash_init(hash);
16904      Opal.hash_clone(self, hash);
16905
16906      return hash;
16907    ;
16908    });
16909    
16910    $def(self, '$to_hash', $return_self);
16911    
16912    $def(self, '$to_proc', function $$to_proc() {
16913      var self = this;
16914
16915      return $send(self, 'proc', [], function $$34(key){var self = $$34.$$s == null ? this : $$34.$$s;
16916
16917        
16918        ;
16919        
16920        if (key == null) {
16921          $Kernel.$raise($$$('ArgumentError'), "no key given")
16922        }
16923      ;
16924        return self['$[]'](key);}, {$$arity: -1, $$s: self})
16925    });
16926    
16927    $def(self, '$transform_keys', function $$transform_keys() {
16928      var block = $$transform_keys.$$p || nil, self = this;
16929
16930      $$transform_keys.$$p = null;
16931      
16932      ;
16933      if (!$truthy(block)) {
16934        return $send(self, 'enum_for', ["transform_keys"], function $$35(){var self = $$35.$$s == null ? this : $$35.$$s;
16935
16936          return self.$size()}, {$$s: self})
16937      };
16938      
16939      var result = $hash();
16940
16941      for (var i = 0, keys = self.$$keys, length = keys.length, key, value; i < length; i++) {
16942        key = keys[i];
16943
16944        if (key.$$is_string) {
16945          value = self.$$smap[key];
16946        } else {
16947          value = key.value;
16948          key = key.key;
16949        }
16950
16951        key = $yield1(block, key);
16952
16953        $hash_put(result, key, value);
16954      }
16955
16956      return result;
16957    ;
16958    });
16959    
16960    $def(self, '$transform_keys!', function $Hash_transform_keys$excl$36() {
16961      var block = $Hash_transform_keys$excl$36.$$p || nil, self = this;
16962
16963      $Hash_transform_keys$excl$36.$$p = null;
16964      
16965      ;
16966      if (!$truthy(block)) {
16967        return $send(self, 'enum_for', ["transform_keys!"], function $$37(){var self = $$37.$$s == null ? this : $$37.$$s;
16968
16969          return self.$size()}, {$$s: self})
16970      };
16971      
16972      $deny_frozen_access(self);
16973
16974      var keys = Opal.slice(self.$$keys),
16975          i, length = keys.length, key, value, new_key;
16976
16977      for (i = 0; i < length; i++) {
16978        key = keys[i];
16979
16980        if (key.$$is_string) {
16981          value = self.$$smap[key];
16982        } else {
16983          value = key.value;
16984          key = key.key;
16985        }
16986
16987        new_key = $yield1(block, key);
16988
16989        $hash_delete(self, key);
16990        $hash_put(self, new_key, value);
16991      }
16992
16993      return self;
16994    ;
16995    });
16996    
16997    $def(self, '$transform_values', function $$transform_values() {
16998      var block = $$transform_values.$$p || nil, self = this;
16999
17000      $$transform_values.$$p = null;
17001      
17002      ;
17003      if (!$truthy(block)) {
17004        return $send(self, 'enum_for', ["transform_values"], function $$38(){var self = $$38.$$s == null ? this : $$38.$$s;
17005
17006          return self.$size()}, {$$s: self})
17007      };
17008      
17009      var result = $hash();
17010
17011      for (var i = 0, keys = self.$$keys, length = keys.length, key, value; i < length; i++) {
17012        key = keys[i];
17013
17014        if (key.$$is_string) {
17015          value = self.$$smap[key];
17016        } else {
17017          value = key.value;
17018          key = key.key;
17019        }
17020
17021        value = $yield1(block, value);
17022
17023        $hash_put(result, key, value);
17024      }
17025
17026      return result;
17027    ;
17028    });
17029    
17030    $def(self, '$transform_values!', function $Hash_transform_values$excl$39() {
17031      var block = $Hash_transform_values$excl$39.$$p || nil, self = this;
17032
17033      $Hash_transform_values$excl$39.$$p = null;
17034      
17035      ;
17036      if (!$truthy(block)) {
17037        return $send(self, 'enum_for', ["transform_values!"], function $$40(){var self = $$40.$$s == null ? this : $$40.$$s;
17038
17039          return self.$size()}, {$$s: self})
17040      };
17041      
17042      $deny_frozen_access(self);
17043
17044      for (var i = 0, keys = self.$$keys, length = keys.length, key, value; i < length; i++) {
17045        key = keys[i];
17046
17047        if (key.$$is_string) {
17048          value = self.$$smap[key];
17049        } else {
17050          value = key.value;
17051          key = key.key;
17052        }
17053
17054        value = $yield1(block, value);
17055
17056        $hash_put(self, key, value);
17057      }
17058
17059      return self;
17060    ;
17061    });
17062    
17063    $def(self, '$values', function $$values() {
17064      var self = this;
17065
17066      
17067      var result = [];
17068
17069      for (var i = 0, keys = self.$$keys, length = keys.length, key; i < length; i++) {
17070        key = keys[i];
17071
17072        if (key.$$is_string) {
17073          result.push(self.$$smap[key]);
17074        } else {
17075          result.push(key.value);
17076        }
17077      }
17078
17079      return result;
17080    
17081    });
17082    $alias(self, "dup", "clone");
17083    $alias(self, "each_pair", "each");
17084    $alias(self, "eql?", "==");
17085    $alias(self, "filter", "select");
17086    $alias(self, "filter!", "select!");
17087    $alias(self, "include?", "has_key?");
17088    $alias(self, "indices", "indexes");
17089    $alias(self, "key", "index");
17090    $alias(self, "key?", "has_key?");
17091    $alias(self, "member?", "has_key?");
17092    $alias(self, "size", "length");
17093    $alias(self, "store", "[]=");
17094    $alias(self, "to_s", "inspect");
17095    $alias(self, "update", "merge!");
17096    $alias(self, "value?", "has_value?");
17097    return $alias(self, "values_at", "indexes");
17098  })('::', null, $nesting);
17099};
17100
17101Opal.modules["corelib/number"] = function(Opal) {/* Generated by Opal 1.7.3 */
17102  var $klass = Opal.klass, $Opal = Opal.Opal, $Kernel = Opal.Kernel, $def = Opal.def, $eqeqeq = Opal.eqeqeq, $truthy = Opal.truthy, $rb_gt = Opal.rb_gt, $not = Opal.not, $rb_lt = Opal.rb_lt, $alias = Opal.alias, $send2 = Opal.send2, $find_super = Opal.find_super, $send = Opal.send, $rb_plus = Opal.rb_plus, $rb_minus = Opal.rb_minus, $eqeq = Opal.eqeq, $return_self = Opal.return_self, $rb_divide = Opal.rb_divide, $to_ary = Opal.to_ary, $rb_times = Opal.rb_times, $rb_le = Opal.rb_le, $rb_ge = Opal.rb_ge, $return_val = Opal.return_val, $const_set = Opal.const_set, self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$;
17103
17104  Opal.add_stubs('require,bridge,raise,name,class,Float,respond_to?,coerce_to!,__coerced__,===,>,!,**,new,<,to_f,==,nan?,infinite?,enum_for,+,-,gcd,lcm,%,/,frexp,to_i,ldexp,rationalize,*,<<,to_r,truncate,-@,size,<=,>=,inspect,angle,to_s,is_a?,abs,__id__,next,coerce_to?');
17105  
17106  self.$require("corelib/numeric");
17107  (function($base, $super, $parent_nesting) {
17108    var self = $klass($base, $super, 'Number');
17109
17110    var $nesting = [self].concat($parent_nesting);
17111
17112    
17113    $Opal.$bridge(Number, self);
17114    Opal.prop(self.$$prototype, '$$is_number', true);
17115    self.$$is_number_class = true;
17116    (function(self, $parent_nesting) {
17117      
17118      
17119      
17120      $def(self, '$allocate', function $$allocate() {
17121        var self = this;
17122
17123        return $Kernel.$raise($$$('TypeError'), "allocator undefined for " + (self.$name()))
17124      });
17125      
17126      
17127      Opal.udef(self, '$' + "new");;
17128      return nil;;
17129    })(Opal.get_singleton_class(self), $nesting);
17130    
17131    $def(self, '$coerce', function $$coerce(other) {
17132      var self = this;
17133
17134      
17135      if (other === nil) {
17136        $Kernel.$raise($$$('TypeError'), "can't convert " + (other.$class()) + " into Float");
17137      }
17138      else if (other.$$is_string) {
17139        return [$Kernel.$Float(other), self];
17140      }
17141      else if (other['$respond_to?']("to_f")) {
17142        return [$Opal['$coerce_to!'](other, $$$('Float'), "to_f"), self];
17143      }
17144      else if (other.$$is_number) {
17145        return [other, self];
17146      }
17147      else {
17148        $Kernel.$raise($$$('TypeError'), "can't convert " + (other.$class()) + " into Float");
17149      }
17150    
17151    });
17152    
17153    $def(self, '$__id__', function $$__id__() {
17154      var self = this;
17155
17156      return (self * 2) + 1;
17157    });
17158    
17159    $def(self, '$+', function $Number_$plus$1(other) {
17160      var self = this;
17161
17162      
17163      if (other.$$is_number) {
17164        return self + other;
17165      }
17166      else {
17167        return self.$__coerced__("+", other);
17168      }
17169    
17170    });
17171    
17172    $def(self, '$-', function $Number_$minus$2(other) {
17173      var self = this;
17174
17175      
17176      if (other.$$is_number) {
17177        return self - other;
17178      }
17179      else {
17180        return self.$__coerced__("-", other);
17181      }
17182    
17183    });
17184    
17185    $def(self, '$*', function $Number_$$3(other) {
17186      var self = this;
17187
17188      
17189      if (other.$$is_number) {
17190        return self * other;
17191      }
17192      else {
17193        return self.$__coerced__("*", other);
17194      }
17195    
17196    });
17197    
17198    $def(self, '$/', function $Number_$slash$4(other) {
17199      var self = this;
17200
17201      
17202      if (other.$$is_number) {
17203        return self / other;
17204      }
17205      else {
17206        return self.$__coerced__("/", other);
17207      }
17208    
17209    });
17210    
17211    $def(self, '$%', function $Number_$percent$5(other) {
17212      var self = this;
17213
17214      
17215      if (other.$$is_number) {
17216        if (other == -Infinity) {
17217          return other;
17218        }
17219        else if (other == 0) {
17220          $Kernel.$raise($$$('ZeroDivisionError'), "divided by 0");
17221        }
17222        else if (other < 0 || self < 0) {
17223          return (self % other + other) % other;
17224        }
17225        else {
17226          return self % other;
17227        }
17228      }
17229      else {
17230        return self.$__coerced__("%", other);
17231      }
17232    
17233    });
17234    
17235    $def(self, '$&', function $Number_$$6(other) {
17236      var self = this;
17237
17238      
17239      if (other.$$is_number) {
17240        return self & other;
17241      }
17242      else {
17243        return self.$__coerced__("&", other);
17244      }
17245    
17246    });
17247    
17248    $def(self, '$|', function $Number_$$7(other) {
17249      var self = this;
17250
17251      
17252      if (other.$$is_number) {
17253        return self | other;
17254      }
17255      else {
17256        return self.$__coerced__("|", other);
17257      }
17258    
17259    });
17260    
17261    $def(self, '$^', function $Number_$$8(other) {
17262      var self = this;
17263
17264      
17265      if (other.$$is_number) {
17266        return self ^ other;
17267      }
17268      else {
17269        return self.$__coerced__("^", other);
17270      }
17271    
17272    });
17273    
17274    $def(self, '$<', function $Number_$lt$9(other) {
17275      var self = this;
17276
17277      
17278      if (other.$$is_number) {
17279        return self < other;
17280      }
17281      else {
17282        return self.$__coerced__("<", other);
17283      }
17284    
17285    });
17286    
17287    $def(self, '$<=', function $Number_$lt_eq$10(other) {
17288      var self = this;
17289
17290      
17291      if (other.$$is_number) {
17292        return self <= other;
17293      }
17294      else {
17295        return self.$__coerced__("<=", other);
17296      }
17297    
17298    });
17299    
17300    $def(self, '$>', function $Number_$gt$11(other) {
17301      var self = this;
17302
17303      
17304      if (other.$$is_number) {
17305        return self > other;
17306      }
17307      else {
17308        return self.$__coerced__(">", other);
17309      }
17310    
17311    });
17312    
17313    $def(self, '$>=', function $Number_$gt_eq$12(other) {
17314      var self = this;
17315
17316      
17317      if (other.$$is_number) {
17318        return self >= other;
17319      }
17320      else {
17321        return self.$__coerced__(">=", other);
17322      }
17323    
17324    });
17325    
17326    var spaceship_operator = function(self, other) {
17327      if (other.$$is_number) {
17328        if (isNaN(self) || isNaN(other)) {
17329          return nil;
17330        }
17331
17332        if (self > other) {
17333          return 1;
17334        } else if (self < other) {
17335          return -1;
17336        } else {
17337          return 0;
17338        }
17339      }
17340      else {
17341        return self.$__coerced__("<=>", other);
17342      }
17343    }
17344  ;
17345    
17346    $def(self, '$<=>', function $Number_$lt_eq_gt$13(other) {
17347      var self = this;
17348
17349      try {
17350        return spaceship_operator(self, other);
17351      } catch ($err) {
17352        if (Opal.rescue($err, [$$$('ArgumentError')])) {
17353          try {
17354            return nil
17355          } finally { Opal.pop_exception(); }
17356        } else { throw $err; }
17357      }
17358    });
17359    
17360    $def(self, '$<<', function $Number_$lt$lt$14(count) {
17361      var self = this;
17362
17363      
17364      count = $Opal['$coerce_to!'](count, $$$('Integer'), "to_int");
17365      return count > 0 ? self << count : self >> -count;
17366    });
17367    
17368    $def(self, '$>>', function $Number_$gt$gt$15(count) {
17369      var self = this;
17370
17371      
17372      count = $Opal['$coerce_to!'](count, $$$('Integer'), "to_int");
17373      return count > 0 ? self >> count : self << -count;
17374    });
17375    
17376    $def(self, '$[]', function $Number_$$$16(bit) {
17377      var self = this;
17378
17379      
17380      bit = $Opal['$coerce_to!'](bit, $$$('Integer'), "to_int");
17381      
17382      if (bit < 0) {
17383        return 0;
17384      }
17385      if (bit >= 32) {
17386        return self < 0 ? 1 : 0;
17387      }
17388      return (self >> bit) & 1;
17389    ;
17390    });
17391    
17392    $def(self, '$+@', function $Number_$plus$$17() {
17393      var self = this;
17394
17395      return +self;
17396    });
17397    
17398    $def(self, '$-@', function $Number_$minus$$18() {
17399      var self = this;
17400
17401      return -self;
17402    });
17403    
17404    $def(self, '$~', function $Number_$$19() {
17405      var self = this;
17406
17407      return ~self;
17408    });
17409    
17410    $def(self, '$**', function $Number_$$$20(other) {
17411      var self = this;
17412
17413      if ($eqeqeq($$$('Integer'), other)) {
17414        if (($not($$$('Integer')['$==='](self)) || ($truthy($rb_gt(other, 0))))) {
17415          return Math.pow(self, other);
17416        } else {
17417          return $$$('Rational').$new(self, 1)['$**'](other)
17418        }
17419      } else if (($rb_lt(self, 0) && (($eqeqeq($$$('Float'), other) || ($eqeqeq($$$('Rational'), other)))))) {
17420        return $$$('Complex').$new(self, 0)['$**'](other.$to_f())
17421      } else if ($truthy(other.$$is_number != null)) {
17422        return Math.pow(self, other);
17423      } else {
17424        return self.$__coerced__("**", other)
17425      }
17426    });
17427    
17428    $def(self, '$==', function $Number_$eq_eq$21(other) {
17429      var self = this;
17430
17431      
17432      if (other.$$is_number) {
17433        return self.valueOf() === other.valueOf();
17434      }
17435      else if (other['$respond_to?']("==")) {
17436        return other['$=='](self);
17437      }
17438      else {
17439        return false;
17440      }
17441    
17442    });
17443    $alias(self, "===", "==");
17444    
17445    $def(self, '$abs', function $$abs() {
17446      var self = this;
17447
17448      return Math.abs(self);
17449    });
17450    
17451    $def(self, '$abs2', function $$abs2() {
17452      var self = this;
17453
17454      return Math.abs(self * self);
17455    });
17456    
17457    $def(self, '$allbits?', function $Number_allbits$ques$22(mask) {
17458      var self = this;
17459
17460      
17461      mask = $Opal['$coerce_to!'](mask, $$$('Integer'), "to_int");
17462      return (self & mask) == mask;;
17463    });
17464    
17465    $def(self, '$anybits?', function $Number_anybits$ques$23(mask) {
17466      var self = this;
17467
17468      
17469      mask = $Opal['$coerce_to!'](mask, $$$('Integer'), "to_int");
17470      return (self & mask) !== 0;;
17471    });
17472    
17473    $def(self, '$angle', function $$angle() {
17474      var self = this;
17475
17476      
17477      if ($truthy(self['$nan?']())) {
17478        return self
17479      };
17480      
17481      if (self == 0) {
17482        if (1 / self > 0) {
17483          return 0;
17484        }
17485        else {
17486          return Math.PI;
17487        }
17488      }
17489      else if (self < 0) {
17490        return Math.PI;
17491      }
17492      else {
17493        return 0;
17494      }
17495    ;
17496    });
17497    
17498    $def(self, '$bit_length', function $$bit_length() {
17499      var self = this;
17500
17501      
17502      if (!$eqeqeq($$$('Integer'), self)) {
17503        $Kernel.$raise($$$('NoMethodError').$new("undefined method `bit_length` for " + (self) + ":Float", "bit_length"))
17504      };
17505      
17506      if (self === 0 || self === -1) {
17507        return 0;
17508      }
17509
17510      var result = 0,
17511          value  = self < 0 ? ~self : self;
17512
17513      while (value != 0) {
17514        result   += 1;
17515        value  >>>= 1;
17516      }
17517
17518      return result;
17519    ;
17520    });
17521    
17522    $def(self, '$ceil', function $$ceil(ndigits) {
17523      var self = this;
17524
17525      
17526      if (ndigits == null) ndigits = 0;
17527      
17528      var f = self.$to_f();
17529
17530      if (f % 1 === 0 && ndigits >= 0) {
17531        return f;
17532      }
17533
17534      var factor = Math.pow(10, ndigits),
17535          result = Math.ceil(f * factor) / factor;
17536
17537      if (f % 1 === 0) {
17538        result = Math.round(result);
17539      }
17540
17541      return result;
17542    ;
17543    }, -1);
17544    
17545    $def(self, '$chr', function $$chr(encoding) {
17546      var self = this;
17547
17548      
17549      ;
17550      return Opal.enc(String.fromCharCode(self), encoding || "BINARY");;
17551    }, -1);
17552    
17553    $def(self, '$denominator', function $$denominator() {
17554      var $yield = $$denominator.$$p || nil, self = this;
17555
17556      $$denominator.$$p = null;
17557      if (($truthy(self['$nan?']()) || ($truthy(self['$infinite?']())))) {
17558        return 1
17559      } else {
17560        return $send2(self, $find_super(self, 'denominator', $$denominator, false, true), 'denominator', [], $yield)
17561      }
17562    });
17563    
17564    $def(self, '$downto', function $$downto(stop) {
17565      var block = $$downto.$$p || nil, self = this;
17566
17567      $$downto.$$p = null;
17568      
17569      ;
17570      if (!(block !== nil)) {
17571        return $send(self, 'enum_for', ["downto", stop], function $$24(){var self = $$24.$$s == null ? this : $$24.$$s;
17572
17573          
17574          if (!$eqeqeq($$$('Numeric'), stop)) {
17575            $Kernel.$raise($$$('ArgumentError'), "comparison of " + (self.$class()) + " with " + (stop.$class()) + " failed")
17576          };
17577          if ($truthy($rb_gt(stop, self))) {
17578            return 0
17579          } else {
17580            return $rb_plus($rb_minus(self, stop), 1)
17581          };}, {$$s: self})
17582      };
17583      
17584      if (!stop.$$is_number) {
17585        $Kernel.$raise($$$('ArgumentError'), "comparison of " + (self.$class()) + " with " + (stop.$class()) + " failed")
17586      }
17587      for (var i = self; i >= stop; i--) {
17588        block(i);
17589      }
17590    ;
17591      return self;
17592    });
17593    
17594    $def(self, '$equal?', function $Number_equal$ques$25(other) {
17595      var self = this, $ret_or_1 = nil;
17596
17597      if ($truthy(($ret_or_1 = self['$=='](other)))) {
17598        return $ret_or_1
17599      } else {
17600        return isNaN(self) && isNaN(other);
17601      }
17602    });
17603    
17604    $def(self, '$even?', function $Number_even$ques$26() {
17605      var self = this;
17606
17607      return self % 2 === 0;
17608    });
17609    
17610    $def(self, '$floor', function $$floor(ndigits) {
17611      var self = this;
17612
17613      
17614      if (ndigits == null) ndigits = 0;
17615      
17616      var f = self.$to_f();
17617
17618      if (f % 1 === 0 && ndigits >= 0) {
17619        return f;
17620      }
17621
17622      var factor = Math.pow(10, ndigits),
17623          result = Math.floor(f * factor) / factor;
17624
17625      if (f % 1 === 0) {
17626        result = Math.round(result);
17627      }
17628
17629      return result;
17630    ;
17631    }, -1);
17632    
17633    $def(self, '$gcd', function $$gcd(other) {
17634      var self = this;
17635
17636      
17637      if (!$eqeqeq($$$('Integer'), other)) {
17638        $Kernel.$raise($$$('TypeError'), "not an integer")
17639      };
17640      
17641      var min = Math.abs(self),
17642          max = Math.abs(other);
17643
17644      while (min > 0) {
17645        var tmp = min;
17646
17647        min = max % min;
17648        max = tmp;
17649      }
17650
17651      return max;
17652    ;
17653    });
17654    
17655    $def(self, '$gcdlcm', function $$gcdlcm(other) {
17656      var self = this;
17657
17658      return [self.$gcd(other), self.$lcm(other)]
17659    });
17660    
17661    $def(self, '$integer?', function $Number_integer$ques$27() {
17662      var self = this;
17663
17664      return self % 1 === 0;
17665    });
17666    
17667    $def(self, '$is_a?', function $Number_is_a$ques$28(klass) {
17668      var $yield = $Number_is_a$ques$28.$$p || nil, self = this;
17669
17670      $Number_is_a$ques$28.$$p = null;
17671      
17672      if (($eqeq(klass, $$$('Integer')) && ($eqeqeq($$$('Integer'), self)))
17672) {
17673        return true
17674      };
17675      if (($eqeq(klass, $$$('Integer')) && ($eqeqeq($$$('Integer'), self)))) {
17676        return true
17677      };
17678      if (($eqeq(klass, $$$('Float')) && ($eqeqeq($$$('Float'), self)))) {
17679        return true
17680      };
17681      return $send2(self, $find_super(self, 'is_a?', $Number_is_a$ques$28, false, true), 'is_a?', [klass], $yield);
17682    });
17683    
17684    $def(self, '$instance_of?', function $Number_instance_of$ques$29(klass) {
17685      var $yield = $Number_instance_of$ques$29.$$p || nil, self = this;
17686
17687      $Number_instance_of$ques$29.$$p = null;
17688      
17689      if (($eqeq(klass, $$$('Integer')) && ($eqeqeq($$$('Integer'), self)))) {
17690        return true
17691      };
17692      if (($eqeq(klass, $$$('Integer')) && ($eqeqeq($$$('Integer'), self)))) {
17693        return true
17694      };
17695      if (($eqeq(klass, $$$('Float')) && ($eqeqeq($$$('Float'), self)))) {
17696        return true
17697      };
17698      return $send2(self, $find_super(self, 'instance_of?', $Number_instance_of$ques$29, false, true), 'instance_of?', [klass], $yield);
17699    });
17700    
17701    $def(self, '$lcm', function $$lcm(other) {
17702      var self = this;
17703
17704      
17705      if (!$eqeqeq($$$('Integer'), other)) {
17706        $Kernel.$raise($$$('TypeError'), "not an integer")
17707      };
17708      
17709      if (self == 0 || other == 0) {
17710        return 0;
17711      }
17712      else {
17713        return Math.abs(self * other / self.$gcd(other));
17714      }
17715    ;
17716    });
17717    
17718    $def(self, '$next', function $$next() {
17719      var self = this;
17720
17721      return self + 1;
17722    });
17723    
17724    $def(self, '$nobits?', function $Number_nobits$ques$30(mask) {
17725      var self = this;
17726
17727      
17728      mask = $Opal['$coerce_to!'](mask, $$$('Integer'), "to_int");
17729      return (self & mask) == 0;;
17730    });
17731    
17732    $def(self, '$nonzero?', function $Number_nonzero$ques$31() {
17733      var self = this;
17734
17735      return self == 0 ? nil : self;
17736    });
17737    
17738    $def(self, '$numerator', function $$numerator() {
17739      var $yield = $$numerator.$$p || nil, self = this;
17740
17741      $$numerator.$$p = null;
17742      if (($truthy(self['$nan?']()) || ($truthy(self['$infinite?']())))) {
17743        return self
17744      } else {
17745        return $send2(self, $find_super(self, 'numerator', $$numerator, false, true), 'numerator', [], $yield)
17746      }
17747    });
17748    
17749    $def(self, '$odd?', function $Number_odd$ques$32() {
17750      var self = this;
17751
17752      return self % 2 !== 0;
17753    });
17754    
17755    $def(self, '$ord', $return_self);
17756    
17757    $def(self, '$pow', function $$pow(b, m) {
17758      var self = this;
17759
17760      
17761      ;
17762      
17763      if (self == 0) {
17764        $Kernel.$raise($$$('ZeroDivisionError'), "divided by 0")
17765      }
17766
17767      if (m === undefined) {
17768        return self['$**'](b);
17769      } else {
17770        if (!($$$('Integer')['$==='](b))) {
17771          $Kernel.$raise($$$('TypeError'), "Integer#pow() 2nd argument not allowed unless a 1st argument is integer")
17772        }
17773
17774        if (b < 0) {
17775          $Kernel.$raise($$$('TypeError'), "Integer#pow() 1st argument cannot be negative when 2nd argument specified")
17776        }
17777
17778        if (!($$$('Integer')['$==='](m))) {
17779          $Kernel.$raise($$$('TypeError'), "Integer#pow() 2nd argument not allowed unless all arguments are integers")
17780        }
17781
17782        if (m === 0) {
17783          $Kernel.$raise($$$('ZeroDivisionError'), "divided by 0")
17784        }
17785
17786        return self['$**'](b)['$%'](m)
17787      }
17788    ;
17789    }, -2);
17790    
17791    $def(self, '$pred', function $$pred() {
17792      var self = this;
17793
17794      return self - 1;
17795    });
17796    
17797    $def(self, '$quo', function $$quo(other) {
17798      var $yield = $$quo.$$p || nil, self = this;
17799
17800      $$quo.$$p = null;
17801      if ($eqeqeq($$$('Integer'), self)) {
17802        return $send2(self, $find_super(self, 'quo', $$quo, false, true), 'quo', [other], $yield)
17803      } else {
17804        return $rb_divide(self, other)
17805      }
17806    });
17807    
17808    $def(self, '$rationalize', function $$rationalize(eps) {
17809      var $a, $b, self = this, f = nil, n = nil;
17810
17811      
17812      ;
17813      
17814      if (arguments.length > 1) {
17815        $Kernel.$raise($$$('ArgumentError'), "wrong number of arguments (" + (arguments.length) + " for 0..1)");
17816      }
17817    ;
17818      if ($eqeqeq($$$('Integer'), self)) {
17819        return $$$('Rational').$new(self, 1)
17820      } else if ($truthy(self['$infinite?']())) {
17821        return $Kernel.$raise($$$('FloatDomainError'), "Infinity")
17822      } else if ($truthy(self['$nan?']())) {
17823        return $Kernel.$raise($$$('FloatDomainError'), "NaN")
17824      } else if ($truthy(eps == null)) {
17825        
17826        $b = $$$('Math').$frexp(self), $a = $to_ary($b), (f = ($a[0] == null ? nil : $a[0])), (n = ($a[1] == null ? nil : $a[1])), $b;
17827        f = $$$('Math').$ldexp(f, $$$($$$('Float'), 'MANT_DIG')).$to_i();
17828        n = $rb_minus(n, $$$($$$('Float'), 'MANT_DIG'));
17829        return $$$('Rational').$new($rb_times(2, f), (1)['$<<']($rb_minus(1, n))).$rationalize($$$('Rational').$new(1, (1)['$<<']($rb_minus(1, n))));
17830      } else {
17831        return self.$to_r().$rationalize(eps)
17832      };
17833    }, -1);
17834    
17835    $def(self, '$remainder', function $$remainder(y) {
17836      var self = this;
17837
17838      return $rb_minus(self, $rb_times(y, $rb_divide(self, y).$truncate()))
17839    });
17840    
17841    $def(self, '$round', function $$round(ndigits) {
17842      var $a, $b, self = this, _ = nil, exp = nil;
17843
17844      
17845      ;
17846      if ($eqeqeq($$$('Integer'), self)) {
17847        
17848        if ($truthy(ndigits == null)) {
17849          return self
17850        };
17851        if (($eqeqeq($$$('Float'), ndigits) && ($truthy(ndigits['$infinite?']())))) {
17852          $Kernel.$raise($$$('RangeError'), "Infinity")
17853        };
17854        ndigits = $Opal['$coerce_to!'](ndigits, $$$('Integer'), "to_int");
17855        if ($truthy($rb_lt(ndigits, $$$($$$('Integer'), 'MIN')))) {
17856          $Kernel.$raise($$$('RangeError'), "out of bounds")
17857        };
17858        if ($truthy(ndigits >= 0)) {
17859          return self
17860        };
17861        ndigits = ndigits['$-@']();
17862        
17863        if (0.415241 * ndigits - 0.125 > self.$size()) {
17864          return 0;
17865        }
17866
17867        var f = Math.pow(10, ndigits),
17868            x = Math.floor((Math.abs(self) + f / 2) / f) * f;
17869
17870        return self < 0 ? -x : x;
17871      ;
17872      } else {
17873        
17874        if (($truthy(self['$nan?']()) && ($truthy(ndigits == null)))) {
17875          $Kernel.$raise($$$('FloatDomainError'), "NaN")
17876        };
17877        ndigits = $Opal['$coerce_to!'](ndigits || 0, $$$('Integer'), "to_int");
17878        if ($truthy($rb_le(ndigits, 0))) {
17879          if ($truthy(self['$nan?']())) {
17880            $Kernel.$raise($$$('RangeError'), "NaN")
17881          } else if ($truthy(self['$infinite?']())) {
17882            $Kernel.$raise($$$('FloatDomainError'), "Infinity")
17883          }
17884        } else if ($eqeq(ndigits, 0)) {
17885          return Math.round(self)
17886        } else if (($truthy(self['$nan?']()) || ($truthy(self['$infinite?']())))) {
17887          return self
17888        };
17889        $b = $$$('Math').$frexp(self), $a = $to_ary($b), (_ = ($a[0] == null ? nil : $a[0])), (exp = ($a[1] == null ? nil : $a[1])), $b;
17890        if ($truthy($rb_ge(ndigits, $rb_minus($rb_plus($$$($$$('Float'), 'DIG'), 2), ($truthy($rb_gt(exp, 0)) ? ($rb_divide(exp, 4)) : ($rb_minus($rb_divide(exp, 3), 1))))))) {
17891          return self
17892        };
17893        if ($truthy($rb_lt(ndigits, ($truthy($rb_gt(exp, 0)) ? ($rb_plus($rb_divide(exp, 3), 1)) : ($rb_divide(exp, 4)))['$-@']()))) {
17894          return 0
17895        };
17896        return Math.round(self * Math.pow(10, ndigits)) / Math.pow(10, ndigits);;
17897      };
17898    }, -1);
17899    
17900    $def(self, '$times', function $$times() {
17901      var block = $$times.$$p || nil, self = this;
17902
17903      $$times.$$p = null;
17904      
17905      ;
17906      if (!$truthy(block)) {
17907        return $send(self, 'enum_for', ["times"], function $$33(){var self = $$33.$$s == null ? this : $$33.$$s;
17908
17909          return self}, {$$s: self})
17910      };
17911      
17912      for (var i = 0; i < self; i++) {
17913        block(i);
17914      }
17915    ;
17916      return self;
17917    });
17918    
17919    $def(self, '$to_f', $return_self);
17920    
17921    $def(self, '$to_i', function $$to_i() {
17922      var self = this;
17923
17924      return self < 0 ? Math.ceil(self) : Math.floor(self);
17925    });
17926    
17927    $def(self, '$to_r', function $$to_r() {
17928      var $a, $b, self = this, f = nil, e = nil;
17929
17930      if ($eqeqeq($$$('Integer'), self)) {
17931        return $$$('Rational').$new(self, 1)
17932      } else {
17933        
17934        $b = $$$('Math').$frexp(self), $a = $to_ary($b), (f = ($a[0] == null ? nil : $a[0])), (e = ($a[1] == null ? nil : $a[1])), $b;
17935        f = $$$('Math').$ldexp(f, $$$($$$('Float'), 'MANT_DIG')).$to_i();
17936        e = $rb_minus(e, $$$($$$('Float'), 'MANT_DIG'));
17937        return $rb_times(f, $$$($$$('Float'), 'RADIX')['$**'](e)).$to_r();
17938      }
17939    });
17940    
17941    $def(self, '$to_s', function $$to_s(base) {
17942      var self = this;
17943
17944      
17945      if (base == null) base = 10;
17946      base = $Opal['$coerce_to!'](base, $$$('Integer'), "to_int");
17947      if (($truthy($rb_lt(base, 2)) || ($truthy($rb_gt(base, 36))))) {
17948        $Kernel.$raise($$$('ArgumentError'), "invalid radix " + (base))
17949      };
17950      if (($eqeq(self, 0) && ($truthy(1/self === -Infinity)))) {
17951        return "-0.0"
17952      };
17953      return self.toString(base);;
17954    }, -1);
17955    
17956    $def(self, '$truncate', function $$truncate(ndigits) {
17957      var self = this;
17958
17959      
17960      if (ndigits == null) ndigits = 0;
17961      
17962      var f = self.$to_f();
17963
17964      if (f % 1 === 0 && ndigits >= 0) {
17965        return f;
17966      }
17967
17968      var factor = Math.pow(10, ndigits),
17969          result = parseInt(f * factor, 10) / factor;
17970
17971      if (f % 1 === 0) {
17972        result = Math.round(result);
17973      }
17974
17975      return result;
17976    ;
17977    }, -1);
17978    
17979    $def(self, '$digits', function $$digits(base) {
17980      var self = this;
17981
17982      
17983      if (base == null) base = 10;
17984      if ($rb_lt(self, 0)) {
17985        $Kernel.$raise($$$($$$('Math'), 'DomainError'), "out of domain")
17986      };
17987      base = $Opal['$coerce_to!'](base, $$$('Integer'), "to_int");
17988      if ($truthy($rb_lt(base, 2))) {
17989        $Kernel.$raise($$$('ArgumentError'), "invalid radix " + (base))
17990      };
17991      
17992      if (self != parseInt(self)) $Kernel.$raise($$$('NoMethodError'), "undefined method `digits' for " + (self.$inspect()))
17993
17994      var value = self, result = [];
17995
17996      if (self == 0) {
17997        return [0];
17998      }
17999
18000      while (value != 0) {
18001        result.push(value % base);
18002        value = parseInt(value / base, 10);
18003      }
18004
18005      return result;
18006    ;
18007    }, -1);
18008    
18009    $def(self, '$divmod', function $$divmod(other) {
18010      var $yield = $$divmod.$$p || nil, self = this;
18011
18012      $$divmod.$$p = null;
18013      if (($truthy(self['$nan?']()) || ($truthy(other['$nan?']())))) {
18014        return $Kernel.$raise($$$('FloatDomainError'), "NaN")
18015      } else if ($truthy(self['$infinite?']())) {
18016        return $Kernel.$raise($$$('FloatDomainError'), "Infinity")
18017      } else {
18018        return $send2(self, $find_super(self, 'divmod', $$divmod, false, true), 'divmod', [other], $yield)
18019      }
18020    });
18021    
18022    $def(self, '$upto', function $$upto(stop) {
18023      var block = $$upto.$$p || nil, self = this;
18024
18025      $$upto.$$p = null;
18026      
18027      ;
18028      if (!(block !== nil)) {
18029        return $send(self, 'enum_for', ["upto", stop], function $$34(){var self = $$34.$$s == null ? this : $$34.$$s;
18030
18031          
18032          if (!$eqeqeq($$$('Numeric'), stop)) {
18033            $Kernel.$raise($$$('ArgumentError'), "comparison of " + (self.$class()) + " with " + (stop.$class()) + " failed")
18034          };
18035          if ($truthy($rb_lt(stop, self))) {
18036            return 0
18037          } else {
18038            return $rb_plus($rb_minus(stop, self), 1)
18039          };}, {$$s: self})
18040      };
18041      
18042      if (!stop.$$is_number) {
18043        $Kernel.$raise($$$('ArgumentError'), "comparison of " + (self.$class()) + " with " + (stop.$class()) + " failed")
18044      }
18045      for (var i = self; i <= stop; i++) {
18046        block(i);
18047      }
18048    ;
18049      return self;
18050    });
18051    
18052    $def(self, '$zero?', function $Number_zero$ques$35() {
18053      var self = this;
18054
18055      return self == 0;
18056    });
18057    
18058    $def(self, '$size', $return_val(4));
18059    
18060    $def(self, '$nan?', function $Number_nan$ques$36() {
18061      var self = this;
18062
18063      return isNaN(self);
18064    });
18065    
18066    $def(self, '$finite?', function $Number_finite$ques$37() {
18067      var self = this;
18068
18069      return self != Infinity && self != -Infinity && !isNaN(self);
18070    });
18071    
18072    $def(self, '$infinite?', function $Number_infinite$ques$38() {
18073      var self = this;
18074
18075      
18076      if (self == Infinity) {
18077        return +1;
18078      }
18079      else if (self == -Infinity) {
18080        return -1;
18081      }
18082      else {
18083        return nil;
18084      }
18085    
18086    });
18087    
18088    $def(self, '$positive?', function $Number_positive$ques$39() {
18089      var self = this;
18090
18091      return self != 0 && (self == Infinity || 1 / self > 0);
18092    });
18093    
18094    $def(self, '$negative?', function $Number_negative$ques$40() {
18095      var self = this;
18096
18097      return self == -Infinity || 1 / self < 0;
18098    });
18099    
18100    function numberToUint8Array(num) {
18101      var uint8array = new Uint8Array(8);
18102      new DataView(uint8array.buffer).setFloat64(0, num, true);
18103      return uint8array;
18104    }
18105
18106    function uint8ArrayToNumber(arr) {
18107      return new DataView(arr.buffer).getFloat64(0, true);
18108    }
18109
18110    function incrementNumberBit(num) {
18111      var arr = numberToUint8Array(num);
18112      for (var i = 0; i < arr.length; i++) {
18113        if (arr[i] === 0xff) {
18114          arr[i] = 0;
18115        } else {
18116          arr[i]++;
18117          break;
18118        }
18119      }
18120      return uint8ArrayToNumber(arr);
18121    }
18122
18123    function decrementNumberBit(num) {
18124      var arr = numberToUint8Array(num);
18125      for (var i = 0; i < arr.length; i++) {
18126        if (arr[i] === 0) {
18127          arr[i] = 0xff;
18128        } else {
18129          arr[i]--;
18130          break;
18131        }
18132      }
18133      return uint8ArrayToNumber(arr);
18134    }
18135  ;
18136    
18137    $def(self, '$next_float', function $$next_float() {
18138      var self = this;
18139
18140      
18141      if ($eqeq(self, $$$($$$('Float'), 'INFINITY'))) {
18142        return $$$($$$('Float'), 'INFINITY')
18143      };
18144      if ($truthy(self['$nan?']())) {
18145        return $$$($$$('Float'), 'NAN')
18146      };
18147      if ($rb_ge(self, 0)) {
18148        return incrementNumberBit(Math.abs(self));
18149      } else {
18150        return decrementNumberBit(self);
18151      };
18152    });
18153    
18154    $def(self, '$prev_float', function $$prev_float() {
18155      var self = this;
18156
18157      
18158      if ($eqeq(self, $$$($$$('Float'), 'INFINITY')['$-@']())) {
18159        return $$$($$$('Float'), 'INFINITY')['$-@']()
18160      };
18161      if ($truthy(self['$nan?']())) {
18162        return $$$($$$('Float'), 'NAN')
18163      };
18164      if ($rb_gt(self, 0)) {
18165        return decrementNumberBit(self);
18166      } else {
18167        return -incrementNumberBit(Math.abs(self));
18168      };
18169    });
18170    $alias(self, "arg", "angle");
18171    $alias(self, "eql?", "==");
18172    $alias(self, "fdiv", "/");
18173    $alias(self, "inspect", "to_s");
18174    $alias(self, "kind_of?", "is_a?");
18175    $alias(self, "magnitude", "abs");
18176    $alias(self, "modulo", "%");
18177    $alias(self, "object_id", "__id__");
18178    $alias(self, "phase", "angle");
18179    $alias(self, "succ", "next");
18180    return $alias(self, "to_int", "to_i");
18181  })('::', $$$('Numeric'), $nesting);
18182  $const_set('::', 'Fixnum', $$$('Number'));
18183  (function($base, $super, $parent_nesting) {
18184    var self = $klass($base, $super, 'Integer');
18185
18186    var $nesting = [self].concat($parent_nesting);
18187
18188    
18189    self.$$is_number_class = true;
18190    self.$$is_integer_class = true;
18191    (function(self, $parent_nesting) {
18192      var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
18193
18194      
18195      
18196      $def(self, '$allocate', function $$allocate() {
18197        var self = this;
18198
18199        return $Kernel.$raise($$$('TypeError'), "allocator undefined for " + (self.$name()))
18200      });
18201      
18202      Opal.udef(self, '$' + "new");;
18203      
18204      $def(self, '$sqrt', function $$sqrt(n) {
18205        
18206        
18207        n = $Opal['$coerce_to!'](n, $$$('Integer'), "to_int");
18208        
18209        if (n < 0) {
18210          $Kernel.$raise($$$($$$('Math'), 'DomainError'), "Numerical argument is out of domain - \"isqrt\"")
18211        }
18212
18213        return parseInt(Math.sqrt(n), 10);
18214      ;
18215      });
18216      return $def(self, '$try_convert', function $$try_convert(object) {
18217        var self = this;
18218
18219        return $$('Opal')['$coerce_to?'](object, self, "to_int")
18220      });
18221    })(Opal.get_singleton_class(self), $nesting);
18222    $const_set(self, 'MAX', Math.pow(2, 30) - 1);
18223    return $const_set(self, 'MIN', -Math.pow(2, 30));
18224  })('::', $$$('Numeric'), $nesting);
18225  return (function($base, $super, $parent_nesting) {
18226    var self = $klass($base, $super, 'Float');
18227
18228    var $nesting = [self].concat($parent_nesting);
18229
18230    
18231    self.$$is_number_class = true;
18232    (function(self, $parent_nesting) {
18233      
18234      
18235      
18236      $def(self, '$allocate', function $$allocate() {
18237        var self = this;
18238
18239        return $Kernel.$raise($$$('TypeError'), "allocator undefined for " + (self.$name()))
18240      });
18241      
18242      Opal.udef(self, '$' + "new");;
18243      return $def(self, '$===', function $eq_eq_eq$41(other) {
18244        
18245        return !!other.$$is_number;
18246      });
18247    })(Opal.get_singleton_class(self), $nesting);
18248    $const_set(self, 'INFINITY', Infinity);
18249    $const_set(self, 'MAX', Number.MAX_VALUE);
18250    $const_set(self, 'MIN', Number.MIN_VALUE);
18251    $const_set(self, 'NAN', NaN);
18252    $const_set(self, 'DIG', 15);
18253    $const_set(self, 'MANT_DIG', 53);
18254    $const_set(self, 'RADIX', 2);
18255    return $const_set(self, 'EPSILON', Number.EPSILON || 2.2204460492503130808472633361816E-16);
18256  })('::', $$$('Numeric'), $nesting);
18257};
18258
18259Opal.modules["corelib/range"] = function(Opal) {/* Generated by Opal 1.7.3 */
18260  var $klass = Opal.klass, $truthy = Opal.truthy, $Kernel = Opal.Kernel, $def = Opal.def, $not = Opal.not, $send2 = Opal.send2, $find_super = Opal.find_super, $rb_lt = Opal.rb_lt, $rb_le = Opal.rb_le, $send = Opal.send, $eqeq = Opal.eqeq, $eqeqeq = Opal.eqeqeq, $return_ivar = Opal.return_ivar, $rb_gt = Opal.rb_gt, $rb_minus = Opal.rb_minus, $Opal = Opal.Opal, $rb_divide = Opal.rb_divide, $rb_plus = Opal.rb_plus, $rb_times = Opal.rb_times, $rb_ge = Opal.rb_ge, $thrower = Opal.thrower, $alias = Opal.alias, self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$;
18261
18262  Opal.add_stubs('require,include,attr_reader,raise,nil?,<=>,include?,!,<,<=,enum_for,size,upto,to_proc,respond_to?,class,succ,==,===,exclude_end?,eql?,begin,end,last,to_a,>,-@,-,to_i,coerce_to!,ceil,/,is_a?,new,loop,+,*,>=,each_with_index,%,step,bsearch,inspect,[],hash,cover?');
18263  
18264  self.$require("corelib/enumerable");
18265  return (function($base, $super, $parent_nesting) {
18266    var self = $klass($base, $super, 'Range');
18267
18268    var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype;
18269
18270    $proto.begin = $proto.end = $proto.excl = nil;
18271    
18272    self.$include($$$('Enumerable'));
18273    self.$$prototype.$$is_range = true;
18274    self.$attr_reader("begin", "end");
18275    
18276    $def(self, '$initialize', function $$initialize(first, last, exclude) {
18277      var self = this;
18278
18279      
18280      if (exclude == null) exclude = false;
18281      if ($truthy(self.begin)) {
18282        $Kernel.$raise($$$('NameError'), "'initialize' called twice")
18283      };
18284      if (!(($truthy(first['$<=>'](last)) || ($truthy(first['$nil?']()))) || ($truthy(last['$nil?']())))) {
18285        $Kernel.$raise($$$('ArgumentError'), "bad value for range")
18286      };
18287      self.begin = first;
18288      self.end = last;
18289      return (self.excl = exclude);
18290    }, -3);
18291    
18292    $def(self, '$===', function $Range_$eq_eq_eq$1(value) {
18293      var self = this;
18294
18295      return self['$include?'](value)
18296    });
18297    
18298    function is_infinite(self) {
18299      if (self.begin === nil || self.end === nil ||
18300          self.begin === -Infinity || self.end === Infinity ||
18301          self.begin === Infinity || self.end === -Infinity) return true;
18302      return false;
18303    }
18304  ;
18305    
18306    $def(self, '$count', function $$count() {
18307      var block = $$count.$$p || nil, self = this;
18308
18309      $$count.$$p = null;
18310      
18311      ;
18312      if (($not((block !== nil)) && ($truthy(is_infinite(self))))) {
18313        return $$$($$$('Float'), 'INFINITY')
18314      };
18315      return $send2(self, $find_super(self, 'count', $$count, false, true), 'count', [], block);
18316    });
18317    
18318    $def(self, '$to_a', function $$to_a() {
18319      var $yield = $$to_a.$$p || nil, self = this;
18320
18321      $$to_a.$$p = null;
18322      
18323      if ($truthy(is_infinite(self))) {
18324        $Kernel.$raise($$$('TypeError'), "cannot convert endless range to an array")
18325      };
18326      return $send2(self, $find_super(self, 'to_a', $$to_a, false, true), 'to_a', [], $yield);
18327    });
18328    
18329    $def(self, '$cover?', function $Range_cover$ques$2(value) {
18330      var self = this, beg_cmp = nil, $ret_or_1 = nil, $ret_or_2 = nil, $ret_or_3 = nil, end_cmp = nil;
18331
18332      
18333      beg_cmp = ($truthy(($ret_or_1 = ($truthy(($ret_or_2 = ($truthy(($ret_or_3 = self.begin['$nil?']())) ? (-1) : ($ret_or_3)))) ? ($ret_or_2) : (self.begin['$<=>'](value))))) && ($ret_or_1));
18334      end_cmp = ($truthy(($ret_or_1 = ($truthy(($ret_or_2 = ($truthy(($ret_or_3 = self.end['$nil?']())) ? (-1) : ($ret_or_3)))) ? ($ret_or_2) : (value['$<=>'](self.end))))) && ($ret_or_1));
18335      if ($truthy(($ret_or_1 = ($truthy(($ret_or_2 = ($truthy(self.excl) ? (($truthy(($ret_or_3 = end_cmp)) ? ($rb_lt(end_cmp, 0)) : ($ret_or_3))) : ($truthy(($ret_or_3 = end_cmp)) ? ($rb_le(end_cmp, 0)) : ($ret_or_3))))) ? (beg_cmp) : ($ret_or_2))))) {
18336        return $rb_le(beg_cmp, 0)
18337      } else {
18338        return $ret_or_1
18339      };
18340    });
18341    
18342    $def(self, '$each', function $$each() {
18343      var block = $$each.$$p || nil, self = this, current = nil, last = nil, $ret_or_1 = nil;
18344
18345      $$each.$$p = null;
18346      
18347      ;
18348      if (!(block !== nil)) {
18349        return $send(self, 'enum_for', ["each"], function $$3(){var self = $$3.$$s == null ? this : $$3.$$s;
18350
18351          return self.$size()}, {$$s: self})
18352      };
18353      
18354      var i, limit;
18355
18356      if (self.begin.$$is_number && self.end.$$is_number) {
18357        if (self.begin % 1 !== 0 || self.end % 1 !== 0) {
18358          $Kernel.$raise($$$('TypeError'), "can't iterate from Float")
18359        }
18360
18361        for (i = self.begin, limit = self.end + ($truthy(self.excl) ? (0) : (1)); i < limit; i++) {
18362          block(i);
18363        }
18364
18365        return self;
18366      }
18367
18368      if (self.begin.$$is_string && self.end.$$is_string) {
18369        $send(self.begin, 'upto', [self.end, self.excl], block.$to_proc())
18370        return self;
18371      }
18372    ;
18373      current = self.begin;
18374      last = self.end;
18375      if (!$truthy(current['$respond_to?']("succ"))) {
18376        $Kernel.$raise($$$('TypeError'), "can't iterate from " + (current.$class()))
18377      };
18378      while ($truthy(($truthy(($ret_or_1 = self.end['$nil?']())) ? ($ret_or_1) : ($rb_lt(current['$<=>'](last), 0))))) {
18379      
18380        Opal.yield1(block, current);
18381        current = current.$succ();
18382      };
18383      if (($not(self.excl) && ($eqeq(current, last)))) {
18384        Opal.yield1(block, current)
18385      };
18386      return self;
18387    });
18388    
18389    $def(self, '$eql?', function $Range_eql$ques$4(other) {
18390      var self = this, $ret_or_1 = nil, $ret_or_2 = nil;
18391
18392      
18393      if (!$eqeqeq($$$('Range'), other)) {
18394        return false
18395      };
18396      if ($truthy(($ret_or_1 = ($truthy(($ret_or_2 = self.excl['$==='](other['$exclude_end?']()))) ? (self.begin['$eql?'](other.$begin())) : ($ret_or_2))))) {
18397        return self.end['$eql?'](other.$end())
18398      } else {
18399        return $ret_or_1
18400      };
18401    });
18402    
18403    $def(self, '$exclude_end?', $return_ivar("excl"));
18404    
18405    $def(self, '$first', function $$first(n) {
18406      var $yield = $$first.$$p || nil, self = this;
18407
18408      $$first.$$p = null;
18409      
18410      ;
18411      if ($truthy(self.begin['$nil?']())) {
18412        $Kernel.$raise($$$('RangeError'), "cannot get the minimum of beginless range")
18413      };
18414      if ($truthy(n == null)) {
18415        return self.begin
18416      };
18417      return $send2(self, $find_super(self, 'first', $$first, false, true), 'first', [n], $yield);
18418    }, -1);
18419    
18420    $def(self, '$last', function $$last(n) {
18421      var self = this;
18422
18423      
18424      ;
18425      if ($truthy(self.end['$nil?']())) {
18426        $Kernel.$raise($$$('RangeError'), "cannot get the maximum of endless range")
18427      };
18428      if ($truthy(n == null)) {
18429        return self.end
18430      };
18431      return self.$to_a().$last(n);
18432    }, -1);
18433    
18434    $def(self, '$max', function $$max() {
18435      var $yield = $$max.$$p || nil, self = this;
18436
18437      $$max.$$p = null;
18438      if ($truthy(self.end['$nil?']())) {
18439        return $Kernel.$raise($$$('RangeError'), "cannot get the maximum of endless range")
18440      } else if (($yield !== nil)) {
18441        return $send2(self, $find_super(self, 'max', $$max, false, true), 'max', [], $yield)
18442      } else if (($not(self.begin['$nil?']()) && (($truthy($rb_gt(self.begin, self.end)) || (($truthy(self.excl) && ($eqeq(self.begin, self.end)))))))) {
18443        return nil
18444      } else {
18445        return self.excl ? self.end - 1 : self.end
18446      }
18447    });
18448    
18449    $def(self, '$min', function $$min() {
18450      var $yield = $$min.$$p || nil, self = this;
18451
18452      $$min.$$p = null;
18453      if ($truthy(self.begin['$nil?']())) {
18454        return $Kernel.$raise($$$('RangeError'), "cannot get the minimum of beginless range")
18455      } else if (($yield !== nil)) {
18456        return $send2(self, $find_super(self, 'min', $$min, false, true), 'min', [], $yield)
18457      } else if (($not(self.end['$nil?']()) && (($truthy($rb_gt(self.begin, self.end)) || (($truthy(self.excl) && ($eqeq(self.begin, self.end)))))))) {
18458        return nil
18459      } else {
18460        return self.begin
18461      }
18462    });
18463    
18464    $def(self, '$size', function $$size() {
18465      var self = this, infinity = nil, range_begin = nil, range_end = nil;
18466
18467      
18468      infinity = $$$($$$('Float'), 'INFINITY');
18469      if ((($eqeq(self.begin, infinity) && ($not(self.end['$nil?']()))) || (($eqeq(self.end, infinity['$-@']()) && ($not(self.begin['$nil?']())))))) {
18470        return 0
18471      };
18472      if ($truthy(is_infinite(self))) {
18473        return infinity
18474      };
18475      if (!($eqeqeq($$$('Numeric'), self.begin) && ($eqeqeq($$$('Numeric'), self.end)))) {
18476        return nil
18477      };
18478      range_begin = self.begin;
18479      range_end = self.end;
18480      if ($truthy(self.excl)) {
18481        range_end = $rb_minus(range_end, 1)
18482      };
18483      if ($truthy($rb_lt(range_end, range_begin))) {
18484        return 0
18485      };
18486      return (Math.abs(range_end - range_begin) + 1).$to_i();
18487    });
18488    
18489    $def(self, '$step', function $$step(n) {
18490      var $yield = $$step.$$p || nil, self = this, $ret_or_1 = nil, i = nil;
18491
18492      $$step.$$p = null;
18493      
18494      ;
18495      
18496      function coerceStepSize() {
18497        if (n == null) {
18498          n = 1;
18499        }
18500        else if (!n.$$is_number) {
18501          n = $Opal['$coerce_to!'](n, $$$('Integer'), "to_int")
18502        }
18503
18504        if (n < 0) {
18505          $Kernel.$raise($$$('ArgumentError'), "step can't be negative")
18506        } else if (n === 0) {
18507          $Kernel.$raise($$$('ArgumentError'), "step can't be 0")
18508        }
18509      }
18510
18511      function enumeratorSize() {
18512        if (!self.begin['$respond_to?']("succ")) {
18513          return nil;
18514        }
18515
18516        if (self.begin.$$is_string && self.end.$$is_string) {
18517          return nil;
18518        }
18519
18520        if (n % 1 === 0) {
18521          return $rb_divide(self.$size(), n).$ceil();
18522        } else {
18523          // n is a float
18524          var begin = self.begin, end = self.end,
18525              abs = Math.abs, floor = Math.floor,
18526              err = (abs(begin) + abs(end) + abs(end - begin)) / abs(n) * $$$($$$('Float'), 'EPSILON'),
18527              size;
18528
18529          if (err > 0.5) {
18530            err = 0.5;
18531          }
18532
18533          if (self.excl) {
18534            size = floor((end - begin) / n - err);
18535            if (size * n + begin < end) {
18536              size++;
18537            }
18538          } else {
18539            size = floor((end - begin) / n + err) + 1
18540          }
18541
18542          return size;
18543        }
18544      }
18545    ;
18546      if (!($yield !== nil)) {
18547        if (((($truthy(self.begin['$is_a?']($$('Numeric'))) || ($truthy(self.begin['$nil?']()))) && (($truthy(self.end['$is_a?']($$('Numeric'))) || ($truthy(self.end['$nil?']()))))) && ($not(($truthy(($ret_or_1 = self.begin['$nil?']())) ? (self.end['$nil?']()) : ($ret_or_1)))))) {
18548          return $$$($$$('Enumerator'), 'ArithmeticSequence').$new(self, n, "step")
18549        } else {
18550          return $send(self, 'enum_for', ["step", n], function $$5(){
18551            
18552            coerceStepSize();
18553            return enumeratorSize();
18554          })
18555        }
18556      };
18557      coerceStepSize();
18558      if ($truthy(self.begin.$$is_number && self.end.$$is_number)) {
18559        
18560        i = 0;
18561        (function(){try { var $t_break = $thrower('break'); return $send(self, 'loop', [], function $$6(){var self = $$6.$$s == null ? this : $$6.$$s, current = nil;
18562          if (self.begin == null) self.begin = nil;
18563          if (self.excl == null) self.excl = nil;
18564          if (self.end == null) self.end = nil;
18565
18566          
18567          current = $rb_plus(self.begin, $rb_times(i, n));
18568          if ($truthy(self.excl)) {
18569            if ($truthy($rb_ge(current, self.end))) {
18570              $t_break.$throw()
18571            }
18572          } else if ($truthy($rb_gt(current, self.end))) {
18573            $t_break.$throw()
18574          };
18575          Opal.yield1($yield, current);
18576          return (i = $rb_plus(i, 1));}, {$$s: self})} catch($e) {
18577          if ($e === $t_break) return $e.$v;
18578          throw $e;
18579        }})();
18580      } else {
18581        
18582        
18583        if (self.begin.$$is_string && self.end.$$is_string && n % 1 !== 0) {
18584          $Kernel.$raise($$$('TypeError'), "no implicit conversion to float from string")
18585        }
18586      ;
18587        $send(self, 'each_with_index', [], function $$7(value, idx){
18588          
18589          if (value == null) value = nil;
18590          if (idx == null) idx = nil;
18591          if ($eqeq(idx['$%'](n), 0)) {
18592            return Opal.yield1($yield, value);
18593          } else {
18594            return nil
18595          };});
18596      };
18597      return self;
18598    }, -1);
18599    
18600    $def(self, '$%', function $Range_$percent$8(n) {
18601      var self = this;
18602
18603      if (($truthy(self.begin['$is_a?']($$('Numeric'))) && ($truthy(self.end['$is_a?']($$('Numeric')))))) {
18604        return $$$($$$('Enumerator'), 'ArithmeticSequence').$new(self, n, "%")
18605      } else {
18606        return self.$step(n)
18607      }
18608    });
18609    
18610    $def(self, '$bsearch', function $$bsearch() {
18611      var block = $$bsearch.$$p || nil, self = this;
18612
18613      $$bsearch.$$p = null;
18614      
18615      ;
18616      if (!(block !== nil)) {
18617        return self.$enum_for("bsearch")
18618      };
18619      if ($truthy(is_infinite(self) && (self.begin.$$is_number || self.end.$$is_number))) {
18620        $Kernel.$raise($$$('NotImplementedError'), "Can't #bsearch an infinite range")
18621      };
18622      if (!$truthy(self.begin.$$is_number && self.end.$$is_number)) {
18623        $Kernel.$raise($$$('TypeError'), "can't do binary search for " + (self.begin.$class()))
18624      };
18625      return $send(self.$to_a(), 'bsearch', [], block.$to_proc());
18626    });
18627    
18628    $def(self, '$to_s', function $$to_s() {
18629      var self = this, $ret_or_1 = nil;
18630
18631      return "" + (($truthy(($ret_or_1 = self.begin)) ? ($ret_or_1) : (""))) + (($truthy(self.excl) ? ("...") : (".."))) + (($truthy(($ret_or_1 = self.end)) ? ($ret_or_1) : ("")))
18632    });
18633    
18634    $def(self, '$inspect', function $$inspect() {
18635      var self = this, $ret_or_1 = nil;
18636
18637      return "" + (($truthy(($ret_or_1 = self.begin)) ? (self.begin.$inspect()) : ($ret_or_1))) + (($truthy(self.excl) ? ("...") : (".."))) + (($truthy(($ret_or_1 = self.end)) ? (self.end.$inspect()) : ($ret_or_1)))
18638    });
18639    
18640    $def(self, '$marshal_load', function $$marshal_load(args) {
18641      var self = this;
18642
18643      
18644      self.begin = args['$[]']("begin");
18645      self.end = args['$[]']("end");
18646      return (self.excl = args['$[]']("excl"));
18647    });
18648    
18649    $def(self, '$hash', function $$hash() {
18650      var self = this;
18651
18652      return [self.begin, self.end, self.excl].$hash()
18653    });
18654    $alias(self, "==", "eql?");
18655    $alias(self, "include?", "cover?");
18656    return $alias(self, "member?", "cover?");
18657  })('::', null, $nesting);
18658};
18659
18660Opal.modules["corelib/proc"] = function(Opal) {/* Generated by Opal 1.7.3 */
18661  var $slice = Opal.slice, $klass = Opal.klass, $truthy = Opal.truthy, $Kernel = Opal.Kernel, $defs = Opal.defs, $def = Opal.def, $send = Opal.send, $to_a = Opal.to_a, $return_self = Opal.return_self, $ensure_kwargs = Opal.ensure_kwargs, $Opal = Opal.Opal, $alias = Opal.alias, nil = Opal.nil, $$$ = Opal.$$$;
18662
18663  Opal.add_stubs('raise,proc,call,to_proc,new,source_location,coerce_to!,dup');
18664  return (function($base, $super) {
18665    var self = $klass($base, $super, 'Proc');
18666
18667    
18668    
18669    Opal.prop(self.$$prototype, '$$is_proc', true);
18670    Opal.prop(self.$$prototype, '$$is_lambda', false);
18671    $defs(self, '$new', function $Proc_new$1() {
18672      var block = $Proc_new$1.$$p || nil;
18673
18674      $Proc_new$1.$$p = null;
18675      
18676      ;
18677      if (!$truthy(block)) {
18678        $Kernel.$raise($$$('ArgumentError'), "tried to create a Proc object without a block")
18679      };
18680      return block;
18681    });
18682    
18683    $def(self, '$call', function $$call($a) {
18684      var block = $$call.$$p || nil, $post_args, args, self = this;
18685
18686      $$call.$$p = null;
18687      
18688      ;
18689      $post_args = $slice(arguments);
18690      args = $post_args;
18691      
18692      if (block !== nil) {
18693        self.$$p = block;
18694      }
18695
18696      var result, $brk = self.$$brk, $ret = self.$$ret;
18697
18698      if ($brk || ($ret && self.$$is_lambda)) {
18699        try {
18700          if (self.$$is_lambda) {
18701            result = self.apply(null, args);
18702          }
18703          else {
18704            result = Opal.yieldX(self, args);
18705          }
18706        } catch (err) {
18707          if (err === $brk) {
18708            return err.$v;
18709          }
18710          else if (self.$$is_lambda && err === $ret) {
18711            return err.$v;
18712          }
18713          else {
18714            throw err;
18715          }
18716        }
18717      }
18718      else {
18719        if (self.$$is_lambda) {
18720          result = self.apply(null, args);
18721        }
18722        else {
18723          result = Opal.yieldX(self, args);
18724        }
18725      }
18726
18727      return result;
18728    ;
18729    }, -1);
18730    
18731    $def(self, '$>>', function $Proc_$gt$gt$2(other) {
18732      var $yield = $Proc_$gt$gt$2.$$p || nil, self = this;
18733
18734      $Proc_$gt$gt$2.$$p = null;
18735      return $send($Kernel, 'proc', [], function $$3($a){var block = $$3.$$p || nil, $post_args, args, self = $$3.$$s == null ? this : $$3.$$s, out = nil;
18736
18737        $$3.$$p = null;
18738        
18739        ;
18740        $post_args = $slice(arguments);
18741        args = $post_args;
18742        out = $send(self, 'call', $to_a(args), block.$to_proc());
18743        return other.$call(out);}, {$$arity: -1, $$s: self})
18744    });
18745    
18746    $def(self, '$<<', function $Proc_$lt$lt$4(other) {
18747      var $yield = $Proc_$lt$lt$4.$$p || nil, self = this;
18748
18749      $Proc_$lt$lt$4.$$p = null;
18750      return $send($Kernel, 'proc', [], function $$5($a){var block = $$5.$$p || nil, $post_args, args, self = $$5.$$s == null ? this : $$5.$$s, out = nil;
18751
18752        $$5.$$p = null;
18753        
18754        ;
18755        $post_args = $slice(arguments);
18756        args = $post_args;
18757        out = $send(other, 'call', $to_a(args), block.$to_proc());
18758        return self.$call(out);}, {$$arity: -1, $$s: self})
18759    });
18760    
18761    $def(self, '$to_proc', $return_self);
18762    
18763    $def(self, '$lambda?', function $Proc_lambda$ques$6() {
18764      var self = this;
18765
18766      return !!self.$$is_lambda;
18767    });
18768    
18769    $def(self, '$arity', function $$arity() {
18770      var self = this;
18771
18772      
18773      if (self.$$is_curried) {
18774        return -1;
18775      } else if (self.$$arity != null) {
18776        return self.$$arity;
18777      } else {
18778        return self.length;
18779      }
18780    
18781    });
18782    
18783    $def(self, '$source_location', function $$source_location() {
18784      var self = this, $ret_or_1 = nil;
18785
18786      
18787      if (self.$$is_curried) { return nil; };
18788      if ($truthy(($ret_or_1 = self.$$source_location))) {
18789        return $ret_or_1
18790      } else {
18791        return nil
18792      };
18793    });
18794    
18795    $def(self, '$binding', function $$binding() {
18796      var $a, self = this;
18797
18798      
18799      if (self.$$is_curried) { $Kernel.$raise($$$('ArgumentError'), "Can't create Binding") };
18800      if ($truthy((($a = $$$('::', 'Binding', 'skip_raise')) ? 'constant' : nil))) {
18801        return $$$('Binding').$new(nil, [], self.$$s, self.$source_location())
18802      } else {
18803        return nil
18804      };
18805    });
18806    
18807    $def(self, '$parameters', function $$parameters($kwargs) {
18808      var lambda, self = this;
18809
18810      
18811      $kwargs = $ensure_kwargs($kwargs);
18812      
18813      lambda = $kwargs.$$smap["lambda"];;
18814      
18815      if (self.$$is_curried) {
18816        return [["rest"]];
18817      } else if (self.$$parameters) {
18818        if (lambda == null ? self.$$is_lambda : lambda) {
18819          return self.$$parameters;
18820        } else {
18821          var result = [], i, length;
18822
18823          for (i = 0, length = self.$$parameters.length; i < length; i++) {
18824            var parameter = self.$$parameters[i];
18825
18826            if (parameter[0] === 'req') {
18827              // required arguments always have name
18828              parameter = ['opt', parameter[1]];
18829            }
18830
18831            result.push(parameter);
18832          }
18833
18834          return result;
18835        }
18836      } else {
18837        return [];
18838      }
18839    ;
18840    }, -1);
18841    
18842    $def(self, '$curry', function $$curry(arity) {
18843      var self = this;
18844
18845      
18846      ;
18847      
18848      if (arity === undefined) {
18849        arity = self.length;
18850      }
18851      else {
18852        arity = $Opal['$coerce_to!'](arity, $$$('Integer'), "to_int");
18853        if (self.$$is_lambda && arity !== self.length) {
18854          $Kernel.$raise($$$('ArgumentError'), "wrong number of arguments (" + (arity) + " for " + (self.length) + ")")
18855        }
18856      }
18857
18858      function curried () {
18859        var args = $slice(arguments),
18860            length = args.length,
18861            result;
18862
18863        if (length > arity && self.$$is_lambda && !self.$$is_curried) {
18864          $Kernel.$raise($$$('ArgumentError'), "wrong number of arguments (" + (length) + " for " + (arity) + ")")
18865        }
18866
18867        if (length >= arity) {
18868          return self.$call.apply(self, args);
18869        }
18870
18871        result = function () {
18872          return curried.apply(null,
18873            args.concat($slice(arguments)));
18874        }
18875        result.$$is_lambda = self.$$is_lambda;
18876        result.$$is_curried = true;
18877
18878        return result;
18879      };
18880
18881      curried.$$is_lambda = self.$$is_lambda;
18882      curried.$$is_curried = true;
18883      return curried;
18884    ;
18885    }, -1);
18886    
18887    $def(self, '$dup', function $$dup() {
18888      var self = this;
18889
18890      
18891      var original_proc = self.$$original_proc || self,
18892          proc = function () {
18893            return original_proc.apply(this, arguments);
18894          };
18895
18896      for (var prop in self) {
18897        if (self.hasOwnProperty(prop)) {
18898          proc[prop] = self[prop];
18899        }
18900      }
18901
18902      return proc;
18903    
18904    });
18905    $alias(self, "===", "call");
18906    $alias(self, "clone", "dup");
18907    $alias(self, "yield", "call");
18908    return $alias(self, "[]", "call");
18909  })('::', Function)
18910};
18911
18912Opal.modules["corelib/method"] = function(Opal) {/* Generated by Opal 1.7.3 */
18913  var $klass = Opal.klass, $def = Opal.def, $truthy = Opal.truthy, $slice = Opal.slice, $alias = Opal.alias, $Kernel = Opal.Kernel, $send = Opal.send, $to_a = Opal.to_a, nil = Opal.nil, $$$ = Opal.$$$;
18914
18915  Opal.add_stubs('attr_reader,arity,curry,>>,<<,new,class,join,source_location,call,raise,bind,to_proc');
18916  
18917  (function($base, $super) {
18918    var self = $klass($base, $super, 'Method');
18919
18920    var $proto = self.$$prototype;
18921
18922    $proto.method = $proto.receiver = $proto.owner = $proto.name = nil;
18923    
18924    self.$attr_reader("owner", "receiver", "name");
18925    
18926    $def(self, '$initialize', function $$initialize(receiver, owner, method, name) {
18927      var self = this;
18928
18929      
18930      self.receiver = receiver;
18931      self.owner = owner;
18932      self.name = name;
18933      return (self.method = method);
18934    });
18935    
18936    $def(self, '$arity', function $$arity() {
18937      var self = this;
18938
18939      return self.method.$arity()
18940    });
18941    
18942    $def(self, '$parameters', function $$parameters() {
18943      var self = this;
18944
18945      return self.method.$$parameters
18946    });
18947    
18948    $def(self, '$source_location', function $$source_location() {
18949      var self = this, $ret_or_1 = nil;
18950
18951      if ($truthy(($ret_or_1 = self.method.$$source_location))) {
18952        return $ret_or_1
18953      } else {
18954        return ["(eval)", 0]
18955      }
18956    });
18957    
18958    $def(self, '$comments', function $$comments() {
18959      var self = this, $ret_or_1 = nil;
18960
18961      if ($truthy(($ret_or_1 = self.method.$$comments))) {
18962        return $ret_or_1
18963      } else {
18964        return []
18965      }
18966    });
18967    
18968    $def(self, '$call', function $$call($a) {
18969      var block = $$call.$$p || nil, $post_args, args, self = this;
18970
18971      $$call.$$p = null;
18972      
18973      ;
18974      $post_args = $slice(arguments);
18975      args = $post_args;
18976      
18977      self.method.$$p = block;
18978
18979      return self.method.apply(self.receiver, args);
18980    ;
18981    }, -1);
18982    
18983    $def(self, '$curry', function $$curry(arity) {
18984      var self = this;
18985
18986      
18987      ;
18988      return self.method.$curry(arity);
18989    }, -1);
18990    
18991    $def(self, '$>>', function $Method_$gt$gt$1(other) {
18992      var self = this;
18993
18994      return self.method['$>>'](other)
18995    });
18996    
18997    $def(self, '$<<', function $Method_$lt$lt$2(other) {
18998      var self = this;
18999
19000      return self.method['$<<'](other)
19001    });
19002    
19003    $def(self, '$unbind', function $$unbind() {
19004      var self = this;
19005
19006      return $$$('UnboundMethod').$new(self.receiver.$class(), self.owner, self.method, self.name)
19007    });
19008    
19009    $def(self, '$to_proc', function $$to_proc() {
19010      var self = this;
19011
19012      
19013      var proc = self.$call.bind(self);
19014      proc.$$unbound = self.method;
19015      proc.$$is_lambda = true;
19016      proc.$$arity = self.method.$$arity == null ? self.method.length : self.method.$$arity;
19017      proc.$$parameters = self.method.$$parameters;
19018      return proc;
19019    
19020    });
19021    
19022    $def(self, '$inspect', function $$inspect() {
19023      var self = this;
19024
19025      return "#<" + (self.$class()) + ": " + (self.receiver.$class()) + "#" + (self.name) + " (defined in " + (self.owner) + " in " + (self.$source_location().$join(":")) + ")>"
19026    });
19027    $alias(self, "[]", "call");
19028    return $alias(self, "===", "call");
19029  })('::', null);
19030  return (function($base, $super) {
19031    var self = $klass($base, $super, 'UnboundMethod');
19032
19033    var $proto = self.$$prototype;
19034
19035    $proto.method = $proto.owner = $proto.name = $proto.source = nil;
19036    
19037    self.$attr_reader("source", "owner", "name");
19038    
19039    $def(self, '$initialize', function $$initialize(source, owner, method, name) {
19040      var self = this;
19041
19042      
19043      self.source = source;
19044      self.owner = owner;
19045      self.method = method;
19046      return (self.name = name);
19047    });
19048    
19049    $def(self, '$arity', function $$arity() {
19050      var self = this;
19051
19052      return self.method.$arity()
19053    });
19054    
19055    $def(self, '$parameters', function $$parameters() {
19056      var self = this;
19057
19058      return self.method.$$parameters
19059    });
19060    
19061    $def(self, '$source_location', function $$source_location() {
19062      var self = this, $ret_or_1 = nil;
19063
19064      if ($truthy(($ret_or_1 = self.method.$$source_location))) {
19065        return $ret_or_1
19066      } else {
19067        return ["(eval)", 0]
19068      }
19069    });
19070    
19071    $def(self, '$comments', function $$comments() {
19072      var self = this, $ret_or_1 = nil;
19073
19074      if ($truthy(($ret_or_1 = self.method.$$comments))) {
19075        return $ret_or_1
19076      } else {
19077        return []
19078      }
19079    });
19080    
19081    $def(self, '$bind', function $$bind(object) {
19082      var self = this;
19083
19084      
19085      if (self.owner.$$is_module || Opal.is_a(object, self.owner)) {
19086        return $$$('Method').$new(object, self.owner, self.method, self.name);
19087      }
19088      else {
19089        $Kernel.$raise($$$('TypeError'), "can't bind singleton method to a different class (expected " + (object) + ".kind_of?(" + (self.owner) + " to be true)");
19090      }
19091    
19092    });
19093    
19094    $def(self, '$bind_call', function $$bind_call(object, $a) {
19095      var block = $$bind_call.$$p || nil, $post_args, args, self = this;
19096
19097      $$bind_call.$$p = null;
19098      
19099      ;
19100      $post_args = $slice(arguments, 1);
19101      args = $post_args;
19102      return $send(self.$bind(object), 'call', $to_a(args), block.$to_proc());
19103    }, -2);
19104    return $def(self, '$inspect', function $$inspect() {
19105      var self = this;
19106
19107      return "#<" + (self.$class()) + ": " + (self.source) + "#" + (self.name) + " (defined in " + (self.owner) + " in " + (self.$source_location().$join(":")) + ")>"
19108    });
19109  })('::', null);
19110};
19111
19112Opal.modules["corelib/variables"] = function(Opal) {/* Generated by Opal 1.7.3 */
19113  var $gvars = Opal.gvars, $const_set = Opal.const_set, $Object = Opal.Object, $hash2 = Opal.hash2, nil = Opal.nil;
19114
19115  Opal.add_stubs('new');
19116  
19117  $gvars['&'] = $gvars['~'] = $gvars['`'] = $gvars["'"] = nil;
19118  $gvars.LOADED_FEATURES = ($gvars["\""] = Opal.loaded_features);
19119  $gvars.LOAD_PATH = ($gvars[":"] = []);
19120  $gvars["/"] = "\n";
19121  $gvars[","] = nil;
19122  $const_set('::', 'ARGV', []);
19123  $const_set('::', 'ARGF', $Object.$new());
19124  $const_set('::', 'ENV', $hash2([], {}));
19125  $gvars.VERBOSE = false;
19126  $gvars.DEBUG = false;
19127  return ($gvars.SAFE = 0);
19128};
19129
19130Opal.modules["corelib/io"] = function(Opal) {/* Generated by Opal 1.7.3 */
19131  var $klass = Opal.klass, $const_set = Opal.const_set, $not = Opal.not, $truthy = Opal.truthy, $def = Opal.def, $return_ivar = Opal.return_ivar, $return_val = Opal.return_val, $slice = Opal.slice, $Kernel = Opal.Kernel, $gvars = Opal.gvars, $send = Opal.send, $to_a = Opal.to_a, $rb_plus = Opal.rb_plus, $neqeq = Opal.neqeq, $range = Opal.range, $hash2 = Opal.hash2, $eqeq = Opal.eqeq, $to_ary = Opal.to_ary, $rb_gt = Opal.rb_gt, $assign_ivar_val = Opal.assign_ivar_val, $alias = Opal.alias, $a, nil = Opal.nil, $$$ = Opal.$$$;
19132
19133  Opal.add_stubs('attr_reader,attr_accessor,!,match?,include?,size,write,String,flatten,puts,sysread_noraise,+,!=,[],ord,getc,readchar,raise,gets,==,to_str,length,split,sub,sysread,>,to_a,each_line,enum_for,getbyte,closed_write?,closed_read?,each,eof,new,write_proc=,read_proc=');
19134  
19135  (function($base, $super) {
19136    var self = $klass($base, $super, 'IO');
19137
19138    var $proto = self.$$prototype;
19139
19140    $proto.read_buffer = $proto.closed = nil;
19141    
19142    $const_set(self, 'SEEK_SET', 0);
19143    $const_set(self, 'SEEK_CUR', 1);
19144    $const_set(self, 'SEEK_END', 2);
19145    $const_set(self, 'SEEK_DATA', 3);
19146    $const_set(self, 'SEEK_HOLE', 4);
19147    $const_set(self, 'READABLE', 1);
19148    $const_set(self, 'WRITABLE', 4);
19149    self.$attr_reader("eof");
19150    self.$attr_accessor("read_proc", "sync", "tty", "write_proc");
19151    
19152    $def(self, '$initialize', function $$initialize(fd, flags) {
19153      var self = this;
19154
19155      
19156      if (flags == null) flags = "r";
19157      self.fd = fd;
19158      self.flags = flags;
19159      self.eof = false;
19160      if (($truthy(flags['$include?']("r")) && ($not(flags['$match?'](/[wa+]/))))) {
19161        return (self.closed = "write")
19162      } else if (($truthy(flags['$match?'](/[wa]/)) && ($not(flags['$match?'](/[r+]/))))) {
19163        return (self.closed = "read")
19164      } else {
19165        return nil
19166      };
19167    }, -2);
19168    
19169    $def(self, '$fileno', $return_ivar("fd"));
19170    
19171    $def(self, '$tty?', function $IO_tty$ques$1() {
19172      var self = this;
19173
19174      return self.tty == true;
19175    });
19176    
19177    $def(self, '$write', function $$write(string) {
19178      var self = this;
19179
19180      
19181      self.write_proc(string);
19182      return string.$size();
19183    });
19184    
19185    $def(self, '$flush', $return_val(nil));
19186    
19187    $def(self, '$<<', function $IO_$lt$lt$2(string) {
19188      var self = this;
19189
19190      
19191      self.$write(string);
19192      return self;
19193    });
19194    
19195    $def(self, '$print', function $$print($a) {
19196      var $post_args, args, self = this;
19197      if ($gvars[","] == null) $gvars[","] = nil;
19198
19199      
19200      $post_args = $slice(arguments);
19201      args = $post_args;
19202      
19203      for (var i = 0, ii = args.length; i < ii; i++) {
19204        args[i] = $Kernel.$String(args[i])
19205      }
19206      self.$write(args.join($gvars[","]));
19207    ;
19208      return nil;
19209    }, -1);
19210    
19211    $def(self, '$puts', function $$puts($a) {
19212      var $post_args, args, self = this;
19213
19214      
19215      $post_args = $slice(arguments);
19216      args = $post_args;
19217      
19218      var line
19219      if (args.length === 0) {
19220        self.$write("\n");
19221        return nil;
19222      } else {
19223        for (var i = 0, ii = args.length; i < ii; i++) {
19224          if (args[i].$$is_array){
19225            var ary = (args[i]).$flatten()
19226            if (ary.length > 0) $send(self, 'puts', $to_a((ary)))
19227          } else {
19228            if (args[i].$$is_string) {
19229              line = args[i].valueOf();
19230            } else {
19231              line = $Kernel.$String(args[i]);
19232            }
19233            if (!line.endsWith("\n")) line += "\n"
19234            self.$write(line)
19235          }
19236        }
19237      }
19238    ;
19239      return nil;
19240    }, -1);
19241    
19242    $def(self, '$getc', function $$getc() {
19243      var self = this, $ret_or_1 = nil, parts = nil, ret = nil;
19244
19245      
19246      self.read_buffer = ($truthy(($ret_or_1 = self.read_buffer)) ? ($ret_or_1) : (""));
19247      parts = "";
19248      do {
19249      
19250        self.read_buffer = $rb_plus(self.read_buffer, parts);
19251        if ($neqeq(self.read_buffer, "")) {
19252          
19253          ret = self.read_buffer['$[]'](0);
19254          self.read_buffer = self.read_buffer['$[]']($range(1, -1, false));
19255          return ret;
19256        };
19257      } while ($truthy((parts = self.$sysread_noraise(1))));;
19258      return nil;
19259    });
19260    
19261    $def(self, '$getbyte', function $$getbyte() {
19262      var $a, self = this;
19263
19264      return ($a = self.$getc(), ($a === nil || $a == null) ? nil : $a.$ord())
19265    });
19266    
19267    $def(self, '$readbyte', function $$readbyte() {
19268      var self = this;
19269
19270      return self.$readchar().$ord()
19271    });
19272    
19273    $def(self, '$readchar', function $$readchar() {
19274      var self = this, $ret_or_1 = nil;
19275
19276      if ($truthy(($ret_or_1 = self.$getc()))) {
19277        return $ret_or_1
19278      } else {
19279        return $Kernel.$raise($$$('EOFError'), "end of file reached")
19280      }
19281    });
19282    
19283    $def(self, '$readline', function $$readline($a) {
19284      var $post_args, args, self = this, $ret_or_1 = nil;
19285
19286      
19287      $post_args = $slice(arguments);
19288      args = $post_args;
19289      if ($truthy(($ret_or_1 = $send(self, 'gets', $to_a(args))))) {
19290        return $ret_or_1
19291      } else {
19292        return $Kernel.$raise($$$('EOFError'), "end of file reached")
19293      };
19294    }, -1);
19295    
19296    $def(self, '$gets', function $$gets(sep, limit, opts) {
19297      var $a, $b, self = this, orig_sep = nil, $ret_or_1 = nil, seplen = nil, data = nil, ret = nil, orig_buffer = nil;
19298      if ($gvars["/"] == null) $gvars["/"] = nil;
19299
19300      
19301      if (sep == null) sep = false;
19302      if (limit == null) limit = nil;
19303      if (opts == null) opts = $hash2([], {});
19304      if (($truthy(sep.$$is_number) && ($not(limit)))) {
19305        $a = [false, sep, limit], (sep = $a[0]), (limit = $a[1]), (opts = $a[2]), $a
19306      };
19307      if ((($truthy(sep.$$is_hash) && ($not(limit))) && ($eqeq(opts, $hash2([], {}))))) {
19308        $a = [false, nil, sep], (sep = $a[0]), (limit = $a[1]), (opts = $a[2]), $a
19309      } else if (($truthy(limit.$$is_hash) && ($eqeq(opts, $hash2([], {}))))) {
19310        $a = [sep, nil, limit], (sep = $a[0]), (limit = $a[1]), (opts = $a[2]), $a
19311      };
19312      orig_sep = sep;
19313      if ($eqeq(sep, false)) {
19314        sep = $gvars["/"]
19315      };
19316      if ($eqeq(sep, "")) {
19317        sep = /\r?\n\r?\n/
19318      };
19319      sep = ($truthy(($ret_or_1 = sep)) ? ($ret_or_1) : (""));
19320      if (!$eqeq(orig_sep, "")) {
19321        sep = sep.$to_str()
19322      };
19323      seplen = ($eqeq(orig_sep, "") ? (2) : (sep.$length()));
19324      if ($eqeq(sep, " ")) {
19325        sep = / /
19326      };
19327      self.read_buffer = ($truthy(($ret_or_1 = self.read_buffer)) ? ($ret_or_1) : (""));
19328      data = "";
19329      ret = nil;
19330      do {
19331      
19332        self.read_buffer = $rb_plus(self.read_buffer, data);
19333        if (($neqeq(sep, "") && ($truthy(($truthy(sep.$$is_regexp) ? (self.read_buffer['$match?'](sep)) : (self.read_buffer['$include?'](sep))))))) {
19334          
19335          orig_buffer = self.read_buffer;
19336          $b = self.read_buffer.$split(sep, 2), $a = $to_ary($b), (ret = ($a[0] == null ? nil : $a[0])), (self.read_buffer = ($a[1] == null ? nil : $a[1])), $b;
19337          if ($neqeq(ret, orig_buffer)) {
19338            ret = $rb_plus(ret, orig_buffer['$[]'](ret.$length(), seplen))
19339          };
19340          break;
19341        };
19342      } while ($truthy((data = self.$sysread_noraise(($eqeq(sep, "") ? (65536) : (1))))));;
19343      if (!$truthy(ret)) {
19344        
19345        $a = [($truthy(($ret_or_1 = self.read_buffer)) ? ($ret_or_1) : ("")), ""], (ret = $a[0]), (self.read_buffer = $a[1]), $a;
19346        if ($eqeq(ret, "")) {
19347          ret = nil
19348        };
19349      };
19350      if ($truthy(ret)) {
19351        
19352        if ($truthy(limit)) {
19353          
19354          ret = ret['$[]'](Opal.Range.$new(0,limit, true));
19355          self.read_buffer = $rb_plus(ret['$[]'](Opal.Range.$new(limit, -1, false)), self.read_buffer);
19356        };
19357        if ($truthy(opts['$[]']("chomp"))) {
19358          ret = ret.$sub(/\r?\n$/, "")
19359        };
19360        if ($eqeq(orig_sep, "")) {
19361          ret = ret.$sub(/^[\r\n]+/, "")
19362        };
19363      };
19364      if ($eqeq(orig_sep, false)) {
19365        $gvars._ = ret
19366      };
19367      return ret;
19368    }, -1);
19369    
19370    $def(self, '$sysread', function $$sysread(integer) {
19371      var self = this, $ret_or_1 = nil;
19372
19373      if ($truthy(($ret_or_1 = self.read_proc(integer)))) {
19374        return $ret_or_1
19375      } else {
19376        
19377        self.eof = true;
19378        return $Kernel.$raise($$$('EOFError'), "end of file reached");
19379      }
19380    });
19381    
19382    $def(self, '$sysread_noraise', function $$sysread_noraise(integer) {
19383      var self = this;
19384
19385      try {
19386        return self.$sysread(integer)
19387      } catch ($err) {
19388        if (Opal.rescue($err, [$$$('EOFError')])) {
19389          try {
19390            return nil
19391          } finally { Opal.pop_exception(); }
19392        } else { throw $err; }
19393      }
19394    });
19395    
19396    $def(self, '$readpartial', function $$readpartial(integer) {
19397      var $a, self = this, $ret_or_1 = nil, part = nil, ret = nil;
19398
19399      
19400      self.read_buffer = ($truthy(($ret_or_1 = self.read_buffer)) ? ($ret_or_1) : (""));
19401      part = self.$sysread(integer);
19402      $a = [$rb_plus(self.read_buffer, ($truthy(($ret_or_1 = part)) ? ($ret_or_1) : (""))), ""], (ret = $a[0]), (self.read_buffer = $a[1]), $a;
19403      if ($eqeq(ret, "")) {
19404        ret = nil
19405      };
19406      return ret;
19407    });
19408    
19409    $def(self, '$read', function $$read(integer) {
19410      var $a, self = this, $ret_or_1 = nil, parts = nil, ret = nil;
19411
19412      
19413      if (integer == null) integer = nil;
19414      self.read_buffer = ($truthy(($ret_or_1 = self.read_buffer)) ? ($ret_or_1) : (""));
19415      parts = "";
19416      ret = nil;
19417      do {
19418      
19419        self.read_buffer = $rb_plus(self.read_buffer, parts);
19420        if (($truthy(integer) && ($truthy($rb_gt(self.read_buffer.$length(), integer))))) {
19421          
19422          $a = [self.read_buffer['$[]'](Opal.Range.$new(0,integer, true)), self.read_buffer['$[]'](Opal.Range.$new(integer, -1, false))], (ret = $a[0]), (self.read_buffer = $a[1]), $a;
19423          return ret;
19424        };
19425      } while ($truthy((parts = self.$sysread_noraise(($truthy(($ret_or_1 = integer)) ? ($ret_or_1) : (65536))))));;
19426      $a = [self.read_buffer, ""], (ret = $a[0]), (self.read_buffer = $a[1]), $a;
19427      return ret;
19428    }, -1);
19429    
19430    $def(self, '$readlines', function $$readlines(separator) {
19431      var self = this;
19432      if ($gvars["/"] == null) $gvars["/"] = nil;
19433
19434      
19435      if (separator == null) separator = $gvars["/"];
19436      return self.$each_line(separator).$to_a();
19437    }, -1);
19438    
19439    $def(self, '$each', function $$each($a, $b) {
19440      var block = $$each.$$p || nil, $post_args, sep, args, self = this, s = nil;
19441      if ($gvars["/"] == null) $gvars["/"] = nil;
19442
19443      $$each.$$p = null;
19444      
19445      ;
19446      $post_args = $slice(arguments);
19447      
19448      if ($post_args.length > 0) sep = $post_args.shift();if (sep == null) sep = $gvars["/"];
19449      args = $post_args;
19450      if (!(block !== nil)) {
19451        return $send(self, 'enum_for', ["each", sep].concat($to_a(args)))
19452      };
19453      while ($truthy((s = $send(self, 'gets', [sep].concat($to_a(args)))))) {
19454      Opal.yield1(block, s)
19455      };
19456      return self;
19457    }, -1);
19458    
19459    $def(self, '$each_byte', function $$each_byte() {
19460      var block = $$each_byte.$$p || nil, self = this, s = nil;
19461
19462      $$each_byte.$$p = null;
19463      
19464      ;
19465      if (!(block !== nil)) {
19466        return self.$enum_for("each_byte")
19467      };
19468      while ($truthy((s = self.$getbyte()))) {
19469      Opal.yield1(block, s)
19470      };
19471      return self;
19472    });
19473    
19474    $def(self, '$each_char', function $$each_char() {
19475      var block = $$each_char.$$p || nil, self = this, s = nil;
19476
19477      $$each_char.$$p = null;
19478      
19479      ;
19480      if (!(block !== nil)) {
19481        return self.$enum_for("each_char")
19482      };
19483      while ($truthy((s = self.$getc()))) {
19484      Opal.yield1(block, s)
19485      };
19486      return self;
19487    });
19488    
19489    $def(self, '$close', $assign_ivar_val("closed", "both"));
19490    
19491    $def(self, '$close_read', function $$close_read() {
19492      var self = this;
19493
19494      if ($eqeq(self.closed, "write")) {
19495        return (self.closed = "both")
19496      } else {
19497        return (self.closed = "read")
19498      }
19499    });
19500    
19501    $def(self, '$close_write', function $$close_write() {
19502      var self = this;
19503
19504      if ($eqeq(self.closed, "read")) {
19505        return (self.closed = "both")
19506      } else {
19507        return (self.closed = "write")
19508      }
19509    });
19510    
19511    $def(self, '$closed?', function $IO_closed$ques$3() {
19512      var self = this;
19513
19514      return self.closed['$==']("both")
19515    });
19516    
19517    $def(self, '$closed_read?', function $IO_closed_read$ques$4() {
19518      var self = this, $ret_or_1 = nil;
19519
19520      if ($truthy(($ret_or_1 = self.closed['$==']("read")))) {
19521        return $ret_or_1
19522      } else {
19523        return self.closed['$==']("both")
19524      }
19525    });
19526    
19527    $def(self, '$closed_write?', function $IO_closed_write$ques$5() {
19528      var self = this, $ret_or_1 = nil;
19529
19530      if ($truthy(($ret_or_1 = self.closed['$==']("write")))) {
19531        return $ret_or_1
19532      } else {
19533        return self.closed['$==']("both")
19534      }
19535    });
19536    
19537    $def(self, '$check_writable', function $$check_writable() {
19538      var self = this;
19539
19540      if ($truthy(self['$closed_write?']())) {
19541        return $Kernel.$raise($$$('IOError'), "not opened for writing")
19542      } else {
19543        return nil
19544      }
19545    });
19546    
19547    $def(self, '$check_readable', function $$check_readable() {
19548      var self = this;
19549
19550      if ($truthy(self['$closed_read?']())) {
19551        return $Kernel.$raise($$$('IOError'), "not opened for reading")
19552      } else {
19553        return nil
19554      }
19555    });
19556    $alias(self, "each_line", "each");
19557    return $alias(self, "eof?", "eof");
19558  })('::', null);
19559  $const_set('::', 'STDIN', ($gvars.stdin = $$$('IO').$new(0, "r")));
19560  $const_set('::', 'STDOUT', ($gvars.stdout = $$$('IO').$new(1, "w")));
19561  $const_set('::', 'STDERR', ($gvars.stderr = $$$('IO').$new(2, "w")));
19562  var console = Opal.global.console;
19563  $$$('STDOUT')['$write_proc='](typeof(process) === 'object' && typeof(process.stdout) === 'object' ? function(s){process.stdout.write(s)} : function(s){console.log(s)});
19564  $$$('STDERR')['$write_proc='](typeof(process) === 'object' && typeof(process.stderr) === 'object' ? function(s){process.stderr.write(s)} : function(s){console.warn(s)});
19565  return ($a = [function(s) { var p = prompt(); if (p !== null) return p + "\n"; return nil; }], $send($$$('STDIN'), 'read_proc=', $a), $a[$a.length - 1]);
19566};
19567
19568Opal.modules["opal/regexp_anchors"] = function(Opal) {/* Generated by Opal 1.7.3 */
19569  var $module = Opal.module, $const_set = Opal.const_set, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$;
19570
19571  Opal.add_stubs('new');
19572  return (function($base, $parent_nesting) {
19573    var self = $module($base, 'Opal');
19574
19575    var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
19576
19577    
19578    $const_set(self, 'REGEXP_START', "^");
19579    $const_set(self, 'REGEXP_END', "$");
19580    $const_set(self, 'FORBIDDEN_STARTING_IDENTIFIER_CHARS', "\\u0001-\\u
19580002F\\u003A-\\u0040\\u005B-\\u005E\\u0060\\u007B-\\u007F");
19581    $const_set(self, 'FORBIDDEN_ENDING_IDENTIFIER_CHARS', "\\u0001-\\u0020\\u0022-\\u002F\\u003A-\\u003E\\u0040\\u005B-\\u005E\\u0060\\u007B-\\u007F");
19582    $const_set(self, 'INLINE_IDENTIFIER_REGEXP', $$('Regexp').$new("[^" + ($$$(self, 'FORBIDDEN_STARTING_IDENTIFIER_CHARS')) + "]*[^" + ($$$(self, 'FORBIDDEN_ENDING_IDENTIFIER_CHARS')) + "]"));
19583    $const_set(self, 'FORBIDDEN_CONST_NAME_CHARS', "\\u0001-\\u0020\\u0021-\\u002F\\u003B-\\u003F\\u0040\\u005B-\\u005E\\u0060\\u007B-\\u007F");
19584    return $const_set(self, 'CONST_NAME_REGEXP', $$('Regexp').$new("" + ($$$(self, 'REGEXP_START')) + "(::)?[A-Z][^" + ($$$(self, 'FORBIDDEN_CONST_NAME_CHARS')) + "]*" + ($$$(self, 'REGEXP_END'))));
19585  })($nesting[0], $nesting)
19586};
19587
19588Opal.modules["opal/mini"] = function(Opal) {/* Generated by Opal 1.7.3 */
19589  var $Object = Opal.Object, nil = Opal.nil;
19590
19591  Opal.add_stubs('require');
19592  
19593  $Object.$require("opal/base");
19594  $Object.$require("corelib/nil");
19595  $Object.$require("corelib/boolean");
19596  $Object.$require("corelib/string");
19597  $Object.$require("corelib/comparable");
19598  $Object.$require("corelib/enumerable");
19599  $Object.$require("corelib/enumerator");
19600  $Object.$require("corelib/array");
19601  $Object.$require("corelib/hash");
19602  $Object.$require("corelib/number");
19603  $Object.$require("corelib/range");
19604  $Object.$require("corelib/proc");
19605  $Object.$require("corelib/method");
19606  $Object.$require("corelib/regexp");
19607  $Object.$require("corelib/variables");
19608  $Object.$require("corelib/io");
19609  return $Object.$require("opal/regexp_anchors");
19610};
19611
19612Opal.modules["corelib/kernel/format"] = function(Opal) {/* Generated by Opal 1.7.3 */
19613  var $coerce_to = Opal.coerce_to, $module = Opal.module, $slice = Opal.slice, $truthy = Opal.truthy, $eqeq = Opal.eqeq, $Opal = Opal.Opal, $Kernel = Opal.Kernel, $gvars = Opal.gvars, $def = Opal.def, $alias = Opal.alias, nil = Opal.nil, $$$ = Opal.$$$;
19614
19615  Opal.add_stubs('respond_to?,[],==,length,coerce_to?,nil?,to_a,raise,to_int,fetch,Integer,Float,to_ary,to_str,inspect,to_s,format');
19616  return (function($base) {
19617    var self = $module($base, 'Kernel');
19618
19619    
19620    
19621    
19622    $def(self, '$format', function $$format(format_string, $a) {
19623      var $post_args, args, ary = nil;
19624      if ($gvars.DEBUG == null) $gvars.DEBUG = nil;
19625
19626      
19627      $post_args = $slice(arguments, 1);
19628      args = $post_args;
19629      if (($eqeq(args.$length(), 1) && ($truthy(args['$[]'](0)['$respond_to?']("to_ary"))))) {
19630        
19631        ary = $Opal['$coerce_to?'](args['$[]'](0), $$$('Array'), "to_ary");
19632        if (!$truthy(ary['$nil?']())) {
19633          args = ary.$to_a()
19634        };
19635      };
19636      
19637      var result = '',
19638          //used for slicing:
19639          begin_slice = 0,
19640          end_slice,
19641          //used for iterating over the format string:
19642          i,
19643          len = format_string.length,
19644          //used for processing field values:
19645          arg,
19646          str,
19647          //used for processing %g and %G fields:
19648          exponent,
19649          //used for keeping track of width and precision:
19650          width,
19651          precision,
19652          //used for holding temporary values:
19653          tmp_num,
19654          //used for processing %{} and %<> fileds:
19655          hash_parameter_key,
19656          closing_brace_char,
19657          //used for processing %b, %B, %o, %x, and %X fields:
19658          base_number,
19659          base_prefix,
19660          base_neg_zero_regex,
19661          base_neg_zero_digit,
19662          //used for processing arguments:
19663          next_arg,
19664          seq_arg_num = 1,
19665          pos_arg_num = 0,
19666          //used for keeping track of flags:
19667          flags,
19668          FNONE  = 0,
19669          FSHARP = 1,
19670          FMINUS = 2,
19671          FPLUS  = 4,
19672          FZERO  = 8,
19673          FSPACE = 16,
19674          FWIDTH = 32,
19675          FPREC  = 64,
19676          FPREC0 = 128;
19677
19678      function CHECK_FOR_FLAGS() {
19679        if (flags&FWIDTH) { $Kernel.$raise($$$('ArgumentError'), "flag after width") }
19680        if (flags&FPREC0) { $Kernel.$raise($$$('ArgumentError'), "flag after precision") }
19681      }
19682
19683      function CHECK_FOR_WIDTH() {
19684        if (flags&FWIDTH) { $Kernel.$raise($$$('ArgumentError'), "width given twice") }
19685        if (flags&FPREC0) { $Kernel.$raise($$$('ArgumentError'), "width after precision") }
19686      }
19687
19688      function GET_NTH_ARG(num) {
19689        if (num >= args.length) { $Kernel.$raise($$$('ArgumentError'), "too few arguments") }
19690        return args[num];
19691      }
19692
19693      function GET_NEXT_ARG() {
19694        switch (pos_arg_num) {
19695        case -1: $Kernel.$raise($$$('ArgumentError'), "unnumbered(" + (seq_arg_num) + ") mixed with 
19695numbered") // raise
19696        case -2: $Kernel.$raise($$$('ArgumentError'), "unnumbered(" + (seq_arg_num) + ") mixed with named") // raise
19697        }
19698        pos_arg_num = seq_arg_num++;
19699        return GET_NTH_ARG(pos_arg_num - 1);
19700      }
19701
19702      function GET_POS_ARG(num) {
19703        if (pos_arg_num > 0) {
19704          $Kernel.$raise($$$('ArgumentError'), "numbered(" + (num) + ") after unnumbered(" + (pos_arg_num) + ")")
19705        }
19706        if (pos_arg_num === -2) {
19707          $Kernel.$raise($$$('ArgumentError'), "numbered(" + (num) + ") after named")
19708        }
19709        if (num < 1) {
19710          $Kernel.$raise($$$('ArgumentError'), "invalid index - " + (num) + "$")
19711        }
19712        pos_arg_num = -1;
19713        return GET_NTH_ARG(num - 1);
19714      }
19715
19716      function GET_ARG() {
19717        return (next_arg === undefined ? GET_NEXT_ARG() : next_arg);
19718      }
19719
19720      function READ_NUM(label) {
19721        var num, str = '';
19722        for (;; i++) {
19723          if (i === len) {
19724            $Kernel.$raise($$$('ArgumentError'), "malformed format string - %*[0-9]")
19725          }
19726          if (format_string.charCodeAt(i) < 48 || format_string.charCodeAt(i) > 57) {
19727            i--;
19728            num = parseInt(str, 10) || 0;
19729            if (num > 2147483647) {
19730              $Kernel.$raise($$$('ArgumentError'), "" + (label) + " too big")
19731            }
19732            return num;
19733          }
19734          str += format_string.charAt(i);
19735        }
19736      }
19737
19738      function READ_NUM_AFTER_ASTER(label) {
19739        var arg, num = READ_NUM(label);
19740        if (format_string.charAt(i + 1) === '$') {
19741          i++;
19742          arg = GET_POS_ARG(num);
19743        } else {
19744          arg = GET_NEXT_ARG();
19745        }
19746        return (arg).$to_int();
19747      }
19748
19749      for (i = format_string.indexOf('%'); i !== -1; i = format_string.indexOf('%', i)) {
19750        str = undefined;
19751
19752        flags = FNONE;
19753        width = -1;
19754        precision = -1;
19755        next_arg = undefined;
19756
19757        end_slice = i;
19758
19759        i++;
19760
19761        switch (format_string.charAt(i)) {
19762        case '%':
19763          begin_slice = i;
19764          // no-break
19765        case '':
19766        case '\n':
19767        case '\0':
19768          i++;
19769          continue;
19770        }
19771
19772        format_sequence: for (; i < len; i++) {
19773          switch (format_string.charAt(i)) {
19774
19775          case ' ':
19776            CHECK_FOR_FLAGS();
19777            flags |= FSPACE;
19778            continue format_sequence;
19779
19780          case '#':
19781            CHECK_FOR_FLAGS();
19782            flags |= FSHARP;
19783            continue format_sequence;
19784
19785          case '+':
19786            CHECK_FOR_FLAGS();
19787            flags |= FPLUS;
19788            continue format_sequence;
19789
19790          case '-':
19791            CHECK_FOR_FLAGS();
19792            flags |= FMINUS;
19793            continue format_sequence;
19794
19795          case '0':
19796            CHECK_FOR_FLAGS();
19797            flags |= FZERO;
19798            continue format_sequence;
19799
19800          case '1':
19801          case '2':
19802          case '3':
19803          case '4':
19804          case '5':
19805          case '6':
19806          case '7':
19807          case '8':
19808          case '9':
19809            tmp_num = READ_NUM('width');
19810            if (format_string.charAt(i + 1) === '$') {
19811              if (i + 2 === len) {
19812                str = '%';
19813                i++;
19814                break format_sequence;
19815              }
19816              if (next_arg !== undefined) {
19817                $Kernel.$raise($$$('ArgumentError'), "value given twice - %" + (tmp_num) + "$")
19818              }
19819              next_arg = GET_POS_ARG(tmp_num);
19820              i++;
19821            } else {
19822              CHECK_FOR_WIDTH();
19823              flags |= FWIDTH;
19824              width = tmp_num;
19825            }
19826            continue format_sequence;
19827
19828          case '<':
19829          case '\{':
19830            closing_brace_char = (format_string.charAt(i) === '<' ? '>' : '\}');
19831            hash_parameter_key = '';
19832
19833            i++;
19834
19835            for (;; i++) {
19836              if (i === len) {
19837                $Kernel.$raise($$$('ArgumentError'), "malformed name - unmatched parenthesis")
19838              }
19839              if (format_string.charAt(i) === closing_brace_char) {
19840
19841                if (pos_arg_num > 0) {
19842                  $Kernel.$raise($$$('ArgumentError'), "named " + (hash_parameter_key) + " after unnumbered(" + (pos_arg_num) + ")")
19843                }
19844                if (pos_arg_num === -1) {
19845                  $Kernel.$raise($$$('ArgumentError'), "named " + (hash_parameter_key) + " after numbered")
19846                }
19847                pos_arg_num = -2;
19848
19849                if (args[0] === undefined || !args[0].$$is_hash) {
19850                  $Kernel.$raise($$$('ArgumentError'), "one hash required")
19851                }
19852
19853                next_arg = (args[0]).$fetch(hash_parameter_key);
19854
19855                if (closing_brace_char === '>') {
19856                  continue format_sequence;
19857                } else {
19858                  str = next_arg.toString();
19859                  if (precision !== -1) { str = str.slice(0, precision); }
19860                  if (flags&FMINUS) {
19861                    while (str.length < width) { str = str + ' '; }
19862                  } else {
19863                    while (str.length < width) { str = ' ' + str; }
19864                  }
19865                  break format_sequence;
19866                }
19867              }
19868              hash_parameter_key += format_string.charAt(i);
19869            }
19870            // raise
19871
19872          case '*':
19873            i++;
19874            CHECK_FOR_WIDTH();
19875            flags |= FWIDTH;
19876            width = READ_NUM_AFTER_ASTER('width');
19877            if (width < 0) {
19878              flags |= FMINUS;
19879              width = -width;
19880            }
19881            continue format_sequence;
19882
19883          case '.':
19884            if (flags&FPREC0) {
19885              $Kernel.$raise($$$('ArgumentError'), "precision given twice")
19886            }
19887            flags |= FPREC|FPREC0;
19888            precision = 0;
19889            i++;
19890            if (format_string.charAt(i) === '*') {
19891              i++;
19892              precision = READ_NUM_AFTER_ASTER('precision');
19893              if (precision < 0) {
19894                flags &= ~FPREC;
19895              }
19896              continue format_sequence;
19897            }
19898            precision = READ_NUM('precision');
19899            continue format_sequence;
19900
19901          case 'd':
19902          case 'i':
19903          case 'u':
19904            arg = $Kernel.$Integer(GET_ARG());
19905            if (arg >= 0) {
19906              str = arg.toString();
19907              while (str.length < precision) { str = '0' + str; }
19908              if (flags&FMINUS) {
19909                if (flags&FPLUS || flags&FSPACE) { str = (flags&FPLUS ? '+' : ' ') + str; }
19910                while (str.length < width) { str = str + ' '; }
19911              } else {
19912                if (flags&FZERO && precision === -1) {
19913                  while (str.length < width - ((flags&FPLUS || flags&FSPACE) ? 1 : 0)) { str = '0' + str; }
19914                  if (flags&FPLUS || flags&FSPACE) { str = (flags&FPLUS ? '+' : ' ') + str; }
19915                } else {
19916                  if (flags&FPLUS || flags&FSPACE) { str = (flags&FPLUS ? '+' : ' ') + str; }
19917                  while (str.length < width) { str = ' ' + str; }
19918                }
19919              }
19920            } else {
19921              str = (-arg).toString();
19922              while (str.length < precision) { str = '0' + str; }
19923              if (flags&FMINUS) {
19924                str = '-' + str;
19925                while (str.length < width) { str = str + ' '; }
19926              } else {
19927                if (flags&FZERO && precision === -1) {
19928                  while (str.length < width - 1) { str = '0' + str; }
19929                  str = '-' + str;
19930                } else {
19931                  str = '-' + str;
19932                  while (str.length < width) { str = ' ' + str; }
19933                }
19934              }
19935            }
19936            break format_sequence;
19937
19938          case 'b':
19939          case 'B':
19940          case 'o':
19941          case 'x':
19942          case 'X':
19943            switch (format_string.charAt(i)) {
19944            case 'b':
19945            case 'B':
19946              base_number = 2;
19947              base_prefix = '0b';
19948              base_neg_zero_regex = /^1+/;
19949              base_neg_zero_digit = '1';
19950              break;
19951            case 'o':
19952              base_number = 8;
19953              base_prefix = '0';
19954              base_neg_zero_regex = /^3?7+/;
19955              base_neg_zero_digit = '7';
19956              break;
19957            case 'x':
19958            case 'X':
19959              base_number = 16;
19960              base_prefix = '0x';
19961              base_neg_zero_regex = /^f+/;
19962              base_neg_zero_digit = 'f';
19963              break;
19964            }
19965            arg = $Kernel.$Integer(GET_ARG());
19966            if (arg >= 0) {
19967              str = arg.toString(base_number);
19968              while (str.length < precision) { str = '0' + str; }
19969              if (flags&FMINUS) {
19970                if (flags&FPLUS || flags&FSPACE) { str = (flags&FPLUS ? '+' : ' ') + str; }
19971                if (flags&FSHARP && arg !== 0) { str = base_prefix + str; }
19972                while (str.length < width) { str = str + ' '; }
19973              } else {
19974                if (flags&FZERO && precision === -1) {
19975                  while (str.length < width - ((flags&FPLUS || flags&FSPACE) ? 1 : 0) - ((flags&FSHARP && arg !== 0) ? base_prefix.length : 0)) { str = '0' + str; }
19976                  if (flags&FSHARP && arg !== 0) { str = base_prefix + str; }
19977                  if (flags&FPLUS || flags&FSPACE) { str = (flags&FPLUS ? '+' : ' ') + str; }
19978                } else {
19979                  if (flags&FSHARP && arg !== 0) { str = base_prefix + str; }
19980                  if (flags&FPLUS || flags&FSPACE) { str = (flags&FPLUS ? '+' : ' ') + str; }
19981                  while (str.length < width) { str = ' ' + str; }
19982                }
19983              }
19984            } else {
19985              if (flags&FPLUS || flags&FSPACE) {
19986                str = (-arg).toString(base_number);
19987                while (str.length < precision) { str = '0' + str; }
19988                if (flags&FMINUS) {
19989                  if (flags&FSHARP) { str = base_prefix + str; }
19990                  str = '-' + str;
19991                  while (str.length < width) { str = str + ' '; }
19992                } else {
19993                  if (flags&FZERO && precision === -1) {
19994                    while (str.length < width - 1 - (flags&FSHARP ? 2 : 0)) { str = '0' + str; }
19995                    if (flags&FSHARP) { str = base_prefix + str; }
19996                    str = '-' + str;
19997                  } else {
19998                    if (flags&FSHARP) { str = base_prefix + str; }
19999                    str = '-' + str;
20000                    while (str.length < width) { str = ' ' + str; }
20001                  }
20002                }
20003              } else {
20004                str = (arg >>> 0).toString(base_number).replace(base_neg_zero_regex, base_neg_zero_digit);
20005                while (str.length < precision - 2) { str = base_neg_zero_digit + str; }
20006                if (flags&FMINUS) {
20007                  str = '..' + str;
20008                  if (flags&FSHARP) { str = base_prefix + str; }
20009                  while (str.length < width) { str = str + ' '; }
20010                } else {
20011                  if (flags&FZERO && precision === -1) {
20012                    while (str.length < width - 2 - (flags&FSHARP ? base_prefix.length : 0)) { str = base_neg_zero_digit + str; }
20013                    str = '..' + str;
20014                    if (flags&FSHARP) { str = base_prefix + str; }
20015                  } else {
20016                    str = '..' + str;
20017                    if (flags&FSHARP) { str = base_prefix + str; }
20018                    while (str.length < width) { str = ' ' + str; }
20019                  }
20020                }
20021              }
20022            }
20023            if (format_string.charAt(i) === format_string.charAt(i).toUpperCase()) {
20024              str = str.toUpperCase();
20025            }
20026            break format_sequence;
20027
20028          case 'f':
20029          case 'e':
20030          case 'E':
20031          case 'g':
20032          case 'G':
20033            arg = $Kernel.$Float(GET_ARG());
20034            if (arg >= 0 || isNaN(arg)) {
20035              if (arg === Infinity) {
20036                str = 'Inf';
20037              } else {
20038                switch (format_string.charAt(i)) {
20039                case 'f':
20040                  str = arg.toFixed(precision === -1 ? 6 : precision);
20041                  break;
20042                case 'e':
20043                case 'E':
20044                  str = arg.toExponential(precision === -1 ? 6 : precision);
20045                  break;
20046                case 'g':
20047                case 'G':
20048                  str = arg.toExponential();
20049                  exponent = parseInt(str.split('e')[1], 10);
20050                  if (!(exponent < -4 || exponent >= (precision === -1 ? 6 : precision))) {
20051                    str = arg.toPrecision(precision === -1 ? (flags&FSHARP ? 6 : undefined) : precision);
20052                  }
20053                  break;
20054                }
20055              }
20056              if (flags&FMINUS) {
20057                if (flags&FPLUS || flags&FSPACE) { str = (flags&FPLUS ? '+' : ' ') + str; }
20058                while (str.length < width) { str = str + ' '; }
20059              } else {
20060                if (flags&FZERO && arg !== Infinity && !isNaN(arg)) {
20061                  while (str.length < width - ((flags&FPLUS || flags&FSPACE) ? 1 : 0)) { str = '0' + str; }
20062                  if (flags&FPLUS || flags&FSPACE) { str = (flags&FPLUS ? '+' : ' ') + str; }
20063                } else {
20064                  if (flags&FPLUS || flags&FSPACE) { str = (flags&FPLUS ? '+' : ' ') + str; }
20065                  while (str.length < width) { str = ' ' + str; }
20066                }
20067              }
20068            } else {
20069              if (arg === -Infinity) {
20070                str = 'Inf';
20071              } else {
20072                switch (format_string.charAt(i)) {
20073                case 'f':
20074                  str = (-arg).toFixed(precision === -1 ? 6 : precision);
20075                  break;
20076                case 'e':
20077                case 'E':
20078                  str = (-arg).toExponential(precision === -1 ? 6 : precision);
20079                  break;
20080                case 'g':
20081                case 'G':
20082                  str = (-arg).toExponential();
20083                  exponent = parseInt(str.split('e')[1], 10);
20084                  if (!(exponent < -4 || exponent >= (precision === -1 ? 6 : precision))) {
20085                    str = (-arg).toPrecision(precision === -1 ? (flags&FSHARP ? 6 : undefined) : precision);
20086                  }
20087                  break;
20088                }
20089              }
20090              if (flags&FMINUS) {
20091                str = '-' + str;
20092                while (str.length < width) { str = str + ' '; }
20093              } else {
20094                if (flags&FZERO && arg !== -Infinity) {
20095                  while (str.length < width - 1) { str = '0' + str; }
20096                  str = '-' + str;
20097                } else {
20098                  str = '-' + str;
20099                  while (str.length < width) { str = ' ' + str; }
20100                }
20101              }
20102            }
20103            if (format_string.charAt(i) === format_string.charAt(i).toUpperCase() && arg !== Infinity && arg !== -Infinity && !isNaN(arg)) {
20104              str = str.toUpperCase();
20105            }
20106            str = str.replace(/([eE][-+]?)([0-9])$/, '$10$2');
20107            break format_sequence;
20108
20109          case 'a':
20110          case 'A':
20111            // Not implemented because there are no specs for this field type.
20112            $Kernel.$raise($$$('NotImplementedError'), "`A` and `a` format field types are not implemented in Opal yet")
20113            // raise
20114
20115          case 'c':
20116            arg = GET_ARG();
20117            if ((arg)['$respond_to?']("to_ary")) { arg = (arg).$to_ary()[0]; }
20118            if ((arg)['$respond_to?']("to_str")) {
20119              str = (arg).$to_str();
20120            } else {
20121              str = String.fromCharCode($coerce_to(arg, $$$('Integer'), 'to_int'));
20122            }
20123            if (str.length !== 1) {
20124              $Kernel.$raise($$$('ArgumentError'), "%c requires a character")
20125            }
20126            if (flags&FMINUS) {
20127              while (str.length < width) { str = str + ' '; }
20128            } else {
20129              while (str.length < width) { str = ' ' + str; }
20130            }
20131            break format_sequence;
20132
20133          case 'p':
20134            str = (GET_ARG()).$inspect();
20135            if (precision !== -1) { str = str.slice(0, precision); }
20136            if (flags&FMINUS) {
20137              while (str.length < width) { str = str + ' '; }
20138            } else {
20139              while (str.length < width) { str = ' ' + str; }
20140            }
20141            break format_sequence;
20142
20143          case 's':
20144            str = (GET_ARG()).$to_s();
20145            if (precision !== -1) { str = str.slice(0, precision); }
20146            if (flags&FMINUS) {
20147              while (str.length < width) { str = str + ' '; }
20148            } else {
20149              while (str.length < width) { str = ' ' + str; }
20150            }
20151            break format_sequence;
20152
20153          default:
20154            $Kernel.$raise($$$('ArgumentError'), "malformed format string - %" + (format_string.charAt(i)))
20155          }
20156        }
20157
20158        if (str === undefined) {
20159          $Kernel.$raise($$$('ArgumentError'), "malformed format string - %")
20160        }
20161
20162        result += format_string.slice(begin_slice, end_slice) + str;
20163        begin_slice = i + 1;
20164      }
20165
20166      if ($gvars.DEBUG && pos_arg_num >= 0 && seq_arg_num < args.length) {
20167        $Kernel.$raise($$$('ArgumentError'), "too many arguments for format string")
20168      }
20169
20170      return result + format_string.slice(begin_slice);
20171    ;
20172    }, -2);
20173    return $alias(self, "sprintf", "format");
20174  })('::')
20175};
20176
20177Opal.modules["corelib/string/encoding"] = function(Opal) {/* Generated by Opal 1.7.3 */
20178  var $klass = Opal.klass, $hash2 = Opal.hash2, $rb_plus = Opal.rb_plus, $truthy = Opal.truthy, $send = Opal.send, $defs = Opal.defs, $eqeq = Opal.eqeq, $def = Opal.def, $return_ivar = Opal.return_ivar, $return_val = Opal.return_val, $slice = Opal.slice, $Kernel = Opal.Kernel, $Opal = Opal.Opal, $rb_lt = Opal.rb_lt, $a, self = Opal.top, $nesting = [], $$ = Opal.$r($nesting), nil = Opal.nil, $$$ = Opal.$$$;
20179
20180  Opal.add_stubs('require,+,[],clone,initialize,new,instance_eval,to_proc,each,const_set,tr,==,default_external,attr_accessor,singleton_class,attr_reader,raise,register,length,bytes,force_encoding,dup,bytesize,enum_for,each_byte,to_a,each_char,each_codepoint,coerce_to!,find,<,default_external=');
20181  
20182  self.$require("corelib/string");
20183  (function($base, $super) {
20184    var self = $klass($base, $super, 'Encoding');
20185
20186    var $proto = self.$$prototype;
20187
20188    $proto.name = $proto.dummy = nil;
20189    
20190    $defs(self, '$register', function $$register(name, options) {
20191      var block = $$register.$$p || nil, self = this, names = nil, $ret_or_1 = nil, ascii = nil, dummy = nil, encoding = nil, register = nil;
20192
20193      $$register.$$p = null;
20194      
20195      ;
20196      if (options == null) options = $hash2([], {});
20197      names = $rb_plus([name], ($truthy(($ret_or_1 = options['$[]']("aliases"))) ? ($ret_or_1) : ([])));
20198      ascii = ($truthy(($ret_or_1 = options['$[]']("ascii"))) && ($ret_or_1));
20199      dummy = ($truthy(($ret_or_1 = options['$[]']("dummy"))) && ($ret_or_1));
20200      if ($truthy(options['$[]']("inherits"))) {
20201        
20202        encoding = options['$[]']("inherits").$clone();
20203        encoding.$initialize(name, names, ascii, dummy);
20204      } else {
20205        encoding = self.$new(name, names, ascii, dummy)
20206      };
20207      if ((block !== nil)) {
20208        $send(encoding, 'instance_eval', [], block.$to_proc())
20209      };
20210      register = Opal.encodings;
20211      return $send(names, 'each', [], function $$1(encoding_name){var self = $$1.$$s == null ? this : $$1.$$s;
20212
20213        
20214        if (encoding_name == null) encoding_name = nil;
20215        self.$const_set(encoding_name.$tr("-", "_"), encoding);
20216        return register[encoding_name] = encoding;}, {$$s: self});
20217    }, -2);
20218    $defs(self, '$find', function $$find(name) {
20219      var self = this;
20220
20221      
20222      if ($eqeq(name, "default_external")) {
20223        return self.$default_external()
20224      };
20225      return Opal.find_encoding(name);;
20226    });
20227    self.$singleton_class().$attr_accessor("default_external");
20228    self.$attr_reader("name", "names");
20229    
20230    $def(self, '$initialize', function $$initialize(name, names, ascii, dummy) {
20231      var self = this;
20232
20233      
20234      self.name = name;
20235      self.names = names;
20236      self.ascii = ascii;
20237      return (self.dummy = dummy);
20238    });
20239    
20240    $def(self, '$ascii_compatible?', $return_ivar("ascii"));
20241    
20242    $def(self, '$dummy?', $return_ivar("dummy"));
20243    
20244    $def(self, '$binary?', $return_val(false));
20245    
20246    $def(self, '$to_s', $return_ivar("name"));
20247    
20248    $def(self, '$inspect', function $$inspect() {
20249      var self = this;
20250
20251      return "#<Encoding:" + (self.name) + (($truthy(self.dummy) ? (" (dummy)") : nil)) + ">"
20252    });
20253    
20254    $def(self, '$charsize', function $$charsize(string) {
20255      
20256      
20257      var len = 0;
20258      for (var i = 0, length = string.length; i < length; i++) {
20259        var charcode = string.charCodeAt(i);
20260        if (!(charcode >= 0xD800 && charcode <= 0xDBFF)) {
20261          len++;
20262        }
20263      }
20264      return len;
20265    
20266    });
20267    
20268    $def(self, '$each_char', function $$each_char(string) {
20269      var block = $$each_char.$$p || nil;
20270
20271      $$each_char.$$p = null;
20272      
20273      ;
20274      
20275      var low_surrogate = "";
20276      for (var i = 0, length = string.length; i < length; i++) {
20277        var charcode = string.charCodeAt(i);
20278        var chr = string.charAt(i);
20279        if (charcode >= 0xDC00 && charcode <= 0xDFFF) {
20280          low_surrogate = chr;
20281          continue;
20282        }
20283        else if (charcode >= 0xD800 && charcode <= 0xDBFF) {
20284          chr = low_surrogate + chr;
20285        }
20286        if (string.encoding.name != "UTF-8") {
20287          chr = new String(chr);
20288          chr.encoding = string.encoding;
20289        }
20290        Opal.yield1(block, chr);
20291      }
20292    ;
20293    });
20294    
20295    $def(self, '$each_byte', function $$each_byte($a) {
20296      var $post_args, $fwd_rest;
20297
20298      
20299      $post_args = $slice(arguments);
20300      $fwd_rest = $post_args;
20301      return $Kernel.$raise($$$('NotImplementedError'));
20302    }, -1);
20303    
20304    $def(self, '$bytesize', function $$bytesize($a) {
20305      var $post_args, $fwd_rest;
20306
20307      
20308      $post_args = $slice(arguments);
20309      $fwd_rest = $post_args;
20310      return $Kernel.$raise($$$('NotImplementedError'));
20311    }, -1);
20312    $klass('::', $$$('StandardError'), 'EncodingError');
20313    return ($klass('::', $$$('EncodingError'), 'CompatibilityError'), nil);
20314  })('::', null);
20315  $send($$$('Encoding'), 'register', ["UTF-8", $hash2(["aliases", "ascii"], {"aliases": ["CP65001"], "ascii": true})], function $$2(){var self = $$2.$$s == null ? this : $$2.$$s;
20316
20317    
20318    
20319    $def(self, '$each_byte', function $$each_byte(string) {
20320      var block = $$each_byte.$$p || nil;
20321
20322      $$each_byte.$$p = null;
20323      
20324      ;
20325      
20326      // Taken from: https://github.com/feross/buffer/blob/f52dffd9df0445b93c0c9065c2f8f0f46b2c729a/index.js#L1954-L2032
20327      var units = Infinity;
20328      var codePoint;
20329      var length = string.length;
20330      var leadSurrogate = null;
20331
20332      for (var i = 0; i < length; ++i) {
20333        codePoint = string.charCodeAt(i);
20334
20335        // is surrogate component
20336        if (codePoint > 0xD7FF && codePoint < 0xE000) {
20337          // last char was a lead
20338          if (!leadSurrogate) {
20339            // no lead yet
20340            if (codePoint > 0xDBFF) {
20341              // unexpected trail
20342              if ((units -= 3) > -1) {
20343                Opal.yield1(block, 0xEF);
20344                Opal.yield1(block, 0xBF);
20345                Opal.yield1(block, 0xBD);
20346              }
20347              continue;
20348            } else if (i + 1 === length) {
20349              // unpaired lead
20350              if ((units -= 3) > -1) {
20351                Opal.yield1(block, 0xEF);
20352                Opal.yield1(block, 0xBF);
20353                Opal.yield1(block, 0xBD);
20354              }
20355              continue;
20356            }
20357
20358            // valid lead
20359            leadSurrogate = codePoint;
20360
20361            continue;
20362          }
20363
20364          // 2 leads in a row
20365          if (codePoint < 0xDC00) {
20366            if ((units -= 3) > -1) {
20367              Opal.yield1(block, 0xEF);
20368              Opal.yield1(block, 0xBF);
20369              Opal.yield1(block, 0xBD);
20370            }
20371            leadSurrogate = codePoint;
20372            continue;
20373          }
20374
20375          // valid surrogate pair
20376          codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000;
20377        } else if (leadSurrogate) {
20378          // valid bmp char, but last char was a lead
20379          if ((units -= 3) > -1) {
20380            Opal.yield1(block, 0xEF);
20381            Opal.yield1(block, 0xBF);
20382            Opal.yield1(block, 0xBD);
20383          }
20384        }
20385
20386        leadSurrogate = null;
20387
20388        // encode utf8
20389        if (codePoint < 0x80) {
20390          if ((units -= 1) < 0) break;
20391          Opal.yield1(block, codePoint);
20392        } else if (codePoint < 0x800) {
20393          if ((units -= 2) < 0) break;
20394          Opal.yield1(block, codePoint >> 0x6 | 0xC0);
20395          Opal.yield1(block, codePoint & 0x3F | 0x80);
20396        } else if (codePoint < 0x10000) {
20397          if ((units -= 3) < 0) break;
20398          Opal.yield1(block, codePoint >> 0xC | 0xE0);
20399          Opal.yield1(block, codePoint >> 0x6 & 0x3F | 0x80);
20400          Opal.yield1(block, codePoint & 0x3F | 0x80);
20401        } else if (codePoint < 0x110000) {
20402          if ((units -= 4) < 0) break;
20403          Opal.yield1(block, codePoint >> 0x12 | 0xF0);
20404          Opal.yield1(block, codePoint >> 0xC & 0x3F | 0x80);
20405          Opal.yield1(block, codePoint >> 0x6 & 0x3F | 0x80);
20406          Opal.yield1(block, codePoint & 0x3F | 0x80);
20407        } else {
20408          // Invalid code point
20409        }
20410      }
20411    ;
20412    });
20413    return $def(self, '$bytesize', function $$bytesize(string) {
20414      
20415      return string.$bytes().$length()
20416    });}, {$$s: self});
20417  $send($$$('Encoding'), 'register', ["UTF-16LE"], function $$3(){var self = $$3.$$s == null ? this : $$3.$$s;
20418
20419    
20420    
20421    $def(self, '$each_byte', function $$each_byte(string) {
20422      var block = $$each_byte.$$p || nil;
20423
20424      $$each_byte.$$p = null;
20425      
20426      ;
20427      
20428      for (var i = 0, length = string.length; i < length; i++) {
20429        var code = string.charCodeAt(i);
20430
20431        Opal.yield1(block, code & 0xff);
20432        Opal.yield1(block, code >> 8);
20433      }
20434    ;
20435    });
20436    return $def(self, '$bytesize', function $$bytesize(string) {
20437      
20438      return string.length * 2;
20439    });}, {$$s: self});
20440  $send($$$('Encoding'), 'register', ["UTF-16BE", $hash2(["inherits"], {"inherits": $$$($$$('Encoding'), 'UTF_16LE')})], function $$4(){var self = $$4.$$s == null ? this : $$4.$$s;
20441
20442    return $def(self, '$each_byte', function $$each_byte(string) {
20443      var block = $$each_byte.$$p || nil;
20444
20445      $$each_byte.$$p = null;
20446      
20447      ;
20448      
20449      for (var i = 0, length = string.length; i < length; i++) {
20450        var code = string.charCodeAt(i);
20451
20452        Opal.yield1(block, code >> 8);
20453        Opal.yield1(block, code & 0xff);
20454      }
20455    ;
20456    })}
20456, {$$s: self});
20457  $send($$$('Encoding'), 'register', ["UTF-32LE"], function $$5(){var self = $$5.$$s == null ? this : $$5.$$s;
20458
20459    
20460    
20461    $def(self, '$each_byte', function $$each_byte(string) {
20462      var block = $$each_byte.$$p || nil;
20463
20464      $$each_byte.$$p = null;
20465      
20466      ;
20467      
20468      for (var i = 0, length = string.length; i < length; i++) {
20469        var code = string.charCodeAt(i);
20470
20471        Opal.yield1(block, code & 0xff);
20472        Opal.yield1(block, code >> 8);
20473        Opal.yield1(block, 0);
20474        Opal.yield1(block, 0);
20475      }
20476    ;
20477    });
20478    return $def(self, '$bytesize', function $$bytesize(string) {
20479      
20480      return string.length * 4;
20481    });}, {$$s: self});
20482  $send($$$('Encoding'), 'register', ["UTF-32BE", $hash2(["inherits"], {"inherits": $$$($$$('Encoding'), 'UTF_32LE')})], function $$6(){var self = $$6.$$s == null ? this : $$6.$$s;
20483
20484    return $def(self, '$each_byte', function $$each_byte(string) {
20485      var block = $$each_byte.$$p || nil;
20486
20487      $$each_byte.$$p = null;
20488      
20489      ;
20490      
20491      for (var i = 0, length = string.length; i < length; i++) {
20492        var code = string.charCodeAt(i);
20493
20494        Opal.yield1(block, 0);
20495        Opal.yield1(block, 0);
20496        Opal.yield1(block, code >> 8);
20497        Opal.yield1(block, code & 0xff);
20498      }
20499    ;
20500    })}, {$$s: self});
20501  $send($$$('Encoding'), 'register', ["ASCII-8BIT", $hash2(["aliases", "ascii"], {"aliases": ["BINARY"], "ascii": true})], function $$7(){var self = $$7.$$s == null ? this : $$7.$$s;
20502
20503    
20504    
20505    $def(self, '$each_char', function $$each_char(string) {
20506      var block = $$each_char.$$p || nil;
20507
20508      $$each_char.$$p = null;
20509      
20510      ;
20511      
20512      for (var i = 0, length = string.length; i < length; i++) {
20513        var chr = new String(string.charAt(i));
20514        chr.encoding = string.encoding;
20515        Opal.yield1(block, chr);
20516      }
20517    ;
20518    });
20519    
20520    $def(self, '$charsize', function $$charsize(string) {
20521      
20522      return string.length;
20523    });
20524    
20525    $def(self, '$each_byte', function $$each_byte(string) {
20526      var block = $$each_byte.$$p || nil;
20527
20528      $$each_byte.$$p = null;
20529      
20530      ;
20531      
20532      for (var i = 0, length = string.length; i < length; i++) {
20533        var code = string.charCodeAt(i);
20534        Opal.yield1(block, code & 0xff);
20535      }
20536    ;
20537    });
20538    
20539    $def(self, '$bytesize', function $$bytesize(string) {
20540      
20541      return string.length;
20542    });
20543    return $def(self, '$binary?', $return_val(true));}, {$$s: self});
20544  $$$('Encoding').$register("ISO-8859-1", $hash2(["aliases", "ascii", "inherits"], {"aliases": ["ISO8859-1"], "ascii": true, "inherits": $$$($$$('Encoding'), 'ASCII_8BIT')}));
20545  $$$('Encoding').$register("US-ASCII", $hash2(["aliases", "ascii", "inherits"], {"aliases": ["ASCII"], "ascii": true, "inherits": $$$($$$('Encoding'), 'ASCII_8BIT')}));
20546  (function($base, $super) {
20547    var self = $klass($base, $super, 'String');
20548
20549    var $proto = self.$$prototype;
20550
20551    $proto.internal_encoding = $proto.bytes = $proto.encoding = nil;
20552    
20553    self.$attr_reader("encoding");
20554    self.$attr_reader("internal_encoding");
20555    Opal.prop(String.prototype, 'bytes', nil);
20556    Opal.prop(String.prototype, 'encoding', $$$($$$('Encoding'), 'UTF_8'));
20557    Opal.prop(String.prototype, 'internal_encoding', $$$($$$('Encoding'), 'UTF_8'));
20558    
20559    $def(self, '$b', function $$b() {
20560      var self = this;
20561
20562      return self.$dup().$force_encoding("binary")
20563    });
20564    
20565    $def(self, '$bytesize', function $$bytesize() {
20566      var self = this;
20567
20568      return self.internal_encoding.$bytesize(self)
20569    });
20570    
20571    $def(self, '$each_byte', function $$each_byte() {
20572      var block = $$each_byte.$$p || nil, self = this;
20573
20574      $$each_byte.$$p = null;
20575      
20576      ;
20577      if (!(block !== nil)) {
20578        return $send(self, 'enum_for', ["each_byte"], function $$8(){var self = $$8.$$s == null ? this : $$8.$$s;
20579
20580          return self.$bytesize()}, {$$s: self})
20581      };
20582      $send(self.internal_encoding, 'each_byte', [self], block.$to_proc());
20583      return self;
20584    });
20585    
20586    $def(self, '$bytes', function $$bytes() {
20587      var self = this, $ret_or_1 = nil;
20588
20589      
20590      
20591      if (typeof self === 'string') {
20592        return (new String(self)).$each_byte().$to_a();
20593      }
20594    ;
20595      self.bytes = ($truthy(($ret_or_1 = self.bytes)) ? ($ret_or_1) : (self.$each_byte().$to_a()));
20596      return self.bytes.$dup();
20597    });
20598    
20599    $def(self, '$each_char', function $$each_char() {
20600      var block = $$each_char.$$p || nil, self = this;
20601
20602      $$each_char.$$p = null;
20603      
20604      ;
20605      if (!(block !== nil)) {
20606        return $send(self, 'enum_for', ["each_char"], function $$9(){var self = $$9.$$s == null ? this : $$9.$$s;
20607
20608          return self.$length()}
20608, {$$s: self})
20609      };
20610      $send(self.encoding, 'each_char', [self], block.$to_proc());
20611      return self;
20612    });
20613    
20614    $def(self, '$chars', function $$chars() {
20615      var block = $$chars.$$p || nil, self = this;
20616
20617      $$chars.$$p = null;
20618      
20619      ;
20620      if (!$truthy(block)) {
20621        return self.$each_char().$to_a()
20622      };
20623      return $send(self, 'each_char', [], block.$to_proc());
20624    });
20625    
20626    $def(self, '$each_codepoint', function $$each_codepoint() {
20627      var block = $$each_codepoint.$$p || nil, self = this;
20628
20629      $$each_codepoint.$$p = null;
20630      
20631      ;
20632      if (!(block !== nil)) {
20633        return self.$enum_for("each_codepoint")
20634      };
20635      
20636      for (var i = 0, length = self.length; i < length; i++) {
20637        Opal.yield1(block, self.codePointAt(i));
20638      }
20639    ;
20640      return self;
20641    });
20642    
20643    $def(self, '$codepoints', function $$codepoints() {
20644      var block = $$codepoints.$$p || nil, self = this;
20645
20646      $$codepoints.$$p = null;
20647      
20648      ;
20649      if ((block !== nil)) {
20650        return $send(self, 'each_codepoint', [], block.$to_proc())
20651      };
20652      return self.$each_codepoint().$to_a();
20653    });
20654    
20655    $def(self, '$encode', function $$encode(encoding) {
20656      var self = this;
20657
20658      return Opal.enc(self, encoding);
20659    });
20660    
20661    $def(self, '$force_encoding', function $$force_encoding(encoding) {
20662      var self = this;
20663
20664      
20665      var str = self;
20666
20667      if (encoding === str.encoding) { return str; }
20668
20669      encoding = $Opal['$coerce_to!'](encoding, $$$('String'), "to_s");
20670      encoding = $$$('Encoding').$find(encoding);
20671
20672      if (encoding === str.encoding) { return str; }
20673
20674      str = Opal.set_encoding(str, encoding);
20675
20676      return str;
20677    
20678    });
20679    
20680    $def(self, '$getbyte', function $$getbyte(idx) {
20681      var self = this, string_bytes = nil;
20682
20683      
20684      string_bytes = self.$bytes();
20685      idx = $Opal['$coerce_to!'](idx, $$$('Integer'), "to_int");
20686      if ($truthy($rb_lt(string_bytes.$length(), idx))) {
20687        return nil
20688      };
20689      return string_bytes['$[]'](idx);
20690    });
20691    
20692    $def(self, '$initialize_copy', function $$initialize_copy(other) {
20693      
20694      return "\n" + "      self.encoding = other.encoding;\n" + "      self.internal_encoding = other.internal_encoding;\n" + "    "
20695    });
20696    return $def(self, '$valid_encoding?', $return_val(true));
20697  })('::', null);
20698  return ($a = [$$$($$('Encoding'), 'UTF_8')], $send($$$('Encoding'), 'default_external=', $a), $a[$a.length - 1]);
20699};
20700
20701Opal.modules["corelib/math"] = function(Opal) {/* Generated by Opal 1.7.3 */
20702  var $type_error = Opal.type_error, $module = Opal.module, $const_set = Opal.const_set, $Class = Opal.Class, $slice = Opal.slice, $Kernel = Opal.Kernel, $defs = Opal.defs, $truthy = Opal.truthy, $send = Opal.send, $def = Opal.def, $rb_minus = Opal.rb_minus, $eqeqeq = Opal.eqeqeq, $rb_divide = Opal.rb_divide, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$;
20703
20704  Opal.add_stubs('new,raise,Float,Integer,module_function,each,define_method,checked,float!,===,gamma,-,integer!,/,infinite?');
20705  return (function($base, $parent_nesting) {
20706    var self = $module($base, 'Math');
20707
20708    var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
20709
20710    
20711    $const_set(self, 'E', Math.E);
20712    $const_set(self, 'PI', Math.PI);
20713    $const_set(self, 'DomainError', $Class.$new($$$('StandardError')));
20714    $defs(self, '$checked', function $$checked(method, $a) {
20715      var $post_args, args;
20716
20717      
20718      $post_args = $slice(arguments, 1);
20719      args = $post_args;
20720      
20721      if (isNaN(args[0]) || (args.length == 2 && isNaN(args[1]))) {
20722        return NaN;
20723      }
20724
20725      var result = Math[method].apply(null, args);
20726
20727      if (isNaN(result)) {
20728        $Kernel.$raise($$('DomainError'), "Numerical argument is out of domain - \"" + (method) + "\"");
20729      }
20730
20731      return result;
20732    ;
20733    }, -2);
20734    $defs(self, '$float!', function $Math_float$excl$1(value) {
20735      
20736      try {
20737        return $Kernel.$Float(value)
20738      } catch ($err) {
20739        if (Opal.rescue($err, [$$$('ArgumentError')])) {
20740          try {
20741            return $Kernel.$raise($type_error(value, $$$('Float')))
20742          } finally { Opal.pop_exception(); }
20743        } else { throw $err; }
20744      }
20745    });
20746    $defs(self, '$integer!', function $Math_integer$excl$2(value) {
20747      
20748      try {
20749        return $Kernel.$Integer(value)
20750      } catch ($err) {
20751        if (Opal.rescue($err, [$$$('ArgumentError')])) {
20752          try {
20753            return $Kernel.$raise($type_error(value, $$$('Integer')))
20754          } finally { Opal.pop_exception(); }
20755        } else { throw $err; }
20756      }
20757    });
20758    self.$module_function();
20759    if (!$truthy((typeof(Math.erf) !== "undefined"))) {
20760      
20761      Opal.prop(Math, 'erf', function(x) {
20762        var A1 =  0.254829592,
20763            A2 = -0.284496736,
20764            A3 =  1.421413741,
20765            A4 = -1.453152027,
20766            A5 =  1.061405429,
20767            P  =  0.3275911;
20768
20769        var sign = 1;
20770
20771        if (x < 0) {
20772            sign = -1;
20773        }
20774
20775        x = Math.abs(x);
20776
20777        var t = 1.0 / (1.0 + P * x);
20778        var y = 1.0 - (((((A5 * t + A4) * t) + A3) * t + A2) * t + A1) * t * Math.exp(-x * x);
20779
20780        return sign * y;
20781      });
20782    
20783    };
20784    if (!$truthy((typeof(Math.erfc) !== "undefined"))) {
20785      
20786      Opal.prop(Math, 'erfc', function(x) {
20787        var z = Math.abs(x),
20788            t = 1.0 / (0.5 * z + 1.0);
20789
20790        var A1 = t * 0.17087277 + -0.82215223,
20791            A2 = t * A1 + 1.48851587,
20792            A3 = t * A2 + -1.13520398,
20793            A4 = t * A3 + 0.27886807,
20794            A5 = t * A4 + -0.18628806,
20795            A6 = t * A5 + 0.09678418,
20796            A7 = t * A6 + 0.37409196,
20797            A8 = t * A7 + 1.00002368,
20798            A9 = t * A8,
20799            A10 = -z * z - 1.26551223 + A9;
20800
20801        var a = t * Math.exp(A10);
20802
20803        if (x < 0.0) {
20804          return 2.0 - a;
20805        }
20806        else {
20807          return a;
20808        }
20809      });
20810    
20811    };
20812    $send(["acos", "acosh", "asin", "asinh", "atan", "atanh", "cbrt", "cos", "cosh", "erf", "erfc", "exp", "sin", "sinh", "sqrt", "tanh"], 'each', [], function $Math$3(method){var self = $Math$3.$$s == null ? this : $Math$3.$$s;
20813
20814      
20815      if (method == null) method = nil;
20816      return $send(self, 'define_method', [method], function $$4(x){
20817        
20818        if (x == null) x = nil;
20819        return $$$('Math').$checked(method, $$$('Math')['$float!'](x));});}, {$$s: self});
20820    
20821    $def(self, '$atan2', function $$atan2(y, x) {
20822      
20823      return $$$('Math').$checked("atan2", $$$('Math')['$float!'](y), $$$('Math')['$float!'](x))
20824    });
20825    
20826    $def(self, '$hypot', function $$hypot(x, y) {
20827      
20828      return $$$('Math').$checked("hypot", $$$('Math')['$float!'](x), $$$('Math')['$float!'](y))
20829    });
20830    
20831    $def(self, '$frexp', function $$frexp(x) {
20832      
20833      
20834      x = $$('Math')['$float!'](x);
20835      
20836      if (isNaN(x)) {
20837        return [NaN, 0];
20838      }
20839
20840      var ex   = Math.floor(Math.log(Math.abs(x)) / Math.log(2)) + 1,
20841          frac = x / Math.pow(2, ex);
20842
20843      return [frac, ex];
20844    ;
20845    });
20846    
20847    $def(self, '$gamma', function $$gamma(n) {
20848      
20849      
20850      n = $$('Math')['$float!'](n);
20851      
20852      var i, t, x, value, result, twoN, threeN, fourN, fiveN;
20853
20854      var G = 4.7421875;
20855
20856      var P = [
20857         0.99999999999999709182,
20858         57.156235665862923517,
20859        -59.597960355475491248,
20860         14.136097974741747174,
20861        -0.49191381609762019978,
20862         0.33994649984811888699e-4,
20863         0.46523628927048575665e-4,
20864        -0.98374475304879564677e-4,
20865         0.15808870322491248884e-3,
20866        -0.21026444172410488319e-3,
20867         0.21743961811521264320e-3,
20868        -0.16431810653676389022e-3,
20869         0.84418223983852743293e-4,
20870        -0.26190838401581408670e-4,
20871         0.36899182659531622704e-5
20872      ];
20873
20874
20875      if (isNaN(n)) {
20876        return NaN;
20877      }
20878
20879      if (n === 0 && 1 / n < 0) {
20880        return -Infinity;
20881      }
20882
20883      if (n === -1 || n === -Infinity) {
20884        $Kernel.$raise($$('DomainError'), "Numerical argument is out of domain - \"gamma\"");
20885      }
20886
20887      if ($$('Integer')['$==='](n)) {
20888        if (n <= 0) {
20889          return isFinite(n) ? Infinity : NaN;
20890        }
20891
20892        if (n > 171) {
20893          return Infinity;
20894        }
20895
20896        value  = n - 2;
20897        result = n - 1;
20898
20899        while (value > 1) {
20900          result *= value;
20901          value--;
20902        }
20903
20904        if (result == 0) {
20905          result = 1;
20906        }
20907
20908        return result;
20909      }
20910
20911      if (n < 0.5) {
20912        return Math.PI / (Math.sin(Math.PI * n) * $$$('Math').$gamma($rb_minus(1, n)));
20913      }
20914
20915      if (n >= 171.35) {
20916        return Infinity;
20917      }
20918
20919      if (n >
20919 85.0) {
20920        twoN   = n * n;
20921        threeN = twoN * n;
20922        fourN  = threeN * n;
20923        fiveN  = fourN * n;
20924
20925        return Math.sqrt(2 * Math.PI / n) * Math.pow((n / Math.E), n) *
20926          (1 + 1 / (12 * n) + 1 / (288 * twoN) - 139 / (51840 * threeN) -
20927          571 / (2488320 * fourN) + 163879 / (209018880 * fiveN) +
20928          5246819 / (75246796800 * fiveN * n));
20929      }
20930
20931      n -= 1;
20932      x  = P[0];
20933
20934      for (i = 1; i < P.length; ++i) {
20935        x += P[i] / (n + i);
20936      }
20937
20938      t = n + G + 0.5;
20939
20940      return Math.sqrt(2 * Math.PI) * Math.pow(t, n + 0.5) * Math.exp(-t) * x;
20941    ;
20942    });
20943    
20944    $def(self, '$ldexp', function $$ldexp(mantissa, exponent) {
20945      
20946      
20947      mantissa = $$('Math')['$float!'](mantissa);
20948      exponent = $$('Math')['$integer!'](exponent);
20949      
20950      if (isNaN(exponent)) {
20951        $Kernel.$raise($$$('RangeError'), "float NaN out of range of integer");
20952      }
20953
20954      return mantissa * Math.pow(2, exponent);
20955    ;
20956    });
20957    
20958    $def(self, '$lgamma', function $$lgamma(n) {
20959      
20960      
20961      if (n == -1) {
20962        return [Infinity, 1];
20963      }
20964      else {
20965        return [Math.log(Math.abs($$$('Math').$gamma(n))), $$$('Math').$gamma(n) < 0 ? -1 : 1];
20966      }
20967    
20968    });
20969    
20970    $def(self, '$log', function $$log(x, base) {
20971      
20972      
20973      ;
20974      if ($eqeqeq($$$('String'), x)) {
20975        $Kernel.$raise($type_error(x, $$$('Float')))
20976      };
20977      if ($truthy(base == null)) {
20978        return $$$('Math').$checked("log", $$$('Math')['$float!'](x))
20979      } else {
20980        
20981        if ($eqeqeq($$$('String'), base)) {
20982          $Kernel.$raise($type_error(base, $$$('Float')))
20983        };
20984        return $rb_divide($$$('Math').$checked("log", $$$('Math')['$float!'](x)), $$$('Math').$checked("log", $$$('Math')['$float!'](base)));
20985      };
20986    }, -2);
20987    
20988    $def(self, '$log10', function $$log10(x) {
20989      
20990      
20991      if ($eqeqeq($$$('String'), x)) {
20992        $Kernel.$raise($type_error(x, $$$('Float')))
20993      };
20994      return $$$('Math').$checked("log10", $$$('Math')['$float!'](x));
20995    });
20996    
20997    $def(self, '$log2', function $$log2(x) {
20998      
20999      
21000      if ($eqeqeq($$$('String'), x)) {
21001        $Kernel.$raise($type_error(x, $$$('Float')))
21002      };
21003      return $$$('Math').$checked("log2", $$$('Math')['$float!'](x));
21004    });
21005    return $def(self, '$tan', function $$tan(x) {
21006      
21007      
21008      x = $$$('Math')['$float!'](x);
21009      if ($truthy(x['$infinite?']())) {
21010        return $$$($$$('Float'), 'NAN')
21011      };
21012      return $$$('Math').$checked("tan", $$$('Math')['$float!'](x));
21013    });
21014  })('::', $nesting)
21015};
21016
21017Opal.modules["corelib/complex/base"] = function(Opal) {/* Generated by Opal 1.7.3 */
21018  var $module = Opal.module, $truthy = Opal.truthy, $def = Opal.def, $klass = Opal.klass, $nesting = [], nil = Opal.nil;
21019
21020  Opal.add_stubs('new,from_string');
21021  
21022  (function($base, $parent_nesting) {
21023    var self = $module($base, 'Kernel');
21024
21025    var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
21026
21027    return $def(self, '$Complex', function $$Complex(real, imag) {
21028      
21029      
21030      if (imag == null) imag = nil;
21031      if ($truthy(imag)) {
21032        return $$('Complex').$new(real, imag)
21033      } else {
21034        return $$('Complex').$new(real, 0)
21035      };
21036    }, -2)
21037  })('::', $nesting);
21038  return (function($base, $super, $parent_nesting) {
21039    var self = $klass($base, $super, 'String');
21040
21041    var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
21042
21043    return $def(self, '$to_c', function $$to_c() {
21044      var self = this;
21045
21046      return $$('Complex').$from_string(self)
21047    })
21048  })('::', null, $nesting);
21049};
21050
21051Opal.modules["corelib/complex"] = function(Opal) {/* Generated by Opal 1.7.3 */
21052  var $klass = Opal.klass, $truthy = Opal.truthy, $eqeqeq = Opal.eqeqeq, $Kernel = Opal.Kernel, $defs = Opal.defs, $rb_times = Opal.rb_times, $def = Opal.def, $rb_plus = Opal.rb_plus, $rb_minus = Opal.rb_minus, $rb_divide = Opal.rb_divide, $eqeq = Opal.eqeq, $to_ary = Opal.to_ary, $rb_gt = Opal.rb_gt, $neqeq = Opal.neqeq, $return_val = Opal.return_val, $const_set = Opal.const_set, $alias = Opal.alias, self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$;
21053
21054  Opal.add_stubs('require,real?,===,raise,new,*,cos,sin,attr_reader,freeze,class,==,real,imag,Complex,-@,+,__coerced__,-,nan?,/,conj,abs2,quo,polar,exp,log,>,!=,divmod,**,hypot,atan2,lcm,denominator,finite?,infinite?,numerator,abs,arg,rationalize,to_f,to_i,to_r,inspect,zero?,positive?,Rational,rect,angle');
21055  
21056  self.$require("corelib/numeric");
21057  self.$require("corelib/complex/base");
21058  return (function($base, $super, $parent_nesting) {
21059    var self = $klass($base, $super, 'Complex');
21060
21061    var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype;
21062
21063    $proto.real = $proto.imag = nil;
21064    
21065    $defs(self, '$rect', function $$rect(real, imag) {
21066      var self = this;
21067
21068      
21069      if (imag == null) imag = 0;
21070      if (!((($eqeqeq($$$('Numeric'), real) && ($truthy(real['$real?']()))) && ($eqeqeq($$$('Numeric'), imag))) && ($truthy(imag['$real?']())))) {
21071        $Kernel.$raise($$$('TypeError'), "not a real")
21072      };
21073      return self.$new(real, imag);
21074    }, -2);
21075    $defs(self, '$polar', function $$polar(r, theta) {
21076      var self = this;
21077
21078      
21079      if (theta == null) theta = 0;
21080      if (!((($eqeqeq($$$('Numeric'), r) && ($truthy(r['$real?']()))) && ($eqeqeq($$$('Numeric'), theta))) && ($truthy(theta['$real?']())))) {
21081        $Kernel.$raise($$$('TypeError'), "not a real")
21082      };
21083      return self.$new($rb_times(r, $$$('Math').$cos(theta)), $rb_times(r, $$$('Math').$sin(theta)));
21084    }, -2);
21085    self.$attr_reader("real", "imag");
21086    
21087    $def(self, '$initialize', function $$initialize(real, imag) {
21088      var self = this;
21089
21090      
21091      if (imag == null) imag = 0;
21092      self.real = real;
21093      self.imag = imag;
21094      return self.$freeze();
21095    }, -2);
21096    
21097    $def(self, '$coerce', function $$coerce(other) {
21098      var self = this;
21099
21100      if ($eqeqeq($$$('Complex'), other)) {
21101        return [other, self]
21102      } else if (($eqeqeq($$$('Numeric'), other) && ($truthy(other['$real?']())))) {
21103        return [$$$('Complex').$new(other, 0), self]
21104      } else {
21105        return $Kernel.$raise($$$('TypeError'), "" + (other.$class()) + " can't be coerced into Complex")
21106      }
21107    });
21108    
21109    $def(self, '$==', function $Complex_$eq_eq$1(other) {
21110      var self = this, $ret_or_1 = nil;
21111
21112      if ($eqeqeq($$$('Complex'), other)) {
21113        if ($truthy(($ret_or_1 = self.real['$=='](other.$real())))) {
21114          return self.imag['$=='](other.$imag())
21115        } else {
21116          return $ret_or_1
21117        }
21118      } else if (($eqeqeq($$$('Numeric'), other) && ($truthy(other['$real?']())))) {
21119        if ($truthy(($ret_or_1 = self.real['$=='](other)))) {
21120          return self.imag['$=='](0)
21121        } else {
21122          return $ret_or_1
21123        }
21124      } else {
21125        return other['$=='](self)
21126      }
21127    });
21128    
21129    $def(self, '$-@', function $Complex_$minus$$2() {
21130      var self = this;
21131
21132      return $Kernel.$Complex(self.real['$-@'](), self.imag['$-@']())
21133    });
21134    
21135    $def(self, '$+', function $Complex_$plus$3(other) {
21136      var self = this;
21137
21138      if ($eqeqeq($$$('Complex'), other)) {
21139        return $Kernel.$Complex($rb_plus(self.real, other.$real()), $rb_plus(self.imag, other.$imag()))
21140      } else if (($eqeqeq($$$('Numeric'), other) && ($truthy(other['$real?']())))) {
21141        return $Kernel.$Complex($rb_plus(self.real, other), self.imag)
21142      } else {
21143        return self.$__coerced__("+", other)
21144      }
21145    });
21146    
21147    $def(self, '$-', function $Complex_$minus$4(other) {
21148      var self = this;
21149
21150      if ($eqeqeq($$$('Complex'), other)) {
21151        return $Kernel.$Complex($rb_minus(self.real, other.$real()), $rb_minus(self.imag, other.$imag()))
21152      } else if (($eqeqeq($$$('Numeric'), other) && ($truthy(other['$real?']())))) {
21153        return $Kernel.$Complex($rb_minus(self.real, other), self.imag)
21154      } else {
21155        return self.$__coerced__("-", other)
21156      }
21157    });
21158    
21159    $def(self, '$*', function $Complex_$$5(other) {
21160      var self = this;
21161
21162      if ($eqeqeq($$$('Complex'), other)) {
21163        return $Kernel.$Complex($rb_minus($rb_times(self.real, other.$real()), $rb_times(self.imag, other.$imag())), $rb_plus($rb_times(self.real, other.$imag()), $rb_times(self.imag, other.$real())))
21164      } else if (($eqeqeq($$$('Numeric'), other) && ($truthy(other['$real?']())))) {
21165        return $Kernel.$Complex($rb_times(self.real, other), $rb_times(self.imag, other))
21166      } else {
21167        return self.$__coerced__("*", other)
21168      }
21169    });
21170    
21171    $def(self, '$/', function $Complex_$slash$6(other) {
21172      var self = this;
21173
21174      if ($eqeqeq($$$('Complex'), other)) {
21175        if ((((($eqeqeq($$$('Number'), self.real) && ($truthy(self.real['$nan?']()))) || (($eqeqeq($$$('Number'), self.imag) && ($truthy(self.imag['$nan?']()))))) || (($eqeqeq($$$('Number'), other.$real()) && ($truthy(other.$real()['$nan?']()))))) || (($eqeqeq($$$('Number'), other.$imag()) && ($truthy(other.$imag()['$nan?']())))))) {
21176          return $$$('Complex').$new($$$($$$('Float'), 'NAN'), $$$($$$('Float'), 'NAN'))
21177        } else {
21178          return $rb_divide($rb_times(self, other.$conj()), other.$abs2())
21179        }
21180      } else if (($eqeqeq($$$('Numeric'), other) && ($truthy(other['$real?']())))) {
21181        return $Kernel.$Complex(self.real.$quo(other), self.imag.$quo(other))
21182      } else {
21183        return self.$__coerced__("/", other)
21184      }
21185    });
21186    
21187    $def(self, '$**', function $Complex_$$$7(other) {
21188      var $a, $b, self = this, r = nil, theta = nil, ore = nil, oim = nil, nr = nil, ntheta = nil, x = nil, z = nil, n = nil, div = nil, mod = nil;
21189
21190      
21191      if ($eqeq(other, 0)) {
21192        return $$$('Complex').$new(1, 0)
21193      };
21194      if ($eqeqeq($$$('Complex'), other)) {
21195        
21196        $b = self.$polar(), $a = $to_ary($b), (r = ($a[0] == null ? nil : $a[0])), (theta = ($a[1] == null ? nil : $a[1])), $b;
21197        ore = other.$real();
21198        oim = other.$imag();
21199        nr = $$$('Math').$exp($rb_minus($rb_times(ore, $$$('Math').$log(r)), $rb_times(oim, theta)));
21200        ntheta = $rb_plus($rb_times(theta, ore), $rb_times(oim, $$$('Math').$log(r)));
21201        return $$$('Complex').$polar(nr, ntheta);
21202      } else if ($eqeqeq($$$('Integer'), other)) {
21203        if ($truthy($rb_gt(other, 0))) {
21204          
21205          x = self;
21206          z = x;
21207          n = $rb_minus(other, 1);
21208          while ($neqeq(n, 0)) {
21209          
21210            $b = n.$divmod(2), $a = $to_ary($b), (div = ($a[0] == null ? nil : $a[0])), (mod = ($a[1] == null ? nil : $a[1])), $b;
21211            while ($eqeq(mod, 0)) {
21212            
21213              x = $Kernel.$Complex($rb_minus($rb_times(x.$real(), x.$real()), $rb_times(x.$imag(), x.$imag())), $rb_times($rb_times(2, x.$real()), x.$imag()));
21214              n = div;
21215              $b = n.$divmod(2), $a = $to_ary($b), (div = ($a[0] == null ? nil : $a[0])), (mod = ($a[1] == null ? nil : $a[1])), $b;
21216            };
21217            z = $rb_times(z, x);
21218            n = $rb_minus(n, 1);
21219          };
21220          return z;
21221        } else {
21222          return $rb_divide($$$('Rational').$new(1, 1), self)['$**'](other['$-@']())
21223        }
21224      } else if (($eqeqeq($$$('Float'), other) || ($eqeqeq($$$('Rational'), other)))) {
21225        
21226        $b = self.$polar(), $a = $to_ary($b), (r = ($a[0] == null ? nil : $a[0])), (theta = ($a[1] == null ? nil : $a[1])), $b;
21227        return $$$('Complex').$polar(r['$**'](other), $rb_times(theta, other));
21228      } else {
21229        return self.$__coerced__("**", other)
21230      };
21231    });
21232    
21233    $def(self, '$abs', function $$abs() {
21234      var self = this;
21235
21236      return $$$('Math').$hypot(self.real, self.imag)
21237    });
21238    
21239    $def(self, '$abs2', function $$abs2() {
21240      var self = this;
21241
21242      return $rb_plus($rb_times(self.real, self.real), $rb_times(self.imag, self.imag))
21243    });
21244    
21245    $def(self, '$angle', function $$angle() {
21246      var self = this;
21247
21248      return $$$('Math').$atan2(self.imag, self.real)
21249    });
21250    
21251    $def(self, '$conj', function $$conj() {
21252      var self = this;
21253
21254      return $Kernel.$Complex(self.real, self.imag['$-@']())
21255    });
21256    
21257    $def(self, '$denominator', function $$denominator() {
21258      var self = this;
21259
21260      return self.real.$denominator().$lcm(self.imag.$denominator())
21261    });
21262    
21263    $def(self, '$eql?', function $Complex_eql$ques$8(other) {
21264      var self = this, $ret_or_1 = nil, $ret_or_2 = nil;
21265
21266      if ($truthy(($ret_or_1 = ($truthy(($ret_or_2 = $$('Complex')['$==='](other))) ? (self.real.$class()['$=='](self.imag.$class())) : ($ret_or_2))))) {
21267        return self['$=='](other)
21268      } else {
21269        return $ret_or_1
21270      }
21271    });
21272    
21273    $def(self, '$fdiv', function $$fdiv(other) {
21274      var self = this;
21275
21276      
21277      if (!$eqeqeq($$$('Numeric'), other)) {
21278        $Kernel.$raise($$$('TypeError'), "" + (other.$class()) + " can't be coerced into Complex")
21279      };
21280      return $rb_divide(self, other);
21281    });
21282    
21283    $def(self, '$finite?', function $Complex_finite$ques$9() {
21284      var self = this, $ret_or_1 = nil;
21285
21286      if ($truthy(($ret_or_1 = self.real['$finite?']()))) {
21287        return self.imag['$finite?']()
21288      } else {
21289        return $ret_or_1
21290      }
21291    });
21292    
21293    $def(self, '$hash', function $$hash() {
21294      var self = this;
21295
21296      return "Complex:" + (self.real) + ":" + (self.imag)
21297    });
21298    
21299    $def(self, '$infinite?', function $Complex_infinite$ques$10() {
21300      var self = this, $ret_or_1 = nil;
21301
21302      if ($truthy(($ret_or_1 = self.real['$infinite?']()))) {
21303        return $ret_or_1
21304      } else {
21305        return self.imag['$infinite?']()
21306      }
21307    });
21308    
21309    $def(self, '$inspect', function $$inspect() {
21310      var self = this;
21311
21312      return "(" + (self) + ")"
21313    });
21314    
21315    $def(self, '$numerator', function $$numerator() {
21316      var self = this, d = nil;
21317
21318      
21319      d = self.$denominator();
21320      return $Kernel.$Complex($rb_times(self.real.$numerator(), $rb_divide(d, self.real.$denominator())), $rb_times(self.imag.$numerator(), $rb_divide(d, self.imag.$denominator())));
21321    });
21322    
21323    $def(self, '$polar', function $$polar() {
21324      var self = this;
21325
21326      return [self.$abs(), self.$arg()]
21327    });
21328    
21329    $def(self, '$rationalize', function $$rationalize(eps) {
21330      var self = this;
21331
21332      
21333      ;
21334      
21335      if (arguments.length > 1) {
21336        $Kernel.$raise($$$('ArgumentError'), "wrong number of arguments (" + (arguments.length) + " for 0..1)");
21337      }
21338    ;
21339      if ($neqeq(self.imag, 0)) {
21340        $Kernel.$raise($$$('RangeError'), "can't convert " + (self) + " into Rational")
21341      };
21342      return self.$real().$rationalize(eps);
21343    }, -1);
21344    
21345    $def(self, '$real?', $return_val(false));
21346    
21347    $def(self, '$rect', function $$rect() {
21348      var self = this;
21349
21350      return [self.real, self.imag]
21351    });
21352    
21353    $def(self, '$to_f', function $$to_f() {
21354      var self = this;
21355
21356      
21357      if (!$eqeq(self.imag, 0)) {
21358        $Kernel.$raise($$$('RangeError'), "can't convert " + (self) + " into Float")
21359      };
21360      return self.real.$to_f();
21361    });
21362    
21363    $def(self, '$to_i', function $$to_i() {
21364      var self = this;
21365
21366      
21367      if (!$eqeq(self.imag, 0)) {
21368        $Kernel.$raise($$$('RangeError'), "can't convert " + (self) + " into Integer")
21369      };
21370      return self.real.$to_i();
21371    });
21372    
21373    $def(self, '$to_r', function $$to_r() {
21374      var self = this;
21375
21376      
21377      if (!$eqeq(self.imag, 0)) {
21378        $Kernel.$raise($$$('RangeError'), "can't convert " + (self) + " into Rational")
21379      };
21380      return self.real.$to_r();
21381    });
21382    
21383    $def(self, '$to_s', function $$to_s() {
21384      var self = this, result = nil;
21385
21386      
21387      result = self.real.$inspect();
21388      result = $rb_plus(result, (((($eqeqeq($$$('Number'), self.imag) && ($truthy(self.imag['$nan?']()))) || ($truthy(self.imag['$positive?']()))) || ($truthy(self.imag['$zero?']()))) ? ("+") : ("-")));
21389      result = $rb_plus(result, self.imag.$abs().$inspect());
21390      if (($eqeqeq($$$('Number'), self.imag) && (($truthy(self.imag['$nan?']()) || ($truthy(self.imag['$infinite?']())))))) {
21391        result = $rb_plus(result, "*")
21392      };
21393      return $rb_plus(result, "i");
21394    });
21395    $const_set($nesting[0], 'I', self.$new(0, 1));
21396    $defs(self, '$from_string', function $$from_string(str) {
21397      
21398      
21399      var re = /[+-]?[\d_]+(\.[\d_]+)?(e\d+)?/,
21400          match = str.match(re),
21401          real, imag, denominator;
21402
21403      function isFloat() {
21404        return re.test(str);
21405      }
21406
21407      function cutFloat() {
21408        var match = str.match(re);
21409        var number = match[0];
21410        str = str.slice(number.length);
21411        return number.replace(/_/g, '');
21412      }
21413
21414      // handles both floats and rationals
21415      function cutNumber() {
21416        if (isFloat()) {
21417          var numerator = parseFloat(cutFloat());
21418
21419          if (str[0] === '/') {
21420            // rational real part
21421            str = str.slice(1);
21422
21423            if (isFloat()) {
21424              var denominator = parseFloat(cutFloat());
21425              return $Kernel.$Rational(numerator, denominator);
21426            } else {
21427              // reverting '/'
21428              str = '/' + str;
21429              return numerator;
21430            }
21431          } else {
21432            // float real part, no denominator
21433            return numerator;
21434          }
21435        } else {
21436          return null;
21437        }
21438      }
21439
21440      real = cutNumber();
21441
21442      if (!real) {
21443        if (str[0] === 'i') {
21444          // i => Complex(0, 1)
21445          return $Kernel.$Complex(0, 1);
21446        }
21447        if (str[0] === '-' && str[1] === 'i') {
21448          // -i => Complex(0, -1)
21449          return $Kernel.$Complex(0, -1);
21450        }
21451        if (str[0] === '+' && str[1] === 'i') {
21452          // +i => Complex(0, 1)
21453          return $Kernel.$Complex(0, 1);
21454        }
21455        // anything => Complex(0, 0)
21456        return $Kernel.$Complex(0, 0);
21457      }
21458
21459      imag = cutNumber();
21460      if (!imag) {
21461        if (str[0] === 'i') {
21462          // 3i => Complex(0, 3)
21463          return $Kernel.$Complex(0, real);
21464        } else {
21465          // 3 => Complex(3, 0)
21466          return $Kernel.$Complex(real, 0);
21467        }
21468      } else {
21469        // 3+2i => Complex(3, 2)
21470        return $Kernel.$Complex(real, imag);
21471      }
21472    
21473    });
21474    (function(self, $parent_nesting) {
21475      
21476      return $alias(self, "rectangular", "rect")
21477    })(Opal.get_singleton_class(self), $nesting);
21478    $alias(self, "arg", "angle");
21479    $alias(self, "conjugate", "conj");
21480    $alias(self, "divide", "/");
21481    $alias(self, "imaginary", "imag");
21482    $alias(self, "magnitude", "abs");
21483    $alias(self, "phase", "arg");
21484    $alias(self, "quo", "/");
21485    $alias(self, "rectangular", "rect");
21486    
21487    Opal.udef(self, '$' + "negative?");;
21488    
21489    Opal.udef(self, '$' + "positive?");;
21490    
21491    
21492    Opal.udef(self, '$' + "step");;
21493    return nil;;
21494  })('::', $$$('Numeric'), $nesting);
21495};
21496
21497Opal.modules["corelib/rational/base"] = function(Opal) {/* Generated by Opal 1.7.3 */
21498  var $module = Opal.module, $def = Opal.def, $klass = Opal.klass, nil = Opal.nil, $$$ = Opal.$$$;
21499
21500  Opal.add_stubs('convert,from_string');
21501  
21502  (function($base) {
21503    var self = $module($base, 'Kernel');
21504
21505    
21506    return $def(self, '$Rational', function $$Rational(numerator, denominator) {
21507      
21508      
21509      if (denominator == null) denominator = 1;
21510      return $$$('Rational').$convert(numerator, denominator);
21511    }, -2)
21512  })('::');
21513  return (function($base, $super) {
21514    var self = $klass($base, $super, 'String');
21515
21516    
21517    return $def(self, '$to_r', function $$to_r() {
21518      var self = this;
21519
21520      return $$$('Rational').$from_string(self)
21521    })
21522  })('::', null);
21523};
21524
21525Opal.modules["corelib/rational"] = function(Opal) {/* Generated by Opal 1.7.3 */
21526  var $klass = Opal.klass, $eqeq = Opal.eqeq, $Kernel = Opal.Kernel, $truthy = Opal.truthy, $rb_lt = Opal.rb_lt, $rb_divide = Opal.rb_divide, $defs = Opal.defs, $eqeqeq = Opal.eqeqeq, $not = Opal.not, $Opal = Opal.Opal, $def = Opal.def, $return_ivar = Opal.return_ivar, $rb_minus = Opal.rb_minus, $rb_times = Opal.rb_times, $rb_plus = Opal.rb_plus, $rb_gt = Opal.rb_gt, $rb_le = Opal.rb_le, $return_self = Opal.return_self, $alias = Opal.alias, self = Opal.top, nil = Opal.nil, $$$ = Opal.$$$;
21527
21528  Opal.add_stubs('require,to_i,==,raise,<,-@,new,gcd,/,nil?,===,reduce,to_r,!,equal?,coerce_to!,freeze,to_f,numerator,denominator,<=>,-,*,__coerced__,+,Rational,>,**,abs,ceil,with_precision,floor,<=,truncate,send');
21529  
21530  self.$require("corelib/numeric");
21531  self.$require("corelib/rational/base");
21532  return (function($base, $super) {
21533    var self = $klass($base, $super, 'Rational');
21534
21535    var $proto = self.$$prototype;
21536
21537    $proto.num = $proto.den = nil;
21538    
21539    $defs(self, '$reduce', function $$reduce(num, den) {
21540      var self = this, gcd = nil;
21541
21542      
21543      num = num.$to_i();
21544      den = den.$to_i();
21545      if ($eqeq(den, 0)) {
21546        $Kernel.$raise($$$('ZeroDivisionError'), "divided by 0")
21547      } else if ($truthy($rb_lt(den, 0))) {
21548        
21549        num = num['$-@']();
21550        den = den['$-@']();
21551      } else if ($eqeq(den, 1)) {
21552        return self.$new(num, den)
21553      };
21554      gcd = num.$gcd(den);
21555      return self.$new($rb_divide(num, gcd), $rb_divide(den, gcd));
21556    });
21557    $defs(self, '$convert', function $$convert(num, den) {
21558      var self = this;
21559
21560      
21561      if (($truthy(num['$nil?']()) || ($truthy(den['$nil?']())))) {
21562        $Kernel.$raise($$$('TypeError'), "cannot convert nil into Rational")
21563      };
21564      if (($eqeqeq($$$('Integer'), num) && ($eqeqeq($$$('Integer'), den)))) {
21565        return self.$reduce(num, den)
21566      };
21567      if ((($eqeqeq($$$('Float'), num) || ($eqeqeq($$$('String'), num))) || ($eqeqeq($$$('Complex'), num)))) {
21568        num = num.$to_r()
21569      };
21570      if ((($eqeqeq($$$('Float'), den) || ($eqeqeq($$$('String'), den))) || ($eqeqeq($$$('Complex'), den)))) {
21571        den = den.$to_r()
21572      };
21573      if (($truthy(den['$equal?'](1)) && ($not($$$('Integer')['$==='](num))))) {
21574        return $Opal['$coerce_to!'](num, $$$('Rational'), "to_r")
21575      } else if (($eqeqeq($$$('Numeric'), num) && ($eqeqeq($$$('Numeric'), den)))) {
21576        return $rb_divide(num, den)
21577      } else {
21578        return self.$reduce(num, den)
21579      };
21580    });
21581    
21582    $def(self, '$initialize', function $$initialize(num, den) {
21583      var self = this;
21584
21585      
21586      self.num = num;
21587      self.den = den;
21588      return self.$freeze();
21589    });
21590    
21591    $def(self, '$numerator', $return_ivar("num"));
21592    
21593    $def(self, '$denominator', $return_ivar("den"));
21594    
21595    $def(self, '$coerce', function $$coerce(other) {
21596      var self = this, $ret_or_1 = nil;
21597
21598      if ($eqeqeq($$$('Rational'), ($ret_or_1 = other))) {
21599        return [other, self]
21600      } else if ($eqeqeq($$$('Integer'), $ret_or_1)) {
21601        return [other.$to_r(), self]
21602      } else if ($eqeqeq($$$('Float'), $ret_or_1)) {
21603        return [other, self.$to_f()]
21604      } else {
21605        return nil
21606      }
21607    });
21608    
21609    $def(self, '$==', function $Rational_$eq_eq$1(other) {
21610      var self = this, $ret_or_1 = nil, $ret_or_2 = nil;
21611
21612      if ($eqeqeq($$$('Rational'), ($ret_or_1 = other))) {
21613        if ($truthy(($ret_or_2 = self.num['$=='](other.$numerator())))) {
21614          return self.den['$=='](other.$denominator())
21615        } else {
21616          return $ret_or_2
21617        }
21618      } else if ($eqeqeq($$$('Integer'), $ret_or_1)) {
21619        if ($truthy(($ret_or_2 = self.num['$=='](other)))) {
21620          return self.den['$=='](1)
21621        } else {
21622          return $ret_or_2
21623        }
21624      } else if ($eqeqeq($$$('Float'), $ret_or_1)) {
21625        return self.$to_f()['$=='](other)
21626      } else {
21627        return other['$=='](self)
21628      }
21629    });
21630    
21631    $def(self, '$<=>', function $Rational_$lt_eq_gt$2(other) {
21632      var self = this, $ret_or_1 = nil;
21633
21634      if ($eqeqeq($$$('Rational'), ($ret_or_1 = other))) {
21635        return $rb_minus($rb_times(self.num, other.$denominator()), $rb_times(self.den, other.$numerator()))['$<=>'](0)
21636      } else if ($eqeqeq($$$('Integer'), $ret_or_1)) {
21637        return $rb_minus(self.num, $rb_times(self.den, other))['$<=>'](0)
21638      } else if ($eqeqeq($$$('Float'), $ret_or_1)) {
21639        return self.$to_f()['$<=>'](other)
21640      } else {
21641        return self.$__coerced__("<=>", other)
21642      }
21643    });
21644    
21645    $def(self, '$+', function $Rational_$plus$3(other) {
21646      var self = this, $ret_or_1 = nil, num = nil, den = nil;
21647
21648      if ($eqeqeq($$$('Rational'), ($ret_or_1 = other))) {
21649        
21650        num = $rb_plus($rb_times(self.num, other.$denominator()), $rb_times(self.den, other.$numerator()));
21651        den = $rb_times(self.den, other.$denominator());
21652        return $Kernel.$Rational(num, den);
21653      } else if ($eqeqeq($$$('Integer'), $ret_or_1)) {
21654        return $Kernel.$Rational($rb_plus(self.num, $rb_times(other, self.den)), self.den)
21655      } else if ($eqeqeq($$$('Float'), $ret_or_1)) {
21656        return $rb_plus(self.$to_f(), other)
21657      } else {
21658        return self.$__coerced__("+", other)
21659      }
21660    });
21661    
21662    $def(self, '$-', function $Rational_$minus$4(other) {
21663      var self = this, $ret_or_1 = nil, num = nil, den = nil;
21664
21665      if ($eqeqeq($$$('Rational'), ($ret_or_1 = other))) {
21666        
21667        num = $rb_minus($rb_times(self.num, other.$denominator()), $rb_times(self.den, other.$numerator()));
21668        den = $rb_times(self.den, other.$denominator());
21669        return $Kernel.$Rational(num, den);
21670      } else if ($eqeqeq($$$('Integer'), $ret_or_1)) {
21671        return $Kernel.$Rational($rb_minus(self.num, $rb_times(other, self.den)), self.den)
21672      } else if ($eqeqeq($$$('Float'), $ret_or_1)) {
21673        return $rb_minus(self.$to_f(), other)
21674      } else {
21675        return self.$__coerced__("-", other)
21676      }
21677    });
21678    
21679    $def(self, '$*', function $Rational_$$5(other) {
21680      var self = this, $ret_or_1 = nil, num = nil, den = nil;
21681
21682      if ($eqeqeq($$$('Rational'), ($ret_or_1 = other))) {
21683        
21684        num = $rb_times(self.num, other.$numerator());
21685        den = $rb_times(self.den, other.$denominator());
21686        return $Kernel.$Rational(num, den);
21687      } else if ($eqeqeq($$$('Integer'), $ret_or_1)) {
21688        return $Kernel.$Rational($rb_times(self.num, other), self.den)
21689      } else if ($eqeqeq($$$('Float'), $ret_or_1)) {
21690        return $rb_times(self.$to_f(), other)
21691      } else {
21692        return self.$__coerced__("*", other)
21693      }
21694    });
21695    
21696    $def(self, '$/', function $Rational_$slash$6(other) {
21697      var self = this, $ret_or_1 = nil, num = nil, den = nil;
21698
21699      if ($eqeqeq($$$('Rational'), ($ret_or_1 = other))) {
21700        
21701        num = $rb_times(self.num, other.$denominator());
21702        den = $rb_times(self.den, other.$numerator());
21703        return $Kernel.$Rational(num, den);
21704      } else if ($eqeqeq($$$('Integer'), $ret_or_1)) {
21705        if ($eqeq(other, 0)) {
21706          return $rb_divide(self.$to_f(), 0.0)
21707        } else {
21708          return $Kernel.$Rational(self.num, $rb_times(self.den, other))
21709        }
21710      } else if ($eqeqeq($$$('Float'), $ret_or_1)) {
21711        return $rb_divide(self.$to_f(), other)
21712      } else {
21713        return self.$__coerced__("/", other)
21714      }
21715    });
21716    
21717    $def(self, '$**', function $Rational_$$$7(other) {
21718      var self = this, $ret_or_1 = nil;
21719
21720      if ($eqeqeq($$$('Integer'), ($ret_or_1 = other))) {
21721        if (($eqeq(self, 0) && ($truthy($rb_lt(other, 0))))) {
21722          return $$$($$$('Float'), 'INFINITY')
21723        } else if ($truthy($rb_gt(other, 0))) {
21724          return $Kernel.$Rational(self.num['$**'](other), self.den['$**'](other))
21725        } else if ($truthy($rb_lt(other, 0))) {
21726          return $Kernel.$Rational(self.den['$**'](other['$-@']()), self.num['$**'](other['$-@']()))
21727        } else {
21728          return $Kernel.$Rational(1, 1)
21729        }
21730      } else if ($eqeqeq($$$('Float'), $ret_or_1)) {
21731        return self.$to_f()['$**'](other)
21732      } else if ($eqeqeq($$$('Rational'), $ret_or_1)) {
21733        if ($eqeq(other, 0)) {
21734          return $Kernel.$Rational(1, 1)
21735        } else if ($eqeq(other.$denominator(), 1)) {
21736          if ($truthy($rb_lt(other, 0))) {
21737            return $Kernel.$Rational(self.den['$**'](other.$numerator().$abs()), self.num['$**'](other.$numerator().$abs()))
21738          } else {
21739            return $Kernel.$Rational(self.num['$**'](other.$numerator()), self.den['$**'](other.$numerator()))
21740          }
21741        } else if (($eqeq(self, 0) && ($truthy($rb_lt(other, 0))))) {
21742          return $Kernel.$raise($$$('ZeroDivisionError'), "divided by 0")
21743        } else {
21744          return self.$to_f()['$**'](other)
21745        }
21746      } else {
21747        return self.$__coerced__("**", other)
21748      }
21749    });
21750    
21751    $def(self, '$abs', function $$abs() {
21752      var self = this;
21753
21754      return $Kernel.$Rational(self.num.$abs(), self.den.$abs())
21755    });
21756    
21757    $def(self, '$ceil', function $$ceil(precision) {
21758      var self = this;
21759
21760      
21761      if (precision == null) precision = 0;
21762      if ($eqeq(precision, 0)) {
21763        return $rb_divide(self.num['$-@'](), self.den)['$-@']().$ceil()
21764      } else {
21765        return self.$with_precision("ceil", precision)
21766      };
21767    }, -1);
21768    
21769    $def(self, '$floor', function $$floor(precision) {
21770      var self = this;
21771
21772      
21773      if (precision == null) precision = 0;
21774      if ($eqeq(precision, 0)) {
21775        return $rb_divide(self.num['$-@'](), self.den)['$-@']().$floor()
21776      } else {
21777        return self.$with_precision("floor", precision)
21778      };
21779    }, -1);
21780    
21781    $def(self, '$hash', function $$hash() {
21782      var self = this;
21783
21784      return "Rational:" + (self.num) + ":" + (self.den)
21785    });
21786    
21787    $def(self, '$inspect', function $$inspect() {
21788      var self = this;
21789
21790      return "(" + (self) + ")"
21791    });
21792    
21793    $def(self, '$rationalize', function $$rationalize(eps) {
21794      var self = this;
21795
21796      
21797      ;
21798      
21799      if (arguments.length > 1) {
21800        $Kernel.$raise($$$('ArgumentError'), "wrong number of arguments (" + (arguments.length) + " for 0..1)");
21801      }
21802
21803      if (eps == null) {
21804        return self;
21805      }
21806
21807      var e = eps.$abs(),
21808          a = $rb_minus(self, e),
21809          b = $rb_plus(self, e);
21810
21811      var p0 = 0,
21812          p1 = 1,
21813          q0 = 1,
21814          q1 = 0,
21815          p2, q2;
21816
21817      var c, k, t;
21818
21819      while (true) {
21820        c = (a).$ceil();
21821
21822        if ($rb_le(c, b)) {
21823          break;
21824        }
21825
21826        k  = c - 1;
21827        p2 = k * p1 + p0;
21828        q2 = k * q1 + q0;
21829        t  = $rb_divide(1, $rb_minus(b, k));
21830        b  = $rb_divide(1, $rb_minus(a, k));
21831        a  = t;
21832
21833        p0 = p1;
21834        q0 = q1;
21835        p1 = p2;
21836        q1 = q2;
21837      }
21838
21839      return $Kernel.$Rational(c * p1 + p0, c * q1 + q0);
21840    ;
21841    }, -1);
21842    
21843    $def(self, '$round', function $$round(precision) {
21844      var self = this, num = nil, den = nil, approx = nil;
21845
21846      
21847      if (precision == null) precision = 0;
21848      if (!$eqeq(precision, 0)) {
21849        return self.$with_precision("round", precision)
21850      };
21851      if ($eqeq(self.num, 0)) {
21852        return 0
21853      };
21854      if ($eqeq(self.den, 1)) {
21855        return self.num
21856      };
21857      num = $rb_plus($rb_times(self.num.$abs(), 2), self.den);
21858      den = $rb_times(self.den, 2);
21859      approx = $rb_divide(num, den).$truncate();
21860      if ($truthy($rb_lt(self.num, 0))) {
21861        return approx['$-@']()
21862      } else {
21863        return approx
21864      };
21865    }, -1);
21866    
21867    $def(self, '$to_f', function $$to_f() {
21868      var self = this;
21869
21870      return $rb_divide(self.num, self.den)
21871    });
21872    
21873    $def(self, '$to_i', function $$to_i() {
21874      var self = this;
21875
21876      return self.$truncate()
21877    });
21878    
21879    $def(self, '$to_r', $return_self);
21880    
21881    $def(self, '$to_s', function $$to_s() {
21882      var self = this;
21883
21884      return "" + (self.num) + "/" + (self.den)
21885    });
21886    
21887    $def(self, '$truncate', function $$truncate(precision) {
21888      var self = this;
21889
21890      
21891      if (precision == null) precision = 0;
21892      if ($eqeq(precision, 0)) {
21893        if ($truthy($rb_lt(self.num, 0))) {
21894          return self.$ceil()
21895        } else {
21896          return self.$floor()
21897        }
21898      } else {
21899        return self.$with_precision("truncate", precision)
21900      };
21901    }, -1);
21902    
21903    $def(self, '$with_precision', function $$with_precision(method, precision) {
21904      var self = this, p = nil, s = nil;
21905
21906      
21907      if (!$eqeqeq($$$('Integer'), precision)) {
21908        $Kernel.$raise($$$('TypeError'), "not an Integer")
21909      };
21910      p = (10)['$**'](precision);
21911      s = $rb_times(self, p);
21912      if ($truthy($rb_lt(precision, 1))) {
21913        return $rb_divide(s.$send(method), p).$to_i()
21914      } else {
21915        return $Kernel.$Rational(s.$send(method), p)
21916      };
21917    });
21918    $defs(self, '$from_string', function $$from_string(string) {
21919      
21920      
21921      var str = string.trimLeft(),
21922          re = /^[+-]?[\d_]+(\.[\d_]+)?/,
21923          match = str.match(re),
21924          numerator, denominator;
21925
21926      function isFloat() {
21927        return re.test(str);
21928      }
21929
21930      function cutFloat() {
21931        var match = str.match(re);
21932        var number = match[0];
21933        str = str.slice(number.length);
21934        return number.replace(/_/g, '');
21935      }
21936
21937      if (isFloat()) {
21938        numerator = parseFloat(cutFloat());
21939
21940        if (str[0] === '/') {
21941          // rational real part
21942          str = str.slice(1);
21943
21944          if (isFloat()) {
21945            denominator = parseFloat(cutFloat());
21946            return $Kernel.$Rational(numerator, denominator);
21947          } else {
21948            return $Kernel.$Rational(numerator, 1);
21949          }
21950        } else {
21951          return $Kernel.$Rational(numerator, 1);
21952        }
21953      } else {
21954        return $Kernel.$Rational(0, 1);
21955      }
21956    
21957    });
21958    $alias(self, "divide", "/");
21959    return $alias(self, "quo", "/");
21960  })('::', $$$('Numeric'));
21961};
21962
21963Opal.modules["corelib/time"] = function(Opal) {/* Generated by Opal 1.7.3 */
21964  var $slice = Opal.slice, $deny_frozen_access = Opal.deny_frozen_access, $klass = Opal.klass, $Kernel = Opal.Kernel, $Opal = Opal.Opal, $defs = Opal.defs, $eqeqeq = Opal.eqeqeq, $def = Opal.def, $truthy = Opal.truthy, $rb_gt = Opal.rb_gt, $rb_lt = Opal.rb_lt, $send = Opal.send, $rb_plus = Opal.rb_plus, $rb_divide = Opal.rb_divide, $rb_minus = Opal.rb_minus, $range = Opal.range, $neqeq = Opal.neqeq, $rb_le = Opal.rb_le, $eqeq = Opal.eqeq, $alias = Opal.alias, self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$;
21965
21966  Opal.add_stubs('require,include,===,raise,coerce_to!,respond_to?,to_str,to_i,_parse_offset,new,<=>,to_f,nil?,>,<,strftime,each,define_method,year,month,day,+,round,/,-,copy_instance_variables,initialize_dup,is_a?,zero?,wday,utc?,mon,yday,hour,min,sec,rjust,ljust,zone,to_s,[],cweek_cyear,jd,to_date,format,isdst,!=,<=,==,ceil,local,gm,asctime,getgm,gmt_offset,inspect,usec,gmtime,gmt?');
21967  
21968  self.$require("corelib/comparable");
21969  return (function($base, $super, $parent_nesting) {
21970    var self = $klass($base, $super, 'Time');
21971
21972    var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
21973
21974    
21975    self.$include($$$('Comparable'));
21976    
21977    var days_of_week = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
21978        short_days   = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
21979        short_months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
21980        long_months  = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "
21980November", "December"];
21981  ;
21982    $defs(self, '$at', function $$at(seconds, frac) {
21983      
21984      
21985      ;
21986      
21987      var result;
21988
21989      if ($$$('Time')['$==='](seconds)) {
21990        if (frac !== undefined) {
21991          $Kernel.$raise($$$('TypeError'), "can't convert Time into an exact number")
21992        }
21993        result = new Date(seconds.getTime());
21994        result.timezone = seconds.timezone;
21995        return result;
21996      }
21997
21998      if (!seconds.$$is_number) {
21999        seconds = $Opal['$coerce_to!'](seconds, $$$('Integer'), "to_int");
22000      }
22001
22002      if (frac === undefined) {
22003        return new Date(seconds * 1000);
22004      }
22005
22006      if (!frac.$$is_number) {
22007        frac = $Opal['$coerce_to!'](frac, $$$('Integer'), "to_int");
22008      }
22009
22010      return new Date(seconds * 1000 + (frac / 1000));
22011    ;
22012    }, -2);
22013    
22014    function time_params(year, month, day, hour, min, sec) {
22015      if (year.$$is_string) {
22016        year = parseInt(year, 10);
22017      } else {
22018        year = $Opal['$coerce_to!'](year, $$$('Integer'), "to_int");
22019      }
22020
22021      if (month === nil) {
22022        month = 1;
22023      } else if (!month.$$is_number) {
22024        if ((month)['$respond_to?']("to_str")) {
22025          month = (month).$to_str();
22026          switch (month.toLowerCase()) {
22027          case 'jan': month =  1; break;
22028          case 'feb': month =  2; break;
22029          case 'mar': month =  3; break;
22030          case 'apr': month =  4; break;
22031          case 'may': month =  5; break;
22032          case 'jun': month =  6; break;
22033          case 'jul': month =  7; break;
22034          case 'aug': month =  8; break;
22035          case 'sep': month =  9; break;
22036          case 'oct': month = 10; break;
22037          case 'nov': month = 11; break;
22038          case 'dec': month = 12; break;
22039          default: month = (month).$to_i();
22040          }
22041        } else {
22042          month = $Opal['$coerce_to!'](month, $$$('Integer'), "to_int");
22043        }
22044      }
22045
22046      if (month < 1 || month > 12) {
22047        $Kernel.$raise($$$('ArgumentError'), "month out of range: " + (month))
22048      }
22049      month = month - 1;
22050
22051      if (day === nil) {
22052        day = 1;
22053      } else if (day.$$is_string) {
22054        day = parseInt(day, 10);
22055      } else {
22056        day = $Opal['$coerce_to!'](day, $$$('Integer'), "to_int");
22057      }
22058
22059      if (day < 1 || day > 31) {
22060        $Kernel.$raise($$$('ArgumentError'), "day out of range: " + (day))
22061      }
22062
22063      if (hour === nil) {
22064        hour = 0;
22065      } else if (hour.$$is_string) {
22066        hour = parseInt(hour, 10);
22067      } else {
22068        hour = $Opal['$coerce_to!'](hour, $$$('Integer'), "to_int");
22069      }
22070
22071      if (hour < 0 || hour > 24) {
22072        $Kernel.$raise($$$('ArgumentError'), "hour out of range: " + (hour))
22073      }
22074
22075      if (min === nil) {
22076        min = 0;
22077      } else if (min.$$is_string) {
22078        min = parseInt(min, 10);
22079      } else {
22080        min = $Opal['$coerce_to!'](min, $$$('Integer'), "to_int");
22081      }
22082
22083      if (min < 0 || min > 59) {
22084        $Kernel.$raise($$$('ArgumentError'), "min out of range: " + (min))
22085      }
22086
22087      if (sec === nil) {
22088        sec = 0;
22089      } else if (!sec.$$is_number) {
22090        if (sec.$$is_string) {
22091          sec = parseInt(sec, 10);
22092        } else {
22093          sec = $Opal['$coerce_to!'](sec, $$$('Integer'), "to_int");
22094        }
22095      }
22096
22097      if (sec < 0 || sec > 60) {
22098        $Kernel.$raise($$$('ArgumentError'), "sec out of range: " + (sec))
22099      }
22100
22101      return [year, month, day, hour, min, sec];
22102    }
22103  ;
22104    $defs(self, '$new', function $Time_new$1(year, month, day, hour, min, sec, utc_offset) {
22105      var self = this;
22106
22107      
22108      ;
22109      if (month == null) month = nil;
22110      if (day == null) day = nil;
22111      if (hour == null) hour = nil;
22112      if (min == null) min = nil;
22113      if (sec == null) sec = nil;
22114      if (utc_offset == null) utc_offset = nil;
22115      
22116      var args, result, timezone, utc_date;
22117
22118      if (year === undefined) {
22119        return new Date();
22120      }
22121
22122      args  = time_params(year, month, day, hour, min, sec);
22123      year  = args[0];
22124      month = args[1];
22125      day   = args[2];
22126      hour  = args[3];
22127      min   = args[4];
22128      sec   = args[5];
22129
22130      if (utc_offset === nil) {
22131        result = new Date(year, month, day, hour, min, 0, sec * 1000);
22132        if (year < 100) {
22133          result.setFullYear(year);
22134        }
22135        return result;
22136      }
22137
22138      timezone = self.$_parse_offset(utc_offset);
22139      utc_date = new Date(Date.UTC(year, month, day, hour, min, 0, sec * 1000));
22140      if (year < 100) {
22141        utc_date.setUTCFullYear(year);
22142      }
22143
22144      result = new Date(utc_date.getTime() - timezone * 3600000);
22145      result.timezone = timezone;
22146
22147      return result;
22148    ;
22149    }, -1);
22150    $defs(self, '$_parse_offset', function $$_parse_offset(utc_offset) {
22151      
22152      
22153      var timezone;
22154      if (utc_offset.$$is_string) {
22155        if (utc_offset == 'UTC') {
22156          timezone = 0;
22157        }
22158        else if(/^[+-]\d\d:[0-5]\d$/.test(utc_offset)) {
22159          var sign, hours, minutes;
22160          sign = utc_offset[0];
22161          hours = +(utc_offset[1] + utc_offset[2]);
22162          minutes = +(utc_offset[4] + utc_offset[5]);
22163
22164          timezone = (sign == '-' ? -1 : 1) * (hours + minutes / 60);
22165        }
22166        else {
22167          // Unsupported: "A".."I","K".."Z"
22168          $Kernel.$raise($$$('ArgumentError'), "\"+HH:MM\", \"-HH:MM\", \"UTC\" expected for utc_offset: " + (utc_offset))
22169        }
22170      }
22171      else if (utc_offset.$$is_number) {
22172        timezone = utc_offset / 3600;
22173      }
22174      else {
22175        $Kernel.$raise($$$('ArgumentError'), "Opal doesn't support other types for a timezone argument than Integer and String")
22176      }
22177      return timezone;
22178    
22179    });
22180    $defs(self, '$local', function $$local(year, month, day, hour, min, sec, millisecond, _dummy1, _dummy2, _dummy3) {
22181      
22182      
22183      if (month == null) month = nil;
22184      if (day == null) day = nil;
22185      if (hour == null) hour = nil;
22186      if (min == null) min = nil;
22187      if (sec == null) sec = nil;
22188      if (millisecond == null) millisecond = nil;
22189      if (_dummy1 == null) _dummy1 = nil;
22190      if (_dummy2 == null) _dummy2 = nil;
22191      if (_dummy3 == null) _dummy3 = nil;
22192      
22193      var args, result;
22194
22195      if (arguments.length === 10) {
22196        args  = $slice(arguments);
22197        year  = args[5];
22198        month = args[4];
22199        day   = args[3];
22200        hour  = args[2];
22201        min   = args[1];
22202        sec   = args[0];
22203      }
22204
22205      args  = time_params(year, month, day, hour, min, sec);
22206      year  = args[0];
22207      month = args[1];
22208      day   = args[2];
22209      hour  = args[3];
22210      min   = args[4];
22211      sec   = args[5];
22212
22213      result = new Date(year, month, day, hour, min, 0, sec * 1000);
22214      if (year < 100) {
22215        result.setFullYear(year);
22216      }
22217      return result;
22218    ;
22219    }, -2);
22220    $defs(self, '$gm', function $$gm(year, month, day, hour, min, sec, millisecond, _dummy1, _dummy2, _dummy3) {
22221      
22222      
22223      if (month == null) month = nil;
22224      if (day == null) day = nil;
22225      if (hour == null) hour = nil;
22226      if (min == null) min = nil;
22227      if (sec == null) sec = nil;
22228      if (millisecond == null) millisecond = nil;
22229      if (_dummy1 == null) _dummy1 = nil;
22230      if (_dummy2 == null) _dummy2 = nil;
22231      if (_dummy3 == null) _dummy3 = nil;
22232      
22233      var args, result;
22234
22235      if (arguments.length === 10) {
22236        args  = $slice(arguments);
22237        year  = args[5];
22238        month = args[4];
22239        day   = args[3];
22240        hour  = args[2];
22241        min   = args[1];
22242        sec   = args[0];
22243      }
22244
22245      args  = time_params(year, month, day, hour, min, sec);
22246      year  = args[0];
22247      month = args[1];
22248      day   = args[2];
22249      hour  = args[3];
22250      min   = args[4];
22251      sec   = args[5];
22252
22253      result = new Date(Date.UTC(year, month, day, hour, min, 0, sec * 1000));
22254      if (year < 100) {
22255        result.setUTCFullYear(year);
22256      }
22257      result.timezone = 0;
22258      return result;
22259    ;
22260    }, -2);
22261    $defs(self, '$now', function $$now() {
22262      var self = this;
22263
22264      return self.$new()
22265    });
22266    
22267    $def(self, '$+', function $Time_$plus$2(other) {
22268      var self = this;
22269
22270      
22271      if ($eqeqeq($$$('Time'), other)) {
22272        $Kernel.$raise($$$('TypeError'), "time + time?")
22273      };
22274      
22275      if (!other.$$is_number) {
22276        other = $Opal['$coerce_to!'](other, $$$('Integer'), "to_int");
22277      }
22278      var result = new Date(self.getTime() + (other * 1000));
22279      result.timezone = self.timezone;
22280      return result;
22281    ;
22282    });
22283    
22284    $def(self, '$-', function $Time_$minus$3(other) {
22285      var self = this;
22286
22287      
22288      if ($eqeqeq($$$('Time'), other)) {
22289        return (self.getTime() - other.getTime()) / 1000
22290      };
22291      
22292      if (!other.$$is_number) {
22293        other = $Opal['$coerce_to!'](other, $$$('Integer'), "to_int");
22294      }
22295      var result = new Date(self.getTime() - (other * 1000));
22296      result.timezone = self.timezone;
22297      return result;
22298    ;
22299    });
22300    
22301    $def(self, '$<=>', function $Time_$lt_eq_gt$4(other) {
22302      var self = this, r = nil;
22303
22304      if ($eqeqeq($$$('Time'), other)) {
22305        return self.$to_f()['$<=>'](other.$to_f())
22306      } else {
22307        
22308        r = other['$<=>'](self);
22309        if ($truthy(r['$nil?']())) {
22310          return nil
22311        } else if ($truthy($rb_gt(r, 0))) {
22312          return -1
22313        } else if ($truthy($rb_lt(r, 0))) {
22314          return 1
22315        } else {
22316          return 0
22317        };
22318      }
22319    });
22320    
22321    $def(self, '$==', function $Time_$eq_eq$5(other) {
22322      var self = this, $ret_or_1 = nil;
22323
22324      if ($truthy(($ret_or_1 = $$$('Time')['$==='](other)))) {
22325        return self.$to_f() === other.$to_f()
22326      } else {
22327        return $ret_or_1
22328      }
22329    });
22330    
22331    $def(self, '$asctime', function $$asctime() {
22332      var self = this;
22333
22334      return self.$strftime("%a %b %e %H:%M:%S %Y")
22335    });
22336    $send([["year", "getFullYear", "getUTCFullYear"], ["mon", "getMonth", "getUTCMonth", 1], ["wday", "getDay", "getUTCDay"], ["day", "getDate", "getUTCDate"], ["hour", "getHours", "getUTCHours"], ["min", "getMinutes", "getUTCMinutes"], ["sec", "getSeconds", "getUTCSeconds"]], 'each', [], function $Time$6(method, getter, utcgetter, difference){var self = $Time$6.$$s == null ? this : $Time$6.$$s;
22337
22338      
22339      if (method == null) method = nil;
22340      if (getter == null) getter = nil;
22341      if (utcgetter == null) utcgetter = nil;
22342      if (difference == null) difference = 0;
22343      return $send(self, 'define_method', [method], function $$7(){var self = $$7.$$s == null ? this : $$7.$$s;
22344
22345        
22346        return difference + ((self.timezone != null) ?
22347          (new Date(self.getTime() + self.timezone * 3600000))[utcgetter]() :
22348          self[getter]())
22349      }, {$$s: self});}, {$$arity: -4, $$s: self});
22350    
22351    $def(self, '$yday', function $$yday() {
22352      var self = this, start_of_year = nil, start_of_day = nil, one_day = nil;
22353
22354      
22355      start_of_year = $$('Time').$new(self.$year()).$to_i();
22356      start_of_day = $$('Time').$new(self.$year(), self.$month(), self.$day()).$to_i();
22357      one_day = 86400;
22358      return $rb_plus($rb_divide($rb_minus(start_of_day, start_of_year), one_day).$round(), 1);
22359    });
22360    
22361    $def(self, '$isdst', function $$isdst() {
22362      var self = this;
22363
22364      
22365      var jan = new Date(self.getFullYear(), 0, 1),
22366          jul = new Date(self.getFullYear(), 6, 1);
22367      return self.getTimezoneOffset() < Math.max(jan.getTimezoneOffset(), jul.getTimezoneOffset());
22368    
22369    });
22370    
22371    $def(self, '$dup', function $$dup() {
22372      var self = this, copy = nil;
22373
22374      
22375      copy = new Date(self.getTime());
22376      copy.$copy_instance_variables(self);
22377      copy.$initialize_dup(self);
22378      return copy;
22379    });
22380    
22381    $def(self, '$eql?', function $Time_eql$ques$8(other) {
22382      var self = this, $ret_or_1 = nil;
22383
22384      if ($truthy(($ret_or_1 = other['$is_a?']($$$('Time'))))) {
22385        return self['$<=>'](other)['$zero?']()
22386      } else {
22387        return $ret_or_1
22388      }
22389    });
22390    $send([["sunday?", 0], ["monday?", 1], ["tuesday?", 2], ["wednesday?", 3], ["thursday?", 4], ["friday?", 5], ["saturday?", 6]], 'each', [], function $Time$9(method, weekday){var self = $Time$9.$$s == null ? this : $Time$9.$$s;
22391
22392      
22393      if (method == null) method = nil;
22394      if (weekday == null) weekday = nil;
22395      return $send(self, 'define_method', [method], function $$10(){var self = $$10.$$s == null ? this : $$10.$$s;
22396
22397        return self.$wday() === weekday}, {$$s: self});}, {$$s: self});
22398    
22399    $def(self, '$hash', function $$hash() {
22400      var self = this;
22401
22402      return 'Time:' + self.getTime();
22403    });
22404    
22405    $def(self, '$inspect', function $$inspect() {
22406      var self = this;
22407
22408      if ($truthy(self['$utc?']())) {
22409        return self.$strftime("%Y-%m-%d %H:%M:%S UTC")
22410      } else {
22411        return self.$strftime("%Y-%m-%d %H:%M:%S %z")
22412      }
22413    });
22414    
22415    $def(self, '$succ', function $$succ() {
22416      var self = this;
22417
22418      
22419      var result = new Date(self.getTime() + 1000);
22420      result.timezone = self.timezone;
22421      return result;
22422    
22423    });
22424    
22425    $def(self, '$usec', function $$usec() {
22426      var self = this;
22427
22428      return self.getMilliseconds() * 1000;
22429    });
22430    
22431    $def(self, '$zone', function $$zone() {
22432      var self = this;
22433
22434      
22435      if (self.timezone === 0) return "UTC";
22436      else if (self.timezone != null) return nil;
22437
22438      var string = self.toString(),
22439          result;
22440
22441      if (string.indexOf('(') == -1) {
22442        result = string.match(/[A-Z]{3,4}/)[0];
22443      }
22444      else {
22445        result = string.match(/\((.+)\)(?:\s|$)/)[1]
22446      }
22447
22448      if (result == "GMT" && /(GMT\W*\d{4})/.test(string)) {
22449        return RegExp.$1;
22450      }
22451      else {
22452        return result;
22453      }
22454    
22455    });
22456    
22457    $def(self, '$getgm', function $$getgm() {
22458      var self = this;
22459
22460      
22461      var result = new Date(self.getTime());
22462      result.timezone = 0;
22463      return result;
22464    
22465    });
22466    
22467    $def(self, '$gmtime', function $$gmtime() {
22468      var self = this;
22469
22470      
22471      if (self.timezone !== 0) {
22472        $deny_frozen_access(self);
22473        self.timezone = 0;
22474      }
22475      return self;
22476    
22477    });
22478    
22479    $def(self, '$gmt?', function $Time_gmt$ques$11() {
22480      var self = this;
22481
22482      return self.timezone === 0;
22483    });
22484    
22485    $def(self, '$gmt_offset', function $$gmt_offset() {
22486      var self = this;
22487
22488      return (self.timezone != null) ? self.timezone * 60 : -self.getTimezoneOffset() * 60;
22489    });
22490    
22491    $def(self, '$strftime', function $$strftime(format) {
22492      var self = this;
22493
22494      
22495      return format.replace(/%([\-_#^0]*:{0,2})(\d+)?([EO]*)(.)/g, function(full, flags, width, _, conv) {
22496        var result = "", jd, c, s,
22497            zero   = flags.indexOf('0') !== -1,
22498            pad    = flags.indexOf('-') === -1,
22499            blank  = flags.indexOf('_') !== -1,
22500            upcase = flags.indexOf('^') !== -1,
22501            invert = flags.indexOf('#') !== -1,
22502            colons = (flags.match(':') || []).length;
22503
22504        width = parseInt(width, 10);
22505
22506        if (zero && blank) {
22507          if (flags.indexOf('0') < flags.indexOf('_')) {
22508            zero = false;
22509          }
22510          else {
22511            blank = false;
22512          }
22513        }
22514
22515        switch (conv) {
22516          case 'Y':
22517            result += self.$year();
22518            break;
22519
22520          case 'C':
22521            zero    = !blank;
22522            result += Math.round(self.$year() / 100);
22523            break;
22524
22525          case 'y':
22526            zero    = !blank;
22527            result += (self.$year() % 100);
22528            break;
22529
22530          case 'm':
22531            zero    = !blank;
22532            result += self.$mon();
22533            break;
22534
22535          case 'B':
22536            result += long_months[self.$mon() - 1];
22537            break;
22538
22539          case 'b':
22540          case 'h':
22541            blank   = !zero;
22542            result += short_months[self.$mon() - 1];
22543            break;
22544
22545          case 'd':
22546            zero    = !blank
22547            result += self.$day();
22548            break;
22549
22550          case 'e':
22551            blank   = !zero
22552            result += self.$day();
22553            break;
22554
22555          case 'j':
22556            zero    = !blank;
22557            width   = isNaN(width) ? 3 : width;
22558            result += self.$yday();
22559            break;
22560
22561          case 'H':
22562            zero    = !blank;
22563            result += self.$hour();
22564            break;
22565
22566          case 'k':
22567            blank   = !zero;
22568            result += self.$hour();
22569            break;
22570
22571          case 'I':
22572            zero    = !blank;
22573            result += (self.$hour() % 12 || 12);
22574            break;
22575
22576          case 'l':
22577            blank   = !zero;
22578            result += (self.$hour() % 12 || 12);
22579            break;
22580
22581          case 'P':
22582            result += (self.$hour() >= 12 ? "pm" : "am");
22583            break;
22584
22585          case 'p':
22586            result += (self.$hour() >= 12 ? "PM" : "AM");
22587            break;
22588
22589          case 'M':
22590            zero    = !blank;
22591            result += self.$min();
22592            break;
22593
22594          case 'S':
22595            zero    = !blank;
22596            result += self.$sec()
22597            break;
22598
22599          case 'L':
22600            zero    = !blank;
22601            width   = isNaN(width) ? 3 : width;
22602            result += self.getMilliseconds();
22603            break;
22604
22605          case 'N':
22606            width   = isNaN(width) ? 9 : width;
22607            result += (self.getMilliseconds().toString()).$rjust(3, "0");
22608            result  = (result).$ljust(width, "0");
22609            break;
22610
22611          case 'z':
22612            var offset  = (self.timezone == null) ? self.getTimezoneOffset() : (-self.timezone * 60),
22613                hours   = Math.floor(Math.abs(offset) / 60),
22614                minutes = Math.abs(offset) % 60;
22615
22616            result += offset < 0 ? "+" : "-";
22617            result += hours < 10 ? "0" : "";
22618            result += hours;
22619
22620            if (colons > 0) {
22621              result += ":";
22622            }
22623
22624            result += minutes < 10 ? "0" : "";
22625            result += minutes;
22626
22627            if (colons > 1) {
22628              result += ":00";
22629            }
22630
22631            break;
22632
22633          case 'Z':
22634            result += self.$zone();
22635            break;
22636
22637          case 'A':
22638            result += days_of_week[self.$wday()];
22639            break;
22640
22641          case 'a':
22642            result += short_days[self.$wday()];
22643            break;
22644
22645          case 'u':
22646            result += (self.$wday() + 1);
22647            break;
22648
22649          case 'w':
22650            result += self.$wday();
22651            break;
22652
22653          case 'V':
22654            result += self.$cweek_cyear()['$[]'](0).$to_s().$rjust(2, "0");
22655            break;
22656
22657          case 'G':
22658            result += self.$cweek_cyear()['$[]'](1);
22659            break;
22660
22661          case 'g':
22662            result += self.$cweek_cyear()['$[]'](1)['$[]']($range(-2, -1, false));
22663            break;
22664
22665          case 's':
22666            result += self.$to_i();
22667            break;
22668
22669          case 'n':
22670            result += "\n";
22671            break;
22672
22673          case 't':
22674            result += "\t";
22675            break;
22676
22677          case '%':
22678            result += "%";
22679            break;
22680
22681          case 'c':
22682            result += self.$strftime("%a %b %e %T %Y");
22683            break;
22684
22685          case 'D':
22686          case 'x':
22687            result += self.$strftime("%m/%d/%y");
22688            break;
22689
22690          case 'F':
22691            result += self.$strftime("%Y-%m-%d");
22692            break;
22693
22694          case 'v':
22695            result += self.$strftime("%e-%^b-%4Y");
22696            break;
22697
22698          case 'r':
22699            result += self.$strftime("%I:%M:%S %p");
22700            break;
22701
22702          case 'R':
22703            result += self.$strftime("%H:%M");
22704            break;
22705
22706          case 'T':
22707          case 'X':
22708            result += self.$strftime("%H:%M:%S");
22709            break;
22710
22711          // Non-standard: JIS X 0301 date format
22712          case 'J':
22713            jd = self.$to_date().$jd();
22714            if (jd < 2405160) {
22715              result += self.$strftime("%Y-%m-%d");
22716              break;
22717            }
22718            else if (jd < 2419614)
22719              c = 'M', s = 1867;
22720            else if (jd < 2424875)
22721              c = 'T', s = 1911;
22722            else if (jd < 2447535)
22723              c = 'S', s = 1925;
22724            else if (jd < 2458605)
22725              c = 'H', s = 1988;
22726            else
22727              c = 'R', s = 2018;
22728
22729            result += self.$format("%c%02d", c, $rb_minus(self.$year(), s));
22730            result += self.$strftime("-%m-%d");
22731            break;
22732
22733          default:
22734            return full;
22735        }
22736
22737        if (upcase) {
22738          result = result.toUpperCase();
22739        }
22740
22741        if (invert) {
22742          result = result.replace(/[A-Z]/, function(c) { c.toLowerCase() }).
22743                          replace(/[a-z]/, function(c) { c.toUpperCase() });
22744        }
22745
22746        if (pad && (zero || blank)) {
22747          result = (result).$rjust(isNaN(width) ? 2 : width, blank ? " " : "0");
22748        }
22749
22750        return result;
22751      });
22752    
22753    });
22754    
22755    $def(self, '$to_a', function $$to_a() {
22756      var self = this;
22757
22758      return [self.$sec(), self.$min(), self.$hour(), self.$day(), self.$month(), self.$year(), self.$wday(), self.$yday(), self.$isdst(), self.$zone()]
22759    });
22760    
22761    $def(self, '$to_f', function $$to_f() {
22762      var self = this;
22763
22764      return self.getTime() / 1000;
22765    });
22766    
22767    $def(self, '$to_i', function $$to_i() {
22768      var self = this;
22769
22770      return parseInt(self.getTime() / 1000, 10);
22771    });
22772    
22773    $def(self, '$cweek_cyear', function $$cweek_cyear() {
22774      var self = this, jan01 = nil, jan01_wday = nil, first_monday = nil, year = nil, offset = nil, week = nil, dec31 = nil, dec31_wday = nil;
22775
22776      
22777      jan01 = $$$('Time').$new(self.$year(), 1, 1);
22778      jan01_wday = jan01.$wday();
22779      first_monday = 0;
22780      year = self.$year();
22781      if (($truthy($rb_le(jan01_wday, 4)) && ($neqeq(jan01_wday, 0)))) {
22782        offset = $rb_minus(jan01_wday, 1)
22783      } else {
22784        
22785        offset = $rb_minus($rb_minus(jan01_wday, 7), 1);
22786        if ($eqeq(offset, -8)) {
22787          offset = -1
22788        };
22789      };
22790      week = $rb_divide($rb_plus(self.$yday(), offset), 7.0).$ceil();
22791      if ($truthy($rb_le(week, 0))) {
22792        return $$$('Time').$new($rb_minus(self.$year(), 1), 12, 31).$cweek_cyear()
22793      } else if ($eqeq(week, 53)) {
22794        
22795        dec31 = $$$('Time').$new(self.$year(), 12, 31);
22796        dec31_wday = dec31.$wday();
22797        if (($truthy($rb_le(dec31_wday, 3)) && ($neqeq(dec31_wday, 0)))) {
22798          
22799          week = 1;
22800          year = $rb_plus(year, 1);
22801        };
22802      };
22803      return [week, year];
22804    });
22805    (function(self, $parent_nesting) {
22806      
22807      
22808      $alias(self, "mktime", "local");
22809      return $alias(self, "utc", "gm");
22810    })(Opal.get_singleton_class(self), $nesting);
22811    $alias(self, "ctime", "asctime");
22812    $alias(self, "dst?", "isdst");
22813    $alias(self, "getutc", "getgm");
22814    $alias(self, "gmtoff", "gmt_offset");
22815    $alias(self, "mday", "day");
22816    $alias(self, "month", "mon");
22817    $alias(self, "to_s", "inspect");
22818    $alias(self, "tv_sec", "to_i");
22819    $alias(self, "tv_usec", "usec");
22820    $alias(self, "utc", "gmtime");
22821    $alias(self, "utc?", "gmt?");
22822    return $alias(self, "utc_offset", "gmt_offset");
22823  })('::', Date, $nesting);
22824};
22825
22826Opal.modules["corelib/struct"] = function(Opal) {/* Generated by Opal 1.7.3 */
22827  var $klass = Opal.klass, $slice = Opal.slice, $extract_kwargs = Opal.extract_kwargs, $ensure_kwargs = Opal.ensure_kwargs, $truthy = Opal.truthy, $neqeq = Opal.neqeq, $eqeq = Opal.eqeq, $Opal = Opal.Opal, $send = Opal.send, $Class = Opal.Class, $to_a = Opal.to_a, $def = Opal.def, $defs = Opal.defs, $Kernel = Opal.Kernel, $hash2 = Opal.hash2, $rb_gt = Opal.rb_gt, $rb_minus = Opal.rb_minus, $eqeqeq = Opal.eqeqeq, $rb_lt = Opal.rb_lt, $rb_ge = Opal.rb_ge, $rb_plus = Opal.rb_plus, $alias = Opal.alias, self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$;
22828
22829  Opal.add_stubs('require,include,!=,upcase,[],==,class,unshift,const_name!,map,coerce_to!,new,each,define_struct_attribute,allocate,initialize,alias_method,module_eval,to_proc,const_set,raise,<<,members,define_method,instance_eval,last,>
22829,length,-,keys,any?,join,[]=,each_with_index,hash,===,<,-@,size,>=,include?,to_sym,instance_of?,__id__,eql?,enum_for,+,name,each_pair,inspect,to_h,args,each_with_object,flatten,to_a,respond_to?,dig');
22830  
22831  self.$require("corelib/enumerable");
22832  return (function($base, $super, $parent_nesting) {
22833    var self = $klass($base, $super, 'Struct');
22834
22835    var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
22836
22837    
22838    self.$include($$$('Enumerable'));
22839    $defs(self, '$new', function $Struct_new$1(const_name, $a, $b) {
22840      var block = $Struct_new$1.$$p || nil, $post_args, $kwargs, args, keyword_init, self = this, klass = nil;
22841
22842      $Struct_new$1.$$p = null;
22843      
22844      ;
22845      $post_args = $slice(arguments, 1);
22846      $kwargs = $extract_kwargs($post_args);
22847      $kwargs = $ensure_kwargs($kwargs);
22848      args = $post_args;
22849      
22850      keyword_init = $kwargs.$$smap["keyword_init"];if (keyword_init == null) keyword_init = false;
22851      if ($truthy(const_name)) {
22852        if (($eqeq(const_name.$class(), $$$('String')) && ($neqeq(const_name['$[]'](0).$upcase(), const_name['$[]'](0))))) {
22853          
22854          args.$unshift(const_name);
22855          const_name = nil;
22856        } else {
22857          
22858          try {
22859            const_name = $Opal['$const_name!'](const_name)
22860          } catch ($err) {
22861            if (Opal.rescue($err, [$$$('TypeError'), $$$('NameError')])) {
22862              try {
22863                
22864                args.$unshift(const_name);
22865                const_name = nil;
22866              } finally { Opal.pop_exception(); }
22867            } else { throw $err; }
22868          };
22869        }
22870      };
22871      $send(args, 'map', [], function $$2(arg){
22872        
22873        if (arg == null) arg = nil;
22874        return $Opal['$coerce_to!'](arg, $$$('String'), "to_str");});
22875      klass = $send($Class, 'new', [self], function $$3(){var self = $$3.$$s == null ? this : $$3.$$s;
22876
22877        
22878        $send(args, 'each', [], function $$4(arg){var self = $$4.$$s == null ? this : $$4.$$s;
22879
22880          
22881          if (arg == null) arg = nil;
22882          return self.$define_struct_attribute(arg);}, {$$s: self});
22883        return (function(self, $parent_nesting) {
22884          
22885          
22886          
22887          $def(self, '$new', function $new$5($a) {
22888            var $post_args, args, self = this, instance = nil;
22889
22890            
22891            $post_args = $slice(arguments);
22892            args = $post_args;
22893            instance = self.$allocate();
22894            instance.$$data = {};
22895            $send(instance, 'initialize', $to_a(args));
22896            return instance;
22897          }, -1);
22898          return self.$alias_method("[]", "new");
22899        })(Opal.get_singleton_class(self), $nesting);}, {$$s: self});
22900      if ($truthy(block)) {
22901        $send(klass, 'module_eval', [], block.$to_proc())
22902      };
22903      klass.$$keyword_init = keyword_init;
22904      if ($truthy(const_name)) {
22905        $$$('Struct').$const_set(const_name, klass)
22906      };
22907      return klass;
22908    }, -2);
22909    $defs(self, '$define_struct_attribute', function $$define_struct_attribute(name) {
22910      var self = this;
22911
22912      
22913      if ($eqeq(self, $$$('Struct'))) {
22914        $Kernel.$raise($$$('ArgumentError'), "you cannot define attributes to the Struct class")
22915      };
22916      self.$members()['$<<'](name);
22917      $send(self, 'define_method', [name], function $$6(){var self = $$6.$$s == null ? this : $$6.$$s;
22918
22919        return self.$$data[name];}, {$$s: self});
22920      return $send(self, 'define_method', ["" + (name) + "="], function $$7(value){var self = $$7.$$s == null ? this : $$7.$$s;
22921
22922        
22923        if (value == null) value = nil;
22924        return self.$$data[name] = value;;}, {$$s: self});
22925    });
22926    $defs(self, '$members', function $$members() {
22927      var self = this, $ret_or_1 = nil;
22928      if (self.members == null) self.members = nil;
22929
22930      
22931      if ($eqeq(self, $$$('Struct'))) {
22932        $Kernel.$raise($$$('ArgumentError'), "the Struct class has no members")
22933      };
22934      return (self.members = ($truthy(($ret_or_1 = self.members)) ? ($ret_or_1) : ([])));
22935    });
22936    $defs(self, '$inherited', function $$inherited(klass) {
22937      var self = this, members = nil;
22938      if (self.members == null) self.members = nil;
22939
22940      
22941      members = self.members;
22942      return $send(klass, 'instance_eval', [], function $$8(){var self = $$8.$$s == null ? this : $$8.$$s;
22943
22944        return (self.members = members)}, {$$s: self});
22945    });
22946    
22947    $def(self, '$initialize', function $$initialize($a) {
22948      var $post_args, args, self = this, kwargs = nil, $ret_or_1 = nil, extra = nil;
22949
22950      
22951      $post_args = $slice(arguments);
22952      args = $post_args;
22953      if ($truthy(self.$class().$$keyword_init)) {
22954        
22955        kwargs = ($truthy(($ret_or_1 = args.$last())) ? ($ret_or_1) : ($hash2([], {})));
22956        if (($truthy($rb_gt(args.$length(), 1)) || ($truthy((args.length === 1 && !kwargs.$$is_hash))))) {
22957          $Kernel.$raise($$$('ArgumentError'), "wrong number of arguments (given " + (args.$length()) + ", expected 0)")
22958        };
22959        extra = $rb_minus(kwargs.$keys(), self.$class().$members());
22960        if ($truthy(extra['$any?']())) {
22961          $Kernel.$raise($$$('ArgumentError'), "unknown keywords: " + (extra.$j
22961oin(", ")))
22962        };
22963        return $send(self.$class().$members(), 'each', [], function $$9(name){var $b, self = $$9.$$s == null ? this : $$9.$$s;
22964
22965          
22966          if (name == null) name = nil;
22967          return ($b = [name, kwargs['$[]'](name)], $send(self, '[]=', $b), $b[$b.length - 1]);}, {$$s: self});
22968      } else {
22969        
22970        if ($truthy($rb_gt(args.$length(), self.$class().$members().$length()))) {
22971          $Kernel.$raise($$$('ArgumentError'), "struct size differs")
22972        };
22973        return $send(self.$class().$members(), 'each_with_index', [], function $$10(name, index){var $b, self = $$10.$$s == null ? this : $$10.$$s;
22974
22975          
22976          if (name == null) name = nil;
22977          if (index == null) index = nil;
22978          return ($b = [name, args['$[]'](index)], $send(self, '[]=', $b), $b[$b.length - 1]);}, {$$s: self});
22979      };
22980    }, -1);
22981    
22982    $def(self, '$initialize_copy', function $$initialize_copy(from) {
22983      var self = this;
22984
22985      
22986      self.$$data = {}
22987      var keys = Object.keys(from.$$data), i, max, name;
22988      for (i = 0, max = keys.length; i < max; i++) {
22989        name = keys[i];
22990        self.$$data[name] = from.$$data[name];
22991      }
22992    
22993    });
22994    $defs(self, '$keyword_init?', function $Struct_keyword_init$ques$11() {
22995      var self = this;
22996
22997      return self.$$keyword_init;
22998    });
22999    
23000    $def(self, '$members', function $$members() {
23001      var self = this;
23002
23003      return self.$class().$members()
23004    });
23005    
23006    $def(self, '$hash', function $$hash() {
23007      var self = this;
23008
23009      return $$('Hash').$new(self.$$data).$hash()
23010    });
23011    
23012    $def(self, '$[]', function $Struct_$$$12(name) {
23013      var self = this;
23014
23015      
23016      if ($eqeqeq($$$('Integer'), name)) {
23017        
23018        if ($truthy($rb_lt(name, self.$class().$members().$size()['$-@']()))) {
23019          $Kernel.$raise($$$('IndexError'), "offset " + (name) + " too small for struct(size:" + (self.$class().$members().$size()) + ")")
23020        };
23021        if ($truthy($rb_ge(name, self.$class().$members().$size()))) {
23022          $Kernel.$raise($$$('IndexError'), "offset " + (name) + " too large for struct(size:" + (self.$class().$members().$size()) + ")")
23023        };
23024        name = self.$class().$members()['$[]'](name);
23025      } else if ($eqeqeq($$$('String'), name)) {
23026        
23027        if(!self.$$data.hasOwnProperty(name)) {
23028          $Kernel.$raise($$$('NameError').$new("no member '" + (name) + "' in struct", name))
23029        }
23030      
23031      } else {
23032        $Kernel.$raise($$$('TypeError'), "no implicit conversion of " + (name.$class()) + " into Integer")
23033      };
23034      name = $Opal['$coerce_to!'](name, $$$('String'), "to_str");
23035      return self.$$data[name];;
23036    });
23037    
23038    $def(self, '$[]=', function $Struct_$$$eq$13(name, value) {
23039      var self = this;
23040
23041      
23042      if ($eqeqeq($$$('Integer'), name)) {
23043        
23044        if ($truthy($rb_lt(name, self.$class().$members().$size()['$-@']()))) {
23045          $Kernel.$raise($$$('IndexError'), "offset " + (name) + " too small for struct(size:" + (self.$class().$members().$size()) + ")")
23046        };
23047        if ($truthy($rb_ge(name, self.$class().$members().$size()))) {
23048          $Kernel.$raise($$$('IndexError'), "offset " + (name) + " too large for struct(size:" + (self.$class().$members().$size()) + ")")
23049        };
23050        name = self.$class().$members()['$[]'](name);
23051      } else if ($eqeqeq($$$('String'), name)) {
23052        if (!$truthy(self.$class().$members()['$include?'](name.$to_sym()))) {
23053          $Kernel.$raise($$$('NameError').$new("no member '" + (name) + "' in struct", name))
23054        }
23055      } else {
23056        $Kernel.$raise($$$('TypeError'), "no implicit conversion of " + (name.$class()) + " into Integer")
23057      };
23058      name = $Opal['$coerce_to!'](name, $$$('String'), "to_str");
23059      return self.$$data[name] = value;;
23060    });
23061    
23062    $def(self, '$==', function $Struct_$eq_eq$14(other) {
23063      var self = this;
23064
23065      
23066      if (!$truthy(other['$instance_of?'](self.$class()))) {
23067        return false
23068      };
23069      
23070      var recursed1 = {}, recursed2 = {};
23071
23072      function _eqeq(struct, other) {
23073        var key, a, b;
23074
23075        recursed1[(struct).$__id__()] = true;
23076        recursed2[(other).$__id__()] = true;
23077
23078        for (key in struct.$$data) {
23079          a = struct.$$data[key];
23080          b = other.$$data[key];
23081
23082          if ($$$('Struct')['$==='](a)) {
23083            if (!recursed1.hasOwnProperty((a).$__id__()) || !recursed2.hasOwnProperty((b).$__id__())) {
23084              if (!_eqeq(a, b)) {
23085                return false;
23086              }
23087            }
23088          } else {
23089            if (!(a)['$=='](b)) {
23090              return false;
23091            }
23092          }
23093        }
23094
23095        return true;
23096      }
23097
23098      return _eqeq(self, other);
23099    ;
23100    });
23101    
23102    $def(self, '$eql?', function $Struct_eql$ques$15(other) {
23103      var self = this;
23104
23105      
23106      if (!$truthy(other['$instance_of?'](self.$class()))) {
23107        return false
23108      };
23109      
23110      var recursed1 = {}, recursed2 = {};
23111
23112      function _eqeq(struct, other) {
23113        var key, a, b;
23114
23115        recursed1[(struct).$__id__()] = true;
23116        recursed2[(other).$__id__()] = true;
23117
23118        for (key in struct.$$data) {
23119          a = struct.$$data[key];
23120          b = other.$$data[key];
23121
23122          if ($$$('Struct')['$==='](a)) {
23123            if (!recursed1.hasOwnProperty((a).$__id__()) || !recursed2.hasOwnProperty((b).$__id__())) {
23124              if (!_eqeq(a, b)) {
23125                return false;
23126              }
23127            }
23128          } else {
23129            if (!(a)['$eql?'](b)) {
23130              return false;
23131            }
23132          }
23133        }
23134
23135        return true;
23136      }
23137
23138      return _eqeq(self, other);
23139    ;
23140    });
23141    
23142    $def(self, '$each', function $$each() {
23143      var $yield = $$each.$$p || nil, self = this;
23144
23145      $$each.$$p = null;
23146      
23147      if (!($yield !== nil)) {
23148        return $send(self, 'enum_for', ["each"], function $$16(){var self = $$16.$$s == null ? this : $$16.$$s;
23149
23150          return self.$size()}, {$$s: self})
23151      };
23152      $send(self.$class().$members(), 'each', [], function $$17(name){var self = $$17.$$s == null ? this : $$17.$$s;
23153
23154        
23155        if (name == null) name = nil;
23156        return Opal.yield1($yield, self['$[]'](name));;}, {$$s: self});
23157      return self;
23158    });
23159    
23160    $def(self, '$each_pair', function $$each_pair() {
23161      var $yield = $$each_pair.$$p || nil, self = this;
23162
23163      $$each_pair.$$p = null;
23164      
23165      if (!($yield !== nil)) {
23166        return $send(self, 'enum_for', ["each_pair"], function $$18(){var self = $$18.$$s == null ? this : $$18.$$s;
23167
23168          return self.$size()}, {$$s: self})
23169      };
23170      $send(self.$class().$members(), 'each', [], function $$19(name){var self = $$19.$$s == null ? this : $$19.$$s;
23171
23172        
23173        if (name == null) name = nil;
23174        return Opal.yield1($yield, [name, self['$[]'](name)]);;}, {$$s: self});
23175      return self;
23176    });
23177    
23178    $def(self, '$length', function $$length() {
23179      var self = this;
23180
23181      return self.$class().$members().$length()
23182    });
23183    
23184    $def(self, '$to_a', function $$to_a() {
23185      var self = this;
23186
23187      return $send(self.$class().$members(), 'map', [], function $$20(name){var self = $$20.$$s == null ? this : $$20.$$s;
23188
23189        
23190        if (name == null) name = nil;
23191        return self['$[]'](name);}, {$$s: self})
23192    });
23193    var inspect_stack = [];
23194    
23195    $def(self, '$inspect', function $$inspect() {
23196      var self = this, result = nil, pushed = nil;
23197
23198      return (function() { try {
23199      
23200      result = "#<struct ";
23201      if ($truthy((inspect_stack)['$include?'](self.$__id__()))) {
23202        return $rb_plus(result, ":...>")
23203      } else {
23204        
23205        (inspect_stack)['$<<'](self.$__id__());
23206        pushed = true;
23207        if (($eqeqeq($$$('Struct'), self) && ($truthy(self.$class().$name())))) {
23208          result = $rb_plus(result, "" + (self.$class()) + " ")
23209        };
23210        result = $rb_plus(result, $send(self.$each_pair(), 'map', [], function $$21(name, value){
23211          
23212          if (name == null) name = nil;
23213          if (value == null) value = nil;
23214          return "" + (name) + "=" + ($$('Opal').$inspect(value));}).$join(", "));
23215        result = $rb_plus(result, ">");
23216        return result;
23217      };
23218      } finally {
23219        ($truthy(pushed) ? (inspect_stack.pop()) : nil)
23220      }; })()
23221    });
23222    
23223    $def(self, '$to_h', function $$to_h() {
23224      var block = $$to_h.$$p || nil, self = this;
23225
23226      $$to_h.$$p = null;
23227      
23228      ;
23229      if ((block !== nil)) {
23230        return $send($send(self, 'map', [], block.$to_proc()), 'to_h', $to_a(self.$args()))
23231      };
23232      return $send(self.$class().$members(), 'each_with_object', [$hash2([], {})], function $$22(name, h){var $a, self = $$22.$$s == null ? this : $$22.$$s;
23233
23234        
23235        if (name == null) name = nil;
23236        if (h == null) h = nil;
23237        return ($a = [name, self['$[]'](name)], $send(h, '[]=', $a), $a[$a.length - 1]);}, {$$s: self});
23238    });
23239    
23240    $def(self, '$values_at', function $$values_at($a) {
23241      var $post_args, args, self = this;
23242
23243      
23244      $post_args = $slice(arguments);
23245      args = $post_args;
23246      args = $send(args, 'map', [], function $$23(arg){
23247        
23248        if (arg == null) arg = nil;
23249        return arg.$$is_range ? arg.$to_a() : arg;}).$flatten();
23250      
23251      var result = [];
23252      for (var i = 0, len = args.length; i < len; i++) {
23253        if (!args[i].$$is_number) {
23254          $Kernel.$raise($$$('TypeError'), "no implicit conversion of " + ((args[i]).$class()) + " into Integer")
23255        }
23256        result.push(self['$[]'](args[i]));
23257      }
23258      return result;
23259    ;
23260    }, -1);
23261    
23262    $def(self, '$dig', function $$dig(key, $a) {
23263      var $post_args, keys, self = this, item = nil;
23264
23265      
23266      $post_args = $slice(arguments, 1);
23267      keys = $post_args;
23268      item = ($truthy(key.$$is_string && self.$$data.hasOwnProperty(key)) ? (self.$$data[key] || nil) : nil);
23269      
23270      if (item === nil || keys.length === 0) {
23271        return item;
23272      }
23273    ;
23274      if (!$truthy(item['$respond_to?']("dig"))) {
23275        $Kernel.$raise($$$('TypeError'), "" + (item.$class()) + " does not have #dig method")
23276      };
23277      return $send(item, 'dig', $to_a(keys));
23278    }, -2);
23279    $alias(self, "size", "length");
23280    $alias(self, "to_s", "inspect");
23281    return $alias(self, "values", "to_a");
23282  })('::', null, $nesting);
23283};
23284
23285Opal.modules["corelib/set"] = function(Opal) {/* Generated by Opal 1.7.3 */
23286  var $freeze = Opal.freeze, $klass = Opal.klass, $slice = Opal.slice, $defs = Opal.defs, $hash2 = Opal.hash2, $truthy = Opal.truthy, $eqeqeq = Opal.eqeqeq, $Kernel = Opal.Kernel, $send = Opal.send, $def = Opal.def, $eqeq = Opal.eqeq, $rb_lt = Opal.rb_lt, $rb_le = Opal.rb_le, $alias = Opal.alias, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$;
23287
23288  Opal.add_stubs('include,new,nil?,===,raise,each,add,merge,class,respond_to?,subtract,dup,join,to_a,equal?,instance_of?,==,instance_variable_get,size,is_a?,all?,include?,[]=,enum_for,[],<<,replace,compare_by_identity,name,compare_by_identity?,delete,select,frozen?,freeze,reject,delete_if,to_proc,keep_if,each_key,empty?,eql?,instance_eval,clear,<,<=,any?,!,intersect?,keys,|,proper_subset?,subset?,proper_superset?,superset?,-,select!,collect!');
23289  return (function($base, $super, $parent_nesting) {
23290    var self = $klass($base, $super, 'Set');
23291
23292    var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $ret_or_1 = nil, $proto = self.$$prototype;
23293
23294    $proto.hash = nil;
23295    
23296    self.$include($$$('Enumerable'));
23297    $defs(self, '$[]', function $Set_$$$1($a) {
23298      var $post_args, ary, self = this;
23299
23300      
23301      $post_args = $slice(arguments);
23302      ary = $post_args;
23303      return self.$new(ary);
23304    }, -1);
23305    
23306    $def(self, '$initialize', function $$initialize(enum$) {
23307      var block = $$initialize.$$p || nil, self = this;
23308
23309      $$initialize.$$p = null;
23310      
23311      ;
23312      if (enum$ == null) enum$ = nil;
23313      self.hash = $hash2([], {});
23314      if ($truthy(enum$['$nil?']())) {
23315        return nil
23316      };
23317      if (!$eqeqeq($$$('Enumerable'), enum$)) {
23318        $Kernel.$raise($$$('ArgumentError'), "value must be enumerable")
23319      };
23320      if ($truthy(block)) {
23321        return $send(enum$, 'each', [], function $$2(item){var self = $$2.$$s == null ? this : $$2.$$s;
23322
23323          
23324          if (item == null) item = nil;
23325          return self.$add(Opal.yield1(block, item));}, {$$s: self})
23326      } else {
23327        return self.$merge(enum$)
23328      };
23329    }, -1);
23330    
23331    $def(self, '$dup', function $$dup() {
23332      var self = this, result = nil;
23333
23334      
23335      result = self.$class().$new();
23336      return result.$merge(self);
23337    });
23338    
23339    $def(self, '$-', function $Set_$minus$3(enum$) {
23340      var self = this;
23341
23342      
23343      if (!$truthy(enum$['$respond_to?']("each"))) {
23344        $Kernel.$raise($$$('ArgumentError'), "value must be enumerable")
23345      };
23346      return self.$dup().$subtract(enum$);
23347    });
23348    
23349    $def(self, '$inspect', function $$inspect() {
23350      var self = this;
23351
23352      return "#<Set: {" + (self.$to_a().$join(",")) + "}>"
23353    });
23354    
23355    $def(self, '$==', function $Set_$eq_eq$4(other) {
23356      var self = this;
23357
23358      if ($truthy(self['$equal?'](other))) {
23359        return true
23360      } else if ($truthy(other['$instance_of?'](self.$class()))) {
23361        return self.hash['$=='](other.$instance_variable_get("@hash"))
23362      } else if (($truthy(other['$is_a?']($$$('Set'))) && ($eqeq(self.$size(), other.$size())))) {
23363        return $send(other, 'all?', [], function $$5(o){var self = $$5.$$s == null ? this : $$5.$$s;
23364          if (self.hash == null) self.hash = nil;
23365
23366          
23367          if (o == null) o = nil;
23368          return self.hash['$include?'](o);}, {$$s: self})
23369      } else {
23370        return false
23371      }
23372    });
23373    
23374    $def(self, '$add', function $$add(o) {
23375      var self = this;
23376
23377      
23378      self.hash['$[]='](o, true);
23379      return self;
23380    });
23381    
23382    $def(self, '$classify', function $$classify() {
23383      var block = $$classify.$$p || nil, self = this, result = nil;
23384
23385      $$classify.$$p = null;
23386      
23387      ;
23388      if (!(block !== nil)) {
23389        return self.$enum_for("classify")
23390      };
23391      result = $send($$$('Hash'), 'new', [], function $$6(h, k){var $a, self = $$6.$$s == null ? this : $$6.$$s;
23392
23393        
23394        if (h == null) h = nil;
23395        if (k == null) k = nil;
23396        return ($a = [k, self.$class().$new()], $send(h, '[]=', $a), $a[$a.length - 1]);}, {$$s: self});
23397      $send(self, 'each', [], function $$7(item){
23398        
23399        if (item == null) item = nil;
23400        return result['$[]'](Opal.yield1(block, item)).$add(item);});
23401      return result;
23402    });
23403    
23404    $def(self, '$collect!', function $Set_collect$excl$8() {
23405      var block = $Set_collect$excl$8.$$p || nil, self = this, result = nil;
23406
23407      $Set_collect$excl$8.$$p = null;
23408      
23409      ;
23410      if (!(block !== nil)) {
23411        return self.$enum_for("collect!")
23412      };
23413      result = self.$class().$new();
23414      $send(self, 'each', [], function $$9(item){
23415        
23416        if (item == null) item = nil;
23417        return result['$<<'](Opal.yield1(block, item));});
23418      return self.$replace(result);
23419    });
23420    
23421    $def(self, '$compare_by_identity', function $$compare_by_identity() {
23422      var self = this;
23423
23424      if ($truthy(self.hash['$respond_to?']("compare_by_identity"))) {
23425        
23426        self.hash.$compare_by_identity();
23427        return self;
23428      } else {
23429        return self.$raise($$('NotImplementedError'), "" + (self.$class().$name()) + "#" + ("compare_by_identity") + " is not implemented")
23430      }
23431    });
23432    
23433    $def(self, '$compare_by_identity?', function $Set_compare_by_identity$ques$10() {
23434      var self = this, $ret_or_1 = nil;
23435
23436      if ($truthy(($ret_or_1 = self.hash['$respond_to?']("compare_by_identity?")))) {
23437        return self.hash['$compare_by_identity?']()
23438      } else {
23439        return $ret_or_1
23440      }
23441    });
23442    
23443    $def(self, '$delete', function $Set_delete$11(o) {
23444      var self = this;
23445
23446      
23447      self.hash.$delete(o);
23448      return self;
23449    });
23450    
23451    $def(self, '$delete?', function $Set_delete$ques$12(o) {
23452      var self = this;
23453
23454      if ($truthy(self['$include?'](o))) {
23455        
23456        self.$delete(o);
23457        return self;
23458      } else {
23459        return nil
23460      }
23461    });
23462    
23463    $def(self, '$delete_if', function $$delete_if() {
23464      var $yield = $$delete_if.$$p || nil, self = this;
23465
23466      $$delete_if.$$p = null;
23467      
23468      if (!($yield !== nil)) {
23469        return self.$enum_for("delete_if")
23470      };
23471      $send($send(self, 'select', [], function $$13(o){
23472        
23473        if (o == null) o = nil;
23474        return Opal.yield1($yield, o);;}), 'each', [], function $$14(o){var self = $$14.$$s == null ? this : $$14.$$s;
23475        if (self.hash == null) self.hash = nil;
23476
23477        
23478        if (o == null) o = nil;
23479        return self.hash.$delete(o);}, {$$s: self});
23480      return self;
23481    });
23482    
23483    $def(self, '$freeze', function $$freeze() {
23484      var self = this;
23485
23486      
23487      if ($truthy(self['$frozen?']())) {
23488        return self
23489      };
23490      self.hash.$freeze();
23491      return $freeze(self);;
23492    });
23493    
23494    $def(self, '$keep_if', function $$keep_if() {
23495      var $yield = $$keep_if.$$p || nil, self = this;
23496
23497      $$keep_if.$$p = null;
23498      
23499      if (!($yield !== nil)) {
23500        return self.$enum_for("keep_if")
23501      };
23502      $send($send(self, 'reject', [], function $$15(o){
23503        
23504        if (o == null) o = nil;
23505        return Opal.yield1($yield, o);;}), 'each', [], function $$16(o){var self = $$16.$$s == null ? this : $$16.$$s;
23506        if (self.hash == null) self.hash = nil;
23507
23508        
23509        if (o == null) o = nil;
23510        return self.hash.$delete(o);}, {$$s: self});
23511      return self;
23512    });
23513    
23514    $def(self, '$reject!', function $Set_reject$excl$17() {
23515      var block = $Set_reject$excl$17.$$p || nil, self = this, before = nil;
23516
23517      $Set_reject$excl$17.$$p = null;
23518      
23519      ;
23520      if (!(block !== nil)) {
23521        return self.$enum_for("reject!")
23522      };
23523      before = self.$size();
23524      $send(self, 'delete_if', [], block.$to_proc());
23525      if ($eqeq(self.$size(), before)) {
23526        return nil
23527      } else {
23528        return self
23529      };
23530    });
23531    
23532    $def(self, '$select!', function $Set_select$excl$18() {
23533      var block = $Set_select$excl$18.$$p || nil, self = this, before = nil;
23534
23535      $Set_select$excl$18.$$p = null;
23536      
23537      ;
23538      if (!(block !== nil)) {
23539        return self.$enum_for("select!")
23540      };
23541      before = self.$size();
23542      $send(self, 'keep_if', [], block.$to_proc());
23543      if ($eqeq(self.$size(), before)) {
23544        return nil
23545      } else {
23546        return self
23547      };
23548    });
23549    
23550    $def(self, '$add?', function $Set_add$ques$19(o) {
23551      var self = this;
23552
23553      if ($truthy(self['$include?'](o))) {
23554        return nil
23555      } else {
23556        return self.$add(o)
23557      }
23558    });
23559    
23560    $def(self, '$each', function $$each() {
23561      var block = $$each.$$p || nil, self = this;
23562
23563      $$each.$$p = null;
23564      
23565      ;
23566      if (!(block !== nil)) {
23567        return self.$enum_for("each")
23568      };
23569      $send(self.hash, 'each_key', [], block.$to_proc());
23570      return self;
23571    });
23572    
23573    $def(self, '$empty?', function $Set_empty$ques$20() {
23574      var self = this;
23575
23576      return self.hash['$empty?']()
23577    });
23578    
23579    $def(self, '$eql?', function $Set_eql$ques$21(other) {
23580      var self = this;
23581
23582      return self.hash['$eql?']($send(other, 'instance_eval', [], function $$22(){var self = $$22.$$s == null ? this : $$22.$$s;
23583        if (self.hash == null) self.hash = nil;
23584
23585        return self.hash}, {$$s: self}))
23586    });
23587    
23588    $def(self, '$clear', function $$clear() {
23589      var self = this;
23590
23591      
23592      self.hash.$clear();
23593      return self;
23594    });
23595    
23596    $def(self, '$include?', function $Set_include$ques$23(o) {
23597      var self = this;
23598
23599      return self.hash['$include?'](o)
23600    });
23601    
23602    $def(self, '$merge', function $$merge(enum$) {
23603      var self = this;
23604
23605      
23606      $send(enum$, 'each', [], function $$24(item){var self = $$24.$$s == null ? this : $$24.$$s;
23607
23608        
23609        if (item == null) item = nil;
23610        return self.$add(item);}, {$$s: self});
23611      return self;
23612    });
23613    
23614    $def(self, '$replace', function $$replace(enum$) {
23615      var self = this;
23616
23617      
23618      self.$clear();
23619      self.$merge(enum$);
23620      return self;
23621    });
23622    
23623    $def(self, '$size', function $$size() {
23624      var self = this;
23625
23626      return self.hash.$size()
23627    });
23628    
23629    $def(self, '$subtract', function $$subtract(enum$) {
23630      var self = this;
23631
23632      
23633      $send(enum$, 'each', [], function $$25(item){var self = $$25.$$s == null ? this : $$25.$$s;
23634
23635        
23636        if (item == null) item = nil;
23637        return self.$delete(item);}, {$$s: self});
23638      return self;
23639    });
23640    
23641    $def(self, '$|', function $Set_$$26(enum$) {
23642      var self = this;
23643
23644      
23645      if (!$truthy(enum$['$respond_to?']("each"))) {
23646        $Kernel.$raise($$$('ArgumentError'), "value must be enumerable")
23647      };
23648      return self.$dup().$merge(enum$);
23649    });
23650    
23651    function is_set(set) {
23652      ($truthy(($ret_or_1 = (set)['$is_a?']($$$('Set')))) ? ($ret_or_1) : ($Kernel.$raise($$$('ArgumentError'), "value must be a set")))
23653    }
23654  ;
23655    
23656    $def(self, '$superset?', function $Set_superset$ques$27(set) {
23657      var self = this;
23658
23659      
23660      is_set(set);
23661      if ($truthy($rb_lt(self.$size(), set.$size()))) {
23662        return false
23663      };
23664      return $send(set, 'all?', [], function $$28(o){var self = $$28.$$s == null ? this : $$28.$$s;
23665
23666        
23667        if (o == null) o = nil;
23668        return self['$include?'](o);}, {$$s: self});
23669    });
23670    
23671    $def(self, '$proper_superset?', function $Set_proper_superset$ques$29(set) {
23672      var self = this;
23673
23674      
23675      is_set(set);
23676      if ($truthy($rb_le(self.$size(), set.$size()))) {
23677        return false
23678      };
23679      return $send(set, 'all?', [], function $$30(o){var self = $$30.$$s == null ? this : $$30.$$s;
23680
23681        
23682        if (o == null) o = nil;
23683        return self['$include?'](o);}, {$$s: self});
23684    });
23685    
23686    $def(self, '$subset?', function $Set_subset$ques$31(set) {
23687      var self = this;
23688
23689      
23690      is_set(set);
23691      if ($truthy($rb_lt(set.$size(), self.$size()))) {
23692        return false
23693      };
23694      return $send(self, 'all?', [], function $$32(o){
23695        
23696        if (o == null) o = nil;
23697        return set['$include?'](o);});
23698    });
23699    
23700    $def(self, '$proper_subset?', function $Set_proper_subset$ques$33(set) {
23701      var self = this;
23702
23703      
23704      is_set(set);
23705      if ($truthy($rb_le(set.$size(), self.$size()))) {
23706        return false
23707      };
23708      return $send(self, 'all?', [], function $$34(o){
23709        
23710        if (o == null) o = nil;
23711        return set['$include?'](o);});
23712    });
23713    
23714    $def(self, '$intersect?', function $Set_intersect$ques$35(set) {
23715      var self = this;
23716
23717      
23718      is_set(set);
23719      if ($truthy($rb_lt(self.$size(), set.$size()))) {
23720        return $send(self, 'any?', [], function $$36(o){
23721          
23722          if (o == null) o = nil;
23723          return set['$include?'](o);})
23724      } else {
23725        return $send(set, 'any?', [], function $$37(o){var self = $$37.$$s == null ? this : $$37.$$s;
23726
23727          
23728          if (o == null) o = nil;
23729          return self['$include?'](o);}, {$$s: self})
23730      };
23731    });
23732    
23733    $def(self, '$disjoint?', function $Set_disjoint$ques$38(set) {
23734      var self = this;
23735
23736      return self['$intersect?'](set)['$!']()
23737    });
23738    
23739    $def(self, '$to_a', function $$to_a() {
23740      var self = this;
23741
23742      return self.hash.$keys()
23743    });
23744    $alias(self, "+", "|");
23745    $alias(self, "<", "proper_subset?");
23746    $alias(self, "<<", "add");
23747    $alias(self, "<=", "subset?");
23748    $alias(self, ">", "proper_superset?");
23749    $alias(self, ">=", "superset?");
23750    $alias(self, "difference", "-");
23751    $alias(self, "filter!", "select!");
23752    $alias(self, "length", "size");
23753    $alias(self, "map!", "collect!");
23754    $alias(self, "member?", "include?");
23755    return $alias(self, "union", "|");
23756  })('::', null, $nesting)
23757};
23758
23759Opal.modules["corelib/dir"] = function(Opal) {/* Generated by Opal 1.7.3 */
23760  var $klass = Opal.klass, $def = Opal.def, $truthy = Opal.truthy, $alias = Opal.alias, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$;
23761
23762  Opal.add_stubs('[],pwd');
23763  return (function($base, $super, $parent_nesting) {
23764    var self = $klass($base, $super, 'Dir');
23765
23766    var $nesting = [self].concat($parent_nesting);
23767
23768    return (function(self, $parent_nesting) {
23769      
23770      
23771      
23772      $def(self, '$chdir', function $$chdir(dir) {
23773        var $yield = $$chdir.$$p || nil, prev_cwd = nil;
23774
23775        $$chdir.$$p = null;
23776        return (function() { try {
23777        
23778        prev_cwd = Opal.current_dir;
23779        Opal.current_dir = dir;
23780        return Opal.yieldX($yield, []);;
23781        } finally {
23782          Opal.current_dir = prev_cwd
23783        }; })()
23784      });
23785      
23786      $def(self, '$pwd', function $$pwd() {
23787        
23788        return Opal.current_dir || '.';
23789      });
23790      
23791      $def(self, '$home', function $$home() {
23792        var $ret_or_1 = nil;
23793
23794        if ($truthy(($ret_or_1 = $$$('ENV')['$[]']("HOME")))) {
23795          return $ret_or_1
23796        } else {
23797          return "."
23798        }
23799      });
23800      return $alias(self, "getwd", "pwd");
23801    })(Opal.get_singleton_class(self), $nesting)
23802  })('::', null, $nesting)
23803};
23804
23805Opal.modules["corelib/file"] = function(Opal) {/* Generated by Opal 1.7.3 */
23806  var $truthy = Opal.truthy, $klass = Opal.klass, $const_set = Opal.const_set, $Opal = Opal.Opal, $regexp = Opal.regexp, $rb_plus = Opal.rb_plus, $def = Opal.def, $Kernel = Opal.Kernel, $eqeq = Opal.eqeq, $rb_lt = Opal.rb_lt, $rb_minus = Opal.rb_minus, $range = Opal.range, $send = Opal.send, $slice = Opal.slice, $alias = Opal.alias, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$;
23807
23808  Opal.add_stubs('respond_to?,to_path,coerce_to!,pwd,split,sub,+,unshift,join,home,raise,start_with?,absolute_path,==,<,dirname,-,basename,empty?,rindex,[],length,nil?,gsub,find,=~,map,each_with_index,flatten,reject,to_proc,end_with?,expand_path,exist?');
23809  return (function($base, $super, $parent_nesting) {
23810    var self = $klass($base, $super, 'File');
23811
23812    var $nesting = [self].concat($parent_nesting), windows_root_rx = nil;
23813
23814    
23815    $const_set($nesting[0], 'Separator', $const_set($nesting[0], 'SEPARATOR', "/"));
23816    $const_set($nesting[0], 'ALT_SEPARATOR', nil);
23817    $const_set($nesting[0], 'PATH_SEPARATOR', ":");
23818    $const_set($nesting[0], 'FNM_SYSCASE', 0);
23819    windows_root_rx = /^[a-zA-Z]:(?:\\|\/)/;
23820    return (function(self, $parent_nesting) {
23821      var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
23822
23823      
23824      
23825      $def(self, '$absolute_path', function $$absolute_path(path, basedir) {
23826        var sep = nil, sep_chars = nil, new_parts = nil, $ret_or_1 = nil, path_abs = nil, basedir_abs = nil, parts = nil, leading_sep = nil, abs = nil, new_path = nil;
23827
23828        
23829        if (basedir == null) basedir = nil;
23830        sep = $$('SEPARATOR');
23831        sep_chars = $sep_chars();
23832        new_parts = [];
23833        path = ($truthy(path['$respond_to?']("to_path")) ? (path.$to_path()) : (path));
23834        path = $Opal['$coerce_to!'](path, $$$('String'), "to_str");
23835        basedir = ($truthy(($ret_or_1 = basedir)) ? ($ret_or_1) : ($$$('Dir').$pwd())
23835);
23836        path_abs = path.substr(0, sep.length) === sep || windows_root_rx.test(path);
23837        basedir_abs = basedir.substr(0, sep.length) === sep || windows_root_rx.test(basedir);
23838        if ($truthy(path_abs)) {
23839          
23840          parts = path.$split($regexp(["[", sep_chars, "]"]));
23841          leading_sep = windows_root_rx.test(path) ? '' : path.$sub($regexp(["^([", sep_chars, "]+).*$"]), "\\1");
23842          abs = true;
23843        } else {
23844          
23845          parts = $rb_plus(basedir.$split($regexp(["[", sep_chars, "]"])), path.$split($regexp(["[", sep_chars, "]"])));
23846          leading_sep = windows_root_rx.test(basedir) ? '' : basedir.$sub($regexp(["^([", sep_chars, "]+).*$"]), "\\1");
23847          abs = basedir_abs;
23848        };
23849        
23850        var part;
23851        for (var i = 0, ii = parts.length; i < ii; i++) {
23852          part = parts[i];
23853
23854          if (
23855            (part === nil) ||
23856            (part === ''  && ((new_parts.length === 0) || abs)) ||
23857            (part === '.' && ((new_parts.length === 0) || abs))
23858          ) {
23859            continue;
23860          }
23861          if (part === '..') {
23862            new_parts.pop();
23863          } else {
23864            new_parts.push(part);
23865          }
23866        }
23867
23868        if (!abs && parts[0] !== '.') {
23869          new_parts.$unshift(".")
23870        }
23871      ;
23872        new_path = new_parts.$join(sep);
23873        if ($truthy(abs)) {
23874          new_path = $rb_plus(leading_sep, new_path)
23875        };
23876        return new_path;
23877      }, -2);
23878      
23879      $def(self, '$expand_path', function $$expand_path(path, basedir) {
23880        var self = this, sep = nil, sep_chars = nil, home = nil, leading_sep = nil, home_path_regexp = nil;
23881
23882        
23883        if (basedir == null) basedir = nil;
23884        sep = $$('SEPARATOR');
23885        sep_chars = $sep_chars();
23886        if ($truthy(path[0] === '~' || (basedir && basedir[0] === '~'))) {
23887          
23888          home = $$('Dir').$home();
23889          if (!$truthy(home)) {
23890            $Kernel.$raise($$$('ArgumentError'), "couldn't find HOME environment -- expanding `~'")
23891          };
23892          leading_sep = windows_root_rx.test(home) ? '' : home.$sub($regexp(["^([", sep_chars, "]+).*$"]), "\\1");
23893          if (!$truthy(home['$start_with?'](leading_sep))) {
23894            $Kernel.$raise($$$('ArgumentError'), "non-absolute home")
23895          };
23896          home = $rb_plus(home, sep);
23897          home_path_regexp = $regexp(["^\\~(?:", sep, "|$)"]);
23898          path = path.$sub(home_path_regexp, home);
23899          if ($truthy(basedir)) {
23900            basedir = basedir.$sub(home_path_regexp, home)
23901          };
23902        };
23903        return self.$absolute_path(path, basedir);
23904      }, -2);
23905      
23906      // Coerce a given path to a path string using #to_path and #to_str
23907      function $coerce_to_path(path) {
23908        if ($truthy((path)['$respond_to?']("to_path"))) {
23909          path = path.$to_path();
23910        }
23911
23912        path = $Opal['$coerce_to!'](path, $$$('String'), "to_str");
23913
23914        return path;
23915      }
23916
23917      // Return a RegExp compatible char class
23918      function $sep_chars() {
23919        if ($$('ALT_SEPARATOR') === nil) {
23920          return Opal.escape_regexp($$('SEPARATOR'));
23921        } else {
23922          return Opal.escape_regexp($rb_plus($$('SEPARATOR'), $$('ALT_SEPARATOR')));
23923        }
23924      }
23925    ;
23926      
23927      $def(self, '$dirname', function $$dirname(path, level) {
23928        var self = this, sep_chars = nil;
23929
23930        
23931        if (level == null) level = 1;
23932        if ($eqeq(level, 0)) {
23933          return path
23934        };
23935        if ($truthy($rb_lt(level, 0))) {
23936          $Kernel.$raise($$$('ArgumentError'), "level can't be negative")
23937        };
23938        sep_chars = $sep_chars();
23939        path = $coerce_to_path(path);
23940        
23941        var absolute = path.match(new RegExp("^[" + (sep_chars) + "]")), out;
23942
23943        path = path.replace(new RegExp("[" + (sep_chars) + "]+$"), ''); // remove trailing separators
23944        path = path.replace(new RegExp("[^" + (sep_chars) + "]+$"), ''); // remove trailing basename
23945        path = path.replace(new RegExp("[" + (sep_chars) + "]+$"), ''); // remove final trailing separators
23946
23947        if (path === '') {
23948          out = absolute ? '/' : '.';
23949        }
23950        else {
23951          out = path;
23952        }
23953
23954        if (level == 1) {
23955          return out;
23956        }
23957        else {
23958          return self.$dirname(out, $rb_minus(level, 1))
23959        }
23960      ;
23961      }, -2);
23962      
23963      $def(self, '$basename', function $$basename(name, suffix) {
23964        var sep_chars = nil;
23965
23966        
23967        if (suffix == null) suffix = nil;
23968        sep_chars = $sep_chars();
23969        name = $coerce_to_path(name);
23970        
23971        if (name.length == 0) {
23972          return name;
23973        }
23974
23975        if (suffix !== nil) {
23976          suffix = $Opal['$coerce_to!'](suffix, $$$('String'), "to_str")
23977        } else {
23978          suffix = null;
23979        }
23980
23981        name = name.replace(new RegExp("(.)[" + (sep_chars) + "]*$"), '$1');
23982        name = name.replace(new RegExp("^(?:.*[" + (sep_chars) + "])?([^" + (sep_chars) + "]+)$"), '$1');
23983
23984        if (suffix === ".*") {
23985          name = name.replace(/\.[^\.]+$/, '');
23986        } else if(suffix !== null) {
23987          suffix = Opal.escape_regexp(suffix);
23988          name = name.replace(new RegExp("" + (suffix) + "$"), '');
23989        }
23990
23991        return name;
23992      ;
23993      }, -2);
23994      
23995      $def(self, '$extname', function $$extname(path) {
23996        var self = this, filename = nil, last_dot_idx = nil;
23997
23998        
23999        path = $coerce_to_path(path);
24000        filename = self.$basename(path);
24001        if ($truthy(filename['$empty?']())) {
24002          return ""
24003        };
24004        last_dot_idx = filename['$[]']($range(1, -1, false)).$rindex(".");
24005        if (($truthy(last_dot_idx['$nil?']()) || ($eqeq($rb_plus(last_dot_idx, 1), $rb_minus(filename.$length(), 1))))) {
24006          return ""
24007        } else {
24008          return filename['$[]'](Opal.Range.$new($rb_plus(last_dot_idx, 1), -1, false))
24009        };
24010      });
24011      
24012      $def(self, '$exist?', function $exist$ques$1(path) {
24013        
24014        return Opal.modules[path] != null
24015      });
24016      
24017      $def(self, '$directory?', function $directory$ques$2(path) {
24018        var files = nil;
24019
24020        
24021        files = [];
24022        
24023        for (var key in Opal.modules) {
24024          files.push(key)
24025        }
24026      ;
24027        path = path.$gsub($regexp(["(^.", $$('SEPARATOR'), "+|", $$('SEPARATOR'), "+$)"]));
24028        return $send(files, 'find', [], function $$3(f){
24029          
24030          if (f == null) f = nil;
24031          return f['$=~']($regexp(["^", path]));});
24032      });
24033      
24034      $def(self, '$join', function $$join($a) {
24035        var $post_args, paths, result = nil;
24036
24037        
24038        $post_args = $slice(arguments);
24039        paths = $post_args;
24040        if ($truthy(paths['$empty?']())) {
24041          return ""
24042        };
24043        result = "";
24044        paths = $send(paths.$flatten().$each_with_index(), 'map', [], function $$4(item, index){
24045          
24046          if (item == null) item = nil;
24047          if (index == null) index = nil;
24048          if (($eqeq(index, 0) && ($truthy(item['$empty?']())))) {
24049            return $$('SEPARATOR')
24050          } else if (($eqeq(paths.$length(), $rb_plus(index, 1)) && ($truthy(item['$empty?']())))) {
24051            return $$('SEPARATOR')
24052          } else {
24053            return item
24054          };});
24055        paths = $send(paths, 'reject', [], "empty?".$to_proc());
24056        $send(paths, 'each_with_index', [], function $$5(item, index){var next_item = nil;
24057
24058          
24059          if (item == null) item = nil;
24060          if (index == null) index = nil;
24061          next_item = paths['$[]']($rb_plus(index, 1));
24062          if ($truthy(next_item['$nil?']())) {
24063            return (result = "" + (result) + (item))
24064          } else {
24065            
24066            if (($truthy(item['$end_with?']($$('SEPARATOR'))) && ($truthy(next_item['$start_with?']($$('SEPARATOR')))))) {
24067              item = item.$sub($regexp([$$('SEPARATOR'), "+$"]), "")
24068            };
24069            return (result = (($truthy(item['$end_with?']($$('SEPARATOR'))) || ($truthy(next_item['$start_with?']($$('SEPARATOR'))))) ? ("" + (result) + (item)) : ("" + (result) + (item) + ($$('SEPARATOR')))));
24070          };});
24071        return result;
24072      }, -1);
24073      
24074      $def(self, '$split', function $$split(path) {
24075        
24076        return path.$split($$('SEPARATOR'))
24077      });
24078      $alias(self, "realpath", "expand_path");
24079      return $alias(self, "exists?", "exist?");
24080    })(Opal.get_singleton_class(self), $nesting);
24081  })('::', $$$('IO'), $nesting)
24082};
24083
24084Opal.modules["corelib/process/base"] = function(Opal) {/* Generated by Opal 1.7.3 */
24085  var $klass = Opal.klass, $slice = Opal.slice, $defs = Opal.defs, $return_val = Opal.return_val, nil = Opal.nil;
24086
24087  
24088  (function($base, $super) {
24089    var self = $klass($base, $super, 'Signal');
24090
24091    
24092    return $defs(self, '$trap', function $$trap($a) {
24093      var $post_args, $fwd_rest;
24094
24095      
24096      $post_args = $slice(arguments);
24097      $fwd_rest = $post_args;
24098      return nil;
24099    }, -1)
24100  })('::', null);
24101  return (function($base, $super) {
24102    var self = $klass($base, $super, 'GC');
24103
24104    
24105    return $defs(self, '$start', $return_val(nil))
24106  })('::', null);
24107};
24108
24109Opal.modules["corelib/process"] = function(Opal) {/* Generated by Opal 1.7.3 */
24110  var $module = Opal.module, $defs = Opal.defs, $truthy = Opal.truthy, $return_val = Opal.return_val, $Kernel = Opal.Kernel, nil = Opal.nil, $$$ = Opal.$$$;
24111
24112  Opal.add_stubs('const_set,size,<<,__register_clock__,to_f,now,new,[],raise');
24113  return (function($base) {
24114    var self = $module($base, 'Process');
24115
24116    var monotonic = nil;
24117
24118    
24119    self.__clocks__ = [];
24120    $defs(self, '$__register_clock__', function $$__register_clock__(name, func) {
24121      var self = this;
24122      if (self.__clocks__ == null) self.__clocks__ = nil;
24123
24124      
24125      self.$const_set(name, self.__clocks__.$size());
24126      return self.__clocks__['$<<'](func);
24127    });
24128    self.$__register_clock__("CLOCK_REALTIME", function() { return Date.now() });
24129    monotonic = false;
24130    
24131    if (Opal.global.performance) {
24132      monotonic = function() {
24133        return performance.now()
24134      };
24135    }
24136    else if (Opal.global.process && process.hrtime) {
24137      // let now be the base to get smaller numbers
24138      var hrtime_base = process.hrtime();
24139
24140      monotonic = function() {
24141        var hrtime = process.hrtime(hrtime_base);
24142        var us = (hrtime[1] / 1000) | 0; // cut below microsecs;
24143        return ((hrtime[0] * 1000) + (us / 1000));
24144      };
24145    }
24146  ;
24147    if ($truthy(monotonic)) {
24148      self.$__register_clock__("CLOCK_MONOTONIC", monotonic)
24149    };
24150    $defs(self, '$pid', $return_val(0));
24151    $defs(self, '$times', function $$times() {
24152      var t = nil;
24153
24154      
24155      t = $$$('Time').$now().$to_f();
24156      return $$$($$$('Benchmark'), 'Tms').$new(t, t, t, t, t);
24157    });
24158    return $defs(self, '$clock_gettime', function $$clock_gettime(clock_id, unit) {
24159      var self = this, $ret_or_1 = nil, clock = nil;
24160      if (self.__clocks__ == null) self.__clocks__ = nil;
24161
24162      
24163      if (unit == null) unit = "float_second";
24164      if ($truthy(($ret_or_1 = (clock = self.__clocks__['$[]'](clock_id))))) {
24165        $ret_or_1
24166      } else {
24167        $Kernel.$raise($$$($$$('Errno'), 'EINVAL'), "clock_gettime(" + (clock_id) + ") " + (self.__clocks__['$[]'](clock_id)))
24168      };
24169      
24170      var ms = clock();
24171      switch (unit) {
24172        case 'float_second':      return  (ms / 1000);         // number of seconds as a float (default)
24173        case 'float_millisecond': return  (ms / 1);            // number of milliseconds as a float
24174        case 'float_microsecond': return  (ms * 1000);         // number of microseconds as a float
24175        case 'second':            return ((ms / 1000)    | 0); // number of seconds as an integer
24176        case 'millisecond':       return ((ms / 1)       | 0); // number of milliseconds as an integer
24177        case 'microsecond':       return ((ms * 1000)    | 0); // number of microseconds as an integer
24178        case 'nanosecond':        return ((ms * 1000000) | 0); // number of nanoseconds as an integer
24179        default: $Kernel.$raise($$$('ArgumentError'), "unexpected unit: " + (unit))
24180      }
24181    ;
24182    }, -2);
24183  })('::')
24184};
24185
24186Opal.modules["corelib/random/formatter"] = function(Opal) {/* Generated by Opal 1.7.3 */
24187  var $klass = Opal.klass, $module = Opal.module, $def = Opal.def, $range = Opal.range, $send = Opal.send, $rb_divide = Opal.rb_divide, $Kernel = Opal.Kernel, $Opal = Opal.Opal, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$;
24188
24189  Opal.add_stubs('_verify_count,bytes,encode,strict_encode64,random_bytes,urlsafe_encode64,split,hex,[]=,[],map,to_proc,join,times,<<,|,ord,/,abs,random_float,raise,coerce_to!,flatten,new,random_number,length,include,extend');
24190  return (function($base, $super, $parent_nesting) {
24191    var self = $klass($base, $super, 'Random');
24192
24193    var $nesting = [self].concat($parent_nesting);
24194
24195    
24196    (function($base, $parent_nesting) {
24197      var self = $module($base, 'Formatter');
24198
24199      var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
24200
24201      
24202      
24203      $def(self, '$hex', function $$hex(count) {
24204        var self = this;
24205
24206        
24207        if (count == null) count = nil;
24208        count = $$$('Random').$_verify_count(count);
24209        
24210        var bytes = self.$bytes(count);
24211        var out = "";
24212        for (var i = 0; i < count; i++) {
24213          out += bytes.charCodeAt(i).toString(16).padStart(2, '0');
24214        }
24215        return (out).$encode("US-ASCII");
24216      ;
24217      }, -1);
24218      
24219      $def(self, '$random_bytes', function $$random_bytes(count) {
24220        var self = this;
24221
24222        
24223        if (count == null) count = nil;
24224        return self.$bytes(count);
24225      }, -1);
24226      
24227      $def(self, '$base64', function $$base64(count) {
24228        var self = this;
24229
24230        
24231        if (count == null) count = nil;
24232        return $$$('Base64').$strict_encode64(self.$random_bytes(count)).$encode("US-ASCII");
24233      }, -1);
24234      
24235      $def(self, '$urlsafe_base64', function $$urlsafe_base64(count, padding) {
24236        var self = this;
24237
24238        
24239        if (count == null) count = nil;
24240        if (padding == null) padding = false;
24241        return $$$('Base64').$urlsafe_encode64(self.$random_bytes(count), padding).$encode("US-ASCII");
24242      }, -1);
24243      
24244      $def(self, '$uuid', function $$uuid() {
24245        var self = this, str = nil;
24246
24247        
24248        str = self.$hex(16).$split("");
24249        str['$[]='](12, "4");
24250        str['$[]='](16, (parseInt(str['$[]'](16), 16) & 3 | 8).toString(16));
24251        str = [str['$[]']($range(0, 8, true)), str['$[]']($range(8, 12, true)), str['$[]']($range(12, 16, true)), str['$[]']($range(16, 20, true)), str['$[]']($range(20, 32, true))];
24252        str = $send(str, 'map', [], "join".$to_proc());
24253        return str.$join("-");
24254      });
24255      
24256      $def(self, '$random_float', function $$random_float() {
24257        var self = this, bs = nil, num = nil;
24258
24259        
24260        bs = self.$bytes(4);
24261        num = 0;
24262        $send((4), 'times', [], function $$1(i){
24263          
24264          if (i == null) i = nil;
24265          num = num['$<<'](8);
24266          return (num = num['$|'](bs['$[]'](i).$ord()));});
24267        return $rb_divide(num.$abs(), 2147483647);
24268      });
24269      
24270      $def(self, '$random_number', function $$random_number(limit) {
24271        var self = this;
24272
24273        
24274        ;
24275        
24276        function randomFloat() {
24277          return self.$random_float();
24278        }
24279
24280        function randomInt(max) {
24281          return Math.floor(randomFloat() * max);
24282        }
24283
24284        function randomRange() {
24285          var min = limit.begin,
24286              max = limit.end;
24287
24288          if (min === nil || max === nil) {
24289            return nil;
24290          }
24291
24292          var length = max - min;
24293
24294          if (length < 0) {
24295            return nil;
24296          }
24297
24298          if (length === 0) {
24299            return min;
24300          }
24301
24302          if (max % 1 === 0 && min % 1 === 0 && !limit.excl) {
24303            length++;
24304          }
24305
24306          return randomInt(length) + min;
24307        }
24308
24309        if (limit == null) {
24310          return randomFloat();
24311        } else if (limit.$$is_range) {
24312          return randomRange();
24313        } else if (limit.$$is_number) {
24314          if (limit <= 0) {
24315            $Kernel.$raise($$$('ArgumentError'), "invalid argument - " + (limit))
24316          }
24317
24318          if (limit % 1 === 0) {
24319            // integer
24320            return randomInt(limit);
24321          } else {
24322            return randomFloat() * limit;
24323          }
24324        } else {
24325          limit = $Opal['$coerce_to!'](limit, $$$('Integer'), "to_int");
24326
24327          if (limit <= 0) {
24328            $Kernel.$raise($$$('ArgumentError'), "invalid argument - " + (limit))
24329          }
24330
24331          return randomInt(limit);
24332        }
24333      ;
24334      }, -1);
24335      return $def(self, '$alphanumeric', function $$alphanumeric(count) {
24336        var self = this, map = nil;
24337
24338        
24339        if (count == null) count = nil;
24340        count = $$('Random').$_verify_count(count);
24341        map = $send([$range("0", "9", false), $range("a", "z", false), $range("A", "Z", false)], 'map', [], "to_a".$to_proc()).$flatten();
24342        return $send($$$('Array'), 'new', [count], function $$2(i){var self = $$2.$$s == null ? this : $$2.$$s;
24343
24344          
24345          if (i == null) i = nil;
24346          return map['$[]'](self.$random_number(map.$length()));}, {$$s: self}).$join();
24347      }, -1);
24348    })(self, $nesting);
24349    self.$include($$$($$$('Random'), 'Formatter'));
24350    return self.$extend($$$($$$('Random'), 'Formatter'));
24351  })('::', null, $nesting)
24352};
24353
24354Opal.modules["corelib/random/mersenne_twister"] = function(Opal) {/* Generated by Opal 1.7.3 */
24355  var $klass = Opal.klass, $const_set = Opal.const_set, $send = Opal.send, nil = Opal.nil, $$$ = Opal.$$$, mersenne_twister = nil;
24356
24357  Opal.add_stubs('generator=');
24358  
24359  mersenne_twister = (function() {
24360  /* Period parameters */
24361  var N = 624;
24362  var M = 397;
24363  var MATRIX_A = 0x9908b0df;      /* constant vector a */
24364  var UMASK = 0x80000000;         /* most significant w-r bits */
24365  var LMASK = 0x7fffffff;         /* least significant r bits */
24366  var MIXBITS = function(u,v) { return ( ((u) & UMASK) | ((v) & LMASK) ); };
24367  var TWIST = function(u,v) { return (MIXBITS((u),(v)) >>> 1) ^ ((v & 0x1) ? MATRIX_A : 0x0); };
24368
24369  function init(s) {
24370    var mt = {left: 0, next: N, state: new Array(N)};
24371    init_genrand(mt, s);
24372    return mt;
24373  }
24374
24375  /* initializes mt[N] with a seed */
24376  function init_genrand(mt, s) {
24377    var j, i;
24378    mt.state[0] = s >>> 0;
24379    for (j=1; j<N; j++) {
24380      mt.state[j] = (1812433253 * ((mt.state[j-1] ^ (mt.state[j-1] >> 30) >>> 0)) + j);
24381      /* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */
24382      /* In the previous versions, MSBs of the seed affect   */
24383      /* only MSBs of the array state[].                     */
24384      /* 2002/01/09 modified by Makoto Matsumoto             */
24385      mt.state[j] &= 0xffffffff;  /* for >32 bit machines */
24386    }
24387    mt.left = 1;
24388    mt.next = N;
24389  }
24390
24391  /* generate N words at one time */
24392  function next_state(mt) {
24393    var p = 0, _p = mt.state;
24394    var j;
24395
24396    mt.left = N;
24397    mt.next = 0;
24398
24399    for (j=N-M+1; --j; p++)
24400      _p[p] = _p[p+(M)] ^ TWIST(_p[p+(0)], _p[p+(1)]);
24401
24402    for (j=M; --j; p++)
24403      _p[p] = _p[p+(M-N)] ^ TWIST(_p[p+(0)], _p[p+(1)]);
24404
24405    _p[p] = _p[p+(M-N)] ^ TWIST(_p[p+(0)], _p[0]);
24406  }
24407
24408  /* generates a random number on [0,0xffffffff]-interval */
24409  function genrand_int32(mt) {
24410    /* mt must be initialized */
24411    var y;
24412
24413    if (--mt.left <= 0) next_state(mt);
24414    y = mt.state[mt.next++];
24415
24416    /* Tempering */
24417    y ^= (y >>> 11);
24418    y ^= (y << 7) & 0x9d2c5680;
24419    y ^= (y << 15) & 0xefc60000;
24420    y ^= (y >>> 18);
24421
24422    return y >>> 0;
24423  }
24424
24425  function int_pair_to_real_exclusive(a, b) {
24426    a >>>= 5;
24427    b >>>= 6;
24428    return(a*67108864.0+b)*(1.0/9007199254740992.0);
24429  }
24430
24431  // generates a random number on [0,1) with 53-bit resolution
24432  function genrand_real(mt) {
24433    /* mt must be initialized */
24434    var a = genrand_int32(mt), b = genrand_int32(mt);
24435    return int_pair_to_real_exclusive(a, b);
24436  }
24437
24438  return { genrand_real: genrand_real, init: init };
24439})();
24440  return (function($base, $super) {
24441    var self = $klass($base, $super, 'Random');
24442
24443    var $a;
24444
24445    
24446    var MAX_INT = Number.MAX_SAFE_INTEGER || Math.pow(2, 53) - 1;
24447    $const_set(self, 'MERSENNE_TWISTER_GENERATOR', {
24448    new_seed: function() { return Math.round(Math.random() * MAX_INT); },
24449    reseed: function(seed) { return mersenne_twister.init(seed); },
24450    rand: function(mt) { return mersenne_twister.genrand_real(mt); }
24451  });
24452    return ($a = [$$$(self, 'MERSENNE_TWISTER_GENERATOR')], $send(self, 'generator=', $a), $a[$a.length - 1]);
24453  })('::', null);
24454};
24455
24456Opal.modules["corelib/random"] = function(Opal) {/* Generated by Opal 1.7.3 */
24457  var $truthy = Opal.truthy, $klass = Opal.klass, $Kernel = Opal.Kernel, $defs = Opal.defs, $Opal = Opal.Opal, $def = Opal.def, $eqeqeq = Opal.eqeqeq, $send = Opal.send, self = Opal.top, nil = Opal.nil, $$$ = Opal.$$$;
24458
24459  Opal.add_stubs('require,attr_reader,to_int,raise,new_seed,coerce_to!,reseed,rand,seed,bytes,===,==,state,_verify_count,encode,join,new,chr,random_number,random_float,const_defined?,const_set');
24460  
24461  self.$require("corelib/random/formatter");
24462  (function($base, $super) {
24463    var self = $klass($base, $super, 'Random');
24464
24465    
24466    
24467    self.$attr_reader("seed", "state");
24468    $defs(self, '$_verify_count', function $$_verify_count(count) {
24469      
24470      
24471      if (!$truthy(count)) count = 16;
24472      if (typeof count !== "number") count = (count).$to_int();
24473      if (count < 0) $Kernel.$raise($$$('ArgumentError'), "negative string size (or size too big)");
24474      count = Math.floor(count);
24475      return count;
24476    
24477    });
24478    
24479    $def(self, '$initialize', function $$initialize(seed) {
24480      var self = this;
24481
24482      
24483      if (seed == null) seed = $$$('Random').$new_seed();
24484      seed = $Opal['$coerce_to!'](seed, $$$('Integer'), "to_int");
24485      self.state = seed;
24486      return self.$reseed(seed);
24487    }, -1);
24488    
24489    $def(self, '$reseed', function $$reseed(seed) {
24490      var self = this;
24491
24492      
24493      self.seed = seed;
24494      return self.$rng = Opal.$$rand.reseed(seed);;
24495    });
24496    $defs(self, '$new_seed', function $$new_seed() {
24497      
24498      return Opal.$$rand.new_seed();
24499    });
24500    $defs(self, '$rand', function $$rand(limit) {
24501      var self = this;
24502
24503      
24504      ;
24505      return $$$(self, 'DEFAULT').$rand(limit);
24506    }, -1);
24507    $defs(self, '$srand', function $$srand(n) {
24508      var self = this, previous_seed = nil;
24509
24510      
24511      if (n == null) n = $$$('Random').$new_seed();
24512      n = $Opal['$coerce_to!'](n, $$$('Integer'), "to_int");
24513      previous_seed = $$$(self, 'DEFAULT').$seed();
24514      $$$(self, 'DEFAULT').$reseed(n);
24515      return previous_seed;
24516    }, -1);
24517    $defs(self, '$urandom', function $$urandom(size) {
24518      
24519      return $$$('SecureRandom').$bytes(size)
24520    });
24521    
24522    $def(self, '$==', function $Random_$eq_eq$1(other) {
24523      var self = this, $ret_or_1 = nil;
24524
24525      
24526      if (!$eqeqeq($$$('Random'), other)) {
24527        return false
24528      };
24529      if ($truthy(($ret_or_1 = self.$seed()['$=='](other.$seed())))) {
24530        return self.$state()['$=='](other.$state())
24531      } else {
24532        return $ret_or_1
24533      };
24534    });
24535    
24536    $def(self, '$bytes', function $$bytes(length) {
24537      var self = this;
24538
24539      
24540      length = $$$('Random').$_verify_count(length);
24541      return $send($$$('Array'), 'new', [length], function $$2(){var self = $$2.$$s == null ? this : $$2.$$s;
24542
24543        return self.$rand(255).$chr()}, {$$s: self}).$join().$encode("ASCII-8BIT");
24544    });
24545    $defs(self, '$bytes', function $$bytes(length) {
24546      var self = this;
24547
24548      return $$$(self, 'DEFAULT').$bytes(length)
24549    });
24550    
24551    $def(self, '$rand', function $$rand(limit) {
24552      var self = this;
24553
24554      
24555      ;
24556      return self.$random_number(limit);
24557    }, -1);
24558    
24559    $def(self, '$random_float', function $$random_float() {
24560      var self = this;
24561
24562      
24563      self.state++;
24564      return Opal.$$rand.rand(self.$rng);
24565    
24566    });
24567    $defs(self, '$random_float', function $$random_float() {
24568      var self = this;
24569
24570      return $$$(self, 'DEFAULT').$random_float()
24571    });
24572    return $defs(self, '$generator=', function $Random_generator$eq$3(generator) {
24573      var self = this;
24574
24575      
24576      Opal.$$rand = generator;
24577      if ($truthy(self['$const_defined?']("DEFAULT"))) {
24578        return $$$(self, 'DEFAULT').$reseed()
24579      } else {
24580        return self.$const_set("DEFAULT", self.$new(self.$new_seed()))
24581      };
24582    });
24583  })('::', null);
24584  return self.$require("corelib/random/mersenne_twister");
24585};
24586
24587Opal.modules["corelib/unsupported"] = function(Opal) {/* Generated by Opal 1.7.3 */
24588  var $Kernel = Opal.Kernel, $klass = Opal.klass, $send = Opal.send, $slice = Opal.slice, $module = Opal.module, $def = Opal.def, $return_val = Opal.return_val, $alias = Opal.alias, $defs = Opal.defs, self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$;
24589
24590  Opal.add_stubs('raise,warn,each,define_method,%,public,private_method_defined?,private_class_method,instance_method,instance_methods,method_defined?,private_methods');
24591  
24592  
24593  var warnings = {};
24594
24595  function handle_unsupported_feature(message) {
24596    switch (Opal.config.unsupported_features_severity) {
24597    case 'error':
24598      $Kernel.$raise($$$('NotImplementedError'), message)
24599      break;
24600    case 'warning':
24601      warn(message)
24602      break;
24603    default: // ignore
24604      // noop
24605    }
24606  }
24607
24608  function warn(string) {
24609    if (warnings[string]) {
24610      return;
24611    }
24612
24613    warnings[string] = true;
24614    self.$warn(string);
24615  }
24616;
24617  (function($base, $super) {
24618    var self = $klass($base, $super, 'String');
24619
24620    
24621    
24622    var ERROR = "String#%s not supported. Mutable String methods are not supported in Opal.";
24623    return $send(["<<", "capitalize!", "chomp!", "chop!", "downcase!", "gsub!", "lstrip!", "next!", "reverse!", "slice!", "squeeze!", "strip!", "sub!", "succ!", "swapcase!", "tr!", "tr_s!", "upcase!", "prepend", "[]=", "clear", "encode!", "unicode_normalize!"], 'each', [], function $String$1(method_name){var self = $String$1.$$s == null ? this : $String$1.$$s;
24624
24625      
24626      if (method_name == null) method_name = nil;
24627      return $send(self, 'define_method', [method_name], function $$2($a){var $post_args, $fwd_rest;
24628
24629        
24630        $post_args = $slice(arguments);
24631        $fwd_rest = $post_args;
24632        return $Kernel.$raise($$$('NotImplementedError'), (ERROR)['$%'](method_name));}, -1);}, {$$s: self});
24633  })('::', null);
24634  (function($base) {
24635    var self = $module($base, 'Kernel');
24636
24637    
24638    
24639    var ERROR = "Object tainting is not supported by Opal";
24640    
24641    $def(self, '$taint', function $$taint() {
24642      var self = this;
24643
24644      
24645      handle_unsupported_feature(ERROR);
24646      return self;
24647    });
24648    
24649    $def(self, '$untaint', function $$untaint() {
24650      var self = this;
24651
24652      
24653      handle_unsupported_feature(ERROR);
24654      return self;
24655    });
24656    return $def(self, '$tainted?', function $Kernel_tainted$ques$3() {
24657      
24658      
24659      handle_unsupported_feature(ERROR);
24660      return false;
24661    });
24662  })('::');
24663  (function($base, $super) {
24664    var self = $klass($base, $super, 'Module');
24665
24666    
24667    
24668    
24669    $def(self, '$public', function $Module_public$4($a) {
24670      var $post_args, methods, self = this;
24671
24672      
24673      $post_args = $slice(arguments);
24674      methods = $post_args;
24675      
24676      if (methods.length === 0) {
24677        self.$$module_function = false;
24678        return nil;
24679      }
24680      return (methods.length === 1) ? methods[0] : methods;
24681    ;
24682    }, -1);
24683    
24684    $def(self, '$private_class_method', function $$private_class_method($a) {
24685      var $post_args, methods;
24686
24687      
24688      $post_args = $slice(arguments);
24689      methods = $post_args;
24690      return (methods.length === 1) ? methods[0] : methods;;
24691    }, -1);
24692    
24693    $def(self, '$private_method_defined?', $return_val(false));
24694    
24695    $def(self, '$private_constant', function $$private_constant($a) {
24696      var $post_args, $fwd_rest;
24697
24698      
24699      $post_args = $slice(arguments);
24700      $fwd_rest = $post_args;
24701      return nil;
24702    }, -1);
24703    $alias(self, "nesting", "public");
24704    $alias(self, "private", "public");
24705    $alias(self, "protected", "public");
24706    $alias(self, "protected_method_defined?", "private_method_defined?");
24707    $alias(self, "public_class_method", "private_class_method");
24708    $alias(self, "public_instance_method", "instance_method");
24709    $alias(self, "public_instance_methods", "instance_methods");
24710    return $alias(self, "public_method_defined?", "method_defined?");
24711  })('::', null);
24712  (function($base) {
24713    var self = $module($base, 'Kernel');
24714
24715    
24716    
24717    
24718    $def(self, '$private_methods', function $$private_methods($a) {
24719      var $post_args, methods;
24720
24721      
24722      $post_args = $slice(arguments);
24723      methods = $post_args;
24724      return [];
24725    }, -1);
24726    $alias(self, "protected_methods", "private_methods");
24727    $alias(self, "private_instance_methods", "private_methods");
24728    return $alias(self, "protected_instance_methods", "private_methods");
24729  })('::');
24730  (function($base, $parent_nesting) {
24731    var self = $module($base, 'Kernel');
24732
24733    var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
24734
24735    return $def(self, '$eval', function $Kernel_eval$5($a) {
24736      var $post_args, $fwd_rest;
24737
24738      
24739      $post_args = $slice(arguments);
24740      $fwd_rest = $post_args;
24741      return $Kernel.$raise($$$('NotImplementedError'), "To use Kernel#eval, you must first require 'opal-parser'. " + ("See https://github.com/opal/opal/blob/" + ($$('RUBY_ENGINE_VERSION')) + "/docs/opal_parser.md for details."));
24742    }, -1)
24743  })('::', $nesting);
24744  $defs(self, '$public', function $public$6($a) {
24745    var $post_args, methods;
24746
24747    
24748    $post_args = $slice(arguments);
24749    methods = $post_args;
24750    return (methods.length === 1) ? methods[0] : methods;;
24751  }, -1);
24752  return $defs(self, '$private', function $private$7($a) {
24753    var $post_args, methods;
24754
24755    
24756    $post_args = $slice(arguments);
24757    methods = $post_args;
24758    return (methods.length === 1) ? methods[0] : methods;;
24759  }, -1);
24760};
24761
24762Opal.queue(function(Opal) {/* Generated by Opal 1.7.3 */
24763  var $Object = Opal.Object, nil = Opal.nil;
24764
24765  Opal.add_stubs('require,autoload');
24766  
24767  $Object.$require("opal/base");
24768  $Object.$require("opal/mini");
24769  $Object.$require("corelib/kernel/format");
24770  $Object.$require("corelib/string/encoding");
24771  $Object.$autoload("Math", "corelib/math");
24772  $Object.$require("corelib/complex/base");
24773  $Object.$autoload("Complex", "corelib/complex");
24774  $Object.$require("corelib/rational/base");
24775  $Object.$autoload("Rational", "corelib/rational");
24776  $Object.$require("corelib/time");
24777  $Object.$autoload("Struct", "corelib/struct");
24778  $Object.$autoload("Set", "corelib/set");
24779  $Object.$autoload("Dir", "corelib/dir");
24780  $Object.$autoload("File", "corelib/file");
24781  $Object.$require("corelib/process/base");
24782  $Object.$autoload("Process", "corelib/process");
24783  $Object.$autoload("Random", "corelib/random");
24784  return $Object.$require("corelib/unsupported");
24785});
24786
24787
24788
24789
24790
24791export default function Asciidoctor(moduleConfig) {
24792Opal.modules["asciidoctor/js/opal_ext/browser/file"] = function(Opal) {/* Generated by Opal 1.7.3 */
24793  var $klass = Opal.klass, $defs = Opal.defs, $nesting = [], nil = Opal.nil;
24794
24795  Opal.add_stubs('new');
24796  return (function($base, $super, $parent_nesting) {
24797    var self = $klass($base, $super, 'File');
24798
24799    var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
24800
24801    return $defs(self, '$read', function $$read(path) {
24802      
24803      
24804      var data = '';
24805      var status = -1;
24806      try {
24807        var xhr = new XMLHttpRequest();
24808        xhr.open('GET', path, false);
24809        xhr.addEventListener('load', function() {
24810          status = this.status;
24811          // status is 0 for local file mode (i.e., file://)
24812          if (status === 0 || status === 200) {
24813            data = this.responseText;
24814          }
24815        });
24816        xhr.overrideMimeType('text/plain');
24817        xhr.send();
24818      }
24819      catch (e) {
24820        throw $$('IOError').$new('Error reading file or directory: ' + path + '; reason: ' + e.message);
24821      }
24822      // assume that no data in local file mode means it doesn't exist
24823      if (status === 404 || (status === 0 && !data)) {
24824        throw $$('IOError').$new('No such file or directory: ' + path);
24825      }
24826      return data;
24827    
24828    })
24829  })($nesting[0], null, $nesting)
24830};
24831
24832Opal.modules["asciidoctor/js/opal_ext/browser"] = function(Opal) {/* Generated by Opal 1.7.3 */
24833  var $const_set = Opal.const_set, self = Opal.top, $nesting = [], nil = Opal.nil;
24834
24835  Opal.add_stubs('require');
24836  
24837  
24838  var platform, engine, framework, ioModule;
24839
24840  if (typeof moduleConfig === 'object' && typeof moduleConfig.runtime === 'object') {
24841    var runtime = moduleConfig.runtime;
24842    platform = runtime.platform;
24843    engine = runtime.engine;
24844    framework = runtime.framework;
24845    ioModule = runtime.ioModule;
24846  }
24847  ioModule = ioModule || 'xmlhttprequest';
24848  platform = platform || 'browser';
24849  engine = engine || '';
24850  framework = framework || '';
24851;
24852  $const_set($nesting[0], 'JAVASCRIPT_IO_MODULE', ioModule);
24853  $const_set($nesting[0], 'JAVASCRIPT_PLATFORM', platform);
24854  $const_set($nesting[0], 'JAVASCRIPT_ENGINE', engine);
24855  $const_set($nesting[0], 'JAVASCRIPT_FRAMEWORK', framework);
24856  return self.$require("asciidoctor/js/opal_ext/browser/file");
24857};
24858
24859Opal.modules["asciidoctor/js/asciidoctor_ext/browser/abstract_node"] = function(Opal) {/* Generated by Opal 1.7.3 */
24860  var $module = Opal.module, $klass = Opal.klass, $hash2 = Opal.hash2, $truthy = Opal.truthy, $def = Opal.def, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$;
24861
24862  Opal.add_stubs('web_path,path_resolver,uriish?,[],attr?,start_with?,descends_from?,base_dir,join,prepare_source_string,read,fetch,warn,logger,normalize_system_path,read_asset');
24863  return (function($base, $parent_nesting) {
24864    var self = $module($base, 'Asciidoctor');
24865
24866    var $nesting = [self].concat($parent_nesting);
24867
24868    return (function($base, $super, $parent_nesting) {
24869      var self = $klass($base, $super, 'AbstractNode');
24870
24871      var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype;
24872
24873      $proto.document = nil;
24874      
24875      
24876      $def(self, '$read_contents', function $$read_contents(target, opts) {
24877        var self = this, doc = nil, start = nil, $ret_or_1 = nil;
24878
24879        
24880        if (opts == null) opts = $hash2([], {});
24881        doc = self.document;
24882        if (($truthy($$('Helpers')['$uriish?'](target)) || ((($truthy((start = opts['$[]']("start"))) && ($truthy($$('Helpers')['$uriish?'](start)))) && ($truthy((target = doc.$path_resolver().$web_path(target, start)))))))) {
24883          if ((($truthy(doc.$path_resolver()['$descends_from?'](target, doc.$base_dir())) || ($truthy(target['$start_with?']("chrome://")))) || ($truthy(doc['$attr?']("allow-uri-read"))))) {
24884            
24885            try {
24886              if ($truthy(opts['$[]']("normalize"))) {
24887                return $$('Helpers').$prepare_source_string($$$('File').$read(target)).$join($$('LF'))
24888              } else {
24889                return $$$('File').$read(target)
24890              }
24891            } catch ($err) {
24892              if (Opal.rescue($err, [$$('StandardError')])) {
24893                try {
24894                  
24895                  if ($truthy(opts.$fetch("warn_on_failure", true))) {
24896                    self.$logger().$warn("could not retrieve contents of " + (($truthy(($ret_or_1 = opts['$[]']("label"))) ? ($ret_or_1) : ("asset"))) + " at URI: " + (target))
24897                  };
24898                  return nil;
24899                } finally { Opal.pop_exception(); }
24900              } else { throw $err; }
24901            };
24902          } else {
24903            
24904            if ($truthy(opts.$fetch("warn_on_failure", true))) {
24905              self.$logger().$warn("cannot retrieve contents of " + (($truthy(($ret_or_1 = opts['$[]']("label"))) ? ($ret_or_1) : ("asset"))) + " at URI: " + (target) + " (allow-uri-read attribute not enabled)")
24906            };
24907            return nil;
24908          }
24909        } else {
24910          
24911          target = self.$normalize_system_path(target, opts['$[]']("start"), nil, $hash2(["target_name"], {"target_name": ($truthy(($ret_or_1 = opts['$[]']("label"))) ? ($ret_or_1) : ("asset"))}));
24912          return self.$read_asset(target, $hash2(["normalize", "warn_on_failure", "label"], {"normalize": opts['$[]']("normalize"), "warn_on_failure": opts.$fetch("warn_on_failure", true), "label": opts['$[]']("label")}));
24913        };
24914      }, -2);
24915      return $def(self, '$generate_data_uri_from_uri', function $$generate_data_uri_from_uri(image_uri, cache_uri) {
24916        var self = this;
24917
24918        
24919        if (cache_uri == null) cache_uri = false;
24920        
24921      var contentType = ''
24922      var b64encoded = ''
24923      var status = -1
24924
24925      try {
24926        var xhr = new XMLHttpRequest()
24927        xhr.open('GET', image_uri, false)
24928        // the response type cannot be changed for synchronous requests made from a document
24929        // xhr.responseType = 'arraybuffer'
24930        xhr.overrideMimeType('text/plain;
24930 charset=x-user-defined')
24931        xhr.addEventListener('load', function() {
24932          status = this.status
24933          // status is 0 for local file mode (i.e., file://)
24934          if (status === 0 || status === 200) {
24935            var binary = ''
24936            var rawText = this.responseText
24937            for (var i = 0, len = rawText.length; i < len; ++i) {
24938              var c = rawText.charCodeAt(i)
24939              var byteCode = c & 0xff // byte at offset i
24940              binary += String.fromCharCode(byteCode)
24941            }
24942            b64encoded = btoa(binary)
24943            contentType = this.getResponseHeader('content-type')
24944          }
24945        })
24946        xhr.send(null)
24947        // try to detect the MIME Type from the file extension
24948        if (!contentType) {
24949          if (image_uri.endsWith('.jpeg') || image_uri.endsWith('.jpg') || image_uri.endsWith('.jpe')) {
24950            contentType = 'image/jpg'
24951          } else if (image_uri.endsWith('.png')) {
24952            contentType = 'image/png'
24953          } else if (image_uri.endsWith('.svg')) {
24954            contentType = 'image/svg+xml'
24955          } else if (image_uri.endsWith('.bmp')) {
24956            contentType = 'image/bmp'
24957          } else if (image_uri.endsWith('.tif') || image_uri.endsWith('.tiff')) {
24958            contentType = 'image/tiff'
24959          }
24960        }
24961      }
24962      catch (e) {
24963        // something bad happened!
24964        status = 0
24965      }
24966
24967      // assume that no data in local file mode means it doesn't exist
24968      if (status === 404 || (status === 0 && (!b64encoded || !contentType))) {
24969        self.$logger().$warn('could not retrieve image data from URI: ' + image_uri)
24970        return image_uri
24971      }
24972      return 'data:' + contentType + ';base64,' + b64encoded
24973    ;
24974      }, -2);
24975    })($nesting[0], null, $nesting)
24976  })($nesting[0], $nesting)
24977};
24978
24979Opal.modules["asciidoctor/js/asciidoctor_ext/browser/open_uri"] = function(Opal) {/* Generated by Opal 1.7.3 */
24980  var $module = Opal.module, $slice = Opal.slice, $send = Opal.send, $to_a = Opal.to_a, $defs = Opal.defs, $nesting = [], nil = Opal.nil;
24981
24982  Opal.add_stubs('new,path');
24983  return (function($base, $parent_nesting) {
24984    var self = $module($base, 'OpenURI');
24985
24986    var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
24987
24988    return $defs($$('OpenURI'), '$open_uri', function $$open_uri(name, $a) {
24989      var $post_args, rest, $yield = $$open_uri.$$p || nil, self = this, file = nil;
24990
24991      $$open_uri.$$p = null;
24992      
24993      $post_args = $slice(arguments, 1);
24994      rest = $post_args;
24995      file = $send($$('File'), 'new', [self.$path()].concat($to_a(rest)));
24996      if (($yield !== nil)) {
24997        return Opal.yield1($yield, file);
24998      } else {
24999        return file
25000      };
25001    }, -2)
25002  })($nesting[0], $nesting)
25003};
25004
25005Opal.modules["asciidoctor/js/asciidoctor_ext/browser/path_resolver"] = function(Opal) {/* Generated by Opal 1.7.3 */
25006  var $module = Opal.module, $klass = Opal.klass, $truthy = Opal.truthy, $def = Opal.def, $nesting = [], nil = Opal.nil;
25007
25008  Opal.add_stubs('absolute_path?,start_with?');
25009  return (function($base, $parent_nesting) {
25010    var self = $module($base, 'Asciidoctor');
25011
25012    var $nesting = [self].concat($parent_nesting);
25013
25014    return (function($base, $super) {
25015      var self = $klass($base, $super, 'PathResolver');
25016
25017      
25018      return $def(self, '$root?', function $PathResolver_root$ques$1(path) {
25019        var self = this, $ret_or_1 = nil;
25020
25021        if ($truthy(($ret_or_1 = self['$absolute_path?'](path)))) {
25022          return $ret_or_1
25023        } else {
25024          
25025          return path['$start_with?']("file://", "http://", "https://", "chrome://");
25026        }
25027      })
25028    })($nesting[0], null)
25029  })($nesting[0], $nesting)
25030};
25031
25032Opal.modules["asciidoctor/js/asciidoctor_ext/browser/reader"] = function(Opal) {/* Generated by Opal 1.7.3 */
25033  var $module = Opal.module, $klass = Opal.klass, $truthy = Opal.truthy, $eqeq = Opal.eqeq, $not = Opal.not, $def = Opal.def, $nesting = [], nil = Opal.nil;
25034
25035  Opal.add_stubs('posixify,new,base_dir,start_with?,uriish?,key?,attributes,descends_from?,replace_next_line,absolute_path?,==,empty?,!,slice,length');
25036  return (function($base, $parent_nesting) {
25037    var self = $module($base, 'Asciidoctor');
25038
25039    var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
25040
25041    return (function($base, $super, $parent_nesting) {
25042      var self = $klass($base, $super, 'PreprocessorReader');
25043
25044      var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype;
25045
25046      $proto.path_resolver = $proto.document = $proto.include_stack = $proto.dir = nil;
25047      return $def(self, '$resolve_include_path', function $$resolve_include_path(target, attrlist, attributes) {
25048        var $a, self = this, p_target = nil, $ret_or_1 = nil, target_type = nil, base_dir = nil, inc_path = nil, relpath = nil, ctx_dir = nil, top_level = nil, offset = nil;
25049
25050        
25051        p_target = (self.path_resolver = ($truthy(($ret_or_1 = self.path_resolver)) ? ($ret_or_1) : ($$('PathResolver').$new("\\")))).$posixify(target);
25052        $a = ["file", self.document.$base_dir()], (target_type = $a[0]), (base_dir = $a[1]), $a;
25053        if ($truthy(p_target['$start_with?']("file://"))) {
25054          inc_path = (relpath = p_target)
25055        } else if ($truthy($$('Helpers')['$uriish?'](p_target))) {
25056          
25057          if (!($truthy(self.path_resolver['$descends_from?'](p_target, base_dir)) || ($truthy(self.document.$attributes()['$key?']("allow-uri-read"))))) {
25058            return self.$replace_next_line("link:" + (target) + "[" + (attrlist) + "]")
25059          };
25060          inc_path = (relpath = p_target);
25061        } else if ($truthy(self.path_resolver['$absolute_path?'](p_target))) {
25062          inc_path = (relpath = "file://" + (($truthy(p_target['$start_with?']("/")) ? ("") : ("/"))) + (p_target))
25063        } else if ($eqeq((ctx_dir = ($truthy((top_level = self.include_stack['$empty?']())) ? (base_dir) : (self.dir))), ".")) {
25064          inc_path = (relpath = p_target)
25065        } else if (($truthy(ctx_dir['$start_with?']("file://")) || ($not($$('Helpers')['$uriish?'](ctx_dir))))) {
25066          
25067          inc_path = "" + (ctx_dir) + "/" + (p_target);
25068          if ($truthy(top_level)) {
25069            relpath = p_target
25070          } else if (($eqeq(base_dir, ".") || ($not((offset = self.path_resolver['$descends_from?'](inc_path, base_dir)))))) {
25071            relpath = inc_path
25072          } else {
25073            relpath = inc_path.$slice(offset, inc_path.$length())
25074          };
25075        } else if ($truthy(top_level)) {
25076          inc_path = "" + (ctx_dir) + "/" + ((relpath = p_target))
25077        } else if (($truthy((offset = self.path_resolver['$descends_from?'](ctx_dir, base_dir))) || ($truthy(self.document.$attributes()['$key?']("allow-uri-read"))))) {
25078          
25079          inc_path = "" + (ctx_dir) + "/" + (p_target);
25080          relpath = ($truthy(offset) ? (inc_path.$slice(offset, inc_path.$length())) : (p_target));
25081        } else {
25082          return self.$replace_next_line("link:" + (target) + "[" + (attrlist) + "]")
25083        };
25084        return [inc_path, "file", relpath];
25085      })
25086    })($nesting[0], $$('Reader'), $nesting)
25087  })($nesting[0], $nesting)
25088};
25089
25090Opal.modules["asciidoctor/js/asciidoctor_ext/browser"] = function(Opal) {/* Generated by Opal 1.7.3 */
25091  var $eqeq = Opal.eqeq, self = Opal.top, $nesting = [], $$ = Opal.$r($nesting), nil = Opal.nil;
25092
25093  Opal.add_stubs('==,require');
25094  if ($eqeq($$('JAVASCRIPT_IO_MODULE'), "xmlhttprequest")) {
25095    
25096    self.$require("asciidoctor/js/asciidoctor_ext/browser/abstract_node");
25097    self.$require("asciidoctor/js/asciidoctor_ext/browser/open_uri");
25098    self.$require("asciidoctor/js/asciidoctor_ext/browser/path_resolver");
25099    return self.$require("asciidoctor/js/asciidoctor_ext/browser/reader");
25100  } else {
25101    return nil
25102  }
25103};
25104
25105Opal.modules["set"] = Opal.return_val(Opal.nil); /* Generated by Opal 1.7.3 */
25106
25107Opal.modules["asciidoctor/js/opal_ext/kernel"] = function(Opal) {/* Generated by Opal 1.7.3 */
25108  "use strict";
25109  var $module = Opal.module, $slice = Opal.slice, $send = Opal.send, $to_a = Opal.to_a, $def = Opal.def, $return_val = Opal.return_val, $nesting = [], nil = Opal.nil;
25110
25111  Opal.add_stubs('new');
25112  return (function($base, $parent_nesting) {
25113    var self = $module($base, 'Kernel');
25114
25115    var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
25116
25117    
25118    
25119    $def(self, '$open', function $$open(path, $a) {
25120      var $post_args, rest, $yield = $$open.$$p || nil, file = nil;
25121
25122      $$open.$$p = null;
25123      
25124      $post_args = $slice(arguments, 1);
25125      rest = $post_args;
25126      file = $send($$('File'), 'new', [path].concat($to_a(rest)));
25127      if (($yield !== nil)) {
25128        return Opal.yield1($yield, file);
25129      } else {
25130        return file
25131      };
25132    }, -2);
25133    return $def(self, '$__dir__', $return_val(""));
25134  })($nesting[0], $nesting)
25135};
25136
25137Opal.modules["asciidoctor/js/opal_ext/file"] = function(Opal) {/* Generated by Opal 1.7.3 */
25138  "use strict";
25139  var $klass = Opal.klass, $def = Opal.def, $truthy = Opal.truthy, $gvars = Opal.gvars, $return_val = Opal.return_val, $defs = Opal.defs, $nesting = [], nil = Opal.nil;
25140
25141  Opal.add_stubs('attr_reader,delete,gsub,read,size,to_enum,chomp,each_line,readlines,split');
25142  
25143  (function($base, $super, $parent_nesting) {
25144    var self = $klass($base, $super, 'File');
25145
25146    var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype;
25147
25148    $proto.eof = $proto.path = nil;
25149    
25150    self.$attr_reader("eof");
25151    self.$attr_reader("lineno");
25152    self.$attr_reader("path");
25153    
25154    $def(self, '$initialize', function $$initialize(path, flags) {
25155      var self = this, encoding_flag_regexp = nil;
25156
25157      
25158      if (flags == null) flags = "r";
25159      self.path = path;
25160      self.contents = nil;
25161      self.eof = false;
25162      self.lineno = 0;
25163      flags = flags.$delete("b");
25164      encoding_flag_regexp = /:(.*)/;
25165      flags = flags.$gsub(encoding_flag_regexp, "");
25166      return (self.flags = flags);
25167    }, -2);
25168    
25169    $def(self, '$read', function $$read() {
25170      var self = this, res = nil;
25171
25172      if ($truthy(self.eof)) {
25173        return ""
25174      } else {
25175        
25176        res = $$('File').$read(self.path);
25177        self.eof = true;
25178        self.lineno = res.$size();
25179        return res;
25180      }
25181    });
25182    
25183    $def(self, '$each_line', function $$each_line(separator) {
25184      var block = $$each_line.$$p || nil, self = this, lines = nil;
25185      if ($gvars["/"] == null) $gvars["/"] = nil;
25186
25187      $$each_line.$$p = null;
25188      
25189      ;
25190      if (separator == null) separator = $gvars["/"];
25191      if ($truthy(self.eof)) {
25192        return ((block !== nil) ? (self) : ([].$to_enum()))
25193      };
25194      if ((block !== nil)) {
25195        
25196        lines = $$('File').$read(self.path);
25197        
25198        self.eof = false;
25199        self.lineno = 0;
25200        var chomped  = lines.$chomp(),
25201            trailing = lines.length != chomped.length,
25202            splitted = chomped.split(separator);
25203        for (var i = 0, length = splitted.length; i < length; i++) {
25204          self.lineno += 1;
25205          if (i < length - 1 || trailing) {
25206            Opal.yield1(block, splitted[i] + separator);
25207          }
25208          else {
25209            Opal.yield1(block, splitted[i]);
25210          }
25211        }
25212        self.eof = true;
25213      ;
25214        return self;
25215      } else {
25216        return self.$read().$each_line()
25217      };
25218    }, -1);
25219    
25220    $def(self, '$readlines', function $$readlines() {
25221      var self = this;
25222
25223      return $$('File').$readlines(self.path)
25224    });
25225    return (function(self, $parent_nesting) {
25226      var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
25227
25228      
25229      
25230      $def(self, '$readlines', function $$readlines(path, separator) {
25231        var content = nil;
25232        if ($gvars["/"] == null) $gvars["/"] = nil;
25233
25234        
25235        if (separator == null) separator = $gvars["/"];
25236        content = $$('File').$read(path);
25237        return content.$split(separator);
25238      }, -2);
25239      
25240      $def(self, '$file?', $return_val(true));
25241      
25242      $def(self, '$readable?', $return_val(true));
25243      return $def(self, '$read', $return_val(""));
25244    })(Opal.get_singleton_class(self), $nesting);
25245  })($nesting[0], null, $nesting);
25246  return (function($base, $super, $parent_nesting) {
25247    var self = $klass($base, $super, 'IO');
25248
25249    var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
25250
25251    return $defs(self, '$read', function $$read(path) {
25252      
25253      return $$('File').$read(path)
25254    })
25255  })($nesting[0], null, $nesting);
25256};
25257
25258Opal.modules["asciidoctor/js/opal_ext/match_data"] = function(Opal) {/* Generated by Opal 1.7.3 */
25259  "use strict";
25260  var $klass = Opal.klass, $send = Opal.send, $def = Opal.def, $nesting = [], nil = Opal.nil;
25261
25262  Opal.add_stubs('[]=');
25263  return (function($base, $super) {
25264    var self = $klass($base, $super, 'MatchData');
25265
25266    var $proto = self.$$prototype;
25267
25268    $proto.matches = nil;
25269    return $def(self, '$[]=', function $MatchData_$$$eq$1(idx, val) {
25270      var $a, self = this;
25271
25272      return ($a = [idx, val], $send(self.matches, '[]=', $a), $a[$a.length - 1])
25273    })
25274  })($nesting[0], null)
25275};
25276
25277Opal.modules["asciidoctor/js/opal_ext/string"] = function(Opal) {/* Generated by Opal 1.7.3 */
25278  "use strict";
25279  var $klass = Opal.klass, $truthy = Opal.truthy, $rb_lt = Opal.rb_lt, $def = Opal.def, $alias = Opal.alias, $rb_ge = Opal.rb_ge, $eqeq = Opal.eqeq, $rb_minus = Opal.rb_minus, $nesting = [], nil = Opal.nil;
25280
25281  Opal.add_stubs('method_defined?,<,length,bytes,to_s,byteslice,limit_bytesize,>=,==,-,_original_byteslice,unpack,_original_unpack');
25282  return (function($base, $super) {
25283    var self = $klass($base, $super, 'String');
25284
25285    
25286    
25287    if (!$truthy(self['$method_defined?']("limit_bytesize"))) {
25288      
25289      $def(self, '$limit_bytesize', function $$limit_bytesize(size) {
25290        var self = this, result = nil;
25291
25292        
25293        if (!$truthy($rb_lt(size, self.$bytes().$length()))) {
25294          return self.$to_s()
25295        };
25296        result = self.$byteslice(0, size);
25297        return result.$to_s();
25298      })
25299    };
25300    if (!$truthy(self['$method_defined?']("limit"))) {
25301      $alias(self, "limit", "limit_bytesize")
25302    };
25303    $alias(self, "_original_byteslice", "byteslice");
25304    
25305    $def(self, '$byteslice', function $$byteslice(index, length) {
25306      var self = this;
25307
25308      
25309      if (length == null) length = 1;
25310      if ((($eqeq(index, 3) && ($truthy($rb_ge(length, index)))) && ($truthy(self.charCodeAt() === 65279)))
25310) {
25311        return (self.substr(1)).$byteslice(0, $rb_minus(length, 3))
25312      } else {
25313        return self.$_original_byteslice(index, length)
25314      };
25315    }, -2);
25316    $alias(self, "_original_unpack", "unpack");
25317    return $def(self, '$unpack', function $$unpack(format) {
25318      var self = this;
25319
25320      if ($eqeq(format, "C3")) {
25321        if ($truthy(self.charCodeAt() === 65279)) {
25322          return [239, 187, 191]
25323        } else {
25324          
25325          var bytes = []
25326          for (var i=0; i < 3; i++) {
25327            if (i < self.length) {
25328              bytes.push(self.charCodeAt(i))
25329            } else {
25330              bytes.push(nil)
25331            }
25332          }
25333          return bytes
25334        
25335        }
25336      } else {
25337        return self.$_original_unpack(format)
25338      }
25339    });
25340  })($nesting[0], null)
25341};
25342
25343Opal.modules["asciidoctor/js/opal_ext/uri"] = function(Opal) {/* Generated by Opal 1.7.3 */
25344  "use strict";
25345  var $module = Opal.module, $defs = Opal.defs, $return_self = Opal.return_self, $def = Opal.def, $nesting = [], nil = Opal.nil;
25346
25347  Opal.add_stubs('extend');
25348  return (function($base, $parent_nesting) {
25349    var self = $module($base, 'URI');
25350
25351    var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
25352
25353    
25354    $defs(self, '$parse', function $$parse(str) {
25355      
25356      return str.$extend($$('URI'))
25357    });
25358    return $def(self, '$path', $return_self);
25359  })($nesting[0], $nesting)
25360};
25361
25362Opal.modules["asciidoctor/js/opal_ext/base64"] = function(Opal) {/* Generated by Opal 1.7.3 */
25363  "use strict";
25364  var $module = Opal.module, $defs = Opal.defs, $ensure_kwargs = Opal.ensure_kwargs, $truthy = Opal.truthy, $nesting = [], nil = Opal.nil;
25365
25366  Opal.add_stubs('delete');
25367  return (function($base) {
25368    var self = $module($base, 'Base64');
25369
25370    
25371    
25372    
25373    var encode, decode;
25374    encode = Opal.global.btoa || function (input) {
25375      var buffer;
25376      if (input instanceof Buffer) {
25377        buffer = input;
25378      } else {
25379        buffer = Buffer.from(input.toString(), 'binary');
25380      }
25381      return buffer.toString('base64');
25382    };
25383    decode = Opal.global.atob || function (input) {
25384      return Buffer.from(input, 'base64').toString('binary');
25385    };
25386  ;
25387    $defs(self, '$decode64', function $$decode64(string) {
25388      
25389      return decode(string.replace(/\r?\n/g, ''));
25390    });
25391    $defs(self, '$encode64', function $$encode64(string) {
25392      
25393      return encode(string).replace(/(.{60})/g, "$1\n").replace(/([^\n])$/g, "$1\n");
25394    });
25395    $defs(self, '$strict_decode64', function $$strict_decode64(string) {
25396      
25397      return decode(string);
25398    });
25399    $defs(self, '$strict_encode64', function $$strict_encode64(string) {
25400      
25401      return encode(string);
25402    });
25403    $defs(self, '$urlsafe_decode64', function $$urlsafe_decode64(string) {
25404      
25405      return decode(string.replace(/\-/g, '+').replace(/_/g, '/'));
25406    });
25407    return $defs(self, '$urlsafe_encode64', function $$urlsafe_encode64(string, $kwargs) {
25408      var padding, str = nil;
25409
25410      
25411      $kwargs = $ensure_kwargs($kwargs);
25412      
25413      padding = $kwargs.$$smap["padding"];if (padding == null) padding = true;
25414      str = encode(string).replace(/\+/g, '-').replace(/\//g, '_');
25415      if (!$truthy(padding)) {
25416        str = str.$delete("=")
25417      };
25418      return str;
25419    }, -2);
25420  })($nesting[0])
25421};
25422
25423Opal.modules["asciidoctor/js/opal_ext/number"] = function(Opal) {/* Generated by Opal 1.7.3 */
25424  "use strict";
25425  var $klass = Opal.klass, $truthy = Opal.truthy, $rb_gt = Opal.rb_gt, $def = Opal.def, $nesting = [], $$ = Opal.$r($nesting), nil = Opal.nil;
25426
25427  Opal.add_stubs('coerce_to!,>');
25428  return (function($base, $super, $parent_nesting) {
25429    var self = $klass($base, $super, 'Number');
25430
25431    var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
25432
25433    return $def(self, '$round', function $$round(ndigits) {
25434      var self = this;
25435
25436      
25437      ;
25438      ndigits = $$('Opal')['$coerce_to!'](ndigits, $$('Integer'), "to_int");
25439      if ($truthy($rb_gt(ndigits, 0))) {
25440        return Number(self.toFixed(ndigits));
25441      } else {
25442        return Math.round(self);
25443      };
25444    }, -1)
25445  })($nesting[0], $$('Numeric'), $nesting)
25446};
25447
25448Opal.modules["asciidoctor/js/opal_ext"] = function(Opal) {/* Generated by Opal 1.7.3 */
25449  "use strict";
25450  var self = Opal.top, nil = Opal.nil;
25451
25452  Opal.add_stubs('require');
25453  
25454  self.$require("asciidoctor/js/opal_ext/kernel");
25455  self.$require("asciidoctor/js/opal_ext/file");
25456  self.$require("asciidoctor/js/opal_ext/match_data");
25457  self.$require("asciidoctor/js/opal_ext/string");
25458  self.$require("asciidoctor/js/opal_ext/uri");
25459  self.$require("asciidoctor/js/opal_ext/base64");
25460  self.$require("asciidoctor/js/opal_ext/number");
25461  
25462// suppress "not supported" warning messages from Opal
25463Opal.config.unsupported_features_severity = 'ignore'
25464
25465// Load specific runtime
25466self.$require("asciidoctor/js/opal_ext/browser");
25467;
25468};
25469
25470Opal.modules["asciidoctor/js/rx"] = function(Opal) {/* Generated by Opal 1.7.3 */
25471  "use strict";
25472  var $module = Opal.module, $const_set = Opal.const_set, $send = Opal.send, $gvars = Opal.gvars, $truthy = Opal.truthy, $def
25472s = Opal.defs, $rb_plus = Opal.rb_plus, $nesting = [], nil = Opal.nil;
25473
25474  Opal.add_stubs('gsub,+,unpack_hex_range');
25475  return (function($base, $parent_nesting) {
25476    var self = $module($base, 'Asciidoctor');
25477
25478    var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
25479
25480    
25481    $const_set($nesting[0], 'HEX_RANGE_RX', /([A-F0-9]{4})(?:-([A-F0-9]{4}))?/);
25482    $defs(self, '$unpack_hex_range', function $$unpack_hex_range(str) {
25483      
25484      return $send(str, 'gsub', [$$('HEX_RANGE_RX')], function $$1(){var $a, $ret_or_1 = nil;
25485
25486        return "\\u" + ((($a = $gvars['~']) === nil ? nil : $a['$[]'](1))) + (($truthy(($ret_or_1 = (($a = $gvars['~']) === nil ? nil : $a['$[]'](2)))) ? ("-\\u" + ((($a = $gvars['~']) === nil ? nil : $a['$[]'](2)))) : ($ret_or_1)))})
25487    });
25488    $const_set($nesting[0], 'P_L', $rb_plus("A-Za-z", self.$unpack_hex_range("00AA00B500BA00C0-00D600D8-00F600F8-02C102C6-02D102E0-02E402EC02EE0370-037403760377037A-037D037F03860388-038A038C038E-03A103A3-03F503F7-0481048A-052F0531-055605590561-058705D0-05EA05F0-05F20620-064A066E066F0671-06D306D506E506E606EE06EF06FA-06FC06FF07100712-072F074D-07A507B107CA-07EA07F407F507FA0800-0815081A082408280840-085808A0-08B20904-0939093D09500958-09610971-09800985-098C098F09900993-09A809AA-09B009B209B6-09B909BD09CE09DC09DD09DF-09E109F009F10A05-0A0A0A0F0A100A13-0A280A2A-0A300A320A330A350A360A380A390A59-0A5C0A5E0A72-0A740A85-0A8D0A8F-0A910A93-0AA80AAA-0AB00AB20AB30AB5-0AB90ABD0AD00AE00AE10B05-0B0C0B0F0B100B13-0B280B2A-0B300B320B330B35-0B390B3D0B5C0B5D0B5F-0B610B710B830B85-0B8A0B8E-0B900B92-0B950B990B9A0B9C0B9E0B9F0BA30BA40BA8-0BAA0BAE-0BB90BD00C05-0C0C0C0E-0C100C12-0C280C2A-0C390C3D0C580C590C600C610C85-0C8C0C8E-0C900C92-0CA80CAA-0CB30CB5-0CB90CBD0CDE0CE00CE10CF10CF20D05-0D0C0D0E-0D100D12-0D3A0D3D0D4E0D600D610D7A-0D7F0D85-0D960D9A-0DB10DB3-0DBB0DBD0DC0-0DC60E01-0E300E320E330E40-0E460E810E820E840E870E880E8A0E8D0E94-0E970E99-0E9F0EA1-0EA30EA50EA70EAA0EAB0EAD-0EB00EB20EB30EBD0EC0-0EC40EC60EDC-0EDF0F000F40-0F470F49-0F6C0F88-0F8C1000-102A103F1050-1055105A-105D106110651066106E-10701075-1081108E10A0-10C510C710CD10D0-10FA10FC-1248124A-124D1250-12561258125A-125D1260-1288128A-128D1290-12B012B2-12B512B8-12BE12C012C2-12C512C8-12D612D8-13101312-13151318-135A1380-138F13A0-13F41401-166C166F-167F1681-169A16A0-16EA16F1-16F81700-170C170E-17111720-17311740-17511760-176C176E-17701780-17B317D717DC1820-18771880-18A818AA18B0-18F51900-191E1950-196D1970-19741980-19AB19C1-19C71A00-1A161A20-1A541AA71B05-1B331B45-1B4B1B83-1BA01BAE1BAF1BBA-1BE51C00-1C231C4D-1C4F1C5A-1C7D1CE9-1CEC1CEE-1CF11CF51CF61D00-1DBF1E00-1F151F18-1F1D1F20-1F451F48-1F4D1F50-1F571F591F5B1F5D1F5F-1F7D1F80-1FB41FB6-1FBC1FBE1FC2-1FC41FC6-1FCC1FD0-1FD31FD6-1FDB1FE0-1FEC1FF2-1FF41FF6-1FFC2071207F2090-209C21022107210A-211321152119-211D212421262128212A-212D212F-2139213C-213F2145-2149214E218321842C00-2C2E2C30-2C5E2C60-2CE42CEB-2CEE2CF22CF32D00-2D252D272D2D2D30-2D672D6F2D80-2D962DA0-2DA62DA8-2DAE2DB0-2DB62DB8-2DBE2DC0-2DC62DC8-2DCE2DD0-2DD62DD8-2DDE2E2F300530063031-3035303B303C3041-3096309D-309F30A1-30FA30FC-30FF3105-312D3131-318E31A0-31BA31F0-31FF3400-4DB54E00-9FCCA000-A48CA4D0-A4FDA500-A60CA610-A61FA62AA62BA640-A66EA67F-A69DA6A0-A6E5A717-A71FA722-A788A78B-A78EA790-A7ADA7B0A7B1A7F7-A801A803-A805A807-A80AA80C-A822A840-A873A882-A8B3A8F2-A8F7A8FBA90A-A925A930-A946A960-A97CA984-A9B2A9CFA9E0-A9E4A9E6-A9EFA9FA-A9FEAA00-AA28AA40-AA42AA44-AA4BAA60-AA76AA7AAA7E-AAAFAAB1AAB5AAB6AAB9-AABDAAC0AAC2AADB-AADDAAE0-AAEAAAF2-AAF4AB01-AB06AB09-AB0EAB11-AB16AB20-AB26AB28-AB2EAB30-AB5AAB5C-AB5FAB64AB65ABC0-ABE2AC00-D7A3D7B0-D7C6D7CB-D7FBF900-FA6DFA70-FAD9FB00-FB06FB13-FB17FB1DFB1F-FB28FB2A-FB36FB38-FB3CFB3EFB40FB41FB43FB44FB46-FBB1FBD3-FD3DFD50-FD8FFD92-FDC7FDF0-FDFBFE70-FE74FE76-FEFCFF21-FF3AFF41-FF5AFF66-FFBEFFC2-FFC7FFCA-FFCFFFD2-FFD7FFDA-FFDC")));
25489    $const_set($nesting[0], 'P_Nl', self.$unpack_hex_range("16EE-16F02160-21822185-218830073021-30293038-303AA6E6-A6EF"));
25490    $const_set($nesting[0], 'P_Nd', $rb_plus("0-9", self.$unpack_hex_range("0660-066906F0-06F907C0-07C90966-096F09E6-09EF0A66-0A6F0AE6-0AEF0B66-0B6F0BE6-0BEF0C66-0C6F0CE6-0CEF0D66-0D6F0DE6-0DEF0E50-0E590ED0-0ED90F20-0F291040-10491090-109917E0-17E91810-18191946-194F19D0-19D91A80-1A891A90-1A991B50-1B591BB0-1BB91C40-1C491C50-1C59A620-A629A8D0-A8D9A900-A909A9D0-A9D9A9F0-A9F9AA50-AA59ABF0-ABF9FF10-FF19")));
25491    $const_set($nesting[0], 'P_Pc', self.$unpack_hex_range("005F203F20402054FE33FE34FE4D-FE4FFF3F"));
25492    $const_set($nesting[0], 'CC_ALPHA', "" + ($$('P_L')) + ($$('P_Nl')));
25493    $const_set($nesting[0], 'CG_ALPHA', "[" + ($$('CC_ALPHA')) + "]");
25494    $const_set($nesting[0], 'CC_ALNUM', "" + ($$('CC_ALPHA')) + ($$('P_Nd')));
25495    $const_set($nesting[0], 'CG_ALNUM', "[" + ($$('CC_ALNUM')) + "]");
25496    $const_set($nesting[0], 'CC_WORD', "" + ($$('CC_ALNUM')) + ($$('P_Pc')));
25497    $const_set($nesting[0], 'CG_WORD', "[" + ($$('CC_WORD')) + "]");
25498    $const_set($nesting[0], 'CG_BLANK', "[ \\t]");
25499    $const_set($nesting[0], 'CC_EOL', "(?=\\n|$)");
25500    $const_set($nesting[0], 'CG_GRAPH', "[^\\s\\x00-\\x1F\\x7F]");
25501    $const_set($nesting[0], 'CC_ALL', "[\\s\\S]");
25502    return $const_set($nesting[0], 'CC_ANY', "[^\\n]");
25503  })($nesting[0], $nesting)
25504};
25505
25506Opal.modules["strscan"] = function(Opal) {/* Generated by Opal 1.7.3 */
25507  "use strict";
25508  var $klass = Opal.klass, $def = Opal.def, $truthy = Opal.truthy, $eqeqeq = Opal.eqeqeq, $Opal = Opal.Opal, $return_ivar = Opal.return_ivar, $send = Opal.send, $alias = Opal.alias, $nesting = [], nil = Opal.nil;
25509
25510  Opal.add_stubs('attr_reader,anchor,empty?,===,to_s,coerce_to!,scan_until,length,size,rest,pos=,beginning_of_line?,get_byte,private');
25511  return (function($base, $super, $parent_nesting) {
25512    var self = $klass($base, $super, 'StringScanner');
25513
25514    var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype;
25515
25516    $proto.pos = $proto.string = $proto.working = $proto.matched = $proto.prev_pos = $proto.match = nil;
25517    
25518    self.$attr_reader("pos", "matched");
25519    
25520    $def(self, '$initialize', function $$initialize(string) {
25521      var self = this;
25522
25523      
25524      self.string = string;
25525      self.pos = 0;
25526      self.matched = nil;
25527      self.working = string;
25528      return (self.match = []);
25529    });
25530    self.$attr_reader("string");
25531    
25532    $def(self, '$beginning_of_line?', function $StringScanner_beginning_of_line$ques$1() {
25533      var self = this;
25534
25535      return self.pos === 0 || self.string.charAt(self.pos - 1) === "\n"
25536    });
25537    
25538    $def(self, '$scan', function $$scan(pattern) {
25539      var self = this;
25540
25541      
25542      pattern = self.$anchor(pattern);
25543      
25544      var result = pattern.exec(self.working);
25545
25546      if (result == null) {
25547        return self.matched = nil;
25548      }
25549      self.prev_pos = self.pos;
25550      self.pos     += result[0].length;
25551      self.working  = self.working.substring(result[0].length);
25552      self.matched  = result[0];
25553      self.match    = result;
25554
25555      return result[0];
25556    ;
25557    });
25558    
25559    $def(self, '$scan_until', function $$scan_until(pattern) {
25560      var self = this;
25561
25562      
25563      pattern = self.$anchor(pattern);
25564      
25565      var working = self.working
25566
25567      for(var i = 0; working.length != i; ++i) {
25568        var result  = pattern.exec(working.substr(i));
25569        if (result !== null) {
25570          var matched_size = i + result[0].length
25571          var matched = working.substr(0, matched_size)
25572
25573          self.matched  = result[0]
25574          self.match  = result
25575          self.prev_pos = self.pos + i; // Position of first character of matched
25576          self.pos += matched_size // Position one after last character of matched
25577          self.working = working.substr(matched_size)
25578
25579          return matched
25580        }
25581      }
25582      return self.matched = nil;
25583    ;
25584    });
25585    
25586    $def(self, '$[]', function $StringScanner_$$$2(idx) {
25587      var self = this, $ret_or_1 = nil;
25588
25589      
25590      if ($truthy(self.match['$empty?']())) {
25591        return nil
25592      };
25593      if ($eqeqeq($$('Symbol'), ($ret_or_1 = idx))) {
25594        idx = idx.$to_s()
25595      } else if (!$eqeqeq($$('String'), $ret_or_1)) {
25596        idx = $Opal['$coerce_to!'](idx, $$('Integer'), "to_int")
25597      };
25598      
25599      var match = self.match;
25600
25601      if (idx < 0) {
25602        idx += match.length;
25603      }
25604
25605      if (idx < 0 || idx >= match.length) {
25606        return nil;
25607      }
25608
25609      if (match[idx] == null) {
25610        return nil;
25611      }
25612
25613      return match[idx];
25614    ;
25615    });
25616    
25617    $def(self, '$check', function $$check(pattern) {
25618      var self = this;
25619
25620      
25621      pattern = self.$anchor(pattern);
25622      
25623      var result = pattern.exec(self.working);
25624
25625      if (result == null) {
25626        return self.matched = nil;
25627      }
25628
25629      return self.matched = result[0];
25630    ;
25631    });
25632    
25633    $def(self, '$check_until', function $$check_until(pattern) {
25634      var self = this;
25635
25636      
25637      var old_prev_pos = self.prev_pos;
25638      var old_pos      = self.pos;
25639      var old_working  = self.working;
25640
25641      var result = self.$scan_until(pattern);
25642
25643      self.prev_pos = old_prev_pos;
25644      self.pos      = old_pos;
25645      self.working  = old_working;
25646
25647      return result;
25648    
25649    });
25650    
25651    $def(self, '$peek', function $$peek(length) {
25652      var self = this;
25653
25654      return self.working.substring(0, length)
25655    });
25656    
25657    $def(self, '$eos?', function $StringScanner_eos$ques$3() {
25658      var self = this;
25659
25660      return self.working.length === 0
25661    });
25662    
25663    $def(self, '$exist?', function $StringScanner_exist$ques$4(pattern) {
25664      var self = this;
25665
25666      
25667      var result = pattern.exec(self.working);
25668
25669      if (result == null) {
25670        return nil;
25671      }
25672      else if (result.index == 0) {
25673        return 0;
25674      }
25675      else {
25676        return result.index + 1;
25677      }
25678    
25679    });
25680    
25681    $def(self, '$skip', function $$skip(pattern) {
25682      var self = this;
25683
25684      
25685      pattern = self.$anchor(pattern);
25686      
25687      var result = pattern.exec(self.working);
25688
25689      if (result == null) {
25690        self.match = [];
25691        return self.matched = nil;
25692      }
25693      else {
25694        var match_str = result[0];
25695        var match_len = match_str.length;
25696
25697        self.matched   = match_str;
25698        self.match     = result;
25699        self.prev_pos  = self.pos;
25700        self.pos      += match_len;
25701        self.working   = self.working.substring(match_len);
25702
25703        return match_len;
25704      }
25705    ;
25706    });
25707    
25708    $def(self, '$skip_until', function $$skip_until(pattern) {
25709      var self = this;
25710
25711      
25712      var result = self.$scan_until(pattern);
25713
25714      if (result === nil) {
25715        return nil;
25716      }
25717      else {
25718        self.matched = result.substr(-1);
25719
25720        return result.length;
25721      }
25722    
25723    });
25724    
25725    $def(self, '$get_byte', function $$get_byte() {
25726      var self = this;
25727
25728      
25729      var result = nil;
25730
25731      if (self.pos < self.string.length) {
25732        self.prev_pos  = self.pos;
25733        self.pos      += 1;
25734        result      = self.matched = self.working.substring(0, 1);
25735        self.working   = self.working.substring(1);
25736      }
25737      else {
25738        self.matched = nil;
25739      }
25740
25741      return result;
25742    
25743    });
25744    
25745    $def(self, '$match?', function $StringScanner_match$ques$5(pattern) {
25746      var self = this;
25747
25748      
25749      pattern = self.$anchor(pattern);
25750      
25751      var result = pattern.exec(self.working);
25752
25753      if (result == null) {
25754        return nil;
25755      }
25756      else {
25757        self.prev_pos = self.pos;
25758
25759        return result[0].length;
25760      }
25761    ;
25762    });
25763    
25764    $def(self, '$pos=', function $StringScanner_pos$eq$6(pos) {
25765      var self = this;
25766
25767      
25768      
25769      if (pos < 0) {
25770        pos += self.string.$length();
25771      }
25772    ;
25773      self.pos = pos;
25774      return (self.working = self.string.slice(pos));
25775    });
25776    
25777    $def(self, '$matched_size', function $$matched_size() {
25778      var self = this;
25779
25780      
25781      if (self.matched === nil) {
25782        return nil;
25783      }
25784
25785      return self.matched.length
25786    
25787    });
25788    
25789    $def(self, '$post_match', function $$post_match() {
25790      var self = this;
25791
25792      
25793      if (self.matched === nil) {
25794        return nil;
25795      }
25796
25797      return self.string.substr(self.pos);
25798    
25799    });
25800    
25801    $def(self, '$pre_match', function $$pre_match() {
25802      var self = this;
25803
25804      
25805      if (self.matched === nil) {
25806        return nil;
25807      }
25808
25809      return self.string.substr(0, self.prev_pos);
25810    
25811    });
25812    
25813    $def(self, '$reset', function $$reset() {
25814      var self = this;
25815
25816      
25817      self.working = self.string;
25818      self.matched = nil;
25819      return (self.pos = 0);
25820    });
25821    
25822    $def(self, '$rest', $return_ivar("working"));
25823    
25824    $def(self, '$rest?', function $StringScanner_rest$ques$7() {
25825      var self = this;
25826
25827      return self.working.length !== 0
25828    });
25829    
25830    $def(self, '$rest_size', function $$rest_size() {
25831      var self = this;
25832
25833      return self.$rest().$size()
25834    });
25835    
25836    $def(self, '$terminate', function $$terminate() {
25837      var $a, self = this;
25838
25839      
25840      self.match = nil;
25841      return ($a = [self.string.$length()], $send(self, 'pos=', $a), $a[$a.length - 1]);
25842    });
25843    
25844    $def(self, '$unscan', function $$unscan() {
25845      var self = this;
25846
25847      
25848      self.pos = self.prev_pos;
25849      self.prev_pos = nil;
25850      self.match = nil;
25851      return self;
25852    });
25853    $alias(self, "bol?", "beginning_of_line?");
25854    $alias(self, "getch", "get_byte");
25855    self.$private();
25856    return $def(self, '$anchor', function $$anchor(pattern) {
25857      
25858      
25859      var flags = pattern.toString().match(/\/([^\/]+)$/);
25860      flags = flags ? flags[1] : undefined;
25861      return new RegExp('^(?:' + pattern.source + ')', flags);
25862    
25863    });
25864  })($nesting[0], null, $nesting)
25865};
25866
25867Opal.modules["asciidoctor/js"] = function(Opal) {/* Generated by Opal 1.7.3 */
25868  "use strict";
25869  var self = Opal.top, nil = Opal.nil;
25870
25871  Opal.add_stubs('require');
25872  
25873  self.$require("asciidoctor/js/opal_ext");
25874  self.$require("asciidoctor/js/rx");
25875  return self.$require("strscan");
25876};
25877
25878Opal.modules["asciidoctor/core_ext/nil_or_empty"] = function(Opal) {/* Generated by Opal 1.7.3 */
25879  "use strict";
25880  var $klass = Opal.klass, $truthy = Opal.truthy, $alias = Opal.alias, $nesting = [], nil = Opal.nil;
25881
25882  Opal.add_stubs('method_defined?,nil?,empty?');
25883  
25884  (function($base, $super) {
25885    var self = $klass($base, $super, 'NilClass');
25886
25887    
25888    if ($truthy(self['$method_defined?']("nil_or_empty?"))) {
25889      return nil
25890    } else {
25891      return $alias(self, "nil_or_empty?", "nil?")
25892    }
25893  })($nesting[0], null);
25894  (function($base, $super) {
25895    var self = $klass($base, $super, 'String');
25896
25897    
25898    if ($truthy(self['$method_defined?']("nil_or_empty?"))) {
25899      return nil
25900    } else {
25901      return $alias(self, "nil_or_empty?", "empty?")
25902    }
25903  })($nesting[0], null);
25904  (function($base, $super) {
25905    var self = $klass($base, $super, 'Array');
25906
25907    
25908    if ($truthy(self['$method_defined?']("nil_or_empty?"))) {
25909      return nil
25910    } else {
25911      return $alias(self, "nil_or_empty?", "empty?")
25912    }
25913  })($nesting[0], null);
25914  (function($base, $super) {
25915    var self = $klass($base, $super, 'Hash');
25916
25917    
25918    if ($truthy(self['$method_defined?']("nil_or_empty?"))) {
25919      return nil
25920    } else {
25921      return $alias(self, "nil_or_empty?", "empty?")
25922    }
25923  })($nesting[0], null);
25924  return (function($base, $super) {
25925    var self = $klass($base, $super, 'Numeric');
25926
25927    
25928    if ($truthy(self['$method_defined?']("nil_or_empty?"))) {
25929      return nil
25930    } else {
25931      return $alias(self, "nil_or_empty?", "nil?")
25932    }
25933  })($nesting[0], null);
25934};
25935
25936Opal.modules["asciidoctor/core_ext/hash/merge"] = function(Opal) {/* Generated by Opal 1.7.3 */
25937  "use strict";
25938  var $eqeq = Opal.eqeq, $send = Opal.send, $slice = Opal.slice, $truthy = Opal.truthy, $rb_lt = Opal.rb_lt, $rb_gt = Opal.rb_gt, $send2 = Opal.send2, $find_super = Opal.find_super, $def = Opal.def, self = Opal.top, $nesting = [], $$ = Opal.$r($nesting), nil = Opal.nil;
25939
25940  Opal.add_stubs('==,arity,instance_method,send,new,<,length,dup,>,inject,merge,[]');
25941  if ($eqeq($$('Hash').$instance_method("merge").$arity(), 1)) {
25942    return $$('Hash').$send("prepend", $send($$('Module'), 'new', [], function $$1(){var self = $$1.$$s == null ? this : $$1.$$s;
25943
25944      return $def(self, '$merge', function $$merge($a) {
25945        var $post_args, args, $yield = $$merge.$$p || nil, self = this, len = nil;
25946
25947        $$merge.$$p = null;
25948        
25949        $post_args = $slice(arguments);
25950        args = $post_args;
25951        if ($truthy($rb_lt((len = args.$length()), 1))) {
25952          return self.$dup()
25953        } else {
25954          
25955          if ($truthy($rb_gt(len, 1))) {
25956            return $send(args, 'inject', [self], function $$2(acc, arg){
25957              
25958              if (acc == null) acc = nil;
25959              if (arg == null) arg = nil;
25960              return acc.$merge(arg);})
25961          } else {
25962            
25963            return $send2(self, $find_super(self, 'merge', $$merge, false, true), 'merge', [args['$[]'](0)], null);
25964          };
25965        };
25966      }, -1)}
25966, {$$s: self}))
25967  } else {
25968    return nil
25969  }
25970};
25971
25972Opal.modules["asciidoctor/core_ext/match_data/names"] = function(Opal) {/* Generated by Opal 1.7.3 */
25973  "use strict";
25974  var $truthy = Opal.truthy, $klass = Opal.klass, $def = Opal.def, $nesting = [], $$ = Opal.$r($nesting), nil = Opal.nil;
25975
25976  Opal.add_stubs('method_defined?');
25977  if ($truthy($$('MatchData')['$method_defined?']("names"))) {
25978    return nil
25979  } else {
25980    return (function($base, $super) {
25981      var self = $klass($base, $super, 'MatchData');
25982
25983      
25984      return $def(self, '$names', function $$names() {
25985        
25986        return []
25987      })
25988    })($nesting[0], null)
25989  }
25990};
25991
25992Opal.modules["asciidoctor/core_ext"] = function(Opal) {/* Generated by Opal 1.7.3 */
25993  "use strict";
25994  var self = Opal.top, nil = Opal.nil;
25995
25996  
25997  self.$require("asciidoctor/core_ext.rb"+ '/../' + "core_ext/nil_or_empty");
25998  self.$require("asciidoctor/core_ext.rb"+ '/../' + "core_ext/hash/merge");
25999  return self.$require("asciidoctor/core_ext.rb"+ '/../' + "core_ext/match_data/names");
26000};
26001
26002Opal.modules["asciidoctor/helpers"] = function(Opal) {/* Generated by Opal 1.7.3 */
26003  "use strict";
26004  var $module = Opal.module, $truthy = Opal.truthy, $eqeq = Opal.eqeq, $gvars = Opal.gvars, $def = Opal.def, $send = Opal.send, $neqeq = Opal.neqeq, $const_set = Opal.const_set, $hash2 = Opal.hash2, $to_ary = Opal.to_ary, $rb_times = Opal.rb_times, $eqeqeq = Opal.eqeqeq, $rb_plus = Opal.rb_plus, $Class = Opal.Class, $Object = Opal.Object, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$;
26005
26006  Opal.add_stubs('module_function,require,include?,include,==,path,message,raise,warn,logger,chomp,empty?,slice,unpack,[],[]=,byteslice,bytesize,map,rstrip,encode,encoding,nil_or_empty?,!=,tap,each_line,<<,!,start_with?,match?,gsub,rindex,index,basename,extname,length,directory?,dirname,mkdir_p,mkdir,private_constant,join,divmod,*,===,+,to_s,to_i,succ,class_for_name,const_get');
26007  return (function($base, $parent_nesting) {
26008    var self = $module($base, 'Asciidoctor');
26009
26010    var $nesting = [self].concat($parent_nesting);
26011
26012    return (function($base, $parent_nesting) {
26013      var self = $module($base, 'Helpers');
26014
26015      var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
26016
26017      
26018      self.$module_function();
26019      
26020      $def(self, '$require_library', function $$require_library(name, gem_name, on_failure) {
26021        var self = this, details = nil;
26022        if ($gvars["!"] == null) $gvars["!"] = nil;
26023
26024        
26025        if (gem_name == null) gem_name = true;
26026        if (on_failure == null) on_failure = "abort";
26027        try {
26028          return self.$require(name)
26029        } catch ($err) {
26030          if (Opal.rescue($err, [$$$('LoadError')])) {
26031            try {
26032              
26033              if (!$truthy(self['$include?']($$('Logging')))) {
26034                self.$include($$('Logging'))
26035              };
26036              if ($truthy(gem_name)) {
26037                
26038                if ($eqeq(gem_name, true)) {
26039                  gem_name = name
26040                };
26041                
26042                switch (on_failure) {
26043                  case "abort":
26044                    
26045                    details = ($eqeq($gvars["!"].$path(), gem_name) ? ("") : (" (reason: " + (($truthy($gvars["!"].$path()) ? ("cannot load '" + ($gvars["!"].$path()) + "'") : ($gvars["!"].$message()))) + ")"));
26046                    self.$raise($$$('LoadError'), "asciidoctor: FAILED: required gem '" + (gem_name) + "' is not available" + (details) + ". Processing aborted.");
26047                    break;
26048                  case "warn":
26049                    
26050                    details = ($eqeq($gvars["!"].$path(), gem_name) ? ("") : (" (reason: " + (($truthy($gvars["!"].$path()) ? ("cannot load '" + ($gvars["!"].$path()) + "'") : ($gvars["!"].$message()))) + ")"));
26051                    self.$logger().$warn("optional gem '" + (gem_name) + "' is not available" + (details) + ". Functionality disabled.");
26052                    break;
26053                  default:
26054                    nil
26055                };
26056              } else 
26057              switch (on_failure) {
26058                case "abort":
26059                  self.$raise($$$('LoadError'), "asciidoctor: FAILED: " + ($gvars["!"].$message().$chomp(".")) + ". Processing aborted.")
26060                  break;
26061                case "warn":
26062                  self.$logger().$warn("" + ($gvars["!"].$message().$chomp(".")) + ". Functionality disabled.")
26063                  break;
26064                default:
26065                  nil
26066              };
26067              return nil;
26068            } finally { Opal.pop_exception(); }
26069          } else { throw $err; }
26070        };
26071      }, -2);
26072      
26073      $def(self, '$prepare_source_array', function $$prepare_source_array(data, trim_end) {
26074        var leading_2_bytes = nil, leading_bytes = nil, first = nil;
26075
26076        
26077        if (trim_end == null) trim_end = true;
26078        if ($truthy(data['$empty?']())) {
26079          return []
26080        };
26081        if ($eqeq((leading_2_bytes = (leading_bytes = (first = data['$[]'](0)).$unpack("C3")).$slice(0, 2)), $$('BOM_BYTES_UTF_16LE'))) {
26082          
26083          data['$[]='](0, first.$byteslice(2, first.$bytesize()));
26084          return ($truthy(trim_end) ? ($send(data, 'map', [], function $$1(line){
26085            
26086            if (line == null) line = nil;
26087            return line.$encode($$('UTF_8'), $$$($$$('Encoding'), 'UTF_16LE')).$rstrip();})) : ($send(data, 'map', [], function $$2(line){
26088            
26089            if (line == null) line = nil;
26090            return line.$encode($$('UTF_8'), $$$($$$('Encoding'), 'UTF_16LE')).$chomp();})));
26091        } else if ($eqeq(leading_2_bytes, $$('BOM_BYTES_UTF_16BE'))) {
26092          
26093          data['$[]='](0, first.$byteslice(2, first.$bytesize()));
26094          return ($truthy(trim_end) ? ($send(data, 'map', [], function $$3(line){
26095            
26096            if (line == null) line = nil;
26097            return line.$encode($$('UTF_8'), $$$($$$('Encoding'), 'UTF_16BE')).$rstrip();})) : ($send(data, 'map', [], function $$4(line){
26098            
26099            if (line == null) line = nil;
26100            return line.$encode($$('UTF_8'), $$$($$$('Encoding'), 'UTF_16BE')).$chomp();})));
26101        } else if ($eqeq(leading_bytes, $$('BOM_BYTES_UTF_8'))) {
26102          data['$[]='](0, first.$byteslice(3, first.$bytesize()))
26103        };
26104        if ($eqeq(first.$encoding(), $$('UTF_8'))) {
26105          if ($truthy(trim_end)) {
26106            return $send(data, 'map', [], function $$5(line){
26107              
26108              if (line == null) line = nil;
26109              return line.$rstrip();})
26110          } else {
26111            return $send(data, 'map', [], function $$6(line){
26112              
26113              if (line == null) line = nil;
26114              return line.$chomp();})
26115          }
26116        } else if ($truthy(trim_end)) {
26117          return $send(data, 'map', [], function $$7(line){
26118            
26119            if (line == null) line = nil;
26120            return line.$encode($$('UTF_8')).$rstrip();})
26121        } else {
26122          return $send(data, 'map', [], function $$8(line){
26123            
26124            if (line == null) line = nil;
26125            return line.$encode($$('UTF_8')).$chomp();})
26126        };
26127      }, -2);
26128      
26129      $def(self, '$prepare_source_string', function $$prepare_source_string(data, trim_end) {
26130        var leading_2_bytes = nil, leading_bytes = nil;
26131
26132        
26133        if (trim_end == null) trim_end = true;
26134        if ($truthy(data['$nil_or_empty?']())) {
26135          return []
26136        };
26137        if ($eqeq((leading_2_bytes = (leading_bytes = data.$unpack("C3")).$slice(0, 2)), $$('BOM_BYTES_UTF_16LE'))) {
26138          data = data.$byteslice(2, data.$bytesize()).$encode($$('UTF_8'), $$$($$$('Encoding'), 'UTF_16LE'))
26139        } else if ($eqeq(leading_2_bytes, $$('BOM_BYTES_UTF_16BE'))) {
26140          data = data.$byteslice(2, data.$bytesize()).$encode($$('UTF_8'), $$$($$$('Encoding'), 'UTF_16BE'))
26141        } else if ($eqeq(leading_bytes, $$('BOM_BYTES_UTF_8'))) {
26142          
26143          data = data.$byteslice(3, data.$bytesize());
26144          if (!$eqeq(data.$encoding(), $$('UTF_8'))) {
26145            data = data.$encode($$('UTF_8'))
26146          };
26147        } else if ($neqeq(data.$encoding(), $$('UTF_8'))) {
26148          data = data.$encode($$('UTF_8'))
26149        };
26150        if ($truthy(trim_end)) {
26151          return $send([], 'tap', [], function $$9(lines){
26152            
26153            if (lines == null) lines = nil;
26154            return $send(data, 'each_line', [], function $$10(line){
26155              
26156              if (line == null) line = nil;
26157              return lines['$<<'](line.$rstrip());});})
26158        } else {
26159          return $send([], 'tap', [], function $$11(lines){
26160            
26161            if (lines == null) lines = nil;
26162            return $send(data, 'each_line', [], function $$12(line){
26163              
26164              if (line == null) line = nil;
26165              return lines['$<<'](line.$chomp());});})
26166        };
26167      }, -2);
26168      if ($eqeq($$$('RUBY_ENGINE'), "jruby")) {
26169        
26170        $def(self, '$uriish?', function $Helpers_uriish$ques$13(str) {
26171          var $ret_or_1 = nil, $ret_or_2 = nil;
26172
26173          if ($truthy(($ret_or_1 = ($truthy(($ret_or_2 = str['$include?'](":"))) ? (str['$start_with?']("uri:classloader:")['$!']()) : ($ret_or_2))))) {
26174            
26175            return $$('UriSniffRx')['$match?'](str);
26176          } else {
26177            return $ret_or_1
26178          }
26179        })
26180      } else {
26181        
26182        $def(self, '$uriish?', function $Helpers_uriish$ques$14(str) {
26183          var $ret_or_1 = nil;
26184
26185          if ($truthy(($ret_or_1 = str['$include?'](":")))) {
26186            
26187            return $$('UriSniffRx')['$match?'](str);
26188          } else {
26189            return $ret_or_1
26190          }
26191        })
26192      };
26193      
26194      $def(self, '$encode_uri_component', function $$encode_uri_component(str) {
26195        
26196        
26197        return encodeURIComponent(str).replace(/%20|[!'()*]/g, function (m) {
26198          return m === '%20' ? '+' : '%' + m.charCodeAt(0).toString(16)
26199        })
26200      
26201      });
26202      
26203      $def(self, '$encode_spaces_in_uri', function $$encode_spaces_in_uri(str) {
26204        
26205        if ($truthy(str['$include?'](" "))) {
26206          
26207          return str.$gsub(" ", "%20");
26208        } else {
26209          return str
26210        }
26211      });
26212      
26213      $def(self, '$rootname', function $$rootname(filename) {
26214        var last_dot_idx = nil;
26215
26216        if ($truthy((last_dot_idx = filename.$rindex(".")))) {
26217          if ($truthy(filename.$index("/", last_dot_idx))) {
26218            return filename
26219          } else {
26220            
26221            return filename.$slice(0, last_dot_idx);
26222          }
26223        } else {
26224          return filename
26225        }
26226      });
26227      
26228      $def(self, '$basename', function $$basename(filename, drop_ext) {
26229        var self = this;
26230
26231        
26232        if (drop_ext == null) drop_ext = nil;
26233        if ($truthy(drop_ext)) {
26234          return $$$('File').$basename(filename, ($eqeq(drop_ext, true) ? (self.$extname(filename)) : (drop_ext)))
26235        } else {
26236          return $$$('File').$basename(filename)
26237        };
26238      }, -2);
26239      
26240      $def(self, '$extname?', function $Helpers_extname$ques$15(path) {
26241        var $ret_or_1 = nil, last_dot_idx = nil;
26242
26243        if ($truthy(($ret_or_1 = (last_dot_idx = path.$rindex("."))))) {
26244          return path.$index("/", last_dot_idx)['$!']()
26245        } else {
26246          return $ret_or_1
26247        }
26248      });
26249      if ($truthy($$$($$$('File'), 'ALT_SEPARATOR'))) {
26250        
26251        $def(self, '$extname', function $$extname(path, fallback) {
26252          var last_dot_idx = nil;
26253
26254          
26255          if (fallback == null) fallback = "";
26256          if ($truthy((last_dot_idx = path.$rindex(".")))) {
26257            if (($truthy(path.$index("/", last_dot_idx)) || ($truthy(path.$index($$$($$$('File'), 'ALT_SEPARATOR'), last_dot_idx))))) {
26258              return fallback
26259            } else {
26260              
26261              return path.$slice(last_dot_idx, path.$length());
26262            }
26263          } else {
26264            return fallback
26265          };
26266        }, -2)
26267      } else {
26268        
26269        $def(self, '$extname', function $$extname(path, fallback) {
26270          var last_dot_idx = nil;
26271
26272          
26273          if (fallback == null) fallback = "";
26274          if ($truthy((last_dot_idx = path.$rindex(".")))) {
26275            if ($truthy(path.$index("/", last_dot_idx))) {
26276              return fallback
26277            } else {
26278              
26279              return path.$slice(last_dot_idx, path.$length());
26280            }
26281          } else {
26282            return fallback
26283          };
26284        }, -2)
26285      };
26286      
26287      $def(self, '$mkdir_p', function $$mkdir_p(dir) {
26288        var self = this, parent_dir = nil;
26289
26290        if ($truthy($$$('File')['$directory?'](dir))) {
26291          return nil
26292        } else {
26293          
26294          if (!$eqeq((parent_dir = $$$('File').$dirname(dir)), ".")) {
26295            self.$mkdir_p(parent_dir)
26296          };
26297          
26298          try {
26299            return $$$('Dir').$mkdir(dir)
26300          } catch ($err) {
26301            if (Opal.rescue($err, [$$$('SystemCallError')])) {
26302              try {
26303                if ($truthy($$$('File')['$directory?'](dir))) {
26304                  return nil
26305                } else {
26306                  return self.$raise()
26307                }
26308              } finally { Opal.pop_exception(); }
26309            } else { throw $err; }
26310          };;
26311        }
26312      });
26313      $const_set($nesting[0], 'ROMAN_NUMERALS', $hash2(["M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"], {"M": 1000, "CM": 900, "D": 500, "CD": 400, "C": 100, "XC": 90, "L": 50, "XL": 40, "X": 10, "IX": 9, "V": 5, "IV": 4, "I": 1}));
26314      self.$private_constant("ROMAN_NUMERALS");
26315      
26316      $def(self, '$int_to_roman', function $$int_to_roman(val) {
26317        
26318        return $send($$('ROMAN_NUMERALS'), 'map', [], function $$16(l, i){var $a, $b, repeat = nil;
26319
26320          
26321          if (l == null) l = nil;
26322          if (i == null) i = nil;
26323          $b = val.$divmod(i), $a = $to_ary($b), (repeat = ($a[0] == null ? nil : $a[0])), (val = ($a[1] == null ? nil : $a[1])), $b;
26324          return $rb_times(l, repeat);}).$join()
26325      });
26326      
26327      $def(self, '$nextval', function $$nextval(current) {
26328        var intval = nil;
26329
26330        if ($eqeqeq($$$('Integer'), current)) {
26331          return $rb_plus(current, 1)
26332        } else if ($eqeq((intval = current.$to_i()).$to_s(), current.$to_s())) {
26333          return $rb_plus(intval, 1)
26334        } else {
26335          return current.$succ()
26336        }
26337      });
26338      
26339      $def(self, '$resolve_class', function $$resolve_class(object) {
26340        var self = this;
26341
26342        if ($eqeqeq($Class, object)) {
26343          return object
26344        } else {
26345          
26346          if ($eqeqeq($$$('String'), object)) {
26347            
26348            return self.$class_for_name(object);
26349          } else {
26350            return nil
26351          };
26352        }
26353      });
26354      return $def(self, '$class_for_name', function $$class_for_name(qualified_name) {
26355        var self = this, resolved = nil;
26356
26357        try {
26358          
26359          if (!$eqeqeq($Class, (resolved = $Object.$const_get(qualified_name, false)))) {
26360            self.$raise()
26361          };
26362          return resolved;
26363        } catch ($err) {
26364          if (Opal.rescue($err, [$$('StandardError')])) {
26365            try {
26366              return self.$raise($$$('NameError'), "Could not resolve class for name: " + (qualified_name))
26367            } finally { Opal.pop_exception(); }
26368          } else { throw $err; }
26369        }
26370      });
26371    })($nesting[0], $nesting)
26372  })($nesting[0], $nesting)
26373};
26374
26375Opal.modules["logger"] = function(Opal) {/* Generated by Opal 1.7.3 */
26376  "use strict";
26377  var $klass = Opal.klass, $module = Opal.module, $const_set = Opal.const_set, $send = Opal.send, $def = Opal.def, $eqeqeq = Opal.eqeqeq, $rb_plus = Opal.rb_plus, $truthy = Opal.truthy, $rb_le = Opal.rb_le, $rb_lt = Opal.rb_lt, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$;
26378
26379  Opal.add_stubs('include,to_h,map,constants,const_get,to_s,format,chr,strftime,message_as_string,
26379===,+,message,class,join,backtrace,inspect,attr_reader,attr_accessor,new,key,upcase,raise,add,to_proc,<=,<,write,call,[],now');
26380  return (function($base, $super, $parent_nesting) {
26381    var self = $klass($base, $super, 'Logger');
26382
26383    var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype;
26384
26385    $proto.level = $proto.progname = $proto.pipe = $proto.formatter = nil;
26386    
26387    (function($base, $parent_nesting) {
26388      var self = $module($base, 'Severity');
26389
26390      var $nesting = [self].concat($parent_nesting);
26391
26392      
26393      $const_set($nesting[0], 'DEBUG', 0);
26394      $const_set($nesting[0], 'INFO', 1);
26395      $const_set($nesting[0], 'WARN', 2);
26396      $const_set($nesting[0], 'ERROR', 3);
26397      $const_set($nesting[0], 'FATAL', 4);
26398      return $const_set($nesting[0], 'UNKNOWN', 5);
26399    })($nesting[0], $nesting);
26400    self.$include($$('Severity'));
26401    $const_set($nesting[0], 'SEVERITY_LABELS', $send($$('Severity').$constants(), 'map', [], function $Logger$1(s){
26402      
26403      if (s == null) s = nil;
26404      return [$$('Severity').$const_get(s), s.$to_s()];}).$to_h());
26405    (function($base, $super, $parent_nesting) {
26406      var self = $klass($base, $super, 'Formatter');
26407
26408      var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
26409
26410      
26411      $const_set($nesting[0], 'MESSAGE_FORMAT', "%s, [%s] %5s -- %s: %s\n");
26412      $const_set($nesting[0], 'DATE_TIME_FORMAT', "%Y-%m-%dT%H:%M:%S.%6N");
26413      
26414      $def(self, '$call', function $$call(severity, time, progname, msg) {
26415        var self = this;
26416
26417        return self.$format($$('MESSAGE_FORMAT'), severity.$chr(), time.$strftime($$('DATE_TIME_FORMAT')), severity, progname, self.$message_as_string(msg))
26418      });
26419      return $def(self, '$message_as_string', function $$message_as_string(msg) {
26420        var $ret_or_1 = nil, $ret_or_2 = nil;
26421
26422        if ($eqeqeq($$$('String'), ($ret_or_1 = msg))) {
26423          return msg
26424        } else if ($eqeqeq($$$('Exception'), $ret_or_1)) {
26425          return $rb_plus("" + (msg.$message()) + " (" + (msg.$class()) + ")\n", ($truthy(($ret_or_2 = msg.$backtrace())) ? ($ret_or_2) : ([])).$join("\n"))
26426        } else {
26427          return msg.$inspect()
26428        }
26429      });
26430    })($nesting[0], null, $nesting);
26431    self.$attr_reader("level");
26432    self.$attr_accessor("progname");
26433    self.$attr_accessor("formatter");
26434    
26435    $def(self, '$initialize', function $$initialize(pipe) {
26436      var self = this;
26437
26438      
26439      self.pipe = pipe;
26440      self.level = $$('DEBUG');
26441      return (self.formatter = $$('Formatter').$new());
26442    });
26443    
26444    $def(self, '$level=', function $Logger_level$eq$2(severity) {
26445      var self = this, level = nil;
26446
26447      if ($eqeqeq($$$('Integer'), severity)) {
26448        return (self.level = severity)
26449      } else if ($truthy((level = $$('SEVERITY_LABELS').$key(severity.$to_s().$upcase())))) {
26450        return (self.level = level)
26451      } else {
26452        return self.$raise($$('ArgumentError'), "invalid log level: " + (severity))
26453      }
26454    });
26455    
26456    $def(self, '$info', function $$info(progname) {
26457      var block = $$info.$$p || nil, self = this;
26458
26459      $$info.$$p = null;
26460      
26461      ;
26462      if (progname == null) progname = nil;
26463      return $send(self, 'add', [$$('INFO'), nil, progname], block.$to_proc());
26464    }, -1);
26465    
26466    $def(self, '$debug', function $$debug(progname) {
26467      var block = $$debug.$$p || nil, self = this;
26468
26469      $$debug.$$p = null;
26470      
26471      ;
26472      if (progname == null) progname = nil;
26473      return $send(self, 'add', [$$('DEBUG'), nil, progname], block.$to_proc());
26474    }, -1);
26475    
26476    $def(self, '$warn', function $$warn(progname) {
26477      var block = $$warn.$$p || nil, self = this;
26478
26479      $$warn.$$p = null;
26480      
26481      ;
26482      if (progname == null) progname = nil;
26483      return $send(self, 'add', [$$('WARN'), nil, progname], block.$to_proc());
26484    }, -1);
26485    
26486    $def(self, '$error', function $$error(progname) {
26487      var block = $$error.$$p || nil, self = this;
26488
26489      $$error.$$p = null;
26490      
26491      ;
26492      if (progname == null) progname = nil;
26493      return $send(self, 'add', [$$('ERROR'), nil, progname], block.$to_proc());
26494    }, -1);
26495    
26496    $def(self, '$fatal', function $$fatal(progname) {
26497      var block = $$fatal.$$p || nil, self = this;
26498
26499      $$fatal.$$p = null;
26500      
26501      ;
26502      if (progname == null) progname = nil;
26503      return $send(self, 'add', [$$('FATAL'), nil, progname], block.$to_proc());
26504    }, -1);
26505    
26506    $def(self, '$unknown', function $$unknown(progname) {
26507      var block = $$unknown.$$p || nil, self = this;
26508
26509      $$unknown.$$p = null;
26510      
26511      ;
26512      if (progname == null) progname = nil;
26513      return $send(self, 'add', [$$('UNKNOWN'), nil, progname], block.$to_proc());
26514    }, -1);
26515    
26516    $def(self, '$info?', function $Logger_info$ques$3() {
26517      var self = this;
26518
26519      return $rb_le(self.level, $$('INFO'))
26520    });
26521    
26522    $def(self, '$debug?', function $Logger_debug$ques$4() {
26523      var self = this;
26524
26525      return $rb_le(self.level, $$('DEBUG'))
26526    });
26527    
26528    $def(self, '$warn?', function $Logger_warn$ques$5() {
26529      var self = this;
26530
26531      return $rb_le(self.level, $$('WARN'))
26532    });
26533    
26534    $def(self, '$error?', function $Logger_error$ques$6() {
26535      var self = this;
26536
26537      return $rb_le(self.level, $$('ERROR'))
26538    });
26539    
26540    $def(self, '$fatal?', function $Logger_fatal$ques$7() {
26541      var self = this;
26542
26543      return $rb_le(self.level, $$('FATAL'))
26544    });
26545    return $def(self, '$add', function $$add(severity, message, progname) {
26546      var block = $$add.$$p || nil, self = this, $ret_or_1 = nil;
26547
26548      $$add.$$p = null;
26549      
26550      ;
26551      if (message == null) message = nil;
26552      if (progname == null) progname = nil;
26553      if ($truthy($rb_lt((severity = ($truthy(($ret_or_1 = severity)
26553) ? ($ret_or_1) : ($$('UNKNOWN')))), self.level))) {
26554        return true
26555      };
26556      progname = ($truthy(($ret_or_1 = progname)) ? ($ret_or_1) : (self.progname));
26557      if (!$truthy(message)) {
26558        if ((block !== nil)) {
26559          message = Opal.yieldX(block, [])
26560        } else {
26561          
26562          message = progname;
26563          progname = self.progname;
26564        }
26565      };
26566      self.pipe.$write(self.formatter.$call(($truthy(($ret_or_1 = $$('SEVERITY_LABELS')['$[]'](severity))) ? ($ret_or_1) : ("ANY")), $$$('Time').$now(), progname, message));
26567      return true;
26568    }, -2);
26569  })($nesting[0], null, $nesting)
26570};
26571
26572Opal.modules["asciidoctor/logging"] = function(Opal) {/* Generated by Opal 1.7.3 */
26573  "use strict";
26574  var $module = Opal.module, $klass = Opal.klass, $slice = Opal.slice, $send2 = Opal.send2, $find_super = Opal.find_super, $to_a = Opal.to_a, $send = Opal.send, $def = Opal.def, $truthy = Opal.truthy, $rb_gt = Opal.rb_gt, $const_set = Opal.const_set, $hash2 = Opal.hash2, $eqeqeq = Opal.eqeqeq, $gvars = Opal.gvars, $alias = Opal.alias, $defs = Opal.defs, self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$;
26575
26576  Opal.add_stubs('require,attr_reader,progname=,formatter=,new,level=,>,[],===,inspect,to_h,map,constants,const_get,<<,clear,empty?,max,attr_accessor,memoize_logger,private,logger,extend,private_class_method,merge');
26577  
26578  self.$require("logger");
26579  return (function($base, $parent_nesting) {
26580    var self = $module($base, 'Asciidoctor');
26581
26582    var $nesting = [self].concat($parent_nesting);
26583
26584    
26585    (function($base, $super, $parent_nesting) {
26586      var self = $klass($base, $super, 'Logger');
26587
26588      var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype;
26589
26590      $proto.max_severity = nil;
26591      
26592      self.$attr_reader("max_severity");
26593      
26594      $def(self, '$initialize', function $$initialize($a) {
26595        var $post_args, args, $b, $yield = $$initialize.$$p || nil, self = this;
26596
26597        $$initialize.$$p = null;
26598        
26599        $post_args = $slice(arguments);
26600        args = $post_args;
26601        $send2(self, $find_super(self, 'initialize', $$initialize, false, true), 'initialize', $to_a(args), $yield);
26602        self['$progname=']("asciidoctor");
26603        self['$formatter=']($$('BasicFormatter').$new());
26604        return ($b = [$$('WARN')], $send(self, 'level=', $b), $b[$b.length - 1]);
26605      }, -1);
26606      
26607      $def(self, '$add', function $$add(severity, message, progname) {
26608        var $yield = $$add.$$p || nil, self = this, $ret_or_1 = nil;
26609
26610        $$add.$$p = null;
26611        
26612        if (message == null) message = nil;
26613        if (progname == null) progname = nil;
26614        if ($truthy($rb_gt((severity = ($truthy(($ret_or_1 = severity)) ? ($ret_or_1) : ($$('UNKNOWN')))), (self.max_severity = ($truthy(($ret_or_1 = self.max_severity)) ? ($ret_or_1) : (severity)))))) {
26615          self.max_severity = severity
26616        };
26617        return $send2(self, $find_super(self, 'add', $$add, false, true), 'add', [severity, message, progname], $yield);
26618      }, -2);
26619      (function($base, $super, $parent_nesting) {
26620        var self = $klass($base, $super, 'BasicFormatter');
26621
26622        var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
26623
26624        
26625        $const_set($nesting[0], 'SEVERITY_LABEL_SUBSTITUTES', $hash2(["WARN", "FATAL"], {"WARN": "WARNING", "FATAL": "FAILED"}));
26626        return $def(self, '$call', function $$call(severity, _, progname, msg) {
26627          var $ret_or_1 = nil;
26628
26629          return "" + (progname) + ": " + (($truthy(($ret_or_1 = $$('SEVERITY_LABEL_SUBSTITUTES')['$[]'](severity))) ? ($ret_or_1) : (severity))) + ": " + (($eqeqeq($$$('String'), msg) ? (msg) : (msg.$inspect()))) + ($$('LF'))
26630        });
26631      })($nesting[0], $$('Formatter'), $nesting);
26632      return (function($base) {
26633        var self = $module($base, 'AutoFormattingMessage');
26634
26635        
26636        return $def(self, '$inspect', function $$inspect() {
26637          var self = this, sloc = nil;
26638
26639          if ($truthy((sloc = self['$[]']("source_location")))) {
26640            return "" + (sloc) + ": " + (self['$[]']("text"))
26641          } else {
26642            return self['$[]']("text")
26643          }
26644        })
26645      })($nesting[0]);
26646    })($nesting[0], $$$('Logger'), $nesting);
26647    (function($base, $super, $parent_nesting) {
26648      var self = $klass($base, $super, 'MemoryLogger');
26649
26650      var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype;
26651
26652      $proto.messages = nil;
26653      
26654      $const_set($nesting[0], 'SEVERITY_SYMBOL_BY_VALUE', $send($$('Severity').$constants(false), 'map', [], function $MemoryLogger$1(c){
26655        
26656        if (c == null) c = nil;
26657        return [$$('Severity').$const_get(c), c];}).$to_h());
26658      self.$attr_reader("messages");
26659      
26660      $def(self, '$initialize', function $$initialize() {
26661        var self = this;
26662
26663        
26664        self['$level=']($$('WARN'));
26665        return (self.messages = []);
26666      });
26667      
26668      $def(self, '$add', function $$add(severity, message, progname) {
26669        var $yield = $$add.$$p || nil, self = this, $ret_or_1 = nil;
26670
26671        $$add.$$p = null;
26672        
26673        if (message == null) message = nil;
26674        if (progname == null) progname = nil;
26675        message = ($truthy(($ret_or_1 = message)) ? ($ret_or_1) : (($yield !== nil) ? (Opal.yieldX($yield, [])) : (progname)));
26676        self.messages['$<<']($hash2(["severity", "message"], {"severity": $$('SEVERITY_SYMBOL_BY_VALUE')['$[]'](($truthy(($ret_or_1 = severity)
26676) ? ($ret_or_1) : ($$('UNKNOWN')))), "message": message}));
26677        return true;
26678      }, -2);
26679      
26680      $def(self, '$clear', function $$clear() {
26681        var self = this;
26682
26683        return self.messages.$clear()
26684      });
26685      
26686      $def(self, '$empty?', function $MemoryLogger_empty$ques$2() {
26687        var self = this;
26688
26689        return self.messages['$empty?']()
26690      });
26691      return $def(self, '$max_severity', function $$max_severity() {
26692        var self = this;
26693
26694        if ($truthy(self['$empty?']())) {
26695          return nil
26696        } else {
26697          return $send(self.messages, 'map', [], function $$3(m){
26698            
26699            if (m == null) m = nil;
26700            return $$('Severity').$const_get(m['$[]']("severity"));}).$max()
26701        }
26702      });
26703    })($nesting[0], $$$('Logger'), $nesting);
26704    (function($base, $super, $parent_nesting) {
26705      var self = $klass($base, $super, 'NullLogger');
26706
26707      var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype;
26708
26709      $proto.max_severity = nil;
26710      
26711      self.$attr_reader("max_severity");
26712      
26713      $def(self, '$initialize', function $$initialize() {
26714        var $a, self = this;
26715
26716        return ($a = [$$('WARN')], $send(self, 'level=', $a), $a[$a.length - 1])
26717      });
26718      return $def(self, '$add', function $$add(severity, message, progname) {
26719        var self = this, $ret_or_1 = nil;
26720
26721        
26722        if (message == null) message = nil;
26723        if (progname == null) progname = nil;
26724        if ($truthy($rb_gt((severity = ($truthy(($ret_or_1 = severity)) ? ($ret_or_1) : ($$('UNKNOWN')))), (self.max_severity = ($truthy(($ret_or_1 = self.max_severity)) ? ($ret_or_1) : (severity)))))) {
26725          self.max_severity = severity
26726        };
26727        return true;
26728      }, -2);
26729    })($nesting[0], $$$('Logger'), $nesting);
26730    (function($base, $parent_nesting) {
26731      var self = $module($base, 'LoggerManager');
26732
26733      var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
26734
26735      
26736      self.logger_class = $$('Logger');
26737      return (function(self, $parent_nesting) {
26738        var $nesting = [self].concat($parent_nesting);
26739
26740        
26741        self.$attr_accessor("logger_class");
26742        
26743        $def(self, '$logger', function $$logger(pipe) {
26744          var self = this, $ret_or_1 = nil;
26745          if (self.logger == null) self.logger = nil;
26746          if (self.logger_class == null) self.logger_class = nil;
26747          if ($gvars.stderr == null) $gvars.stderr = nil;
26748
26749          
26750          if (pipe == null) pipe = $gvars.stderr;
26751          self.$memoize_logger();
26752          return (self.logger = ($truthy(($ret_or_1 = self.logger)) ? ($ret_or_1) : (self.logger_class.$new(pipe))));
26753        }, -1);
26754        
26755        $def(self, '$logger=', function $logger$eq$4(new_logger) {
26756          var self = this, $ret_or_1 = nil;
26757          if (self.logger_class == null) self.logger_class = nil;
26758          if ($gvars.stderr == null) $gvars.stderr = nil;
26759
26760          return (self.logger = ($truthy(($ret_or_1 = new_logger)) ? ($ret_or_1) : (self.logger_class.$new($gvars.stderr))))
26761        });
26762        self.$private();
26763        return $def(self, '$memoize_logger', function $$memoize_logger() {
26764          var self = this;
26765
26766          return (function(self, $parent_nesting) {
26767            
26768            
26769            $alias(self, "logger", "logger");
26770            return self.$attr_reader("logger");
26771          })(Opal.get_singleton_class(self), $nesting)
26772        });
26773      })(Opal.get_singleton_class(self), $nesting);
26774    })($nesting[0], $nesting);
26775    return (function($base, $parent_nesting) {
26776      var self = $module($base, 'Logging');
26777
26778      var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
26779
26780      
26781      $defs(self, '$included', function $$included(into) {
26782        
26783        return into.$extend($$('Logging'))
26784      });
26785      self.$private_class_method("included");
26786      
26787      $def(self, '$logger', function $$logger() {
26788        
26789        return $$('LoggerManager').$logger()
26790      });
26791      return $def(self, '$message_with_context', function $$message_with_context(text, context) {
26792        
26793        
26794        if (context == null) context = $hash2([], {});
26795        return $hash2(["text"], {"text": text}).$merge(context).$extend($$$($$('Logger'), 'AutoFormattingMessage'));
26796      }, -2);
26797    })($nesting[0], $nesting);
26798  })($nesting[0], $nesting);
26799};
26800
26801Opal.modules["asciidoctor/rx"] = function(Opal) {/* Generated by Opal 1.7.3 */
26802  "use strict";
26803  var $module = Opal.module, $const_set = Opal.const_set, $regexp = Opal.regexp, $hash2 = Opal.hash2, $send = Opal.send, $truthy = Opal.truthy, $hash = Opal.hash, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$;
26804
26805  Opal.add_stubs('join,to_a,new,[]=,empty?,escape');
26806  return (function($base, $parent_nesting) {
26807    var self = $module($base, 'Asciidoctor');
26808
26809    var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
26810
26811    
26812    $module($nesting[0], 'Rx');
26813    $const_set($nesting[0], 'AuthorInfoLineRx', $regexp(["^(", $$('CG_WORD'), "[", $$('CC_WORD'), "\\-'.]*)(?: +(", $$('CG_WORD'), "[", $$('CC_WORD'), "\\-'.]*))?(?: +(", $$('CG_WORD'), "[", $$('CC_WORD'), "\\-'.]*))?(?: +<([^>]+)>)?$"]));
26814    $const_set($nesting[0], 'AuthorDelimiterRx', /;(?: |$)/);
26815    $const_set($nesting[0], 'RevisionInfoLineRx', $regexp(["^(?:[^\\d{]*(", $$('CC_ANY'), "*?),)? *(?!:)(", $$('CC_ANY'), "*?)(?: *(?!^),?: *(", $$('CC_ANY'), "*))?$"]));
26816    $const_set($nesting[0], 'ManpageTitleVolnumRx', $regexp(["^(", $$('CC_ANY'), "+?) *\\( *(", $$('CC_ANY'), "+?) *\\)$"]));
26817    $const_set($nesting[0], 'ManpageNamePurposeRx', $regexp(["^(", $$('CC_ANY'), "+?) +- +(", $$('CC_ANY'), "+)$"]));
26818    $const_set($nesting[0], 'ConditionalDirectiveRx', $regexp(["^(\\\\)?(ifdef|ifndef|ifeval|endif)::(\\S*?(?:([,+])\\S*?)?)\\[(", $$('CC_ANY'), "+)?\\]$"]));
26819    $const_set($nesting[0], 'EvalExpressionRx', $regexp(["^(", $$('CC_ANY'), "+?) *([=!><]=|[><]) *(", $$('CC_ANY'), "+)$"]));
26820    $const_set($nesting[0], 'IncludeDirectiveRx', $regexp(["^(\\\\)?include::([^\\s\\[](?:[^\\[]*[^\\s\\[])?)\\[(", $$('CC_ANY'), "+)?\\]$"]));
26821    $const_set($nesting[0], 'TagDirectiveRx', /\b(?:tag|(e)nd)::(\S+?)\[\](?=$|[ \r])/m);
26822    $const_set($nesting[0], 'AttributeEntryRx', $regexp(["^:(!?", $$('CG_WORD'), "[^:]*):(?:[ \\t]+(", $$('CC_ANY'), "*))?$"]));
26823    $const_set($nesting[0], 'InvalidAttributeNameCharsRx', $regexp(["[^", $$('CC_WORD'), "-]"]));
26824    $const_set($nesting[0], 'AttributeEntryPassMacroRx', $regexp(["^pass:([a-z]+(?:,[a-z-]+)*)?\\[(", $$('CC_ALL'), "*)\\]$"]));
26825    $const_set($nesting[0], 'AttributeReferenceRx', $regexp(["(\\\\)?\\{(", $$('CG_WORD'), "[", $$('CC_WORD'), "-]*|(set|counter2?):", $$('CC_ANY'), "+?)(\\\\)?\\}"]));
26826    $const_set($nesting[0], 'BlockAnchorRx', $regexp(["^\\[\\[(?:|([", $$('CC_ALPHA'), "_:][", $$('CC_WORD'), "\\-:.]*)(?:, *(", $$('CC_ANY'), "+))?)\\]\\]$"]));
26827    $const_set($nesting[0], 'BlockAttributeListRx', $regexp(["^\\[(|[", $$('CC_WORD'), ".#%{,\"']", $$('CC_ANY'), "*)\\]$"]));
26828    $const_set($nesting[0], 'BlockAttributeLineRx', $regexp(["^\\[(?:|[", $$('CC_WORD'), ".#%{,\"']", $$('CC_ANY'), "*|\\[(?:|[", $$('CC_ALPHA'), "_:][", $$('CC_WORD'), "\\-:.]*(?:, *", $$('CC_ANY'), "+)?)\\])\\]$"]));
26829    $const_set($nesting[0], 'BlockTitleRx', $regexp(["^\\.(\\.?[^ \\t.]", $$('CC_ANY'), "*)$"]));
26830    $const_set($nesting[0], 'AdmonitionParagraphRx', $regexp(["^(", $$('ADMONITION_STYLES').$to_a().$join("|"), "):[ \\t]+"]));
26831    $const_set($nesting[0], 'LiteralParagraphRx', $regexp(["^([ \\t]+", $$('CC_ANY'), "*)$"]));
26832    $const_set($nesting[0], 'AtxSectionTitleRx', $regexp(["^(=={0,5})[ \\t]+(", $$('CC_ANY'), "+?)(?:[ \\t]+\\1)?$"]));
26833    $const_set($nesting[0], 'ExtAtxSectionTitleRx', $regexp(["^(=={0,5}|#\\\#{0,5})[ \\t]+(", $$('CC_ANY'), "+?)(?:[ \\t]+\\1)?$"]));
26834    $const_set($nesting[0], 'SetextSectionTitleRx', $regexp(["^((?!\\.)", $$('CC_ANY'), "*?", $$('CG_ALNUM'), $$('CC_ANY'), "*)$"]));
26835    $const_set($nesting[0], 'InlineSectionAnchorRx', $regexp([" (\\\\)?\\[\\[([", $$('CC_ALPHA'), "_:][", $$('CC_WORD'), "\\-:.]*)(?:, *(", $$('CC_ANY'), "+))?\\]\\]$"]));
26836    $const_set($nesting[0], 'InvalidSectionIdCharsRx', $regexp(["<[^>]+>|&(?:[a-z][a-z]+\\d{0,2}|#\\d\\d\\d{0,4}|#x[\\da-f][\\da-f][\\da-f]{0,3});|[^ ", $$('CC_WORD'), "\\-.]+?"]));
26837    $const_set($nesting[0], 'SectionLevelStyleRx', /^sect\d$/);
26838    $const_set($nesting[0], 'AnyListRx', $regexp(["^(?:[ \\t]*(?:-|\\*\\**|\\.\\.*|\\u2022|\\d+\\.|[a-zA-Z]\\.|[IVXivx]+\\))[ \\t]|(?!//[^/])[ \\t]*[^ \\t]", $$('CC_ANY'), "*?(?::::{0,2}|;;)(?:$|[ \\t])|<(?:\\d+|\\.)>[ \\t])"]));
26839    $const_set($nesting[0], 'UnorderedListRx', $regexp(["^[ \\t]*(-|\\*\\**|\\u2022)[ \\t]+(", $$('CC_ANY'), "*)$"]));
26840    $const_set($nesting[0], 'OrderedListRx', $regexp(["^[ \\t]*(\\.\\.*|\\d+\\.|[a-zA-Z]\\.|[IVXivx]+\\))[ \\t]+(", $$('CC_ANY'), "*)$"]));
26841    $const_set($nesting[0], 'OrderedListMarkerRxMap', $hash2(["arabic", "loweralpha", "lowerroman", "upperalpha", "upperroman"], {"arabic": /\d+\./, "loweralpha": /[a-z]\./, "lowerroman": /[ivx]+\)/, "upperalpha": /[A-Z]\./, "upperroman": /[IVX]+\)/}));
26842    $const_set($nesting[0], 'DescriptionListRx', $regexp(["^(?!//[^/])[ \\t]*([^ \\t]", $$('CC_ANY'), "*?)(:::{0,2}|;;)(?:$|[ \\t]+(", $$('CC_ANY'), "*)$)"]));
26843    $const_set($nesting[0], 'DescriptionListSiblingRx', $hash2(["::", ":::", "::::", ";;"], {"::": $regexp(["^(?!//[^/])[ \\t]*([^ \\t]", $$('CC_ANY'), "*?[^:]|[^ \\t:])(::)(?:$|[ \\t]+(", $$('CC_ANY'), "*)$)"]), ":::": $regexp(["^(?!//[^/])[ \\t]*([^ \\t]", $$('CC_ANY'), "*?[^:]|[^ \\t:])(:::)(?:$|[ \\t]+(", $$('CC_ANY'), "*)$)"]), "::::": $regexp(["^(?!//[^/])[ \\t]*([^ \\t]", $$('CC_ANY'), "*?[^:]|[^ \\t:])(::::)(?:$|[ \\t]+(", $$('CC_ANY'), "*)$)"]), ";;": $regexp(["^(?!//[^/])[ \\t]*([^ \\t]", $$('CC_ANY'), "*?)(;;)(?:$|[ \\t]+(", $$('CC_ANY'), "*)$)"])}));
26844    $const_set($nesting[0], 'CalloutListRx', $regexp(["^<(\\d+|\\.)>[ \\t]+(", $$('CC_ANY'), "*)$"]));
26845    $const_set($nesting[0], 'CalloutExtractRx', /((?:\/\/|#|--|;;) ?)?(\\)?<!?(|--)(\d+|\.)\3>(?=(?: ?\\?<!?\3(?:\d+|\.)\3>)*$)/);
26846    $const_set($nesting[0], 'CalloutExtractRxt', "(\\\\)?<()(\\d+|\\.)>(?=(?: ?\\\\?<(?:\\d+|\\.)>)*$)");
26847    $const_set($nesting[0], 'CalloutExtractRxMap', $send($$$('Hash'), 'new', [], function $Asciidoctor$1(h, k){var $a;
26848
26849      
26850      if (h == null) h = nil;
26851      if (k == null) k = nil;
26852      return ($a = [k, $regexp(["(", ($truthy(k['$empty?']()) ? ("") : ("" + ($$$('Regexp').$escape(k)) + " ?")), ")?", $$('CalloutExtractRxt')])], $send(h, '[]=', $a), $a[$a.length - 1]);}));
26853    $const_set($nesting[0], 'CalloutScanRx', $regexp(["\\\\?<!?(|--)(\\d+|\\.)\\1>(?=(?: ?\\\\?<!?\\1(?:\\d+|\\.)\\1>)*", $$('CC_EOL'), ")"]));
26854    $const_set($nesting[0], 'CalloutSourceRx', $regexp(["((?://|#|--|;;) ?)?(\\\\)?&lt;!?(|--)(\\d+|\\.)\\3&gt;(?=(?: ?\\\\?&lt;!?\\3(?:\\d+|\\.)\\3&gt;)*", $$('CC_EOL'), ")"]));
26855    $const_set($nesting[0], 'CalloutSourceRxt', "(\\\\)?&lt;()(\\d+|\\.)&gt;(?=(?: ?\\\\?&lt;(?:\\d+|\\.)&gt;)*" + ($$('CC_EOL')) + ")");
26856    $const_set($nesting[0], 'CalloutSourceRxMap', $send($$$('Hash'), 'new', [], function $Asciidoctor$2(h, k){var $a;
26857
26858      
26859      if (h == null) h = nil;
26860      if (k == null) k = nil;
26861      return ($a = [k, $regexp(["(", ($truthy(k['$empty?']()) ? ("") : ("" + ($$$('Regexp').$escape(k)) + " ?")), ")?", $$('CalloutSourceRxt')])], $send(h, '[]=', $a), $a[$a.length - 1]);}));
26862    $const_set($nesting[0], 'ListRxMap', $hash2(["ulist", "olist", "dlist", "colist"], {"ulist": $$('UnorderedListRx'), "olist": $$('OrderedListRx'), "dlist": $$('DescriptionListRx'), "colist": $$('CalloutListRx')}));
26863    $const_set($nesting[0], 'ColumnSpecRx', /^(?:(\d+)\*)?([<^>](?:\.[<^>]?)?|(?:[<^>]?\.)?[<^>])?(\d+%?|~)?([a-z])?$/);
26864    $const_set($nesting[0], 'CellSpecStartRx', /^[ \t]*(?:(\d+(?:\.\d*)?|(?:\d*\.)?\d+)([*+]))?([<^>](?:\.[<^>]?)?|(?:[<^>]?\.)?[<^>])?([a-z])?$/);
26865    $const_set($nesting[0], 'CellSpecEndRx', /[ \t]+(?:(\d+(?:\.\d*)?|(?:\d*\.)?\d+)([*+]))?([<^>](?:\.[<^>]?)?|(?:[<^>]?\.)?[<^>])?([a-z])?$/);
26866    $const_set($nesting[0], 'CustomBlockMacroRx', $regexp(["^(", $$('CG_WORD'), "[", $$('CC_WORD'), "-]*)::(|\\S|\\S", $$('CC_ANY'), "*?\\S)\\[(", $$('CC_ANY'), "+)?\\]$"]));
26867    $const_set($nesting[0], 'BlockMediaMacroRx', $regexp(["^(image|video|audio)::(\\S|\\S", $$('CC_ANY'), "*?\\S)\\[(", $$('CC_ANY'), "+)?\\]$"]));
26868    $const_set($nesting[0], 'BlockTocMacroRx', $regexp(["^toc::\\[(", $$('CC_ANY'), "+)?\\]$"]));
26869    $const_set($nesting[0], 'InlineAnchorRx', $regexp(["(\\\\)?(?:\\[\\[([", $$('CC_ALPHA'), "_:][", $$('CC_WORD'), "\\-:.]*)(?:, *(", $$('CC_ANY'), "+?))?\\]\\]|anchor:([", $$('CC_ALPHA'), "_:][", $$('CC_WORD'), "\\-:.]*)\\[(?:\\]|(", $$('CC_ANY'), "*?[^\\\\])\\]))"]));
26870    $const_set($nesting[0], 'InlineAnchorScanRx', $regexp(["(?:^|[^\\\\\\[])\\[\\[([", $$('CC_ALPHA'), "_:][", $$('CC_WORD'), "\\-:.]*)(?:, *(", $$('CC_ANY'), "+?))?\\]\\]|(?:^|[^\\\\])anchor:([", $$('CC_ALPHA'), "_:][", $$('CC_WORD'), "\\-:.]*)\\[(?:\\]|(", $$('CC_ANY'), "*?[^\\\\])\\])"]));
26871    $const_set($nesting[0], 'LeadingInlineAnchorRx', $regexp(["^\\[\\[([", $$('CC_ALPHA'), "_:][", $$('CC_WORD'), "\\-:.]*)(?:, *(", $$('CC_ANY'), "+?))?\\]\\]"]));
26872    $const_set($nesting[0], 'InlineBiblioAnchorRx', $regexp(["^\\[\\[\\[([", $$('CC_ALPHA'), "_:][", $$('CC_WORD'), "\\-:.]*)(?:, *(", $$('CC_ANY'), "+?))?\\]\\]\\]"]));
26873    $const_set($nesting[0], 'InlineEmailRx', $regexp(["([\\\\>:/])?", $$('CG_WORD'), "(?:&amp;|[", $$('CC_WORD'), "\\-.%+])*@", $$('CG_ALNUM'), "[", $$('CC_ALNUM'), "_\\-.]*\\.[a-zA-Z]{2,5}\\b"]));
26874    $const_set($nesting[0], 'InlineFootnoteMacroRx', $regexp(["\\\\?footnote(?:(ref):|:([", $$('CC_WORD'), "-]+)?)\\[(?:|(", $$('CC_ALL'), "*?[^\\\\]))\\](?!</a>)"], 'm'));
26875    $const_set($nesting[0], 'InlineImageMacroRx', $regexp(["\\\\?i(?:mage|con):([^:\\s\\[](?:[^\\n\\[]*[^\\s\\[])?)\\[(|", $$('CC_ALL'), "*?[^\\\\])\\]"], 'm'));
26876    $const_set($nesting[0], 'InlineIndextermMacroRx', $regexp(["\\\\?(?:(indexterm2?):\\[(", $$('CC_ALL'), "*?[^\\\\])\\]|\\(\\((", $$('CC_ALL'), "+?)\\)\\)(?!\\)))"], 'm'));
26877    $const_set($nesting[0], 'InlineKbdBtnMacroRx', $regexp(["(\\\\)?(kbd|btn):\\[(", $$('CC_ALL'), "*?[^\\\\])\\]"], 'm'));
26878    $const_set($nesting[0], 'InlineLinkRx', $regexp(["(^|link:|", $$('CG_BLANK'), "|&lt;|[>\\(\\)\\[\\];
26878\"'])(\\\\?(?:https?|file|ftp|irc)://)(?:([^\\s\\[\\]]+)\\[(|", $$('CC_ALL'), "*?[^\\\\])\\]|([^\\s\\[\\]<]*([^\\s,.?!\\[\\]<\\)])))"], 'm'));
26879    $const_set($nesting[0], 'InlineLinkMacroRx', $regexp(["\\\\?(?:link|(mailto)):(|[^:\\s\\[][^\\s\\[]*)\\[(|", $$('CC_ALL'), "*?[^\\\\])\\]"], 'm'));
26880    $const_set($nesting[0], 'MacroNameRx', $regexp(["^", $$('CG_WORD'), "[", $$('CC_WORD'), "-]*$"]));
26881    $const_set($nesting[0], 'InlineStemMacroRx', $regexp(["\\\\?(stem|(?:latex|ascii)math):([a-z]+(?:,[a-z-]+)*)?\\[(", $$('CC_ALL'), "*?[^\\\\])\\]"], 'm'));
26882    $const_set($nesting[0], 'InlineMenuMacroRx', $regexp(["\\\\?menu:(", $$('CG_WORD'), "|[", $$('CC_WORD'), "&][^\\n\\[]*[^\\s\\[])\\[ *(?:|(", $$('CC_ALL'), "*?[^\\\\]))\\]"], 'm'));
26883    $const_set($nesting[0], 'InlineMenuRx', $regexp(["\\\\?\"([", $$('CC_WORD'), "&][^\"]*?[ \\n]+&gt;[ \\n]+[^\"]*)\""]));
26884    $const_set($nesting[0], 'InlinePassRx', $hash(false, ["+", "-]", $regexp(["((?:^|[^", $$('CC_WORD'), ";:\\\\])(?=(\\[)|\\+)|\\\\(?=\\[)|(?=\\\\\\+))(?:\\2(x-|[^\\]]+ x-)\\]|(?:\\[([^\\]]+)\\])?(?=(\\\\)?\\+))(\\5?(\\+|`)(\\S|\\S", $$('CC_ALL'), "*?\\S)\\7)(?!", $$('CG_WORD'), ")"], 'm')], true, ["`", nil, $regexp(["(^|[^`", $$('CC_WORD'), "])(?:(\\Z)()|\\[([^\\]]+)\\](?=(\\\\))?)?(\\5?(`)([^`\\s]|[^`\\s]", $$('CC_ALL'), "*?\\S)\\7)(?![`", $$('CC_WORD'), "])"], 'm')]));
26885    $const_set($nesting[0], 'InlinePassMacroRx', $regexp(["(?:(?:(\\\\?)\\[([^\\]]+)\\])?(\\\\{0,2})(\\+\\+\\+?|\\$\\$)(", $$('CC_ALL'), "*?)\\4|(\\\\?)pass:([a-z]+(?:,[a-z-]+)*)?\\[(|", $$('CC_ALL'), "*?[^\\\\])\\])"], 'm'));
26886    $const_set($nesting[0], 'InlineXrefMacroRx', $regexp(["\\\\?(?:&lt;&lt;([", $$('CC_WORD'), "#/.:{]", $$('CC_ALL'), "*?)&gt;&gt;|xref:([", $$('CC_WORD'), "#/.:{]", $$('CC_ALL'), "*?)\\[(?:\\]|(", $$('CC_ALL'), "*?[^\\\\])\\]))"], 'm'));
26887    $const_set($nesting[0], 'HardLineBreakRx', $regexp(["^(", $$('CC_ANY'), "*) \\+$"], 'm'));
26888    $const_set($nesting[0], 'MarkdownThematicBreakRx', /^ {0,3}([-*_])( *)\1\2\1$/);
26889    $const_set($nesting[0], 'ExtLayoutBreakRx', /^(?:'{3,}|<{3,}|([-*_])( *)\1\2\1)$/);
26890    $const_set($nesting[0], 'BlankLineRx', /\n{2,}/);
26891    $const_set($nesting[0], 'EscapedSpaceRx', /\\([ \t\n])/);
26892    $const_set($nesting[0], 'ReplaceableTextRx', /[&']|--|\.\.\.|\([CRT]M?\)/);
26893    $const_set($nesting[0], 'SpaceDelimiterRx', /([^\\])[ \t\n]+/);
26894    $const_set($nesting[0], 'SubModifierSniffRx', /[+-]/);
26895    $const_set($nesting[0], 'TrailingDigitsRx', /\d+$/);
26896    $const_set($nesting[0], 'UriSniffRx', $regexp(["^", $$('CG_ALPHA'), "[", $$('CC_ALNUM'), ".+-]+:/{0,2}"]));
26897    return $const_set($nesting[0], 'XmlSanitizeRx', /<[^>]+>/);
26898  })($nesting[0], $nesting)
26899};
26900
26901Opal.modules["asciidoctor/substitutors"] = function(Opal) {/* Generated by Opal 1.7.3 */
26902  "use strict";
26903  var $module = Opal.module, $const_set = Opal.const_set, $hash2 = Opal.hash2, $hash = Opal.hash, $rb_plus = Opal.rb_plus, $regexp = Opal.regexp, $not = Opal.not, $truthy = Opal.truthy, $send = Opal.send, $def = Opal.def, $alias = Opal.alias, $gvars = Opal.gvars, $eqeq = Opal.eqeq, $to_ary = Opal.to_ary, $neqeq = Opal.neqeq, $to_a = Opal.to_a, $eqeqeq = Opal.eqeqeq, $rb_gt = Opal.rb_gt, $slice = Opal.slice, $rb_minus = Opal.rb_minus, $rb_lt = Opal.rb_lt, $rb_times = Opal.rb_times, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$;
26904
26905  Opal.add_stubs('freeze,+,keys,!,empty?,===,[],join,include?,extract_passthroughs,each,sub_specialchars,sub_quotes,sub_attributes,sub_replacements,sub_macros,highlight_source,sub_callouts,sub_post_replacements,warn,logger,restore_passthroughs,clear,split,apply_subs,gsub,match?,compat_mode,convert_quoted_text,attributes,==,shift,store_attribute,!=,attribute_undefined,counter,key?,downcase,attribute_missing,info,squeeze,delete,reject,start_with?,do_replacement,inline_macros?,extensions,inline_macros,regexp,instance,slice,length,names,config,merge,[]=,normalize_text,parse_attributes,process_method,expand_subs,text=,text,convert,class,strip,index,min,compact,>,end_with?,map,chop,new,pop,rstrip,register,tr,basename,parse,lstrip,split_simple_csv,-,partition,extract_attributes_from_text,sub,encode_uri_component,style,extname?,rindex,catalog,info?,fetch,outfilesuffix,natural_xrefs,resolve_id,find,footnotes,id,<,size,<<,attr?,attr,to_s,read_next_id,callouts,highlight?,syntax_highlighter,sub_source,extract_callouts,name,to_i,to_sym,resolve_lines_to_highlight,highlight,nil_or_empty?,restore_callouts,count,to_a,|,sort,*,parse_quoted_text_attributes,resolve_pass_subs,basebackend?,error,chr,drop,&,resolve_subs,resolve_block_subs,parse_into,private,shorthand_property_syntax,each_char');
26906  return (function($base, $parent_nesting) {
26907    var self = $module($base, 'Asciidoctor');
26908
26909    var $nesting = [self].concat($parent_nesting);
26910
26911    return (function($base, $parent_nesting) {
26912      var self = $module($base, 'Substitutors');
26913
26914      var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
26915
26916      
26917      $const_set($nesting[0], 'SpecialCharsRx', /[<&>]/);
26918      $const_set($nesting[0], 'SpecialCharsTr', $hash2([">", "<", "&"], {">": "&gt;", "<": "&lt;", "&": "&amp;"}));
26919      $const_set($nesting[0], 'QuotedTextSniffRx', $hash(false, /[*_`#^~]/, true, /[*'_+#^~]/));
26920      $const_set($nesting[0], 'BASIC_SUBS', ["specialcharacters"]).$freeze();
26921      $const_set($nesting[0], 'HEADER_SUBS', ["specialcharacters", "attributes"]).$freeze();
26922      $const_set($nesting[0], 'NO_SUBS', []).$freeze();
26923      $const_set($nesting[0], 'NORMAL_SUBS', ["specialcharacters", "quotes", "attributes", "replacements", "macros", "post_replacements"]).$freeze();
26924      $const_set($nesting[0], 'REFTEXT_SUBS', ["specialcharacters", "quotes", "replacements"]).$freeze();
26925      $const_set($nesting[0], 'VERBATIM_SUBS', ["specialcharacters", "callouts"]).$freeze();
26926      $const_set($nesting[0], 'SUB_GROUPS', $hash2(["none", "normal", "verbatim", "specialchars"], {"none": $$('NO_SUBS'), "normal": $$('NORMAL_SUBS'), "verbatim": $$('VERBATIM_SUBS'), "specialchars": $$('BASIC_SUBS')}));
26927      $const_set($nesting[0], 'SUB_HINTS', $hash2(["a", "m", "n", "p", "q", "r", "c", "v"], {"a": "attributes", "m": "macros", "n": "normal", "p": "post_replacements", "q": "quotes", "r": "replacements", "c": "specialcharacters", "v": "verbatim"}));
26928      $const_set($nesting[0], 'SUB_OPTIONS', $hash2(["block", "inline"], {"block": $rb_plus($rb_plus($$('SUB_GROUPS').$keys(), $$('NORMAL_SUBS')), ["callouts"]), "inline": $rb_plus($$('SUB_GROUPS').$keys(), $$('NORMAL_SUBS'))}));
26929      $const_set($nesting[0], 'CAN', "\u0018");
26930      $const_set($nesting[0], 'DEL', "\u007F");
26931      $const_set($nesting[0], 'PASS_START', "\u0096");
26932      $const_set($nesting[0], 'PASS_END', "\u0097");
26933      $const_set($nesting[0], 'PassSlotRx', $regexp([$$('PASS_START'), "(\\d+)", $$('PASS_END')]));
26934      $const_set($nesting[0], 'HighlightedPassSlotRx', $regexp(["<span\\b[^>]*>", $$('PASS_START'), "</span>[^\\d]*(\\d+)[^\\d]*<span\\b[^>]*>", $$('PASS_END'), "</span>"]));
26935      $const_set($nesting[0], 'RS', "\\");
26936      $const_set($nesting[0], 'R_SB', "]");
26937      $const_set($nesting[0], 'ESC_R_SB', "\\]");
26938      $const_set($nesting[0], 'PLUS', "+");
26939      
26940      $def(self, '$apply_subs', function $$apply_subs(text, subs) {
26941        var self = this, is_multiline = nil, passthrus = nil, $ret_or_1 = nil, clear_passthrus = nil;
26942        if (self.passthroughs == null) self.passthroughs = nil;
26943        if (self.passthroughs_locked == null) self.passthroughs_locked = nil;
26944
26945        
26946        if (subs == null) subs = $$('NORMAL_SUBS');
26947        if (($truthy(text['$empty?']()) || ($not(subs)))) {
26948          return text
26949        };
26950        if ($truthy((is_multiline = $$$('Array')['$==='](text)))) {
26951          text = ($truthy(text['$[]'](1)) ? (text.$join($$('LF'))) : (text['$[]'](0)))
26952        };
26953        if ($truthy(subs['$include?']("macros"))) {
26954          
26955          text = self.$extract_passthroughs(text);
26956          if (!$truthy(self.passthroughs['$empty?']())) {
26957            
26958            passthrus = self.passthroughs;
26959            self.passthroughs_locked = ($truthy(($ret_or_1 = self.passthroughs_locked)) ? ($ret_or_1) : ((clear_passthrus = true)));
26960          };
26961        };
26962        $send(subs, 'each', [], function $$1(type){var self = $$1.$$s == null ? this : $$1.$$s;
26963
26964          
26965          if (type == null) type = nil;
26966          
26967          switch (type) {
26968            case "specialcharacters":
26969              return (text = self.$sub_specialchars(text))
26970            case "quotes":
26971              return (text = self.$sub_quotes(text))
26972            case "attributes":
26973              if ($truthy(text['$include?']($$('ATTR_REF_HEAD')))) {
26974                return (text = self.$sub_attributes(text))
26975              } else {
26976                return nil
26977              }
26978              break;
26979            case "replacements":
26980              return (text = self.$sub_replacements(text))
26981            case "macros":
26982              return (text = self.$sub_macros(text))
26983            case "highlight":
26984              return (text = self.$highlight_source(text, subs['$include?']("callouts")))
26985            case "callouts":
26986              if ($truthy(subs['$include?']("highlight"))) {
26987                return nil
26988              } else {
26989                return (text = self.$sub_callouts(text))
26990              }
26991              break;
26992            case "post_replacements":
26993              return (text = self.$sub_post_replacements(text))
26994            default:
26995              return self.$logger().$warn("unknown substitution type " + (type))
26996          };}, {$$s: self});
26997        if ($truthy(passthrus)) {
26998          
26999          text = self.$restore_passthroughs(text);
27000          if ($truthy(clear_passthrus)) {
27001            
27002            passthrus.$clear();
27003            self.passthroughs_locked = nil;
27004          };
27005        };
27006        if ($truthy(is_multiline)) {
27007          
27008          return text.$split($$('LF'), -1);
27009        } else {
27010          return text
27011        };
27012      }, -2);
27013      
27014      $def(self, '$apply_normal_subs', function $$apply_normal_subs(text) {
27015        var self = this;
27016
27017        return self.$apply_subs(text, $$('NORMAL_SUBS'))
27018      });
27019      
27020      $def(self, '$apply_header_subs', function $$apply_header_subs(text) {
27021        var self = this;
27022
27023        return self.$apply_subs(text, $$('HEADER_SUBS'))
27024      });
27025      $alias(self, "apply_title_subs", "apply_subs");
27026      
27027      $def(self, '$apply_reftext_subs', function $$apply_reftext_subs(text) {
27028        var self = this;
27029
27030        return self.$apply_subs(text, $$('REFTEXT_SUBS'))
27031      });
27032      
27033      $def(self, '$sub_specialchars', function $$sub_specialchars(text) {
27034        
27035        if ((($truthy(text['$include?'](">")) || ($truthy(text['$include?']("&")))) || ($truthy(text['$include?']("<"))))) {
27036          
27037          return text.$gsub($$('SpecialCharsRx'), $$('SpecialCharsTr'));
27038        } else {
27039          return text
27040        }
27041      });
27042      $alias(self, "sub_specialcharacters", "sub_specialchars");
27043      
27044      $def(self, '$sub_quotes', function $$sub_quotes(text) {
27045        var self = this, compat = nil;
27046        if (self.document == null) self.document = nil;
27047
27048        
27049        if ($truthy($$('QuotedTextSniffRx')['$[]']((compat = self.document.$compat_mode()))['$match?'](text))) {
27050          $send($$('QUOTE_SUBS')['$[]'](compat), 'each', [], function $$2(type, scope, pattern){var self = $$2.$$s == null ? this : $$2.$$s;
27051
27052            
27053            if (type == null) type = nil;
27054            if (scope == null) scope = nil;
27055            if (pattern == null) pattern = nil;
27056            return (text = $send(text, 'gsub', [pattern], function $$3(){var self = $$3.$$s == null ? this : $$3.$$s;
27057              if ($gvars["~"] == null) $gvars["~"] = nil;
27058
27059              return self.$convert_quoted_text($gvars["~"], type, scope)}, {$$s: self}));}, {$$s: self})
27060        };
27061        return text;
27062      });
27063      
27064      $def(self, '$sub_attributes', function $$sub_attributes(text, opts) {
27065        var self = this, doc_attrs = nil, drop = nil, drop_line = nil, drop_line_severity = nil, drop_empty_line = nil, attribute_undefined = nil, attribute_missing = nil, lines = nil;
27066        if (self.document == null) self.document = nil;
27067
27068        
27069        if (opts == null) opts = $hash2([], {});
27070        doc_attrs = self.document.$attributes();
27071        drop = (drop_line = (drop_line_severity = (drop_empty_line = (attribute_undefined = (attribute_missing = nil)))));
27072        text = $send(text, 'gsub', [$$('AttributeReferenceRx')], function $$4(){var $a, $b, self = $$4.$$s == null ? this : $$4.$$s, args = nil, $ret_or_2 = nil, _ = nil, value = nil, $ret_or_3 = nil, key = nil, $ret_or_4 = nil;
27073          if (self.document == null) self.document = nil;
27074
27075          if (($eqeq((($a = $gvars['~']) === nil ? nil : $a['$[]'](1)), $$('RS')) || ($eqeq((($a = $gvars['~']) === nil ? nil : $a['$[]'](4)), $$('RS'))))) {
27076            return "{" + ((($a = $gvars['~']) === nil ? nil : $a['$[]'](2))) + "}"
27077          } else if ($truthy((($a = $gvars['~']) === nil ? nil : $a['$[]'](3)))) {
27078            
27079            switch ((args = (($a = $gvars['~']) === nil ? nil : $a['$[]'](2)).$split(":", 3)).$shift()) {
27080              case "set":
27081                
27082                $b = $$('Parser').$store_attribute(args['$[]'](0), ($truthy(($ret_or_2 = args['$[]'](1))) ? ($ret_or_2) : ("")), self.document), $a = $to_ary($b), (_ = ($a[0] == null ? nil : $a[0])), (value = ($a[1] == null ? nil : $a[1])), $b;
27083                if (($truthy(value) || ($neqeq((attribute_undefined = ($truthy(($ret_or_2 = attribute_undefined)) ? ($ret_or_2) : (($truthy(($ret_or_3 = doc_attrs['$[]']("attribute-undefined"))) ? ($ret_or_3) : ($$('Compliance').$attribute_undefined()))))), "drop-line")))) {
27084                  return (drop = (drop_empty_line = $$('DEL')))
27085                } else {
27086                  return (drop = (drop_line = $$('CAN')))
27087                };
27088                break;
27089              case "counter2":
27090                
27091                $send(self.document, 'counter', $to_a(args));
27092                return (drop = (drop_empty_line = $$('DEL')));
27093              default:
27094                return $send(self.document, 'counter', $to_a(args))
27095            }
27096          } else if ($truthy(doc_attrs['$key?']((key = (($a = $gvars['~']) === nil ? nil : $a['$[]'](2)).$downcase())))) {
27097            return doc_attrs['$[]'](key)
27098          } else if ($truthy((value = $$('INTRINSIC_ATTRIBUTES')['$[]'](key)))) {
27099            return value
27100          } else 
27101          switch ((attribute_missing = ($truthy(($ret_or_2 = attribute_missing)) ? ($ret_or_2) : (($truthy(($ret_or_3 = ($truthy(($ret_or_4 = opts['$[]']("attribute_missing"))) ? ($ret_or_4) : (doc_attrs['$[]']("attribute-missing"))))) ? ($ret_or_3) : ($$('Compliance').$attribute_missing())))))) {
27102            case "drop":
27103              return (drop = (drop_empty_line = $$('DEL')))
27104            case "drop-line":
27105              
27106              if ($eqeq((drop_line_severity = ($truthy(($ret_or_2 = drop_line_severity)
27106) ? ($ret_or_2) : (($truthy(($ret_or_3 = opts['$[]']("drop_line_severity"))) ? ($ret_or_3) : ("info"))))), "info")) {
27107                $send(self.$logger(), 'info', [], function $$5(){
27108                  return "dropping line containing reference to missing attribute: " + (key)})
27109              };
27110              return (drop = (drop_line = $$('CAN')));
27111            case "warn":
27112              
27113              self.$logger().$warn("skipping reference to missing attribute: " + (key));
27114              return (($a = $gvars['~']) === nil ? nil : $a['$[]'](0));
27115            default:
27116              return (($a = $gvars['~']) === nil ? nil : $a['$[]'](0))
27117          }}, {$$s: self});
27118        if ($truthy(drop)) {
27119          if ($truthy(drop_empty_line)) {
27120            
27121            lines = text.$squeeze($$('DEL')).$split($$('LF'), -1);
27122            if ($truthy(drop_line)) {
27123              return $send(lines, 'reject', [], function $$6(line){var $ret_or_1 = nil, $ret_or_2 = nil, $ret_or_3 = nil;
27124
27125                
27126                if (line == null) line = nil;
27127                if ($truthy(($ret_or_1 = ($truthy(($ret_or_2 = ($truthy(($ret_or_3 = line['$==']($$('DEL')))) ? ($ret_or_3) : (line['$==']($$('CAN')))))) ? ($ret_or_2) : (line['$start_with?']($$('CAN'))))))) {
27128                  return $ret_or_1
27129                } else {
27130                  
27131                  return line['$include?']($$('CAN'));
27132                };}).$join($$('LF')).$delete($$('DEL'))
27133            } else {
27134              return $send(lines, 'reject', [], function $$7(line){
27135                
27136                if (line == null) line = nil;
27137                return line['$==']($$('DEL'));}).$join($$('LF')).$delete($$('DEL'))
27138            };
27139          } else if ($truthy(text['$include?']($$('LF')))) {
27140            return $send(text.$split($$('LF'), -1), 'reject', [], function $$8(line){var $ret_or_1 = nil, $ret_or_2 = nil;
27141
27142              
27143              if (line == null) line = nil;
27144              if ($truthy(($ret_or_1 = ($truthy(($ret_or_2 = line['$==']($$('CAN')))) ? ($ret_or_2) : (line['$start_with?']($$('CAN'))))))) {
27145                return $ret_or_1
27146              } else {
27147                
27148                return line['$include?']($$('CAN'));
27149              };}).$join($$('LF'))
27150          } else {
27151            return ""
27152          }
27153        } else {
27154          return text
27155        };
27156      }, -2);
27157      
27158      $def(self, '$sub_replacements', function $$sub_replacements(text) {
27159        var self = this;
27160
27161        
27162        if ($truthy($$('ReplaceableTextRx')['$match?'](text))) {
27163          $send($$('REPLACEMENTS'), 'each', [], function $$9(pattern, replacement, restore){var self = $$9.$$s == null ? this : $$9.$$s;
27164
27165            
27166            if (pattern == null) pattern = nil;
27167            if (replacement == null) replacement = nil;
27168            if (restore == null) restore = nil;
27169            return (text = $send(text, 'gsub', [pattern], function $$10(){var self = $$10.$$s == null ? this : $$10.$$s;
27170              if ($gvars["~"] == null) $gvars["~"] = nil;
27171
27172              return self.$do_replacement($gvars["~"], replacement, restore)}, {$$s: self}));}, {$$s: self})
27173        };
27174        return text;
27175      });
27176      
27177      $def(self, '$sub_macros', function $$sub_macros(text) {
27178        var self = this, found_square_bracket = nil, found_colon = nil, found_macroish = nil, $ret_or_1 = nil, found_macroish_short = nil, doc_attrs = nil, doc = nil, extensions = nil;
27179        if (self.document == null) self.document = nil;
27180        if (self.parent == null) self.parent = nil;
27181        if (self.context == null) self.context = nil;
27182
27183        
27184        found_square_bracket = text['$include?']("[");
27185        found_colon = text['$include?'](":");
27186        found_macroish = ($truthy(($ret_or_1 = found_square_bracket)) ? (found_colon) : ($ret_or_1));
27187        found_macroish_short = ($truthy(($ret_or_1 = found_macroish)) ? (text['$include?'](":[")) : ($ret_or_1));
27188        doc_attrs = (doc = self.document).$attributes();
27189        if (($truthy((extensions = doc.$extensions())) && ($truthy(extensions['$inline_macros?']())))) {
27190          $send(extensions.$inline_macros(), 'each', [], function $$11(extension){var self = $$11.$$s == null ? this : $$11.$$s;
27191
27192            
27193            if (extension == null) extension = nil;
27194            return (text = $send(text, 'gsub', [extension.$instance().$regexp()], function $$12(){var $a, $b, self = $$12.$$s == null ? this : $$12.$$s, match = nil, target = nil, content = nil, attributes = nil, default_attrs = nil, ext_config = nil, $ret_or_2 = nil, replacement = nil, inline_subs = nil;
27195              if ($gvars["~"] == null) $gvars["~"] = nil;
27196
27197              
27198              if ($truthy((match = (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)))['$start_with?']($$('RS')))) {
27199                return (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$slice(1, (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$length())
27200              };
27201              if ($truthy($gvars["~"].$names()['$empty?']())) {
27202                $a = [(($b = $gvars['~']) === nil ? nil : $b['$[]'](1)), (($b = $gvars['~']) === nil ? nil : $b['$[]'](2))], (target = $a[0]), (content = $a[1]), $a
27203              } else {
27204                $a = [(function() { try {
27205                  return $gvars["~"]['$[]']("target")
27206                } catch ($err) {
27207                  if (Opal.rescue($err, [$$('StandardError')])) {
27208                    try {
27209                      return nil
27210                    } finally { Opal.pop_exception(); }
27211                  } else { throw $err; }
27212                }})(), (function() { try {
27213                  return $gvars["~"]['$[]']("content")
27214                } catch ($err) {
27215                  if (Opal.rescue($err, [$$('StandardError')])) {
27216                    try {
27217                      return nil
27218                    } finally { Opal.pop_exception(); }
27219                  } else { throw $err; }
27220                }})()], (target = $a[0]), (content = $a[1]), $a
27221              };
27222              attributes = ($truthy((default_attrs = (ext_config = extension.$config())['$[]']("default_attrs"))) ? (default_attrs.$merge()) : ($hash2([], {})));
27223              if ($truthy(content)) {
27224                
27225                if ($truthy(content['$empty?']())) {
27226                  if (!$eqeq(ext_config['$[]']("content_model"), "attributes")) {
27227                    attributes['$[]=']("text", content)
27228                  }
27229                } else {
27230                  
27231                  content = self.$normalize_text(content, true, true);
27232                  if ($eqeq(ext_config['$[]']("content_model"), "attributes")) {
27233                    self.$parse_attributes(content, ($truthy(($ret_or_1 = ($truthy(($ret_or_2 = ext_config['$[]']("positional_attrs"))) ? ($ret_or_2) : (ext_config['$[]']("pos_attrs"))))) ? ($ret_or_1) : ([])), $hash2(["into"], {"into": attributes}))
27234                  } else {
27235                    attributes['$[]=']("text", content)
27236                  };
27237                };
27238                target = ($truthy(($ret_or_1 = target)) ? ($ret_or_1) : ($eqeq(ext_config['$[]']("format"), "short") ? (content) : (target)));
27239              };
27240              if ($eqeqeq($$('Inline'), (replacement = extension.$process_method()['$[]'](self, target, attributes)))) {
27241                
27242                if (($truthy((inline_subs = replacement.$attributes().$delete("subs"))) && ($truthy((inline_subs = self.$expand_subs(inline_subs, "custom inline macro")))))) {
27243                  replacement['$text='](self.$apply_subs(replacement.$text(), inline_subs))
27244                };
27245                return replacement.$convert();
27246              } else if ($truthy(replacement)) {
27247                
27248                $send(self.$logger(), 'info', [], function $$13(){
27249                  return "expected substitution value for custom inline macro to be of type Inline; got " + (replacement.$class()) + ": " + (match)});
27250                return replacement;
27251              } else {
27252                return ""
27253              };}, {$$s: self}));}, {$$s: self})
27254        };
27255        if ($truthy(doc_attrs['$key?']("experimental"))) {
27256          
27257          if (($truthy(found_macroish_short) && (($truthy(text['$include?']("kbd:")) || ($truthy(text['$include?']("bt
27257n:"))))))) {
27258            text = $send(text, 'gsub', [$$('InlineKbdBtnMacroRx')], function $$14(){var $a, self = $$14.$$s == null ? this : $$14.$$s, keys = nil, delim_idx = nil, delim = nil;
27259
27260              if ($truthy((($a = $gvars['~']) === nil ? nil : $a['$[]'](1)))) {
27261                return (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$slice(1, (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$length())
27262              } else if ($eqeq((($a = $gvars['~']) === nil ? nil : $a['$[]'](2)), "kbd")) {
27263                
27264                if ($truthy((keys = (($a = $gvars['~']) === nil ? nil : $a['$[]'](3)).$strip())['$include?']($$('R_SB')))) {
27265                  keys = keys.$gsub($$('ESC_R_SB'), $$('R_SB'))
27266                };
27267                if (($truthy($rb_gt(keys.$length(), 1)) && ($truthy((delim_idx = ($truthy((delim_idx = keys.$index(",", 1))) ? ([delim_idx, keys.$index("+", 1)].$compact().$min()) : (keys.$index("+", 1)))))))) {
27268                  
27269                  delim = keys.$slice(delim_idx, 1);
27270                  if ($truthy(keys['$end_with?'](delim))) {
27271                    
27272                    keys = $send(keys.$chop().$split(delim, -1), 'map', [], function $$15(key){
27273                      
27274                      if (key == null) key = nil;
27275                      return key.$strip();});
27276                    keys['$[]='](-1, $rb_plus(keys['$[]'](-1), delim));
27277                  } else {
27278                    keys = $send(keys.$split(delim), 'map', [], function $$16(key){
27279                      
27280                      if (key == null) key = nil;
27281                      return key.$strip();})
27282                  };
27283                } else {
27284                  keys = [keys]
27285                };
27286                return $$('Inline').$new(self, "kbd", nil, $hash2(["attributes"], {"attributes": $hash2(["keys"], {"keys": keys})})).$convert();
27287              } else {
27288                return $$('Inline').$new(self, "button", self.$normalize_text((($a = $gvars['~']) === nil ? nil : $a['$[]'](3)), true, true)).$convert()
27289              }}, {$$s: self})
27290          };
27291          if (($truthy(found_macroish) && ($truthy(text['$include?']("menu:"))))) {
27292            text = $send(text, 'gsub', [$$('InlineMenuMacroRx')], function $$17(){var $a, self = $$17.$$s == null ? this : $$17.$$s, menu = nil, items = nil, delim = nil, submenus = nil, menuitem = nil;
27293
27294              
27295              if ($truthy((($a = $gvars['~']) === nil ? nil : $a['$[]'](0))['$start_with?']($$('RS')))) {
27296                return (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$slice(1, (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$length())
27297              };
27298              menu = (($a = $gvars['~']) === nil ? nil : $a['$[]'](1));
27299              if ($truthy((items = (($a = $gvars['~']) === nil ? nil : $a['$[]'](2))))) {
27300                
27301                if ($truthy(items['$include?']($$('R_SB')))) {
27302                  items = items.$gsub($$('ESC_R_SB'), $$('R_SB'))
27303                };
27304                if ($truthy((delim = ($truthy(items['$include?']("&gt;")) ? ("&gt;") : (($truthy(items['$include?'](",")) ? (",") : (nil))))))) {
27305                  
27306                  submenus = $send(items.$split(delim), 'map', [], function $$18(it){
27307                    
27308                    if (it == null) it = nil;
27309                    return it.$strip();});
27310                  menuitem = submenus.$pop();
27311                } else {
27312                  $a = [[], items.$rstrip()], (submenus = $a[0]), (menuitem = $a[1]), $a
27313                };
27314              } else {
27315                $a = [[], nil], (submenus = $a[0]), (menuitem = $a[1]), $a
27316              };
27317              return $$('Inline').$new(self, "menu", nil, $hash2(["attributes"], {"attributes": $hash2(["menu", "submenus", "menuitem"], {"menu": menu, "submenus": submenus, "menuitem": menuitem})})).$convert();}, {$$s: self})
27318          };
27319          if (($truthy(text['$include?']("\"")) && ($truthy(text['$include?']("&gt;"))))) {
27320            text = $send(text, 'gsub', [$$('InlineMenuRx')], function $$19(){var $a, $b, $c, self = $$19.$$s == null ? this : $$19.$$s, menu = nil, submenus = nil, menuitem = nil;
27321
27322              
27323              if ($truthy((($a = $gvars['~']) === nil ? nil : $a['$[]'](0))['$start_with?']($$('RS')))) {
27324                return (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$slice(1, (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$length())
27325              };
27326              $b = $send((($c = $gvars['~']) === nil ? nil : $c['$[]'](1)).$split("&gt;"), 'map', [], function $$20(it){
27327                
27328                if (it == null) it = nil;
27329                return it.$strip();}), $a = $to_ary($b), (menu = ($a[0] == null ? nil : $a[0])), (submenus = $slice($a, 1)), $b;
27330              menuitem = submenus.$pop();
27331              return $$('Inline').$new(self, "menu", nil, $hash2(["attributes"], {"attributes": $hash2(["menu", "submenus", "menuitem"], {"menu": menu, "submenus": submenus, "menuitem": menuitem})})).$convert();}, {$$s: self})
27332          };
27333        };
27334        if (($truthy(found_macroish) && (($truthy(text['$include?']("image:")) || ($truthy(text['$include?']("icon:"))))))) {
27335          text = $send(text, 'gsub', [$$('InlineImageMacroRx')], function $$21(){var $a, self = $$21.$$s == null ? this : $$21.$$s, type = nil, posattrs = nil, target = nil, attrs = nil;
27336
27337            
27338            if ($truthy((($a = $gvars['~']) === nil ? nil : $a['$[]'](0))['$start_with?']($$('RS')))) {
27339              return (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$slice(1, (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$length())
27340            } else if ($truthy((($a = $gvars['~']) === nil ? nil : $a['$[]'](0))['$start_with?']("icon:"))) {
27341              $a = ["icon", ["size"]], (type = $a[0]), (posattrs = $a[1]), $a
27342            } else {
27343              $a = ["image", ["alt", "width", "height"]], (type = $a[0]), (posattrs = $a[1]), $a
27344            };
27345            target = (($a = $gvars['~']) === nil ? nil : $a['$[]'](1));
27346            attrs = self.$parse_attributes((($a = $gvars['~']) === nil ? nil : $a['$[]'](2)), posattrs, $hash2(["unescape_input"], {"unescape_input": true}));
27347            if (!$eqeq(type, "icon")) {
27348              
27349              doc.$register("images", target);
27350              attrs['$[]=']("imagesdir", doc_attrs['$[]']("imagesdir"));
27351            };
27352            if ($truthy(($ret_or_1 = attrs['$[]']("alt")))) {
27353              $ret_or_1
27354            } else {
27355              attrs['$[]=']("alt", ($a = ["default-alt", $$('Helpers').$basename(target, true).$tr("_-", " ")], $send(attrs, '[]=', $a), $a[$a.length - 1]))
27356            };
27357            return $$('Inline').$new(self, "image", nil, $hash2(["type", "target", "attributes"], {"type": type, "target": target, "attributes": attrs})).$convert();}, {$$s: self})
27358        };
27359        if ((($truthy(text['$include?']("((")) && ($truthy(text['$include?']("))")))) || (($truthy(found_macroish_short) && ($truthy(text['$include?']("dexterm"))))))) {
27360          text = $send(text, 'gsub', [$$('InlineIndextermMacroRx')], function $$22(){var $a, $b, self = $$22.$$s == null ? this : $$22.$$s, attrlist = nil, primary = nil, attrs = nil, see_also = nil, term = nil, $ret_or_2 = nil, $ret_or_3 = nil, encl_text = nil, visible = nil, before = nil, after = nil, _ = nil, see = nil, subbed_term = nil, terms = nil;
27361
27362            
27363            switch ((($a = $gvars['~']) === nil ? nil : $a['$[]'](1))) {
27364              case "indexterm":
27365                
27366                if ($truthy((($a = $gvars['~']) === nil ? nil : $a['$[]'](0))['$start_with?']($$('RS')))) {
27367                  return (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$slice(1, (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$length())
27368                };
27369                if ($truthy((attrlist = self.$normalize_text((($a = $gvars['~']) === nil ? nil : $a['$[]'](2)), true, true))['$include?']("="))) {
27370                  if ($truthy((primary = (attrs = $$('AttributeList').$new(attrlist, self).$parse())['$[]'](1)))) {
27371                    
27372                    attrs['$[]=']("terms", [primary]);
27373                    if ($truthy((see_also = attrs['$[]']("see-also")))) {
27374                      attrs['$[]=']("see-also", ($truthy(see_also['$include?'](",")) ? ($send(see_also.$split(","), 'map', [], function $$23(it){
27375                        
27376                        if (it == null) it = nil;
27377                        return it.$lstrip();})) : ([see_also])))
27378                    };
27379                  } else {
27380                    attrs = $hash2(["terms"], {"terms": attrlist})
27381                  }
27382                } else {
27383                  attrs = $hash2(["terms"], {"terms": self.$split_simple_csv(attrlist)})
27384                };
27385                return $$('Inline').$new(self, "indexterm", nil, $hash2(["attributes"], {"attributes": attrs})).$convert();
27386              case "indexterm2":
27387                
27388                if ($truthy((($a = $gvars['~']) === nil ? nil : $a['$[]'](0))['$start_with?']($$('RS')))) {
27389                  return (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$slice(1, (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$length())
27390                };
27391                if ($truthy((term = self.$normalize_text((($a = $gvars['~']) === nil ? nil : $a['$[]'](2)), true, true))['$include?']("="))) {
27392                  
27393                  term = ($truthy(($ret_or_2 = ($truthy(($ret_or_3 = (attrs = $$('AttributeList').$new(term, self).$parse())['$[]'](1))) ? ($ret_or_3) : ((attrs = nil))))) ? ($ret_or_2) : (term));
27394                  if (($truthy(attrs) && ($truthy((see_also = attrs['$[]']("see-also")))))) {
27395                    attrs['$[]=']("see-also", ($truthy(see_also['$include?'](",")) ? ($send(see_also.$split(","), 'map', [], function $$24(it){
27396                      
27397                      if (it == null) it = nil;
27398                      return it.$lstrip();})) : ([see_also])))
27399                  };
27400                };
27401                return $$('Inline').$new(self, "indexterm", term, $hash2(["attributes", "type"], {"attributes": attrs, "type": "visible"})).$convert();
27402              default:
27403                
27404                encl_text = (($a = $gvars['~']) === nil ? nil : $a['$[]'](3));
27405                if ($truthy((($a = $gvars['~']) === nil ? nil : $a['$[]'](0))['$start_with?']($$('RS')))) {
27406                  if (($truthy(encl_text['$start_with?']("(")) && ($truthy(encl_text['$end_with?'](")"))))) {
27407                    
27408                    encl_text = encl_text.$slice(1, $rb_minus(encl_text.$length(), 2));
27409                    $a = [true, "(", ")"], (visible = $a[0]), (before = $a[1]), (after = $a[2]), $a;
27410                  } else {
27411                    return (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$slice(1, (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$length())
27412                  }
27413                } else {
27414                  
27415                  visible = true;
27416                  if ($truthy(encl_text['$start_with?']("("))) {
27417                    if ($truthy(encl_text['$end_with?'](")"))) {
27418                      $a = [encl_text.$slice(1, $rb_minus(encl_text.$length(), 2)), false], (encl_text = $a[0]), (visible = $a[1]), $a
27419                    } else {
27420                      $a = [encl_text.$slice(1, encl_text.$length()), "(", ""], (encl_text = $a[0]), (before = $a[1]), (after = $a[2]), $a
27421                    }
27422                  } else if ($truthy(encl_text['$end_with?'](")"))) {
27423                    $a = [encl_text.$chop(), "", ")"], (encl_text = $a[0]), (before = $a[1]), (after = $a[2]), $a
27424                  };
27425                };
27426                if ($truthy(visible)) {
27427                  
27428                  if ($truthy((term = self.$normalize_text(encl_text, true))['$include?'](";&"))) {
27429                    if ($truthy(term['$include?'](" &gt;&gt; "))) {
27430                      
27431                      $b = term.$partition(" &gt;&gt; "), $a = $to_ary($b), (term = ($a[0] == null ? nil : $a[0])), (_ = ($a[1] == null ? nil : $a[1])), (see = ($a[2] == null ? nil : $a[2])), $b;
27432                      attrs = $hash2(["see"], {"see": see});
27433                    } else if ($truthy(term['$include?'](" &amp;&gt; "))) {
27434                      
27435                      $b = term.$split(" &amp;&gt; "), $a = $to_ary($b), (term = ($a[0] == null ? nil : $a[0])), (see_also = $slice($a, 1)), $b;
27436                      attrs = $hash2(["see-also"], {"see-also": see_also});
27437                    }
27438                  };
27439                  subbed_term = $$('Inline').$new(self, "indexterm", term, $hash2(["attributes", "type"], {"attributes": attrs, "type": "visible"})).$convert();
27440                } else {
27441                  
27442                  attrs = $hash2([], {});
27443                  if ($truthy((terms = self.$normalize_text(encl_text, true))['$include?'](";&"))) {
27444                    if ($truthy(terms['$include?'](" &gt;&gt; "))) {
27445                      
27446                      $b = terms.$partition(" &gt;&gt; "), $a = $to_ary($b), (terms = ($a[0] == null ? nil : $a[0])), (_ = ($a[1] == null ? nil : $a[1])), (see = ($a[2] == null ? nil : $a[2])), $b;
27447                      attrs['$[]=']("see", see);
27448                    } else if ($truthy(terms['$include?'](" &amp;&gt; "))) {
27449                      
27450                      $b = terms.$split(" &amp;&gt; "), $a = $to_ary($b), (terms = ($a[0] == null ? nil : $a[0])), (see_also = $slice($a, 1)), $b;
27451                      attrs['$[]=']("see-also", see_also);
27452                    }
27453                  };
27454                  attrs['$[]=']("terms", self.$split_simple_csv(terms));
27455                  subbed_term = $$('Inline').$new(self, "indexterm", nil, $hash2(["attributes"], {"attributes": attrs})).$convert();
27456                };
27457                if ($truthy(before)) {
27458                  return "" + (before) + (subbed_term) + (after)
27459                } else {
27460                  return subbed_term
27461                };
27462            }}, {$$s: self})
27463        };
27464        if (($truthy(found_colon) && ($truthy(text['$include?']("://"))))) {
27465          text = $send(text, 'gsub', [$$('InlineLinkRx')], function $$25(){var $a, $b, self = $$25.$$s == null ? this : $$25.$$s, target = nil, rs_idx = nil, prefix = nil, suffix = nil, link_text = nil, attrs = nil, link_opts = nil, new_link_text = nil, bare = nil;
27466
27467            
27468            if ($truthy((target = $rb_plus((($a = $gvars['~']) === nil ? nil : $a['$[]'](2)), ($truthy(($ret_or_1 = (($a = $gvars['~']) === nil ? nil : $a['$[]'](3)))) ? ($ret_or_1) : ((($a = $gvars['~']) === nil ? nil : $a['$[]'](5))))))['$start_with?']($$('RS')))) {
27469              return $rb_plus((($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$slice(0, (rs_idx = (($a = $gvars['~']) === nil ? nil : $a['$[]'](1)).$length())), (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$slice($rb_plus(rs_idx, 1), (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$length()))
27470            };
27471            $a = [(($b = $gvars['~']) === nil ? nil : $b['$[]'](1)), ""], (prefix = $a[0]), (suffix = $a[1]), $a;
27472            if ($truthy((($a = $gvars['~']) === nil ? nil : $a['$[]'](4)))) {
27473              
27474              if ($eqeq(prefix, "link:")) {
27475                prefix = ""
27476              };
27477              if ($truthy((link_text = (($a = $gvars['~']) === nil ? nil : $a['$[]'](4)))['$empty?']())) {
27478                link_text = nil
27479              };
27480            } else {
27481              
27482              
27483              switch (prefix) {
27484                case "link:":
27485                case "\"":
27486                case "'":
27487                  return (($a = $gvars['~']) === nil ? nil : $a['$[]'](0))
27488                default:
27489                  nil
27490              };
27491              
27492              switch ((($a = $gvars['~']) === nil ? nil : $a['$[]'](6))) {
27493                case ";":
27494                  
27495                  if (($truthy(prefix['$start_with?']("&lt;")) && ($truthy(target['$end_with?']("&gt;"))))) {
27496                    
27497                    prefix = prefix.$slice(4, prefix.$length());
27498                    target = target.$slice(0, $rb_minus(target.$length(), 4));
27499                  } else if ($truthy((target = target.$chop())['$end_with?'](")"))) {
27500                    
27501                    target = target.$chop();
27502                    suffix = ");";
27503                  } else {
27504                    suffix = ";"
27505                  };
27506                  if ($truthy(target['$end_with?']("://"))) {
27507                    return (($a = $gvars['~']) === nil ? nil : $a['$[]'](0))
27508                  };
27509                  break;
27510                case ":":
27511                  
27512                  if ($truthy((target = target.$chop())['$end_with?'](")"))) {
27513                    
27514                    target = target.$chop();
27515                    suffix = "):";
27516                  } else {
27517                    suffix = ":"
27518                  };
27519                  if ($truthy(target['$end_with?']("://"))) {
27520                    return (($a = $gvars['~']) === nil ? nil : $a['$[]'](0))
27521                  };
27522                  break;
27523                default:
27524                  nil
27525              };
27526            };
27527            $a = [nil, $hash2(["type"], {"type": "link"})], (attrs = $a[0]), (link_opts = $a[1]), $a;
27528            if ($truthy(link_text)) {
27529              
27530              if ($truthy(link_text['$include?']($$('R_SB')))) {
27531                new_link_text = (link_text = link_text.$gsub($$('ESC_R_SB'), $$('R_SB')))
27532              };
27533              if (($not(doc.$compat_mode()) && ($truthy(link_text['$include?']("="))))) {
27534                
27535                $b = self.$extract_attributes_from_text(link_text, ""), $a = $to_ary($b), (link_text = ($a[0] == null ? nil : $a[0])), (attrs = ($a[1] == null ? nil : $a[1])), $b;
27536                new_link_text = link_text;
27537                link_opts['$[]=']("id", attrs['$[]']("id"));
27538              };
27539              if ($truthy(link_text['$end_with?']("^"))) {
27540                
27541                new_link_text = (link_text = link_text.$chop());
27542                if ($truthy(attrs)) {
27543                  if ($truthy(($ret_or_1 = attrs['$[]']("window")))) {
27544                    $ret_or_1
27545                  } else {
27546                    attrs['$[]=']("window", "_blank")
27547                  }
27548                } else {
27549                  attrs = $hash2(["window"], {"window": "_blank"})
27550                };
27551              };
27552              if (($truthy(new_link_text) && ($truthy(new_link_text['$empty?']())))) {
27553                
27554                link_text = ($truthy(doc_attrs['$key?']("hide-uri-scheme")) ? (target.$sub($$('UriSniffRx'), "")) : (target));
27555                bare = true;
27556              };
27557            } else {
27558              
27559              link_text = ($truthy(doc_attrs['$key?']("hide-uri-scheme")) ? (target.$sub($$('UriSniffRx'), "")) : (target));
27560              bare = true;
27561            };
27562            if ($truthy(bare)) {
27563              if ($truthy(attrs)) {
27564                attrs['$[]=']("role", ($truthy(attrs['$key?']("role")) ? ("bare " + (attrs['$[]']("role"))) : ("bare")))
27565              } else {
27566                attrs = $hash2(["role"], {"role": "bare"})
27567              }
27568            };
27569            doc.$register("links", ($a = ["target", target], $send(link_opts, '[]=', $a), $a[$a.length - 1]));
27570            if ($truthy(attrs)) {
27571              link_opts['$[]=']("attributes", attrs)
27572            };
27573            return "" + (prefix) + ($$('Inline').$new(self, "anchor", link_text, link_opts).$convert()) + (suffix);}, {$$s: self})
27574        };
27575        if (($truthy(found_macroish) && (($truthy(text['$include?']("link:")) || ($truthy(text['$include?']("ilto:"))))))) {
27576          text = $send(text, 'gsub', [$$('InlineLinkMacroRx')], function $$26(){var $a, $b, self = $$26.$$s == null ? this : $$26.$$s, mailto = nil, target = nil, mailto_text = nil, attrs = nil, link_opts = nil, link_text = nil;
27577
27578            
27579            if ($truthy((($a = $gvars['~']) === nil ? nil : $a['$[]'](0))['$start_with?']($$('RS')))) {
27580              return (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$slice(1, (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$length())
27581            } else if ($truthy((mailto = (($a = $gvars['~']) === nil ? nil : $a['$[]'](1))))) {
27582              target = $rb_plus("mailto:", (mailto_text = (($a = $gvars['~']) === nil ? nil : $a['$[]'](2))))
27583            } else {
27584              target = (($a = $gvars['~']) === nil ? nil : $a['$[]'](2))
27585            };
27586            $a = [nil, $hash2(["type"], {"type": "link"})], (attrs = $a[0]), (link_opts = $a[1]), $a;
27587            if (!$truthy((link_text = (($a = $gvars['~']) === nil ? nil : $a['$[]'](3)))['$empty?']())) {
27588              
27589              if ($truthy(link_text['$include?']($$('R_SB')))) {
27590                link_text = link_text.$gsub($$('ESC_R_SB'), $$('R_SB'))
27591              };
27592              if ($truthy(mailto)) {
27593                if (($not(doc.$compat_mode()) && ($truthy(link_text['$include?'](","))))) {
27594                  
27595                  $b = self.$extract_attributes_from_text(link_text, ""), $a = $to_ary($b), (link_text = ($a[0] == null ? nil : $a[0])), (attrs = ($a[1] == null ? nil : $a[1])), $b;
27596                  link_opts['$[]=']("id", attrs['$[]']("id"));
27597                  if ($truthy(attrs['$key?'](2))) {
27598                    if ($truthy(attrs['$key?'](3))) {
27599                      target = "" + (target) + "?subject=" + ($$('Helpers').$encode_uri_component(attrs['$[]'](2))) + "&amp;body=" + ($$('Helpers').$encode_uri_component(attrs['$[]'](3)))
27600                    } else {
27601                      target = "" + (target) + "?subject=" + ($$('Helpers').$encode_uri_component(attrs['$[]'](2)))
27602                    }
27603                  };
27604                }
27605              } else if (($not(doc.$compat_mode()) && ($truthy(link_text['$include?']("="))))) {
27606                
27607                $b = self.$extract_attributes_from_text(link_text, ""), $a = $to_ary($b), (link_text = ($a[0] == null ? nil : $a[0])), (attrs = ($a[1] == null ? nil : $a[1])), $b;
27608                link_opts['$[]=']("id", attrs['$[]']("id"));
27609              };
27610              if ($truthy(link_text['$end_with?']("^"))) {
27611                
27612                link_text = link_text.$chop();
27613                if ($truthy(attrs)) {
27614                  if ($truthy(($ret_or_1 = attrs['$[]']("window")))) {
27615                    $ret_or_1
27616                  } else {
27617                    attrs['$[]=']("window", "_blank")
27618                  }
27619                } else {
27620                  attrs = $hash2(["window"], {"window": "_blank"})
27621                };
27622              };
27623            };
27624            if ($truthy(link_text['$empty?']())) {
27625              if ($truthy(mailto)) {
27626                link_text = mailto_text
27627              } else {
27628                
27629                if ($truthy(doc_attrs['$key?']("hide-uri-scheme"))) {
27630                  if ($truthy((link_text = target.$sub($$('UriSniffRx'), ""))['$empty?']())) {
27631                    link_text = target
27632                  }
27633                } else {
27634                  link_text = target
27635                };
27636                if ($truthy(attrs)) {
27637                  attrs['$[]=']("role", ($truthy(attrs['$key?']("role")) ? ("bare " + (attrs['$[]']("role"))) : ("bare")))
27638                } else {
27639                  attrs = $hash2(["role"], {"role": "bare"})
27640                };
27641              }
27642            };
27643            doc.$register("links", ($a = ["target", target], $send(link_opts, '[]=', $a), $a[$a.length - 1]));
27644            if ($truthy(attrs)) {
27645              link_opts['$[]=']("attributes", attrs)
27646            };
27647            return $$('Inline').$new(self, "anchor", link_text, link_opts).$convert();}, {$$s: self})
27648        };
27649        if ($truthy(text['$include?']("@"))) {
27650          text = $send(text, 'gsub', [$$('InlineEmailRx')], function $$27(){var $a, self = $$27.$$s == null ? this : $$27.$$s, target = nil, address = nil;
27651
27652            
27653            if ($truthy((($a = $gvars['~']) === nil ? nil : $a['$[]'](1)))) {
27654              return ($eqeq((($a = $gvars['~']) === nil ? nil : $a['$[]'](1)), $$('RS')) ? ((($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$slice(1, (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$length())) : ((($a = $gvars['~']) === nil ? nil : $a['$[]'](0))))
27655            };
27656            target = $rb_plus("mailto:", (address = (($a = $gvars['~']) === nil ? nil : $a['$[]'](0))));
27657            doc.$register("links", target);
27658            return $$('Inline').$new(self, "anchor", address, $hash2(["type", "target"], {"type": "link", "target": target})).$convert();}, {$$s: self})
27659        };
27660        if ((($truthy(found_square_bracket) && ($eqeq(self.context, "list_item"))) && ($eqeq(self.parent.$style(), "bibliography")))) {
27661          text = $send(text, 'sub', [$$('InlineBiblioAnchorRx')], function $$28(){var $a, self = $$28.$$s == null ? this : $$28.$$s;
27662
27663            return $$('Inline').$new(self, "anchor", (($a = $gvars['~']) === nil ? nil : $a['$[]'](2)), $hash2(["type", "id"], {"type": "bibref", "id": (($a = $gvars['~']) === nil ? nil : $a['$[]'](1))})).$convert()}, {$$s: self})
27664        };
27665        if ((($truthy(found_square_bracket) && ($truthy(text['$include?']("[[")))) || (($truthy(found_macroish) && ($truthy(text['$include?']("or:"))))))) {
27666          text = $send(text, 'gsub', [$$('InlineAnchorRx')], function $$29(){var $a, self = $$29.$$s == null ? this : $$29.$$s, id = nil, reftext = nil;
27667
27668            
27669            if ($truthy((($a = $gvars['~']) === nil ? nil : $a['$[]'](1)))) {
27670              return (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$slice(1, (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$length())
27671            };
27672            if ($truthy((id = (($a = $gvars['~']) === nil ? nil : $a['$[]'](2))))) {
27673              reftext = (($a = $gvars['~']) === nil ? nil : $a['$[]'](3))
27674            } else {
27675              
27676              id = (($a = $gvars['~']) === nil ? nil : $a['$[]'](4));
27677              if (($truthy((reftext = (($a = $gvars['~']) === nil ? nil : $a['$[]'](5)))) && ($truthy(reftext['$include?']($$('R_SB')))))) {
27678                reftext = reftext.$gsub($$('ESC_R_SB'), $$('R_SB'))
27679              };
27680            };
27681            return $$('Inline').$new(self, "anchor", reftext, $hash2(["type", "id"], {"type": "ref", "id": id})).$convert();}, {$$s: self})
27682        };
27683        if ((($truthy(text['$include?']("&")) && ($truthy(text['$include?'](";&l")))) || (($truthy(found_macroish) && ($truthy(text['$include?']("xref:"))))))) {
27684          text = $send(text, 'gsub', [$$('InlineXrefMacroRx')], function $$30(){var $a, $b, self = $$30.$$s == null ? this : $$30.$$s, attrs = nil, refid = nil, _ = nil, link_text = nil, macro = nil, fragment = nil, hash_idx = nil, fragment_len = nil, path = nil, src2src = nil, target = nil;
27685
27686            
27687            if ($truthy((($a = $gvars['~']) === nil ? nil : $a['$[]'](0))['$start_with?']($$('RS')))) {
27688              return (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$slice(1, (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$length())
27689            };
27690            attrs = $hash2([], {});
27691            if ($truthy((refid = (($a = $gvars['~']) === nil ? nil : $a['$[]'](1))))) {
27692              if ($truthy(refid['$include?'](","))) {
27693                
27694                $b = refid.$partition(","), $a = $to_ary($b), (refid = ($a[0] == null ? nil : $a[0])), (_ = ($a[1] == null ? nil : $a[1])), (link_text = ($a[2] == null ? nil : $a[2])), $b;
27695                if ($truthy((link_text = link_text.$lstrip())['$empty?']())) {
27696                  link_text = nil
27697                };
27698              }
27699            } else {
27700              
27701              macro = true;
27702              refid = (($a = $gvars['~']) === nil ? nil : $a['$[]'](2));
27703              if ($truthy((link_text = (($a = $gvars['~']) === nil ? nil : $a['$[]'](3))))) {
27704                
27705                if ($truthy(link_text['$include?']($$('R_SB')))) {
27706                  link_text = link_text.$gsub($$('ESC_R_SB'), $$('R_SB'))
27707                };
27708                if (($not(doc.$compat_mode()) && ($truthy(link_text['$include?']("="))))) {
27709                  $b = self.$extract_attributes_from_text(link_text), $a = $to_ary($b), (link_text = ($a[0] == null ? nil : $a[0])), (attrs = ($a[1] == null ? nil : $a[1])), $b
27710                };
27711              };
27712            };
27713            if ($truthy(doc.$compat_mode())) {
27714              fragment = refid
27715            } else if (($truthy((hash_idx = refid.$index("#"))) && ($neqeq(refid['$[]']($rb_minus(hash_idx, 1)), "&")))) {
27716              if ($truthy($rb_gt(hash_idx, 0))) {
27717                
27718                if ($truthy($rb_gt((fragment_len = $rb_minus($rb_minus(refid.$length(), 1), hash_idx)), 0))) {
27719                  $a = [refid.$slice(0, hash_idx), refid.$slice($rb_plus(hash_idx, 1), fragment_len)], (path = $a[0]), (fragment = $a[1]), $a
27720                } else {
27721                  path = refid.$chop()
27722                };
27723                if ($truthy(macro)) {
27724                  if ($truthy(path['$end_with?'](".adoc"))) {
27725                    src2src = (path = path.$slice(0, $rb_minus(path.$length(), 5)))
27726                  }
27726 else if ($not($$('Helpers')['$extname?'](path))) {
27727                    src2src = path
27728                  }
27729                } else if ($truthy($send(path, 'end_with?', $to_a($$('ASCIIDOC_EXTENSIONS').$keys())))) {
27730                  src2src = (path = path.$slice(0, path.$rindex(".")))
27731                } else {
27732                  src2src = path
27733                };
27734              } else {
27735                $a = [refid, refid.$slice(1, refid.$length())], (target = $a[0]), (fragment = $a[1]), $a
27736              }
27737            } else if ($truthy(macro)) {
27738              if ($truthy(refid['$end_with?'](".adoc"))) {
27739                src2src = (path = refid.$slice(0, $rb_minus(refid.$length(), 5)))
27740              } else if ($truthy($$('Helpers')['$extname?'](refid))) {
27741                path = refid
27742              } else {
27743                fragment = refid
27744              }
27745            } else {
27746              fragment = refid
27747            };
27748            if ($truthy(target)) {
27749              
27750              refid = fragment;
27751              if (($truthy(self.$logger()['$info?']()) && ($not(doc.$catalog()['$[]']("refs")['$[]'](refid))))) {
27752                self.$logger().$info("possible invalid reference: " + (refid))
27753              };
27754            } else if ($truthy(path)) {
27755              if (($truthy(src2src) && (($eqeq(doc.$attributes()['$[]']("docname"), path) || ($truthy(doc.$catalog()['$[]']("includes")['$[]'](path))))))) {
27756                if ($truthy(fragment)) {
27757                  
27758                  $a = [fragment, nil, "#" + (fragment)], (refid = $a[0]), (path = $a[1]), (target = $a[2]), $a;
27759                  if (($truthy(self.$logger()['$info?']()) && ($not(doc.$catalog()['$[]']("refs")['$[]'](refid))))) {
27760                    self.$logger().$info("possible invalid reference: " + (refid))
27761                  };
27762                } else {
27763                  $a = [nil, nil, "#"], (refid = $a[0]), (path = $a[1]), (target = $a[2]), $a
27764                }
27765              } else {
27766                
27767                $a = [path, "" + (($truthy(($ret_or_1 = doc.$attributes()['$[]']("relfileprefix"))) ? ($ret_or_1) : (""))) + (path) + (($truthy(src2src) ? (doc.$attributes().$fetch("relfilesuffix", doc.$outfilesuffix())) : ("")))], (refid = $a[0]), (path = $a[1]), $a;
27768                if ($truthy(fragment)) {
27769                  $a = ["" + (refid) + "#" + (fragment), "" + (path) + "#" + (fragment)], (refid = $a[0]), (target = $a[1]), $a
27770                } else {
27771                  target = path
27772                };
27773              }
27774            } else if (($truthy(doc.$compat_mode()) || ($not($$('Compliance').$natural_xrefs())))) {
27775              
27776              $a = [fragment, "#" + (fragment)], (refid = $a[0]), (target = $a[1]), $a;
27777              if (($truthy(self.$logger()['$info?']()) && ($not(doc.$catalog()['$[]']("refs")['$[]'](refid))))) {
27778                self.$logger().$info("possible invalid reference: " + (refid))
27779              };
27780            } else if ($truthy(doc.$catalog()['$[]']("refs")['$[]'](fragment))) {
27781              $a = [fragment, "#" + (fragment)], (refid = $a[0]), (target = $a[1]), $a
27782            } else if ((($truthy(fragment['$include?'](" ")) || ($neqeq(fragment.$downcase(), fragment))) && ($truthy((refid = doc.$resolve_id(fragment)))))) {
27783              $a = [refid, "#" + (refid)], (fragment = $a[0]), (target = $a[1]), $a
27784            } else {
27785              
27786              $a = [fragment, "#" + (fragment)], (refid = $a[0]), (target = $a[1]), $a;
27787              if ($truthy(self.$logger()['$info?']())) {
27788                self.$logger().$info("possible invalid reference: " + (refid))
27789              };
27790            };
27791            attrs['$[]=']("path", path);
27792            attrs['$[]=']("fragment", fragment);
27793            attrs['$[]=']("refid", refid);
27794            return $$('Inline').$new(self, "anchor", link_text, $hash2(["type", "target", "attributes"], {"type": "xref", "target": target, "attributes": attrs})).$convert();}, {$$s: self})
27795        };
27796        if (($truthy(found_macroish) && ($truthy(text['$include?']("tnote"))))) {
27797          text = $send(text, 'gsub', [$$('InlineFootnoteMacroRx')], function $$31(){var $a, $b, $c, self = $$31.$$s == null ? this : $$31.$$s, id = nil, content = nil, footnote = nil, index = nil, type = nil, target = nil;
27798
27799            
27800            if ($truthy((($a = $gvars['~']) === nil ? nil : $a['$[]'](0))['$start_with?']($$('RS')))) {
27801              return (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$slice(1, (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$length())
27802            };
27803            if ($truthy((($a = $gvars['~']) === nil ? nil : $a['$[]'](1)))) {
27804              if ($truthy((($a = $gvars['~']) === nil ? nil : $a['$[]'](3)))) {
27805                
27806                $b = (($c = $gvars['~']) === nil ? nil : $c['$[]'](3)).$split(",", 2), $a = $to_ary($b), (id = ($a[0] == null ? nil : $a[0])), (content = ($a[1] == null ? nil : $a[1])), $b;
27807                if (!$truthy(doc.$compat_mode())) {
27808                  self.$logger().$warn("found deprecated footnoteref macro: " + ((($a = $gvars['~']) === nil ? nil : $a['$[]'](0))) + "; use footnote macro with target instead")
27809                };
27810              } else {
27811                return (($a = $gvars['~']) === nil ? nil : $a['$[]'](0))
27812              }
27813            } else {
27814              
27815              id = (($a = $gvars['~']) === nil ? nil : $a['$[]'](2));
27816              content = (($a = $gvars['~']) === nil ? nil : $a['$[]'](3));
27817            };
27818            if ($truthy(id)) {
27819              if ($truthy((footnote = $send(doc.$footnotes(), 'find', [], function $$32(candidate){
27820                
27821                if (candidate == null) candidate = nil;
27822                return candidate.$id()['$=='](id);})))) {
27823                
27824                $a = [footnote.$index(), footnote.$text()], (index = $a[0]), (content = $a[1]), $a;
27825                $a = ["xref", id, nil], (type = $a[0]), (target = $a[1]), (id = $a[2]), $a;
27826              } else if ($truthy(content)) {
27827                
27828                content = self.$restore_passthroughs(self.$normalize_text(content, true, true));
27829                index = doc.$counter("footnote-number");
27830                doc.$register("footnotes", $$$($$('Document'), 'Footnote').$new(index, id, content));
27831                $a = ["ref", nil], (type = $a[0]), (target = $a[1]), $a;
27832              } else {
27833                
27834                self.$logger().$warn("invalid footnote reference: " + (id));
27835                $a = ["xref", id, id, nil], (type = $a[0]), (target = $a[1]), (content = $a[2]), (id = $a[3]), $a;
27836              }
27837            } else if ($truthy(content)) {
27838              
27839              content = self.$restore_passthroughs(self.$normalize_text(content, true, true));
27840              index = doc.$counter("footnote-number");
27841              doc.$register("footnotes", $$$($$('Document'), 'Footnote').$new(index, id, content));
27842              type = (target = nil);
27843            } else {
27844              return (($a = $gvars['~']) === nil ? nil : $a['$[]'](0))
27845            };
27846            return $$('Inline').$new(self, "footnote", content, $hash2(["attributes", "id", "target", "type"], {"attributes": $hash2(["index"], {"index": index}), "id": id, "target": target, "type": type})).$convert();}, {$$s: self})
27847        };
27848        return text;
27849      });
27850      
27851      $def(self, '$sub_post_replacements', function $$sub_post_replacements(text) {
27852        var self = this, lines = nil, last = nil;
27853        if (self.document == null) self.document = nil;
27854        if (self.attributes == null) self.attributes = nil;
27855
27856        if (($truthy(self.attributes['$[]']("hardbreaks-option")) || ($truthy(self.document.$attributes()['$[]']("hardbreaks-option"))))) {
27857          
27858          lines = text.$split($$('LF'), -1);
27859          if ($truthy($rb_lt(lines.$size(), 2))) {
27860            return text
27861          };
27862          last = lines.$pop();
27863          return $send(lines, 'map', [], function $$33(line){var self = $$33.$$s == null ? this : $$33.$$s;
27864
27865            
27866            if (line == null) line = nil;
27867            return $$('Inline').$new(self, "break", ($truthy(line['$end_with?']($$('HARD_LINE_BREAK'))) ? (line.$slice(0, $rb_minus(line.$length(), 2))) : (line)), $hash2(["type"], {"type": "line"})).$convert();}, {$$s: self})['$<<'](last).$join($$('LF'));
27868        } else if (($truthy(text['$include?']($$('PLUS'))) && ($truthy(text['$include?']($$('HARD_LINE_BREAK')))))) {
27869          return $send(text, 'gsub', [$$('HardLineBreakRx')], function $$34(){var $a, self = $$34.$$s == null ? this : $$34.$$s;
27870
27871            return $$('Inline').$new(self, "break", (($a = $gvars['~']) === nil ? nil : $a['$[]'](1)), $hash2(["type"], {"type": "line"})).$convert()}, {$$s: self})
27872        } else {
27873          return text
27874        }
27875      });
27876      
27877      $def(self, '$sub_source', function $$sub_source(source, process_callouts) {
27878        var self = this;
27879
27880        if ($truthy(process_callouts)) {
27881          return self.$sub_callouts(self.$sub_specialchars(source))
27882        } else {
27883          
27884          return self.$sub_specialchars(source);
27885        }
27886      });
27887      
27888      $def(self, '$sub_callouts', function $$sub_callouts(text) {
27889        var self = this, callout_rx = nil, autonum = nil;
27890
27891        
27892        callout_rx = ($truthy(self['$attr?']("line-comment")) ? ($$('CalloutSourceRxMap')['$[]'](self.$attr("line-comment"))) : ($$('CalloutSourceRx')));
27893        autonum = 0;
27894        return $send(text, 'gsub', [callout_rx], function $$35(){var $a, self = $$35.$$s == null ? this : $$35.$$s, $ret_or_1 = nil;
27895          if (self.document == null) self.document = nil;
27896
27897          if ($truthy((($a = $gvars['~']) === nil ? nil : $a['$[]'](2)))) {
27898            return (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$sub($$('RS'), "")
27899          } else {
27900            return $$('Inline').$new(self, "callout", ($eqeq((($a = $gvars['~']) === nil ? nil : $a['$[]'](4)), ".") ? ((autonum = $rb_plus(autonum, 1)).$to_s()) : ((($a = $gvars['~']) === nil ? nil : $a['$[]'](4)))), $hash2(["id", "attributes"], {"id": self.document.$callouts().$read_next_id(), "attributes": $hash2(["guard"], {"guard": ($truthy(($ret_or_1 = (($a = $gvars['~']) === nil ? nil : $a['$[]'](1)))) ? ($ret_or_1) : (($eqeq((($a = $gvars['~']) === nil ? nil : $a['$[]'](3)), "--") ? (["<!--", "-->"]) : (nil))))})})).$convert()
27901          }}, {$$s: self});
27902      });
27903      
27904      $def(self, '$highlight_source', function $$highlight_source(source, process_callouts) {
27905        var $a, $b, self = this, syntax_hl = nil, callout_marks = nil, doc_attrs = nil, syntax_hl_name = nil, start_line_number = nil, linenums_mode = nil, $ret_or_1 = nil, highlight_lines = nil, highlighted = nil, source_offset = nil;
27906        if (self.document == null) self.document = nil;
27907        if (self.passthroughs == null) self.passthroughs = nil;
27908
27909        
27910        if (!($truthy((syntax_hl = self.document.$syntax_highlighter())) && ($truthy(syntax_hl['$highlight?']())))) {
27911          return self.$sub_source(source, process_callouts)
27912        };
27913        if ($truthy(process_callouts)) {
27914          $b = self.$extract_callouts(source), $a = $to_ary($b), (source = ($a[0] == null ? nil : $a[0])), (callout_marks = ($a[1] == null ? nil : $a[1])), $b
27915        };
27916        doc_attrs = self.document.$attributes();
27917        syntax_hl_name = syntax_hl.$name();
27918        if (($truthy((linenums_mode = ($truthy(self['$attr?']("linenums")) ? (($truthy(($ret_or_1 = doc_attrs['$[]']("" + (syntax_hl_name) + "-linenums-mode"))) ? ($ret_or_1) : ("table")).$to_sym()
27918) : (nil)))) && ($truthy($rb_lt((start_line_number = self.$attr("start", 1).$to_i()), 1))))) {
27919          start_line_number = 1
27920        };
27921        if ($truthy(self['$attr?']("highlight"))) {
27922          highlight_lines = self.$resolve_lines_to_highlight(source, self.$attr("highlight"), start_line_number)
27923        };
27924        $b = syntax_hl.$highlight(self, source, self.$attr("language"), $hash2(["callouts", "css_mode", "highlight_lines", "number_lines", "start_line_number", "style"], {"callouts": callout_marks, "css_mode": ($truthy(($ret_or_1 = doc_attrs['$[]']("" + (syntax_hl_name) + "-css"))) ? ($ret_or_1) : ("class")).$to_sym(), "highlight_lines": highlight_lines, "number_lines": linenums_mode, "start_line_number": start_line_number, "style": doc_attrs['$[]']("" + (syntax_hl_name) + "-style")})), $a = $to_ary($b), (highlighted = ($a[0] == null ? nil : $a[0])), (source_offset = ($a[1] == null ? nil : $a[1])), $b;
27925        if (!$truthy(self.passthroughs['$empty?']())) {
27926          highlighted = highlighted.$gsub($$('HighlightedPassSlotRx'), "" + ($$('PASS_START')) + "\\1" + ($$('PASS_END')))
27927        };
27928        if ($truthy(callout_marks['$nil_or_empty?']())) {
27929          return highlighted
27930        } else {
27931          
27932          return self.$restore_callouts(highlighted, callout_marks, source_offset);
27933        };
27934      });
27935      
27936      $def(self, '$resolve_lines_to_highlight', function $$resolve_lines_to_highlight(source, spec, start) {
27937        var lines = nil, shift = nil;
27938
27939        
27940        if (start == null) start = nil;
27941        lines = [];
27942        if ($truthy(spec['$include?'](" "))) {
27943          spec = spec.$delete(" ")
27944        };
27945        $send(($truthy(spec['$include?'](",")) ? (spec.$split(",")) : (spec.$split(";"))), 'map', [], function $$36(entry){var $a, $b, negate = nil, delim = nil, from = nil, _ = nil, to = nil, line = nil;
27946
27947          
27948          if (entry == null) entry = nil;
27949          if ($truthy(entry['$start_with?']("!"))) {
27950            
27951            entry = entry.$slice(1, entry.$length());
27952            negate = true;
27953          };
27954          if ($truthy((delim = ($truthy(entry['$include?']("..")) ? ("..") : (($truthy(entry['$include?']("-")) ? ("-") : (nil))))))) {
27955            
27956            $b = entry.$partition(delim), $a = $to_ary($b), (from = ($a[0] == null ? nil : $a[0])), (_ = ($a[1] == null ? nil : $a[1])), (to = ($a[2] == null ? nil : $a[2])), $b;
27957            if (($truthy(to['$empty?']()) || ($truthy($rb_lt((to = to.$to_i()), 0))))) {
27958              to = $rb_plus(source.$count($$('LF')), 1)
27959            };
27960            if ($truthy(negate)) {
27961              return (lines = $rb_minus(lines, Opal.Range.$new(from.$to_i(), to, false).$to_a()))
27962            } else {
27963              return (lines = lines['$|'](Opal.Range.$new(from.$to_i(), to, false).$to_a()))
27964            };
27965          } else if ($truthy(negate)) {
27966            return lines.$delete(entry.$to_i())
27967          } else if ($not(lines['$include?']((line = entry.$to_i())))) {
27968            return lines['$<<'](line)
27969          } else {
27970            return nil
27971          };});
27972        if (!$eqeq((shift = ($truthy(start) ? ($rb_minus(start, 1)) : (0))), 0)) {
27973          lines = $send(lines, 'map', [], function $$37(it){
27974            
27975            if (it == null) it = nil;
27976            return $rb_minus(it, shift);})
27977        };
27978        return lines.$sort();
27979      }, -3);
27980      
27981      $def(self, '$extract_passthroughs', function $$extract_passthroughs(text) {
27982        var $a, $b, self = this, compat_mode = nil, passthrus = nil, pass_inline_char1 = nil, pass_inline_char2 = nil, pass_inline_rx = nil;
27983        if (self.document == null) self.document = nil;
27984        if (self.passthroughs == null) self.passthroughs = nil;
27985
27986        
27987        compat_mode = self.document.$compat_mode();
27988        passthrus = self.passthroughs;
27989        if ((($truthy(text['$include?']("++")) || ($truthy(text['$include?']("$$")))) || ($truthy(text['$include?']("ss:"))))) {
27990          text = $send(text, 'gsub', [$$('InlinePassMacroRx')], function $$38(){var $a, self = $$38.$$s == null ? this : $$38.$$s, boundary = nil, attrlist = nil, escape_count = nil, preceding = nil, old_behavior = nil, attributes = nil, subs = nil, passthru_key = nil, $ret_or_1 = nil;
27991
27992            
27993            if ($truthy((boundary = (($a = $gvars['~']) === nil ? nil : $a['$[]'](4))))) {
27994              
27995              if (($truthy(compat_mode) && ($eqeq(boundary, "++")))) {
27996                return "" + (($truthy((($a = $gvars['~']) === nil ? nil : $a['$[]'](2))) ? ("" + ((($a = $gvars['~']) === nil ? nil : $a['$[]'](1))) + "[" + ((($a = $gvars['~']) === nil ? nil : $a['$[]'](2))) + "]" + ((($a = $gvars['~']) === nil ? nil : $a['$[]'](3)))) : ("" + ((($a = $gvars['~']) === nil ? nil : $a['$[]'](1))) + ((($a = $gvars['~']) === nil ? nil : $a['$[]'](3)))))) + "++" + (self.$extract_passthroughs((($a = $gvars['~']) === nil ? nil : $a['$[]'](5)))) + "++"
27997              };
27998              if ($truthy((attrlist = (($a = $gvars['~']) === nil ? nil : $a['$[]'](2))))) {
27999                if ($truthy($rb_gt((escape_count = (($a = $gvars['~']) === nil ? nil : $a['$[]'](3)).$length()), 0))) {
28000                  return "" + ((($a = $gvars['~']) === nil ? nil : $a['$[]'](1))) + "[" + (attrlist) + "]" + ($rb_times($$('RS'), $rb_minus(e
28000scape_count, 1))) + (boundary) + ((($a = $gvars['~']) === nil ? nil : $a['$[]'](5))) + (boundary)
28001                } else if ($eqeq((($a = $gvars['~']) === nil ? nil : $a['$[]'](1)), $$('RS'))) {
28002                  preceding = "[" + (attrlist) + "]"
28003                } else if ($eqeq(boundary, "++")) {
28004                  if ($eqeq(attrlist, "x-")) {
28005                    
28006                    old_behavior = true;
28007                    attributes = $hash2([], {});
28008                  } else if ($truthy(attrlist['$end_with?'](" x-"))) {
28009                    
28010                    old_behavior = true;
28011                    attributes = self.$parse_quoted_text_attributes(attrlist.$slice(0, $rb_minus(attrlist.$length(), 3)));
28012                  } else {
28013                    attributes = self.$parse_quoted_text_attributes(attrlist)
28014                  }
28015                } else {
28016                  attributes = self.$parse_quoted_text_attributes(attrlist)
28017                }
28018              } else if ($truthy($rb_gt((escape_count = (($a = $gvars['~']) === nil ? nil : $a['$[]'](3)).$length()), 0))) {
28019                return "" + ($rb_times($$('RS'), $rb_minus(escape_count, 1))) + (boundary) + ((($a = $gvars['~']) === nil ? nil : $a['$[]'](5))) + (boundary)
28020              };
28021              subs = ($eqeq(boundary, "+++") ? ([]) : ($$('BASIC_SUBS')));
28022              if ($truthy(attributes)) {
28023                if ($truthy(old_behavior)) {
28024                  passthrus['$[]=']((passthru_key = passthrus.$size()), $hash2(["text", "subs", "type", "attributes"], {"text": (($a = $gvars['~']) === nil ? nil : $a['$[]'](5)), "subs": $$('NORMAL_SUBS'), "type": "monospaced", "attributes": attributes}))
28025                } else {
28026                  passthrus['$[]=']((passthru_key = passthrus.$size()), $hash2(["text", "subs", "type", "attributes"], {"text": (($a = $gvars['~']) === nil ? nil : $a['$[]'](5)), "subs": subs, "type": "unquoted", "attributes": attributes}))
28027                }
28028              } else {
28029                passthrus['$[]=']((passthru_key = passthrus.$size()), $hash2(["text", "subs"], {"text": (($a = $gvars['~']) === nil ? nil : $a['$[]'](5)), "subs": subs}))
28030              };
28031            } else {
28032              
28033              if ($eqeq((($a = $gvars['~']) === nil ? nil : $a['$[]'](6)), $$('RS'))) {
28034                return (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$slice(1, (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$length())
28035              };
28036              if ($truthy((subs = (($a = $gvars['~']) === nil ? nil : $a['$[]'](7))))) {
28037                passthrus['$[]=']((passthru_key = passthrus.$size()), $hash2(["text", "subs"], {"text": self.$normalize_text((($a = $gvars['~']) === nil ? nil : $a['$[]'](8)), nil, true), "subs": self.$resolve_pass_subs(subs)}))
28038              } else {
28039                passthrus['$[]=']((passthru_key = passthrus.$size()), $hash2(["text"], {"text": self.$normalize_text((($a = $gvars['~']) === nil ? nil : $a['$[]'](8)), nil, true)}))
28040              };
28041            };
28042            return "" + (($truthy(($ret_or_1 = preceding)) ? ($ret_or_1) : (""))) + ($$('PASS_START')) + (passthru_key) + ($$('PASS_END'));}, {$$s: self})
28043        };
28044        $b = $$('InlinePassRx')['$[]'](compat_mode), $a = $to_ary($b), (pass_inline_char1 = ($a[0] == null ? nil : $a[0])), (pass_inline_char2 = ($a[1] == null ? nil : $a[1])), (pass_inline_rx = ($a[2] == null ? nil : $a[2])), $b;
28045        if (($truthy(text['$include?'](pass_inline_char1)) || (($truthy(pass_inline_char2) && ($truthy(text['$include?'](pass_inline_char2))))))) {
28046          text = $send(text, 'gsub', [pass_inline_rx], function $$39(){var $c, self = $$39.$$s == null ? this : $$39.$$s, preceding = nil, attrlist = nil, $ret_or_1 = nil, escaped = nil, quoted_text = nil, format_mark = nil, content = nil, old_behavior = nil, old_behavior_forced = nil, attributes = nil, passthru_key = nil, subs = nil;
28047
28048            
28049            preceding = (($c = $gvars['~']) === nil ? nil : $c['$[]'](1));
28050            attrlist = ($truthy(($ret_or_1 = (($c = $gvars['~']) === nil ? nil : $c['$[]'](4)))) ? ($ret_or_1) : ((($c = $gvars['~']) === nil ? nil : $c['$[]'](3))));
28051            if ($truthy((($c = $gvars['~']) === nil ? nil : $c['$[]'](5)))) {
28052              escaped = true
28053            };
28054            quoted_text = (($c = $gvars['~']) === nil ? nil : $c['$[]'](6));
28055            format_mark = (($c = $gvars['~']) === nil ? nil : $c['$[]'](7));
28056            content = (($c = $gvars['~']) === nil ? nil : $c['$[]'](8));
28057            if ($truthy(compat_mode)) {
28058              old_behavior = true
28059            } else if (($truthy(attrlist) && (($eqeq(attrlist, "x-") || ($truthy(attrlist['$end_with?'](" x-"))))))) {
28060              old_behavior = (old_behavior_forced = true)
28061            };
28062            if ($truthy(attrlist)) {
28063              if ($truthy(escaped)) {
28064                return "" + (preceding) + "[" + (attrlist) + "]" + (quoted_text.$slice(1, quoted_text.$length()))
28065              } else if ($eqeq(preceding, $$('RS'))) {
28066                
28067                if (($truthy(old_behavior_forced) && ($eqeq(format_mark, "`")))
28067) {
28068                  return "" + (preceding) + "[" + (attrlist) + "]" + (quoted_text)
28069                };
28070                preceding = "[" + (attrlist) + "]";
28071              } else if ($truthy(old_behavior_forced)) {
28072                attributes = ($eqeq(attrlist, "x-") ? ($hash2([], {})) : (self.$parse_quoted_text_attributes(attrlist.$slice(0, $rb_minus(attrlist.$length(), 3)))))
28073              } else {
28074                attributes = self.$parse_quoted_text_attributes(attrlist)
28075              }
28076            } else if ($truthy(escaped)) {
28077              return "" + (preceding) + (quoted_text.$slice(1, quoted_text.$length()))
28078            } else if (($truthy(compat_mode) && ($eqeq(preceding, $$('RS'))))) {
28079              return quoted_text
28080            };
28081            if ($truthy(compat_mode)) {
28082              passthrus['$[]=']((passthru_key = passthrus.$size()), $hash2(["text", "subs", "attributes", "type"], {"text": content, "subs": $$('BASIC_SUBS'), "attributes": attributes, "type": "monospaced"}))
28083            } else if ($truthy(attributes)) {
28084              if ($truthy(old_behavior)) {
28085                
28086                subs = ($eqeq(format_mark, "`") ? ($$('BASIC_SUBS')) : ($$('NORMAL_SUBS')));
28087                passthrus['$[]=']((passthru_key = passthrus.$size()), $hash2(["text", "subs", "attributes", "type"], {"text": content, "subs": subs, "attributes": attributes, "type": "monospaced"}));
28088              } else {
28089                passthrus['$[]=']((passthru_key = passthrus.$size()), $hash2(["text", "subs", "attributes", "type"], {"text": content, "subs": $$('BASIC_SUBS'), "attributes": attributes, "type": "unquoted"}))
28090              }
28091            } else {
28092              passthrus['$[]=']((passthru_key = passthrus.$size()), $hash2(["text", "subs"], {"text": content, "subs": $$('BASIC_SUBS')}))
28093            };
28094            return "" + (preceding) + ($$('PASS_START')) + (passthru_key) + ($$('PASS_END'));}, {$$s: self})
28095        };
28096        if (($truthy(text['$include?'](":")) && (($truthy(text['$include?']("stem:")) || ($truthy(text['$include?']("math:"))))))) {
28097          text = $send(text, 'gsub', [$$('InlineStemMacroRx')], function $$40(){var $c, self = $$40.$$s == null ? this : $$40.$$s, type = nil, subs = nil, content = nil, passthru_key = nil;
28098            if (self.document == null) self.document = nil;
28099
28100            
28101            if ($truthy((($c = $gvars['~']) === nil ? nil : $c['$[]'](0))['$start_with?']($$('RS')))) {
28102              return (($c = $gvars['~']) === nil ? nil : $c['$[]'](0)).$slice(1, (($c = $gvars['~']) === nil ? nil : $c['$[]'](0)).$length())
28103            };
28104            if ($eqeq((type = (($c = $gvars['~']) === nil ? nil : $c['$[]'](1)).$to_sym()), "stem")) {
28105              type = $$('STEM_TYPE_ALIASES')['$[]'](self.document.$attributes()['$[]']("stem")).$to_sym()
28106            };
28107            subs = (($c = $gvars['~']) === nil ? nil : $c['$[]'](2));
28108            content = self.$normalize_text((($c = $gvars['~']) === nil ? nil : $c['$[]'](3)), nil, true);
28109            if ((($eqeq(type, "latexmath") && ($truthy(content['$start_with?']("$")))) && ($truthy(content['$end_with?']("$"))))) {
28110              content = content.$slice(1, $rb_minus(content.$length(), 2))
28111            };
28112            subs = ($truthy(subs) ? (self.$resolve_pass_subs(subs)) : (($truthy(self.document['$basebackend?']("html")) ? ($$('BASIC_SUBS')) : (nil))));
28113            passthrus['$[]=']((passthru_key = passthrus.$size()), $hash2(["text", "subs", "type"], {"text": content, "subs": subs, "type": type}));
28114            return "" + ($$('PASS_START')) + (passthru_key) + ($$('PASS_END'));}, {$$s: self})
28115        };
28116        return text;
28117      });
28118      
28119      $def(self, '$restore_passthroughs', function $$restore_passthroughs(text) {
28120        var self = this, passthrus = nil;
28121        if (self.passthroughs == null) self.passthroughs = nil;
28122
28123        
28124        passthrus = self.passthroughs;
28125        return $send(text, 'gsub', [$$('PassSlotRx')], function $$41(){var $a, self = $$41.$$s == null ? this : $$41.$$s, pass = nil, subbed_text = nil, type = nil, attributes = nil, id = nil;
28126
28127          if ($truthy((pass = passthrus['$[]']((($a = $gvars['~']) === nil ? nil : $a['$[]'](1)).$to_i())))) {
28128            
28129            subbed_text = self.$apply_subs(pass['$[]']("text"), pass['$[]']("subs"));
28130            if ($truthy((type = pass['$[]']("type")))) {
28131              
28132              if ($truthy((attributes = pass['$[]']("attributes")))) {
28133                id = attributes['$[]']("id")
28134              };
28135              subbed_text = $$('Inline').$new(self, "quoted", subbed_text, $hash2(["type", "id", "attributes"], {"type": type, "id": id, "attributes": attributes})).$convert();
28136            };
28137            if ($truthy(subbed_text['$include?']($$('PASS_START')))) {
28138              return self.$restore_passthroughs(subbed_text)
28139            } else {
28140              return subbed_text
28141            };
28142          } else {
28143            
28144            self.$logger().$error("unresolved passthrough detected: " + (text));
28145            return "??pass??";
28146          }}, {$$s: self});
28147      });
28148      
28149      $def(self, '$resolve_subs', function $$resolve_subs(subs, type, defaults, subject) {
28150        var self = this, candidates = nil, modifiers_present = nil, resolved = nil, invalid = nil;
28151
28152        
28153        if (type == null) type = "block";
28154        if (defaults == null) defaults = nil;
28155        if (subject == null) subject = nil;
28156        if ($truthy(subs['$nil_or_empty?']())) {
28157          return nil
28158        };
28159        candidates = nil;
28160        if ($truthy(subs['$include?'](" "))) {
28161          subs = subs.$delete(" ")
28162        };
28163        modifiers_present = $$('SubModifierSniffRx')['$match?'](subs);
28164        $send(subs.$split(","), 'each', [], function $$42(key){var modifier_operation = nil, first = nil, resolved_keys = nil, resolved_key = nil, candidate = nil, $ret_or_1 = nil;
28165
28166          
28167          if (key == null) key = nil;
28168          modifier_operation = nil;
28169          if ($truthy(modifiers_present)) {
28170            if ($eqeq((first = key.$chr()), "+")) {
28171              
28172              modifier_operation = "append";
28173              key = key.$slice(1, key.$length());
28174            } else if ($eqeq(first, "-")) {
28175              
28176              modifier_operation = "remove";
28177              key = key.$slice(1, key.$length());
28178            } else if ($truthy(key['$end_with?']("+"))) {
28179              
28180              modifier_operation = "prepend";
28181              key = key.$chop();
28182            }
28183          };
28184          key = key.$to_sym();
28185          if (($eqeq(type, "inline") && (($eqeq(key, "verbatim") || ($eqeq(key, "v")))))) {
28186            resolved_keys = $$('BASIC_SUBS')
28187          } else if ($truthy($$('SUB_GROUPS')['$key?'](key))) {
28188            resolved_keys = $$('SUB_GROUPS')['$[]'](key)
28189          } else if ((($eqeq(type, "inline") && ($eqeq(key.$length(), 1))) && ($truthy($$('SUB_HINTS')['$key?'](key))))) {
28190            
28191            resolved_key = $$('SUB_HINTS')['$[]'](key);
28192            if ($truthy((candidate = $$('SUB_GROUPS')['$[]'](resolved_key)))) {
28193              resolved_keys = candidate
28194            } else {
28195              resolved_keys = [resolved_key]
28196            };
28197          } else {
28198            resolved_keys = [key]
28199          };
28200          if ($truthy(modifier_operation)) {
28201            
28202            candidates = ($truthy(($ret_or_1 = candidates)) ? ($ret_or_1) : (($truthy(defaults) ? (defaults.$drop(0)) : ([]))));
28203            
28204            switch (modifier_operation) {
28205              case "append":
28206                return (candidates = $rb_plus(candidates, resolved_keys))
28207              case "prepend":
28208                return (candidates = $rb_plus(resolved_keys, candidates))
28209              case "remove":
28210                return (candidates = $rb_minus(candidates, resolved_keys))
28211              default:
28212                return nil
28213            };
28214          } else {
28215            
28216            candidates = ($truthy(($ret_or_1 = candidates)) ? ($ret_or_1) : ([]));
28217            return (candidates = $rb_plus(candidates, resolved_keys));
28218          };});
28219        if (!$truthy(candidates)) {
28220          return nil
28221        };
28222        resolved = candidates['$&']($$('SUB_OPTIONS')['$[]'](type));
28223        if (!$truthy($rb_minus(candidates, resolved)['$empty?']())) {
28224          
28225          invalid = $rb_minus(candidates, resolved);
28226          self.$logger().$warn("invalid substitution type" + (($truthy($rb_gt(invalid.$size(), 1)) ? ("s") : (""))) + (($truthy(subject) ? (" for ") : (""))) + (subject) + ": " + (invalid.$join(", ")));
28227        };
28228        return resolved;
28229      }, -2);
28230      
28231      $def(self, '$resolve_block_subs', function $$resolve_block_subs(subs, defaults, subject) {
28232        var self = this;
28233
28234        return self.$resolve_subs(subs, "block", defaults, subject)
28235      });
28236      
28237      $def(self, '$resolve_pass_subs', function $$resolve_pass_subs(subs) {
28238        var self = this;
28239
28240        return self.$resolve_subs(subs, "inline", nil, "passthrough macro")
28241      });
28242      
28243      $def(self, '$expand_subs', function $$expand_subs(subs, subject) {
28244        var self = this, $ret_or_1 = nil, $ret_or_2 = nil, expanded_subs = nil;
28245
28246        
28247        if (subject == null) subject = nil;
28248        if ($eqeqeq($$$('Symbol'), ($ret_or_1 = subs))) {
28249          if ($eqeq(subs, "none")) {
28250            return nil
28251          } else if ($truthy(($ret_or_2 = $$('SUB_GROUPS')['$[]'](subs)))) {
28252            return $ret_or_2
28253          } else {
28254            return [subs]
28255          }
28256        } else if ($eqeqeq($$$('Array'), $ret_or_1)) {
28257          
28258          expanded_subs = [];
28259          $send(subs, 'each', [], function $$43(key){var sub_group = nil;
28260
28261            
28262            if (key == null) key = nil;
28263            if ($eqeq(key, "none")) {
28264              return nil
28265            } else if ($truthy((sub_group = $$('SUB_GROUPS')['$[]'](key)))) {
28266              return (expanded_subs = $rb_plus(expanded_subs, sub_group))
28267            } else {
28268              return expanded_subs['$<<'](key)
28269            };});
28270          if ($truthy(expanded_subs['$empty?']())) {
28271            return nil
28272          } else {
28273            return expanded_subs
28274          };
28275        } else {
28276          return self.$resolve_subs(subs, "inline", nil, subject)
28277        };
28278      }, -2);
28279      
28280      $def(self, '$commit_subs', function $$commit_subs() {
28281        var self = this, default_subs = nil, custom_subs = nil, $ret_or_1 = nil, idx = nil, syntax_hl = nil;
28282        if (self.default_subs == null) self.default_subs = nil;
28283        if (self.content_model == null) self.content_model = nil;
28284        if (self.context == null) self.context = nil;
28285        if (self.subs == null) self.subs = nil;
28286        if (self.attributes == null) self.attributes = nil;
28287        if (self.document == null) self.document = nil;
28288        if (self.style == null) self.style = nil;
28289
28290        
28291        if (!$truthy((default_subs = self.default_subs))) {
28292          
28293          switch (self.content_model) {
28294            case "simple":
28295              default_subs = $$('NORMAL_SUBS')
28296              break;
28297            case "verbatim":
28298              default_subs = ($eqeq(self.context, "verse") ? ($$('NORMAL_SUBS')) : ($$('VERBATIM_SUBS')))
28299              break;
28300            case "raw":
28301              default_subs = ($eqeq(self.context, "stem") ? ($$('BASIC_SUBS')) : ($$('NO_SUBS')))
28302              break;
28303            default:
28304              return self.subs
28305          }
28306        };
28307        if ($truthy((custom_subs = self.attributes['$[]']("subs")))) {
28308          self.subs = ($truthy(($ret_or_1 = self.$resolve_block_subs(custom_subs, default_subs, self.context))) ? ($ret_or_1) : ([]))
28309        } else {
28310          self.subs = default_subs.$drop(0)
28311        };
28312        if ((((($eqeq(self.context, "listing") && ($eqeq(self.style, "source"))) && ($truthy((syntax_hl = self.document.$syntax_highlighter())))) && ($truthy(syntax_hl['$highlight?']()))) && ($truthy((idx = self.subs.$index("specialcharacters")))))) {
28313          self.subs['$[]='](idx, "highlight")
28314        };
28315        return nil;
28316      });
28317      
28318      $def(self, '$parse_attributes', function $$parse_attributes(attrlist, posattrs, opts) {
28319        var self = this, block = nil, into = nil;
28320        if (self.document == null) self.document = nil;
28321
28322        
28323        if (posattrs == null) posattrs = [];
28324        if (opts == null) opts = $hash2([], {});
28325        if ($truthy(($truthy(attrlist) ? (attrlist['$empty?']()) : (true)))) {
28326          return $hash2([], {})
28327        };
28328        if ($truthy(opts['$[]']("unescape_input"))) {
28329          attrlist = self.$normalize_text(attrlist, true, true)
28330        };
28331        if (($truthy(opts['$[]']("sub_input")) && ($truthy(attrlist['$include?']($$('ATTR_REF_HEAD')))))) {
28332          attrlist = self.document.$sub_attributes(attrlist)
28333        };
28334        if ($truthy(opts['$[]']("sub_result"))) {
28335          block = self
28336        };
28337        if ($truthy((into = opts['$[]']("into")))) {
28338          return $$('AttributeList').$new(attrlist, block).$parse_into(into, posattrs)
28339        } else {
28340          return $$('AttributeList').$new(attrlist, block).$parse(posattrs)
28341        };
28342      }, -2);
28343      self.$private();
28344      
28345      $def(self, '$extract_attributes_from_text', function $$extract_attributes_from_text(text, default_text) {
28346        var self = this, attrlist = nil, resolved_text = nil, attrs = nil;
28347
28348        
28349        if (default_text == null) default_text = nil;
28350        attrlist = ($truthy(text['$include?']($$('LF'))) ? (text.$tr($$('LF'), " ")) : (text));
28351        if ($truthy((resolved_text = (attrs = $$('AttributeList').$new(attrlist, self).$parse())['$[]'](1)))) {
28352          if ($eqeq(resolved_text, attrlist)) {
28353            return [text, attrs.$clear()]
28354          } else {
28355            return [resolved_text, attrs]
28356          }
28357        } else {
28358          return [default_text, attrs]
28359        };
28360      }, -2);
28361      
28362      $def(self, '$extract_callouts', function $$extract_callouts(source) {
28363        var self = this, callout_marks = nil, autonum = nil, lineno = nil, last_lineno = nil, callout_rx = nil;
28364
28365        
28366        callout_marks = $hash2([], {});
28367        autonum = (lineno = 0);
28368        last_lineno = nil;
28369        callout_rx = ($truthy(self['$attr?']("line-comment")) ? ($$('CalloutExtractRxMap')['$[]'](self.$attr("line-comment"))) : ($$('CalloutExtractRx')));
28370        source = $send(source.$split($$('LF'), -1), 'map', [], function $$44(line){
28371          
28372          if (line == null) line = nil;
28373          lineno = $rb_plus(lineno, 1);
28374          return $send(line, 'gsub', [callout_rx], function $$45(){var $a, $ret_or_1 = nil;
28375
28376            if ($truthy((($a = $gvars['~']) === nil ? nil : $a['$[]'](2)))) {
28377              return (($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$sub($$('RS'), "")
28378            } else {
28379              
28380              ($truthy(($ret_or_1 = callout_marks['$[]'](lineno))) ? ($ret_or_1) : (($a = [lineno, []], $send(callout_marks, '[]=', $a), $a[$a.length - 1])))['$<<']([($truthy(($ret_or_1 = (($a = $gvars['~']) === nil ? nil : $a['$[]'](1)))) ? ($ret_or_1) : (($eqeq((($a = $gvars['~']) === nil ? nil : $a['$[]'](3)), "--") ? (["<!--", "-->"]) : (nil)))), ($eqeq((($a = $gvars['~']) === nil ? nil : $a['$[]'](4)), ".") ? ((autonum = $rb_plus(autonum, 1)).$to_s()) : ((($a = $gvars['~']) === nil ? nil : $a['$[]'](4))))]);
28381              last_lineno = lineno;
28382              return "";
28383            }});}).$join($$('LF'));
28384        if ($truthy(last_lineno)) {
28385          if ($eqeq(last_lineno, lineno)) {
28386            source = "" + (source) + ($$('LF'))
28387          }
28388        } else {
28389          callout_marks = nil
28390        };
28391        return [source, callout_marks];
28392      });
28393      
28394      $def(self, '$restore_callouts', function $$restore_callouts(source, callout_marks, source_offset) {
28395        var self = this, preamble = nil, lineno = nil;
28396
28397        
28398        if (source_offset == null) source_offset = nil;
28399        if ($truthy(source_offset)) {
28400          
28401          preamble = source.$slice(0, source_offset);
28402          source = source.$slice(source_offset, source.$length());
28403        } else {
28404          preamble = ""
28405        };
28406        lineno = 0;
28407        return $rb_plus(preamble, $send(source.$split($$('LF'), -1), 'map', [], function $$46(line){var $a, $b, self = $$46.$$s == null ? this : $$46.$$s, conums = nil, guard = nil, numeral = nil;
28408          if (self.document == null) self.document = nil;
28409
28410          
28411          if (line == null) line = nil;
28412          if ($truthy((conums = callout_marks.$delete((lineno = $rb_plus(lineno, 1)))))) {
28413            if ($eqeq(conums.$size(), 1)) {
28414              
28415              $b = conums['$[]'](0), $a = $to_ary($b), (guard = ($a[0] == null ? nil : $a[0])), (numeral = ($a[1] == null ? nil : $a[1])), $b;
28416              return "" + (line) + ($$('Inline').$new(self, "callout", numeral, $hash2(["id", "attributes"], {"id": self.document.$callouts().$read_next_id(), "attributes": $hash2(["guard"], {"guard": guard})})).$convert());
28417            } else {
28418              return "" + (line) + ($send(conums, 'map', [], function $$47(guard_it, numeral_it){var self = $$47.$$s == null ? this : $$47.$$s;
28419                if (self.document == null) self.document = nil;
28420
28421                
28422                if (guard_it == null) guard_it = nil;
28423                if (numeral_it == null) numeral_it = nil;
28424                return $$('Inline').$new(self, "callout", numeral_it, $hash2(["id", "attributes"], {"id": self.document.$callouts().$read_next_id(), "attributes": $hash2(["guard"], {"guard": guard_it})})).$convert();}, {$$s: self}).$join(" "))
28425            }
28426          } else {
28427            return line
28428          };}, {$$s: self}).$join($$('LF')));
28429      }, -3);
28430      
28431      $def(self, '$convert_quoted_text', function $$convert_quoted_text(match, type, scope) {
28432        var self = this, attrs = nil, unescaped_attrs = nil, attrlist = nil, id = nil, attributes = nil;
28433
28434        
28435        if ($truthy(match['$[]'](0)['$start_with?']($$('RS')))) {
28436          if (($eqeq(scope, "constrained") && ($truthy((attrs = match['$[]'](2)))))) {
28437            unescaped_attrs = "[" + (attrs) + "]"
28438          } else {
28439            return match['$[]'](0).$slice(1, match['$[]'](0).$length())
28440          }
28441        };
28442        if ($eqeq(scope, "constrained")) {
28443          if ($truthy(unescaped_attrs)) {
28444            return "" + (unescaped_attrs) + ($$('Inline').$new(self, "quoted", match['$[]'](3), $hash2(["type"], {"type": type})).$convert())
28445          } else {
28446            
28447            if ($truthy((attrlist = match['$[]'](2)))) {
28448              
28449              id = (attributes = self.$parse_quoted_text_attributes(attrlist))['$[]']("id");
28450              if ($eqeq(type, "mark")) {
28451                type = "unquoted"
28452              };
28453            };
28454            return "" + (match['$[]'](1)) + ($$('Inline').$new(self, "quoted", match['$[]'](3), $hash2(["type", "id", "attributes"], {"type": type, "id": id, "attributes": attributes})).$convert());
28455          }
28456        } else {
28457          
28458          if ($truthy((attrlist = match['$[]'](1)))) {
28459            
28460            id = (attributes = self.$parse_quoted_text_attributes(attrlist))['$[]']("id");
28461            if ($eqeq(type, "mark")) {
28462              type = "unquoted"
28463            };
28464          };
28465          return $$('Inline').$new(self, "quoted", match['$[]'](2), $hash2(["type", "id", "attributes"], {"type": type, "id": id, "attributes": attributes})).$convert();
28466        };
28467      });
28468      
28469      $def(self, '$do_replacement', function $$do_replacement(m, replacement, restore) {
28470        var captured = nil;
28471
28472        if ($truthy((captured = m['$[]'](0))['$include?']($$('RS')))) {
28473          return captured.$sub($$('RS'), "")
28474        } else 
28475        switch (restore) {
28476          case "none":
28477            return replacement
28478          case "bounding":
28479            return $rb_plus($rb_plus(m['$[]'](1), replacement), m['$[]'](2))
28480          default:
28481            return $rb_plus(m['$[]'](1), replacement)
28482        }
28483      });
28484      nil;
28485      
28486      $def(self, '$parse_quoted_text_attributes', function $$parse_quoted_text_attributes(str) {
28487        var $a, $b, self = this, before = nil, _ = nil, after = nil, attrs = nil, id = nil, roles = nil;
28488
28489        
28490        if ($truthy(str['$include?']($$('ATTR_REF_HEAD')))) {
28491          str = self.$sub_attributes(str)
28492        };
28493        if ($truthy(str['$include?'](","))) {
28494          str = str.$slice(0, str.$index(","))
28495        };
28496        if ($truthy((str = str.$strip())['$empty?']())) {
28497          return $hash2([], {})
28498        } else if (($truthy(str['$start_with?'](".", "#")) && ($truthy($$('Compliance').$shorthand_property_syntax())))) {
28499          
28500          $b = str.$partition("#"), $a = $to_ary($b), (before = ($a[0] == null ? nil : $a[0])), (_ = ($a[1] == null ? nil : $a[1])), (after = ($a[2] == null ? nil : $a[2])), $b;
28501          attrs = $hash2([], {});
28502          if ($truthy(after['$empty?']())) {
28503            if ($truthy($rb_gt(before.$length(), 1))) {
28504              attrs['$[]=']("role", before.$tr(".", " ").$lstrip())
28505            }
28506          } else {
28507            
28508            $b = after.$partition("."), $a = $to_ary($b), (id = ($a[0] == null ? nil : $a[0])), (_ = ($a[1] == null ? nil : $a[1])), (roles = ($a[2] == null ? nil : $a[2])), $b;
28509            if (!$truthy(id['$empty?']())) {
28510              attrs['$[]=']("id", id)
28511            };
28512            if ($truthy(roles['$empty?']())) {
28513              if ($truthy($rb_gt(before.$length(), 1))) {
28514                attrs['$[]=']("role", before.$tr(".", " ").$lstrip())
28515              }
28516            } else if ($truthy($rb_gt(before.$length(), 1))) {
28517              attrs['$[]=']("role", $rb_plus($rb_plus(before, "."), roles).$tr(".", " ").$lstrip())
28518            } else {
28519              attrs['$[]=']("role", roles.$tr(".", " "))
28520            };
28521          };
28522          return attrs;
28523        } else {
28524          return $hash2(["role"], {"role": str})
28525        };
28526      });
28527      
28528      $def(self, '$normalize_text', function $$normalize_text(text, normalize_whitespace, unescape_closing_square_brackets) {
28529        
28530        
28531        if (normalize_whitespace == null) normalize_whitespace = nil;
28532        if (unescape_closing_square_brackets == null) unescape_closing_square_brackets = nil;
28533        if (!$truthy(text['$empty?']())) {
28534          
28535          if ($truthy(normalize_whitespace)) {
28536            text = text.$strip().$tr($$('LF'), " ")
28537          };
28538          if (($truthy(unescape_closing_square_brackets) && ($
28538truthy(text['$include?']($$('R_SB')))))) {
28539            text = text.$gsub($$('ESC_R_SB'), $$('R_SB'))
28540          };
28541        };
28542        return text;
28543      }, -2);
28544      return $def(self, '$split_simple_csv', function $$split_simple_csv(str) {
28545        var values = nil, accum = nil, quote_open = nil;
28546
28547        if ($truthy(str['$empty?']())) {
28548          return []
28549        } else if ($truthy(str['$include?']("\""))) {
28550          
28551          values = [];
28552          accum = "";
28553          quote_open = nil;
28554          $send(str, 'each_char', [], function $$48(c){
28555            
28556            if (c == null) c = nil;
28557            
28558            switch (c) {
28559              case ",":
28560                if ($truthy(quote_open)) {
28561                  return (accum = $rb_plus(accum, c))
28562                } else {
28563                  
28564                  values['$<<'](accum.$strip());
28565                  return (accum = "");
28566                }
28567                break;
28568              case "\"":
28569                return (quote_open = quote_open['$!']())
28570              default:
28571                return (accum = $rb_plus(accum, c))
28572            };});
28573          return values['$<<'](accum.$strip());
28574        } else {
28575          return $send(str.$split(","), 'map', [], function $$49(it){
28576            
28577            if (it == null) it = nil;
28578            return it.$strip();})
28579        }
28580      });
28581    })($nesting[0], $nesting)
28582  })($nesting[0], $nesting)
28583};
28584
28585Opal.modules["asciidoctor/version"] = function(Opal) {/* Generated by Opal 1.7.3 */
28586  "use strict";
28587  var $module = Opal.module, $const_set = Opal.const_set, $nesting = [], nil = Opal.nil;
28588
28589  return (function($base, $parent_nesting) {
28590    var self = $module($base, 'Asciidoctor');
28591
28592    var $nesting = [self].concat($parent_nesting);
28593
28594    return $const_set($nesting[0], 'VERSION', "2.0.20")
28595  })($nesting[0], $nesting)
28596};
28597
28598Opal.modules["asciidoctor/abstract_node"] = function(Opal) {/* Generated by Opal 1.7.3 */
28599  "use strict";
28600  var $module = Opal.module, $klass = Opal.klass, $hash2 = Opal.hash2, $eqeq = Opal.eqeq, $truthy = Opal.truthy, $def = Opal.def, $send = Opal.send, $rb_minus = Opal.rb_minus, $eqeqeq = Opal.eqeqeq, $rb_lt = Opal.rb_lt, $not = Opal.not, $to_ary = Opal.to_ary, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$;
28601
28602  Opal.add_stubs('include,attr_reader,attr_accessor,==,document,to_s,[],merge,raise,converter,attributes,key?,[]=,delete,tap,new,each_key,end_with?,<<,slice,-,length,update,split,include?,===,join,empty?,apply_reftext_subs,attr?,attr,extname?,image_uri,<,safe,normalize_web_path,uriish?,encode_spaces_in_uri,generate_data_uri_from_uri,generate_data_uri,extname,normalize_system_path,readable?,strict_encode64,binread,warn,logger,require_library,!,open_uri,content_type,read,base_dir,root?,path_resolver,system_path,web_path,!=,prepare_source_string,fetch,read_asset');
28603  return (function($base, $parent_nesting) {
28604    var self = $module($base, 'Asciidoctor');
28605
28606    var $nesting = [self].concat($parent_nesting);
28607
28608    return (function($base, $super, $parent_nesting) {
28609      var self = $klass($base, $super, 'AbstractNode');
28610
28611      var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype;
28612
28613      $proto.document = $proto.attributes = $proto.parent = nil;
28614      
28615      self.$include($$('Logging'));
28616      self.$include($$('Substitutors'));
28617      self.$attr_reader("attributes");
28618      self.$attr_reader("context");
28619      self.$attr_reader("document");
28620      self.$attr_accessor("id");
28621      self.$attr_reader("node_name");
28622      self.$attr_reader("parent");
28623      
28624      $def(self, '$initialize', function $$initialize(parent, context, opts) {
28625        var self = this, attrs = nil;
28626
28627        
28628        if (opts == null) opts = $hash2([], {});
28629        if ($eqeq(context, "document")) {
28630          self.document = self
28631        } else if ($truthy(parent)) {
28632          self.document = (self.parent = parent).$document()
28633        };
28634        self.node_name = (self.context = context).$to_s();
28635        self.attributes = ($truthy((attrs = opts['$[]']("attributes"))) ? (attrs.$merge()) : ($hash2([], {})));
28636        return (self.passthroughs = []);
28637      }, -3);
28638      
28639      $def(self, '$block?', function $AbstractNode_block$ques$1() {
28640        var self = this;
28641
28642        return self.$raise($$$('NotImplementedError'))
28643      });
28644      
28645      $def(self, '$inline?', function $AbstractNode_inline$ques$2() {
28646        var self = this;
28647
28648        return self.$raise($$$('NotImplementedError'))
28649      });
28650      
28651      $def(self, '$converter', function $$converter() {
28652        var self = this;
28653
28654        return self.document.$converter()
28655      });
28656      
28657      $def(self, '$parent=', function $AbstractNode_parent$eq$3(parent) {
28658        var $a, self = this;
28659
28660        return $a = [parent, parent.$document()], (self.parent = $a[0]), (self.document = $a[1]), $a
28661      });
28662      
28663      $def(self, '$attr', function $$attr(name, default_value, fallback_name) {
28664        var self = this, $ret_or_1 = nil, $ret_or_2 = nil, $ret_or_3 = nil, $ret_or_4 = nil;
28665
28666        
28667        if (default_value == null) default_value = nil;
28668        if (fallback_name == null) fallback_name = nil;
28669        if ($truthy(($ret_or_1 = self.attributes['$[]'](name.$to_s())))) {
28670          return $ret_or_1
28671        } else {
28672          
28673          if ($truthy(($ret_or_2 = ($truthy(($ret_or_3 = ($truthy(($ret_or_4 = fallback_name)) ? (self.parent) : ($ret_or_4)))) ? (self.document.$attributes()['$[]'](($eqeq(fallback_name, true) ? (name) : (fallback_name)).$to_s())) : ($ret_or_3))))) {
28674            return $ret_or_2
28675          } else {
28676            return default_value
28677          };
28678        };
28679      }, -2);
28680      
28681      $def(self, '$attr?', function $AbstractNode_attr$ques$4(name, expected_value, fallback_name) {
28682        var self = this, $ret_or_1 = nil;
28683
28684        
28685        if (expected_value == null) expected_value = nil;
28686        if (fallback_name == null) fallback_name = nil;
28687        if ($truthy(expected_value)) {
28688          return expected_value['$=='](($truthy(($ret_or_1 = self.attributes['$[]'](name.$to_s()))) ? ($ret_or_1) : ((($truthy(fallback_name) && ($truthy(self.parent))) ? (self.document.$attributes()['$[]'](($eqeq(fallback_name, true) ? (name) : (fallback_name)).$to_s())) : (nil)))))
28689        } else if ($truthy(($ret_or_1 = self.attributes['$key?'](name.$to_s())))) {
28690          return $ret_or_1
28691        } else {
28692          
28693          if (($truthy(fallback_name) && ($truthy(self.parent)))) {
28694            
28695            return self.document.$attributes()['$key?'](($eqeq(fallback_name, true) ? (name) : (fallback_name)).$to_s());
28696          } else {
28697            return false
28698          };
28699        };
28700      }, -2);
28701      
28702      $def(self, '$set_attr', function $$set_attr(name, value, overwrite) {
28703        var self = this;
28704
28705        
28706        if (value == null) value = "";
28707        if (overwrite == null) overwrite = true;
28708        if (($eqeq(overwrite, false) && ($truthy(self.attributes['$key?'](name))))) {
28709          return false
28710        } else {
28711          
28712          self.attributes['$[]='](name, value);
28713          return true;
28714        };
28715      }, -2);
28716      
28717      $def(self, '$remove_attr', function $$remove_attr(name) {
28718        var self = this;
28719
28720        return self.attributes.$delete(name)
28721      });
28722      
28723      $def(self, '$option?', function $AbstractNode_option$ques$5(name) {
28724        var self = this;
28725
28726        if ($truthy(self.attributes['$[]']("" + (name) + "-option"))) {
28727          return true
28728        } else {
28729          return false
28730        }
28731      });
28732      
28733      $def(self, '$set_option', function $$set_option(name) {
28734        var self = this;
28735
28736        
28737        self.attributes['$[]=']("" + (name) + "-option", "");
28738        return nil;
28739      });
28740      
28741      $def(self, '$enabled_options', function $$enabled_options() {
28742        var self = this;
28743
28744        return $send($$$('Set').$new(), 'tap', [], function $$6(accum){var self = $$6.$$s == null ? this : $$6.$$s;
28745          if (self.attributes == null) self.attributes = nil;
28746
28747          
28748          if (accum == null) accum = nil;
28749          return $send(self.attributes, 'each_key', [], function $$7(k){
28750            
28751            if (k == null) k = nil;
28752            if ($truthy(k.$to_s()['$end_with?']("-option"))) {
28753              return accum['$<<'](k.$slice(0, $rb_minus(k.$length(), 7)))
28754            } else {
28755              return nil
28756            };});}, {$$s: self})
28757      });
28758      
28759      $def(self, '$update_attributes', function $$update_attributes(new_attributes) {
28760        var self = this;
28761
28762        return self.attributes.$update(new_attributes)
28763      });
28764      
28765      $def(self, '$role', function $$role() {
28766        var self = this;
28767
28768        return self.attributes['$[]']("role")
28769      });
28770      
28771      $def(self, '$roles', function $$roles() {
28772        var self = this, val = nil;
28773
28774        if ($truthy((val = self.attributes['$[]']("role")))) {
28775          return val.$split()
28776        } else {
28777          return []
28778        }
28779      });
28780      
28781      $def(self, '$role?', function $AbstractNode_role$ques$8(expected_value) {
28782        var self = this;
28783
28784        
28785        if (expected_value == null) expected_value = nil;
28786        if ($truthy(expected_value)) {
28787          return expected_value['$=='](self.attributes['$[]']("role"))
28788        } else {
28789          
28790          return self.attributes['$key?']("role");
28791        };
28792      }, -1);
28793      
28794      $def(self, '$has_role?', function $AbstractNode_has_role$ques$9(name) {
28795        var self = this, val = nil;
28796
28797        if ($truthy((val = self.attributes['$[]']("role")))) {
28798          
28799          return (((" ") + (val)) + " ")['$include?'](" " + (name) + " ");
28800        } else {
28801          return false
28802        }
28803      });
28804      
28805      $def(self, '$role=', function $AbstractNode_role$eq$10(names) {
28806        var $a, self = this;
28807
28808        return ($a = ["role", ($eqeqeq($$$('Array'), names) ? (names.$join(" ")) : (names))], $send(self.attributes, '[]=', $a), $a[$a.length - 1])
28809      });
28810      
28811      $def(self, '$add_role', function $$add_role(name) {
28812        var self = this, val = nil;
28813
28814        if ($truthy((val = self.attributes['$[]']("role")))) {
28815          if ($truthy((((" ") + (val)) + " ")['$include?'](" " + (name) + " "))) {
28816            return false
28817          } else {
28818            
28819            self.attributes['$[]=']("role", "" + (val) + " " + (name));
28820            return true;
28821          }
28822        } else {
28823          
28824          self.attributes['$[]=']("role", name);
28825          return true;
28826        }
28827      });
28828      
28829      $def(self, '$remove_role', function $$remove_role(name) {
28830        var self = this, val = nil;
28831
28832        if (($truthy((val = self.attributes['$[]']("role"))) && ($truthy((val = val.$split()).$delete(name))))) {
28833          
28834          if ($truthy(val['$empty?']())) {
28835            self.attributes.$delete("role")
28836          } else {
28837            self.attributes['$[]=']("role", val.$join(" "))
28838          };
28839          return true;
28840        } else {
28841          return false
28842        }
28843      });
28844      
28845      $def(self, '$reftext', function $$reftext() {
28846        var self = this, val = nil;
28847
28848        if ($truthy((val = self.attributes['$[]']("reftext")))) {
28849          
28850          return self.$apply_reftext_subs(val);
28851        } else {
28852          return nil
28853        }
28854      });
28855      
28856      $def(self, '$reftext?', function $AbstractNode_reftext$ques$11() {
28857        var self = this;
28858
28859        return self.attributes['$key?']("reftext")
28860      });
28861      
28862      $def(self, '$icon_uri', function $$icon_uri(name) {
28863        var self = this, icon = nil;
28864
28865        
28866        if ($truthy(self['$attr?']("icon"))) {
28867          
28868          icon = self.$attr("icon");
28869          if (!$truthy($$('Helpers')['$extname?'](icon))) {
28870            icon = "" + (icon) + "." + (self.document.$attr("icontype", "png"))
28871          };
28872        } else {
28873          icon = "" + (name) + "." + (self.document.$attr("icontype", "png"))
28874        };
28875        return self.$image_uri(icon, "iconsdir");
28876      });
28877      
28878      $def(self, '$image_uri', function $$image_uri(target_image, asset_dir_key) {
28879        var self = this, doc = nil, images_base = nil;
28880
28881        
28882        if (asset_dir_key == null) asset_dir_key = "imagesdir";
28883        if (($truthy($rb_lt((doc = self.document).$safe(), $$$($$('SafeMode'), 'SECURE'))) && ($truthy(doc['$attr?']("data-uri"))))) {
28884          if ((($truthy($$('Helpers')['$uriish?'](target_image)) && ($truthy((target_image = $$('Helpers').$encode_spaces_in_uri(target_image))))) || (((($truthy(asset_dir_key) && ($truthy((images_base = doc.$attr(asset_dir_key))))) && ($truthy($$('Helpers')['$uriish?'](images_base)))) && ($truthy((target_image = self.$normalize_web_path(target_image, images_base, false)))))))) {
28885            if ($truthy(doc['$attr?']("allow-uri-read"))) {
28886              
28887              return self.$generate_data_uri_from_uri(target_image, doc['$attr?']("cache-uri"));
28888            } else {
28889              return target_image
28890            }
28891          } else {
28892            return self.$generate_data_uri(target_image, asset_dir_key)
28893          }
28894        } else {
28895          return self.$normalize_web_path(target_image, ($truthy(asset_dir_key) ? (doc.$attr(asset_dir_key)) : (nil)))
28896        };
28897      }, -2);
28898      
28899      $def(self, '$media_uri', function $$media_uri(target, asset_dir_key) {
28900        var self = this;
28901
28902        
28903        if (asset_dir_key == null) asset_dir_key = "imagesdir";
28904        return self.$normalize_web_path(target, ($truthy(asset_dir_key) ? (self.document.$attr(asset_dir_key)) : (nil)));
28905      }, -2);
28906      
28907      $def(self, '$generate_data_uri', function $$generate_data_uri(target_image, asset_dir_key) {
28908        var self = this, ext = nil, mimetype = nil, image_path = nil;
28909
28910        
28911        if (asset_dir_key == null) asset_dir_key = nil;
28912        if ($truthy((ext = $$('Helpers').$extname(target_image, nil)))) {
28913          mimetype = ($eqeq(ext, ".svg") ? ("image/svg+xml") : ("image/" + (ext.$slice(1, ext.$length()))))
28914        } else {
28915          mimetype = "application/octet-stream"
28916        };
28917        if ($truthy(asset_dir_key)) {
28918          image_path = self.$normalize_system_path(target_image, self.document.$attr(asset_dir_key), nil, $hash2(["target_name"], {"target_name": "image"}))
28919        } else {
28920          image_path = self.$normalize_system_path(target_image)
28921        };
28922        if ($truthy($$$('File')['$readable?'](image_path))) {
28923          return "data:" + (mimetype) + ";base64," + ($$$('Base64').$strict_encode64($$$('File').$binread(image_path)))
28924        } else {
28925          
28926          self.$logger().$warn("image to embed not found or not readable: " + (image_path));
28927          return "data:" + (mimetype) + ";base64,";
28928        };
28929      }, -2);
28930      
28931      $def(self, '$generate_data_uri_from_uri', function $$generate_data_uri_from_uri(image_uri, cache_uri) {
28932        var $a, $b, self = this, mimetype = nil, bindata = nil;
28933
28934        
28935        if (cache_uri == null) cache_uri = false;
28936        if ($truthy(cache_uri)) {
28937          $$('Helpers').$require_library("open-uri/cached", "open-uri-cached")
28938        } else if ($not($$('RUBY_ENGINE_OPAL'))) {
28939          $$$('OpenURI')
28940        };
28941        
28942        try {
28943          
28944          $b = $send($$$('OpenURI'), 'open_uri', [image_uri, $$('URI_READ_MODE')], function $$12(f){
28945            
28946            if (f == null) f = nil;
28947            return [f.$content_type(), f.$read()];}), $a = $to_ary($b), (mimetype = ($a[0] == null ? nil : $a[0])), (bindata = ($a[1] == null ? nil : $a[1])), $b;
28948          return "data:" + (mimetype) + ";base64," + ($$$('Base64').$strict_encode64(bindata));
28949        } catch ($err) {
28950          if (Opal.rescue($err, [$$('StandardError')])) {
28951            try {
28952              
28953              self.$logger().$warn("could not retrieve image data from URI: " + (image_uri));
28954              return image_uri;
28955            } finally { Opal.pop_exception(); }
28956          } else { throw $err; }
28957        };;
28958      }, -2);
28959      
28960      $def(self, '$normalize_asset_path', function $$normalize_asset_path(asset_ref, asset_name, autocorrect) {
28961        var self = this;
28962
28963        
28964        if (asset_name == null) asset_name = "path";
28965        if (autocorrect == null) autocorrect = true;
28966        return self.$normalize_system_path(asset_ref, self.document.$base_dir(), nil, $hash2(["target_name", "recover"], {"target_name": asset_name, "recover": autocorrect}));
28967      }, -2);
28968      
28969      $def(self, '$normalize_system_path', function $$normalize_system_path(target, start, jail, opts) {
28970        var self = this, doc = nil, $ret_or_1 = nil;
28971
28972        
28973        if (start == null) start = nil;
28974        if (jail == null) jail = nil;
28975        if (opts == null) opts = $hash2([], {});
28976        if ($truthy($rb_lt((doc = self.document).$safe(), $$$($$('SafeMode'), 'SAFE')))) {
28977          if ($truthy(start)) {
28978            if (!$truthy(doc.$path_resolver()['$root?'](start))) {
28979              start = $$$('File').$join(doc.$base_dir(), start)
28980            }
28981          } else {
28982            start = doc.$base_dir()
28983          }
28984        } else {
28985          
28986          start = ($truthy(($ret_or_1 = start)) ? ($ret_or_1) : (doc.$base_dir()));
28987          jail = ($truthy(($ret_or_1 = jail)) ? ($ret_or_1) : (doc.$base_dir()));
28988        };
28989        return doc.$path_resolver().$system_path(target, start, jail, opts);
28990      }, -2);
28991      
28992      $def(self, '$normalize_web_path', function $$normalize_web_path(target, start, preserve_uri_target) {
28993        var self = this;
28994
28995        
28996        if (start == null) start = nil;
28997        if (preserve_uri_target == null) preserve_uri_target = true;
28998        if (($truthy(preserve_uri_target) && ($truthy($$('Helpers')['$uriish?'](target))))) {
28999          return $$('Helpers').$encode_spaces_in_uri(target)
29000        } else {
29001          return self.document.$path_resolver().$web_path(target, start)
29002        };
29003      }, -2);
29004      
29005      $def(self, '$read_asset', function $$read_asset(path, opts) {
29006        var self = this, $ret_or_1 = nil;
29007
29008        
29009        if (opts == null) opts = $hash2([], {});
29010        if (!$eqeqeq($$$('Hash'), opts)) {
29011          opts = $hash2(["warn_on_failure"], {"warn_on_failure": opts['$!='](false)})
29012        };
29013        if ($truthy($$$('File')['$readable?'](path))) {
29014          if ($truthy(opts['$[]']("normalize"))) {
29015            
29016            return $$('Helpers').$prepare_source_string($$$('File').$read(path, $hash2(["mode"], {"mode": $$('FILE_READ_MODE')}))).$join($$('LF'));
29017          } else {
29018            
29019            return $$$('File').$read(path, $hash2(["mode"], {"mode": $$('FILE_READ_MODE')}));
29020          }
29021        } else if ($truthy(opts['$[]']("warn_on_failure"))) {
29022          
29023          self.$logger().$warn("" + (($truthy(($ret_or_1 = self.$attr("docfile"))) ? ($ret_or_1) : ("<stdin>"))) + ": " + (($truthy(($ret_or_1 = opts['$[]']("label"))) ? ($ret_or_1) : ("file"))) + " does not exist or cannot be read: " + (path));
29024          return nil;
29025        } else {
29026          return nil
29027        };
29028      }, -2);
29029      
29030      $def(self, '$read_contents', function $$read_contents(target, opts) {
29031        var self = this, doc = nil, start = nil, contents = nil, $ret_or_1 = nil;
29032
29033        
29034        if (opts == null) opts = $hash2([], {});
29035        doc = self.document;
29036        if (($truthy($$('Helpers')['$uriish?'](target)) || ((($truthy((start = opts['$[]']("start"))) && ($truthy($$('Helpers')['$uriish?'](start)))) && ($truthy((target = doc.$path_resolver().$web_path(target, start)))))))) {
29037          if ($truthy(doc['$attr?']("allow-uri-read"))) {
29038            
29039            if ($truthy(doc['$attr?']("cache-uri"))) {
29040              $$('Helpers').$require_library("open-uri/cached", "open-uri-cached")
29041            };
29042            
29043            try {
29044              if ($truthy(opts['$[]']("normalize"))) {
29045                contents = $$('Helpers').$prepare_source_string($send($$$('OpenURI'), 'open_uri', [target, $$('URI_READ_MODE')], function $$13(f){
29046                  
29047                  if (f == null) f = nil;
29048                  return f.$read();})).$join($$('LF'))
29049              } else {
29050                contents = $send($$$('OpenURI'), 'open_uri', [target, $$('URI_READ_MODE')], function $$14(f){
29051                  
29052                  if (f == null) f = nil;
29053                  return f.$read();})
29054              }
29055            } catch ($err) {
29056              if (Opal.rescue($err, [$$('StandardError')])) {
29057                try {
29058                  if ($truthy(opts.$fetch("warn_on_failure", true))) {
29059                    self.$logger().$warn("could not retrieve contents of " + (($truthy(($ret_or_1 = opts['$[]']("label"))) ? ($ret_or_1) : ("asset"))) + " at URI: " + (target))
29060                  }
29061                } finally { Opal.pop_exception(); }
29062              } else { throw $err; }
29063            };;
29064          } else if ($truthy(opts.$fetch("warn_on_failure", true))) {
29065            self.$logger().$warn("cannot retrieve contents of " + (($truthy(($ret_or_1 = opts['$[]']("label"))) ? ($ret_or_1) : ("asset"))) + " at URI: " + (target) + " (allow-uri-read attribute not enabled)")
29066          }
29067        } else {
29068          
29069          target = self.$normalize_system_path(target, opts['$[]']("start"), nil, $hash2(["target_name"], {"target_name": ($truthy(($ret_or_1 = opts['$[]']("label"))) ? ($ret_or_1) : ("asset"))}));
29070          contents = self.$read_asset(target, $hash2(["normalize", "warn_on_failure", "label"], {"normalize": opts['$[]']("normalize"), "warn_on_failure": opts.$fetch("warn_on_failure", true), "label": opts['$[]']("label")}));
29071        };
29072        if ((($truthy(contents) && ($truthy(opts['$[]']("warn_if_empty")))) && ($truthy(contents['$empty?']())))) {
29073          self.$logger().$warn("contents of " + (($truthy(($ret_or_1 = opts['$[]']("label"))) ? ($ret_or_1) : ("asset"))) + " is empty: " + (target))
29074        };
29075        return contents;
29076      }, -2);
29077      return $def(self, '$is_uri?', function $AbstractNode_is_uri$ques$15(str) {
29078        
29079        return $$('Helpers')['$uriish?'](str)
29080      });
29081    })($nesting[0], null, $nesting)
29082  })($nesting[0], $nesting)
29083};
29084
29085Opal.modules["asciidoctor/abstract_block"] = function(Opal) {/* Generated by Opal 1.7.3 */
29086  "use strict";
29087  var $module = Opal.module, $klass = Opal.klass, $hash2 = Opal.hash2, $send2 = Opal.send2, $find_super = Opal.find_super, $eqeq = Opal.eqeq, $eqeqeq = Opal.eqeqeq, $def = Opal.def, $return_val = Opal.return_val, $truthy = Opal.truthy, $alias = Opal.alias, $send = Opal.send, $rb_plus = Opal.rb_plus, $not = Opal.not, $neqeq = Opal.neqeq, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$;
29088
29089  Opal.add_stubs('attr_reader,attr_writer,attr_accessor,==,===,level,file,lineno,playback_attributes,convert,converter,join,map,to_s,parent,parent=,<<,empty?,Integer,find_by_internal,to_proc,find_by,context,[],items,+,find_index,include?,next_adjacent_block,blocks,select,sub_specialchars,match?,sub_replacements,title,apply_title_subs,delete,!,reftext,nil_or_empty?,sub_placeholder,sub_quotes,compat_mode,attributes,chomp,increment_and_store_counter,index=,numbered,sectname,numeral=,counter,caption=,numeral,int_to_roman,each,assign_numeral,reindex_sections,protected,has_role?,raise,header?,!=,flatten,head,rows,merge,body,foot,style,inner_document');
29090  return (function($base, $parent_nesting) {
29091    var self = $module($base, 'Asciidoctor');
29092
29093    var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
29094
29095    return (function($base, $super, $parent_nesting) {
29096      var self = $klass($base, $super, 'AbstractBlock');
29097
29098      var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype;
29099
29100      $proto.source_location = $proto.document = $proto.attributes = $proto.blocks = $proto.numeral = $proto.context = $proto.parent = $proto.caption = $proto.style = $proto.converted_title = $proto.title = $proto.subs = $proto.next_section_index = $proto.next_section_ordinal = $proto.id = $proto.header = nil;
29101      
29102      self.$attr_reader("blocks");
29103      self.$attr_writer("caption");
29104      self.$attr_accessor("content_model");
29105      self.$attr_accessor("level");
29106      self.$attr_accessor("numeral");
29107      self.$attr_accessor("source_location");
29108      self.$attr_accessor("style");
29109      self.$attr_reader("subs");
29110      
29111      $def(self, '$initialize', function $$initialize(parent, context, opts) {
29112        var $yield = $$initialize.$$p || nil, self = this;
29113
29114        $$initialize.$$p = null;
29115        
29116        if (opts == null) opts = $hash2([], {});
29117        $send2(self, $find_super(self, 'initialize', $$initialize, false, true), 'initialize', [parent, context, opts], $yield);
29118        self.content_model = "compound";
29119        self.blocks = [];
29120        self.subs = [];
29121        self.id = (self.title = (self.caption = (self.numeral = (self.style = (self.default_subs = (self.source_location = nil))))));
29122        if (($eqeq(context, "document") || ($eqeq(context, "section")))) {
29123          
29124          self.level = (self.next_section_index = 0);
29125          return (self.next_section_ordinal = 1);
29126        } else if ($eqeqeq($$('AbstractBlock'), parent)) {
29127          return (self.level = parent.$level())
29128        } else {
29129          return (self.level = nil)
29130        };
29131      }, -3);
29132      
29133      $def(self, '$block?', $return_val(true));
29134      
29135      $def(self, '$inline?', $return_val(false));
29136      
29137      $def(self, '$file', function $$file() {
29138        var self = this, $ret_or_1 = nil;
29139
29140        if ($truthy(($ret_or_1 = self.source_location))) {
29141          return self.source_location.$file()
29142        } else {
29143          return $ret_or_1
29144        }
29145      });
29146      
29147      $def(self, '$lineno', function $$lineno() {
29148        var self = this, $ret_or_1 = nil;
29149
29150        if ($truthy(($ret_or_1 = self.source_location))) {
29151          return self.source_location.$lineno()
29152        } else {
29153          return $ret_or_1
29154        }
29155      });
29156      
29157      $def(self, '$convert', function $$convert() {
29158        var self = this;
29159
29160        
29161        self.document.$playback_attributes(self.attributes);
29162        return self.$converter().$convert(self);
29163      });
29164      $alias(self, "render", "convert");
29165      
29166      $def(self, '$content', function $$content() {
29167        var self = this;
29168
29169        return $send(self.blocks, 'map', [], function $$1(b){
29170          
29171          if (b == null) b = nil;
29172          return b.$convert();}).$join($$('LF'))
29173      });
29174      
29175      $def(self, '$context=', function $AbstractBlock_context$eq$2(context) {
29176        var self = this;
29177
29178        return (self.node_name = (self.context = context).$to_s())
29179      });
29180      
29181      $def(self, '$<<', function $AbstractBlock_$lt$lt$3(block) {
29182        var self = this;
29183
29184        
29185        if (!$eqeq(block.$parent(), self)) {
29186          block['$parent='](self)
29187        };
29188        self.blocks['$<<'](block);
29189        return self;
29190      });
29191      $alias(self, "append", "<<");
29192      
29193      $def(self, '$blocks?', function $AbstractBlock_blocks$ques$4() {
29194        var self = this;
29195
29196        if ($truthy(self.blocks['$empty?']())) {
29197          return false
29198        } else {
29199          return true
29200        }
29201      });
29202      
29203      $def(self, '$sections?', $return_val(false));
29204      
29205      $def(self, '$number', function $$number() {
29206        var self = this;
29207
29208        try {
29209          
29210          return self.$Integer(self.numeral);
29211        } catch ($err) {
29212          if (Opal.rescue($err, [$$('StandardError')])) {
29213            try {
29214              return self.numeral
29215            } finally { Opal.pop_exception(); }
29216          } else { throw $err; }
29217        }
29218      });
29219      
29220      $def(self, '$number=', function $AbstractBlock_number$eq$5(val) {
29221        var self = this;
29222
29223        return (self.numeral = val.$to_s())
29224      });
29225      
29226      $def(self, '$find_by', function $$find_by(selector) {
29227        var block = $$find_by.$$p || nil, self = this, result = nil;
29228
29229        $$find_by.$$p = null;
29230        
29231        ;
29232        if (selector == null) selector = $hash2([], {});
29233        try {
29234          return $send(self, 'find_by_internal', [selector, (result = [])], block.$to_proc())
29235        } catch ($err) {
29236          if (Opal.rescue($err, [$$$('StopIteration')])) {
29237            try {
29238              return result
29239            } finally { Opal.pop_exception(); }
29240          } else { throw $err; }
29241        };
29242      }, -1);
29243      $alias(self, "query", "find_by");
29244      
29245      $def(self, '$next_adjacent_block', function $$next_adjacent_block() {
29246        var self = this, p = nil, sib = nil;
29247
29248        if ($eqeq(self.context, "document")) {
29249          return nil
29250        } else if (($eqeq((p = self.parent).$context(), "dlist") && ($eqeq(self.context, "list_item")))) {
29251          if ($truthy((sib = p.$items()['$[]']($rb_plus($send(p.$items(), 'find_index', [], function $$6(terms, desc){var self = $$6.$$s == null ? this : $$6.$$s, $ret_or_1 = nil;
29252
29253            
29254            if (terms == null) terms = nil;
29255            if (desc == null) desc = nil;
29256            if ($truthy(($ret_or_1 = terms['$include?'](self)))) {
29257              return $ret_or_1
29258            } else {
29259              return desc['$=='](self)
29260            };}, {$$s: self}), 1))))) {
29261            return sib
29262          } else {
29263            return p.$next_adjacent_block()
29264          }
29265        } else if ($truthy((sib = p.$blocks()['$[]']($rb_plus(p.$blocks().$find_index(self), 1))))) {
29266          return sib
29267        } else {
29268          return p.$next_adjacent_block()
29269        }
29270      });
29271      
29272      $def(self, '$sections', function $$sections() {
29273        var self = this;
29274
29275        return $send(self.blocks, 'select', [], function $$7(block){
29276          
29277          if (block == null) block = nil;
29278          return block.$context()['$==']("section");})
29279      });
29280      
29281      $def(self, '$alt', function $$alt() {
29282        var self = this, text = nil;
29283
29284        if ($truthy((text = self.attributes['$[]']("alt")))) {
29285          if ($eqeq(text, self.attributes['$[]']("default-alt"))) {
29286            return self.$sub_specialchars(text)
29287          } else {
29288            
29289            text = self.$sub_specialchars(text);
29290            if ($truthy($$('ReplaceableTextRx')['$match?'](text))) {
29291              
29292              return self.$sub_replacements(text);
29293            } else {
29294              return text
29295            };
29296          }
29297        } else {
29298          return ""
29299        }
29300      });
29301      
29302      $def(self, '$caption', function $$caption() {
29303        var self = this;
29304
29305        if ($eqeq(self.context, "admonition")) {
29306          return self.attributes['$[]']("textlabel")
29307        } else {
29308          return self.caption
29309        }
29310      });
29311      
29312      $def(self, '$captioned_title', function $$captioned_title() {
29313        var self = this;
29314
29315        return "" + (self.caption) + (self.$title())
29316      });
29317      
29318      $def(self, '$list_marker_keyword', function $$list_marker_keyword(list_type) {
29319        var self = this, $ret_or_1 = nil;
29320
29321        
29322        if (list_type == null) list_type = nil;
29323        return $$('ORDERED_LIST_KEYWORDS')['$[]'](($truthy(($ret_or_1 = list_type)) ? ($ret_or_1) : (self.style)));
29324      }, -1);
29325      
29326      $def(self, '$title', function $$title() {
29327        var self = this, $ret_or_1 = nil, $ret_or_2 = nil;
29328
29329        return (self.converted_title = ($truthy(($ret_or_1 = self.converted_title)) ? ($ret_or_1) : ($truthy(($ret_or_2 = self.title)) ? (self.$apply_title_subs(self.title)) : ($ret_or_2))))
29330      });
29331      
29332      $def(self, '$title?', function $AbstractBlock_title$ques$8() {
29333        var self = this;
29334
29335        if ($truthy(self.title)) {
29336          return true
29337        } else {
29338          return false
29339        }
29340      });
29341      
29342      $def(self, '$title=', function $AbstractBlock_title$eq$9(val) {
29343        var self = this;
29344
29345        
29346        self.converted_title = nil;
29347        return (self.title = val);
29348      });
29349      
29350      $def(self, '$sub?', function $AbstractBlock_sub$ques$10(name) {
29351        var self = this;
29352
29353        return self.subs['$include?'](name)
29354      });
29355      
29356      $def(self, '$remove_sub', function $$remove_sub(sub) {
29357        var self = this;
29358
29359        
29360        self.subs.$delete(sub);
29361        return nil;
29362      });
29363      
29364      $def(self, '$xreftext', function $$xreftext(xrefstyle) {
29365        var self = this, val = nil, quoted_title = nil, prefix = nil, caption_attr_name = nil;
29366
29367        
29368        if (xrefstyle == null) xrefstyle = nil;
29369        if (($truthy((val = self.$reftext())) && ($not(val['$empty?']())))) {
29370          return val
29371        } else if ((($truthy(xrefstyle) && ($truthy(self.title))) && ($not(self.caption['$nil_or_empty?']())))) {
29372          
29373          switch (xrefstyle) {
29374            case "full":
29375              
29376              quoted_title = self.$sub_placeholder(self.$sub_quotes(($truthy(self.document.$compat_mode()) ? ("``%s''") : ("\"`%s`\""))), self.$title());
29377              if ((($truthy(self.numeral) && ($truthy((caption_attr_name = $$('CAPTION_ATTRIBUTE_NAMES')['$[]'](self.context))))) && ($truthy((prefix = self.document.$attributes()['$[]'](caption_attr_name)))))) {
29378                return "" + (prefix) + " " + (self.numeral) + ", " + (quoted_title)
29379              } else {
29380                return "" + (self.caption.$chomp(". ")) + ", " + (quoted_title)
29381              };
29382              break;
29383            case "short":
29384              if ((($truthy(self.numeral) && ($truthy((caption_attr_name = $$('CAPTION_ATTRIBUTE_NAMES')['$[]'](self.context))))) && ($truthy((prefix = self.document.$attributes()['$[]'](caption_attr_name)))))) {
29385                return "" + (prefix) + " " + (self.numeral)
29386              } else {
29387                return self.caption.$chomp(". ")
29388              }
29389              break;
29390            default:
29391              return self.$title()
29392          }
29393        } else {
29394          return self.$title()
29395        };
29396      }, -1);
29397      
29398      $def(self, '$assign_caption', function $$assign_caption(value, caption_context) {
29399        var self = this, $ret_or_1 = nil, prefix = nil, attr_name = nil;
29400
29401        
29402        if (caption_context == null) caption_context = self.context;
29403        if ((($truthy(self.caption) || ($not(self.title))) || ($truthy((self.caption = ($truthy(($ret_or_1 = value)) ? ($ret_or_1) : (self.document.$attributes()['$[]']("caption")))))))) {
29404          return nil
29405        } else if (($truthy((attr_name = $$('CAPTION_ATTRIBUTE_NAMES')['$[]'](caption_context))) && ($truthy((prefix = self.document.$attributes()['$[]'](attr_name)))))) {
29406          
29407          self.caption = "" + (prefix) + " " + ((self.numeral = self.document.$increment_and_store_counter("" + (caption_context) + "-number", self))) + ". ";
29408          return nil;
29409        } else {
29410          return nil
29411        };
29412      }, -2);
29413      
29414      $def(self, '$assign_numeral', function $$assign_numeral(section) {
29415        var $a, self = this, like = nil, sectname = nil, caption = nil;
29416
29417        
29418        self.next_section_index = $rb_plus(($a = [self.next_section_index], $send(section, 'index=', $a), $a[$a.length - 1]), 1);
29419        if ($truthy((like = section.$numbered()))) {
29420          if ($eqeq((sectname = section.$sectname()), "appendix")) {
29421            
29422            section['$numeral='](self.document.$counter("appendix-number", "A"));
29423            section['$caption='](($truthy((caption = self.document.$attributes()['$[]']("appendix-caption"))) ? ("" + (caption) + " " + (section.$numeral()) + ": ") : ("" + (section.$numeral()) + ". ")));
29424          } else if (($eqeq(sectname, "chapter") || ($eqeq(like, "chapter")))) {
29425            section['$numeral='](self.document.$counter("chapter-number", 1).$to_s())
29426          } else {
29427            
29428            section['$numeral='](($eqeq(sectname, "part") ? ($$('Helpers').$int_to_roman(self.next_section_ordinal)) : (self.next_section_ordinal.$to_s())));
29429            self.next_section_ordinal = $rb_plus(self.next_section_ordinal, 1);
29430          }
29431        };
29432        return nil;
29433      });
29434      
29435      $def(self, '$reindex_sections', function $$reindex_sections() {
29436        var self = this;
29437
29438        
29439        self.next_section_index = 0;
29440        self.next_section_ordinal = 1;
29441        return $send(self.blocks, 'each', [], function $$11(block){var self = $$11.$$s == null ? this : $$11.$$s;
29442
29443          
29444          if (block == null) block = nil;
29445          if ($eqeq(block.$context(), "section")) {
29446            
29447            self.$assign_numeral(block);
29448            return block.$reindex_sections();
29449          } else {
29450            return nil
29451          };}, {$$s: self});
29452      });
29453      self.$protected();
29454      return $def(self, '$find_by_internal', function $$find_by_internal(selector, result) {
29455        var block = $$find_by_internal.$$p || nil, self = this, id_selector = nil, role_selector = nil, style_selector = nil, any_context = nil, context_selector = nil, verdict = nil;
29456
29457        $$find_by_internal.$$p = null;
29458        
29459        ;
29460        if (selector == null) selector = $hash2([], {});
29461        if (result == null) result = [];
29462        if ((((($truthy((any_context = ($truthy((context_selector = selector['$[]']("context"))) ? (nil) : (true)))) || ($eqeq(context_selector, self.context))) && (($not((style_selector = selector['$[]']("style"))) || ($eqeq(style_selector, self.style))))) && (($not((role_selector = selector['$[]']("role"))) || ($truthy(self['$has_role?'](role_selector)))))) && (($not((id_selector = selector['$[]']("id"))) || ($eqeq(id_selector, self.id)))))) {
29463          if ((block !== nil)) {
29464            if ($truthy((verdict = Opal.yield1(block, self)))) {
29465              
29466              switch (verdict) {
29467                case "prune":
29468                  
29469                  result['$<<'](self);
29470                  if ($truthy(id_selector)) {
29471                    self.$raise($$$('StopIteration'))
29472                  };
29473                  return result;
29474                case "reject":
29475                  
29476                  if ($truthy(id_selector)) {
29477                    self.$raise($$$('StopIteration'))
29478                  };
29479                  return result;
29480                case "stop":
29481                  self.$raise($$$('StopIteration'))
29482                  break;
29483                default:
29484                  
29485                  result['$<<'](self);
29486                  if ($truthy(id_selector)) {
29487                    self.$raise($$$('StopIteration'))
29488                  };
29489              }
29490            } else if ($truthy(id_selector)) {
29491              self.$raise($$$('StopIteration'))
29492            }
29493          } else {
29494            
29495            result['$<<'](self);
29496            if ($truthy(id_selector)) {
29497              self.$raise($$$('StopIteration'))
29498            };
29499          }
29500        };
29501        
29502        switch (self.context) {
29503          case "document":
29504            if (!$eqeq(context_selector, "document")) {
29505              
29506              if (($truthy(self['$header?']()) && (($truthy(any_context) || ($eqeq(context_selector, "section")))))) {
29507                $send(self.header, 'find_by_internal', [selector, result], block.$to_proc())
29508              };
29509              $send(self.blocks, 'each', [], function $$12(b){
29510                
29511                if (b == null) b = nil;
29512                if (($eqeq(context_selector, "section") && ($neqeq(b.$context(), "section")))) {
29513                  return nil
29514                };
29515                return $send(b, 'find_by_internal', [selector, result], block.$to_proc());});
29516            }
29517            break;
29518          case "dlist":
29519            if (($truthy(any_context) || ($neqeq(context_selector, "section")))) {
29520              $send(self.blocks.$flatten(), 'each', [], function $$13(b){
29521                
29522                if (b == null) b = nil;
29523                if ($truthy(b)) {
29524                  return $send(b, 'find_by_internal', [selector, result], block.$to_proc())
29525                } else {
29526                  return nil
29527                };})
29528            }
29529            break;
29530          case "table":
29531            if ($truthy(selector['$[]']("traverse_documents"))) {
29532              
29533              $send(self.$rows().$head(), 'each', [], function $$14(r){
29534                
29535                if (r == null) r = nil;
29536                return $send(r, 'each', [], function $$15(c){
29537                  
29538                  if (c == null) c = nil;
29539                  return $send(c, 'find_by_internal', [selector, result], block.$to_proc());});});
29540              if ($eqeq(context_selector, "inner_document")) {
29541                selector = selector.$merge($hash2(["context"], {"context": "document"}))
29542              };
29543              $send($rb_plus(self.$rows().$body(), self.$rows().$foot()), 'each', [], function $$16(r){
29544                
29545                if (r == null) r = nil;
29546                return $send(r, 'each', [], function $$17(c){
29547                  
29548                  if (c == null) c = nil;
29549                  $send(c, 'find_by_internal', [selector, result], block.$to_proc());
29550                  if ($eqeq(c.$style(), "asciidoc")) {
29551                    return $send(c.$inner_document(), 'find_by_internal', [selector, result], block.$to_proc())
29552                  } else {
29553                    return nil
29554                  };});});
29555            } else {
29556              $send($rb_plus($rb_plus(self.$rows().$head(), self.$rows().$body()), self.$rows().$foot()), 'each', [], function $$18(r){
29557                
29558                if (r == null) r = nil;
29559                return $send(r, 'each', [], function $$19(c){
29560                  
29561                  if (c == null) c = nil;
29562                  return $send(c, 'find_by_internal', [selector, result], block.$to_proc());});})
29563            }
29564            break;
29565          default:
29566            $send(self.blocks, 'each', [], function $$20(b){
29567              
29568              if (b == null) b = nil;
29569              if (($eqeq(context_selector, "section") && ($neqeq(b.$context(), "section")))) {
29570                return nil
29571              };
29572              return $send(b, 'find_by_internal', [selector, result], block.$to_proc());})
29573        };
29574        return result;
29575      }, -1);
29576    })($nesting[0], $$('AbstractNode'), $nesting)
29577  })($nesting[0], $nesting)
29578};
29579
29580Opal.modules["asciidoctor/attribute_list"] = function(Opal) {/* Generated by Opal 1.7.3 */
29581  "use strict";
29582  var $module = Opal.module, $klass = Opal.klass, $const_set = Opal.const_set, $hash = Opal.hash, $regexp = Opal.regexp, $hash2 = Opal.hash2, $def = Opal.def, $truthy = Opal.truthy, $rb_plus = Opal.rb_plus, $send = Opal.send, $defs = Opal.defs, $eqeqeq = Opal.eqeqeq, $eqeq = Opal.eqeq, $rb_times = Opal.rb_times, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$;
29583
29584  Opal.add_stubs('new,[],update,parse,parse_attribute,eos?,skip_delimiter,+,rekey,each_with_index,[]=,private,skip_blank,===,peek,parse_attribute_value,get_byte,start_with?,scan_name,end_with?,rstrip,string,==,unscan,scan_to_delimiter,*,include?,delete,each,split,empty?,apply_subs,scan_to_quote,gsub,skip,scan');
29585  return (function($base, $parent_nesting) {
29586    var self = $module($base, 'Asciidoctor');
29587
29588    var $nesting = [self].concat($parent_nesting);
29589
29590    return (function($base, $super, $parent_nesting) {
29591      var self = $klass($base, $super, 'AttributeList');
29592
29593      var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype;
29594
29595      $proto.attributes = $proto.scanner = $proto.delimiter = $proto.block = $proto.delimiter_skip_pattern = $proto.delimiter_boundary_pattern = nil;
29596      
29597      $const_set($nesting[0], 'APOS', "'");
29598      $const_set($nesting[0], 'BACKSLASH', "\\");
29599      $const_set($nesting[0], 'QUOT', "\"");
29600      $const_set($nesting[0], 'BoundaryRx', $hash($$('QUOT'), /.*?[^\\](?=")/, $$('APOS'), /.*?[^\\](?=')/, ",", /.*?(?=[ \t]*(,|$))/));
29601      $const_set($nesting[0], 'EscapedQuotes', $hash($$('QUOT'), "\\\"", $$('APOS'), "\\'"));
29602      $const_set($nesting[0], 'NameRx', $regexp([$$('CG_WORD'), "[", $$('CC_WORD'), "\\-.]*"]));
29603      $const_set($nesting[0], 'BlankRx', /[ \t]+/);
29604      $const_set($nesting[0], 'SkipRx', $hash2([","], {",": /[ \t]*(,|$)/}));
29605      
29606      $def(self, '$initialize', function $$initialize(source, block, delimiter) {
29607        var self = this;
29608
29609        
29610        if (block == null) block = nil;
29611        if (delimiter == null) delimiter = ",";
29612        self.scanner = $$$('StringScanner').$new(source);
29613        self.block = block;
29614        self.delimiter = delimiter;
29615        self.delimiter_skip_pattern = $$('SkipRx')['$[]'](delimiter);
29616        self.delimiter_boundary_pattern = $$('BoundaryRx')['$[]'](delimiter);
29617        return (self.attributes = nil);
29618      }, -2);
29619      
29620      $def(self, '$parse_into', function $$parse_into(attributes, positional_attrs) {
29621        var self = this;
29622
29623        
29624        if (positional_attrs == null) positional_attrs = [];
29625        return attributes.$update(self.$parse(positional_attrs));
29626      }, -2);
29627      
29628      $def(self, '$parse', function $$parse(positional_attrs) {
29629        var self = this, index = nil;
29630
29631        
29632        if (positional_attrs == null) positional_attrs = [];
29633        if ($truthy(self.attributes)) {
29634          return self.attributes
29635        };
29636        self.attributes = $hash2([], {});
29637        index = 0;
29638        while ($truthy(self.$parse_attribute(index, positional_attrs))) {
29639        
29640          if ($truthy(self.scanner['$eos?']())) {
29641            break
29642          };
29643          self.$skip_delimiter();
29644          index = $rb_plus(index, 1);
29645        };
29646        return self.attributes;
29647      }, -1);
29648      
29649      $def(self, '$rekey', function $$rekey(positional_attrs) {
29650        var self = this;
29651
29652        return $$('AttributeList').$rekey(self.attributes, positional_attrs)
29653      });
29654      $defs(self, '$rekey', function $$rekey(attributes, positional_attrs) {
29655        
29656        
29657        $send(positional_attrs, 'each_with_index', [], function $$1(key, index){var $a, val = nil;
29658
29659          
29660          if (key == null) key = nil;
29661          if (index == null) index = nil;
29662          if (($truthy(key) && ($truthy((val = attributes['$[]']($rb_plus(index, 1))))))) {
29663            return ($a = [key, val], $send(attributes, '[]=', $a), $a[$a.length - 1])
29664          } else {
29665            return nil
29666          };});
29667        return attributes;
29668      });
29669      self.$private();
29670      
29671      $def(self, '$parse_attribute', function $$parse_attribute(index, positional_attrs) {
29672        var self = this, continue$ = nil, $ret_or_1 = nil, name = nil, single_quoted = nil, skipped = nil, $ret_or_2 = nil, $ret_or_3 = nil, c = nil, value = nil, positional_attr_name = nil;
29673
29674        
29675        continue$ = true;
29676        self.$skip_blank();
29677        if ($eqeqeq($$('QUOT'), ($ret_or_1 = self.scanner.$peek(1)))) {
29678          name = self.$parse_attribute_value(self.scanner.$get_byte())
29679        } else if ($eqeqeq($$('APOS'), $ret_or_1)) {
29680          
29681          name = self.$parse_attribute_value(self.scanner.$get_byte());
29682          if (!$truthy(name['$start_with?']($$('APOS')))) {
29683            single_quoted = true
29684          };
29685        } else {
29686          
29687          skipped = ($truthy(($ret_or_2 = ($truthy(($ret_or_3 = (name = self.$scan_name()))) ? (self.$skip_blank()) : ($ret_or_3)))) ? ($ret_or_2) : (0));
29688          if ($truthy(self.scanner['$eos?']())) {
29689            
29690            if (!($truthy(name) || ($truthy(self.scanner.$string().$rstrip()['$end_with?'](self.delimiter))))) {
29691              return nil
29692            };
29693            continue$ = nil;
29694          } else if ($eqeq((c = self.scanner.$get_byte()), self.delimiter)) {
29695            self.scanner.$unscan()
29696          } else if ($truthy(name)) {
29697            if ($eqeq(c, "=")) {
29698              
29699              self.$skip_blank();
29700              if ($eqeqeq($$('QUOT'), ($ret_or_2 = (c = self.scanner.$get_byte())))) {
29701                value = self.$parse_attribute_value(c)
29702              } else if ($eqeqeq($$('APOS'), $ret_or_2)) {
29703                
29704                value = self.$parse_attribute_value(c);
29705                if (!$truthy(value['$start_with?']($$('APOS')))) {
29706                  single_quoted = true
29707                };
29708              } else if ($eqeqeq(self.delimiter, $ret_or_2)) {
29709                
29710                value = "";
29711                self.scanner.$unscan();
29712              } else if ($eqeqeq(nil, $ret_or_2)) {
29713                value = ""
29714              } else {
29715                
29716                value = "" + (c) + (self.$scan_to_delimiter());
29717                if ($eqeq(value, "None")) {
29718                  return true
29719                };
29720              };
29721            } else {
29722              name = "" + (name) + ($rb_times(" ", skipped)) + (c) + (self.$scan_to_delimiter())
29723            }
29724          } else {
29725            name = "" + (c) + (self.$scan_to_delimiter())
29726          };
29727        };
29728        if ($truthy(value)) {
29729          
29730          switch (name) {
29731            case "options":
29732            case "opts":
29733              if ($truthy(value['$include?'](","))) {
29734                
29735                if ($truthy(value['$include?'](" "))) {
29736                  value = value.$delete(" ")
29737                };
29738                $send(value.$split(","), 'each', [], function $$2(opt){var $a, self = $$2.$$s == null ? this : $$2.$$s;
29739                  if (self.attributes == null) self.attributes = nil;
29740
29741                  
29742                  if (opt == null) opt = nil;
29743                  if ($truthy(opt['$empty?']())) {
29744                    return nil
29745                  } else {
29746                    return ($a = ["" + (opt) + "-option", ""], $send(self.attributes, '[]=', $a), $a[$a.length - 1])
29747                  };}, {$$s: self});
29748              } else if (!$truthy(value['$empty?']())) {
29749                self.attributes['$[]=']("" + (value) + "-option", "")
29750              }
29751              break;
29752            default:
29753              if (($truthy(single_quoted) && ($truthy(self.block)))) {
29754                
29755                switch (name) {
29756                  case "title":
29757                  case "reftext":
29758                    self.attributes['$[]='](name, value)
29759                    break;
29760                  default:
29761                    self.attributes['$[]='](name, self.block.$apply_subs(value))
29762                }
29763              } else {
29764                self.attributes['$[]='](name, value)
29765              }
29766          }
29767        } else {
29768          
29769          if (($truthy(single_quoted) && ($truthy(self.block)))) {
29770            name = self.block.$apply_subs(name)
29771          };
29772          if (($truthy((positional_attr_name = positional_attrs['$[]'](index))) && ($truthy(name)))) {
29773            self.attributes['$[]='](positional_attr_name, name)
29774          };
29775          self.attributes['$[]=']($rb_plus(index, 1), name);
29776        };
29777        return continue$;
29778      });
29779      
29780      $def(self, '$parse_attribute_value', function $$parse_attribute_value(quote) {
29781        var self = this, value = nil;
29782
29783        if ($eqeq(self.scanner.$peek(1), quote)) {
29784          
29785          self.scanner.$get_byte();
29786          return "";
29787        } else if ($truthy((value = self.$scan_to_quote(quote)))) {
29788          
29789          self.scanner.$get_byte();
29790          if ($truthy(value['$include?']($$('BACKSLASH')))) {
29791            
29792            return value.$gsub($$('EscapedQuotes')['$[]'](quote), quote);
29793          } else {
29794            return value
29795          };
29796        } else {
29797          return "" + (quote) + (self.$scan_to_delimiter())
29798        }
29799      });
29800      
29801      $def(self, '$skip_blank', function $$skip_blank() {
29802        var self = this;
29803
29804        return self.scanner.$skip($$('BlankRx'))
29805      });
29806      
29807      $def(self, '$skip_delimiter', function $$skip_delimiter() {
29808        var self = this;
29809
29810        return self.scanner.$skip(self.delimiter_skip_pattern)
29811      });
29812      
29813      $def(self, '$scan_name', function $$scan_name() {
29814        var self = this;
29815
29816        return self.scanner.$scan($$('NameRx'))
29817      });
29818      
29819      $def(self, '$scan_to_delimiter', function $$scan_to_delimiter() {
29820        var self = this;
29821
29822        return self.scanner.$scan(self.delimiter_boundary_pattern)
29823      });
29824      return $def(self, '$scan_to_quote', function $$scan_to_quote(quote) {
29825        var self = this;
29826
29827        return self.scanner.$scan($$('BoundaryRx')['$[]'](quote))
29828      });
29829    })($nesting[0], null, $nesting)
29830  })($nesting[0], $nesting)
29831};
29832
29833Opal.modules["asciidoctor/block"] = function(Opal) {/* Generated by Opal 1.7.3 */
29834  "use strict";
29835  var $module = Opal.module, $klass = Opal.klass, $const_set = Opal.const_set, $hash2 = Opal.hash2, $alias = Opal.alias, $send2 = Opal.send2, $find_super = Opal.find_super, $truthy = Opal.truthy, $eqeqeq = Opal.eqeqeq, $def = Opal.def, $rb_lt = Opal.rb_lt, $eqeq = Opal.eqeq, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$;
29836
29837  Opal.add_stubs('default=,context,attr_accessor,[],key?,===,drop,delete,[]=,to_s,commit_subs,nil_or_empty?,prepare_source_string,apply_subs,join,<,size,empty?,rstrip,shift,pop,==,warn,logger,class,object_id,inspect');
29838  return (function($base, $parent_nesting) {
29839    var self = $module($base, 'Asciidoctor');
29840
29841    var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
29842
29843    return (function($base, $super, $parent_nesting) {
29844      var self = $klass($base, $super, 'Block');
29845
29846      var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype;
29847
29848      $proto.attributes = $proto.content_model = $proto.lines = $proto.subs = $proto.blocks = $proto.context = $proto.style = nil;
29849      
29850      $const_set($nesting[0], 'DEFAULT_CONTENT_MODEL', $hash2(["audio", "image", "listing", "literal", "stem", "open", "page_break", "pass", "thematic_break", "video"], {"audio": "empty", "image": "empty", "listing": "verbatim", "literal": "verbatim", "stem": "raw", "open": "compound", "page_break": "empty", "pass": "raw", "thematic_break": "empty", "video": "empty"}))['$default=']("simple");
29851      $alias(self, "blockname", "context");
29852      self.$attr_accessor("lines");
29853      
29854      $def(self, '$initialize', function $$initialize(parent, context, opts) {
29855        var $yield = $$initialize.$$p || nil, self = this, $ret_or_1 = nil, subs = nil, raw_source = nil;
29856
29857        $$initialize.$$p = null;
29858        
29859        if (opts == null) opts = $hash2([], {});
29860        $send2(self, $find_super(self, 'initialize', $$initialize, false, true), 'initialize', [parent, context, opts], $yield);
29861        self.content_model = ($truthy(($ret_or_1 = opts['$[]']("content_model"))) ? ($ret_or_1) : ($$('DEFAULT_CONTENT_MODEL')['$[]'](context)));
29862        if ($truthy(opts['$key?']("subs"))) {
29863          if ($truthy((subs = opts['$[]']("subs")))) {
29864            
29865            if ($eqeqeq("default", ($ret_or_1 = subs))) {
29866              self.default_subs = opts['$[]']("default_subs")
29867            } else if ($eqeqeq($$$('Array'), $ret_or_1)) {
29868              
29869              self.default_subs = subs.$drop(0);
29870              self.attributes.$delete("subs");
29871            } else {
29872              
29873              self.default_subs = nil;
29874              self.attributes['$[]=']("subs", subs.$to_s());
29875            };
29876            self.$commit_subs();
29877          } else {
29878            
29879            self.default_subs = [];
29880            self.attributes.$delete("subs");
29881          }
29882        } else {
29883          self.default_subs = nil
29884        };
29885        if ($truthy((raw_source = opts['$[]']("source"))['$nil_or_empty?']())) {
29886          return (self.lines = [])
29887        } else if ($eqeqeq($$$('String'), raw_source)) {
29888          return (self.lines = $$('Helpers').$prepare_source_string(raw_source))
29889        } else {
29890          return (self.lines = raw_source.$drop(0))
29891        };
29892      }, -3);
29893      
29894      $def(self, '$content', function $$content() {
29895        var $yield = $$content.$$p || nil, self = this, result = nil, $ret_or_2 = nil, first = nil, last = nil;
29896
29897        $$content.$$p = null;
29898        
29899        switch (self.content_model) {
29900          case "compound":
29901            return $send2(self, $find_super(self, 'content', $$content, false, true), 'content', [], $yield)
29902          case "simple":
29903            return self.$apply_subs(self.lines.$join($$('LF')), self.subs)
29904          case "verbatim":
29905          case "raw":
29906            
29907            result = self.$apply_subs(self.lines, self.subs);
29908            if ($truthy($rb_lt(result.$size(), 2))) {
29909              if ($truthy(($ret_or_2 = result['$[]'](0)))) {
29910                return $ret_or_2
29911              } else {
29912                return ""
29913              }
29914            } else {
29915              
29916              while ($truthy(($truthy(($ret_or_2 = (first = result['$[]'](0)))) ? (first.$rstrip()['$empty?']()) : ($ret_or_2)))) {
29917              result.$shift()
29918              };
29919              while ($truthy(($truthy(($ret_or_2 = (last = result['$[]'](-1)))) ? (last.$rstrip()['$empty?']()) : ($ret_or_2)))) {
29920              result.$pop()
29921              };
29922              return result.$join($$('LF'));
29923            };
29924            break;
29925          default:
29926            
29927            if (!$eqeq(self.content_model, "empty")) {
29928              self.$logger().$warn("unknown content model '" + (self.content_model) + "' for block: " + (self))
29929            };
29930            return nil;
29931        }
29932      });
29933      
29934      $def(self, '$source', function $$source() {
29935        var self = this;
29936
29937        return self.lines.$join($$('LF'))
29938      });
29939      return $def(self, '$to_s', function $$to_s() {
29940        var self = this, content_summary = nil;
29941
29942        
29943        content_summary = ($eqeq(self.content_model, "compound") ? ("blocks: " + (self.blocks.$size())) : ("lines: " + (self.lines.$size())));
29944        return "#<" + (self.$class()) + "@" + (self.$object_id()) + " {context: " + (self.context.$inspect()) + ", content_model: " + (self.content_model.$inspect()) + ", style: " + (self.style.$inspect()) + ", " + (content_summary) + "}>";
29945      });
29946    })($nesting[0], $$('AbstractBlock'), $nesting)
29947  })($nesting[0], $nesting)
29948};
29949
29950Opal.modules["asciidoctor/callouts"] = function(Opal) {/* Generated by Opal 1.7.3 */
29951  "use strict";
29952  var $module = Opal.module, $klass = Opal.klass, $def = Opal.def, $hash2 = Opal.hash2, $rb_plus = Opal.rb_plus, $truthy = Opal.truthy, $rb_le = Opal.rb_le, $rb_minus = Opal.rb_minus, $send = Opal.send, $eqeq = Opal.eqeq, $rb_lt = Opal.rb_lt, $nesting = [], nil = Opal.nil;
29953
29954  Opal.add_stubs('next_list,<<,current_list,to_i,generate_next_callout_id,+,<=,size,[],-,chop,join,map,==,<,private,generate_callout_id');
29955  return (function($base, $parent_nesting) {
29956    var self = $module($base, 'Asciidoctor');
29957
29958    var $nesting = [self].concat($parent_nesting);
29959
29960    return (function($base, $super) {
29961      var self = $klass($base, $super, 'Callouts');
29962
29963      var $proto = self.$$prototype;
29964
29965      $proto.co_index = $proto.lists = $proto.list_index = nil;
29966      
29967      
29968      $def(self, '$initialize', function $$initialize() {
29969        var self = this;
29970
29971        
29972        self.lists = [];
29973        self.list_index = 0;
29974        return self.$next_list();
29975      });
29976      
29977      $def(self, '$register', function $$register(li_ordinal) {
29978        var self = this, id = nil;
29979
29980        
29981        self.$current_list()['$<<']($hash2(["ordinal", "id"], {"ordinal": li_ordinal.$to_i(), "id": (id = self.$generate_next_callout_id())}));
29982        self.co_index = $rb_plus(self.co_index, 1);
29983        return id;
29984      });
29985      
29986      $def(self, '$read_next_id', function $$read_next_id() {
29987        var self = this, id = nil, list = nil;
29988
29989        
29990        id = nil;
29991        list = self.$current_list();
29992        if ($truthy($rb_le(self.co_index, list.$size()))) {
29993          id = list['$[]']($rb_minus(self.co_index, 1))['$[]']("id")
29994        };
29995        self.co_index = $rb_plus(self.co_index, 1);
29996        return id;
29997      });
29998      
29999      $def(self, '$callout_ids', function $$callout_ids(li_ordinal) {
30000        var self = this;
30001
30002        return $send(self.$current_list(), 'map', [], function $$1(it){
30003          
30004          if (it == null) it = nil;
30005          if ($eqeq(it['$[]']("ordinal"), li_ordinal)) {
30006            return "" + (it['$[]']("id")) + " "
30007          } else {
30008            return ""
30009          };}).$join().$chop()
30010      });
30011      
30012      $def(self, '$current_list', function $$current_list() {
30013        var self = this;
30014
30015        return self.lists['$[]']($rb_minus(self.list_index, 1))
30016      });
30017      
30018      $def(self, '$next_list', function $$next_list() {
30019        var self = this;
30020
30021        
30022        self.list_index = $rb_plus(self.list_index, 1);
30023        if ($truthy($rb_lt(self.lists.$size(), self.list_index))) {
30024          self.lists['$<<']([])
30025        };
30026        self.co_index = 1;
30027        return nil;
30028      });
30029      
30030      $def(self, '$rewind', function $$rewind() {
30031        var self = this;
30032
30033        
30034        self.list_index = 1;
30035        self.co_index = 1;
30036        return nil;
30037      });
30038      self.$private();
30039      
30040      $def(self, '$generate_next_callout_id', function $$generate_next_callout_id() {
30041        var self = this;
30042
30043        return self.$generate_callout_id(self.list_index, self.co_index)
30044      });
30045      return $def(self, '$generate_callout_id', function $$generate_callout_id(list_index, co_index) {
30046        
30047        return "CO" + (list_index) + "-" + (co_index)
30048      });
30049    })($nesting[0], null)
30050  })($nesting[0], $nesting)
30051};
30052
30053Opal.modules["asciidoctor/converter/composite"] = function(Opal) {/* Generated by Opal 1.7.3 */
30054  "use strict";
30055  var $module = Opal.module, $klass = Opal.klass, $slice = Opal.slice, $extract_kwargs = Opal.extract_kwargs, $ensure_kwargs = Opal.ensure_kwargs, $send = Opal.send, $truthy = Opal.truthy, $def = Opal.def, $thrower = Opal.thrower, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$;
30056
30057  Opal.add_stubs('attr_reader,each,respond_to?,composed,init_backend_traits,backend_traits,new,[]=,find_converter,convert,converter_for,node_name,[],handles?,raise');
30058  return (function($base, $parent_nesting) {
30059    var self = $module($base, 'Asciidoctor');
30060
30061    var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
30062
30063    return (function($base, $super) {
30064      var self = $klass($base, $super, 'CompositeConverter');
30065
30066      var $proto = self.$$prototype;
30067
30068      $proto.converter_cache = $proto.converters = nil;
30069      
30070      self.$attr_reader("converters");
30071      
30072      $def(self, '$initialize', function $$initialize(backend, $a, $b) {
30073        var $post_args, $kwargs, converters, backend_traits_source, self = this;
30074
30075        
30076        $post_args = $slice(arguments, 1);
30077        $kwargs = $extract_kwargs($post_args);
30078        $kwargs = $ensure_kwargs($kwargs);
30079        converters = $post_args;
30080        
30081        backend_traits_source = $kwargs.$$smap["backend_traits_source"];if (backend_traits_source == null) backend_traits_source = nil;
30082        self.backend = backend;
30083        $send((self.converters = converters), 'each', [], function $$1(converter){var self = $$1.$$s == null ? this : $$1.$$s;
30084
30085          
30086          if (converter == null) converter = nil;
30087          if ($truthy(converter['$respond_to?']("composed"))) {
30088            return converter.$composed(self)
30089          } else {
30090            return nil
30091          };}, {$$s: self});
30092        if ($truthy(backend_traits_source)) {
30093          self.$init_backend_traits(backend_traits_source.$backend_traits())
30094        };
30095        return (self.converter_cache = $send($$$('Hash'), 'new', [], function $$2(hash, key){var $c, self = $$2.$$s == null ? this : $$2.$$s;
30096
30097          
30098          if (hash == null) hash = nil;
30099          if (key == null) key = nil;
30100          return ($c = [key, self.$find_converter(key)], $send(hash, '[]=', $c), $c[$c.length - 1]);}, {$$s: self}));
30101      }, -2);
30102      
30103      $def(self, '$convert', function $$convert(node, transform, opts) {
30104        var self = this, $ret_or_1 = nil;
30105
30106        
30107        if (transform == null) transform = nil;
30108        if (opts == null) opts = nil;
30109        return self.$converter_for((transform = ($truthy(($ret_or_1 = transform)) ? ($ret_or_1) : (node.$node_name())))).$convert(node, transform, opts);
30110      }, -2);
30111      
30112      $def(self, '$converter_for', function $$converter_for(transform) {
30113        var self = this;
30114
30115        return self.converter_cache['$[]'](transform)
30116      });
30117      return $def(self, '$find_converter', function $$find_converter(transform) {try { var $t_return = $thrower('return'); 
30118        var self = this;
30119
30120        
30121        $send(self.converters, 'each', [], function $$3(candidate){
30122          
30123          if (candidate == null) candidate = nil;
30124          if ($truthy(candidate['$handles?'](transform))) {
30125            $t_return.$throw(candidate)
30126          } else {
30127            return nil
30128          };}, {$$ret: $t_return});
30129        return self.$raise("Could not find a converter to handle transform: " + (transform));} catch($e) {
30130          if ($e === $t_return) return $e.$v;
30131          throw $e;
30132        }
30133      });
30134    })($$('Converter'), $$$($$('Converter'), 'Base'))
30135  })($nesting[0], $nesting)
30136};
30137
30138Opal.modules["asciidoctor/converter"] = function(Opal) {/* Generated by Opal 1.7.3 */
30139  "use strict";
30140  var $module = Opal.module, $hash2 = Opal.hash2, $def = Opal.def, $return_val = Opal.return_val, $truthy = Opal.truthy, $eqeq = Opal.eqeq, $defs = Opal.defs, $send = Opal.send, $alias = Opal.alias, $slice = Opal.slice, $to_a = Opal.to_a, $extract_kwargs = Opal.extract_kwargs, $ensure_kwargs = Opal.ensure_kwargs, $eqeqeq = Opal.eqeqeq, $Class = Opal.Class, $klass = Opal.klass, $class_variable_set = Opal.class_variable_set, $class_variable_get = Opal.class_variable_get, $rb_plus = Opal.rb_plus, $gvars = Opal.gvars, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$;
30141
30142  Opal.add_stubs('autoload,attr_reader,raise,class,[],sub,slice,length,==,[]=,backend_traits,derive_backend_traits,register,map,to_s,new,create,default,each,default=,registry,for,===,supports_templates?,merge,private,include,delete,clear,send,extend,private_class_method,node_name,+,name,receiver,warn,logger,respond_to?,content');
30143  return (function($base, $parent_nesting) {
30144    var self = $module($base, 'Asciidoctor');
30145
30146    var $nesting = [self].concat($parent_nesting);
30147
30148    return (function($base, $parent_nesting) {
30149      var self = $module($base, 'Converter');
30150
30151      var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
30152
30153      
30154      self.$autoload("CompositeConverter", "" + ("asciidoctor") + "/converter/composite");
30155      nil;
30156      self.$attr_reader("backend");
30157      
30158      $def(self, '$initialize', function $$initialize(backend, opts) {
30159        var self = this;
30160
30161        
30162        if (opts == null) opts = $hash2([], {});
30163        return (self.backend = backend);
30164      }, -2);
30165      
30166      $def(self, '$convert', function $$convert(node, transform, opts) {
30167        var self = this;
30168        if (self.backend == null) self.backend = nil;
30169
30170        
30171        if (transform == null) transform = nil;
30172        if (opts == null) opts = nil;
30173        return self.$raise($$$('NotImplementedError'), "" + (self.$class()) + " (backend: " + (self.backend) + ") must implement the #" + ("convert") + " method");
30174      }, -2);
30175      
30176      $def(self, '$handles?', $return_val(true));
30177      $defs(self, '$derive_backend_traits', function $$derive_backend_traits(backend, basebackend) {
30178        var outfilesuffix = nil, $ret_or_1 = nil, filetype = nil;
30179
30180        
30181        if (basebackend == null) basebackend = nil;
30182        if (!$truthy(backend)) {
30183          return $hash2([], {})
30184        };
30185        if ($truthy((outfilesuffix = $$('DEFAULT_EXTENSIONS')['$[]']((basebackend = ($truthy(($ret_or_1 = basebackend)) ? ($ret_or_1) : (backend.$sub($$('TrailingDigitsRx'), "")))))))) {
30186          filetype = outfilesuffix.$slice(1, outfilesuffix.$length())
30187        } else {
30188          outfilesuffix = "." + ((filetype = basebackend))
30189        };
30190        if ($eqeq(filetype, "html")) {
30191          return $hash2(["basebackend", "filetype", "htmlsyntax", "outfilesuffix"], {"basebackend": basebackend, "filetype": filetype, "htmlsyntax": "html", "outfilesuffix": outfilesuffix})
30192        } else {
30193          return $hash2(["basebackend", "filetype", "outfilesuffix"], {"basebackend": basebackend, "filetype": filetype, "outfilesuffix": outfilesuffix})
30194        };
30195      }, -2);
30196      (function($base, $parent_nesting) {
30197        var self = $module($base, 'BackendTraits');
30198
30199        var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
30200
30201        
30202        
30203        $def(self, '$basebackend', function $$basebackend(value) {
30204          var $a, self = this;
30205
30206          
30207          if (value == null) value = nil;
30208          if ($truthy(value)) {
30209            
30210            return ($a = ["basebackend", value], $send(self.$backend_traits(value), '[]=', $a), $a[$a.length - 1]);
30211          } else {
30212            return self.$backend_traits()['$[]']("basebackend")
30213          };
30214        }, -1);
30215        
30216        $def(self, '$filetype', function $$filetype(value) {
30217          var $a, self = this;
30218
30219          
30220          if (value == null) value = nil;
30221          if ($truthy(value)) {
30222            
30223            return ($a = ["filetype", value], $send(self.$backend_traits(), '[]=', $a), $a[$a.length - 1]);
30224          } else {
30225            return self.$backend_traits()['$[]']("filetype")
30226          };
30227        }, -1);
30228        
30229        $def(self, '$htmlsyntax', function $$htmlsyntax(value) {
30230          var $a, self = this;
30231
30232          
30233          if (value == null) value = nil;
30234          if ($truthy(value)) {
30235            
30236            return ($a = ["htmlsyntax", value], $send(self.$backend_traits(), '[]=', $a), $a[$a.length - 1]);
30237          } else {
30238            return self.$backend_traits()['$[]']("htmlsyntax")
30239          };
30240        }, -1);
30241        
30242        $def(self, '$outfilesuffix', function $$outfilesuffix(value) {
30243          var $a, self = this;
30244
30245          
30246          if (value == null) value = nil;
30247          if ($truthy(value)) {
30248            
30249            return ($a = ["outfilesuffix", value], $send(self.$backend_traits(), '[]=', $a), $a[$a.length - 1]);
30250          } else {
30251            return self.$backend_traits()['$[]']("outfilesuffix")
30252          };
30253        }, -1);
30254        
30255        $def(self, '$supports_templates', function $$supports_templates(value) {
30256          var $a, self = this;
30257
30258          
30259          if (value == null) value = true;
30260          return ($a = ["supports_templates", value], $send(self.$backend_traits(), '[]=', $a), $a[$a.length - 1]);
30261        }, -1);
30262        
30263        $def(self, '$supports_templates?', function $BackendTraits_supports_templates$ques$1() {
30264          var self = this;
30265
30266          return self.$backend_traits()['$[]']("supports_templates")
30267        });
30268        
30269        $def(self, '$init_backend_traits', function $$init_backend_traits(value) {
30270          var self = this, $ret_or_1 = nil;
30271
30272          
30273          if (value == null) value = nil;
30274          return (self.backend_traits = ($truthy(($ret_or_1 = value)) ? ($ret_or_1) : ($hash2([], {}))));
30275        }, -1);
30276        
30277        $def(self, '$backend_traits', function $$backend_traits(basebackend) {
30278          var self = this, $ret_or_1 = nil;
30279          if (self.backend_traits == null) self.backend_traits = nil;
30280          if (self.backend == null) self.backend = nil;
30281
30282          
30283          if (basebackend == null) basebackend = nil;
30284          return (self.backend_traits = ($truthy(($ret_or_1 = self.backend_traits)) ? ($ret_or_1) : ($$('Converter').$derive_backend_traits(self.backend, basebackend))));
30285        }, -1);
30286        $alias(self, "backend_info", "backend_traits");
30287        return $defs(self, '$derive_backend_traits', function $$derive_backend_traits(backend, basebackend) {
30288          
30289          
30290          if (basebackend == null) basebackend = nil;
30291          return $$('Converter').$derive_backend_traits(backend, basebackend);
30292        }, -2);
30293      })($nesting[0], $nesting);
30294      (function($base, $parent_nesting) {
30295        var self = $module($base, 'Config');
30296
30297        var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
30298
30299        return $def(self, '$register_for', function $$register_for($a) {
30300          var $post_args, backends, self = this;
30301
30302          
30303          $post_args = $slice(arguments);
30304          backends = $post_args;
30305          return $send($$('Converter'), 'register', [self].concat($to_a($send(backends, 'map', [], function $$2(backend){
30306            
30307            if (backend == null) backend = nil;
30308            return backend.$to_s();}))));
30309        }, -1)
30310      })($nesting[0], $nesting);
30311      (function($base, $parent_nesting) {
30312        var self = $module($base, 'Factory');
30313
30314        var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
30315
30316        
30317        $defs(self, '$new', function $Factory_new$3($a, $b) {
30318          var $post_args, $kwargs, converters, proxy_default;
30319
30320          
30321          $post_args = $slice(arguments);
30322          $kwargs = $extract_kwargs($post_args);
30323          $kwargs = $ensure_kwargs($kwargs);
30324          
30325          if ($post_args.length > 0) converters = $post_args.shift();if (converters == null) converters = nil;
30326          
30327          proxy_default = $kwargs.$$smap["proxy_default"];if (proxy_default == null) proxy_default = true;
30328          if ($truthy(proxy_default)) {
30329            
30330            return $$('DefaultFactoryProxy').$new(converters);
30331          } else {
30332            
30333            return $$('CustomFactory').$new(converters);
30334          };
30335        }, -1);
30336        $defs(self, '$default', function $Factory_default$4($a) {
30337          var $post_args, args;
30338
30339          
30340          $post_args = $slice(arguments);
30341          args = $post_args;
30342          return $$('Converter');
30343        }, -1);
30344        $defs(self, '$create', function $$create(backend, opts) {
30345          var self = this;
30346
30347          
30348          if (opts == null) opts = $hash2([], {});
30349          return self.$default().$create(backend, opts);
30350        }, -2);
30351        
30352        $def(self, '$register', function $$register(converter, $a) {
30353          var $post_args, backends, self = this;
30354
30355          
30356          $post_args = $slice(arguments, 1);
30357          backends = $post_args;
30358          return $send(backends, 'each', [], function $$5(backend){var $b, self = $$5.$$s == null ? this : $$5.$$s;
30359
30360            
30361            if (backend == null) backend = nil;
30362            if ($eqeq(backend, "*")) {
30363              
30364              return ($b = [converter], $send(self.$registry(), 'default=', $b), $b[$b.length - 1]);
30365            } else {
30366              
30367              return ($b = [backend, converter], $send(self.$registry(), '[]=', $b), $b[$b.length - 1]);
30368            };}, {$$s: self});
30369        }, -2);
30370        
30371        $def(self, '$for', function $Factory_for$6(backend) {
30372          var self = this;
30373
30374          return self.$registry()['$[]'](backend)
30375        });
30376        
30377        $def(self, '$create', function $$create(backend, opts) {
30378          var self = this, converter = nil, template_dirs = nil, delegate_backend = nil;
30379
30380          
30381          if (opts == null) opts = $hash2([], {});
30382          if ($truthy((converter = self.$for(backend)))) {
30383            
30384            if ($eqeqeq($Class, converter)) {
30385              converter = converter.$new(backend, opts)
30386            };
30387            if ((($truthy((template_dirs = opts['$[]']("template_dirs"))) && ($eqeqeq($$('BackendTraits'), converter))) && ($truthy(converter['$supports_templates?']())))) {
30388              return $$('CompositeConverter').$new(backend, $$('TemplateConverter').$new(backend, template_dirs, opts), converter, $hash2(["backend_traits_source"], {"backend_traits_source": converter}))
30389            } else {
30390              return converter
30391            };
30392          } else if ($truthy((template_dirs = opts['$[]']("template_dirs")))) {
30393            if (($truthy((delegate_backend = opts['$[]']("delegate_backend"))) && ($truthy((converter = self.$for(delegate_backend)))))) {
30394              
30395              if ($eqeqeq($Class, converter)) {
30396                converter = converter.$new(delegate_backend, opts)
30397              };
30398              return $$('CompositeConverter').$new(backend, $$('TemplateConverter').$new(backend, template_dirs, opts), converter, $hash2(["backend_traits_source"], {"backend_traits_source": converter}));
30399            } else {
30400              return $$('TemplateConverter').$new(backend, template_dirs, opts)
30401            }
30402          } else {
30403            return nil
30404          };
30405        }, -2);
30406        
30407        $def(self, '$converters', function $$converters() {
30408          var self = this;
30409
30410          return self.$registry().$merge()
30411        });
30412        self.$private();
30413        return $def(self, '$registry', function $$registry() {
30414          var self = this;
30415
30416          return self.$raise($$$('NotImplementedError'), "" + ($$('Factory')) + " subclass " + (self.$class()) + " must implement the #" + ("registry") + " method")
30417        });
30418      })($nesting[0], $nesting);
30419      (function($base, $super, $parent_nesting) {
30420        var self = $klass($base, $super, 'CustomFactory');
30421
30422        var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
30423
30424        
30425        self.$include($$('Factory'));
30426        
30427        $def(self, '$initialize', function $$initialize(seed_registry) {
30428          var self = this;
30429
30430          
30431          if (seed_registry == null) seed_registry = nil;
30432          if ($truthy(seed_registry)) {
30433            
30434            seed_registry['$default='](seed_registry.$delete("*"));
30435            return (self.registry = seed_registry);
30436          } else {
30437            return (self.registry = $hash2([], {}))
30438          };
30439        }, -1);
30440        
30441        $def(self, '$unregister_all', function $$unregister_all() {
30442          var $a, self = this;
30443
30444          return ($a = [nil], $send(self.$registry().$clear(), 'default=', $a), $a[$a.length - 1])
30445        });
30446        self.$private();
30447        return self.$attr_reader("registry");
30448      })($nesting[0], null, $nesting);
30449      (function($base, $parent_nesting) {
30450        var self = $module($base, 'DefaultFactory');
30451
30452        var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
30453
30454        
30455        self.$include($$('Factory'));
30456        self.$private();
30457        $class_variable_set($nesting[0], '@@registry', $hash2([], {}));
30458        
30459        $def(self, '$registry', function $$registry() {
30460          
30461          return $class_variable_get($nesting[0], '@@registry', false)
30462        });
30463        return nil;
30464      })($nesting[0], $nesting);
30465      (function($base, $super, $parent_nesting) {
30466        var self = $klass($base, $super, 'DefaultFactoryProxy');
30467
30468        var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
30469
30470        
30471        self.$include($$('DefaultFactory'));
30472        return nil;
30473      })($nesting[0], $$('CustomFactory'), $nesting);
30474      $defs(self, '$included', function $$included(into) {
30475        
30476        
30477        into.$send("include", $$('BackendTraits'));
30478        return into.$extend($$('Config'));
30479      });
30480      self.$private_class_method("included");
30481      (function($base, $super, $parent_nesting) {
30482        var self = $klass($base, $super, 'Base');
30483
30484        var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype;
30485
30486        $proto.backend = nil;
30487        
30488        self.$include($$('Logging'));
30489        self.$include($$('Converter'));
30490        
30491        $def(self, '$convert', function $$convert(node, transform, opts) {
30492          var self = this, ex = nil;
30493          if ($gvars["!"] == null) $gvars["!"] = nil;
30494
30495          
30496          if (transform == null) transform = node.$node_name();
30497          if (opts == null) opts = nil;
30498          try {
30499            if ($truthy(opts)) {
30500              
30501              return self.$send($rb_plus("convert_", transform), node, opts);
30502            } else {
30503              
30504              return self.$send($rb_plus("convert_", transform), node);
30505            }
30506          } catch ($err) {
30507            if (Opal.rescue($err, [$$('StandardError')])) {
30508              try {
30509                
30510                if (!(($eqeqeq($$$('NoMethodError'), (ex = $gvars["!"])) && ($eqeq(ex.$receiver(), self))) && ($eqeq(ex.$name().$to_s(), transform)))) {
30511                  self.$raise()
30512                };
30513                self.$logger().$warn("missing convert handler for " + (ex.$name()) + " node in " + (self.backend) + " backend (" + (self.$class()) + ")");
30514                return nil;
30515              } finally { Opal.pop_exception(); }
30516            } else { throw $err; }
30517          };
30518        }, -2);
30519        
30520        $def(self, '$handles?', function $Base_handles$ques$7(transform) {
30521          var self = this;
30522
30523          return self['$respond_to?']("convert_" + (transform))
30524        });
30525        
30526        $def(self, '$content_only', function $$content_only(node) {
30527          
30528          return node.$content()
30529        });
30530        return $def(self, '$skip', $return_val(nil));
30531      })($nesting[0], null, $nesting);
30532      return self.$extend($$('DefaultFactory'));
30533    })($nesting[0], $nesting)
30534  })($nesting[0], $nesting)
30535};
30536
30537Opal.modules["asciidoctor/document"] = function(Opal) {/* Generated by Opal 1.7.3 */
30538  "use strict";
30539  var $module = Opal.module, $klass = Opal.klass, $const_set = Opal.const_set, $send = Opal.send, $alias = Opal.alias, $truthy = Opal.truthy, $def = Opal.def, $hash2 = Opal.hash2, $not = Opal.not, $to_ary = Opal.to_ary, $return_ivar = Opal.return_ivar, $send2 = Opal.send2, $find_super = Opal.find_super, $rb_minus = Opal.rb_minus, $eqeq = Opal.eqeq, $eqeqeq = Opal.eqeqeq, $hash = Opal.hash, $rb_ge = Opal.rb_ge, $rb_plus = Opal.rb_plus, $neqeq = Opal.neqeq, $thrower = Opal.thrower, $rb_gt = Opal.rb_gt, $rb_lt = Opal.rb_lt, $gvars = Opal.gvars, $to_a = Opal.to_a, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$;
30540
30541  Opal.add_stubs('new,target,attr_reader,nil?,<<,[],[]=,main,include?,strip,squeeze,gsub,!,empty?,rpartition,attr_accessor,catalog,delete,base_dir,options,merge,instance_variable_get,attributes,safe,compat_mode,outfilesuffix,sourcemap,path_resolver,converter,extensions,syntax_highlighter,each,end_with?,start_with?,slice,-,length,chop,==,downcase,===,extname,value_for_name,key?,freeze,attribute_undefined,attribute_missing,update,&,keys,name_for_value,expand_path,pwd,to_s,>=,+,abs,to_i,delete_if,update_doctype_attributes,cursor,parse,restore_attributes,update_backend_attributes,fetch,fill_datetime_attributes,activate,groups,create,to_proc,preprocessors?,preprocessors,process_method,tree_processors?,tree_processors,!=,counter,nil_or_empty?,attribute_locked?,nextval,value,save_to,increment_and_store_counter,register,tap,xreftext,>,source,source_lines,doctitle,sectname=,title=,first_section,title,reftext,<,find,context,header?,assign_numeral,clear_playback_attributes,save_attributes,name,negate,rewind,replace,apply_attribute_value_subs,delete?,start,doctype,content_model,warn,logger,content,convert,postprocessors?,postprocessors,record,write,respond_to?,chomp,class,write_alternate_pages,map,split,resolve_docinfo_subs,normalize_system_path,read_asset,apply_subs,docinfo_processors?,join,concat,compact,docinfo_processors,object_id,inspect,size,private,=~,resolve_pass_subs,apply_header_subs,limit_bytesize,bytesize,valid_encoding?,byteslice,resolve_subs,utc,at,Integer,now,index,strftime,year,utc_offset,partition,create_converter,basebackend,filetype,htmlsyntax,derive_backend_traits,raise');
30542  return (function($base, $parent_nesting) {
30543    var self = $module($base, 'Asciidoctor');
30544
30545    var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
30546
30547    return (function($base, $super, $parent_nesting) {
30548      var self = $klass($base, $super, 'Document');
30549
30550      var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype;
30551
30552      $proto.attributes = $proto.safe = $proto.sourcemap = $proto.reader = $proto.base_dir = $proto.parsed = $proto.parent_document = $proto.extensions = $proto.options = $proto.counters = $proto.catalog = $proto.reftexts = $proto.next_section_index = $proto.header = $proto.blocks = $proto.header_attributes = $proto.attributes_modified = $proto.backend = $proto.attribute_overrides = $proto.timings = $proto.converter = $proto.outfilesuffix = $proto.docinfo_processor_extensions = $proto.document = $proto.max_attribute_value_size = $proto.id = $proto.doctype = nil;
30553      
30554      $const_set($nesting[0], 'ImageReference', $send($$$('Struct'), 'new', ["target", "imagesdir"], function $Document$1(){var self = $Document$1.$$s == null ? this : $Document$1.$$s;
30555
30556        return $alias(self, "to_s", "target")}, {$$s: self}));
30557      $const_set($nesting[0], 'Footnote', $$$('Struct').$new("index", "id", "text"));
30558      (function($base, $super) {
30559        var self = $klass($base, $super, 'AttributeEntry');
30560
30561        
30562        
30563        self.$attr_reader("name", "value", "negate");
30564        
30565        $def(self, '$initialize', function $$initialize(name, value, negate) {
30566          var self = this;
30567
30568          
30569          if (negate == null) negate = nil;
30570          self.name = name;
30571          self.value = value;
30572          return (self.negate = ($truthy(negate['$nil?']()) ? (value['$nil?']()) : (negate)));
30573        }, -3);
30574        return $def(self, '$save_to', function $$save_to(block_attributes) {
30575          var $a, self = this, $ret_or_1 = nil;
30576
30577          
30578          ($truthy(($ret_or_1 = block_attributes['$[]']("attribute_entries"))) ? ($ret_or_1) : (($a = ["attribute_entries", []], $send(block_attributes, '[]=', $a), $a[$a.length - 1])))['$<<'](self);
30579          return self;
30580        });
30581      })($nesting[0], null);
30582      (function($base, $super, $parent_nesting) {
30583        var self = $klass($base, $super, 'Title');
30584
30585        var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype;
30586
30587        $proto.subtitle = nil;
30588        
30589        self.$attr_reader("main");
30590        $alias(self, "title", "main");
30591        self.$attr_reader("subtitle");
30592        self.$attr_reader("combined");
30593        
30594        $def(self, '$initialize', function $$initialize(val, opts) {
30595          var $a, $b, self = this, sep = nil, $ret_or_1 = nil, _ = nil;
30596
30597          
30598          if (opts == null) opts = $hash2([], {});
30599          if (($truthy((self.sanitized = opts['$[]']("sanitize"))) && ($truthy(val['$include?']("<"))))) {
30600            val = val.$gsub($$('XmlSanitizeRx'), "").$squeeze(" ").$strip()
30601          };
30602          if (($truthy((sep = ($truthy(($ret_or_1 = opts['$[]']("separator"))) ? ($ret_or_1) : (":")))['$empty?']()) || ($not(val['$include?']((sep = "" + (sep) + " ")))))) {
30603            
30604            self.main = val;
30605            self.subtitle = nil;
30606          } else {
30607            $b = val.$rpartition(sep), $a = $to_ary($b), (self.main = ($a[0] == null ? nil : $a[0])), (_ = ($a[1] == null ? nil : $a[1])), (self.subtitle = ($a[2] == null ? nil : $a[2])), $b
30608          };
30609          return (self.combined = val);
30610        }, -2);
30611        
30612        $def(self, '$sanitized?', $return_ivar("sanitized"));
30613        
30614        $def(self, '$subtitle?', function $Title_subtitle$ques$2() {
30615          var self = this;
30616
30617          if ($truthy(self.subtitle)) {
30618            return true
30619          } else {
30620            return false
30621          }
30622        });
30623        return $def(self, '$to_s', $return_ivar("combined"));
30624      })($nesting[0], null, $nesting);
30625      $const_set($nesting[0], 'Author', $$$('Struct').$new("name", "firstname", "middlename", "lastname", "initials", "email"));
30626      self.$attr_reader("safe");
30627      self.$attr_reader("compat_mode");
30628      self.$attr_reader("backend");
30629      self.$attr_reader("doctype");
30630      self.$attr_accessor("sourcemap");
30631      self.$attr_reader("catalog");
30632      $alias(self, "references", "catalog");
30633      self.$attr_reader("counters");
30634      self.$attr_reader("header");
30635      self.$attr_reader("base_dir");
30636      self.$attr_reader("options");
30637      self.$attr_reader("outfilesuffix");
30638      self.$attr_reader("parent_document");
30639      self.$attr_reader("reader");
30640      self.$attr_reader("path_resolver");
30641      self.$attr_reader("converter");
30642      self.$attr_reader("syntax_highlighter");
30643      self.$attr_reader("extensions");
30644      
30645      $def(self, '$initialize', function $$initialize(data, options) {
30646        var $a, $b, $c, $d, $e, $yield = $$initialize.$$p || nil, self = this, parent_doc = nil, $ret_or_1 = nil, attr_overrides = nil, parent_doctype = nil, initialize_extensions = nil, to_file = nil, safe_mode = nil, input_mtime = nil, standalone = nil, attrs = nil, safe_mode_name = nil, base_dir_val = nil, backend_val = nil, doctype_val = nil, size = nil, initial_backend = nil, ext_registry = nil, ext_block = nil;
30647
30648        $$initialize.$$p = null;
30649        
30650        if (data == null) data = nil;
30651        if (options == null) options = $hash2([], {});
30652        $send2(self, $find_super(self, 'initialize', $$initialize, false, true), 'initialize', [self, "document"], null);
30653        if ($truthy((parent_doc = options.$delete("parent")))) {
30654          
30655          self.parent_document = parent_doc;
30656          if ($truthy(($ret_or_1 = options['$[]']("base_dir")))) {
30657            $ret_or_1
30658          } else {
30659            options['$[]=']("base_dir", parent_doc.$base_dir())
30660          };
30661          if ($truthy(parent_doc.$options()['$[]']("catalog_assets"))) {
30662            options['$[]=']("catalog_assets", true)
30663          };
30664          if ($truthy(parent_doc.$options()['$[]']("to_dir"))) {
30665            options['$[]=']("to_dir", parent_doc.$options()['$[]']("to_dir"))
30666          };
30667          self.catalog = parent_doc.$catalog().$merge($hash2(["footnotes"], {"footnotes": []}));
30668          self.attribute_overrides = (attr_overrides = parent_doc.$instance_variable_get("@attribute_overrides").$merge(parent_doc.$attributes()));
30669          attr_overrides.$delete("compat-mode");
30670          parent_doctype = attr_overrides.$delete("doctype");
30671          attr_overrides.$delete("notitle");
30672          attr_overrides.$delete("showtitle");
30673          attr_overrides.$delete("toc");
30674          self.attributes['$[]=']("toc-placement", ($truthy(($ret_or_1 = attr_overrides.$delete("toc-placement"))) ? ($ret_or_1) : ("auto")));
30675          attr_overrides.$delete("toc-position");
30676          self.safe = parent_doc.$safe();
30677          if ($truthy((self.compat_mode = parent_doc.$compat_mode()))) {
30678            self.attributes['$[]=']("compat-mode", "")
30679          };
30680          self.outfilesuffix = parent_doc.$outfilesuffix();
30681          self.sourcemap = parent_doc.$sourcemap();
30682          self.timings = nil;
30683          self.path_resolver = parent_doc.$path_resolver();
30684          self.converter = parent_doc.$converter();
30685          initialize_extensions = nil;
30686          self.extensions = parent_doc.$extensions();
30687          self.syntax_highlighter = parent_doc.$syntax_highlighter();
30688        } else {
30689          
30690          self.parent_document = nil;
30691          self.catalog = $hash2(["ids", "refs", "footnotes", "links", "images", "callouts", "includes"], {"ids": $hash2([], {}), "refs": $hash2([], {}), "footnotes": [], "links": [], "images": [], "callouts": $$('Callouts').$new(), "includes": $hash2([], {})});
30692          self.attribute_overrides = (attr_overrides = $hash2([], {}));
30693          $send(($truthy(($ret_or_1 = options['$[]']("attributes"))) ? ($ret_or_1) : ($hash2([], {}))), 'each', [], function $$3(key, val){var $a;
30694
30695            
30696            if (key == null) key = nil;
30697            if (val == null) val = nil;
30698            if ($truthy(key['$end_with?']("@"))) {
30699              if ($truthy(key['$start_with?']("!"))) {
30700                $a = [key.$slice(1, $rb_minus(key.$length(), 2)), false], (key = $a[0]), (val = $a[1]), $a
30701              } else if ($truthy(key['$end_with?']("!@"))) {
30702                $a = [key.$slice(0, $rb_minus(key.$length(), 2)), false], (key = $a[0]), (val = $a[1]), $a
30703              } else {
30704                $a = [key.$chop(), "" + (val) + "@"], (key = $a[0]), (val = $a[1]), $a
30705              }
30706            } else if ($truthy(key['$start_with?']("!"))) {
30707              $a = [key.$slice(1, key.$length()), ($eqeq(val, "@") ? (false) : (nil))], (key = $a[0]), (val = $a[1]), $a
30708            } else if ($truthy(key['$end_with?']("!"))) {
30709              $a = [key.$chop(), ($eqeq(val, "@") ? (false) : (nil))], (key = $a[0]), (val = $a[1]), $a
30710            };
30711            return ($a = [key.$downcase(), val], $send(attr_overrides, '[]=', $a), $a[$a.length - 1]);});
30712          if ($eqeqeq($$$('String'), (to_file = options['$[]']("to_file")))
30712) {
30713            attr_overrides['$[]=']("outfilesuffix", $$('Helpers').$extname(to_file))
30714          };
30715          if ($not((safe_mode = options['$[]']("safe")))) {
30716            self.safe = $$$($$('SafeMode'), 'SECURE')
30717          } else if ($eqeqeq($$$('Integer'), safe_mode)) {
30718            self.safe = safe_mode
30719          } else {
30720            self.safe = (function() { try {
30721              
30722              return $$('SafeMode').$value_for_name(safe_mode);
30723            } catch ($err) {
30724              if (Opal.rescue($err, [$$('StandardError')])) {
30725                try {
30726                  return $$$($$('SafeMode'), 'SECURE')
30727                } finally { Opal.pop_exception(); }
30728              } else { throw $err; }
30729            }})()
30730          };
30731          input_mtime = options.$delete("input_mtime");
30732          self.compat_mode = attr_overrides['$key?']("compat-mode");
30733          self.sourcemap = options['$[]']("sourcemap");
30734          self.timings = options.$delete("timings");
30735          self.path_resolver = $$('PathResolver').$new();
30736          initialize_extensions = (($truthy((($b = $$$('::', 'Asciidoctor', 'skip_raise')) && ($a = $$$($b, 'Extensions', 'skip_raise')) ? 'constant' : nil)) || ($truthy(options['$key?']("extensions")))) ? ($$$($$$('Asciidoctor'), 'Extensions')) : (nil));
30737          self.extensions = nil;
30738          if (($truthy(options['$key?']("header_footer")) && ($not(options['$key?']("standalone"))))) {
30739            options['$[]=']("standalone", options['$[]']("header_footer"))
30740          };
30741        };
30742        self.parsed = (self.reftexts = (self.header = (self.header_attributes = nil)));
30743        self.counters = $hash2([], {});
30744        self.attributes_modified = $$$('Set').$new();
30745        self.docinfo_processor_extensions = $hash2([], {});
30746        standalone = options['$[]']("standalone");
30747        (self.options = options).$freeze();
30748        attrs = self.attributes;
30749        if (!$truthy(parent_doc)) {
30750          
30751          attrs['$[]=']("attribute-undefined", $$('Compliance').$attribute_undefined());
30752          attrs['$[]=']("attribute-missing", $$('Compliance').$attribute_missing());
30753          attrs.$update($$('DEFAULT_ATTRIBUTES'));
30754        };
30755        if ($truthy(standalone)) {
30756          
30757          attr_overrides['$[]=']("embedded", nil);
30758          attrs['$[]=']("copycss", "");
30759          attrs['$[]=']("iconfont-remote", "");
30760          attrs['$[]=']("stylesheet", "");
30761          attrs['$[]=']("webfonts", "");
30762        } else {
30763          
30764          attr_overrides['$[]=']("embedded", "");
30765          if (($truthy(attr_overrides['$key?']("showtitle")) && ($eqeq(attr_overrides.$keys()['$&'](["notitle", "showtitle"])['$[]'](-1), "showtitle")))) {
30766            attr_overrides['$[]=']("notitle", $hash(nil, "", false, "@", "@", false)['$[]'](attr_overrides['$[]']("showtitle")))
30767          } else if ($truthy(attr_overrides['$key?']("notitle"))) {
30768            attr_overrides['$[]=']("showtitle", $hash(nil, "", false, "@", "@", false)['$[]'](attr_overrides['$[]']("notitle")))
30769          } else {
30770            attrs['$[]=']("notitle", "")
30771          };
30772        };
30773        attr_overrides['$[]=']("asciidoctor", "");
30774        attr_overrides['$[]=']("asciidoctor-version", $$$($$$('Asciidoctor'), 'VERSION'));
30775        attr_overrides['$[]=']("safe-mode-name", (safe_mode_name = $$('SafeMode').$name_for_value(self.safe)));
30776        attr_overrides['$[]=']("safe-mode-" + (safe_mode_name), "");
30777        attr_overrides['$[]=']("safe-mode-level", self.safe);
30778        if ($truthy(($ret_or_1 = attr_overrides['$[]']("max-include-depth")))) {
30779          $ret_or_1
30780        } else {
30781          attr_overrides['$[]=']("max-include-depth", 64)
30782        };
30783        if ($truthy(($ret_or_1 = attr_overrides['$[]']("allow-uri-read")))) {
30784          $ret_or_1
30785        } else {
30786          attr_overrides['$[]=']("allow-uri-read", nil)
30787        };
30788        if ($truthy(attr_overrides['$key?']("numbered"))) {
30789          attr_overrides['$[]=']("sectnums", attr_overrides.$delete("numbered"))
30790        };
30791        if ($truthy(attr_overrides['$key?']("hardbreaks"))) {
30792          attr_overrides['$[]=']("hardbreaks-option", attr_overrides.$delete("hardbreaks"))
30793        };
30794        if ($truthy((base_dir_val = options['$[]']("base_dir")))) {
30795          self.base_dir = ($c = ["docdir", $$$('File').$expand_path(base_dir_val)], $send(attr_overrides, '[]=', $c), $c[$c.length - 1])
30796        } else if ($truthy(attr_overrides['$[]']("docdir"))) {
30797          self.base_dir = attr_overrides['$[]']("docdir")
30798        } else {
30799          self.base_dir = ($c = ["docdir", $$$('Dir').$pwd()], $send(attr_overrides, '[]=', $c), $c[$c.length - 1])
30800        };
30801        if ($truthy((backend_val = options['$[]']("backend")))) {
30802          attr_overrides['$[]=']("backend", backend_val.$to_s())
30803        };
30804        if ($truthy((doctype_val = options['$[]']("doctype")))) {
30805          attr_overrides['$[]=']("doctype", doctype_val.$to_s())
30806        };
30807        if ($truthy($rb_ge(self.safe, $$$($$('SafeMode'), 'SERVER')))) {
30808          
30809          if ($truthy(($ret_or_1 = attr_overrides['$[]']("copycss")))) {
30810            $ret_or_1
30811          } else {
30812            attr_overrides['$[]=']("copycss", nil)
30813          };
30814          if ($truthy(($ret_or_1 = attr_overrides['$[]']("source-highlighter")))) {
30815            $ret_or_1
30816          } else {
30817            attr_overrides['$[]=']("source-highlighter", nil)
30818          };
30819          if ($truthy(($ret_or_1 = attr_overrides['$[]']("backend")))) {
30820            $ret_or_1
30821          } else {
30822            attr_overrides['$[]=']("backend", $$('DEFAULT_BACKEND'))
30823          };
30824          if (($not(parent_doc) && ($truthy(attr_overrides['$key?']("docfile"))))) {
30825            attr_overrides['$[]=']("docfile", attr_overrides['$[]']("docfile")['$[]'](Opal.Range.$new($rb_plus(attr_overrides['$[]']("docdir").$length(), 1), -1, false)))
30826          };
30827          attr_overrides['$[]=']("docdir", "");
30828          if ($truthy(($ret_or_1 = attr_overrides['$[]']("user-home")))) {
30829            $ret_or_1
30830          } else {
30831            attr_overrides['$[]=']("user-home", ".")
30832          };
30833          if ($truthy($rb_ge(self.safe, $$$($$('SafeMode'), 'SECURE')))) {
30834            
30835            if (!$truthy(attr_overrides['$key?']("max-attribute-value-size"))) {
30836              attr_overrides['$[]=']("max-attribute-value-size", 4096)
30837            };
30838            if (!$truthy(attr_overrides['$key?']("linkcss"))) {
30839              attr_overrides['$[]=']("linkcss", "")
30840            };
30841            if ($truthy(($ret_or_1 = attr_overrides['$[]']("icons")))) {
30842              $ret_or_1
30843            } else {
30844              attr_overrides['$[]=']("icons", nil)
30845            };
30846          };
30847        } else if ($truthy(($ret_or_1 = attr_overrides['$[]']("user-home")))) {
30848          $ret_or_1
30849        } else {
30850          attr_overrides['$[]=']("user-home", $$('USER_HOME'))
30851        };
30852        self.max_attribute_value_size = ($truthy((size = ($truthy(($ret_or_1 = attr_overrides['$[]']("max-attribute-value-size"))) ? ($ret_or_1) : (($c = ["max-attribute-value-size", nil], $send(attr_overrides, '[]=', $c), $c[$c.length - 1]))))) ? (size.$to_i().$abs()) : (nil));
30853        $send(attr_overrides, 'delete_if', [], function $$4(key, val){var $d, verdict = nil;
30854
30855          
30856          if (key == null) key = nil;
30857          if (val == null) val = nil;
30858          if ($truthy(val)) {
30859            
30860            if (($eqeqeq($$$('String'), val) && ($truthy(val['$end_with?']("@"))))) {
30861              $d = [val.$chop(), true], (val = $d[0]), (verdict = $d[1]), $d
30862            };
30863            attrs['$[]='](key, val);
30864          } else {
30865            
30866            attrs.$delete(key);
30867            verdict = val['$=='](false);
30868          };
30869          return verdict;});
30870        if ($truthy(parent_doc)) {
30871          
30872          self.backend = attrs['$[]']("backend");
30873          if (!$eqeq((self.doctype = ($c = ["doctype", parent_doctype], $send(attrs, '[]=', $c), $c[$c.length - 1])), $$('DEFAULT_DOCTYPE'))) {
30874            self.$update_doctype_attributes($$('DEFAULT_DOCTYPE'))
30875          };
30876          self.reader = $$('Reader').$new(data, options['$[]']("cursor"));
30877          if ($truthy(self.sourcemap)) {
30878            self.source_location = self.reader.$cursor()
30879          };
30880          $$('Parser').$parse(self.reader, self);
30881          self.$restore_attributes();
30882          return (self.parsed = true);
30883        } else {
30884          
30885          self.backend = nil;
30886          if ($eqeq((initial_backend = ($truthy(($ret_or_1 = attrs['$[]']("backend"))) ? ($ret_or_1) : ($$('DEFAULT_BACKEND')))), "manpage")) {
30887            self.doctype = ($c = ["doctype", ($d = ["doctype", "manpage"], $send(attr_overrides, '[]=', $d), $d[$d.length - 1])], $send(attrs, '[]=', $c), $c[$c.length - 1])
30888          } else {
30889            self.doctype = ($truthy(($ret_or_1 = attrs['$[]']("doctype"))) ? ($ret_or_1) : (($c = ["doctype", $$('DEFAULT_DOCTYPE')], $send(attrs, '[]=', $c), $c[$c.length - 1])))
30890          };
30891          self.$update_backend_attributes(initial_backend, true);
30892          if ($truthy(($ret_or_1 = attrs['$[]']("stylesdir")))) {
30893            $ret_or_1
30894          } else {
30895            attrs['$[]=']("stylesdir", ".")
30896          };
30897          if ($truthy(($ret_or_1 = attrs['$[]']("iconsdir")))) {
30898            $ret_or_1
30899          } else {
30900            attrs['$[]=']("iconsdir", "" + (attrs.$fetch("imagesdir", "./images")) + "/icons")
30901          };
30902          self.$fill_datetime_attributes(attrs, input_mtime);
30903          if ($truthy(initialize_extensions)) {
30904            if ($truthy((ext_registry = options['$[]']("extension_registry")))) {
30905              if (($eqeqeq($$$($$('Extensions'), 'Registry'), ext_registry) || (($truthy((($e = $$$('::', 'AsciidoctorJ', 'skip_raise')) && ($d = $$$($e, 'Extensions', 'skip_raise')) && ($c = $$$($d, 'ExtensionRegistry', 'skip_raise')) ? 'constant' : nil)) && ($eqeqeq($$$($$$($$$('AsciidoctorJ'), 'Extensions'), 'ExtensionRegistry'), ext_registry)))))) {
30906                self.extensions = ext_registry.$activate(self)
30907              }
30908            } else if ($truthy((ext_block = options['$[]']("extensions"))['$nil?']())) {
30909              if (!$truthy($$('Extensions').$groups()['$empty?']())) {
30910                self.extensions = $$$($$('Extensions'), 'Registry').$new().$activate(self)
30911              }
30912            } else if ($eqeqeq($$$('Proc'), ext_block)) {
30913              self.extensions = $send($$('Extensions'), 'create', [], ext_block.$to_proc()).$activate(self)
30914            }
30915          };
30916          self.reader = $$('PreprocessorReader').$new(self, data, $$$($$('Reader'), 'Cursor').$new(attrs['$[]']("docfile"), self.base_dir), $hash2(["normalize"], {"normalize": true}));
30917          if ($truthy(self.sourcemap)) {
30918            return (self.source_location = self.reader.$cursor())
30919          } else {
30920            return nil
30921          };
30922        };
30923      }, -1);
30924      
30925      $def(self, '$parse', function $$parse(data) {
30926        var self = this, doc = nil, exts = nil;
30927
30928        
30929        if (data == null) data = nil;
30930        if ($truthy(self.parsed)) {
30931          return self
30932        } else {
30933          
30934          doc = self;
30935          if ($truthy(data)) {
30936            
30937            self.reader = $$('PreprocessorReader').$new(doc, data, $$$($$('Reader'), 'Cursor').$new(self.attributes['$[]']("docfile"), self.base_dir), $hash2(["normalize"], {"normalize": true}));
30938            if ($truthy(self.sourcemap)) {
30939              self.source_location = self.reader.$cursor()
30940            };
30941          };
30942          if (($truthy((exts = ($truthy(self.parent_document) ? (nil) : (self.extensions)))) && ($truthy(exts['$preprocessors?']())))) {
30943            $send(exts.$preprocessors(), 'each', [], function $$5(ext){var self = $$5.$$s == null ? this : $$5.$$s, $ret_or_1 = nil;
30944              if (self.reader == null) self.reader = nil;
30945
30946              
30947              if (ext == null) ext = nil;
30948              return (self.reader = ($truthy(($ret_or_1 = ext.$process_method()['$[]'](doc, self.reader))) ? ($ret_or_1) : (self.reader)));}, {$$s: self})
30949          };
30950          $$('Parser').$parse(self.reader, doc, $hash2(["header_only"], {"header_only": self.options['$[]']("parse_header_only")}));
30951          self.$restore_attributes();
30952          if (($truthy(exts) && ($truthy(exts['$tree_processors?']())))) {
30953            $send(exts.$tree_processors(), 'each', [], function $$6(ext){var result = nil;
30954
30955              
30956              if (ext == null) ext = nil;
30957              if ((($truthy((result = ext.$process_method()['$[]'](doc))) && ($eqeqeq($$('Document'), result))) && ($neqeq(result, doc)))) {
30958                return (doc = result)
30959              } else {
30960                return nil
30961              };})
30962          };
30963          self.parsed = true;
30964          return doc;
30965        };
30966      }, -1);
30967      
30968      $def(self, '$parsed?', $return_ivar("parsed"));
30969      
30970      $def(self, '$counter', function $$counter(name, seed) {
30971        var $a, self = this, curr_val = nil, locked = nil, next_val = nil;
30972
30973        
30974        if (seed == null) seed = nil;
30975        if ($truthy(self.parent_document)) {
30976          return self.parent_document.$counter(name, seed)
30977        };
30978        if ((($truthy((locked = self['$attribute_locked?'](name))) && ($truthy((curr_val = self.counters['$[]'](name))))) || ($not((curr_val = self.attributes['$[]'](name))['$nil_or_empty?']())))) {
30979          next_val = ($a = [name, $$('Helpers').$nextval(curr_val)], $send(self.counters, '[]=', $a), $a[$a.length - 1])
30980        } else if ($truthy(seed)) {
30981          next_val = ($a = [name, ($eqeq(seed, seed.$to_i().$to_s()) ? (seed.$to_i()) : (seed))], $send(self.counters, '[]=', $a), $a[$a.length - 1])
30982        } else {
30983          next_val = ($a = [name, 1], $send(self.counters, '[]=', $a), $a[$a.length - 1])
30984        };
30985        if (!$truthy(locked)) {
30986          self.attributes['$[]='](name, next_val)
30987        };
30988        return next_val;
30989      }, -2);
30990      
30991      $def(self, '$increment_and_store_counter', function $$increment_and_store_counter(counter_name, block) {
30992        var self = this;
30993
30994        return $$('AttributeEntry').$new(counter_name, self.$counter(counter_name)).$save_to(block.$attributes()).$value()
30995      });
30996      $alias(self, "counter_increment", "increment_and_store_counter");
30997      
30998      $def(self, '$register', function $$register(type, value) {
30999        var self = this, id = nil, $logical_op_recvr_tmp_1 = nil, $ret_or_2 = nil, ref = nil;
31000
31001        
31002        switch (type) {
31003          case "ids":
31004            return self.$register("refs", [(id = value['$[]'](0)), $$('Inline').$new(self, "anchor", value['$[]'](1), $hash2(["type", "id"], {"type": "ref", "id": id}))])
31005          case "refs":
31006            
31007            
31008            $logical_op_recvr_tmp_1 = self.catalog['$[]']("refs");
31009            if ($truthy(($ret_or_2 = $logical_op_recvr_tmp_1['$[]'](value['$[]'](0))))) {
31010              $ret_or_2
31011            } else {
31012              $logical_op_recvr_tmp_1['$[]='](value['$[]'](0), (ref = value['$[]'](1)))
31013            };;
31014            return ref;
31015          case "footnotes":
31016            return self.catalog['$[]'](type)['$<<'](value)
31017          default:
31018            if ($truthy(self.options['$[]']("catalog_assets"))) {
31019              return self.catalog['$[]'](type)['$<<'](($eqeq(type, "images") ? ($$('ImageReference').$new(value, self.attributes['$[]']("imagesdir"))) : (value)))
31020            } else {
31021              return nil
31022            }
31023        }
31024      });
31025      
31026      $def(self, '$resolve_id', function $$resolve_id(text) {
31027        var self = this, resolved_id = nil, accum = nil;
31028
31029        if ($truthy(self.reftexts)) {
31030          return self.reftexts['$[]'](text)
31031        } else if ($truthy(self.parsed)) {
31032          return $send((self.reftexts = $hash2([], {})), 'tap', [], function $$7(accum){var self = $$7.$$s == null ? this : $$7.$$s;
31033            if (self.catalog == null) self.catalog = nil;
31034
31035            
31036            if (accum == null) accum = nil;
31037            return $send(self.catalog['$[]']("refs"), 'each', [], function $$8(id, ref){var $a, $ret_or_1 = nil;
31038
31039              
31040              if (id == null) id = nil;
31041              if (ref == null) ref = nil;
31042              if ($truthy(($ret_or_1 = accum['$[]'](ref.$xreftext())))) {
31043                return $ret_or_1
31044              } else {
31045                return ($a = [ref.$xreftext(), id], $send(accum, '[]=', $a), $a[$a.length - 1])
31046              };});}, {$$s: self})['$[]'](text)
31047        } else {
31048          
31049          resolved_id = nil;
31050          self.reftexts = (accum = $hash2([], {}));
31051          (function(){try { var $t_break = $thrower('break'); return $send(self.catalog['$[]']("refs"), 'each', [], function $$9(id, ref){var $a, xreftext = nil, $ret_or_1 = nil;
31052
31053            
31054            if (id == null) id = nil;
31055            if (ref == null) ref = nil;
31056            if ($eqeq((xreftext = ref.$xreftext()), text)) {
31057              
31058              resolved_id = id;
31059              $t_break.$throw();
31060            };
31061            if ($truthy(($ret_or_1 = accum['$[]'](xreftext)))) {
31062              return $ret_or_1
31063            } else {
31064              return ($a = [xreftext, id], $send(accum, '[]=', $a), $a[$a.length - 1])
31065            };})} catch($e) {
31066            if ($e === $t_break) return $e.$v;
31067            throw $e;
31068          }})();
31069          self.reftexts = nil;
31070          return resolved_id;
31071        }
31072      });
31073      
31074      $def(self, '$sections?', function $Document_sections$ques$10() {
31075        var self = this;
31076
31077        return $rb_gt(self.next_section_index, 0)
31078      });
31079      
31080      $def(self, '$footnotes?', function $Document_footnotes$ques$11() {
31081        var self = this;
31082
31083        if ($truthy(self.catalog['$[]']("footnotes")['$empty?']())) {
31084          return false
31085        } else {
31086          return true
31087        }
31088      });
31089      
31090      $def(self, '$footnotes', function $$footnotes() {
31091        var self = this;
31092
31093        return self.catalog['$[]']("footnotes")
31094      });
31095      
31096      $def(self, '$callouts', function $$callouts() {
31097        var self = this;
31098
31099        return self.catalog['$[]']("callouts")
31100      });
31101      
31102      $def(self, '$nested?', function $Document_nested$ques$12() {
31103        var self = this;
31104
31105        if ($truthy(self.parent_document)) {
31106          return true
31107        } else {
31108          return false
31109        }
31110      });
31111      
31112      $def(self, '$embedded?', function $Document_embedded$ques$13() {
31113        var self = this;
31114
31115        return self.attributes['$key?']("embedded")
31116      });
31117      
31118      $def(self, '$extensions?', function $Document_extensions$ques$14() {
31119        var self = this;
31120
31121        if ($truthy(self.extensions)) {
31122          return true
31123        } else {
31124          return false
31125        }
31126      });
31127      
31128      $def(self, '$source', function $$source() {
31129        var self = this;
31130
31131        if ($truthy(self.reader)) {
31132          return self.reader.$source()
31133        } else {
31134          return nil
31135        }
31136      });
31137      
31138      $def(self, '$source_lines', function $$source_lines() {
31139        var self = this;
31140
31141        if ($truthy(self.reader)) {
31142          return self.reader.$source_lines()
31143        } else {
31144          return nil
31145        }
31146      });
31147      
31148      $def(self, '$basebackend?', function $Document_basebackend$ques$15(base) {
31149        var self = this;
31150
31151        return self.attributes['$[]']("basebackend")['$=='](base)
31152      });
31153      
31154      $def(self, '$title', function $$title() {
31155        var self = this;
31156
31157        return self.$doctitle()
31158      });
31159      
31160      $def(self, '$title=', function $Document_title$eq$16(title) {
31161        var $a, self = this, sect = nil;
31162
31163        
31164        if (!$truthy((sect = self.header))) {
31165          (sect = (self.header = $$('Section').$new(self, 0)))['$sectname=']("header")
31166        };
31167        return ($a = [title], $send(sect, 'title=', $a), $a[$a.length - 1]);
31168      });
31169      
31170      $def(self, '$doctitle', function $$doctitle(opts) {
31171        var self = this, val = nil, sect = nil, $ret_or_1 = nil, separator = nil;
31172
31173        
31174        if (opts == null) opts = $hash2([], {});
31175        if (!$truthy((val = self.attributes['$[]']("title")))) {
31176          if ($truthy((sect = self.$first_section()))) {
31177            val = sect.$title()
31178          } else if ($not(($truthy(($ret_or_1 = opts['$[]']("use_fallback"))) ? ((val = self.attributes['$[]']("untitled-label"))) : ($ret_or_1)))) {
31179            return nil
31180          }
31181        };
31182        if ($truthy((separator = opts['$[]']("partition")))) {
31183          return $$('Title').$new(val, opts.$merge($hash2(["separator"], {"separator": ($eqeq(separator, true) ? (self.attributes['$[]']("title-separator")) : (separator))})))
31184        } else if (($truthy(opts['$[]']("sanitize")) && ($truthy(val['$include?']("<"))))) {
31185          return val.$gsub($$('XmlSanitizeRx'), "").$squeeze(" ").$strip()
31186        } else {
31187          return val
31188        };
31189      }, -1);
31190      $alias(self, "name", "doctitle");
31191      
31192      $def(self, '$xreftext', function $$xreftext(xrefstyle) {
31193        var self = this, val = nil;
31194
31195        
31196        if (xrefstyle == null) xrefstyle = nil;
31197        if (($truthy((val = self.$reftext())) && ($not(val['$empty?']())))) {
31198          return val
31199        } else {
31200          return self.$title()
31201        };
31202      }, -1);
31203      
31204      $def(self, '$author', function $$author() {
31205        var self = this;
31206
31207        return self.attributes['$[]']("author")
31208      });
31209      
31210      $def(self, '$authors', function $$authors() {
31211        var self = this, attrs = nil, authors = nil, num_authors = nil, $ret_or_1 = nil, idx = nil;
31212
31213        if ($truthy((attrs = self.attributes)['$key?']("author"))) {
31214          
31215          authors = [$$('Author').$new(attrs['$[]']("author"), attrs['$[]']("firstname"), attrs['$[]']("middlename"), attrs['$[]']("lastname"), attrs['$[]']("authorinitials"), attrs['$[]']("email"))];
31216          if ($truthy($rb_gt((num_authors = ($truthy(($ret_or_1 = attrs['$[]']("authorcount"))) ? ($ret_or_1) : (0))), 1))) {
31217            
31218            idx = 1;
31219            while ($truthy($rb_lt(idx, num_authors))) {
31220            
31221              idx = $rb_plus(idx, 1);
31222              authors['$<<']($$('Author').$new(attrs['$[]']("author_" + (idx)), attrs['$[]']("firstname_" + (idx)), attrs['$[]']("middlename_" + (idx)), attrs['$[]']("lastname_" + (idx)), attrs['$[]']("authorinitials_" + (idx)), attrs['$[]']("email_" + (idx))));
31223            };
31224          };
31225          return authors;
31226        } else {
31227          return []
31228        }
31229      });
31230      
31231      $def(self, '$revdate', function $$revdate() {
31232        var self = this;
31233
31234        return self.attributes['$[]']("revdate")
31235      });
31236      
31237      $def(self, '$notitle', function $$notitle() {
31238        var self = this;
31239
31240        return self.attributes['$key?']("notitle")
31241      });
31242      
31243      $def(self, '$noheader', function $$noheader() {
31244        var self = this;
31245
31246        return self.attributes['$key?']("noheader")
31247      });
31248      
31249      $def(self, '$nofooter', function $$nofooter() {
31250        var self = this;
31251
31252        return self.attributes['$key?']("nofooter")
31253      });
31254      
31255      $def(self, '$first_section', function $$first_section() {
31256        var self = this, $ret_or_1 = nil;
31257
31258        if ($truthy(($ret_or_1 = self.header))) {
31259          return $ret_or_1
31260        } else {
31261          return $send(self.blocks, 'find', [], function $$17(e){
31262            
31263            if (e == null) e = nil;
31264            return e.$context()['$==']("section");})
31265        }
31266      });
31267      
31268      $def(self, '$header?', function $Document_header$ques$18() {
31269        var self = this;
31270
31271        if ($truthy(self.header)) {
31272          return true
31273        } else {
31274          return false
31275        }
31276      });
31277      $alias(self, "has_header?", "header?");
31278      
31279      $def(self, '$<<', function $Document_$lt$lt$19(block) {
31280        var $yield = $Document_$lt$lt$19.$$p || nil, self = this;
31281
31282        $Document_$lt$lt$19.$$p = null;
31283        
31284        if ($eqeq(block.$context(), "section")) {
31285          self.$assign_numeral(block)
31286        };
31287        return $send2(self, $find_super(self, '<<', $Document_$lt$lt$19, false, true), '<<', [block], $yield);
31288      });
31289      
31290      $def(self, '$finalize_header', function $$finalize_header(unrooted_attributes, header_valid) {
31291        var self = this;
31292
31293        
31294        if (header_valid == null) header_valid = true;
31295        self.$clear_playback_attributes(unrooted_attributes);
31296        self.$save_attributes();
31297        if (!$truthy(header_valid)) {
31298          unrooted_attributes['$[]=']("invalid-header", true)
31299        };
31300        return unrooted_attributes;
31301      }, -2);
31302      
31303      $def(self, '$playback_attributes', function $$playback_attributes(block_attributes) {
31304        var self = this;
31305
31306        if ($truthy(block_attributes['$key?']("attribute_entries"))) {
31307          return $send(block_attributes['$[]']("attribute_entries"), 'each', [], function $$20(entry){var self = $$20.$$s == null ? this : $$20.$$s, name = nil;
31308            if (self.attributes == null) self.attributes = nil;
31309
31310            
31311            if (entry == null) entry = nil;
31312            name = entry.$name();
31313            if ($truthy(entry.$negate())) {
31314              
31315              self.attributes.$delete(name);
31316              if ($eqeq(name, "compat-mode")) {
31317                return (self.compat_mode = false)
31318              } else {
31319                return nil
31320              };
31321            } else {
31322              
31323              self.attributes['$[]='](name, entry.$value());
31324              if ($eqeq(name, "compat-mode")) {
31325                return (self.compat_mode = true)
31326              } else {
31327                retur
31327n nil
31328              };
31329            };}, {$$s: self})
31330        } else {
31331          return nil
31332        }
31333      });
31334      
31335      $def(self, '$restore_attributes', function $$restore_attributes() {
31336        var self = this;
31337
31338        
31339        if (!$truthy(self.parent_document)) {
31340          self.catalog['$[]']("callouts").$rewind()
31341        };
31342        return self.attributes.$replace(self.header_attributes);
31343      });
31344      
31345      $def(self, '$set_attribute', function $$set_attribute(name, value) {
31346        var self = this, $ret_or_2 = nil;
31347
31348        
31349        if (value == null) value = "";
31350        if ($truthy(self['$attribute_locked?'](name))) {
31351          return nil
31352        } else {
31353          
31354          if (!$truthy(value['$empty?']())) {
31355            value = self.$apply_attribute_value_subs(value)
31356          };
31357          if ($truthy(self.header_attributes)) {
31358            self.attributes['$[]='](name, value)
31359          } else {
31360            
31361            
31362            switch (name) {
31363              case "backend":
31364                self.$update_backend_attributes(value, ($truthy(($ret_or_2 = self.attributes_modified['$delete?']("htmlsyntax"))) ? (value['$=='](self.backend)) : ($ret_or_2)))
31365                break;
31366              case "doctype":
31367                self.$update_doctype_attributes(value)
31368                break;
31369              default:
31370                self.attributes['$[]='](name, value)
31371            };
31372            self.attributes_modified['$<<'](name);
31373          };
31374          return value;
31375        };
31376      }, -2);
31377      
31378      $def(self, '$delete_attribute', function $$delete_attribute(name) {
31379        var self = this;
31380
31381        if ($truthy(self['$attribute_locked?'](name))) {
31382          return false
31383        } else {
31384          
31385          self.attributes.$delete(name);
31386          self.attributes_modified['$<<'](name);
31387          return true;
31388        }
31389      });
31390      
31391      $def(self, '$attribute_locked?', function $Document_attribute_locked$ques$21(name) {
31392        var self = this;
31393
31394        return self.attribute_overrides['$key?'](name)
31395      });
31396      
31397      $def(self, '$set_header_attribute', function $$set_header_attribute(name, value, overwrite) {
31398        var self = this, attrs = nil, $ret_or_1 = nil;
31399
31400        
31401        if (value == null) value = "";
31402        if (overwrite == null) overwrite = true;
31403        attrs = ($truthy(($ret_or_1 = self.header_attributes)) ? ($ret_or_1) : (self.attributes));
31404        if (($eqeq(overwrite, false) && ($truthy(attrs['$key?'](name))))) {
31405          return false
31406        } else {
31407          
31408          attrs['$[]='](name, value);
31409          return true;
31410        };
31411      }, -2);
31412      
31413      $def(self, '$convert', function $$convert(opts) {
31414        var $a, self = this, block = nil, $ret_or_1 = nil, output = nil, transform = nil, exts = nil;
31415
31416        
31417        if (opts == null) opts = $hash2([], {});
31418        if ($truthy(self.timings)) {
31419          self.timings.$start("convert")
31420        };
31421        if (!$truthy(self.parsed)) {
31422          self.$parse()
31423        };
31424        if (!($truthy($rb_ge(self.safe, $$$($$('SafeMode'), 'SERVER'))) || ($truthy(opts['$empty?']())))) {
31425          
31426          if (!$truthy(($a = ["outfile", opts['$[]']("outfile")], $send(self.attributes, '[]=', $a), $a[$a.length - 1]))) {
31427            self.attributes.$delete("outfile")
31428          };
31429          if (!$truthy(($a = ["outdir", opts['$[]']("outdir")], $send(self.attributes, '[]=', $a), $a[$a.length - 1]))) {
31430            self.attributes.$delete("outdir")
31431          };
31432        };
31433        if ($eqeq(self.$doctype(), "inline")) {
31434          if ($truthy((block = ($truthy(($ret_or_1 = self.blocks['$[]'](0))) ? ($ret_or_1) : (self.header))))) {
31435            if (($eqeq(block.$content_model(), "compound") || ($eqeq(block.$content_model(), "empty")))) {
31436              self.$logger().$warn("no inline candidate; use the inline doctype to convert a single paragragh, verbatim, or raw block")
31437            } else {
31438              output = block.$content()
31439            }
31440          }
31441        } else {
31442          
31443          if ($truthy(opts['$key?']("standalone"))) {
31444            transform = ($truthy(opts['$[]']("standalone")) ? ("document") : ("embedded"))
31445          } else if ($truthy(opts['$key?']("header_footer"))) {
31446            transform = ($truthy(opts['$[]']("header_footer")) ? ("document") : ("embedded"))
31447          } else {
31448            transform = ($truthy(self.options['$[]']("standalone")) ? ("document") : ("embedded"))
31449          };
31450          output = self.converter.$convert(self, transform);
31451        };
31452        if (!$truthy(self.parent_document)) {
31453          if (($truthy((exts = self.extensions)) && ($truthy(exts['$postprocessors?']())))) {
31454            $send(exts.$postprocessors(), 'each', [], function $$22(ext){var self = $$22.$$s == null ? this : $$22.$$s;
31455
31456              
31457              if (ext == null) ext = nil;
31458              return (output = ext.$process_method()['$[]'](self, output));}, {$$s: self})
31459          }
31460        };
31461        if ($truthy(self.timings)) {
31462          self.timings.$record("convert")
31463        };
31464        return output;
31465      }, -1);
31466      $alias(self, "render", "convert");
31467      
31468      $def(self, '$write', function $$write(output, target) {
31469        var self = this;
31470
31471        
31472        if ($truthy(self.timings)) {
31473          self.timings.$start("write")
31474        };
31475        if ($eqeqeq($$('Writer'), self.converter)) {
31476          self.converter.$write(output, target)
31477        } else {
31478          
31479          if ($truthy(target['$respond_to?']("write"))) {
31480            if (!$truthy(output['$nil_or_empty?']())) {
31481              
31482              target.$write(output.$chomp());
31483              target.$write($$('LF'));
31484            }
31485          } else {
31486            $$$('File').$write(target, output, $hash2(["mode"], {"mode": $$('FILE_WRITE_MODE')}))
31487          };
31488          if ((($eqeq(self.backend, "manpage") && ($eqeqeq($$$('String'), target))) && ($truthy(self.converter.$class()['$respond_to?']("write_alternate_pages"))))) {
31489            self.converter.$class().$write_alternate_pages(self.attributes['$[]']("mannames"), self.attributes['$[]']("manvolnum"), target)
31490          };
31491        };
31492        if ($truthy(self.timings)) {
31493          self.timings.$record("write")
31494        };
31495        return nil;
31496      });
31497      
31498      $def(self, '$content', function $$content() {
31499        var $yield = $$content.$$p || nil, self = this;
31500
31501        $$content.$$p = null;
31502        
31503        self.attributes.$delete("title");
31504        return $send2(self, $find_super(self, 'content', $$content, false, true), 'content', [], $yield);
31505      });
31506      
31507      $def(self, '$docinfo', function $$docinfo(location, suffix) {
31508        var $a, self = this, qualifier = nil, $ret_or_1 = nil, docinfo = nil, content = nil, docinfo_file = nil, docinfo_dir = nil, docinfo_subs = nil, docinfo_path = nil, shared_docinfo = nil, private_docinfo = nil;
31509
31510        
31511        if (location == null) location = "head";
31512        if (suffix == null) suffix = nil;
31513        if ($truthy($rb_lt(self.$safe(), $$$($$('SafeMode'), 'SECURE')))) {
31514          
31515          if (!$eqeq(location, "head")) {
31516            qualifier = "-" + (location)
31517          };
31518          suffix = ($truthy(($ret_or_1 = suffix)) ? ($ret_or_1) : (self.outfilesuffix
31518));
31519          if ($truthy((docinfo = self.attributes['$[]']("docinfo"))['$nil_or_empty?']())) {
31520            if ($truthy(self.attributes['$key?']("docinfo2"))) {
31521              docinfo = ["private", "shared"]
31522            } else if ($truthy(self.attributes['$key?']("docinfo1"))) {
31523              docinfo = ["shared"]
31524            } else {
31525              docinfo = ($truthy(docinfo) ? (["private"]) : (nil))
31526            }
31527          } else {
31528            docinfo = $send(docinfo.$split(","), 'map', [], function $$23(it){
31529              
31530              if (it == null) it = nil;
31531              return it.$strip();})
31532          };
31533          if ($truthy(docinfo)) {
31534            
31535            content = [];
31536            $a = ["docinfo" + (qualifier) + (suffix), self.attributes['$[]']("docinfodir"), self.$resolve_docinfo_subs()], (docinfo_file = $a[0]), (docinfo_dir = $a[1]), (docinfo_subs = $a[2]), $a;
31537            if (!$truthy(docinfo['$&'](["shared", "shared-" + (location)])['$empty?']())) {
31538              
31539              docinfo_path = self.$normalize_system_path(docinfo_file, docinfo_dir);
31540              if ($truthy((shared_docinfo = self.$read_asset(docinfo_path, $hash2(["normalize"], {"normalize": true}))))) {
31541                content['$<<'](self.$apply_subs(shared_docinfo, docinfo_subs))
31542              };
31543            };
31544            if (!($truthy(self.attributes['$[]']("docname")['$nil_or_empty?']()) || ($truthy(docinfo['$&'](["private", "private-" + (location)])['$empty?']())))) {
31545              
31546              docinfo_path = self.$normalize_system_path("" + (self.attributes['$[]']("docname")) + "-" + (docinfo_file), docinfo_dir);
31547              if ($truthy((private_docinfo = self.$read_asset(docinfo_path, $hash2(["normalize"], {"normalize": true}))))) {
31548                content['$<<'](self.$apply_subs(private_docinfo, docinfo_subs))
31549              };
31550            };
31551          };
31552        };
31553        if (($truthy(self.extensions) && ($truthy(self['$docinfo_processors?'](location))))) {
31554          return ($truthy(($ret_or_1 = content)) ? ($ret_or_1) : ([])).$concat($send(self.docinfo_processor_extensions['$[]'](location), 'map', [], function $$24(ext){var self = $$24.$$s == null ? this : $$24.$$s;
31555
31556            
31557            if (ext == null) ext = nil;
31558            return ext.$process_method()['$[]'](self);}, {$$s: self}).$compact()).$join($$('LF'))
31559        } else if ($truthy(content)) {
31560          return content.$join($$('LF'))
31561        } else {
31562          return ""
31563        };
31564      }, -1);
31565      
31566      $def(self, '$docinfo_processors?', function $Document_docinfo_processors$ques$25(location) {
31567        var $a, self = this;
31568
31569        
31570        if (location == null) location = "head";
31571        if ($truthy(self.docinfo_processor_extensions['$key?'](location))) {
31572          return self.docinfo_processor_extensions['$[]'](location)['$!='](false)
31573        } else if (($truthy(self.extensions) && ($truthy(self.document.$extensions()['$docinfo_processors?'](location))))) {
31574          return ($a = [location, self.document.$extensions().$docinfo_processors(location)], $send(self.docinfo_processor_extensions, '[]=', $a), $a[$a.length - 1])['$!']()['$!']()
31575        } else {
31576          return ($a = [location, false], $send(self.docinfo_processor_extensions, '[]=', $a), $a[$a.length - 1])
31577        };
31578      }, -1);
31579      
31580      $def(self, '$to_s', function $$to_s() {
31581        var self = this, $ret_or_1 = nil;
31582
31583        return "#<" + (self.$class()) + "@" + (self.$object_id()) + " {doctype: " + (self.$doctype().$inspect()) + ", doctitle: " + (($truthy(($ret_or_1 = self.header)) ? (self.header.$title()) : ($ret_or_1)).$inspect()) + ", blocks: " + (self.blocks.$size()) + "}>"
31584      });
31585      self.$private();
31586      
31587      $def(self, '$apply_attribute_value_subs', function $$apply_attribute_value_subs(value) {
31588        var $a, self = this;
31589
31590        
31591        if ($truthy($$('AttributeEntryPassMacroRx')['$=~'](value))) {
31592          
31593          value = (($a = $gvars['~']) === nil ? nil : $a['$[]'](2));
31594          if ($truthy((($a = $gvars['~']) === nil ? nil : $a['$[]'](1)))) {
31595            value = self.$apply_subs(value, self.$resolve_pass_subs((($a = $gvars['~']) === nil ? nil : $a['$[]'](1))))
31596          };
31597        } else {
31598          value = self.$apply_header_subs(value)
31599        };
31600        if ($truthy(self.max_attribute_value_size)) {
31601          
31602          return self.$limit_bytesize(value, self.max_attribute_value_size);
31603        } else {
31604          return value
31605        };
31606      });
31607      
31608      $def(self, '$limit_bytesize', function $$limit_bytesize(str, max) {
31609        
31610        
31611        if ($truthy($rb_gt(str.$bytesize(), max))) {
31612          while (!($truthy((str = str.$byteslice(0, max))['$valid_encoding?']()))) {
31613          max = $rb_minus(max, 1)
31614          }
31615        };
31616        return str;
31617      });
31618      
31619      $def(self, '$resolve_docinfo_subs', function $$resolve_docinfo_subs() {
31620        var self = this;
31621
31622        if ($truthy(self.attributes['$key?']("docinfosubs"))) {
31623          
31624          return self.$resolve_subs(self.attributes['$[]']("docinfosubs"), "block", nil, "docinfo");
31625        } else {
31626          return ["attributes"]
31627        }
31628      });
31629      
31630      $def(self, '$create_converter', function $$create_converter(backend, delegate_backend) {
31631        var self = this, converter_opts = nil, template_dirs = nil, $ret_or_1 = nil, opts = nil, converter = nil;
31632
31633        
31634        converter_opts = $hash2(["document", "htmlsyntax"], {"document": self, "htmlsyntax": self.attributes['$[]']("htmlsyntax")});
31635        if ($truthy((template_dirs = ($truthy(($ret_or_1 = (opts = self.options)['$[]']("template_dirs"))) ? ($ret_or_1) : (opts['$[]']("template_dir")))))) {
31636          
31637          converter_opts['$[]=']("template_dirs", [].concat($to_a(template_dirs)));
31638          converter_opts['$[]=']("template_cache", opts.$fetch("template_cache", true));
31639          converter_opts['$[]=']("template_engine", opts['$[]']("template_engine"));
31640          converter_opts['$[]=']("template_engine_options", opts['$[]']("template_engine_options"));
31641          converter_opts['$[]=']("eruby", opts['$[]']("eruby"));
31642          converter_opts['$[]=']("safe", self.safe);
31643          if ($truthy(delegate_backend)) {
31644            converter_opts['$[]=']("delegate_backend", delegate_backend)
31645          };
31646        };
31647        if ($truthy((converter = opts['$[]']("converter")))) {
31648          return $$$($$('Converter'), 'CustomFactory').$new($hash(backend, converter)).$create(backend, converter_opts)
31649        } else {
31650          return opts.$fetch("converter_factory", $$('Converter')).$create(backend, converter_opts)
31651        };
31652      });
31653      
31654      $def(self, '$clear_playback_attributes', function $$clear_playback_attributes(attributes) {
31655        
31656        return attributes.$delete("attribute_entries")
31657      });
31658      
31659      $def(self, '$save_attributes', function $$save_attributes() {
31660        var self = this, doctitle_val = nil, attrs = nil, $ret_or_1 = nil, toc_val = nil, toc_position_val = nil, toc_placement_val = nil, default_toc_position = nil, default_toc_class = nil, position = nil, icons_val = nil, basebackend = nil, syntax_hl_name = nil, syntax_hl_factory = nil, syntax_hls = nil;
31661
31662        
31663        if (!($truthy((attrs = self.attributes)['$key?']("doctitle")) || ($not((doctitle_val = self.$doctitle()))))) {
31664          attrs['$[]=']("doctitle", doctitle_val)
31665        };
31666        self.id = ($truthy(($ret_or_1 = self.id)) ? ($ret_or_1) : (attrs['$[]']("css-signature")));
31667        if ($truthy((toc_val = ($truthy(attrs.$delete("toc2")) ? ("left") : (attrs['$[]']("toc")))))) {
31668          
31669          toc_position_val = (($truthy((toc_placement_val = attrs.$fetch("toc-placement", "macro"))) && ($neqeq(toc_placement_val, "auto"))) ? (toc_placement_val) : (attrs['$[]']("toc-position")));
31670          if (!($truthy(toc_val['$empty?']()) && ($truthy(toc_position_val['$nil_or_empty?']())))) {
31671            
31672            default_toc_position = "left";
31673            default_toc_class = "toc2";
31674            position = ($truthy(toc_position_val['$nil_or_empty?']()) ? (($truthy(toc_val['$empty?']()) ? (default_toc_position) : (toc_val))) : (toc_position_val));
31675            attrs['$[]=']("toc", "");
31676            attrs['$[]=']("toc-placement", "auto");
31677            
31678            switch (position) {
31679              case "left":
31680              case "<":
31681              case "&lt;":
31682                attrs['$[]=']("toc-position", "left")
31683                break;
31684              case "right":
31685              case ">":
31686              case "&gt;":
31687                attrs['$[]=']("toc-position", "right")
31688                break;
31689              case "top":
31690              case "^":
31691                attrs['$[]=']("toc-position", "top")
31692                break;
31693              case "bottom":
31694              case "v":
31695                attrs['$[]=']("toc-position", "bottom")
31696                break;
31697              case "preamble":
31698              case "macro":
31699                
31700                attrs['$[]=']("toc-position", "content");
31701                attrs['$[]=']("toc-placement", position);
31702                default_toc_class = nil;
31703                break;
31704              default:
31705                
31706                attrs.$delete("toc-position");
31707                default_toc_class = nil;
31708            };
31709            if ($truthy(default_toc_class)) {
31710              if ($truthy(($ret_or_1 = attrs['$[]']("toc-class")))) {
31711                $ret_or_1
31712              } else {
31713                attrs['$[]=']("toc-class", default_toc_class)
31714              }
31715            };
31716          };
31717        };
31718        if (($truthy((icons_val = attrs['$[]']("icons"))) && ($not(attrs['$key?']("icontype"))))) {
31719          
31720          switch (icons_val) {
31721            case "":
31722            case "font":
31723              
31724              break;
31725            default:
31726              
31727              attrs['$[]=']("icons", "");
31728              if (!$eqeq(icons_val, "image")) {
31729                attrs['$[]=']("icontype", icons_val)
31730              };
31731          }
31732        };
31733        if (($truthy((self.compat_mode = attrs['$key?']("compat-mode"))) && ($truthy(attrs['$key?']("language"))))) {
31734          attrs['$[]=']("source-language", attrs['$[]']("language"))
31735        };
31736        if (!$truthy(self.parent_document)) {
31737          
31738          if ($eqeq((basebackend = attrs['$[]']("basebackend")), "html")) {
31739            if (($truthy((syntax_hl_name = attrs['$[]']("source-highlighter"))) && ($not(attrs['$[]']("" + (syntax_hl_name) + "-unavailable"))))) {
31740              if ($truthy((syntax_hl_factory = self.options['$[]']("syntax_highlighter_factory")))) {
31741                self.syntax_highlighter = syntax_hl_factory.$create(syntax_hl_name, self.backend, $hash2(["document"], {"document": self}))
31742              } else if ($truthy((syntax_hls = self.options['$[]']("syntax_highlighters")))) {
31743                self.syntax_highlighter = $$$($$('SyntaxHighlighter'), 'DefaultFactoryProxy').$new(syntax_hls).$create(syntax_hl_name, self.backend, $hash2(["document"], {"document": self}))
31744              } else {
31745                self.syntax_highlighter = $$('SyntaxHighlighter').$create(syntax_hl_name, self.backend, $hash2(["document"], {"document": self}))
31746              }
31747            }
31748          } else if ($eqeq(basebackend, "docbook")) {
31749            
31750            if (!($truthy(self['$attribute_locked?']("toc")) || ($truthy(self.attributes_modified['$include?']("toc"))))) {
31751              attrs['$[]=']("toc", "")
31752            };
31753            if (!($truthy(self['$attribute_locked?']("sectnums")) || ($truthy(self.attributes_modified['$include?']("sectnums"))))) {
31754              attrs['$[]=']("sectnums", "")
31755            };
31756          };
31757          self.outfilesuffix = attrs['$[]']("outfilesuffix");
31758          $send($$('FLEXIBLE_ATTRIBUTES'), 'each', [], function $$26(name){var self = $$26.$$s == null ? this : $$26.$$s;
31759            if (self.attribute_overrides == null) self.attribute_overrides = nil;
31760
31761            
31762            if (name == null) name = nil;
31763            if (($truthy(self.attribute_overrides['$key?'](name)) && ($truthy(self.attribute_overrides['$[]'](name))))) {
31764              return self.attribute_overrides.$delete(name)
31765            } else {
31766              return nil
31767            };}, {$$s: self});
31768        };
31769        return (self.header_attributes = attrs.$merge());
31770      });
31771      
31772      $def(self, '$fill_datetime_attributes', function $$fill_datetime_attributes(attrs, input_mtime) {
31773        var $a, self = this, now = nil, source_date_epoch = nil, localdate = nil, $ret_or_1 = nil, localtime = nil, $ret_or_2 = nil, docdate = nil, doctime = nil;
31774
31775        
31776        now = ($truthy($$$('ENV')['$key?']("SOURCE_DATE_EPOCH")) ? ((source_date_epoch = $$$('Time').$at(self.$Integer($$$('ENV')['$[]']("SOURCE_DATE_EPOCH"))).$utc())) : ($$$('Time').$now()));
31777        if ($truthy((localdate = attrs['$[]']("localdate")))) {
31778          if ($truthy(($ret_or_1 = attrs['$[]']("localyear")))) {
31779            $ret_or_1
31780          } else {
31781            attrs['$[]=']("localyear", ($eqeq(localdate.$index("-"), 4) ? (localdate.$slice(0, 4)) : (nil)))
31782          }
31783        } else {
31784          
31785          localdate = ($a = ["localdate", now.$strftime("%F")], $send(attrs, '[]=', $a), $a[$a.length - 1]);
31786          if ($truthy(($ret_or_1 = attrs['$[]']("localyear")))) {
31787            $ret_or_1
31788          } else {
31789            attrs['$[]=']("localyear", now.$year().$to_s())
31790          };
31791        };
31792        localtime = ($truthy(($ret_or_1 = attrs['$[]']("localtime"))) ? ($ret_or_1) : (($a = ["localtime", now.$strftime("%T " + (($eqeq(now.$utc_offset(), 0) ? ("UTC") : ("%z"))))], $send(attrs, '[]=', $a), $a[$a.length - 1])));
31793        if ($truthy(($ret_or_1 = attrs['$[]']("localdatetime")))) {
31794          $ret_or_1
31795        } else {
31796          attrs['$[]=']("localdatetime", "" + (localdate) + " " + (localtime))
31797        };
31798        input_mtime = ($truthy(($ret_or_1 = ($truthy(($ret_or_2 = source_date_epoch)) ? ($ret_or_2) : (input_mtime)))) ? ($ret_or_1) : (now));
31799        if ($truthy((docdate = attrs['$[]']("docdate")))) {
31800          if ($truthy(($ret_or_1 = attrs['$[]']("docyear")))) {
31801            $ret_or_1
31802          } else {
31803            attrs['$[]=']("docyear", ($eqeq(docdate.$index("-"), 4) ? (docdate.$slice(0, 4)) : (nil)))
31804          }
31805        } else {
31806          
31807          docdate = ($a = ["docdate", input_mtime.$strftime("%F")], $send(attrs, '[]=', $a), $a[$a.length - 1]);
31808          if ($truthy(($ret_or_1 = attrs['$[]']("docyear")))) {
31809            $ret_or_1
31810          } else {
31811            attrs['$[]=']("docyear", input_mtime.$year().$to_s())
31812          };
31813        };
31814        doctime = ($truthy(($ret_or_1 = attrs['$[]']("doctime"))) ? ($ret_or_1) : (($a = ["doctime", input_mtime.$strftime("%T " + (($eqeq(input_mtime.$utc_offset(), 0) ? ("UTC") : ("%z"))))], $send(attrs, '[]=', $a), $a[$a.length - 1])));
31815        if ($truthy(($ret_or_1 = attrs['$[]']("docdatetime")))) {
31816          $ret_or_1
31817        } else {
31818          attrs['$[]=']("docdatetime", "" + (docdate) + " " + (doctime))
31819        };
31820        return nil;
31821      });
31822      
31823      $def(self, '$update_backend_attributes', function $$update_backend_attributes(new_backend, init) {
31824        var $a, $b, self = this, current_backend = nil, current_basebackend = nil, attrs = nil, current_doctype = nil, actual_backend = nil, _ = nil, $ret_or_1 = nil, delegate_backend = nil, converter = nil, new_basebackend = nil, new_filetype = nil, htmlsyntax = nil, backend_traits = nil, current_filetype = nil, page_width = nil;
31825
31826        
31827        if (init == null) init = nil;
31828        if (($truthy(init) || ($neqeq(new_backend, self.backend)))) {
31829          
31830          current_backend = self.backend;
31831          current_basebackend = (attrs = self.attributes)['$[]']("basebackend");
31832          current_doctype = self.doctype;
31833          if ($truthy(new_backend['$include?'](":"))) {
31834            $b = new_backend.$partition(":"), $a = $to_ary($b), (actual_backend = ($a[0] == null ? nil : $a[0])), (_ = ($a[1] == null ? nil : $a[1])), (new_backend = ($a[2] == null ? nil : $a[2])), $b
31835          };
31836          if ($truthy(new_backend['$start_with?']("xhtml"))) {
31837            
31838            attrs['$[]=']("htmlsyntax", "xml");
31839            new_backend = new_backend.$slice(1, new_backend.$length());
31840          } else if ($truthy(new_backend['$start_with?']("html"))) {
31841            if ($truthy(($ret_or_1 = attrs['$[]']("htmlsyntax")))) {
31842              $ret_or_1
31843            } else {
31844              attrs['$[]=']("htmlsyntax", "html")
31845            }
31846          };
31847          new_backend = ($truthy(($ret_or_1 = $$('BACKEND_ALIASES')['$[]'](new_backend))) ? ($ret_or_1) : (new_backend));
31848          if ($truthy(actual_backend)) {
31849            $a = [actual_backend, new_backend], (new_backend = $a[0]), (delegate_backend = $a[1]), $a
31850          };
31851          if ($truthy(current_doctype)) {
31852            
31853            if ($truthy(current_backend)) {
31854              
31855              attrs.$delete("backend-" + (current_backend));
31856              attrs.$delete("backend-" + (current_backend) + "-doctype-" + (current_doctype));
31857            };
31858            attrs['$[]=']("backend-" + (new_backend) + "-doctype-" + (current_doctype), "");
31859            attrs['$[]=']("doctype-" + (current_doctype), "");
31860          } else if ($truthy(current_backend)) {
31861            attrs.$delete("backend-" + (current_backend))
31862          };
31863          attrs['$[]=']("backend-" + (new_backend), "");
31864          self.backend = ($a = ["backend", new_backend], $send(attrs, '[]=', $a), $a[$a.length - 1]);
31865          if ($eqeqeq($$$($$('Converter'), 'BackendTraits'), (converter = self.$create_converter(new_backend, delegate_backend)))) {
31866            
31867            new_basebackend = converter.$basebackend();
31868            new_filetype = converter.$filetype();
31869            if ($truthy((htmlsyntax = converter.$htmlsyntax()))) {
31870              attrs['$[]=']("htmlsyntax", htmlsyntax)
31871            };
31872            if ($truthy(init)) {
31873              if ($truthy(($ret_or_1 = attrs['$[]']("outfilesuffix")))) {
31874                $ret_or_1
31875              } else {
31876                attrs['$[]=']("outfilesuffix", converter.$outfilesuffix())
31877              }
31878            } else if (!$truthy(self['$attribute_locked?']("outfilesuffix"))) {
31879              attrs['$[]=']("outfilesuffix", converter.$outfilesuffix())
31880            };
31881          } else if ($truthy(converter)) {
31882            
31883            backend_traits = $$('Converter').$derive_backend_traits(new_backend);
31884            new_basebackend = backend_traits['$[]']("basebackend");
31885            new_filetype = backend_traits['$[]']("filetype");
31886            if ($truthy(init)) {
31887              if ($truthy(($ret_or_1 = attrs['$[]']("outfilesuffix")))) {
31888                $ret_or_1
31889              } else {
31890                attrs['$[]=']("outfilesuffix", backend_traits['$[]']("outfilesuffix"))
31891              }
31892            } else if (!$truthy(self['$attribute_locked?']("outfilesuffix"))) {
31893              attrs['$[]=']("outfilesuffix", backend_traits['$[]']("outfilesuffix"))
31894            };
31895          } else {
31896            self.$raise($$$('NotImplementedError'), "asciidoctor: FAILED: missing converter for backend '" + (ne
31896w_backend) + "'. Processing aborted.")
31897          };
31898          self.converter = converter;
31899          if ($truthy((current_filetype = attrs['$[]']("filetype")))) {
31900            attrs.$delete("filetype-" + (current_filetype))
31901          };
31902          attrs['$[]=']("filetype", new_filetype);
31903          attrs['$[]=']("filetype-" + (new_filetype), "");
31904          if ($truthy((page_width = $$('DEFAULT_PAGE_WIDTHS')['$[]'](new_basebackend)))) {
31905            attrs['$[]=']("pagewidth", page_width)
31906          } else {
31907            attrs.$delete("pagewidth")
31908          };
31909          if ($neqeq(new_basebackend, current_basebackend)) {
31910            
31911            if ($truthy(current_doctype)) {
31912              
31913              if ($truthy(current_basebackend)) {
31914                
31915                attrs.$delete("basebackend-" + (current_basebackend));
31916                attrs.$delete("basebackend-" + (current_basebackend) + "-doctype-" + (current_doctype));
31917              };
31918              attrs['$[]=']("basebackend-" + (new_basebackend) + "-doctype-" + (current_doctype), "");
31919            } else if ($truthy(current_basebackend)) {
31920              attrs.$delete("basebackend-" + (current_basebackend))
31921            };
31922            attrs['$[]=']("basebackend-" + (new_basebackend), "");
31923            attrs['$[]=']("basebackend", new_basebackend);
31924          };
31925          return new_backend;
31926        } else {
31927          return nil
31928        };
31929      }, -2);
31930      return $def(self, '$update_doctype_attributes', function $$update_doctype_attributes(new_doctype) {
31931        var $a, self = this, attrs = nil, current_backend = nil, current_basebackend = nil, current_doctype = nil;
31932
31933        if (($truthy(new_doctype) && ($neqeq(new_doctype, self.doctype)))) {
31934          
31935          $a = [self.backend, (attrs = self.attributes)['$[]']("basebackend"), self.doctype], (current_backend = $a[0]), (current_basebackend = $a[1]), (current_doctype = $a[2]), $a;
31936          if ($truthy(current_doctype)) {
31937            
31938            attrs.$delete("doctype-" + (current_doctype));
31939            if ($truthy(current_backend)) {
31940              
31941              attrs.$delete("backend-" + (current_backend) + "-doctype-" + (current_doctype));
31942              attrs['$[]=']("backend-" + (current_backend) + "-doctype-" + (new_doctype), "");
31943            };
31944            if ($truthy(current_basebackend)) {
31945              
31946              attrs.$delete("basebackend-" + (current_basebackend) + "-doctype-" + (current_doctype));
31947              attrs['$[]=']("basebackend-" + (current_basebackend) + "-doctype-" + (new_doctype), "");
31948            };
31949          } else {
31950            
31951            if ($truthy(current_backend)) {
31952              attrs['$[]=']("backend-" + (current_backend) + "-doctype-" + (new_doctype), "")
31953            };
31954            if ($truthy(current_basebackend)) {
31955              attrs['$[]=']("basebackend-" + (current_basebackend) + "-doctype-" + (new_doctype), "")
31956            };
31957          };
31958          attrs['$[]=']("doctype-" + (new_doctype), "");
31959          return (self.doctype = ($a = ["doctype", new_doctype], $send(attrs, '[]=', $a), $a[$a.length - 1]));
31960        } else {
31961          return nil
31962        }
31963      });
31964    })($nesting[0], $$('AbstractBlock'), $nesting)
31965  })($nesting[0], $nesting)
31966};
31967
31968Opal.modules["asciidoctor/inline"] = function(Opal) {/* Generated by Opal 1.7.3 */
31969  "use strict";
31970  var $module = Opal.module, $klass = Opal.klass, $hash2 = Opal.hash2, $send2 = Opal.send2, $find_super = Opal.find_super, $def = Opal.def, $return_val = Opal.return_val, $alias = Opal.alias, $truthy = Opal.truthy, $nesting = [], nil = Opal.nil;
31971
31972  Opal.add_stubs('attr_accessor,attr_reader,[],convert,converter,attr,==,apply_reftext_subs,reftext');
31973  return (function($base, $parent_nesting) {
31974    var self = $module($base, 'Asciidoctor');
31975
31976    var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
31977
31978    return (function($base, $super) {
31979      var self = $klass($base, $super, 'Inline');
31980
31981      var $proto = self.$$prototype;
31982
31983      $proto.text = $proto.type = nil;
31984      
31985      self.$attr_accessor("text");
31986      self.$attr_reader("type");
31987      self.$attr_accessor("target");
31988      
31989      $def(self, '$initialize', function $$initialize(parent, context, text, opts) {
31990        var $yield = $$initialize.$$p || nil, self = this;
31991
31992        $$initialize.$$p = null;
31993        
31994        if (text == null) text = nil;
31995        if (opts == null) opts = $hash2([], {});
31996        $send2(self, $find_super(self, 'initialize', $$initialize, false, true), 'initialize', [parent, context, opts], null);
31997        self.node_name = "inline_" + (context);
31998        self.text = text;
31999        self.id = opts['$[]']("id");
32000        self.type = opts['$[]']("type");
32001        return (self.target = opts['$[]']("target"));
32002      }, -3);
32003      
32004      $def(self, '$block?', $return_val(false));
32005      
32006      $def(self, '$inline?', $return_val(true));
32007      
32008      $def(self, '$convert', function $$convert() {
32009        var self = this;
32010
32011        return self.$converter().$convert(self)
32012      });
32013      $alias(self, "render", "convert");
32014      
32015      $def(self, '$alt', function $$alt() {
32016        var self = this, $ret_or_1 = nil;
32017
32018        if ($truthy(($ret_or_1 = self.$attr("alt")))) {
32019          return $ret_or_1
32020        } else {
32021          return ""
32022        }
32023      });
32024      
32025      $def(self, '$reftext?', function $Inline_reftext$ques$1() {
32026        var self = this, $ret_or_1 = nil, $ret_or_2 = nil;
32027
32028        if ($truthy(($ret_or_1 = self.text))) {
32029          
32030          if ($truthy(($ret_or_2 = self.type['$==']("ref")))) {
32031            return $ret_or_2
32032          } else {
32033            return self.type['$==']("bibref")
32034          };
32035        } else {
32036          return $ret_or_1
32037        }
32038      });
32039      
32040      $def(self, '$reftext', function $$reftext() {
32041        var self = this, val = nil;
32042
32043        if ($truthy((val = self.text))) {
32044          
32045          return self.$apply_reftext_subs(val);
32046        } else {
32047          return nil
32048        }
32049      });
32050      return $def(self, '$xreftext', function $$xreftext(xrefstyle) {
32051        var self = this;
32052
32053        
32054        if (xrefstyle == null) xrefstyle = nil;
32055        return self.$reftext();
32056      }, -1);
32057    })($nesting[0], $$('AbstractNode'))
32058  })($nesting[0], $nesting)
32059};
32060
32061Opal.modules["asciidoctor/list"] = function(Opal) {/* Generated by Opal 1.7.3 */
32062  "use strict";
32063  var $module = Opal.module, $klass = Opal.klass, $alias = Opal.alias, $hash2 = Opal.hash2, $send2 = Opal.send2, $find_super = Opal.find_super, $def = Opal.def, $truthy = Opal.truthy, $eqeq = Opal.eqeq, $nesting = [], nil = Opal.nil;
32064
32065  Opal.add_stubs('blocks,blocks?,==,next_list,callouts,convert,class,object_id,inspect,size,items,parent,attr_accessor,level,drop,nil_or_empty?,apply_subs,attr_writer,empty?,===,[],outline?,!,simple?,source,shift,context');
32066  return (function($base, $parent_nesting) {
32067    var self = $module($base, 'Asciidoctor');
32068
32069    var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
32070
32071    
32072    (function($base, $super) {
32073      var self = $klass($base, $super, 'List');
32074
32075      var $proto = self.$$prototype;
32076
32077      $proto.context = $proto.document = $proto.style = nil;
32078      
32079      $alias(self, "items", "blocks");
32080      $alias(self, "content", "blocks");
32081      $alias(self, "items?", "blocks?");
32082      
32083      $def(self, '$initialize', function $$initialize(parent, context, opts) {
32084        var $yield = $$initialize.$$p || nil, self = this;
32085
32086        $$initialize.$$p = null;
32087        
32088        if (opts == null) opts = $hash2([], {});
32089        return $send2(self, $find_super(self, 'initialize', $$initialize, false, true), 'initialize', [parent, context, opts], $yield);
32090      }, -3);
32091      
32092      $def(self, '$outline?', function $List_outline$ques$1() {
32093        var self = this, $ret_or_1 = nil;
32094
32095        if ($truthy(($ret_or_1 = self.context['$==']("ulist")))) {
32096          return $ret_or_1
32097        } else {
32098          return self.context['$==']("olist")
32099        }
32100      });
32101      
32102      $def(self, '$convert', function $$convert() {
32103        var $yield = $$convert.$$p || nil, self = this, result = nil;
32104
32105        $$convert.$$p = null;
32106        if ($eqeq(self.context, "colist")) {
32107          
32108          result = $send2(self, $find_super(self, 'convert', $$convert, false, true), 'convert', [], $yield);
32109          self.document.$callouts().$next_list();
32110          return result;
32111        } else {
32112          return $send2(self, $find_super(self, 'convert', $$convert, false, true), 'convert', [], $yield)
32113        }
32114      });
32115      $alias(self, "render", "convert");
32116      return $def(self, '$to_s', function $$to_s() {
32117        var self = this;
32118
32119        return "#<" + (self.$class()) + "@" + (self.$object_id()) + " {context: " + (self.context.$inspect()) + ", style: " + (self.style.$inspect()) + ", items: " + (self.$items().$size()) + "}>"
32120      });
32121    })($nesting[0], $$('AbstractBlock'));
32122    return (function($base, $super, $parent_nesting) {
32123      var self = $klass($base, $super, 'ListItem');
32124
32125      var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype;
32126
32127      $proto.text = $proto.subs = $proto.blocks = nil;
32128      
32129      $alias(self, "list", "parent");
32130      self.$attr_accessor("marker");
32131      
32132      $def(self, '$initialize', function $$initialize(parent, text) {
32133        var $yield = $$initialize.$$p || nil, self = this;
32134
32135        $$initialize.$$p = null;
32136        
32137        if (text == null) text = nil;
32138        $send2(self, $find_super(self, 'initialize', $$initialize, false, true), 'initialize', [parent, "list_item"], null);
32139        self.text = text;
32140        self.level = parent.$level();
32141        return (self.subs = $$('NORMAL_SUBS').$drop(0));
32142      }, -2);
32143      
32144      $def(self, '$text?', function $ListItem_text$ques$2() {
32145        var self = this;
32146
32147        if ($truthy(self.text['$nil_or_empty?']())) {
32148          return false
32149        } else {
32150          return true
32151        }
32152      });
32153      
32154      $def(self, '$text', function $$text() {
32155        var self = this, $ret_or_1 = nil;
32156
32157        if ($truthy(($ret_or_1 = self.text))) {
32158          
32159          return self.$apply_subs(self.text, self.subs);
32160        } else {
32161          return $ret_or_1
32162        }
32163      });
32164      self.$attr_writer("text");
32165      
32166      $def(self, '$simple?', function $ListItem_simple$ques$3() {
32167        var self = this, $ret_or_1 = nil, $ret_or_2 = nil, $ret_or_3 = nil, blk = nil;
32168
32169        if ($truthy(($ret_or_1 = self.blocks['$empty?']()))) {
32170          return $ret_or_1
32171        } else {
32172          
32173          if ($truthy(($ret_or_2 = ($truthy(($ret_or_3 = self.blocks.$size()['$=='](1))) ? ($$('List')['$===']((blk = self.blocks['$[]'](0)))) : ($ret_or_3))))) {
32174            return blk['$outline?']()
32175          } else {
32176            return $ret_or_2
32177          };
32178        }
32179      });
32180      
32181      $def(self, '$compound?', function $ListItem_compound$ques$4() {
32182        var self = this;
32183
32184        return self['$simple?']()['$!']()
32185      });
32186      
32187      $def(self, '$fold_first', function $$fold_first() {
32188        var self = this;
32189
32190        
32191        self.text = ($truthy(self.text['$nil_or_empty?']()) ? (self.blocks.$shift().$source()) : ("" + (self.text) + ($$('LF')) + (self.blocks.$shift().$source())));
32192        return nil;
32193      });
32194      return $def(self, '$to_s', function $$to_s() {
32195        var self = this, $ret_or_1 = nil;
32196
32197        return "#<" + (self.$class()) + "@" + (self.$object_id()) + " {list_context: " + (self.$parent().$context().$inspect()) + ", text: " + (self.text.$inspect()) + ", blocks: " + (($truthy(($ret_or_1 = self.blocks)) ? ($ret_or_1) : ([])).$size()) + "}>"
32198      });
32199    })($nesting[0], $$('AbstractBlock'), $nesting);
32200  })($nesting[0], $nesting)
32201};
32202
32203Opal.modules["asciidoctor/parser"] = function(Opal) {/* Generated by Opal 1.7.3 */
32204  "use strict";
32205  var $module = Opal.module, $klass = Opal.klass, $const_set = Opal.const_set, $send = Opal.send, $truthy = Opal.truthy, $hash2 = Opal.hash2, $to_ary = Opal.to_ary, $defs = Opal.defs, $eqeq = Opal.eqeq, $not = Opal.not, $gvars = Opal.gvars, $neqeq = Opal.neqeq, $rb_plus = Opal.rb_plus, $rb_lt = Opal.rb_lt, $rb_gt = Opal.rb_gt, $to_a = Opal.to_a, $eqeqeq = Opal.eqeqeq, $rb_minus = Opal.rb_minus, $rb_times = Opal.rb_times, $thrower = Opal.thrower, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$;
32206
32207  Opal.add_stubs('include,new,proc,start_with?,match?,is_delimited_block?,private_class_method,parse_document_header,[],has_more_lines?,next_section,assign_numeral,<<,blocks,skip_blank_lines,parse_block_metadata_lines,attributes,is_next_line_doctitle?,[]=,finalize_header,nil_or_empty?,title=,sourcemap,cursor,parse_section_title,id=,include?,sub_specialchars,sub_attributes,source_location=,header,attribute_locked?,id,clear,delete,instance_variable_get,parse_header_metadata,==,!,register,process_authors,update,doctype,parse_manpage_header,=~,downcase,error,logger,message_with_context,cursor_at_line,backend,save,is_next_line_section?,initialize_section,join,map,read_lines_until,lstrip,split,title,restore_save,discard_save,header?,empty?,context,!=,attr?,attr,key?,document,+,level,special,sectname,to_i,<,>,warn,next_block,blocks?,style,style=,parent=,content_model,content_model=,lines,subs,size,context=,shift,unwrap_standalone_preamble,
32207source_location,merge,fetch,parse_block_metadata_line,extensions,block_macros?,mark,read_line,terminator,to_s,masq,to_sym,registered_for_block?,debug?,debug,cursor_at_mark,strict_verbatim_paragraphs,unshift_line,markdown_syntax,keys,chr,uniform?,length,end_with?,parse_attributes,attribute_missing,tr,basename,assign_caption,registered_for_block_macro?,config,process_method,replace,parse_callout_list,callouts,===,parse_list,parse_description_list,underline_style_section_titles,is_section_title?,peek_line,atx_section_title?,generate_id,level=,read_paragraph_lines,adjust_indentation!,map!,slice,pop,build_block,apply_subs,chop,catalog_inline_anchors,rekey,index,strip,-,parse_table,each,raise,title?,update_attributes,commit_subs,sub?,catalog_callouts,source,remove_sub,block_terminates_paragraph,to_proc,nil?,parse_blocks,parse_list_item,items,scan,gsub,count,advance,dup,match,callout_ids,next_list,catalog_inline_anchor,marker=,catalog_inline_biblio_anchor,set_option,text=,resolve_ordered_list_marker,read_lines_for_list_item,skip_line_comments,unshift_lines,fold_first,text?,is_sibling_list_item?,concat,find,casecmp,sectname=,special=,numbered=,numbered,lineno,peek_lines,setext_section_title?,abs,cursor_at_prev_line,process_attribute_entries,next_line_empty?,apply_header_subs,rstrip,each_with_index,compact,to_h,squeeze,to_a,parse_style_attribute,process_attribute_entry,skip_comment_lines,store_attribute,sanitize_attribute_name,set_attribute,save_to,delete_attribute,ord,int_to_roman,resolve_list_marker,parse_colspecs,create_columns,has_header_option=,format,starts_with_delimiter?,close_open_cell,parse_cellspec,delimiter,match_delimiter,pre_match,post_match,buffer_has_unclosed_quotes?,skip_past_delimiter,buffer=,buffer,skip_past_escaped_delimiter,keep_cell_open,push_cellspec,close_cell,cell_open?,columns,assign_column_widths,partition_header_footer,upto,partition,shorthand_property_syntax,each_char,yield_buffered_attribute,any?,*,each_byte,%');
32208  return (function($base, $parent_nesting) {
32209    var self = $module($base, 'Asciidoctor');
32210
32211    var $nesting = [self].concat($parent_nesting);
32212
32213    return (function($base, $super, $parent_nesting) {
32214      var self = $klass($base, $super, 'Parser');
32215
32216      var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
32217
32218      
32219      self.$include($$('Logging'));
32220      $const_set($nesting[0], 'BlockMatchData', $$('Struct').$new("context", "masq", "tip", "terminator"));
32221      $const_set($nesting[0], 'TAB', "\t");
32222      $const_set($nesting[0], 'TabIndentRx', /^\t+/);
32223      $const_set($nesting[0], 'StartOfBlockProc', $send(self, 'proc', [], function $Parser$1(l){var self = $Parser$1.$$s == null ? this : $Parser$1.$$s, $ret_or_1 = nil, $ret_or_2 = nil;
32224
32225        
32226        if (l == null) l = nil;
32227        if ($truthy(($ret_or_1 = ($truthy(($ret_or_2 = l['$start_with?']("["))) ? ($$('BlockAttributeLineRx')['$match?'](l)) : ($ret_or_2))))) {
32228          return $ret_or_1
32229        } else {
32230          
32231          return self['$is_delimited_block?'](l);
32232        };}, {$$s: self}));
32233      $const_set($nesting[0], 'StartOfListProc', $send(self, 'proc', [], function $Parser$2(l){
32234        
32235        if (l == null) l = nil;
32236        return $$('AnyListRx')['$match?'](l);}));
32237      $const_set($nesting[0], 'StartOfBlockOrListProc', $send(self, 'proc', [], function $Parser$3(l){var self = $Parser$3.$$s == null ? this : $Parser$3.$$s, $ret_or_1 = nil, $ret_or_2 = nil, $ret_or_3 = nil;
32238
32239        
32240        if (l == null) l = nil;
32241        if ($truthy(($ret_or_1 = ($truthy(($ret_or_2 = self['$is_delimited_block?'](l))) ? ($ret_or_2) : (($truthy(($ret_or_3 = l['$start_with?']("["))) ? ($$('BlockAttributeLineRx')['$match?'](l)) : ($ret_or_3))))))) {
32242          return $ret_or_1
32243        } else {
32244          
32245          return $$('AnyListRx')['$match?'](l);
32246        };}, {$$s: self}));
32247      $const_set($nesting[0], 'NoOp', nil);
32248      $const_set($nesting[0], 'AuthorKeys', ["author", "authorinitials", "firstname", "middlename", "lastname", "email"]);
32249      $const_set($nesting[0], 'TableCellHorzAlignments', $hash2(["<", ">", "^"], {"<": "left", ">": "right", "^": "center"}));
32250      $const_set($nesting[0], 'TableCellVertAlignments', $hash2(["<", ">", "^"], {"<": "top", ">": "bottom", "^": "middle"}));
32251      $const_set($nesting[0], 'TableCellStyles', $hash2(["d", "s", "e", "m", "h", "l", "a"], {"d": "none", "s": "strong", "e": "emphasis", "m": "monospaced", "h": "header", "l": "literal", "a": "asciidoc"}));
32252      self.$private_class_method("new");
32253      $defs(self, '$parse', function $$parse(reader, document, options) {
32254        var $a, $b, self = this, block_attributes = nil, header_only = nil, new_section = nil;
32255
32256        
32257        if (options == null) options = $hash2([], {});
32258        block_attributes = self.$parse_document_header(reader, document, (header_only = options['$[]']("header_only")));
32259        if (!$truthy(header_only)) {
32260          while ($truthy(reader['$has_more_lines?']())) {
32261          
32262            $b = self.$next_section(reader, document, block_attributes), $a = $to_ary($b), (new_section = ($a[0] == null ? nil : $a[0])), (block_attributes = ($a[1] == null ? nil : $a[1])), $b;
32263            if ($truthy(new_section)) {
32264              
32265              document.$assign_numeral(new_section);
32266              document.$blocks()['$<<'](new_section);
32267            };
32268          }
32269        };
32270        return document;
32271      }, -3);
32272      $defs(self, '$parse_document_header', function $$parse_document_header(reader, document, header_only) {
32273        var $a, $b, $c, self = this, block_attrs = nil, doc_attrs = nil, implicit_doctitle = nil, val = nil, doctitle_attr_val = nil, source_location = nil, _ = nil, l0_section_title = nil, atx = nil, separator = nil, doc_id = nil, role = nil, reftext = nil, modified_attrs = nil, author = nil, author_metadata = nil;
32274
32275        
32276        if (header_only == null) header_only = false;
32277        block_attrs = ($truthy(reader.$skip_blank_lines()) ? (self.$parse_block_metadata_lines(reader, document)) : ($hash2([], {})));
32278        doc_attrs = document.$attributes();
32279        if (($truthy((implicit_doctitle = self['$is_next_line_doctitle?'](reader, block_attrs, doc_attrs['$[]']("leveloffset")))) && ($truthy(block_attrs['$[]']("title"))))) {
32280          
32281          doc_attrs['$[]=']("authorcount", 0);
32282          return document.$finalize_header(block_attrs, false);
32283        };
32284        if (!$truthy((val = doc_attrs['$[]']("doctitle"))['$nil_or_empty?']())) {
32285          document['$title=']((doctitle_attr_val = val))
32286        };
32287        if ($truthy(implicit_doctitle)) {
32288          
32289          if ($truthy(document.$sourcemap())) {
32290            source_location = reader.$cursor()
32291          };
32292          $b = self.$parse_section_title(reader, document), $a = $to_ary($b), ($c = [($a[0] == null ? nil : $a[0])], $send(document, 'id=', $c), $c[$c.length - 1]), (_ = ($a[1] == null ? nil : $a[1])), (l0_section_title = ($a[2] == null ? nil : $a[2])), (_ = ($a[3] == null ? nil : $a[3])), (atx = ($a[4] == null ? nil : $a[4])), $b;
32293          if ($truthy(doctitle_attr_val)) {
32294            l0_section_title = nil
32295          } else {
32296            
32297            document['$title='](l0_section_title);
32298            if ($truthy(($a = ["doctitle", (doctitle_attr_val = document.$sub_specialchars(l0_section_title))], $send(doc_attrs, '[]=', $a), $a[$a.length - 1])['$include?']($$('ATTR_REF_HEAD')))) {
32299              doc_attrs['$[]=']("doctitle", (doctitle_attr_val = document.$sub_attributes(doctitle_attr_val, $hash2(["attribute_missing"], {"attribute_missing": "skip"}))))
32300            };
32301          };
32302          if ($truthy(source_location)) {
32303            document.$header()['$source_location='](source_location)
32304          };
32305          if (!($truthy(atx) || ($truthy(document['$attribute_locked?']("compat-mode"))))) {
32306            doc_attrs['$[]=']("compat-mode", "")
32307          };
32308          if ($truthy((separator = block_attrs['$[]']("separator")))) {
32309            if (!$truthy(document['$attribute_locked?']("title-separator"))) {
32310              doc_attrs['$[]=']("title-separator", separator)
32311            }
32312          };
32313          if ($truthy((doc_id = block_attrs['$[]']("id")))) {
32314            document['$id='](doc_id)
32315          } else {
32316            doc_id = document.$id()
32317          };
32318          if ($truthy((role = block_attrs['$[]']("role")))) {
32319            doc_attrs['$[]=']("role", role)
32320          };
32321          if ($truthy((reftext = block_attrs['$[]']("reftext")))) {
32322            doc_attrs['$[]=']("reftext", reftext)
32323          };
32324          block_attrs.$clear();
32325          (modified_attrs = document.$instance_variable_get("@attributes_modified")).$delete("doctitle");
32326          self.$parse_header_metadata(reader, document, nil);
32327          if ($truthy(modified_attrs['$include?']("doctitle"))) {
32328            if (($truthy((val = doc_attrs['$[]']("doctitle"))['$nil_or_empty?']()) || ($eqeq(val, doctitle_attr_val)))) {
32329              doc_attrs['$[]=']("doctitle", doctitle_attr_val)
32330            } else {
32331              document['$title='](val)
32332            }
32333          } else if ($not(l0_section_title)) {
32334            modified_attrs['$<<']("doctitle")
32335          };
32336          if ($truthy(doc_id)) {
32337            document.$register("refs", [doc_id, document])
32338          };
32339        } else if ($truthy((author = doc_attrs['$[]']("author")))) {
32340          
32341          author_metadata = self.$process_authors(author, true, false);
32342          if ($truthy(doc_attrs['$[]']("authorinitials"))) {
32343            author_metadata.$delete("authorinitials")
32344          };
32345          doc_attrs.$update(author_metadata);
32346        } else if ($truthy((author = doc_attrs['$[]']("authors")))) {
32347          
32348          author_metadata = self.$process_authors(author, true);
32349          doc_attrs.$update(author_metadata);
32350        } else {
32351          doc_attrs['$[]=']("authorcount", 0)
32352        };
32353        if ($eqeq(document.$doctype(), "manpage")) {
32354          self.$parse_manpage_header(reader, document, block_attrs, header_only)
32355        };
32356        return document.$finalize_header(block_attrs);
32357      }, -3);
32358      $defs(self, '$parse_manpage_header', function $$parse_manpage_header(reader, document, block_attributes, header_only) {
32359        var $a, self = this, doc_attrs = nil, manvolnum = nil, mantitle = nil, $ret_or_1 = nil, $ret_or_2 = nil, manname = nil, name_section_level = nil, name_section = nil, name_section_buffer = nil, mannames = nil, manpurpose = nil, error_msg = nil;
32360
32361        
32362        if (header_only == null) header_only = false;
32363        if ($truthy($$('ManpageTitleVolnumRx')['$=~']((doc_attrs = document.$attributes())['$[]']("doctitle")))) {
32364          
32365          doc_attrs['$[]=']("manvolnum", (manvolnum = (($a = $gvars['~']) === nil ? nil : $a['$[]'](2))));
32366          doc_attrs['$[]=']("mantitle", ($truthy((mantitle = (($a = $gvars['~']) === nil ? nil : $a['$[]'](1)))['$include?']($$('ATTR_REF_HEAD'))) ? (document.$sub_attributes(mantitle)) : (mantitle)).$downcase());
32367        } else {
32368          
32369          self.$logger().$error(self.$message_with_context("non-conforming manpage title", $hash2(["source_location"], {"source_location": reader.$cursor_at_line(1)})));
32370          doc_attrs['$[]=']("mantitle", ($truthy(($ret_or_1 = ($truthy(($ret_or_2 = doc_attrs['$[]']("doctitle"))) ? ($ret_or_2) : (doc_attrs['$[]']("docname"))))) ? ($ret_or_1) : ("command")));
32371          doc_attrs['$[]=']("manvolnum", (manvolnum = "1"));
32372        };
32373        if (($truthy((manname = doc_attrs['$[]']("manname"))) && ($truthy(doc_attrs['$[]']("manpurpose"))))) {
32374          
32375          if ($truthy(($ret_or_1 = doc_attrs['$[]']("manname-title")))) {
32376            $ret_or_1
32377          } else {
32378            doc_attrs['$[]=']("manname-title", "Name")
32379          };
32380          doc_attrs['$[]=']("mannames", [manname]);
32381          if ($eqeq(document.$backend(), "manpage")) {
32382            
32383            doc_attrs['$[]=']("docname", manname);
32384            doc_attrs['$[]=']("outfilesuffix", "." + (manvolnum));
32385          };
32386        } else if (!$truthy(header_only)) {
32387          
32388          reader.$skip_blank_lines();
32389          reader.$save();
32390          block_attributes.$update(self.$parse_block_metadata_lines(reader, document));
32391          if ($truthy((name_section_level = self['$is_next_line_section?'](reader, $hash2([], {}))))) {
32392            if ($eqeq(name_section_level, 1)) {
32393              
32394              name_section = self.$initialize_section(reader, document, $hash2([], {}));
32395              name_section_buffer = $send(reader.$read_lines_until($hash2(["break_on_blank_lines", "skip_line_comments"], {"break_on_blank_lines": true, "skip_line_comments": true})), 'map', [], function $$4(l){
32396                
32397                if (l == null) l = nil;
32398                return l.$lstrip();}).$join(" ");
32399              if ($truthy($$('ManpageNamePurposeRx')['$=~'](name_section_buffer))) {
32400                
32401                if ($truthy((manname = (($a = $gvars['~']) === nil ? nil : $a['$[]'](1)))['$include?']($$('ATTR_REF_HEAD')))) {
32402                  manname = document.$sub_attributes(manname)
32403                };
32404                if ($truthy(manname['$include?'](","))) {
32405                  manname = (mannames = $send(manname.$split(","), 'map', [], function $$5(n){
32406                    
32407                    if (n == null) n = nil;
32408                    return n.$lstrip();}))['$[]'](0)
32409                } else {
32410                  mannames = [manname]
32411                };
32412                if ($truthy((manpurpose = (($a = $gvars['~']) === nil ? nil : $a['$[]'](2)))['$include?']($$('ATTR_REF_HEAD')))) {
32413                  manpurpose = document.$sub_attributes(manpurpose)
32414                };
32415                if ($truthy(($ret_or_1 = doc_attrs['$[]']("manname-title")))) {
32416                  $ret_or_1
32417                } else {
32418                  doc_attrs['$[]=']("manname-title", name_section.$title())
32419                };
32420                if ($truthy(name_section.$id())) {
32421                  doc_attrs['$[]=']("manname-id", name_section.$id())
32422                };
32423                doc_attrs['$[]=']("manname", manname);
32424                doc_attrs['$[]=']("mannames", mannames);
32425                doc_attrs['$[]=']("manpurpose", manpurpose);
32426                if ($eqeq(document.$backend(), "manpage")) {
32427                  
32428                  doc_attrs['$[]=']("docname", manname);
32429                  doc_attrs['$[]=']("outfilesuffix", "." + (manvolnum));
32430                };
32431              } else {
32432                error_msg = "non-conforming name section body"
32433              };
32434            } else {
32435              error_msg = "name section must be at level 1"
32436            }
32437          } else {
32438            error_msg = "name section expected"
32439          };
32440          if ($truthy(error_msg)) {
32441            
32442            reader.$restore_save();
32443            self.$logger().$error(self.$message_with_context(error_msg, $hash2(["source_location"], {"source_location": reader.$cursor()})));
32444            doc_attrs['$[]=']("manname", (manname = ($truthy(($ret_or_1 = doc_attrs['$[]']("docname"))) ? ($ret_or_1) : ("command"))));
32445            doc_attrs['$[]=']("mannames", [manname]);
32446            if ($eqeq(document.$backend(), "manpage")) {
32447              
32448              doc_attrs['$[]=']("docname", manname);
32449              doc_attrs['$[]=']("outfilesuffix", "." + (manvolnum));
32450            };
32451          } else {
32452            reader.$discard_save()
32453          };
32454        };
32455        return nil;
32456      }, -4);
32457      $defs(self, '$next_section', function $$next_section(reader, parent, attributes) {
32458        var $a, $b, self = this, preamble = nil, intro = nil, part = nil, has_header = nil, book = nil, document = nil, section = nil, current_level = nil, expected_next_level = nil, expected_next_level_alt = nil, title = nil, sectname = nil, next_level = nil, expected_condition = nil, new_section = nil, block_cursor = nil, new_block = nil, $ret_or_1 = nil, first_block = nil, child_block = nil;
32459
32460        
32461        if (attributes == null) attributes = $hash2([], {});
32462        preamble = (intro = (part = false));
32463        if ((($eqeq(parent.$context(), "document") && ($truthy(parent.$blocks()['$empty?']()))) && ((($truthy((has_header = parent['$header?']())) || ($truthy(attributes.$delete("invalid-header")))) || ($not(self['$is_next_line_section?'](reader, attributes))))))) {
32464          
32465          book = (document = parent).$doctype()['$==']("book");
32466          if (($truthy(has_header) || (($truthy(book) && ($neqeq(attributes['$[]'](1), "abstract")))))) {
32467            
32468            preamble = (intro = $$('Block').$new(parent, "preamble", $hash2(["content_model"], {"content_model": "compound"})));
32469            if (($truthy(book) && ($truthy(parent['$attr?']("preface-title"))))) {
32470              preamble['$title='](parent.$attr("preface-title"))
32471            };
32472            parent.$blocks()['$<<'](preamble);
32473          };
32474          section = parent;
32475          current_level = 0;
32476          if ($truthy(parent.$attributes()['$key?']("fragment"))) {
32477            expected_next_level = -1
32478          } else if ($truthy(book)) {
32479            $a = [1, 0], (expected_next_level = $a[0]), (expected_next_level_alt = $a[1]), $a
32480          } else {
32481            expected_next_level = 1
32482          };
32483        } else {
32484          
32485          book = (document = parent.$document()).$doctype()['$==']("book");
32486          section = self.$initialize_section(reader, parent, attributes);
32487          attributes = ($truthy((title = attributes['$[]']("title"))) ? ($hash2(["title"], {"title": title})) : ($hash2([], {})));
32488          expected_next_level = $rb_plus((current_level = section.$level()), 1);
32489          if ($eqeq(current_level, 0)) {
32490            part = book
32491          } else if (($eqeq(current_level, 1) && ($truthy(section.$special())))) {
32492            if (!(($eqeq((sectname = section.$sectname()), "appendix") || ($eqeq(sectname, "preface"))) || ($eqeq(sectname, "abstract")))) {
32493              expected_next_level = nil
32494            }
32495          };
32496        };
32497        reader.$skip_blank_lines();
32498        while ($truthy(reader['$has_more_lines?']())) {
32499        
32500          self.$parse_block_metadata_lines(reader, document, attributes);
32501          if ($truthy((next_level = self['$is_next_line_section?'](reader, attributes)))) {
32502            
32503            if ($truthy(document['$attr?']("leveloffset"))) {
32504              
32505              next_level = $rb_plus(next_level, document.$attr("leveloffset").$to_i());
32506              if ($truthy($rb_lt(next_level, 0))) {
32507                next_level = 0
32508              };
32509            };
32510            if ($truthy($rb_gt(next_level, current_level))) {
32511              
32512              if ($truthy(expected_next_level)) {
32513                if (!(($eqeq(next_level, expected_next_level) || (($truthy(expected_next_level_alt) && ($eqeq(next_level, expected_next_level_alt))))) || ($truthy($rb_lt(expected_next_level, 0))))) {
32514                  
32515                  expected_condition = ($truthy(expected_next_level_alt) ? ("expected levels " + (expected_next_level_alt) + " or " + (expected_next_level)) : ("expected level " + (expected_next_level)));
32516                  self.$logger().$warn(self.$message_with_context("section title out of sequence: " + (expected_condition) + ", got level " + (next_level), $hash2(["source_location"], {"source_location": reader.$cursor()})));
32517                }
32518              } else {
32519                self.$logger().$error(self.$message_with_context("" + (sectname) + " sections do not support nested sections", $hash2(["source_location"], {"source_location": reader.$cursor()})))
32520              };
32521              $b = self.$next_section(reader, section, attributes), $a = $to_ary($b), (new_section = ($a[0] == null ? nil : $a[0])), (attributes = ($a[1] == null ? nil : $a[1])), $b;
32522              section.$assign_numeral(new_section);
32523              section.$blocks()['$<<'](new_section);
32524            } else if (($eqeq(next_level, 0) && ($eqeq(section, document)))) {
32525              
32526              if (!$truthy(book)) {
32527                self.$logger().$error(self.$message_with_context("level 0 sections can only be used when doctype is book", $hash2(["source_location"], {"source_location": reader.$cursor()})))
32528              };
32529              $b = self.$next_section(reader, section, attributes), $a = $to_ary($b), (new_section = ($a[0] == null ? nil : $a[0])), (attributes = ($a[1] == null ? nil : $a[1])), $b;
32530              section.$assign_numeral(new_section);
32531              section.$blocks()['$<<'](new_section);
32532            } else {
32533              break
32534            };
32535          } else {
32536            
32537            block_cursor = reader.$cursor();
32538            if ($truthy((new_block = self.$next_block(reader, ($truthy(($ret_or_1 = intro)) ? ($ret_or_1) : (section)), attributes, $hash2(["parse_metadata"], {"parse_metadata": false}))))) {
32539              
32540              if ($truthy(part)) {
32541                if ($not(section['$blocks?']())) {
32542                  if ($neqeq(new_block.$style(), "partintro")) {
32543                    if (($eqeq(new_block.$style(), "open") && ($eqeq(new_block.$context(), "open")))) {
32544                      new_block['$style=']("partintro")
32545                    } else {
32546                      
32547                      new_block['$parent=']((intro = $$('Block').$new(section, "open", $hash2(["content_model"], {"content_model": "compound"}))));
32548                      intro['$style=']("partintro");
32549                      section.$blocks()['$<<'](intro);
32550                    }
32551                  } else if ($eqeq(new_block.$content_model(), "simple")) {
32552                    
32553                    new_block['$content_model=']("compound");
32554                    new_block['$<<']($$('Block').$new(new_block, "paragraph", $hash2(["source", "subs"], {"source": new_block.$lines(), "subs": new_block.$subs()})));
32555                    new_block.$lines().$clear();
32556                    new_block.$subs().$clear();
32557                  }
32558                } else if ($eqeq(section.$blocks().$size(), 1)) {
32559                  
32560                  first_block = section.$blocks()['$[]'](0);
32561                  if (($not(intro) && ($eqeq(first_block.$content_model(), "compound")))) {
32562                    self.$logger().$error(self.$message_with_context("illegal block content outside of partintro block", $hash2(["source_location"], {"source_location": block_cursor})))
32563                  } else if ($neqeq(first_block.$content_model(), "compound")) {
32564                    
32565                    new_block['$parent=']((intro = $$('Block').$new(section, "open", $hash2(["content_model"], {"content_model": "compound"}))));
32566                    if ($eqeq(first_block.$style(), ($a = ["partintro"], $send(intro, 'style=', $a), $a[$a.length - 1]))) {
32567                      
32568                      first_block['$context=']("paragraph");
32569                      first_block['$style='](nil);
32570                    };
32571                    section.$blocks().$shift();
32572                    intro['$<<'](first_block);
32573                    section.$blocks()['$<<'](intro);
32574                  };
32575                }
32576              };
32577              ($truthy(($ret_or_1 = intro)) ? ($ret_or_1) : (section)).$blocks()['$<<'](new_block);
32578              attributes.$clear();
32579            };
32580          };
32581          if ($truthy(($ret_or_1 = reader.$skip_blank_lines()))) {
32582            $ret_or_1
32583          } else {
32584            break
32585          };
32586        };
32587        if ($truthy(part)) {
32588          if (!($truthy(section['$blocks?']()) && ($eqeq(section.$blocks()['$[]'](-1).$context(), "section")))) {
32589            self.$logger().$error(self.$message_with_context("invalid part, must have at least one section (e.g., chapter, appendix, etc.)", $hash2(["source_location"], {"source_location": reader.$cursor()})))
32590          }
32591        } else if ($truthy(preamble)) {
32592          if ($truthy(preamble['$blocks?']())) {
32593            if ((($truthy(book) || ($truthy(document.$blocks()['$[]'](1)))) || ($not($$('Compliance').$unwrap_standalone_preamble())))) {
32594              if ($truthy(document.$sourcemap())) {
32595                preamble['$source_location='](preamble.$blocks()['$[]'](0).$source_location())
32596              }
32597            } else {
32598              
32599              document.$blocks().$shift();
32600              while ($truthy((child_block = preamble.$blocks().$shift()))) {
32601              document['$<<'](child_block)
32602              };
32603            }
32604          } else {
32605            document.$blocks().$shift()
32606          }
32607        };
32608        return [($eqeq(section, parent) ? (nil) : (section)), attributes.$merge()];
32609      }, -3);
32610      $defs(self, '$next_block', function $$next_block(reader, parent, attributes, options) {
32611        var $a, $b, self = this, skipped = nil, text_only = nil, document = nil, $ret_or_1 = nil, extensions = nil, block_extensions = nil, block_macro_extensions = nil, this_line = nil, doc_attrs = nil, style = nil, block = nil, block_context = nil, cloaked_context = nil, terminator = nil, delimited_block = nil, indented = nil, md_syntax = nil, ch0 = nil, layout_break_chars = nil, ll = nil, blk_ctx = nil, target = nil, blk_attrs = nil, posattrs = nil, expanded_target = nil, $ret_or_2 = nil, scaledwidth = nil, block_title = nil, extension = nil, report_unknown_block_macro = nil, content = nil, ext_config = nil, default_attrs = nil, float_id = nil, float_reftext = nil, float_level = nil, lines = nil, content_adjacent = nil, admonition_name = nil, credit_line = nil, attribution = nil, citetitle = nil, language = nil, comma_idx = nil, block_cursor = nil, block_reader = nil, content_model = nil, positional_attrs = nil, block_id = nil;
32612        if ($gvars["~"] == null) $gvars["~"] = nil;
32613
32614        
32615        if (attributes == null) attributes = $hash2([], {});
32616        if (options == null) options = $hash2([], {});
32617        if (!$truthy((skipped = reader.$skip_blank_lines()))) {
32618          return nil
32619        };
32620        if (($truthy((text_only = options['$[]']("text_only"))) && ($truthy($rb_gt(skipped, 0))))) {
32621          
32622          options.$delete("text_only");
32623          text_only = nil;
32624        };
32625        document = parent.$document();
32626        if ($truthy(options.$fetch("parse_metadata", true))) {
32627          while ($truthy(self.$parse_block_metadata_line(reader, document, attributes, options))) {
32628          
32629            reader.$shift();
32630            if ($truthy(($ret_or_1 = reader.$skip_blank_lines()))) {
32631              $ret_or_1
32632            } else {
32633              return nil
32634            };
32635          }
32636        };
32637        if ($truthy((extensions = document.$extensions()))) {
32638          $a = [extensions['$blocks?'](), extensions['$block_macros?']()], (block_extensions = $a[0]), (block_macro_extensions = $a[1]), $a
32639        };
32640        reader.$mark();
32641        $a = [reader.$read_line(), document.$attributes(), attributes['$[]'](1)], (this_line = $a[0]), (doc_attrs = $a[1]), (style = $a[2]), $a;
32642        block = (block_context = (cloaked_context = (terminator = nil)));
32643        if ($truthy((delimited_block = self['$is_delimited_block?'](this_line, true)))) {
32644          
32645          block_context = (cloaked_context = delimited_block.$context());
32646          terminator = delimited_block.$terminator();
32647          if ($truthy(style)) {
32648            if (!$eqeq(style, block_context.$to_s())) {
32649              if ($truthy(delimited_block.$masq()['$include?'](style))) {
32650                block_context = style.$to_sym()
32651              } else if (($truthy(delimited_block.$masq()['$include?']("admonition")) && ($truthy($$('ADMONITION_STYLES')['$include?'](style))))) {
32652                block_context = "admonition"
32653              } else if (($truthy(block_extensions) && ($truthy(extensions['$registered_for_block?'](style, block_context))))) {
32654                block_context = style.$to_sym()
32655              } else {
32656                
32657                if ($truthy(self.$logger()['$debug?']())) {
32658                  self.$logger().$debug(self.$message_with_context("unknown style for " + (block_context) + " block: " + (style), $hash2(["source_location"], {"source_location": reader.$cursor_at_mark()})))
32659                };
32660                style = block_context.$to_s();
32661              }
32662            }
32663          } else {
32664            style = ($a = ["style", block_context.$to_s()], $send(attributes, '[]=', $a), $a[$a.length - 1])
32665          };
32666        };
32667        if (!$truthy(delimited_block)) {
32668          while ($truthy(true)) {
32669          
32670            if ((($truthy(style) && ($truthy($$('Compliance').$strict_verbatim_paragraphs()))) && ($truthy($$('VERBATIM_STYLES')['$include?'](style))))) {
32671              
32672              block_context = style.$to_sym();
32673              reader.$unshift_line(this_line);
32674              break;
32675            };
32676            if ($truthy(text_only)) {
32677              indented = this_line['$start_with?'](" ", $$('TAB'))
32678            } else {
32679              
32680              md_syntax = $$('Compliance').$markdown_syntax();
32681              if ($truthy(this_line['$start_with?'](" "))) {
32682                
32683                $a = [true, " "], (indented = $a[0]), (ch0 = $a[1]), $a;
32684                if ((($truthy(md_syntax) && ($truthy($send(this_line.$lstrip(), 'start_with?', $to_a($$('MARKDOWN_THEMATIC_BREAK_CHARS').$keys()))))) && ($truthy($$('MarkdownThematicBreakRx')['$match?'](this_line))))) {
32685                  
32686                  block = $$('Block').$new(parent, "thematic_break", $hash2(["content_model"], {"content_model": "empty"}));
32687                  break;
32688                };
32689              } else if ($truthy(this_line['$start_with?']($$('TAB')))) {
32690                $a = [true, $$('TAB')], (indented = $a[0]), (ch0 = $a[1]), $a
32691              } else {
32692                
32693                $a = [false, this_line.$chr()], (indented = $a[0]), (ch0 = $a[1]), $a;
32694                layout_break_chars = ($truthy(md_syntax) ? ($$('HYBRID_LAYOUT_BREAK_CHARS')) : ($$('LAYOUT_BREAK_CHARS')));
32695                if (($truthy(layout_break_chars['$key?'](ch0)) && ($truthy(($truthy(md_syntax) ? ($$('ExtLayoutBreakRx')['$match?'](this_line)) : ($truthy(($ret_or_1 = self['$uniform?'](this_line, ch0, (ll = this_line.$length())))) ? ($rb_gt(ll, 2)) : ($ret_or_1))))))) {
32696                  
32697                  block = $$('Block').$new(parent, layout_break_chars['$[]'](ch0), $hash2(["content_model"], {"content_model": "empty"}));
32698                  break;
32699                } else if (($truthy(this_line['$end_with?']("]")) && ($truthy(this_line['$include?']("::"))))) {
32700                  if ((($eqeq(ch0, "i") || ($truthy(this_line['$start_with?']("video:", "audio:")))) && ($truthy($$('BlockMediaMacroRx')['$=~'](this_line))))) {
32701                    
32702                    $a = [(($b = $gvars['~']) === nil ? nil : $b['$[]'](1)).$to_sym(), (($b = $gvars['~']) === nil ? nil : $b['$[]'](2)), (($b = $gvars['~']) === nil ? nil : $b['$[]'](3))], (blk_ctx = $a[0]), (target = $a[1]), (blk_attrs = $a[2]), $a;
32703                    block = $$('Block').$new(parent, blk_ctx, $hash2(["content_model"], {"content_model": "empty"}));
32704                    if ($truthy(blk_attrs)) {
32705                      
32706                      
32707                      switch (blk_ctx) {
32708                        case "video":
32709                          posattrs = ["poster", "width", "height"]
32710                          break;
32711                        case "audio":
32712                          posattrs = []
32713                          break;
32714                        default:
32715                          posattrs = ["alt", "width", "height"]
32716                      };
32717                      block.$parse_attributes(blk_attrs, posattrs, $hash2(["sub_input", "into"], {"sub_input": true, "into": attributes}));
32718                    };
32719                    if ($truthy(attributes['$key?']("style"))) {
32720                      attributes.$delete("style")
32721                    };
32722                    if ($truthy(target['$include?']($$('ATTR_REF_HEAD')))) {
32723                      if ((($truthy((expanded_target = block.$sub_attributes(target))['$empty?']()) && ($eqeq(($truthy(($ret_or_1 = doc_attrs['$[]']("attribute-missing"))) ? ($ret_or_1) : ($$('Compliance').$attribute_missing())), "drop-line"))) && ($truthy(block.$sub_attributes($rb_plus(target, " "), $hash2(["attribute_missing", "drop_line_severity"], {"attribute_missing": "drop-line", "drop_line_severity": "ignore"}))['$empty?']())))) {
32724                        
32725                        attributes.$clear();
32726                        return nil;
32727                      } else {
32728                        target = expanded_target
32729                      }
32730                    };
32731                    if ($eqeq(blk_ctx, "image")) {
32732                      
32733                      document.$register("images", target);
32734                      attributes['$[]=']("imagesdir", doc_attrs['$[]']("imagesdir"));
32735                      if ($truthy(($ret_or_1 = attributes['$[]']("alt")))) {
32736                        $ret_or_1
32737                      } else {
32738                        attributes['$[]=']("alt", ($truthy(($ret_or_2 = style)) ? ($ret_or_2) : (($a = ["default-alt", $$('Helpers').$basename(target, true).$tr("_-", " ")], $send(attributes, '[]=', $a), $a[$a.length - 1]))))
32739                      };
32740                      if (!$truthy((scaledwidth = attributes.$delete("scaledwidth"))['$nil_or_empty?']())) {
32741                        attributes['$[]=']("scaledwidth", ($truthy($$('TrailingDigitsRx')['$match?'](scaledwidth)) ? ("" + (scaledwidth) + "%") : (scaledwidth)))
32742                      };
32743                      if ($truthy(attributes['$[]']("title"))) {
32744                        
32745                        block['$title=']((block_title = attributes.$delete("title")));
32746                        block.$assign_caption(attributes.$delete("caption"), "f
32746igure");
32747                      };
32748                    };
32749                    attributes['$[]=']("target", target);
32750                    break;
32751                  } else if ((($eqeq(ch0, "t") && ($truthy(this_line['$start_with?']("toc:")))) && ($truthy($$('BlockTocMacroRx')['$=~'](this_line))))) {
32752                    
32753                    block = $$('Block').$new(parent, "toc", $hash2(["content_model"], {"content_model": "empty"}));
32754                    if ($truthy((($a = $gvars['~']) === nil ? nil : $a['$[]'](1)))) {
32755                      block.$parse_attributes((($a = $gvars['~']) === nil ? nil : $a['$[]'](1)), [], $hash2(["into"], {"into": attributes}))
32756                    };
32757                    break;
32758                  } else if ($truthy(($truthy(block_macro_extensions) ? (($truthy(($ret_or_1 = ($truthy(($ret_or_2 = $$('CustomBlockMacroRx')['$=~'](this_line))) ? ((extension = extensions['$registered_for_block_macro?']((($a = $gvars['~']) === nil ? nil : $a['$[]'](1))))) : ($ret_or_2)))) ? ($ret_or_1) : ((report_unknown_block_macro = self.$logger()['$debug?']())))) : (($truthy(($ret_or_1 = self.$logger()['$debug?']())) ? ((report_unknown_block_macro = $$('CustomBlockMacroRx')['$=~'](this_line))) : ($ret_or_1)))))) {
32759                    if ($truthy(report_unknown_block_macro)) {
32760                      self.$logger().$debug(self.$message_with_context("unknown name for block macro: " + ((($a = $gvars['~']) === nil ? nil : $a['$[]'](1))), $hash2(["source_location"], {"source_location": reader.$cursor_at_mark()})))
32761                    } else {
32762                      
32763                      content = (($a = $gvars['~']) === nil ? nil : $a['$[]'](3));
32764                      if ($truthy((target = (($a = $gvars['~']) === nil ? nil : $a['$[]'](2)))['$include?']($$('ATTR_REF_HEAD')))) {
32765                        if ((($truthy((expanded_target = parent.$sub_attributes(target))['$empty?']()) && ($eqeq(($truthy(($ret_or_1 = doc_attrs['$[]']("attribute-missing"))) ? ($ret_or_1) : ($$('Compliance').$attribute_missing())), "drop-line"))) && ($truthy(parent.$sub_attributes($rb_plus(target, " "), $hash2(["attribute_missing", "drop_line_severity"], {"attribute_missing": "drop-line", "drop_line_severity": "ignore"}))['$empty?']())))) {
32766                          
32767                          attributes.$clear();
32768                          return nil;
32769                        } else {
32770                          target = expanded_target
32771                        }
32772                      };
32773                      if ($eqeq((ext_config = extension.$config())['$[]']("content_model"), "attributes")) {
32774                        if ($truthy(content)) {
32775                          document.$parse_attributes(content, ($truthy(($ret_or_1 = ($truthy(($ret_or_2 = ext_config['$[]']("positional_attrs"))) ? ($ret_or_2) : (ext_config['$[]']("pos_attrs"))))) ? ($ret_or_1) : ([])), $hash2(["sub_input", "into"], {"sub_input": true, "into": attributes}))
32776                        }
32777                      } else {
32778                        attributes['$[]=']("text", ($truthy(($ret_or_1 = content)) ? ($ret_or_1) : ("")))
32779                      };
32780                      if ($truthy((default_attrs = ext_config['$[]']("default_attrs")))) {
32781                        $send(attributes, 'update', [default_attrs], function $$6(_, old_v){
32782                          
32783                          if (_ == null) _ = nil;
32784                          if (old_v == null) old_v = nil;
32785                          return old_v;})
32786                      };
32787                      if (($truthy((block = extension.$process_method()['$[]'](parent, target, attributes))) && ($neqeq(block, parent)))) {
32788                        
32789                        attributes.$replace(block.$attributes());
32790                        break;
32791                      } else {
32792                        
32793                        attributes.$clear();
32794                        return nil;
32795                      };
32796                    }
32797                  }
32798                };
32799              };
32800            };
32801            if ((($not(indented) && ($eqeq((ch0 = ($truthy(($ret_or_1 = ch0)) ? ($ret_or_1) : (this_line.$chr()))), "<"))) && ($truthy($$('CalloutListRx')['$=~'](this_line))))) {
32802              
32803              reader.$unshift_line(this_line);
32804              block = self.$parse_callout_list(reader, $gvars["~"], parent, document.$callouts());
32805              attributes['$[]=']("style", "arabic");
32806              break;
32807            } else if ($truthy($$('UnorderedListRx')['$match?'](this_line))) {
32808              
32809              reader.$unshift_line(this_line);
32810              if ((($not(style) && ($eqeqeq($$('Section'), parent))) && ($eqeq(parent.$sectname(), "bibliography")))) {
32811                attributes['$[]=']("style", (style = "bibliography"))
32812              };
32813              block = self.$parse_list(reader, "ulist", parent, style);
32814              break;
32815            } else if ($truthy($$('OrderedListRx')['$match?'](this_line))) {
32816              
32817              reader.$unshift_line(this_line);
32818              block = self.$parse_list(reader, "olist", parent, style);
32819              if ($truthy(block.$style())) {
32820                attributes['$[]=']("style", block.$style())
32821              };
32822              break;
32823            } else if ((($truthy(this_line['$include?']("::")) || ($truthy(this_line['$include?'](";;")))) && ($truthy($$('DescriptionListRx')['$=~'](this_line))))) {
32824              
32825              reader.$unshift_line(this_line);
32826              block = self.$parse_description_list(reader, $gvars["~"], parent);
32827              break;
32828            } else if ((($eqeq(style, "float") || ($eqeq(style, "discrete"))) && ($truthy(($truthy($$('Compliance').$underline_style_section_titles()) ? (self['$is_section_title?'](this_line, reader.$peek_line())) : ($truthy(($ret_or_1 = indented['$!']())) ? (self['$atx_section_title?'](this_line)) : ($ret_or_1))))))) {
32829              
32830              reader.$unshift_line(this_line);
32831              $b = self.$parse_section_title(reader, document, attributes['$[]']("id")), $a = $to_ary($b), (float_id = ($a[0] == null ? nil : $a[0])), (float_reftext = ($a[1] == null ? nil : $a[1])), (block_title = ($a[2] == null ? nil : $a[2])), (float_level = ($a[3] == null ? nil : $a[3])), $b;
32832              if ($truthy(float_reftext)) {
32833                attributes['$[]=']("reftext", float_reftext)
32834              };
32835              block = $$('Block').$new(parent, "floating_title", $hash2(["content_model"], {"content_model": "empty"}));
32836              block['$title='](block_title);
32837              attributes.$delete("title");
32838              block['$id='](($truthy(($ret_or_1 = float_id)) ? ($ret_or_1) : (($truthy(doc_attrs['$key?']("sectids")) ? ($$('Section').$generate_id(block.$title(), document)) : (nil)))));
32839              block['$level='](float_level);
32840              break;
32841            } else if (($truthy(style) && ($neqeq(style, "normal")))) {
32842              if ($truthy($$('PARAGRAPH_STYLES')['$include?'](style))) {
32843                
32844                block_context = style.$to_sym();
32845                cloaked_context = "paragraph";
32846                reader.$unshift_line(this_line);
32847                break;
32848              } else if ($truthy($$('ADMONITION_STYLES')['$include?'](style))) {
32849                
32850                block_context = "admonition";
32851                cloaked_context = "paragraph";
32852                reader.$unshift_line(this_line);
32853                break;
32854              } else if (($truthy(block_extensions) && ($truthy(extensions['$registered_for_block?'](style, "paragraph"))))) {
32855                
32856                block_context = style.$to_sym();
32857                cloaked_context = "paragraph";
32858                reader.$unshift_line(this_line);
32859                break;
32860              } else {
32861                
32862                if ($truthy(self.$logger()['$debug?']())) {
32863                  self.$logger().$debug(self.$message_with_context("unknown style for paragraph: " + (style), $hash2(["source_location"], {"source_location": reader.$cursor_at_mark()})))
32864                };
32865                style = nil;
32866              }
32867            };
32868            reader.$unshift_line(this_line);
32869            if (($truthy(indented) && ($not(style)))) {
32870              
32871              lines = self.$read_paragraph_lines(reader, (content_adjacent = ($eqeq(skipped, 0) ? (options['$[]']("list_type")) : (nil))), $hash2(["skip_line_comments"], {"skip_line_comments": text_only}));
32872              self['$adjust_indentation!'](lines);
32873              if (($truthy(text_only) || ($eqeq(content_adjacent, "dlist")))) {
32874                block = $$('Block').$new(parent, "paragraph", $hash2(["content_model", "source", "attributes"], {"content_model": "simple", "source": lines, "attributes": attributes}))
32875              } else {
32876                block = $$('Block').$new(parent, "literal", $hash2(["content_model", "source", "attributes"], {"content_model": "verbatim", "source": lines, "attributes": attributes}))
32877              };
32878            } else {
32879              
32880              lines = self.$read_paragraph_lines(reader, ($truthy(($ret_or_1 = skipped['$=='](0))) ? (options['$[]']("list_type")) : ($ret_or_1)), $hash2(["skip_line_comments"], {"skip_line_comments": true}));
32881              if ($truthy(text_only)) {
32882                
32883                if (($truthy(indented) && ($eqeq(style, "normal")))) {
32884                  self['$adjust_indentation!'](lines)
32885                };
32886                block = $$('Block').$new(parent, "paragraph", $hash2(["content_model", "source", "attributes"], {"content_model": "simple", "source": lines, "attributes": attributes}));
32887              } else if ((($truthy($$('ADMONITION_STYLE_HEADS')['$include?'](ch0)) && ($truthy(this_line['$include?'](":")))) && ($truthy($$('AdmonitionParagraphRx')['$=~'](this_line))))) {
32888                
32889                lines['$[]='](0, (($a = $gvars['~']) === nil ? nil : $a.$post_match()));
32890                attributes['$[]=']("name", (admonition_name = ($a = ["style", (($b = $gvars['~']) === nil ? nil : $b['$[]'](1))], $send(attributes, '[]=', $a), $a[$a.length - 1]).$downcase()));
32891                attributes['$[]=']("textlabel", ($truthy(($ret_or_1 = attributes.$delete("caption"))) ? ($ret_or_1) : (doc_attrs['$[]']("" + (admonition_name) + "-caption"))));
32892                block = $$('Block').$new(parent, "admonition", $hash2(["content_model", "source", "attributes"], {"content_model": "simple", "source": lines, "attributes": attributes}));
32893              } else if ((($truthy(md_syntax) && ($eqeq(ch0, ">"))) && ($truthy(this_line['$start_with?']("> "))))) {
32894                
32895                $send(lines, 'map!', [], function $$7(line){
32896                  
32897                  if (line == null) line = nil;
32898                  if ($eqeq(line, ">")) {
32899                    
32900                    return line.$slice(1, line.$length());
32901                  } else {
32902                    
32903                    if ($truthy(line['$start_with?']("> "))) {
32904                      
32905                      return line.$slice(2, line.$length());
32906                    } else {
32907                      return line
32908                    };
32909                  };});
32910                if ($truthy(lines['$[]'](-1)['$start_with?']("-- "))) {
32911                  
32912                  credit_line = (credit_line = lines.$pop()).$slice(3, credit_line.$length());
32913                  if (!$truthy(lines['$empty?']())) {
32914                    while ($truthy(lines['$[]'](-1)['$empty?']())) {
32915                    lines.$pop()
32916                    }
32917                  };
32918                };
32919                attributes['$[]=']("style", "quote");
32920                block = self.$build_block("quote", "compound", false, parent, $$('Reader').$new(lines), attributes);
32921                if ($truthy(credit_line)) {
32922                  
32923                  $b = block.$apply_subs(credit_line).$split(", ", 2), $a = $to_ary($b), (attribution = ($a[0] == null ? nil : $a[0])), (citetitle = ($a[1] == null ? nil : $a[1])), $b;
32924                  if ($truthy(attribution)) {
32925                    attributes['$[]=']("attribution", attribution)
32926                  };
32927                  if ($truthy(citetitle)) {
32928                    attributes['$[]=']("citetitle", citetitle)
32929                  };
32930                };
32931              } else if (((($eqeq(ch0, "\"") && ($truthy($rb_gt(lines.$size(), 1)))) && ($truthy(lines['$[]'](-1)['$start_with?']("-- ")))) && ($truthy(lines['$[]'](-2)['$end_with?']("\""))))) {
32932                
32933                lines['$[]='](0, this_line.$slice(1, this_line.$length()));
32934                credit_line = (credit_line = lines.$pop()).$slice(3, credit_line.$length());
32935                while ($truthy(lines['$[]'](-1)['$empty?']())) {
32936                lines.$pop()
32937                };
32938                lines['$<<'](lines.$pop().$chop());
32939                attributes['$[]=']("style", "quote");
32940                block = $$('Block').$new(parent, "quote", $hash2(["content_model", "source", "attributes"], {"content_model": "simple", "source": lines, "attributes": attributes}));
32941                $b = block.$apply_subs(credit_line).$split(", ", 2), $a = $to_ary($b), (attribution = ($a[0] == null ? nil : $a[0])), (citetitle = ($a[1] == null ? nil : $a[1])), $b;
32942                if ($truthy(attribution)) {
32943                  attributes['$[]=']("attribution", attribution)
32944                };
32945                if ($truthy(citetitle)) {
32946                  attributes['$[]=']("citetitle", citetitle)
32947                };
32948              } else {
32949                
32950                if (($truthy(indented) && ($eqeq(style, "normal")))) {
32951                  self['$adjust_indentation!'](lines)
32952                };
32953                block = $$('Block').$new(parent, "paragraph", $hash2(["content_model", "source", "attributes"], {"content_model": "simple", "source": lines, "attributes": attributes}));
32954              };
32955              self.$catalog_inline_anchors(lines.$join($$('LF')), block, document, reader);
32956            };
32957            break;
32958          }
32959        };
32960        if (!$truthy(block)) {
32961          
32962          switch (block_context) {
32963            case "listing":
32964            case "source":
32965              
32966              if (($eqeq(block_context, "source") || (($not(attributes['$[]'](1)) && ($truthy((language = ($truthy(($ret_or_2 = attributes['$[]'](2))) ? ($ret_or_2) : (doc_attrs['$[]']("source-language")))))))))) {
32967                
32968                if ($truthy(language)) {
32969                  
32970                  attributes['$[]=']("style", "source");
32971                  attributes['$[]=']("language", language);
32972                  $$('AttributeList').$rekey(attributes, [nil, nil, "linenums"]);
32973                } else {
32974                  
32975                  $$('AttributeList').$rekey(attributes, [nil, "language", "linenums"]);
32976                  if (!$truthy(attributes['$key?']("language"))) {
32977                    if ($truthy(doc_attrs['$key?']("source-language"))) {
32978                      attributes['$[]=']("language", doc_attrs['$[]']("source-language"))
32979                    }
32980                  };
32981                };
32982                if (!$truthy(attributes['$key?']("linenums"))) {
32983                  if (($truthy(attributes['$[]']("linenums-option")) || ($truthy(doc_attrs['$[]']("source-linenums-option"))))) {
32984                    attributes['$[]=']("linenums", "")
32985                  }
32986                };
32987                if (!$truthy(attributes['$key?']("indent"))) {
32988                  if ($truthy(doc_attrs['$key?']("source-indent"))) {
32989                    attributes['$[]=']("indent", doc_attrs['$[]']("source-indent"))
32990                  }
32991                };
32992              };
32993              block = self.$build_block("listing", "verbatim", terminator, parent, reader, attributes);
32994              break;
32995            case "fenced_code":
32996              
32997              attributes['$[]=']("style", "source");
32998              if ($truthy($rb_gt((ll = this_line.$length()), 3))) {
32999                if ($truthy((comma_idx = (language = this_line.$slice(3, ll)).$index(",")))) {
33000                  if ($truthy($rb_gt(comma_idx, 0))) {
33001                    
33002                    language = language.$slice(0, comma_idx).$strip();
33003                    if ($truthy($rb_lt(comma_idx, $rb_minus(ll, 4)))) {
33004                      attributes['$[]=']("linenums", "")
33005                    };
33006                  } else if ($truthy($rb_gt(ll, 4))) {
33007                    attributes['$[]=']("linenums", "")
33008                  }
33009                } else {
33010                  language = language.$lstrip()
33011                }
33012              };
33013              if ($truthy(language['$nil_or_empty?']())) {
33014                if ($truthy(doc_attrs['$key?']("source-language"))) {
33015                  attributes['$[]=']("language", doc_attrs['$[]']("source-language"))
33016                }
33017              } else {
33018                attributes['$[]=']("language", language)
33019              };
33020              if (!$truthy(attributes['$key?']("linenums"))) {
33021                if (($truthy(attributes['$[]']("linenums-option")) || ($truthy(doc_attrs['$[]']("source-linenums-option"))))) {
33022                  attributes['$[]=']("linenums", "")
33023                }
33024              };
33025              if (!$truthy(attributes['$key?']("indent"))) {
33026                if ($truthy(doc_attrs['$key?']("source-indent"))) {
33027                  attributes['$[]=']("indent", doc_attrs['$[]']("source-indent"))
33028                }
33029              };
33030              terminator = terminator.$slice(0, 3);
33031              block = self.$build_block("listing", "verbatim", terminator, parent, reader, attributes);
33032              break;
33033            case "table":
33034              
33035              block_cursor = reader.$cursor();
33036              block_reader = $$('Reader').$new(reader.$read_lines_until($hash2(["terminator", "skip_line_comments", "context", "cursor"], {"terminator": terminator, "skip_line_comments": true, "context": "table", "cursor": "at_mark"})), block_cursor);
33037              if (!$truthy(terminator['$start_with?']("|", "!"))) {
33038                if ($truthy(($ret_or_2 = attributes['$[]']("format")))) {
33039                  $ret_or_2
33040                } else {
33041                  attributes['$[]=']("format", ($truthy(terminator['$start_with?'](",")) ? ("csv") 
33041: ("dsv")))
33042                }
33043              };
33044              block = self.$parse_table(block_reader, parent, attributes);
33045              break;
33046            case "sidebar":
33047              block = self.$build_block(block_context, "compound", terminator, parent, reader, attributes)
33048              break;
33049            case "admonition":
33050              
33051              attributes['$[]=']("name", (admonition_name = style.$downcase()));
33052              attributes['$[]=']("textlabel", ($truthy(($ret_or_2 = attributes.$delete("caption"))) ? ($ret_or_2) : (doc_attrs['$[]']("" + (admonition_name) + "-caption"))));
33053              block = self.$build_block(block_context, "compound", terminator, parent, reader, attributes);
33054              break;
33055            case "open":
33056            case "abstract":
33057            case "partintro":
33058              block = self.$build_block("open", "compound", terminator, parent, reader, attributes)
33059              break;
33060            case "literal":
33061              block = self.$build_block(block_context, "verbatim", terminator, parent, reader, attributes)
33062              break;
33063            case "example":
33064              
33065              if ($truthy(attributes['$[]']("collapsible-option"))) {
33066                attributes['$[]=']("caption", "")
33067              };
33068              block = self.$build_block(block_context, "compound", terminator, parent, reader, attributes);
33069              break;
33070            case "quote":
33071            case "verse":
33072              
33073              $$('AttributeList').$rekey(attributes, [nil, "attribution", "citetitle"]);
33074              block = self.$build_block(block_context, ($eqeq(block_context, "verse") ? ("verbatim") : ("compound")), terminator, parent, reader, attributes);
33075              break;
33076            case "stem":
33077            case "latexmath":
33078            case "asciimath":
33079              
33080              if ($eqeq(block_context, "stem")) {
33081                attributes['$[]=']("style", $$('STEM_TYPE_ALIASES')['$[]'](($truthy(($ret_or_2 = attributes['$[]'](2))) ? ($ret_or_2) : (doc_attrs['$[]']("stem")))))
33082              };
33083              block = self.$build_block("stem", "raw", terminator, parent, reader, attributes);
33084              break;
33085            case "pass":
33086              block = self.$build_block(block_context, "raw", terminator, parent, reader, attributes)
33087              break;
33088            case "comment":
33089              
33090              self.$build_block(block_context, "skip", terminator, parent, reader, attributes);
33091              attributes.$clear();
33092              return nil;
33093            default:
33094              if (($truthy(block_extensions) && ($truthy((extension = extensions['$registered_for_block?'](block_context, cloaked_context)))))) {
33095                
33096                if (!$eqeq((content_model = (ext_config = extension.$config())['$[]']("content_model")), "skip")) {
33097                  
33098                  if (!$truthy((positional_attrs = ($truthy(($ret_or_2 = ext_config['$[]']("positional_attrs"))) ? ($ret_or_2) : (ext_config['$[]']("pos_attrs"))))['$nil_or_empty?']())) {
33099                    $$('AttributeList').$rekey(attributes, $rb_plus([nil], positional_attrs))
33100                  };
33101                  if ($truthy((default_attrs = ext_config['$[]']("default_attrs")))) {
33102                    $send(default_attrs, 'each', [], function $$8(k, v){var $c;
33103
33104                      
33105                      if (k == null) k = nil;
33106                      if (v == null) v = nil;
33107                      if ($truthy(($ret_or_2 = attributes['$[]'](k)))) {
33108                        return $ret_or_2
33109                      } else {
33110                        return ($c = [k, v], $send(attributes, '[]=', $c), $c[$c.length - 1])
33111                      };})
33112                  };
33113                  attributes['$[]=']("cloaked-context", cloaked_context);
33114                };
33115                if (!$truthy((block = self.$build_block(block_context, content_model, terminator, parent, reader, attributes, $hash2(["extension"], {"extension": extension}))))) {
33116                  
33117                  attributes.$clear();
33118                  return nil;
33119                };
33120              } else {
33121                self.$raise("Unsupported block type " + (block_context) + " at " + (reader.$cursor()))
33122              }
33123          }
33124        };
33125        if ($truthy(document.$sourcemap())) {
33126          block['$source_location='](reader.$cursor_at_mark())
33127        };
33128        if ($truthy(attributes['$[]']("title"))) {
33129          
33130          block['$title=']((block_title = attributes.$delete("title")));
33131          if ($truthy($$('CAPTION_ATTRIBUTE_NAMES')['$[]'](block.$context()))) {
33132            block.$assign_caption(attributes.$delete("caption"))
33133          };
33134        };
33135        block['$style='](attributes['$[]']("style"));
33136        if ($truthy((block_id = ($truthy(($ret_or_1 = block.$id())) ? ($ret_or_1) : (($a = [attributes['$[]']("id")], $send(block, 'id=', $a), $a[$a.length - 1])))))) {
33137          
33138          if ($truthy(($truthy(block_title) ? (block_title['$include?']($$('ATTR_REF_HEAD'))) : (block['$title?']())))) {
33139            block.$title()
33140          };
33141          if (!$truthy(document.$register("refs", [block_id, block]))) {
33142            self.$logger().$warn(self.$message_with_context("id assigned to block already in use: " + (block_id), $hash2(["source_location"], {"source_location": reader.$cursor_at_mark()})))
33143          };
33144        };
33145        if (!$truthy(attributes['$empty?']())) {
33146          block.$update_attributes(attributes)
33147        };
33148        block.$commit_subs();
33149        if ($truthy(block['$sub?']("callouts"))) {
33150          if (!$truthy(self.$catalog_callouts(block.$source(), document))) {
33151            block.$remove_sub("callouts")
33152          }
33153        };
33154        return block;
33155      }, -3);
33156      $defs(self, '$read_paragraph_lines', function $$read_paragraph_lines(reader, break_at_list, opts) {
33157        var break_condition = nil;
33158
33159        
33160        if (opts == null) opts = $hash2([], {});
33161        opts['$[]=']("break_on_blank_lines", true);
33162        opts['$[]=']("break_on_list_continuation", true);
33163        opts['$[]=']("preserve_last_line", true);
33164        break_condition = ($truthy(break_at_list) ? (($truthy($$('Compliance').$block_terminates_paragraph()) ? ($$('StartOfBlockOrListProc')) : ($$('StartOfListProc')))) : (($truthy($$('Compliance').$block_terminates_paragraph()) ? ($$('StartOfBlockProc')) : ($$('NoOp')))));
33165        return $send(reader, 'read_lines_until', [opts], break_condition.$to_proc());
33166      }, -3);
33167      $defs(self, '$is_delimited_block?', function $Parser_is_delimited_block$ques$9(line, return_match_data) {
33168        var $a, $b, self = this, line_len = nil, tip = nil, tip_len = nil, context = nil, masq = nil;
33169
33170        
33171        if (return_match_data == null) return_match_data = nil;
33172        if (!($truthy($rb_gt((line_len = line.$length()), 1)) && ($truthy($$('DELIMITED_BLOCK_HEADS')['$[]'](line.$slice(0, 2)))))) {
33173          return nil
33174        };
33175        if ($eqeq(line_len, 2)) {
33176          
33177          tip = line;
33178          tip_len = 2;
33179        } else {
33180          
33181          if ($truthy($rb_lt(line_len, 5))) {
33182            
33183            tip = line;
33184            tip_len = line_len;
33185          } else {
33186            tip = line.$slice(0, (tip_len = 4))
33187          };
33188          if (($truthy($$('Compliance').$markdown_syntax()) && ($truthy(tip['$start_with?']("`"))))) {
33189            if ($eqeq(tip_len, 4)) {
33190              
33191              if (($eqeq(tip, "````") || ($neqeq((tip = tip.$chop()), "```")))) {
33192                return nil
33193              };
33194              line = tip;
33195              line_len = (tip_len = 3);
33196            } else if ($neqeq(tip, "```")) {
33197              return nil
33198            }
33199          } else if ($eqeq(tip_len, 3)) {
33200            return nil
33201          };
33202        };
33203        $b = $$('DELIMITED_BLOCKS')['$[]'](tip), $a = $to_ary($b), (context = ($a[0] == null ? nil : $a[0])), (masq = ($a[1] == null ? nil : $a[1])), $b;
33204        if (($truthy(context) && (($eqeq(line_len, tip_len) || ($truthy(self['$uniform?'](line.$slice(1, line_len), $$('DELIMITED_BLOCK_TAILS')['$[]'](tip), $rb_minus(line_len, 1)))))))) {
33205          if ($truthy(return_match_data)) {
33206            
33207            return $$('BlockMatchData').$new(context, masq, tip, line);
33208          } else {
33209            return true
33210          }
33211        } else {
33212          return nil
33213        };
33214      }, -2);
33215      $defs(self, '$build_block', function $$build_block(block_context, content_model, terminator, parent, reader, attributes, options) {
33216        var $a, self = this, skip_processing = nil, parse_as_content_model = nil, lines = nil, block_reader = nil, block_cursor = nil, tab_size = nil, $ret_or_2 = nil, indent = nil, extension = nil, block = nil, $ret_or_1 = nil;
33217
33218        
33219        if (options == null) options = $hash2([], {});
33220        
33221        switch (content_model) {
33222          case "skip":
33223            $a = [true, "simple"], (skip_processing = $a[0]), (parse_as_content_model = $a[1]), $a
33224            break;
33225          case "raw":
33226            $a = [false, "simple"], (skip_processing = $a[0]), (parse_as_content_model = $a[1]), $a
33227            break;
33228          default:
33229            $a = [false, content_model], (skip_processing = $a[0]), (parse_as_content_model = $a[1]), $a
33230        };
33231        if ($truthy(terminator['$nil?']())) {
33232          
33233          if ($eqeq(parse_as_content_model, "verbatim")) {
33234            lines = reader.$read_lines_until($hash2(["break_on_blank_lines", "break_on_list_continuation"], {"break_on_blank_lines": true, "break_on_list_continuation": true}))
33235          } else {
33236            
33237            if ($eqeq(content_model, "compound")) {
33238              content_model = "simple"
33239            };
33240            lines = self.$read_paragraph_lines(reader, false, $hash2(["skip_line_comments", "skip_processing"], {"skip_line_comments": true, "skip_processing": skip_processing}));
33241          };
33242          block_reader = nil;
33243        } else if ($neqeq(parse_as_content_model, "compound")) {
33244          
33245          lines = reader.$read_lines_until($hash2(["terminator", "skip_processing", "context", "cursor"], {"terminator": terminator, "skip_processing": skip_processing, "context": block_context, "cursor": "at_mark"}));
33246          block_reader = nil;
33247        } else if ($eqeq(terminator, false)) {
33248          
33249          lines = nil;
33250          block_reader = reader;
33251        } else {
33252          
33253          lines = nil;
33254          block_cursor = reader.$cursor();
33255          block_reader = $$('Reader').$new(reader.$read_lines_until($hash2(["terminator", "skip_processing", "context", "cursor"], {"terminator": terminator, "skip_processing": skip_processing, "context": block_context, "cursor": "at_mark"})), block_cursor);
33256        };
33257        
33258        switch (content_model) {
33259          case "verbatim":
33260            
33261            tab_size = ($truthy(($ret_or_2 = attributes['$[]']("tabsize"))) ? ($ret_or_2) : (parent.$document().$attributes()['$[]']("tabsize"))).$to_i();
33262            if ($truthy((indent = attributes['$[]']("indent")))) {
33263              self['$adjust_indentation!'](lines, indent.$to_i(), tab_size)
33264            } else if ($truthy($rb_gt(tab_size, 0))) {
33265              self['$adjust_indentation!'](lines, -1, tab_size)
33266            };
33267            break;
33268          case "skip":
33269            return nil
33270          default:
33271            nil
33272        };
33273        if ($truthy((extension = options['$[]']("extension")))) {
33274          
33275          attributes.$delete("style");
33276          if (($truthy((block = extension.$process_method()['$[]'](parent, ($truthy(($ret_or_1 = block_reader)) ? ($ret_or_1) : ($$('Reader').$new(lines))), attributes.$merge()))) && ($neqeq(block, parent)))) {
33277            
33278            attributes.$replace(block.$attributes());
33279            if ((($eqeq(block.$content_model(), "compound") && ($eqeqeq($$('Block'), block))) && ($not((lines = block.$lines())['$empty?']())))) {
33280              
33281              content_model = "compound";
33282              block_reader = $$('Reader').$new(lines);
33283            };
33284          } else {
33285            return nil
33286          };
33287        } else {
33288          block = $$('Block').$new(parent, block_context, $hash2(["content_model", "source", "attributes"], {"content_model": content_model, "source": lines, "attributes": attributes}))
33289        };
33290        if ($eqeq(content_model, "compound")) {
33291          self.$parse_blocks(block_reader, block)
33292        };
33293        return block;
33294      }, -7);
33295      $defs(self, '$parse_blocks', function $$parse_blocks(reader, parent, attributes) {
33296        var self = this, $ret_or_1 = nil, $ret_or_2 = nil, block = nil;
33297
33298        
33299        if (attributes == null) attributes = nil;
33300        if ($truthy(attributes)) {
33301          while ($truthy(($truthy(($ret_or_1 = ($truthy(($ret_or_2 = (block = self.$next_block(reader, parent, attributes.$merge())))) ? (parent.$blocks()['$<<'](block)) : ($ret_or_2)))) ? ($ret_or_1) : (reader['$has_more_lines?']())))) {
33302          
33303          }
33304        } else {
33305          while ($truthy(($truthy(($ret_or_1 = ($truthy(($ret_or_2 = (block = self.$next_block(reader, parent)))) ? (parent.$blocks()['$<<'](block)) : ($ret_or_2)))) ? ($ret_or_1) : (reader['$has_more_lines?']())))) {
33306          
33307          }
33308        };
33309        return nil;
33310      }, -3);
33311      $defs(self, '$parse_list', function $$parse_list(reader, list_type, parent, style) {
33312        var $a, self = this, list_block = nil, list_rx = nil, $ret_or_1 = nil, list_item = nil;
33313        if ($gvars["~"] == null) $gvars["~"] = nil;
33314
33315        
33316        list_block = $$('List').$new(parent, list_type);
33317        list_rx = $$('ListRxMap')['$[]'](list_type);
33318        while ($truthy(($truthy(($ret_or_1 = reader['$has_more_lines?']())) ? (list_rx['$=~'](reader.$peek_line())) : ($ret_or_1)))) {
33319        
33320          if ($truthy((list_item = self.$parse_list_item(reader, list_block, $gvars["~"], (($a = $gvars['~']) === nil ? nil : $a['$[]'](1)), style)))) {
33321            list_block.$items()['$<<'](list_item)
33322          };
33323          if ($truthy(($ret_or_1 = reader.$skip_blank_lines()))) {
33324            $ret_or_1
33325          } else {
33326            break
33327          };
33328        };
33329        return list_block;
33330      });
33331      $defs(self, '$catalog_callouts', function $$catalog_callouts(text, document) {
33332        var found = nil, autonum = nil;
33333
33334        
33335        found = false;
33336        autonum = 0;
33337        if ($truthy(text['$include?']("<"))) {
33338          $send(text, 'scan', [$$('CalloutScanRx')], function $$10(){var $a;
33339
33340            
33341            if (!$truthy((($a = $gvars['~']) === nil ? nil : $a['$[]'](0))['$start_with?']("\\"))) {
33342              document.$callouts().$register(($eqeq((($a = $gvars['~']) === nil ? nil : $a['$[]'](2)), ".") ? ((autonum = $rb_plus(autonum, 1)).$to_s()) : ((($a = $gvars['~']) === nil ? nil : $a['$[]'](2)))))
33343            };
33344            return (found = true);})
33345        };
33346        return found;
33347      });
33348      $defs(self, '$catalog_inline_anchor', function $$catalog_inline_anchor(id, reftext, node, location, doc) {
33349        var self = this;
33350
33351        
33352        if (doc == null) doc = node.$document();
33353        if (($truthy(reftext) && ($truthy(reftext['$include?']($$('ATTR_REF_HEAD')))))) {
33354          reftext = doc.$sub_attributes(reftext)
33355        };
33356        if (!$truthy(doc.$register("refs", [id, $$('Inline').$new(node, "anchor", reftext, $hash2(["type", "id"], {"type": "ref", "id": id}))]))) {
33357          
33358          if ($eqeqeq($$('Reader'), location)) {
33359            location = location.$cursor()
33360          };
33361          self.$logger().$warn(self.$message_with_context("id assigned to anchor already in use: " + (id), $hash2(["source_location"], {"source_location": location})));
33362        };
33363        return nil;
33364      }, -5);
33365      $defs(self, '$catalog_inline_anchors', function $$catalog_inline_anchors(text, block, document, reader) {
33366        var self = this;
33367
33368        
33369        if (($truthy(text['$include?']("[[")) || ($truthy(text['$include?']("or:"))))) {
33370          $send(text, 'scan', [$$('InlineAnchorScanRx')], function $$11(){var $a, self = $$11.$$s == null ? this : $$11.$$s, id = nil, reftext = nil, location = nil, offset = nil;
33371
33372            
33373            if ($truthy((id = (($a = $gvars['~']) === nil ? nil : $a['$[]'](1))))) {
33374              if ((($truthy((reftext = (($a = $gvars['~']) === nil ? nil : $a['$[]'](2)))) && ($truthy(reftext['$include?']($$('ATTR_REF_HEAD'))))) && ($truthy((reftext = document.$sub_attributes(reftext))['$empty?']())))) {
33375                return nil
33376              }
33377            } else {
33378              
33379              id = (($a = $gvars['~']) === nil ? nil : $a['$[]'](3));
33380              if ($truthy((reftext = (($a = $gvars['~']) === nil ? nil : $a['$[]'](4))))) {
33381                if ($truthy(reftext['$include?']("]"))) {
33382                  
33383                  reftext = reftext.$gsub("\\]", "]");
33384                  if ($truthy(reftext['$include?']($$('ATTR_REF_HEAD')))) {
33385                    reftext = document.$sub_attributes(reftext)
33386                  };
33387                } else if ($truthy(reftext['$include?']($$('ATTR_REF_HEAD')))) {
33388                  if ($truthy((reftext = document.$sub_attributes(reftext))['$empty?']())) {
33389                    reftext = nil
33390                  }
33391                }
33392              };
33393            };
33394            if ($truthy(document.$register("refs", [id, $$('Inline').$new(block, "anchor", reftext, $hash2(["type", "id"], {"type": "ref", "id": id}))]))) {
33395              return nil
33396            } else {
33397              
33398              location = reader.$cursor_at_mark();
33399              if ($truthy($rb_gt((offset = $rb_plus((($a = $gvars['~']) === nil ? nil : $a.$pre_match()).$count($$('LF')), ($truthy((($a = $gvars['~']) === nil ? nil : $a['$[]'](0))['$start_with?']($$('LF'))) ? (1) : (0)))), 0))) {
33400                (location = location.$dup()).$advance(offset)
33401              };
33402              return self.$logger().$warn(self.$message_with_context("id assigned to anchor already in use: " + (id), $hash2(["source_location"], {"source_location": location})));
33403            };}, {$$s: self})
33404        };
33405        return nil;
33406      });
33407      $defs(self, '$catalog_inline_biblio_anchor', function $$catalog_inline_biblio_anchor(id, reftext, node, reader) {
33408        var self = this, $ret_or_1 = nil;
33409
33410        
33411        if (!$truthy(node.$document().$register("refs", [id, $$('Inline').$new(node, "anchor", ($truthy(($ret_or_1 = reftext)) ? ("[" + (reftext) + "]") : ($ret_or_1)), $hash2(["type", "id"], {"type": "bibref", "id": id}))]))) {
33412          self.$logger().$warn(self.$message_with_context("id assigned to bibliography anchor already in use: " + (id), $hash2(["source_location"], {"source_location": reader.$cursor()})))
33413        };
33414        return nil;
33415      });
33416      $defs(self, '$parse_description_list', function $$parse_description_list(reader, match, parent) {
33417        var self = this, list_block = nil, sibling_pattern = nil, current_pair = nil, $ret_or_1 = nil, next_pair = nil;
33418        if ($gvars["~"] == null) $gvars["~"] = nil;
33419
33420        
33421        list_block = $$('List').$new(parent, "dlist");
33422        sibling_pattern = $$('DescriptionListSiblingRx')['$[]'](match['$[]'](2));
33423        list_block.$items()['$<<']((current_pair = self.$parse_list_item(reader, list_block, match, sibling_pattern)));
33424        while ($truthy(($truthy(($ret_or_1 = reader['$has_more_lines?']())) ? (sibling_pattern['$=~'](reader.$peek_line())) : ($ret_or_1)))) {
33425        
33426          next_pair = self.$parse_list_item(reader, list_block, $gvars["~"], sibling_pattern);
33427          if ($truthy(current_pair['$[]'](1))) {
33428            list_block.$items()['$<<']((current_pair = next_pair))
33429          } else {
33430            
33431            current_pair['$[]'](0)['$<<'](next_pair['$[]'](0)['$[]'](0));
33432            current_pair['$[]='](1, next_pair['$[]'](1));
33433          };
33434        };
33435        return list_block;
33436      });
33437      $defs(self, '$parse_callout_list', function $$parse_callout_list(reader, match, parent, callouts) {
33438        var self = this, list_block = nil, next_index = nil, autonum = nil, $ret_or_1 = nil, $ret_or_2 = nil, num = nil, list_item = nil, coids = nil;
33439
33440        
33441        list_block = $$('List').$new(parent, "colist");
33442        next_index = 1;
33443        autonum = 0;
33444        while ($truthy(($truthy(($ret_or_1 = match)) ? ($ret_or_1) : (($truthy(($ret_or_2 = (match = $$('CalloutListRx').$match(reader.$peek_line())))) ? (reader.$mark()) : ($ret_or_2)))))) {
33445        
33446          if ($eqeq((num = match['$[]'](1)), ".")) {
33447            num = (autonum = $rb_plus(autonum, 1)).$to_s()
33448          };
33449          if (!$eqeq(num, next_index.$to_s())) {
33450            self.$logger().$warn(self.$message_with_context("callout list item index: expected " + (next_index) + ", got " + (num), $hash2(["source_location"], {"source_location": reader.$cursor_at_mark()})))
33451          };
33452          if ($truthy((list_item = self.$parse_list_item(reader, list_block, match, "<1>")))) {
33453            
33454            list_block.$items()['$<<'](list_item);
33455            if ($truthy((coids = callouts.$callout_ids(list_block.$items().$size()))['$empty?']())) {
33456              self.$logger().$warn(self.$message_with_context("no callout found for <" + (list_block.$items().$size()) + ">", $hash2(["source_location"], {"source_location": reader.$cursor_at_mark()})))
33457            } else {
33458              list_item.$attributes()['$[]=']("coids", coids)
33459            };
33460          };
33461          next_index = $rb_plus(next_index, 1);
33462          match = nil;
33463        };
33464        callouts.$next_list();
33465        return list_block;
33466      });
33467      $defs(self, '$parse_list_item', function $$parse_list_item(reader, list_block, match, sibling_trait, style) {
33468        var $a, $b, self = this, list_type = nil, dlist = nil, list_term = nil, term_text = nil, $ret_or_1 = nil, item_text = nil, has_text = nil, list_item = nil, sourcemap_assignment_deferred = nil, ordinal = nil, implicit_style = nil, $ret_or_2 = nil, $ret_or_3 = nil, block_cursor = nil, list_item_reader = nil, comment_lines = nil, subsequent_line = nil, content_adjacent = nil, block = nil, first_block = nil;
33469
33470        
33471        if (style == null) style = nil;
33472        if ($eqeq((list_type = list_block.$context()), "dlist")) {
33473          
33474          dlist = true;
33475          list_term = $$('ListItem').$new(list_block, (term_text = match['$[]'](1)));
33476          if (($truthy(term_text['$start_with?']("[[")) && ($truthy($$('LeadingInlineAnchorRx')['$=~'](term_text))))) {
33477            self.$catalog_inline_anchor((($a = $gvars['~']) === nil ? nil : $a['$[]'](1)), ($truthy(($ret_or_1 = (($a = $gvars['~']) === nil ? nil : $a['$[]'](2)))) ? ($ret_or_1) : ((($a = $gvars['~']) === nil ? nil : $a.$post_match()).$lstrip())), list_term, reader)
33478          };
33479          if ($truthy((item_text = match['$[]'](3)))) {
33480            has_text = true
33481          };
33482          list_item = $$('ListItem').$new(list_block, item_text);
33483          if ($truthy(list_block.$document().$sourcemap())) {
33484            
33485            list_term['$source_location='](reader.$cursor());
33486            if ($truthy(has_text)) {
33487              list_item['$source_location='](list_term.$source_location())
33488            } else {
33489              sourcemap_assignment_deferred = true
33490            };
33491          };
33492        } else {
33493          
33494          has_text = true;
33495          list_item = $$('ListItem').$new(list_block, (item_text = match['$[]'](2)));
33496          if ($truthy(list_block.$document().$sourcemap())) {
33497            list_item['$source_location='](reader.$cursor())
33498          };
33499          
33500          switch (list_type) {
33501            case "ulist":
33502              
33503              list_item['$marker='](sibling_trait);
33504              if ($truthy(item_text['$start_with?']("["))) {
33505                if (($truthy(style) && ($eqeq(style, "bibliography")))) {
33506                  if ($truthy($$('InlineBiblioAnchorRx')['$=~'](item_text))) {
33507                    self.$catalog_inline_biblio_anchor((($a = $gvars['~']) === nil ? nil : $a['$[]'](1)), (($a = $gvars['~']) === nil ? nil : $a['$[]'](2)), list_item, reader)
33508                  }
33509                } else if ($truthy(item_text['$start_with?']("[["))) {
33510                  if ($truthy($$('LeadingInlineAnchorRx')['$=~'](item_text))) {
33511                    self.$catalog_inline_anchor((($a = $gvars['~']) === nil ? nil : $a['$[]'](1)), (($a = $gvars['~']) === nil ? nil : $a['$[]'](2)), list_item, reader)
33512                  }
33513                } else if ($truthy(item_text['$start_with?']("[ ] ", "[x] ", "[*] "))) {
33514                  
33515                  list_block.$set_option("checklist");
33516                  list_item.$attributes()['$[]=']("checkbox", "");
33517                  if (!$truthy(item_text['$start_with?']("[ "))) {
33518                    list_item.$attributes()['$[]=']("checked", "")
33519                  };
33520                  list_item['$text='](item_text.$slice(4, item_text.$length()));
33521                }
33522              };
33523              break;
33524            case "olist":
33525              
33526              $b = self.$resolve_ordered_list_marker(sibling_trait, (ordinal = list_block.$items().$size()), true, reader), $a = $to_ary($b), (sibling_trait = ($a[0] == null ? nil : $a[0])), (implicit_style = ($a[1] == null ? nil : $a[1])), $b;
33527              list_item['$marker='](sibling_trait);
33528              if (($eqeq(ordinal, 0) && ($not(style)))) {
33529                list_block['$style='](($truthy(($ret_or_2 = implicit_style)) ? ($ret_or_2) : (($truthy(($ret_or_3 = $$('ORDERED_LIST_STYLES')['$[]']($rb_minus(sibling_trait.$length(), 1)))) ? ($ret_or_3) : ("arabic")).$to_s())))
33530              };
33531              if (($truthy(item_text['$start_with?']("[[")) && ($truthy($$('LeadingInlineAnchorRx')['$=~'](item_text))))) {
33532                self.$catalog_inline_anchor((($a = $gvars['~']) === nil ? nil : $a['$[]'](1)), (($a = $gvars['~']) === nil ? nil : $a['$[]'](2)), list_item, reader)
33533              };
33534              break;
33535            default:
33536              
33537              list_item['$marker='](sibling_trait);
33538              if (($truthy(item_text['$start_with?']("[[")) && ($truthy($$('LeadingInlineAnchorRx')['$=~'](item_text))))) {
33539                self.$catalog_inline_anchor((($a = $gvars['~']) === nil ? nil : $a['$[]'](1)), (($a = $gvars['~']) === nil ? nil : $a['$[]'](2)), list_item, reader)
33540              };
33541          };
33542        };
33543        reader.$shift();
33544        block_cursor = reader.$cursor();
33545        list_item_reader = $$('Reader').$new(self.$read_lines_for_list_item(reader, list_type, sibling_trait, has_text), block_cursor);
33546        if ($truthy(list_item_reader['$has_more_lines?']())) {
33547          
33548          if ($truthy(sourcemap_assignment_deferred)) {
33549            list_item['$source_location='](block_cursor)
33550          };
33551          comment_lines = list_item_reader.$skip_line_comments();
33552          if ($truthy((subsequent_line = list_item_reader.$peek_line()))) {
33553            
33554            if (!$truthy(comment_lines['$empty?']())) {
33555              list_item_reader.$unshift_lines(comment_lines)
33556            };
33557            if (!$truthy(subsequent_line['$empty?']())) {
33558              
33559              content_adjacent = true;
33560              if (!$truthy(dlist)) {
33561                has_text = nil
33562              };
33563            };
33564          };
33565          if ($truthy((block = self.$next_block(list_item_reader, list_item, $hash2([], {}), $hash2(["text_only", "list_type"], {"text_only": ($truthy(has_text) ? (nil) : (true)), "list_type": list_type}))))) {
33566            list_item.$blocks()['$<<'](block)
33567          };
33568          while ($truthy(list_item_reader['$has_more_lines?']())) {
33569          if ($truthy((block = self.$next_block(list_item_reader, list_item, $hash2([], {}), $hash2(["list_type"], {"list_type": list_type}))))) {
33570              list_item.$blocks()['$<<'](block)
33571            }
33572          };
33573          if ((($truthy(content_adjacent) && ($truthy((first_block = list_item.$blocks()['$[]'](0))))) && ($eqeq(first_block.$context(), "paragraph")))) {
33574            list_item.$fold_first()
33575          };
33576        };
33577        if ($truthy(dlist)) {
33578          return [[list_term], (($truthy(list_item['$text?']()) || ($truthy(list_item['$blocks?']()))) ? (list_item) : (nil))]
33579        } else {
33580          return list_item
33581        };
33582      }, -5);
33583      $defs(self, '$read_lines_for_list_item', function $$read_lines_for_list_item(reader, list_type, sibling_trait, has_text) {
33584        var $a, self = this, buffer = nil, continuation = nil, within_nested_list = nil, detached_continuation = nil, dlist = nil, this_line = nil, prev_line = nil, match = nil, block_attribute_lines = nil, next_line = nil, interrupt = nil, ch0 = nil, nested_list_type = nil, $ret_or_1 = nil, last_line = nil;
33585
33586        
33587        if (sibling_trait == null) sibling_trait = nil;
33588        if (has_text == null) has_text = true;
33589        buffer = [];
33590        continuation = "inactive";
33591        within_nested_list = false;
33592        detached_continuation = nil;
33593        dlist = list_type['$==']("dlist");
33594        while ($truthy(reader['$has_more_lines?']())) {
33595        
33596          this_line = reader.$read_line();
33597          if ($truthy(self['$is_sibling_list_item?'](this_line, list_type, sibling_trait))) {
33598            break
33599          };
33600          prev_line = ($truthy(buffer['$empty?']()) ? (nil) : (buffer['$[]'](-1)));
33601          if ($eqeq(prev_line, $$('LIST_CONTINUATION'))) {
33602            
33603            if ($eqeq(continuation, "inactive")) {
33604              
33605              continuation = "active";
33606              has_text = true;
33607              if (!$truthy(within_nested_list)) {
33608                buffer['$[]='](-1, "")
33609              };
33610            };
33611            if ($eqeq(this_line, $$('LIST_CONTINUATION'))) {
33612              
33613              if ($neqeq(continuation, "frozen")) {
33614                
33615                continuation = "frozen";
33616                buffer['$<<'](this_line);
33617              };
33618              this_line = nil;
33619              continue;
33620            };
33621          };
33622          if ($truthy((match = self['$is_delimited_block?'](this_line, true)))) {
33623            
33624            if (!$eqeq(continuation, "active")) {
33625              break
33626            };
33627            buffer['$<<'](this_line);
33628            buffer.$concat(reader.$read_lines_until($hash2(["terminator", "read_last_line", "context"], {"terminator": match.$terminator(), "read_last_line": true, "context": nil})));
33629            continuation = "inactive";
33630          } else if (((($truthy(dlist) && ($neqeq(continuation, "active"))) && ($truthy(this_line['$start_with?']("[")))) && ($truthy($$('BlockAttributeLineRx')['$match?'](this_line))))) {
33631            
33632            block_attribute_lines = [this_line];
33633            while ($truthy((next_line = reader.$peek_line()))) {
33634            
33635              if ($truthy(self['$is_delimited_block?'](next_line))) {
33636                interrupt = true
33637              } else if (($truthy(next_line['$empty?']()) || (($truthy(next_line['$start_with?']("[")) && ($truthy($$('BlockAttributeLineRx')['$match?'](next_line))))))) {
33638                
33639                block_attribute_lines['$<<'](reader.$read_line());
33640                continue;
33641              } else if (($truthy($$('AnyListRx')['$match?'](next_line)) && ($not(self['$is_sibling_list_item?'](next_line, list_type, sibling_trait))))) {
33642                buffer.$concat(block_attribute_lines)
33643              } else {
33644                interrupt = true
33645              };
33646              break;
33647            };
33648            if ($truthy(interrupt)) {
33649              
33650              reader.$unshift_lines(block_attribute_lines);
33651              break;
33652            };
33653          } else if (($eqeq(continuation, "active") && ($not(this_line['$empty?']())))) {
33654            if ($truthy($$('LiteralParagraphRx')['$match?'](this_line))) {
33655              
33656              reader.$unshift_line(this_line);
33657              if ($truthy(dlist)) {
33658                buffer.$concat($send(reader, 'read_lines_until', [$hash2(["preserve_last_line", "break_on_blank_lines", "break_on_list_continuation"], {"preserve_last_line": true, "break_on_blank_lines": true, "break_on_list_continuation": true})], function $$12(line){var self = $$12.$$s == null ? this : $$12.$$s;
33659
33660                  
33661                  if (line == null) line = nil;
33662                  return self['$is_sibling_list_item?'](line, list_type, sibling_trait);}, {$$s: self}))
33663              } else {
33664                buffer.$concat(reader.$read_lines_until($hash2(["preserve_last_line", "break_on_blank_lines", "break_on_list_continuation"], {"preserve_last_line": true, "break_on_blank_lines": true, "break_on_list_continuation": true})))
33665              };
33666              continuation = "inactive";
33667            } else if (((($eqeq((ch0 = this_line.$chr()), ".") && ($truthy($$('BlockTitleRx')['$match?'](this_line)))) || (($eqeq(ch0, "[") && ($truthy($$('BlockAttributeLineRx')['$match?'](this_line)))))) || (($eqeq(ch0, ":") && ($truthy($$('AttributeEntryRx')['$match?'](this_line))))))) {
33668              buffer['$<<'](this_line)
33669            } else {
33670              
33671              if ($truthy((nested_list_type = $send(($truthy(within_nested_list) ? (["dlist"]) : ($$('NESTABLE_LIST_CONTEXTS'))), 'find', [], function $$13(ctx){
33672                
33673                if (ctx == null) ctx = nil;
33674                return $$('ListRxMap')['$[]'](ctx)['$match?'](this_line);})))) {
33675                
33676                within_nested_list = true;
33677                if (($eqeq(nested_list_type, "dlist") && ($truthy((($a = $gvars['~']) === nil ? nil : $a['$[]'](3))['$nil_or_empty?']())))) {
33678                  has_text = false
33679                };
33680              };
33681              buffer['$<<'](this_line);
33682              continuation = "inactive";
33683            }
33684          } else if (($truthy(prev_line) && ($truthy(prev_line['$empty?']())))) {
33685            
33686            if ($truthy(this_line['$empty?']())) {
33687              
33688              if (!$truthy((this_line = ($truthy(($ret_or_1 = reader.$skip_blank_lines())) ? (reader.$read_line()) : ($ret_or_1))))) {
33689                break
33690              };
33691              if ($truthy(self['$is_sibling_list_item?'](this_line, list_type, sibling_trait))) {
33692                break
33693              };
33694            };
33695            if ($eqeq(this_line, $$('LIST_CONTINUATION'))) {
33696              
33697              detached_continuation = buffer.$size();
33698              buffer['$<<'](this_line);
33699            } else if ($truthy(has_text)) {
33700              if ($truthy(self['$is_sibling_list_item?'](this_line, list_type, sibling_trait))) {
33701                break
33702              } else if ($truthy((nested_list_type = $send($$('NESTABLE_LIST_CONTEXTS'), 'find', [], function $$14(ctx){
33703                
33704                if (ctx == null) ctx = nil;
33705                return $$('ListRxMap')['$[]'](ctx)['$=~'](this_line);})))) {
33706                
33707                buffer['$<<'](this_line);
33708                within_nested_list = true;
33709                if (($eqeq(nested_list_type, "dlist") && ($truthy((($a = $gvars['~']) === nil ? nil : $a['$[]'](3))['$nil_or_empty?']())))) {
33710                  has_text = false
33711                };
33712              } else if ($truthy($$('LiteralParagraphRx')['$match?'](this_line))) {
33713                
33714                reader.$unshift_line(this_line);
33715                if ($truthy(dlist)) {
33716                  buffer.$concat($send(reader, 'read_lines_until', [$hash2(["preserve_last_line", "break_on_blank_lines", "break_on_list_continuation"], {"preserve_last_line": true, "break_on_blank_lines": true, "break_on_list_continuation": true})], function $$15(line){var self = $$15.$$s == null ? this : $$15.$$s;
33717
33718                    
33719                    if (line == null) line = nil;
33720                    return self['$is_sibling_list_item?'](line, list_type, sibling_trait);}, {$$s: self}))
33721                } else {
33722                  buffer.$concat(reader.$read_lines_until($hash2(["preserve_last_line", "break_on_blank_lines", "break_on_list_continuation"], {"preserve_last_line": true, "break_on_blank_lines": true, "break_on_list_continuation": true})))
33723                };
33724              } else {
33725                break
33726              }
33727            } else {
33728              
33729              if (!$truthy(within_nested_list)) {
33730                buffer.$pop()
33731              };
33732              buffer['$<<'](this_line);
33733              has_text = true;
33734            };
33735          } else {
33736            
33737            if (!$truthy(this_line['$empty?']())) {
33738              has_text = true
33739            };
33740            if ($truthy((nested_list_type = $send(($truthy(within_nested_list) ? (["dlist"]) : ($$('NESTABLE_LIST_CONTEXTS'))), 'find', [], function $$16(ctx){
33741              
33742              if (ctx == null) ctx = nil;
33743              return $$('ListRxMap')['$[]'](ctx)['$=~'](this_line);})))) {
33744              
33745              within_nested_list = true;
33746              if (($eqeq(nested_list_type, "dlist") && ($truthy((($a = $gvars['~']) === nil ? nil : $a['$[]'](3))['$nil_or_empty?']())))) {
33747                has_text = false
33748              };
33749            };
33750            buffer['$<<'](this_line);
33751          };
33752          this_line = nil;
33753        };
33754        if ($truthy(this_line)) {
33755          reader.$unshift_line(this_line)
33756        };
33757        if ($truthy(detached_continuation)) {
33758          buffer['$[]='](detached_continuation, "")
33759        };
33760        while (!($truthy(buffer['$empty?']()))) {
33761        if ($truthy((last_line = buffer['$[]'](-1))['$empty?']())) {
33762            buffer.$pop()
33763          } else {
33764            
33765            if ($eqeq(last_line, $$('LIST_CONTINUATION'))) {
33766              buffer.$pop()
33767            };
33768            break;
33769          }
33770        };
33771        return buffer;
33772      }, -3);
33773      $defs(self, '$initialize_section', function $$initialize_section(reader, parent, attributes) {
33774        var $a, $b, self = this, document = nil, book = nil, doctype = nil, source_location = nil, sect_style = nil, sect_id = nil, sect_reftext = nil, sect_title = nil, sect_level = nil, sect_atx = nil, sect_name = nil, sect_special = nil, sect_numbered = nil, section = nil, $ret_or_1 = nil, id = nil, generated_id = nil;
33775
33776        
33777        if (attributes == null) attributes = $hash2([], {});
33778        document = parent.$document();
33779        book = (doctype = document.$doctype())['$==']("book");
33780        if ($truthy(document.$sourcemap())) {
33781          source_location = reader.$cursor()
33782        };
33783        sect_style = attributes['$[]'](1);
33784        $b = self.$parse_section_title(reader, document, attributes['$[]']("id")), $a = $to_ary($b), (sect_id = ($a[0] == null ? nil : $a[0])), (sect_reftext = ($a[1] == null ? nil : $a[1])), (sect_title = ($a[2] == null ? nil : $a[2])), (sect_level = ($a[3] == null ? nil : $a[3])), (sect_atx = ($a[4] == null ? nil : $a[4])), $b;
33785        if ($truthy(sect_style)) {
33786          if (($truthy(book) && ($eqeq(sect_style, "abstract")))) {
33787            $a = ["chapter", 1], (sect_name = $a[0]), (sect_level = $a[1]), $a
33788          } else if (($truthy(sect_style['$start_with?']("sect")) && ($truthy($$('SectionLevelStyleRx')['$match?'](sect_style))))) {
33789            sect_name = "section"
33790          } else {
33791            
33792            $a = [sect_style, true], (sect_name = $a[0]), (sect_special = $a[1]), $a;
33793            if ($eqeq(sect_level, 0)) {
33794              sect_level = 1
33795            };
33796            sect_numbered = sect_name['$==']("appendix");
33797          }
33798        } else if ($truthy(book)) {
33799          sect_name = ($eqeq(sect_level, 0) ? ("part") : (($truthy($rb_gt(sect_level, 1)) ? ("section") : ("chapter"))))
33800        } else if (($eqeq(doctype, "manpage") && ($eqeq(sect_title.$casecmp("synopsis"), 0)))) {
33801          $a = ["synopsis", true], (sect_name = $a[0]), (sect_special = $a[1]), $a
33802        } else {
33803          sect_name = "section"
33804        };
33805        if ($truthy(sect_reftext)) {
33806          attributes['$[]=']("reftext", sect_reftext)
33807        };
33808        section = $$('Section').$new(parent, sect_level);
33809        $a = [sect_id, sect_title, sect_name, source_location], ($b = [$a[0]], $send(section, 'id=', $b), $b[$b.length - 1]), ($b = [$a[1]], $send(section, 'title=', $b), $b[$b.length - 1]), ($b = [$a[2]], $send(section, 'sectname=', $b), $b[$b.length - 1]), ($b = [$a[3]], $send(section, 'source_location=', $b), $b[$b.length - 1]), $a;
33810        if ($truthy(sect_special)) {
33811          
33812          section['$special='](true);
33813          if ($truthy(sect_numbered)) {
33814            section['$numbered='](true)
33815          }
33815 else if ($eqeq(document.$attributes()['$[]']("sectnums"), "all")) {
33816            section['$numbered=']((($truthy(book) && ($eqeq(sect_level, 1))) ? ("chapter") : (true)))
33817          };
33818        } else if (($truthy(document.$attributes()['$[]']("sectnums")) && ($truthy($rb_gt(sect_level, 0))))) {
33819          section['$numbered='](($truthy(section.$special()) ? (($truthy(($ret_or_1 = parent.$numbered())) || ($ret_or_1))) : (true)))
33820        } else if ((($truthy(book) && ($eqeq(sect_level, 0))) && ($truthy(document.$attributes()['$[]']("partnums"))))) {
33821          section['$numbered='](true)
33822        };
33823        if ($truthy((id = ($truthy(($ret_or_1 = section.$id())) ? ($ret_or_1) : (($a = [($truthy(document.$attributes()['$key?']("sectids")) ? ((generated_id = $$('Section').$generate_id(section.$title(), document))) : (nil))], $send(section, 'id=', $a), $a[$a.length - 1])))))) {
33824          
33825          if (!($truthy(generated_id) || ($not(sect_title['$include?']($$('ATTR_REF_HEAD')))))) {
33826            section.$title()
33827          };
33828          if (!$truthy(document.$register("refs", [id, section]))) {
33829            self.$logger().$warn(self.$message_with_context("id assigned to section already in use: " + (id), $hash2(["source_location"], {"source_location": reader.$cursor_at_line($rb_minus(reader.$lineno(), ($truthy(sect_atx) ? (1) : (2))))})))
33830          };
33831        };
33832        section.$update_attributes(attributes);
33833        reader.$skip_blank_lines();
33834        return section;
33835      }, -3);
33836      $defs(self, '$is_next_line_section?', function $Parser_is_next_line_section$ques$17(reader, attributes) {
33837        var self = this, style = nil, next_lines = nil, $ret_or_1 = nil;
33838
33839        
33840        if (($truthy((style = attributes['$[]'](1))) && (($eqeq(style, "discrete") || ($eqeq(style, "float")))))) {
33841          return nil
33842        };
33843        if ($truthy($$('Compliance').$underline_style_section_titles())) {
33844          
33845          next_lines = reader.$peek_lines(2, ($truthy(($ret_or_1 = style)) ? (style['$==']("comment")) : ($ret_or_1)));
33846          return self['$is_section_title?'](($truthy(($ret_or_1 = next_lines['$[]'](0))) ? ($ret_or_1) : ("")), next_lines['$[]'](1));
33847        } else {
33848          return self['$atx_section_title?'](($truthy(($ret_or_1 = reader.$peek_line())) ? ($ret_or_1) : ("")))
33849        };
33850      });
33851      $defs(self, '$is_next_line_doctitle?', function $Parser_is_next_line_doctitle$ques$18(reader, attributes, leveloffset) {
33852        var self = this, $ret_or_1 = nil, sect_level = nil;
33853
33854        if ($truthy(leveloffset)) {
33855          if ($truthy(($ret_or_1 = (sect_level = self['$is_next_line_section?'](reader, attributes))))) {
33856            
33857            return $rb_plus(sect_level, leveloffset.$to_i())['$=='](0);
33858          } else {
33859            return $ret_or_1
33860          }
33861        } else {
33862          return self['$is_next_line_section?'](reader, attributes)['$=='](0)
33863        }
33864      });
33865      $defs(self, '$is_section_title?', function $Parser_is_section_title$ques$19(line1, line2) {
33866        var self = this, $ret_or_1 = nil;
33867
33868        
33869        if (line2 == null) line2 = nil;
33870        if ($truthy(($ret_or_1 = self['$atx_section_title?'](line1)))) {
33871          return $ret_or_1
33872        } else {
33873          
33874          if ($truthy(line2['$nil_or_empty?']())) {
33875            return nil
33876          } else {
33877            return self['$setext_section_title?'](line1, line2)
33878          };
33879        };
33880      }, -2);
33881      $defs(self, '$atx_section_title?', function $Parser_atx_section_title$ques$20(line) {
33882        var $a, $ret_or_1 = nil;
33883
33884        if ($truthy(($truthy($$('Compliance').$markdown_syntax()) ? (($truthy(($ret_or_1 = line['$start_with?']("=", "#"))) ? ($$('ExtAtxSectionTitleRx')['$=~'](line)) : ($ret_or_1))) : (($truthy(($ret_or_1 = line['$start_with?']("="))) ? ($$('AtxSectionTitleRx')['$=~'](line)) : ($ret_or_1)))))) {
33885          return $rb_minus((($a = $gvars['~']) === nil ? nil : $a['$[]'](1)).$length(), 1)
33886        } else {
33887          return nil
33888        }
33889      });
33890      $defs(self, '$setext_section_title?', function $Parser_setext_section_title$ques$21(line1, line2) {
33891        var self = this, line2_len = nil, level = nil, line2_ch0 = nil;
33892
33893        if (((($truthy((level = $$('SETEXT_SECTION_LEVELS')['$[]']((line2_ch0 = line2.$chr())))) && ($truthy(self['$uniform?'](line2, line2_ch0, (line2_len = line2.$length()))))) && ($truthy($$('SetextSectionTitleRx')['$match?'](line1)))) && ($truthy($rb_lt($rb_minus(line1.$length(), line2_len).$abs(), 2)))
33893)) {
33894          return level
33895        } else {
33896          return nil
33897        }
33898      });
33899      $defs(self, '$parse_section_title', function $$parse_section_title(reader, document, sect_id) {
33900        var $a, $b, self = this, sect_reftext = nil, line1 = nil, $ret_or_1 = nil, sect_level = nil, sect_title = nil, atx = nil, line2_len = nil, line2_ch0 = nil, line2 = nil;
33901
33902        
33903        if (sect_id == null) sect_id = nil;
33904        sect_reftext = nil;
33905        line1 = reader.$read_line();
33906        if ($truthy(($truthy($$('Compliance').$markdown_syntax()) ? (($truthy(($ret_or_1 = line1['$start_with?']("=", "#"))) ? ($$('ExtAtxSectionTitleRx')['$=~'](line1)) : ($ret_or_1))) : (($truthy(($ret_or_1 = line1['$start_with?']("="))) ? ($$('AtxSectionTitleRx')['$=~'](line1)) : ($ret_or_1)))))) {
33907          
33908          $a = [$rb_minus((($b = $gvars['~']) === nil ? nil : $b['$[]'](1)).$length(), 1), (($b = $gvars['~']) === nil ? nil : $b['$[]'](2)), true], (sect_level = $a[0]), (sect_title = $a[1]), (atx = $a[2]), $a;
33909          if (!$truthy(sect_id)) {
33910            if ((($truthy(sect_title['$end_with?']("]]")) && ($truthy($$('InlineSectionAnchorRx')['$=~'](sect_title)))) && ($not((($a = $gvars['~']) === nil ? nil : $a['$[]'](1)))))) {
33911              $a = [sect_title.$slice(0, $rb_minus(sect_title.$length(), (($b = $gvars['~']) === nil ? nil : $b['$[]'](0)).$length())), (($b = $gvars['~']) === nil ? nil : $b['$[]'](2)), (($b = $gvars['~']) === nil ? nil : $b['$[]'](3))], (sect_title = $a[0]), (sect_id = $a[1]), (sect_reftext = $a[2]), $a
33912            }
33913          };
33914        } else if (((((($truthy($$('Compliance').$underline_style_section_titles()) && ($truthy((line2 = reader.$peek_line(true))))) && ($truthy((sect_level = $$('SETEXT_SECTION_LEVELS')['$[]']((line2_ch0 = line2.$chr())))))) && ($truthy(self['$uniform?'](line2, line2_ch0, (line2_len = line2.$length()))))) && ($truthy((sect_title = ($truthy(($ret_or_1 = $$('SetextSectionTitleRx')['$=~'](line1))) ? ((($a = $gvars['~']) === nil ? nil : $a['$[]'](1))) : ($ret_or_1)))))) && ($truthy($rb_lt($rb_minus(line1.$length(), line2_len).$abs(), 2))))) {
33915          
33916          atx = false;
33917          if (!$truthy(sect_id)) {
33918            if ((($truthy(sect_title['$end_with?']("]]")) && ($truthy($$('InlineSectionAnchorRx')['$=~'](sect_title)))) && ($not((($a = $gvars['~']) === nil ? nil : $a['$[]'](1)))))) {
33919              $a = [sect_title.$slice(0, $rb_minus(sect_title.$length(), (($b = $gvars['~']) === nil ? nil : $b['$[]'](0)).$length())), (($b = $gvars['~']) === nil ? nil : $b['$[]'](2)), (($b = $gvars['~']) === nil ? nil : $b['$[]'](3))], (sect_title = $a[0]), (sect_id = $a[1]), (sect_reftext = $a[2]), $a
33920            }
33921          };
33922          reader.$shift();
33923        } else {
33924          self.$raise("Unrecognized section at " + (reader.$cursor_at_prev_line()))
33925        };
33926        if ($truthy(document['$attr?']("leveloffset"))) {
33927          
33928          sect_level = $rb_plus(sect_level, document.$attr("leveloffset").$to_i());
33929          if ($truthy($rb_lt(sect_level, 0))) {
33930            sect_level = 0
33931          };
33932        };
33933        return [sect_id, sect_reftext, sect_title, sect_level, atx];
33934      }, -3);
33935      $defs(self, '$parse_header_metadata', function $$parse_header_metadata(reader, document, retrieve) {
33936        var $a, self = this, doc_attrs = nil, $ret_or_1 = nil, authorcount = nil, implicit_author_metadata = nil, implicit_author = nil, implicit_authorinitials = nil, implicit_authors = nil, rev_line = nil, match = nil, rev_metadata = nil, component = nil, author_line = nil, author_metadata = nil, authors = nil, author_idx = nil, author_key = nil, explicit = nil, sparse = nil, author_override = nil;
33937
33938        
33939        if (document == null) document = nil;
33940        if (retrieve == null) retrieve = true;
33941        doc_attrs = ($truthy(($ret_or_1 = document)) ? (document.$attributes()) : ($ret_or_1));
33942        self.$process_attribute_entries(reader, document);
33943        if (($truthy(reader['$has_more_lines?']()) && ($not(reader['$next_line_empty?']())))) {
33944          
33945          authorcount = (implicit_author_metadata = self.$process_authors(reader.$read_line())).$delete("authorcount");
33946          if (($truthy(document) && ($truthy($rb_gt(($a = ["authorcount", authorcount], $send(doc_attrs, '[]=', $a), $a[$a.length - 1]), 0))))) {
33947            
33948            $send(implicit_author_metadata, 'each', [], function $$22(key, val){var $b;
33949
33950              
33951              if (key == null) key = nil;
33952              if (val == null) val = nil;
33953              if ($truthy(doc_attrs['$key?'](key))) {
33954                return nil
33955              } else {
33956                return ($b = [key, document.$apply_header_subs(val)], $send(doc_attrs, '[]=', $b), $b[$b.length - 1])
33957              };});
33958            implicit_author = doc_attrs['$[]']("author");
33959            implicit_authorinitials = doc_attrs['$[]']("authorinitials");
33960            implicit_authors = doc_attrs['$[]']("authors");
33961          };
33962          implicit_author_metadata['$[]=']("authorcount", authorcount);
33963          self.$process_attribute_entries(reader, document);
33964          if (($truthy(reader['$has_more_lines?']()) && ($not(reader['$next_line_empty?']())))) {
33965            
33966            rev_line = reader.$read_line();
33967            if ($truthy((match = $$('RevisionInfoLineRx').$match(rev_line)))) {
33968              
33969              rev_metadata = $hash2([], {});
33970              if ($truthy(match['$[]'](1))) {
33971                rev_metadata['$[]=']("revnumber", match['$[]'](1).$rstrip())
33972              };
33973              if (!$truthy((component = match['$[]'](2).$strip())['$empty?']())) {
33974                if (($not(match['$[]'](1)) && ($truthy(component['$start_with?']("v"))))) {
33975                  rev_metadata['$[]=']("revnumber", component.$slice(1, component.$length()))
33976                } else {
33977                  rev_metadata['$[]=']("revdate", component)
33978                }
33979              };
33980              if ($truthy(match['$[]'](3))) {
33981                rev_metadata['$[]=']("revremark", match['$[]'](3).$rstrip())
33982              };
33983              if (($truthy(document) && ($not(rev_metadata['$empty?']())))) {
33984                $send(rev_metadata, 'each', [], function $$23(key, val){var $b;
33985
33986                  
33987                  if (key == null) key = nil;
33988                  if (val == null) val = nil;
33989                  if ($truthy(doc_attrs['$key?'](key))) {
33990                    return nil
33991                  } else {
33992                    return ($b = [key, document.$apply_header_subs(val)], $send(doc_attrs, '[]=', $b), $b[$b.length - 1])
33993                  };})
33994              };
33995            } else {
33996              reader.$unshift_line(rev_line)
33997            };
33998          };
33999          self.$process_attribute_entries(reader, document);
34000          reader.$skip_blank_lines();
34001        } else {
34002          implicit_author_metadata = $hash2([], {})
34003        };
34004        if ($truthy(document)) {
34005          
34006          if (($truthy(doc_attrs['$key?']("author")) && ($neqeq((author_line = doc_attrs['$[]']("author")), implicit_author)))) {
34007            
34008            author_metadata = self.$process_authors(author_line, true, false);
34009            if ($neqeq(doc_attrs['$[]']("authorinitials"), implicit_authorinitials)) {
34010              author_metadata.$delete("authorinitials")
34011            };
34012          } else if (($truthy(doc_attrs['$key?']("authors")) && ($neqeq((author_line = doc_attrs['$[]']("authors")), implicit_authors)))) {
34013            author_metadata = self.$process_authors(author_line, true)
34014          } else {
34015            
34016            $a = [[], 1, "author_1", false, false], (authors = $a[0]), (author_idx = $a[1]), (author_key = $a[2]), (explicit = $a[3]), (sparse = $a[4]), $a;
34017            while ($truthy(doc_attrs['$key?'](author_key))) {
34018            
34019              if ($eqeq((author_override = doc_attrs['$[]'](author_key)), implicit_author_metadata['$[]'](author_key))) {
34020                
34021                authors['$<<'](nil);
34022                sparse = true;
34023              } else {
34024                
34025                authors['$<<'](author_override);
34026                explicit = true;
34027              };
34028              author_key = "author_" + ((author_idx = $rb_plus(author_idx, 1)));
34029            };
34030            if ($truthy(explicit)) {
34031              
34032              if ($truthy(sparse)) {
34033                $send(authors, 'each_with_index', [], function $$24(author, idx){var $b, name_idx = nil;
34034
34035                  
34036                  if (author == null) author = nil;
34037                  if (idx == null) idx = nil;
34038                  if ($truthy(author)) {
34039                    return nil
34040                  };
34041                  return ($b = [idx, $send([implicit_author_metadata['$[]']("firstname_" + ((name_idx = $rb_plus(idx, 1)))), implicit_author_metadata['$[]']("middlename_" + (name_idx)), implicit_author_metadata['$[]']("lastname_" + (name_idx))].$compact(), 'map', [], function $$25(it){
34042                    
34043                    if (it == null) it = nil;
34044                    return it.$tr(" ", "_");}).$join(" ")], $send(authors, '[]=', $b), $b[$b.length - 1]);})
34045              };
34046              author_metadata = self.$process_authors(authors, true, false);
34047            } else {
34048              author_metadata = $hash2(["authorcount"], {"authorcount": 0})
34049            };
34050          };
34051          if ($eqeq(author_metadata['$[]']("authorcount"), 0)) {
34052            if ($truthy(authorcount)) {
34053              author_metadata = nil
34054            } else {
34055              doc_attrs['$[]=']("authorcount", 0)
34056            }
34057          } else {
34058            
34059            doc_attrs.$update(author_metadata);
34060            if (($not(doc_attrs['$key?']("email")) && ($truthy(doc_attrs['$key?']("email_1"))))) {
34061              doc_attrs['$[]=']("email", doc_attrs['$[]']("email_1"))
34062            };
34063          };
34064        };
34065        if ($truthy(retrieve)) {
34066          return implicit_author_metadata.$merge(rev_metadata.$to_h(), author_metadata.$to_h())
34067        } else {
34068          return nil
34069        };
34070      }, -2);
34071      $defs(self, '$process_authors', function $$process_authors(author_line, names_only, multiple) {
34072        var author_metadata = nil, author_idx = nil;
34073
34074        
34075        if (names_only == null) names_only = false;
34076        if (multiple == null) multiple = true;
34077        author_metadata = $hash2([], {});
34078        author_idx = 0;
34079        $send((($truthy(multiple) && ($truthy(author_line['$include?'](";")))) ? (author_line.$split($$('AuthorDelimiterRx'))) : ([].concat($to_a(author_line)))), 'each', [], function $$26(author_entry){var $a, key_map = nil, segments = nil, match = nil, author = nil, fname = nil, mname = nil, lname = nil, $ret_or_1 = nil;
34080
34081          
34082          if (author_entry == null) author_entry = nil;
34083          if ($truthy(author_entry['$empty?']())) {
34084            return nil
34085          };
34086          key_map = $hash2([], {});
34087          if ($eqeq((author_idx = $rb_plus(author_idx, 1)), 1)) {
34088            $send($$('AuthorKeys'), 'each', [], function $$27(key){var $a;
34089
34090              
34091              if (key == null) key = nil;
34092              return ($a = [key.$to_sym(), key], $send(key_map, '[]=', $a), $a[$a.length - 1]);})
34093          } else {
34094            $send($$('AuthorKeys'), 'each', [], function $$28(key){var $a;
34095
34096              
34097              if (key == null) key = nil;
34098              return ($a = [key.$to_sym(), "" + (key) + "_" + (author_idx)], $send(key_map, '[]=', $a), $a[$a.length - 1]);})
34099          };
34100          if ($truthy(names_only)) {
34101            
34102            if ($truthy(author_entry['$include?']("<"))) {
34103              
34104              author_metadata['$[]='](key_map['$[]']("author"), author_entry.$tr("_", " "));
34105              author_entry = author_entry.$gsub($$('XmlSanitizeRx'), "");
34106            };
34107            if ($eqeq((segments = author_entry.$split(nil, 3)).$size(), 3)) {
34108              segments['$<<'](segments.$pop().$squeeze(" "))
34109            };
34110          } else if ($truthy((match = $$('AuthorInfoLineRx').$match(author_entry)))) {
34111            (segments = match.$to_a()).$shift()
34112          };
34113          if ($truthy(segments)) {
34114            
34115            author = ($a = [key_map['$[]']("firstname"), (fname = segments['$[]'](0).$tr("_", " "))], $send(author_metadata, '[]=', $a), $a[$a.length - 1]);
34116            author_metadata['$[]='](key_map['$[]']("authorinitials"), fname.$chr());
34117            if ($truthy(segments['$[]'](1))) {
34118              if ($truthy(segments['$[]'](2))) {
34119                
34120                author_metadata['$[]='](key_map['$[]']("middlename"), (mname = segments['$[]'](1).$tr("_", " ")));
34121                author_metadata['$[]='](key_map['$[]']("lastname"), (lname = segments['$[]'](2).$tr("_", " ")));
34122                author = $rb_plus($rb_plus($rb_plus($rb_plus(fname, " "), mname), " "), lname);
34123                author_metadata['$[]='](key_map['$[]']("authorinitials"), "" + (fname.$chr()) + (mname.$chr()) + (lname.$chr()));
34124              } else {
34125                
34126                author_metadata['$[]='](key_map['$[]']("lastname"), (lname = segments['$[]'](1).$tr("_", " ")));
34127                author = $rb_plus($rb_plus(fname, " "), lname);
34128                author_metadata['$[]='](key_map['$[]']("authorinitials"), "" + (fname.$chr()) + (lname.$chr()));
34129              }
34130            };
34131            if ($truthy(($ret_or_1 = author_metadata['$[]'](key_map['$[]']("author"))))) {
34132              $ret_or_1
34133            } else {
34134              author_metadata['$[]='](key_map['$[]']("author"), author)
34135            };
34136            if (!($truthy(names_only) || ($not(segments['$[]'](3))))) {
34137              author_metadata['$[]='](key_map['$[]']("email"), segments['$[]'](3))
34138            };
34139          } else {
34140            
34141            author_metadata['$[]='](key_map['$[]']("author"), ($a = [key_map['$[]']("firstname"), (fname = author_entry.$squeeze(" ").$strip())], $send(author_metadata, '[]=', $a), $a[$a.length - 1]));
34142            author_metadata['$[]='](key_map['$[]']("authorinitials"), fname.$chr());
34143          };
34144          if ($eqeq(author_idx, 1)) {
34145            return ($a = ["authors", author_metadata['$[]'](key_map['$[]']("author"))], $send(author_metadata, '[]=', $a), $a[$a.length - 1])
34146          } else {
34147            
34148            if ($eqeq(author_idx, 2)) {
34149              $send($$('AuthorKeys'), 'each', [], function $$29(key){var $b;
34150
34151                
34152                if (key == null) key = nil;
34153                if ($truthy(author_metadata['$key?'](key))) {
34154                  return ($b = ["" + (key) + "_1", author_metadata['$[]'](key)], $send(author_metadata, '[]=', $b), $b[$b.length - 1])
34155                } else {
34156                  return nil
34157                };})
34158            };
34159            return ($a = ["authors", "" + (author_metadata['$[]']("authors")) + ", " + (author_metadata['$[]'](key_map['$[]']("author")))], $send(author_metadata, '[]=', $a), $a[$a.length - 1]);
34160          };});
34161        author_metadata['$[]=']("authorcount", author_idx);
34162        return author_metadata;
34163      }, -2);
34164      $defs(self, '$parse_block_metadata_lines', function $$parse_block_metadata_lines(reader, document, attributes, options) {
34165        var self = this, $ret_or_1 = nil;
34166
34167        
34168        if (attributes == null) attributes = $hash2([], {});
34169        if (options == null) options = $hash2([], {});
34170        while ($truthy(self.$parse_block_metadata_line(reader, document, attributes, options))) {
34171        
34172          reader.$shift();
34173          if ($truthy(($ret_or_1 = reader.$skip_blank_lines()))) {
34174            $ret_or_1
34175          } else {
34176            break
34177          };
34178        };
34179        return attributes;
34180      }, -3);
34181      $defs(self, '$parse_block_metadata_line', function $$parse_block_metadata_line(reader, document, attributes, options) {
34182        var $a, self = this, normal = nil, next_line = nil, reftext = nil, current_style = nil, $ret_or_1 = nil, ll = nil;
34183        if ($gvars["~"] == null) $gvars["~"] = nil;
34184
34185        
34186        if (options == null) options = $hash2([], {});
34187        if (($truthy((next_line = reader.$peek_line())) && ($truthy(($truthy(options['$[]']("text_only")) ? (next_line['$start_with?']("[", "/")) : ((normal = next_line['$start_with?']("[", ".", "/", ":")))))))) {
34188          if ($truthy(next_line['$start_with?']("["))) {
34189            if ($truthy(next_line['$start_with?']("[["))) {
34190              if (($truthy(next_line['$end_with?']("]]")) && ($truthy($$('BlockAnchorRx')['$=~'](next_line))))) {
34191                
34192                attributes['$[]=']("id", (($a = $gvars['~']) === nil ? nil : $a['$[]'](1)));
34193                if ($truthy((reftext = (($a = $gvars['~']) === nil ? nil : $a['$[]'](2))))) {
34194                  attributes['$[]=']("reftext", ($truthy(reftext['$include?']($$('ATTR_REF_HEAD'))) ? (document.$sub_attributes(reftext)) : (reftext)))
34195                };
34196                return true;
34197              }
34198            } else if (($truthy(next_line['$end_with?']("]")) && ($truthy($$('BlockAttributeListRx')['$=~'](next_line))))) {
34199              
34200              current_style = attributes['$[]'](1);
34201              if ($truthy(document.$parse_attributes((($a = $gvars['~']) === nil ? nil : $a['$[]'](1)), [], $hash2(["sub_input", "sub_result", "into"], {"sub_input": true, "sub_result": true, "into": attributes}))['$[]'](1))) {
34202                attributes['$[]='](1, ($truthy(($ret_or_1 = self.$parse_style_attribute(attributes, reader))) ? ($ret_or_1) : (current_style)))
34203              };
34204              return true;
34205            }
34206          } else if (($truthy(normal) && ($truthy(next_line['$start_with?']("."))))) {
34207            if ($truthy($$('BlockTitleRx')['$=~'](next_line))) {
34208              
34209              attributes['$[]=']("title", (($a = $gvars['~']) === nil ? nil : $a['$[]'](1)));
34210              return true;
34211            }
34212          } else if (($not(normal) || ($truthy(next_line['$start_with?']("/"))))) {
34213            if ($truthy(next_line['$start_with?']("//"))) {
34214              if ($eqeq(next_line, "//")) {
34215                return true
34216              } else if (($truthy(normal) && ($truthy(self['$uniform?'](next_line, "/", (ll = next_line.$length())))))) {
34217                if (!$eqeq(ll, 3)) {
34218                  
34219                  reader.$read_lines_until($hash2(["terminator", "skip_first_line", "preserve_last_line", "skip_processing", "context"], {"terminator": next_line, "skip_first_line": true, "preserve_last_line": true, "skip_processing": true, "context": "comment"}));
34220                  return true;
34221                }
34222              } else if (!$truthy(next_line['$start_with?']("///"))) {
34223                return true
34224              }
34225            }
34226          } else if ((($truthy(normal) && ($truthy(next_line['$start_with?'](":")))) && ($truthy($$('AttributeEntryRx')['$=~'](next_line))))) {
34227            
34228            self.$process_attribute_entry(reader, document, attributes, $gvars["~"]);
34229            return true;
34230          }
34231        };
34232        return nil;
34233      }, -4);
34234      $defs(self, '$process_attribute_entries', function $$process_attribute_entries(reader, document, attributes) {
34235        var self = this;
34236
34237        
34238        if (attributes == null) attributes = nil;
34239        reader.$skip_comment_lines();
34240        while ($truthy(self.$process_attribute_entry(reader, document, attributes))) {
34241        
34242          reader.$shift();
34243          reader.$skip_comment_lines();
34244        };
34245      }, -3);
34246      $defs(self, '$process_attribute_entry', function $$process_attribute_entry(reader, document, attributes, match) {
34247        var $a, self = this, value = nil, con = nil, $ret_or_1 = nil, next_line = nil, $ret_or_2 = nil, keep_open = nil;
34248
34249        
34250        if (attributes == null) attributes = nil;
34251        if (match == null) match = nil;
34252        if (($truthy(match) || ($truthy((match = ($truthy(reader['$has_more_lines?']()) ? ($$('AttributeEntryRx').$match(reader.$peek_line())) : (nil))))))) {
34253          
34254          if ($truthy((value = match['$[]'](2))['$nil_or_empty?']())) {
34255            value = ""
34256          } else if ($truthy(value['$end_with?']($$('LINE_CONTINUATION'), $$('LINE_CONTINUATION_LEGACY')))) {
34257            
34258            $a = [value.$slice($rb_minus(value.$length(), 2), 2), value.$slice(0, $rb_minus(value.$length(), 2)).$rstrip()], (con = $a[0]), (value = $a[1]), $a;
34259            while ($truthy(($truthy(($ret_or_1 = reader.$advance())) ? ((next_line = ($truthy(($ret_or_2 = reader.$peek_line())) ? ($ret_or_2) : ("")))['$empty?']()['$!']()) : ($ret_or_1)))) {
34260            
34261              next_line = next_line.$lstrip();
34262              if ($truthy((keep_open = next_line['$end_with?'](con)))) {
34263                next_line = next_line.$slice(0, $rb_minus(next_line.$length(), 2)).$rstrip()
34264              };
34265              value = "" + (value) + (($truthy(value['$end_with?']($$('HARD_LINE_BREAK'))) ? ($$('LF')) : (" "))) + (next_line);
34266              if (!$truthy(keep_open)) {
34267                break
34268              };
34269            };
34270          };
34271          self.$store_attribute(match['$[]'](1), value, document, attributes);
34272          return true;
34273        } else {
34274          return nil
34275        };
34276      }, -3);
34277      $defs(self, '$store_attribute', function $$store_attribute(name, value, doc, attrs) {
34278        var self = this, resolved_value = nil;
34279
34280        
34281        if (doc == null) doc = nil;
34282        if (attrs == null) attrs = nil;
34283        if ($truthy(name['$end_with?']("!"))) {
34284          
34285          name = name.$chop();
34286          value = nil;
34287        } else if ($truthy(name['$start_with?']("!"))) {
34288          
34289          name = name.$slice(1, name.$length());
34290          value = nil;
34291        };
34292        if ($eqeq((name = self.$sanitize_attribute_name(name)), "numbered")) {
34293          name = "sectnums"
34294        } else if ($eqeq(name, "hardbreaks")) {
34295          name = "hardbreaks-option"
34296        } else if ($eqeq(name, "showtitle")) {
34297          self.$store_attribute("notitle", ($truthy(value) ? (nil) : ("")), doc, attrs)
34298        };
34299        if ($truthy(doc)) {
34300          if ($truthy(value)) {
34301            
34302            if ($eqeq(name, "leveloffset")) {
34303              if ($truthy(value['$start_with?']("+"))) {
34304                value = $rb_plus(doc.$attr("leveloffset", 0).$to_i(), value.$slice(1, value.$length()).$to_i()).$to_s()
34305              } else if ($truthy(value['$start_with?']("-"))) {
34306                value = $rb_minus(doc.$attr("leveloffset", 0).$to_i(), value.$slice(1, value.$length()).$to_i()).$to_s()
34307              }
34308            };
34309            if ($truthy((resolved_value = doc.$set_attribute(name, value)))) {
34310              
34311              value = resolved_value;
34312              if ($truthy(attrs)) {
34313                $$$($$('Document'), 'AttributeEntry').$new(name, value).$save_to(attrs)
34314              };
34315            };
34316          } else if (($truthy(doc.$delete_attribute(name)) && ($truthy(attrs)))) {
34317            $$$($$('Document'), 'AttributeEntry').$new(name, value).$save_to(attrs)
34318          }
34319        } else if ($truthy(attrs)) {
34320          $$$($$('Document'), 'AttributeEntry').$new(name, value).$save_to(attrs)
34321        };
34322        return [name, value];
34323      }, -3);
34324      $defs(self, '$resolve_list_marker', function $$resolve_list_marker(list_type, marker, ordinal, validate, reader) {
34325        var self = this;
34326
34327        
34328        if (ordinal == null) ordinal = 0;
34329        if (validate == null) validate = false;
34330        if (reader == null) reader = nil;
34331        
34332        switch (list_type) {
34333          case "ulist":
34334            return marker
34335          case "olist":
34336            return self.$resolve_ordered_list_marker(marker, ordinal, validate, reader)['$[]'](0)
34337          default:
34338            return "<1>"
34339        };
34340      }, -3);
34341      $defs(self, '$resolve_ordered_list_marker', function $$resolve_ordered_list_marker(marker, ordinal, validate, reader) {
34342        var self = this, style = nil, expected = nil, actual = nil;
34343
34344        
34345        if (ordinal == null) ordinal = 0;
34346        if (validate == null) validate = false;
34347        if (reader == null) reader = nil;
34348        if ($truthy(marker['$start_with?']("."))) {
34349          return [marker]
34350        };
34351        
34352        switch ((style = $send($$('ORDERED_LIST_STYLES'), 'find', [], function $$30(s){
34353          
34354          if (s == null) s = nil;
34355          return $$('OrderedListMarkerRxMap')['$[]'](s)['$match?'](marker);}))) {
34356          case "arabic":
34357            
34358            if ($truthy(validate)) {
34359              
34360              expected = $rb_plus(ordinal, 1);
34361              actual = marker.$to_i();
34362            };
34363            marker = "1.";
34364            break;
34365          case "loweralpha":
34366            
34367            if ($truthy(validate)) {
34368              
34369              expected = $rb_plus("a"['$[]'](0).$ord(), ordinal).$chr();
34370              actual = marker.$chop();
34371            };
34372            marker = "a.";
34373            break;
34374          case "upperalpha":
34375            
34376            if ($truthy(validate)) {
34377              
34378              expected = $rb_plus("A"['$[]'](0).$ord(), ordinal).$chr();
34379              actual = marker.$chop();
34380            };
34381            marker = "A.";
34382            break;
34383          case "lowerroman":
34384            
34385            if ($truthy(validate)) {
34386              
34387              expected = $$('Helpers').$int_to_roman($rb_plus(ordinal, 1)).$downcase();
34388              actual = marker.$chop();
34389            };
34390            marker = "i)";
34391            break;
34392          case "upperroman":
34393            
34394            if ($truthy(validate)) {
34395              
34396              expected = $$('Helpers').$int_to_roman($rb_plus(ordinal, 1));
34397              actual = marker.$chop();
34398            };
34399            marker = "I)";
34400            break;
34401          default:
34402            nil
34403        };
34404        if (($truthy(validate) && ($neqeq(expected, actual)))) {
34405          self.$logger().$warn(self.$message_with_context("list item index: expected " + (expected) + ", got " + (actual), $hash2(["source_location"], {"source_location": reader.$cursor()})))
34406        };
34407        return [marker, style];
34408      }, -2);
34409      $defs(self, '$is_sibling_list_item?', function $Parser_is_sibling_list_item$ques$31(line, list_type, sibling_trait) {
34410        var $a, self = this, $ret_or_1 = nil;
34411
34412        if ($eqeqeq($$$('Regexp'), sibling_trait)) {
34413          return sibling_trait['$match?'](line)
34414        } else if ($truthy(($ret_or_1 = $$('ListRxMap')['$[]'](list_type)['$=~'](line)))) {
34415          return sibling_trait['$=='](self.$resolve_list_marker(list_type, (($a = $gvars['~']) === nil ? nil : $a['$[]'](1))))
34416        } else {
34417          return $ret_or_1
34418        }
34419      });
34420      $defs(self, '$parse_table', function $$parse_table(table_reader, parent, attributes) {
34421        var $a, $b, $c, self = this, table = nil, colspecs = nil, explicit_colspecs = nil, skipped = nil, $ret_or_1 = nil, implicit_header = nil, parser_ctx = nil, format = nil, loop_idx = nil, implicit_header_boundary = nil, line = nil, beyond_first = nil, next_cellspec = nil, m = nil, pre_match = nil, post_match = nil, cell_text = nil, $logical_op_recvr_tmp_2 = nil;
34422
34423        
34424        table = $$('Table').$new(parent, attributes);
34425        if (($truthy(attributes['$key?']("cols")) && ($not((colspecs = self.$parse_colspecs(attributes['$[]']("cols")))['$empty?']())))) {
34426          
34427          table.$create_columns(colspecs);
34428          explicit_colspecs = true;
34429        };
34430        skipped = ($truthy(($ret_or_1 = table_reader.$skip_blank_lines())) ? ($ret_or_1) : (0));
34431        if ($truthy(attributes['$[]']("header-option"))) {
34432          table['$has_header_option='](true)
34433        } else if (($eqeq(skipped, 0) && ($not(attributes['$[]']("noheader-option"))))) {
34434          
34435          table['$has_header_option=']("implicit");
34436          implicit_header = true;
34437        };
34438        parser_ctx = $$$($$('Table'), 'ParserContext').$new(table_reader, table, attributes);
34439        $a = [parser_ctx.$format(), -1, nil], (format = $a[0]), (loop_idx = $a[1]), (implicit_header_boundary = $a[2]), $a;
34440        while ($truthy((line = table_reader.$read_line()))) {
34441        
34442          if (($truthy((beyond_first = $rb_gt((loop_idx = $rb_plus(loop_idx, 1)), 0))) && ($truthy(line['$empty?']())))) {
34443            
34444            line = nil;
34445            if ($truthy(implicit_header_boundary)) {
34446              implicit_header_boundary = $rb_plus(implicit_header_boundary, 1)
34447            };
34448          } else if ($eqeq(format, "psv")) {
34449            if ($truthy(parser_ctx['$starts_with_delimiter?'](line))) {
34450              
34451              line = line.$slice(1, line.$length());
34452              parser_ctx.$close_open_cell();
34453              if ($truthy(implicit_header_boundary)) {
34454                implicit_header_boundary = nil
34455              };
34456            } else {
34457              
34458              $b = self.$parse_cellspec(line, "start", parser_ctx.$delimiter()), $a = $to_ary($b), (next_cellspec = ($a[0] == null ? nil : $a[0])), (line = ($a[1] == null ? nil : $a[1])), $b;
34459              if ($truthy(next_cellspec)) {
34460                
34461                parser_ctx.$close_open_cell(next_cellspec);
34462                if ($truthy(implicit_header_boundary)) {
34463                  implicit_header_boundary = nil
34464                };
34465              } else if (($truthy(implicit_header_boundary) && ($eqeq(implicit_header_boundary, loop_idx)))) {
34466                table['$has_header_option=']((implicit_header = (implicit_header_boundary = nil)))
34467              };
34468            }
34469          };
34470          if (!$truthy(beyond_first)) {
34471            
34472            table_reader.$mark();
34473            if ($truthy(implicit_header)) {
34474              if (($truthy(table_reader['$has_more_lines?']()) && ($truthy(table_reader.$peek_line()['$empty?']())))) {
34475                implicit_header_boundary = 1
34476              } else {
34477                table['$has_header_option=']((implicit_header = nil))
34478              }
34479            };
34480          };
34481          $a = false;while ($a || $truthy(true)) {$a = false;
34482          if (($truthy(line) && ($truthy((m = parser_ctx.$match_delimiter(line)))))) {
34483              
34484              $b = [m.$pre_match(), m.$post_match()], (pre_match = $b[0]), (post_match = $b[1]), $b;
34485              if ($eqeqeq("csv", ($ret_or_1 = format))) {
34486                
34487                if ($truthy(parser_ctx['$buffer_has_unclosed_quotes?'](pre_match))) {
34488                  
34489                  parser_ctx.$skip_past_delimiter(pre_match);
34490                  if ($truthy((line = post_match)['$empty?']())) {
34491                    break
34492                  };
34493                  $a = true;continue;
34494                };
34495                parser_ctx['$buffer=']("" + (parser_ctx.$buffer()) + (pre_match));
34496              } else if ($eqeqeq("dsv", $ret_or_1)) {
34497                
34498                if ($truthy(pre_match['$end_with?']("\\"))) {
34499                  
34500                  parser_ctx.$skip_past_escaped_delimiter(pre_match);
34501                  if ($truthy((line = post_match)['$empty?']())) {
34502                    
34503                    parser_ctx['$buffer=']("" + (parser_ctx.$buffer()) + ($$('LF')));
34504                    parser_ctx.$keep_cell_open();
34505                    break;
34506                  };
34507                  $a = true;continue;
34508                };
34509                parser_ctx['$buffer=']("" + (parser_ctx.$buffer()) + (pre_match));
34510              } else {
34511                
34512                if ($truthy(pre_match['$end_with?']("\\"))) {
34513                  
34514                  parser_ctx.$skip_past_escaped_delimiter(pre_match);
34515                  if ($truthy((line = post_match)['$empty?']())) {
34516                    
34517                    parser_ctx['$buffer=']("" + (parser_ctx.$buffer()) + ($$('LF')));
34518                    parser_ctx.$keep_cell_open();
34519                    break;
34520                  };
34521                  $a = true;continue;
34522                };
34523                $c = self.$parse_cellspec(pre_match), $b = $to_ary($c), (next_cellspec = ($b[0] == null ? nil : $b[0])), (cell_text = ($b[1] == null ? nil : $b[1])), $c;
34524                parser_ctx.$push_cellspec(next_cellspec);
34525                parser_ctx['$buffer=']("" + (parser_ctx.$buffer()) + (cell_text));
34526              };
34527              if ($truthy((line = post_match)['$empty?']())) {
34528                line = nil
34529              };
34530              parser_ctx.$close_cell();
34531            } else {
34532              
34533              parser_ctx['$buffer=']("" + (parser_ctx.$buffer()) + (line) + ($$('LF')));
34534              
34535              switch (format) {
34536                case "csv":
34537                  if ($truthy(parser_ctx['$buffer_has_unclosed_quotes?']())) {
34538                    
34539                    if (($truthy(implicit_header_boundary) && ($eqeq(loop_idx, 0)))) {
34540                      table['$has_header_option=']((implicit_header = (implicit_header_boundary = nil)))
34541                    };
34542                    parser_ctx.$keep_cell_open();
34543                  } else {
34544                    parser_ctx.$close_cell(true)
34545                  }
34546                  break;
34547                case "dsv":
34548                  parser_ctx.$close_cell(true)
34549                  break;
34550                default:
34551                  parser_ctx.$keep_cell_open()
34552              };
34553              break;
34554            }
34555          };
34556          if ($truthy(parser_ctx['$cell_open?']())) {
34557            if (!$truthy(table_reader['$has_more_lines?']())) {
34558              parser_ctx.$close_cell(true)
34559            }
34560          } else if ($truthy(($ret_or_1 = table_reader.$skip_blank_lines()))) {
34561            $ret_or_1
34562          } else {
34563            break
34564          };
34565        };
34566        if (!($eqeq((($logical_op_recvr_tmp_2 = table.$attributes()), ($truthy(($ret_or_1 = $logical_op_recvr_tmp_2['$[]']("colcount"))) ? ($ret_or_1) : (($a = ["colcount", table.$columns().$size()], $send($logical_op_recvr_tmp_2, '[]=', $a), $a[$a.length - 1])))), 0) || ($truthy(explicit_colspecs)))) {
34567          table.$assign_column_widths()
34568        };
34569        if ($truthy(implicit_header)) {
34570          table['$has_header_option='](true)
34571        };
34572        table.$partition_header_footer(attributes);
34573        return table;
34574      });
34575      $defs(self, '$parse_colspecs', function $$parse_colspecs(records) {
34576        var specs = nil;
34577
34578        
34579        if ($truthy(records['$include?'](" "))) {
34580          records = records.$delete(" ")
34581        };
34582        if ($eqeq(records, records.$to_i().$to_s())) {
34583          return $send($$$('Array'), 'new', [records.$to_i()], function $$32(){
34584            return $hash2(["width"], {"width": 1})})
34585        };
34586        specs = [];
34587        $send(($truthy(records['$include?'](",")) ? (records.$split(",", -1)) : (records.$split(";", -1))), 'each', [], function $$33(record){var $a, $b, m = nil, spec = nil, colspec = nil, rowspec = nil, width = nil;
34588
34589          
34590          if (record == null) record = nil;
34591          if ($truthy(record['$empty?']())) {
34592            return specs['$<<']($hash2(["width"], {"width": 1}))
34593          } else if ($truthy((m = $$('ColumnSpecRx').$match(record)))) {
34594            
34595            spec = $hash2([], {});
34596            if ($truthy(m['$[]'](2))) {
34597              
34598              $b = m['$[]'](2).$split("."), $a = $to_ary($b), (colspec = ($a[0] == null ? nil : $a[0])), (rowspec = ($a[1] == null ? nil : $a[1])), $b;
34599              if (($not(colspec['$nil_or_empty?']()) && ($truthy($$('TableCellHorzAlignments')['$key?'](colspec))))) {
34600                spec['$[]=']("halign", $$('TableCellHorzAlignments')['$[]'](colspec))
34601              };
34602              if (($not(rowspec['$nil_or_empty?']()) && ($truthy($$('TableCellVertAlignments')['$key?'](rowspec))))) {
34603                spec['$[]=']("valign", $$('TableCellVertAlignments')['$[]'](rowspec))
34604              };
34605            };
34606            if ($truthy((width = m['$[]'](3)))) {
34607              spec['$[]=']("width", ($eqeq(width, "~") ? (-1) : (width.$to_i())))
34608            } else {
34609              spec['$[]=']("width", 1)
34610            };
34611            if (($truthy(m['$[]'](4)) && ($truthy($$('TableCellStyles')['$key?'](m['$[]'](4)))))) {
34612              spec['$[]=']("style", $$('TableCellStyles')['$[]'](m['$[]'](4)))
34613            };
34614            if ($truthy(m['$[]'](1))) {
34615              return $send((1), 'upto', [m['$[]'](1).$to_i()], function $$34(){
34616                return specs['$<<'](spec.$merge())})
34617            } else {
34618              return specs['$<<'](spec)
34619            };
34620          } else {
34621            return nil
34622          };});
34623        return specs;
34624      });
34625      $defs(self, '$parse_cellspec', function $$parse_cellspec(line, pos, delimiter) {
34626        var $a, $b, m = nil, rest = nil, spec_part = nil, _ = nil, spec = nil, colspec = nil, rowspec = nil;
34627
34628        
34629        if (pos == null) pos = "end";
34630        if (delimiter == null) delimiter = nil;
34631        $a = [nil, ""], (m = $a[0]), (rest = $a[1]), $a;
34632        if ($eqeq(pos, "start")) {
34633          if ($truthy(line['$include?'](delimiter))) {
34634            
34635            $b = line.$partition(delimiter), $a = $to_ary($b), (spec_part = ($a[0] == null ? nil : $a[0])), (_ = ($a[1] == null ? nil : $a[1])), (rest = ($a[2] == null ? nil : $a[2])), $b;
34636            if ($truthy((m = $$('CellSpecStartRx').$match(spec_part)))) {
34637              if ($truthy(m['$[]'](0)['$empty?']())) {
34638                return [$hash2([], {}), rest]
34639              }
34640            } else {
34641              return [nil, line]
34642            };
34643          } else {
34644            return [nil, line]
34645          }
34646        } else if ($truthy((m = $$('CellSpecEndRx').$match(line)))) {
34647          
34648          if ($truthy(m['$[]'](0).$lstrip()['$empty?']())) {
34649            return [$hash2([], {}), line.$rstrip()]
34650          };
34651          rest = m.$pre_match();
34652        } else {
34653          return [$hash2([], {}), line]
34654        };
34655        spec = $hash2([], {});
34656        if ($truthy(m['$[]'](1))) {
34657          
34658          $b = m['$[]'](1).$split("."), $a = $to_ary($b), (colspec = ($a[0] == null ? nil : $a[0])), (rowspec = ($a[1] == null ? nil : $a[1])), $b;
34659          colspec = ($truthy(colspec['$nil_or_empty?']()) ? (1) : (colspec.$to_i()));
34660          rowspec = ($truthy(rowspec['$nil_or_empty?']()) ? (1) : (rowspec.$to_i()));
34661          
34662          switch (m['$[]'](2)) {
34663            case "+":
34664              
34665              if (!$eqeq(colspec, 1)) {
34666                spec['$[]=']("colspan", colspec)
34667              };
34668              if (!$eqeq(rowspec, 1)) {
34669                spec['$[]=']("rowspan", rowspec)
34670              };
34671              break;
34672            case "*":
34673              if (!$eqeq(colspec, 1)) {
34674                spec['$[]=']("repeatcol", colspec)
34675              }
34676              break;
34677            default:
34678              nil
34679          };
34680        };
34681        if ($truthy(m['$[]'](3))) {
34682          
34683          $b = m['$[]'](3).$split("."), $a = $to_ary($b), (colspec = ($a[0] == null ? nil : $a[0])), (rowspec = ($a[1] == null ? nil : $a[1])), $b;
34684          if (($not(colspec['$nil_or_empty?']()) && ($truthy($$('TableCellHorzAlignments')['$key?'](colspec))))) {
34685            spec['$[]=']("halign", $$('TableCellHorzAlignments')['$[]'](colspec))
34686          };
34687          if (($not(rowspec['$nil_or_empty?']()) && ($truthy($$('TableCellVertAlignments')['$key?'](rowspec))))) {
34688            spec['$[]=']("valign", $$('TableCellVertAlignments')['$[]'](rowspec))
34689          };
34690        };
34691        if (($truthy(m['$[]'](4)) && ($truthy($$('TableCellStyles')['$key?'](m['$[]'](4)))))) {
34692          spec['$[]=']("style", $$('TableCellStyles')['$[]'](m['$[]'](4)))
34693        };
34694        return [spec, rest];
34695      }, -2);
34696      $defs(self, '$parse_style_attribute', function $$parse_style_attribute(attributes, reader) {
34697        var $a, self = this, raw_style = nil, name = nil, accum = nil, parsed_attrs = nil, parsed_style = nil, existing_role = nil;
34698
34699        
34700        if (reader == null) reader = nil;
34701        if ((($truthy((raw_style = attributes['$[]'](1))) && ($not(raw_style['$include?'](" ")))) && ($truthy($$('Compliance').$shorthand_property_syntax())))) {
34702          
34703          name = nil;
34704          accum = "";
34705          parsed_attrs = $hash2([], {});
34706          $send(raw_style, 'each_char', [], function $$35(c){var self = $$35.$$s == null ? this : $$35.$$s;
34707
34708            
34709            if (c == null) c = nil;
34710            
34711            switch (c) {
34712              case ".":
34713                
34714                self.$yield_buffered_attribute(parsed_attrs, name, accum, reader);
34715                accum = "";
34716                return (name = "role");
34717              case "#":
34718                
34719                self.$yield_buffered_attribute(parsed_attrs, name, accum, reader);
34720                accum = "";
34721                return (name = "id");
34722              case "%":
34723                
34724                self.$yield_buffered_attribute(parsed_attrs, name, accum, reader);
34725                accum = "";
34726                return (name = "option");
34727              default:
34728                return (accum = $rb_plus(accum, c))
34729            };}, {$$s: self});
34730          if ($truthy(name)) {
34731            
34732            self.$yield_buffered_attribute(parsed_attrs, name, accum, reader);
34733            if ($truthy((parsed_style = parsed_attrs['$[]']("style")))) {
34734              attributes['$[]=']("style", parsed_style)
34735            };
34736            if ($truthy(parsed_attrs['$key?']("id"))) {
34737              attributes['$[]=']("id", parsed_attrs['$[]']("id"))
34738            };
34739            if ($truthy(parsed_attrs['$key?']("role"))) {
34740              attributes['$[]=']("role", ($truthy((existing_role = attributes['$[]']("role"))['$nil_or_empty?']()) ? (parsed_attrs['$[]']("role").$join(" ")) : ("" + (existing_role) + " " + (parsed_attrs['$[]']("role").$join(" ")))))
34741            };
34742            if ($truthy(parsed_attrs['$key?']("option"))) {
34743              $send(parsed_attrs['$[]']("option"), 'each', [], function $$36(opt){var $a;
34744
34745                
34746                if (opt == null) opt = nil;
34747                return ($a = ["" + (opt) + "-option", ""], $send(attributes, '[]=', $a), $a[$a.length - 1]);})
34748            };
34749            return parsed_style;
34750          } else {
34751            return ($a = ["style", raw_style], $send(attributes, '[]=', $a), $a[$a.length - 1])
34752          };
34753        } else {
34754          return ($a = ["style", raw_style], $send(attributes, '[]=', $a), $a[$a.length - 1])
34755        };
34756      }, -2);
34757      $defs(self, '$yield_buffered_attribute', function $$yield_buffered_attribute(attrs, name, value, reader) {
34758        var $a, self = this, $ret_or_1 = nil;
34759
34760        
34761        if ($truthy(name)) {
34762          if ($truthy(value['$empty?']())) {
34763            if ($truthy(reader)) {
34764              self.$logger().$warn(self.$message_with_context("invalid empty " + (name) + " detected in style attribute", $hash2(["source_location"], {"source_location": reader.$cursor_at_prev_line()})))
34765            } else {
34766              self.$logger().$warn("invalid empty " + (name) + " detected in style attribute")
34767            }
34768          } else if ($eqeq(name, "id")) {
34769            
34770            if ($truthy(attrs['$key?']("id"))) {
34771              if ($truthy(reader)) {
34772                self.$logger().$warn(self.$message_with_context("multiple ids detected in style attribute", $hash2(["source_location"], {"source_location": reader.$cursor_at_prev_line()})))
34773              } else {
34774                self.$logger().$warn("multiple ids detected in style attribute")
34775              }
34776            };
34777            attrs['$[]='](name, value);
34778          } else {
34779            ($truthy(($ret_or_1 = attrs['$[]'](name))) ? ($ret_or_1) : (($a = [name, []], $send(attrs, '[]=', $a), $a[$a.length - 1])))['$<<'](value)
34780          }
34781        } else if (!$truthy(value['$empty?']())) {
34782          attrs['$[]=']("style", value)
34783        };
34784        return nil;
34785      });
34786      $defs(self, '$adjust_indentation!', function $Parser_adjust_indentation$excl$37(lines, indent_size, tab_size) {
34787        var full_tab_space = nil, block_indent = nil, new_block_indent = nil;
34788
34789        
34790        if (indent_size == null) indent_size = 0;
34791        if (tab_size == null) tab_size = 0;
34792        if ($truthy(lines['$empty?']())) {
34793          return nil
34794        };
34795        if (($truthy($rb_gt(tab_size, 0)) && ($truthy($send(lines, 'any?', [], function $$38(line){
34796          
34797          if (line == null) line = nil;
34798          return line['$include?']($$('TAB'));}))))) {
34799          
34800          full_tab_space = $rb_times(" ", tab_size);
34801          $send(lines, 'map!', [], function $$39(line){var tab_idx = nil, leading_tabs = nil, spaces_added = nil, idx = nil, result = nil;
34802
34803            
34804            if (line == null) line = nil;
34805            if (($truthy(line['$empty?']()) || ($truthy((tab_idx = line.$index($$('TAB')))['$nil?']())))) {
34806              return line
34807            } else {
34808              
34809              if ($eqeq(tab_idx, 0)) {
34810                
34811                leading_tabs = 0;
34812                (function(){try { var $t_break = $thrower('break'); return $send(line, 'each_byte', [], function $$40(b){
34813                  
34814                  if (b == null) b = nil;
34815                  if (!$eqeq(b, 9)) {
34816                    $t_break.$throw()
34817                  };
34818                  return (leading_tabs = $rb_plus(leading_tabs, 1));})} catch($e) {
34819                  if ($e === $t_break) return $e.$v;
34820                  throw $e;
34821                }})();
34822                line = "" + ($rb_times(full_tab_space, leading_tabs)) + (line.$slice(leading_tabs, line.$length()));
34823                if (!$truthy(line['$include?']($$('TAB')))) {
34824                  return line
34825                };
34826              };
34827              spaces_added = 0;
34828              idx = 0;
34829              result = "";
34830              $send(line, 'each_char', [], function $$41(c){var offset = nil, spaces = nil;
34831
34832                
34833                if (c == null) c = nil;
34834                if ($eqeq(c, $$('TAB'))) {
34835                  if ($eqeq((offset = $rb_plus(idx, spaces_added))['$%'](tab_size), 0)) {
34836                    
34837                    spaces_added = $rb_plus(spaces_added, $rb_minus(tab_size, 1));
34838                    result = $rb_plus(result, full_tab_space);
34839                  } else {
34840                    
34841                    if (!$eqeq((spaces = $rb_minus(tab_size, offset['$%'](tab_size))), 1)) {
34842                      spaces_added = $rb_plus(spaces_added, $rb_minus(spaces, 1))
34843                    };
34844                    result = $rb_plus(result, $rb_times(" ", spaces));
34845                  }
34846                } else {
34847                  result = $rb_plus(result, c)
34848                };
34849                return (idx = $rb_plus(idx, 1));});
34850              return result;
34851            };});
34852        };
34853        if ($truthy($rb_lt(indent_size, 0))) {
34854          return nil
34855        };
34856        block_indent = nil;
34857        (function(){try { var $t_break = $thrower('break'); return $send(lines, 'each', [], function $$42(line){var line_indent = nil;
34858
34859          
34860          if (line == null) line = nil;
34861          if ($truthy(line['$empty?']())) {
34862            return nil
34863          };
34864          if ($eqeq((line_indent = $rb_minus(line.$length(), line.$lstrip().$length())), 0)) {
34865            
34866            block_indent = nil;
34867            $t_break.$throw();
34868          };
34869          if (($truthy(block_indent) && ($truthy($rb_lt(block_indent, line_indent))))) {
34870            return nil
34871          } else {
34872            return (block_indent = line_indent)
34873          };})} catch($e) {
34874          if ($e === $t_break) return $e.$v;
34875          throw $e;
34876        }})();
34877        if ($eqeq(indent_size, 0)) {
34878          if ($truthy(block_indent)) {
34879            $send(lines, 'map!', [], function $$43(line){
34880              
34881              if (line == null) line = nil;
34882              if ($truthy(line['$empty?']())) {
34883                return line
34884              } else {
34885                
34886                return line.$slice(block_indent, line.$length());
34887              };})
34888          }
34889        } else {
34890          
34891          new_block_indent = $rb_times(" ", indent_size);
34892          if ($truthy(block_indent)) {
34893            $send(lines, 'map!', [], function $$44(line){
34894              
34895              if (line == null) line = nil;
34896              if ($truthy(line['$empty?']())) {
34897                return line
34898              } else {
34899                return $rb_plus(new_block_indent, line.$slice(block_indent, line.$length()))
34900              };})
34901          } else {
34902            $send(lines, 'map!', [], function $$45(line){
34903              
34904              if (line == null) line = nil;
34905              if ($truthy(line['$empty?']())) {
34906                return line
34907              } else {
34908                return $rb_plus(new_block_indent, line)
34909              };})
34910          };
34911        };
34912        return nil;
34913      }, -2);
34914      $defs(self, '$uniform?', function $Parser_uniform$ques$46(str, chr, len) {
34915        
34916        return str.$count(chr)['$=='](len)
34917      });
34918      return $defs(self, '$sanitize_attribute_name', function $$sanitize_attribute_name(name) {
34919        
34920        return name.$gsub($$('InvalidAttributeNameCharsRx'), "").$downcase()
34921      });
34922    })($nesting[0], null, $nesting)
34923  })($nesting[0], $nesting)
34924};
34925
34926Opal.modules["asciidoctor/path_resolver"] = function(Opal) {/* Generated by Opal 1.7.3 */
34927  "use strict";
34928  var $module = Opal.module, $klass = Opal.klass, $const_set = Opal.const_set, $truthy = Opal.truthy, $hash2 = Opal.hash2, $def = Opal.def, $eqeq = Opal.eqeq, $alias = Opal.alias, $rb_plus = Opal.rb_plus, $to_ary = Opal.to_ary, $send = Opal.send, $not = Opal.not, $neqeq = Opal.neqeq, $rb_gt = Opal.rb_gt, $gvars = Opal.gvars, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$;
34929
34930  Opal.add_stubs('include,attr_accessor,root?,posixify,expand_path,pwd,start_with?,==,match?,absolute_path?,+,length,descends_from?,slice,to_s,relative_path_from,new,include?,tr,partition_path,each,pop,<<,join_path,[],web_root?,unc?,index,split,delete,[]=,join,raise,!,fetch,warn,logger,empty?,nil_or_empty?,chomp,!=,>,size,extract_uri_prefix,end_with?,gsub,private,=~');
34931  return (function($base, $parent_nesting) {
34932    var self = $module($base, 'Asciidoctor');
34933
34934    var $nesting = [self].concat($parent_nesting);
34935
34936    return (function($base, $super, $parent_nesting) {
34937      var self = $klass($base, $super, 'PathResolver');
34938
34939      var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype;
34940
34941      $proto.file_separator = $proto._partition_path_web = $proto._partition_path_sys = $proto.working_dir = nil;
34942      
34943      self.$include($$('Logging'));
34944      $const_set($nesting[0], 'DOT', ".");
34945      $const_set($nesting[0], 'DOT_DOT', "..");
34946      $const_set($nesting[0], 'DOT_SLASH', "./");
34947      $const_set($nesting[0], 'SLASH', "/");
34948      $const_set($nesting[0], 'BACKSLASH', "\\");
34949      $const_set($nesting[0], 'DOUBLE_SLASH', "//");
34950      $const_set($nesting[0], 'URI_CLASSLOADER', "uri:classloader:");
34951      $const_set($nesting[0], 'WindowsRootRx', /^(?:[a-zA-Z]:)?[\\\/]/);
34952      self.$attr_accessor("file_separator");
34953      self.$attr_accessor("working_dir");
34954      
34955      $def(self, '$initialize', function $$initialize(file_separator, working_dir) {
34956        var self = this, $ret_or_1 = nil, $ret_or_2 = nil;
34957
34958        
34959        if (file_separator == null) file_separator = nil;
34960        if (working_dir == null) working_dir = nil;
34961        self.file_separator = ($truthy(($ret_or_1 = ($truthy(($ret_or_2 = file_separator)) ? ($ret_or_2) : ($$$($$$('File'), 'ALT_SEPARATOR'))))) ? ($ret_or_1) : ($$$($$$('File'), 'SEPARATOR')));
34962        self.working_dir = ($truthy(working_dir) ? (($truthy(self['$root?'](working_dir)) ? (self.$posixify(working_dir)) : ($$$('File').$expand_path(working_dir)))) : ($$$('Dir').$pwd())
34962);
34963        self._partition_path_sys = $hash2([], {});
34964        return (self._partition_path_web = $hash2([], {}));
34965      }, -1);
34966      
34967      $def(self, '$absolute_path?', function $PathResolver_absolute_path$ques$1(path) {
34968        var self = this, $ret_or_1 = nil, $ret_or_2 = nil;
34969
34970        if ($truthy(($ret_or_1 = path['$start_with?']($$('SLASH'))))) {
34971          return $ret_or_1
34972        } else {
34973          
34974          if ($truthy(($ret_or_2 = self.file_separator['$==']($$('BACKSLASH'))))) {
34975            
34976            return $$('WindowsRootRx')['$match?'](path);
34977          } else {
34978            return $ret_or_2
34979          };
34980        }
34981      });
34982      if (($eqeq($$('RUBY_ENGINE'), "opal") && ($eqeq($$$('JAVASCRIPT_IO_MODULE'), "xmlhttprequest")))) {
34983        
34984        $def(self, '$root?', function $PathResolver_root$ques$2(path) {
34985          var self = this, $ret_or_1 = nil;
34986
34987          if ($truthy(($ret_or_1 = self['$absolute_path?'](path)))) {
34988            return $ret_or_1
34989          } else {
34990            
34991            return path['$start_with?']("file://", "http://", "https://");
34992          }
34993        })
34994      } else if ($eqeq($$$('RUBY_ENGINE'), "jruby")) {
34995        
34996        $def(self, '$root?', function $PathResolver_root$ques$3(path) {
34997          var self = this, $ret_or_1 = nil;
34998
34999          if ($truthy(($ret_or_1 = self['$absolute_path?'](path)))) {
35000            return $ret_or_1
35001          } else {
35002            
35003            return path['$start_with?']($$('URI_CLASSLOADER'));
35004          }
35005        })
35006      } else {
35007        $alias(self, "root?", "absolute_path?")
35008      };
35009      
35010      $def(self, '$unc?', function $PathResolver_unc$ques$4(path) {
35011        
35012        return path['$start_with?']($$('DOUBLE_SLASH'))
35013      });
35014      
35015      $def(self, '$web_root?', function $PathResolver_web_root$ques$5(path) {
35016        
35017        return path['$start_with?']($$('SLASH'))
35018      });
35019      
35020      $def(self, '$descends_from?', function $PathResolver_descends_from$ques$6(path, base) {
35021        var $ret_or_1 = nil;
35022
35023        if ($eqeq(base, path)) {
35024          return 0
35025        } else if ($eqeq(base, $$('SLASH'))) {
35026          if ($truthy(($ret_or_1 = path['$start_with?']($$('SLASH'))))) {
35027            return 1
35028          } else {
35029            return $ret_or_1
35030          }
35031        } else if ($truthy(($ret_or_1 = path['$start_with?']($rb_plus(base, $$('SLASH')))))) {
35032          
35033          return $rb_plus(base.$length(), 1);
35034        } else {
35035          return $ret_or_1
35036        }
35037      });
35038      
35039      $def(self, '$relative_path', function $$relative_path(path, base) {
35040        var self = this, offset = nil;
35041
35042        if ($truthy(self['$root?'](path))) {
35043          if ($truthy((offset = self['$descends_from?'](path, base)))) {
35044            return path.$slice(offset, path.$length())
35045          } else {
35046            
35047            try {
35048              return $$('Pathname').$new(path).$relative_path_from($$('Pathname').$new(base)).$to_s()
35049            } catch ($err) {
35050              if (Opal.rescue($err, [$$('StandardError')])) {
35051                try {
35052                  return path
35053                } finally { Opal.pop_exception(); }
35054              } else { throw $err; }
35055            };
35056          }
35057        } else {
35058          return path
35059        }
35060      });
35061      
35062      $def(self, '$posixify', function $$posixify(path) {
35063        var self = this;
35064
35065        if ($truthy(path)) {
35066          if (($eqeq(self.file_separator, $$('BACKSLASH')) && ($truthy(path['$include?']($$('BACKSLASH')))))) {
35067            
35068            return path.$tr($$('BACKSLASH'), $$('SLASH'));
35069          } else {
35070            return path
35071          }
35072        } else {
35073          return ""
35074        }
35075      });
35076      $alias(self, "posixfy", "posixify");
35077      
35078      $def(self, '$expand_path', function $$expand_path(path) {
35079        var $a, $b, self = this, path_segments = nil, path_root = nil, resolved_segments = nil;
35080
35081        
35082        $b = self.$partition_path(path), $a = $to_ary($b), (path_segments = ($a[0] == null ? nil : $a[0])), (path_root = ($a[1] == null ? nil : $a[1])), $b;
35083        if ($truthy(path['$include?']($$('DOT_DOT')))) {
35084          
35085          resolved_segments = [];
35086          $send(path_segments, 'each', [], function $$7(segment){
35087            
35088            if (segment == null) segment = nil;
35089            if ($eqeq(segment, $$('DOT_DOT'))) {
35090              return resolved_segments.$pop()
35091            } else {
35092              return resolved_segments['$<<'](segment)
35093            };});
35094          return self.$join_path(resolved_segments, path_root);
35095        } else {
35096          return self.$join_path(path_segments, path_root)
35097        };
35098      });
35099      
35100      $def(self, '$partition_path', function $$partition_path(path, web) {
35101        var $a, self = this, result = nil, cache = nil, posix_path = nil, root = nil, path_segments = nil;
35102
35103        
35104        if (web == null) web = nil;
35105        if ($truthy((result = (cache = ($truthy(web) ? (self._partition_path_web) : (self._partition_path_sys)))['$[]'](path))
35105)) {
35106          return result
35107        };
35108        posix_path = self.$posixify(path);
35109        if ($truthy(web)) {
35110          if ($truthy(self['$web_root?'](posix_path))) {
35111            root = $$('SLASH')
35112          } else if ($truthy(posix_path['$start_with?']($$('DOT_SLASH')))) {
35113            root = $$('DOT_SLASH')
35114          }
35115        } else if ($truthy(self['$root?'](posix_path))) {
35116          if ($truthy(self['$unc?'](posix_path))) {
35117            root = $$('DOUBLE_SLASH')
35118          } else if ($truthy(posix_path['$start_with?']($$('SLASH')))) {
35119            root = $$('SLASH')
35120          } else if ($truthy(posix_path['$start_with?']($$('URI_CLASSLOADER')))) {
35121            root = posix_path.$slice(0, $$('URI_CLASSLOADER').$length())
35122          } else {
35123            root = posix_path.$slice(0, $rb_plus(posix_path.$index($$('SLASH')), 1))
35124          }
35125        } else if ($truthy(posix_path['$start_with?']($$('DOT_SLASH')))) {
35126          root = $$('DOT_SLASH')
35127        };
35128        path_segments = ($truthy(root) ? (posix_path.$slice(root.$length(), posix_path.$length())) : (posix_path)).$split($$('SLASH'));
35129        path_segments.$delete($$('DOT'));
35130        return ($a = [path, [path_segments, root]], $send(cache, '[]=', $a), $a[$a.length - 1]);
35131      }, -2);
35132      
35133      $def(self, '$join_path', function $$join_path(segments, root) {
35134        
35135        
35136        if (root == null) root = nil;
35137        if ($truthy(root)) {
35138          return "" + (root) + (segments.$join($$('SLASH')))
35139        } else {
35140          
35141          return segments.$join($$('SLASH'));
35142        };
35143      }, -2);
35144      
35145      $def(self, '$system_path', function $$system_path(target, start, jail, opts) {
35146        var $a, $b, self = this, target_path = nil, $ret_or_1 = nil, target_segments = nil, jail_segments = nil, jail_root = nil, recheck = nil, start_segments = nil, start_root = nil, resolved_segments = nil, unresolved_segments = nil, warned = nil;
35147
35148        
35149        if (start == null) start = nil;
35150        if (jail == null) jail = nil;
35151        if (opts == null) opts = $hash2([], {});
35152        if ($truthy(jail)) {
35153          
35154          if (!$truthy(self['$root?'](jail))) {
35155            self.$raise($$$('SecurityError'), "Jail is not an absolute path: " + (jail))
35156          };
35157          jail = self.$posixify(jail);
35158        };
35159        if ($truthy(target)) {
35160          if ($truthy(self['$root?'](target))) {
35161            
35162            target_path = self.$expand_path(target);
35163            if (($truthy(jail) && ($not(self['$descends_from?'](target_path, jail))))) {
35164              if ($truthy(opts.$fetch("recover", true))) {
35165                
35166                self.$logger().$warn("" + (($truthy(($ret_or_1 = opts['$[]']("target_name"))) ? ($ret_or_1) : ("path"))) + " is outside of jail; recovering automatically");
35167                $b = self.$partition_path(target_path), $a = $to_ary($b), (target_segments = ($a[0] == null ? nil : $a[0])), $b;
35168                $b = self.$partition_path(jail), $a = $to_ary($b), (jail_segments = ($a[0] == null ? nil : $a[0])), (jail_root = ($a[1] == null ? nil : $a[1])), $b;
35169                return self.$join_path($rb_plus(jail_segments, target_segments), jail_root);
35170              } else {
35171                self.$raise($$$('SecurityError'), "" + (($truthy(($ret_or_1 = opts['$[]']("target_name"))) ? ($ret_or_1) : ("path"))) + " " + (target) + " is outside of jail: " + (jail) + " (disallowed in safe mode)")
35172              }
35173            };
35174            return target_path;
35175          } else {
35176            $b = self.$partition_path(target), $a = $to_ary($b), (target_segments = ($a[0] == null ? nil : $a[0])), $b
35177          }
35178        } else {
35179          target_segments = []
35180        };
35181        if ($truthy(target_segments['$empty?']())) {
35182          if ($truthy(start['$nil_or_empty?']())) {
35183            return ($truthy(($ret_or_1 = jail)) ? ($ret_or_1) : (self.working_dir))
35184          } else if ($truthy(self['$root?'](start))) {
35185            if ($truthy(jail)) {
35186              start = self.$posixify(start)
35187            } else {
35188              return self.$expand_path(start)
35189            }
35190          } else {
35191            
35192            $b = self.$partition_path(start), $a = $to_ary($b), (target_segments = ($a[0] == null ? nil : $a[0])), $b;
35193            start = ($truthy(($ret_or_1 = jail)) ? ($ret_or_1) : (self.working_dir));
35194          }
35195        } else if ($truthy(start['$nil_or_empty?']())) {
35196          start = ($truthy(($ret_or_1 = jail)) ? ($ret_or_1) : (self.working_dir))
35197        } else if ($truthy(self['$root?'](start))) {
35198          if ($truthy(jail)) {
35199            start = self.$posixify(start)
35200          }
35201        } else {
35202          start = "" + (($truthy(($ret_or_1 = jail)) ? ($ret_or_1) : (self.working_dir)).$chomp("/")) + "/" + (start)
35203        };
35204        if ((($truthy(jail) && ($truthy((recheck = self['$descends_from?'](start, jail)['$!']())))) && ($eqeq(self.file_separator, $$('BACKSLASH'))))) {
35205          
35206          $b = self.$partition_path(start), $a = $to_ary($b), (start_segments = ($a[0] == null ? nil : $a[0])), (start_root = ($a[1] == null ? nil : $a[1])), $b;
35207          $b = self.$partition_path(jail), $a = $to_ary($b), (jail_segments = ($a[0] == null ? nil : $a[0])), (jail_root = ($a[1] == null ? nil : $a[1])), $b;
35208          if ($neqeq(start_root, jail_root)) {
35209            if ($truthy(opts.$fetch("recover", true))) {
35210              
35211              self.$logger().$warn("start path for " + (($truthy(($ret_or_1 = opts['$[]']("target_name"))) ? ($ret_or_1) : ("path"))) + " is outside of jail root; recovering automatically");
35212              start_segments = jail_segments;
35213              recheck = false;
35214            } else {
35215              self.$raise($$$('SecurityError'), "start path for " + (($truthy(($ret_or_1 = opts['$[]']("target_name"))) ? ($ret_or_1) : ("path"))) + " " + (start) + " refers to location outside jail root: " + (jail) + " (disallowed in safe mode)")
35216            }
35217          };
35218        } else {
35219          $b = self.$partition_path(start), $a = $to_ary($b), (start_segments = ($a[0] == null ? nil : $a[0])), (jail_root = ($a[1] == null ? nil : $a[1])), $b
35220        };
35221        if ($truthy((resolved_segments = $rb_plus(start_segments, target_segments))['$include?']($$('DOT_DOT')))) {
35222          
35223          $a = [resolved_segments, []], (unresolved_segments = $a[0]), (resolved_segments = $a[1]), $a;
35224          if ($truthy(jail)) {
35225            
35226            if (!$truthy(jail_segments)) {
35227              $b = self.$partition_path(jail), $a = $to_ary($b), (jail_segments = ($a[0] == null ? nil : $a[0])), $b
35228            };
35229            warned = false;
35230            $send(unresolved_segments, 'each', [], function $$8(segment){var self = $$8.$$s == null ? this : $$8.$$s;
35231
35232              
35233              if (segment == null) segment = nil;
35234              if ($eqeq(segment, $$('DOT_DOT'))) {
35235                if ($truthy($rb_gt(resolved_segments.$size(), jail_segments.$size()))) {
35236                  return resolved_segments.$pop()
35237                } else if ($truthy(opts.$fetch("recover", true))) {
35238                  if ($truthy(warned)) {
35239                    return nil
35240                  } else {
35241                    
35242                    self.$logger().$warn("" + (($truthy(($ret_or_1 = opts['$[]']("target_name"))) ? ($ret_or_1) : ("path"))) + " has illegal reference to ancestor of jail; recovering automatically");
35243                    return (warned = true);
35244                  }
35245                } else {
35246                  return self.$raise($$$('SecurityError'), "" + (($truthy(($ret_or_1 = opts['$[]']("target_name"))) ? ($ret_or_1) : ("path"))) + " " + (target) + " refers to location outside jail: " + (jail) + " (disallowed in safe mode)")
35247                }
35248              } else {
35249                return resolved_segments['$<<'](segment)
35250              };}, {$$s: self});
35251          } else {
35252            $send(unresolved_segments, 'each', [], function $$9(segment){
35253              
35254              if (segment == null) segment = nil;
35255              if ($eqeq(segment, $$('DOT_DOT'))) {
35256                return resolved_segments.$pop()
35257              } else {
35258                return resolved_segments['$<<'](segment)
35259              };})
35260          };
35261        };
35262        if ($truthy(recheck)) {
35263          
35264          target_path = self.$join_path(resolved_segments, jail_root);
35265          if ($truthy(self['$descends_from?'](target_path, jail))) {
35266            return target_path
35267          } else if ($truthy(opts.$fetch("recover", true))) {
35268            
35269            self.$logger().$warn("" + (($truthy(($ret_or_1 = opts['$[]']("target_name"))) ? ($ret_or_1) : ("path"))) + " is outside of jail; recovering automatically");
35270            if (!$truthy(jail_segments)) {
35271              $b = self.$partition_path(jail), $a = $to_ary($b), (jail_segments = ($a[0] == null ? nil : $a[0])), $b
35272            };
35273            return self.$join_path($rb_plus(jail_segments, target_segments), jail_root);
35274          } else {
35275            return self.$raise($$$('SecurityError'), "" + (($truthy(($ret_or_1 = opts['$[]']("target_name"))) ? ($ret_or_1) : ("path"))) + " " + (target) + " is outside of jail: " + (jail) + " (disallowed in safe mode)")
35276          };
35277        } else {
35278          return self.$join_path(resolved_segments, jail_root)
35279        };
35280      }, -2);
35281      
35282      $def(self, '$web_path', function $$web_path(target, start) {
35283        var $a, $b, self = this, uri_prefix = nil, target_segments = nil, target_root = nil, resolved_segments = nil, resolved_path = nil;
35284
35285        
35286        if (start == null) start = nil;
35287        target = self.$posixify(target);
35288        start = self.$posixify(start);
35289        if (!($truthy(start['$nil_or_empty?']()) || ($truthy(self['$web_root?'](target))))) {
35290          $b = self.$extract_uri_prefix("" + (start) + (($truthy(start['$end_with?']($$('SLASH'))) ? ("") : ($$('SLASH')))) + (target)), $a = $to_ary($b), (target = ($a[0] == null ? nil : $a[0])), (uri_prefix = ($a[1] == null ? nil : $a[1])), $b
35291        };
35292        $b = self.$partition_path(target, true), $a = $to_ary($b), (target_segments = ($a[0] == null ? nil : $a[0])), (target_root = ($a[1] == null ? nil : $a[1])), $b;
35293        resolved_segments = [];
35294        $send(target_segments, 'each', [], function $$10(segment){
35295          
35296          if (segment == null) segment = nil;
35297          if ($eqeq(segment, $$('DOT_DOT'))) {
35298            if ($truthy(resolved_segments['$empty?']())) {
35299              if (($truthy(target_root) && ($neqeq(target_root, $$('DOT_SLASH'))))) {
35300                return nil
35301              } else {
35302                return resolved_segments['$<<'](segment)
35303              }
35304            } else if ($eqeq(resolved_segments['$[]'](-1), $$('DOT_DOT'))) {
35305              return resolved_segments['$<<'](segment)
35306            } else {
35307              return resolved_segments.$pop()
35308            }
35309          } else {
35310            return resolved_segments['$<<'](segment)
35311          };});
35312        if ($truthy((resolved_path = self.$join_path(resolved_segments, target_root))['$include?'](" "))) {
35313          resolved_path = resolved_path.$gsub(" ", "%20")
35314        };
35315        if ($truthy(uri_prefix)) {
35316          return "" + (uri_prefix) + (resolved_path)
35317        } else {
35318          return resolved_path
35319        };
35320      }, -2);
35321      self.$private();
35322      return $def(self, '$extract_uri_prefix', function $$extract_uri_prefix(str) {
35323        var $a;
35324
35325        if (($truthy(str['$include?'](":")) && ($truthy($$('UriSniffRx')['$=~'](str))))) {
35326          return [str.$slice((($a = $gvars['~']) === nil ? nil : $a['$[]'](0)).$length(), str.$length()), (($a = $gvars['~']) === nil ? nil : $a['$[]'](0))]
35327        } else {
35328          return str
35329        }
35330      });
35331    })($nesting[0], null, $nesting)
35332  })($nesting[0], $nesting)
35333};
35334
35335Opal.modules["asciidoctor/reader"] = function(Opal) {/* Generated by Opal 1.7.3 */
35336  "use strict";
35337  var $module = Opal.module, $klass = Opal.klass, $def = Opal.def, $rb_plus = Opal.rb_plus, $alias = Opal.alias, $hash2 = Opal.hash2, $not = Opal.not, $eqeqeq = Opal.eqeqeq, $to_ary = Opal.to_ary, $truthy = Opal.truthy, $rb_gt = Opal.rb_gt, $send = Opal.send, $rb_minus = Opal.rb_minus, $thrower = Opal.thrower, $eqeq = Opal.eqeq, $rb_times = Opal.rb_times, $neqeq = Opal.neqeq, $to_a = Opal.to_a, $assign_ivar_val = Opal.assign_ivar_val, $send2 = Opal.send2, $find_super = Opal.find_super, $rb_ge = Opal.rb_ge, $gvars = Opal.gvars, $rb_lt = Opal.rb_lt, $hash = Opal.hash, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$;
35338
35339  Opal.add_stubs('include,attr_reader,+,line_info,attr_accessor,!,===,split,file,dir,dirname,path,basename,lineno,reverse,prepare_lines,empty?,nil_or_empty?,peek_line,[],>,slice,length,process_line,times,shift,read_line,<<,-,unshift_all,has_more_lines?,read_lines,join,unshift,unshift_line,unshift_lines,replace_next_line,start_with?,==,*,read_lines_until,size,clear,cursor,[]=,fetch,!=,cursor_at_mark,warn,logger,message_with_context,pop,push,respond_to?,reverse_each,new,tap,each,instance_variables,instance_variable_get,drop,instance_variable_set,class,object_id,inspect,private,prepare_source_array,prepare_source_string,chomp,valid_encoding?,to_s,raise,to_i,attributes,catalog,pop_include,parse,path=,dup,end_with?,keys,rindex,rootname,key?,attr,reverse!,>=,exceeds_max_depth?,nil?,include_processors?,extensions,extensions?,include_processors,map,skip_front_matter!,adjust_indentation!,include?,=~,preprocess_conditional_directive,preprocess_include_directive,downcase,error,none?,any?,all?,strip,send,resolve_expr_val,rstrip,sub_attributes,attribute_missing,info,parse_attributes,find,handles?,instance,process_method,safe,resolve_include_path,method,split_delimited_value,partition,<,to_a,uniq,s
35339ort,call,each_line,infinite?,push_include,delete,first,values,value?,create_include_cursor,delete_at,keep_if,read,uriish?,attr?,require_library,normalize_system_path,file?,relative_path,path_resolver,base_dir,to_f');
35340  return (function($base, $parent_nesting) {
35341    var self = $module($base, 'Asciidoctor');
35342
35343    var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
35344
35345    
35346    (function($base, $super, $parent_nesting) {
35347      var self = $klass($base, $super, 'Reader');
35348
35349      var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype;
35350
35351      $proto.file = $proto.lines = $proto.look_ahead = $proto.unescape_next_line = $proto.lineno = $proto.process_lines = $proto.dir = $proto.path = $proto.mark = $proto.source_lines = $proto.saved = nil;
35352      
35353      self.$include($$('Logging'));
35354      (function($base, $super) {
35355        var self = $klass($base, $super, 'Cursor');
35356
35357        var $proto = self.$$prototype;
35358
35359        $proto.lineno = $proto.path = nil;
35360        
35361        self.$attr_reader("file", "dir", "path", "lineno");
35362        
35363        $def(self, '$initialize', function $$initialize(file, dir, path, lineno) {
35364          var $a, self = this;
35365
35366          
35367          if (dir == null) dir = nil;
35368          if (path == null) path = nil;
35369          if (lineno == null) lineno = 1;
35370          return $a = [file, dir, path, lineno], (self.file = $a[0]), (self.dir = $a[1]), (self.path = $a[2]), (self.lineno = $a[3]), $a;
35371        }, -2);
35372        
35373        $def(self, '$advance', function $$advance(num) {
35374          var self = this;
35375
35376          return (self.lineno = $rb_plus(self.lineno, num))
35377        });
35378        
35379        $def(self, '$line_info', function $$line_info() {
35380          var self = this;
35381
35382          return "" + (self.path) + ": line " + (self.lineno)
35383        });
35384        return $alias(self, "to_s", "line_info");
35385      })($nesting[0], null);
35386      self.$attr_reader("file");
35387      self.$attr_reader("dir");
35388      self.$attr_reader("path");
35389      self.$attr_reader("lineno");
35390      self.$attr_reader("source_lines");
35391      self.$attr_accessor("process_lines");
35392      self.$attr_accessor("unterminated");
35393      
35394      $def(self, '$initialize', function $$initialize(data, cursor, opts) {
35395        var $a, $b, self = this, $ret_or_1 = nil;
35396
35397        
35398        if (data == null) data = nil;
35399        if (cursor == null) cursor = nil;
35400        if (opts == null) opts = $hash2([], {});
35401        if ($not(cursor)) {
35402          
35403          self.file = nil;
35404          self.dir = ".";
35405          self.path = "<stdin>";
35406          self.lineno = 1;
35407        } else if ($eqeqeq($$$('String'), cursor)) {
35408          
35409          self.file = cursor;
35410          $b = $$$('File').$split(self.file), $a = $to_ary($b), (self.dir = ($a[0] == null ? nil : $a[0])), (self.path = ($a[1] == null ? nil : $a[1])), $b;
35411          self.lineno = 1;
35412        } else {
35413          
35414          if ($truthy((self.file = cursor.$file()))) {
35415            
35416            self.dir = ($truthy(($ret_or_1 = cursor.$dir())) ? ($ret_or_1) : ($$$('File').$dirname(self.file)));
35417            self.path = ($truthy(($ret_or_1 = cursor.$path())) ? ($ret_or_1) : ($$$('File').$basename(self.file)));
35418          } else {
35419            
35420            self.dir = ($truthy(($ret_or_1 = cursor.$dir())) ? ($ret_or_1) : ("."));
35421            self.path = ($truthy(($ret_or_1 = cursor.$path())) ? ($ret_or_1) : ("<stdin>"));
35422          };
35423          self.lineno = ($truthy(($ret_or_1 = cursor.$lineno())) ? ($ret_or_1) : (1));
35424        };
35425        self.lines = (self.source_lines = self.$prepare_lines(data, opts)).$reverse();
35426        self.mark = nil;
35427        self.look_ahead = 0;
35428        self.process_lines = true;
35429        self.unescape_next_line = false;
35430        self.unterminated = nil;
35431        return (self.saved = nil);
35432      }, -1);
35433      
35434      $def(self, '$has_more_lines?', function $Reader_has_more_lines$ques$1() {
35435        var self = this;
35436
35437        if ($truthy(self.lines['$empty?']())) {
35438          
35439          self.look_ahead = 0;
35440          return false;
35441        } else {
35442          return true
35443        }
35444      });
35445      
35446      $def(self, '$empty?', function $Reader_empty$ques$2() {
35447        var self = this;
35448
35449        if ($truthy(self.lines['$empty?']())) {
35450          
35451          self.look_ahead = 0;
35452          return true;
35453        } else {
35454          return false
35455        }
35456      });
35457      $alias(self, "eof?", "empty?");
35458      
35459      $def(self, '$next_line_empty?', function $Reader_next_line_empty$ques$3() {
35460        var self = this;
35461
35462        return self.$peek_line()['$nil_or_empty?']()
35463      });
35464      
35465      $def(self, '$peek_line', function $$peek_line(direct) {
35466        var self = this, next_line = nil, line = nil;
35467
35468        
35469        if (direct == null) direct = false;
35470        while ($truthy(true)) {
35471        
35472          next_line = self.lines['$[]'](-1);
35473          if (($truthy(direct) || ($truthy($rb_gt(self.look_ahead, 0))))) {
35474            return ($truthy(self.unescape_next_line) ? (next_line.$slice(1, next_line.$length())) : (next_line))
35475          } else if ($truthy(next_line)) {
35476            if ($truthy((line = self.$process_line(next_line)))) {
35477              return line
35478            }
35479          } else {
35480            
35481            self.look_ahead = 0;
35482            return nil;
35483          };
35484        };
35485      }, -1);
35486      
35487      $def(self, '$peek_lines', function $$peek_lines(num, direct) {
35488        var self = this, old_look_ahead = nil, result = nil, $ret_or_1 = nil;
35489
35490        
35491        if (num == null) num = nil;
35492        if (direct == null) direct = false;
35493        old_look_ahead = self.look_ahead;
35494        result = [];
35495        (function(){try { var $t_break = $thrower('break'); return $send(($truthy(($ret_or_1 = num)) ? ($ret_or_1) : ($$('MAX_INT'))), 'times', [], function $$4(){var self = $$4.$$s == null ? this : $$4.$$s, line = nil;
35496          if (self.lineno == null) self.lineno = nil;
35497
35498          if ($truthy((line = ($truthy(direct) ? (self.$shift()) : (self.$read_line()))))) {
35499            return result['$<<'](line)
35500          } else {
35501            
35502            if ($truthy(direct)) {
35503              self.lineno = $rb_minus(self.lineno, 1)
35504            };
35505            $t_break.$throw();
35506          }}, {$$s: self})} catch($e) {
35507          if ($e === $t_break) return $e.$v;
35508          throw $e;
35509        }})();
35510        if (!$truthy(result['$empty?']())) {
35511          
35512          self.$unshift_all(result);
35513          if ($truthy(direct)) {
35514            self.look_ahead = old_look_ahead
35515          };
35516        };
35517        return result;
35518      }, -1);
35519      
35520      $def(self, '$read_line', function $$read_line() {
35521        var self = this;
35522
35523        if (($truthy($rb_gt(self.look_ahead, 0)) || ($truthy(self['$has_more_lines?']())))) {
35524          return self.$shift()
35525        } else {
35526          return nil
35527        }
35528      });
35529      
35530      $def(self, '$read_lines', function $$read_lines() {
35531        var self = this, lines = nil;
35532
35533        
35534        lines = [];
35535        while ($truthy(self['$has_more_lines?']())) {
35536        lines['$<<'](self.$shift())
35537        };
35538        return lines;
35539      });
35540      $alias(self, "readlines", "read_lines");
35541      
35542      $def(self, '$read', function $$read() {
35543        var self = this;
35544
35545        return self.$read_lines().$join($$('LF'))
35546      });
35547      
35548      $def(self, '$advance', function $$advance() {
35549        var self = this;
35550
35551        if ($truthy(self.$shift())) {
35552          return true
35553        } else {
35554          return false
35555        }
35556      });
35557      
35558      $def(self, '$unshift_line', function $$unshift_line(line_to_restore) {
35559        var self = this;
35560
35561        
35562        self.$unshift(line_to_restore);
35563        return nil;
35564      });
35565      $alias(self, "restore_line", "unshift_line");
35566      
35567      $def(self, '$unshift_lines', function $$unshift_lines(lines_to_restore) {
35568        var self = this;
35569
35570        return self.$unshift_all(lines_to_restore)
35571      });
35572      $alias(self, "restore_lines", "unshift_lines");
35573      
35574      $def(self, '$replace_next_line', function $$replace_next_line(replacement) {
35575        var self = this;
35576
35577        
35578        self.$shift();
35579        self.$unshift(replacement);
35580        return true;
35581      });
35582      $alias(self, "replace_line", "replace_next_line");
35583      
35584      $def(self, '$skip_blank_lines', function $$skip_blank_lines() {
35585        var self = this, num_skipped = nil, next_line = nil;
35586
35587        
35588        if ($truthy(self['$empty?']())) {
35589          return nil
35590        };
35591        num_skipped = 0;
35592        while ($truthy((next_line = self.$peek_line()))) {
35593        if ($truthy(next_line['$empty?']())) {
35594            
35595            self.$shift();
35596            num_skipped = $rb_plus(num_skipped, 1);
35597          } else {
35598            return num_skipped
35599          }
35600        };
35601      });
35602      
35603      $def(self, '$skip_comment_lines', function $$skip_comment_lines() {
35604        var self = this, $ret_or_1 = nil, next_line = nil, ll = nil;
35605
35606        
35607        if ($truthy(self['$empty?']())) {
35608          return nil
35609        };
35610        while ($truthy(($truthy(($ret_or_1 = (next_line = self.$peek_line()))) ? (next_line['$empty?']()['$!']()) : ($ret_or_1)))) {
35611        if ($truthy(next_line['$start_with?']("//"))) {
35612            if ($truthy(next_line['$start_with?']("///"))) {
35613              if (($truthy($rb_gt((ll = next_line.$length()), 3)) && ($eqeq(next_line, $rb_times("/", ll))))) {
35614                self.$read_lines_until($hash2(["terminator", "skip_first_line", "read_last_line", "skip_processing", "context"], {"terminator": next_line, "skip_first_line": true, "read_last_line": true, "skip_processing": true, "context": "comment"}))
35615              } else {
35616                break
35617              }
35618            } else {
35619              self.$shift()
35620            }
35621          } else {
35622            break
35623          }
35624        };
35625        return nil;
35626      });
35627      
35628      $def(self, '$skip_line_comments', function $$skip_line_comments() {
35629        var self = this, comment_lines = nil, $ret_or_1 = nil, next_line = nil;
35630
35631        
35632        if ($truthy(self['$empty?']())) {
35633          return []
35634        };
35635        comment_lines = [];
35636        while ($truthy(($truthy(($ret_or_1 = (next_line = self.$peek_line()))) ? (next_line['$empty?']()['$!']()) : ($ret_or_1)))) {
35637        if ($truthy(next_line['$start_with?']("//"))) {
35638            comment_lines['$<<'](self.$shift())
35639          } else {
35640            break
35641          }
35642        };
35643        return comment_lines;
35644      });
35645      
35646      $def(self, '$terminate', function $$terminate() {
35647        var self = this;
35648
35649        
35650        self.lineno = $rb_plus(self.lineno, self.lines.$size());
35651        self.lines.$clear();
35652        self.look_ahead = 0;
35653        return nil;
35654      });
35655      
35656      $def(self, '$read_lines_until', function $$read_lines_until(options) {
35657        var $a, $yield = $$read_lines_until.$$p || nil, self = this, result = nil, restore_process_lines = nil, terminator = nil, start_cursor = nil, $ret_or_1 = nil, break_on_blank_lines = nil, break_on_list_continuation = nil, skip_comments = nil, line_read = nil, line_restored = nil, line = nil, $ret_or_2 = nil, $ret_or_3 = nil, $ret_or_4 = nil, $ret_or_5 = nil, context = nil;
35658
35659        $$read_lines_until.$$p = null;
35660        
35661        if (options == null) options = $hash2([], {});
35662        result = [];
35663        if (($truthy(self.process_lines) && ($truthy(options['$[]']("skip_processing"))))) {
35664          
35665          self.process_lines = false;
35666          restore_process_lines = true;
35667        };
35668        if ($truthy((terminator = options['$[]']("terminator")))) {
35669          
35670          start_cursor = ($truthy(($ret_or_1 = options['$[]']("cursor"))) ? ($ret_or_1) : (self.$cursor()));
35671          break_on_blank_lines = false;
35672          break_on_list_continuation = false;
35673        } else {
35674          
35675          break_on_blank_lines = options['$[]']("break_on_blank_lines");
35676          break_on_list_continuation = options['$[]']("break_on_list_continuation");
35677        };
35678        skip_comments = options['$[]']("skip_line_comments");
35679        line_read = (line_restored = nil);
35680        if ($truthy(options['$[]']("skip_first_line"))) {
35681          self.$shift()
35682        };
35683        while ($truthy((line = self.$read_line()))) {
35684        
35685          if ($truthy(($truthy(terminator) ? (line['$=='](terminator)) : (($truthy(($ret_or_1 = ($truthy(($ret_or_2 = ($truthy(($ret_or_3 = break_on_blank_lines)) ? (line['$empty?']()) : ($ret_or_3)))) ? ($ret_or_2) : (($truthy(($ret_or_3 = ($truthy(($ret_or_4 = ($truthy(($ret_or_5 = break_on_list_continuation)) ? (line_read) : ($ret_or_5)))) ? (line['$==']($$('LIST_CONTINUATION'))) : ($ret_or_4)))) ? (($a = ["preserve_last_line", true], $send(options, '[]=', $a), $a[$a.length - 1])) : ($ret_or_3)))))) ? ($ret_or_1) : (($truthy(($ret_or_2 = ($yield !== nil))) ? (Opal.yield1($yield, line)) : ($ret_or_2)))))))) {
35686            
35687            if ($truthy(options['$[]']("read_last_line"))) {
35688              result['$<<'](line)
35689            };
35690            if ($truthy(options['$[]']("preserve_last_line"))) {
35691              
35692              self.$unshift(line);
35693              line_restored = true;
35694            };
35695            break;
35696          };
35697          if (!(($truthy(skip_comments) && ($truthy(line['$start_with?']("//")))) && ($not(line['$start_with?']("///"))))) {
35698            
35699            result['$<<'](line);
35700            line_read = true;
35701          };
35702        };
35703        if ($truthy(restore_process_lines)) {
35704          
35705          self.process_lines = true;
35706          if (($truthy(line_restored) && ($not(terminator)))) {
35707            self.look_ahead = $rb_minus(self.look_ahead, 1)
35708          };
35709        };
35710        if ((($truthy(terminator) && ($neqeq(terminator, line))) && ($truthy((context = options.$fetch("context", terminator)))))) {
35711          
35712          if ($eqeq(start_cursor, "at_mark")) {
35713            start_cursor = self.$cursor_at_mark()
35714          };
35715          self.$logger().$warn(self.$message_with_context("unterminated " + (context) + " block", $hash2(["source_location"], {"source_location": start_cursor})));
35716          self.unterminated = true;
35717        };
35718        return result;
35719      }, -1);
35720      
35721      $def(self, '$shift', function $$shift() {
35722        var self = this;
35723
35724        
35725        self.lineno = $rb_plus(self.lineno, 1);
35726        if (!$eqeq(self.look_ahead, 0)) {
35727          self.look_ahead = $rb_minus(self.look_ahead, 1)
35728        };
35729        return self.lines.$pop();
35730      });
35731      
35732      $def(self, '$unshift', function $$unshift(line) {
35733        var self = this;
35734
35735        
35736        self.lineno = $rb_minus(self.lineno, 1);
35737        self.look_ahead = $rb_plus(self.look_ahead, 1);
35738        self.lines.$push(line);
35739        return nil;
35740      });
35741      if ($eqeq($$$('RUBY_ENGINE'), "jruby")) {
35742        
35743        $def(self, '$unshift_all', function $$unshift_all(lines_to_restore) {
35744          var self = this;
35745
35746          
35747          self.lineno = $rb_minus(self.lineno, lines_to_restore.$size());
35748          self.look_ahead = $rb_plus(self.look_ahead, lines_to_restore.$size());
35749          if ($truthy(lines_to_restore['$respond_to?']("reverse"))) {
35750            $send(self.lines, 'push', $to_a(lines_to_restore.$reverse()))
35751          } else {
35752            $send(lines_to_restore, 'reverse_each', [], function $$5(it){var self = $$5.$$s == null ? this : $$5.$$s;
35753              if (self.lines == null) self.lines = nil;
35754
35755              
35756              if (it == null) it = nil;
35757              return self.lines.$push(it);}, {$$s: self})
35758          };
35759          return nil;
35760        })
35761      } else {
35762        
35763        $def(self, '$unshift_all', function $$unshift_all(lines_to_restore) {
35764          var self = this;
35765
35766          
35767          self.lineno = $rb_minus(self.lineno, lines_to_restore.$size());
35768          self.look_ahead = $rb_plus(self.look_ahead, lines_to_restore.$size());
35769          $send(self.lines, 'push', $to_a(lines_to_restore.$reverse()));
35770          return nil;
35771        })
35772      };
35773      
35774      $def(self, '$cursor', function $$cursor() {
35775        var self = this;
35776
35777        return $$('Cursor').$new(self.file, self.dir, self.path, self.lineno)
35778      });
35779      
35780      $def(self, '$cursor_at_line', function $$cursor_at_line(lineno) {
35781        var self = this;
35782
35783        return $$('Cursor').$new(self.file, self.dir, self.path, lineno)
35784      });
35785      
35786      $def(self, '$cursor_at_mark', function $$cursor_at_mark() {
35787        var self = this;
35788
35789        if ($truthy(self.mark)) {
35790          return $send($$('Cursor'), 'new', $to_a(self.mark))
35791        } else {
35792          return self.$cursor()
35793        }
35794      });
35795      
35796      $def(self, '$cursor_before_mark', function $$cursor_before_mark() {
35797        var $a, $b, self = this, m_file = nil, m_dir = nil, m_path = nil, m_lineno = nil;
35798
35799        if ($truthy(self.mark)) {
35800          
35801          $b = self.mark, $a = $to_ary($b), (m_file = ($a[0] == null ? nil : $a[0])), (m_dir = ($a[1] == null ? nil : $a[1])), (m_path = ($a[2] == null ? nil : $a[2])), (m_lineno = ($a[3] == null ? nil : $a[3])), $b;
35802          return $$('Cursor').$new(m_file, m_dir, m_path, $rb_minus(m_lineno, 1));
35803        } else {
35804          return $$('Cursor').$new(self.file, self.dir, self.path, $rb_minus(self.lineno, 1))
35805        }
35806      });
35807      
35808      $def(self, '$cursor_at_prev_line', function $$cursor_at_prev_line() {
35809        var self = this;
35810
35811        return $$('Cursor').$new(self.file, self.dir, self.path, $rb_minus(self.lineno, 1))
35812      });
35813      
35814      $def(self, '$mark', function $$mark() {
35815        var self = this;
35816
35817        return (self.mark = [self.file, self.dir, self.path, self.lineno])
35818      });
35819      
35820      $def(self, '$line_info', function $$line_info() {
35821        var self = this;
35822
35823        return "" + (self.path) + ": line " + (self.lineno)
35824      });
35825      
35826      $def(self, '$lines', function $$lines() {
35827        var self = this;
35828
35829        return self.lines.$reverse()
35830      });
35831      
35832      $def(self, '$string', function $$string() {
35833        var self = this;
35834
35835        return self.lines.$reverse().$join($$('LF'))
35836      });
35837      
35838      $def(self, '$source', function $$source() {
35839        var self = this;
35840
35841        return self.source_lines.$join($$('LF'))
35842      });
35843      
35844      $def(self, '$save', function $$save() {
35845        var self = this;
35846
35847        
35848        self.saved = $send($hash2([], {}), 'tap', [], function $$6(accum){var self = $$6.$$s == null ? this : $$6.$$s;
35849
35850          
35851          if (accum == null) accum = nil;
35852          return $send(self.$instance_variables(), 'each', [], function $$7(name){var $a, self = $$7.$$s == null ? this : $$7.$$s, val = nil;
35853
35854            
35855            if (name == null) name = nil;
35856            if (($eqeq(name, "@saved") || ($eqeq(name, "@source_lines")))) {
35857              return nil
35858            } else {
35859              return ($a = [name, ($eqeqeq($$$('Array'), (val = self.$instance_variable_get(name))) ? (val.$drop(0)) : (val))], $send(accum, '[]=', $a), $a[$a.length - 1])
35860            };}, {$$s: self});}, {$$s: self});
35861        return nil;
35862      });
35863      
35864      $def(self, '$restore_save', function $$restore_save() {
35865        var self = this;
35866
35867        if ($truthy(self.saved)) {
35868          
35869          $send(self.saved, 'each', [], function $$8(name, val){var self = $$8.$$s == null ? this : $$8.$$s;
35870
35871            
35872            if (name == null) name = nil;
35873            if (val == null) val = nil;
35874            return self.$instance_variable_set(name, val);}, {$$s: self});
35875          return (self.saved = nil);
35876        } else {
35877          return nil
35878        }
35879      });
35880      
35881      $def(self, '$discard_save', $assign_ivar_val("saved", nil));
35882      
35883      $def(self, '$to_s', function $$to_s() {
35884        var self = this;
35885
35886        return "#<" + (self.$class()) + "@" + (self.$object_id()) + " {path: " + (self.path.$inspect()) + ", line: " + (self.lineno) + "}>"
35887      });
35888      self.$private();
35889      
35890      $def(self, '$prepare_lines', function $$prepare_lines(data, opts) {
35891        var self = this, normalize = nil;
35892
35893        
35894        if (opts == null) opts = $hash2([], {});
35895        try {
35896          if ($truthy((normalize = opts['$[]']("normalize")))) {
35897            if ($eqeqeq($$$('Array'), data)) {
35898              
35899              return $$('Helpers').$prepare_source_array(data, normalize['$!=']("chomp"));
35900            } else {
35901              
35902              return $$('Helpers').$prepare_source_string(data, normalize['$!=']("chomp"));
35903            }
35904          } else if ($eqeqeq($$$('Array'), data)) {
35905            return data.$drop(0)
35906          } else if ($truthy(data)) {
35907            return data.$chomp().$split($$('LF'), -1)
35908          } else {
35909            return []
35910          }
35911        } catch ($err) {
35912          if (Opal.rescue($err, [$$('StandardError')])) {
35913            try {
35914              if ($truthy(($eqeqeq($$$('Array'), data) ? (data.$join()) : (data.$to_s()))['$valid_encoding?']())) {
35915                return self.$raise()
35916              } else {
35917                return self.$raise($$$('ArgumentError'), "source is either binary or contains invali
35917d Unicode data")
35918              }
35919            } finally { Opal.pop_exception(); }
35920          } else { throw $err; }
35921        };
35922      }, -2);
35923      return $def(self, '$process_line', function $$process_line(line) {
35924        var self = this;
35925
35926        
35927        if ($truthy(self.process_lines)) {
35928          self.look_ahead = $rb_plus(self.look_ahead, 1)
35929        };
35930        return line;
35931      });
35932    })($nesting[0], null, $nesting);
35933    return (function($base, $super, $parent_nesting) {
35934      var self = $klass($base, $super, 'PreprocessorReader');
35935
35936      var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype;
35937
35938      $proto.include_stack = $proto.lines = $proto.file = $proto.dir = $proto.path = $proto.lineno = $proto.maxdepth = $proto.process_lines = $proto.includes = $proto.document = $proto.unescape_next_line = $proto.include_processor_extensions = $proto.look_ahead = $proto.skipping = $proto.conditional_stack = nil;
35939      
35940      self.$attr_reader("include_stack");
35941      
35942      $def(self, '$initialize', function $$initialize(document, data, cursor, opts) {
35943        var $yield = $$initialize.$$p || nil, self = this, default_include_depth = nil, $ret_or_1 = nil;
35944
35945        $$initialize.$$p = null;
35946        
35947        if (data == null) data = nil;
35948        if (cursor == null) cursor = nil;
35949        if (opts == null) opts = $hash2([], {});
35950        self.document = document;
35951        $send2(self, $find_super(self, 'initialize', $$initialize, false, true), 'initialize', [data, cursor, opts], null);
35952        if ($truthy($rb_gt((default_include_depth = ($truthy(($ret_or_1 = document.$attributes()['$[]']("max-include-depth"))) ? ($ret_or_1) : (64)).$to_i()), 0))) {
35953          self.maxdepth = $hash2(["abs", "curr", "rel"], {"abs": default_include_depth, "curr": default_include_depth, "rel": default_include_depth})
35954        } else {
35955          self.maxdepth = nil
35956        };
35957        self.include_stack = [];
35958        self.includes = document.$catalog()['$[]']("includes");
35959        self.skipping = false;
35960        self.conditional_stack = [];
35961        return (self.include_processor_extensions = nil);
35962      }, -2);
35963      
35964      $def(self, '$has_more_lines?', function $PreprocessorReader_has_more_lines$ques$9() {
35965        var self = this;
35966
35967        if ($truthy(self.$peek_line())) {
35968          return true
35969        } else {
35970          return false
35971        }
35972      });
35973      
35974      $def(self, '$empty?', function $PreprocessorReader_empty$ques$10() {
35975        var self = this;
35976
35977        if ($truthy(self.$peek_line())) {
35978          return false
35979        } else {
35980          return true
35981        }
35982      });
35983      $alias(self, "eof?", "empty?");
35984      
35985      $def(self, '$peek_line', function $$peek_line(direct) {
35986        var $yield = $$peek_line.$$p || nil, self = this, line = nil;
35987
35988        $$peek_line.$$p = null;
35989        
35990        if (direct == null) direct = false;
35991        if ($truthy((line = $send2(self, $find_super(self, 'peek_line', $$peek_line, false, true), 'peek_line', [direct], $yield)))) {
35992          return line
35993        } else if ($truthy(self.include_stack['$empty?']())) {
35994          return nil
35995        } else {
35996          
35997          self.$pop_include();
35998          return self.$peek_line(direct);
35999        };
36000      }, -1);
36001      
36002      $def(self, '$push_include', function $$push_include(data, file, path, lineno, attributes) {
36003        var self = this, dir = nil, $ret_or_1 = nil, rel_maxdepth = nil, curr_maxdepth = nil, abs_maxdepth = nil, leveloffset = nil;
36004
36005        
36006        if (file == null) file = nil;
36007        if (path == null) path = nil;
36008        if (lineno == null) lineno = 1;
36009        if (attributes == null) attributes = $hash2([], {});
36010        self.include_stack['$<<']([self.lines, self.file, self.dir, self.path, self.lineno, self.maxdepth, self.process_lines]);
36011        if ($truthy((self.file = file))) {
36012          
36013          if ($eqeqeq($$$('String'), file)) {
36014            self.dir = $$$('File').$dirname(file)
36015          } else if ($truthy($$('RUBY_ENGINE_OPAL'))) {
36016            self.dir = $$$('URI').$parse($$$('File').$dirname((file = file.$to_s())))
36017          } else {
36018            
36019            (self.dir = file.$dup())['$path='](($eqeq((dir = $$$('File').$dirname(file.$path())), "/") ? ("") : (dir)));
36020            file = file.$to_s();
36021          };
36022          self.path = (path = ($truthy(($ret_or_1 = path)) ? ($ret_or_1) : ($$$('File').$basename(file))));
36023          if ($truthy((self.process_lines = $send(file, 'end_with?', $to_a($$('ASCIIDOC_EXTENSIONS').$keys()))))) {
36024            if ($truthy(($ret_or_1 = self.includes['$[]'](path.$slice(0, path.$rindex(".")))))) {
36025              $ret_or_1
36026            } else {
36027              self.includes['$[]='](path.$slice(0, path.$rindex(".")), ($truthy(attributes['$[]']("partial-option")) ? (nil) : (true)))
36028            }
36029          };
36030        } else {
36031          
36032          self.dir = ".";
36033          self.process_lines = true;
36034          if ($truthy((self.path = path))) {
36035            if ($truthy(($ret_or_1 = self.includes['$[]']($$('Helpers').$rootname(path))))) {
36036              $ret_or_1
36037            } else {
36038              self.includes['$[]=']($$('Helpers').$rootname(path), ($truthy(attributes['$[]']("partial-option")) ? (nil) : (true)))
36039            }
36040          } else {
36041            self.path = "<stdin>"
36042          };
36043        };
36044        self.lineno = lineno;
36045        if (($truthy(self.maxdepth) && ($truthy(attributes['$key?']("depth"))))) {
36046          if ($truthy($rb_gt((rel_maxdepth = attributes['$[]']("depth").$to_i()), 0))) {
36047            
36048            if ($truthy($rb_gt((curr_maxdepth = $rb_plus(self.include_stack.$size(), rel_maxdepth)), (abs_maxdepth = self.maxdepth['$[]']("abs"))))) {
36049              curr_maxdepth = (rel_maxdepth = abs_maxdepth)
36050            };
36051            self.maxdepth = $hash2(["abs", "curr", "rel"], {"abs": abs_maxdepth, "curr": curr_maxdepth, "rel": rel_maxdepth});
36052          } else {
36053            self.maxdepth = $hash2(["abs", "curr", "rel"], {"abs": self.maxdepth['$[]']("abs"), "curr": self.include_stack.$size(), "rel": 0})
36054          }
36055        };
36056        if ($truthy((self.lines = self.$prepare_lines(data, $hash2(["normalize", "condense", "indent"], {"normalize": ($truthy(($ret_or_1 = self.process_lines)) ? ($ret_or_1) : ("chomp")), "condense": false, "indent": attributes['$[]']("indent")})))['$empty?']())) {
36057          self.$pop_include()
36058        } else {
36059          
36060          if ($truthy(attributes['$key?']("leveloffset"))) {
36061            
36062            self.lines = $rb_plus($rb_plus([($truthy((leveloffset = self.document.$attr("leveloffset"))) ? (":leveloffset: " + (leveloffset)) : (":leveloffset!:")), ""], self.lines.$reverse()), ["", ":leveloffset: " + (attributes['$[]']("leveloffset"))]);
36063            self.lineno = $rb_minus(self.lineno, 2);
36064          } else {
36065            self.lines['$reverse!']()
36066          };
36067          self.look_ahead = 0;
36068        };
36069        return self;
36070      }, -2);
36071      
36072      $def(self, '$include_depth', function $$include_depth() {
36073        var self = this;
36074
36075        return self.include_stack.$size()
36076      });
36077      
36078      $def(self, '$exceeds_max_depth?', function $PreprocessorReader_exceeds_max_depth$ques$11() {
36079        var self = this, $ret_or_1 = nil, $ret_or_2 = nil;
36080
36081        if ($truthy(($ret_or_1 = ($truthy(($ret_or_2 = self.maxdepth)) ? ($rb_ge(self.include_stack.$size(), self.maxdepth['$[]']("curr"))) : ($ret_or_2))))) {
36082          return self.maxdepth['$[]']("rel")
36083        } else {
36084          return $ret_or_1
36085        }
36086      });
36087      $alias(self, "exceeded_max_depth?", "exceeds_max_depth?");
36088      
36089      $def(self, '$shift', function $$shift() {
36090        var $yield = $$shift.$$p || nil, self = this, line = nil;
36091
36092        $$shift.$$p = null;
36093        if ($truthy(self.unescape_next_line)) {
36094          
36095          self.unescape_next_line = false;
36096          return (line = $send2(self, $find_super(self, 'shift', $$shift, false, true), 'shift', [], $yield)).$slice(1, line.$length());
36097        } else {
36098          return $send2(self, $find_super(self, 'shift', $$shift, false, true), 'shift', [], $yield)
36099        }
36100      });
36101      
36102      $def(self, '$include_processors?', function $PreprocessorReader_include_processors$ques$12() {
36103        var self = this;
36104
36105        if ($truthy(self.include_processor_extensions['$nil?']())) {
36106          if (($truthy(self.document['$extensions?']()) && ($truthy(self.document.$extensions()['$include_processors?']())))) {
36107            return (self.include_processor_extensions = self.document.$extensions().$include_processors())['$!']()['$!']()
36108          } else {
36109            return (self.include_processor_extensions = false)
36110          }
36111        } else {
36112          return self.include_processor_extensions['$!='](false)
36113        }
36114      });
36115      
36116      $def(self, '$create_include_cursor', function $$create_include_cursor(file, path, lineno) {
36117        var dir = nil;
36118
36119        
36120        if ($eqeqeq($$$('String'), file)) {
36121          dir = $$$('File').$dirname(file)
36122        } else if ($truthy($$('RUBY_ENGINE_OPAL'))) {
36123          dir = $$$('File').$dirname((file = file.$to_s()))
36124        } else {
36125          
36126          dir = ($eqeq((dir = $$$('File').$dirname(file.$path())), "") ? ("/") : (dir));
36127          file = file.$to_s();
36128        };
36129        return $$('Cursor').$new(file, dir, path, lineno);
36130      });
36131      
36132      $def(self, '$to_s', function $$to_s() {
36133        var self = this;
36134
36135        return "#<" + (self.$class()) + "@" + (self.$object_id()) + " {path: " + (self.path.$inspect()) + ", line: " + (self.lineno) + ", include depth: " + (self.include_stack.$size()) + ", include stack: [" + ($send(self.include_stack, 'map', [], function $$13(inc){
36136          
36137          if (inc == null) inc = nil;
36138          return inc.$to_s();}).$join(", ")) + "]}>"
36139      });
36140      self.$private();
36141      
36142      $def(self, '$prepare_lines', function $$prepare_lines(data, opts) {
36143        var $yield = $$prepare_lines.$$p || nil, self = this, result = nil, front_matter = nil, $ret_or_1 = nil, last = nil;
36144
36145        $$prepare_lines.$$p = null;
36146        
36147        if (opts == null) opts = $hash2([], {});
36148        result = $send2(self, $find_super(self, 'prepare_lines', $$prepare_lines, false, true), 'prepare_lines', [data, opts], $yield);
36149        if ((($truthy(self.document) && ($truthy(self.document.$attributes()['$[]']("skip-front-matter")))) && ($truthy((front_matter = self['$skip_front_matter!'](result)))))) {
36150          self.document.$attributes()['$[]=']("front-matter", front_matter.$join($$('LF')))
36151        };
36152        if ($truthy(opts.$fetch("condense", true))) {
36153          while ($truthy(($truthy(($ret_or_1 = (last = result['$[]'](-1)))) ? (last['$empty?']()) : ($ret_or_1)))) {
36154          result.$pop()
36155          }
36156        };
36157        if ($truthy(opts['$[]']("indent"))) {
36158          $$('Parser')['$adjust_indentation!'](result, opts['$[]']("indent").$to_i(), self.document.$attr("tabsize").$to_i())
36159        };
36160        return result;
36161      }, -2);
36162      
36163      $def(self, '$process_line', function $$process_line(line) {
36164        var $a, self = this;
36165
36166        
36167        if (!$truthy(self.process_lines)) {
36168          return line
36169        };
36170        if ($truthy(line['$empty?']())) {
36171          
36172          self.look_ahead = $rb_plus(self.look_ahead, 1);
36173          return line;
36174        };
36175        if ((($truthy(line['$end_with?']("]")) && ($not(line['$start_with?']("[")))) && ($truthy(line['$include?']("::"))))) {
36176          if (($truthy(line['$include?']("if")) && ($truthy($$('ConditionalDirectiveRx')['$=~'](line))))) {
36177            if ($eqeq((($a = $gvars['~']) === nil ? nil : $a['$[]'](1)), "\\")) {
36178              
36179              self.unescape_next_line = true;
36180              self.look_ahead = $rb_plus(self.look_ahead, 1);
36181              return line.$slice(1, line.$length());
36182            } else if ($truthy(self.$preprocess_conditional_directive((($a = $gvars['~']) === nil ? nil : $a['$[]'](2)), (($a = $gvars['~']) === nil ? nil : $a['$[]'](3)), (($a = $gvars['~']) === nil ? nil : $a['$[]'](4)), (($a = $gvars['~']) === nil ? nil : $a['$[]'](5))))) {
36183              
36184              self.$shift();
36185              return nil;
36186            } else {
36187              
36188              self.look_ahead = $rb_plus(self.look_ahead, 1);
36189              return line;
36190            }
36191          } else if ($truthy(self.skipping)) {
36192            
36193            self.$shift();
36194            return nil;
36195          } else if (($truthy(line['$start_with?']("inc", "\\inc")) && ($truthy($$('IncludeDirectiveRx')['$=~'](line))))) {
36196            if ($eqeq((($a = $gvars['~']) === nil ? nil : $a['$[]'](1)), "\\")) {
36197              
36198              self.unescape_next_line = true;
36199              self.look_ahead = $rb_plus(self.look_ahead, 1);
36200              return line.$slice(1, line.$length());
36201            } else if ($truthy(self.$preprocess_include_directive((($a = $gvars['~']) === nil ? nil : $a['$[]'](2)), (($a = $gvars['~']) === nil ? nil : $a['$[]'](3))))) {
36202              return nil
36203            } else {
36204              
36205              self.look_ahead = $rb_plus(self.look_ahead, 1);
36206              return line;
36207            }
36208          } else {
36209            
36210            self.look_ahead = $rb_plus(self.look_ahead, 1);
36211            return line;
36212          }
36213        } else if ($truthy(self.skipping)) {
36214          
36215          self.$shift();
36216          return nil;
36217        } else {
36218          
36219          self.look_ahead = $rb_plus(self.look_ahead, 1);
36220          return line;
36221        };
36222      });
36223      
36224      $def(self, '$preprocess_conditional_directive', function $$preprocess_conditional_directive(keyword, target, delimiter, text) {
36225        var $a, self = this, no_target = nil, pair = nil, skip = nil, lhs = nil, op = nil, rhs = nil;
36226
36227        
36228        if (!$truthy((no_target = target['$empty?']()))) {
36229          target = target.$downcase()
36230        };
36231        if ($eqeq(keyword, "endif")) {
36232          
36233          if ($truthy(text)) {
36234            self.$logger().$error(self.$message_with_context("malformed preprocessor directive - text not permitted: endif::" + (target) + "[" + (text) + "]", $hash2(["source_location"], {"source_location": self.$cursor()})))
36235          } else if ($truthy(self.conditional_stack['$empty?']())) {
36236            self.$logger().$error(self.$message_with_context("unmatched preprocessor directive: endif::" + (target) + "[]", $hash2(["source_location"], {"source_location": self.$cursor()})))
36237          } else if (($truthy(no_target) || ($eqeq(target, (pair = self.conditional_stack['$[]'](-1))['$[]']("target"))))) {
36238            
36239            self.conditional_stack.$pop();
36240            self.skipping = ($truthy(self.conditional_stack['$empty?']()) ? (false) : (self.conditional_stack['$[]'](-1)['$[]']("skipping")));
36241          } else {
36242            self.$logger().$error(self.$message_with_context("mismatched preprocessor directive: endif::" + (target) + "[], expected endif::" + (pair['$[]']("target")) + "[]", $hash2(["source_location"], {"source_location": self.$cursor()})))
36243          };
36244          return true;
36245        } else if ($truthy(self.skipping)) {
36246          skip = false
36247        } else 
36248        switch (keyword) {
36249          case "ifdef":
36250            
36251            if ($truthy(no_target)) {
36252              
36253              self.$logger().$error(self.$message_with_context("malformed preprocessor directive - missing target: ifdef::[" + (text) + "]", $hash2(["source_location"], {"source_location": self.$cursor()})));
36254              return true;
36255            };
36256            
36257            switch (delimiter) {
36258              case ",":
36259                skip = $send(target.$split(",", -1), 'none?', [], function $$14(name){var self = $$14.$$s == null ? this : $$14.$$s;
36260                  if (self.document == null) self.document = nil;
36261
36262                  
36263                  if (name == null) name = nil;
36264                  return self.document.$attributes()['$key?'](name);}, {$$s: self})
36265                break;
36266              case "+":
36267                skip = $send(target.$split("+", -1), 'any?', [], function $$15(name){var self = $$15.$$s == null ? this : $$15.$$s;
36268                  if (self.document == null) self.document = nil;
36269
36270                  
36271                  if (name == null) name = nil;
36272                  return self.document.$attributes()['$key?'](name)['$!']();}, {$$s: self})
36273                break;
36274              default:
36275                skip = self.document.$attributes()['$key?'](target)['$!']()
36276            };
36277            break;
36278          case "ifndef":
36279            
36280            if ($truthy(no_target)) {
36281              
36282              self.$logger().$error(self.$message_with_context("malformed preprocessor directive - missing target: ifndef::[" + (text) + "]", $hash2(["source_location"], {"source_location": self.$cursor()})));
36283              return true;
36284            };
36285            
36286            switch (delimiter) {
36287              case ",":
36288                skip = $send(target.$split(",", -1), 'any?', [], function $$16(name){var self = $$16.$$s == null ? this : $$16.$$s;
36289                  if (self.document == null) self.document = nil;
36290
36291                  
36292                  if (name == null) name = nil;
36293                  return self.document.$attributes()['$key?'](name);}, {$$s: self})
36294                break;
36295              case "+":
36296                skip = $send(target.$split("+", -1), 'all?', [], function $$17(name){var self = $$17.$$s == null ? this : $$17.$$s;
36297                  if (self.document == null) self.document = nil;
36298
36299                  
36300                  if (name == null) name = nil;
36301                  return self.document.$attributes()['$key?'](name);}, {$$s: self})
36302                break;
36303              default:
36304                skip = self.document.$attributes()['$key?'](target)
36305            };
36306            break;
36307          case "ifeval":
36308            if ($truthy(no_target)) {
36309              if (($truthy(text) && ($truthy($$('EvalExpressionRx')['$=~'](text.$strip()))))) {
36310                
36311                lhs = (($a = $gvars['~']) === nil ? nil : $a['$[]'](1));
36312                op = (($a = $gvars['~']) === nil ? nil : $a['$[]'](2));
36313                rhs = (($a = $gvars['~']) === nil ? nil : $a['$[]'](3));
36314                skip = (function() { try {
36315                  if ($truthy(self.$resolve_expr_val(lhs).$send(op, self.$resolve_expr_val(rhs)))) {
36316                    return false
36317                  } else {
36318                    return true
36319                  }
36320                } catch ($err) {
36321                  if (Opal.rescue($err, [$$('StandardError')])) {
36322                    try {
36323                      return true
36324                    } finally { Opal.pop_exception(); }
36325                  } else { throw $err; }
36326                }})();
36327              } else {
36328                
36329                self.$logger().$error(self.$message_with_context("malformed preprocessor directive - " + (($truthy(text) ? ("invalid expression") : ("missing expression"))) + ": ifeval::[" + (text) + "]", $hash2(["source_location"], {"source_location": self.$cursor()})));
36330                return true;
36331              }
36332            } else {
36333              
36334              self.$logger().$error(self.$message_with_context("malformed preprocessor directive - target not permitted: ifeval::" + (target) + "[" + (text) + "]", $hash2(["source_location"], {"source_location": self.$cursor()})));
36335              return true;
36336            }
36337            break;
36338          default:
36339            nil
36340        };
36341        if (($eqeq(keyword, "ifeval") || ($not(text)))) {
36342          
36343          if ($truthy(skip)) {
36344            self.skipping = true
36345          };
36346          self.conditional_stack['$<<']($hash2(["target", "skip", "skipping"], {"target": target, "skip": ski
36346p, "skipping": self.skipping}));
36347        } else if (!($truthy(self.skipping) || ($truthy(skip)))) {
36348          
36349          self.$replace_next_line(text.$rstrip());
36350          self.$unshift("");
36351          if ($truthy(text['$start_with?']("include::"))) {
36352            self.look_ahead = $rb_minus(self.look_ahead, 1)
36353          };
36354        };
36355        return true;
36356      });
36357      
36358      $def(self, '$preprocess_include_directive', function $$preprocess_include_directive(target, attrlist) {
36359        var $a, $b, self = this, doc = nil, expanded_target = nil, attr_missing = nil, $ret_or_1 = nil, ext = nil, parsed_attrs = nil, inc_path = nil, target_type = nil, relpath = nil, reader = nil, read_mode = nil, enc = nil, read_mode_params = nil, inc_linenos = nil, inc_tags = nil, tag = nil, inc_lines = nil, inc_offset = nil, inc_lineno = nil, tag_stack = nil, tags_selected = nil, active_tag = nil, select = nil, base_select = nil, wildcard = nil, missing_tags = nil, inc_content = nil;
36360
36361        
36362        doc = self.document;
36363        if (($truthy((expanded_target = target)['$include?']($$('ATTR_REF_HEAD'))) && ($truthy((expanded_target = doc.$sub_attributes(target, $hash2(["attribute_missing"], {"attribute_missing": ($eqeq((attr_missing = ($truthy(($ret_or_1 = doc.$attributes()['$[]']("attribute-missing"))) ? ($ret_or_1) : ($$('Compliance').$attribute_missing()))), "warn") ? ("drop-line") : (attr_missing))})))['$empty?']())))) {
36364          if (($eqeq(attr_missing, "drop-line") && ($truthy(doc.$sub_attributes($rb_plus(target, " "), $hash2(["attribute_missing", "drop_line_severity"], {"attribute_missing": "drop-line", "drop_line_severity": "ignore"}))['$empty?']())))) {
36365            
36366            $send(self.$logger(), 'info', [], function $$18(){var self = $$18.$$s == null ? this : $$18.$$s;
36367
36368              return self.$message_with_context("include dropped due to missing attribute: include::" + (target) + "[" + (attrlist) + "]", $hash2(["source_location"], {"source_location": self.$cursor()}))}, {$$s: self});
36369            self.$shift();
36370            return true;
36371          } else if ($truthy(doc.$parse_attributes(attrlist, [], $hash2(["sub_input"], {"sub_input": true}))['$[]']("optional-option"))) {
36372            
36373            $send(self.$logger(), 'info', [], function $$19(){var self = $$19.$$s == null ? this : $$19.$$s;
36374
36375              return self.$message_with_context("optional include dropped " + ((($eqeq(attr_missing, "warn") && ($truthy(doc.$sub_attributes($rb_plus(target, " "), $hash2(["attribute_missing", "drop_line_severity"], {"attribute_missing": "drop-line", "drop_line_severity": "ignore"}))['$empty?']()))) ? ("due to missing attribute") : ("because resolved target is blank"))) + ": include::" + (target) + "[" + (attrlist) + "]", $hash2(["source_location"], {"source_location": self.$cursor()}))}, {$$s: self});
36376            self.$shift();
36377            return true;
36378          } else {
36379            
36380            self.$logger().$warn(self.$message_with_context("include dropped " + ((($eqeq(attr_missing, "warn") && ($truthy(doc.$sub_attributes($rb_plus(target, " "), $hash2(["attribute_missing", "drop_line_severity"], {"attribute_missing": "drop-line", "drop_line_severity": "ignore"}))['$empty?']()))) ? ("due to missing attribute") : ("because resolved target is blank"))) + ": include::" + (target) + "[" + (attrlist) + "]", $hash2(["source_location"], {"source_location": self.$cursor()})));
36381            return self.$replace_next_line("Unresolved directive in " + (self.path) + " - include::" + (target) + "[" + (attrlist) + "]");
36382          }
36383        } else if (($truthy(self['$include_processors?']()) && ($truthy((ext = $send(self.include_processor_extensions, 'find', [], function $$20(candidate){
36384          
36385          if (candidate == null) candidate = nil;
36386          return candidate.$instance()['$handles?'](expanded_target);})))))) {
36387          
36388          self.$shift();
36389          ext.$process_method()['$[]'](doc, self, expanded_target, doc.$parse_attributes(attrlist, [], $hash2(["sub_input"], {"sub_input": true})));
36390          return true;
36391        } else if ($truthy($rb_ge(doc.$safe(), $$$($$('SafeMode'), 'SECURE')))) {
36392          return self.$replace_next_line("link:" + (expanded_target) + "[role=include]")
36393        } else if ($truthy(self.maxdepth)) {
36394          
36395          if ($truthy($rb_ge(self.include_stack.$size(), self.maxdepth['$[]']("curr")))) {
36396            
36397            self.$logger().$error(self.$message_with_context("maximum include depth of " + (self.maxdepth['$[]']("rel")) + " exceeded", $hash2(["source_location"], {"source_location": self.$cursor()})));
36398            return nil;
36399          };
36400          parsed_attrs = doc.$parse_attributes(attrlist, [], $hash2(["sub_input"], {"sub_input": true}));
36401          $b = self.$resolve_include_path(expanded_target, attrlist, parsed_attrs), $a = $to_ary($b), (inc_path = ($a[0] == null ? nil : $a[0])), (target_type = ($a[1] == null ? nil : $a[1])), (relpath = ($a[2] == null ? nil : $a[2])), $b;
36402          
36403          switch (target_type) {
36404            case "file":
36405              
36406              reader = $$$('File').$method("open");
36407              read_mode = $$('FILE_READ_MODE');
36408              break;
36409            case "uri":
36410              
36411              reader = $$$('OpenURI').$method("open_uri");
36412              read_mode = $$('URI_READ_MODE');
36413              break;
36414            default:
36415              return inc_path
36416          };
36417          if (!$truthy($$('RUBY_ENGINE_OPAL'))) {
36418            if (($truthy((enc = parsed_attrs['$[]']("encoding"))) && ($truthy((function() { try {
36419              return $$$('Encoding').$find(enc)
36420            } catch ($err) {
36421              if (Opal.rescue($err, [$$('StandardError')])) {
36422                try {
36423                  return nil
36424                } finally { Opal.pop_exception(); }
36425              } else { throw $err; }
36426            }})())))) {
36427              
36428              (read_mode_params = read_mode.$split(":"))['$[]='](1, enc);
36429              read_mode = read_mode_params.$join(":");
36430            }
36431          };
36432          inc_linenos = (inc_tags = nil);
36433          if ($truthy(attrlist)) {
36434            if ($truthy(parsed_attrs['$key?']("lines"))) {
36435              
36436              inc_linenos = [];
36437              $send(self.$split_delimited_value(parsed_attrs['$[]']("lines")), 'each', [], function $$21(linedef){var $c, $d, from = nil, _ = nil, to = nil;
36438
36439                
36440                if (linedef == null) linedef = nil;
36441                if ($truthy(linedef['$include?'](".."))) {
36442                  
36443                  $d = linedef.$partition(".."), $c = $to_ary($d), (from = ($c[0] == null ? nil : $c[0])), (_ = ($c[1] == null ? nil : $c[1])), (to = ($c[2] == null ? nil : $c[2])), $d;
36444                  return (inc_linenos = $rb_plus(inc_linenos, (($truthy(to['$empty?']()) || ($truthy($rb_lt((to = to.$to_i()), 0)))) ? ([from.$to_i(), $$$($$$('Float'), 'INFINITY')]) : (Opal.Range.$new(from.$to_i(), to, false).$to_a()))));
36445                } else {
36446                  return inc_linenos['$<<'](linedef.$to_i())
36447                };});
36448              inc_linenos = ($truthy(inc_linenos['$empty?']()) ? (nil) : (inc_linenos.$sort().$uniq()));
36449            } else if ($truthy(parsed_attrs['$key?']("tag"))) {
36450              if (!($truthy((tag = parsed_attrs['$[]']("tag"))['$empty?']()) || ($eqeq(tag, "!")))) {
36451                inc_tags = ($truthy(tag['$start_with?']("!")) ? ($hash(tag.$slice(1, tag.$length()), false)) : ($hash(tag, true)))
36452              }
36453            } else if ($truthy(parsed_attrs['$key?']("tags"))) {
36454              
36455              inc_tags = $hash2([], {});
36456              $send(self.$split_delimited_value(parsed_attrs['$[]']("tags")), 'each', [], function $$22(tagdef){var $c;
36457
36458                
36459                if (tagdef == null) tagdef = nil;
36460                if (($truthy(tagdef['$empty?']()) || ($eqeq(tagdef, "!")))) {
36461                  return nil
36462                } else if ($truthy(tagdef['$start_with?']("!"))) {
36463                  return ($c = [tagdef.$slice(1, tagdef.$length()), false], $send(inc_tags, '[]=', $c), $c[$c.length - 1])
36464                } else {
36465                  return ($c = [tagdef, true], $send(inc_tags, '[]=', $c), $c[$c.length - 1])
36466                };});
36467              if ($truthy(inc_tags['$empty?']())) {
36468                inc_tags = nil
36469              };
36470            }
36471          };
36472          if ($truthy(inc_linenos)) {
36473            
36474            $a = [[], nil, 0], (inc_lines = $a[0]), (inc_offset = $a[1]), (inc_lineno = $a[2]), $a;
36475            
36476            try {
36477              $send(reader, 'call', [inc_path, read_mode], function $$23(f){var select_remaining = nil;
36478
36479                
36480                if (f == null) f = nil;
36481                select_remaining = nil;
36482                return (function(){try { var $t_break = $thrower('break'); return $send(f, 'each_line', [], function $$24(l){var select = nil;
36483
36484                  
36485                  if (l == null) l = nil;
36486                  inc_lineno = $rb_plus(inc_lineno, 1);
36487                  if (($truthy(select_remaining) || (($eqeqeq($$$('Float'), (select = inc_linenos['$[]'](0))) && ($truthy((select_remaining = select['$infinite?']()))))))) {
36488                    
36489                    inc_offset = ($truthy(($ret_or_1 = inc_offset)) ? ($ret_or_1) : (inc_lineno));
36490                    return inc_lines['$<<'](l);
36491                  } else {
36492                    
36493                    if ($eqeq(select, inc_lineno)) {
36494                      
36495                      inc_offset = ($truthy(($ret_or_1 = inc_offset)) ? ($ret_or_1) : (inc_lineno));
36496                      inc_lines['$<<'](l);
36497                      inc_linenos.$shift();
36498                    };
36499                    if ($truthy(inc_linenos['$empty?']())) {
36500                      $t_break.$throw()
36501                    } else {
36502                      return nil
36503                    };
36504                  };})} catch($e) {
36505                  if ($e === $t_break) return $e.$v;
36506                  throw $e;
36507                }})();})
36508            } catch ($err) {
36509              if (Opal.rescue($err, [$$('StandardError')])) {
36510                try {
36511                  
36512                  self.$logger().$error(self.$message_with_context("include " + (target_type) + " not readable: " + (inc_path), $hash2(["source_location"], {"source_location": self.$cursor()})));
36513                  return self.$replace_next_line("Unresolved directive in " + (self.path) + " - include::" + (expanded_target) + "[" + (attrlist) + "]");
36514                } finally { Opal.pop_exception(); }
36515              } else { throw $err; }
36516            };;
36517            self.$shift();
36518            if ($truthy(inc_offset)) {
36519              
36520              parsed_attrs['$[]=']("partial-option", "");
36521              self.$push_include(inc_lines, inc_path, relpath, inc_offset, parsed_attrs);
36522            };
36523          } else if ($truthy(inc_tags)) {
36524            
36525            $a = [[], nil, 0, [], $$$('Set').$new(), nil], (inc_lines = $a[0]), (inc_offset = $a[1]), (inc_lineno = $a[2]), (tag_stack = $a[3]), (tags_selected = $a[4]), (active_tag = $a[5]), $a;
36526            if ($truthy(inc_tags['$key?']("**"))) {
36527              
36528              select = (base_select = inc_tags.$delete("**"));
36529              if ($truthy(inc_tags['$key?']("*"))) {
36530                wildcard = inc_tags.$delete("*")
36531              } else if (($not(select) && ($eqeq(inc_tags.$values().$first(), false)))) {
36532                wildcard = true
36533              };
36534            } else if ($truthy(inc_tags['$key?']("*"))) {
36535              if ($eqeq(inc_tags.$keys().$first(), "*")) {
36536                select = (base_select = (wildcard = inc_tags.$delete("*"))['$!']())
36537              } else {
36538                
36539                select = (base_select = false);
36540                wildcard = inc_tags.$delete("*");
36541              }
36542            } else {
36543              select = (base_select = inc_tags['$value?'](true)['$!']())
36544            };
36545            
36546            try {
36547              $send(reader, 'call', [inc_path, read_mode], function $$25(f){var $c, self = $$25.$$s == null ? this : $$25.$$s, dbl_co = nil, dbl_sb = nil;
36548
36549                
36550                if (f == null) f = nil;
36551                $c = ["::", "[]"], (dbl_co = $c[0]), (dbl_sb = $c[1]), $c;
36552                return $send(f, 'each_line', [], function $$26(l){var $d, $e, self = $$26.$$s == null ? this : $$26.$$s, this_tag = nil, include_cursor = nil, idx = nil;
36553
36554                  
36555                  if (l == null) l = nil;
36556                  inc_lineno = $rb_plus(inc_lineno, 1);
36557                  if ((($truthy(l['$include?'](dbl_co)) && ($truthy(l['$include?'](dbl_sb)))) && ($truthy($$('TagDirectiveRx')['$=~'](l))))) {
36558                    
36559                    this_tag = (($d = $gvars['~']) === nil ? nil : $d['$[]'](2));
36560                    if ($truthy((($d = $gvars['~']) === nil ? nil : $d['$[]'](1)))) {
36561                      if ($eqeq(this_tag, active_tag)) {
36562                        
36563                        tag_stack.$pop();
36564                        return $e = ($truthy(tag_stack['$empty?']()) ? ([nil, base_select]) : (tag_stack['$[]'](-1))), $d = $to_ary($e), (active_tag = ($d[0] == null ? nil : $d[0])), (select = ($d[1] == null ? nil : $d[1])), $e;
36565                      } else if ($truthy(inc_tags['$key?'](this_tag))) {
36566                        
36567                        include_cursor = self.$create_include_cursor(inc_path, expanded_target, inc_lineno);
36568                        if ($truthy((idx = $send(tag_stack, 'rindex', [], function $$27(key){
36569                          
36570                          if (key == null) key = nil;
36571                          return key['$=='](this_tag);}, {$$has_trailing_comma_in_args: true})))) {
36572                          
36573                          if ($eqeq(idx, 0)) {
36574                            tag_stack.$shift()
36575                          } else {
36576                            
36577                            tag_stack.$delete_at(idx);
36578                          };
36579                          return self.$logger().$warn(self.$message_with_context("mismatched end tag (expected '" + (active_tag) + "' but found '" + (this_tag) + "') at line " + (inc_lineno) + " of include " + (target_type) + ": " + (inc_path), $hash2(["source_location", "include_location"], {"source_location": self.$cursor(), "include_location": include_cursor})));
36580                        } else {
36581                          return self.$logger().$warn(self.$message_with_context("unexpected end tag '" + (this_tag) + "' at line " + (inc_lineno) + " of include " + (target_type) + ": " + (inc_path), $hash2(["source_location", "include_location"], {"source_location": self.$cursor(), "include_location": include_cursor})))
36582                        };
36583                      } else {
36584                        return nil
36585                      }
36586                    } else if ($truthy(inc_tags['$key?'](this_tag))) {
36587                      
36588                      if ($truthy((select = inc_tags['$[]'](this_tag)))) {
36589                        tags_selected['$<<'](this_tag)
36590                      };
36591                      return tag_stack['$<<']([(active_tag = this_tag), select, inc_lineno]);
36592                    } else if ($not(wildcard['$nil?']())) {
36593                      
36594                      select = (($truthy(active_tag) && ($not(select))) ? (false) : (wildcard));
36595                      return tag_stack['$<<']([(active_tag = this_tag), select, inc_lineno]);
36596                    } else {
36597                      return nil
36598                    };
36599                  } else if ($truthy(select)) {
36600                    
36601                    inc_offset = ($truthy(($ret_or_1 = inc_offset)) ? ($ret_or_1) : (inc_lineno));
36602                    return inc_lines['$<<'](l);
36603                  } else {
36604                    return nil
36605                  };}, {$$s: self});}, {$$s: self})
36606            } catch ($err) {
36607              if (Opal.rescue($err, [$$('StandardError')])) {
36608                try {
36609                  
36610                  self.$logger().$error(self.$message_with_context("include " + (target_type) + " not readable: " + (inc_path), $hash2(["source_location"], {"source_location": self.$cursor()})));
36611                  return self.$replace_next_line("Unresolved directive in " + (self.path) + " - include::" + (expanded_target) + "[" + (attrlist) + "]");
36612                } finally { Opal.pop_exception(); }
36613              } else { throw $err; }
36614            };;
36615            if (!$truthy(tag_stack['$empty?']())) {
36616              $send(tag_stack, 'each', [], function $$28(tag_name, _, tag_lineno){var self = $$28.$$s == null ? this : $$28.$$s;
36617
36618                
36619                if (tag_name == null) tag_name = nil;
36620                if (_ == null) _ = nil;
36621                if (tag_lineno == null) tag_lineno = nil;
36622                return self.$logger().$warn(self.$message_with_context("detected unclosed tag '" + (tag_name) + "' starting at line " + (tag_lineno) + " of include " + (target_type) + ": " + (inc_path), $hash2(["source_location", "include_location"], {"source_location": self.$cursor(), "include_location": self.$create_include_cursor(inc_path, expanded_target, tag_lineno)})));}, {$$s: self})
36623            };
36624            if (!$truthy((missing_tags = $rb_minus($send(inc_tags, 'keep_if', [], function $$29(_, v){
36625              
36626              if (_ == null) _ = nil;
36627              if (v == null) v = nil;
36628              return v;}).$keys(), tags_selected.$to_a()))['$empty?']())) {
36629              self.$logger().$warn(self.$message_with_context("tag" + (($truthy($rb_gt(missing_tags.$size(), 1)) ? ("s") : (""))) + " '" + (missing_tags.$join(", ")) + "' not found in include " + (target_type) + ": " + (inc_path), $hash2(["source_location"], {"source_location": self.$cursor()})))
36630            };
36631            self.$shift();
36632            if ($truthy(inc_offset)) {
36633              
36634              if (!(($truthy(base_select) && ($neqeq(wildcard, false))) && ($truthy(inc_tags['$empty?']())))) {
36635                parsed_attrs['$[]=']("partial-option", "")
36636              };
36637              self.$push_include(inc_lines, inc_path, relpath, inc_offset, parsed_attrs);
36638            };
36639          } else {
36640            
36641            inc_content = nil;
36642            
36643            try {
36644              
36645              inc_content = $send(reader, 'call', [inc_path, read_mode], function $$30(f){
36646                
36647                if (f == null) f = nil;
36648                return f.$read();});
36649              self.$shift();
36650            } catch ($err) {
36651              if (Opal.rescue($err, [$$('StandardError')])) {
36652                try {
36653                  
36654                  self.$logger().$error(self.$message_with_context("include " + (target_type) + " not readable: " + (inc_path), $hash2(["source_location"], {"source_location": self.$cursor()})));
36655                  return self.$replace_next_line("Unresolved directive in " + (self.path) + " - include::" + (expanded_target) + "[" + (attrlist) + "]");
36656                } finally { Opal.pop_exception(); }
36657              } else { throw $err; }
36658            };;
36659            self.$push_include(inc_content, inc_path, relpath, 1, parsed_attrs);
36660          };
36661          return true;
36662        } else {
36663          return nil
36664        };
36665      });
36666      
36667      $def(self, '$resolve_include_path', function $$resolve_include_path(target, attrlist, attributes) {
36668        var $a, $b, self = this, doc = nil, inc_path = nil, relpath = nil;
36669
36670        
36671        doc = self.document;
36672        if (($truthy($$('Helpers')['$uriish?'](target)) || ($truthy(($eqeqeq($$$('String'), self.dir) ? (nil) : ((target = "" + (self.dir) + "/" + (target)))))))) {
36673          
36674          if (!$truthy(doc['$attr?']("allow-uri-read"))) {
36675            return self.$replace_next_line("link:" + (target) + "[role=include]")
36676          };
36677          if ($truthy(doc['$attr?']("cache-uri"))) {
36678            if (!$truthy((($b = $$$('::', 'OpenURI', 'skip_raise')) && ($a = $$$($b, 'Cache', 'ski
36678p_raise')) ? 'constant' : nil))) {
36679              $$('Helpers').$require_library("open-uri/cached", "open-uri-cached")
36680            }
36681          } else if ($not($$('RUBY_ENGINE_OPAL'))) {
36682            $$$('OpenURI')
36683          };
36684          return [$$$('URI').$parse(target), "uri", target];
36685        } else {
36686          
36687          inc_path = doc.$normalize_system_path(target, self.dir, nil, $hash2(["target_name"], {"target_name": "include file"}));
36688          if (!$truthy($$$('File')['$file?'](inc_path))) {
36689            if ($truthy(attributes['$[]']("optional-option"))) {
36690              
36691              $send(self.$logger(), 'info', [], function $$31(){var self = $$31.$$s == null ? this : $$31.$$s;
36692
36693                return self.$message_with_context("optional include dropped because include file not found: " + (inc_path), $hash2(["source_location"], {"source_location": self.$cursor()}))}, {$$s: self});
36694              self.$shift();
36695              return true;
36696            } else {
36697              
36698              self.$logger().$error(self.$message_with_context("include file not found: " + (inc_path), $hash2(["source_location"], {"source_location": self.$cursor()})));
36699              return self.$replace_next_line("Unresolved directive in " + (self.path) + " - include::" + (target) + "[" + (attrlist) + "]");
36700            }
36701          };
36702          relpath = doc.$path_resolver().$relative_path(inc_path, doc.$base_dir());
36703          return [inc_path, "file", relpath];
36704        };
36705      });
36706      
36707      $def(self, '$pop_include', function $$pop_include() {
36708        var $a, $b, self = this;
36709
36710        if ($truthy(self.include_stack['$empty?']())) {
36711          return nil
36712        } else {
36713          
36714          $b = self.include_stack.$pop(), $a = $to_ary($b), (self.lines = ($a[0] == null ? nil : $a[0])), (self.file = ($a[1] == null ? nil : $a[1])), (self.dir = ($a[2] == null ? nil : $a[2])), (self.path = ($a[3] == null ? nil : $a[3])), (self.lineno = ($a[4] == null ? nil : $a[4])), (self.maxdepth = ($a[5] == null ? nil : $a[5])), (self.process_lines = ($a[6] == null ? nil : $a[6])), $b;
36715          self.look_ahead = 0;
36716          return nil;
36717        }
36718      });
36719      
36720      $def(self, '$split_delimited_value', function $$split_delimited_value(val) {
36721        
36722        if ($truthy(val['$include?'](","))) {
36723          
36724          return val.$split(",");
36725        } else {
36726          
36727          return val.$split(";");
36728        }
36729      });
36730      
36731      $def(self, '$skip_front_matter!', function $PreprocessorReader_skip_front_matter$excl$32(data, increment_linenos) {
36732        var self = this, delim = nil, original_data = nil, front_matter = nil, $ret_or_1 = nil, eof = nil;
36733
36734        
36735        if (increment_linenos == null) increment_linenos = true;
36736        if (!$eqeq((delim = data['$[]'](0)), "---")) {
36737          return nil
36738        };
36739        original_data = data.$drop(0);
36740        data.$shift();
36741        front_matter = [];
36742        if ($truthy(increment_linenos)) {
36743          self.lineno = $rb_plus(self.lineno, 1)
36744        };
36745        while (!($truthy(($truthy(($ret_or_1 = (eof = data['$empty?']()))) ? ($ret_or_1) : (data['$[]'](0)['$=='](delim)))))) {
36746        
36747          front_matter['$<<'](data.$shift());
36748          if ($truthy(increment_linenos)) {
36749            self.lineno = $rb_plus(self.lineno, 1)
36750          };
36751        };
36752        if ($truthy(eof)) {
36753          
36754          $send(data, 'unshift', $to_a(original_data));
36755          if ($truthy(increment_linenos)) {
36756            self.lineno = $rb_minus(self.lineno, original_data.$size())
36757          };
36758          return nil;
36759        };
36760        data.$shift();
36761        if ($truthy(increment_linenos)) {
36762          self.lineno = $rb_plus(self.lineno, 1)
36763        };
36764        return front_matter;
36765      }, -2);
36766      return $def(self, '$resolve_expr_val', function $$resolve_expr_val(val) {
36767        var self = this, quoted = nil;
36768
36769        
36770        if ((($truthy(val['$start_with?']("\"")) && ($truthy(val['$end_with?']("\"")))) || (($truthy(val['$start_with?']("'")) && ($truthy(val['$end_with?']("'"))))))) {
36771          
36772          quoted = true;
36773          val = val.$slice(1, $rb_minus(val.$length(), 1));
36774        } else {
36775          quoted = false
36776        };
36777        if ($truthy(val['$include?']($$('ATTR_REF_HEAD')))) {
36778          val = self.document.$sub_attributes(val, $hash2(["attribute_missing"], {"attribute_missing": "drop"}))
36779        };
36780        if ($truthy(quoted)) {
36781          return val
36782        } else if ($truthy(val['$empty?']())) {
36783          return nil
36784        } else if ($eqeq(val, "true")) {
36785          return true
36786        } else if ($eqeq(val, "false")) {
36787          return false
36788        } else if ($truthy(val.$rstrip()['$empty?']())) {
36789          return " "
36790        } else if ($truthy(val['$include?']("."))) {
36791          return val.$to_f()
36792        } else {
36793          return val.$to_i()
36794        };
36795      });
36796    })($nesting[0], $$('Reader'), $nesting);
36797  })($nesting[0], $nesting)
36798};
36799
36800Opal.modules["asciidoctor/section"] = function(Opal) {/* Generated by Opal 1.7.3 */
36801  "use strict";
36802  var $module = Opal.module, $klass = Opal.klass, $hash2 = Opal.hash2, $send2 = Opal.send2, $find_super = Opal.find_super, $eqeqeq = Opal.eqeqeq, $truthy = Opal.truthy, $rb_plus = Opal.rb_plus, $def = Opal.def, $alias = Opal.alias, $rb_gt = Opal.rb_gt, $eqeq = Opal.eqeq, $not = Opal.not, $send = Opal.send, $defs = Opal.defs, $nesting = [], nil = Opal.nil;
36803
36804  Opal.add_stubs('attr_accessor,attr_reader,===,+,level,special,title,generate_id,>,==,sectnum,!,empty?,reftext,sub_placeholder,sub_quotes,compat_mode,[],attributes,context,assign_numeral,class,object_id,inspect,size,[]=,chr,length,gsub,downcase,delete,tr_s,end_with?,chop,start_with?,slice,key?,catalog,unique_id_start_index');
36805  return (function($base, $parent_nesting) {
36806    var self = $module($base, 'Asciidoctor');
36807
36808    var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
36809
36810    return (function($base, $super, $parent_nesting) {
36811      var self = $klass($base, $super, 'Section');
36812
36813      var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype;
36814
36815      $proto.document = $proto.next_section_index = $proto.parent = $proto.level = $proto.numeral = $proto.numbered = $proto.sectname = $proto.title = $proto.blocks = nil;
36816      
36817      self.$attr_accessor("index");
36818      self.$attr_accessor("sectname");
36819      self.$attr_accessor("special");
36820      self.$attr_accessor("numbered");
36821      self.$attr_reader("caption");
36822      
36823      $def(self, '$initialize', function $$initialize(parent, level, numbered, opts) {
36824        var $a, $yield = $$initialize.$$p || nil, self = this, $ret_or_1 = nil;
36825
36826        $$initialize.$$p = null;
36827        
36828        if (parent == null) parent = nil;
36829        if (level == null) level = nil;
36830        if (numbered == null) numbered = false;
36831        if (opts == null) opts = $hash2([], {});
36832        $send2(self, $find_super(self, 'initialize', $$initialize, false, true), 'initialize', [parent, "section", opts], null);
36833        if ($eqeqeq($$('Section'), parent)) {
36834          $a = [($truthy(($ret_or_1 = level)) ? ($ret_or_1) : ($rb_plus(parent.$level(), 1))), parent.$special()], (self.level = $a[0]), (self.special = $a[1]), $a
36835        } else {
36836          $a = [($truthy(($ret_or_1 = level)) ? ($ret_or_1) : (1)), false], (self.level = $a[0]), (self.special = $a[1]), $a
36837        };
36838        self.numbered = numbered;
36839        return (self.index = 0);
36840      }, -1);
36841      $alias(self, "name", "title");
36842      
36843      $def(self, '$generate_id', function $$generate_id() {
36844        var self = this;
36845
36846        return $$('Section').$generate_id(self.$title(), self.document)
36847      });
36848      
36849      $def(self, '$sections?', function $Section_sections$ques$1() {
36850        var self = this;
36851
36852        return $rb_gt(self.next_section_index, 0)
36853      });
36854      
36855      $def(self, '$sectnum', function $$sectnum(delimiter, append) {
36856        var self = this, $ret_or_1 = nil;
36857
36858        
36859        if (delimiter == null) delimiter = ".";
36860        if (append == null) append = nil;
36861        append = ($truthy(($ret_or_1 = append)) ? ($ret_or_1) : (($eqeq(append, false) ? ("") : (delimiter))));
36862        if (($truthy($rb_gt(self.level, 1)) && ($eqeqeq($$('Section'), self.parent)))) {
36863          return "" + (self.parent.$sectnum(delimiter, delimiter)) + (self.numeral) + (append)
36864        } else {
36865          return "" + (self.numeral) + (append)
36866        };
36867      }, -1);
36868      
36869      $def(self, '$xreftext', function $$xreftext(xrefstyle) {
36870        var self = this, val = nil, type = nil, quoted_title = nil, signifier = nil;
36871
36872        
36873        if (xrefstyle == null) xrefstyle = nil;
36874        if (($truthy((val = self.$reftext())) && ($not(val['$empty?']())))) {
36875          return val
36876        } else if ($truthy(xrefstyle)) {
36877          if ($truthy(self.numbered)) {
36878            
36879            switch (xrefstyle) {
36880              case "full":
36881                
36882                if (($eqeq((type = self.sectname), "chapter") || ($eqeq(type, "appendix")))) {
36883                  quoted_title = self.$sub_placeholder(self.$sub_quotes("_%s_"), self.$title())
36884                } else {
36885                  quoted_title = self.$sub_placeholder(self.$sub_quotes(($truthy(self.document.$compat_mode()) ? ("``%s''") : ("\"`%s`\""))), self.$title())
36886                };
36887                if ($truthy((signifier = self.document.$attributes()['$[]']("" + (type) + "-refsig")))) {
36888                  return "" + (signifier) + " " + (self.$sectnum(".", ",")) + " " + (quoted_title)
36889                } else {
36890                  return "" + (self.$sectnum(".", ",")) + " " + (quoted_title)
36891                };
36892                break;
36893              case "short":
36894                if ($truthy((signifier = self.document.$attributes()['$[]']("" + (self.sectname) + "-refsig")))) {
36895                  return "" + (signifier) + " " + (self.$sectnum(".", ""))
36896                } else {
36897                  return self.$sectnum(".", "")
36898                }
36899                break;
36900              default:
36901                if (($eqeq((type = self.sectname), "chapter") || ($eqeq(type, "appendix")))) {
36902                  
36903                  return self.$sub_placeholder(self.$sub_quotes("_%s_"), self.$title());
36904                } else {
36905                  return self.$title()
36906                }
36907            }
36908          } else if (($eqeq((type = self.sectname), "chapter") || ($eqeq(type, "appendix")))) {
36909            
36910            return self.$sub_placeholder(self.$sub_quotes("_%s_"), self.$title());
36911          } else {
36912            return self.$title()
36913          }
36914        } else {
36915          return self.$title()
36916        };
36917      }, -1);
36918      
36919      $def(self, '$<<', function $Section_$lt$lt$2(block) {
36920        var $yield = $Section_$lt$lt$2.$$p || nil, self = this;
36921
36922        $Section_$lt$lt$2.$$p = null;
36923        
36924        if ($eqeq(block.$context(), "section")) {
36925          self.$assign_numeral(block)
36926        };
36927        return $send2(self, $find_super(self, '<<', $Section_$lt$lt$2, false, true), '<<', [block], $yield);
36928      });
36929      
36930      $def(self, '$to_s', function $$to_s() {
36931        var $yield = $$to_s.$$p || nil, self = this, formal_title = nil;
36932
36933        $$to_s.$$p = null;
36934        if ($truthy(self.title)) {
36935          
36936          formal_title = ($truthy(self.numbered) ? ("" + (self.$sectnum()) + " " + (self.title)) : (self.title));
36937          return "#<" + (self.$class()) + "@" + (self.$object_id()) + " {level: " + (self.level) + ", title: " + (formal_title.$inspect()) + ", blocks: " + (self.blocks.$size()) + "}>";
36938        } else {
36939          return $send2(self, $find_super(self, 'to_s', $$to_s, false, true), 'to_s', [], $yield)
36940        }
36941      });
36942      return $defs(self, '$generate_id', function $$generate_id(title, document) {
36943        var $a, attrs = nil, pre = nil, $ret_or_1 = nil, sep = nil, no_sep = nil, sep_sub = nil, gen_id = nil, ids = nil, cnt = nil, candidate_id = nil;
36944
36945        
36946        attrs = document.$attributes();
36947        pre = ($truthy(($ret_or_1 = attrs['$[]']("idprefix"))) ? ($ret_or_1) : ("_"));
36948        if ($truthy((sep = attrs['$[]']("idseparator")))) {
36949          if (($eqeq(sep.$length(), 1) || (($not((no_sep = sep['$empty?']())) && ($truthy((sep = ($a = ["idseparator", sep.$chr()], $send(attrs, '[]=', $a), $a[$a.length - 1])))))))) {
36950            sep_sub = (($eqeq(sep, "-") || ($eqeq(sep, "."))) ? (" .-") : (" " + (sep) + ".-"))
36951          }
36952        } else {
36953          $a = ["_", " _.-"], (sep = $a[0]), (sep_sub = $a[1]), $a
36954        };
36955        gen_id = "" + (pre) + (title.$downcase().$gsub($$('InvalidSectionIdCharsRx'), ""));
36956        if ($truthy(no_sep)) {
36957          gen_id = gen_id.$delete(" ")
36958        } else {
36959          
36960          gen_id = gen_id.$tr_s(sep_sub, sep);
36961          if ($truthy(gen_id['$end_with?'](sep))) {
36962            gen_id = gen_id.$chop()
36963          };
36964          if (($truthy(pre['$empty?']()) && ($truthy(gen_id['$start_with?'](sep))))) {
36965            gen_id = gen_id.$slice(1, gen_id.$length())
36966          };
36967        };
36968        if ($truthy(document.$catalog()['$[]']("refs")['$key?'](gen_id))) {
36969          
36970          ids = document.$catalog()['$[]']("refs");
36971          cnt = $$('Compliance').$unique_id_start_index();
36972          while ($truthy(ids['$[]']((candidate_id = "" + (gen_id) + (sep) + (cnt))))) {
36973          cnt = $rb_plus(cnt, 1)
36974          };
36975          return candidate_id;
36976        } else {
36977          return gen_id
36978        };
36979      });
36980    })($nesting[0], $$('AbstractBlock'), $nesting)
36981  })($nesting[0], $nesting)
36982};
36983
36984Opal.modules["asciidoctor/stylesheets"] = function(Opal) {/* Generated by Opal 1.7.3 */
36985  "use strict";
36986  var $module = Opal.module, $klass = Opal.klass, $const_set = Opal.const_set, $return_ivar = Opal.return_ivar, $defs = Opal.defs, $def = Opal.def, $truthy = Opal.truthy, $hash2 = Opal.hash2, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$;
36987
36988  Opal.add_stubs('join,new,rstrip,read,primary_stylesheet_data,write,primary_stylesheet_name,stylesheet_basename,for,read_stylesheet,coderay_stylesheet_data,coderay_stylesheet_name,pygments_stylesheet_data,pygments_stylesheet_name');
36989  return (function($base, $parent_nesting) {
36990    var self = $module($base, 'Asciidoctor');
36991
36992    var $nesting = [self].concat($parent_nesting);
36993
36994    return (function($base, $super, $parent_nesting) {
36995      var self = $klass($base, $super, 'Stylesheets');
36996
36997      var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype;
36998
36999      $proto.primary_stylesheet_data = nil;
37000      
37001      $const_set($nesting[0], 'DEFAULT_STYLESHEET_NAME', "asciidoctor.css");
37002      $const_set($nesting[0], 'STYLESHEETS_DIR', $$$('File').$join($$('DATA_DIR'), "stylesheets"));
37003      self.__instance__ = self.$new();
37004      $defs(self, '$instance', $return_ivar("__instance__"));
37005      
37006      $def(self, '$primary_stylesheet_name', function $$primary_stylesheet_name() {
37007        
37008        return $$('DEFAULT_STYLESHEET_NAME')
37009      });
37010      
37011      $def(self, '$primary_stylesheet_data', function $$primary_stylesheet_data() {
37012        var self = this, $ret_or_1 = nil;
37013
37014        return (self.primary_stylesheet_data = ($truthy(($ret_or_1 = self.primary_stylesheet_data)) ? ($ret_or_1) : ($$$('File').$read($$$('File').$join($$('STYLESHEETS_DIR'), "asciidoctor-default.css"), $hash2(["mode"], {"mode": $$('FILE_READ_MODE')})).$rstrip())))
37015      });
37016      
37017      $def(self, '$embed_primary_stylesheet', function $$embed_primary_stylesheet() {
37018        var self = this;
37019
37020        return "<style>\n" + (self.$primary_stylesheet_data()) + "\n" + "</style>"
37021      });
37022      
37023      $def(self, '$write_primary_stylesheet', function $$write_primary_stylesheet(target_dir) {
37024        var self = this;
37025
37026        
37027        if (target_dir == null) target_dir = ".";
37028        return $$$('File').$write($$$('File').$join(target_dir, self.$primary_stylesheet_name()), self.$primary_stylesheet_data(), $hash2(["mode"], {"mode": $$('FILE_WRITE_MODE')}));
37029      }, -1);
37030      
37031      $def(self, '$coderay_stylesheet_name', function $$coderay_stylesheet_name() {
37032        
37033        return $$('SyntaxHighlighter').$for("coderay").$stylesheet_basename()
37034      });
37035      
37036      $def(self, '$coderay_stylesheet_data', function $$coderay_stylesheet_data() {
37037        
37038        return $$('SyntaxHighlighter').$for("coderay").$read_stylesheet()
37039      });
37040      
37041      $def(self, '$embed_coderay_stylesheet', function $$embed_coderay_stylesheet() {
37042        var self = this;
37043
37044        return "<style>\n" + (self.$coderay_stylesheet_data()) + "\n" + "</style>"
37045      });
37046      
37047      $def(self, '$write_coderay_stylesheet', function $$write_coderay_stylesheet(target_dir) {
37048        var self = this;
37049
37050        
37051        if (target_dir == null) target_dir = ".";
37052        return $$$('File').$write($$$('File').$join(target_dir, self.$coderay_stylesheet_name()), self.$coderay_stylesheet_data(), $hash2(["mode"], {"mode": $$('FILE_WRITE_MODE')}));
37053      }, -1);
37054      
37055      $def(self, '$pygments_stylesheet_name', function $$pygments_stylesheet_name(style) {
37056        
37057        
37058        if (style == null) style = nil;
37059        return $$('SyntaxHighlighter').$for("pygments").$stylesheet_basename(style);
37060      }, -1);
37061      
37062      $def(self, '$pygments_stylesheet_data', function $$pygments_stylesheet_data(style) {
37063        
37064        
37065        if (style == null) style = nil;
37066        return $$('SyntaxHighlighter').$for("pygments").$read_stylesheet(style);
37067      }, -1);
37068      
37069      $def(self, '$embed_pygments_stylesheet', function $$embed_pygments_stylesheet(style) {
37070        var self = this;
37071
37072        
37073        if (style == null) style = nil;
37074        return "<style>\n" + (self.$pygments_stylesheet_data(style)) + "\n" + "</style>";
37075      }, -1);
37076      return $def(self, '$write_pygments_stylesheet', function $$write_pygments_stylesheet(target_dir, style) {
37077        var self = this;
37078
37079        
37080        if (target_dir == null) target_dir = ".";
37081        if (style == null) style = nil;
37082        return $$$('File').$write($$$('File').$join(target_dir, self.$pygments_stylesheet_name(style)), self.$pygments_stylesheet_data(style), $hash2(["mode"], {"mode": $$('FILE_WRITE_MODE')}));
37083      }, -1);
37084    })($nesting[0], null, $nesting)
37085  })($nesting[0], $nesting)
37086};
37087
37088Opal.modules["asciidoctor/table"] = function(Opal) {/* Generated by Opal 1.7.3 */
37089  "use strict";
37090  var $module = Opal.module, $klass = Opal.klass, $const_set = Opal.const_set, $def = Opal.def, $alias = Opal.alias, $hash2 = Opal.hash2, $send2 = Opal.send2, $find_super = Opal.find_super, $truthy = Opal.truthy, $rb_lt = Opal.rb_lt, $rb_gt = Opal.rb_gt, $eqeq = Opal.eqeq, $rb_times = Opal.rb_times, $rb_divide = Opal.rb_divide, $send = Opal.send, $rb_plus = Opal.rb_plus, $rb_minus = Opal.rb_minus, $return_val = Opal.return_val, $to_a = Opal.to_a, $gvars = Opal.gvars, $neqeq = Opal.neqeq, $return_ivar = Opal.return_ivar, $to_ary = Opal.to_ary, $regexp = Opal.regexp, $not = Opal.not, $thrower = Opal.thrower, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$;
37091
37092  Opal.add_stubs('attr_accessor,send,attr_reader,new,[],<,>,to_i,==,[]=,attributes,truncate,*,/,to_f,empty?,body,each,<<,size,+,assign_column_widths,warn,logger,-,update_attributes,assign_width,round,head=,map,shift,reinitialize,nil?,unshift,foot=,pop,parent,sourcemap,dup,header_row?,table,style,merge,delete,start_with?,rstrip,slice,length,advance,lstrip,strip,split,include?,readlines,catalog_inline_anch
37092or,=~,apply_subs,attr_writer,convert,text,!=,file,lineno,include,to_set,mark,key?,nested?,document,error,message_with_context,cursor_at_prev_line,nil_or_empty?,escape,columns,match,chop,end_with?,gsub,!,push_cellspec,cell_open?,close_cell,take_cellspec,squeeze,upto,times,cursor_before_mark,rowspan,activate_rowspan,colspan,end_of_row?,close_row,private,rows,effective_column_visits');
37093  return (function($base, $parent_nesting) {
37094    var self = $module($base, 'Asciidoctor');
37095
37096    var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
37097
37098    
37099    (function($base, $super, $parent_nesting) {
37100      var self = $klass($base, $super, 'Table');
37101
37102      var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype;
37103
37104      $proto.attributes = $proto.document = $proto.rows = $proto.has_header_option = $proto.columns = nil;
37105      
37106      $const_set($nesting[0], 'DEFAULT_PRECISION', 4);
37107      (function($base, $super) {
37108        var self = $klass($base, $super, 'Rows');
37109
37110        var $proto = self.$$prototype;
37111
37112        $proto.head = $proto.body = $proto.foot = nil;
37113        
37114        self.$attr_accessor("head", "foot", "body");
37115        
37116        $def(self, '$initialize', function $$initialize(head, foot, body) {
37117          var self = this;
37118
37119          
37120          if (head == null) head = [];
37121          if (foot == null) foot = [];
37122          if (body == null) body = [];
37123          self.head = head;
37124          self.foot = foot;
37125          return (self.body = body);
37126        }, -1);
37127        $alias(self, "[]", "send");
37128        
37129        $def(self, '$by_section', function $$by_section() {
37130          var self = this;
37131
37132          return [["head", self.head], ["body", self.body], ["foot", self.foot]]
37133        });
37134        return $def(self, '$to_h', function $$to_h() {
37135          var self = this;
37136
37137          return $hash2(["head", "body", "foot"], {"head": self.head, "body": self.body, "foot": self.foot})
37138        });
37139      })($nesting[0], null);
37140      self.$attr_accessor("columns");
37141      self.$attr_accessor("rows");
37142      self.$attr_accessor("has_header_option");
37143      self.$attr_reader("caption");
37144      
37145      $def(self, '$initialize', function $$initialize(parent, attributes) {
37146        var $a, $yield = $$initialize.$$p || nil, self = this, pcwidth = nil, pcwidth_intval = nil, abswidth_val = nil;
37147
37148        $$initialize.$$p = null;
37149        
37150        $send2(self, $find_super(self, 'initialize', $$initialize, false, true), 'initialize', [parent, "table"], null);
37151        self.rows = $$('Rows').$new();
37152        self.columns = [];
37153        self.has_header_option = false;
37154        if ($truthy((pcwidth = attributes['$[]']("width")))) {
37155          if (($truthy($rb_gt((pcwidth_intval = pcwidth.$to_i()), 100)) || ($truthy($rb_lt(pcwidth_intval, 1))))) {
37156            if (!($eqeq(pcwidth_intval, 0) && (($eqeq(pcwidth, "0") || ($eqeq(pcwidth, "0%")))))) {
37157              pcwidth_intval = 100
37158            }
37159          }
37160        } else {
37161          pcwidth_intval = 100
37162        };
37163        self.attributes['$[]=']("tablepcwidth", pcwidth_intval);
37164        if ($truthy(self.document.$attributes()['$[]']("pagewidth"))) {
37165          self.attributes['$[]=']("tableabswidth", ($eqeq((abswidth_val = $rb_times($rb_divide(pcwidth_intval, 100), self.document.$attributes()['$[]']("pagewidth").$to_f()).$truncate($$('DEFAULT_PRECISION'))), abswidth_val.$to_i()) ? (abswidth_val.$to_i()) : (abswidth_val)))
37166        };
37167        if ($truthy(attributes['$[]']("rotate-option"))) {
37168          return ($a = ["orientation", "landscape"], $send(self.attributes, '[]=', $a), $a[$a.length - 1])
37169        } else {
37170          return nil
37171        };
37172      });
37173      
37174      $def(self, '$header_row?', function $Table_header_row$ques$1() {
37175        var self = this, val = nil;
37176
37177        if (($truthy((val = self.has_header_option)) && ($truthy(self.rows.$body()['$empty?']())))) {
37178          return val
37179        } else {
37180          return nil
37181        }
37182      });
37183      
37184      $def(self, '$create_columns', function $$create_columns(colspecs) {
37185        var self = this, cols = nil, autowidth_cols = nil, width_base = nil, num_c
37185ols = nil;
37186
37187        
37188        cols = [];
37189        autowidth_cols = nil;
37190        width_base = 0;
37191        $send(colspecs, 'each', [], function $$2(colspec){var self = $$2.$$s == null ? this : $$2.$$s, colwidth = nil, $ret_or_1 = nil;
37192
37193          
37194          if (colspec == null) colspec = nil;
37195          colwidth = colspec['$[]']("width");
37196          cols['$<<']($$('Column').$new(self, cols.$size(), colspec));
37197          if ($truthy($rb_lt(colwidth, 0))) {
37198            return (autowidth_cols = ($truthy(($ret_or_1 = autowidth_cols)) ? ($ret_or_1) : ([])))['$<<'](cols['$[]'](-1))
37199          } else {
37200            return (width_base = $rb_plus(width_base, colwidth))
37201          };}, {$$s: self});
37202        if ($truthy($rb_gt((num_cols = (self.columns = cols).$size()), 0))) {
37203          
37204          self.attributes['$[]=']("colcount", num_cols);
37205          if (!($truthy($rb_gt(width_base, 0)) || ($truthy(autowidth_cols)))) {
37206            width_base = nil
37207          };
37208          self.$assign_column_widths(width_base, autowidth_cols);
37209        };
37210        return nil;
37211      });
37212      
37213      $def(self, '$assign_column_widths', function $$assign_column_widths(width_base, autowidth_cols) {
37214        var self = this, precision = nil, total_width = nil, col_pcwidth = nil, autowidth = nil, autowidth_attrs = nil;
37215
37216        
37217        if (width_base == null) width_base = nil;
37218        if (autowidth_cols == null) autowidth_cols = nil;
37219        precision = $$('DEFAULT_PRECISION');
37220        total_width = (col_pcwidth = 0);
37221        if ($truthy(width_base)) {
37222          
37223          if ($truthy(autowidth_cols)) {
37224            
37225            if ($truthy($rb_gt(width_base, 100))) {
37226              
37227              autowidth = 0;
37228              self.$logger().$warn("total column width must not exceed 100% when using autowidth columns; got " + (width_base) + "%");
37229            } else {
37230              
37231              autowidth = $rb_divide($rb_minus(100, width_base), autowidth_cols.$size()).$truncate(precision);
37232              if ($eqeq(autowidth.$to_i(), autowidth)) {
37233                autowidth = autowidth.$to_i()
37234              };
37235              width_base = 100;
37236            };
37237            autowidth_attrs = $hash2(["width", "autowidth-option"], {"width": autowidth, "autowidth-option": ""});
37238            $send(autowidth_cols, 'each', [], function $$3(col){
37239              
37240              if (col == null) col = nil;
37241              return col.$update_attributes(autowidth_attrs);});
37242          };
37243          $send(self.columns, 'each', [], function $$4(col){
37244            
37245            if (col == null) col = nil;
37246            return (total_width = $rb_plus(total_width, (col_pcwidth = col.$assign_width(nil, width_base, precision))));});
37247        } else {
37248          
37249          col_pcwidth = $rb_divide(100, self.columns.$size()).$truncate(precision);
37250          if ($eqeq(col_pcwidth.$to_i(), col_pcwidth)) {
37251            col_pcwidth = col_pcwidth.$to_i()
37252          };
37253          $send(self.columns, 'each', [], function $$5(col){
37254            
37255            if (col == null) col = nil;
37256            return (total_width = $rb_plus(total_width, col.$assign_width(col_pcwidth, nil, precision)));});
37257        };
37258        if (!$eqeq(total_width, 100)) {
37259          self.columns['$[]'](-1).$assign_width($rb_plus($rb_minus(100, total_width), col_pcwidth).$round(precision), nil, precision)
37260        };
37261        return nil;
37262      }, -1);
37263      return $def(self, '$partition_header_footer', function $$partition_header_footer(attrs) {
37264        var $a, self = this, num_body_rows = nil, body = nil;
37265
37266        
37267        num_body_rows = ($a = ["rowcount", (body = self.rows.$body()).$size()], $send(self.attributes, '[]=', $a), $a[$a.length - 1]);
37268        if ($truthy($rb_gt(num_body_rows, 0))) {
37269          if ($truthy(self.has_header_option)) {
37270            
37271            self.rows['$head=']([$send(body.$shift(), 'map', [], function $$6(cell){
37272              
37273              if (cell == null) cell = nil;
37274              return cell.$reinitialize(true);})]);
37275            num_body_rows = $rb_minus(num_body_rows, 1);
37276          } else if ($truthy(self.has_header_option['$nil?']())) {
37277            
37278            self.has_header_option = false;
37279            body.$unshift($send(body.$shift(), 'map', [], function $$7(cell){
37280              
37281              if (cell == null) cell = nil;
37282              return cell.$reinitialize(false);}));
37283          }
37284        };
37285        if (($truthy($rb_gt(num_body_rows, 0)) && ($truthy(attrs['$[]']("footer-option"))))) {
37286          self.rows['$foot=']([body.$pop()])
37287        };
37288        return nil;
37289      });
37290    })($nesting[0], $$('AbstractBlock'), $nesting);
37291    (function($base, $super) {
37292      var self = $klass($base, $super, 'Column');
37293
37294      var $proto = self.$$prototype;
37295
37296      $proto.attributes = nil;
37297      
37298      self.$attr_accessor("style");
37299      
37300      $def(self, '$initialize', function $$initialize(table, index, attributes) {
37301        var $yield = $$initialize.$$p || nil, self = this, $ret_or_1 = nil;
37302
37303        $$initialize.$$p = null;
37304        
37305        if (attributes == null) attributes = $hash2([], {});
37306        $send2(self, $find_super(self, 'initialize', $$initialize, false, true), 'initialize', [table, "table_column"], null);
37307        self.style = attributes['$[]']("style");
37308        attributes['$[]=']("colnumber", $rb_plus(index, 1));
37309        if ($truthy(($ret_or_1 = attributes['$[]']("width")))) {
37310          $ret_or_1
37311        } else {
37312          attributes['$[]=']("width", 1)
37313        };
37314        if ($truthy(($ret_or_1 = attributes['$[]']("halign")))) {
37315          $ret_or_1
37316        } else {
37317          attributes['$[]=']("halign", "left")
37318        };
37319        if ($truthy(($ret_or_1 = attributes['$[]']("valign")))) {
37320          $ret_or_1
37321        } else {
37322          attributes['$[]=']("valign", "top")
37323        };
37324        return self.$update_attributes(attributes);
37325      }, -3);
37326      $alias(self, "table", "parent");
37327      
37328      $def(self, '$assign_width', function $$assign_width(col_pcwidth, width_base, precision) {
37329        var $a, self = this, col_abswidth = nil;
37330
37331        
37332        if ($truthy(width_base)) {
37333          
37334          col_pcwidth = $rb_divide($rb_times(self.attributes['$[]']("width").$to_f(), 100), width_base).$truncate(precision);
37335          if ($eqeq(col_pcwidth.$to_i(), col_pcwidth)) {
37336            col_pcwidth = col_pcwidth.$to_i()
37337          };
37338        };
37339        if ($truthy(self.$parent().$attributes()['$[]']("tableabswidth"))) {
37340          self.attributes['$[]=']("colabswidth", ($eqeq((col_abswidth = $rb_times($rb_divide(col_pcwidth, 100), self.$parent().$attributes()['$[]']("tableabswidth")).$truncate(precision)), col_abswidth.$to_i()) ? (col_abswidth.$to_i()) : (col_abswidth)))
37341        };
37342        return ($a = ["colpcwidth", col_pcwidth], $send(self.attributes, '[]=', $a), $a[$a.length - 1]);
37343      });
37344      
37345      $def(self, '$block?', $return_val(false));
37346      return $def(self, '$inline?', $return_val(false));
37347    })($$('Table'), $$('AbstractNode'));
37348    (function($base, $super, $parent_nesting) {
37349      var self = $klass($base, $super, 'Cell');
37350
37351      var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype;
37352
37353      $proto.document = $proto.reinitialize_args = $proto.attributes = $proto.cursor = $proto.text = $proto.subs = $proto.style = $proto.inner_document = $proto.source_location = $proto.colspan = $proto.rowspan = nil;
37354      
37355      $const_set($nesting[0], 'DOUBLE_LF', $rb_times($$('LF'), 2));
37356      self.$attr_accessor("colspan");
37357      self.$attr_accessor("rowspan");
37358      $alias(self, "column", "parent");
37359      self.$attr_reader("inner_document");
37360      
37361      $def(self, '$initialize', function $$initialize(column, cell_text, attributes, opts) {
37362        var $a, $yield = $$initialize.$$p || nil, self = this, in_header_row = nil, cell_style = nil, $ret_or_1 = nil, $ret_or_2 = nil, asciidoc = nil, inner_document_cursor = nil, lines_advanced = nil, literal = nil, normal_psv = nil, parent_doctitle = nil, inner_document_lines = nil, unprocessed_line1 = nil, preprocessed_lines = nil;
37363
37364        $$initialize.$$p = null;
37365        
37366        if (attributes == null) attributes = $hash2([], {});
37367        if (opts == null) opts = $hash2([], {});
37368        $send2(self, $find_super(self, 'initialize', $$initialize, false, true), 'initialize', [column, "table_cell"], null);
37369        self.cursor = (self.reinitialize_args = nil);
37370        if ($truthy(self.document.$sourcemap())) {
37371          self.source_location = opts['$[]']("cursor").$dup()
37372        };
37373        if ($truthy(column)) {
37374          
37375          if ($truthy((in_header_row = column.$table()['$header_row?']()))) {
37376            if (($eqeq(in_header_row, "implicit") && ($truthy((cell_style = ($truthy(($ret_or_1 = column.$style())) ? ($ret_or_1) : (($truthy(($ret_or_2 = attributes)) ? (attributes['$[]']("style")) : ($ret_or_2))))))))) {
37377              
37378              if (($eqeq(cell_style, "asciidoc") || ($eqeq(cell_style, "literal")))) {
37379                self.reinitialize_args = [column, cell_text, ($truthy(($ret_or_1 = attributes)) ? (attributes.$merge()) : ($ret_or_1)), opts]
37380              };
37381              cell_style = nil;
37382            }
37383          } else {
37384            cell_style = column.$style()
37385          };
37386          self.$update_attributes(column.$attributes());
37387        };
37388        if ($truthy(attributes)) {
37389          
37390          if ($truthy(attributes['$empty?']())) {
37391            self.colspan = (self.rowspan = nil)
37392          } else {
37393            
37394            $a = [attributes.$delete("colspan"), attributes.$delete("rowspan")], (self.colspan = $a[0]), (self.rowspan = $a[1]), $a;
37395            if (!$truthy(in_header_row)) {
37396              cell_style = ($truthy(($ret_or_1 = attributes['$[]']("style"))) ? ($ret_or_1) : (cell_style))
37397            };
37398            self.$update_attributes(attributes);
37399          };
37400          
37401          switch (cell_style) {
37402            case "asciidoc":
37403              
37404              asciidoc = true;
37405              inner_document_cursor = opts['$[]']("cursor");
37406              if ($truthy((cell_text = cell_text.$rstrip())['$start_with?']($$('LF')))) {
37407                
37408                lines_advanced = 1;
37409                while ($truthy((cell_text = cell_text.$slice(1, cell_text.$length()))['$start_with?']($$('LF')))) {
37410                lines_advanced = $rb_plus(lines_advanced, 1)
37411                };
37412                inner_document_cursor.$advance(lines_advanced);
37413              } else {
37414                cell_text = cell_text.$lstrip()
37415              };
37416              break;
37417            case "literal":
37418              
37419              literal = true;
37420              cell_text = cell_text.$rstrip();
37421              while ($truthy(cell_text['$start_with?']($$('LF')))) {
37422              cell_text = cell_text.$slice(1, cell_text.$length())
37423              };
37424              break;
37425            default:
37426              
37427              normal_psv = true;
37428              cell_text = ($truthy(cell_text) ? (cell_text.$strip()) : (""));
37429          };
37430        } else {
37431          
37432          self.colspan = (self.rowspan = nil);
37433          if ($eqeq(cell_style, "asciidoc")) {
37434            
37435            asciidoc = true;
37436            inner_document_cursor = opts['$[]']("cursor");
37437          };
37438        };
37439        if ($truthy(asciidoc)) {
37440          
37441          parent_doctitle = self.document.$attributes().$delete("doctitle");
37442          inner_document_lines = cell_text.$split($$('LF'), -1);
37443          if (!$truthy(inner_document_lines['$empty?']())) {
37444            if ($truthy((unprocessed_line1 = inner_document_lines['$[]'](0))['$include?']("::"))) {
37445              
37446              preprocessed_lines = $$('PreprocessorReader').$new(self.document, [unprocessed_line1]).$readlines();
37447              if (!($eqeq(unprocessed_line1, preprocessed_lines['$[]'](0)) && ($truthy($rb_lt(preprocessed_lines.$size(), 2))))) {
37448                
37449                inner_document_lines.$shift();
37450                if (!$truthy(preprocessed_lines['$empty?']())) {
37451                  $send(inner_document_lines, 'unshift', $to_a(preprocessed_lines))
37452                };
37453              };
37454            }
37455          };
37456          self.inner_document = $$('Document').$new(inner_document_lines, $hash2(["standalone", "parent", "cursor"], {"standalone": false, "parent": self.document, "cursor": inner_document_cursor}));
37457          if (!$truthy(parent_doctitle['$nil?']())) {
37458            self.document.$attributes()['$[]=']("doctitle", parent_doctitle)
37459          };
37460          self.subs = nil;
37461        } else if ($truthy(literal)) {
37462          
37463          self.content_model = "verbatim";
37464          self.subs = $$('BASIC_SUBS');
37465        } else {
37466          
37467          if ($truthy(normal_psv)) {
37468            if ($truthy(in_header_row)) {
37469              self.cursor = opts['$[]']("cursor")
37470            } else {
37471              self.$catalog_inline_anchor(cell_text, opts['$[]']("cursor"))
37472            }
37473          };
37474          self.content_model = "simple";
37475          self.subs = $$('NORMAL_SUBS');
37476        };
37477        self.text = cell_text;
37478        return (self.style = cell_style);
37479      }, -3);
37480      
37481      $def(self, '$reinitialize', function $$reinitialize(has_header) {
37482        var self = this;
37483
37484        
37485        if ($truthy(has_header)) {
37486          self.reinitialize_args = nil
37487        } else if ($truthy(self.reinitialize_args)) {
37488          return $send($$$($$('Table'), 'Cell'), 'new', $to_a(self.reinitialize_args))
37489        } else {
37490          self.style = self.attributes['$[]']("style")
37491        };
37492        if ($truthy(self.cursor)) {
37493          self.$catalog_inline_anchor()
37494        };
37495        return self;
37496      });
37497      
37498      $def(self, '$catalog_inline_anchor', function $$catalog_inline_anchor(cell_text, cursor) {
37499        var $a, self = this;
37500
37501        
37502        if (cell_text == null) cell_text = self.text;
37503        if (cursor == null) cursor = nil;
37504        if (!$truthy(cursor)) {
37505          $a = [self.cursor, nil], (cursor = $a[0]), (self.cursor = $a[1]), $a
37506        };
37507        if (($truthy(cell_text['$start_with?']("[[")) && ($truthy($$('LeadingInlineAnchorRx')['$=~'](cell_text))))) {
37508          return $$('Parser').$catalog_inline_anchor((($a = $gvars['~']) === nil ? nil : $a['$[]'](1)), (($a = $gvars['~']) === nil ? nil : $a['$[]'](2)), self, cursor, self.document)
37509        } else {
37510          return nil
37511        };
37512      }, -1);
37513      
37514      $def(self, '$text', function $$text() {
37515        var self = this;
37516
37517        return self.$apply_subs(self.text, self.subs)
37518      });
37519      self.$attr_writer("text");
37520      
37521      $def(self, '$content', function $$content() {
37522        var self = this, cell_style = nil, subbed_text = nil;
37523
37524        if ($eqeq((cell_style = self.style), "asciidoc")) {
37525          return self.inner_document.$convert()
37526        } else if ($truthy(self.text['$include?']($$('DOUBLE_LF')))) {
37527          return $send(self.$text().$split($$('BlankLineRx')), 'map', [], function $$8(para){var self = $$8.$$s == null ? this : $$8.$$s;
37528
37529            
37530            if (para == null) para = nil;
37531            if (($truthy(cell_style) && ($neqeq(cell_style, "header")))) {
37532              return $$('Inline').$new(self.$parent(), "quoted", para, $hash2(["type"], {"type": cell_style})).$convert()
37533            } else {
37534              return para
37535            };}, {$$s: self})
37536        } else if ($truthy((subbed_text = self.$text())['$empty?']())) {
37537          return []
37538        } else if (($truthy(cell_style) && ($neqeq(cell_style, "header")))) {
37539          return [$$('Inline').$new(self.$parent(), "quoted", subbed_text, $hash2(["type"], {"type": cell_style})).$convert()]
37540        } else {
37541          return [subbed_text]
37542        }
37543      });
37544      
37545      $def(self, '$lines', function $$lines() {
37546        var self = this;
37547
37548        return self.text.$split($$('LF'))
37549      });
37550      
37551      $def(self, '$source', $return_ivar("text"));
37552      
37553      $def(self, '$file', function $$file() {
37554        var self = this, $ret_or_1 = nil;
37555
37556        if ($truthy(($ret_or_1 = self.source_location))) {
37557          return self.source_location.$file()
37558        } else {
37559          return $ret_or_1
37560        }
37561      });
37562      
37563      $def(self, '$lineno', function $$lineno() {
37564        var self = this, $ret_or_1 = nil;
37565
37566        if ($truthy(($ret_or_1 = self.source_location))) {
37567          return self.source_location.$lineno()
37568        } else {
37569          return $ret_or_1
37570        }
37571      });
37572      return $def(self, '$to_s', function $$to_s() {
37573        var $yield = $$to_s.$$p || nil, self = this, $ret_or_1 = nil;
37574
37575        $$to_s.$$p = null;
37576        return "" + ($send2(self, $find_super(self, 'to_s', $$to_s, false, true), 'to_s', [], $yield)) + " - [text: " + (self.text) + ", colspan: " + (($truthy(($ret_or_1 = self.colspan)) ? ($ret_or_1) : (1))) + ", rowspan: " + (($truthy(($ret_or_1 = self.rowspan)) ? ($ret_or_1) : (1))) + ", attributes: " + (self.attributes) + "]"
37577      });
37578    })($$('Table'), $$('AbstractBlock'), $nesting);
37579    return (function($base, $super, $parent_nesting) {
37580      var self = $klass($base, $super, 'ParserContext');
37581
37582      var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype;
37583
37584      $proto.delimiter = $proto.delimiter_rx = $proto.buffer = $proto.cellspecs = $proto.cell_open = $proto.format = $proto.start_cursor_data = $proto.reader = $proto.table = $proto.current_row = $proto.colcount = $proto.column_visits = $proto.active_rowspans = $proto.linenum = nil;
37585      
37586      self.$include($$('Logging'));
37587      $const_set($nesting[0], 'FORMATS', ["psv", "csv", "dsv", "tsv"].$to_set());
37588      $const_set($nesting[0], 'DELIMITERS', $hash2(["psv", "csv", "dsv", "tsv", "!sv"], {"psv": ["|", /\|/], "csv": [",", /,/], "dsv": [":", /:/], "tsv": ["\t", /\t/], "!sv": ["!", /!/]}));
37589      self.$attr_accessor("table");
37590      self.$attr_accessor("format");
37591      self.$attr_reader("colcount");
37592      self.$attr_accessor("buffer");
37593      self.$attr_reader("delimiter");
37594      self.$attr_reader("delimiter_re");
37595      
37596      $def(self, '$initialize', function $$initialize(reader, table, attributes) {
37597        var $a, $b, self = this, xsv = nil, sep = nil;
37598
37599        
37600        if (attributes == null) attributes = $hash2([], {});
37601        self.start_cursor_data = (self.reader = reader).$mark();
37602        self.table = table;
37603        if ($truthy(attributes['$key?']("format"))) {
37604          if ($truthy($$('FORMATS')['$include?']((xsv = attributes['$[]']("format"))))) {
37605            if ($eqeq(xsv, "tsv")) {
37606              self.format = "csv"
37607            } else if (($eqeq((self.format = xsv), "psv") && ($truthy(table.$document()['$nested?']())))) {
37608              xsv = "!sv"
37609            }
37610          } else {
37611            
37612            self.$logger().$error(self.$message_with_context("illegal table format: " + (xsv), $hash2(["source_location"], {"source_location": reader.$cursor_at_prev_line()})));
37613            $a = ["psv", ($truthy(table.$document()['$nested?']()) ? ("!sv") 
37613: ("psv"))], (self.format = $a[0]), (xsv = $a[1]), $a;
37614          }
37615        } else {
37616          $a = ["psv", ($truthy(table.$document()['$nested?']()) ? ("!sv") : ("psv"))], (self.format = $a[0]), (xsv = $a[1]), $a
37617        };
37618        if ($truthy(attributes['$key?']("separator"))) {
37619          if ($truthy((sep = attributes['$[]']("separator"))['$nil_or_empty?']())) {
37620            $b = $$('DELIMITERS')['$[]'](xsv), $a = $to_ary($b), (self.delimiter = ($a[0] == null ? nil : $a[0])), (self.delimiter_rx = ($a[1] == null ? nil : $a[1])), $b
37621          } else if ($eqeq(sep, "\\t")) {
37622            $b = $$('DELIMITERS')['$[]']("tsv"), $a = $to_ary($b), (self.delimiter = ($a[0] == null ? nil : $a[0])), (self.delimiter_rx = ($a[1] == null ? nil : $a[1])), $b
37623          } else {
37624            $a = [sep, $regexp([$$$('Regexp').$escape(sep)])], (self.delimiter = $a[0]), (self.delimiter_rx = $a[1]), $a
37625          }
37626        } else {
37627          $b = $$('DELIMITERS')['$[]'](xsv), $a = $to_ary($b), (self.delimiter = ($a[0] == null ? nil : $a[0])), (self.delimiter_rx = ($a[1] == null ? nil : $a[1])), $b
37628        };
37629        self.colcount = ($truthy(table.$columns()['$empty?']()) ? (-1) : (table.$columns().$size()));
37630        self.buffer = "";
37631        self.cellspecs = [];
37632        self.cell_open = false;
37633        self.active_rowspans = [0];
37634        self.column_visits = 0;
37635        self.current_row = [];
37636        return (self.linenum = -1);
37637      }, -3);
37638      
37639      $def(self, '$starts_with_delimiter?', function $ParserContext_starts_with_delimiter$ques$9(line) {
37640        var self = this;
37641
37642        return line['$start_with?'](self.delimiter)
37643      });
37644      
37645      $def(self, '$match_delimiter', function $$match_delimiter(line) {
37646        var self = this;
37647
37648        return self.delimiter_rx.$match(line)
37649      });
37650      
37651      $def(self, '$skip_past_delimiter', function $$skip_past_delimiter(pre) {
37652        var self = this;
37653
37654        
37655        self.buffer = "" + (self.buffer) + (pre) + (self.delimiter);
37656        return nil;
37657      });
37658      
37659      $def(self, '$skip_past_escaped_delimiter', function $$skip_past_escaped_delimiter(pre) {
37660        var self = this;
37661
37662        
37663        self.buffer = "" + (self.buffer) + (pre.$chop()) + (self.delimiter);
37664        return nil;
37665      });
37666      
37667      $def(self, '$buffer_has_unclosed_quotes?', function $ParserContext_buffer_has_unclosed_quotes$ques$10(append, q) {
37668        var self = this, record = nil, qq = nil, trailing_quote = nil, $ret_or_1 = nil;
37669
37670        
37671        if (append == null) append = nil;
37672        if (q == null) q = "\"";
37673        if ($eqeq((record = ($truthy(append) ? ($rb_plus(self.buffer, append).$strip()) : (self.buffer.$strip()))), q)) {
37674          return true
37675        } else if ($truthy(record['$start_with?'](q))) {
37676          
37677          qq = $rb_plus(q, q);
37678          if ((($truthy((trailing_quote = record['$end_with?'](q))) && ($truthy(record['$end_with?'](qq)))) || ($truthy(record['$start_with?'](qq))))) {
37679            if ($truthy(($ret_or_1 = (record = record.$gsub(qq, ""))['$start_with?'](q)))) {
37680              return record['$end_with?'](q)['$!']()
37681            } else {
37682              return $ret_or_1
37683            }
37684          } else {
37685            return trailing_quote['$!']()
37686          };
37687        } else {
37688          return false
37689        };
37690      }, -1);
37691      
37692      $def(self, '$take_cellspec', function $$take_cellspec() {
37693        var self = this;
37694
37695        return self.cellspecs.$shift()
37696      });
37697      
37698      $def(self, '$push_cellspec', function $$push_cellspec(cellspec) {
37699        var self = this, $ret_or_1 = nil;
37700
37701        
37702        if (cellspec == null) cellspec = $hash2([], {});
37703        self.cellspecs['$<<'](($truthy(($ret_or_1 = cellspec)) ? ($ret_or_1) : ($hash2([], {}))));
37704        return nil;
37705      }, -1);
37706      
37707      $def(self, '$keep_cell_open', function $$keep_cell_open() {
37708        var self = this;
37709
37710        
37711        self.cell_open = true;
37712        return nil;
37713      });
37714      
37715      $def(self, '$mark_cell_closed', function $$mark_cell_closed() {
37716        var self = this;
37717
37718        
37719        self.cell_open = false;
37720        return nil;
37721      });
37722      
37723      $def(self, '$cell_open?', $return_ivar("cell_open"));
37724      
37725      $def(self, '$cell_closed?', function $ParserContext_cell_closed$ques$11() {
37726        var self = this;
37727
37728        return self.cell_open['$!']()
37729      });
37730      
37731      $def(self, '$close_open_cell', function $$close_open_cell(next_cellspec) {
37732        var self = this;
37733
37734        
37735        if (next_cellspec == null) next_cellspec = $hash2([], {});
37736        self.$push_cellspec(next_cellspec);
37737        if ($truthy(self['$cell_open?']())) {
37738          self.$close_cell(true)
37739        };
37740        self.$advance();
37741        return nil;
37742      }, -1);
37743      
37744      $def(self, '$close_cell', function $$close_cell(eol) {try { var $t_return = $thrower('return'); 
37745        var self = this, cell_text = nil, cellspec = nil, repeat = nil, $ret_or_1 = nil, q = nil;
37746
37747        
37748        if (eol == null) eol = false;
37749        if ($eqeq(self.format, "psv")) {
37750          
37751          cell_text = self.buffer;
37752          self.buffer = "";
37753          if ($truthy((cellspec = self.$take_cellspec()))) {
37754            repeat = ($truthy(($ret_or_1 = cellspec.$delete("repeatcol"))) ? ($ret_or_1) : (1))
37755          } else {
37756            
37757            self.$logger().$error(self.$message_with_context("table missing leading separator; recovering automatically", $hash2(["source_location"], {"source_location": $send($$$($$('Reader'), 'Cursor'), 'new', $to_a(self.start_cursor_data))})));
37758            cellspec = $hash2([], {});
37759            repeat = 1;
37760          };
37761        } else {
37762          
37763          cell_text = self.buffer.$strip();
37764          self.buffer = "";
37765          cellspec = nil;
37766          repeat = 1;
37767          if ((($eqeq(self.format, "csv") && ($not(cell_text['$empty?']()))) && ($truthy(cell_text['$include?']((q = "\"")))))) {
37768            if (($truthy(cell_text['$start_with?'](q)) && ($truthy(cell_text['$end_with?'](q))))) {
37769              if ($truthy((cell_text = cell_text.$slice(1, $rb_minus(cell_text.$length(), 2))))) {
37770                cell_text = cell_text.$strip().$squeeze(q)
37771              } else {
37772                
37773                self.$logger().$error(self.$message_with_context("unclosed quote in CSV data; setting cell to empty", $hash2(["source_location"], {"source_location": self.reader.$cursor_at_prev_line()})));
37774                cell_text = "";
37775              }
37776            } else {
37777              cell_text = cell_text.$squeeze(q)
37778            }
37779          };
37780        };
37781        $send((1), 'upto', [repeat], function $$12(i){var self = $$12.$$s == null ? this : $$12.$$s, column = nil, extra_cols = nil, offset = nil, cell = nil;
37782          if (self.colcount == null) self.colcount = nil;
37783          if (self.table == null) self.table = nil;
37784          if (self.current_row == null) self.current_row = nil;
37785          if (self.reader == null) self.reader = nil;
37786          if (self.column_visits == null) self.column_visits = nil;
37787          if (self.linenum == null) self.linenum = nil;
37788
37789          
37790          if (i == null) i = nil;
37791          if ($eqeq(self.colcount, -1)) {
37792            
37793            self.table.$columns()['$<<']((column = $$$($$('Table'), 'Column').$new(self.table, $rb_minus($rb_plus(self.table.$columns().$size(), i), 1))));
37794            if ((($truthy(cellspec) && ($truthy(cellspec['$key?']("colspan")))) && ($truthy($rb_gt((extra_cols = $rb_minus(cellspec['$[]']("colspan").$to_i(), 1)), 0))))) {
37795              
37796              offset = self.table.$columns().$size();
37797              $send(extra_cols, 'times', [], function $$13(j){var self = $$13.$$s == null ? this : $$13.$$s;
37798                if (self.table == null) self.table = nil;
37799
37800                
37801                if (j == null) j = nil;
37802                return self.table.$columns()['$<<']($$$($$('Table'), 'Column').$new(self.table, $rb_plus(offset, j)));}, {$$s: self});
37803            };
37804          } else if (!$truthy((column = self.table.$columns()['$[]'](self.current_row.$size())))) {
37805            
37806            self.$logger().$error(self.$message_with_context("dropping cell because it exceeds specified number of columns", $hash2(["source_location"], {"source_location": self.reader.$cursor_before_mark()})));
37807            $t_return.$throw();
37808          };
37809          cell = $$$($$('Table'), 'Cell').$new(column, cell_text, cellspec, $hash2(["cursor"], {"cursor": self.reader.$cursor_before_mark()}));
37810          self.reader.$mark();
37811          if (!($not(cell.$rowspan()) || ($eqeq(cell.$rowspan(), 1)))) {
37812            self.$activate_rowspan(cell.$rowspan(), ($truthy(($ret_or_1 = cell.$colspan())) ? ($ret_or_1) : (1)))
37813          };
37814          self.column_visits = $rb_plus(self.column_visits, ($truthy(($ret_or_1 = cell.$colspan())) ? ($ret_or_1) : (1)));
37815          self.current_row['$<<'](cell);
37816          if (($truthy(self['$end_of_row?']()) && ((($neqeq(self.colcount, -1) || ($truthy($rb_gt(self.linenum, 0)))) || (($truthy(eol) && ($eqeq(i, repeat)))))))) {
37817            return self.$close_row()
37818          } else {
37819            return nil
37820          };}, {$$s: self, $$ret: $t_return});
37821        self.cell_open = false;
37822        return nil;} catch($e) {
37823          if ($e === $t_return) return $e.$v;
37824          throw $e;
37825        }
37826      }, -1);
37827      self.$private();
37828      
37829      $def(self, '$close_row', function $$close_row() {
37830        var self = this, $ret_or_1 = nil;
37831
37832        
37833        self.table.$rows().$body()['$<<'](self.current_row);
37834        if ($eqeq(self.colcount, -1)) {
37835          self.colcount = self.column_visits
37836        };
37837        self.column_visits = 0;
37838        self.current_row = [];
37839        self.active_rowspans.$shift();
37840        if ($truthy(($ret_or_1 = self.active_rowspans['$[]'](0)))) {
37841          $ret_or_1
37842        } else {
37843          self.active_rowspans['$[]='](0, 0)
37844        };
37845        return nil;
37846      });
37847      
37848      $def(self, '$activate_rowspan', function $$activate_rowspan(rowspan, colspan) {
37849        var self = this;
37850
37851        
37852        $send((1), 'upto', [$rb_minus(rowspan, 1)], function $$14(i){var $a, self = $$14.$$s == null ? this : $$14.$$s, $ret_or_1 = nil;
37853          if (self.active_rowspans == null) self.active_rowspans = nil;
37854
37855          
37856          if (i == null) i = nil;
37857          return ($a = [i, $rb_plus(($truthy(($ret_or_1 = self.active_rowspans['$[]'](i))) ? ($ret_or_1) : (0)), colspan)], $send(self.active_rowspans, '[]=', $a), $a[$a.length - 1]);}, {$$s: self});
37858        return nil;
37859      });
37860      
37861      $def(self, '$end_of_row?', function $ParserContext_end_of_row$ques$15() {
37862        var self = this, $ret_or_1 = nil;
37863
37864        if ($truthy(($ret_or_1 = self.colcount['$=='](-1)))) {
37865          return $ret_or_1
37866        } else {
37867          return self.$effective_column_visits()['$=='](self.colcount)
37868        }
37869      });
37870      
37871      $def(self, '$effective_column_visits', function $$effective_column_visits() {
37872        var self = this;
37873
37874        return $rb_plus(self.column_visits, self.active_rowspans['$[]'](0))
37875      });
37876      return $def(self, '$advance', function $$advance() {
37877        var self = this;
37878
37879        return (self.linenum = $rb_plus(self.linenum, 1))
37880      });
37881    })($$('Table'), null, $nesting);
37882  })($nesting[0], $nesting)
37883};
37884
37885Opal.modules["asciidoctor/writer"] = function(Opal) {/* Generated by Opal 1.7.3 */
37886  "use strict";
37887  var $module = Opal.module, $truthy = Opal.truthy, $rb_plus = Opal.rb_plus, $hash2 = Opal.hash2, $def = Opal.def, $return_val = Opal.return_val, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$;
37888
37889  Opal.add_stubs('respond_to?,write,+,chomp,include');
37890  return (function($base, $parent_nesting) {
37891    var self = $module($base, 'Asciidoctor');
37892
37893    var $nesting = [self].concat($parent_nesting);
37894
37895    
37896    (function($base, $parent_nesting) {
37897      var self = $module($base, 'Writer');
37898
37899      var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
37900
37901      return $def(self, '$write', function $$write(output, target) {
37902        
37903        
37904        if ($truthy(target['$respond_to?']("write"))) {
37905          target.$write($rb_plus(output.$chomp(), $$('LF')))
37906        } else {
37907          $$$('File').$write(target, output, $hash2(["mode"], {"mode": $$('FILE_WRITE_MODE')}))
37908        };
37909        return nil;
37910      })
37911    })($nesting[0], $nesting);
37912    return (function($base, $parent_nesting) {
37913      var self = $module($base, 'VoidWriter');
37914
37915      var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
37916
37917      
37918      self.$include($$('Writer'));
37919      return $def(self, '$write', $return_val(nil));
37920    })($nesting[0], $nesting);
37921  })($nesting[0], $nesting)
37922};
37923
37924Opal.modules["asciidoctor/load"] = function(Opal) {/* Generated by Opal 1.7.3 */
37925  "use strict";
37926  var $module = Opal.module, $hash2 = Opal.hash2, $truthy = Opal.truthy, $neqeq = Opal.neqeq, $not = Opal.not, $eqeqeq = Opal.eqeqeq, $send = Opal.send, $to_ary = Opal.to_ary, $rb_plus = Opal.rb_plus, $eqeq = Opal.eqeq, $def = Opal.def, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$;
37927
37928  Opal.add_stubs('merge,[],start,!=,logger,key?,logger=,new,!,===,dup,tap,each,partition,[]=,split,gsub,+,respond_to?,keys,raise,join,ancestors,class,==,at,to_i,mtime,absolute_path,path,dirname,basename,extname,read,rewind,drop,record,parse,exception,message,set_backtrace,backtrace,stack_trace=,stack_trace,open,load');
37929  return (function($base, $parent_nesting) {
37930    var self = $module($base, 'Asciidoctor');
37931
37932    var $nesting = [self].concat($parent_nesting);
37933
37934    return (function(self, $parent_nesting) {
37935      var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
37936
37937      
37938      
37939      $def(self, '$load', function $$load(input, options) {
37940        var $a, $b, $c, $d, self = this, timings = nil, logger = nil, $ret_or_1 = nil, attrs = nil, input_path = nil, source = nil, doc = nil, e = nil, context = nil, wrapped_e = nil;
37941
37942        
37943        if (options == null) options = $hash2([], {});
37944        try {
37945          
37946          options = options.$merge();
37947          if ($truthy((timings = options['$[]']("timings")))) {
37948            timings.$start("read")
37949          };
37950          if (($truthy(options['$key?']("logger")) && ($neqeq((logger = options['$[]']("logger")), $$('LoggerManager').$logger())))) {
37951            $$('LoggerManager')['$logger='](($truthy(($ret_or_1 = logger)) ? ($ret_or_1) : ($$('NullLogger').$new())))
37952          };
37953          if ($not((attrs = options['$[]']("attributes")))) {
37954            attrs = $hash2([], {})
37955          } else if ($eqeqeq($$$('Hash'), attrs)) {
37956            attrs = attrs.$merge()
37957          } else if (($truthy((($c = $$$('::', 'Java', 'skip_raise')) && ($b = $$$($c, 'JavaUtil', 'ski
37957p_raise')) && ($a = $$$($b, 'Map', 'skip_raise')) ? 'constant' : nil)) && ($eqeqeq($$$($$$($$$('Java'), 'JavaUtil'), 'Map'), attrs)))) {
37958            attrs = attrs.$dup()
37959          } else if ($eqeqeq($$$('Array'), attrs)) {
37960            attrs = $send($hash2([], {}), 'tap', [], function $$1(accum){
37961              
37962              if (accum == null) accum = nil;
37963              return $send(attrs, 'each', [], function $$2(entry){var $d, $e, k = nil, _ = nil, v = nil;
37964
37965                
37966                if (entry == null) entry = nil;
37967                $e = entry.$partition("="), $d = $to_ary($e), (k = ($d[0] == null ? nil : $d[0])), (_ = ($d[1] == null ? nil : $d[1])), (v = ($d[2] == null ? nil : $d[2])), $e;
37968                return ($d = [k, v], $send(accum, '[]=', $d), $d[$d.length - 1]);});})
37969          } else if ($eqeqeq($$$('String'), attrs)) {
37970            attrs = $send($hash2([], {}), 'tap', [], function $$3(accum){
37971              
37972              if (accum == null) accum = nil;
37973              return $send(attrs.$gsub($$('SpaceDelimiterRx'), $rb_plus("\\1", $$('NULL'))).$gsub($$('EscapedSpaceRx'), "\\1").$split($$('NULL')), 'each', [], function $$4(entry){var $d, $e, k = nil, _ = nil, v = nil;
37974
37975                
37976                if (entry == null) entry = nil;
37977                $e = entry.$partition("="), $d = $to_ary($e), (k = ($d[0] == null ? nil : $d[0])), (_ = ($d[1] == null ? nil : $d[1])), (v = ($d[2] == null ? nil : $d[2])), $e;
37978                return ($d = [k, v], $send(accum, '[]=', $d), $d[$d.length - 1]);});})
37979          } else if (($truthy(attrs['$respond_to?']("keys")) && ($truthy(attrs['$respond_to?']("[]"))))) {
37980            attrs = $send($hash2([], {}), 'tap', [], function $$5(accum){
37981              
37982              if (accum == null) accum = nil;
37983              return $send(attrs.$keys(), 'each', [], function $$6(k){var $d;
37984
37985                
37986                if (k == null) k = nil;
37987                return ($d = [k, attrs['$[]'](k)], $send(accum, '[]=', $d), $d[$d.length - 1]);});})
37988          } else {
37989            self.$raise($$$('ArgumentError'), "illegal type for attributes option: " + (attrs.$class().$ancestors().$join(" < ")))
37990          };
37991          if ($eqeqeq($$$('File'), input)) {
37992            
37993            options['$[]=']("input_mtime", ($eqeq($$('RUBY_ENGINE'), "jruby") ? ($$$('Time').$at(input.$mtime().$to_i())) : (input.$mtime())));
37994            attrs['$[]=']("docfile", (input_path = $$$('File').$absolute_path(input.$path())));
37995            attrs['$[]=']("docdir", $$$('File').$dirname(input_path));
37996            attrs['$[]=']("docname", $$('Helpers').$basename(input_path, ($d = ["docfilesuffix", $$('Helpers').$extname(input_path)], $send(attrs, '[]=', $d), $d[$d.length - 1])));
37997            source = input.$read();
37998          } else if ($truthy(input['$respond_to?']("read"))) {
37999            
38000            try {
38001              input.$rewind()
38002            } catch ($err) {
38003              if (Opal.rescue($err, [$$('StandardError')])) {
38004                try {
38005                  nil
38006                } finally { Opal.pop_exception(); }
38007              } else { throw $err; }
38008            };
38009            source = input.$read();
38010          } else if ($eqeqeq($$$('String'), input)) {
38011            source = input
38012          } else if ($eqeqeq($$$('Array'), input)) {
38013            source = input.$drop(0)
38014          } else if ($truthy(input)) {
38015            self.$raise($$$('ArgumentError'), "unsupported input type: " + (input.$class()))
38016          };
38017          if ($truthy(timings)) {
38018            
38019            timings.$record("read");
38020            timings.$start("parse");
38021          };
38022          options['$[]=']("attributes", attrs);
38023          doc = ($eqeq(options['$[]']("parse"), false) ? ($$('Document').$new(source, options)) : ($$('Document').$new(source, options).$parse()));
38024          if ($truthy(timings)) {
38025            timings.$record("parse")
38026          };
38027          return doc;
38028        } catch ($err) {
38029          if (Opal.rescue($err, [$$('StandardError')])) {(e = $err)
38030            try {
38031              
38032              
38033              try {
38034                
38035                context = "asciidoctor: FAILED: " + (($truthy(($ret_or_1 = attrs['$[]']("docfile"))) ? ($ret_or_1) : ("<stdin>"))) + ": Failed to load AsciiDoc document";
38036                if ($truthy(e['$respond_to?']("exception"))) {
38037                  
38038                  wrapped_e = e.$exception("" + (context) + " - " + (e.$message()));
38039                  wrapped_e.$set_backtrace(e.$backtrace());
38040                } else {
38041                  
38042                  wrapped_e = e.$class().$new(context, e);
38043                  wrapped_e['$stack_trace='](e.$stack_trace());
38044                };
38045              } catch ($err) {
38046                if (Opal.rescue($err, [$$('StandardError')])) {
38047                  try {
38048                    wrapped_e = e
38049                  } finally { Opal.pop_exception(); }
38050                } else { throw $err; }
38051              };;
38052              return self.$raise(wrapped_e);
38053            } finally { Opal.pop_exception(); }
38054          } else { throw $err; }
38055        };
38056      }, -2);
38057      return $def(self, '$load_file', function $$load_file(filename, options) {
38058        var self = this;
38059
38060        
38061        if (options == null) options = $hash2([], {});
38062        return $send($$$('File'), 'open', [filename, $$('FILE_READ_MODE')], function $$7(file){var self = $$7.$$s == null ? this : $$7.$$s;
38063
38064          
38065          if (file == null) file = nil;
38066          return self.$load(file, options);}, {$$s: self});
38067      }, -2);
38068    })(Opal.get_singleton_class(self), $nesting)
38069  })($nesting[0], $nesting)
38070};
38071
38072Opal.modules["asciidoctor/convert"] = function(Opal) {/* Generated by Opal 1.7.3 */
38073  "use strict";
38074  var $module = Opal.module, $hash2 = Opal.hash2, $eqeqeq = Opal.eqeqeq, $truthy = Opal.truthy, $eqeq = Opal.eqeq, $rb_ge = Opal.rb_ge, $not = Opal.not, $rb_lt = Opal.rb_lt, $neqeq = Opal.neqeq, $def = Opal.def, $send = Opal.send, $alias = Opal.alias, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$;
38075
38076  Opal.add_stubs('delete,merge,===,absolute_path,path,load,respond_to?,[]=,key?,fetch,[],dirname,expand_path,join,attributes,outfilesuffix,==,raise,pwd,>=,safe,normalize_system_path,mkdir_p,directory?,!,convert,write,attr,ur
38076iish?,basebackend?,attr?,<,include?,syntax_highlighter,write_stylesheet?,write_primary_stylesheet,instance,to_s,read_asset,file?,!=,write_stylesheet,open,convert_file');
38077  return (function($base, $parent_nesting) {
38078    var self = $module($base, 'Asciidoctor');
38079
38080    var $nesting = [self].concat($parent_nesting);
38081
38082    return (function(self, $parent_nesting) {
38083      var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
38084
38085      
38086      
38087      $def(self, '$convert', function $$convert(input, options) {
38088        var self = this, to_dir = nil, mkdirs = nil, $ret_or_1 = nil, to_file = nil, write_to_target = nil, sibling_path = nil, stream_output = nil, outdir = nil, doc = nil, outfile = nil, working_dir = nil, jail = nil, output = nil, stylesdir = nil, stylesheet = nil, copy_asciidoctor_stylesheet = nil, copy_user_stylesheet = nil, copy_syntax_hl_stylesheet = nil, syntax_hl = nil, stylesoutdir = nil, stylesheet_src = nil, stylesheet_dest = nil, stylesheet_data = nil, stylesheet_outdir = nil;
38089
38090        
38091        if (options == null) options = $hash2([], {});
38092        (options = options.$merge()).$delete("parse");
38093        to_dir = options.$delete("to_dir");
38094        mkdirs = options.$delete("mkdirs");
38095        if (($eqeqeq(true, ($ret_or_1 = (to_file = options.$delete("to_file")))) || ($eqeqeq(nil, $ret_or_1)))) {
38096          
38097          if (!$truthy((write_to_target = to_dir))) {
38098            if ($eqeqeq($$$('File'), input)) {
38099              sibling_path = $$$('File').$absolute_path(input.$path())
38100            }
38101          };
38102          to_file = nil;
38103        } else if ($eqeqeq(false, $ret_or_1)) {
38104          to_file = nil
38105        } else if ($eqeqeq("/dev/null", $ret_or_1)) {
38106          return self.$load(input, options)
38107        } else if (!$truthy((stream_output = to_file['$respond_to?']("write")))) {
38108          options['$[]=']("to_file", (write_to_target = to_file))
38109        };
38110        if (!$truthy(options['$key?']("standalone"))) {
38111          if (($truthy(sibling_path) || ($truthy(write_to_target)))) {
38112            options['$[]=']("standalone", options.$fetch("header_footer", true))
38113          } else if ($truthy(options['$key?']("header_footer"))) {
38114            options['$[]=']("standalone", options['$[]']("header_footer"))
38115          }
38116        };
38117        if ($truthy(sibling_path)) {
38118          options['$[]=']("to_dir", (outdir = $$$('File').$dirname(sibling_path)))
38119        } else if ($truthy(write_to_target)) {
38120          if ($truthy(to_dir)) {
38121            if ($truthy(to_file)) {
38122              options['$[]=']("to_dir", $$$('File').$dirname($$$('File').$expand_path(to_file, to_dir)))
38123            } else {
38124              options['$[]=']("to_dir", $$$('File').$expand_path(to_dir))
38125            }
38126          } else if ($truthy(to_file)) {
38127            options['$[]=']("to_dir", $$$('File').$dirname($$$('File').$expand_path(to_file)))
38128          }
38129        };
38130        doc = self.$load(input, options);
38131        if ($truthy(sibling_path)) {
38132          
38133          outfile = $$$('File').$join(outdir, "" + (doc.$attributes()['$[]']("docname")) + (doc.$outfilesuffix()));
38134          if ($eqeq(outfile, sibling_path)) {
38135            self.$raise($$$('IOError'), "input file and output file cannot be the same: " + (outfile))
38136          };
38137        } else if ($truthy(write_to_target)) {
38138          
38139          working_dir = ($truthy(options['$key?']("base_dir")) ? ($$$('File').$expand_path(options['$[]']("base_dir"))) : ($$$('Dir').$pwd())
38139);
38140          jail = ($truthy($rb_ge(doc.$safe(), $$$($$('SafeMode'), 'SAFE'))) ? (working_dir) : (nil));
38141          if ($truthy(to_dir)) {
38142            
38143            outdir = doc.$normalize_system_path(to_dir, working_dir, jail, $hash2(["target_name", "recover"], {"target_name": "to_dir", "recover": false}));
38144            if ($truthy(to_file)) {
38145              
38146              outfile = doc.$normalize_system_path(to_file, outdir, nil, $hash2(["target_name", "recover"], {"target_name": "to_dir", "recover": false}));
38147              outdir = $$$('File').$dirname(outfile);
38148            } else {
38149              outfile = $$$('File').$join(outdir, "" + (doc.$attributes()['$[]']("docname")) + (doc.$outfilesuffix()))
38150            };
38151          } else if ($truthy(to_file)) {
38152            
38153            outfile = doc.$normalize_system_path(to_file, working_dir, jail, $hash2(["target_name", "recover"], {"target_name": "to_dir", "recover": false}));
38154            outdir = $$$('File').$dirname(outfile);
38155          };
38156          if (($eqeqeq($$$('File'), input) && ($eqeq(outfile, $$$('File').$absolute_path(input.$path()))))) {
38157            self.$raise($$$('IOError'), "input file and output file cannot be the same: " + (outfile))
38158          };
38159          if ($truthy(mkdirs)) {
38160            $$('Helpers').$mkdir_p(outdir)
38161          } else if (!$truthy($$$('File')['$directory?'](outdir))) {
38162            self.$raise($$$('IOError'), "target directory does not exist: " + (to_dir) + " (hint: set :mkdirs option)")
38163          };
38164        } else {
38165          
38166          outfile = to_file;
38167          outdir = nil;
38168        };
38169        if (($truthy(outfile) && ($not(stream_output)))) {
38170          output = doc.$convert($hash2(["outfile", "outdir"], {"outfile": outfile, "outdir": outdir}))
38171        } else {
38172          output = doc.$convert()
38173        };
38174        if ($truthy(outfile)) {
38175          
38176          doc.$write(output, outfile);
38177          if (((((($not(stream_output) && ($truthy($rb_lt(doc.$safe(), $$$($$('SafeMode'), 'SECURE'))))) && ($truthy(doc['$attr?']("linkcss")))) && ($truthy(doc['$attr?']("copycss")))) && ($truthy(doc['$basebackend?']("html")))) && ($not(($truthy(($ret_or_1 = (stylesdir = doc.$attr("stylesdir")))) ? ($$('Helpers')['$uriish?'](stylesdir)) : ($ret_or_1)))))) {
38178            
38179            if ($truthy((stylesheet = doc.$attr("stylesheet")))) {
38180              if ($truthy($$('DEFAULT_STYLESHEET_KEYS')['$include?'](stylesheet))) {
38181                copy_asciidoctor_stylesheet = true
38182              } else if ($not($$('Helpers')['$uriish?'](stylesheet))) {
38183                copy_user_stylesheet = true
38184              }
38185            };
38186            copy_syntax_hl_stylesheet = ($truthy(($ret_or_1 = (syntax_hl = doc.$syntax_highlighter()))) ? (syntax_hl['$write_stylesheet?'](doc)) : ($ret_or_1));
38187            if ((($truthy(copy_asciidoctor_stylesheet) || ($truthy(copy_user_stylesheet))) || ($truthy(copy_syntax_hl_stylesheet)))) {
38188              
38189              stylesoutdir = doc.$normalize_system_path(stylesdir, outdir, ($truthy($rb_ge(doc.$safe(), $$$($$('SafeMode'), 'SAFE'))) ? (outdir) : (nil)));
38190              if ($truthy(mkdirs)) {
38191                $$('Helpers').$mkdir_p(stylesoutdir)
38192              } else if (!$truthy($$$('File')['$directory?'](stylesoutdir))) {
38193                self.$raise($$$('IOError'), "target stylesheet directory does not exist: " + (stylesoutdir) + " (hint: set :mkdirs option)")
38194              };
38195              if ($truthy(copy_asciidoctor_stylesheet)) {
38196                $$('Stylesheets').$instance().$write_primary_stylesheet(stylesoutdir)
38197              } else if ($truthy(copy_user_stylesheet)) {
38198                
38199                if (($eqeq((stylesheet_src = doc.$attr("copycss")), "") || ($eqeq(stylesheet_src, true)))) {
38200                  stylesheet_src = doc.$normalize_system_path(stylesheet)
38201                } else {
38202                  stylesheet_src = doc.$normalize_system_path(stylesheet_src.$to_s())
38203                };
38204                stylesheet_dest = doc.$normalize_system_path(stylesheet, stylesoutdir, ($truthy($rb_ge(doc.$safe(), $$$($$('SafeMode'), 'SAFE'))) ? (outdir) : (nil)));
38205                if (($neqeq(stylesheet_src, stylesheet_dest) && ($truthy((stylesheet_data = doc.$read_asset(stylesheet_src, $hash2(["warn_on_failure", "label"], {"warn_on_failure": $$$('File')['$file?'](stylesheet_dest)['$!'](), "label": "stylesheet"}))))))) {
38206                  
38207                  if (($neqeq((stylesheet_outdir = $$$('File').$dirname(stylesheet_dest)), stylesoutdir) && ($not($$$('File')['$directory?'](stylesheet_outdir))))) {
38208                    if ($truthy(mkdirs)) {
38209                      $$('Helpers').$mkdir_p(stylesheet_outdir)
38210                    } else {
38211                      self.$raise($$$('IOError'), "target stylesheet directory does not exist: " + (stylesheet_outdir) + " (hint: set :mkdirs option)")
38212                    }
38213                  };
38214                  $$$('File').$write(stylesheet_dest, stylesheet_data, $hash2(["mode"], {"mode": $$('FILE_WRITE_MODE')}));
38215                };
38216              };
38217              if ($truthy(copy_syntax_hl_stylesheet)) {
38218                syntax_hl.$write_stylesheet(doc, stylesoutdir)
38219              };
38220            };
38221          };
38222          return doc;
38223        } else {
38224          return output
38225        };
38226      }, -2);
38227      
38228      $def(self, '$convert_file', function $$convert_file(filename, options) {
38229        var self = this;
38230
38231        
38232        if (options == null) options = $hash2([], {});
38233        return $send($$$('File'), 'open', [filename, $$('FILE_READ_MODE')], function $$1(file){var self = $$1.$$s == null ? this : $$1.$$s;
38234
38235          
38236          if (file == null) file = nil;
38237          return self.$convert(file, options);}, {$$s: self});
38238      }, -2);
38239      $alias(self, "render", "convert");
38240      return $alias(self, "render_file", "convert_file");
38241    })(Opal.get_singleton_class(self), $nesting)
38242  })($nesting[0], $nesting)
38243};
38244
38245Opal.modules["asciidoctor/syntax_highlighter/highlightjs"] = function(Opal) {/* Generated by Opal 1.7.3 */
38246  "use strict";
38247  var $module = Opal.module, $klass = Opal.klass, $slice = Opal.slice, $send2 = Opal.send2, $find_super = Opal.find_super, $to_a = Opal.to_a, $def = Opal.def, $hash2 = Opal.hash2, $send = Opal.send, $truthy = Opal.truthy, $return_val = Opal.return_val, $eqeq = Opal.eqeq, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$;
38248
38249  Opal.add_stubs('register_for,merge,proc,[]=,attr,[],==,attr?,join,map,split,lstrip');
38250  return (function($base, $parent_nesting) {
38251    var self = $module($base, 'Asciidoctor');
38252
38253    var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
38254
38255    return (function($base, $super, $parent_nesting) {
38256      var self = $klass($base, $super, 'HighlightJsAdapter');
38257
38258      var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
38259
38260      
38261      self.$register_for("highlightjs", "highlight.js");
38262      
38263      $def(self, '$initialize', function $$initialize($a) {
38264        var $post_args, args, $yield = $$initialize.$$p || nil, self = this;
38265
38266        $$initialize.$$p = null;
38267        
38268        $post_args = $slice(arguments);
38269        args = $post_args;
38270        $send2(self, $find_super(self, 'initialize', $$initialize, false, true), 'initialize', $to_a(args), $yield);
38271        return (self.name = (self.pre_class = "highlightjs"));
38272      }, -1);
38273      
38274      $def(self, '$format', function $$format(node, lang, opts) {
38275        var $yield = $$format.$$p || nil, self = this;
38276
38277        $$format.$$p = null;
38278        return $send2(self, $find_super(self, 'format', $$format, false, true), 'format', [node, lang, opts.$merge($hash2(["transform"], {"transform": $send(self, 'proc', [], function $$1(_, code){var $a, $ret_or_1 = nil;
38279
38280          
38281          if (_ == null) _ = nil;
38282          if (code == null) code = nil;
38283          return ($a = ["class", "language-" + (($truthy(($ret_or_1 = lang)) ? ($ret_or_1) : ("none"))) + " hljs"], $send(code, '[]=', $a), $a[$a.length - 1]);})}))], null)
38284      });
38285      
38286      $def(self, '$docinfo?', $return_val(true));
38287      return $def(self, '$docinfo', function $$docinfo(location, doc, opts) {
38288        var base_url = nil;
38289
38290        
38291        base_url = doc.$attr("highlightjsdir", "" + (opts['$[]']("cdn_base_url")) + "/highlight.js/" + ($$('HIGHLIGHT_JS_VERSION')));
38292        if ($eqeq(location, "head")) {
38293          return "<link rel=\"stylesheet\" href=\"" + (base_url) + "/styles/" + (doc.$attr("highlightjs-theme", "github")) + ".min.css\"" + (opts['$[]']("self_closing_tag_slash")) + ">"
38294        } else {
38295          return "<script src=\"" + (base_url) + "/highlight.min.js\"></script>\n" + (($truthy(doc['$attr?']("highlightjs-languages")) ? ($send(doc.$attr("highlightjs-languages").$split(","), 'map', [], function $$2(lang){
38296            
38297            if (lang == null) lang = nil;
38298            return "<script src=\"" + (base_url) + "/languages/" + (lang.$lstrip()) + ".min.js\"></script>\n";}).$join()) : (""))) + "<script>\n" + "if (!hljs.initHighlighting.called) {\n" + "  hljs.initHighlighting.called = true\n" + "  ;[].slice.call(document.querySelectorAll('pre.highlight >
38298 code[data-lang]')).forEach(function (el) { hljs.highlightBlock(el) })\n" + "}\n" + "</script>"
38299        };
38300      });
38301    })($$('SyntaxHighlighter'), $$$($$('SyntaxHighlighter'), 'Base'), $nesting)
38302  })($nesting[0], $nesting)
38303};
38304
38305Opal.modules["asciidoctor/syntax_highlighter"] = function(Opal) {/* Generated by Opal 1.7.3 */
38306  "use strict";
38307  var $module = Opal.module, $hash2 = Opal.hash2, $def = Opal.def, $return_val = Opal.return_val, $defs = Opal.defs, $slice = Opal.slice, $send = Opal.send, $to_a = Opal.to_a, $truthy = Opal.truthy, $eqeqeq = Opal.eqeqeq, $Class = Opal.Class, $klass = Opal.klass, $class_variable_set = Opal.class_variable_set, $class_variable_get = Opal.class_variable_get, self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$;
38308
38309  Opal.add_stubs('attr_reader,raise,class,extend,private_class_method,register,map,to_s,each,[]=,registry,[],for,===,new,name,private,include,delete,join,content');
38310  
38311  (function($base, $parent_nesting) {
38312    var self = $module($base, 'Asciidoctor');
38313
38314    var $nesting = [self].concat($parent_nesting);
38315
38316    return (function($base, $parent_nesting) {
38317      var self = $module($base, 'SyntaxHighlighter');
38318
38319      var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
38320
38321      
38322      self.$attr_reader("name");
38323      
38324      $def(self, '$initialize', function $$initialize(name, backend, opts) {
38325        var self = this;
38326
38327        
38328        if (backend == null) backend = "html5";
38329        if (opts == null) opts = $hash2([], {});
38330        return (self.name = (self.pre_class = name));
38331      }, -2);
38332      
38333      $def(self, '$docinfo?', $return_val(nil));
38334      
38335      $def(self, '$docinfo', function $$docinfo(location, doc, opts) {
38336        var self = this;
38337
38338        return self.$raise($$$('NotImplementedError'), "" + ($$('SyntaxHighlighter')) + " subclass " + (self.$class()) + " must implement the #" + ("docinfo") + " method since #docinfo? returns true")
38339      });
38340      
38341      $def(self, '$highlight?', $return_val(nil));
38342      
38343      $def(self, '$highlight', function $$highlight(node, source, lang, opts) {
38344        var self = this;
38345
38346        return self.$raise($$$('NotImplementedError'), "" + ($$('SyntaxHighlighter')) + " subclass " + (self.$class()) + " must implement the #" + ("highlight") + " method since #highlight? returns true")
38347      });
38348      
38349      $def(self, '$format', function $$format(node, lang, opts) {
38350        var self = this;
38351
38352        return self.$raise($$$('NotImplementedError'), "" + ($$('SyntaxHighlighter')) + " subclass " + (self.$class()) + " must implement the #" + ("format") + " method")
38353      });
38354      
38355      $def(self, '$write_stylesheet?', $return_val(nil));
38356      
38357      $def(self, '$write_stylesheet', function $$write_stylesheet(doc, to_dir) {
38358        var self = this;
38359
38360        return self.$raise($$$('NotImplementedError'), "" + ($$('SyntaxHighlighter')) + " subclass " + (self.$class()) + " must implement the #" + ("write_stylesheet") + " method since #write_stylesheet? returns true")
38361      });
38362      $defs(self, '$included', function $$included(into) {
38363        
38364        return into.$extend($$('Config'))
38365      });
38366      self.$private_class_method("included");
38367      (function($base, $parent_nesting) {
38368        var self = $module($base, 'Config');
38369
38370        var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
38371
38372        return $def(self, '$register_for', function $$register_for($a) {
38373          var $post_args, names, self = this;
38374
38375          
38376          $post_args = $slice(arguments);
38377          names = $post_args;
38378          return $send($$('SyntaxHighlighter'), 'register', [self].concat($to_a($send(names, 'map', [], function $$1(name){
38379            
38380            if (name == null) name = nil;
38381            return name.$to_s();}))));
38382        }, -1)
38383      })($nesting[0], $nesting);
38384      (function($base, $parent_nesting) {
38385        var self = $module($base, 'Factory');
38386
38387        var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
38388
38389        
38390        
38391        $def(self, '$register', function $$register(syntax_highlighter, $a) {
38392          var $post_args, names, self = this;
38393
38394          
38395          $post_args = $slice(arguments, 1);
38396          names = $post_args;
38397          return $send(names, 'each', [], function $$2(name){var $b, self = $$2.$$s == null ? this : $$2.$$s;
38398
38399            
38400            if (name == null) name = nil;
38401            return ($b = [name, syntax_highlighter], $send(self.$registry(), '[]=', $b), $b[$b.length - 1]);}, {$$s: self});
38402        }, -2);
38403        
38404        $def(self, '$for', function $Factory_for$3(name) {
38405          var self = this;
38406
38407          return self.$registry()['$[]'](name)
38408        });
38409        
38410        $def(self, '$create', function $$create(name, backend, opts) {
38411          var self = this, syntax_hl = nil;
38412
38413          
38414          if (backend == null) backend = "html5";
38415          if (opts == null) opts = $hash2([], {});
38416          if ($truthy((syntax_hl = self.$for(name)))) {
38417            
38418            if ($eqeqeq($Class, syntax_hl)) {
38419              syntax_hl = syntax_hl.$new(name, backend, opts)
38420            };
38421            if (!$truthy(syntax_hl.$name())) {
38422              self.$raise($$$('NameError'), "" + (syntax_hl.$class()) + " must specify a value for `name'")
38423            };
38424            return syntax_hl;
38425          } else {
38426            return nil
38427          };
38428        }, -2);
38429        self.$private();
38430        return $def(self, '$registry', function $$registry() {
38431          var self = this;
38432
38433          return self.$raise($$$('NotImplementedError'), "" + ($$('Factory')) + " subclass " + (self.$class()) + " must implement the #" + ("registry") + " method")
38434        });
38435      })($nesting[0], $nesting);
38436      (function($base, $super, $parent_nesting) {
38437        var self = $klass($base, $super, 'CustomFactory');
38438
38439        var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
38440
38441        
38442        self.$include($$('Factory'));
38443        
38444        $def(self, '$initialize', function $$initialize(seed_registry) {
38445          var self = this, $ret_or_1 = nil;
38446
38447          
38448          if (seed_registry == null) seed_registry = nil;
38449          return (self.registry = ($truthy(($ret_or_1 = seed_registry)) ? ($ret_or_1) : ($hash2([], {}))));
38450        }, -1);
38451        self.$private();
38452        return self.$attr_reader("registry");
38453      })($nesting[0], null, $nesting);
38454      (function($base, $parent_nesting) {
38455        var self = $module($base, 'DefaultFactory');
38456
38457        var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
38458
38459        
38460        self.$include($$('Factory'));
38461        $class_variable_set($nesting[0], '@@registry', $hash2([], {}));
38462        self.$private();
38463        
38464        $def(self, '$registry', function $$registry() {
38465          
38466          return $class_variable_get($nesting[0], '@@registry', false)
38467        });
38468        return nil;
38469      })($nesting[0], $nesting);
38470      (function($base, $super, $parent_nesting) {
38471        var self = $klass($base, $super, 'DefaultFactoryProxy');
38472
38473        var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
38474
38475        
38476        self.$include($$('DefaultFactory'));
38477        return nil;
38478      })($nesting[0], $$('CustomFactory'), $nesting);
38479      (function($base, $super, $parent_nesting) {
38480        var self = $klass($base, $super, 'Base');
38481
38482        var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype;
38483
38484        $proto.pre_class = nil;
38485        
38486        self.$include($$('SyntaxHighlighter'));
38487        return $def(self, '$format', function $$format(node, lang, opts) {
38488          var self = this, class_attr_val = nil, transform = nil, pre = nil, code = nil;
38489
38490          
38491          class_attr_val = ($truthy(opts['$[]']("nowrap")) ? ("" + (self.pre_class) + " highlight nowrap") : ("" + (self.pre_class) + " highlight"));
38492          if ($truthy((transform = opts['$[]']("transform")))) {
38493            
38494            transform['$[]']((pre = $hash2(["class"], {"class": class_attr_val})), (code = ($truthy(lang) ? ($hash2(["data-lang"], {"data-lang": lang})) : ($hash2([], {})))));
38495            if ($truthy((lang = code.$delete("data-lang")))) {
38496              code['$[]=']("data-lang", lang)
38497            };
38498            return "<pre" + ($send(pre, 'map', [], function $$4(k, v){
38499              
38500              if (k == null) k = nil;
38501              if (v == null) v = nil;
38502              return " " + (k) + "=\"" + (v) + "\"";}).$join()) + "><code" + ($send(code, 'map', [], function $$5(k, v){
38503              
38504              if (k == null) k = nil;
38505              if (v == null) v = nil;
38506              return " " + (k) + "=\"" + (v) + "\"";}).$join()) + ">" + (node.$content()) + "</code></pre>";
38507          } else {
38508            return "<pre class=\"" + (class_attr_val) + "\"><code" + (($truthy(lang) ? (" data-lang=\"" + (lang) + "\"") : (""))) + ">" + (node.$content()) + "</code></pre>"
38509          };
38510        });
38511      })($nesting[0], null, $nesting);
38512      return self.$extend($$('DefaultFactory'));
38513    })($nesting[0], $nesting)
38514  })($nesting[0], $nesting);
38515  self.$require("asciidoctor/syntax_highlighter.rb"+ '/../' + "syntax_highlighter/highlightjs");
38516  return nil;
38517};
38518
38519Opal.modules["asciidoctor/timings"] = function(Opal) {/* Generated by Opal 1.7.3 */
38520  "use strict";
38521  var $module = Opal.module, $klass = Opal.klass, $hash2 = Opal.hash2, $def = Opal.def, $send = Opal.send, $rb_minus = Opal.rb_minus, $slice = Opal.slice, $rb_plus = Opal.rb_plus, $truthy = Opal.truthy, $rb_gt = Opal.rb_gt, $gvars = Opal.gvars, $eqeq = Opal.eqeq, $const_set = Opal.const_set, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$;
38522
38523  Opal.add_stubs('[]=,now,-,delete,reduce,+,[],>,time,puts,sprintf,to_f,read_parse,convert,read_parse_convert,private,==,const_defined?,clock_gettime');
38524  return (function($base, $parent_nesting) {
38525    var self = $module($base, 'Asciidoctor');
38526
38527    var $nesting = [self].concat($parent_nesting);
38528
38529    return (function($base, $super, $parent_nesting) {
38530      var self = $klass($base, $super, 'Timings');
38531
38532      var $a, $b, $c, $d, $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype;
38533
38534      $proto.timers = $proto.log = nil;
38535      
38536      
38537      $def(self, '$initialize', function $$initialize() {
38538        var self = this;
38539
38540        
38541        self.log = $hash2([], {});
38542        return (self.timers = $hash2([], {}));
38543      });
38544      
38545      $def(self, '$start', function $$start(key) {
38546        var $a, self = this;
38547
38548        return ($a = [key, self.$now()], $send(self.timers, '[]=', $a), $a[$a.length - 1])
38549      });
38550      
38551      $def(self, '$record', function $$record(key) {
38552        var $a, self = this;
38553
38554        return ($a = [key, $rb_minus(self.$now(), self.timers.$delete(key))], $send(self.log, '[]=', $a), $a[$a.length - 1])
38555      });
38556      
38557      $def(self, '$time', function $$time($a) {
38558        var $post_args, keys, self = this, time = nil;
38559
38560        
38561        $post_args = $slice(arguments);
38562        keys = $post_args;
38563        time = $send(keys, 'reduce', [0], function $$1(sum, key){var self = $$1.$$s == null ? this : $$1.$$s, $ret_or_1 = nil;
38564          if (self.log == null) self.log = nil;
38565
38566          
38567          if (sum == null) sum = nil;
38568          if (key == null) key = nil;
38569          return $rb_plus(sum, ($truthy(($ret_or_1 = self.log['$[]'](key))) ? ($ret_or_1) : (0)));}, {$$s: self});
38570        if ($truthy($rb_gt(time, 0))) {
38571          return time
38572        } else {
38573          return nil
38574        };
38575      }, -1);
38576      
38577      $def(self, '$read', function $$read() {
38578        var self = this;
38579
38580        return self.$time("read")
38581      });
38582      
38583      $def(self, '$parse', function $$parse() {
38584        var self = this;
38585
38586        return self.$time("parse")
38587      });
38588      
38589      $def(self, '$read_parse', function $$read_parse() {
38590        var self = this;
38591
38592        return self.$time("read", "parse")
38593      });
38594      
38595      $def(self, '$convert', function $$convert() {
38596        var self = this;
38597
38598        return self.$time("convert")
38599      });
38600      
38601      $def(self, '$read_parse_convert', function $$read_parse_convert() {
38602        var self = this;
38603
38604        return self.$time("read", "parse", "convert")
38605      });
38606      
38607      $def(self, '$write', function $$write() {
38608        var self = this;
38609
38610        return self.$time("write")
38611      });
38612      
38613      $def(self, '$total', function $$total() {
38614        var self = this;
38615
38616        return self.$time("read", "parse", "convert", "write")
38617      });
38618      
38619      $def(self, '$print_report', function $$print_report(to, subject) {
38620        var self = this;
38621        if ($gvars.stdout == null) $gvars.stdout = nil;
38622
38623        
38624        if (to == null) to = $gvars.stdout;
38625        if (subject == null) subject = nil;
38626        if ($truthy(subject)) {
38627          to.$puts("Input file: " + (subject))
38628        };
38629        to.$puts("  Time to read and parse source: " + (self.$sprintf("%05.5f", self.$read_parse().$to_f())));
38630        to.$puts("  Time to convert document: " + (self.$sprintf("%05.5f", self.$convert().$to_f())));
38631        return to.$puts("  Total time (read, parse and convert): " + (self.$sprintf("%05.5f", self.$read_parse_convert().$to_f())));
38632      }, -1);
38633      self.$private();
38634      if (($truthy($$$('Process')['$const_defined?']("CLOCK_MONOTONIC", false)) && ($eqeq(((($a = $$$('::', 'Process', 'skip_raise')) && ($b = $a, $b) && ($c = $b) && ((($d = $c.$clock_gettime) && !$d.$$stub) || $c['$respond_to_missing?']('clock_gettime'))) ? 'method' : nil), "method")))) {
38635        
38636        $const_set($nesting[0], 'CLOCK_ID', $$$($$$('Process'), 'CLOCK_MONOTONIC'));
38637        return $def(self, '$now', function $$now() {
38638          
38639          return $$$('Process').$clock_gettime($$('CLOCK_ID'))
38640        });
38641      } else {
38642        return $def(self, '$now', function $$now() {
38643          
38644          return $$$('Time').$now()
38645        })
38646      };
38647    })($nesting[0], null, $nesting)
38648  })($nesting[0], $nesting)
38649};
38650
38651Opal.modules["asciidoctor/converter/html5"] = function(Opal) {/* Generated by Opal 1.7.3 */
38652  "use strict";
38653  var $module = Opal.module, $klass = Opal.klass, $const_set = Opal.const_set, $hash2 = Opal.hash2, $regexp = Opal.regexp, $eqeq = Opal.eqeq, $def = Opal.def, $send2 = Opal.send2, $find_super = Opal.find_super, $truthy = Opal.truthy, $send = Opal.send, $rb_gt = Opal.rb_gt, $rb_plus = Opal.rb_plus, $not = Opal.not, $neqeq = Opal.neqeq, $rb_le = Opal.rb_le, $rb_lt = Opal.rb_lt, $to_ary = Opal.to_ary, $rb_times = Opal.rb_times, $rb_minus = Opal.rb_minus, $gvars = Opal.gvars, $return_val = Opal.return_val, $alias = Opal.alias, $eqeqeq = Opal.eqeqeq, $slice = Opal.slice, $to_a = Opal.to_a, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$;
38654
38655  Opal.add_stubs('register_for,default=,==,[],init_backend_traits,node_name,convert_inline_quoted,convert_paragraph,convert_inline_anch
38655or,convert_section,convert_listing,convert_literal,convert_ulist,convert_olist,convert_dlist,convert_admonition,convert_colist,convert_embedded,convert_example,convert_floating_title,convert_image,convert_inline_break,convert_inline_button,convert_inline_callout,convert_inline_footnote,convert_inline_image,convert_inline_indexterm,convert_inline_kbd,convert_inline_menu,convert_open,convert_page_break,convert_preamble,convert_quote,convert_sidebar,convert_stem,convert_table,convert_thematic_break,convert_verse,convert_video,convert_document,convert_toc,convert_pass,convert_audio,empty?,attr,attr?,<<,include?,sub_replacements,gsub,extname,slice,length,doctitle,normalize_web_path,primary_stylesheet_data,instance,read_contents,syntax_highlighter,size,docinfo,id,sections?,doctype,role?,role,join,noheader,convert,converter,generate_manname_section,header?,notitle,title,header,each,authors,>,name,email,sub_macros,+,downcase,concat,content,!,footnotes?,footnotes,index,text,nofooter,docinfo?,[]=,delete_at,inspect,!=,to_i,attributes,document,sections,level,caption,captioned_title,<=,numbered,<,sectname,sectnum,convert_outline,title?,icon_uri,compact,media_uri,option?,append_boolean_attribute,style,items,blocks?,text?,chomp,safe,read_svg_contents,alt,image_uri,encode_attribute_value,append_link_constraint_attrs,highlight?,to_sym,format,*,-,count,end_with?,start_with?,list_marker_keyword,parent,warn,logger,context,error,content_only,new,columns,to_h,rows,colspan,rowspan,unshift,shift,split,pop,nil_or_empty?,type,===,catalog,get_root_document,xreftext,target,reftext,chop,sub,match,private,upcase,nested?,parent_document,handles?,to_s,send');
38656  return (function($base, $parent_nesting) {
38657    var self = $module($base, 'Asciidoctor');
38658
38659    var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
38660
38661    return (function($base, $super, $parent_nesting) {
38662      var self = $klass($base, $super, 'Html5Converter');
38663
38664      var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype;
38665
38666      $proto.void_element_slash = $proto.xml_mode = $proto.refs = $proto.resolving_xref = nil;
38667      
38668      self.$register_for("html5");
38669      $const_set($nesting[0], 'QUOTE_TAGS', $hash2(["monospaced", "emphasis", "strong", "double", "single", "mark", "superscript", "subscript", "asciimath", "latexmath"], {"monospaced": ["<code>", "</code>", true], "emphasis": ["<em>", "</em>", true], "strong": ["<strong>", "</strong>", true], "double": ["&#8220;", "&#8221;"], "single": ["&#8216;", "&#8217;"], "mark": ["<mark>", "</mark>", true], "superscript": ["<sup>", "</sup>", true], "subscript": ["<sub>", "</sub>", true], "asciimath": ["\\$", "\\$"], "latexmath": ["\\(", "\\)"]}))['$default='](["", ""]);
38670      $const_set($nesting[0], 'DropAnchorRx', /<(?:a\b[^>]*|\/a)>/);
38671      $const_set($nesting[0], 'StemBreakRx', / *\\\n(?:\\?\n)*|\n\n+/);
38672      
38673      $const_set($nesting[0], 'SvgPreambleRx', $regexp(["^", $$('CC_ALL'), "*?(?=<svg[\\s>])"]));
38674      $const_set($nesting[0], 'SvgStartTagRx', /^<svg(?:\s[^>]*)?>/);;
38675      $const_set($nesting[0], 'DimensionAttributeRx', $regexp(["\\s(?:width|height|style)=([\"'])", $$('CC_ANY'), "*?\\1"]));
38676      
38677      $def(self, '$initialize', function $$initialize(backend, opts) {
38678        var self = this, syntax = nil;
38679
38680        
38681        if (opts == null) opts = $hash2([], {});
38682        self.backend = backend;
38683        if ($eqeq(opts['$[]']("htmlsyntax"), "xml")) {
38684          
38685          syntax = "xml";
38686          self.xml_mode = true;
38687          self.void_element_slash = "/";
38688        } else {
38689          
38690          syntax = "html";
38691          self.xml_mode = nil;
38692          self.void_element_slash = "";
38693        };
38694        return self.$init_backend_traits($hash2(["basebackend", "filetype", "htmlsyntax", "outfilesuffix", "supports_templates"], {"basebackend": "html", "filetype": "html", "htmlsyntax": syntax, "outfilesuffix": ".html", "supports_templates": true}));
38695      }, -2);
38696      
38697      $def(self, '$convert', function $$convert(node, transform, opts) {
38698        var $yield = $$convert.$$p || nil, self = this;
38699
38700        $$convert.$$p = null;
38701        
38702        if (transform == null) transform = node.$node_name();
38703        if (opts == null) opts = nil;
38704        
38705        switch (transform) {
38706          case "inline_quoted":
38707            return self.$convert_inline_quoted(node)
38708          case "paragraph":
38709            return self.$convert_paragraph(node)
38710          case "inline_anchor":
38711            return self.$convert_inline_anchor(node)
38712          case "section":
38713            return self.$convert_section(node)
38714          case "listing":
38715            return self.$convert_listing(node)
38716          case "literal":
38717            return self.$convert_literal(node)
38718          case "ulist":
38719            return self.$convert_ulist(node)
38720          case "olist":
38721            return self.$convert_olist(node)
38722          case "dlist":
38723            return self.$convert_dlist(node)
38724          case "admonition":
38725            return self.$convert_admonition(node)
38726          case "colist":
38727            return self.$convert_colist(node)
38728          case "embedded":
38729            return self.$convert_embedded(node)
38730          case "example":
38731            return self.$convert_example(node)
38732          case "floating_title":
38733            return self.$convert_floating_title(node)
38734          case "image":
38735            return self.$convert_image(node)
38736          case "inline_break":
38737            return self.$convert_inline_break(node)
38738          case "inline_button":
38739            return self.$convert_inline_button(node)
38740          case "inline_callout":
38741            return self.$convert_inline_callout(node)
38742          case "inline_footnote":
38743            return self.$convert_inline_footnote(node)
38744          case "inline_image":
38745            return self.$convert_inline_image(node)
38746          case "inline_indexterm":
38747            return self.$convert_inline_indexterm(node)
38748          case "inline_kbd":
38749            return self.$convert_inline_kbd(node)
38750          case "inline_menu":
38751            return self.$convert_inline_menu(node)
38752          case "open":
38753            return self.$convert_open(node)
38754          case "page_break":
38755            return self.$convert_page_break(node)
38756          case "preamble":
38757            return self.$convert_preamble(node)
38758          case "quote":
38759            return self.$convert_quote(node)
38760          case "sidebar":
38761            return self.$convert_sidebar(node)
38762          case "stem":
38763            return self.$convert_stem(node)
38764          case "table":
38765            return self.$convert_table(node)
38766          case "thematic_break":
38767            return self.$convert_thematic_break(node)
38768          case "verse":
38769            return self.$convert_verse(node)
38770          case "video":
38771            return self.$convert_video(node)
38772          case "document":
38773            return self.$convert_document(node)
38774          case "toc":
38775            return self.$convert_toc(node)
38776          case "pass":
38777            return self.$convert_pass(node)
38778          case "audio":
38779            return self.$convert_audio(node)
38780          default:
38781            return $send2(self, $find_super(self, 'convert', $$convert, false, true), 'convert', [node, transform, opts], $yield)
38782        };
38783      }, -2);
38784      
38785      $def(self, '$convert_document', function $$convert_document(node) {
38786        var self = this, br = nil, slash = nil, asset_uri_scheme = nil, cdn_base_url = nil, linkcss = nil, max_width_attr = nil, result = nil, lang_attribute = nil, authors = nil, icon_href = nil, icon_type = nil, icon_ext = nil, webfonts = nil, iconfont_stylesheet = nil, syntax_hl = nil, syntax_hl_docinfo_head_idx = nil, docinfo_content = nil, id_attr = nil, sectioned = nil, classes = nil, details = nil, idx = nil, $ret_or_1 = nil, eqnums_val = nil, eqnums_opt = nil;
38787
38788        
38789        br = "<br" + ((slash = self.void_element_slash)) + ">";
38790        if (!$truthy((asset_uri_scheme = node.$attr("asset-uri-scheme", "https"))['$empty?']())) {
38791          asset_uri_scheme = "" + (asset_uri_scheme) + ":"
38792        };
38793        cdn_base_url = "" + (asset_uri_scheme) + "//cdnjs.cloudflare.com/ajax/libs";
38794        linkcss = node['$attr?']("linkcss");
38795        max_width_attr = ($truthy(node['$attr?']("max-width")) ? (" style=\"max-width: " + (node.$attr("max-width")) + ";\"") : (""));
38796        result = ["<!DOCTYPE html>"];
38797        lang_attribute = ($truthy(node['$attr?']("nolang")) ? ("") : (" lang=\"" + (node.$attr("lang", "en")) + "\""));
38798        result['$<<']("<html" + (($truthy(self.xml_mode) ? (" xmlns=\"http://www.w3.org/1999/xhtml\"") : (""))) + (lang_attribute) + ">");
38799        result['$<<']("<head>\n" + "<meta charset=\"" + (node.$attr("encoding", "UTF-8")) + "\"" + (slash) + ">\n" + "<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\"" + (slash) + ">\n" + "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"" + (slash) + ">\n" + "<meta name=\"generator\" content=\"Asciidoctor " + (node.$attr("asciidoctor-version")) + "\"" + (slash) + ">");
38800        if ($truthy(node['$attr?']("app-name"))) {
38801          result['$<<']("<meta name=\"application-name\" content=\"" + (node.$attr("app-name")) + "\"" + (slash) + ">")
38802        };
38803        if ($truthy(node['$attr?']("description"))) {
38804          result['$<<']("<meta name=\"description\" content=\"" + (node.$attr("description")) + "\"" + (slash) + ">")
38805        };
38806        if ($truthy(node['$attr?']("keywords"))) {
38807          result['$<<']("<meta name=\"keywords\" content=\"" + (node.$attr("keywords")) + "\"" + (slash) + ">")
38808        };
38809        if ($truthy(node['$attr?']("authors"))) {
38810          result['$<<']("<meta name=\"author\" content=\"" + (($truthy((authors = node.$sub_replacements(node.$attr("authors")))['$include?']("<")) ? (
38810authors.$gsub($$('XmlSanitizeRx'), "")) : (authors))) + "\"" + (slash) + ">")
38811        };
38812        if ($truthy(node['$attr?']("copyright"))) {
38813          result['$<<']("<meta name=\"copyright\" content=\"" + (node.$attr("copyright")) + "\"" + (slash) + ">")
38814        };
38815        if ($truthy(node['$attr?']("favicon"))) {
38816          
38817          if ($truthy((icon_href = node.$attr("favicon"))['$empty?']())) {
38818            
38819            icon_href = "favicon.ico";
38820            icon_type = "image/x-icon";
38821          } else if ($truthy((icon_ext = $$('Helpers').$extname(icon_href, nil)))) {
38822            icon_type = ($eqeq(icon_ext, ".ico") ? ("image/x-icon") : ("image/" + (icon_ext.$slice(1, icon_ext.$length()))))
38823          } else {
38824            icon_type = "image/x-icon"
38825          };
38826          result['$<<']("<link rel=\"icon\" type=\"" + (icon_type) + "\" href=\"" + (icon_href) + "\"" + (slash) + ">");
38827        };
38828        result['$<<']("<title>" + (node.$doctitle($hash2(["sanitize", "use_fallback"], {"sanitize": true, "use_fallback": true}))) + "</title>");
38829        if ($truthy($$('DEFAULT_STYLESHEET_KEYS')['$include?'](node.$attr("stylesheet")))) {
38830          
38831          if ($truthy((webfonts = node.$attr("webfonts")))) {
38832            result['$<<']("<link rel=\"stylesheet\" href=\"" + (asset_uri_scheme) + "//fonts.googleapis.com/css?family=" + (($truthy(webfonts['$empty?']()) ? ("Open+Sans:300,300italic,400,400italic,600,600italic%7CNoto+Serif:400,400italic,700,700italic%7CDroid+Sans+Mono:400,700") : (webfonts))) + "\"" + (slash) + ">")
38833          };
38834          if ($truthy(linkcss)) {
38835            result['$<<']("<link rel=\"stylesheet\" href=\"" + (node.$normalize_web_path($$('DEFAULT_STYLESHEET_NAME'), node.$attr("stylesdir", ""), false)) + "\"" + (slash) + ">")
38836          } else {
38837            result['$<<']("<style>\n" + ($$('Stylesheets').$instance().$primary_stylesheet_data()) + "\n" + "</style>")
38838          };
38839        } else if ($truthy(node['$attr?']("stylesheet"))) {
38840          if ($truthy(linkcss)) {
38841            result['$<<']("<link rel=\"stylesheet\" href=\"" + (node.$normalize_web_path(node.$attr("stylesheet"), node.$attr("stylesdir", ""))) + "\"" + (slash) + ">")
38842          } else {
38843            result['$<<']("<style>\n" + (node.$read_contents(node.$attr("stylesheet"), $hash2(["start", "warn_on_failure", "label"], {"start": node.$attr("stylesdir"), "warn_on_failure": true, "label": "stylesheet"}))) + "\n" + "</style>")
38844          }
38845        };
38846        if ($truthy(node['$attr?']("icons", "font"))) {
38847          if ($truthy(node['$attr?']("iconfont-remote"))) {
38848            result['$<<']("<link rel=\"stylesheet\" href=\"" + (node.$attr("iconfont-cdn", "" + (cdn_base_url) + "/font-awesome/" + ($$('FONT_AWESOME_VERSION')) + "/css/font-awesome.min.css")) + "\"" + (slash) + ">")
38849          } else {
38850            
38851            iconfont_stylesheet = "" + (node.$attr("iconfont-name", "font-awesome")) + ".css";
38852            result['$<<']("<link rel=\"stylesheet\" href=\"" + (node.$normalize_web_path(iconfont_stylesheet, node.$attr("stylesdir", ""), false)) + "\"" + (slash) + ">");
38853          }
38854        };
38855        if ($truthy((syntax_hl = node.$syntax_highlighter()))) {
38856          result['$<<']((syntax_hl_docinfo_head_idx = result.$size()))
38857        };
38858        if (!$truthy((docinfo_content = node.$docinfo())['$empty?']())) {
38859          result['$<<'](docinfo_content)
38860        };
38861        result['$<<']("</head>");
38862        id_attr = ($truthy(node.$id()) ? (" id=\"" + (node.$id()) + "\"") : (""));
38863        if (((($truthy((sectioned = node['$sections?']())) && ($truthy(node['$attr?']("toc-class")))) && ($truthy(node['$attr?']("toc")))) && ($truthy(node['$attr?']("toc-placement", "auto"))))) {
38864          classes = [node.$doctype(), node.$attr("toc-class"), "toc-" + (node.$attr("toc-position", "header"))]
38865        } else {
38866          classes = [node.$doctype()]
38867        };
38868        if ($truthy(node['$role?']())) {
38869          classes['$<<'](node.$role())
38870        };
38871        result['$<<']("<body" + (id_attr) + " class=\"" + (classes.$join(" ")) + "\">");
38872        if (!$truthy((docinfo_content = node.$docinfo("header"))['$empty?']())) {
38873          result['$<<'](docinfo_content)
38874        };
38875        if (!$truthy(node.$noheader())) {
38876          
38877          result['$<<']("<div id=\"header\"" + (max_width_attr) + ">");
38878          if ($eqeq(node.$doctype(), "manpage")) {
38879            
38880            result['$<<']("<h1>" + (node.$doctitle()) + " Manual Page</h1>");
38881            if ((($truthy(sectioned) && ($truthy(node['$attr?']("toc")))) && ($truthy(node['$attr?']("toc-placement", "auto"))))) {
38882              result['$<<']("<div id=\"toc\" class=\"" + (node.$attr("toc-class", "toc")) + "\">\n" + "<div id=\"toctitle\">" + (node.$attr("toc-title")) + "</div>\n" + (node.$converter().$convert(node, "outline")) + "\n" + "</div>")
38883            };
38884            if ($truthy(node['$attr?']("manpurpose"))) {
38885              result['$<<'](self.$generate_manname_section(node))
38886            };
38887          } else {
38888            
38889            if ($truthy(node['$header?']())) {
38890              
38891              if (!$truthy(node.$notitle())) {
38892                result['$<<']("<h1>" + (node.$header().$title()) + "</h1>")
38893              };
38894              details = [];
38895              idx = 1;
38896              $send(node.$authors(), 'each', [], function $$1(author){
38897                
38898                if (author == null) author = nil;
38899                details['$<<']("<span id=\"author" + (($truthy($rb_gt(idx, 1)) ? (idx) : (""))) + "\" class=\"author\">" + (node.$sub_replacements(author.$name())) + "</span>" + (br));
38900                if ($truthy(author.$email())) {
38901                  details['$<<']("<span id=\"email" + (($truthy($rb_gt(idx, 1)) ? (idx) : (""))) + "\" class=\"email\">" + (node.$sub_macros(author.$email())) + "</span>" + (br))
38902                };
38903                return (idx = $rb_plus(idx, 1));});
38904              if ($truthy(node['$attr?']("revnumber"))) {
38905                details['$<<']("<span id=\"revnumber\">" + (($truthy(($ret_or_1 = node.$attr("version-label"))) ? ($ret_or_1) : ("")).$downcase()) + " " + (node.$attr("revnumber")) + (($truthy(node['$attr?']("revdate")) ? (",") : (""))) + "</span>")
38906              };
38907              if ($truthy(node['$attr?']("revdate"))) {
38908                details['$<<']("<span id=\"revdate\">" + (node.$attr("revdate")) + "</span>")
38909              };
38910              if ($truthy(node['$attr?']("revremark"))) {
38911                details['$<<']("" + (br) + "<span id=\"revremark\">" + (node.$attr("revremark")) + "</span>")
38912              };
38913              if (!$truthy(details['$empty?']())) {
38914                
38915                result['$<<']("<div class=\"details\">");
38916                result.$concat(details);
38917                result['$<<']("</div>");
38918              };
38919            };
38920            if ((($truthy(sectioned) && ($truthy(node['$attr?']("toc")))) && ($truthy(node['$attr?']("toc-placement", "auto"))))) {
38921              result['$<<']("<div id=\"toc\" class=\"" + (node.$attr("toc-class", "toc")) + "\">\n" + "<div id=\"toctitle\">" + (node.$attr("toc-title")) + "</div>\n" + (node.$converter().$convert(node, "outline")) + "\n" + "</div>")
38922            };
38923          };
38924          result['$<<']("</div>");
38925        };
38926        result['$<<']("<div id=\"content\"" + (max_width_attr) + ">\n" + (node.$content()) + "\n" + "</div>");
38927        if (($truthy(node['$footnotes?']()) && ($not(node['$attr?']("nofootnotes"))))) {
38928          
38929          result['$<<']("<div id=\"footnotes\"" + (max_width_attr) + ">\n" + "<hr" + (slash) + ">");
38930          $send(node.$footnotes(), 'each', [], function $$2(footnote){
38931            
38932            if (footnote == null) footnote = nil;
38933            return result['$<<']("<div class=\"footnote\" id=\"_footnotedef_" + (footnote.$index()) + "\">\n" + "<a href=\"#_footnoteref_" + (footnote.$index()) + "\">" + (footnote.$index()) + "</a>. " + (footnote.$text()) + "\n" + "</div>");});
38934          result['$<<']("</div>");
38935        };
38936        if (!$truthy(node.$nofooter())) {
38937          
38938          result['$<<']("<div id=\"footer\"" + (max_width_attr) + ">");
38939          result['$<<']("<div id=\"footer-text\">");
38940          if ($truthy(node['$attr?']("revnumber"))) {
38941            result['$<<']("" + (node.$attr("version-label")) + " " + (node.$attr("revnumber")) + (br))
38942          };
38943          if (($truthy(node['$attr?']("last-update-label")) && ($not(node['$attr?']("reproducible"))))) {
38944            result['$<<']("" + (node.$attr("last-update-label")) + " " + (node.$attr("docdatetime")))
38945          };
38946          result['$<<']("</div>");
38947          result['$<<']("</div>");
38948        };
38949        if ($truthy(syntax_hl)) {
38950          
38951          if ($truthy(syntax_hl['$docinfo?']("head"))) {
38952            result['$[]='](syntax_hl_docinfo_head_idx, syntax_hl.$docinfo("head", node, $hash2(["cdn_base_url", "linkcss", "self_closing_tag_slash"], {"cdn_base_url": cdn_base_url, "linkcss": linkcss, "self_
38952closing_tag_slash": slash})))
38953          } else {
38954            result.$delete_at(syntax_hl_docinfo_head_idx)
38955          };
38956          if ($truthy(syntax_hl['$docinfo?']("footer"))) {
38957            result['$<<'](syntax_hl.$docinfo("footer", node, $hash2(["cdn_base_url", "linkcss", "self_closing_tag_slash"], {"cdn_base_url": cdn_base_url, "linkcss": linkcss, "self_closing_tag_slash": slash})))
38958          };
38959        };
38960        if ($truthy(node['$attr?']("stem"))) {
38961          
38962          eqnums_val = node.$attr("eqnums", "none");
38963          if ($truthy(eqnums_val['$empty?']())) {
38964            eqnums_val = "AMS"
38965          };
38966          eqnums_opt = " equationNumbers: { autoNumber: \"" + (eqnums_val) + "\" } ";
38967          result['$<<']("<script type=\"text/x-mathjax-config\">\n" + "MathJax.Hub.Config({\n" + "  messageStyle: \"none\",\n" + "  tex2jax: {\n" + "    inlineMath: [" + ($$('INLINE_MATH_DELIMITERS')['$[]']("latexmath").$inspect()) + "],\n" + "    displayMath: [" + ($$('BLOCK_MATH_DELIMITERS')['$[]']("latexmath").$inspect()) + "],\n" + "    ignoreClass: \"nostem|nolatexmath\"\n" + "  },\n" + "  asciimath2jax: {\n" + "    delimiters: [" + ($$('BLOCK_MATH_DELIMITERS')['$[]']("asciimath").$inspect()) + "],\n" + "    ignoreClass: \"nostem|noasciimath\"\n" + "  },\n" + "  TeX: {" + (eqnums_opt) + "}\n" + "})\n" + "MathJax.Hub.Register.StartupHook(\"AsciiMath Jax Ready\", function () {\n" + "  MathJax.InputJax.AsciiMath.postfilterHooks.Add(function (data, node) {\n" + "    if ((node = data.script.parentNode) && (node = node.parentNode) && node.classList.contains(\"stemblock\")) {\n" + "      data.math.root.display = \"block\"\n" + "    }\n" + "    return data\n" + "  })\n" + "})\n" + "</script>\n" + "<script src=\"" + (cdn_base_url) + "/mathjax/" + ($$('MATHJAX_VERSION')) + "/MathJax.js?config=TeX-MML-AM_HTMLorMML\"></script>");
38968        };
38969        if (!$truthy((docinfo_content = node.$docinfo("footer"))['$empty?']())) {
38970          result['$<<'](docinfo_content)
38971        };
38972        result['$<<']("</body>");
38973        result['$<<']("</html>");
38974        return result.$join($$('LF'));
38975      });
38976      
38977      $def(self, '$convert_embedded', function $$convert_embedded(node) {
38978        var self = this, result = nil, id_attr = nil, toc_p = nil;
38979
38980        
38981        result = [];
38982        if ($eqeq(node.$doctype(), "manpage")) {
38983          
38984          if (!$truthy(node.$notitle())) {
38985            
38986            id_attr = ($truthy(node.$id()) ? (" id=\"" + (node.$id()) + "\"") : (""));
38987            result['$<<']("<h1" + (id_attr) + ">" + (node.$doctitle()) + " Manual Page</h1>");
38988          };
38989          if ($truthy(node['$attr?']("manpurpose"))) {
38990            result['$<<'](self.$generate_manname_section(node))
38991          };
38992        } else if (($truthy(node['$header?']()) && ($not(node.$notitle())))) {
38993          
38994          id_attr = ($truthy(node.$id()) ? (" id=\"" + (node.$id()) + "\"") : (""));
38995          result['$<<']("<h1" + (id_attr) + ">" + (node.$header().$title()) + "</h1>");
38996        };
38997        if (((($truthy(node['$sections?']()) && ($truthy(node['$attr?']("toc")))) && ($neqeq((toc_p = node.$attr("toc-placement")), "macro"))) && ($neqeq(toc_p, "preamble")))) {
38998          result['$<<']("<div id=\"toc\" class=\"toc\">\n" + "<div id=\"toctitle\">" + (node.$attr("toc-title")) + "</div>\n" + (node.$converter().$convert(node, "outline")) + "\n" + "</div>")
38999        };
39000        result['$<<'](node.$content());
39001        if (($truthy(node['$footnotes?']()) && ($not(node['$attr?']("nofootnotes"))))) {
39002          
39003          result['$<<']("<div id=\"footnotes\">\n" + "<hr" + (self.void_element_slash) + ">");
39004          $send(node.$footnotes(), 'each', [], function $$3(footnote){
39005            
39006            if (footnote == null) footnote = nil;
39007            return result['$<<']("<div class=\"footnote\" id=\"_footnotedef_" + (footnote.$index()) + "\">\n" + "<a href=\"#_footnoteref_" + (footnote.$index()) + "\">" + (footnote.$index()) + "</a>. " + (footnote.$text()) + "\n" + "</div>");});
39008          result['$<<']("</div>");
39009        };
39010        return result.$join($$('LF'));
39011      });
39012      
39013      $def(self, '$convert_outline', function $$convert_outline(node, opts) {
39014        var self = this, sectnumlevels = nil, $ret_or_1 = nil, $ret_or_2 = nil, toclevels = nil, sections = nil, result = nil;
39015
39016        
39017        if (opts == null) opts = $hash2([], {});
39018        if (!$truthy(node['$sections?']())) {
39019          return nil
39020        };
39021        sectnumlevels = ($truthy(($ret_or_1 = opts['$[]']("sectnumlevels"))) ? ($ret_or_1) : (($truthy(($ret_or_2 = node.$document().$attributes()['$[]']("sectnumlevels"))) ? ($ret_or_2) : (3)).$to_i()));
39022        toclevels = ($truthy(($ret_or_1 = opts['$[]']("toclevels"))) ? ($ret_or_1) : (($truthy(($ret_or_2 = node.$document().$attributes()['$[]']("toclevels"))) ? ($ret_or_2) : (2)).$to_i()));
39023        sections = node.$sections();
39024        result = ["<ul class=\"sectlevel" + (sections['$[]'](0).$level()) + "\">"];
39025        $send(sections, 'each', [], function $$4(section){var self = $$4.$$s == null ? this : $$4.$$s, slevel = nil, stitle = nil, signifier = nil, child_toc_level = nil;
39026
39027          
39028          if (section == null) section = nil;
39029          slevel = section.$level();
39030          if ($truthy(section.$caption())) {
39031            stitle = section.$captioned_title()
39032          } else if (($truthy(section.$numbered()) && ($truthy($rb_le(slevel, sectnumlevels))))) {
39033            if (($truthy($rb_lt(slevel, 2)) && ($eqeq(node.$document().$doctype(), "book")))) {
39034              
39035              switch (section.$sectname()) {
39036                case "chapter":
39037                  stitle = "" + (($truthy((signifier = node.$document().$attributes()['$[]']("chapter-signifier"))) ? ("" + (signifier) + " ") : (""))) + (section.$sectnum()) + " " + (section.$title())
39038                  break;
39039                case "part":
39040                  stitle = "" + (($truthy((signifier = node.$document().$attributes()['$[]']("part-signifier"))) ? ("" + (signifier) + " ") : (""))) + (section.$sectnum(nil, ":")) + " " + (section.$title())
39041                  break;
39042                default:
39043                  stitle = "" + (section.$sectnum()) + " " + (section.$title())
39044              }
39045            } else {
39046              stitle = "" + (section.$sectnum()) + " " + (section.$title())
39047            }
39048          } else {
39049            stitle = section.$title()
39050          };
39051          if ($truthy(stitle['$include?']("<a"))) {
39052            stitle = stitle.$gsub($$('DropAnchorRx'), "")
39053          };
39054          if (($truthy($rb_lt(slevel, toclevels)) && ($truthy((child_toc_level = self.$convert_outline(section, $hash2(["toclevels", "sectnumlevels"], {"toclevels": toclevels, "sectnumlevels": sectnumlevels}))))))) {
39055            
39056            result['$<<']("<li><a href=\"#" + (section.$id()) + "\">" + (stitle) + "</a>");
39057            result['$<<'](child_toc_level);
39058            return result['$<<']("</li>");
39059          } else {
39060            return result['$<<']("<li><a href=\"#" + (section.$id()) + "\">" + (stitle) + "</a></li>")
39061          };}, {$$s: self});
39062        result['$<<']("</ul>");
39063        return result.$join($$('LF'));
39064      }, -2);
39065      
39066      $def(self, '$convert_section', function $$convert_section(node) {
39067        var doc_attrs = nil, level = nil, title = nil, $ret_or_1 = nil, signifier = nil, id_attr = nil, id = nil, role = nil;
39068
39069        
39070        doc_attrs = node.$document().$attributes();
39071        level = node.$level();
39072        if ($truthy(node.$caption())) {
39073          title = node.$captioned_title()
39074        } else if (($truthy(node.$numbered()) && ($truthy($rb_le(level, ($truthy(($ret_or_1 = doc_attrs['$[]']("sectnumlevels"))) ? ($ret_or_1) : (3)).$to_i()))))) {
39075          if (($truthy($rb_lt(level, 2)) && ($eqeq(node.$document().$doctype(), "book")))) {
39076            
39077            switch (node.$sectname()) {
39078              case "chapter":
39079                title = "" + (($truthy((signifier = doc_attrs['$[]']("chapter-signifier"))) ? ("" + (signifier) + " ") : (""))) + (node.$sectnum()) + " " + (node.$title())
39080                break;
39081              case "part":
39082                title = "" + (($truthy((signifier = doc_attrs['$[]']("part-signifier"))) ? ("" + (signifier) + " ") : (""))) + (node.$sectnum(nil, ":")) + " " + (node.$title())
39083                break;
39084              default:
39085                title = "" + (node.$sectnum()) + " " + (node.$title())
39086            }
39087          } else {
39088            title = "" + (node.$sectnum()) + " " + (node.$title())
39089          }
39090        } else {
39091          title = node.$title()
39092        };
39093        if ($truthy(node.$id())) {
39094          
39095          id_attr = " id=\"" + ((id = node.$id())) + "\"";
39096          if ($truthy(doc_attrs['$[]']("sectlinks"))) {
39097            title = "<a class=\"link\" href=\"#" + (id) + "\">" + (title) + "</a>"
39098          };
39099          if ($truthy(doc_attrs['$[]']("sectanchors"))) {
39100            if ($eqeq(doc_attrs['$[]']("sectanchors"), "after")) {
39101              title = "" + (title) + "<a class=\"anchor\" href=\"#" + (id) + "\"></a>"
39102            } else {
39103              title = "<a class=\"anchor\" href=\"#" + (id) + "\"></a>" + (title)
39104            }
39105          };
39106        } else {
39107          id_attr = ""
39108        };
39109        if ($eqeq(level, 0)) {
39110          return "<h1" + (id_attr) + " class=\"sect0" + (($truthy((role = node.$role())) ? (" " + (role)) : (""))) + "\">" + (title) + "</h1>\n" + (node.$content())
39111        } else {
39112          return "<div class=\"sect" + (level) + (($truthy((role = node.$role())) ? (" " + (role)) : (""))) + "\">\n" + "<h" + ($rb_plus(level, 1)) + (id_attr) + ">" + (title) + "</h" + ($rb_plus(level, 1)) + ">\n" + (($eqeq(level, 1) ? ("<div class=\"sectionbody\">\n" + (node.$content()) + "\n" + "</div>") : (node.$content()))) + "\n" + "</div>"
39113        };
39114      });
39115      
39116      $def(self, '$convert_admonition', function $$convert_admonition(node) {
39117        var self = this, id_attr = nil, name = nil, title_element = nil, label = nil, role = nil;
39118
39119        
39120        id_attr = ($truthy(node.$id()) ? (" id=\"" + (node.$id()) + "\"") : (""));
39121        name = node.$attr("name");
39122        title_element = ($truthy(node['$title?']()) ? ("<div class=\"title\">" + (node.$title()) + "</div>\n") : (""));
39123        if ($truthy(node.$document()['$attr?']("icons"))) {
39124          if (($truthy(node.$document()['$attr?']("icons", "font")) && ($not(node['$attr?']("icon"))))) {
39125            label = "<i class=\"fa icon-" + (name) + "\" title=\"" + (node.$attr("textlabel")) + "\"></i>"
39126          } else {
39127            label = "<img src=\"" + (node.$icon_uri(name)) + "\" alt=\"" + (node.$attr("textlabel")) + "\"" + (self.void_element_slash) + ">"
39128          }
39129        } else {
39130          label = "<div class=\"title\">" + (node.$attr("textlabel")) + "</div>"
39131        };
39132        return "<div" + (id_attr) + " class=\"admonitionblock " + (name) + (($truthy((role = node.$role())) ? (" " + (role)) : (""))) + "\">\n" + "<table>\n" + "<tr>\n" + "<td class=\"icon\">\n" + (label) + "\n" + "</td>\n" + "<td class=\"content\">\n" + (title_element) + (node.$content()) + "\n" + "</td>\n" + "</tr>\n" + "</table>\n" + "</div>";
39133      });
39134      
39135      $def(self, '$convert_audio', function $$convert_audio(node) {
39136        var self = this, xml = nil, id_attribute = nil, classes = nil, class_attribute = nil, title_element = nil, start_t = nil, end_t = nil, time_anchor = nil, $ret_or_1 = nil;
39137
39138        
39139        xml = self.xml_mode;
39140        id_attribute = ($truthy(node.$id()) ? (" id=\"" + (node.$id()) + "\"") : (""));
39141        classes = ["audioblock", node.$role()].$compact();
39142        class_attribute = " class=\"" + (classes.$join(" ")) + "\"";
39143        title_element = ($truthy(node['$title?']()) ? ("<div class=\"title\">" + (node.$title()) + "</div>\n") : (""));
39144        start_t = node.$attr("start");
39145        end_t = node.$attr("end");
39146        time_anchor = (($truthy(start_t) || ($truthy(end_t))) ? ("#t=" + (($truthy(($ret_or_1 = start_t)) ? ($ret_or_1) : (""))) + (($truthy(end_t) ? ("," + (end_t)) : ("")))) : (""));
39147        return "<div" + (id_attribute) + (class_attribute) + ">\n" + (title_element) + "<div class=\"content\">\n" + "<audio src=\"" + (node.$media_uri(node.$attr("target"))) + (time_anchor) + "\"" + (($truthy(node['$option?']("autoplay")) ? (self.$append_boolean_attribute("autoplay", xml)) : (""))) + (($truthy(node['$option?']("nocontrols")) ? ("") : (self.$append_boolean_attribute("controls", xml)))) + (($truthy(node['$option?']("loop")) ? (self.$append_boolean_attribute("loop", xml)) : (""))) + ">\n" + "Your browser does not support the audio tag.\n" + "</audio>\n" + "</div>\n" + "</div>";
39148      });
39149      
39150      $def(self, '$convert_colist', function $$convert_colist(node) {
39151        var $a, self = this, result = nil, id_attribute = nil, classes = nil, class_attribute = nil, font_icons = nil, num = nil;
39152
39153        
39154        result = [];
39155        id_attribute = ($truthy(node.$id()) ? (" id=\"" + (node.$id()) + "\"") : (""));
39156        classes = ["colist", node.$style(), node.$role()].$compact();
39157        class_attribute = " class=\"" + (classes.$join(" ")) + "\"";
39158        result['$<<']("<div" + (id_attribute) + (class_attribute) + ">");
39159        if ($truthy(node['$title?']())) {
39160          result['$<<']("<div class=\"title\">" + (node.$title()) + "</div>")
39161        };
39162        if ($truthy(node.$document()['$attr?']("icons"))) {
39163          
39164          result['$<<']("<table>");
39165          $a = [node.$document()['$attr?']("icons", "font"), 0], (font_icons = $a[0]), (num = $a[1]), $a;
39166          $send(node.$items(), 'each', [], function $$5(item){var self = $$5.$$s == null ? this : $$5.$$s, num_label = nil;
39167            if (self.void_element_slash == null) self.void_element_slash = nil;
39168
39169            
39170            if (item == null) item = nil;
39171            num = $rb_plus(num, 1);
39172            if ($truthy(font_icons)) {
39173              num_label = "<i class=\"conum\" data-value=\"" + (num) + "\"></i><b>" + (num) + "</b>"
39174            } else {
39175              num_label = "<img src=\"" + (node.$icon_uri("callouts/" + (num))) + "\" alt=\"" + (num) + "\"" + (self.void_element_slash) + ">"
39176            };
39177            return result['$<<']("<tr>\n" + "<td>" + (num_label) + "</td>\n" + "<td>" + (item.$text()) + (($truthy(item['$blocks?']()) ? ($rb_plus($$('LF'), item.$content())) : (""))) + "</td>\n" + "</tr>");}, {$$s: self});
39178          result['$<<']("</table>");
39179        } else {
39180          
39181          result['$<<']("<ol>");
39182          $send(node.$items(), 'each', [], function $$6(item){
39183            
39184            if (item == null) item = nil;
39185            return result['$<<']("<li>\n" + "<p>" + (item.$text()) + "</p>" + (($truthy(item['$blocks?']()) ? ($rb_plus($$('LF'), item.$content())) : (""))) + "\n" + "</li>");});
39186          result['$<<']("</ol>");
39187        };
39188        result['$<<']("</div>");
39189        return result.$join($$('LF'));
39190      });
39191      
39192      $def(self, '$convert_dlist', function $$convert_dlist(node) {
39193        var self = this, result = nil, id_attribute = nil, classes = nil, class_attribute = nil, slash = nil, col_style_attribute = nil, dt_style_attribute = nil;
39194
39195        
39196        result = [];
39197        id_attribute = ($truthy(node.$id()) ? (" id=\"" + (node.$id()) + "\"") : (""));
39198        
39199        switch (node.$style()) {
39200          case "qanda":
39201            classes = ["qlist", "qanda", node.$role()]
39202            break;
39203          case "horizontal":
39204            classes = ["hdlist", node.$role()]
39205            break;
39206          default:
39207            classes = ["dlist", node.$style(), node.$role()]
39208        };
39209        class_attribute = " class=\"" + (classes.$compact().$join(" ")) + "\"";
39210        result['$<<']("<div" + (id_attribute) + (class_attribute) + ">");
39211        if ($truthy(node['$title?']())) {
39212          result['$<<']("<div class=\"title\">" + (node.$title()) + "</div>")
39213        };
39214        
39215        switch (node.$style()) {
39216          case "qanda":
39217            
39218            result['$<<']("<ol>");
39219            $send(node.$items(), 'each', [], function $$7(terms, dd){
39220              
39221              if (terms == null) terms = nil;
39222              if (dd == null) dd = nil;
39223              result['$<<']("<li>");
39224              $send(terms, 'each', [], function $$8(dt){
39225                
39226                if (dt == null) dt = nil;
39227                return result['$<<']("<p><em>" + (dt.$text()) + "</em></p>");});
39228              if ($truthy(dd)) {
39229                
39230                if ($truthy(dd['$text?']())) {
39231                  result['$<<']("<p>" + (dd.$text()) + "</p>")
39232                };
39233                if ($truthy(dd['$blocks?']())) {
39234                  result['$<<'](dd.$content())
39235                };
39236              };
39237              return result['$<<']("</li>");});
39238            result['$<<']("</ol>");
39239            break;
39240          case "horizontal":
39241            
39242            slash = self.void_element_slash;
39243            result['$<<']("<table>");
39244            if (($truthy(node['$attr?']("labelwidth")) || ($truthy(node['$attr?']("itemwidth"))))) {
39245              
39246              result['$<<']("<colgroup>");
39247              col_style_attribute = ($truthy(node['$attr?']("labelwidth")) ? (" style=\"width: " + (node.$attr("labelwidth").$chomp("%")) + "%;\"") : (""));
39248              result['$<<']("<col" + (col_style_attribute) + (slash) + ">");
39249              col_style_attribute = ($truthy(node['$attr?']("itemwidth")) ? (" style=\"width: " + (node.$attr("itemwidth").$chomp("%")) + "%;\"") : (""));
39250              result['$<<']("<col" + (col_style_attribute) + (slash) + ">");
39251              result['$<<']("</colgroup>");
39252            };
39253            $send(node.$items(), 'each', [], function $$9(terms, dd){var first_term = nil;
39254
39255              
39256              if (terms == null) terms = nil;
39257              if (dd == null) dd = nil;
39258              result['$<<']("<tr>");
39259              result['$<<']("<td class=\"hdlist1" + (($truthy(node['$option?']("strong")) ? (" strong") : (""))) + "\">");
39260              first_term = true;
39261              $send(terms, 'each', [], function $$10(dt){
39262                
39263                if (dt == null) dt = nil;
39264                if (!$truthy(first_term)) {
39265                  result['$<<']("<br" + (slash) + ">")
39266                };
39267                result['$<<'](dt.$text());
39268                return (first_term = nil);});
39269              result['$<<']("</td>");
39270              result['$<<']("<td class=\"hdlist2\">");
39271              if ($truthy(dd)) {
39272                
39273                if ($truthy(dd['$text?']())) {
39274                  result['$<<']("<p>" + (dd.$text()) + "</p>")
39275                };
39276                if ($truthy(dd['$blocks?']())) {
39277                  result['$<<'](dd.$content())
39278                };
39279              };
39280              result['$<<']("</td>");
39281              return result['$<<']("</tr>");});
39282            result['$<<']("</table>");
39283            break;
39284          default:
39285            
39286            result['$<<']("<dl>");
39287            dt_style_attribute = ($truthy(node.$style()) ? ("") : (" class=\"hdlist1\""));
39288            $send(node.$items(), 'each', [], function $$11(terms, dd){
39289              
39290              if (terms == null) terms = nil;
39291              if (dd == null) dd = nil;
39292              $send(terms, 'each', [], function $$12(dt){
39293                
39294                if (dt == null) dt = nil;
39295                return result['$<<']("<dt" + (dt_style_attribute) + ">" + (dt.$text()) + "</dt>");});
39296              if (!$truthy(dd)) {
39297                return nil
39298              };
39299              result['$<<']("<dd>");
39300              if ($truthy(dd['$text?']())) {
39301                result['$<<']("<p>" + (dd.$text()) + "</p>")
39302              };
39303              if ($truthy(dd['$blocks?']())) {
39304                result['$<<'](dd.$content())
39305              };
39306              return result['$<<']("</dd>");});
39307            result['$<<']("</dl>");
39308        };
39309        result['$<<']("</div>");
39310        return result.$join($$('LF'));
39311      });
39312      
39313      $def(self, '$convert_example', function $$convert_example(node) {
39314        var id_attribute = nil, class_attribute = nil, summary_element = nil, title_element = nil, role = nil;
39315
39316        
39317        id_attribute = ($truthy(node.$id()) ? (" id=\"" + (node.$id()) + "\"") : (""));
39318        if ($truthy(node['$option?']("collapsible"))) {
39319          
39320          class_attribute = ($truthy(node.$role()) ? (" class=\"" + (node.$role()) + "\"") : (""));
39321          summary_element = ($truthy(node['$title?']()) ? ("<summary class=\"title\">" + (node.$title()) + "</summary>") : ("<summary class=\"title\">
39321Details</summary>"));
39322          return "<details" + (id_attribute) + (class_attribute) + (($truthy(node['$option?']("open")) ? (" open") : (""))) + ">\n" + (summary_element) + "\n" + "<div class=\"content\">\n" + (node.$content()) + "\n" + "</div>\n" + "</details>";
39323        } else {
39324          
39325          title_element = ($truthy(node['$title?']()) ? ("<div class=\"title\">" + (node.$captioned_title()) + "</div>\n") : (""));
39326          return "<div" + (id_attribute) + " class=\"exampleblock" + (($truthy((role = node.$role())) ? (" " + (role)) : (""))) + "\">\n" + (title_element) + "<div class=\"content\">\n" + (node.$content()) + "\n" + "</div>\n" + "</div>";
39327        };
39328      });
39329      
39330      $def(self, '$convert_floating_title', function $$convert_floating_title(node) {
39331        var tag_name = nil, id_attribute = nil, classes = nil;
39332
39333        
39334        tag_name = "h" + ($rb_plus(node.$level(), 1));
39335        id_attribute = ($truthy(node.$id()) ? (" id=\"" + (node.$id()) + "\"") : (""));
39336        classes = [node.$style(), node.$role()].$compact();
39337        return "<" + (tag_name) + (id_attribute) + " class=\"" + (classes.$join(" ")) + "\">" + (node.$title()) + "</" + (tag_name) + ">";
39338      });
39339      
39340      $def(self, '$convert_image', function $$convert_image(node) {
39341        var self = this, target = nil, width_attr = nil, height_attr = nil, img = nil, $ret_or_1 = nil, fallback = nil, id_attr = nil, classes = nil, class_attr = nil, title_el = nil;
39342
39343        
39344        target = node.$attr("target");
39345        width_attr = ($truthy(node['$attr?']("width")) ? (" width=\"" + (node.$attr("width")) + "\"") : (""));
39346        height_attr = ($truthy(node['$attr?']("height")) ? (" height=\"" + (node.$attr("height")) + "\"") : (""));
39347        if ((($truthy(node['$attr?']("format", "svg")) || ($truthy(target['$include?'](".svg")))) && ($truthy($rb_lt(node.$document().$safe(), $$$($$('SafeMode'), 'SECURE')))))) {
39348          if ($truthy(node['$option?']("inline"))) {
39349            img = ($truthy(($ret_or_1 = self.$read_svg_contents(node, target))) ? ($ret_or_1) : ("<span class=\"alt\">" + (node.$alt()) + "</span>"))
39350          } else if ($truthy(node['$option?']("interactive"))) {
39351            
39352            fallback = ($truthy(node['$attr?']("fallback")) ? ("<img src=\"" + (node.$image_uri(node.$attr("fallback"))) + "\" alt=\"" + (self.$encode_attribute_value(node.$alt())) + "\"" + (width_attr) + (height_attr) + (self.void_element_slash) + ">") : ("<span class=\"alt\">" + (node.$alt()) + "</span>"));
39353            img = "<object type=\"image/svg+xml\" data=\"" + (node.$image_uri(target)) + "\"" + (width_attr) + (height_attr) + ">" + (fallback) + "</object>";
39354          } else {
39355            img = "<img src=\"" + (node.$image_uri(target)) + "\" alt=\"" + (self.$encode_attribute_value(node.$alt())) + "\"" + (width_attr) + (height_attr) + (self.void_element_slash) + ">"
39356          }
39357        } else {
39358          img = "<img src=\"" + (node.$image_uri(target)) + "\" alt=\"" + (self.$encode_attribute_value(node.$alt())) + "\"" + (width_attr) + (height_attr) + (self.void_element_slash) + ">"
39359        };
39360        if ($truthy(node['$attr?']("link"))) {
39361          img = "<a class=\"image\" href=\"" + (node.$attr("link")) + "\"" + (self.$append_link_constraint_attrs(node).$join()) + ">" + (img) + "</a>"
39362        };
39363        id_attr = ($truthy(node.$id()) ? (" id=\"" + (node.$id()) + "\"") : (""));
39364        classes = ["imageblock"];
39365        if ($truthy(node['$attr?']("float"))) {
39366          classes['$<<'](node.$attr("float"))
39367        };
39368        if ($truthy(node['$attr?']("align"))) {
39369          classes['$<<']("text-" + (node.$attr("align")))
39370        };
39371        if ($truthy(node.$role())) {
39372          classes['$<<'](node.$role())
39373        };
39374        class_attr = " class=\"" + (classes.$join(" ")) + "\"";
39375        title_el = ($truthy(node['$title?']()) ? ("\n<div class=\"title\">" + (node.$captioned_title()) + "</div>") : (""));
39376        return "<div" + (id_attr) + (class_attr) + ">\n" + "<div class=\"content\">\n" + (img) + "\n" + "</div>" + (title_el) + "\n" + "</div>";
39377      });
39378      
39379      $def(self, '$convert_listing', function $$convert_listing(node) {
39380        var nowrap = nil, $ret_or_1 = nil, lang = nil, syntax_hl = nil, opts = nil, doc_attrs = nil, pre_open = nil, pre_close = nil, id_attribute = nil, title_element = nil, role = nil;
39381
39382        
39383        nowrap = ($truthy(($ret_or_1 = node['$option?']("nowrap"))) ? ($ret_or_1) : (node.$document()['$attr?']("prewrap")['$!']()));
39384        if ($eqeq(node.$style(), "source")) {
39385          
39386          lang = node.$attr("language");
39387          if ($truthy((syntax_hl = node.$document().$syntax_highlighter()))) {
39388            
39389            opts = ($truthy(syntax_hl['$highlight?']()) ? ($hash2(["css_mode", "style"], {"css_mode": ($truthy(($ret_or_1 = (doc_attrs = node.$document().$attributes())['$[]']("" + (syntax_hl.$name()) + "-css"))) ? ($ret_or_1) : ("class")).$to_sym(), "style": doc_attrs['$[]']("" + (syntax_hl.$name()) + "-style")})) : ($hash2([], {})));
39390            opts['$[]=']("nowrap", nowrap);
39391          } else {
39392            
39393            pre_open = "<pre class=\"highlight" + (($truthy(nowrap) ? (" nowrap") : (""))) + "\"><code" + (($truthy(lang) ? (" class=\"language-" + (lang) + "\" data-lang=\"" + (lang) + "\"") : (""))) + ">";
39394            pre_close = "</code></pre>";
39395          };
39396        } else {
39397          
39398          pre_open = "<pre" + (($truthy(nowrap) ? (" class=\"nowrap\"") : (""))) + ">";
39399          pre_close = "</pre>";
39400        };
39401        id_attribute = ($truthy(node.$id()) ? (" id=\"" + (node.$id()) + "\"") : (""));
39402        title_element = ($truthy(node['$title?']()) ? ("<div class=\"title\">" + (node.$captioned_title()) + "</div>\n") : (""));
39403        return "<div" + (id_attribute) + " class=\"listingblock" + (($truthy((role = node.$role())) ? (" " + (role)) : (""))) + "\">\n" + (title_element) + "<div class=\"content\">\n" + (($truthy(syntax_hl) ? (syntax_hl.$format(node, lang, opts)) : ($rb_plus($rb_plus(pre_open, node.$content()), pre_close)))) + "\n" + "</div>\n" + "</div>";
39404      });
39405      
39406      $def(self, '$convert_literal', function $$convert_literal(node) {
39407        var id_attribute = nil, title_element = nil, nowrap = nil, $ret_or_1 = nil, role = nil;
39408
39409        
39410        id_attribute = ($truthy(node.$id()) ? (" id=\"" + (node.$id()) + "\"") : (""));
39411        title_element = ($truthy(node['$title?']()) ? ("<div class=\"title\">" + (node.$title()) + "</div>\n") : (""));
39412        nowrap = ($truthy(($ret_or_1 = node.$document()['$attr?']("prewrap")['$!']())) ? ($ret_or_1) : (node['$option?']("nowrap")));
39413        return "<div" + (id_attribute) + " class=\"literalblock" + (($truthy((role = node.$role())) ? (" " + (role)) : (""))) + "\">\n" + (title_element) + "<div class=\"content\">\n" + "<pre" + (($truthy(nowrap) ? (" class=\"nowrap\"") : (""))) + ">" + (node.$content()) + "</pre>\n" + "</div>\n" + "</div>";
39414      });
39415      
39416      $def(self, '$convert_stem', function $$convert_stem(node) {
39417        var $a, $b, self = this, id_attribute = nil, title_element = nil, style = nil, open = nil, close = nil, equation = nil, br = nil, role = nil;
39418
39419        
39420        id_attribute = ($truthy(node.$id()) ? (" id=\"" + (node.$id()) + "\"") : (""));
39421        title_element = ($truthy(node['$title?']()) ? ("<div class=\"title\">" + (node.$title()) + "</div>\n") : (""));
39422        $b = $$('BLOCK_MATH_DELIMITERS')['$[]']((style = node.$style().$to_sym())), $a = $to_ary($b), (open = ($a[0] == null ? nil : $a[0])), (close = ($a[1] == null ? nil : $a[1])), $b;
39423        if ($truthy((equation = node.$content()))) {
39424          
39425          if (($eqeq(style, "asciimath") && ($truthy(equation['$include?']($$('LF')))))) {
39426            
39427            br = "" + ($$('LF')) + "<br" + (self.void_element_slash) + ">";
39428            equation = $send(equation, 'gsub', [$$('StemBreakRx')], function $$13(){var $c;
39429
39430              return "" + (close) + ($rb_times(br, $rb_minus((($c = $gvars['~']) === nil ? nil : $c['$[]'](0)).$count($$('LF')), 1))) + ($$('LF')) + (open)});
39431          };
39432          if (!($truthy(equation['$start_with?'](open)) && ($truthy(equation['$end_with?'](close))))) {
39433            equation = "" + (open) + (equation) + (close)
39434          };
39435        } else {
39436          equation = ""
39437        };
39438        return "<div" + (id_attribute) + " class=\"stemblock" + (($truthy((role = node.$role())) ? (" " + (role)) : (""))) + "\">\n" + (title_element) + "<div class=\"content\">\n" + (equation) + "\n" + "</div>\n" + "</div>";
39439      });
39440      
39441      $def(self, '$convert_olist', function $$convert_olist(node) {
39442        var self = this, result = nil, id_attribute = nil, classes = nil, class_attribute = nil, type_attribute = nil, keyword = nil, start_attribute = nil, reversed_attribute = nil;
39443
39444        
39445        result = [];
39446        id_attribute = ($truthy(node.$id()) ? (" id=\"" + (node.$id()) + "\"") : (""));
39447        classes = ["olist", node.$style(), node.$role()].$compact();
39448        class_attribute = " class=\"" + (classes.$join(" ")) + "\"";
39449        result['$<<']("<div" + (id_attribute) + (class_attribute) + ">");
39450        if ($truthy(node['$title?']())) {
39451          result['$<<']("<div class=\"title\">" + (node.$title()) + "</div>")
39452        };
39453        type_attribute = ($truthy((keyword = node.$list_marker_keyword())) ? (" type=\"" + (keyword) + "\"") : (""));
39454        start_attribute = ($truthy(node['$attr?']("start")) ? (" start=\"" + (node.$attr("start")) + "\"") : (""));
39455        reversed_attribute = ($truthy(node['$option?']("reversed")) ? (self.$append_boolean_attribute("reversed", self.xml_mode)) : (""));
39456        result['$<<']("<ol class=\"" + (node.$style()) + "\"" + (type_attribute) + (start_attribute) + (reversed_attribute) + ">");
39457        $send(node.$items(), 'each', [], function $$14(item){
39458          
39459          if (item == null) item = nil;
39460          if ($truthy(item.$id())) {
39461            result['$<<']("<li id=\"" + (item.$id()) + "\"" + (($truthy(item.$role()) ? (" class=\"" + (item.$role()) + "\"") : (""))) + ">")
39462          } else if ($truthy(item.$role())) {
39463            result['$<<']("<li class=\"" + (item.$role()) + "\">")
39464          } else {
39465            result['$<<']("<li>")
39466          };
39467          result['$<<']("<p>" + (item.$text()) + "</p>");
39468          if ($truthy(item['$blocks?']())) {
39469            result['$<<'](item.$content())
39470          };
39471          return result['$<<']("</li>");});
39472        result['$<<']("</ol>");
39473        result['$<<']("</div>");
39474        return result.$join($$('LF'));
39475      });
39476      
39477      $def(self, '$convert_open', function $$convert_open(node) {
39478        var self = this, style = nil, id_attr = nil, title_el = nil, role = nil;
39479
39480        if ($eqeq((style = node.$style()), "abstract")) {
39481          if (($eqeq(node.$parent(), node.$document()) && ($eqeq(node.$document().$doctype(), "book")))) {
39482            
39483            self.$logger().$warn("abstract block cannot be used in a document without a title when doctype is book. Excluding block content.");
39484            return "";
39485          } else {
39486            
39487            id_attr = ($truthy(node.$id()) ? (" id=\"" + (node.$id()) + "\"") : (""));
39488            title_el = ($truthy(node['$title?']()) ? ("<div class=\"title\">" + (node.$title()) + "</div>\n") : (""));
39489            return "<div" + (id_attr) + " class=\"quoteblock abstract" + (($truthy((role = node.$role())) ? (" " + (role)) : (""))) + "\">\n" + (title_el) + "<blockquote>\n" + (node.$content()) + "\n" + "</blockquote>\n" + "</div>";
39490          }
39491        } else if (($eqeq(style, "partintro") && ((($truthy($rb_gt(node.$level(), 0)) || ($neqeq(node.$parent().$context(), "section"))) || ($neqeq(node.$document().$doctype(), "book")))))) {
39492          
39493          self.$logger().$error("partintro block can only be used when doctype is book and must be a child of a book part. Excluding block content.");
39494          return "";
39495        } else {
39496          
39497          id_attr = ($truthy(node.$id()) ? (" id=\"" + (node.$id()) + "\"") : (""));
39498          title_el = ($truthy(node['$title?']()) ? ("<div class=\"title\">" + (node.$title()) + "</div>\n") : (""));
39499          return "<div" + (id_attr) + " class=\"openblock" + ((($truthy(style) && ($neqeq(style, "open"))) ? (" " + (style)) : (""))) + (($truthy((role = node.$role())) ? (" " + (role)) : (""))) + "\">\n" + (title_el) + "<div class=\"content\">\n" + (node.$content()) + "\n" + "</div>\n" + "</div>";
39500        }
39501      });
39502      
39503      $def(self, '$convert_page_break', $return_val("<div style=\"page-break-after: always;\"></div>"));
39504      
39505      $def(self, '$convert_paragraph', function $$convert_paragraph(node) {
39506        var attributes = nil;
39507
39508        
39509        if ($truthy(node.$role())) {
39510          attributes = "" + (($truthy(node.$id()) ? (" id=\"" + (node.$id()) + "\"") : (""))) + " class=\"paragraph " + (node.$role()) + "\""
39511        } else if ($truthy(node.$id())) {
39512          attributes = " id=\"" + (node.$id()) + "\" class=\"paragraph\""
39513        } else {
39514          attributes = " class=\"paragraph\""
39515        };
39516        if ($truthy(node['$title?']())) {
39517          return "<div" + (attributes) + ">\n" + "<div class=\"title\">" + (node.$title()) + "</div>\n" + "<p>" + (node.$content()) + "</p>\n" + "</div>"
39518        } else {
39519          return "<div" + (attributes) + ">\n" + "<p>" + (node.$content()) + "</p>\n" + "</div>"
39520        };
39521      });
39522      $alias(self, "convert_pass", "content_only");
39523      
39524      $def(self, '$convert_preamble', function $$convert_preamble(node) {
39525        var doc = nil, toc = nil;
39526
39527        
39528        if ((($truthy((doc = node.$document())['$attr?']("toc-placement", "preamble")) && ($truthy(doc['$sections?']()))) && ($truthy(doc['$attr?']("toc"))))) {
39529          toc = "\n" + "<div id=\"toc\" class=\"" + (doc.$attr("toc-class", "toc")) + "\">\n" + "<div id=\"toctitle\">" + (doc.$attr("toc-title")) + "</div>\n" + (doc.$converter().$convert(doc, "outline")) + "\n" + "</div>"
39530        } else {
39531          toc = ""
39532        };
39533        return "<div id=\"preamble\">\n" + "<div class=\"sectionbody\">\n" + (node.$content()) + "\n" + "</div>" + (toc) + "\n" + "</div>";
39534      });
39535      
39536      $def(self, '$convert_quote', function $$convert_quote(node) {
39537        var self = this, id_attribute = nil, classes = nil, class_attribute = nil, title_element = nil, attribution = nil, citetitle = nil, cite_element = nil, attribution_text = nil, attribution_element = nil;
39538
39539        
39540        id_attribute = ($truthy(node.$id()) ? (" id=\"" + (node.$id()) + "\"") : (""));
39541        classes = ["quoteblock", node.$role()].$compact();
39542        class_attribute = " class=\"" + (classes.$join(" ")) + "\"";
39543        title_element = ($truthy(node['$title?']()) ? ("\n<div class=\"title\">" + (node.$title()) + "</div>") : (""));
39544        attribution = ($truthy(node['$attr?']("attribution")) ? (node.$attr("attribution")) : (nil));
39545        citetitle = ($truthy(node['$attr?']("citetitle")) ? (node.$attr("citetitle")) : (nil));
39546        if (($truthy(attribution) || ($truthy(citetitle)))) {
39547          
39548          cite_element = ($truthy(citetitle) ? ("<cite>" + (citetitle) + "</cite>") : (""));
39549          attribution_text = ($truthy(attribution) ? ("&#8212; " + (attribution) + (($truthy(citetitle) ? ("<br" + (self.void_element_slash) + ">
39549\n") : ("")))) : (""));
39550          attribution_element = "\n<div class=\"attribution\">\n" + (attribution_text) + (cite_element) + "\n</div>";
39551        } else {
39552          attribution_element = ""
39553        };
39554        return "<div" + (id_attribute) + (class_attribute) + ">" + (title_element) + "\n" + "<blockquote>\n" + (node.$content()) + "\n" + "</blockquote>" + (attribution_element) + "\n" + "</div>";
39555      });
39556      
39557      $def(self, '$convert_thematic_break', function $$convert_thematic_break(node) {
39558        var self = this;
39559
39560        return "<hr" + (self.void_element_slash) + ">"
39561      });
39562      
39563      $def(self, '$convert_sidebar', function $$convert_sidebar(node) {
39564        var id_attribute = nil, title_element = nil, role = nil;
39565
39566        
39567        id_attribute = ($truthy(node.$id()) ? (" id=\"" + (node.$id()) + "\"") : (""));
39568        title_element = ($truthy(node['$title?']()) ? ("<div class=\"title\">" + (node.$title()) + "</div>\n") : (""));
39569        return "<div" + (id_attribute) + " class=\"sidebarblock" + (($truthy((role = node.$role())) ? (" " + (role)) : (""))) + "\">\n" + "<div class=\"content\">\n" + (title_element) + (node.$content()) + "\n" + "</div>\n" + "</div>";
39570      });
39571      
39572      $def(self, '$convert_table', function $$convert_table(node) {
39573        var self = this, result = nil, id_attribute = nil, frame = nil, classes = nil, stripes = nil, style_attribute = nil, autowidth = nil, tablewidth = nil, role = nil, class_attribute = nil, slash = nil;
39574
39575        
39576        result = [];
39577        id_attribute = ($truthy(node.$id()) ? (" id=\"" + (node.$id()) + "\"") : (""));
39578        if ($eqeq((frame = node.$attr("frame", "all", "table-frame")), "topbot")) {
39579          frame = "ends"
39580        };
39581        classes = ["tableblock", "frame-" + (frame), "grid-" + (node.$attr("grid", "all", "table-grid"))];
39582        if ($truthy((stripes = node.$attr("stripes", nil, "table-stripes")))) {
39583          classes['$<<']("stripes-" + (stripes))
39584        };
39585        style_attribute = "";
39586        if (($truthy((autowidth = node['$option?']("autowidth"))) && ($not(node['$attr?']("width"))))) {
39587          classes['$<<']("fit-content")
39588        } else if ($eqeq((tablewidth = node.$attr("tablepcwidth")), 100)) {
39589          classes['$<<']("stretch")
39590        } else {
39591          style_attribute = " style=\"width: " + (tablewidth) + "%;\""
39592        };
39593        if ($truthy(node['$attr?']("float"))) {
39594          classes['$<<'](node.$attr("float"))
39595        };
39596        if ($truthy((role = node.$role()))) {
39597          classes['$<<'](role)
39598        };
39599        class_attribute = " class=\"" + (classes.$join(" ")) + "\"";
39600        result['$<<']("<table" + (id_attribute) + (class_attribute) + (style_attribute) + ">");
39601        if ($truthy(node['$title?']())) {
39602          result['$<<']("<caption class=\"title\">" + (node.$captioned_title()) + "</caption>")
39603        };
39604        if ($truthy($rb_gt(node.$attr("rowcount"), 0))) {
39605          
39606          slash = self.void_element_slash;
39607          result['$<<']("<colgroup>");
39608          if ($truthy(autowidth)) {
39609            result = $rb_plus(result, $$('Array').$new(node.$columns().$size(), "<col" + (slash) + ">"))
39610          } else {
39611            $send(node.$columns(), 'each', [], function $$15(col){
39612              
39613              if (col == null) col = nil;
39614              return result['$<<'](($truthy(col['$option?']("autowidth")) ? ("<col" + (slash) + ">") : ("<col style=\"width: " + (col.$attr("colpcwidth")) + "%;\"" + (slash) + ">")));})
39615          };
39616          result['$<<']("</colgroup>");
39617          $send(node.$rows().$to_h(), 'each', [], function $$16(tsec, rows){
39618            
39619            if (tsec == null) tsec = nil;
39620            if (rows == null) rows = nil;
39621            if ($truthy(rows['$empty?']())) {
39622              return nil
39623            };
39624            result['$<<']("<t" + (tsec) + ">");
39625            $send(rows, 'each', [], function $$17(row){
39626              
39627              if (row == null) row = nil;
39628              result['$<<']("<tr>");
39629              $send(row, 'each', [], function $$18(cell){var cell_content = nil, cell_tag_name = nil, cell_class_attribute = nil, cell_colspan_attribute = nil, cell_rowspan_attribute = nil, cell_style_attribute = nil;
39630
39631                
39632                if (cell == null) cell = nil;
39633                if ($eqeq(tsec, "head")) {
39634                  cell_content = cell.$text()
39635                } else 
39636                switch (cell.$style()) {
39637                  case "asciidoc":
39638                    cell_content = "<div class=\"content\">" + (cell.$content()) + "</div>"
39639                    break;
39640                  case "literal":
39641                    cell_content = "<div class=\"literal\"><pre>" + (cell.$text()) + "</pre></div>"
39642                    break;
39643                  default:
39644                    cell_content = ($truthy((cell_content = cell.$content())['$empty?']()) ? ("") : ("<p class=\"tableblock\">" + (cell_content.$join("</p>\n" + "<p class=\"tableblock\">")) + "</p>"))
39645                };
39646                cell_tag_name = (($eqeq(tsec, "head") || ($eqeq(cell.$style(), "header"))) ? ("th") : ("td"));
39647                cell_class_attribute = " class=\"tableblock halign-" + (cell.$attr("halign")) + " valign-" + (cell.$attr("valign")) + "\"";
39648                cell_colspan_attribute = ($truthy(cell.$colspan()) ? (" c
39648olspan=\"" + (cell.$colspan()) + "\"") : (""));
39649                cell_rowspan_attribute = ($truthy(cell.$rowspan()) ? (" rowspan=\"" + (cell.$rowspan()) + "\"") : (""));
39650                cell_style_attribute = ($truthy(node.$document()['$attr?']("cellbgcolor")) ? (" style=\"background-color: " + (node.$document().$attr("cellbgcolor")) + ";\"") : (""));
39651                return result['$<<']("<" + (cell_tag_name) + (cell_class_attribute) + (cell_colspan_attribute) + (cell_rowspan_attribute) + (cell_style_attribute) + ">" + (cell_content) + "</" + (cell_tag_name) + ">");});
39652              return result['$<<']("</tr>");});
39653            return result['$<<']("</t" + (tsec) + ">");});
39654        };
39655        result['$<<']("</table>");
39656        return result.$join($$('LF'));
39657      });
39658      
39659      $def(self, '$convert_toc', function $$convert_toc(node) {
39660        var doc = nil, id_attr = nil, title_id_attr = nil, title = nil, levels = nil, role = nil;
39661
39662        
39663        if (!(($truthy((doc = node.$document())['$attr?']("toc-placement", "macro")) && ($truthy(doc['$sections?']()))) && ($truthy(doc['$attr?']("toc"))))) {
39664          return "<!-- toc disabled -->"
39665        };
39666        if ($truthy(node.$id())) {
39667          
39668          id_attr = " id=\"" + (node.$id()) + "\"";
39669          title_id_attr = " id=\"" + (node.$id()) + "title\"";
39670        } else {
39671          
39672          id_attr = " id=\"toc\"";
39673          title_id_attr = " id=\"toctitle\"";
39674        };
39675        title = ($truthy(node['$title?']()) ? (node.$title()) : (doc.$attr("toc-title")));
39676        levels = ($truthy(node['$attr?']("levels")) ? (node.$attr("levels").$to_i()) : (nil));
39677        role = ($truthy(node['$role?']()) ? (node.$role()) : (doc.$attr("toc-class", "toc")));
39678        return "<div" + (id_attr) + " class=\"" + (role) + "\">\n" + "<div" + (title_id_attr) + " class=\"title\">" + (title) + "</div>\n" + (doc.$converter().$convert(doc, "outline", $hash2(["toclevels"], {"toclevels": levels}))) + "\n" + "</div>";
39679      });
39680      
39681      $def(self, '$convert_ulist', function $$convert_ulist(node) {
39682        var self = this, result = nil, id_attribute = nil, div_classes = nil, marker_checked = nil, marker_unchecked = nil, checklist = nil, ul_class_attribute = nil;
39683
39684        
39685        result = [];
39686        id_attribute = ($truthy(node.$id()) ? (" id=\"" + (node.$id()) + "\"") : (""));
39687        div_classes = ["ulist", node.$style(), node.$role()].$compact();
39688        marker_checked = (marker_unchecked = "");
39689        if ($truthy((checklist = node['$option?']("checklist")))) {
39690          
39691          div_classes.$unshift(div_classes.$shift(), "checklist");
39692          ul_class_attribute = " class=\"checklist\"";
39693          if ($truthy(node['$option?']("interactive"))) {
39694            if ($truthy(self.xml_mode)) {
39695              
39696              marker_checked = "<input type=\"checkbox\" data-item-complete=\"1\" checked=\"checked\"/> ";
39697              marker_unchecked = "<input type=\"checkbox\" data-item-complete=\"0\"/> ";
39698            } else {
39699              
39700              marker_checked = "<input type=\"checkbox\" data-item-complete=\"1\" checked> ";
39701              marker_unchecked = "<input type=\"checkbox\" data-item-complete=\"0\"> ";
39702            }
39703          } else if ($truthy(node.$document()['$attr?']("icons", "font"))) {
39704            
39705            marker_checked = "<i class=\"fa fa-check-square-o\"></i> ";
39706            marker_unchecked = "<i class=\"fa fa-square-o\"></i> ";
39707          } else {
39708            
39709            marker_checked = "&#10003; ";
39710            marker_unchecked = "&#10063; ";
39711          };
39712        } else {
39713          ul_class_attribute = ($truthy(node.$style()) ? (" class=\"" + (node.$style()) + "\"") : (""))
39714        };
39715        result['$<<']("<div" + (id_attribute) + " class=\"" + (div_classes.$join(" ")) + "\">");
39716        if ($truthy(node['$title?']())) {
39717          result['$<<']("<div class=\"title\">" + (node.$title()) + "</div>")
39718        };
39719        result['$<<']("<ul" + (ul_class_attribute) + ">");
39720        $send(node.$items(), 'each', [], function $$19(item){
39721          
39722          if (item == null) item = nil;
39723          if ($truthy(item.$id())) {
39724            result['$<<']("<li id=\"" + (item.$id()) + "\"" + (($truthy(item.$role()) ? (" class=\"" + (item.$role()) + "\"") : (""))) + ">")
39725          } else if ($truthy(item.$role())) {
39726            result['$<<']("<li class=\"" + (item.$role()) + "\">")
39727          } else {
39728            result['$<<']("<li>")
39729          };
39730          if (($truthy(checklist) && ($truthy(item['$attr?']("checkbox"))))) {
39731            result['$<<']("<p>" + (($truthy(item['$attr?']("checked")) ? (marker_checked) : (marker_unchecked))) + (item.$text()) + "</p>")
39732          } else {
39733            result['$<<']("<p>" + (item.$text()) + "</p>")
39734          };
39735          if ($truthy(item['$blocks?']())) {
39736            result['$<<'](item.$content())
39737          };
39738          return result['$<<']("</li>");});
39739        result['$<<']("</ul>");
39740        result['$<<']("</div>");
39741        return result.$join($$('LF'));
39742      });
39743      
39744      $def(self, '$convert_verse', function $$convert_verse(node) {
39745        var self = this, id_attribute = nil, classes = nil, class_attribute = nil, title_element = nil, attribution = nil, citetitle = nil, cite_element = nil, attribution_text = nil, attribution_element = nil;
39746
39747        
39748        id_attribute = ($truthy(node.$id()) ? (" id=\"" + (node.$id()) + "\"") : (""));
39749        classes = ["verseblock", node.$role()].$compact();
39750        class_attribute = " class=\"" + (classes.$join(" ")) + "\"";
39751        title_element = ($truthy(node['$title?']()) ? ("\n<div class=\"title\">" + (node.$title()) + "</div>") : (""));
39752        attribution = ($truthy(node['$attr?']("attribution")) ? (node.$attr("attribution")) : (nil));
39753        citetitle = ($truthy(node['$attr?']("citetitle")) ? (node.$attr("citetitle")) : (nil));
39754        if (($truthy(attribution) || ($truthy(citetitle)))) {
39755          
39756          cite_element = ($truthy(citetitle) ? ("<cite>" + (citetitle) + "</cite>") : (""));
39757          attribution_text = ($truthy(attribution) ? ("&#8212; " + (attribution) + (($truthy(citetitle) ? ("<br" + (self.void_element_slash) + ">
39757\n") : ("")))) : (""));
39758          attribution_element = "\n<div class=\"attribution\">\n" + (attribution_text) + (cite_element) + "\n</div>";
39759        } else {
39760          attribution_element = ""
39761        };
39762        return "<div" + (id_attribute) + (class_attribute) + ">" + (title_element) + "\n" + "<pre class=\"content\">" + (node.$content()) + "</pre>" + (attribution_element) + "\n" + "</div>";
39763      });
39764      
39765      $def(self, '$convert_video', function $$convert_video(node) {
39766        var $a, $b, self = this, xml = nil, id_attribute = nil, classes = nil, class_attribute = nil, title_element = nil, width_attribute = nil, height_attribute = nil, asset_uri_scheme = nil, start_anchor = nil, delimiter = nil, target = nil, hash = nil, hash_param = nil, $ret_or_2 = nil, autoplay_param = nil, loop_param = nil, muted_param = nil, rel_param_val = nil, start_param = nil, end_param = nil, has_loop_param = nil, mute_param = nil, controls_param = nil, fs_param = nil, fs_attribute = nil, modest_param = nil, theme_param = nil, hl_param = nil, list = nil, list_param = nil, playlist = nil, poster_attribute = nil, val = nil, preload_attribute = nil, start_t = nil, end_t = nil, time_anchor = nil;
39767
39768        
39769        xml = self.xml_mode;
39770        id_attribute = ($truthy(node.$id()) ? (" id=\"" + (node.$id()) + "\"") : (""));
39771        classes = ["videoblock"];
39772        if ($truthy(node['$attr?']("float"))) {
39773          classes['$<<'](node.$attr("float"))
39774        };
39775        if ($truthy(node['$attr?']("align"))) {
39776          classes['$<<']("text-" + (node.$attr("align")))
39777        };
39778        if ($truthy(node.$role())) {
39779          classes['$<<'](node.$role())
39780        };
39781        class_attribute = " class=\"" + (classes.$join(" ")) + "\"";
39782        title_element = ($truthy(node['$title?']()) ? ("\n<div class=\"title\">" + (node.$title()) + "</div>") : (""));
39783        width_attribute = ($truthy(node['$attr?']("width")) ? (" width=\"" + (node.$attr("width")) + "\"") : (""));
39784        height_attribute = ($truthy(node['$attr?']("height")) ? (" height=\"" + (node.$attr("height")) + "\"") : (""));
39785        
39786        switch (node.$attr("poster")) {
39787          case "vimeo":
39788            
39789            if (!$truthy((asset_uri_scheme = node.$document().$attr("asset-uri-scheme", "https"))['$empty?']())) {
39790              asset_uri_scheme = "" + (asset_uri_scheme) + ":"
39791            };
39792            start_anchor = ($truthy(node['$attr?']("start")) ? ("#at=" + (node.$attr("start"))) : (""));
39793            delimiter = ["?"];
39794            $b = node.$attr("target").$split("/", 2), $a = $to_ary($b), (target = ($a[0] == null ? nil : $a[0])), (hash = ($a[1] == null ? nil : $a[1])), $b;
39795            hash_param = ($truthy((hash = ($truthy(($ret_or_2 = hash)) ? ($ret_or_2) : (node.$attr("hash"))))) ? ("" + (($truthy(($ret_or_2 = delimiter.$pop())) ? ($ret_or_2) : ("&amp;"))) + "h=" + (hash)) : (""));
39796            autoplay_param = ($truthy(node['$option?']("autoplay")) ? ("" + (($truthy(($ret_or_2 = delimiter.$pop())) ? ($ret_or_2) : ("&amp;"))) + "autoplay=1") : (""));
39797            loop_param = ($truthy(node['$option?']("loop")) ? ("" + (($truthy(($ret_or_2 = delimiter.$pop())) ? ($ret_or_2) : ("&amp;"))) + "loop=1") : (""));
39798            muted_param = ($truthy(node['$option?']("muted")) ? ("" + (($truthy(($ret_or_2 = delimiter.$pop())) ? ($ret_or_2) : ("&amp;"))) + "muted=1") : (""));
39799            return "<div" + (id_attribute) + (class_attribute) + ">" + (title_element) + "\n" + "<div class=\"content\">\n" + "<iframe" + (width_attribute) + (height_attribute) + " src=\"" + (asset_uri_scheme) + "//player.vimeo.com/video/" + (target) + (hash_param) + (autoplay_param) + (loop_param) + (muted_param) + (start_anchor) + "\" frameborder=\"0\"" + (($truthy(node['$option?']("nofullscreen")) ? ("") : (self.$append_boolean_attribute("allowfullscreen", xml)))) + "></iframe>\n" + "</div>\n" + "</div>";
39800          case "youtube":
39801            
39802            if (!$truthy((asset_uri_scheme = node.$document().$attr("asset-uri-scheme", "https"))['$empty?']())) {
39803              asset_uri_scheme = "" + (asset_uri_scheme) + ":"
39804            };
39805            rel_param_val = ($truthy(node['$option?']("related")) ? (1) : (0));
39806            start_param = ($truthy(node['$attr?']("start")) ? ("&amp;start=" + (node.$attr("start"))) : (""));
39807            end_param = ($truthy(node['$attr?']("end")) ? ("&amp;end=" + (node.$attr("end"))) : (""));
39808            autoplay_param = ($truthy(node['$option?']("autoplay")) ? ("&amp;autoplay=1") : (""));
39809            loop_param = ($truthy((has_loop_param = node['$option?']("loop"))) ? ("&amp;loop=1") : (""));
39810            mute_param = ($truthy(node['$option?']("muted")) ? ("&amp;mute=1") : (""));
39811            controls_param = ($truthy(node['$option?']("nocontrol
39811s")) ? ("&amp;controls=0") : (""));
39812            if ($truthy(node['$option?']("nofullscreen"))) {
39813              
39814              fs_param = "&amp;fs=0";
39815              fs_attribute = "";
39816            } else {
39817              
39818              fs_param = "";
39819              fs_attribute = self.$append_boolean_attribute("allowfullscreen", xml);
39820            };
39821            modest_param = ($truthy(node['$option?']("modest")) ? ("&amp;modestbranding=1") : (""));
39822            theme_param = ($truthy(node['$attr?']("theme")) ? ("&amp;theme=" + (node.$attr("theme"))) : (""));
39823            hl_param = ($truthy(node['$attr?']("lang")) ? ("&amp;hl=" + (node.$attr("lang"))) : (""));
39824            $b = node.$attr("target").$split("/", 2), $a = $to_ary($b), (target = ($a[0] == null ? nil : $a[0])), (list = ($a[1] == null ? nil : $a[1])), $b;
39825            if ($truthy((list = ($truthy(($ret_or_2 = list)) ? ($ret_or_2) : (node.$attr("list")))))) {
39826              list_param = "&amp;list=" + (list)
39827            } else {
39828              
39829              $b = target.$split(",", 2), $a = $to_ary($b), (target = ($a[0] == null ? nil : $a[0])), (playlist = ($a[1] == null ? nil : $a[1])), $b;
39830              if ($truthy((playlist = ($truthy(($ret_or_2 = playlist)) ? ($ret_or_2) : (node.$attr("playlist")))))) {
39831                list_param = "&amp;playlist=" + (target) + "," + (playlist)
39832              } else {
39833                list_param = ($truthy(has_loop_param) ? ("&amp;playlist=" + (target)) : (""))
39834              };
39835            };
39836            return "<div" + (id_attribute) + (class_attribute) + ">" + (title_element) + "\n" + "<div class=\"content\">\n" + "<iframe" + (width_attribute) + (height_attribute) + " src=\"" + (asset_uri_scheme) + "//www.youtube.com/embed/" + (target) + "?rel=" + (rel_param_val) + (start_param) + (end_param) + (autoplay_param) + (loop_param) + (mute_param) + (controls_param) + (list_param) + (fs_param) + (modest_param) + (theme_param) + (hl_param) + "\" frameborder=\"0\"" + (fs_attribute) + "></iframe>\n" + "</div>\n" + "</div>";
39837          default:
39838            
39839            poster_attribute = ($truthy((val = node.$attr("poster"))['$nil_or_empty?']()) ? ("") : (" poster=\"" + (node.$media_uri(val)) + "\""));
39840            preload_attribute = ($truthy((val = node.$attr("preload"))['$nil_or_empty?']()) ? ("") : (" preload=\"" + (val) + "\""));
39841            start_t = node.$attr("start");
39842            end_t = node.$attr("end");
39843            time_anchor = (($truthy(start_t) || ($truthy(end_t))) ? ("#t=" + (($truthy(($ret_or_2 = start_t)) ? ($ret_or_2) : (""))) + (($truthy(end_t) ? ("," + (end_t)) : ("")))) : (""));
39844            return "<div" + (id_attribute) + (class_attribute) + ">" + (title_element) + "\n" + "<div class=\"content\">\n" + "<video src=\"" + (node.$media_uri(node.$attr("target"))) + (time_anchor) + "\"" + (width_attribute) + (height_attribute) + (poster_attribute) + (($truthy(node['$option?']("autoplay")) ? (self.$append_boolean_attribute("autoplay", xml)) : (""))) + (($truthy(node['$option?']("muted")) ? (self.$append_boolean_attribute("muted", xml)) : (""))) + (($truthy(node['$option?']("nocontrols")) ? ("") : (self.$append_boolean_attribute("controls", xml)))) + (($truthy(node['$option?']("loop")) ? (self.$append_boolean_attribute("loop", xml)) : (""))) + (preload_attribute) + ">\n" + "Your browser does not support the video tag.\n" + "</video>\n" + "</div>\n" + "</div>";
39845        };
39846      });
39847      
39848      $def(self, '$convert_inline_anchor', function $$convert_inline_anchor(node) {
39849        var self = this, path = nil, attrs = nil, text = nil, $ret_or_2 = nil, ref = nil, $ret_or_3 = nil, refid = nil, top = nil, outer = nil;
39850
39851        
39852        switch (node.$type()) {
39853          case "xref":
39854            
39855            if ($truthy((path = node.$attributes()['$[]']("path")))) {
39856              
39857              attrs = self.$append_link_constraint_attrs(node, ($truthy(node.$role()) ? ([" class=\"" + (node.$role()) + "\""]) : ([]))).$join();
39858              text = ($truthy(($ret_or_2 = node.$text())) ? ($ret_or_2) : (path));
39859            } else {
39860              
39861              attrs = ($truthy(node.$role()) ? (" class=\"" + (node.$role()) + "\"") : (""));
39862              if (!$truthy((text = node.$text()))) {
39863                if ($eqeqeq($$('AbstractNode'), (ref = ($truthy(($ret_or_2 = (self.refs = ($truthy(($ret_or_3 = self.refs)) ? ($ret_or_3) : (node.$document().$catalog()['$[]']("refs"))))['$[]']((refid = node.$attributes()['$[]']("refid"))))) ? ($ret_or_2) : (($truthy(refid['$nil_or_empty?']()) ? ((top = self.$get_root_document(node))) : (nil))))))) {
39864                  if (($truthy((self.resolving_xref = ($truthy(($ret_or_2 = self.resolving_xref)) ? ($ret_or_2) : ((outer = true))))) && ($truthy(outer)))) {
39865                    
39866                    if ($truthy((text = ref.$xreftext(node.$attr("xrefstyle", nil, true))))) {
39867                      if ($truthy(text['$include?']("<a"))) {
39868                        text = text.$gsub($$('DropAnchorRx'), "")
39869                      }
39870                    } else {
39871                      text = ($truthy(top) ? ("[^top]") : ("[" + (refid) + "]"))
39872                    };
39873                    self.resolving_xref = nil;
39874                  } else {
39875                    text = ($truthy(top) ? ("[^top]") : ("[" + (refid) + "]"))
39876                  }
39877                } else {
39878                  text = "[" + (refid) + "]"
39879                }
39880              };
39881            };
39882            return "<a href=\"" + (node.$target()) + "\"" + (attrs) + ">" + (text) + "</a>";
39883          case "ref":
39884            return "<a id=\"" + (node.$id()) + "\"></a>"
39885          case "link":
39886            
39887            attrs = ($truthy(node.$id()) ? ([" id=\"" + (node.$id()) + "\""]) : ([]));
39888            if ($truthy(node.$role())) {
39889              attrs['$<<'](" class=\"" + (node.$role()) + "\"")
39890            };
39891            if ($truthy(node['$attr?']("title"))) {
39892              attrs['$<<'](" title=\"" + (node.$attr("title")) + "\"")
39893            };
39894            return "<a href=\"" + (node.$target()) + "\"" + (self.$append_link_constraint_attrs(node, attrs).$join()) + ">" + (node.$text()) + "</a>";
39895          case "bibref":
39896            return "<a id=\"" + (node.$id()) + "\"></a>[" + (($truthy(($ret_or_2 = node.$reftext())) ? ($ret_or_2) : (node.$id()))) + "]"
39897          default:
39898            
39899            self.$logger().$warn("unknown anchor type: " + (node.$type().$inspect()));
39900            return nil;
39901        }
39902      });
39903      
39904      $def(self, '$convert_inline_break', function $$convert_inline_break(node) {
39905        var self = this;
39906
39907        return "" + (node.$text()) + "<br" + (self.void_element_slash) + ">"
39908      });
39909      
39910      $def(self, '$convert_inline_button', function $$convert_inline_button(node) {
39911        
39912        return "<b class=\"button\">" + (node.$text()) + "</b>"
39913      });
39914      
39915      $def(self, '$convert_inline_callout', function $$convert_inline_callout(node) {
39916        var self = this, src = nil, guard = nil;
39917
39918        if ($truthy(node.$document()['$attr?']("icons", "font"))) {
39919          return "<i class=\"conum\" data-value=\"" + (node.$text()) + "\"></i><b>(" + (node.$text()) + ")</b>"
39920        } else if ($truthy(node.$document()['$attr?']("icons"))) {
39921          
39922          src = node.$icon_uri("callouts/" + (node.$text()));
39923          return "<img src=\"" + (src) + "\" alt=\"" + (node.$text()) + "\"" + (self.void_element_slash) + ">";
39924        } else if ($eqeqeq($$$('Array'), (guard = node.$attributes()['$[]']("guard")))) {
39925          return "&lt;!--<b class=\"conum\">(" + (node.$text()) + ")</b>--&gt;"
39926        } else {
39927          return "" + (guard) + "<b class=\"conum\">(" + (node.$text()) + ")</b>"
39928        }
39929      });
39930      
39931      $def(self, '$convert_inline_footnote', function $$convert_inline_footnote(node) {
39932        var index = nil, id_attr = nil;
39933
39934        if ($truthy((index = node.$attr("index")))) {
39935          if ($eqeq(node.$type(), "xref")) {
39936            return "<sup class=\"footnoteref\">[<a class=\"footnote\" href=\"#_footnotedef_" + (index) + "\" title=\"View footnote.\">" + (index) + "</a>]</sup>"
39937          } else {
39938            
39939            id_attr = ($truthy(node.$id()) ? (" id=\"_footnote_" + (node.$id()) + "\"") : (""));
39940            return "<sup class=\"footnote\"" + (id_attr) + ">[<a id=\"_footnoteref_" + (index) + "\" class=\"footnote\" href=\"#_footnotedef_" + (index) + "\" title=\"View footnote.\">" + (index) + "</a>]</sup>";
39941          }
39942        } else if ($eqeq(node.$type(), "xref")) {
39943          return "<sup class=\"footnoteref red\" title=\"Unresolved footnote reference.\">[" + (node.$text()) + "]</sup>"
39944        } else {
39945          return nil
39946        }
39947      });
39948      
39949      $def(self, '$convert_inline_image', function $$convert_inline_image(node) {
39950        var self = this, target = nil, type = nil, $ret_or_1 = nil, icons = nil, i_class_attr_val = nil, attrs = nil, img = nil, fallback = nil, class_attr_val = nil, role = nil;
39951
39952        
39953        target = node.$target();
39954        if ($eqeq((type = ($truthy(($ret_or_1 = node.$type())) ? ($ret_or_1) : ("image"))), "icon")) {
39955          if ($eqeq((icons = node.$document().$attr("icons")), "font")) {
39956            
39957            i_class_attr_val = "fa fa-" + (target);
39958            if ($truthy(node['$attr?']("size"))) {
39959              i_class_attr_val = "" + (i_class_attr_val) + " fa-" + (node.$attr("size"))
39960            };
39961            if ($truthy(node['$attr?']("flip"))) {
39962              i_class_attr_val = "" + (i_class_attr_val) + " fa-flip-" + (node.$attr("flip"))
39963            } else if ($truthy(node['$attr?']("rotate"))) {
39964              i_class_attr_val = "" + (i_class_attr_val) + " fa-rotate-" + (node.$attr("rotate"))
39965            };
39966            attrs = ($truthy(node['$attr?']("title")) ? (" title=\"" + (node.$attr("title")) + "\"") : (""));
39967            img = "<i class=\"" + (i_class_attr_val) + "\"" + (attrs) + "></i>";
39968          } else if ($truthy(icons)) {
39969            
39970            attrs = ($truthy(node['$attr?']("width")) ? (" width=\"" + (node.$attr("width")) + "\"") : (""));
39971            if ($truthy(node['$attr?']("height"))) {
39972              attrs = "" + (attrs) + " height=\"" + (node.$attr("height")) + "\""
39973            };
39974            if ($truthy(node['$attr?']("title"))) {
39975              attrs = "" + (attrs) + " title=\"" + (node.$attr("title")) + "\""
39976            };
39977            img = "<img src=\"" + (node.$icon_uri(target)) + "\" alt=\"" + (self.$encode_attribute_value(node.$alt())) + "\"" + (attrs) + (self.void_element_slash) + ">";
39978          } else {
39979            img = "[" + (node.$alt()) + "&#93;"
39980          }
39981        } else {
39982          
39983          attrs = ($truthy(node['$attr?']("width")) ? (" width=\"" + (node.$attr("width")) + "\"") : (""));
39984          if ($truthy(node['$attr?']("height"))) {
39985            attrs = "" + (attrs) + " height=\"" + (node.$attr("height")) + "\""
39986          };
39987          if ($truthy(node['$attr?']("title"))) {
39988            attrs = "" + (attrs) + " title=\"" + (node.$attr("title")) + "\""
39989          };
39990          if ((($truthy(node['$attr?']("format", "svg")) || ($truthy(target['$include?'](".svg")))) && ($truthy($rb_lt(node.$document().$safe(), $$$($$('SafeMode'), 'SECURE')))))) {
39991            if ($truthy(node['$option?']("inline"))) {
39992              img = ($truthy(($ret_or_1 = self.$read_svg_contents(node, target))) ? ($ret_or_1) : ("<span class=\"alt\">" + (node.$alt()) + "</span>"))
39993            } else if ($truthy(node['$option?']("interactive"))) {
39994              
39995              fallback = ($truthy(node['$attr?']("fallback")) ? ("<img src=\"" + (node.$image_uri(node.$attr("fallback"))) + "\" alt=\"" + (self.$encode_attribute_value(node.$alt())) + "\"" + (attrs) + (self.void_element_slash) + ">") : ("<span class=\"alt\">" + (node.$alt()) + "</span>"));
39996              img = "<object type=\"image/svg+xml\" data=\"" + (node.$image_uri(target)) + "\"" + (attrs) + ">" + (fallback) + "</object>";
39997            } else {
39998              img = "<img src=\"" + (node.$image_uri(target)) + "\" alt=\"" + (self.$encode_attribute_value(node.$alt())) + "\"" + (attrs) + (self.void_element_slash) + ">"
39999            }
40000          } else {
40001            img = "<img src=\"" + (node.$image_uri(target)) + "\" alt=\"" + (self.$encode_attribute_value(node.$alt())) + "\"" + (attrs) + (self.void_element_slash) + ">"
40002          };
40003        };
40004        if ($truthy(node['$attr?']("link"))) {
40005          img = "<a class=\"image\" href=\"" + (node.$attr("link")) + "\"" + (self.$append_link_constraint_attrs(node).$join()) + ">" + (img) + "</a>"
40006        };
40007        class_attr_val = type;
40008        if ($truthy((role = node.$role()))) {
40009          class_attr_val = ($truthy(node['$attr?']("float")) ? ("" + (class_attr_val) + " " + (node.$attr("float")) + " " + (role)) : ("" + (class_attr_val) + " " + (role)))
40010        } else if ($truthy(node['$attr?']("float"))) {
40011          class_attr_val = "" + (class_attr_val) + " " + (node.$attr("float"))
40012        };
40013        return "<span class=\"" + (class_attr_val) + "\">" + (img) + "</span>";
40014      });
40015      
40016      $def(self, '$convert_inline_indexterm', function $$convert_inline_indexterm(node) {
40017        
40018        if ($eqeq(node.$type(), "visible")) {
40019          return node.$text()
40020        } else {
40021          return ""
40022        }
40023      });
40024      
40025      $def(self, '$convert_inline_kbd', function $$convert_inline_kbd(node) {
40026        var keys = nil;
40027
40028        if ($eqeq((keys = node.$attr("keys")).$size(), 1)) {
40029          return "<kbd>" + (keys['$[]'](0)) + "</kbd>"
40030        } else {
40031          return "<span class=\"keyseq\"><kbd>" + (keys.$join("</kbd>+<kbd>")) + "</kbd></span>"
40032        }
40033      });
40034      
40035      $def(self, '$convert_inline_menu', function $$convert_inline_menu(node) {
40036        var caret = nil, submenu_joiner = nil, menu = nil, submenus = nil, menuitem = nil;
40037
40038        
40039        caret = ($truthy(node.$document()['$attr?']("icons", "font")) ? ("&#160;<i class=\"fa fa-angle-right caret\"></i> ") : ("&#160;<b class=\"caret\">&#8250;</b> "));
40040        submenu_joiner = "</b>" + (caret) + "<b class=\"submenu\">";
40041        menu = node.$attr("menu");
40042        if ($truthy((submenus = node.$attr("submenus"))['$empty?']())) {
40043          if ($truthy((menuitem = node.$attr("menuitem")))) {
40044            return "<span class=\"menuseq\"><b class=\"menu\">" + (menu) + "</b>" + (caret) + "<b class=\"menuitem\">" + (menuitem) + "</b></span>"
40045          } else {
40046            return "<b class=\"menuref\">" + (menu) + "</b>"
40047          }
40048        } else {
40049          return "<span class=\"menuseq\"><b class=\"menu\">" + (menu) + "</b>" + (caret) + "<b class=\"submenu\">" + (submenus.$join(submenu_joiner)) + "</b>" + (caret) + "<b class=\"menuitem\">" + (node.$attr("menuitem")) + "</b></span>"
40050        };
40051      });
40052      
40053      $def(self, '$convert_inline_quoted', function $$convert_inline_quoted(node) {
40054        var $a, $b, open = nil, close = nil, tag = nil, class_attr = nil;
40055
40056        
40057        $b = $$('QUOTE_TAGS')['$[]'](node.$type()), $a = $to_ary($b), (open = ($a[0] == null ? nil : $a[0])), (close = ($a[1] == null ? nil : $a[1])), (tag = ($a[2] == null ? nil : $a[2])), $b;
40058        if ($truthy(node.$id())) {
40059          
40060          class_attr = ($truthy(node.$role()) ? (" class=\"" + (node.$role()) + "\"") : (""));
40061          if ($truthy(tag)) {
40062            return "" + (open.$chop()) + " id=\"" + (node.$id()) + "\"" + (class_attr) + ">" + (node.$text()) + (close)
40063          } else {
40064            return "<span id=\"" + (node.$id()) + "\"" + (class_attr) + ">" + (open) + (node.$text()) + (close) + "</span>"
40065          };
40066        } else if ($truthy(node.$role())) {
40067          if ($truthy(tag)) {
40068            return "" + (open.$chop()) + " class=\"" + (node.$role()) + "\">" + (node.$text()) + (close)
40069          } else {
40070            return "<span class=\"" + (node.$role()) + "\">" + (open) + (node.$text()) + (close) + "</span>"
40071          }
40072        } else {
40073          return "" + (open) + (node.$text()) + (close)
40074        };
40075      });
40076      
40077      $def(self, '$read_svg_contents', function $$read_svg_contents(node, target) {
40078        var svg = nil, old_start_tag = nil, new_start_tag = nil, start_tag_match = nil;
40079
40080        
40081        if ($truthy((svg = node.$read_contents(target, $hash2(["start", "normalize", "label", "warn_if_empty"], {"start": node.$document().$attr("imagesdir"), "normalize": true, "label
40081": "SVG", "warn_if_empty": true}))))) {
40082          
40083          if ($truthy(svg['$empty?']())) {
40084            return nil
40085          };
40086          if (!$truthy(svg['$start_with?']("<svg"))) {
40087            svg = svg.$sub($$('SvgPreambleRx'), "")
40088          };
40089          old_start_tag = (new_start_tag = (start_tag_match = nil));
40090          $send(["width", "height"], 'each', [], function $$20(dim){var $ret_or_1 = nil, $ret_or_2 = nil;
40091
40092            
40093            if (dim == null) dim = nil;
40094            if (!$truthy(node['$attr?'](dim))) {
40095              return nil
40096            };
40097            if (!$truthy(new_start_tag)) {
40098              
40099              if ($eqeq((start_tag_match = ($truthy(($ret_or_1 = start_tag_match)) ? ($ret_or_1) : ($truthy(($ret_or_2 = svg.$match($$('SvgStartTagRx')))) ? ($ret_or_2) : ("no_match")))), "no_match")) {
40100                return nil
40101              };
40102              new_start_tag = (old_start_tag = start_tag_match['$[]'](0)).$gsub($$('DimensionAttributeRx'), "");
40103            };
40104            return (new_start_tag = "" + (new_start_tag.$chop()) + " " + (dim) + "=\"" + (node.$attr(dim)) + "\">");});
40105          if ($truthy(new_start_tag)) {
40106            svg = "" + (new_start_tag) + (svg['$[]'](Opal.Range.$new(old_start_tag.$length(), -1, false)))
40107          };
40108        };
40109        return svg;
40110      });
40111      self.$private();
40112      
40113      $def(self, '$append_boolean_attribute', function $$append_boolean_attribute(name, xml) {
40114        
40115        if ($truthy(xml)) {
40116          return " " + (name) + "=\"" + (name) + "\""
40117        } else {
40118          return " " + (name)
40119        }
40120      });
40121      
40122      $def(self, '$append_link_constraint_attrs', function $$append_link_constraint_attrs(node, attrs) {
40123        var rel = nil, window = nil;
40124
40125        
40126        if (attrs == null) attrs = [];
40127        if ($truthy(node['$option?']("nofollow"))) {
40128          rel = "nofollow"
40129        };
40130        if ($truthy((window = node.$attributes()['$[]']("window")))) {
40131          
40132          attrs['$<<'](" target=\"" + (window) + "\"");
40133          if (($eqeq(window, "_blank") || ($truthy(node['$option?']("noopener"))))) {
40134            attrs['$<<'](($truthy(rel) ? (" rel=\"" + (rel) + " noopener\"") : (" rel=\"noopener\"")))
40135          };
40136        } else if ($truthy(rel)) {
40137          attrs['$<<'](" rel=\"" + (rel) + "\"")
40138        };
40139        return attrs;
40140      }, -2);
40141      
40142      $def(self, '$encode_attribute_value', function $$encode_attribute_value(val) {
40143        
40144        if ($truthy(val['$include?']("\""))) {
40145          
40146          return val.$gsub("\"", "&quot;");
40147        } else {
40148          return val
40149        }
40150      });
40151      
40152      $def(self, '$generate_manname_section', function $$generate_manname_section(node) {
40153        var manname_title = nil, next_section_title = nil, next_section = nil, manname_id_attr = nil, manname_id = nil;
40154
40155        
40156        manname_title = node.$attr("manname-title", "Name");
40157        if (($truthy((next_section = node.$sections()['$[]'](0))) && ($eqeq((next_section_title = next_section.$title()), next_section_title.$upcase())))) {
40158          manname_title = manname_title.$upcase()
40159        };
40160        manname_id_attr = ($truthy((manname_id = node.$attr("manname-id"))) ? (" id=\"" + (manname_id) + "\"") : (""));
40161        return "<h2" + (manname_id_attr) + ">" + (manname_title) + "</h2>\n" + "<div class=\"sectionbody\">\n" + "<p>" + (node.$attr("mannames").$join(", ")) + " - " + (node.$attr("manpurpose")) + "</p>\n" + "</div>";
40162      });
40163      
40164      $def(self, '$get_root_document', function $$get_root_document(node) {
40165        
40166        
40167        while ($truthy((node = node.$document())['$nested?']())) {
40168        node = node.$parent_document()
40169        };
40170        return node;
40171      });
40172      
40173      $def(self, '$method_missing', function $$method_missing(id, $a) {
40174        var $post_args, args, $yield = $$method_missing.$$p || nil, self = this, name = nil;
40175
40176        $$method_missing.$$p = null;
40177        
40178        $post_args = $slice(arguments, 1);
40179        args = $post_args;
40180        if (($not((name = id.$to_s())['$start_with?']("convert_")) && ($truthy(self['$handles?'](name))))) {
40181          
40182          return $send(self, 'send', ["convert_" + (name)].concat($to_a(args)));
40183        } else {
40184          return $send2(self, $find_super(self, 'method_missing', $$method_missing, false, true), 'method_missing', [id].concat($to_a(args)), $yield)
40185        };
40186      }, -2);
40187      return $def(self, '$respond_to_missing?', function $Html5Converter_respond_to_missing$ques$21(id, $a) {
40188        var $post_args, options, self = this, $ret_or_1 = nil, name = nil;
40189
40190        
40191        $post_args = $slice(arguments, 1);
40192        options = $post_args;
40193        if ($truthy(($ret_or_1 = (name = id.$to_s())['$start_with?']("convert_")['$!']()))) {
40194          
40195          return self['$handles?'](name);
40196        } else {
40197          return $ret_or_1
40198        };
40199      }, -2);
40200    })($$('Converter'), $$$($$('Converter'), 'Base'), $nesting)
40201  })($nesting[0], $nesting)
40202};
40203
40204Opal.modules["asciidoctor/extensions"] = function(Opal) {/* Generated by Opal 1.7.3 */
40205  "use strict";
40206  var $module = Opal.module, $klass = Opal.klass, $truthy = Opal.truthy, $hash2 = Opal.hash2, $def = Opal.def, $send = Opal.send, $alias = Opal.alias, $slice = Opal.slice, $rb_plus = Opal.rb_plus, $eqeq = Opal.eqeq, $rb_gt = Opal.rb_gt, $not = Opal.not, $eqeqeq = Opal.eqeqeq, $to_a = Opal.to_a, $to_ary = Opal.to_ary, $const_set = Opal.const_set, $return_val = Opal.return_val, $send2 = Opal.send2, $find_super = Opal.find_super, $NilClass = Opal.NilClass, $class_variable_set = Opal.class_variable_set, $class_variable_get = Opal.class_variable_get, $regexp = Opal.regexp, $Class = Opal.Class, $return_ivar = Opal.return_ivar, $rb_lt = Opal.rb_lt, $rb_minus = Opal.rb_minus, $hash = Opal.hash, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$;
40207
40208  Opal.add_stubs('[]=,config,const_defined?,singleton_class?,include,const_get,extend,enable_dsl,attr_reader,merge,class,update,raise,document,==,doctype,[],+,level,delete,>,casecmp,new,title=,sectname=,special=,fetch,numbered=,attr?,!,key?,special,numbered,id=,generate_id,title,update_attributes,tr,basename,create_block,assign_caption,===,parse_blocks,empty?,include?,sub_attributes,parse,each,define_method,unshift,shift,send,size,re
40208ceiver,binding,define_singleton_method,instance_exec,to_proc,call,option,content_model,flatten,positional_attributes,default_attributes,respond_to?,to_s,partition,to_i,<<,compact,inspect,resolve_attributes,attr_accessor,to_set,contexts,match?,resolve_regexp,format,method,register,reset,values,groups,arity,activate,add_document_processor,tree_processor,tree_processors?,tree_processors,any?,select,add_syntax_processor,to_sym,instance_variable_get,kind,private,join,map,split,capitalize,instance_variable_set,resolve_args,singleton_class,process_block_given?,source_location,freeze,resolve_class,<,update_config,as_symbol,name,name=,pop,-,-@,next_auto_id,generate_name,each_with_object');
40209  
40210  nil;
40211  return (function($base, $parent_nesting) {
40212    var self = $module($base, 'Asciidoctor');
40213
40214    var $nesting = [self].concat($parent_nesting);
40215
40216    return (function($base, $parent_nesting) {
40217      var self = $module($base, 'Extensions');
40218
40219      var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
40220
40221      
40222      (function($base, $super, $parent_nesting) {
40223        var self = $klass($base, $super, 'Processor');
40224
40225        var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype;
40226
40227        $proto.config = nil;
40228        
40229        (function(self, $parent_nesting) {
40230          
40231          
40232          
40233          $def(self, '$config', function $$config() {
40234            var self = this, $ret_or_1 = nil;
40235            if (self.config == null) self.config = nil;
40236
40237            return (self.config = ($truthy(($ret_or_1 = self.config)) ? ($ret_or_1) : ($hash2([], {}))))
40238          });
40239          
40240          $def(self, '$option', function $$option(key, default_value) {
40241            var $a, self = this;
40242
40243            return ($a = [key, default_value], $send(self.$config(), '[]=', $a), $a[$a.length - 1])
40244          });
40245          
40246          $def(self, '$enable_dsl', function $$enable_dsl() {
40247            var self = this;
40248
40249            if ($truthy(self['$const_defined?']("DSL"))) {
40250              if ($truthy(self['$singleton_class?']())) {
40251                return self.$include(self.$const_get("DSL"))
40252              } else {
40253                return self.$extend(self.$const_get("DSL"))
40254              }
40255            } else {
40256              return nil
40257            }
40258          });
40259          return $alias(self, "use_dsl", "enable_dsl");
40260        })(Opal.get_singleton_class(self), $nesting);
40261        self.$attr_reader("config");
40262        
40263        $def(self, '$initialize', function $$initialize(config) {
40264          var self = this;
40265
40266          
40267          if (config == null) config = $hash2([], {});
40268          return (self.config = self.$class().$config().$merge(config));
40269        }, -1);
40270        
40271        $def(self, '$update_config', function $$update_config(config) {
40272          var self = this;
40273
40274          return self.config.$update(config)
40275        });
40276        
40277        $def(self, '$process', function $$process($a) {
40278          var $post_args, args, self = this;
40279
40280          
40281          $post_args = $slice(arguments);
40282          args = $post_args;
40283          return self.$raise($$$('NotImplementedError'), "" + ($$('Processor')) + " subclass " + (self.$class()) + " must implement the #" + ("process") + " method");
40284        }, -1);
40285        
40286        $def(self, '$create_section', function $$create_section(parent, title, attrs, opts) {
40287          var $a, $b, doc = nil, book = nil, doctype = nil, level = nil, $ret_or_1 = nil, style = nil, sectname = nil, special = nil, sect = nil, id = nil;
40288
40289          
40290          if (opts == null) opts = $hash2([], {});
40291          doc = parent.$document();
40292          book = (doctype = doc.$doctype())['$==']("book");
40293          level = ($truthy(($ret_or_1 = opts['$[]']("level"))) ? ($ret_or_1) : ($rb_plus(parent.$level(), 1)));
40294          if ($truthy((style = attrs.$delete("style")))) {
40295            if (($truthy(book) && ($eqeq(style, "abstract")))) {
40296              $a = ["chapter", 1], (sectname = $a[0]), (level = $a[1]), $a
40297            } else {
40298              
40299              $a = [style, true], (sectname = $a[0]), (special = $a[1]), $a;
40300              if ($eqeq(level, 0)) {
40301                level = 1
40302              };
40303            }
40304          } else if ($truthy(book)) {
40305            sectname = ($eqeq(level, 0) ? ("part") : (($truthy($rb_gt(level, 1)) ? ("section") : ("chapter"))))
40306          } else if (($eqeq(doctype, "manpage") && ($eqeq(title.$casecmp("synopsis"), 0)))) {
40307            $a = ["synopsis", true], (sectname = $a[0]), (special = $a[1]), $a
40308          } else {
40309            sectname = "section"
40310          };
40311          sect = $$('Section').$new(parent, level);
40312          $a = [title, sectname], ($b = [$a[0]], $send(sect, 'title=', $b), $b[$b.length - 1]), ($b = [$a[1]], $send(sect, 'sectname=', $b), $b[$b.length - 1]), $a;
40313          if ($truthy(special)) {
40314            
40315            sect['$special='](true);
40316            if ($truthy(opts.$fetch("numbered", style['$==']("appendix")))) {
40317              sect['$numbered='](true)
40318            } else if (($not(opts['$key?']("numbered")) && ($truthy(doc['$attr?']("sectnums", "all"))))) {
40319              sect['$numbered=']((($truthy(book) && ($eqeq(level, 1))) ? ("chapter") : (true)))
40320            };
40321          } else if ($truthy($rb_gt(level, 0))) {
40322            if ($truthy(opts.$fetch("numbered", doc['$attr?']("sectnums")))) {
40323              sect['$numbered='](($truthy(sect.$special()) ? (($truthy(($ret_or_1 = parent.$numbered())) || ($ret_or_1))) : (true)))
40324            }
40325          } else if ($truthy(opts.$fetch("numbered", ($truthy(($ret_or_1 = book)) ? (doc['$attr?']("partnums")) : ($ret_or_1))))) {
40326            sect['$numbered='](true)
40327          };
40328          if ($eqeq((id = attrs['$[]']("id")), false)) {
40329            attrs.$delete("id")
40330          } else {
40331            sect['$id='](($a = ["id", ($truthy(($ret_or_1 = id)) ? ($ret_or_1) : (($truthy(doc['$attr?']("sectids")) ? ($$('Section').$generate_id(sect.$title(), doc)) : (nil))))], $send(attrs, '[]=', $a), $a[$a.length - 1]))
40332          };
40333          sect.$update_attributes(attrs);
40334          return sect;
40335        }, -4);
40336        
40337        $def(self, '$create_block', function $$create_block(parent, context, source, attrs, opts) {
40338          
40339          
40340          if (opts == null) opts = $hash2([], {});
40341          return $$('Block').$new(parent, context, $hash2(["source", "attributes"], {"source": source, "attributes": attrs}).$merge(opts));
40342        }, -5);
40343        
40344        $def(self, '$create_list', function $$create_list(parent, context, attrs) {
40345          var list = nil;
40346
40347          
40348          if (attrs == null) attrs = nil;
40349          list = $$('List').$new(parent, context);
40350          if ($truthy(attrs)) {
40351            list.$update_attributes(attrs)
40352          };
40353          return list;
40354        }, -3);
40355        
40356        $def(self, '$create_list_item', function $$create_list_item(parent, text) {
40357          
40358          
40359          if (text == null) text = nil;
40360          return $$('ListItem').$new(parent, text);
40361        }, -2);
40362        
40363        $def(self, '$create_image_block', function $$create_image_block(parent, attrs, opts) {
40364          var $a, self = this, target = nil, $ret_or_1 = nil, title = nil, block = nil;
40365
40366          
40367          if (opts == null) opts = $hash2([], {});
40368          if (!$truthy((target = attrs['$[]']("target")))) {
40369            self.$raise($$$('ArgumentError'), "Unable to create an image block, target attribute is required")
40370          };
40371          if ($truthy(($ret_or_1 = attrs['$[]']("alt")))) {
40372            $ret_or_1
40373          } else {
40374            attrs['$[]=']("alt", ($a = ["default-alt", $$('Helpers').$basename(target, true).$tr("_-", " ")], $send(attrs, '[]=', $a), $a[$a.length - 1]))
40375          };
40376          title = ($truthy(attrs['$key?']("title")) ? (attrs.$delete("title")) : (nil));
40377          block = self.$create_block(parent, "image", nil, attrs, opts);
40378          if ($truthy(title)) {
40379            
40380            block['$title='](title);
40381            block.$assign_caption(attrs.$delete("caption"), "figure");
40382          };
40383          return block;
40384        }, -3);
40385        
40386        $def(self, '$create_inline', function $$create_inline(parent, context, text, opts) {
40387          
40388          
40389          if (opts == null) opts = $hash2([], {});
40390          return $$('Inline').$new(parent, context, text, ($eqeq(context, "quoted") ? ($hash2(["type"], {"type": "unquoted"}).$merge(opts)) : (opts)));
40391        }, -4);
40392        
40393        $def(self, '$parse_content', function $$parse_content(parent, content, attributes) {
40394          var reader = nil;
40395
40396          
40397          if (attributes == null) attributes = nil;
40398          reader = ($eqeqeq($$('Reader'), content) ? (content) : ($$('Reader').$new(content)));
40399          $$('Parser').$parse_blocks(reader, parent, attributes);
40400          return parent;
40401        }, -3);
40402        
40403        $def(self, '$parse_attributes', function $$parse_attributes(block, attrlist, opts) {
40404          var $ret_or_1 = nil;
40405
40406          
40407          if (opts == null) opts = $hash2([], {});
40408          if ($truthy(($truthy(attrlist) ? (attrlist['$empty?']()) : (true)))) {
40409            return $hash2([], {})
40410          };
40411          if (($truthy(opts['$[]']("sub_attributes")) && ($truthy(attrlist['$include?']($$('ATTR_REF_HEAD')))))) {
40412            attrlist = block.$sub_attributes(attrlist)
40413          };
40414          return $$('AttributeList').$new(attrlist).$parse(($truthy(($ret_or_1 = opts['$[]']("positional_attributes"))) ? ($ret_or_1) : ([])));
40415        }, -3);
40416        return $send([["create_paragraph", "create_block", "paragraph"], ["create_open_block", "create_block", "open"], ["create_example_block", "create_block", "example"], ["create_pass_block", "create_block", "pass"], ["create_listing_block", "create_block", "listing"], ["create_literal_block", "create_block", "literal"], ["create_anchor", "create_inline", "anchor"], ["create_inline_pass", "create_inline", "quoted"]], 'each', [], function $Processor$1(method_name, delegate_method_name, context){var self = $Processor$1.$$s == null ? this : $Processor$1.$$s;
40417
40418          
40419          if (method_name == null) method_name = nil;
40420          if (delegate_method_name == null) delegate_method_name = nil;
40421          if (context == null) context = nil;
40422          return $send(self, 'define_method', [method_name], function $$2($a){var $post_args, args, self = $$2.$$s == null ? this : $$2.$$s;
40423
40424            
40425            $post_args = $slice(arguments);
40426            args = $post_args;
40427            args.$unshift(args.$shift(), context);
40428            return $send(self, 'send', [delegate_method_name].concat($to_a(args)));}, {$$arity: -1, $$s: self});}, {$$s: self});
40429      })($nesting[0], null, $nesting);
40430      (function($base) {
40431        var self = $module($base, 'ProcessorDsl');
40432
40433        
40434        
40435        
40436        $def(self, '$option', function $$option(key, value) {
40437          var $a, self = this;
40438
40439          return ($a = [key, value], $send(self.$config(), '[]=', $a), $a[$a.length - 1])
40440        });
40441        
40442        $def(self, '$process', function $$process($a) {
40443          var block = $$process.$$p || nil, $post_args, args, $b, self = this, context = nil;
40444          if (self.process_block == null) self.process_block = nil;
40445
40446          $$process.$$p = null;
40447          
40448          ;
40449          $post_args = $slice(arguments);
40450          args = $post_args;
40451          if ((block !== nil)) {
40452            
40453            if (!$truthy(args['$empty?']())) {
40454              self.$raise($$$('ArgumentError'), "wrong number of arguments (given " + (args.$size()) + ", expected 0)")
40455            };
40456            if (!($truthy(block.$binding()) && ($eqeq(self, block.$binding().$receiver())))) {
40457              
40458              context = self;
40459              $send(block, 'define_singleton_method', ["call"], function $$3($b){var $post_args, m_args;
40460
40461                
40462                $post_args = $slice(arguments);
40463                m_args = $post_args;
40464                return $send(context, 'instance_exec', $to_a(m_args), block.$to_proc());}, -1);
40465            };
40466            return (self.process_block = block);
40467          } else if ($truthy((($b = self['process_block'], $b != null && $b !== nil) ? 'instance-variable' : nil))) {
40468            return $send(self.process_block, 'call', $to_a(args))
40469          } else {
40470            return self.$raise($$$('NotImplementedError'), "" + (self.$class()) + " #" + ("process") + " method called before being registered")
40471          };
40472        }, -1);
40473        return $def(self, '$process_block_given?', function $ProcessorDsl_process_block_given$ques$4() {
40474          var $a, self = this;
40475
40476          return (($a = self['process_block'], $a != null && $a !== nil) ? 'instance-variable' : nil)
40477        });
40478      })($nesting[0]);
40479      (function($base, $parent_nesting) {
40480        var self = $module($base, 'DocumentProcessorDsl');
40481
40482        var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
40483
40484        
40485        self.$include($$('ProcessorDsl'));
40486        return $def(self, '$prefer', function $$prefer() {
40487          var self = this;
40488
40489          return self.$option("position", ">>")
40490        });
40491      })($nesting[0], $nesting);
40492      (function($base, $parent_nesting) {
40493        var self = $module($base, 'SyntaxProcessorDsl');
40494
40495        var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
40496
40497        
40498        self.$include($$('ProcessorDsl'));
40499        
40500        $def(self, '$named', function $$named(value) {
40501          var self = this;
40502
40503          if ($eqeqeq($$('Processor'), self)) {
40504            return (self.name = value)
40505          } else {
40506            return self.$option("name", value)
40507          }
40508        });
40509        
40510        $def(self, '$content_model', function $$content_model(value) {
40511          var self = this;
40512
40513          return self.$option("content_model", value)
40514        });
40515        $alias(self, "parse_content_as", "content_model");
40516        
40517        $def(self, '$positional_attributes', function $$positional_attributes($a) {
40518          var $post_args, value, self = this;
40519
40520          
40521          $post_args = $slice(arguments);
40522          value = $post_args;
40523          return self.$option("positional_attrs", value.$flatten());
40524        }, -1);
40525        $alias(self, "name_positional_attributes", "positional_attributes");
40526        $alias(self, "positional_attrs", "positional_attributes");
40527        
40528        $def(self, '$default_attributes', function $$default_attributes(value) {
40529          var self = this;
40530
40531          return self.$option("default_attrs", value)
40532        });
40533        $alias(self, "default_attrs", "default_attributes");
40534        
40535        $def(self, '$resolve_attributes', function $$resolve_attributes($a) {
40536          var $post_args, args, $b, self = this, $ret_or_1 = nil, names = nil, defaults = nil;
40537
40538          
40539          $post_args = $slice(arguments);
40540          args = $post_args;
40541          if (!$truthy($rb_gt(args.$size(), 1))) {
40542            if ($truthy((args = args.$fetch(0, true))['$respond_to?']("to_sym"))) {
40543              args = [args]
40544            }
40545          };
40546          if ($eqeqeq(true, ($ret_or_1 = args))) {
40547            
40548            self.$option("positional_attrs", []);
40549            return self.$option("default_attrs", $hash2([], {}));
40550          } else if ($eqeqeq($$$('Array'), $ret_or_1)) {
40551            
40552            $b = [[], $hash2([], {})], (names = $b[0]), (defaults = $b[1]), $b;
40553            $send(args, 'each', [], function $$5(arg){var $c, $d, name = nil, _ = nil, value = nil, idx = nil;
40554
40555              
40556              if (arg == null) arg = nil;
40557              if ($truthy((arg = arg.$to_s())['$include?']("="))) {
40558                
40559                $d = arg.$partition("="), $c = $to_ary($d), (name = ($c[
405590] == null ? nil : $c[0])), (_ = ($c[1] == null ? nil : $c[1])), (value = ($c[2] == null ? nil : $c[2])), $d;
40560                if ($truthy(name['$include?'](":"))) {
40561                  
40562                  $d = name.$partition(":"), $c = $to_ary($d), (idx = ($c[0] == null ? nil : $c[0])), (_ = ($c[1] == null ? nil : $c[1])), (name = ($c[2] == null ? nil : $c[2])), $d;
40563                  idx = ($eqeq(idx, "@") ? (names.$size()) : (idx.$to_i()));
40564                  names['$[]='](idx, name);
40565                };
40566                return ($c = [name, value], $send(defaults, '[]=', $c), $c[$c.length - 1]);
40567              } else if ($truthy(arg['$include?'](":"))) {
40568                
40569                $d = arg.$partition(":"), $c = $to_ary($d), (idx = ($c[0] == null ? nil : $c[0])), (_ = ($c[1] == null ? nil : $c[1])), (name = ($c[2] == null ? nil : $c[2])), $d;
40570                idx = ($eqeq(idx, "@") ? (names.$size()) : (idx.$to_i()));
40571                return ($c = [idx, name], $send(names, '[]=', $c), $c[$c.length - 1]);
40572              } else {
40573                return names['$<<'](arg)
40574              };});
40575            self.$option("positional_attrs", names.$compact());
40576            return self.$option("default_attrs", defaults);
40577          } else if ($eqeqeq($$$('Hash'), $ret_or_1)) {
40578            
40579            $b = [[], $hash2([], {})], (names = $b[0]), (defaults = $b[1]), $b;
40580            $send(args, 'each', [], function $$6(key, val){var $c, $d, name = nil, idx = nil, _ = nil;
40581
40582              
40583              if (key == null) key = nil;
40584              if (val == null) val = nil;
40585              if ($truthy((name = key.$to_s())['$include?'](":"))) {
40586                
40587                $d = name.$partition(":"), $c = $to_ary($d), (idx = ($c[0] == null ? nil : $c[0])), (_ = ($c[1] == null ? nil : $c[1])), (name = ($c[2] == null ? nil : $c[2])), $d;
40588                idx = ($eqeq(idx, "@") ? (names.$size()) : (idx.$to_i()));
40589                names['$[]='](idx, name);
40590              };
40591              if ($truthy(val)) {
40592                return ($c = [name, val], $send(defaults, '[]=', $c), $c[$c.length - 1])
40593              } else {
40594                return nil
40595              };});
40596            self.$option("positional_attrs", names.$compact());
40597            return self.$option("default_attrs", defaults);
40598          } else {
40599            return self.$raise($$$('ArgumentError'), "unsupported attributes specification for macro: " + (args.$inspect()))
40600          };
40601        }, -1);
40602        return $alias(self, "resolves_attributes", "resolve_attributes");
40603      })($nesting[0], $nesting);
40604      (function($base, $super, $parent_nesting) {
40605        var self = $klass($base, $super, 'Preprocessor');
40606
40607        var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
40608
40609        return $def(self, '$process', function $$process(document, reader) {
40610          var self = this;
40611
40612          return self.$raise($$$('NotImplementedError'), "" + ($$('Preprocessor')) + " subclass " + (self.$class()) + " must implement the #" + ("process") + " method")
40613        })
40614      })($nesting[0], $$('Processor'), $nesting);
40615      $const_set($$('Preprocessor'), 'DSL', $$('DocumentProcessorDsl'));
40616      (function($base, $super, $parent_nesting) {
40617        var self = $klass($base, $super, 'TreeProcessor');
40618
40619        var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
40620
40621        return $def(self, '$process', function $$process(document) {
40622          var self = this;
40623
40624          return self.$raise($$$('NotImplementedError'), "" + ($$('TreeProcessor')) + " subclass " + (self.$class()) + " must implement the #" + ("process") + " method")
40625        })
40626      })($nesting[0], $$('Processor'), $nesting);
40627      $const_set($$('TreeProcessor'), 'DSL', $$('DocumentProcessorDsl'));
40628      $const_set($nesting[0], 'Treeprocessor', $$('TreeProcessor'));
40629      (function($base, $super, $parent_nesting) {
40630        var self = $klass($base, $super, 'Postprocessor');
40631
40632        var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
40633
40634        return $def(self, '$process', function $$process(document, output) {
40635          var self = this;
40636
40637          return self.$raise($$$('NotImplementedError'), "" + ($$('Postprocessor')) + " subclass " + (self.$class()) + " must implement the #" + ("process") + " method")
40638        })
40639      })($nesting[0], $$('Processor'), $nesting);
40640      $const_set($$('Postprocessor'), 'DSL', $$('DocumentProcessorDsl'));
40641      (function($base, $super, $parent_nesting) {
40642        var self = $klass($base, $super, 'IncludeProcessor');
40643
40644        var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
40645
40646        
40647        
40648        $def(self, '$process', function $$process(document, reader, target, attributes) {
40649          var self = this;
40650
40651          return self.$raise($$$('NotImplementedError'), "" + ($$('IncludeProcessor')) + " subclass " + (self.$class()) + " must implement the #" + ("process") + " method")
40652        });
40653        return $def(self, '$handles?', $return_val(true));
40654      })($nesting[0], $$('Processor'), $nesting);
40655      (function($base, $parent_nesting) {
40656        var self = $module($base, 'IncludeProcessorDsl');
40657
40658        var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
40659
40660        
40661        self.$include($$('DocumentProcessorDsl'));
40662        return $def(self, '$handles?', function $IncludeProcessorDsl_handles$ques$7($a) {
40663          var block = $IncludeProcessorDsl_handles$ques$7.$$p || nil, $post_args, args, $b, self = this;
40664          if (self.handles_block == null) self.handles_block = nil;
40665
40666          $IncludeProcessorDsl_handles$ques$7.$$p = null;
40667          
40668          ;
40669          $post_args = $slice(arguments);
40670          args = $post_args;
40671          if ((block !== nil)) {
40672            
40673            if (!$truthy(args['$empty?']())) {
40674              self.$raise($$$('ArgumentError'), "wrong number of arguments (given " + (args.$size()) + ", expected 0)")
40675            };
40676            return (self.handles_block = block);
40677          } else if ($truthy((($b = self['handles_block'], $b != null && $b !== nil) ? 'instance-variable' : nil))) {
40678            return self.handles_block.$call(args['$[]'](0))
40679          } else {
40680            return true
40681          };
40682        }, -1);
40683      })($nesting[0], $nesting);
40684      $const_set($$('IncludeProcessor'), 'DSL', $$('IncludeProcessorDsl'));
40685      (function($base, $super, $parent_nesting) {
40686        var self = $klass($base, $super, 'DocinfoProcessor');
40687
40688        var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype;
40689
40690        $proto.config = nil;
40691        
40692        
40693        $def(self, '$initialize', function $$initialize(config) {
40694          var $a, $yield = $$initialize.$$p || nil, self = this, $ret_or_1 = nil;
40695
40696          $$initialize.$$p = null;
40697          
40698          if (config == null) config = $hash2([], {});
40699          $send2(self, $find_super(self, 'initialize', $$initialize, false, true), 'initialize', [config], null);
40700          if ($truthy(($ret_or_1 = self.config['$[]']("location")))) {
40701            return $ret_or_1
40702          } else {
40703            return ($a = ["location", "head"], $send(self.config, '[]=', $a), $a[$a.length - 1])
40704          };
40705        }, -1);
40706        return $def(self, '$process', function $$process(document) {
40707          var self = this;
40708
40709          return self.$raise($$$('NotImplementedError'), "" + ($$('DocinfoProcessor')) + " subclass " + (self.$class()) + " must implement the #" + ("process") + " method")
40710        });
40711      })($nesting[0], $$('Processor'), $nesting);
40712      (function($base, $parent_nesting) {
40713        var self = $module($base, 'DocinfoProcessorDsl');
40714
40715        var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
40716
40717        
40718        self.$include($$('DocumentProcessorDsl'));
40719        return $def(self, '$at_location', function $$at_location(value) {
40720          var self = this;
40721
40722          return self.$option("location", value)
40723        });
40724      })($nesting[0], $nesting);
40725      $const_set($$('DocinfoProcessor'), 'DSL', $$('DocinfoProcessorDsl'));
40726      (function($base, $super, $parent_nesting) {
40727        var self = $klass($base, $super, 'BlockProcessor');
40728
40729        var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype;
40730
40731        $proto.config = nil;
40732        
40733        self.$attr_accessor("name");
40734        
40735        $def(self, '$initialize', function $$initialize(name, config) {
40736          var $a, $yield = $$initialize.$$p || nil, self = this, $ret_or_1 = nil, $ret_or_2 = nil;
40737
40738          $$initialize.$$p = null;
40739          
40740          if (name == null) name = nil;
40741          if (config == null) config = $hash2([], {});
40742          $send2(self, $find_super(self, 'initialize', $$initialize, false, true), 'initialize', [config], null);
40743          self.name = ($truthy(($ret_or_1 = name)) ? ($ret_or_1) : (self.config['$[]']("name")));
40744          if ($eqeqeq($NilClass, ($ret_or_1 = self.config['$[]']("contexts")))) {
40745            if ($truthy(($ret_or_2 = self.config['$[]']("contexts")))) {
40746              $ret_or_2
40747            } else {
40748              self.config['$[]=']("contexts", ["open", "paragraph"].$to_set())
40749            }
40750          } else if ($eqeqeq($$$('Symbol'), $ret_or_1)) {
40751            self.config['$[]=']("contexts", [self.config['$[]']("contexts")].$to_set())
40752          } else {
40753            self.config['$[]=']("contexts", self.config['$[]']("contexts").$to_set())
40754          };
40755          if ($truthy(($ret_or_1 = self.config['$[]']("content_model")))) {
40756            return $ret_or_1
40757          } else {
40758            return ($a = ["content_model", "compound"], $send(self.config, '[]=', $a), $a[$a.length - 1])
40759          };
40760        }, -1);
40761        return $def(self, '$process', function $$process(parent, reader, attributes) {
40762          var self = this;
40763
40764          return self.$raise($$$('NotImplementedError'), "" + ($$('BlockProcessor')) + " subclass " + (self.$class()) + " must implement the #" + ("process") + " method")
40765        });
40766      })($nesting[0], $$('Processor'), $nesting);
40767      (function($base, $parent_nesting) {
40768        var self = $module($base, 'BlockProcessorDsl');
40769
40770        var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
40771
40772        
40773        self.$include($$('SyntaxProcessorDsl'));
40774        
40775        $def(self, '$contexts', function $$contexts($a) {
40776          var $post_args, value, self = this;
40777
40778          
40779          $post_args = $slice(arguments);
40780          value = $post_args;
40781          return self.$option("contexts", value.$flatten().$to_set());
40782        }, -1);
40783        $alias(self, "on_contexts", "contexts");
40784        $alias(self, "on_context", "contexts");
40785        return $alias(self, "bind_to", "contexts");
40786      })($nesting[0], $nesting);
40787      $const_set($$('BlockProcessor'), 'DSL', $$('BlockProcessorDsl'));
40788      (function($base, $super, $parent_nesting) {
40789        var self = $klass($base, $super, 'MacroProcessor');
40790
40791        var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype;
40792
40793        $proto.config = nil;
40794        
40795        self.$attr_accessor("name");
40796        
40797        $def(self, '$initialize', function $$initialize(name, config) {
40798          var $a, $yield = $$initialize.$$p || nil, self = this, $ret_or_1 = nil;
40799
40800          $$initialize.$$p = null;
40801          
40802          if (name == null) name = nil;
40803          if (config == null) config = $hash2([], {});
40804          $send2(self, $find_super(self, 'initialize', $$initialize, false, true), 'initialize', [config], null);
40805          self.name = ($truthy(($ret_or_1 = name)) ? ($ret_or_1) : (self.config['$[]']("name")));
40806          if ($truthy(($ret_or_1 = self.config['$[]']("content_model")))) {
40807            return $ret_or_1
40808          } else {
40809            return ($a = ["content_model", "attributes"], $send(self.config, '[]=', $a), $a[$a.length - 1])
40810          };
40811        }, -1);
40812        return $def(self, '$process', function $$process(parent, target, attributes) {
40813          var self = this;
40814
40815          return self.$raise($$$('NotImplementedError'), "" + ($$('MacroProcessor')) + " subclass " + (self.$class()) + " must implement the #" + ("process") + " method")
40816        });
40817      })($nesting[0], $$('Processor'), $nesting);
40818      (function($base, $parent_nesting) {
40819        var self = $module($base, 'MacroProcessorDsl');
40820
40821        var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
40822
40823        
40824        self.$include($$('SyntaxProcessorDsl'));
40825        
40826        $def(self, '$resolve_attributes', function $$resolve_attributes($a) {
40827          var $post_args, args, $yield = $$resolve_attributes.$$p || nil, self = this;
40828
40829          $$resolve_attributes.$$p = null;
40830          
40831          $post_args = $slice(arguments);
40832          args = $post_args;
40833          if (($eqeq(args.$size(), 1) && ($not(args['$[]'](0))))) {
40834            return self.$option("content_model", "text")
40835          } else {
40836            
40837            $send2(self, $find_super(self, 'resolve_attributes', $$resolve_attributes, false, true), 'resolve_attributes', $to_a(args), $yield);
40838            return self.$option("content_model", "attributes");
40839          };
40840        }, -1);
40841        return $alias(self, "resolves_attributes", "resolve_attributes");
40842      })($nesting[0], $nesting);
40843      (function($base, $super, $parent_nesting) {
40844        var self = $klass($base, $super, 'BlockMacroProcessor');
40845
40846        var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype;
40847
40848        $proto.name = nil;
40849        return $def(self, '$name', function $$name() {
40850          var self = this;
40851
40852          
40853          if (!$truthy($$('MacroNameRx')['$match?'](self.name.$to_s()))) {
40854            self.$raise($$$('ArgumentError'), "invalid name for block macro: " + (self.name))
40855          };
40856          return self.name;
40857        })
40858      })($nesting[0], $$('MacroProcessor'), $nesting);
40859      $const_set($$('BlockMacroProcessor'), 'DSL', $$('MacroProcessorDsl'));
40860      (function($base, $super, $parent_nesting) {
40861        var self = $klass($base, $super, 'InlineMacroProcessor');
40862
40863        var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype;
40864
40865        $proto.config = $proto.name = nil;
40866        
40867        $class_variable_set($nesting[0], '@@rx_cache', $hash2([], {}));
40868        
40869        $def(self, '$regexp', function $$regexp() {
40870          var $a, self = this, $ret_or_1 = nil;
40871
40872          if ($truthy(($ret_or_1 = self.config['$[]']("regexp")))) {
40873            return $ret_or_1
40874          } else {
40875            return ($a = ["regexp", self.$resolve_regexp(self.name.$to_s(), self.config['$[]']("format"))], $send(self.config, '[]=', $a), $a[$a.length - 1])
40876          }
40877        });
40878        return $def(self, '$resolve_regexp', function $$resolve_regexp(name, format) {
40879          var $a, self = this, $ret_or_1 = nil;
40880
40881          
40882          if (!$truthy($$('MacroNameRx')['$match?'](name))) {
40883            self.$raise($$$('ArgumentError'), "invalid name for inline macro: " + (name))
40884          };
40885          if ($truthy(($ret_or_1 = $class_variable_get($nesting[0], '@@rx_cache', false)['$[]']([name, format])))) {
40886            return $ret_or_1
40887          } else {
40888            return ($a = [[name, format], $regexp(["\\\\?", name, ":", ($eqeq(format, "short") ? ("(){0}") : ("(\\S+?)")), "\\[(|", $$('CC_ANY'), "*?[^\\\\])\\]"])], $send($class_variable_get($nesting[0], '@@rx_cache', false), '[]=', $a), $a[$a.length - 1])
40889          };
40890        });
40891      })($nesting[0], $$('MacroProcessor'), $nesting);
40892      (function($base, $parent_nesting) {
40893        var self = $module($base, 'InlineMacroProcessorDsl');
40894
40895        var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
40896
40897        
40898        self.$include($$('MacroProcessorDsl'));
40899        
40900        $def(self, '$format', function $$format(value) {
40901          var self = this;
40902
40903          return self.$option("format", value)
40904        });
40905        $alias(self, "match_format", "format");
40906        $alias(self, "using_format", "format");
40907        return $def(self, '$match', function $$match(value) {
40908          var self = this;
40909
40910          return self.$option("regexp", value)
40911        });
40912      })($nesting[0], $nesting);
40913      $const_set($$('InlineMacroProcessor'), 'DSL', $$('InlineMacroProcessorDsl'));
40914      (function($base, $super) {
40915        var self = $klass($base, $super, 'Extension');
40916
40917        
40918        
40919        self.$attr_reader("kind");
40920        self.$attr_reader("config");
40921        self.$attr_reader("instance");
40922        return $def(self, '$initialize', function $$initialize(kind, instance, config) {
40923          var self = this;
40924
40925          
40926          self.kind = kind;
40927          self.instance = instance;
40928          return (self.config = config);
40929        });
40930      })($nesting[0], null);
40931      (function($base, $super) {
40932        var self = $klass($base, $super, 'ProcessorExtension');
40933
40934        
40935        
40936        self.$attr_reader("process_method");
40937        return $def(self, '$initialize', function $$initialize(kind, instance, process_method) {
40938          var $yield = $$initialize.$$p || nil, self = this, $ret_or_1 = nil;
40939
40940          $$initialize.$$p = null;
40941          
40942          if (process_method == null) process_method = nil;
40943          $send2(self, $find_super(self, 'initialize', $$initialize, false, true), 'initialize', [kind, instance, instance.$config()], null);
40944          return (self.process_method = ($truthy(($ret_or_1 = process_method)) ? ($ret_or_1) : (instance.$method("process"))));
40945        }, -3);
40946      })($nesting[0], $$('Extension'));
40947      (function($base, $super, $parent_nesting) {
40948        var self = $klass($base, $super, 'Group');
40949
40950        var $nesting = [self].concat($parent_nesting);
40951
40952        
40953        (function(self, $parent_nesting) {
40954          var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
40955
40956          return $def(self, '$register', function $$register(name) {
40957            var self = this;
40958
40959            
40960            if (name == null) name = nil;
40961            return $$('Extensions').$register(name, self);
40962          }, -1)
40963        })(Opal.get_singleton_class(self), $nesting);
40964        return $def(self, '$activate', function $$activate(registry) {
40965          var self = this;
40966
40967          return self.$raise($$$('NotImplementedError'))
40968        });
40969      })($nesting[0], null, $nesting);
40970      (function($base, $super, $parent_nesting) {
40971        var self = $klass($base, $super, 'Registry');
40972
40973        var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype;
40974
40975        $proto.document = $proto.groups = $proto.preprocessor_extensions = $proto.tree_processor_extensions = $proto.postprocessor_extensions = $proto.include_processor_extensions = $proto.docinfo_processor_extensions = $proto.block_extensions = $proto.block_macro_extensions = $proto.inline_macro_extensions = nil;
40976        
40977        self.$attr_reader("document");
40978        self.$attr_reader("groups");
40979        
40980        $def(self, '$initialize', function $$initialize(groups) {
40981          var self = this;
40982
40983          
40984          if (groups == null) groups = $hash2([], {});
40985          self.groups = groups;
40986          self.$reset();
40987          self.preprocessor_extensions = (self.tree_processor_extensions = (self.postprocessor_extensions = (self.include_processor_extensions = (self.docinfo_processor_extensions = (self.block_extensions = (self.block_macro_extensions = (self.inline_macro_extensions = nil)))))));
40988          return (self.document = nil);
40989        }, -1);
40990        
40991        $def(self, '$activate', function $$activate(document) {
40992          var self = this, ext_groups = nil;
40993
40994          
40995          if ($truthy(self.document)) {
40996            self.$reset()
40997          };
40998          self.document = document;
40999          if (!$truthy((ext_groups = $rb_plus($$('Extensions').$groups().$values(), self.groups.$values())
40999)['$empty?']())) {
41000            $send(ext_groups, 'each', [], function $$8(group){var self = $$8.$$s == null ? this : $$8.$$s, $ret_or_1 = nil;
41001
41002              
41003              if (group == null) group = nil;
41004              if ($eqeqeq($$$('Proc'), ($ret_or_1 = group))) {
41005                
41006                switch (group.$arity()) {
41007                  case 0:
41008                  case -1:
41009                    return $send(self, 'instance_exec', [], group.$to_proc())
41010                  case 1:
41011                    return group.$call(self)
41012                  default:
41013                    return nil
41014                }
41015              } else if ($eqeqeq($Class, $ret_or_1)) {
41016                return group.$new().$activate(self)
41017              } else {
41018                return group.$activate(self)
41019              };}, {$$s: self})
41020          };
41021          return self;
41022        });
41023        
41024        $def(self, '$preprocessor', function $$preprocessor($a) {
41025          var block = $$preprocessor.$$p || nil, $post_args, args, self = this;
41026
41027          $$preprocessor.$$p = null;
41028          
41029          ;
41030          $post_args = $slice(arguments);
41031          args = $post_args;
41032          return $send(self, 'add_document_processor', ["preprocessor", args], block.$to_proc());
41033        }, -1);
41034        
41035        $def(self, '$preprocessors?', function $Registry_preprocessors$ques$9() {
41036          var self = this;
41037
41038          return self.preprocessor_extensions['$!']()['$!']()
41039        });
41040        
41041        $def(self, '$preprocessors', $return_ivar("preprocessor_extensions"));
41042        
41043        $def(self, '$tree_processor', function $$tree_processor($a) {
41044          var block = $$tree_processor.$$p || nil, $post_args, args, self = this;
41045
41046          $$tree_processor.$$p = null;
41047          
41048          ;
41049          $post_args = $slice(arguments);
41050          args = $post_args;
41051          return $send(self, 'add_document_processor', ["tree_processor", args], block.$to_proc());
41052        }, -1);
41053        
41054        $def(self, '$tree_processors?', function $Registry_tree_processors$ques$10() {
41055          var self = this;
41056
41057          return self.tree_processor_extensions['$!']()['$!']()
41058        });
41059        
41060        $def(self, '$tree_processors', $return_ivar("tree_processor_extensions"));
41061        $alias(self, "treeprocessor", "tree_processor");
41062        $alias(self, "treeprocessors?", "tree_processors?");
41063        $alias(self, "treeprocessors", "tree_processors");
41064        
41065        $def(self, '$postprocessor', function $$postprocessor($a) {
41066          var block = $$postprocessor.$$p || nil, $post_args, args, self = this;
41067
41068          $$postprocessor.$$p = null;
41069          
41070          ;
41071          $post_args = $slice(arguments);
41072          args = $post_args;
41073          return $send(self, 'add_document_processor', ["postprocessor", args], block.$to_proc());
41074        }, -1);
41075        
41076        $def(self, '$postprocessors?', function $Registry_postprocessors$ques$11() {
41077          var self = this;
41078
41079          return self.postprocessor_extensions['$!']()['$!']()
41080        });
41081        
41082        $def(self, '$postprocessors', $return_ivar("postprocessor_extensions"));
41083        
41084        $def(self, '$include_processor', function $$include_processor($a) {
41085          var block = $$include_processor.$$p || nil, $post_args, args, self = this;
41086
41087          $$include_processor.$$p = null;
41088          
41089          ;
41090          $post_args = $slice(arguments);
41091          args = $post_args;
41092          return $send(self, 'add_document_processor', ["include_processor", args], block.$to_proc());
41093        }, -1);
41094        
41095        $def(self, '$include_processors?', function $Registry_include_processors$ques$12() {
41096          var self = this;
41097
41098          return self.include_processor_extensions['$!']()['$!']()
41099        });
41100        
41101        $def(self, '$include_processors', $return_ivar("include_processor_extensions"));
41102        
41103        $def(self, '$docinfo_processor', function $$docinfo_processor($a) {
41104          var block = $$docinfo_processor.$$p || nil, $post_args, args, self = this;
41105
41106          $$docinfo_processor.$$p = null;
41107          
41108          ;
41109          $post_args = $slice(arguments);
41110          args = $post_args;
41111          return $send(self, 'add_document_processor', ["docinfo_processor", args], block.$to_proc());
41112        }, -1);
41113        
41114        $def(self, '$docinfo_processors?', function $Registry_docinfo_processors$ques$13(location) {
41115          var self = this;
41116
41117          
41118          if (location == null) location = nil;
41119          if ($truthy(self.docinfo_processor_extensions)) {
41120            if ($truthy(location)) {
41121              return $send(self.docinfo_processor_extensions, 'any?', [], function $$14(ext){
41122                
41123                if (ext == null) ext = nil;
41124                return ext.$config()['$[]']("location")['$=='](location);})
41125            } else {
41126              return true
41127            }
41128          } else {
41129            return false
41130          };
41131        }, -1);
41132        
41133        $def(self, '$docinfo_processors', function $$docinfo_processors(location) {
41134          var self = this;
41135
41136          
41137          if (location == null) location = nil;
41138          if ($truthy(self.docinfo_processor_extensions)) {
41139            if ($truthy(location)) {
41140              return $send(self.docinfo_processor_extensions, 'select', [], function $$15(ext){
41141                
41142                if (ext == null) ext = nil;
41143                return ext.$config()['$[]']("location")['$=='](location);})
41144            } else {
41145              return self.docinfo_processor_extensions
41146            }
41147          } else {
41148            return nil
41149          };
41150        }, -1);
41151        
41152        $def(self, '$block', function $$block($a) {
41153          var block = $$block.$$p || nil, $post_args, args, self = this;
41154
41155          $$block.$$p = null;
41156          
41157          ;
41158          $post_args = $slice(arguments);
41159          args = $post_args;
41160          return $send(self, 'add_syntax_processor', ["block", args], block.$to_proc());
41161        }, -1);
41162        
41163        $def(self, '$blocks?', function $Registry_blocks$ques$16() {
41164          var self = this;
41165
41166          return self.block_extensions['$!']()['$!']()
41167        });
41168        
41169        $def(self, '$registered_for_block?', function $Registry_registered_for_block$ques$17(name, context) {
41170          var self = this, ext = nil;
41171
41172          if ($truthy((ext = self.block_extensions['$[]'](name.$to_sym()
41172)))) {
41173            if ($truthy(ext.$config()['$[]']("contexts")['$include?'](context))) {
41174              return ext
41175            } else {
41176              return false
41177            }
41178          } else {
41179            return false
41180          }
41181        });
41182        
41183        $def(self, '$find_block_extension', function $$find_block_extension(name) {
41184          var self = this;
41185
41186          return self.block_extensions['$[]'](name.$to_sym())
41187        });
41188        
41189        $def(self, '$block_macro', function $$block_macro($a) {
41190          var block = $$block_macro.$$p || nil, $post_args, args, self = this;
41191
41192          $$block_macro.$$p = null;
41193          
41194          ;
41195          $post_args = $slice(arguments);
41196          args = $post_args;
41197          return $send(self, 'add_syntax_processor', ["block_macro", args], block.$to_proc());
41198        }, -1);
41199        
41200        $def(self, '$block_macros?', function $Registry_block_macros$ques$18() {
41201          var self = this;
41202
41203          return self.block_macro_extensions['$!']()['$!']()
41204        });
41205        
41206        $def(self, '$registered_for_block_macro?', function $Registry_registered_for_block_macro$ques$19(name) {
41207          var self = this, ext = nil;
41208
41209          if ($truthy((ext = self.block_macro_extensions['$[]'](name.$to_sym())))) {
41210            return ext
41211          } else {
41212            return false
41213          }
41214        });
41215        
41216        $def(self, '$find_block_macro_extension', function $$find_block_macro_extension(name) {
41217          var self = this;
41218
41219          return self.block_macro_extensions['$[]'](name.$to_sym())
41220        });
41221        
41222        $def(self, '$inline_macro', function $$inline_macro($a) {
41223          var block = $$inline_macro.$$p || nil, $post_args, args, self = this;
41224
41225          $$inline_macro.$$p = null;
41226          
41227          ;
41228          $post_args = $slice(arguments);
41229          args = $post_args;
41230          return $send(self, 'add_syntax_processor', ["inline_macro", args], block.$to_proc());
41231        }, -1);
41232        
41233        $def(self, '$inline_macros?', function $Registry_inline_macros$ques$20() {
41234          var self = this;
41235
41236          return self.inline_macro_extensions['$!']()['$!']()
41237        });
41238        
41239        $def(self, '$registered_for_inline_macro?', function $Registry_registered_for_inline_macro$ques$21(name) {
41240          var self = this, ext = nil;
41241
41242          if ($truthy((ext = self.inline_macro_extensions['$[]'](name.$to_sym())))) {
41243            return ext
41244          } else {
41245            return false
41246          }
41247        });
41248        
41249        $def(self, '$find_inline_macro_extension', function $$find_inline_macro_extension(name) {
41250          var self = this;
41251
41252          return self.inline_macro_extensions['$[]'](name.$to_sym())
41253        });
41254        
41255        $def(self, '$inline_macros', function $$inline_macros() {
41256          var self = this;
41257
41258          return self.inline_macro_extensions.$values()
41259        });
41260        
41261        $def(self, '$prefer', function $$prefer($a) {
41262          var block = $$prefer.$$p || nil, $post_args, args, self = this, extension = nil, arg0 = nil, extensions_store = nil;
41263
41264          $$prefer.$$p = null;
41265          
41266          ;
41267          $post_args = $slice(arguments);
41268          args = $post_args;
41269          extension = ($eqeqeq($$('ProcessorExtension'), (arg0 = args.$shift())) ? (arg0) : ($send(self, 'send', [arg0].concat($to_a(args)), block.$to_proc())));
41270          extensions_store = self.$instance_variable_get(((("@") + (extension.$kind())) + "_extensions").$to_sym());
41271          extensions_store.$unshift(extensions_store.$delete(extension));
41272          return extension;
41273        }, -1);
41274        self.$private();
41275        
41276        $def(self, '$add_document_processor', function $$add_document_processor(kind, args) {
41277          var block = $$add_document_processor.$$p || nil, $a, $b, $c, self = this, kind_name = nil, kind_class_symbol = nil, kind_class = nil, kind_java_class = nil, kind_store = nil, $ret_or_1 = nil, config = nil, processor = nil, extension = nil, processor_class = nil, processor_instance = nil;
41278
41279          $$add_document_processor.$$p = null;
41280          
41281          ;
41282          kind_name = kind.$to_s().$tr("_", " ");
41283          kind_class_symbol = $send(kind_name.$split(), 'map', [], function $$22(it){
41284            
41285            if (it == null) it = nil;
41286            return it.$capitalize();}).$join().$to_sym();
41287          kind_class = $$('Extensions').$const_get(kind_class_symbol, false);
41288          kind_java_class = ($truthy((($a = $$$('::', 'AsciidoctorJ', 'skip_raise')) ? 'constant' : nil)) ? ($$$($$$('AsciidoctorJ'), 'Extensions').$const_get(kind_class_symbol, false)) : (nil));
41289          kind_store = ($truthy(($ret_or_1 = self.$instance_variable_get(((("@") + (kind)) + "_extensions").$to_sym()
41289))) ? ($ret_or_1) : (self.$instance_variable_set(((("@") + (kind)) + "_extensions").$to_sym(), [])));
41290          if ((block !== nil)) {
41291            
41292            config = self.$resolve_args(args, 1);
41293            (processor = kind_class.$new(config)).$singleton_class().$enable_dsl();
41294            if ($eqeq(block.$arity(), 0)) {
41295              $send(processor, 'instance_exec', [], block.$to_proc())
41296            } else {
41297              Opal.yield1(block, processor)
41298            };
41299            if (!$truthy(processor['$process_block_given?']())) {
41300              self.$raise($$$('NoMethodError'), "No block specified to process " + (kind_name) + " extension at " + (block.$source_location().$join(":")))
41301            };
41302            processor.$freeze();
41303            extension = $$('ProcessorExtension').$new(kind, processor);
41304          } else {
41305            
41306            $c = self.$resolve_args(args, 2), $b = $to_ary($c), (processor = ($b[0] == null ? nil : $b[0])), (config = ($b[1] == null ? nil : $b[1])), $c;
41307            if ($truthy((processor_class = $$('Helpers').$resolve_class(processor)))) {
41308              
41309              if (!($truthy($rb_lt(processor_class, kind_class)) || (($truthy(kind_java_class) && ($truthy($rb_lt(processor_class, kind_java_class))))))) {
41310                self.$raise($$$('ArgumentError'), "Invalid type for " + (kind_name) + " extension: " + (processor))
41311              };
41312              processor_instance = processor_class.$new(config);
41313              processor_instance.$freeze();
41314              extension = $$('ProcessorExtension').$new(kind, processor_instance);
41315            } else if (($eqeqeq(kind_class, processor) || (($truthy(kind_java_class) && ($eqeqeq(kind_java_class, processor)))))) {
41316              
41317              processor.$update_config(config);
41318              processor.$freeze();
41319              extension = $$('ProcessorExtension').$new(kind, processor);
41320            } else {
41321              self.$raise($$$('ArgumentError'), "Invalid arguments specified for registering " + (kind_name) + " extension: " + (args))
41322            };
41323          };
41324          if ($eqeq(extension.$config()['$[]']("position"), ">>")) {
41325            
41326            kind_store.$unshift(extension);
41327          } else {
41328            
41329            kind_store['$<<'](extension);
41330          };
41331          return extension;
41332        });
41333        
41334        $def(self, '$add_syntax_processor', function $$add_syntax_processor(kind, args) {
41335          var block = $$add_syntax_processor.$$p || nil, $a, $b, $c, self = this, kind_name = nil, kind_class_symbol = nil, kind_class = nil, kind_java_class = nil, kind_store = nil, $ret_or_1 = nil, name = nil, config = nil, processor = nil, processor_class = nil, processor_instance = nil;
41336
41337          $$add_syntax_processor.$$p = null;
41338          
41339          ;
41340          kind_name = kind.$to_s().$tr("_", " ");
41341          kind_class_symbol = $send(kind_name.$split(), 'map', [], function $$23(it){
41342            
41343            if (it == null) it = nil;
41344            return it.$capitalize();})['$<<']("Processor").$join().$to_sym();
41345          kind_class = $$('Extensions').$const_get(kind_class_symbol, false);
41346          kind_java_class = ($truthy((($a = $$$('::', 'AsciidoctorJ', 'skip_raise')) ? 'constant' : nil)) ? ($$$($$$('AsciidoctorJ'), 'Extensions').$const_get(kind_class_symbol, false)) : (nil));
41347          kind_store = ($truthy(($ret_or_1 = self.$instance_variable_get(((("@") + (kind)) + "_extensions").$to_sym()))) ? ($ret_or_1) : (self.$instance_variable_set(((("@") + (kind)) + "_extensions").$to_sym(), $hash2([], {}))));
41348          if ((block !== nil)) {
41349            
41350            $c = self.$resolve_args(args, 2), $b = $to_ary($c), (name = ($b[0] == null ? nil : $b[0])), (config = ($b[1] == null ? nil : $b[1])), $c;
41351            (processor = kind_class.$new(self.$as_symbol(name), config)).$singleton_class().$enable_dsl();
41352            if ($eqeq(block.$arity(), 0)) {
41353              $send(processor, 'instance_exec', [], block.$to_proc())
41354            } else {
41355              Opal.yield1(block, processor)
41356            };
41357            if (!$truthy((name = self.$as_symbol(processor.$name())))) {
41358              self.$raise($$$('ArgumentError'), "No name specified for " + (kind_name) + " extension at " + (block.$source_location().$join(":")))
41359            };
41360            if (!$truthy(processor['$process_block_given?']())) {
41361              self.$raise($$$('NoMethodError'), "No block specified to process " + (kind_name) + " extension at " + (block.$source_location().$join(":")))
41362            };
41363            processor.$freeze();
41364            return ($b = [name, $$('ProcessorExtension').$new(kind, processor)], $send(kind_store, '[]=', $b), $b[$b.length - 1]);
41365          } else {
41366            
41367            $c = self.$resolve_args(args, 3), $b = $to_ary($c), (processor = ($b[0] == null ? nil : $b[0])), (name = ($b[1] == null ? nil : $b[1])), (config = ($b[2] == null ? nil : $b[2])), $c;
41368            if ($truthy((processor_class = $$('Helpers').$resolve_class(processor)))) {
41369              
41370              if (!($truthy($rb_lt(processor_class, kind_class)) || (($truthy(kind_java_class) && ($truthy($rb_lt(processor_class, kind_java_class))))))) {
41371                self.$raise($$$('ArgumentError'), "Class specified for " + (kind_name) + " extension does not inherit from " + (kind_class) + ": " + (processor))
41372              };
41373              processor_instance = processor_class.$new(self.$as_
41373symbol(name), config);
41374              if (!$truthy((name = self.$as_symbol(processor_instance.$name())))) {
41375                self.$raise($$$('ArgumentError'), "No name specified for " + (kind_name) + " extension: " + (processor))
41376              };
41377              processor_instance.$freeze();
41378              return ($b = [name, $$('ProcessorExtension').$new(kind, processor_instance)], $send(kind_store, '[]=', $b), $b[$b.length - 1]);
41379            } else if (($eqeqeq(kind_class, processor) || (($truthy(kind_java_class) && ($eqeqeq(kind_java_class, processor)))))) {
41380              
41381              processor.$update_config(config);
41382              if (!$truthy((name = ($truthy(name) ? (($b = [self.$as_symbol(name)], $send(processor, 'name=', $b), $b[$b.length - 1])) : (self.$as_symbol(processor.$name())))))) {
41383                self.$raise($$$('ArgumentError'), "No name specified for " + (kind_name) + " extension: " + (processor))
41384              };
41385              processor.$freeze();
41386              return ($b = [name, $$('ProcessorExtension').$new(kind, processor)], $send(kind_store, '[]=', $b), $b[$b.length - 1]);
41387            } else {
41388              return self.$raise($$$('ArgumentError'), "Invalid arguments specified for registering " + (kind_name) + " extension: " + (args))
41389            };
41390          };
41391        });
41392        
41393        $def(self, '$reset', function $$reset() {
41394          var self = this;
41395
41396          
41397          self.preprocessor_extensions = (self.tree_processor_extensions = (self.postprocessor_extensions = (self.include_processor_extensions = (self.docinfo_processor_extensions = (self.block_extensions = (self.block_macro_extensions = (self.inline_macro_extensions = nil)))))));
41398          return (self.document = nil);
41399        });
41400        
41401        $def(self, '$resolve_args', function $$resolve_args(args, expect) {
41402          var opts = nil, missing = nil;
41403
41404          
41405          opts = ($eqeqeq($$$('Hash'), args['$[]'](-1)) ? (args.$pop()) : ($hash2([], {})));
41406          if ($eqeq(expect, 1)) {
41407            return opts
41408          };
41409          if ($truthy($rb_gt((missing = $rb_minus($rb_minus(expect, 1), args.$size())), 0))) {
41410            args = $rb_plus(args, $$$('Array').$new(missing))
41411          } else if ($truthy($rb_lt(missing, 0))) {
41412            args.$pop(missing['$-@']())
41413          };
41414          args['$<<'](opts);
41415          return args;
41416        });
41417        return $def(self, '$as_symbol', function $$as_symbol(name) {
41418          
41419          if ($truthy(name)) {
41420            return name.$to_sym()
41421          } else {
41422            return nil
41423          }
41424        });
41425      })($nesting[0], null, $nesting);
41426      return (function(self, $parent_nesting) {
41427        var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
41428
41429        
41430        
41431        $def(self, '$generate_name', function $$generate_name() {
41432          var self = this;
41433
41434          return "extgrp" + (self.$next_auto_id())
41435        });
41436        
41437        $def(self, '$next_auto_id', function $$next_auto_id() {
41438          var self = this, $ret_or_1 = nil;
41439          if (self.auto_id == null) self.auto_id = nil;
41440
41441          
41442          self.auto_id = ($truthy(($ret_or_1 = self.auto_id)) ? ($ret_or_1) : (-1));
41443          return (self.auto_id = $rb_plus(self.auto_id, 1));
41444        });
41445        
41446        $def(self, '$groups', function $$groups() {
41447          var self = this, $ret_or_1 = nil;
41448          if (self.groups == null) self.groups = nil;
41449
41450          return (self.groups = ($truthy(($ret_or_1 = self.groups)) ? ($ret_or_1) : ($hash2([], {}))))
41451        });
41452        
41453        $def(self, '$create', function $$create(name) {
41454          var block = $$create.$$p || nil, self = this, $ret_or_1 = nil;
41455
41456          $$create.$$p = null;
41457          
41458          ;
41459          if (name == null) name = nil;
41460          if ((block !== nil)) {
41461            return $$('Registry').$new($hash(($truthy(($ret_or_1 = name)) ? ($ret_or_1) : (self.$generate_name())), block))
41462          } else {
41463            return $$('Registry').$new()
41464          };
41465        }, -1);
41466        
41467        $def(self, '$register', function $$register($a) {
41468          var block = $$register.$$p || nil, $post_args, args, $b, self = this, argc = nil, resolved_group = nil, group = nil, $ret_or_1 = nil, name = nil;
41469
41470          $$register.$$p = null;
41471          
41472          ;
41473          $post_args = $slice(arguments);
41474          args = $post_args;
41475          argc = args.$size();
41476          if ((block !== nil)) {
41477            resolved_group = block
41478          } else if ($truthy((group = args.$pop()))) {
41479            resolved_group = ($truthy(($ret_or_1 = $$('Helpers').$resolve_class(group))) ? ($ret_or_1) : (group))
41480          } else {
41481            self.$raise($$$('ArgumentError'), "Extension group to register not specified")
41482          };
41483          name = ($truthy(($ret_or_1 = args.$pop())) ? ($ret_or_1) : (self.$generate_name()));
41484          if (!$truthy(args['$empty?']())) {
41485            self.$raise($$$('ArgumentError'), "Wrong number of arguments (" + (argc) + " for 1..2)")
41486          };
41487          return ($b = [name.$to_sym(), resolved_group], $send(self.$groups(), '[]=', $b), $b[$b.length - 1]);
41488        }, -1);
41489        
41490        $def(self, '$unregister_all', function $$unregister_all() {
41491          var self = this;
41492
41493          
41494          self.groups = $hash2([], {});
41495          return nil;
41496        });
41497        return $def(self, '$unregister', function $$unregister($a) {
41498          var $post_args, names, self = this;
41499
41500          
41501          $post_args = $slice(arguments);
41502          names = $post_args;
41503          $send(names, 'each_with_object', [self.$groups()], function $$24(group, catalog){
41504            
41505            if (group == null) group = nil;
41506            if (catalog == null) catalog = nil;
41507            return catalog.$delete(group.$to_sym());});
41508          return nil;
41509        }, -1);
41510      })(Opal.get_singleton_class(self), $nesting);
41511    })($nesting[0], $nesting)
41512  })($nesting[0], $nesting);
41513};
41514
41515Opal.modules["asciidoctor/js/asciidoctor_ext/stylesheet"] = function(Opal) {/* Generated by Opal 1.7.3 */
41516  "use strict";
41517  var $module = Opal.module, $klass = Opal.klass, $truthy = Opal.truthy, $def = Opal.def, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$;
41518
41519  Opal.add_stubs('rstrip,read,join');
41520  return (function($base, $parent_nesting) {
41521    var self = $module($base, 'Asciidoctor');
41522
41523    var $nesting = [self].concat($parent_nesting);
41524
41525    return (function($base, $super) {
41526      var self = $klass($base, $super, 'Stylesheets');
41527
41528      var $proto = self.$$prototype;
41529
41530      $proto.primary_stylesheet_data = nil;
41531      return $def(self, '$primary_stylesheet_data', function $$primary_stylesheet_data() {
41532        var self = this, $ret_or_1 = nil;
41533
41534        return (self.primary_stylesheet_data = ($truthy(($ret_or_1 = self.primary_stylesheet_data)) ? ($ret_or_1) : ($$$('IO').$read($$$('File').$join("css", "asciidoctor.css")).$rstrip())))
41535      })
41536    })($nesting[0], null)
41537  })($nesting[0], $nesting)
41538};
41539
41540Opal.modules["asciidoctor/js/asciidoctor_ext/document"] = function(Opal) {/* Generated by Opal 1.7.3 */
41541  "use strict";
41542  var $module = Opal.module, $klass = Opal.klass, $def = Opal.def, $nesting = [], nil = Opal.nil;
41543
41544  return (function($base, $parent_nesting) {
41545    var self = $module($base, 'Asciidoctor');
41546
41547    var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
41548
41549    return (function($base, $super) {
41550      var self = $klass($base, $super, 'Document');
41551
41552      
41553      return $def(self, '$fill_datetime_attributes', function $$fill_datetime_attributes(attrs, input_mtime) {
41554        
41555        
41556      var $truthy = Opal.truthy
41557      var $falsy = Opal.falsy
41558      var nil = Opal.nil
41559      var utc_offset
41560      var source_date_epoch
41561      var localdate
41562      var localyear
41563      var localtime
41564      var localdatetime
41565      var docdate
41566      var doctime
41567
41568      var getYear = function (time, utc_offset) {
41569        return utc_offset === 0 ? time.getUTCFullYear() : time.getFullYear()
41570      }
41571      var getMonth = function (time, utc_offset) {
41572        return utc_offset === 0 ? time.getUTCMonth() : time.getMonth()
41573      }
41574      var getDay = function (time, utc_offset) {
41575        return utc_offset === 0 ? time.getUTCDate() : time.getDate()
41576      }
41577      var getHours = function (time, utc_offset) {
41578        return utc_offset === 0 ? time.getUTCHours() : time.getHours()
41579      }
41580
41581      var now = new Date()
41582      // See https://reproducible-builds.org/specs/source-date-epoch/
41583      if (Opal.const_get_qualified('::', 'ENV')['$key?']('SOURCE_DATE_EPOCH')) {
41584        now.setTime(parseInt(Opal.const_get_qualified('::', 'ENV')['$[]']('SOURCE_DATE_EPOCH')) * 1000)
41585        source_date_epoch = now
41586        utc_offset = 0  // utc
41587      } else {
41588        utc_offset = -now.getTimezoneOffset() / 60 // local date
41589      }
41590      // localdate and localyear
41591      if ($truthy((localdate = attrs['$[]']('localdate')))) {
41592        if ($falsy(localyear = attrs['$[]']('localyear'))) {
41593          localyear = localdate.indexOf('-') === 4 ? localdate.substring(0, 4) : nil
41594          attrs['$[]=']('localyear', localyear)
41595        }
41596      } else {
41597        var now_year = getYear(now, utc_offset).toString()
41598        var now_month = ('0' + (getMonth(now, utc_offset) + 1)).slice(-2)
41599        var now_day = ('0' + getDay(now, utc_offset)).slice(-2)
41600        localdate = now_year + '-' + now_month + '-' + now_day
41601        attrs['$[]=']('localdate', localdate)
41602        localyear = now_year
41603        attrs['$[]=']('localyear', now_year)
41604      }
41605      // localtime
41606      if ($falsy((localtime = attrs['$[]']('localtime')))) {
41607        var hours = ('0' + (getHours(now, utc_offset))).slice(-2)
41608        var minutes = ('0' + (now.getMinutes())).slice(-2)
41609        var seconds = ('0' + (now.getSeconds())).slice(-2)
41610        var utc_offset_format
41611        if (utc_offset === 0) {
41612          utc_offset_format = 'UTC'
41613        } else if (utc_offset > 0) {
41614          utc_offset_format = ('+0' + (utc_offset * 100)).slice(-5)
41615        } else {
41616          utc_offset_format = ('-0' + (-utc_offset * 100)).slice(-5)
41617        }
41618        localtime = hours + ':' + minutes + ':' + seconds + ' ' + utc_offset_format
41619        attrs['$[]=']('localtime', localtime)
41620      }
41621      // localdatetime
41622      if ($falsy((localdatetime = attrs['$[]']('localdatetime')))) {
41623        localdatetime = localdate + ' ' + localtime
41624        attrs['$[]=']('localdatetime', localdatetime)
41625      }
41626
41627      // docdate, doctime and docdatetime should default to localdate, localtime and localdatetime if not otherwise set
41628      if ($truthy(source_date_epoch)) {
41629        input_mtime = source_date_epoch
41630      } else if ($truthy(input_mtime)) {
41631        utc_offset = -input_mtime.getTimezoneOffset() / 60
41632      } else {
41633        input_mtime = now
41634      }
41635
41636      // docdate and docyear
41637      if ($truthy(docdate = attrs['$[]']('docdate'))) {
41638        attrs['$[]=']('docyear', docdate.indexOf('-') === 4 ? docdate.substring(0, 4) : nil)
41639      } else {
41640        var mtime_year = getYear(input_mtime, utc_offset).toString()
41641        var mtime_month = ('0' + (getMonth(input_mtime, utc_offset) + 1)).slice(-2)
41642        var mtime_day = ('0' + (getDay(input_mtime, utc_offset))).slice(-2)
41643        docdate = mtime_year + '-' + mtime_month + '-' + mtime_day
41644        attrs['$[]=']('docdate', docdate)
41645        if ($falsy(attrs['$[]']('docyear'))) {
41646          attrs['$[]=']('docyear', mtime_year)
41647        }
41648      }
41649      // doctime
41650      if ($falsy(doctime = attrs['$[]']('doctime'))) {
41651        var mtime_hours = ('0' + (getHours(input_mtime, utc_offset))).slice(-2)
41652        var mtime_minutes = ('0' + (input_mtime.getMinutes())).slice(-2)
41653        var mtime_seconds = ('0' + (input_mtime.getSeconds())).slice(-2)
41654        var utc_offset_format
41655        if (utc_offset === 0) {
41656          utc_offset_format = 'UTC'
41657        } else if (utc_offset > 0) {
41658          utc_offset_format = ('+0' + (utc_offset * 100)).slice(-5)
41659        } else {
41660          utc_offset_format = ('-0' + (-utc_offset * 100)).slice(-5)
41661        }
41662        doctime = mtime_hours + ':' + mtime_minutes + ':' + mtime_seconds + ' ' + utc_offset_format
41663        attrs['$[]=']('doctime', doctime)
41664      }
41665      // docdatetime
41666      if ($falsy(attrs['$[]']('docdatetime'))) {
41667        attrs['$[]=']('docdatetime', docdate + ' ' + doctime)
41668      }
41669      return nil
41670    
41671      })
41672    })($nesting[0], $$('AbstractBlock'))
41673  })($nesting[0], $nesting)
41674};
41675
41676Opal.modules["asciidoctor/js/asciidoctor_ext/substitutors"] = function(Opal) {/* Generated by Opal 1.7.3 */
41677  "use strict";
41678  var $module = Opal.module, $def = Opal.def, $nesting = [], nil = Opal.nil;
41679
41680  return (function($base, $parent_nesting) {
41681    var self = $module($base, 'Asciidoctor');
41682
41683    var $nesting = [self].concat($parent_nesting);
41684
41685    return (function($base) {
41686      var self = $module($base, 'Substitutors');
41687
41688      
41689      return $def(self, '$sub_placeholder', function $$sub_placeholder(format_string, replacement) {
41690        
41691        return format_string.replace('%s', replacement);
41692      })
41693    })($nesting[0])
41694  })($nesting[0], $nesting)
41695};
41696
41697Opal.modules["asciidoctor/js/asciidoctor_ext/parser"] = function(Opal) {/* Generated by Opal 1.7.3 */
41698  "use strict";
41699  var $module = Opal.module, $klass = Opal.klass, $truthy = Opal.truthy, $defs = Opal.defs, $nesting = [], nil = Opal.nil;
41700
41701  return (function($base, $parent_nesting) {
41702    var self = $module($base, 'Asciidoctor');
41703
41704    var $nesting = [self].concat($parent_nesting);
41705
41706    return (function($base, $super) {
41707      var self = $klass($base, $super, 'Parser');
41708
41709      
41710      if ($truthy(String.prototype.repeat)) {
41711        return $defs(self, '$uniform?', function $Parser_uniform$ques$1(str, chr, len) {
41712          
41713          return chr.repeat(len) === str;
41714        })
41715      } else {
41716        return $defs(self, '$uniform?', function $Parser_uniform$ques$2(str, chr, len) {
41717          
41718          return Array.apply(null, { length: len }).map(function () { return chr }).join('') === str;
41719        })
41720      }
41721    })($nesting[0], null)
41722  })($nesting[0], $nesting)
41723};
41724
41725Opal.modules["asciidoctor/js/asciidoctor_ext/syntax_highlighter"] = function(Opal) {/* Generated by Opal 1.7.3 */
41726  "use strict";
41727  var $module = Opal.module, $truthy = Opal.truthy, $def = Opal.def, $nesting = [], nil = Opal.nil;
41728
41729  Opal.add_stubs('key?,registry,[],include?,include,empty?,debug,logger,join,keys');
41730  return (function($base, $parent_nesting) {
41731    var self = $module($base, 'Asciidoctor');
41732
41733    var $nesting = [self].concat($parent_nesting);
41734
41735    return (function($base, $parent_nesting) {
41736      var self = $module($base, 'SyntaxHighlighter');
41737
41738      var $nesting = [self].concat($parent_nesting);
41739
41740      return (function($base, $parent_nesting) {
41741        var self = $module($base, 'Factory');
41742
41743        var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting);
41744
41745        return $def(self, '$for', function $Factory_for$1(name) {
41746          var self = this;
41747
41748          if ($truthy(self.$registry()['$key?'](name))) {
41749            return self.$registry()['$[]'](name)
41750          } else {
41751            
41752            if (!$truthy(self['$include?']($$('Logging')))) {
41753              self.$include($$('Logging'))
41754            };
41755            if ($truthy(self.$registry()['$empty?']())) {
41756              self.$logger().$debug("no syntax highlighter available, functionality disabled.")
41757            } else {
41758              self.$logger().$debug("syntax highlighter named '" + (name) + "' is not available, must be one of: '" + (self.$registry().$keys().$join("', '")) + "'.")
41759            };
41760            return nil;
41761          }
41762        })
41763      })($nesting[0], $nesting)
41764    })($nesting[0], $nesting)
41765  })($nesting[0], $nesting)
41766};
41767
41768Opal.modules["asciidoctor/js/asciidoctor_ext"] = function(Opal) {/* Generated by Opal 1.7.3 */
41769  "use strict";
41770  var self = Opal.top, nil = Opal.nil;
41771
41772  Opal.add_stubs('require');
41773  
41774  self.$require("asciidoctor/js/asciidoctor_ext/stylesheet");
41775  self.$require("asciidoctor/js/asciidoctor_ext/document");
41776  self.$require("asciidoctor/js/asciidoctor_ext/substitutors");
41777  self.$require("asciidoctor/js/asciidoctor_ext/parser");
41778  self.$require("asciidoctor/js/asciidoctor_ext/syntax_highlighter");
41779  
41780// Load specific runtime
41781self.$require("asciidoctor/js/asciidoctor_ext/browser");
41782;
41783};
41784
41785Opal.modules["asciidoctor/js/opal_ext/logger"] = function(Opal) {/* Generated by Opal 1.7.3 */
41786  "use strict";
41787  var $klass = Opal.klass, $def = Opal.def, $truthy = Opal.truthy, $rb_lt = Opal.rb_lt, $nesting = [], nil = Opal.nil;
41788
41789  Opal.add_stubs('chr,rjust,message_as_string,<,write,call,[]');
41790  return (function($base, $super, $parent_nesting) {
41791    var self = $klass($base, $super, 'Logger');
41792
41793    var $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $proto = self.$$prototype;
41794
41795    $proto.level = $proto.progname = $proto.pipe = $proto.formatter = nil;
41796    
41797    (function($base, $super) {
41798      var self = $klass($base, $super, 'Formatter');
41799
41800      
41801      return $def(self, '$call', function $$call(severity, time, progname, msg) {
41802        var self = this, time_format = nil;
41803
41804        
41805        time_format = time.getFullYear() + '-' + ('0'+(time.getMonth()+1)).slice(-2) + '-' + ('0'+time.getDate()).slice(-2) + 'T' + ('0'+time.getHours()).slice(-2) + ':' + ('0'+time.getMinutes()).slice(-2) + ':' + ('0'+time.getSeconds()).slice(-2) + '.' + ('00' + new Date().getMilliseconds() * 1000).slice(-6);
41806        return "" + (severity.$chr()) + ", [" + (time_format) + "] " + (severity.$rjust(5)) + " -- " + (progname) + ": " + (self.$message_as_string(msg));
41807      })
41808    })($nesting[0], null);
41809    return $def(self, '$add', function $$add(severity, message, progname) {
41810      var block = $$add.$$p || nil, self = this, $ret_or_1 = nil;
41811
41812      $$add.$$p = null;
41813      
41814      ;
41815      if (message == null) message = nil;
41816      if (progname == null) progname = nil;
41817      if ($truthy($rb_lt((severity = ($truthy(($ret_or_1 = severity)
41817) ? ($ret_or_1) : ($$('UNKNOWN')))), self.level))) {
41818        return true
41819      };
41820      progname = ($truthy(($ret_or_1 = progname)) ? ($ret_or_1) : (self.progname));
41821      if (!$truthy(message)) {
41822        if ((block !== nil)) {
41823          message = Opal.yieldX(block, [])
41824        } else {
41825          
41826          message = progname;
41827          progname = self.progname;
41828        }
41829      };
41830      self.pipe.$write(self.formatter.$call(($truthy(($ret_or_1 = $$('SEVERITY_LABELS')['$[]'](severity))) ? ($ret_or_1) : ("ANY")), new Date(), progname, message));
41831      return true;
41832    }, -2);
41833  })($nesting[0], null, $nesting)
41834};
41835
41836Opal.modules["asciidoctor/js/postscript"] = function(Opal) {/* Generated by Opal 1.7.3 */
41837  "use strict";
41838  var self = Opal.top, nil = Opal.nil;
41839
41840  Opal.add_stubs('require');
41841  
41842  self.$require("asciidoctor/converter/composite");
41843  self.$require("asciidoctor/converter/html5");
41844  self.$require("asciidoctor/extensions");
41845  self.$require("asciidoctor/js/asciidoctor_ext");
41846  return self.$require("asciidoctor/js/opal_ext/logger");
41847};
41848
41849Opal.queue(function(Opal) {/* Generated by Opal 1.7.3 */
41850  "use strict";
41851  var $module = Opal.module, $const_set = Opal.const_set, $send = Opal.send, $to_ary = Opal.to_ary, $defs = Opal.defs, $def = Opal.def, $truthy = Opal.truthy, $hash2 = Opal.hash2, $eqeq = Opal.eqeq, $rb_minus = Opal.rb_minus, $regexp = Opal.regexp, self = Opal.top, $nesting = [], nil = Opal.nil, $$$ = Opal.$$$;
41852
41853  Opal.add_stubs('require,==,to_h,sort,map,constants,const_get,downcase,to_s,<=>,upcase,[],values,new,attr_reader,instance_variable_set,send,singleton_class,<<,define,dirname,absolute_path,join,home,pwd,to_set,tap,each,chr,each_key,[]=,slice,length,-,merge,default=,drop,insert');
41854  
41855  self.$require("set");
41856  self.$require("asciidoctor/js");
41857  (function($base, $parent_nesting) {
41858    var self = $module($base, 'Asciidoctor');
41859
41860    var $a, $nesting = [self].concat($parent_nesting), $$ = Opal.$r($nesting), $ret_or_1 = nil;
41861
41862    
41863    $const_set($nesting[0], 'RUBY_ENGINE_OPAL', $const_set($nesting[0], 'RUBY_ENGINE', $$$('RUBY_ENGINE'))['$==']("opal"));
41864    (function($base, $parent_nesting) {
41865      var self = $module($base, 'SafeMode');
41866
41867      var $nesting = [self].concat($parent_nesting);
41868
41869      
41870      $const_set($nesting[0], 'UNSAFE', 0);
41871      $const_set($nesting[0], 'SAFE', 1);
41872      $const_set($nesting[0], 'SERVER', 10);
41873      $const_set($nesting[0], 'SECURE', 20);
41874      self.names_by_value = $send($send(self.$constants(false), 'map', [], function $SafeMode$1(sym){var self = $SafeMode$1.$$s == null ? this : $SafeMode$1.$$s;
41875
41876        
41877        if (sym == null) sym = nil;
41878        return [self.$const_get(sym), sym.$to_s().$downcase()];}, {$$s: self}), 'sort', [], function $SafeMode$2($mlhs_tmp1, $mlhs_tmp2){var $a, $b, a = nil, b = nil;
41879
41880        
41881        if ($mlhs_tmp1 == null) $mlhs_tmp1 = nil;
41882        if ($mlhs_tmp2 == null) $mlhs_tmp2 = nil;
41883        $b = $mlhs_tmp1, $a = $to_ary($b), (a = ($a[0] == null ? nil : $a[0])), $b;
41884        $b = $mlhs_tmp2, $a = $to_ary($b), (b = ($a[0] == null ? nil : $a[0])), $b;
41885        return a['$<=>'](b);}, {$$has_top_level_mlhs_arg: true}).$to_h();
41886      $defs(self, '$value_for_name', function $$value_for_name(name) {
41887        var self = this;
41888
41889        return self.$const_get(name.$upcase(), false)
41890      });
41891      $defs(self, '$name_for_value', function $$name_for_value(value) {
41892        var self = this;
41893        if (self.names_by_value == null) self.names_by_value = nil;
41894
41895        return self.names_by_value['$[]'](value)
41896      });
41897      return $defs(self, '$names', function $$names() {
41898        var self = this;
41899        if (self.names_by_value == null) self.names_by_value = nil;
41900
41901        return self.names_by_value.$values()
41902      });
41903    })($nesting[0], $nesting);
41904    (function($base, $parent_nesting) {
41905      var self = $module($base, 'Compliance');
41906
41907      var $nesting = [self].concat($parent_nesting);
41908
41909      
41910      self.keys = $$$('Set').$new();
41911      (function(self, $parent_nesting) {
41912        
41913        
41914        self.$attr_reader("keys");
41915        return $def(self, '$define', function $$define(key, value) {
41916          var self = this;
41917          if (self.keys == null) self.keys = nil;
41918
41919          
41920          self.$instance_variable_set("@" + (key), value);
41921          self.$singleton_class().$send("attr_accessor", key);
41922          self.keys['$<<'](key);
41923          return nil;
41924        });
41925      })(Opal.get_singleton_class(self), $nesting);
41926      self.$define("block_terminates_paragraph", true);
41927      self.$define("strict_verbatim_paragraphs", true);
41928      self.$define("underline_style_section_titles", true);
41929      self.$define("unwrap_standalone_preamble", true);
41930      self.$define("attribute_missing", "skip");
41931      self.$define("attribute_undefined", "drop-line");
41932      self.$define("shorthand_property_syntax", true);
41933      self.$define("natural_xrefs", true);
41934      self.$define("unique_id_start_index", 2);
41935      return self.$define("markdown_syntax", true);
41936    })($nesting[0], $nesting);
41937    if (!$truthy((($a = $$('ROOT_DIR', 'skip_raise')) ? 'constant' : nil))) {
41938      $const_set($nesting[0], 'ROOT_DIR', $$$('File').$dirname($$$('File').$absolute_path(".")))
41939    };
41940    $const_set($nesting[0], 'LIB_DIR', $$$('File').$join($$('ROOT_DIR'), "lib"));
41941    $const_set($nesting[0], 'DATA_DIR', $$$('File').$join($$('ROOT_DIR'), "data"));
41942    $const_set($nesting[0], 'USER_HOME', (function() { try {
41943      return $$$('Dir').$home()
41944    } catch ($err) {
41945      if (Opal.rescue($err, [$$('StandardError')])) {
41946        try {
41947          
41948          if ($truthy(($ret_or_1 = $$$('ENV')['$[]']("HOME")))) {
41949            return $ret_or_1
41950          } else {
41951            return $$$('Dir').$pwd()
41952          };
41953        } finally { Opal.pop_exception(); }
41954      } else { throw $err; }
41955    }})());
41956    $const_set($nesting[0], 'LF', "\n");
41957    $const_set($nesting[0], 'NULL', "\x00");
41958    $const_set($nesting[0], 'TAB', "\t");
41959    $const_set($nesting[0], 'MAX_INT', 9007199254740991);
41960    $const_set($nesting[0], 'UTF_8', $$$($$$('Encoding'), 'UTF_8'));
41961    $const_set($nesting[0], 'BOM_BYTES_UTF_8', [239, 187, 191]);
41962    $const_set($nesting[0], 'BOM_BYTES_UTF_16LE', [255, 254]);
41963    $const_set($nesting[0], 'BOM_BYTES_UTF_16BE', [254, 255]);
41964    $const_set($nesting[0], 'FILE_READ_MODE', ($truthy($$('RUBY_ENGINE_OPAL')) ? ("r") : ("rb:utf-8:utf-8")));
41965    $const_set($nesting[0], 'URI_READ_MODE', $$('FILE_READ_MODE'));
41966    $const_set($nesting[0], 'FILE_WRITE_MODE', ($truthy($$('RUBY_ENGINE_OPAL')) ? ("w") : ("w:utf-8")));
41967    $const_set($nesting[0], 'DEFAULT_DOCTYPE', "article");
41968    $const_set($nesting[0], 'DEFAULT_BACKEND', "html5");
41969    $const_set($nesting[0], 'DEFAULT_STYLESHEET_KEYS', ["", "DEFAULT"].$to_set());
41970    $const_set($nesting[0], 'DEFAULT_STYLESHEET_NAME', "asciidoctor.css");
41971    $const_set($nesting[0], 'BACKEND_ALIASES', $hash2(["html", "docbook"], {"html": "html5", "docbook": "docbook5"}));
41972    $const_set($nesting[0], 'DEFAULT_PAGE_WIDTHS', $hash2(["docbook"], {"docbook": 425}));
41973    $const_set($nesting[0], 'DEFAULT_EXTENSIONS', $hash2(["html", "docbook", "pdf", "epub", "manpage", "asciidoc"], {"html": ".html", "docbook": ".xml", "pdf": ".pdf", "epub": ".epub", "manpage": ".man", "asciidoc": ".adoc"}));
41974    $const_set($nesting[0], 'ASCIIDOC_EXTENSIONS', $hash2([".adoc", ".asciidoc", ".asc", ".ad", ".txt"], {".adoc": true, ".asciidoc": true, ".asc": true, ".ad": true, ".txt": true}));
41975    $const_set($nesting[0], 'SETEXT_SECTION_LEVELS', $hash2(["=", "-", "~", "^", "+"], {"=": 0, "-": 1, "~": 2, "^": 3, "+": 4}));
41976    $const_set($nesting[0], 'ADMONITION_STYLES', ["NOTE", "TIP", "IMPORTANT", "WARNING", "CAUTION"].$to_set());
41977    $const_set($nesting[0], 'ADMONITION_STYLE_HEADS', $send($$$('Set').$new(), 'tap', [], function $Asciidoctor$3(accum){
41978      
41979      if (accum == null) accum = nil;
41980      return $send($$('ADMONITION_STYLES'), 'each', [], function $$4(s){
41981        
41982        if (s == null) s = nil;
41983        return accum['$<<'](s.$chr());});}));
41984    $const_set($nesting[0], 'PARAGRAPH_STYLES', ["comment", "example", "literal", "listing", "normal", "open", "pass", "quote", "sidebar", "source", "verse", "abstract", "partintro"].$to_set());
41985    $const_set($nesting[0], 'VERBATIM_STYLES', ["literal", "listing", "source", "verse"].$to_set());
41986    $const_set($nesting[0], 'DELIMITED_BLOCKS', $hash2(["--", "----", "....", "====", "****", "____", "++++", "|===", ",===", ":===", "!===", "////", "```"], {"--": ["open", ["comment", "example", "literal", "listing", "pass", "quote", "sidebar", "source", "verse", "admonition", "abstract", "partintro"].$to_set()], "----": ["listing", ["literal", "source"].$to_set()], "....": ["literal", ["listing", "source"].$to_set()], "====": ["example", ["admonition"].$to_set()], "****": ["sidebar", $$$('Set').$new()], "____": ["quote", ["ver
41986se"].$to_set()], "++++": ["pass", ["stem", "latexmath", "asciimath"].$to_set()], "|===": ["table", $$$('Set').$new()], ",===": ["table", $$$('Set').$new()], ":===": ["table", $$$('Set').$new()], "!===": ["table", $$$('Set').$new()], "////": ["comment", $$$('Set').$new()], "```": ["fenced_code", $$$('Set').$new()]}));
41987    $const_set($nesting[0], 'DELIMITED_BLOCK_HEADS', $send($hash2([], {}), 'tap', [], function $Asciidoctor$5(accum){
41988      
41989      if (accum == null) accum = nil;
41990      return $send($$('DELIMITED_BLOCKS'), 'each_key', [], function $$6(k){var $b;
41991
41992        
41993        if (k == null) k = nil;
41994        return ($b = [k.$slice(0, 2), true], $send(accum, '[]=', $b), $b[$b.length - 1]);});}));
41995    $const_set($nesting[0], 'DELIMITED_BLOCK_TAILS', $send($hash2([], {}), 'tap', [], function $Asciidoctor$7(accum){
41996      
41997      if (accum == null) accum = nil;
41998      return $send($$('DELIMITED_BLOCKS'), 'each_key', [], function $$8(k){var $b;
41999
42000        
42001        if (k == null) k = nil;
42002        if ($eqeq(k.$length(), 4)) {
42003          return ($b = [k, k['$[]']($rb_minus(k.$length(), 1))], $send(accum, '[]=', $b), $b[$b.length - 1])
42004        } else {
42005          return nil
42006        };});}));
42007    $const_set($nesting[0], 'CAPTION_ATTRIBUTE_NAMES', $hash2(["example", "figure", "listing", "table"], {"example": "example-caption", "figure": "figure-caption", "listing": "listing-caption", "table": "table-caption"}));
42008    $const_set($nesting[0], 'LAYOUT_BREAK_CHARS', $hash2(["'", "<"], {"'": "thematic_break", "<": "page_break"}));
42009    $const_set($nesting[0], 'MARKDOWN_THEMATIC_BREAK_CHARS', $hash2(["-", "*", "_"], {"-": "thematic_break", "*": "thematic_break", "_": "thematic_break"}));
42010    $const_set($nesting[0], 'HYBRID_LAYOUT_BREAK_CHARS', $$('LAYOUT_BREAK_CHARS').$merge($$('MARKDOWN_THEMATIC_BREAK_CHARS')));
42011    $const_set($nesting[0], 'NESTABLE_LIST_CONTEXTS', ["ulist", "olist", "dlist"]);
42012    $const_set($nesting[0], 'ORDERED_LIST_STYLES', ["arabic", "loweralpha", "lowerroman", "upperalpha", "upperroman"]);
42013    $const_set($nesting[0], 'ORDERED_LIST_KEYWORDS', $hash2(["loweralpha", "lowerroman", "upperalpha", "upperroman"], {"loweralpha": "a", "lowerroman": "i", "upperalpha": "A", "upperroman": "I"}));
42014    $const_set($nesting[0], 'ATTR_REF_HEAD', "{");
42015    $const_set($nesting[0], 'LIST_CONTINUATION', "+");
42016    $const_set($nesting[0], 'HARD_LINE_BREAK', " +");
42017    $const_set($nesting[0], 'LINE_CONTINUATION', " \\");
42018    $const_set($nesting[0], 'LINE_CONTINUATION_LEGACY', " +");
42019    $const_set($nesting[0], 'BLOCK_MATH_DELIMITERS', $hash2(["asciimath", "latexmath"], {"asciimath": ["\\$", "\\$"], "latexmath": ["\\[", "\\]"]}));
42020    $const_set($nesting[0], 'INLINE_MATH_DELIMITERS', $hash2(["asciimath", "latexmath"], {"asciimath": ["\\$", "\\$"], "latexmath": ["\\(", "\\)"]}));
42021    $const_set($nesting[0], 'STEM_TYPE_ALIASES', $hash2(["latexmath", "latex", "tex"], {"latexmath": "latexmath", "latex": "latexmath", "tex": "latexmath"}))['$default=']("asciimath");
42022    $const_set($nesting[0], 'FONT_AWESOME_VERSION', "4.7.0");
42023    $const_set($nesting[0], 'HIGHLIGHT_JS_VERSION', "9.18.3");
42024    $const_set($nesting[0], 'MATHJAX_VERSION', "2.7.9");
42025    $const_set($nesting[0], 'DEFAULT_ATTRIBUTES', $hash2(["appendix-caption", "appendix-refsig", "caution-caption", "chapter-refsig", "example-caption", "figure-caption", "important-caption", "last-update-label", "note-caption", "part-refsig", "prewrap", "sectids", "section-refsig", "table-caption", "tip-caption", "toc-placement", "toc-title", "untitled-label", "version-label", "warning-caption"], {"appendix-caption": "Appendix", "appendix-refsig": "Appendix", "caution-caption": "Caution", "chapter-refsig": "Chapter", "example-caption": "Example", "figure-caption": "Figure", "important-caption": "Important", "last-update-label": "Last updated", "note-caption": "Note", "part-refsig": "Part", "prewrap": "", "sectids": "", "section-refsig": "Section", "table-caption": "Table", "tip-caption": "Tip", "toc-placement": "auto", "toc-title": "Table of Contents", "untitled-label": "Untitled", "version-label": "Version", "warning-caption": "Warning"}));
42026    $const_set($nesting[0], 'FLEXIBLE_ATTRIBUTES', ["sectnums"]);
42027    $const_set($nesting[0], 'INTRINSIC_ATTRIBUTES', $hash2(["startsb", "endsb", "vbar", "caret", "asterisk", "tilde", "plus", "backslash", "backtick", "blank", "empty", "sp", "two-colons", "two-semicolons", "nbsp", "deg", "zwsp", "quot", "apos", "lsquo", "rsquo", "ldquo", "rdquo", "wj", "brvbar", "pp", "cpp", "amp", "lt", "gt"], {"startsb": "[", "endsb": "]", "vbar": "|", "caret": "^", "asterisk": "*", "tilde": "~", "plus": "&#43;", "backslash": "\\", "backtick": "`", "blank": "", "empty": "", "sp": " ", "two-colons": "::", "two-semicolons": ";;", "nbsp": "&#160;", "deg": "&#176;", "zwsp": "&#8203;", "quot": "&#34;", "apos": "&#39;", "lsquo": "&#8216;", "rsquo": "&#8217;", "ldquo": "&#8220;", "rdquo": "&#8221;", "wj": "&#8288;", "brvbar": "&#166;", "pp": "&#43;&#43;", "cpp": "C&#43;&#43;", "amp": "&", "lt": "<", "gt": ">"}));
42028    nil;
42029    $const_set($nesting[0], 'QUOTE_SUBS', $send($hash2([], {}), 'tap', [], function $Asciidoctor$9(accum){var normal = nil, compat = nil;
42030
42031      
42032      if (accum == null) accum = nil;
42033      accum['$[]='](false, (normal = [["strong", "unconstrained", $regexp(["\\\\?(?:\\[([^\\]]+)\\])?\\*\\*(", $$('CC_ALL'), "+?)\\*\\*"], 'm')], ["strong", "constrained", $regexp(["(^|[^", $$('CC_WORD'), ";:}])(?:\\[([^\\]]+)\\])?\\*(\\S|\\S", $$('CC_ALL'), "*?\\S)\\*(?!", $$('CG_WORD'), ")"], 'm')], ["double", "constrained", $regexp(["(^|[^", $$('CC_WORD'), ";:}])(?:\\[([^\\]]+)\\])?\"`(\\S|\\S", $$('CC_ALL'), "*?\\S)`\"(?!", $$('CG_WORD'), ")"], 'm')], ["single", "constrained", $regexp(["(^|[^", $$('CC_WORD'), ";:`}])(?:\\[([^\\]]+)\\])?'`(\\S|\\S", $$('CC_ALL'), "*?\\S)`'(?!", $$('CG_WORD'), ")"], 'm')], ["monospaced", "unconstrained", $regexp(["\\\\?(?:\\[([^\\]]+)\\])?``(", $$('CC_ALL'), "+?)``"], 'm')], ["monospaced", "constrained", $regexp(["(^|[^", $$('CC_WORD'), ";:\"'`}])(?:\\[([^\\]]+)\\])?`(\\S|\\S", $$('CC_ALL'), "*?\\S)`(?![", $$('CC_WORD'), "\"'`])"], 'm')], ["emphasis", "unconstrained", $regexp(["\\\\?(?:\\[([^\\]]+)\\])?__(", $$('CC_ALL'), "+?)__"], 'm')], ["emphasis", "constrained", $regexp(["(^|[^", $$('CC_WORD'), ";:}])(?:\\[([^\\]]+)\\])?_(\\S|\\S", $$('CC_ALL'), "*?\\S)_(?!", $$('CG_WORD'), ")"], 'm')], ["mark", "unconstrained", $regexp(["\\\\?(?:\\[([^\\]]+)\\])?##(", $$('CC_ALL'), "+?)##"], 'm')], ["mark", "constrained", $regexp(["(^|[^", $$('CC_WORD'), "&;:}])(?:\\[([^\\]]+)\\])?#(\\S|\\S", $$('CC_ALL'), "*?\\S)#(?!", $$('CG_WORD'), ")"], 'm')], ["superscript", "unconstrained", /\\?(?:\[([^\]]+)\])?\^(\S+?)\^/], ["subscript", "unconstrained", /\\?(?:\[([^\]]+)\])?~(\S+?)~/]]));
42034      accum['$[]='](true, (compat = normal.$drop(0)));
42035      compat['$[]='](2, ["double", "constrained", $regexp(["(^|[^", $$('CC_WORD'), ";:}])(?:\\[([^\\]]+)\\])?``(\\S|\\S", $$('CC_ALL'), "*?\\S)''(?!", $$('CG_WORD'), ")"], 'm')]);
42036      compat['$[]='](3, ["single", "constrained", $regexp(["(^|[^", $$('CC_WORD'), ";:}])(?:\\[([^\\]]+)\\])?`(\\S|\\S", $$('CC_ALL'), "*?\\S)'(?!", $$('CG_WORD'), ")"], 'm')]);
42037      compat['$[]='](4, ["monospaced", "unconstrained", $regexp(["\\\\?(?:\\[([^\\]]+)\\])?\\+\\+(", $$('CC_ALL'), "+?)\\+\\+"], 'm')]);
42038      compat['$[]='](5, ["monospaced", "constrained", $regexp(["(^|[^", $$('CC_WORD'), ";:}])(?:\\[([^\\]]+)\\])?\\+(\\S|\\S", $$('CC_ALL'), "*?\\S)\\+(?!", $$('CG_WORD'), ")"], 'm')]);
42039      return compat.$insert(3, ["emphasis", "constrained", $regexp(["(^|[^", $$('CC_WORD'), ";:}])(?:\\[([^\\]]+)\\])?'(\\S|\\S", $$('CC_ALL'), "*?\\S)'(?!", $$('CG_WORD'), ")"], 'm')]);}));
42040    $const_set($nesting[0], 'REPLACEMENTS', [[/\\?\(C\)/, "&#169;", "none"], [/\\?\(R\)/, "&#174;", "none"], [/\\?\(TM\)/, "&#8482;", "none"], [/(?: |\n|^|\\)--(?: |\n|$)/, "&#8201;&#8212;&#8201;", "none"], [$regexp(["(", $$('CG_WORD'), ")\\\\?--(?=", $$('CG_WORD'), ")"]), "&#8212;&#8203;", "leading"], [/\\?\.\.\./, "&#8230;&#8203;", "none"], [/\\?`'/, "&#8217;", "none"], [$regexp(["(", $$('CG_ALNUM'), ")\\\\?'(?=", $$('CG_ALPHA'), ")"]), "&#8217;", "leading"], [/\\?-&gt;/, "&#8594;", "none"], [/\\?=&gt;/, "&#8658;", "none"], [/\\?&lt;-/, "&#8592;", "none"], [/\\?&lt;=/, "&#8656;", "none"], [/\\?(&)amp;((?:[a-zA-Z][a-zA-Z]+\d{0,2}|#\d\d\d{0,4}|#x[\da-fA-F][\da-fA-F][\da-fA-F]{0,3});)/, "", "bounding"]]);
42041    nil;
42042    return nil;
42043  })($nesting[0], $nesting);
42044  self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/core_ext");
42045  self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/helpers");
42046  self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/logging");
42047  self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/rx");
42048  self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/substitutors");
42049  self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/version");
42050  self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/abstract_node");
42051  self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/abstract_block");
42052  self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/attribute_list");
42053  self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/block");
42054  self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/callouts");
42055  self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/converter");
42056  self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/document");
42057  self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/inline");
42058  self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/list");
42059  self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/parser");
42060  self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/path_resolver");
42061  self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/reader");
42062  self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/section");
42063  self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/stylesheets");
42064  self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/table");
42065  self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/writer");
42066  self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/load");
42067  self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/convert");
42068  
42069  self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/syntax_highlighter");
42070  self.$require("asciidoctor.rb"+ '/../' + "asciidoctor/timings");
42071  return self.$require("asciidoctor/js/postscript");;
42072});
42073
42074
42075/* global Opal */
42076
42077/**
42078 * Convert a JSON to an (Opal) Hash.
42079 * @private
42080 */
42081const toHash = function (object) {
42082  return object && !object.$$is_hash ? Opal.hash2(Object.keys(object), object) : object
42083}
42084
42085/**
42086 * Convert an (Opal) Hash to JSON.
42087 * @private
42088 */
42089const fromHash = function (hash) {
42090  const object = {}
42091  if (hash) {
42092    const stringMap = hash.$$smap
42093    for (const key in stringMap) {
42094      const value = stringMap[key]
42095      object[key] = value === Opal.nil ? undefined : value
42096    }
42097    const numericMap = hash.$$map
42098    if (numericMap) {
42099      const positional = []
42100      for (const key in numericMap) {
42101        const entry = numericMap[key]
42102        const value = entry.value
42103        const index = entry.key - 1
42104        positional[index] = value === Opal.nil ? undefined : value
42105      }
42106      if (positional.length > 0) {
42107        object.$positional = positional
42108      }
42109    }
42110  }
42111  return object
42112}
42113
42114const fromHashKeys = function (hash) {
42115  const object = {}
42116  if (hash) {
42117    const data = hash.$$keys
42118    for (const key in data) {
42119      const value = data[key].value
42120      object[key.toString()] = value === Opal.nil ? undefined : value
42121    }
42122  }
42123  return object
42124}
42125
42126/**
42127 * @private
42128 */
42129const prepareOptions = function (options) {
42130  options = toHash(options)
42131  if (options) {
42132    const converter = options['$[]']('converter')
42133    if (converter && converter !== Opal.nil) {
42134      options['$[]=']('converter', bridgeConverter(converter))
42135    }
42136    const attrs = options['$[]']('attributes')
42137    if (attrs && typeof attrs === 'object' && attrs.constructor.name === 'Object') {
42138      options = options.$dup()
42139      options['$[]=']('attributes', toHash(attrs))
42140    }
42141  }
42142  return options
42143}
42144
42145const bridgeConverter = function (converter) {
42146  const buildBackendTraitsFromObject = function (obj) {
42147    return Object.assign({},
42148      obj.basebackend ? { basebackend: obj.basebackend } : {},
42149      obj.outfilesuffix ? { outfilesuffix: obj.outfilesuffix } : {},
42150      obj.filetype ? { filetype: obj.filetype } : {},
42151      obj.htmlsyntax ? { htmlsyntax: obj.htmlsyntax } : {},
42152      obj.supports_templates ? { supports_templates: obj.supports_templates } : {}
42153    )
42154  }
42155  const assignBackendTraitsToInstance = function (obj, instance) {
42156    if (obj.backend_traits) {
42157      instance.backend_traits = toHash(obj.backend_traits)
42158    } else if (obj.backendTraits) {
42159      instance.backend_traits = toHash(obj.backendTraits)
42160    } else if (obj.basebackend || obj.outfilesuffix || obj.filetype || obj.htmlsyntax || obj.supports_templates) {
42161      instance.backend_traits = toHash(buildBackendTraitsFromObject(obj))
42162    }
42163  }
42164  const bridgeHandlesMethodToInstance = function (obj, instance) {
42165    bridgeMethodToInstance(obj, instance, '$handles?', 'handles', function () {
42166      return true
42167    })
42168  }
42169  const bridgeComposedMethodToInstance = function (obj, instance) {
42170    bridgeMethodToInstance(obj, instance, '$composed', 'composed')
42171  }
42172  const bridgeEqEqMethodToInstance = function (obj, instance) {
42173    bridgeMethodToInstance(obj, instance, '$==', '==', function (other) {
42174      return instance === other
42175    })
42176  }
42177  const bridgeSendMethodToInstance = function (obj, instance) {
42178    bridgeMethodToInstance(obj, instance, '$send', 'send', function (symbol) {
42179      const [, ...args] = Array.from(arguments)
42180      const func = instance['$' + symbol]
42181      if (func) {
42182        return func.apply(instance, args)
42183      }
42184      throw new Error(`undefined method \`${symbol}\` for \`${instance.toString()}\``)
42185    })
42186  }
42187  const bridgeMethodToInstance = function (obj, instance, methodName, functionName, defaultImplementation) {
42188    if (typeof obj[methodName] === 'undefined') {
42189      if (typeof obj[functionName] === 'function') {
42190        instance[methodName] = obj[functionName]
42191      } else if (defaultImplementation) {
42192        instance[methodName] = defaultImplementation
42193      }
42194    }
42195  }
42196  const addRespondToMethod = function (instance) {
42197    if (typeof instance['$respond_to?'] !== 'function') {
42198      instance['$respond_to?'] = function (name) {
42199        return typeof this[name] === 'function'
42200      }
42201    }
42202  }
42203  if (typeof converter === 'function') {
42204    // Class
42205    const object = initializeClass(ConverterBase, converter.constructor.name, {
42206      initialize: function (backend, opts) {
42207        const self = this
42208        const result = new converter(backend, opts) // eslint-disable-line
42209        Object.assign(this, result)
42210        assignBackendTraitsToInstance(result, self)
42211        const propertyNames = Object.getOwnPropertyNames(converter.prototype)
42212        for (let i = 0; i < propertyNames.length; i++) {
42213          const propertyName = propertyNames[i]
42214          if (propertyName !== 'constructor') {
42215            self[propertyName] = result[propertyName]
42216          }
42217        }
42218        if (typeof result.$convert === 'undefined' && typeof result.convert === 'function') {
42219          self.$convert = result.convert
42220        }
42221        bridgeHandlesMethodToInstance(result, self)
42222        bridgeComposedMethodToInstance(result, self)
42223        addRespondToMethod(self)
42224        self.super(backend, opts)
42225      }
42226    })
42227    object.$extend(ConverterBackendTraits)
42228    return object
42229  }
42230  if (typeof converter === 'object') {
42231    // Instance
42232    if (typeof converter.$convert === 'undefined' && typeof converter.convert === 'function') {
42233      converter.$convert = converter.convert
42234    }
42235    assignBackendTraitsToInstance(converter, converter)
42236    if (converter.backend_traits) {
42237      // "extends" ConverterBackendTraits
42238      const converterBackendTraitsFunctionNames = [
42239        'basebackend',
42240        'filetype',
42241        'htmlsyntax',
42242        'outfilesuffix',
42243        'supports_templates',
42244        'supports_templates?',
42245        'init_backend_traits',
42246        'backend_traits'
42247      ]
42248      for (const functionName of converterBackendTraitsFunctionNames) {
42249        converter['$' + functionName] = ConverterBackendTraits.prototype['$' + functionName]
42250      }
42251      converter.$$meta = ConverterBackendTraits
42252    }
42253    bridgeHandlesMethodToInstance(converter, converter)
42254    bridgeComposedMethodToInstance(converter, converter)
42255    bridgeEqEqMethodToInstance(converter, converter)
42256    bridgeSendMethodToInstance(converter, converter)
42257    addRespondToMethod(converter)
42258    return converter
42259  }
42260  return converter
42261}
42262
42263function initializeClass (superClass, className, functions, defaultFunctions, argProxyFunctions) {
42264  const scope = Opal.klass(Opal.Object, superClass, className, function () { })
42265  let postConstructFunction
42266  let initializeFunction
42267  let constructorFunction
42268  const defaultFunctionsOverridden = {}
42269  for (const functionName in functions) {
42270    if (Object.prototype.hasOwnProperty.call(functions, functionName)) {
42271      (function (functionName) {
42272        const userFunction = functions[functionName]
42273        if (functionName === 'postConstruct') {
42274          postConstructFunction = userFunction
42275        } else if (functionName === 'initialize') {
42276          initializeFunction = userFunction
42277        } else if (functionName === 'constructor') {
42278          constructorFunction = userFunction
42279        } else {
42280          if (defaultFunctions && Object.prototype.hasOwnProperty.call(defaultFunctions, functionName)) {
42281            defaultFunctionsOverridden[functionName] = true
42282          }
42283          let $function
42284          Opal.def(scope, '$' + functionName, ($function = function () {
42285            let args
42286            if (argProxyFunctions && Object.prototype.hasOwnProperty.call(argProxyFunctions, functionName)) {
42287              args = argProxyFunctions[functionName](arguments)
42288            } else {
42289              args = arguments
42290            }
42291            // append Ruby block as the final argument
42292            const $block = $function.$$p
42293            if ($block) {
42294              args[args.length] = function () { return Opal.yield1($block) }
42295              args.length += 1
42296              $function.$$p = null
42297            }
42298            return userFunction.apply(this, args)
42299          }))
42300        }
42301      }(functionName))
42302    }
42303  }
42304  let initialize
42305  if (typeof constructorFunction === 'function') {
42306    initialize = function () {
42307      const args = Array.from(arguments)
42308      for (let i = 0; i < args.length; i++) {
42309        // convert all (Opal) Hash arguments to JSON.
42310        if (typeof args[i] === 'object' && '$$smap' in args[i]) {
42311          args[i] = fromHash(args[i])
42312        }
42313      }
42314      args.unshift(null)
42315      const result = new (Function.prototype.bind.apply(constructorFunction, args)) // eslint-disable-line
42316      Object.assign(this, result)
42317      if (typeof postConstructFunction === 'function') {
42318        postConstructFunction.bind(this)()
42319      }
42320    }
42321  } else if (typeof initializeFunction === 'function') {
42322    initialize = function () {
42323      const args = Array.from(arguments)
42324      for (let i = 0; i < args.length; i++) {
42325        // convert all (Opal) Hash arguments to JSON.
42326        if (typeof args[i] === 'object' && '$$smap' in args[i]) {
42327          args[i] = fromHash(args[i])
42328        }
42329      }
42330      initializeFunction.apply(this, args)
42331      if (typeof postConstructFunction === 'function') {
42332        postConstructFunction.bind(this)()
42333      }
42334    }
42335  } else {
42336    initialize = function () {
42337      Opal.send(this, Opal.find_super_dispatcher(this, 'initialize', initialize))
42338      if (typeof postConstructFunction === 'function') {
42339        postConstructFunction.bind(this)()
42340      }
42341    }
42342  }
42343  Opal.def(scope, '$initialize', initialize)
42344  let $superFunction
42345  Opal.def(scope, 'super', ($superFunction = function (func) {
42346    if (typeof func === 'function') {
42347      Opal.send(this, Opal.find_super_dispatcher(this, func.name, func))
42348    } else {
42349      // Bind the initialize function to super();
42350      const argumentsList = Array.from(arguments)
42351      for (let i = 0; i < argumentsList.length; i++) {
42352        // convert all (Opal) Hash arguments to JSON.
42353        if (typeof argumentsList[i] === 'object') {
42354          argumentsList[i] = toHash(argumentsList[i])
42355        }
42356      }
42357      Opal.send(this, Opal.find_super_dispatcher(this, 'initialize', initialize), argumentsList)
42358    }
42359  }))
42360  for (const functionName in functions) {
42361    $superFunction[functionName] = function () {
42362      const argumentsList = Array.from(arguments)
42363      for (let i = 0; i < argumentsList.length; i++) {
42364        // convert all (Opal) Hash arguments to JSON.
42365        if (typeof argumentsList[i] === 'object' && typeof argumentsList[i].constructor === 'function' && argumentsList[i].constructor.name === 'Object') {
42366          argumentsList[i] = toHash(argumentsList[i])
42367        }
42368      }
42369      const self = scope.$$prototype
42370      return Opal.send(self, Opal.find_super_dispatcher(self, functionName, self[`$${functionName}`]), argumentsList)
42371    }
42372  }
42373  if (defaultFunctions) {
42374    for (const defaultFunctionName in defaultFunctions) {
42375      if (Object.prototype.hasOwnProperty.call(defaultFunctions, defaultFunctionName) && !Object.prototype.hasOwnProperty.call(defaultFunctionsOverrid
42375den, defaultFunctionName)) {
42376        (function (defaultFunctionName) {
42377          const defaultFunction = defaultFunctions[defaultFunctionName]
42378          Opal.def(scope, '$' + defaultFunctionName, function () {
42379            return defaultFunction.apply(this, arguments)
42380          })
42381        }(defaultFunctionName))
42382      }
42383    }
42384  }
42385  return scope
42386}
42387
42388// Asciidoctor API
42389
42390/**
42391 * @namespace
42392 * @description
42393 * The main application interface (API) for Asciidoctor.
42394 * This API provides methods to parse AsciiDoc content and convert it to various output formats using built-in or third-party converters.
42395 *
42396 * An AsciiDoc document can be as simple as a single line of content,
42397 * though it more commonly starts with a document header that declares the document title and document attribute definitions.
42398 * The document header is then followed by zero or more section titles, optionally nested, to organize the paragraphs, blocks, lists, etc. of the document.
42399 *
42400 * By default, the processor converts the AsciiDoc document to HTML 5 using a built-in converter.
42401 * However, this behavior can be changed by specifying a different backend (e.g., +docbook+).
42402 * A backend is a keyword for an output format (e.g., DocBook).
42403 * That keyword, in turn, is used to select a converter, which carries out the request to convert the document to that format.
42404 *
42405 * @example
42406 * asciidoctor.convertFile('document.adoc', { 'safe': 'safe' }) // Convert an AsciiDoc file
42407 *
42408 * asciidoctor.convert("I'm using *Asciidoctor* version {asciidoctor-version}.", { 'safe': 'safe' }) // Convert an AsciiDoc string
42409 *
42410 * const doc = asciidoctor.loadFile('document.adoc', { 'safe': 'safe' }) // Parse an AsciiDoc file into a document object
42411 *
42412 * const doc = asciidoctor.load("= Document Title\n\nfirst paragraph\n\nsecond paragraph", { 'safe': 'safe' }) // Parse an AsciiDoc string into a document object
42413 */
42414const Asciidoctor = Opal.Asciidoctor.$$class
42415
42416/**
42417 * Get Asciidoctor core version number.
42418 *
42419 * @returns {string} - the version number of Asciidoctor core.
42420 * @memberof Asciidoctor
42421 */
42422Asciidoctor.prototype.getCoreVersion = function () {
42423  return this.$$const.VERSION
42424}
42425
42426/**
42427 * Get Asciidoctor.js runtime environment information.
42428 *
42429 * @returns {Object} - the runtime environment including the ioModule, the platform, the engine and the framework.
42430 * @memberof Asciidoctor
42431 */
42432Asciidoctor.prototype.getRuntime = function () {
42433  return {
42434    ioModule: Opal.const_get_qualified('::', 'JAVASCRIPT_IO_MODULE'),
42435    platform: Opal.const_get_qualified('::', 'JAVASCRIPT_PLATFORM'),
42436    engine: Opal.const_get_qualified('::', 'JAVASCRIPT_ENGINE'),
42437    framework: Opal.const_get_qualified('::', 'JAVASCRIPT_FRAMEWORK')
42438  }
42439}
42440
42441/**
42442 * Parse the AsciiDoc source input into an {@link Document} and convert it to the specified backend format.
42443 *
42444 * Accepts input as a Buffer or String.
42445 *
42446 * @param {string|Buffer} input - AsciiDoc input as String or Buffer
42447 * @param {Object} options - a JSON of options to control processing (default: {})
42448 * @returns {string|Document} - the {@link Document} object if the converted String is written to a file,
42449 * otherwise the converted String
42450 * @example
42451 * const input = `= Hello, AsciiDoc!
42452 * Guillaume Grossetie <[email protected]>
42453 *
42454 * An introduction to http://asciidoc.org[AsciiDoc].
42455 *
42456 * == First Section
42457 *
42458 * * item 1
42459 * * item 2`
42460 *
42461 * const html = asciidoctor.convert(input)
42462 * @memberof Asciidoctor
42463 */
42464Asciidoctor.prototype.convert = function (input, options) {
42465  if (typeof input === 'object' && input.constructor.name === 'Buffer') {
42466    input = input.toString('utf8')
42467  }
42468  const toFile = options && options.to_file
42469  if (typeof toFile === 'object' && toFile.constructor.name === 'Writable' && typeof toFile.write === 'function') {
42470    toFile['$respond_to?'] = (name) => name === 'write'
42471    toFile.$object_id = () => ''
42472    toFile.$write = function (data) {
42473      this.write(data)
42474    }
42475  }
42476  const opts = prepareOptions(options)
42477  const result = this.$convert(input, opts)
42478  if (typeof toFile === 'object' && toFile.constructor.name === 'Writable' && typeof toFile.end === 'function') {
42479    toFile.end()
42480  }
42481  return result === Opal.nil ? '' : result
42482}
42483
42484/**
42485 * Parse the AsciiDoc source input into an {@link Document} and convert it to the specified backend format.
42486 *
42487 * @param {string} filename - source filename
42488 * @param {Object} options - a JSON of options to control processing (default: {})
42489 * @returns {string|Document} - the {@link Document} object if the converted String is written to a file,
42490 * otherwise the converted String
42491 * @example
42492 * const html = asciidoctor.convertFile('./document.adoc')
42493 * @memberof Asciidoctor
42494 */
42495Asciidoctor.prototype.convertFile = function (filename, options) {
42496  return this.$convert_file(filename, prepareOptions(options))
42497}
42498
42499/**
42500 * Parse the AsciiDoc source input into an {@link Document}
42501 *
42502 * Accepts input as a Buffer or String.
42503 *
42504 * @param {string|Buffer} input - AsciiDoc input as String or Buffer
42505 * @param {Object} options - a JSON of options to control processing (default: {})
42506 * @returns {Document} - the {@link Document} object
42507 * @memberof Asciidoctor
42508 */
42509Asciidoctor.prototype.load = function (input, options) {
42510  if (typeof input === 'object' && input.constructor.name === 'Buffer') {
42511    input = input.toString('utf8')
42512  }
42513  return this.$load(input, prepareOptions(options))
42514}
42515
42516/**
42517 * Parse the contents of the AsciiDoc source file into an {@link Document}
42518 *
42519 * @param {string} filename - source filename
42520 * @param {Object} options - a JSON of options to control processing (default: {})
42521 * @returns {Document} - the {@link Document} object
42522 * @memberof Asciidoctor
42523 */
42524Asciidoctor.prototype.loadFile = function (filename, options) {
42525  return this.$load_file(filename, prepareOptions(options))
42526}
42527
42528// AbstractBlock API
42529
42530/**
42531 * @namespace
42532 * @extends AbstractNode
42533 */
42534const AbstractBlock = Opal.Asciidoctor.AbstractBlock
42535
42536/**
42537 *  Describes the type of content this block accepts and how it should be converted.
42538 * @returns {string} - the type of content this block accepts.
42539 * @memberof AbstractBlock
42540 */
42541AbstractBlock.prototype.getContentModel = function () {
42542  const contentModel = this.content_model
42543  return contentModel === Opal.nil ? undefined : contentModel
42544}
42545
42546/**
42547 *  Set the type of content this block accepts. Acceptable values are:
42548 *  - compound - this block contains other blocks
42549 *  - simple - this block holds a paragraph of prose that receives normal substitutions
42550 *  - verbatim - this block holds verbatim text (displayed "as is") that receives verbatim substitutions
42551 *  - raw - this block holds unprocessed content passed directly to the output with no substitutions applied
42552 *  - empty - this block has no content
42553 * @param {string} contentModel - type of content, one of: compound, simple, verbatim, raw or empty.
42554 * @memberof AbstractBlock
42555 */
42556AbstractBlock.prototype.setContentModel = function (contentModel) {
42557  this.content_model = contentModel
42558}
42559
42560/**
42561 * Append a block to this block's list of child blocks.
42562 * @param {AbstractBlock} block - the block to append
42563 * @returns {AbstractBlock} - the parent block to which this block was appended.
42564 * @memberof AbstractBlock
42565 */
42566AbstractBlock.prototype.append = function (block) {
42567  this.$append(block)
42568  return this
42569}
42570
42571/**
42572 * Get the String title of this Block with title substitutions applied
42573 *
42574 * The following substitutions are applied to block and section titles:
42575 *
42576 * <code>specialcharacters</code>, <code>quotes</code>, <code>replacements</code>, <code>macros</code>, <code>attributes</code> and <code>post_replacements</code>
42577 *
42578 * @returns {string} - the converted String title for this Block, or undefined if the title is not set.
42579 * @example
42580 * block.title // "Foo 3^ # {two-colons} Bar(1)"
42581 * block.getTitle(); // "Foo 3^ # :: Bar(1)"
42582 * @memberof AbstractBlock
42583 */
42584AbstractBlock.prototype.getTitle = function () {
42585  const title = this.$title()
42586  return title === Opal.nil ? undefined : title
42587}
42588
42589/**
42590 * Set the String block title.
42591 *
42592 * @param {string} title - The block title
42593 * @returns {string} - the new String title assigned to this Block.
42594 * @memberof AbstractBlock
42595 */
42596AbstractBlock.prototype.setTitle = function (title) {
42597  title = typeof title === 'undefined' ? Opal.nil : title
42598  return this['$title='](title)
42599}
42600
42601/**
42602 * Generate and assign caption to block if not already assigned.
42603 *
42604 * If the block has a title and a caption prefix is available for this block,
42605 * then build a caption from this information, assign it a number and store it
42606 * to the caption attribute on the block.
42607 *
42608 * If a caption has already been assigned to this block, do nothing.
42609 *
42610 * The parts of a complete caption are: `<prefix> <number>. <title>`
42611 * This partial caption represents the part the precedes the title.
42612 *
42613 * @param {string} value - the String caption to assign to this block or nil to use document attribute.
42614 * @param {string} captionContext - the String context to use when resolving caption-related attributes.
42615 * If not provided, the name of the context for this block is used. Only certain contexts allow the caption to be looked up.
42616 *
42617 * @memberof AbstractBlock
42618 */
42619AbstractBlock.prototype.assignCaption = function (value, captionContext) {
42620  value = typeof value === 'undefined' ? Opal.nil : value
42621  captionContext = typeof captionContext === 'undefined' ? null : captionContext
42622  this.$assign_caption(value, captionContext)
42623}
42624
42625/**
42626 * Convenience method that returns the interpreted title of the Block
42627 * with the caption prepended.
42628 * Concatenates the value of this Block's caption instance variable and the
42629 * return value of this Block's title method. No space is added between the
42630 * two values. If the Block does not have a caption, the interpreted title is
42631 * returned.
42632 *
42633 * @returns {string} - the converted String title prefixed with the caption, or just the converted String title if no caption is set
42634 * @memberof AbstractBlock
42635 */
42636AbstractBlock.prototype.getCaptionedTitle = function () {
42637  return this.$captioned_title()
42638}
42639
42640/**
42641 * Get the style (block type qualifier) for this block.
42642 *
42643 * @returns {string} - the style for this block
42644 * @memberof AbstractBlock
42645 */
42646AbstractBlock.prototype.getStyle = function () {
42647  const style = this.style
42648  return style === Opal.nil ? undefined : style
42649}
42650
42651/**
42652 * Set the style for this block.
42653 *
42654 * @param {string} style - Style
42655 * @memberof AbstractBlock
42656 */
42657AbstractBlock.prototype.setStyle = function (style) {
42658  this.style = style
42659}
42660
42661/**
42662 * Get the location in the AsciiDoc source where this block begins.
42663 *
42664 * @returns {Cursor} - the location in the AsciiDoc source where this block begins
42665 * @memberof AbstractBlock
42666 */
42667AbstractBlock.prototype.getSourceLocation = function () {
42668  const sourceLocation = this.source_location
42669  if (sourceLocation === Opal.nil) {
42670    return undefined
42671  }
42672  sourceLocation.getFile = function () {
42673    const file = this.file
42674    return file === Opal.nil ? undefined : file
42675  }
42676  sourceLocation.getDirectory = function () {
42677    const dir = this.dir
42678    return dir === Opal.nil ? undefined : dir
42679  }
42680  sourceLocation.getPath = function () {
42681    const path = this.path
42682    return path === Opal.nil ? undefined : path
42683  }
42684  sourceLocation.getLineNumber = function () {
42685    const lineno = this.lineno
42686    return lineno === Opal.nil ? undefined : lineno
42687  }
42688  return sourceLocation
42689}
42690
42691/**
42692 * Get the caption for this block.
42693 *
42694 * @returns {string} - the caption for this block
42695 * @memberof AbstractBlock
42696 */
42697AbstractBlock.prototype.getCaption = function () {
42698  const caption = this.$caption()
42699  return caption === Opal.nil ? undefined : caption
42700}
42701
42702/**
42703 * Set the caption for this block.
42704 *
42705 * @param {string} caption - Caption
42706 * @memberof AbstractBlock
42707 */
42708AbstractBlock.prototype.setCaption = function (caption) {
42709  this.caption = typeof caption === 'undefined' ? Opal.nil : caption
42710}
42711
42712/**
42713 * Get the level of this section or the section level in which this block resides.
42714 *
42715 * @returns {number} - the level (Integer) of this section
42716 * @memberof AbstractBlock
42717 */
42718AbstractBlock.prototype.getLevel = function () {
42719  const level = this.level
42720  return level === Opal.nil ? undefined : level
42721}
42722
42723/**
42724 * Get the substitution keywords to be applied to the contents of this block.
42725 *
42726 * @returns {Array<string>} - the list of {string} substitution keywords associated with this block.
42727 * @memberof AbstractBlock
42728 */
42729AbstractBlock.prototype.getSubstitutions = function () {
42730  return this.subs
42731}
42732
42733/**
42734 * Check whether a given substitution keyword is present in the substitutions for this block.
42735 *
42736 * @returns {boolean} - whether the substitution is present on this block.
42737 * @memberof AbstractBlock
42738 */
42739AbstractBlock.prototype.hasSubstitution = function (substitution) {
42740  return this['$sub?'](substitution)
42741}
42742
42743/**
42744 * Remove the specified substitution keyword from the list of substitutions for this block.
42745 *
42746 * @memberof AbstractBlock
42747 */
42748AbstractBlock.prototype.removeSubstitution = function (substitution) {
42749  this.$remove_sub(substitution)
42750}
42751
42752/**
42753 * Checks if the {@link AbstractBlock} contains any child blocks.
42754 *
42755 * @returns {boolean} - whether the {@link AbstractBlock} has child blocks.
42756 * @memberof AbstractBlock
42757 */
42758AbstractBlock.prototype.hasBlocks = function () {
42759  return this.blocks.length > 0
42760}
42761
42762/**
42763 * Get the list of {@link AbstractBlock} sub-blocks for this block.
42764 *
42765 * @returns {Array<AbstractBlock>} - a list of {@link AbstractBlock} sub-blocks
42766 * @memberof AbstractBlock
42767 */
42768AbstractBlock.prototype.getBlocks = function () {
42769  return this.blocks
42770}
42771
42772/**
42773 * Get the converted result of the child blocks by converting the children appropriate to content model that this block supports.
42774 *
42775 * @returns {string} - the converted result of the child blocks
42776 * @memberof AbstractBlock
42777 */
42778AbstractBlock.prototype.getContent = function () {
42779  const content = this.$content()
42780  return content === Opal.nil ? undefined : content
42781}
42782
42783/**
42784 * Get the converted content for this block.
42785 * If the block has child blocks, the content method should cause them to be converted
42786 * and returned as content that can be included in the parent block's template.
42787 *
42788 * @returns {string} - the converted String content for this block
42789 * @memberof AbstractBlock
42790 */
42791AbstractBlock.prototype.convert = function () {
42792  return this.$convert()
42793}
42794
42795/**
42796 * Query for all descendant block-level nodes in the document tree
42797 * that match the specified selector (context, style, id, and/or role).
42798 * If a function block is given, it's used as an additional filter.
42799 * If no selector or function block is supplied, all block-level nodes in the tree are returned.
42800 * @param {Object} [selector]
42801 * @param {function} [block]
42802 * @example
42803 * doc.findBy({'context': 'section'});
42804 * // => { level: 0, title: "Hello, AsciiDoc!", blocks: 0 }
42805 * // => { level: 1, title: "First Section", blocks: 1 }
42806 *
42807 * doc.findBy({'context': 'section'}, function (section) { return section.getLevel() === 1; });
42808 * // => { level: 1, title: "First Section", blocks: 1 }
42809 *
42810 * doc.findBy({'context': 'listing', 'style': 'source'});
42811 * // => { context: :listing, content_model: :verbatim, style: "source", lines: 1 }
42812 *
42813 * @returns {Array<AbstractBlock>} - a list of block-level nodes that match the filter or an empty list if no matches are found
42814 * @memberof AbstractBlock
42815 */
42816AbstractBlock.prototype.findBy = function (selector, block) {
42817  if (typeof block === 'undefined' && typeof selector === 'function') {
42818    return Opal.send(this, 'find_by', null, selector)
42819  } else if (typeof block === 'function') {
42820    return Opal.send(this, 'find_by', [toHash(selector)], block)
42821  } else {
42822    return this.$find_by(toHash(selector))
42823  }
42824}
42825
42826/**
42827 * Get the source line number where this block started.
42828 * @returns {number} - the source line number where this block started
42829 * @memberof AbstractBlock
42830 */
42831AbstractBlock.prototype.getLineNumber = function () {
42832  const lineno = this.$lineno()
42833  return lineno === Opal.nil ? undefined : lineno
42834}
42835
42836/**
42837 * Check whether this block has any child Section objects.
42838 * Only applies to Document and Section instances.
42839 * @returns {boolean} - true if this block has child Section objects, otherwise false
42840 * @memberof AbstractBlock
42841 */
42842AbstractBlock.prototype.hasSections = function () {
42843  // REMIND: call directly the underlying method "$sections?"
42844  // once https://github.com/asciidoctor/asciidoctor/pull/3591 is merged and a new version is released.
42845  // return this['$sections?']()
42846  return this.next_section_index !== Opal.nil && this.next_section_index > 0
42847}
42848
42849/**
42850 * Get the Array of child Section objects.
42851 * Only applies to Document and Section instances.
42852 * @memberof AbstractBlock
42853 * @returns {Array<Section>} - an {Array} of {@link Section} objects
42854 */
42855AbstractBlock.prototype.getSections = function () {
42856  return this.$sections()
42857}
42858
42859/**
42860 * Get the numeral of this block (if section, relative to parent, otherwise absolute).
42861 * Only assigned to section if automatic section numbering is enabled.
42862 * Only assigned to formal block (block with title) if corresponding caption attribute is present.
42863 * If the section is an appendix, the numeral is a letter (starting with A).
42864 * @returns {string} - the numeral
42865 * @memberof AbstractBlock
42866 */
42867AbstractBlock.prototype.getNumeral = function () {
42868  const numeral = this.$numeral()
42869  return numeral === Opal.nil ? undefined : numeral
42870}
42871
42872/**
42873 * Set the numeral of this block.
42874 * @param {string} value - The numeral value
42875 * @memberof AbstractBlock
42876 */
42877AbstractBlock.prototype.setNumeral = function (value) {
42878  this['$numeral='](value)
42879}
42880
42881/**
42882 * A convenience method that checks whether the title of this block is defined.
42883 *
42884 * @returns {boolean} - a {boolean} indicating whether this block has a title.
42885 * @memberof AbstractBlock
42886 */
42887AbstractBlock.prototype.hasTitle = function () {
42888  return this['$title?']()
42889}
42890
42891/**
42892 * Returns the converted alt text for this block image.
42893 * @returns {string} - the {string} value of the alt attribute with XML special character and replacement substitutions applied.
42894 * @memberof AbstractBlock
42895 */
42896AbstractBlock.prototype.getAlt = function () {
42897  return this.$alt()
42898}
42899
42900// Section API
42901
42902/**
42903 * @description
42904 * Methods for managing sections of AsciiDoc content in a document.
42905 *
42906 * @example
42907 * <pre>
42908 *   section = asciidoctor.Section.create()
42909 *   section.setTitle('Section 1')
42910 *   section.setId('sect1')
42911 *   section.getBlocks().length // 0
42912 *   section.getId() // "sect1"
42913 *   section.append(newBlock)
42914 *   section.getBlocks().length // 1
42915 * </pre>
42916 * @namespace
42917 * @extends AbstractBlock
42918 */
42919const Section = Opal.Asciidoctor.Section
42920
42921/**
42922 * Create a {Section} object.
42923 * @param {AbstractBlock} [parent] - The parent AbstractBlock. If set, must be a Document or Section object (default: undefined)
42924 * @param {number} [level] - The Integer level of this section (default: 1 more than parent level or 1 if parent not defined)
42925 * @param {boolean} [numbered] - A Boolean indicating whether numbering is enabled for this Section (default: false)
42926 * @param {Object} [opts] - An optional JSON of options (default: {})
42927 * @returns {Section} - a new {Section} object
42928 * @memberof Section
42929 */
42930Section.create = function (parent, level, numbered, opts) {
42931  if (opts && opts.attributes) {
42932    opts.attributes = toHash(opts.attributes)
42933  }
42934  return this.$new(parent, level, numbered, toHash(opts))
42935}
42936
42937/**
42938 * Set the level of this section or the section level in which this block resides.
42939 * @param {number} level - Level (Integer)
42940 * @memberof AbstractBlock
42941 */
42942Section.prototype.setLevel = function (level) {
42943  this.level = level
42944}
42945
42946/**
42947 * Get the 0-based index order of this section within the parent block.
42948 * @returns {number}
42949 * @memberof Section
42950 */
42951Section.prototype.getIndex = function () {
42952  return this.index
42953}
42954
42955/**
42956 * Set the 0-based index order of this section within the parent block.
42957 * @param {string} index - The index order of this section
42958 * @memberof Section
42959 */
42960Section.prototype.setIndex = function (index) {
42961  this.index = index
42962}
42963
42964/**
42965 * Get the section name of this section.
42966 * @returns {string|undefined}
42967 * @memberof Section
42968 */
42969Section.prototype.getSectionName = function () {
42970  const sectname = this.sectname
42971  return sectname === Opal.nil ? undefined : sectname
42972}
42973
42974/**
42975 * Set the section name of this section.
42976 * @param {string} value - The section name
42977 * @memberof Section
42978 */
42979Section.prototype.setSectionName = function (value) {
42980  this.sectname = value
42981}
42982
42983/**
42984 * Get the section numeral of this section.
42985 * @returns {string}
42986 * @memberof Section
42987 */
42988Section.prototype.getSectionNumeral = function () {
42989  return this.$sectnum()
42990}
42991
42992Section.prototype.getSectionNumber = Section.prototype.getSectionNumeral
42993
42994/**
42995 * Get the flag to indicate whether this is a special section or a child of one.
42996 * @returns {boolean}
42997 * @memberof Section
42998 */
42999Section.prototype.isSpecial = function () {
43000  return this.special
43001}
43002
43003/**
43004 * Set the flag to indicate whether this is a special section or a child of one.
43005 * @param {boolean} value - A flag to indicated if this is a special section
43006 * @memberof Section
43007 */
43008Section.prototype.setSpecial = function (value) {
43009  this.special = value
43010}
43011
43012/**
43013 * Get the state of the numbered attribute at this section (need to preserve for creating TOC).
43014 * @returns {boolean}
43015 * @memberof Section
43016 */
43017Section.prototype.isNumbered = function () {
43018  return this.numbered
43019}
43020
43021/**
43022 * Get the caption for this section (only relevant for appendices).
43023 * @returns {string}
43024 * @memberof Section
43025 */
43026Section.prototype.getCaption = function () {
43027  const value = this.caption
43028  return value === Opal.nil ? undefined : value
43029}
43030
43031/**
43032 * Get the name of the Section (title)
43033 * @returns {string}
43034 * @see {@link AbstractBlock#getTitle}
43035 * @memberof Section
43036 */
43037Section.prototype.getName = function () {
43038  return this.getTitle()
43039}
43040
43041/**
43042 * @description
43043 * Methods for managing AsciiDoc content blocks.
43044 *
43045 * @example
43046 * block = asciidoctor.Block.create(parent, 'paragraph', {source: '_This_ is a <test>'})
43047 * block.getContent()
43048 * // "<em>This</em> is a &lt;test&gt;"
43049 *
43050 * @namespace
43051 * @extends AbstractBlock
43052 */
43053const Block = Opal.Asciidoctor.Block
43054
43055/**
43056 * Create a {Block} object.
43057 * @param {AbstractBlock} parent - The parent {AbstractBlock} with a compound content model to which this {Block} will be appended.
43058 * @param {string} context - The context name for the type of content (e.g., "paragraph").
43059 * @param {Object} [opts] - a JSON of options to customize block initialization: (default: {})
43060 * @param {string} opts.content_model - indicates whether blocks can be nested in this {Block} ("compound"),
43061 * otherwise how the lines should be processed ("simple", "verbatim", "raw", "empty"). (default: "simple")
43062 * @param {Object} opts.attributes - a JSON of attributes (key/value pairs) to assign to this {Block}. (default: {})
43063 * @param {string|Array<string>} opts.source - a String or {Array} of raw source for this {Block}. (default: undefined)
43064 *
43065 * IMPORTANT: If you don't specify the `subs` option, you must explicitly call the `commit_subs` method to resolve and assign the substitutions
43066 * to this block (which are resolved from the `subs` attribute, if specified, or the default substitutions based on this block's context).
43067 * If you want to use the default subs for a block, pass the option `subs: "default"`.
43068 * You can override the default subs using the `default_subs` option.
43069 *
43070 * @returns {Block} - a new {Block} object
43071 * @memberof Block
43072 */
43073Block.create = function (parent, context, opts) {
43074  if (opts && opts.attributes) {
43075    opts.attributes = toHash(opts.attributes)
43076  }
43077  return this.$new(parent, context, toHash(opts))
43078}
43079
43080/**
43081 * Get the source of this block.
43082 * @returns {string} - the String source of this block.
43083 * @memberof Block
43084 */
43085Block.prototype.getSource = function () {
43086  return this.$source()
43087}
43088
43089/**
43090 * Get the source lines of this block.
43091 * @returns {Array<string>} - the String {Array} of source lines for this block.
43092 * @memberof Block
43093 */
43094Block.prototype.getSourceLines = function () {
43095  return this.lines
43096}
43097
43098// AbstractNode API
43099
43100/**
43101 * @namespace
43102 * @description
43103 * An abstract base class that provides state and methods for managing a node of AsciiDoc content.
43104 * The state and methods on this class are common to all content segments in an AsciiDoc document.
43105 */
43106const AbstractNode = Opal.Asciidoctor.AbstractNode
43107
43108/**
43109 * Apply the specified substitutions to the text.
43110 * If no substitutions are specified, the following substitutions are applied:
43111 * <code>specialcharacters</code>, <code>quotes</code>, <code>attributes</code>, <code>replacements</code>, <code>macros</code>, and <code>post_replacements</code>.
43112 *
43113 * @param {string|Array<string>} text - The String or String Array of text to process; must not be undefined.
43114 * @param {Array<string>} [subs] - The substitutions to perform; must be an Array or undefined.
43115 * @returns {string|Array<string>} - a String or String Array to match the type of the text argument with substitutions applied.
43116 * @memberof AbstractNode
43117 */
43118AbstractNode.prototype.applySubstitutions = function (text, subs) {
43119  return this.$apply_subs(text, subs)
43120}
43121
43122/**
43123 * Resolve the list of comma-delimited subs against the possible options.
43124 *
43125 * @param {string} subs - The comma-delimited String of substitution names or aliases.
43126 * @param {string} [type] - A String representing the context for which the subs are being resolved (default: 'block').
43127 * @param {Array<string>} [defaults] - An Array of substitutions to start with when computing incremental substitutions (default: undefined).
43128 * @param {string} [subject] - The String to use in log messages to communicate the subject for which subs are being resolved (default: undefined)
43129 *
43130 * @returns {Array<string>} - An Array of Strings representing the substitution operation or nothing if no subs are found.
43131 * @memberof AbstractNode
43132 */
43133AbstractNode.prototype.resolveSubstitutions = function (subs, type, defaults, subject) {
43134  if (typeof type === 'undefined') {
43135    type = 'block'
43136  }
43137  if (typeof defaults === 'undefined') {
43138    defaults = Opal.nil
43139  }
43140  if (typeof subject === 'undefined') {
43141    subject = Opal.nil
43142  }
43143  const value = this.$resolve_subs(subs, type, defaults, subject)
43144  return value === Opal.nil ? undefined : value
43145}
43146
43147/**
43148 * Call {@link AbstractNode#resolveSubstitutions} for the 'block' type.
43149 *
43150 * @see {@link AbstractNode#resolveSubstitutions}
43151 */
43152AbstractNode.prototype.resolveBlockSubstitutions = function (subs, defaults, subject) {
43153  return this.resolveSubstitutions(subs, 'block', defaults, subject)
43154}
43155
43156/**
43157 * Call {@link AbstractNode#resolveSubstitutions} for the 'inline' type with the subject set as passthrough macro.
43158 *
43159 * @see {@link AbstractNode#resolveSubstitutions}
43160 */
43161AbstractNode.prototype.resolvePassSubstitutions = function (subs) {
43162  return this.resolveSubstitutions(subs, 'inline', undefined, 'passthrough macro')
43163}
43164
43165/**
43166 * @returns {string} - the String name of this node
43167 * @memberof AbstractNode
43168 */
43169AbstractNode.prototype.getNodeName = function () {
43170  return this.node_name
43171}
43172
43173/**
43174 * @returns {Object} - the JSON of attributes for this node
43175 * @memberof AbstractNode
43176 */
43177AbstractNode.prototype.getAttributes = function () {
43178  return fromHash(this.attributes)
43179}
43180
43181/**
43182 * Get the value of the specified attribute.
43183 * If the attribute is not found on this node, fallback_name is set, and this node is not the Document node, get the value of the specified attribute from the Document node.
43184 *
43185 * Look for the specified attribute in the attributes on this node and return the value of the attribute, if found.
43186 * Otherwise, if fallback_name is set (default: same as name) and this node is not the Document node, look for that attribute on the Document node and return its value, if found.
43187 * Otherwise, return the default value (default: undefined).
43188 *
43189 * @param {string} name - The String of the attribute to resolve.
43190 * @param {*} [defaultValue] - The {Object} value to return if the attribute is not found (default: undefined).
43191 * @param {string} [fallbackName] - The String of the attribute to resolve on the Document if the attribute is not found on this node (default: same as name).
43192 *
43193 * @returns {*} - the {Object} value (typically a String) of the attribute or defaultValue if the attribute is not found.
43194 * @memberof AbstractNode
43195 */
43196AbstractNode.prototype.getAttribute = function (name, defaultValue, fallbackName) {
43197  const value = this.$attr(name, defaultValue, fallbackName)
43198  return value === Opal.nil ? undefined : value
43199}
43200
43201/**
43202 * Check whether the specified attribute is present on this node.
43203 *
43204 * @param {string} name - The String of the attribute to resolve.
43205 * @returns {boolean} - true if the attribute is present, otherwise false
43206 * @memberof AbstractNode
43207 */
43208AbstractNode.prototype.hasAttribute = function (name) {
43209  return name in this.attributes.$$smap
43210}
43211
43212/**
43213 * Check if the specified attribute is defined using the same logic as {AbstractNode#getAttribute}, optionally performing acomparison with the expected value if specified.
43214 *
43215 * Look for the specified attribute in the attributes on this node.
43216 * If not found, fallback_name is specified (default: same as name), and this node is not the Document node, look for that attribute on the Document node.
43217 * In either case, if the attribute is found, and the comparison value is truthy, return whether the two values match.
43218 * Otherwise, return whether the attribute was found.
43219 *
43220 * @param {string} name - The String name of the attribute to resolve.
43221 * @param {*} [expectedValue] - The expected Object value of the attribute (default: undefined).
43222 * @param {string} fallbackName - The String of the attribute to resolve on the Document if the attribute is not found on this node (default: same as name).
43223 *
43224 * @returns {boolean} - a Boolean indicating whether the attribute exists and, if a truthy comparison value is specified, whether the value of the attribute matches the comparison value.
43225 * @memberof AbstractNode
43226 */
43227AbstractNode.prototype.isAttribute = function (name, expectedValue, fallbackName) {
43228  return this['$attr?'](name, expectedValue, fallbackName)
43229}
43230
43231/**
43232 * Assign the value to the attribute name for the current node.
43233 *
43234 * @param {string} name - The String attribute name to assign
43235 * @param {*} value - The Object value to assign to the attribute (default: '')
43236 * @param {boolean} overwrite - A Boolean indicating whether to assign the attribute if currently present in the attributes JSON (default: true)
43237 *
43238 * @returns {boolean} - a Boolean indicating whether the assignment was performed
43239 * @memberof AbstractNode
43240 */
43241AbstractNode.prototype.setAttribute = function (name, value, overwrite) {
43242  if (typeof overwrite === 'undefined') overwrite = true
43243  return this.$set_attr(name, value, overwrite)
43244}
43245
43246/**
43247 * Remove the attribute from the current node.
43248 * @param {string} name - The String attribute name to remove
43249 * @returns {string} - the previous {string} value, or undefined if the attribute was not present.
43250 * @memberof AbstractNode
43251 */
43252AbstractNode.prototype.removeAttribute = function (name) {
43253  const value = this.$remove_attr(name)
43254  return value === Opal.nil ? undefined : value
43255}
43256
43257/**
43258 * Get the {@link Document} to which this node belongs.
43259 *
43260 * @returns {Document} - the {@link Document} object to which this node belongs.
43261 * @memberof AbstractNode
43262 */
43263AbstractNode.prototype.getDocument = function () {
43264  return this.document
43265}
43266
43267/**
43268 * Get the {@link AbstractNode} to which this node is attached.
43269 *
43270 * @memberof AbstractNode
43271 * @returns {AbstractNode} - the {@link AbstractNode} object to which this node is attached,
43272 * or undefined if this node has no parent.
43273 */
43274AbstractNode.prototype.getParent = function () {
43275  const parent = this.parent
43276  return parent === Opal.nil ? undefined : parent
43277}
43278
43279/**
43280 * @returns {boolean} - true if this {AbstractNode} is an instance of {Inline}
43281 * @memberof AbstractNode
43282 */
43283AbstractNode.prototype.isInline = function () {
43284  return this['$inline?']()
43285}
43286
43287/**
43288 * @returns {boolean} - true if this {AbstractNode} is an instance of {Block}
43289 * @memberof AbstractNode
43290 */
43291AbstractNode.prototype.isBlock = function () {
43292  return this['$block?']()
43293}
43294
43295/**
43296 * Checks if the role attribute is set on this node and, if an expected value is given, whether the space-separated role matches that value.
43297 *
43298 * @param {string} expectedValue - The expected String value of the role (optional, default: undefined)
43299 *
43300 * @returns {boolean} - a Boolean indicating whether the role attribute is set on this node and, if an expected value is given, whether the space-separated role matches that value.
43301 * @memberof AbstractNode
43302 */
43303AbstractNode.prototype.isRole = function (expectedValue) {
43304  return this['$role?'](expectedValue)
43305}
43306
43307/**
43308 * Retrieves the space-separated String role for this node.
43309 *
43310 * @returns {string} - the role as a space-separated String.
43311 * @memberof AbstractNode
43312 */
43313AbstractNode.prototype.getRole = function () {
43314  const role = this.$role()
43315  return role === Opal.nil ? undefined : role
43316}
43317
43318/**
43319 * Sets the value of the role attribute on this node.
43320 *
43321 * @param {...string|Array<string>} names - A single role name, a space-separated String of role names, an Array of role names or a list of role names
43322 *
43323 * @returns {string} - the value of the role attribute
43324 * @memberof AbstractNode
43325 */
43326AbstractNode.prototype.setRole = function (names) {
43327  if (Array.isArray(names) || (typeof names === 'string' && arguments.length === 1)) {
43328    return this['$role='](names)
43329  }
43330  return this['$role='](Array.from(arguments))
43331}
43332
43333/**
43334 * Checks if the specified role is present in the list of roles for this node.
43335 *
43336 * @param {string} name - The String name of the role to find.
43337 *
43338 * @returns {boolean} - a Boolean indicating whether this node has the specified role.
43339 * @memberof AbstractNode
43340 */
43341AbstractNode.prototype.hasRole = function (name) {
43342  return this['$has_role?'](name)
43343}
43344
43345/**
43346 * Retrieves the String role names for this node as an Array.
43347 *
43348 * @returns {Array<string>} - the role names as a String {Array}, which is empty if the role attribute is absent on this node.
43349 * @memberof AbstractNode
43350 */
43351AbstractNode.prototype.getRoles = function () {
43352  return this.$roles()
43353}
43354
43355/**
43356 * Adds the given role directly to this node.
43357 *
43358 * @param {string} name - The name of the role to add
43359 *
43360 * @returns {boolean} - a Boolean indicating whether the role was added.
43361 * @memberof AbstractNode
43362 */
43363AbstractNode.prototype.addRole = function (name) {
43364  return this.$add_role(name)
43365}
43366
43367/**
43368 * Public: Removes the given role directly from this node.
43369 *
43370 * @param {string} name - The name of the role to remove
43371 *
43372 * @returns {boolean} - a Boolean indicating whether the role was removed.
43373 * @memberof AbstractNode
43374 */
43375AbstractNode.prototype.removeRole = function (name) {
43376  return this.$remove_role(name)
43377}
43378
43379/**
43380 * A convenience method that checks if the reftext attribute is defined.
43381 * @returns {boolean} - A Boolean indicating whether the reftext attribute is defined
43382 * @memberof AbstractNode
43383 */
43384AbstractNode.prototype.isReftext = function () {
43385  return this['$reftext?']()
43386}
43387
43388/**
43389 * A convenience method that returns the value of the reftext attribute with substitutions applied.
43390 * @returns {string|undefined} - the value of the reftext attribute with substitutions applied.
43391 * @memberof AbstractNode
43392 */
43393AbstractNode.prototype.getReftext = function () {
43394  const reftext = this.$reftext()
43395  return reftext === Opal.nil ? undefined : reftext
43396}
43397
43398/**
43399 * @returns {string} - Get the context name for this node
43400 * @memberof AbstractNode
43401 */
43402AbstractNode.prototype.getContext = function () {
43403  const context = this.context
43404  // Automatically convert Opal pseudo-symbol to String
43405  return typeof context === 'string' ? context : context.toString()
43406}
43407
43408/**
43409 * @returns {string} - the String id of this node
43410 * @memberof AbstractNode
43411 */
43412AbstractNode.prototype.getId = function () {
43413  const id = this.id
43414  return id === Opal.nil ? undefined : id
43415}
43416
43417/**
43418 * @param {string} id - the String id of this node
43419 * @memberof AbstractNode
43420 */
43421AbstractNode.prototype.setId = function (id) {
43422  this.id = id
43423}
43424
43425/**
43426 * A convenience method to check if the specified option attribute is enabled on the current node.
43427 * Check if the option is enabled. This method simply checks to see if the <name>-option attribute is defined on the current node.
43428 *
43429 * @param {string} name - the String name of the option
43430 *
43431 * @return {boolean} - a Boolean indicating whether the option has been specified
43432 * @memberof AbstractNode
43433 */
43434AbstractNode.prototype.isOption = function (name) {
43435  return this['$option?'](name)
43436}
43437
43438/**
43439 * Set the specified option on this node.
43440 * This method sets the specified option on this node by setting the <name>-option attribute.
43441 *
43442 * @param {string} name - the String name of the option
43443 *
43444 * @memberof AbstractNode
43445 */
43446AbstractNode.prototype.setOption = function (name) {
43447  return this.$set_option(name)
43448}
43449
43450/**
43451 * @memberof AbstractNode
43452 */
43453AbstractNode.prototype.getIconUri = function (name) {
43454  return this.$icon_uri(name)
43455}
43456
43457/**
43458 * @memberof AbstractNode
43459 */
43460AbstractNode.prototype.getMediaUri = function (target, assetDirKey) {
43461  return this.$media_uri(target, assetDirKey)
43462}
43463
43464/**
43465 * @memberof AbstractNode
43466 */
43467AbstractNode.prototype.getImageUri = function (targetImage, assetDirKey) {
43468  return this.$image_uri(targetImage, assetDirKey)
43469}
43470
43471/**
43472 * Get the {Converter} instance being used to convert the current {Document}.
43473 * @returns {Object}
43474 * @memberof AbstractNode
43475 */
43476AbstractNode.prototype.getConverter = function () {
43477  return this.$converter()
43478}
43479
43480/**
43481 * @memberof AbstractNode
43482 */
43483AbstractNode.prototype.readContents = function (target, options) {
43484  return this.$read_contents(target, toHash(options))
43485}
43486
43487/**
43488 * Read the contents of the file at the specified path.
43489 * This method assumes that the path is safe to read.
43490 * It checks that the file is readable before attempting to read it.
43491 *
43492 * @param path - the {string} path from which to read the contents
43493 * @param {Object} options - a JSON {Object} of options to control processing (default: {})
43494 * @param {boolean} options.warn_on_failure - a {boolean} that controls whether a warning is issued if the file cannot be read (default: false)
43495 * @param {boolean} options.normalize - a {boolean} that controls whether the lines are normalized and coerced to UTF-8 (default: false)
43496 *
43497 * @returns {string} - the String content of the file at the specified path, or undefined if the file does not exist.
43498 * @memberof AbstractNode
43499 */
43500AbstractNode.prototype.readAsset = function (path, options) {
43501  const result = this.$read_asset(path, toHash(options))
43502  return result === Opal.nil ? undefined : result
43503}
43504
43505/**
43506 * @memberof AbstractNode
43507 */
43508AbstractNode.prototype.normalizeWebPath = function (target, start, preserveTargetUri) {
43509  return this.$normalize_web_path(target, start, preserveTargetUri)
43510}
43511
43512/**
43513 * @memberof AbstractNode
43514 */
43515AbstractNode.prototype.normalizeSystemPath = function (target, start, jail, options) {
43516  return this.$normalize_system_path(target, start, jail, toHash(options))
43517}
43518
43519/**
43520 * @memberof AbstractNode
43521 */
43522AbstractNode.prototype.normalizeAssetPath = function (assetRef, assetName, autoCorrect) {
43523  return this.$normalize_asset_path(assetRef, assetName, autoCorrect)
43524}
43525
43526// Document API
43527
43528/**
43529 * The {@link Document} class represents a parsed AsciiDoc document.
43530 *
43531 * Document is the root node of a parsed AsciiDoc document.<br/>
43532 * It provides an abstract syntax tree (AST) that represents the structure of the AsciiDoc document
43533 * from which the Document object was parsed.
43534 *
43535 * Although the constructor can be used to create an empty document object,
43536 * more commonly, you'll load the document object from AsciiDoc source
43537 * using the primary API methods on {@link Asciidoctor}.
43538 * When using one of these APIs, you almost always want to set the safe mode to 'safe' (or 'unsafe')
43539 * to enable all of Asciidoctor's features.
43540 *
43541 * <pre>
43542 *   const doc = Asciidoctor.load('= Hello, AsciiDoc!', { 'safe': 'safe' })
43543 *   // => Asciidoctor::Document { doctype: "article", doctitle: "Hello, AsciiDoc!", blocks: 0 }
43544 * </pre>
43545 *
43546 * Instances of this class can be used to extract information from the document or alter its structure.
43547 * As such, the Document object is most often used in extensions and by integrations.
43548 *
43549 * The most basic usage of the Document object is to retrieve the document's title.
43550 *
43551 * <pre>
43552 *  const source = '= Document Title'
43553 *  const doc = asciidoctor.load(source, { 'safe': 'safe' })
43554 *  console.log(doc.getTitle()) // 'Document Title'
43555 * </pre>
43556 *
43557 * You can also use the Document object to access document attributes defined in the header, such as the author and doctype.
43558 * @namespace
43559 * @extends AbstractBlock
43560 */
43561const Document = Opal.Asciidoctor.Document
43562
43563/**
43564 * Append a content Block to this Document.
43565 * If the child block is a Section, assign an index to it.
43566 * @param {AbstractBlock} block - the child Block to append to this parent Block
43567 * @returns {AbstractBlock} - the parent block to which this block was appended.
43568 * @memberof Document
43569 */
43570Document.prototype.append = function (block) {
43571  this['$<<'](block)
43572  return this
43573}
43574
43575/**
43576 * Returns the SyntaxHighlighter associated with this document.
43577 *
43578 * @returns {SyntaxHighlighter} - the SyntaxHighlighter associated with this document.
43579 * @memberof Document
43580 */
43581Document.prototype.getSyntaxHighlighter = function () {
43582  const syntaxHighlighter = this.syntax_highlighter
43583  // eslint-disable-next-line no-proto
43584  const prototype = syntaxHighlighter.__proto__
43585  if (prototype) {
43586    if (typeof prototype['$highlight?'] === 'function') {
43587      prototype.handlesHighlighting = function () {
43588        const value = prototype['$highlight?']()
43589        return value === Opal.nil ? false : value
43590      }
43591    }
43592    if (typeof prototype['$docinfo?'] === 'function') {
43593      prototype.hasDocinfo = prototype['$docinfo?']
43594    }
43595    if (typeof prototype.$format === 'function') {
43596      prototype.format = function (node, lang, opts) {
43597        return this.$format(node, lang, toHash(opts))
43598      }
43599    }
43600    if (typeof prototype.$docinfo === 'function') {
43601      prototype.docinfo = function (location, doc, opts) {
43602        return this.$docinfo(location, doc, toHash(opts))
43603      }
43604    }
43605  }
43606  return syntaxHighlighter
43607}
43608
43609/**
43610 * Returns a JSON {Object} of references captured by the processor.
43611 *
43612 * @returns {Object} - a JSON {Object} of {AbstractNode} in the document.
43613 * @memberof Document
43614 */
43615Document.prototype.getRefs = function () {
43616  return fromHash(this.catalog.$$smap.refs)
43617}
43618
43619/**
43620 * Returns an {Array} of {Document/ImageReference} captured by the processor.
43621 *
43622 * @returns {Array<ImageReference>} - an {Array} of {Document/ImageReference} in the document.
43623 * Will return an empty array if the option "catalog_assets: true" was not defined on the processor.
43624 * @memberof Document
43625 */
43626Document.prototype.getImages = function () {
43627  return this.catalog.$$smap.images
43628}
43629
43630/**
43631 * Returns an {Array} of links captured by the processor.
43632 *
43633 * @returns {Array<string>} - an {Array} of links in the document.
43634 * Will return an empty array if:
43635 * - the function was called before the document was converted
43636 * - the option "catalog_assets: true" was not defined on the processor
43637 * @memberof Document
43638 */
43639Document.prototype.getLinks = function () {
43640  return this.catalog.$$smap.links
43641}
43642
43643/**
43644 * @returns {boolean} - true if the document has footnotes otherwise false
43645 * @memberof Document
43646 */
43647Document.prototype.hasFootnotes = function () {
43648  return this['$footnotes?']()
43649}
43650
43651/**
43652 * Returns an {Array} of {Document/Footnote} captured by the processor.
43653 *
43654 * @returns {Array<Footnote>} - an {Array} of {Document/Footnote} in the document.
43655 * Will return an empty array if the function was called before the document was converted.
43656 * @memberof Document
43657 */
43658Document.prototype.getFootnotes = function () {
43659  return this.$footnotes()
43660}
43661
43662/**
43663 * Returns the level-0 {Section} (i.e. the document title).
43664 * Only stores the title, not the header attributes.
43665 *
43666 * @returns {string} - the level-0 {Section}.
43667 * @memberof Document
43668 */
43669Document.prototype.getHeader = function () {
43670  return this.header
43671}
43672
43673/**
43674 * @memberof Document
43675 */
43676Document.prototype.setAttribute = function (name, value) {
43677  return this.$set_attribute(name, value)
43678}
43679
43680/**
43681
43682 * @memberof Document
43683 */
43684Document.prototype.removeAttribute = function (name) {
43685  this.attributes.$delete(name)
43686  this.attribute_overrides.$delete(name)
43687}
43688
43689/**
43690 * Convert the AsciiDoc document using the templates loaded by the C
43690onverter.
43691 * If a "template_dir" is not specified, or a template is missing, the converter will fall back to using the appropriate built-in template.
43692 *
43693 * @param {Object} [options] - a JSON of options to control processing (default: {})
43694 *
43695 * @returns {string}
43696 * @memberof Document
43697 */
43698Document.prototype.convert = function (options) {
43699  const result = this.$convert(toHash(options))
43700  return result === Opal.nil ? '' : result
43701}
43702
43703/**
43704 * Write the output to the specified file.
43705 *
43706 * If the converter responds to "write", delegate the work of writing the file to that method.
43707 * Otherwise, write the output the specified file.
43708 *
43709 * @param {string} output
43710 * @param {string} target
43711 *
43712 * @memberof Document
43713 */
43714Document.prototype.write = function (output, target) {
43715  return this.$write(output, target)
43716}
43717
43718/**
43719 * @returns {string} - the full name of the author as a String
43720 * @memberof Document
43721 */
43722Document.prototype.getAuthor = function () {
43723  return this.$author()
43724}
43725
43726/**
43727 * @returns {string}
43728 * @memberof Document
43729 */
43730Document.prototype.getSource = function () {
43731  return this.$source()
43732}
43733
43734/**
43735 * @returns {Array<string>}
43736 * @memberof Document
43737 */
43738Document.prototype.getSourceLines = function () {
43739  return this.$source_lines()
43740}
43741
43742/**
43743 * @returns {boolean}
43744 * @memberof Document
43745 */
43746Document.prototype.isNested = function () {
43747  return this['$nested?']()
43748}
43749
43750/**
43751 * @returns {boolean}
43752 * @memberof Document
43753 */
43754Document.prototype.isEmbedded = function () {
43755  return this['$embedded?']()
43756}
43757
43758/**
43759 * @returns {boolean}
43760 * @memberof Document
43761 */
43762Document.prototype.hasExtensions = function () {
43763  return this['$extensions?']()
43764}
43765
43766/**
43767 * Get the value of the doctype attribute for this document.
43768 * @returns {string}
43769 * @memberof Document
43770 */
43771Document.prototype.getDoctype = function () {
43772  return this.doctype
43773}
43774
43775/**
43776 * Get the value of the backend attribute for this document.
43777 * @returns {string}
43778 * @memberof Document
43779 */
43780Document.prototype.getBackend = function () {
43781  return this.backend
43782}
43783
43784/**
43785 * @returns {boolean}
43786 * @memberof Document
43787 */
43788Document.prototype.isBasebackend = function (base) {
43789  return this['$basebackend?'](base)
43790}
43791
43792/**
43793 * Get the title explicitly defined in the document attributes.
43794 * @returns {string}
43795 * @see {@link AbstractNode#getAttributes}
43796 * @memberof Document
43797 */
43798Document.prototype.getTitle = function () {
43799  const title = this.$title()
43800  return title === Opal.nil ? undefined : title
43801}
43802
43803/**
43804 * Set the title on the document header
43805 *
43806 * Set the title of the document header to the specified value.
43807 * If the header does not exist, it is first created.
43808 *
43809 * @param {string} title - the String title to assign as the title of the document header
43810 *
43811 * @returns {string} - the new String title assigned to the document header
43812 * @memberof Document
43813 */
43814Document.prototype.setTitle = function (title) {
43815  return this['$title='](title)
43816}
43817
43818/**
43819 * @returns {Document/Title} - a {@link Document/Title}
43820 * @memberof Document
43821 */
43822Document.prototype.getDocumentTitle = function (options) {
43823  const doctitle = this.$doctitle(toHash(options))
43824  return doctitle === Opal.nil ? undefined : doctitle
43825}
43826
43827/**
43828 * @see {@link Document#getDocumentTitle}
43829 * @memberof Document
43830 */
43831Document.prototype.getDoctitle = Document.prototype.getDocumentTitle
43832
43833/**
43834 * Get the document catalog JSON object.
43835 * @returns {Object}
43836 * @memberof Document
43837 */
43838Document.prototype.getCatalog = function () {
43839  return fromHash(this.catalog)
43840}
43841
43842/**
43843 *
43844 * @returns {Object}
43845 * @see Document#getCatalog
43846 * @memberof Document
43847 */
43848Document.prototype.getReferences = Document.prototype.getCatalog
43849
43850/**
43851 * Get the document revision date from document header (document attribute <code>revdate</code>).
43852 * @returns {string}
43853 * @memberof Document
43854 */
43855Document.prototype.getRevisionDate = function () {
43856  return this.getAttribute('revdate')
43857}
43858
43859/**
43860 * @see Document#getRevisionDate
43861 * @returns {string}
43862 * @memberof Document
43863 */
43864Document.prototype.getRevdate = function () {
43865  return this.getRevisionDate()
43866}
43867
43868/**
43869 * Get the document revision number from document header (document attribute <code>revnumber</code>).
43870 * @returns {string}
43871 * @memberof Document
43872 */
43873Document.prototype.getRevisionNumber = function () {
43874  return this.getAttribute('revnumber')
43875}
43876
43877/**
43878 * Get the document revision remark from document header (document attribute <code>revremark</code>).
43879 * @returns {string}
43880 * @memberof Document
43881 */
43882Document.prototype.getRevisionRemark = function () {
43883  return this.getAttribute('revremark')
43884}
43885
43886/**
43887 *  Assign a value to the specified attribute in the document header.
43888 *
43889 *  The assignment will be visible when the header attributes are restored,
43890 *  typically between processor phases (e.g., between parse and convert).
43891 *
43892 * @param {string} name - The {string} attribute name to assign
43893 * @param {Object} value - The {Object} value to assign to the attribute (default: '')
43894 * @param {boolean} overwrite - A {boolean} indicating whether to assign the attribute
43895 * if already present in the attributes Hash (default: true)
43896 *
43897 * @returns {boolean} - true if the assignment was performed otherwise false
43898 * @memberof Document
43899 */
43900Document.prototype.setHeaderAttribute = function (name, value, overwrite) {
43901  if (typeof overwrite === 'undefined') overwrite = true
43902  if (typeof value === 'undefined') value = ''
43903  return this.$set_header_attribute(name, value, overwrite)
43904}
43905
43906/**
43907 * Convenience method to retrieve the authors of this document as an {Array} of {Document/Author} objects.
43908 *
43909 * This method is backed by the author-related attributes on the document.
43910 *
43911 * @returns {Array<Author>} - an {Array} of {Document/Author} objects.
43912 * @memberof Document
43913 */
43914Document.prototype.getAuthors = function () {
43915  return this.$authors()
43916}
43917
43918// Document.Footnote API
43919
43920/**
43921 * @namespace
43922 * @module Document/Footnote
43923 */
43924const Footnote = Document.Footnote
43925
43926/**
43927 * @returns {number} - the footnote's index
43928 * @memberof Document/Footnote
43929 */
43930Footnote.prototype.getIndex = function () {
43931  const index = this.$$data.index
43932  return index === Opal.nil ? undefined : index
43933}
43934
43935/**
43936 * @returns {number} - the footnote's id
43937 * @memberof Document/Footnote
43938 */
43939Footnote.prototype.getId = function () {
43940  const id = this.$$data.id
43941  return id === Opal.nil ? undefined : id
43942}
43943
43944/**
43945 * @returns {string} - the footnote's text
43946 * @memberof Document/Footnote
43947 */
43948Footnote.prototype.getText = function () {
43949  const text = this.$$data.text
43950  return text === Opal.nil ? undefined : text
43951}
43952
43953// Document.ImageReference API
43954
43955/**
43956 * @class
43957 * @module Document/ImageReference
43958 */
43959const ImageReference = Document.ImageReference
43960
43961/**
43962 * @returns {string} - the image's target
43963 * @memberof Document/ImageReference
43964 */
43965ImageReference.prototype.getTarget = function () {
43966  return this.$$data.target
43967}
43968
43969/**
43970 * @returns {string} - the image's directory (imagesdir attribute)
43971 * @memberof Document/ImageReference
43972 */
43973ImageReference.prototype.getImagesDirectory = function () {
43974  const value = this.$$data.imagesdir
43975  return value === Opal.nil ? undefined : value
43976}
43977
43978// Document.Author API
43979
43980/**
43981 * The Author class represents information about an author extracted from document attributes.
43982 * @namespace
43983 * @module Document/Author
43984 */
43985const Author = Document.Author
43986
43987/**
43988 * @returns {string} - the author's full name
43989 * @memberof Document/Author
43990 */
43991Author.prototype.getName = function () {
43992  const name = this.$$data.name
43993  return name === Opal.nil ? undefined : name
43994}
43995
43996/**
43997 * @returns {string} - the author's first name
43998 * @memberof Document/Author
43999 */
44000Author.prototype.getFirstName = function () {
44001  const firstName = this.$$data.firstname
44002  return firstName === Opal.nil ? undefined : firstName
44003}
44004
44005/**
44006 * @returns {string} - the author's middle name (or undefined if the author has no middle name)
44007 * @memberof Document/Author
44008 */
44009Author.prototype.getMiddleName = function () {
44010  const middleName = this.$$data.middlename
44011  return middleName === Opal.nil ? undefined : middleName
44012}
44013
44014/**
44015 * @returns {string} - the author's last name
44016 * @memberof Document/Author
44017 */
44018Author.prototype.getLastName = function () {
44019  const lastName = this.$$data.lastname
44020  return lastName === Opal.nil ? undefined : lastName
44021}
44022
44023/**
44024 * @returns {string}
44024 - the author's initials (by default based on the author's name)
44025 * @memberof Document/Author
44026 */
44027Author.prototype.getInitials = function () {
44028  const initials = this.$$data.initials
44029  return initials === Opal.nil ? undefined : initials
44030}
44031
44032/**
44033 * @returns {string} - the author's email
44034 * @memberof Document/Author
44035 */
44036Author.prototype.getEmail = function () {
44037  const email = this.$$data.email
44038  return email === Opal.nil ? undefined : email
44039}
44040
44041// private constructor
44042Document.RevisionInfo = function (date, number, remark) {
44043  this.date = date
44044  this.number = number
44045  this.remark = remark
44046}
44047
44048/**
44049 * @class
44050 * @namespace
44051 * @module Document/RevisionInfo
44052 */
44053const RevisionInfo = Document.RevisionInfo
44054
44055/**
44056 * Get the document revision date from document header (document attribute <code>revdate</code>).
44057 * @returns {string}
44058 * @memberof Document/RevisionInfo
44059 */
44060RevisionInfo.prototype.getDate = function () {
44061  return this.date
44062}
44063
44064/**
44065 * Get the document revision number from document header (document attribute <code>revnumber</code>).
44066 * @returns {string}
44067 * @memberof Document/RevisionInfo
44068 */
44069RevisionInfo.prototype.getNumber = function () {
44070  return this.number
44071}
44072
44073/**
44074 * Get the document revision remark from document header (document attribute <code>revremark</code>).
44075 * A short summary of changes in this document revision.
44076 * @returns {string}
44077 * @memberof Document/RevisionInfo
44078 */
44079RevisionInfo.prototype.getRemark = function () {
44080  return this.remark
44081}
44082
44083/**
44084 * @returns {boolean} - true if the revision info is empty (ie. not defined), otherwise false
44085 * @memberof Document/RevisionInfo
44086 */
44087RevisionInfo.prototype.isEmpty = function () {
44088  return this.date === undefined && this.number === undefined && this.remark === undefined
44089}
44090
44091// SafeMode API
44092
44093/**
44094 * @namespace
44095 */
44096const SafeMode = Opal.Asciidoctor.SafeMode
44097
44098/**
44099 * @param {string} name - the name of the security level
44100 * @returns {number} - the integer value of the corresponding security level
44101 */
44102SafeMode.getValueForName = function (name) {
44103  return this.$value_for_name(name)
44104}
44105
44106/**
44107 * @param {number} value - the integer value of the security level
44108 * @returns {string} - the name of the corresponding security level
44109 */
44110SafeMode.getNameForValue = function (value) {
44111  const name = this.$name_for_value(value)
44112  return name === Opal.nil ? undefined : name
44113}
44114
44115/**
44116 * @returns {Array<string>} - the String {Array} of security levels
44117 */
44118SafeMode.getNames = function () {
44119  return this.$names()
44120}
44121
44122// Callouts API
44123
44124/**
44125 * Maintains a catalog of callouts and their associations.
44126 * @namespace
44127 */
44128const Callouts = Opal.Asciidoctor.Callouts
44129
44130/**
44131 * Create a new Callouts.
44132 * @returns {Callouts} - a new Callouts
44133 * @memberof Callouts
44134 */
44135Callouts.create = function () {
44136  return this.$new()
44137}
44138
44139/**
44140 * Register a new callout for the given list item ordinal.
44141 * Generates a unique id for this callout based on the index of the next callout list in the document and the index of this callout since the end of the last callout list.
44142 *
44143 * @param {number} ordinal - the Integer ordinal (1-based) of the list item to which this callout is to be associated
44144 * @returns {string} - The unique String id of this callout
44145 * @example
44146 *  callouts = asciidoctor.Callouts.create()
44147 *  callouts.register(1)
44148 *  // => "CO1-1"
44149 *  callouts.nextList()
44150 *  callouts.register(2)
44151 *  // => "CO2-1"
44152 * @memberof Callouts
44153 */
44154
44155Callouts.prototype.register = function (ordinal) {
44156  return this.$register(ordinal)
44157}
44158/**
44159 * Get the next callout index in the document.
44160 *
44161 * Reads the next callout index in the document and advances the pointer.
44162 * This method is used during conversion to retrieve the unique id of the callout that was generated during parsing.
44163 *
44164 * @returns {string} - The unique String id of the next callout in the document
44165 * @memberof Callouts
44166 */
44167Callouts.prototype.readNextId = function () {
44168  return this.$read_next_id()
44169}
44170
44171/**
44172 * et a space-separated list of callout ids for the specified list item.
44173 * @param {number} ordinal - the Integer ordinal (1-based) of the list item for which to retrieve the callouts
44174 * @returns {string} - a space-separated String of callout ids associated with the specified list item
44175 * @memberof Callouts
44176 */
44177Callouts.prototype.getCalloutIds = function (ordinal) {
44178  return this.$callout_ids(ordinal)
44179}
44180
44181/**
44182 * @memberof Callouts
44183 */
44184Callouts.prototype.getLists = function () {
44185  const lists = this.lists
44186  if (lists && lists.length > 0) {
44187    for (let i = 0; i < lists.length; i++) {
44188      const list = lists[i]
44189      if (list && list.length > 0) {
44190        for (let j = 0; j < list.length; j++) {
44191          if (typeof list[j] === 'object' && '$$smap' in list[j]) {
44192            list[j] = fromHash(list[j])
44193          }
44194        }
44195      }
44196    }
44197  }
44198  return lists
44199}
44200
44201/**
44202 * @memberof Callouts
44203 */
44204Callouts.prototype.getListIndex = function () {
44205  return this.list_index
44206}
44207
44208/**
44209 * The current list for which callouts are being collected.
44210 * @returns {Array} - The Array of callouts at the position of the list index pointer
44211 * @memberof Callouts
44212 */
44213Callouts.prototype.getCurrentList = function () {
44214  const currentList = this.$current_list()
44215  if (currentList && currentList.length > 0) {
44216    for (let i = 0; i < currentList.length; i++) {
44217      if (typeof currentList[i] === 'object' && '$$smap' in currentList[i]) {
44218        currentList[i] = fromHash(currentList[i])
44219      }
44220    }
44221  }
44222  return currentList
44223}
44224
44225/**
44226 * Advance to the next callout list in the document.
44227 * @memberof Callouts
44228 */
44229Callouts.prototype.nextList = function () {
44230  return this.$nextList()
44231}
44232
44233/**
44234 * Rewind the list index pointer, intended to be used when switching from the parsing to conversion phase.
44235 * @memberof Callouts
44236 */
44237Callouts.prototype.rewind = function () {
44238  return this.$rewind()
44239}
44240
44241/**
44242 * @returns {Document/RevisionInfo} - a {@link Document/RevisionInfo}
44243 * @memberof Document
44244 */
44245Document.prototype.getRevisionInfo = function () {
44246  return new Document.RevisionInfo(this.getRevisionDate(), this.getRevisionNumber(), this.getRevisionRemark())
44247}
44248
44249/**
44250 * @returns {boolean} - true if the document contains revision info, otherwise false
44251 * @memberof Document
44252 */
44253Document.prototype.hasRevisionInfo = function () {
44254  const revisionInfo = this.getRevisionInfo()
44255  return !revisionInfo.isEmpty()
44256}
44257
44258/**
44259 * @returns {boolean}
44260 * @memberof Document
44261 */
44262Document.prototype.getNotitle = function () {
44263  return this.$notitle()
44264}
44265
44266/**
44267 * @returns {boolean}
44268 * @memberof Document
44269 */
44270Document.prototype.getNoheader = function () {
44271  return this.$noheader()
44272}
44273
44274/**
44275 * @returns {boolean}
44276 * @memberof Document
44277 */
44278Document.prototype.getNofooter = function () {
44279  return this.$nofooter()
44280}
44281
44282/**
44283 * @returns {boolean}
44284 * @memberof Document
44285 */
44286Document.prototype.hasHeader = function () {
44287  return this['$header?']()
44288}
44289
44290/**
44291 * Replay attribute assignments at the block level.
44292 *
44293 * <i>This method belongs to an internal API that deals with how attributes are managed by the processor.</i>
44294 * If you understand why this group of methods are necessary, and what they do, feel free to use them.
44295 * <strong>However, keep in mind they are subject to change at any time.</strong>
44296 *
44297 * @param {Object} blockAttributes - A JSON of attributes
44298 * @memberof Document
44299 */
44300Document.prototype.playbackAttributes = function (blockAttributes) {
44301  blockAttributes = toHash(blockAttributes)
44302  if (blockAttributes) {
44303    const attrEntries = blockAttributes['$[]']('attribute_entries')
44304    if (attrEntries && Array.isArray(attrEntries)) {
44305      const result = []
44306      for (let i = 0; i < attrEntries.length; i++) {
44307        const attrEntryObject = attrEntries[i]
44308        if (attrEntryObject && typeof attrEntryObject === 'object' && attrEntryObject.constructor.name === 'Object') {
44309          attrEntryObject.$name = function () {
44310            return this.name
44311          }
44312          attrEntryObject.$value = function () {
44313            return this.value
44314          }
44315          attrEntryObject.$negate = function () {
44316            return this.negate
44317          }
44318        }
44319        result.push(attrEntryObject)
44320      }
44321      blockAttributes['$[]=']('attribute_entries', result)
44322    }
44323  }
44324  this.$playback_attributes(blockAttributes)
44325}
44326
44327/**
44328 * Delete the specified attribute from the document if the name is not locked.
44329 * If the attribute is locked, false is returned.
44330 * Otherwise, the attribute is deleted.
44331 *
44332 * @param {string} name - the String attribute name
44333 *
44334 * @returns {boolean} - true if the attribute was deleted, false if it was not because it's locked
44335 * @memberof Document
44336 */
44337Document.prototype.deleteAttribute = function (name) {
44338  return this.$delete_attribute(name)
44339}
44340
44341/**
44342 * Determine if the attribute has been locked by being assigned in document options.
44343 *
44344 * @param {string} key - The attribute key to check
44345 *
44346 * @returns {boolean} - true if the attribute is locked, false otherwise
44347 * @memberof Document
44348 */
44349Document.prototype.isAttributeLocked = function (key) {
44350  return this['$attribute_locked?'](key)
44351}
44352
44353/**
44354 * Restore the attributes to the previously saved state (attributes in header).
44355 *
44356 * @memberof Document
44357 */
44358Document.prototype.restoreAttributes = function () {
44359  return this.$restore_attributes()
44360}
44361
44362/**
44363 * Parse the AsciiDoc source stored in the {Reader} into an abstract syntax tree.
44364 *
44365 * If the data parameter is not nil, create a new {PreprocessorReader} and assigned it to the reader property of this object.
44366 * Otherwise, continue with the reader that was created when the {Document} was instantiated.
44367 * Pass the reader to {Parser.parse} to parse the source data into an abstract syntax tree.
44368 *
44369 * If parsing has already been performed, this method returns without performing any processing.
44370 *
44371 * @param {string|Array<string>} [data] - The optional replacement AsciiDoc source data as a String or String Array. (default: undefined)
44372 *
44373 * @returns {Document} - this {Document}
44374 * @memberof Document
44375 */
44376Document.prototype.parse = function (data) {
44377  return this.$parse(data)
44378}
44379
44380/**
44381 * Read the docinfo file(s) for inclusion in the document template
44382 *
44383 * If the docinfo1 attribute is set, read the docinfo.ext file.
44384 * If the docinfo attribute is set, read the doc-name.docinfo.ext file.
44385 * If the docinfo2 attribute is set, read both files in that order.
44386 *
44387 * @param {string} docinfoLocation - The Symbol location of the docinfo (e.g., head, footer, etc). (default: head)
44388 * @param {string|undefined} suffix - The suffix of the docinfo file(s).
44389 * If not set, the extension will be set to the outfilesuffix. (default: undefined)
44390 *
44391 * @returns {string} - the contents of the docinfo file(s) or empty string if no files are found or the safe mode is secure or greater.
44392 * @memberof Document
44393 */
44394Document.prototype.getDocinfo = function (docinfoLocation, suffix) {
44395  return this.$docinfo(docinfoLocation, suffix)
44396}
44397
44398/**
44399 * @param {string} [docinfoLocation] - A {string} for checking docinfo extensions at a given location (head or footer) (default: head)
44400 * @returns {boolean}
44401 * @memberof Document
44402 */
44403Document.prototype.hasDocinfoProcessors = function (docinfoLocation) {
44404  return this['$docinfo_processors?'](docinfoLocation)
44405}
44406
44407/**
44408 * Increment the specified counter and store it in the block's attributes.
44409 *
44410 * @param {string} counterName - the String name of the counter attribute
44411 * @param {Block} block - the {Block} on which to save the counter
44412 *
44413 * @returns {number} - the next number in the sequence for the specified counter
44414 * @memberof Document
44415 */
44416Document.prototype.incrementAndStoreCounter = function (counterName, block) {
44417  return this.$increment_and_store_counter(counterName, block)
44418}
44419
44420/**
44421 * @deprecated Please use {Document#incrementAndStoreCounter} method.
44422 * @memberof Document
44423 */
44424Document.prototype.counterIncrement = Document.prototype.incrementAndStoreCounter
44425
44426/**
44427 * Get the named counter and take the next number in the sequence.
44428 *
44429 * @param {string} name - the String name of the counter
44430 * @param {string|number} seed - the initial value as a String or Integer
44431 *
44432 * @returns {number} the next number in the sequence for the specified counter
44433 * @memberof Document
44434 */
44435Document.prototype.counter = function (name, seed) {
44436  return this.$counter(name, seed)
44437}
44438
44439/**
44440 * A read-only integer value indicating the level of security that should be enforced while processing this document.
44441 * The value must be set in the Document constructor using the "safe" option.
44442 *
44443 * A value of 0 (UNSAFE) disables any of the security features enforced by Asciidoctor.
44444 *
44445 * A value of 1 (SAFE) closely parallels safe mode in AsciiDoc.
44446 * In particular, it prevents access to files which reside outside of the parent directory of the source file and disables any macro other than the include directive.
44447 *
44448 * A value of 10 (SERVER) disallows the document from setting attributes that would affect the conversion of the document,
44449 * in addition to all the security features of SafeMode.SAFE.
44450 * For instance, this level forbids changing the backend or source-highlighter using an attribute defined in the source document header.
44451 * This is the most fundamental level of security for server deployments (hence the name).
44452 *
44453 * A value of 20 (SECURE) disallows the document from attempting to read files from the file system and including the contents of them into the document,
44454 * in addition to all the security features of SafeMode.SECURE.
44455 * In particular, it disallows use of the include::[] directive and the embedding of binary content (data uri), stylesheets and JavaScripts referenced by the document.
44456 * (Asciidoctor and trusted extensions may still be allowed to embed trusted content into the document).
44457 *
44458 * Since Asciidoctor is aiming for wide adoption, 20 (SECURE) is the default value and is recommended for server deployments.
44459 *
44460 * A value of 100 (PARANOID) is planned to disallow the use of passthrough macros and prevents the document from setting any known attributes,
44461 * in addition to all the security features of SafeMode.SECURE.
44462 * Please note that this level is not currently implemented (and therefore not enforced)!
44463 *
44464 * @returns {number} - An integer value indicating the level of security
44465 * @memberof Document
44466 */
44467Document.prototype.getSafe = function () {
44468  return this.safe
44469}
44470
44471/**
44472 * Get the Boolean AsciiDoc compatibility mode.
44473 * Enabling this attribute activates the following syntax changes:
44474 *
44475 *   * single quotes as constrained emphasis formatting marks
44476 *   * single backticks parsed as inline literal, formatted as monospace
44477 *   * single plus parsed as constrained, monospaced inline formatting
44478 *   * double plus parsed as constrained, monospaced inline formatting
44479 *
44480 * @returns {boolean}
44481 * @memberof Document
44482 */
44483Document.prototype.getCompatMode = function () {
44484  return this.compat_mode
44485}
44486
44487/**
44488 * Get the Boolean flag that indicates whether source map information should be tracked by the parser.
44489 * @returns {boolean}
44490 * @memberof Document
44491 */
44492Document.prototype.getSourcemap = function () {
44493  const sourcemap = this.sourcemap
44494  return sourcemap === Opal.nil ? false : sourcemap
44495}
44496
44497/**
44498 * Set the Boolean flag that indicates whether source map information should be tracked by the parser.
44499 * @param {boolean} value
44500 * @memberof Document
44501 */
44502Document.prototype.setSourcemap = function (value) {
44503  this.sourcemap = value
44504}
44505
44506/**
44507 * Get the JSON of document counters.
44508 * @returns {Object}
44509 * @memberof Document
44510 */
44511Document.prototype.getCounters = function () {
44512  return fromHash(this.counters)
44513}
44514
44515/**
44516 * @returns {Object}
44517 * @memberof Document
44518 */
44519Document.prototype.getCallouts = function () {
44520  return this.$callouts()
44521}
44522
44523/**
44524 * Get the String base directory for converting this document.
44525 *
44526 * Defaults to directory of the source file.
44527 * If the source is a string, defaults to the current directory.
44528 * @returns {string}
44529 * @memberof Document
44530 */
44531Document.prototype.getBaseDir = function () {
44532  return this.base_dir
44533}
44534
44535/**
44536 * Get the JSON of resolved options used to initialize this {Document}.
44537 * @returns {Object}
44538 * @memberof Document
44539 */
44540Document.prototype.getOptions = function () {
44541  return fromHash(this.options)
44542}
44543
44544/**
44545 * Get the outfilesuffix defined at the end of the header.
44546 * @returns {string}
44547 * @memberof Document
44548 */
44549Document.prototype.getOutfilesuffix = function () {
44550  return this.outfilesuffix
44551}
44552
44553/**
44554 * Get a reference to the parent Document of this nested document.
44555 * @returns {Document|undefined}
44556 * @memberof Document
44557 */
44558Document.prototype.getParentDocument = function () {
44559  const parentDocument = this.parent_document
44560  return parentDocument === Opal.nil ? undefined : parentDocument
44561}
44562
44563/**
44564 * Get the {Reader} associated with this document.
44565 * @returns {Object}
44566 * @memberof Document
44567 */
44568Document.prototype.getReader = function () {
44569  return this.reader
44570}
44571
44572/**
44573 * Get the {Converter} instance being used to convert the current {Document}.
44574 * @returns {Object}
44575 * @memberof Document
44576 */
44577Document.prototype.getConverter = function () {
44578  return this.converter
44579}
44580
44581/**
44582 * Get the activated {Extensions.Registry} associated with this document.
44583 * @returns {Extensions/Registry}
44584 * @memberof Document
44585 */
44586Document.prototype.getExtensions = function () {
44587  const extensions = this.extensions
44588  return extensions === Opal.nil ? undefined : extensions
44589}
44590
44591// Document.Title API
44592
44593/**
44594 * A partitioned title (i.e., title & subtitle).
44595 * @namespace
44596 * @module Document/Title
44597 */
44598const Title = Document.Title
44599
44600/**
44601 * @returns {string}
44602 * @memberof Document/Title
44603 */
44604Title.prototype.getMain = function () {
44605  return this.main
44606}
44607
44608/**
44609 * @returns {string}
44610 * @memberof Document/Title
44611 */
44612Title.prototype.getCombined = function () {
44613  return this.combined
44614}
44615
44616/**
44617 * @returns {string}
44618 * @memberof Document/Title
44619 */
44620Title.prototype.getSubtitle = function () {
44621  const subtitle = this.subtitle
44622  return subtitle === Opal.nil ? undefined : subtitle
44623}
44624
44625/**
44626 * @returns {boolean}
44627 * @memberof Document/Title
44628 */
44629Title.prototype.isSanitized = function () {
44630  const sanitized = this['$sanitized?']()
44631  return sanitized === Opal.nil ? false : sanitized
44632}
44633
44634/**
44635 * @returns {boolean}
44636 * @memberof Document/Title
44637 */
44638Title.prototype.hasSubtitle = function () {
44639  return this['$subtitle?']()
44640}
44641
44642// Inline API
44643
44644/**
44645 * Methods for managing inline elements in AsciiDoc block.
44646 * @namespace
44647 * @extends AbstractNode
44648 */
44649const Inline = Opal.Asciidoctor.Inline
44650
44651/**
44652 * Create a new Inline element.
44653 * @param {AbstractBlock} parent
44654 * @param {string} context
44655 * @param {string|undefined} text
44656 * @param {Object|undefined} opts
44657 * @returns {Inline} - a new Inline element
44658 * @memberof Inline
44659 */
44660Inline.create = function (parent, context, text, opts) {
44661  return this.$new(parent, context, text, prepareOptions(opts))
44662}
44663
44664/**
44665 * Get the converted content for this inline node.
44666 *
44667 * @returns {string} - the converted String content for this inline node
44668 * @memberof Inline
44669 */
44670Inline.prototype.convert = function () {
44671  return this.$convert()
44672}
44673
44674/**
44675 * Get the converted String text of this Inline node, if applicable.
44676 *
44677 * @returns {string|undefined} - the converted String text for this Inline node, or undefined if not applicable for this node.
44678 * @memberof Inline
44679 */
44680Inline.prototype.getText = function () {
44681  const text = this.$text()
44682  return text === Opal.nil ? undefined : text
44683}
44684
44685/**
44686 * Get the String sub-type (aka qualifier) of this Inline node.
44687 *
44688 * This value is used to distinguish different variations of the same node
44689 * category, such as different types of anchors.
44690 *
44691 * @returns {string} - the string sub-type of this Inline node.
44692 * @memberof Inline
44693 */
44694Inline.prototype.getType = function () {
44695  return this.$type()
44696}
44697
44698/**
44699 * Get the primary String target of this Inline node.
44700 *
44701 * @returns {string|undefined} - the string target of this Inline node.
44702 * @memberof Inline
44703 */
44704Inline.prototype.getTarget = function () {
44705  const target = this.$target()
44706  return target === Opal.nil ? undefined : target
44707}
44708
44709/**
44710 * Returns the converted alt text for this inline image.
44711 *
44712 * @returns {string} - the String value of the alt attribute.
44713 * @memberof Inline
44714 */
44715Inline.prototype.getAlt = function () {
44716  return this.$alt()
44717}
44718
44719// List API
44720
44721/**
44722 * Methods for managing AsciiDoc lists (ordered, unordered and description lists).
44723 * @namespace
44724 * @extends AbstractBlock
44725 */
44726const List = Opal.Asciidoctor.List
44727
44728/**
44729 * Checks if the {@link List} contains any child {@link ListItem}.
44730 *
44731 * @memberof List
44732 * @returns {boolean} - whether the {@link List} has child {@link ListItem}.
44733 */
44734List.prototype.hasItems = function () {
44735  return this['$items?']()
44736}
44737
44738/**
44739 * Get the Array of {@link ListItem} nodes for this {@link List}.
44740 *
44741 * @returns {Array<ListItem>} - an Array of {@link ListItem} nodes.
44742 * @memberof List
44743 */
44744List.prototype.getItems = function () {
44745  return this.blocks
44746}
44747
44748// ListItem API
44749
44750/**
44751 * Methods for managing items for AsciiDoc olists, ulist, and dlists.
44752 *
44753 * In a description list (dlist), each item is a tuple that consists of a 2-item Array of ListItem terms and a ListItem description (i.e., [[term, term, ...], desc].
44754 * If a description is not set, then the second entry in the tuple is nil.
44755 * @namespace
44756 * @extends AbstractBlock
44757 */
44758const ListItem = Opal.Asciidoctor.ListItem
44759
44760/**
44761 * Get the converted String text of this {@link ListItem} node.
44762 *
44763 * @returns {string} - the converted String text for this {@link ListItem} node.
44764 * @memberof ListItem
44765 */
44766ListItem.prototype.getText = function () {
44767  return this.$text()
44768}
44769
44770/**
44771 * Set the String source text of this {@link ListItem} node.
44772 *
44773 * @returns {string} - the new String text assigned to this {@link ListItem}
44774 * @memberof ListItem
44775 */
44776ListItem.prototype.setText = function (text) {
44777  return this['$text='](text)
44778}
44779
44780/**
44781 * A convenience method that checks whether the text of this {@link ListItem} is not blank (i.e. not undefined or empty string).
44782 *
44783 * @returns {boolean} - whether the text is not blank
44784 * @memberof ListItem
44785 */
44786ListItem.prototype.hasText = function () {
44787  return this['$text?']()
44788}
44789
44790/**
44791 * Get the {string} used to mark this {@link ListItem}.
44792 *
44793 * @returns {string}
44794 * @memberof ListItem
44795 */
44796ListItem.prototype.getMarker = function () {
44797  return this.marker
44798}
44799
44800/**
44801 * Set the {string} used to mark this {@link ListItem}.
44802 *
44803 * @param {string} marker - the {string} used to mark this {@link ListItem}
44804 * @memberof ListItem
44805 */
44806ListItem.prototype.setMarker = function (marker) {
44807  this.marker = marker
44808}
44809
44810/**
44811 * Get the {@link List} to which this {@link ListItem} is attached.
44812 *
44813 * @returns {List} - the {@link List} object to which this {@link ListItem} is attached,
44814 * or undefined if this node has no parent.
44815 * @memberof ListItem
44816 */
44817ListItem.prototype.getList = function () {
44818  return this.$list()
44819}
44820
44821/**
44822 * @see {@link ListItem#getList}
44823 * @memberof ListItem
44824 */
44825ListItem.prototype.getParent = ListItem.prototype.getList
44826
44827// Reader API
44828
44829/** @namespace */
44830const Reader = Opal.Asciidoctor.Reader
44831
44832/**
44833 * Push source onto the front of the reader and switch the context based on the file, document-relative path and line information given.
44834 *
44835 * This method is typically used in an IncludeProcessor to add source read from the target specified.
44836 *
44837 * @param {string} data
44838 * @param {string|undefined} file
44839 * @param {string|undefined} path
44840 * @param {number} lineno - The line number
44841 * @param {Object} attributes - a JSON of attributes
44842 * @returns {Reader} - this {Reader} object.
44843 * @memberof Reader
44844 */
44845Reader.prototype.pushInclude = function (data, file, path, lineno, attributes) {
44846  return this.$push_include(data, file, path, lineno, toHash(attributes))
44847}
44848
44849/**
44850 * Get the current location of the reader's cursor, which encapsulates the file, dir, path, and lineno of the file being read.
44851 *
44852 * @returns {Cursor}
44853 * @memberof Reader
44854 */
44855Reader.prototype.getCursor = function () {
44856  return this.$cursor()
44857}
44858
44859/**
44860 * Get the remaining unprocessed lines, without consuming them, as an {Array} of {string}.
44861 *
44862 * Lines will not be consumed from the Reader (ie. you will be able to read these lines again).
44863 *
44864 * @returns {Array<string>} - the remaining unprocessed lines as an {Array} of {string}.
44865 * @memberof Reader
44866 */
44867Reader.prototype.getLines = function () {
44868  return this.$lines()
44869}
44870
44871/**
44872 * Get the remaining unprocessed lines, without consuming them, as a {string}.
44873 *
44874 * Lines will not be consumed from the Reader (ie. you will be able to read these lines again).
44875 *
44876 * @returns {string} - the remaining unprocessed lines as a {string} (joined by linefeed characters).
44877 * @memberof Reader
44878 */
44879Reader.prototype.getString = function () {
44880  return this.$string()
44881}
44882
44883/**
44884 * Check whether there are any lines left to read.
44885 * If a previous call to this method resulted in a value of false, immediately returned the cached value.
44886 * Otherwise, delegate to peekLine to determine if there is a next line available.
44887 *
44888 * @returns {boolean} - true if there are more lines, false if there are not.
44889 * @memberof Reader
44890 */
44891Reader.prototype.hasMoreLines = function () {
44892  return this['$has_more_lines?']()
44893}
44894
44895/**
44896 * Check whether this reader is empty (contains no lines).
44897 *
44898 * @returns {boolean} - true if there are no more lines to peek, otherwise false.
44899 * @memberof Reader
44900 */
44901Reader.prototype.isEmpty = function () {
44902  return this['$empty?']()
44903}
44904
44905/**
44906 * Peek at the next line.
44907 * Processes the line if not already marked as processed, but does not consume it (ie. you will be able to read this line again).
44908 *
44909 * This method will probe the reader for more lines.
44910 * If there is a next line that has not previously been visited, the line is passed to the Reader#processLine method to be initialized.
44911 * This call gives sub-classes the opportunity to do preprocessing.
44912 * If the return value of the Reader#processLine is undefined, the data is assumed to be changed and Reader#peekLine is invoked again to perform further processing.
44913 *
44914 * If hasMoreLines is called immediately before peekLine, the direct flag is implicitly true (since the line is flagged as visited).
44915 *
44916 * @param {boolean} direct - A {boolean} flag to bypasses the check for more lines and immediately returns the first element of the internal lines {Array}. (default: false)
44917 * @returns {string} - the next line as a {string} if there are lines remaining.
44918 * @memberof Reader
44919 */
44920Reader.prototype.peekLine = function (direct) {
44921  direct = direct || false
44922  const line = this.$peek_line(direct)
44923  return line === Opal.nil ? undefined : line
44924}
44925
44926/**
44927 * Consume, preprocess, and return the next line.
44928 *
44929 * Line will be consumed from the Reader (ie. you won't be able to read this line again).
44930 *
44931 * @returns {string}
44931 - the next line as a {string} if data is present.
44932 * @memberof Reader
44933 */
44934Reader.prototype.readLine = function () {
44935  const line = this.$read_line()
44936  return line === Opal.nil ? undefined : line
44937}
44938
44939/**
44940 * Consume, preprocess, and return the remaining lines.
44941 *
44942 * This method calls Reader#readLine repeatedly until all lines are consumed and returns the lines as an {Array} of {string}.
44943 * This method differs from Reader#getLines in that it processes each line in turn, hence triggering any preprocessors implemented in sub-classes.
44944 *
44945 * Lines will be consumed from the Reader (ie. you won't be able to read these lines again).
44946 *
44947 * @returns {Array<string>} - the lines read as an {Array} of {string}.
44948 * @memberof Reader
44949 */
44950Reader.prototype.readLines = function () {
44951  return this.$read_lines()
44952}
44953
44954/**
44955 * Consume, preprocess, and return the remaining lines joined as a {string}.
44956 *
44957 * Delegates to Reader#readLines, then joins the result.
44958 *
44959 * Lines will be consumed from the Reader (ie. you won't be able to read these lines again).
44960 *
44961 * @returns {string} - the lines read joined as a {string}
44962 * @memberof Reader
44963 */
44964Reader.prototype.read = function () {
44965  return this.$read()
44966}
44967
44968/**
44969 * Advance to the next line by discarding the line at the front of the stack.
44970 *
44971 * @returns {boolean} - a Boolean indicating whether there was a line to discard.
44972 * @memberof Reader
44973 */
44974Reader.prototype.advance = function () {
44975  return this.$advance()
44976}
44977
44978// Cursor API
44979
44980/** @namespace */
44981const Cursor = Opal.Asciidoctor.Reader.Cursor
44982
44983/**
44984 * Get the file associated to the cursor.
44985 * @returns {string|undefined}
44986 * @memberof Cursor
44987 */
44988Cursor.prototype.getFile = function () {
44989  const file = this.file
44990  return file === Opal.nil ? undefined : file
44991}
44992
44993/**
44994 * Get the directory associated to the cursor.
44995 * @returns {string|undefined} - the directory associated to the cursor
44996 * @memberof Cursor
44997 */
44998Cursor.prototype.getDirectory = function () {
44999  const dir = this.dir
45000  return dir === Opal.nil ? undefined : dir
45001}
45002
45003/**
45004 * Get the path associated to the cursor.
45005 * @returns {string|undefined} - the path associated to the cursor (or '<stdin>')
45006 * @memberof Cursor
45007 */
45008Cursor.prototype.getPath = function () {
45009  const path = this.path
45010  return path === Opal.nil ? undefined : path
45011}
45012
45013/**
45014 * Get the line number of the cursor.
45015 * @returns {number|undefined} - the line number of the cursor
45016 * @memberof Cursor
45017 */
45018Cursor.prototype.getLineNumber = function () {
45019  return this.lineno
45020}
45021
45022// Logger API (available in Asciidoctor 1.5.7+)
45023
45024function initializeLoggerFormatterClass (className, functions) {
45025  const superclass = Opal.const_get_qualified(Opal.Logger, 'Formatter')
45026  return initializeClass(superclass, className, functions, {}, {
45027    call: function (args) {
45028      for (let i = 0; i < args.length; i++) {
45029        // convert all (Opal) Hash arguments to JSON.
45030        if (typeof args[i] === 'object' && '$$smap' in args[i]) {
45031          args[i] = fromHash(args[i])
45032        }
45033      }
45034      return args
45035    }
45036  })
45037}
45038
45039function initializeLoggerClass (className, functions) {
45040  const superClass = Opal.const_get_qualified(Opal.Asciidoctor, 'Logger')
45041  return initializeClass(superClass, className, functions, {}, {
45042    add: function (args) {
45043      if (args.length >= 2 && typeof args[2] === 'object' && '$$smap' in args[2]) {
45044        const message = args[2]
45045        const messageObject = fromHash(message)
45046        messageObject.getText = function () {
45047          return this.text
45048        }
45049        messageObject.getSourceLocation = function () {
45050          return this.source_location
45051        }
45052        messageObject.$inspect = function () {
45053          const sourceLocation = this.getSourceLocation()
45054          if (sourceLocation) {
45055            return sourceLocation.getPath() + ': line ' + sourceLocation.getLineNumber() + ': ' + this.getText()
45056          } else {
45057            return this.getText()
45058          }
45059        }
45060        args[2] = messageObject
45061      }
45062      if (args.length >= 1) {
45063        args[1] = args[1] === Opal.nil ? undefined : args[1]
45064      }
45065      return args
45066    }
45067  })
45068}
45069
45070/**
45071 * @namespace
45072 */
45073const LoggerManager = Opal.const_get_qualified(Opal.Asciidoctor, 'LoggerManager', true)
45074
45075// Alias
45076Opal.Asciidoctor.LoggerManager = LoggerManager
45077
45078/**
45079 * @memberof LoggerManager
45080 */
45081LoggerManager.getLogger = function () {
45082  return this.$logger()
45083}
45084
45085/**
45086 * @memberof LoggerManager
45087 */
45088LoggerManager.setLogger = function (logger) {
45089  this['$logger='](logger)
45090}
45091
45092/**
45093 * @memberof LoggerManager
45094 */
45095LoggerManager.newLogger = function (name, functions) {
45096  return initializeLoggerClass(name, functions).$new()
45097}
45098
45099/**
45100 * @memberof LoggerManager
45101 */
45102LoggerManager.newFormatter = function (name, functions) {
45103  return initializeLoggerFormatterClass(name, functions).$new()
45104}
45105
45106/**
45107 * @namespace
45108 */
45109const LoggerSeverity = Opal.const_get_qualified(Opal.Logger, 'Severity', true)
45110
45111// Alias
45112Opal.Asciidoctor.LoggerSeverity = LoggerSeverity
45113
45114/**
45115 * @memberof LoggerSeverity
45116 */
45117LoggerSeverity.get = function (severity) {
45118  return LoggerSeverity.$constants()[severity]
45119}
45120
45121/**
45122 * @namespace
45123 */
45124const LoggerFormatter = Opal.const_get_qualified(Opal.Logger, 'Formatter', true)
45125
45126// Alias
45127Opal.Asciidoctor.LoggerFormatter = LoggerFormatter
45128
45129/**
45130 * @memberof LoggerFormatter
45131 */
45132LoggerFormatter.prototype.call = function (severity, time, programName, message) {
45133  return this.$call(LoggerSeverity.get(severity), time, programName, message)
45134}
45135
45136/**
45137 * @namespace
45138 */
45139const MemoryLogger = Opal.const_get_qualified(Opal.Asciidoctor, 'MemoryLogger', true)
45140
45141// Alias
45142Opal.Asciidoctor.MemoryLogger = MemoryLogger
45143
45144/**
45145 * Create a new MemoryLogger.
45146 * @returns {MemoryLogger} - a MemoryLogger
45147 * @memberof MemoryLogger
45148 */
45149MemoryLogger.create = function () {
45150  return this.$new()
45151}
45152
45153/**
45154 * @returns {Array<Object>} - a list of messages
45155 * @memberof MemoryLogger
45156 */
45157MemoryLogger.prototype.getMessages = function () {
45158  const messages = this.messages
45159  const result = []
45160  for (let i = 0; i < messages.length; i++) {
45161    const message = messages[i]
45162    const messageObject = fromHash(message)
45163    if (typeof messageObject.message === 'string') {
45164      messageObject.getText = function () {
45165        return this.message
45166      }
45167    } else {
45168      // also convert the message attribute
45169      messageObject.message = fromHash(messageObject.message)
45170      messageObject.getText = function () {
45171        return this.message.text
45172      }
45173    }
45174    messageObject.getSeverity = function () {
45175      return this.severity.toString()
45176    }
45177    messageObject.getSourceLocation = function () {
45178      return this.message.source_location
45179    }
45180    result.push(messageObject)
45181  }
45182  return result
45183}
45184
45185const Logging = Opal.const_get_qualified(Opal.Asciidoctor, 'Logging', true)
45186
45187Opal.Asciidoctor.Logging = Logging
45188
45189Logging.getLogger = function () {
45190  return LoggerManager.$logger()
45191}
45192
45193Logging.createLogMessage = function (text, context) {
45194  return Logging.prototype.$message_with_context(text, toHash(context))
45195}
45196
45197// alias
45198
45199/**
45200 * @memberof Reader
45201 */
45202Reader.prototype.getLogger = Logging.getLogger
45203/**
45204 * @memberof Reader
45205 */
45206Reader.prototype.createLogMessage = Logging.createLogMessage
45207
45208/**
45209 * @memberof AbstractNode
45210 */
45211AbstractNode.prototype.getLogger = Logging.getLogger
45212/**
45213 * @memberof AbstractNode
45214 */
45215AbstractNode.prototype.createLogMessage = Logging.createLogMessage
45216
45217/**
45218 * @namespace
45219 */
45220const Logger = Opal.const_get_qualified(Opal.Asciidoctor, 'Logger', true)
45221
45222// Alias
45223Opal.Asciidoctor.Logger = Logger
45224
45225/**
45226 * @returns {number|undefined} - the maximum severity
45227 * @memberof Logger
45228 */
45229Logger.prototype.getMaxSeverity = function () {
45230  const result = this.max_severity
45231  return result === Opal.nil ? undefined : result
45232}
45233/**
45234 * @returns {LoggerFormatter} - the formatter
45235 * @memberof Logger
45236 */
45237Logger.prototype.getFormatter = function () {
45238  return this.formatter
45239}
45240/**
45241 * @param {LoggerFormatter} formatter - the formatter
45242 * @memberof Logger
45243 */
45244Logger.prototype.setFormatter = function (formatter) {
45245  this.formatter = formatter
45246}
45247/**
45248 * @returns {number} - the logging severity threshold
45249 * @memberof Logger
45250 */
45251Logger.prototype.getLevel = function () {
45252  return this.level
45253}
45254/**
45255 * @param {number} level - the logging severity threshold
45256 * @memberof Logger
45257 */
45258Logger.prototype.setLevel = function (level) {
45259  this.level = level
45260}
45261/**
45262 * @returns {string} - the program name
45263 * @memberof Logger
45264 */
45265Logger.prototype.getProgramName = function () {
45266  return this.progname
45267}
45268/**
45269 * @param {string} programName - the program name
45270 * @memberof Logger
45271 */
45272Logger.prototype.setProgramName = function (programName) {
45273  this.progname = programName
45274}
45275
45276const RubyLogger = Opal.const_get_qualified('::', 'Logger')
45277
45278const log = function (logger, level, message) {
45279  logger['$' + level](message)
45280}
45281RubyLogger.prototype.add = function (severity, message, programName) {
45282  const severityValue = typeof severity === 'string' ? LoggerSeverity[severity.toUpperCase()] : severity
45283  this.$add(severityValue, message, programName)
45284}
45285RubyLogger.prototype.log = RubyLogger.prototype.add
45286RubyLogger.prototype.debug = function (message) {
45287  log(this, 'debug', message)
45288}
45289RubyLogger.prototype.info = function (message) {
45290  log(this, 'info', message)
45291}
45292RubyLogger.prototype.warn = function (message) {
45293  log(this, 'warn', message)
45294}
45295RubyLogger.prototype.error = function (message) {
45296  log(this, 'error', message)
45297}
45298RubyLogger.prototype.fatal = function (message) {
45299  log(this, 'fatal', message)
45300}
45301RubyLogger.prototype.isDebugEnabled = function () {
45302  return this['$debug?']()
45303}
45304RubyLogger.prototype.isInfoEnabled = function () {
45305  return this['$info?']()
45306}
45307RubyLogger.prototype.isWarnEnabled = function () {
45308  return this['$warn?']()
45309}
45310RubyLogger.prototype.isErrorEnabled = function () {
45311  return this['$error?']()
45312}
45313RubyLogger.prototype.isFatalEnabled = function () {
45314  return this['$fatal?']()
45315}
45316
45317/**
45318 * @namespace
45319 */
45320const NullLogger = Opal.const_get_qualified(Opal.Asciidoctor, 'NullLogger', true)
45321
45322// Alias
45323Opal.Asciidoctor.NullLogger = NullLogger
45324
45325/**
45326 * Create a new NullLogger.
45327 * @returns {NullLogger} - a NullLogger
45328 * @memberof NullLogger
45329 */
45330NullLogger.create = function () {
45331  return this.$new()
45332}
45333
45334/**
45335 * @returns {number|undefined} - the maximum severity
45336 * @memberof NullLogger
45337 */
45338NullLogger.prototype.getMaxSeverity = function () {
45339  return this.max_severity
45340}
45341
45342// Alias
45343Opal.Asciidoctor.StopIteration = Opal.StopIteration
45344
45345/**
45346 * @namespace
45347 */
45348const Timings = Opal.const_get_qualified(Opal.Asciidoctor, 'Timings', true)
45349
45350// Alias
45351Opal.Asciidoctor.Timings = Timings
45352
45353/**
45354 * Create a new Timings.
45355 * @returns {Timings} - a Timings
45356 * @memberof Timings
45357 */
45358Timings.create = function () {
45359  return this.$new()
45360}
45361
45362/**
45363 * Print a report to the specified output.
45364 * The report will include:
45365 * - the time to read and parse source
45366 * - the time to convert document
45367 * - the total time (read, parse and convert)
45368 * @param {RubyLogger|console|Object} [to] - an optional output (by default stdout)
45369 * @param {string} [subject] - an optional subject (usually the file name)
45370 * @memberof Timings
45371 */
45372Timings.prototype.printReport = function (to, subject) {
45373  let outputFunction
45374  if (to) {
45375    if (typeof to.$add === 'function') {
45376      outputFunction = function (message) {
45377        to.$add(1, message)
45378      }
45379    } else if (typeof to.log === 'function') {
45380      outputFunction = to.log
45381    } else if (typeof to.write === 'function') {
45382      outputFunction = function (message) {
45383        to.write(message, 'utf-8')
45384      }
45385    } else {
45386      throw new Error('The output should be a Stream (with a write function), an object with a log function or a Ruby Logger (with a add function)')
45387    }
45388  } else {
45389    outputFunction = function (message) {
45390      Opal.gvars.stdout.$write(message)
45391    }
45392  }
45393  if (subject) {
45394    outputFunction('Input file: ' + subject)
45395  }
45396  outputFunction(' Time to read and parse source: ' + this.$read_parse().toFixed(2))
45397  outputFunction(' Time to convert document: ' + this.$convert().toFixed(2))
45398  outputFunction(' Total time (read, parse and convert): ' + this.$read_parse_convert().toFixed(2))
45399}
45400
45401/**
45402 * @namespace
45403 * @description
45404 * This API is experimental and subject to change.
45405 *
45406 * A pluggable adapter for integrating a syntax (aka code) highlighter into AsciiDoc processing.
45407 *
45408 * There are two types of syntax highlighter adapters. The first performs syntax highlighting during the convert phase.
45409 * This adapter type must define a "handlesHighlighting" method that returns true.
45410 * The companion "highlight" method will then be called to handle the "specialcharacters" substitution for source blocks.
45411 *
45412 * The second assumes syntax highlighting is performed on the client (e.g., when the HTML document is loaded).
45413 * This adapter type must define a "hasDocinfo" method that returns true.
45414 * The companion "docinfo" method will then be called to insert markup into the output document.
45415 * The docinfo functionality is available to both adapter types.
45416 *
45417 * Asciidoctor.js provides several a built-in adapter for highlight.js.
45418 * Additional adapters can be registered using SyntaxHighlighter.register.
45419 */
45420const SyntaxHighlighter = Opal.const_get_qualified(Opal.Asciidoctor, 'SyntaxHighlighter', true)
45421
45422// Alias
45423Opal.Asciidoctor.SyntaxHighlighter = SyntaxHighlighter
45424
45425/**
45426 * Associates the syntax highlighter class or object with the specified names.
45427 *
45428 * @description This API is experimental and subject to change.
45429 *
45430 * @param {string|Array} names - A {string} name or an {Array} of {string} names
45431 * @param functions - A list of functions representing a {SyntaxHighlighter} or a {SyntaxHighlighter} class to instantiate
45432 * @memberof SyntaxHighlighter
45433 */
45434SyntaxHighlighter.register = function (names, functions) {
45435  const name = typeof names === 'string' ? names : names[0]
45436  if (typeof functions === 'function') {
45437    const classObject = functions
45438    const prototype = classObject.prototype
45439    const properties = Object.getOwnPropertyNames(prototype)
45440    functions = {}
45441    for (const propertyIdx in properties) {
45442      const propertyName = properties[propertyIdx]
45443      functions[propertyName] = prototype[propertyName]
45444    }
45445  }
45446  const scope = initializeClass(SyntaxHighlighterBase, name, functions, {}, {
45447    format: function (args) {
45448      if (args.length >= 2 && typeof args[2] === 'object' && '$$smap' in args[2]) {
45449        args[2] = fromHash(args[2])
45450      }
45451      if (args.length >= 1) {
45452        args[1] = args[1] === Opal.nil ? undefined : args[1]
45453      }
45454      return args
45455    },
45456    highlight: function (args) {
45457      if (args.length >= 3 && typeof args[3] === 'object' && '$$smap' in args[3]) {
45458        let opts = args[3]
45459        opts = fromHash(opts)
45460        for (const key in opts) {
45461          const value = opts[key]
45462          if (key === 'callouts') {
45463            const callouts = fromHashKeys(value)
45464            for (const idx in callouts) {
45465              const callout = callouts[idx]
45466              for (let i = 0; i < callout.length; i++) {
45467                const items = callout[i]
45468                for (let j = 0; j < items.length; j++) {
45469                  items[j] = items[j] === Opal.nil ? undefined : items[j]
45470                }
45471              }
45472            }
45473            opts[key] = callouts
45474          } else {
45475            opts[key] = value === Opal.nil ? undefined : value
45476          }
45477        }
45478        args[3] = opts
45479      }
45480      if (args.length >= 2) {
45481        args[2] = args[2] === Opal.nil ? undefined : args[2]
45482      }
45483      return args
45484    }
45485  })
45486  for (const functionName in functions) {
45487    if (Object.prototype.hasOwnProperty.call(functions, functionName)) {
45488      (function (functionName) {
45489        const userFunction = functions[functionName]
45490        if (functionName === 'handlesHighlighting') {
45491          Opal.def(scope, '$highlight?', function () {
45492            return userFunction.call()
45493          })
45494        } else if (functionName === 'hasDocinfo') {
45495          Opal.def(scope, '$docinfo?', function (location) {
45496            return userFunction.apply(this, [location])
45497          })
45498        }
45499      }(functionName))
45500    }
45501  }
45502  Opal.def(scope, '$name', function () {
45503    return name
45504  })
45505  SyntaxHighlighter.$register(scope, names)
45506  return scope
45507}
45508
45509/**
45510 * Retrieves the syntax highlighter class or object registered for the specified name.
45511 *
45512 * @description This API is experimental and subject to change.
45513 *
45514 * @param {string} name - The {string} name of the syntax highlighter to retrieve.
45515 * @returns {SyntaxHighlighter} - the {SyntaxHighlighter} registered for this name.
45516 * @memberof SyntaxHighlighter
45517 */
45518SyntaxHighlighter.get = function (name) {
45519  const result = SyntaxHighlighter.$for(name)
45520  return result === Opal.nil ? undefined : result
45521}
45522
45523/**
45524 * @deprecated Please use {SyntaxHighlighter#get} method as "for" is a reserved keyword.
45525 */
45526SyntaxHighlighter.for = SyntaxHighlighter.get
45527
45528/**
45529 * @namespace
45530 */
45531const SyntaxHighlighterBase = Opal.const_get_qualified(SyntaxHighlighter, 'Base', true)
45532
45533// Alias
45534Opal.Asciidoctor.SyntaxHighlighterBase = SyntaxHighlighterBase
45535
45536/**
45537 * Statically register the current class in the registry for the specified names.
45538 *
45539 * @description This API is experimental and subject to change.
45540 *
45541 * @param {string|Array<string>} names - A {string} name or an {Array} of {string} names
45542 * @memberof SyntaxHighlighterBase
45543 */
45544SyntaxHighlighterBase.prototype.registerFor = function (names) {
45545  SyntaxHighlighter.$register(this, names)
45546}
45547
45548// Table API
45549
45550/**
45551 * Methods for managing AsciiDoc tables.
45552 * @namespace
45553 * @extends AbstractBlock
45554 */
45555const Table = Opal.Asciidoctor.Table
45556
45557/**
45558 * Create a new Table element.
45559 * @param {AbstractBlock} parent
45560 * @param {Object|undefined} attributes
45561 * @returns {Table} - a new {Table} object
45562 */
45563Table.create = function (parent, attributes) {
45564  return this.$new(parent, toHash(attributes))
45565}
45566
45567/**
45568 * Get the caption of the table.
45569 * @returns {string}
45570 * @memberof Table
45571 */
45572Table.prototype.getCaption = function () {
45573  return this.caption
45574}
45575
45576/**
45577 * Get the rows of this table.
45578 * @returns {Table.Rows} - an {Table.Rows} object with the members "head", "body" and "foot"
45579 * @memberof Table
45580 */
45581Table.prototype.getRows = function () {
45582  return this.rows
45583}
45584
45585/**
45586 * Get the columns of this table.
45587 * @returns {Array<Column>}
45588 * @memberof Table
45589 */
45590Table.prototype.getColumns = function () {
45591  return this.columns
45592}
45592
45593
45594/**
45595 * Get the head rows of this table.
45596 * @returns {Array<Array<Cell>>} - an Array of Array of Cell
45597 * @memberof Table
45598 */
45599Table.prototype.getHeadRows = function () {
45600  return this.rows.head
45601}
45602
45603/**
45604 * Check if the table has a head rows.
45605 * @returns {boolean}
45606 * @memberof Table
45607 */
45608Table.prototype.hasHeadRows = function () {
45609  return this.rows !== Opal.nil && this.rows.head.length > 0
45610}
45611
45612/**
45613 * Get the body rows of this table.
45614 * @returns {Array<Array<Cell>>} - an Array of Array of Cell
45615 * @memberof Table
45616 */
45617Table.prototype.getBodyRows = function () {
45618  return this.rows.body
45619}
45620
45621/**
45622 * Check if the table has a body rows.
45623 * @returns {boolean}
45624 */
45625Table.prototype.hasBodyRows = function () {
45626  return this.rows !== Opal.nil && this.rows.body.length > 0
45627}
45628
45629/**
45630 * Get the foot rows of this table.
45631 * @returns {Array<Array<Cell>>} - an Array of Array of Cell
45632 * @memberof Table
45633 */
45634Table.prototype.getFootRows = function () {
45635  return this.rows.foot
45636}
45637
45638/**
45639 * Check if the table has a foot rows.
45640 * @returns {boolean}
45641 */
45642Table.prototype.hasFootRows = function () {
45643  return this.rows !== Opal.nil && this.rows.foot.length > 0
45644}
45645
45646/**
45647 * Check if the table has a header option set.
45648 * @returns {boolean}
45649 * @memberof Table
45650 */
45651Table.prototype.hasHeaderOption = function () {
45652  return this.has_header_option
45653}
45654
45655/**
45656 * Check if the table has the footer option set.
45657 * @returns {boolean}
45658 * @memberof Table
45659 */
45660Table.prototype.hasFooterOption = function () {
45661  return this.isOption('footer')
45662}
45663
45664/**
45665 * Check if the table has the autowidth option set.
45666 * @returns {boolean}
45667 * @memberof Table
45668 */
45669Table.prototype.hasAutowidthOption = function () {
45670  return this.isOption('autowidth')
45671}
45672
45673/**
45674 * Get the number of rows in the table.
45675 * Please note that the header and footer rows are also counted.
45676 * @returns {number|undefined}
45677 * @memberof Table
45678 */
45679Table.prototype.getRowCount = function () {
45680  return this.getAttribute('rowcount')
45681}
45682
45683/**
45684 * Set the number of rows in the table.
45685 * Please note that the header and footer rows are also counted.
45686 * @param {number} value - the value
45687 * @memberof Table
45688 */
45689Table.prototype.setRowCount = function (value) {
45690  this.setAttribute('rowcount', value)
45691}
45692
45693/**
45694 * Get the number of columns in the table.
45695 * @returns {number|undefined}
45696 * @memberof Table
45697 */
45698Table.prototype.getColumnCount = function () {
45699  return this.getAttribute('colcount')
45700}
45701
45702/**
45703 * Set the number of columns in the table.
45704 * @param {number} value - the value
45705 * @memberof Table
45706 */
45707Table.prototype.setColumnCount = function (value) {
45708  this.setAttribute('colcount', value)
45709}
45710
45711// Rows
45712
45713/**
45714 * @namespace
45715 */
45716const Rows = Opal.Asciidoctor.Table.Rows
45717
45718/**
45719 * Create a new Rows element.
45720 * @param {array<array<Cell>>} head
45721 * @param {array<array<Cell>>} foot
45722 * @param {array<array<Cell>>} body
45723 * @returns Rows
45724 */
45725Rows.create = function (head, foot, body) {
45726  return this.$new(head, foot, body)
45727}
45728
45729/**
45730 * Get head rows.
45731 * @returns {array<array<Cell>>}
45732 */
45733Rows.prototype.getHead = function () {
45734  return this.head
45735}
45736
45737/**
45738 * Get foot rows.
45739 * @returns {array<array<Cell>>}
45740 */
45741Rows.prototype.getFoot = function () {
45742  return this.foot
45743}
45744
45745/**
45746 * Get body rows.
45747 * @returns {array<array<Cell>>}
45748 */
45749Rows.prototype.getBody = function () {
45750  return this.body
45751}
45752
45753/**
45754 * Retrieve the rows grouped by section as a nested Array.
45755 *
45756 * Creates a 2-dimensional array of two element entries.
45757 * The first element is the section name as a string.
45758 * The second element is the Array of rows in that section.
45759 * The entries are in document order (head, foot, body).
45760 * @returns {[[string, array<array<Cell>>], [string, array<array<Cell>>], [string, array<array<Cell>>]]}
45761 */
45762Rows.prototype.bySection = function () {
45763  return [['head', this.head], ['body', this.body], ['foot', this.foot]]
45764}
45765
45766// Table Column
45767
45768/**
45769 * Methods to manage the columns of an AsciiDoc table.
45770 * In particular, it keeps track of the column specs.
45771 * @namespace
45772 * @extends AbstractNode
45773 */
45774const Column = Opal.Asciidoctor.Table.Column
45775
45776/**
45777 * Create a new Column element.
45778 * @param {Table} table
45779 * @param {number} index
45780 * @param {Object|undefined} attributes
45781 * @returns Column
45782 */
45783Column.create = function (table, index, attributes) {
45784  return this.$new(table, index, toHash(attributes))
45785}
45786
45787/**
45788 * Get the column number of this cell.
45789 * @returns {number|undefined}
45790 * @memberof Column
45791 */
45792Column.prototype.getColumnNumber = function () {
45793  return this.getAttribute('colnumber')
45794}
45795
45796/**
45797 * Get the width of this cell.
45798 * @returns {string|undefined}
45799 * @memberof Column
45800 */
45801Column.prototype.getWidth = function () {
45802  return this.getAttribute('width')
45803}
45803
45804
45805/**
45806 * Get the horizontal align of this cell.
45807 * @returns {string|undefined}
45808 * @memberof Column
45809 */
45810Column.prototype.getHorizontalAlign = function () {
45811  return this.getAttribute('halign')
45812}
45813
45814/**
45815 * Get the vertical align of this cell.
45816 * @returns {string|undefined}
45817 * @memberof Column
45818 */
45819Column.prototype.getVerticalAlign = function () {
45820  return this.getAttribute('valign')
45821}
45822
45823/**
45824 * Get the style of this cell.
45825 * @returns {string}
45826 * @memberof Column
45827 */
45828Column.prototype.getStyle = function () {
45829  const style = this.style
45830  return style === Opal.nil ? undefined : style
45831}
45832
45833// Table Cell
45834
45835/**
45836 * Methods for managing the cells in an AsciiDoc table.
45837 * @namespace
45838 * @extends AbstractBlock
45839 */
45840const Cell = Opal.Asciidoctor.Table.Cell
45841
45842/**
45843 * Create a new Cell element
45844 * @param {Column} column
45845 * @param {string} cellText
45846 * @param {Object|undefined} attributes
45847 * @param {Object|undefined} opts
45848 * @returns {Cell}
45849 */
45850Cell.create = function (column, cellText, attributes, opts) {
45851  return this.$new(column, cellText, toHash(attributes), toHash(opts))
45852}
45853
45854/**
45855 * Get the column span of this {@link Cell} node.
45856 * @returns {number} - An Integer of the number of columns this cell will span (default: undefined)
45857 * @memberof Cell
45858 */
45859Cell.prototype.getColumnSpan = function () {
45860  const colspan = this.colspan
45861  return colspan === Opal.nil ? undefined : colspan
45862}
45863
45864/**
45865 * Set the column span of this {@link Cell} node.
45866 * @param {number} value
45867 * @returns {number} - The new colspan value
45868 * @memberof Cell
45869 */
45870Cell.prototype.setColumnSpan = function (value) {
45871  return this['$colspan='](value)
45872}
45873
45874/**
45875 * Get the row span of this {@link Cell} node
45876 * @returns {number|undefined} - An Integer of the number of rows this cell will span (default: undefined)
45877 * @memberof Cell
45878 */
45879Cell.prototype.getRowSpan = function () {
45880  const rowspan = this.rowspan
45881  return rowspan === Opal.nil ? undefined : rowspan
45882}
45883
45884/**
45885 * Set the row span of this {@link Cell} node
45886 * @param {number} value
45887 * @returns {number}
45887 - The new rowspan value
45888 * @memberof Cell
45889 */
45890Cell.prototype.setRowSpan = function (value) {
45891  return this['$rowspan='](value)
45892}
45893
45894/**
45895 * Get the content of the cell.
45896 * This method should not be used for cells in the head row or that have the literal style.
45897 * @returns {string}
45898 * @memberof Cell
45899 */
45900Cell.prototype.getContent = function () {
45901  return this.$content()
45902}
45903
45904/**
45905 * Get the text of the cell.
45906 * @returns {string}
45907 * @memberof Cell
45908 */
45909Cell.prototype.getText = function () {
45910  return this.$text()
45911}
45912
45913/**
45914 * Get the source of the cell.
45915 * @returns {string}
45916 * @memberof Cell
45917 */
45918Cell.prototype.getSource = function () {
45919  return this.$source()
45920}
45921
45922/**
45923 * Get the lines of the cell.
45924 * @returns {Array<string>}
45925 * @memberof Cell
45926 */
45927Cell.prototype.getLines = function () {
45928  return this.$lines()
45929}
45930
45931/**
45932 * Get the line number of the cell.
45933 * @returns {number|undefined}
45934 * @memberof Cell
45935 */
45936Cell.prototype.getLineNumber = function () {
45937  const lineno = this.$lineno()
45938  return lineno === Opal.nil ? undefined : lineno
45939}
45940
45941/**
45942 * Get the source file of the cell.
45943 * @returns {string|undefined}
45944 * @memberof Cell
45945 */
45946Cell.prototype.getFile = function () {
45947  const file = this.$file()
45948  return file === Opal.nil ? undefined : file
45949}
45950
45951/**
45952 * Get the style of the cell.
45953 * @returns {string|undefined}
45954 * @memberof Cell
45955 */
45956Cell.prototype.getStyle = function () {
45957  const style = this.$style()
45958  return style === Opal.nil ? undefined : style
45959}
45960
45961/**
45962 * Get the column of this cell.
45963 * @returns {Column|undefined}
45964 * @memberof Cell
45965 */
45966Cell.prototype.getColumn = function () {
45967  const column = this.$column()
45968  return column === Opal.nil ? undefined : column
45969}
45970
45971/**
45972 * Get the width of this cell.
45973 * @returns {string|undefined}
45974 * @memberof Cell
45975 */
45976Cell.prototype.getWidth = function () {
45977  return this.getAttribute('width')
45978}
45979
45980/**
45981 * Get the column width in percentage of this cell.
45982 * @returns {string|undefined}
45983 * @memberof Cell
45984 */
45985Cell.prototype.getColumnPercentageWidth = function () {
45986  return this.getAttribute('colpcwidth')
45987}
45988
45989/**
45990 * Get the nested {Document} of this cell when style is 'asciidoc'.
45991 * @returns {Document|undefined} - the nested {Document}
45992 * @memberof Cell
45993 */
45994Cell.prototype.getInnerDocument = function () {
45995  const innerDocument = this.inner_document
45996  return innerDocument === Opal.nil ? undefined : innerDocument
45997}
45998
45999// Templates
46000
46001/**
46002 * @description
46003 * This API is experimental and subject to change.
46004 *
46005 * Please note that this API is currently only available in a Node environment.
46006 * We recommend to use a custom converter if you are running in the browser.
46007 *
46008 * @namespace
46009 * @module Converter/TemplateConverter
46010 */
46011const TemplateConverter = Opal.Asciidoctor.Converter.TemplateConverter
46012
46013if (TemplateConverter) {
46014  // Alias
46015  Opal.Asciidoctor.TemplateConverter = TemplateConverter
46016
46017  /**
46018   * Create a new TemplateConverter.
46019   * @param {string} backend - the backend name
46020   * @param templateDirectories - a list of template directories
46021   * @param {Object} opts - a JSON of options
46022   * @param {string} opts.template_engine - the name of the template engine
46023   * @param {Object} [opts.template_cache] - an optional template cache
46024   * @param {Object} [opts.template_cache.scans] - a JSON of template objects keyed by template name keyed by path patterns
46025   * @param {Object} [opts.template_cache.templates] - a JSON of template objects keyed by file paths
46026   * @returns {TemplateConverter}
46027   * @memberof Converter/TemplateConverter
46028   */
46029  TemplateConverter.create = function (backend, templateDirectories, opts) {
46030    if (opts && opts.template_cache) {
46031      opts.template_cache = toHash(opts.template_cache)
46032    }
46033    this.$new(backend, templateDirectories, toHash(opts))
46034  }
46035
46036  /**
46037   * @returns {Object} - The global cache
46038   * @memberof Converter/TemplateConverter
46039   */
46040  TemplateConverter.getCache = function () {
46041    const caches = fromHash(this.caches)
46042    if (caches) {
46043      if (caches.scans) {
46044        caches.scans = fromHash(caches.scans)
46045        for (const key in caches.scans) {
46046          caches.scans[key] = fromHash(caches.scans[key])
46047        }
46048      }
46049      if (caches.templates) {
46050        caches.templates = fromHash(caches.templates)
46051      }
46052    }
46053    return caches
46054  }
46055
46056  /**
46057   * Clear the global cache.
46058   * @memberof Converter/TemplateConverter
46059   */
46060  TemplateConverter.clearCache = function () {
46061    this.$clear_caches()
46062  }
46063
46064  /**
46065   * Convert an {AbstractNode} to the backend format using the named template.
46066   *
46067   * Looks for a template that matches the value of the template name or,
46068   * if the template name is not specified, the value of the {@see AbstractNode.getNodeName} function.
46069   *
46070   * @param {AbstractNode} node - the AbstractNode to convert
46071   * @param {string} templateName - the {string} name of the template to use, or the node name of the node if a template name is not specified. (optional, default: undefined)
46072   * @param {Object} opts - an optional JSON that is passed as local variables to the template. (optional, default: undefined)
46073   * @returns {string} - The {string} result from rendering the template
46074   * @memberof Converter/TemplateConverter
46075   */
46076  TemplateConverter.prototype.convert = function (node, templateName, opts) {
46077    return this.$convert(node, templateName, toHash(opts))
46078  }
46079
46080  /**
46081   * Checks whether there is a template registered with the specified name.
46082   *
46083   * @param {string} name - the {string} template name
46084   * @returns {boolean} - a {boolean} that indicates whether a template is registered for the specified template name.
46085   * @memberof Converter/TemplateConverter
46086   */
46087  TemplateConverter.prototype.handles = function (name) {
46088    return this['$handles?'](name)
46089  }
46090
46091  /**
46092   * Converts the {AbstractNode} using only its converted content.
46093   *
46094   * @param {AbstractNode} node
46095   * @returns {string} - the converted {string} content.
46096   * @memberof Converter/TemplateConverter
46097   */
46098  TemplateConverter.prototype.getContentOnly = function (node) {
46099    return this.$content_only(node)
46100  }
46101
46102  /**
46103   * Skips conversion of the {AbstractNode}.
46104   *
46105   * @param {AbstractNode} node
46106   * @memberof Converter/TemplateConverter
46107   */
46108  TemplateConverter.prototype.skip = function (node) {
46109    this.$skip(node)
46110  }
46111
46112  /**
46113   * Retrieves the templates that this converter manages.
46114   *
46115   * @returns {Object} - a JSON of template objects keyed by template name
46116   * @memberof Converter/TemplateConverter
46117   */
46118  TemplateConverter.prototype.getTemplates = function () {
46119    return fromHash(this.$templates())
46120  }
46121
46122  /**
46123   * Registers a template with this converter.
46124   *
46125   * @param {string} name - the {string} template name
46126   * @param {Object} template - the template object to register
46127   * @returns {Object} - the template object
46128   * @memberof Converter/TemplateConverter
46129   */
46130  TemplateConverter.prototype.register = function (name, template) {
46131    return this.$register(name, template)
46132  }
46133
46134  /**
46135   * @namespace
46136   * @description
46137   * This API is experimental and subject to change.
46138   *
46139   * Please note that this API is currently only available in a Node environment.
46140   * We recommend to use a custom converter if you are running in the browser.
46141   *
46142   * A pluggable adapter for integrating a template engine into the built-in template converter.
46143   */
46144  const TemplateEngine = {}
46145  TemplateEngine.registry = {}
46146
46147  // Alias
46148  Opal.Asciidoctor.TemplateEngine = TemplateEngine
46149
46150  /**
46151   * Register a template engine adapter for the given names.
46152   * @param {string|Array} names - a {string} name or an {Array} of {string} names
46153   * @param {Object} templateEngineAdapter - a template engine adapter instance
46154   * @example
46155   *  const fs = require('fs')
46156   *  class DotTemplateEngineAdapter {
46157   *    constructor () {
46158   *      this.doT = require('dot')
46159   *    }
46160   *    compile (file, _) {
46161   *      const templateFn = this.doT.template(fs.readFileSync(file, 'utf8'))
46162   *      return {
46163   *        render: templateFn
46164   *      }
46165   *    }
46166   *  }
46167   *  asciidoctor.TemplateEngine.register('dot, new DotTemplateEngineAdapter())
46168   * @memberof TemplateEngine
46169   */
46170  TemplateEngine.register = function (names, templateEngineAdapter) {
46171    if (typeof names === 'string') {
46172      this.registry[names] = templateEngineAdapter
46173    } else {
46174      // array
46175      for (let i = 0; i < names.length; i++) {
46176        const name = names[i]
46177        this.registry[name] = templateEngineAdapter
46178      }
46179    }
46180  }
46181}
46182
46183/**
46184 * @namespace
46185 * @module Converter/CompositeConverter
46186 */
46187const CompositeConverter = Opal.Asciidoctor.Converter.CompositeConverter
46188
46189if (CompositeConverter) {
46190  // Alias
46191  Opal.Asciidoctor.CompositeConverter = CompositeConverter
46192
46193  /**
46194   * Delegates to the first converter that identifies itself as the handler for the given transform.
46195   * The optional Hash is passed as the last option to the delegate's convert method.
46196   *
46197   * @param node - the AbstractNode to convert
46198   * @param [transform] - the optional {string} transform, or the name of the node if no transform is specified. (optional, default: undefined)
46199   * @param [opts] - an optional JSON that is passed as local variables to the template. (optional, default: undefined)
46200   * @returns The {string} result from the delegate's convert method
46201   * @memberof Converter/CompositeConverter
46202   */
46203  CompositeConverter.prototype.convert = function (node, transform, opts) {
46204    return this.$convert(node, transform, toHash(opts))
46205  }
46206
46207  /**
46208   * Converts the {AbstractNode} using only its converted content.
46209   *
46210   * @param {AbstractNode} node
46211   * @returns {string} - the converted {string} content.
46212   * @memberof Converter/CompositeConverter
46213   */
46214  CompositeConverter.prototype.getContentOnly = function (node) {
46215    return this.$content_only(node)
46216  }
46217
46218  /**
46219   * Skips conversion of the {AbstractNode}.
46220   *
46221   * @param {AbstractNode} node
46222   * @memberof Converter/CompositeConverter
46223   */
46224  CompositeConverter.prototype.skip = function (node) {
46225    this.$skip(node)
46226  }
46227
46228  /**
46229   * Get the Array of Converter objects in the chain.
46230   * @returns {[Converter]}
46231   * @memberof Converter/CompositeConverter
46232   */
46233  CompositeConverter.prototype.getConverters = function () {
46234    return this.converters
46235  }
46236
46237  /**
46238   * Retrieve the converter for the specified transform.
46239   * @param transform
46240   * @returns {Converter|undefined}
46241   * @memberof Converter/CompositeConverter
46242   */
46243  CompositeConverter.prototype.getConverter = function (transform) {
46244    const converter = this.$converter_for(transform)
46245    return converter === Opal.nil ? undefined : converter
46246  }
46247
46248  /**
46249   * Find the converter for the specified transform.
46250   * Throw an exception if no converter is found.
46251   *
46252   * @param transform
46253   * @returns {Converter} - the matching converter
46254   * @throws Error if no converter is found
46255   * @memberof Converter/CompositeConverter
46256   */
46257  CompositeConverter.prototype.findConverter = function (transform) {
46258    return this.$find_converter(transform)
46259  }
46260}
46261
46262// Converter API
46263
46264/**
46265 * @namespace
46266 * @module Converter
46267 */
46268const Converter = Opal.const_get_qualified(Opal.Asciidoctor, 'Converter')
46269
46270// Alias
46271Opal.Asciidoctor.Converter = Converter
46272
46273/**
46274 * Convert the specified node.
46275 *
46276 * @param {AbstractNode} node - the AbstractNode to convert
46277 * @param {string} transform - an optional String transform that hints at
46278 * which transformation should be applied to this node.
46279 * @param {Object} opts - a JSON of options that provide additional hints about how to convert the node (default: {})
46280 * @returns the {Object} result of the conversion, typically a {string}.
46281 * @memberof Converter
46282 */
46283Converter.prototype.convert = function (node, transform, opts) {
46284  return this.$convert(node, transform, toHash(opts))
46285}
46286
46287/**
46288 * Create an instance of the converter bound to the specified backend.
46289 *
46290 * @param {string} backend - look for a converter bound to this keyword.
46291 * @param {Object} opts - a JSON of options to pass to the converter (default: {})
46292 * @returns {Converter} - a converter instance for converting nodes in an Asciidoctor AST.
46293 * @memberof Converter
46294 */
46295Converter.create = function (backend, opts) {
46296  return this.$create(backend, toHash(opts))
46297}
46298
46299// Converter Factory API
46300
46301/**
46302 * @namespace
46303 * @module Converter/Factory
46304 */
46305const ConverterFactory = Opal.Asciidoctor.Converter.Factory
46306
46307const ConverterBase = Opal.Asciidoctor.Converter.Base
46308
46309// Alias
46310Opal.Asciidoctor.ConverterFactory = ConverterFactory
46311
46312const ConverterBackendTraits = Opal.Asciidoctor.Converter.BackendTraits
46313
46314// Alias
46315Opal.Asciidoctor.ConverterBackendTraits = ConverterBackendTraits
46316
46317/**
46318 * Register a custom converter in the global converter factory to handle conversion to the specified backends.
46319 * If the backend value is an asterisk, the converter is used to handle any backend that does not have an explicit converter.
46320 *
46321 * @param converter - The Converter instance to register
46322 * @param backends {Array} - A {string} {Array} of backend names that this converter should be registered to handle (optional, default: ['*'])
46323 * @return {*} - Returns nothing
46324 * @memberof Converter/Factory
46325 */
46326ConverterFactory.register = function (converter, backends) {
46327  const args = [bridgeConverter(converter)].concat(backends)
46328  return Converter.$register.apply(Converter, args)
46329}
46330
46331/**
46332 * Retrieves the singleton instance of the converter factory.
46333 *
46334 * @param {boolean} initialize - instantiate the singleton if it has not yet
46335 * been instantiated. If this value is false and the singleton has not yet been
46336 * instantiated, this method returns a fresh instance.
46337 * @returns {Converter/Factory} an instance of the converter factory.
46338 * @memberof Converter/Factory
46339 */
46340ConverterFactory.getDefault = function (initialize) {
46341  return this.$default(initialize)
46342}
46343
46344/**
46345 * Create an instance of the converter bound to the specified backend.
46346 *
46347 * @param {string} backend - look for a converter bound to this keyword.
46348 * @param {Object} opts - a JSON of options to pass to the converter (default: {})
46349 * @returns {Converter} - a converter instance for converting nodes in an Asciidoctor AST.
46350 * @memberof Converter/Factory
46351 */
46352ConverterFactory.prototype.create = function (backend, opts) {
46353  return this.$create(backend, toHash(opts))
46354}
46355
46356/**
46357 * Get the converter registry.
46358 * @returns the registry of converter instances or classes keyed by backend name
46359 * @memberof Converter/Factory
46360 */
46361ConverterFactory.getRegistry = function () {
46362  return fromHash(Converter.$registry())
46363}
46364
46365/**
46366 * Lookup the custom converter registered with this factory to handle the specified backend.
46367 *
46368 * @param {string} backend - The {string} backend name.
46369 * @returns the {Converter} class or instance registered to convert the specified backend or undefined if no match is found.
46370 * @memberof Converter/Factory
46371 */
46372ConverterFactory.for = function (backend) {
46373  const converter = Converter.$for(backend)
46374  return converter === Opal.nil ? undefined : converter
46375}
46376
46377/*
46378 * Unregister any custom converter classes that are registered with this factory.
46379 * Intended for testing only!
46380 */
46381ConverterFactory.unregisterAll = function () {
46382  const internalRegistry = Converter.DefaultFactory.$$cvars['@@registry']
46383  Converter.DefaultFactory.$$cvars['@@registry'] = toHash({ html5: internalRegistry['$[]']('html5') })
46384}
46385
46386// Built-in converter
46387
46388/**
46389 * @namespace
46390 * @module Converter/Html5Converter
46391 */
46392const Html5Converter = Opal.Asciidoctor.Converter.Html5Converter
46393
46394// Alias
46395Opal.Asciidoctor.Html5Converter = Html5Converter
46396
46397/**
46398 * Create a new Html5Converter.
46399 * @returns {Html5Converter} - a Html5Converter
46400 * @memberof Converter/Html5Converter
46401 */
46402Html5Converter.create = function () {
46403  return this.$new()
46404}
46405
46406/**
46407 * Converts an {AbstractNode} using the given transform.
46408 * This method must be implemented by a concrete converter class.
46409 *
46410 * @param {AbstractNode} node - The concrete instance of AbstractNode to convert.
46411 * @param {string}
46411 [transform] - An optional String transform that hints at which transformation should be applied to this node.
46412 * If a transform is not given, the transform is often derived from the value of the {AbstractNode#getNodeName} property. (optional, default: undefined)
46413 * @param {Object} [opts]- An optional JSON of options hints about how to convert the node. (optional, default: undefined)
46414 *
46415 * @returns {string} - the String result.
46416 * @memberof Converter/Html5Converter
46417 */
46418Html5Converter.prototype.convert = function (node, transform, opts) {
46419  return this.$convert(node, transform, opts)
46420}
46421
46422/* global Opal, fromHash, toHash, initializeClass */
46423// Extensions API
46424
46425/**
46426 * @private
46427 */
46428const toBlock = function (block) {
46429  // arity is a mandatory field
46430  block.$$arity = block.length
46431  return block
46432}
46433
46434const registerExtension = function (registry, type, processor, name) {
46435  if (typeof processor === 'object' || processor.$$is_class) {
46436    // processor is an instance or a class
46437    return registry['$' + type](processor, name)
46438  } else {
46439    // processor is a function/lambda
46440    return Opal.send(registry, type, name && [name], toBlock(processor))
46441  }
46442}
46443
46444/**
46445 * @namespace
46446 * @description
46447 * Extensions provide a way to participate in the parsing and converting
46448 * phases of the AsciiDoc processor or extend the AsciiDoc syntax.
46449 *
46450 * The various extensions participate in AsciiDoc processing as follows:
46451 *
46452 * 1. After the source lines are normalized, {{@link Extensions/Preprocessor}}s modify or replace
46453 *    the source lines before parsing begins. {{@link Extensions/IncludeProcessor}}s are used to
46454 *    process include directives for targets which they claim to handle.
46455 * 2. The Parser parses the block-level content into an abstract syntax tree.
46456 *    Custom blocks and block macros are processed by associated {{@link Extensions/
46456BlockProcessor}}s
46457 *    and {{@link Extensions/BlockMacroProcessor}}s, respectively.
46458 * 3. {{@link Extensions/TreeProcessor}}s are run on the abstract syntax tree.
46459 * 4. Conversion of the document begins, at which point inline markup is processed
46460 *    and converted. Custom inline macros are processed by associated {InlineMacroProcessor}s.
46461 * 5. {{@link Extensions/Postprocessor}}s modify or replace the converted document.
46462 * 6. The output is written to the output stream.
46463 *
46464 * Extensions may be registered globally using the {Extensions.register} method
46465 * or added to a custom {Registry} instance and passed as an option to a single
46466 * Asciidoctor processor.
46467 *
46468 * @example
46469 * asciidoctor.Extensions.register(function () {
46470 *   this.block(function () {
46471 *     const self = this
46472 *     self.named('shout')
46473 *     self.onContext('paragraph')
46474 *     self.process(function (parent, reader) {
46475 *       const lines = reader.getLines().map(function (l) { return l.toUpperCase(); })
46476 *       return self.createBlock(parent, 'paragraph', lines)
46477 *     })
46478 *   })
46479 * })
46480 */
46481const Extensions = Opal.const_get_qualified(Opal.Asciidoctor, 'Extensions')
46482
46483// Alias
46484Opal.Asciidoctor.Extensions = Extensions
46485
46486/**
46487 * Create a new {@link Extensions/Registry}.
46488 * @param {string} name
46489 * @param {function} block
46490 * @memberof Extensions
46491 * @returns {Extensions/Registry} - returns a {@link Extensions/Registry}
46492 */
46493Extensions.create = function (name, block) {
46494  if (typeof name === 'function' && typeof block === 'undefined') {
46495    return Opal.send(this, 'create', null, toBlock(name))
46496  } else if (typeof block === 'function') {
46497    return Opal.send(this, 'create', [name], toBlock(block))
46498  } else {
46499    return this.$create()
46500  }
46501}
46502
46503/**
46504 * @memberof Extensions
46505 */
46506Extensions.register = function (name, block) {
46507  if (typeof name === 'function' && typeof block === 'undefined') {
46508    return Opal.send(this, 'register', null, toBlock(name))
46509  } else {
46510    return Opal.send(this, 'register', [name], toBlock(block))
46511  }
46512}
46513
46514/**
46515 * Get statically-registered extension groups.
46516 * @memberof Extensions
46517 */
46518Extensions.getGroups = function () {
46519  return fromHash(this.$groups())
46520}
46521
46522/**
46523 * Unregister all statically-registered extension groups.
46524 * @memberof Extensions
46525 */
46526Extensions.unregisterAll = function () {
46527  this.$unregister_all()
46528}
46529
46530/**
46531 * Unregister the specified statically-registered extension groups.
46532 *
46533 * NOTE Opal cannot delete an entry from a Hash that is indexed by symbol, so
46534 * we have to resort to using low-level operations in this method.
46535 *
46536 * @memberof Extensions
46537 */
46538Extensions.unregister = function () {
46539  const names = Array.prototype.concat.apply([], arguments)
46540  const groups = this.$groups()
46541  const groupNameIdx = {}
46542  let i = 0
46543  const groupSymbolNames = groups.$$keys
46544  for (; i < groupSymbolNames.length; i++) {
46545    const groupSymbolName = groupSymbolNames[i]
46546    groupNameIdx[groupSymbolName.toString()] = groupSymbolName
46547  }
46548  for (let j = 0; j < names.length; j++) {
46549    const groupStringName = names[j]
46550    if (groupStringName in groupNameIdx) Opal.hash_delete(groups, groupNameIdx[groupStringName])
46551  }
46552}
46553
46554/**
46555 * @namespace
46556 * @module Extensions/Registry
46557 */
46558const Registry = Extensions.Registry
46559
46560/**
46561 * @memberof Extensions/Registry
46562 */
46563Registry.prototype.getGroups = Extensions.getGroups
46564
46565/**
46566 * @memberof Extensions/Registry
46567 */
46568Registry.prototype.unregisterAll = function () {
46569  this.groups = Opal.hash()
46570}
46571
46572/**
46573 * @memberof Extensions/Registry
46574 */
46575Registry.prototype.unregister = Extensions.unregister
46576
46577/**
46578 * @memberof Extensions/Registry
46579 */
46580Registry.prototype.prefer = function (name, processor) {
46581  if (arguments.length === 1) {
46582    processor = name
46583    name = null
46584  }
46585  if (typeof processor === 'object' || processor.$$is_class) {
46586    // processor is an instance or a class
46587    return this.$prefer(name, processor)
46588  } else {
46589    // processor is a function/lambda
46590    return Opal.send(this, 'prefer', name && [name], toBlock(processor))
46591  }
46592}
46593
46594/**
46595 * @memberof Extensions/Registry
46596 */
46597Registry.prototype.block = function (name, processor) {
46598  if (arguments.length === 1) {
46599    processor = name
46600    name = null
46601  }
46602  return registerExtension(this, 'block', processor, name)
46603}
46604
46605/**
46606 * @memberof Extensions/Registry
46607 */
46608Registry.prototype.inlineMacro = function (name, processor) {
46609  if (arguments.length === 1) {
46610    processor = name
46611    name = null
46612  }
46613  return registerExtension(this, 'inline_macro', processor, name)
46614}
46615
46616/**
46617 * @memberof Extensions/Registry
46618 */
46619Registry.prototype.includeProcessor = function (name, processor) {
46620  if (arguments.length === 1) {
46621    processor = name
46622    name = null
46623  }
46624  return registerExtension(this, 'include_processor', processor, name)
46625}
46626
46627/**
46628 * @memberof Extensions/Registry
46629 */
46630Registry.prototype.blockMacro = function (name, processor) {
46631  if (arguments.length === 1) {
46632    processor = name
46633    name = null
46634  }
46635  return registerExtension(this, 'block_macro', processor, name)
46636}
46637
46638/**
46639 * @memberof Extensions/Registry
46640 */
46641Registry.prototype.treeProcessor = function (name, processor) {
46642  if (arguments.length === 1) {
46643    processor = name
46644    name = null
46645  }
46646  return registerExtension(this, 'tree_processor', processor, name)
46647}
46648
46649/**
46650 * @memberof Extensions/Registry
46651 */
46652Registry.prototype.postprocessor = function (name, processor) {
46653  if (arguments.length === 1) {
46654    processor = name
46655    name = null
46656  }
46657  return registerExtension(this, 'postprocessor', processor, name)
46658}
46659
46660/**
46661 * @memberof Extensions/Registry
46662 */
46663Registry.prototype.preprocessor = function (name, processor) {
46664  if (arguments.length === 1) {
46665    processor = name
46666    name = null
46667  }
46668  return registerExtension(this, 'preprocessor', processor, name)
46669}
46670
46671/**
46672 * @memberof Extensions/Registry
46673 */
46674Registry.prototype.docinfoProcessor = function (name, processor) {
46675  if (arguments.length === 1) {
46676    processor = name
46677    name = null
46678  }
46679  return registerExtension(this, 'docinfo_processor', processor, name)
46680}
46681
46682/**
46683 * Checks whether any {{@link Extensions/Preprocessor}} extensions have been registered.
46684 *
46685 * @memberof Extensions/Registry
46686 * @returns a {boolean} indicating whether any {{@link Extensions/Preprocessor}} extensions are registered.
46687 */
46688Registry.prototype.hasPreprocessors = function () {
46689  return this['$preprocessors?']()
46690}
46691
46692/**
46693 * Checks whether any {{@link Extensions/TreeProcessor}} extensions have been registered.
46694 *
46695 * @memberof Extensions/Registry
46696 * @returns a {boolean} indicating whether any {{@link Extensions/TreeProcessor}} extensions are registered.
46697 */
46698Registry.prototype.hasTreeProcessors = function () {
46699  return this['$tree_processors?']()
46700}
46701
46702/**
46703 * Checks whether any {{@link Extensions/IncludeProcessor}} extensions have been registered.
46704 *
46705 * @memberof Extensions/Registry
46706 * @returns a {boolean} indicating whether any {{@link Extensions/IncludeProcessor}} extensions are registered.
46707 */
46708Registry.prototype.hasIncludeProcessors = function () {
46709  return this['$include_processors?']()
46710}
46711
46712/**
46713 * Checks whether any {{@link Extensions/Postprocessor}} extensions have been registered.
46714 *
46715 * @memberof Extensions/Registry
46716 * @returns a {boolean} indicating whether any {{@link Extensions/Postprocessor}} extensions are registered.
46717 */
46718Registry.prototype.hasPostprocessors = function () {
46719  return this['$postprocessors?']()
46720}
46721
46722/**
46723 * Checks whether any {{@link Extensions/DocinfoProcessor}} extensions have been registered.
46724 *
46725 * @memberof Extensions/Registry
46726 * @param location - A {string} for selecting docinfo extensions at a given location (head or footer) (default: undefined)
46727 * @returns a {boolean} indicating whether any {{@link Extensions/DocinfoProcessor}} extensions are registered.
46728 */
46729Registry.prototype.hasDocinfoProcessors = function (location) {
46730  return this['$docinfo_processors?'](location)
46731}
46732
46733/**
46734 * Checks whether any {{@link Extensions/BlockProcessor}} extensions have been registered.
46735 *
46736 * @memberof Extensions/Registry
46737 * @returns a {boolean} indicating whether any {{@link Extensions/BlockProcessor}} extensions are registered.
46738 */
46739Registry.prototype.hasBlocks = function () {
46740  return this['$blocks?']()
46741}
46742
46743/**
46744 * Checks whether any {{@link Extensions/BlockMacroProcessor}} extensions have been registered.
46745 *
46746 * @memberof Extensions/Registry
46747 * @returns a {boolean} indicating whether any {{@link Extensions/BlockMacroProcessor}} extensions are registered.
46748 */
46749Registry.prototype.hasBlockMacros = function () {
46750  return this['$block_macros?']()
46751}
46752
46753/**
46754 * Checks whether any {{@link Extensions/InlineMacroProcessor}} extensions have been registered.
46755 *
46756 * @memberof Extensions/Registry
46757 * @returns a {boolean} indicating whether any {{@link Extensions/InlineMacroProcessor}} extensions are registered.
46758 */
46759Registry.prototype.hasInlineMacros = function () {
46760  return this['$inline_macros?']()
46761}
46762
46763/**
46764 * Retrieves the Extension proxy objects for all the {{@link Extensions/Preprocessor}} instances stored in this registry.
46765 *
46766 * @memberof Extensions/Registry
46767 * @returns an {array} of Extension proxy objects.
46768 */
46769Registry.prototype.getPreprocessors = function () {
46770  return this.$preprocessors()
46771}
46772
46773/**
46774 * Retrieves the Extension proxy objects for all the {{@link Extensions/TreeProcessor}} instances stored in this registry.
46775 *
46776 * @memberof Extensions/Registry
46777 * @returns an {array} of Extension proxy objects.
46778 */
46779Registry.prototype.getTreeProcessors = function () {
46780  return this.$tree_processors()
46781}
46782
46783/**
46784 * Retrieves the Extension proxy objects for all the {{@link Extensions/IncludeProcessor}} instances stored in this registry.
46785 *
46786 * @memberof Extensions/Registry
46787 * @returns an {array} of Extension proxy objects.
46788 */
46789Registry.prototype.getIncludeProcessors = function () {
46790  return this.$include_processors()
46791}
46792
46793/**
46794 * Retrieves the Extension proxy objects for all the {{@link Extensions/Postprocessor}} instances stored in this registry.
46795 *
46796 * @memberof Extensions/Registry
46797 * @returns an {array} of Extension proxy objects.
46798 */
46799Registry.prototype.getPostprocessors = function () {
46800  return this.$postprocessors()
46801}
46802
46803/**
46804 * Retrieves the Extension proxy objects for all the {{@link Extensions/DocinfoProcessor}} instances stored in this registry.
46805 *
46806 * @memberof Extensions/Registry
46807 * @param location - A {string} for selecting docinfo extensions at a given location (head or footer) (default: undefined)
46808 * @returns an {array} of Extension proxy objects.
46809 */
46810Registry.prototype.getDocinfoProcessors = function (location) {
46811  return this.$docinfo_processors(location)
46812}
46813
46814/**
46815 * Retrieves the Extension proxy objects for all the {{@link Extensions/
46815BlockProcessor}} instances stored in this registry.
46816 *
46817 * @memberof Extensions/Registry
46818 * @returns an {array} of Extension proxy objects.
46819 */
46820Registry.prototype.getBlocks = function () {
46821  return this.block_extensions.$values()
46822}
46823
46824/**
46825 * Retrieves the Extension proxy objects for all the {{@link Extensions/BlockMacroProcessor}} instances stored in this registry.
46826 *
46827 * @memberof Extensions/Registry
46828 * @returns an {array} of Extension proxy objects.
46829 */
46830Registry.prototype.getBlockMacros = function () {
46831  return this.block_macro_extensions.$values()
46832}
46833
46834/**
46835 * Retrieves the Extension proxy objects for all the {{@link Extensions/InlineMacroProcessor}} instances stored in this registry.
46836 *
46837 * @memberof Extensions/Registry
46838 * @returns an {array} of Extension proxy objects.
46839 */
46840Registry.prototype.getInlineMacros = function () {
46841  return this.$inline_macros()
46842}
46843
46844/**
46845 * Get any {{@link Extensions/InlineMacroProcessor}} extensions are registered to handle the specified inline macro name.
46846 *
46847 * @param name - the {string} inline macro name
46848 * @memberof Extensions/Registry
46849 * @returns the Extension proxy object for the {{@link Extensions/InlineMacroProcessor}} that matches the inline macro name or undefined if no match is found.
46850 */
46851Registry.prototype.getInlineMacroFor = function (name) {
46852  const result = this['$registered_for_inline_macro?'](name)
46853  return result === false ? undefined : result
46854}
46855
46856/**
46857 * Get any {{@link Extensions/BlockProcessor}} extensions are registered to handle the specified block name appearing on the specified context.
46858 * @param name - the {string} block name
46859 * @param context - the context of the block: paragraph, open... (optional)
46860 * @memberof Extensions/Registry
46861 * @returns the Extension proxy object for the {{@link Extensions/BlockProcessor}} that matches the block name and context or undefined if no match is found.
46862 */
46863Registry.prototype.getBlockFor = function (name, context) {
46864  if (typeof context === 'undefined') {
46865    const ext = this.$find_block_extension(name)
46866    return ext === Opal.nil ? undefined : ext
46867  }
46868  const result = this['$registered_for_block?'](name, context)
46869  return result === false ? undefined : result
46870}
46871
46872/**
46873 * Get any {{@link Extensions/BlockMacroProcessor}} extensions are registered to handle the specified macro name.
46874 *
46875 * @param name - the {string} macro name
46876 * @memberof Extensions/Registry
46877 * @returns the Extension proxy object for the {{@link Extensions/BlockMacroProcessor}} that matches the macro name or undefined if no match is found.
46878 */
46879Registry.prototype.getBlockMacroFor = function (name) {
46880  const result = this['$registered_for_block_macro?'](name)
46881  return result === false ? undefined : result
46882}
46883
46884/**
46885 * @namespace
46886 * @module Extensions/Processor
46887 */
46888const Processor = Extensions.Processor
46889
46890/**
46891 * The extension will be added to the beginning of the list for that extension type. (default is append).
46892 * @memberof Extensions/Processor
46893 * @deprecated Please use the <code>prefer</pre> function on the {@link Extensions/Registry},
46894 * the {@link Extensions/IncludeProcessor},
46895 * the {@link Extensions/TreeProcessor},
46896 * the {@link Extensions/Postprocessor},
46897 * the {@link Extensions/Preprocessor}
46898 * or the {@link Extensions/DocinfoProcessor}
46899 */
46900Processor.prototype.prepend = function () {
46901  this.$option('position', '>>')
46902}
46903
46904/**
46905 * @memberof Extensions/Processor
46906 */
46907Processor.prototype.process = function (block) {
46908  const handler = {
46909    apply: function (target, thisArg, argumentsList) {
46910      for (let i = 0; i < argumentsList.length; i++) {
46911        // convert all (Opal) Hash arguments to JSON.
46912        if (typeof argumentsList[i] === 'object' && '$$smap' in argumentsList[i]) {
46913          argumentsList[i] = fromHash(argumentsList[i])
46914        }
46915      }
46916      return target.apply(thisArg, argumentsList)
46917    }
46918  }
46919  const blockProxy = new Proxy(block, handler)
46920  return Opal.send(this, 'process', null, toBlock(blockProxy))
46921}
46922
46923/**
46924 * @param {string} name
46925 * @memberof Extensions/Processor
46926 */
46927Processor.prototype.named = function (name) {
46928  return this.$named(name)
46929}
46930
46931/**
46932 * Creates a block and links it to the specified parent.
46933 *
46934 * @param {Block|Section|Document} parent - The parent Block (Block, Section, or Document) of this new block.
46935 * @param {string} context
46936 * @param {string|Array<string>} source
46937 * @param {Object|undefined} attrs - A JSON of attributes
46938 * @param {Object|undefined} opts - A JSON of options
46939 * @return {Block}
46940 * @memberof Extensions/Processor
46941 */
46942Processor.prototype.createBlock = function (parent, context, source, attrs, opts) {
46943  return this.$create_block(parent, context, source, toHash(attrs), toHash(opts))
46944}
46945
46946/**
46947 * Creates a list block node and links it to the specified parent.
46948 *
46949 * @param parent - The parent Block (Block, Section, or Document) of this new list block.
46950 * @param {string} context - The list context (e.g., ulist, olist, colist, dlist)
46951 * @param {Object} attrs - An object of attributes to set on this list block
46952 * @returns {List}
46953 * @memberof Extensions/Processor
46954 */
46955Processor.prototype.createList = function (parent, context, attrs) {
46956  return this.$create_list(parent, context, toHash(attrs))
46957}
46958
46959/**
46960 * Creates a list item node and links it to the specified parent.
46961 *
46962 * @param {List} parent - The parent {List} of this new list item block.
46963 * @param {string} text - The text of the list item.
46964 * @returns {ListItem}
46965 * @memberof Extensions/Processor
46966 */
46967Processor.prototype.createListItem = function (parent, text) {
46968  return this.$create_list_item(parent, text)
46969}
46970
46971/**
46972 * Creates an image block node and links it to the specified parent.
46973 * @param {Block|Section|Document} parent - The parent Block of this new image block.
46974 * @param {Object}
46974 attrs - A JSON of attributes
46975 * @param {string} attrs.target - the target attribute to set the source of the image.
46976 * @param {string} attrs.alt - the alt attribute to specify an alternative text for the image.
46977 * @param {Object} opts - A JSON of options
46978 * @returns {Block}
46979 * @memberof Extensions/Processor
46980 */
46981Processor.prototype.createImageBlock = function (parent, attrs, opts) {
46982  return this.$create_image_block(parent, toHash(attrs), toHash(opts))
46983}
46984
46985/**
46986 * Creates a paragraph block and links it to the specified parent.
46987 *
46988 * @param {Block|Section|Document} parent - The parent Block (Block, Section, or Document) of this new block.
46989 * @param {string|Array<string>} source - The source
46990 * @param {Object|undefined} attrs - An object of attributes to set on this block
46991 * @param {Object|undefined} opts - An object of options to set on this block
46992 * @returns {Block} - a paragraph {Block}
46993 * @memberof Extensions/Processor
46994 */
46995Processor.prototype.createParagraph = function (parent, source, attrs, opts) {
46996  return this.$create_paragraph(parent, source, toHash(attrs), toHash(opts))
46997}
46998
46999/**
47000 * Creates an open block and links it to the specified parent.
47001 *
47002 * @param {Block|Section|Document} parent - The parent Block (Block, Section, or Document) of this new block.
47003 * @param {string|Array<string>} source - The source
47004 * @param {Object|undefined} attrs - An object of attributes to set on this block
47005 * @param {Object|undefined} opts - An object of options to set on this block
47006 * @returns {Block} - an open {Block}
47007 * @memberof Extensions/Processor
47008 */
47009Processor.prototype.createOpenBlock = function (parent, source, attrs, opts) {
47010  return this.$create_open_block(parent, source, toHash(attrs), toHash(opts))
47011}
47012
47013/**
47014 * Creates an example block and links it to the specified parent.
47015 *
47016 * @param {Block|Section|Document} parent - The parent Block (Block, Section, or Document) of this new block.
47017 * @param {string|Array<string>} source - The source
47018 * @param {Object|undefined} attrs - An object of attributes to set on this block
47019 * @param {Object|undefined} opts - An object of options to set on this block
47020 * @returns {Block} - an example {Block}
47021 * @memberof Extensions/Processor
47022 */
47023Processor.prototype.createExampleBlock = function (parent, source, attrs, opts) {
47024  return this.$create_example_block(parent, source, toHash(attrs), toHash(opts))
47025}
47026
47027/**
47028 * Creates a literal block and links it to the specified parent.
47029 *
47030 * @param {Block|Section|Document} parent - The parent Block (Block, Section, or Document) of this new block.
47031 * @param {string|Array<string>} source - The source
47032 * @param {Object|undefined} attrs - An object of attributes to set on this block
47033 * @param {Object|undefined} opts - An object of options to set on this block
47034 * @returns {Block} - a literal {Block}
47035 * @memberof Extensions/Processor
47036 */
47037Processor.prototype.createPassBlock = function (parent, source, attrs, opts) {
47038  return this.$create_pass_block(parent, source, toHash(attrs), toHash(opts))
47039}
47040
47041/**
47042 * Creates a listing block and links it to the specified parent.
47043 *
47044 * @param {Block|Section|Document} parent - The parent Block (Block, Section, or Document) of this new block.
47045 * @param {string|Array<string>} source - The source
47046 * @param {Object|undefined} attrs - An object of attributes to set on this block
47047 * @param {Object|undefined} opts - An object of options to set on this block
47048 * @returns {Block} - a listing {Block}
47049 * @memberof Extensions/Processor
47050 */
47051Processor.prototype.createListingBlock = function (parent, source, attrs, opts) {
47052  return this.$create_listing_block(parent, source, toHash(attrs), toHash(opts))
47053}
47054
47055/**
47056 * Creates a literal block and links it to the specified parent.
47057 *
47058 * @param {Block|Section|Document} parent - The parent Block (Block, Section, or Document) of this new block.
47059 * @param {string|Array<string>} source - The source
47060 * @param {Object|undefined} attrs - An object of attributes to set on this block
47061 * @param {Object|undefined} opts - An object of options to set on this block
47062 * @returns {Block} - a literal {Block}
47063 * @memberof Extensions/Processor
47064 */
47065Processor.prototype.createLiteralBlock = function (parent, source, attrs, opts) {
47066  return this.$create_literal_block(parent, source, toHash(attrs), toHash(opts))
47067}
47068
47069/**
47070 * Creates an inline anchor and links it to the specified parent.
47071 *
47072 * @param {Block|Section|Document} parent - The parent Block (Block, Section, or Document) of this new block.
47073 * @param {string} text - The text
47074 * @param {Object|undefined} opts - An object of options to set on this block
47075 * @returns {Inline} - an {Inline} anchor
47076 * @memberof Extensions/Processor
47077 */
47078Processor.prototype.createAnchor = function (parent, text, opts) {
47079  if (opts && opts.attributes) {
47080    opts.attributes = toHash(opts.attributes)
47081  }
47082  return this.$create_anchor(parent, text, toHash(opts))
47083}
47084
47085/**
47086 * Creates an inline pass and links it to the specified parent.
47087 *
47088 * @param {Block|Section|Document} parent - The parent Block (Block, Section, or Document) of this new block.
47089 * @param {string} text - The text
47090 * @param {Object|undefined} opts - An object of options to set on this block
47091 * @returns {Inline} - an {Inline} pass
47092 * @memberof Extensions/Processor
47093 */
47094Processor.prototype.createInlinePass = function (parent, text, opts) {
47095  if (opts && opts.attributes) {
47096    opts.attributes = toHash(opts.attributes)
47097  }
47098  return this.$create_inline_pass(parent, text, toHash(opts))
47099}
47100
47101/**
47102 * Creates an inline node and links it to the specified parent.
47103 *
47104 * @param {Block|Section|Document} parent - The parent Block of this new inline node.
47105 * @param {string} context - The context name
47106 * @param {string} text - The text
47107 * @param {Object|undefined} opts - A JSON of options
47108 * @returns {Inline} - an {Inline} node
47109 * @memberof Extensions/Processor
47110 */
47111Processor.prototype.createInline = function (parent, context, text, opts) {
47112  if (opts && opts.attributes) {
47113    opts.attributes = toHash(opts.attributes)
47114  }
47115  return this.$create_inline(parent, context, text, toHash(opts))
47116}
47117
47118/**
47119 * Parses blocks in the content and attaches the block to the parent.
47120 * @param {AbstractBlock} parent - the parent block
47121 * @param {string|Array<string>} content - the content
47122 * @param {Object|undefined} attrs - an object of attributes
47123 * @returns {AbstractNode} - The parent node into which the blocks are parsed.
47124 * @memberof Extensions/Processor
47125 */
47126Processor.prototype.parseContent = function (parent, content, attrs) {
47127  return this.$parse_content(parent, content, toHash(attrs))
47128}
47129
47130/**
47131 *  Parses the attrlist String into a JSON of attributes
47132 * @param {AbstractBlock} block - the current AbstractBlock or the parent AbstractBlock if there is no current block (used for applying subs)
47133 * @param {string} attrlist - the list of attributes as a String
47134 * @param {Object|undefined} opts - an optional JSON of options to control processing:
47135 * - positional_attributes: an Array of attribute names to map positional arguments to (optional, default: [])
47136 * - sub_attributes: enables attribute substitution on the attrlist argument (optional, default: false)
47137 *
47138 * @returns - a JSON of parsed attributes
47139 * @memberof Extensions/Processor
47140 */
47141Processor.prototype.parseAttributes = function (block, attrlist, opts) {
47142  if (opts && opts.attributes) {
47143    opts.attributes = toHash(opts.attributes)
47144  }
47145  return fromHash(this.$parse_attributes(block, attrlist, toHash(opts)))
47146}
47147
47148/**
47149 * @param {string|Array<string>} value - Name of a positional attribute or an Array of positional attribute names
47150 * @memberof Extensions/Processor
47151 */
47152Processor.prototype.positionalAttributes = function (value) {
47153  return this.$positional_attrs(value)
47154}
47155
47156/**
47157 * Specify how to resolve attributes.
47158 *
47159 * @param {string|Array<string>|Object|boolean} [value] - A specification to resolve attributes.
47160 * @memberof Extensions/Processor
47161 */
47162Processor.prototype.resolveAttributes = function (value) {
47163  if (typeof value === 'object' && !Array.isArray(value)) {
47164    return this.$resolves_attributes(toHash(value))
47165  }
47166  if (arguments.length > 1) {
47167    return this.$resolves_attributes(Array.prototype.slice.call(arguments))
47168  }
47169  if (typeof value === 'undefined') {
47170    // Convert to nil otherwise an exception is thrown at:
47171    // https://github.com/asciidoctor/asciidoctor/blob/0bcb4addc17b307f62975aad203fb556a1bcd8a5/lib/asciidoctor/extensions.rb#L583
47172    //
47173    // if args.size == 1 && !args[0]
47174    //
47175    // In the above Ruby code, args[0] is undefined and Opal will try to call the function "!" on an undefined object.
47176    return this.$resolves_attributes(Opal.nil)
47177  }
47178  return this.$resolves_attributes(value)
47179}
47180
47181/**
47182 * @deprecated Please use the <code>resolveAttributes</pre> function on the {@link Extensions/Processor}.
47183 * @memberof Extensions/Processor
47184 * @see {Processor#resolveAttributes}
47185 */
47186Processor.prototype.resolvesAttributes = Processor.prototype.resolveAttributes
47187
47188/**
47189 * Get the configuration JSON for this processor instance.
47190 * @memberof Extensions/Processor
47191 */
47192Processor.prototype.getConfig = function () {
47193  return fromHash(this.config)
47194}
47195
47196/**
47197 * @memberof Extensions/Processor
47198 */
47199Processor.prototype.option = function (key, value) {
47200  this.$option(key, value)
47201}
47202
47203/**
47204 * @namespace
47205 * @module Extensions/BlockProcessor
47206 */
47207const BlockProcessor = Extensions.BlockProcessor
47208
47209/**
47210 * @param {Object} value - a JSON of default values for attributes
47211 * @memberof Extensions/BlockProcessor
47212 */
47213BlockProcessor.prototype.defaultAttributes = function (value) {
47214  this.$default_attributes(toHash(value))
47215}
47216
47217/**
47218 * @param {string} context - A context name
47219 * @memberof Extensions/BlockProcessor
47220 */
47221BlockProcessor.prototype.onContext = function (context) {
47222  return this.$on_context(context)
47223}
47224
47225/**
47226 * @param {...string} contexts - A list of context names
47227 * @memberof Extensions/BlockProcessor
47228 */
47229BlockProcessor.prototype.onContexts = function (contexts) {
47230  return this.$on_contexts(Array.prototype.slice.call(arguments))
47231}
47232
47233/**
47234 * @returns {string}
47235 * @memberof Extensions/BlockProcessor
47236 */
47237BlockProcessor.prototype.getName = function () {
47238  const name = this.name
47239  return name === Opal.nil ? undefined : name
47240}
47241
47242/**
47243 * @param {string} value
47244 * @memberof Extensions/BlockProcessor
47245 */
47246BlockProcessor.prototype.parseContentAs = function (value) {
47247  this.$parse_content_as(value)
47248}
47249
47250/**
47251 * @namespace
47252 * @module Extensions/BlockMacroProcessor
47253 */
47254const BlockMacroProcessor = Extensions.BlockMacroProcessor
47255
47256/**
47257 * @param {Object} value - a JSON of default values for attributes
47258 * @memberof Extensions/BlockMacroProcessor
47259 */
47260BlockMacroProcessor.prototype.defaultAttributes = function (value) {
47261  this.$default_attributes(toHash(value))
47262}
47263
47264/**
47265 * @returns {string} - the block macro name
47266 * @memberof Extensions/BlockMacroProcessor
47267 */
47268BlockMacroProcessor.prototype.getName = function () {
47269  const name = this.name
47270  return name === Opal.nil ? undefined : name
47271}
47272
47273/**
47274 * @param {string} value
47275 * @memberof Extensions/BlockMacroProcessor
47276 */
47277BlockMacroProcessor.prototype.parseContentAs = function (value) {
47278  this.$parse_content_as(value)
47279}
47280
47281/**
47282 * @namespace
47283 * @module Extensions/InlineMacroProcessor
47284 */
47285const InlineMacroProcessor = Extensions.InlineMacroProcessor
47286
47287/**
47288 * @param {Object} value - a JSON of default values for attributes
47289 * @memberof Extensions/InlineMacroProcessor
47290 */
47291InlineMacroProcessor.prototype.defaultAttributes = function (value) {
47292  this.$default_attributes(toHash(value))
47293}
47294
47295/**
47296 * @returns {string} - the inline macro name
47297 * @memberof Extensions/InlineMacroProcessor
47298 */
47299InlineMacroProcessor.prototype.getName = function () {
47300  const name = this.name
47301  return name === Opal.nil ? undefined : name
47302}
47303
47304/**
47305 * @param {string} value
47306 * @memberof Extensions/InlineMacroProcessor
47307 */
47308InlineMacroProcessor.prototype.parseContentAs = function (value) {
47309  this.$parse_content_as(value)
47310}
47311
47312/**
47313 * @param {string} value
47314 * @memberof Extensions/InlineMacroProcessor
47315 */
47316InlineMacroProcessor.prototype.matchFormat = function (value) {
47317  this.$match_format(value)
47318}
47319
47320/**
47321 * @param {RegExp} value
47322 * @memberof Extensions/InlineMacroProcessor
47323 */
47324InlineMacroProcessor.prototype.match = function (value) {
47325  this.$match(value)
47326}
47327
47328/**
47329 * @namespace
47330 * @module Extensions/IncludeProcessor
47331 */
47332const IncludeProcessor = Extensions.IncludeProcessor
47333
47334/**
47335 * @memberof Extensions/IncludeProcessor
47336 */
47337IncludeProcessor.prototype.handles = function (block) {
47338  return Opal.send(this, 'handles?', null, toBlock(block))
47339}
47340
47341/**
47342 * @memberof Extensions/IncludeProcessor
47343 */
47344IncludeProcessor.prototype.prefer = function () {
47345  this.$prefer()
47346}
47347
47348/**
47349 * @namespace
47350 * @module Extensions/TreeProcessor
47351 */
47352const TreeProcessor = Extensions.TreeProcessor
47353
47354/**
47355 * @memberof Extensions/TreeProcessor
47356 */
47357TreeProcessor.prototype.prefer = function () {
47358  this.$prefer()
47359}
47360
47361/**
47362 * @namespace
47363 * @module Extensions/Postprocessor
47364 */
47365const Postprocessor = Extensions.Postprocessor
47366
47367/**
47368 * @memberof Extensions/Postprocessor
47369 */
47370Postprocessor.prototype.prefer = function () {
47371  this.$prefer()
47372}
47373
47374/**
47375 * @namespace
47376 * @module Extensions/Preprocessor
47377 */
47378const Preprocessor = Extensions.Preprocessor
47379
47380/**
47381 * @memberof Extensions/Preprocessor
47382 */
47383Preprocessor.prototype.prefer = function () {
47384  this.$prefer()
47385}
47386
47387/**
47388 * @namespace
47389 * @module Extensions/DocinfoProcessor
47390 */
47391const DocinfoProcessor = Extensions.DocinfoProcessor
47392
47393/**
47394 * @memberof Extensions/DocinfoProcessor
47395 */
47396DocinfoProcessor.prototype.prefer = function () {
47397  this.$prefer()
47398}
47399
47400/**
47401 * @param {string} value - The docinfo location ("head", "header" or "footer")
47402 * @memberof Extensions/DocinfoProcessor
47403 */
47404DocinfoProcessor.prototype.atLocation = function (value) {
47405  this.$at_location(value)
47406}
47407
47408function initializeProcessorClass (superclassName, className, functions) {
47409  const superClass = Opal.const_get_qualified(Extensions, superclassName)
47410  return initializeClass(superClass, className, functions, {
47411    'handles?': function () {
47412      return true
47413    }
47414  })
47415}
47416
47417// Postprocessor
47418
47419/**
47420 * Create a postprocessor
47421 * @description this API is experimental and subject to change
47422 * @memberof Extensions
47423 */
47424Extensions.createPostprocessor = function (name, functions) {
47425  if (arguments.length === 1) {
47426    functions = name
47427    name = null
47428  }
47429  return initializeProcessorClass('Postprocessor', name, functions)
47430}
47431
47432/**
47433 * Create and instantiate a postprocessor
47434 * @description this API is experimental and subject to change
47435 * @memberof Extensions
47436 */
47437Extensions.newPostprocessor = function (name, functions) {
47438  if (arguments.length === 1) {
47439    functions = name
47440    name = null
47441  }
47442  return this.createPostprocessor(name, functions).$new()
47443}
47444
47445// Preprocessor
47446
47447/**
47448 * Create a preprocessor
47449 * @description this API is experimental and subject to change
47450 * @memberof Extensions
47451 */
47452Extensions.createPreprocessor = function (name, functions) {
47453  if (arguments.length === 1) {
47454    functions = name
47455    name = null
47456  }
47457  return initializeProcessorClass('Preprocessor', name, functions)
47458}
47459
47460/**
47461 * Create and instantiate a preprocessor
47462 * @description this API is experimental and subject to change
47463 * @memberof Extensions
47464 */
47465Extensions.newPreprocessor = function (name, functions) {
47466  if (arguments.length === 1) {
47467    functions = name
47468    name = null
47469  }
47470  return this.createPreprocessor(name, functions).$new()
47471}
47472
47473// Tree Processor
47474
47475/**
47476 * Create a tree processor
47477 * @description this API is experimental and subject to change
47478 * @memberof Extensions
47479 */
47480Extensions.createTreeProcessor = function (name, functions) {
47481  if (arguments.length === 1) {
47482    functions = name
47483    name = null
47484  }
47485  return initializeProcessorClass('TreeProcessor', name, functions)
47486}
47487
47488/**
47489 * Create and instantiate a tree processor
47490 * @description this API is experimental and subject to change
47491 * @memberof Extensions
47492 */
47493Extensions.newTreeProcessor = function (name, functions) {
47494  if (arguments.length === 1) {
47495    functions = name
47496    name = null
47497  }
47498  return this.createTreeProcessor(name, functions).$new()
47499}
47500
47501// Include Processor
47502
47503/**
47504 * Create an include processor
47505 * @description this API is experimental and subject to change
47506 * @memberof Extensions
47507 */
47508Extensions.createIncludeProcessor = function (name, functions) {
47509  if (arguments.length === 1) {
47510    functions = name
47511    name = null
47512  }
47513  return initializeProcessorClass('IncludeProcessor', name, functions)
47514}
47515
47516/**
47517 * Create and instantiate an include processor
47518 * @description this API is experimental and subject to change
47519 * @memberof Extensions
47520 */
47521Extensions.newIncludeProcessor = function (name, functions) {
47522  if (arguments.length === 1) {
47523    functions = name
47524    name = null
47525  }
47526  return this.createIncludeProcessor(name, functions).$new()
47527}
47528
47529// Docinfo Processor
47530
47531/**
47532 * Create a Docinfo processor
47533 * @description this API is experimental and subject to change
47534 * @memberof Extensions
47535 */
47536Extensions.createDocinfoProcessor = function (name, functions) {
47537  if (arguments.length === 1) {
47538    functions = name
47539    name = null
47540  }
47541  return initializeProcessorClass('DocinfoProcessor', name, functions)
47542}
47543
47544/**
47545 * Create and instantiate a Docinfo processor
47546 * @description this API is experimental and subject to change
47547 * @memberof Extensions
47548 */
47549Extensions.newDocinfoProcessor = function (name, functions) {
47550  if (arguments.length === 1) {
47551    functions = name
47552    name = null
47553  }
47554  return this.createDocinfoProcessor(name, functions).$new()
47555}
47556
47557// Block Processor
47558
47559/**
47560 * Create a block processor
47561 * @description this API is experimental and subject to change
47562 * @memberof Extensions
47563 */
47564Extensions.createBlockProcessor = function (name, functions) {
47565  if (arguments.length === 1) {
47566    functions = name
47567    name = null
47568  }
47569  return initializeProcessorClass('BlockProcessor', name, functions)
47570}
47571
47572/**
47573 * Create and instantiate a block processor
47574 * @description this API is experimental and subject to change
47575 * @memberof Extensions
47576 */
47577Extensions.newBlockProcessor = function (name, functions) {
47578  if (arguments.length === 1) {
47579    functions = name
47580    name = null
47581  }
47582  return this.createBlockProcessor(name, functions).$new()
47583}
47584
47585// Inline Macro Processor
47586
47587/**
47588 * Create an inline macro processor
47589 * @description this API is experimental and subject to change
47590 * @memberof Extensions
47591 */
47592Extensions.createInlineMacroProcessor = function (name, functions) {
47593  if (arguments.length === 1) {
47594    functions = name
47595    name = null
47596  }
47597  return initializeProcessorClass('InlineMacroProcessor', name, functions)
47598}
47599
47600/**
47601 * Create and instantiate an inline macro processor
47602 * @description this API is experimental and subject to change
47603 * @memberof Extensions
47604 */
47605Extensions.newInlineMacroProcessor = function (name, functions) {
47606  if (arguments.length === 1) {
47607    functions = name
47608    name = null
47609  }
47610  return this.createInlineMacroProcessor(name, functions).$new()
47611}
47612
47613// Block Macro Processor
47614
47615/**
47616 * Create a block macro processor
47617 * @description this API is experimental and subject to change
47618 * @memberof Extensions
47619 */
47620Extensions.createBlockMacroProcessor = function (name, functions) {
47621  if (arguments.length === 1) {
47622    functions = name
47623    name = null
47624  }
47625  return initializeProcessorClass('BlockMacroProcessor', name, functions)
47626}
47627
47628/**
47629 * Create and instantiate a block macro processor
47630 * @description this API is experimental and subject to change
47631 * @memberof Extensions
47632 */
47633Extensions.newBlockMacroProcessor = function (name, functions) {
47634  if (arguments.length === 1) {
47635    functions = name
47636    name = null
47637  }
47638  return this.createBlockMacroProcessor(name, functions).$new()
47639}
47640
47641
47642var ASCIIDOCTOR_JS_VERSION = '3.0.3';
47643
47644  /**
47645   * Get Asciidoctor.js version number.
47646   *
47647   * @memberof Asciidoctor
47648   * @returns {string} - returns the version number of Asciidoctor.js.
47649   */
47650  Opal.Asciidoctor.prototype.getVersion = function () {
47651    return ASCIIDOCTOR_JS_VERSION
47652  }
47653  return Opal.Asciidoctor
47654}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.