opal 1.0.3 → 1.1.1.rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.codeclimate.yml +13 -12
- data/.gitattributes +1 -1
- data/.github/FUNDING.yml +1 -0
- data/.github/workflows/build.yml +90 -0
- data/.jshintrc +1 -1
- data/.overcommit.yml +35 -0
- data/.rubocop.yml +44 -7
- data/{.rubocop_todo.yml → .rubocop/todo.yml} +4 -5
- data/CHANGELOG.md +152 -1
- data/Gemfile +2 -3
- data/HACKING.md +2 -9
- data/LICENSE +1 -1
- data/README.md +21 -18
- data/UNRELEASED.md +4 -2
- data/benchmark-ips/bm_array_pop_1.rb +8 -0
- data/benchmark-ips/bm_array_shift.rb +7 -0
- data/benchmark-ips/bm_js_symbols_vs_strings.rb +7 -2
- data/benchmark-ips/class_shovel_vs_singleton_class.rb +16 -0
- data/bin/build-browser-source-map-support +4 -0
- data/bin/format-filters +54 -0
- data/bin/git-submodule-fast-install +49 -0
- data/bin/remove-filters +39 -0
- data/bin/setup +4 -0
- data/bin/yarn +11 -0
- data/docs/releasing.md +18 -0
- data/docs/roda-sprockets.md +86 -0
- data/docs/sinatra.md +5 -12
- data/examples/rack/Gemfile +1 -0
- data/examples/rack/app/application.rb +3 -0
- data/examples/rack/config.ru +5 -4
- data/exe/opal-repl +2 -83
- data/lib/opal/ast/builder.rb +1 -1
- data/lib/opal/builder.rb +2 -10
- data/lib/opal/builder_processors.rb +1 -1
- data/lib/opal/cli.rb +4 -1
- data/lib/opal/cli_options.rb +11 -3
- data/lib/opal/cli_runners.rb +27 -37
- data/lib/opal/cli_runners/applescript.rb +5 -44
- data/lib/opal/cli_runners/chrome.js +7 -35
- data/lib/opal/cli_runners/chrome.rb +75 -17
- data/lib/opal/cli_runners/compiler.rb +17 -0
- data/lib/opal/cli_runners/nashorn.rb +9 -43
- data/lib/opal/cli_runners/nodejs.rb +18 -47
- data/lib/opal/cli_runners/server.rb +18 -6
- data/lib/opal/cli_runners/source-map-support-browser.js +6449 -0
- data/lib/opal/cli_runners/source-map-support-node.js +3704 -0
- data/lib/opal/cli_runners/source-map-support.js +639 -0
- data/lib/opal/cli_runners/system_runner.rb +45 -0
- data/lib/opal/compiler.rb +57 -29
- data/lib/opal/config.rb +0 -5
- data/lib/opal/erb.rb +1 -1
- data/lib/opal/magic_comments.rb +34 -0
- data/lib/opal/nodes/args/arity_check.rb +2 -1
- data/lib/opal/nodes/base.rb +1 -1
- data/lib/opal/nodes/call.rb +1 -4
- data/lib/opal/nodes/def.rb +2 -0
- data/lib/opal/nodes/iter.rb +1 -1
- data/lib/opal/nodes/literal.rb +19 -14
- data/lib/opal/nodes/logic.rb +5 -80
- data/lib/opal/nodes/masgn.rb +2 -0
- data/lib/opal/nodes/rescue.rb +1 -1
- data/lib/opal/nodes/super.rb +24 -10
- data/lib/opal/nodes/top.rb +5 -4
- data/lib/opal/parser/with_c_lexer.rb +2 -1
- data/lib/opal/parser/with_ruby_lexer.rb +1 -1
- data/lib/opal/path_reader.rb +2 -2
- data/lib/opal/paths.rb +8 -5
- data/lib/opal/repl.rb +103 -0
- data/lib/opal/rewriter.rb +4 -0
- data/lib/opal/rewriters/for_rewriter.rb +1 -1
- data/lib/opal/rewriters/js_reserved_words.rb +7 -7
- data/lib/opal/rewriters/numblocks.rb +31 -0
- data/lib/opal/rewriters/returnable_logic.rb +33 -0
- data/lib/opal/util.rb +11 -48
- data/lib/opal/version.rb +1 -1
- data/opal.gemspec +26 -26
- data/opal/corelib/array.rb +160 -118
- data/opal/corelib/array/pack.rb +5 -3
- data/opal/corelib/basic_object.rb +4 -4
- data/opal/corelib/class.rb +2 -1
- data/opal/corelib/comparable.rb +49 -31
- data/opal/corelib/constants.rb +5 -5
- data/opal/corelib/enumerable.rb +108 -46
- data/opal/corelib/enumerator.rb +27 -12
- data/opal/corelib/file.rb +3 -1
- data/opal/corelib/hash.rb +6 -1
- data/opal/corelib/helpers.rb +8 -28
- data/opal/corelib/io.rb +12 -7
- data/opal/corelib/kernel.rb +45 -14
- data/opal/corelib/kernel/format.rb +3 -1
- data/opal/corelib/math.rb +8 -6
- data/opal/corelib/method.rb +8 -0
- data/opal/corelib/module.rb +17 -2
- data/opal/corelib/number.rb +3 -12
- data/opal/corelib/proc.rb +16 -0
- data/opal/corelib/random/mersenne_twister.rb +147 -0
- data/opal/corelib/range.rb +3 -13
- data/opal/corelib/regexp.rb +10 -6
- data/opal/corelib/runtime.js +208 -81
- data/opal/corelib/string.rb +55 -49
- data/opal/corelib/string/encoding.rb +109 -32
- data/opal/corelib/string/unpack.rb +2 -17
- data/opal/corelib/struct.rb +14 -1
- data/opal/corelib/time.rb +4 -0
- data/opal/opal.rb +1 -1
- data/opal/opal/mini.rb +1 -1
- data/package.json +16 -0
- data/spec/README.md +10 -0
- data/spec/filters/bugs/array.rb +76 -0
- data/spec/filters/bugs/base64.rb +10 -0
- data/spec/filters/bugs/basicobject.rb +12 -0
- data/spec/filters/bugs/bigdecimal.rb +248 -0
- data/spec/filters/bugs/class.rb +12 -0
- data/spec/filters/bugs/complex.rb +7 -0
- data/spec/filters/bugs/date.rb +104 -0
- data/spec/filters/bugs/encoding.rb +259 -0
- data/spec/filters/bugs/enumerable.rb +26 -0
- data/spec/filters/bugs/enumerator.rb +48 -0
- data/spec/filters/bugs/exception.rb +120 -0
- data/spec/filters/bugs/file.rb +48 -0
- data/spec/filters/bugs/float.rb +74 -0
- data/spec/filters/bugs/hash.rb +60 -0
- data/spec/filters/bugs/integer.rb +78 -0
- data/spec/filters/bugs/io.rb +9 -0
- data/spec/filters/bugs/kernel.rb +401 -0
- data/spec/filters/bugs/language.rb +451 -0
- data/spec/filters/bugs/marshal.rb +50 -0
- data/spec/filters/bugs/math.rb +4 -0
- data/spec/filters/bugs/method.rb +79 -0
- data/spec/filters/bugs/module.rb +281 -0
- data/spec/filters/bugs/nilclass.rb +4 -0
- data/spec/filters/bugs/numeric.rb +27 -0
- data/spec/filters/bugs/openstruct.rb +8 -0
- data/spec/filters/bugs/pack_unpack.rb +138 -0
- data/spec/filters/bugs/pathname.rb +9 -0
- data/spec/filters/bugs/proc.rb +80 -0
- data/spec/filters/bugs/random.rb +20 -0
- data/spec/filters/bugs/range.rb +139 -0
- data/spec/filters/bugs/rational.rb +12 -0
- data/spec/filters/bugs/regexp.rb +91 -0
- data/spec/filters/bugs/set.rb +51 -0
- data/spec/filters/bugs/singleton.rb +7 -0
- data/spec/filters/bugs/string.rb +341 -0
- data/spec/filters/bugs/stringscanner.rb +78 -0
- data/spec/filters/bugs/struct.rb +26 -0
- data/spec/filters/bugs/symbol.rb +7 -0
- data/spec/filters/bugs/time.rb +109 -0
- data/spec/filters/bugs/unboundmethod.rb +33 -0
- data/spec/filters/bugs/warnings.rb +30 -0
- data/spec/filters/unsupported/array.rb +168 -0
- data/spec/filters/unsupported/basicobject.rb +15 -0
- data/spec/filters/unsupported/bignum.rb +55 -0
- data/spec/filters/unsupported/class.rb +5 -0
- data/spec/filters/unsupported/delegator.rb +6 -0
- data/spec/filters/unsupported/enumerable.rb +12 -0
- data/spec/filters/unsupported/enumerator.rb +14 -0
- data/spec/filters/unsupported/file.rb +4 -0
- data/spec/filters/unsupported/fixnum.rb +15 -0
- data/spec/filters/unsupported/float.rb +47 -0
- data/spec/filters/unsupported/freeze.rb +259 -0
- data/spec/filters/unsupported/hash.rb +44 -0
- data/spec/filters/unsupported/integer.rb +101 -0
- data/spec/filters/unsupported/kernel.rb +35 -0
- data/spec/filters/unsupported/language.rb +25 -0
- data/spec/filters/unsupported/marshal.rb +44 -0
- data/spec/filters/unsupported/matchdata.rb +63 -0
- data/spec/filters/unsupported/math.rb +4 -0
- data/spec/filters/unsupported/pathname.rb +4 -0
- data/spec/filters/unsupported/privacy.rb +287 -0
- data/spec/filters/unsupported/proc.rb +4 -0
- data/spec/filters/unsupported/random.rb +5 -0
- data/spec/filters/unsupported/range.rb +8 -0
- data/spec/filters/unsupported/regexp.rb +70 -0
- data/spec/filters/unsupported/set.rb +5 -0
- data/spec/filters/unsupported/singleton.rb +7 -0
- data/spec/filters/unsupported/string.rb +687 -0
- data/spec/filters/unsupported/struct.rb +7 -0
- data/spec/filters/unsupported/symbol.rb +21 -0
- data/spec/filters/unsupported/taint.rb +162 -0
- data/spec/filters/unsupported/thread.rb +10 -0
- data/spec/filters/unsupported/time.rb +204 -0
- data/spec/filters/unsupported/usage_of_files.rb +262 -0
- data/spec/lib/builder_processors_spec.rb +44 -0
- data/spec/lib/builder_spec.rb +133 -0
- data/spec/lib/cli_runners/server_spec.rb +25 -0
- data/spec/lib/cli_runners_spec.rb +16 -0
- data/spec/lib/cli_spec.rb +256 -0
- data/spec/lib/compiler_spec.rb +693 -0
- data/spec/lib/config_spec.rb +112 -0
- data/spec/lib/dependency_resolver_spec.rb +43 -0
- data/spec/lib/deprecations_spec.rb +17 -0
- data/spec/lib/fixtures/complex_sprockets.js.rb.erb +4 -0
- data/spec/lib/fixtures/file_with_directives.js +2 -0
- data/spec/lib/fixtures/jst_file.js.jst +1 -0
- data/spec/lib/fixtures/no_requires.rb +1 -0
- data/spec/lib/fixtures/opal_file.rb +2 -0
- data/spec/lib/fixtures/require_tree_test.rb +3 -0
- data/spec/lib/fixtures/required_file.js +1 -0
- data/spec/lib/fixtures/required_tree_test/required_file1.rb +1 -0
- data/spec/lib/fixtures/required_tree_test/required_file2.rb +1 -0
- data/spec/lib/fixtures/requires.rb +7 -0
- data/spec/lib/fixtures/source_location_test.rb +7 -0
- data/spec/lib/fixtures/source_map.rb +1 -0
- data/spec/lib/fixtures/source_map/subfolder/other_file.rb +1 -0
- data/spec/lib/fixtures/sprockets_file.js.rb +3 -0
- data/spec/lib/fixtures/sprockets_require_tree_test.rb +3 -0
- data/spec/lib/path_reader_spec.rb +47 -0
- data/spec/lib/paths_spec.rb +18 -0
- data/spec/lib/repl_spec.rb +28 -0
- data/spec/lib/rewriters/base_spec.rb +68 -0
- data/spec/lib/rewriters/binary_operator_assignment_spec.rb +153 -0
- data/spec/lib/rewriters/block_to_iter_spec.rb +28 -0
- data/spec/lib/rewriters/dot_js_syntax_spec.rb +108 -0
- data/spec/lib/rewriters/explicit_writer_return_spec.rb +186 -0
- data/spec/lib/rewriters/for_rewriter_spec.rb +92 -0
- data/spec/lib/rewriters/hashes/key_duplicates_rewriter_spec.rb +47 -0
- data/spec/lib/rewriters/js_reserved_words_spec.rb +119 -0
- data/spec/lib/rewriters/logical_operator_assignment_spec.rb +202 -0
- data/spec/lib/rewriters/opal_engine_check_spec.rb +84 -0
- data/spec/lib/rewriters/returnable_logic_spec.rb +52 -0
- data/spec/lib/rewriters/rubyspec/filters_rewriter_spec.rb +59 -0
- data/spec/lib/simple_server_spec.rb +56 -0
- data/spec/lib/source_map/file_spec.rb +67 -0
- data/spec/lib/source_map/index_spec.rb +80 -0
- data/spec/lib/spec_helper.rb +105 -0
- data/spec/mspec-opal/formatters.rb +197 -0
- data/spec/mspec-opal/runner.rb +172 -0
- data/spec/opal/compiler/irb_spec.rb +44 -0
- data/spec/opal/compiler/unicode_spec.rb +10 -0
- data/spec/opal/core/array/dup_spec.rb +23 -0
- data/spec/opal/core/array/intersection_spec.rb +38 -0
- data/spec/opal/core/array/minus_spec.rb +38 -0
- data/spec/opal/core/array/union_spec.rb +38 -0
- data/spec/opal/core/array/uniq_spec.rb +49 -0
- data/spec/opal/core/class/inherited_spec.rb +18 -0
- data/spec/opal/core/enumerable/all_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/any_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/collect_break_spec.rb +13 -0
- data/spec/opal/core/enumerable/count_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/detect_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/drop_while_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/each_slice_break_spec.rb +6 -0
- data/spec/opal/core/enumerable/each_with_index_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/each_with_object_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/find_all_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/find_index_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/grep_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/max_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/max_by_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/min_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/min_by_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/none_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/one_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/reduce_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/take_while_break_spec.rb +5 -0
- data/spec/opal/core/enumerator/with_index_spec.rb +6 -0
- data/spec/opal/core/exception_spec.rb +8 -0
- data/spec/opal/core/fixtures/require_tree_files/file 1.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_files/file 2.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_files/file 3.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_files/file 4.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_files/file 5.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_files/nested/nested 1.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_files/nested/nested 2.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_files/other/other 1.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_with_dot/file 1.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_with_dot/file 2.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_with_dot/file 3.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_with_dot/index.rb +3 -0
- data/spec/opal/core/hash/internals_spec.rb +339 -0
- data/spec/opal/core/helpers_spec.rb +14 -0
- data/spec/opal/core/iterable_props_spec.rb +53 -0
- data/spec/opal/core/kernel/at_exit_spec.rb +70 -0
- data/spec/opal/core/kernel/freeze_spec.rb +15 -0
- data/spec/opal/core/kernel/instance_variables_spec.rb +110 -0
- data/spec/opal/core/kernel/methods_spec.rb +25 -0
- data/spec/opal/core/kernel/public_methods_spec.rb +25 -0
- data/spec/opal/core/kernel/require_tree_spec.rb +18 -0
- data/spec/opal/core/kernel/respond_to_spec.rb +15 -0
- data/spec/opal/core/language/DATA/characters_support_spec.rb +9 -0
- data/spec/opal/core/language/DATA/empty___END___spec.rb +7 -0
- data/spec/opal/core/language/DATA/multiple___END___spec.rb +10 -0
- data/spec/opal/core/language/arguments/mlhs_arg_spec.rb +18 -0
- data/spec/opal/core/language/keyword_arguments_spec.rb +9 -0
- data/spec/opal/core/language/numblocks_spec.rb +16 -0
- data/spec/opal/core/language/safe_navigator_spec.rb +7 -0
- data/spec/opal/core/language/while_spec.rb +31 -0
- data/spec/opal/core/language_spec.rb +29 -0
- data/spec/opal/core/marshal/dump_spec.rb +81 -0
- data/spec/opal/core/marshal/load_spec.rb +13 -0
- data/spec/opal/core/module_spec.rb +27 -0
- data/spec/opal/core/object_id_spec.rb +56 -0
- data/spec/opal/core/regexp/interpolation_spec.rb +40 -0
- data/spec/opal/core/regexp/match_spec.rb +78 -0
- data/spec/opal/core/runtime/bridged_classes_spec.rb +123 -0
- data/spec/opal/core/runtime/constants_spec.rb +16 -0
- data/spec/opal/core/runtime/eval_spec.rb +5 -0
- data/spec/opal/core/runtime/exit_spec.rb +29 -0
- data/spec/opal/core/runtime/is_a_spec.rb +48 -0
- data/spec/opal/core/runtime/loaded_spec.rb +20 -0
- data/spec/opal/core/runtime/main_methods_spec.rb +39 -0
- data/spec/opal/core/runtime/method_missing_spec.rb +68 -0
- data/spec/opal/core/runtime/rescue_spec.rb +37 -0
- data/spec/opal/core/runtime/string_spec.rb +25 -0
- data/spec/opal/core/runtime/truthy_spec.rb +61 -0
- data/spec/opal/core/runtime_spec.rb +58 -0
- data/spec/opal/core/string/each_byte_spec.rb +19 -0
- data/spec/opal/core/string/gsub_spec.rb +35 -0
- data/spec/opal/core/string/to_sym_spec.rb +9 -0
- data/spec/opal/core/string_spec.rb +28 -0
- data/spec/opal/core/struct/dup_spec.rb +11 -0
- data/spec/opal/core/time_spec.rb +68 -0
- data/spec/opal/stdlib/erb/erb_spec.rb +30 -0
- data/spec/opal/stdlib/erb/inline_block.opalerb +3 -0
- data/spec/opal/stdlib/erb/quoted.opalerb +1 -0
- data/spec/opal/stdlib/erb/simple.opalerb +1 -0
- data/spec/opal/stdlib/js_spec.rb +72 -0
- data/spec/opal/stdlib/json/ext_spec.rb +55 -0
- data/spec/opal/stdlib/json/parse_spec.rb +37 -0
- data/spec/opal/stdlib/logger/logger_spec.rb +308 -0
- data/spec/opal/stdlib/native/alias_native_spec.rb +27 -0
- data/spec/opal/stdlib/native/array_spec.rb +11 -0
- data/spec/opal/stdlib/native/date_spec.rb +12 -0
- data/spec/opal/stdlib/native/deprecated_include_spec.rb +8 -0
- data/spec/opal/stdlib/native/each_spec.rb +13 -0
- data/spec/opal/stdlib/native/element_reference_spec.rb +16 -0
- data/spec/opal/stdlib/native/exposure_spec.rb +33 -0
- data/spec/opal/stdlib/native/ext_spec.rb +19 -0
- data/spec/opal/stdlib/native/hash_spec.rb +67 -0
- data/spec/opal/stdlib/native/initialize_spec.rb +17 -0
- data/spec/opal/stdlib/native/method_missing_spec.rb +51 -0
- data/spec/opal/stdlib/native/native_alias_spec.rb +26 -0
- data/spec/opal/stdlib/native/native_class_spec.rb +18 -0
- data/spec/opal/stdlib/native/native_module_spec.rb +13 -0
- data/spec/opal/stdlib/native/native_reader_spec.rb +22 -0
- data/spec/opal/stdlib/native/native_writer_spec.rb +30 -0
- data/spec/opal/stdlib/native/new_spec.rb +92 -0
- data/spec/opal/stdlib/native/struct_spec.rb +12 -0
- data/spec/opal/stdlib/pp_spec.rb +5 -0
- data/spec/opal/stdlib/promise/always_spec.rb +49 -0
- data/spec/opal/stdlib/promise/error_spec.rb +15 -0
- data/spec/opal/stdlib/promise/rescue_spec.rb +53 -0
- data/spec/opal/stdlib/promise/then_spec.rb +79 -0
- data/spec/opal/stdlib/promise/trace_spec.rb +51 -0
- data/spec/opal/stdlib/promise/value_spec.rb +15 -0
- data/spec/opal/stdlib/promise/when_spec.rb +34 -0
- data/spec/opal/stdlib/source_map_spec.rb +8 -0
- data/spec/opal/stdlib/strscan/scan_spec.rb +11 -0
- data/spec/opal/stdlib/template/paths_spec.rb +10 -0
- data/spec/opal/stdlib/thread/mutex_spec.rb +40 -0
- data/spec/opal/stdlib/thread/thread_queue_spec.rb +32 -0
- data/spec/opal/stdlib/thread/thread_spec.rb +60 -0
- data/spec/ruby_specs +183 -0
- data/spec/spec_helper.rb +31 -0
- data/spec/support/guard_platform.rb +4 -0
- data/spec/support/match_helpers.rb +57 -0
- data/spec/support/mspec_rspec_adapter.rb +33 -0
- data/spec/support/rewriters_helper.rb +54 -0
- data/spec/support/source_map_helper.rb +190 -0
- data/stdlib/base64.rb +2 -2
- data/stdlib/bigdecimal.rb +15 -3
- data/stdlib/bigdecimal/bignumber.js.rb +1 -1
- data/stdlib/bigdecimal/util.rb +148 -0
- data/stdlib/delegate.rb +8 -0
- data/stdlib/nodejs/fileutils.rb +1 -1
- data/stdlib/nodejs/kernel.rb +0 -13
- data/stdlib/nodejs/stacktrace.rb +4 -179
- data/stdlib/ostruct.rb +5 -0
- data/stdlib/pp.rb +586 -19
- data/stdlib/prettyprint.rb +556 -0
- data/stdlib/rbconfig/sizeof.rb +2 -0
- data/stdlib/securerandom.rb +32 -0
- data/stdlib/set.rb +36 -0
- data/stdlib/strscan.rb +15 -0
- data/tasks/benchmarking.rake +1 -1
- data/tasks/linting.rake +3 -5
- data/tasks/releasing.rake +2 -5
- data/tasks/testing.rake +16 -11
- data/tasks/testing/mspec_special_calls.rb +1 -19
- data/test/nodejs/fixtures/cat.png +0 -0
- data/test/nodejs/fixtures/hello.rb +1 -0
- data/test/nodejs/fixtures/iso88591.txt +1 -0
- data/test/nodejs/fixtures/utf8.txt +1 -0
- data/test/nodejs/fixtures/win1258.txt +1 -0
- data/test/nodejs/test_dir.rb +39 -0
- data/test/nodejs/test_env.rb +62 -0
- data/test/nodejs/test_error.rb +29 -0
- data/test/nodejs/test_file.rb +206 -0
- data/test/nodejs/test_file_encoding.rb +20 -0
- data/test/nodejs/test_io.rb +18 -0
- data/test/nodejs/test_opal_builder.rb +12 -0
- data/test/nodejs/test_pathname.rb +16 -0
- data/test/opal/cat.png +0 -0
- data/test/opal/http_server.rb +52 -0
- data/test/opal/test_base64.rb +115 -0
- data/test/opal/test_keyword.rb +590 -0
- data/test/opal/test_matrix.rb +661 -0
- data/test/opal/test_openuri.rb +53 -0
- data/test/opal/unsupported_and_bugs.rb +39 -0
- data/yarn.lock +1355 -0
- metadata +905 -40
- data/.travis.yml +0 -109
- data/appveyor.yml +0 -35
- data/lib/opal/nodes/runtime_helpers.rb +0 -51
- data/opal/corelib/random/MersenneTwister.js +0 -137
- data/opal/corelib/random/mersenne_twister.js.rb +0 -13
- data/stdlib/bigdecimal/kernel.rb +0 -5
@@ -0,0 +1,556 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# This class implements a pretty printing algorithm. It finds line breaks and
|
4
|
+
# nice indentations for grouped structure.
|
5
|
+
#
|
6
|
+
# By default, the class assumes that primitive elements are strings and each
|
7
|
+
# byte in the strings have single column in width. But it can be used for
|
8
|
+
# other situations by giving suitable arguments for some methods:
|
9
|
+
# * newline object and space generation block for PrettyPrint.new
|
10
|
+
# * optional width argument for PrettyPrint#text
|
11
|
+
# * PrettyPrint#breakable
|
12
|
+
#
|
13
|
+
# There are several candidate uses:
|
14
|
+
# * text formatting using proportional fonts
|
15
|
+
# * multibyte characters which has columns different to number of bytes
|
16
|
+
# * non-string formatting
|
17
|
+
#
|
18
|
+
# == Bugs
|
19
|
+
# * Box based formatting?
|
20
|
+
# * Other (better) model/algorithm?
|
21
|
+
#
|
22
|
+
# Report any bugs at http://bugs.ruby-lang.org
|
23
|
+
#
|
24
|
+
# == References
|
25
|
+
# Christian Lindig, Strictly Pretty, March 2000,
|
26
|
+
# http://www.st.cs.uni-sb.de/~lindig/papers/#pretty
|
27
|
+
#
|
28
|
+
# Philip Wadler, A prettier printer, March 1998,
|
29
|
+
# http://homepages.inf.ed.ac.uk/wadler/topics/language-design.html#prettier
|
30
|
+
#
|
31
|
+
# == Author
|
32
|
+
# Tanaka Akira <akr@fsij.org>
|
33
|
+
#
|
34
|
+
class PrettyPrint
|
35
|
+
|
36
|
+
# This is a convenience method which is same as follows:
|
37
|
+
#
|
38
|
+
# begin
|
39
|
+
# q = PrettyPrint.new(output, maxwidth, newline, &genspace)
|
40
|
+
# ...
|
41
|
+
# q.flush
|
42
|
+
# output
|
43
|
+
# end
|
44
|
+
#
|
45
|
+
def PrettyPrint.format(output=''.dup, maxwidth=79, newline="\n", genspace=lambda {|n| ' ' * n})
|
46
|
+
q = PrettyPrint.new(output, maxwidth, newline, &genspace)
|
47
|
+
yield q
|
48
|
+
q.flush
|
49
|
+
output
|
50
|
+
end
|
51
|
+
|
52
|
+
# This is similar to PrettyPrint::format but the result has no breaks.
|
53
|
+
#
|
54
|
+
# +maxwidth+, +newline+ and +genspace+ are ignored.
|
55
|
+
#
|
56
|
+
# The invocation of +breakable+ in the block doesn't break a line and is
|
57
|
+
# treated as just an invocation of +text+.
|
58
|
+
#
|
59
|
+
def PrettyPrint.singleline_format(output=''.dup, maxwidth=nil, newline=nil, genspace=nil)
|
60
|
+
q = SingleLine.new(output)
|
61
|
+
yield q
|
62
|
+
output
|
63
|
+
end
|
64
|
+
|
65
|
+
# Creates a buffer for pretty printing.
|
66
|
+
#
|
67
|
+
# +output+ is an output target. If it is not specified, '' is assumed. It
|
68
|
+
# should have a << method which accepts the first argument +obj+ of
|
69
|
+
# PrettyPrint#text, the first argument +sep+ of PrettyPrint#breakable, the
|
70
|
+
# first argument +newline+ of PrettyPrint.new, and the result of a given
|
71
|
+
# block for PrettyPrint.new.
|
72
|
+
#
|
73
|
+
# +maxwidth+ specifies maximum line length. If it is not specified, 79 is
|
74
|
+
# assumed. However actual outputs may overflow +maxwidth+ if long
|
75
|
+
# non-breakable texts are provided.
|
76
|
+
#
|
77
|
+
# +newline+ is used for line breaks. "\n" is used if it is not specified.
|
78
|
+
#
|
79
|
+
# The block is used to generate spaces. {|width| ' ' * width} is used if it
|
80
|
+
# is not given.
|
81
|
+
#
|
82
|
+
def initialize(output=''.dup, maxwidth=79, newline="\n", &genspace)
|
83
|
+
@output = output
|
84
|
+
@maxwidth = maxwidth
|
85
|
+
@newline = newline
|
86
|
+
@genspace = genspace || lambda {|n| ' ' * n}
|
87
|
+
|
88
|
+
@output_width = 0
|
89
|
+
@buffer_width = 0
|
90
|
+
@buffer = []
|
91
|
+
|
92
|
+
root_group = Group.new(0)
|
93
|
+
@group_stack = [root_group]
|
94
|
+
@group_queue = GroupQueue.new(root_group)
|
95
|
+
@indent = 0
|
96
|
+
end
|
97
|
+
|
98
|
+
# The output object.
|
99
|
+
#
|
100
|
+
# This defaults to '', and should accept the << method
|
101
|
+
attr_reader :output
|
102
|
+
|
103
|
+
# The maximum width of a line, before it is separated in to a newline
|
104
|
+
#
|
105
|
+
# This defaults to 79, and should be a Fixnum
|
106
|
+
attr_reader :maxwidth
|
107
|
+
|
108
|
+
# The value that is appended to +output+ to add a new line.
|
109
|
+
#
|
110
|
+
# This defaults to "\n", and should be String
|
111
|
+
attr_reader :newline
|
112
|
+
|
113
|
+
# A lambda or Proc, that takes one argument, of a Fixnum, and returns
|
114
|
+
# the corresponding number of spaces.
|
115
|
+
#
|
116
|
+
# By default this is:
|
117
|
+
# lambda {|n| ' ' * n}
|
118
|
+
attr_reader :genspace
|
119
|
+
|
120
|
+
# The number of spaces to be indented
|
121
|
+
attr_reader :indent
|
122
|
+
|
123
|
+
# The PrettyPrint::GroupQueue of groups in stack to be pretty printed
|
124
|
+
attr_reader :group_queue
|
125
|
+
|
126
|
+
# Returns the group most recently added to the stack.
|
127
|
+
#
|
128
|
+
# Contrived example:
|
129
|
+
# out = ""
|
130
|
+
# => ""
|
131
|
+
# q = PrettyPrint.new(out)
|
132
|
+
# => #<PrettyPrint:0x82f85c0 @output="", @maxwidth=79, @newline="\n", @genspace=#<Proc:0x82f8368@/home/vbatts/.rvm/rubies/ruby-head/lib/ruby/2.0.0/prettyprint.rb:82 (lambda)>, @output_width=0, @buffer_width=0, @buffer=[], @group_stack=[#<PrettyPrint::Group:0x82f8138 @depth=0, @breakables=[], @break=false>], @group_queue=#<PrettyPrint::GroupQueue:0x82fb7c0 @queue=[[#<PrettyPrint::Group:0x82f8138 @depth=0, @breakables=[], @break=false>]]>, @indent=0>
|
133
|
+
# q.group {
|
134
|
+
# q.text q.current_group.inspect
|
135
|
+
# q.text q.newline
|
136
|
+
# q.group(q.current_group.depth + 1) {
|
137
|
+
# q.text q.current_group.inspect
|
138
|
+
# q.text q.newline
|
139
|
+
# q.group(q.current_group.depth + 1) {
|
140
|
+
# q.text q.current_group.inspect
|
141
|
+
# q.text q.newline
|
142
|
+
# q.group(q.current_group.depth + 1) {
|
143
|
+
# q.text q.current_group.inspect
|
144
|
+
# q.text q.newline
|
145
|
+
# }
|
146
|
+
# }
|
147
|
+
# }
|
148
|
+
# }
|
149
|
+
# => 284
|
150
|
+
# puts out
|
151
|
+
# #<PrettyPrint::Group:0x8354758 @depth=1, @breakables=[], @break=false>
|
152
|
+
# #<PrettyPrint::Group:0x8354550 @depth=2, @breakables=[], @break=false>
|
153
|
+
# #<PrettyPrint::Group:0x83541cc @depth=3, @breakables=[], @break=false>
|
154
|
+
# #<PrettyPrint::Group:0x8347e54 @depth=4, @breakables=[], @break=false>
|
155
|
+
def current_group
|
156
|
+
@group_stack.last
|
157
|
+
end
|
158
|
+
|
159
|
+
# Breaks the buffer into lines that are shorter than #maxwidth
|
160
|
+
def break_outmost_groups
|
161
|
+
while @maxwidth < @output_width + @buffer_width
|
162
|
+
return unless group = @group_queue.deq
|
163
|
+
until group.breakables.empty?
|
164
|
+
data = @buffer.shift
|
165
|
+
@output_width = data.output(@output, @output_width)
|
166
|
+
@buffer_width -= data.width
|
167
|
+
end
|
168
|
+
while !@buffer.empty? && Text === @buffer.first
|
169
|
+
text = @buffer.shift
|
170
|
+
@output_width = text.output(@output, @output_width)
|
171
|
+
@buffer_width -= text.width
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
# This adds +obj+ as a text of +width+ columns in width.
|
177
|
+
#
|
178
|
+
# If +width+ is not specified, obj.length is used.
|
179
|
+
#
|
180
|
+
def text(obj, width=obj.length)
|
181
|
+
if @buffer.empty?
|
182
|
+
@output << obj
|
183
|
+
@output_width += width
|
184
|
+
else
|
185
|
+
text = @buffer.last
|
186
|
+
unless Text === text
|
187
|
+
text = Text.new
|
188
|
+
@buffer << text
|
189
|
+
end
|
190
|
+
text.add(obj, width)
|
191
|
+
@buffer_width += width
|
192
|
+
break_outmost_groups
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
# This is similar to #breakable except
|
197
|
+
# the decision to break or not is determined individually.
|
198
|
+
#
|
199
|
+
# Two #fill_breakable under a group may cause 4 results:
|
200
|
+
# (break,break), (break,non-break), (non-break,break), (non-break,non-break).
|
201
|
+
# This is different to #breakable because two #breakable under a group
|
202
|
+
# may cause 2 results:
|
203
|
+
# (break,break), (non-break,non-break).
|
204
|
+
#
|
205
|
+
# The text +sep+ is inserted if a line is not broken at this point.
|
206
|
+
#
|
207
|
+
# If +sep+ is not specified, " " is used.
|
208
|
+
#
|
209
|
+
# If +width+ is not specified, +sep.length+ is used. You will have to
|
210
|
+
# specify this when +sep+ is a multibyte character, for example.
|
211
|
+
#
|
212
|
+
def fill_breakable(sep=' ', width=sep.length)
|
213
|
+
group { breakable sep, width }
|
214
|
+
end
|
215
|
+
|
216
|
+
# This says "you can break a line here if necessary", and a +width+\-column
|
217
|
+
# text +sep+ is inserted if a line is not broken at the point.
|
218
|
+
#
|
219
|
+
# If +sep+ is not specified, " " is used.
|
220
|
+
#
|
221
|
+
# If +width+ is not specified, +sep.length+ is used. You will have to
|
222
|
+
# specify this when +sep+ is a multibyte character, for example.
|
223
|
+
#
|
224
|
+
def breakable(sep=' ', width=sep.length)
|
225
|
+
group = @group_stack.last
|
226
|
+
if group.break?
|
227
|
+
flush
|
228
|
+
@output << @newline
|
229
|
+
@output << @genspace.call(@indent)
|
230
|
+
@output_width = @indent
|
231
|
+
@buffer_width = 0
|
232
|
+
else
|
233
|
+
@buffer << Breakable.new(sep, width, self)
|
234
|
+
@buffer_width += width
|
235
|
+
break_outmost_groups
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
# Groups line break hints added in the block. The line break hints are all
|
240
|
+
# to be used or not.
|
241
|
+
#
|
242
|
+
# If +indent+ is specified, the method call is regarded as nested by
|
243
|
+
# nest(indent) { ... }.
|
244
|
+
#
|
245
|
+
# If +open_obj+ is specified, <tt>text open_obj, open_width</tt> is called
|
246
|
+
# before grouping. If +close_obj+ is specified, <tt>text close_obj,
|
247
|
+
# close_width</tt> is called after grouping.
|
248
|
+
#
|
249
|
+
def group(indent=0, open_obj='', close_obj='', open_width=open_obj.length, close_width=close_obj.length)
|
250
|
+
text open_obj, open_width
|
251
|
+
group_sub {
|
252
|
+
nest(indent) {
|
253
|
+
yield
|
254
|
+
}
|
255
|
+
}
|
256
|
+
text close_obj, close_width
|
257
|
+
end
|
258
|
+
|
259
|
+
# Takes a block and queues a new group that is indented 1 level further.
|
260
|
+
def group_sub
|
261
|
+
group = Group.new(@group_stack.last.depth + 1)
|
262
|
+
@group_stack.push group
|
263
|
+
@group_queue.enq group
|
264
|
+
begin
|
265
|
+
yield
|
266
|
+
ensure
|
267
|
+
@group_stack.pop
|
268
|
+
if group.breakables.empty?
|
269
|
+
@group_queue.delete group
|
270
|
+
end
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
# Increases left margin after newline with +indent+ for line breaks added in
|
275
|
+
# the block.
|
276
|
+
#
|
277
|
+
def nest(indent)
|
278
|
+
@indent += indent
|
279
|
+
begin
|
280
|
+
yield
|
281
|
+
ensure
|
282
|
+
@indent -= indent
|
283
|
+
end
|
284
|
+
end
|
285
|
+
|
286
|
+
# outputs buffered data.
|
287
|
+
#
|
288
|
+
def flush
|
289
|
+
@buffer.each {|data|
|
290
|
+
@output_width = data.output(@output, @output_width)
|
291
|
+
}
|
292
|
+
@buffer.clear
|
293
|
+
@buffer_width = 0
|
294
|
+
end
|
295
|
+
|
296
|
+
# The Text class is the means by which to collect strings from objects.
|
297
|
+
#
|
298
|
+
# This class is intended for internal use of the PrettyPrint buffers.
|
299
|
+
class Text # :nodoc:
|
300
|
+
|
301
|
+
# Creates a new text object.
|
302
|
+
#
|
303
|
+
# This constructor takes no arguments.
|
304
|
+
#
|
305
|
+
# The workflow is to append a PrettyPrint::Text object to the buffer, and
|
306
|
+
# being able to call the buffer.last() to reference it.
|
307
|
+
#
|
308
|
+
# As there are objects, use PrettyPrint::Text#add to include the objects
|
309
|
+
# and the width to utilized by the String version of this object.
|
310
|
+
def initialize
|
311
|
+
@objs = []
|
312
|
+
@width = 0
|
313
|
+
end
|
314
|
+
|
315
|
+
# The total width of the objects included in this Text object.
|
316
|
+
attr_reader :width
|
317
|
+
|
318
|
+
# Render the String text of the objects that have been added to this Text object.
|
319
|
+
#
|
320
|
+
# Output the text to +out+, and increment the width to +output_width+
|
321
|
+
def output(out, output_width)
|
322
|
+
@objs.each {|obj| out << obj}
|
323
|
+
output_width + @width
|
324
|
+
end
|
325
|
+
|
326
|
+
# Include +obj+ in the objects to be pretty printed, and increment
|
327
|
+
# this Text object's total width by +width+
|
328
|
+
def add(obj, width)
|
329
|
+
@objs << obj
|
330
|
+
@width += width
|
331
|
+
end
|
332
|
+
end
|
333
|
+
|
334
|
+
# The Breakable class is used for breaking up object information
|
335
|
+
#
|
336
|
+
# This class is intended for internal use of the PrettyPrint buffers.
|
337
|
+
class Breakable # :nodoc:
|
338
|
+
|
339
|
+
# Create a new Breakable object.
|
340
|
+
#
|
341
|
+
# Arguments:
|
342
|
+
# * +sep+ String of the separator
|
343
|
+
# * +width+ Fixnum width of the +sep+
|
344
|
+
# * +q+ parent PrettyPrint object, to base from
|
345
|
+
def initialize(sep, width, q)
|
346
|
+
@obj = sep
|
347
|
+
@width = width
|
348
|
+
@pp = q
|
349
|
+
@indent = q.indent
|
350
|
+
@group = q.current_group
|
351
|
+
@group.breakables.push self
|
352
|
+
end
|
353
|
+
|
354
|
+
# Holds the separator String
|
355
|
+
#
|
356
|
+
# The +sep+ argument from ::new
|
357
|
+
attr_reader :obj
|
358
|
+
|
359
|
+
# The width of +obj+ / +sep+
|
360
|
+
attr_reader :width
|
361
|
+
|
362
|
+
# The number of spaces to indent.
|
363
|
+
#
|
364
|
+
# This is inferred from +q+ within PrettyPrint, passed in ::new
|
365
|
+
attr_reader :indent
|
366
|
+
|
367
|
+
# Render the String text of the objects that have been added to this
|
368
|
+
# Breakable object.
|
369
|
+
#
|
370
|
+
# Output the text to +out+, and increment the width to +output_width+
|
371
|
+
def output(out, output_width)
|
372
|
+
@group.breakables.shift
|
373
|
+
if @group.break?
|
374
|
+
out << @pp.newline
|
375
|
+
out << @pp.genspace.call(@indent)
|
376
|
+
@indent
|
377
|
+
else
|
378
|
+
@pp.group_queue.delete @group if @group.breakables.empty?
|
379
|
+
out << @obj
|
380
|
+
output_width + @width
|
381
|
+
end
|
382
|
+
end
|
383
|
+
end
|
384
|
+
|
385
|
+
# The Group class is used for making indentation easier.
|
386
|
+
#
|
387
|
+
# While this class does neither the breaking into newlines nor indentation,
|
388
|
+
# it is used in a stack (as well as a queue) within PrettyPrint, to group
|
389
|
+
# objects.
|
390
|
+
#
|
391
|
+
# For information on using groups, see PrettyPrint#group
|
392
|
+
#
|
393
|
+
# This class is intended for internal use of the PrettyPrint buffers.
|
394
|
+
class Group # :nodoc:
|
395
|
+
# Create a Group object
|
396
|
+
#
|
397
|
+
# Arguments:
|
398
|
+
# * +depth+ - this group's relation to previous groups
|
399
|
+
def initialize(depth)
|
400
|
+
@depth = depth
|
401
|
+
@breakables = []
|
402
|
+
@break = false
|
403
|
+
end
|
404
|
+
|
405
|
+
# This group's relation to previous groups
|
406
|
+
attr_reader :depth
|
407
|
+
|
408
|
+
# Array to hold the Breakable objects for this Group
|
409
|
+
attr_reader :breakables
|
410
|
+
|
411
|
+
# Makes a break for this Group, and returns true
|
412
|
+
def break
|
413
|
+
@break = true
|
414
|
+
end
|
415
|
+
|
416
|
+
# Boolean of whether this Group has made a break
|
417
|
+
def break?
|
418
|
+
@break
|
419
|
+
end
|
420
|
+
|
421
|
+
# Boolean of whether this Group has been queried for being first
|
422
|
+
#
|
423
|
+
# This is used as a predicate, and ought to be called first.
|
424
|
+
def first?
|
425
|
+
if defined? @first
|
426
|
+
false
|
427
|
+
else
|
428
|
+
@first = false
|
429
|
+
true
|
430
|
+
end
|
431
|
+
end
|
432
|
+
end
|
433
|
+
|
434
|
+
# The GroupQueue class is used for managing the queue of Group to be pretty
|
435
|
+
# printed.
|
436
|
+
#
|
437
|
+
# This queue groups the Group objects, based on their depth.
|
438
|
+
#
|
439
|
+
# This class is intended for internal use of the PrettyPrint buffers.
|
440
|
+
class GroupQueue # :nodoc:
|
441
|
+
# Create a GroupQueue object
|
442
|
+
#
|
443
|
+
# Arguments:
|
444
|
+
# * +groups+ - one or more PrettyPrint::Group objects
|
445
|
+
def initialize(*groups)
|
446
|
+
@queue = []
|
447
|
+
groups.each {|g| enq g}
|
448
|
+
end
|
449
|
+
|
450
|
+
# Enqueue +group+
|
451
|
+
#
|
452
|
+
# This does not strictly append the group to the end of the queue,
|
453
|
+
# but instead adds it in line, base on the +group.depth+
|
454
|
+
def enq(group)
|
455
|
+
depth = group.depth
|
456
|
+
@queue << [] until depth < @queue.length
|
457
|
+
@queue[depth] << group
|
458
|
+
end
|
459
|
+
|
460
|
+
# Returns the outer group of the queue
|
461
|
+
def deq
|
462
|
+
@queue.each {|gs|
|
463
|
+
(gs.length-1).downto(0) {|i|
|
464
|
+
unless gs[i].breakables.empty?
|
465
|
+
group = gs.slice!(i, 1).first
|
466
|
+
group.break
|
467
|
+
return group
|
468
|
+
end
|
469
|
+
}
|
470
|
+
gs.each {|group| group.break}
|
471
|
+
gs.clear
|
472
|
+
}
|
473
|
+
return nil
|
474
|
+
end
|
475
|
+
|
476
|
+
# Remote +group+ from this queue
|
477
|
+
def delete(group)
|
478
|
+
@queue[group.depth].delete(group)
|
479
|
+
end
|
480
|
+
end
|
481
|
+
|
482
|
+
# PrettyPrint::SingleLine is used by PrettyPrint.singleline_format
|
483
|
+
#
|
484
|
+
# It is passed to be similar to a PrettyPrint object itself, by responding to:
|
485
|
+
# * #text
|
486
|
+
# * #breakable
|
487
|
+
# * #nest
|
488
|
+
# * #group
|
489
|
+
# * #flush
|
490
|
+
# * #first?
|
491
|
+
#
|
492
|
+
# but instead, the output has no line breaks
|
493
|
+
#
|
494
|
+
class SingleLine
|
495
|
+
# Create a PrettyPrint::SingleLine object
|
496
|
+
#
|
497
|
+
# Arguments:
|
498
|
+
# * +output+ - String (or similar) to store rendered text. Needs to respond to '<<'
|
499
|
+
# * +maxwidth+ - Argument position expected to be here for compatibility.
|
500
|
+
# This argument is a noop.
|
501
|
+
# * +newline+ - Argument position expected to be here for compatibility.
|
502
|
+
# This argument is a noop.
|
503
|
+
def initialize(output, maxwidth=nil, newline=nil)
|
504
|
+
@output = output
|
505
|
+
@first = [true]
|
506
|
+
end
|
507
|
+
|
508
|
+
# Add +obj+ to the text to be output.
|
509
|
+
#
|
510
|
+
# +width+ argument is here for compatibility. It is a noop argument.
|
511
|
+
def text(obj, width=nil)
|
512
|
+
@output << obj
|
513
|
+
end
|
514
|
+
|
515
|
+
# Appends +sep+ to the text to be output. By default +sep+ is ' '
|
516
|
+
#
|
517
|
+
# +width+ argument is here for compatibility. It is a noop argument.
|
518
|
+
def breakable(sep=' ', width=nil)
|
519
|
+
@output << sep
|
520
|
+
end
|
521
|
+
|
522
|
+
# Takes +indent+ arg, but does nothing with it.
|
523
|
+
#
|
524
|
+
# Yields to a block.
|
525
|
+
def nest(indent) # :nodoc:
|
526
|
+
yield
|
527
|
+
end
|
528
|
+
|
529
|
+
# Opens a block for grouping objects to be pretty printed.
|
530
|
+
#
|
531
|
+
# Arguments:
|
532
|
+
# * +indent+ - noop argument. Present for compatibility.
|
533
|
+
# * +open_obj+ - text appended before the &blok. Default is ''
|
534
|
+
# * +close_obj+ - text appended after the &blok. Default is ''
|
535
|
+
# * +open_width+ - noop argument. Present for compatibility.
|
536
|
+
# * +close_width+ - noop argument. Present for compatibility.
|
537
|
+
def group(indent=nil, open_obj='', close_obj='', open_width=nil, close_width=nil)
|
538
|
+
@first.push true
|
539
|
+
@output << open_obj
|
540
|
+
yield
|
541
|
+
@output << close_obj
|
542
|
+
@first.pop
|
543
|
+
end
|
544
|
+
|
545
|
+
# Method present for compatibility, but is a noop
|
546
|
+
def flush # :nodoc:
|
547
|
+
end
|
548
|
+
|
549
|
+
# This is used as a predicate, and ought to be called first.
|
550
|
+
def first?
|
551
|
+
result = @first[-1]
|
552
|
+
@first[-1] = false
|
553
|
+
result
|
554
|
+
end
|
555
|
+
end
|
556
|
+
end
|