opal 0.10.6 → 0.11.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.codeclimate.yml +19 -0
- data/.gitmodules +1 -1
- data/.jshintrc +1 -2
- data/.travis.yml +26 -18
- data/CHANGELOG.md +89 -23
- data/{CODE_OF_CONDUCT.md → CONDUCT.md} +0 -0
- data/Gemfile +19 -21
- data/HACKING.md +2 -0
- data/README.md +7 -6
- data/Rakefile +1 -1
- data/appveyor.yml +21 -4
- data/benchmark-ips/bm_case.rb +33 -0
- data/benchmark-ips/bm_constants_lookup.rb +13 -0
- data/benchmark-ips/bm_is_number.rb +29 -0
- data/benchmark-ips/bm_symbol_to_proc.rb +19 -0
- data/benchmark/bm_constant_lookup_big.rb +799 -0
- data/benchmark/bm_constant_lookup_small.rb +59 -0
- data/benchmark/bm_module_definition_big.rb +400 -0
- data/benchmark/bm_module_definition_small.rb +30 -0
- data/bin/opal-repl +23 -1
- data/docs/compiled_ruby.md +16 -14
- data/docs/faq.md +3 -3
- data/docs/rspec.md +2 -1
- data/docs/unsupported_features.md +6 -4
- data/examples/rack/Gemfile +1 -0
- data/examples/rack/app/application.rb +14 -3
- data/examples/rack/app/user.rb +2 -0
- data/examples/rack/config.ru +1 -1
- data/examples/rack/index.html.erb +1 -0
- data/lib/opal.rb +6 -1
- data/lib/opal/ast/builder.rb +17 -0
- data/lib/opal/ast/node.rb +30 -0
- data/lib/opal/builder.rb +14 -3
- data/lib/opal/builder_processors.rb +1 -0
- data/lib/opal/cli.rb +45 -59
- data/lib/opal/cli_options.rb +11 -7
- data/lib/opal/cli_runners.rb +1 -0
- data/lib/opal/cli_runners/applescript.rb +3 -3
- data/lib/opal/cli_runners/nashorn.rb +1 -0
- data/lib/opal/cli_runners/nodejs.rb +4 -1
- data/lib/opal/cli_runners/phantom.js +1 -2
- data/lib/opal/cli_runners/phantomjs.rb +3 -2
- data/lib/opal/cli_runners/server.rb +1 -0
- data/lib/opal/compiler.rb +145 -94
- data/lib/opal/config.rb +1 -0
- data/lib/opal/deprecations.rb +18 -0
- data/lib/opal/erb.rb +1 -0
- data/lib/opal/errors.rb +1 -0
- data/lib/opal/fragment.rb +1 -0
- data/lib/opal/hike_path_finder.rb +1 -0
- data/lib/opal/nodes.rb +3 -0
- data/lib/opal/nodes/arglist.rb +2 -1
- data/lib/opal/nodes/args/initialize_kwargs.rb +1 -0
- data/lib/opal/nodes/args/kwarg.rb +7 -7
- data/lib/opal/nodes/args/kwoptarg.rb +6 -7
- data/lib/opal/nodes/args/kwrestarg.rb +5 -5
- data/lib/opal/nodes/args/mlhsarg.rb +3 -2
- data/lib/opal/nodes/args/normarg.rb +6 -7
- data/lib/opal/nodes/args/optarg.rb +5 -7
- data/lib/opal/nodes/args/post_args.rb +6 -5
- data/lib/opal/nodes/args/post_kwargs.rb +1 -0
- data/lib/opal/nodes/args/restarg.rb +7 -7
- data/lib/opal/nodes/array.rb +1 -0
- data/lib/opal/nodes/base.rb +24 -3
- data/lib/opal/nodes/call.rb +167 -155
- data/lib/opal/nodes/call_special.rb +31 -217
- data/lib/opal/nodes/case.rb +36 -22
- data/lib/opal/nodes/class.rb +4 -3
- data/lib/opal/nodes/constants.rb +28 -48
- data/lib/opal/nodes/csend.rb +25 -0
- data/lib/opal/nodes/def.rb +49 -16
- data/lib/opal/nodes/defined.rb +170 -60
- data/lib/opal/nodes/definitions.rb +40 -133
- data/lib/opal/nodes/defs.rb +29 -0
- data/lib/opal/nodes/for.rb +52 -25
- data/lib/opal/nodes/hash.rb +12 -35
- data/lib/opal/nodes/helpers.rb +27 -54
- data/lib/opal/nodes/if.rb +21 -32
- data/lib/opal/nodes/inline_args.rb +12 -13
- data/lib/opal/nodes/iter.rb +61 -36
- data/lib/opal/nodes/literal.rb +189 -116
- data/lib/opal/nodes/logic.rb +20 -25
- data/lib/opal/nodes/masgn.rb +20 -18
- data/lib/opal/nodes/module.rb +10 -11
- data/lib/opal/nodes/node_with_args.rb +14 -17
- data/lib/opal/nodes/rescue.rb +37 -70
- data/lib/opal/nodes/runtime_helpers.rb +8 -3
- data/lib/opal/nodes/scope.rb +9 -5
- data/lib/opal/nodes/singleton_class.rb +4 -3
- data/lib/opal/nodes/super.rb +115 -87
- data/lib/opal/nodes/top.rb +7 -2
- data/lib/opal/nodes/variables.rb +46 -35
- data/lib/opal/nodes/while.rb +11 -1
- data/lib/opal/nodes/yield.rb +1 -17
- data/lib/opal/parser.rb +28 -770
- data/lib/opal/path_reader.rb +5 -1
- data/lib/opal/paths.rb +10 -4
- data/lib/opal/regexp_anchors.rb +1 -0
- data/lib/opal/rewriter.rb +60 -0
- data/lib/opal/rewriters/base.rb +60 -0
- data/lib/opal/rewriters/binary_operator_assignment.rb +144 -0
- data/lib/opal/rewriters/block_to_iter.rb +17 -0
- data/lib/opal/rewriters/break_finder.rb +34 -0
- data/lib/opal/rewriters/dot_js_syntax.rb +60 -0
- data/lib/opal/rewriters/explicit_writer_return.rb +58 -0
- data/lib/opal/rewriters/js_reserved_words.rb +111 -0
- data/lib/opal/rewriters/logical_operator_assignment.rb +155 -0
- data/lib/opal/rewriters/opal_engine_check.rb +42 -0
- data/lib/opal/rewriters/rubyspec/filters_rewriter.rb +67 -0
- data/lib/opal/server.rb +4 -0
- data/lib/opal/simple_server.rb +100 -0
- data/lib/opal/source_map.rb +1 -1
- data/lib/opal/util.rb +5 -5
- data/lib/opal/version.rb +2 -1
- data/lib/tilt/opal.rb +1 -0
- data/opal.gemspec +8 -7
- data/opal/README.md +1 -1
- data/opal/corelib/array.rb +137 -83
- data/opal/corelib/basic_object.rb +6 -6
- data/opal/corelib/class.rb +14 -11
- data/opal/corelib/complex.rb +5 -1
- data/opal/corelib/constants.rb +3 -3
- data/opal/corelib/enumerable.rb +129 -11
- data/opal/corelib/error.rb +35 -17
- data/opal/corelib/file.rb +65 -170
- data/opal/corelib/hash.rb +128 -13
- data/opal/corelib/helpers.rb +12 -15
- data/opal/corelib/io.rb +1 -0
- data/opal/corelib/kernel.rb +40 -21
- data/opal/corelib/marshal/read_buffer.rb +1 -1
- data/opal/corelib/method.rb +33 -13
- data/opal/corelib/module.rb +133 -81
- data/opal/corelib/number.rb +141 -25
- data/opal/corelib/numeric.rb +0 -8
- data/opal/corelib/process.rb +44 -4
- data/opal/corelib/random.rb +117 -0
- data/opal/corelib/random/seedrandom.js.rb +15 -0
- data/opal/corelib/range.rb +133 -10
- data/opal/corelib/regexp.rb +37 -9
- data/opal/corelib/runtime.js +601 -390
- data/opal/corelib/string.rb +39 -8
- data/opal/corelib/string/encoding.rb +51 -7
- data/opal/corelib/struct.rb +20 -0
- data/opal/corelib/time.rb +3 -3
- data/opal/corelib/variables.rb +1 -1
- data/opal/opal.rb +1 -0
- data/spec/filters/bugs/array.rb +5 -1
- data/spec/filters/bugs/basicobject.rb +2 -5
- data/spec/filters/bugs/bigdecimal.rb +8 -22
- data/spec/filters/bugs/class.rb +2 -1
- data/spec/filters/bugs/comparable.rb +5 -0
- data/spec/filters/bugs/date.rb +3 -3
- data/spec/filters/bugs/enumerable.rb +4 -11
- data/spec/filters/bugs/enumerator.rb +2 -4
- data/spec/filters/bugs/exception.rb +16 -2
- data/spec/filters/bugs/file.rb +8 -0
- data/spec/filters/bugs/float.rb +7 -1
- data/spec/filters/bugs/hash.rb +6 -2
- data/spec/filters/bugs/integer.rb +2 -0
- data/spec/filters/bugs/io.rb +8 -0
- data/spec/filters/bugs/kernel.rb +9 -138
- data/spec/filters/bugs/language.rb +89 -174
- data/spec/filters/bugs/marshal.rb +33 -35
- data/spec/filters/bugs/method.rb +0 -24
- data/spec/filters/bugs/module.rb +19 -55
- data/spec/filters/bugs/numeric.rb +0 -119
- data/spec/filters/bugs/pathname.rb +2 -0
- data/spec/filters/bugs/proc.rb +5 -4
- data/spec/filters/bugs/random.rb +7 -0
- data/spec/filters/bugs/range.rb +12 -120
- data/spec/filters/bugs/rational.rb +1 -1
- data/spec/filters/bugs/regexp.rb +2 -40
- data/spec/filters/bugs/set.rb +0 -1
- data/spec/filters/bugs/string.rb +5 -8
- data/spec/filters/bugs/stringscanner.rb +11 -19
- data/spec/filters/bugs/time.rb +7 -1
- data/spec/filters/bugs/unboundmethod.rb +1 -11
- data/spec/filters/unsupported/array.rb +5 -1
- data/spec/filters/unsupported/basicobject.rb +1 -1
- data/spec/filters/unsupported/bignum.rb +4 -1
- data/spec/filters/unsupported/class.rb +1 -1
- data/spec/filters/unsupported/delegator.rb +1 -1
- data/spec/filters/unsupported/enumerable.rb +1 -1
- data/spec/filters/unsupported/enumerator.rb +1 -1
- data/spec/filters/unsupported/file.rb +4 -0
- data/spec/filters/unsupported/fixnum.rb +1 -1
- data/spec/filters/unsupported/float.rb +4 -1
- data/spec/filters/unsupported/freeze.rb +27 -5
- data/spec/filters/unsupported/hash.rb +7 -15
- data/spec/filters/unsupported/integer.rb +1 -1
- data/spec/filters/unsupported/kernel.rb +2 -1
- data/spec/filters/unsupported/language.rb +6 -1
- data/spec/filters/unsupported/marshal.rb +1 -1
- data/spec/filters/unsupported/matchdata.rb +4 -1
- data/spec/filters/unsupported/math.rb +1 -1
- data/spec/filters/unsupported/pathname.rb +1 -1
- data/spec/filters/unsupported/privacy.rb +141 -9
- data/spec/filters/unsupported/proc.rb +1 -1
- data/spec/filters/unsupported/random.rb +4 -0
- data/spec/filters/unsupported/range.rb +7 -0
- data/spec/filters/unsupported/regexp.rb +25 -15
- data/spec/filters/unsupported/set.rb +1 -1
- data/spec/filters/unsupported/singleton.rb +1 -1
- data/spec/filters/unsupported/string.rb +110 -101
- data/spec/filters/unsupported/struct.rb +1 -1
- data/spec/filters/unsupported/symbol.rb +2 -1
- data/spec/filters/unsupported/taint.rb +22 -7
- data/spec/filters/unsupported/thread.rb +1 -1
- data/spec/filters/unsupported/time.rb +1 -1
- data/spec/lib/builder_spec.rb +17 -0
- data/spec/lib/cli_spec.rb +37 -8
- data/spec/lib/compiler/call_spec.rb +98 -66
- data/spec/lib/compiler_spec.rb +39 -30
- data/spec/lib/dependency_resolver_spec.rb +2 -2
- data/spec/lib/deprecations_spec.rb +16 -0
- data/spec/lib/fixtures/source_location_test.rb +7 -0
- data/spec/lib/rewriters/binary_operator_assignment_spec.rb +151 -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/js_reserved_words_spec.rb +116 -0
- data/spec/lib/rewriters/logical_operator_assignment_spec.rb +202 -0
- data/spec/lib/rewriters/opal_engine_check_spec.rb +82 -0
- data/spec/lib/rewriters/rubyspec/filters_rewriter_spec.rb +53 -0
- data/spec/lib/simple_server_spec.rb +54 -0
- data/spec/mspec-opal/formatters.rb +65 -17
- data/spec/mspec-opal/runner.rb +47 -67
- data/spec/opal/core/date_spec.rb +14 -0
- data/spec/opal/core/exception_spec.rb +10 -0
- data/spec/opal/core/hash/internals_spec.rb +10 -10
- data/spec/opal/core/kernel/rand_spec.rb +0 -4
- data/spec/opal/core/kernel/respond_to_spec.rb +5 -2
- data/spec/opal/core/language/constant_lookup_spec.rb +38 -0
- data/spec/opal/core/language/predefined_spec.rb +1 -1
- data/spec/opal/core/language/safe_navigator_spec.rb +7 -0
- data/spec/opal/core/language/send_spec.rb +1 -9
- data/spec/opal/core/language/string_spec.rb +8 -8
- data/spec/opal/core/language/versions/def_2_0_spec.rb +0 -4
- data/spec/opal/core/language_spec.rb +32 -0
- data/spec/opal/core/module/const_get_spec.rb +1 -1
- data/spec/opal/core/runtime/is_a_spec.rb +36 -0
- data/spec/opal/core/runtime/rescue_spec.rb +35 -0
- data/spec/opal/core/runtime_spec.rb +4 -4
- data/spec/opal/core/string_spec.rb +8 -8
- data/spec/opal/core/time_spec.rb +26 -17
- data/spec/opal/stdlib/erb/quoted.opalerb +1 -1
- data/spec/opal/stdlib/json/parse_spec.rb +4 -0
- data/spec/opal/stdlib/native/hash_spec.rb +16 -0
- data/spec/ruby_specs +2 -1
- data/spec/spec_helper.rb +1 -0
- data/spec/support/rewriters_helper.rb +24 -0
- data/stdlib/base64.rb +4 -2
- data/stdlib/bigdecimal/bignumber.js.rb +1 -1
- data/stdlib/date.rb +18 -19
- data/stdlib/json.rb +16 -4
- data/stdlib/nashorn/file.rb +15 -0
- data/stdlib/native.rb +21 -12
- data/stdlib/nodejs/dir.rb +1 -1
- data/stdlib/nodejs/file.rb +49 -20
- data/stdlib/nodejs/io.rb +22 -1
- data/stdlib/nodejs/{node_modules/js-yaml/dist/js-yaml.js → js-yaml-3-6-1.js} +815 -626
- data/stdlib/nodejs/kernel.rb +3 -1
- data/stdlib/nodejs/package.json +0 -1
- data/stdlib/nodejs/stacktrace.rb +163 -0
- data/stdlib/nodejs/yaml.rb +2 -1
- data/stdlib/opal-platform.rb +15 -0
- data/stdlib/opal/platform.rb +5 -13
- data/stdlib/pathname.rb +1 -1
- data/stdlib/strscan.rb +15 -1
- data/stdlib/yaml.rb +1 -1
- data/tasks/benchmarking.rake +9 -0
- data/tasks/building.rake +24 -20
- data/tasks/linting.rake +24 -13
- data/tasks/testing.rake +322 -205
- data/tasks/testing/mspec_special_calls.rb +44 -15
- data/tasks/testing/opal_rspec_smoketest.Gemfile +13 -0
- data/test/nodejs/fixtures/hello.rb +1 -0
- data/test/nodejs/test_file.rb +57 -0
- data/test/nodejs/test_io.rb +18 -0
- data/test/nodejs/test_opal_builder.rb +12 -0
- data/test/opal/unsupported_and_bugs.rb +9 -0
- metadata +127 -240
- data/lib/opal/parser/grammar.rb +0 -6157
- data/lib/opal/parser/grammar.y +0 -2011
- data/lib/opal/parser/keywords.rb +0 -66
- data/lib/opal/parser/lexer.rb +0 -1352
- data/lib/opal/parser/parser_scope.rb +0 -28
- data/lib/opal/parser/sexp.rb +0 -90
- data/lib/opal/sprockets.rb +0 -77
- data/lib/opal/sprockets/environment.rb +0 -23
- data/lib/opal/sprockets/erb.rb +0 -28
- data/lib/opal/sprockets/path_reader.rb +0 -36
- data/lib/opal/sprockets/processor.rb +0 -173
- data/lib/opal/sprockets/server.rb +0 -133
- data/lib/opal/sprockets/source_map_header_patch.rb +0 -41
- data/lib/opal/sprockets/source_map_server.rb +0 -117
- data/spec/filters/bugs/compiler_opal.rb +0 -5
- data/spec/filters/bugs/language_opal.rb +0 -88
- data/spec/filters/unsupported/module.rb +0 -8
- data/spec/lib/compiler/pre_processed_conditionals_spec.rb +0 -87
- data/spec/lib/lexer_spec.rb +0 -110
- data/spec/lib/parser/alias_spec.rb +0 -26
- data/spec/lib/parser/and_spec.rb +0 -13
- data/spec/lib/parser/aref_spec.rb +0 -10
- data/spec/lib/parser/attrasgn_spec.rb +0 -28
- data/spec/lib/parser/begin_spec.rb +0 -42
- data/spec/lib/parser/block_spec.rb +0 -12
- data/spec/lib/parser/break_spec.rb +0 -17
- data/spec/lib/parser/call_spec.rb +0 -201
- data/spec/lib/parser/class_spec.rb +0 -35
- data/spec/lib/parser/comments_spec.rb +0 -11
- data/spec/lib/parser/def_spec.rb +0 -109
- data/spec/lib/parser/if_spec.rb +0 -26
- data/spec/lib/parser/iter_spec.rb +0 -59
- data/spec/lib/parser/lambda_spec.rb +0 -219
- data/spec/lib/parser/literal_spec.rb +0 -118
- data/spec/lib/parser/masgn_spec.rb +0 -37
- data/spec/lib/parser/module_spec.rb +0 -27
- data/spec/lib/parser/not_spec.rb +0 -21
- data/spec/lib/parser/op_asgn1_spec.rb +0 -23
- data/spec/lib/parser/op_asgn2_spec.rb +0 -23
- data/spec/lib/parser/op_asgn_spec.rb +0 -17
- data/spec/lib/parser/or_spec.rb +0 -13
- data/spec/lib/parser/return_spec.rb +0 -22
- data/spec/lib/parser/sclass_spec.rb +0 -21
- data/spec/lib/parser/string_spec.rb +0 -286
- data/spec/lib/parser/super_spec.rb +0 -20
- data/spec/lib/parser/unary_spec.rb +0 -52
- data/spec/lib/parser/undef_spec.rb +0 -19
- data/spec/lib/parser/unless_spec.rb +0 -13
- data/spec/lib/parser/variables_spec.rb +0 -112
- data/spec/lib/parser/while_spec.rb +0 -15
- data/spec/lib/parser/yield_spec.rb +0 -20
- data/spec/lib/sprockets/erb_spec.rb +0 -38
- data/spec/lib/sprockets/path_reader_spec.rb +0 -41
- data/spec/lib/sprockets/processor_spec.rb +0 -79
- data/spec/lib/sprockets/server_spec.rb +0 -102
- data/spec/lib/sprockets_spec.rb +0 -39
- data/spec/lib/tilt/opal_spec.rb +0 -37
- data/spec/opal/core/language/block_spec.rb +0 -538
- data/spec/opal/core/language/proc_spec.rb +0 -263
- data/spec/opal/core/language/variables_spec.rb +0 -1366
- data/spec/opal/core/runtime/block_send_spec.rb +0 -28
- data/spec/opal/core/runtime/send_spec.rb +0 -34
- data/spec/support/parser_helpers.rb +0 -37
- data/stdlib/nodejs/node_modules/js-yaml/HISTORY.md +0 -277
- data/stdlib/nodejs/node_modules/js-yaml/LICENSE +0 -21
- data/stdlib/nodejs/node_modules/js-yaml/README.md +0 -288
- data/stdlib/nodejs/node_modules/js-yaml/bin/js-yaml.js +0 -140
- data/stdlib/nodejs/node_modules/js-yaml/bower.json +0 -23
- data/stdlib/nodejs/node_modules/js-yaml/dist/js-yaml.min.js +0 -3
- data/stdlib/nodejs/node_modules/js-yaml/examples/custom_types.js +0 -102
- data/stdlib/nodejs/node_modules/js-yaml/examples/custom_types.yml +0 -18
- data/stdlib/nodejs/node_modules/js-yaml/examples/dumper.js +0 -31
- data/stdlib/nodejs/node_modules/js-yaml/examples/dumper.json +0 -22
- data/stdlib/nodejs/node_modules/js-yaml/examples/sample_document.js +0 -18
- data/stdlib/nodejs/node_modules/js-yaml/examples/sample_document.yml +0 -197
- data/stdlib/nodejs/node_modules/js-yaml/index.js +0 -7
- data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml.js +0 -39
- data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/common.js +0 -62
- data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/dumper.js +0 -554
- data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/exception.js +0 -25
- data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/loader.js +0 -1581
- data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/mark.js +0 -78
- data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/schema.js +0 -103
- data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/schema/core.js +0 -18
- data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/schema/default_full.js +0 -25
- data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/schema/default_safe.js +0 -28
- data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/schema/failsafe.js +0 -17
- data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/schema/json.js +0 -25
- data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type.js +0 -61
- data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type/binary.js +0 -133
- data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type/bool.js +0 -37
- data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type/float.js +0 -110
- data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type/int.js +0 -183
- data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type/js/function.js +0 -85
- data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type/js/regexp.js +0 -84
- data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type/js/undefined.js +0 -27
- data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type/map.js +0 -8
- data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type/merge.js +0 -12
- data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type/null.js +0 -36
- data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type/omap.js +0 -56
- data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type/pairs.js +0 -61
- data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type/seq.js +0 -8
- data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type/set.js +0 -33
- data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type/str.js +0 -8
- data/stdlib/nodejs/node_modules/js-yaml/lib/js-yaml/type/timestamp.js +0 -98
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/HISTORY.md +0 -115
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/LICENSE +0 -21
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/README.md +0 -239
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/examples/arguments.js +0 -36
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/examples/choice.js +0 -22
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/examples/constants.js +0 -59
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/examples/help.js +0 -13
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/examples/nargs.js +0 -33
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/examples/parents.js +0 -28
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/examples/prefix_chars.js +0 -23
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/examples/sub_commands.js +0 -49
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/examples/sum.js +0 -35
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/examples/testformatters.js +0 -270
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/index.js +0 -1
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/action.js +0 -146
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/action/append.js +0 -55
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/action/append/constant.js +0 -47
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/action/count.js +0 -40
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/action/help.js +0 -48
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/action/store.js +0 -50
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/action/store/constant.js +0 -43
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/action/store/false.js +0 -27
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/action/store/true.js +0 -26
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/action/subparsers.js +0 -148
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/action/version.js +0 -50
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/action_container.js +0 -481
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/argparse.js +0 -14
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/argument/error.js +0 -50
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/argument/exclusive.js +0 -54
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/argument/group.js +0 -75
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/argument_parser.js +0 -1168
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/const.js +0 -18
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/help/added_formatters.js +0 -88
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/help/formatter.js +0 -798
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/lib/namespace.js +0 -77
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/node_modules/underscore.string/.npmignore +0 -2
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/node_modules/underscore.string/.travis.yml +0 -8
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/node_modules/underscore.string/README.markdown +0 -825
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/node_modules/underscore.string/bower.json +0 -33
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/node_modules/underscore.string/component.json +0 -11
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/node_modules/underscore.string/foo.js +0 -10
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/node_modules/underscore.string/gulpfile.js +0 -26
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/node_modules/underscore.string/lib/underscore.string.js +0 -673
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/node_modules/underscore.string/libpeerconnection.log +0 -0
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/node_modules/underscore.string/package.json +0 -107
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/node_modules/underscore/LICENSE +0 -23
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/node_modules/underscore/README.md +0 -22
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/node_modules/underscore/package.json +0 -69
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/node_modules/underscore/underscore-min.js +0 -6
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/node_modules/underscore/underscore.js +0 -1415
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/argparse/package.json +0 -62
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/esprima/README.md +0 -73
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/esprima/bin/esparse.js +0 -117
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/esprima/bin/esvalidate.js +0 -177
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/esprima/esprima.js +0 -3908
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/esprima/package.json +0 -69
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/esprima/test/compat.js +0 -239
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/esprima/test/reflect.js +0 -422
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/esprima/test/run.js +0 -66
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/esprima/test/runner.js +0 -387
- data/stdlib/nodejs/node_modules/js-yaml/node_modules/esprima/test/test.js +0 -20238
- data/stdlib/nodejs/node_modules/js-yaml/package.json +0 -83
data/lib/opal/parser/keywords.rb
DELETED
@@ -1,66 +0,0 @@
|
|
1
|
-
module Opal
|
2
|
-
module Keywords
|
3
|
-
|
4
|
-
class KeywordTable
|
5
|
-
attr_accessor :name, :id, :state
|
6
|
-
|
7
|
-
def initialize(name, id, state)
|
8
|
-
@name = name
|
9
|
-
@id = id
|
10
|
-
@state = state
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
KEYWORDS = [
|
15
|
-
["__LINE__", [:k__LINE__, :k__LINE__], :expr_end],
|
16
|
-
["__FILE__", [:k__FILE__, :k__FILE__], :expr_end],
|
17
|
-
["alias", [:kALIAS, :kALIAS], :expr_fname],
|
18
|
-
["and", [:kAND, :kAND], :expr_beg],
|
19
|
-
["begin", [:kBEGIN, :kBEGIN], :expr_beg],
|
20
|
-
["break", [:kBREAK, :kBREAK], :expr_mid],
|
21
|
-
["case", [:kCASE, :kCASE], :expr_beg],
|
22
|
-
["class", [:kCLASS, :kCLASS], :expr_class],
|
23
|
-
["def", [:kDEF, :kDEF], :expr_fname],
|
24
|
-
["defined?", [:kDEFINED, :kDEFINED], :expr_arg],
|
25
|
-
["do", [:kDO, :kDO], :expr_beg],
|
26
|
-
["else", [:kELSE, :kELSE], :expr_beg],
|
27
|
-
["elsif", [:kELSIF, :kELSIF], :expr_beg],
|
28
|
-
["end", [:kEND, :kEND], :expr_end],
|
29
|
-
["ensure", [:kENSURE, :kENSURE], :expr_beg],
|
30
|
-
["false", [:kFALSE, :kFALSE], :expr_end],
|
31
|
-
["for", [:kFOR, :kFOR], :expr_beg],
|
32
|
-
["if", [:kIF, :kIF_MOD], :expr_beg],
|
33
|
-
["in", [:kIN, :kIN], :expr_beg],
|
34
|
-
["module", [:kMODULE, :kMODULE], :expr_beg],
|
35
|
-
["nil", [:kNIL, :kNIL], :expr_end],
|
36
|
-
["next", [:kNEXT, :kNEXT], :expr_mid],
|
37
|
-
["not", [:kNOT, :kNOT], :expr_beg],
|
38
|
-
["or", [:kOR, :kOR], :expr_beg],
|
39
|
-
["redo", [:kREDO, :kREDO], :expr_end],
|
40
|
-
["rescue", [:kRESCUE, :kRESCUE_MOD], :expr_mid],
|
41
|
-
["return", [:kRETURN, :kRETURN], :expr_mid],
|
42
|
-
["self", [:kSELF, :kSELF], :expr_end],
|
43
|
-
["super", [:kSUPER, :kSUPER], :expr_arg],
|
44
|
-
["then", [:kTHEN, :kTHEN], :expr_beg],
|
45
|
-
["true", [:kTRUE, :kTRUE], :expr_end],
|
46
|
-
["undef", [:kUNDEF, :kUNDEF], :expr_fname],
|
47
|
-
["unless", [:kUNLESS, :kUNLESS_MOD], :expr_beg],
|
48
|
-
["until", [:kUNTIL, :kUNTIL_MOD], :expr_beg],
|
49
|
-
["when", [:kWHEN, :kWHEN], :expr_beg],
|
50
|
-
["while", [:kWHILE, :kWHILE_MOD], :expr_beg],
|
51
|
-
["yield", [:kYIELD, :kYIELD], :expr_arg]
|
52
|
-
].map { |decl| KeywordTable.new(*decl) }
|
53
|
-
|
54
|
-
def self.map
|
55
|
-
unless @map
|
56
|
-
@map = {}
|
57
|
-
KEYWORDS.each { |k| @map[k.name] = k }
|
58
|
-
end
|
59
|
-
@map
|
60
|
-
end
|
61
|
-
|
62
|
-
def self.keyword(kw)
|
63
|
-
map[kw]
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
data/lib/opal/parser/lexer.rb
DELETED
@@ -1,1352 +0,0 @@
|
|
1
|
-
require 'opal/regexp_anchors'
|
2
|
-
require 'strscan'
|
3
|
-
require 'opal/parser/keywords'
|
4
|
-
|
5
|
-
module Opal
|
6
|
-
# {Opal::Lexer} is used by {Opal::Parser} to step through ruby code, and
|
7
|
-
# returning tokens representing each chunk of ruby code.
|
8
|
-
#
|
9
|
-
# Tokens are in the form:
|
10
|
-
#
|
11
|
-
# [token, [value, location]]
|
12
|
-
#
|
13
|
-
# where `location` is in the form `[line_number, column_number]`. The location
|
14
|
-
# data can be used to produce source maps in the compiler. Tokens are
|
15
|
-
# generally ruby symbols, and the value will always be a string value.
|
16
|
-
#
|
17
|
-
# The main method used by the parser is {#next_token}, which is called
|
18
|
-
# repeatedly until a token of value `false` is returned, which indicated the
|
19
|
-
# EOF has been reached.
|
20
|
-
#
|
21
|
-
# Generally this class is only used by {Opal::Parser} directly.
|
22
|
-
#
|
23
|
-
class Lexer
|
24
|
-
|
25
|
-
STR_FUNC_ESCAPE = 0x01
|
26
|
-
STR_FUNC_EXPAND = 0x02
|
27
|
-
STR_FUNC_REGEXP = 0x04
|
28
|
-
STR_FUNC_QWORDS = 0x08
|
29
|
-
STR_FUNC_SYMBOL = 0x10
|
30
|
-
STR_FUNC_INDENT = 0x20
|
31
|
-
STR_FUNC_XQUOTE = 0x40
|
32
|
-
|
33
|
-
STR_SQUOTE = 0x00
|
34
|
-
STR_DQUOTE = STR_FUNC_EXPAND
|
35
|
-
STR_XQUOTE = STR_FUNC_EXPAND | STR_FUNC_XQUOTE
|
36
|
-
STR_REGEXP = STR_FUNC_REGEXP | STR_FUNC_ESCAPE | STR_FUNC_EXPAND
|
37
|
-
STR_SWORD = STR_FUNC_QWORDS
|
38
|
-
STR_DWORD = STR_FUNC_QWORDS | STR_FUNC_EXPAND
|
39
|
-
STR_SSYM = STR_FUNC_SYMBOL
|
40
|
-
STR_DSYM = STR_FUNC_SYMBOL | STR_FUNC_EXPAND
|
41
|
-
|
42
|
-
attr_reader :line, :column
|
43
|
-
attr_reader :scope
|
44
|
-
attr_reader :eof_content
|
45
|
-
|
46
|
-
attr_accessor :lex_state
|
47
|
-
attr_accessor :strterm
|
48
|
-
attr_accessor :scanner
|
49
|
-
attr_accessor :yylval
|
50
|
-
attr_accessor :parser
|
51
|
-
|
52
|
-
# Create a new instance using the given ruby code and filename for
|
53
|
-
# reference.
|
54
|
-
#
|
55
|
-
# Opal::Lexer.new("ruby code", "my_file.rb")
|
56
|
-
#
|
57
|
-
# @param source [String] ruby code to lex
|
58
|
-
# @param file [String] filename of given ruby code
|
59
|
-
def initialize(source, file)
|
60
|
-
@lex_state = :expr_beg
|
61
|
-
@cond = 0
|
62
|
-
@cmdarg = 0
|
63
|
-
@line = 1
|
64
|
-
@tok_line = 1
|
65
|
-
@column = 0
|
66
|
-
@tok_column = 0
|
67
|
-
@file = file
|
68
|
-
|
69
|
-
@scanner = StringScanner.new(source)
|
70
|
-
@scanner_stack = [@scanner]
|
71
|
-
|
72
|
-
@case_stmt = nil
|
73
|
-
@paren_nest = 0
|
74
|
-
@lambda_stack = []
|
75
|
-
end
|
76
|
-
|
77
|
-
# Returns next token from source input stream.
|
78
|
-
#
|
79
|
-
# Token in form:
|
80
|
-
#
|
81
|
-
# [token, [value, [source_line, source_column]]]
|
82
|
-
#
|
83
|
-
# @return [Array]
|
84
|
-
def next_token
|
85
|
-
token = self.yylex
|
86
|
-
value = self.yylval
|
87
|
-
location = [@tok_line, @tok_column]
|
88
|
-
|
89
|
-
# once location is stored, ensure next token starts in correct place
|
90
|
-
@tok_column = @column
|
91
|
-
@tok_line = @line
|
92
|
-
|
93
|
-
[token, [value, location]]
|
94
|
-
end
|
95
|
-
|
96
|
-
def has_local?(local)
|
97
|
-
parser.scope.has_local?(local.to_sym)
|
98
|
-
end
|
99
|
-
|
100
|
-
def cond_push(n)
|
101
|
-
@cond = (@cond << 1) | (n & 1)
|
102
|
-
end
|
103
|
-
|
104
|
-
def cond_pop
|
105
|
-
@cond = @cond >> 1
|
106
|
-
end
|
107
|
-
|
108
|
-
def cond_lexpop
|
109
|
-
@cond = (@cond >> 1) | (@cond & 1)
|
110
|
-
end
|
111
|
-
|
112
|
-
def cond?
|
113
|
-
(@cond & 1) != 0
|
114
|
-
end
|
115
|
-
|
116
|
-
def cmdarg_push(n)
|
117
|
-
unless @lparen_arg_seen
|
118
|
-
@cmdarg = (@cmdarg << 1) | (n & 1)
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
def cmdarg_pop
|
123
|
-
@cmdarg = @cmdarg >> 1
|
124
|
-
end
|
125
|
-
|
126
|
-
def cmdarg_lexpop
|
127
|
-
@cmdarg = (@cmdarg >> 1) | (@cmdarg & 1)
|
128
|
-
end
|
129
|
-
|
130
|
-
def cmdarg?
|
131
|
-
(@cmdarg & 1) != 0
|
132
|
-
end
|
133
|
-
|
134
|
-
def arg?
|
135
|
-
[:expr_arg, :expr_cmdarg].include? @lex_state
|
136
|
-
end
|
137
|
-
|
138
|
-
def end?
|
139
|
-
[:expr_end, :expr_endarg, :expr_endfn].include? @lex_state
|
140
|
-
end
|
141
|
-
|
142
|
-
def beg?
|
143
|
-
[:expr_beg, :expr_value, :expr_mid, :expr_class].include? @lex_state
|
144
|
-
end
|
145
|
-
|
146
|
-
def after_operator?
|
147
|
-
[:expr_fname, :expr_dot].include? @lex_state
|
148
|
-
end
|
149
|
-
|
150
|
-
def label_state?
|
151
|
-
[:expr_beg, :expr_endfn].include?(@lex_state) or arg?
|
152
|
-
end
|
153
|
-
|
154
|
-
def spcarg?
|
155
|
-
arg? and @space_seen and !space?
|
156
|
-
end
|
157
|
-
|
158
|
-
def space?
|
159
|
-
@scanner.check(/\s/)
|
160
|
-
end
|
161
|
-
|
162
|
-
def set_arg_state
|
163
|
-
@lex_state = after_operator? ? :expr_arg : :expr_beg
|
164
|
-
end
|
165
|
-
|
166
|
-
def scan(regexp)
|
167
|
-
if result = @scanner.scan(regexp)
|
168
|
-
@column += result.length
|
169
|
-
@yylval += @scanner.matched
|
170
|
-
end
|
171
|
-
|
172
|
-
result
|
173
|
-
end
|
174
|
-
|
175
|
-
def skip(regexp)
|
176
|
-
if result = @scanner.scan(regexp)
|
177
|
-
@column += result.length
|
178
|
-
@tok_column = @column
|
179
|
-
end
|
180
|
-
|
181
|
-
result
|
182
|
-
end
|
183
|
-
|
184
|
-
def check(regexp)
|
185
|
-
@scanner.check regexp
|
186
|
-
end
|
187
|
-
|
188
|
-
def pushback(n)
|
189
|
-
@scanner.pos -= n
|
190
|
-
end
|
191
|
-
|
192
|
-
def matched
|
193
|
-
@scanner.matched
|
194
|
-
end
|
195
|
-
|
196
|
-
def line=(line)
|
197
|
-
@column = @tok_column = 0
|
198
|
-
@line = @tok_line = line
|
199
|
-
end
|
200
|
-
|
201
|
-
def new_strterm(func, term, paren)
|
202
|
-
{ :type => :string, :func => func, :term => term, :paren => paren }
|
203
|
-
end
|
204
|
-
|
205
|
-
def new_strterm2(func, term, paren)
|
206
|
-
term = new_strterm(func, term, paren)
|
207
|
-
term.merge({ :balance => true, :nesting => 0 })
|
208
|
-
end
|
209
|
-
|
210
|
-
def new_op_asgn(value)
|
211
|
-
self.yylval = value
|
212
|
-
@lex_state = :expr_beg
|
213
|
-
:tOP_ASGN
|
214
|
-
end
|
215
|
-
|
216
|
-
def process_numeric
|
217
|
-
@lex_state = :expr_end
|
218
|
-
|
219
|
-
if scan(/[\d_]+\.[\d_]+\b|[\d_]+(\.[\d_]+)?[eE][-+]?[\d_]+\b/) # FLOATS
|
220
|
-
self.yylval = scanner.matched.gsub(/_/, '').to_f
|
221
|
-
return :tFLOAT
|
222
|
-
elsif scan(/([^0][\d_]*|0)\b/) # BASE 10
|
223
|
-
self.yylval = scanner.matched.gsub(/_/, '').to_i
|
224
|
-
return :tINTEGER
|
225
|
-
elsif scan(/0[bB](0|1|_)+/) # BASE 2
|
226
|
-
self.yylval = scanner.matched.to_i(2)
|
227
|
-
return :tINTEGER
|
228
|
-
elsif scan(/0[xX](\d|[a-f]|[A-F]|_)+/) # BASE 16
|
229
|
-
self.yylval = scanner.matched.to_i(16)
|
230
|
-
return :tINTEGER
|
231
|
-
elsif scan(/0[oO]?([0-7]|_)+/) # BASE 8
|
232
|
-
self.yylval = scanner.matched.to_i(8)
|
233
|
-
return :tINTEGER
|
234
|
-
elsif scan(/0[dD]([0-9]|_)+/) # BASE 10
|
235
|
-
self.yylval = scanner.matched.gsub(/_/, '').to_i
|
236
|
-
return :tINTEGER
|
237
|
-
else
|
238
|
-
raise "Lexing error on numeric type: `#{scanner.peek 5}`"
|
239
|
-
end
|
240
|
-
end
|
241
|
-
|
242
|
-
def read_escape
|
243
|
-
if scan(/\\/)
|
244
|
-
"\\"
|
245
|
-
elsif scan(/n/)
|
246
|
-
"\n"
|
247
|
-
elsif scan(/t/)
|
248
|
-
"\t"
|
249
|
-
elsif scan(/r/)
|
250
|
-
"\r"
|
251
|
-
elsif scan(/f/)
|
252
|
-
"\f"
|
253
|
-
elsif scan(/v/)
|
254
|
-
"\v"
|
255
|
-
elsif scan(/a/)
|
256
|
-
"\a"
|
257
|
-
elsif scan(/b/)
|
258
|
-
"\b"
|
259
|
-
elsif scan(/e/)
|
260
|
-
"\e"
|
261
|
-
elsif scan(/s/)
|
262
|
-
" "
|
263
|
-
elsif scan(/[0-7]{1,3}/)
|
264
|
-
(matched.to_i(8) % 0x100).chr
|
265
|
-
elsif scan(/x([0-9a-fA-F]{1,2})/)
|
266
|
-
scanner[1].to_i(16).chr
|
267
|
-
elsif scan(/u([0-9a-zA-Z]{1,4})/)
|
268
|
-
scanner[1].to_i(16).chr(Encoding::UTF_8)
|
269
|
-
elsif scan(/C-([a-zA-Z])/)
|
270
|
-
# Control character ?\C-z or ?\C-Z
|
271
|
-
# ?\C-a = "\u0001" = 1
|
272
|
-
(scanner[1].downcase.ord - 'a'.ord + '1'.to_i(16)).chr(Encoding::UTF_8)
|
273
|
-
elsif scan(/C-([0-9])/)
|
274
|
-
# Control character ?\C-0
|
275
|
-
# ?\C-0 = "\u0010"
|
276
|
-
(scanner[1].ord - '0'.ord + '10'.to_i(16)).chr(Encoding::UTF_8)
|
277
|
-
elsif scan(/M-\\C-([a-zA-Z])/)
|
278
|
-
# Meta control character ?\M-\C-z or ?\M-\C-Z
|
279
|
-
# ?\M-\C-z = "\x81"
|
280
|
-
(scanner[1].downcase.ord - 'a'.ord + '81'.to_i(16)).chr(Encoding::UTF_8)
|
281
|
-
elsif scan(/M-\\C-([0-9])/)
|
282
|
-
# Meta control character ?\M-\C-0
|
283
|
-
# ?\M-\C-0 = "\x90"
|
284
|
-
(scanner[1].ord - '0'.ord + '90'.to_i(16)).chr(Encoding::UTF_8)
|
285
|
-
else
|
286
|
-
# escaped char doesnt need escaping, so just return it
|
287
|
-
scan(/./)
|
288
|
-
end
|
289
|
-
end
|
290
|
-
|
291
|
-
def peek_variable_name
|
292
|
-
if check(/[@$]/)
|
293
|
-
:tSTRING_DVAR
|
294
|
-
elsif scan(/\{/)
|
295
|
-
:tSTRING_DBEG
|
296
|
-
end
|
297
|
-
end
|
298
|
-
|
299
|
-
def here_document(str_parse)
|
300
|
-
eos_regx = /[ \t]*#{Regexp.escape(str_parse[:term])}(\r*\n|$)/
|
301
|
-
expand = (str_parse[:func] & STR_FUNC_EXPAND) != 0
|
302
|
-
|
303
|
-
# Don't escape single-quoted heredoc identifiers
|
304
|
-
escape = str_parse[:func] != STR_SQUOTE
|
305
|
-
|
306
|
-
if check(eos_regx)
|
307
|
-
scan(/[ \t]*#{Regexp.escape(str_parse[:term])}/)
|
308
|
-
|
309
|
-
if str_parse[:scanner]
|
310
|
-
@scanner_stack << str_parse[:scanner]
|
311
|
-
@scanner = str_parse[:scanner]
|
312
|
-
end
|
313
|
-
|
314
|
-
return :tSTRING_END
|
315
|
-
end
|
316
|
-
|
317
|
-
str_buffer = []
|
318
|
-
|
319
|
-
if scan(/#/)
|
320
|
-
if tok = peek_variable_name
|
321
|
-
return tok
|
322
|
-
end
|
323
|
-
|
324
|
-
str_buffer << '#'
|
325
|
-
end
|
326
|
-
|
327
|
-
until check(eos_regx) && scanner.bol?
|
328
|
-
if scanner.eos?
|
329
|
-
raise "reached EOF while in heredoc"
|
330
|
-
end
|
331
|
-
|
332
|
-
if scan(/\n/)
|
333
|
-
str_buffer << scanner.matched
|
334
|
-
elsif expand && check(/#(?=[\$\@\{])/)
|
335
|
-
break
|
336
|
-
elsif scan(/\\/)
|
337
|
-
str_buffer << (escape ? self.read_escape : scanner.matched)
|
338
|
-
else
|
339
|
-
reg = Regexp.new("[^\#\0\\\\\n]+|.")
|
340
|
-
|
341
|
-
scan reg
|
342
|
-
str_buffer << scanner.matched
|
343
|
-
end
|
344
|
-
end
|
345
|
-
|
346
|
-
complete_str = str_buffer.join ''
|
347
|
-
@line += complete_str.count("\n")
|
348
|
-
|
349
|
-
if str_parse[:squiggly_heredoc]
|
350
|
-
# "squiggly" heredoc should be post-processed.
|
351
|
-
# here we remove the indentation of the least-indented
|
352
|
-
# line from each line of the content
|
353
|
-
lines = complete_str.lines
|
354
|
-
min_indent = lines.map { |line| line.scan(/#{REGEXP_START}\s+/)[0].length }.min
|
355
|
-
complete_str = lines.map { |line| line[min_indent, line.length] }.join
|
356
|
-
end
|
357
|
-
|
358
|
-
self.yylval = complete_str
|
359
|
-
return :tSTRING_CONTENT
|
360
|
-
end
|
361
|
-
|
362
|
-
def parse_string
|
363
|
-
str_parse = self.strterm
|
364
|
-
func = str_parse[:func]
|
365
|
-
|
366
|
-
space = false
|
367
|
-
|
368
|
-
qwords = (func & STR_FUNC_QWORDS) != 0
|
369
|
-
expand = (func & STR_FUNC_EXPAND) != 0
|
370
|
-
regexp = (func & STR_FUNC_REGEXP) != 0
|
371
|
-
|
372
|
-
space = true if qwords and scan(/\s+/)
|
373
|
-
|
374
|
-
# if not end of string, so we must be parsing contents
|
375
|
-
str_buffer = []
|
376
|
-
|
377
|
-
if scan Regexp.new(Regexp.escape(str_parse[:term]))
|
378
|
-
if qwords && !str_parse[:done_last_space]#&& space
|
379
|
-
str_parse[:done_last_space] = true
|
380
|
-
pushback(1)
|
381
|
-
self.yylval = ' '
|
382
|
-
return :tSPACE
|
383
|
-
end
|
384
|
-
|
385
|
-
if str_parse[:balance]
|
386
|
-
if str_parse[:nesting] == 0
|
387
|
-
|
388
|
-
if regexp
|
389
|
-
self.yylval = scan(/\w+/)
|
390
|
-
return :tREGEXP_END
|
391
|
-
end
|
392
|
-
return !cond? && scan(/:[^:]/) ? :tLABEL_END : :tSTRING_END
|
393
|
-
else
|
394
|
-
str_buffer << scanner.matched
|
395
|
-
str_parse[:nesting] -= 1
|
396
|
-
self.strterm = str_parse
|
397
|
-
end
|
398
|
-
elsif regexp
|
399
|
-
@lex_state = :expr_end
|
400
|
-
self.yylval = scan(/\w+/)
|
401
|
-
return :tREGEXP_END
|
402
|
-
else
|
403
|
-
if str_parse[:scanner]
|
404
|
-
@scanner_stack << str_parse[:scanner]
|
405
|
-
@scanner = str_parse[:scanner]
|
406
|
-
end
|
407
|
-
|
408
|
-
return !cond? && scan(/:[^:]/) ? :tLABEL_END : :tSTRING_END
|
409
|
-
end
|
410
|
-
end
|
411
|
-
|
412
|
-
if space
|
413
|
-
self.yylval = ' '
|
414
|
-
return :tSPACE
|
415
|
-
end
|
416
|
-
|
417
|
-
if str_parse[:balance] and scan Regexp.new(Regexp.escape(str_parse[:paren]))
|
418
|
-
str_buffer << scanner.matched
|
419
|
-
str_parse[:nesting] += 1
|
420
|
-
elsif check(/#[@$]/)
|
421
|
-
scan(/#/)
|
422
|
-
if expand
|
423
|
-
return :tSTRING_DVAR
|
424
|
-
else
|
425
|
-
str_buffer << scanner.matched
|
426
|
-
end
|
427
|
-
|
428
|
-
elsif scan(/#\{/)
|
429
|
-
if expand
|
430
|
-
return :tSTRING_DBEG
|
431
|
-
else
|
432
|
-
str_buffer << scanner.matched
|
433
|
-
|
434
|
-
# For qword without interpolation containing its :paren symbols
|
435
|
-
# like %w(()) ow %i{{}} we should mark our str_parse expression
|
436
|
-
# as nesting. As a result, #add_string_content will try to read 1 more
|
437
|
-
# closing ')' or '}' from the string
|
438
|
-
if qwords && scanner.matched.match(Regexp.new(Regexp.escape(str_parse[:paren])))
|
439
|
-
str_parse[:nesting] += 1
|
440
|
-
end
|
441
|
-
end
|
442
|
-
|
443
|
-
# causes error, so we will just collect it later on with other text
|
444
|
-
elsif scan(/\#/)
|
445
|
-
str_buffer << '#'
|
446
|
-
end
|
447
|
-
|
448
|
-
add_string_content str_buffer, str_parse
|
449
|
-
|
450
|
-
complete_str = str_buffer.join ''
|
451
|
-
@line += complete_str.count("\n")
|
452
|
-
|
453
|
-
self.yylval = complete_str
|
454
|
-
return :tSTRING_CONTENT
|
455
|
-
end
|
456
|
-
|
457
|
-
def add_string_content(str_buffer, str_parse)
|
458
|
-
func = str_parse[:func]
|
459
|
-
|
460
|
-
end_str_re = Regexp.new(Regexp.escape(str_parse[:term]))
|
461
|
-
|
462
|
-
qwords = (func & STR_FUNC_QWORDS) != 0
|
463
|
-
expand = (func & STR_FUNC_EXPAND) != 0
|
464
|
-
regexp = (func & STR_FUNC_REGEXP) != 0
|
465
|
-
escape = (func & STR_FUNC_ESCAPE) != 0
|
466
|
-
xquote = (func == STR_XQUOTE)
|
467
|
-
|
468
|
-
until scanner.eos?
|
469
|
-
c = nil
|
470
|
-
handled = true
|
471
|
-
|
472
|
-
if check end_str_re
|
473
|
-
# eos
|
474
|
-
# if its just balancing, add it ass normal content..
|
475
|
-
if str_parse[:balance] && (str_parse[:nesting] != 0)
|
476
|
-
# we only checked above, so actually scan it
|
477
|
-
scan end_str_re
|
478
|
-
c = scanner.matched
|
479
|
-
str_parse[:nesting] -= 1
|
480
|
-
else
|
481
|
-
# not balancing, so break (eos!)
|
482
|
-
break
|
483
|
-
end
|
484
|
-
|
485
|
-
elsif str_parse[:balance] and scan Regexp.new(Regexp.escape(str_parse[:paren]))
|
486
|
-
str_parse[:nesting] += 1
|
487
|
-
c = scanner.matched
|
488
|
-
|
489
|
-
elsif qwords && scan(/\s/)
|
490
|
-
pushback(1)
|
491
|
-
break
|
492
|
-
elsif expand && check(/#(?=[\$\@\{])/)
|
493
|
-
break
|
494
|
-
elsif qwords and scan(/\s/)
|
495
|
-
pushback(1)
|
496
|
-
break
|
497
|
-
elsif scan(/\\/)
|
498
|
-
if xquote # opal - treat xstrings as dquotes? forces us to double escape
|
499
|
-
c = "\\" + scan(/./)
|
500
|
-
elsif qwords and scan(/\n/)
|
501
|
-
str_buffer << "\n"
|
502
|
-
next
|
503
|
-
elsif expand and scan(/\n/)
|
504
|
-
next
|
505
|
-
elsif qwords and scan(/\s/)
|
506
|
-
c = ' '
|
507
|
-
elsif regexp
|
508
|
-
if scan(/(.)/)
|
509
|
-
c = "\\" + scanner.matched
|
510
|
-
end
|
511
|
-
elsif expand
|
512
|
-
c = self.read_escape
|
513
|
-
elsif scan(/\n/)
|
514
|
-
# nothing..
|
515
|
-
elsif scan(/\\/)
|
516
|
-
if escape
|
517
|
-
c = "\\\\"
|
518
|
-
else
|
519
|
-
c = scanner.matched
|
520
|
-
end
|
521
|
-
else # \\
|
522
|
-
unless scan(end_str_re)
|
523
|
-
str_buffer << "\\"
|
524
|
-
else
|
525
|
-
#c = scanner.matched
|
526
|
-
end
|
527
|
-
end
|
528
|
-
else
|
529
|
-
handled = false
|
530
|
-
end
|
531
|
-
|
532
|
-
unless handled
|
533
|
-
reg = if qwords
|
534
|
-
Regexp.new("[^#{Regexp.escape str_parse[:term]}\#\0\n\ \\\\]+|.")
|
535
|
-
elsif str_parse[:balance]
|
536
|
-
Regexp.new("[^#{Regexp.escape str_parse[:term]}#{Regexp.escape str_parse[:paren]}\#\0\\\\]+|.")
|
537
|
-
else
|
538
|
-
Regexp.new("[^#{Regexp.escape str_parse[:term]}\#\0\\\\]+|.")
|
539
|
-
end
|
540
|
-
|
541
|
-
scan reg
|
542
|
-
c = scanner.matched
|
543
|
-
end
|
544
|
-
|
545
|
-
c ||= scanner.matched
|
546
|
-
str_buffer << c
|
547
|
-
end
|
548
|
-
|
549
|
-
raise "reached EOF while in string" if scanner.eos?
|
550
|
-
end
|
551
|
-
|
552
|
-
def heredoc_identifier
|
553
|
-
starts_with_minus = !!scan(/-/) # optional heredoc beginning
|
554
|
-
|
555
|
-
squiggly_heredoc = !starts_with_minus && !!scan(/~/)
|
556
|
-
|
557
|
-
# Escaping character can be ' or " or can be blank
|
558
|
-
scan(/(['"]?)/)
|
559
|
-
escape_char = @scanner[0]
|
560
|
-
|
561
|
-
if escape_char != ''
|
562
|
-
# When heredoc identified starts with ' or "
|
563
|
-
# we should read until the same closing character appears
|
564
|
-
# again in the source
|
565
|
-
regexp = Regexp.new("([^#{escape_char}]+)")
|
566
|
-
else
|
567
|
-
# Otherwise we read all characters until whitespace found
|
568
|
-
regexp = /\w+/
|
569
|
-
end
|
570
|
-
|
571
|
-
if scan(regexp)
|
572
|
-
escape_method = (escape_char == "'") ? STR_SQUOTE : STR_DQUOTE
|
573
|
-
heredoc = @scanner[0]
|
574
|
-
|
575
|
-
self.strterm = new_strterm(escape_method, heredoc, heredoc)
|
576
|
-
self.strterm[:type] = :heredoc
|
577
|
-
self.strterm[:squiggly_heredoc] = squiggly_heredoc
|
578
|
-
|
579
|
-
# read closing ' or " character
|
580
|
-
scan(Regexp.new(escape_char)) if escape_char
|
581
|
-
|
582
|
-
# if ruby code at end of line after heredoc, we have to store it to
|
583
|
-
# parse after heredoc is finished parsing
|
584
|
-
end_of_line = scan(/.*\n/)
|
585
|
-
self.strterm[:scanner] = StringScanner.new(end_of_line) if end_of_line != "\n"
|
586
|
-
|
587
|
-
self.line += 1
|
588
|
-
self.yylval = heredoc
|
589
|
-
return :tSTRING_BEG
|
590
|
-
end
|
591
|
-
end
|
592
|
-
|
593
|
-
def process_identifier(matched, cmd_start)
|
594
|
-
last_state = @lex_state
|
595
|
-
|
596
|
-
if label_state? and !check(/::/) and scan(/:/)
|
597
|
-
@lex_state = :expr_beg
|
598
|
-
self.yylval = matched
|
599
|
-
return :tLABEL
|
600
|
-
end
|
601
|
-
|
602
|
-
if matched == 'defined?'
|
603
|
-
if after_operator?
|
604
|
-
@lex_state = :expr_end
|
605
|
-
return :tIDENTIFIER
|
606
|
-
end
|
607
|
-
|
608
|
-
@lex_state = :expr_arg
|
609
|
-
return :kDEFINED
|
610
|
-
end
|
611
|
-
|
612
|
-
if matched.end_with? '?', '!'
|
613
|
-
result = :tIDENTIFIER
|
614
|
-
else
|
615
|
-
if @lex_state == :expr_fname
|
616
|
-
if !check(/\=\>/) and scan(/\=/)
|
617
|
-
result = :tIDENTIFIER
|
618
|
-
matched += scanner.matched
|
619
|
-
end
|
620
|
-
|
621
|
-
elsif matched =~ /#{REGEXP_START}[A-Z]/
|
622
|
-
result = :tCONSTANT
|
623
|
-
else
|
624
|
-
result = :tIDENTIFIER
|
625
|
-
end
|
626
|
-
end
|
627
|
-
|
628
|
-
if @lex_state != :expr_dot and kw = Keywords.keyword(matched)
|
629
|
-
old_state = @lex_state
|
630
|
-
@lex_state = kw.state
|
631
|
-
|
632
|
-
if old_state == :expr_fname
|
633
|
-
self.yylval = kw.name
|
634
|
-
return kw.id[0]
|
635
|
-
end
|
636
|
-
|
637
|
-
if @lex_state == :expr_beg
|
638
|
-
cmd_start = true
|
639
|
-
end
|
640
|
-
|
641
|
-
if matched == "do"
|
642
|
-
if after_operator?
|
643
|
-
@lex_state = :expr_end
|
644
|
-
return :tIDENTIFIER
|
645
|
-
end
|
646
|
-
|
647
|
-
if @lambda_stack.last == @paren_nest
|
648
|
-
@lambda_stack.pop
|
649
|
-
@lex_state = :expr_beg
|
650
|
-
return :kDO_LAMBDA
|
651
|
-
elsif cond?
|
652
|
-
@lex_state = :expr_beg
|
653
|
-
return :kDO_COND
|
654
|
-
elsif cmdarg? && @lex_state != :expr_cmdarg
|
655
|
-
@lex_state = :expr_beg
|
656
|
-
return :kDO_BLOCK
|
657
|
-
elsif last_state == :expr_endarg
|
658
|
-
return :kDO_BLOCK
|
659
|
-
else
|
660
|
-
@lex_state = :expr_beg
|
661
|
-
return :kDO
|
662
|
-
end
|
663
|
-
else
|
664
|
-
if old_state == :expr_beg or old_state == :expr_value
|
665
|
-
self.yylval = matched
|
666
|
-
return kw.id[0]
|
667
|
-
else
|
668
|
-
if kw.id[0] != kw.id[1]
|
669
|
-
@lex_state = :expr_beg
|
670
|
-
end
|
671
|
-
|
672
|
-
self.yylval = matched
|
673
|
-
return kw.id[1]
|
674
|
-
end
|
675
|
-
end
|
676
|
-
end
|
677
|
-
|
678
|
-
if [:expr_beg, :expr_dot, :expr_mid, :expr_arg, :expr_cmdarg].include? @lex_state
|
679
|
-
@lex_state = cmd_start ? :expr_cmdarg : :expr_arg
|
680
|
-
elsif @lex_state == :expr_fname
|
681
|
-
@lex_state = :expr_endfn
|
682
|
-
else
|
683
|
-
@lex_state = :expr_end
|
684
|
-
end
|
685
|
-
|
686
|
-
if ![:expr_dot, :expr_fname].include?(last_state) and has_local?(matched)
|
687
|
-
@lex_state = :expr_end
|
688
|
-
end
|
689
|
-
|
690
|
-
self.yylval = matched
|
691
|
-
|
692
|
-
return matched =~ /#{REGEXP_START}[A-Z]/ ? :tCONSTANT : :tIDENTIFIER
|
693
|
-
end
|
694
|
-
|
695
|
-
# Does the heavy lifting for `next_token`.
|
696
|
-
def yylex
|
697
|
-
@yylval = ''
|
698
|
-
@space_seen = false
|
699
|
-
cmd_start = false
|
700
|
-
c = ''
|
701
|
-
|
702
|
-
if self.strterm
|
703
|
-
if self.strterm[:type] == :heredoc
|
704
|
-
token = here_document(self.strterm)
|
705
|
-
else
|
706
|
-
token = parse_string
|
707
|
-
end
|
708
|
-
|
709
|
-
if token == :tSTRING_END or token == :tREGEXP_END or token == :tLABEL_END
|
710
|
-
self.strterm = nil
|
711
|
-
@lex_state = :expr_end
|
712
|
-
end
|
713
|
-
|
714
|
-
return token
|
715
|
-
end
|
716
|
-
|
717
|
-
while true
|
718
|
-
if skip(/\ |\t|\r/)
|
719
|
-
@space_seen = true
|
720
|
-
next
|
721
|
-
|
722
|
-
elsif skip(/(\n|#)/)
|
723
|
-
c = scanner.matched
|
724
|
-
if c == '#'
|
725
|
-
skip(/(.*)/)
|
726
|
-
else
|
727
|
-
self.line += 1
|
728
|
-
end
|
729
|
-
|
730
|
-
skip(/(\n+)/)
|
731
|
-
|
732
|
-
if scanner.matched
|
733
|
-
self.line += scanner.matched.length
|
734
|
-
end
|
735
|
-
|
736
|
-
next if [:expr_beg, :expr_dot].include? @lex_state
|
737
|
-
|
738
|
-
if skip(/([\ \t\r\f\v]*)\./)
|
739
|
-
@space_seen = true unless scanner[1].empty?
|
740
|
-
pushback(1)
|
741
|
-
|
742
|
-
next unless check(/\.\./)
|
743
|
-
end
|
744
|
-
|
745
|
-
cmd_start = true
|
746
|
-
@lex_state = :expr_beg
|
747
|
-
self.yylval = '\\n'
|
748
|
-
return :tNL
|
749
|
-
|
750
|
-
elsif scan(/\;/)
|
751
|
-
@lex_state = :expr_beg
|
752
|
-
return :tSEMI
|
753
|
-
|
754
|
-
elsif check(/\*/)
|
755
|
-
if scan(/\*\*\=/)
|
756
|
-
return new_op_asgn('**')
|
757
|
-
elsif scan(/\*\*/)
|
758
|
-
if [:expr_beg, :expr_mid].include? @lex_state
|
759
|
-
# kwsplat like **{ a: 1 }
|
760
|
-
return :tDSTAR
|
761
|
-
else
|
762
|
-
self.set_arg_state
|
763
|
-
return :tPOW
|
764
|
-
end
|
765
|
-
elsif scan(/\*\=/)
|
766
|
-
return new_op_asgn('*')
|
767
|
-
else
|
768
|
-
scan(/\*/)
|
769
|
-
|
770
|
-
if after_operator?
|
771
|
-
@lex_state = :expr_arg
|
772
|
-
return :tSTAR2
|
773
|
-
elsif @space_seen && check(/\S/)
|
774
|
-
@lex_state = :expr_beg
|
775
|
-
return :tSTAR
|
776
|
-
elsif [:expr_beg, :expr_mid].include? @lex_state
|
777
|
-
@lex_state = :expr_beg
|
778
|
-
return :tSTAR
|
779
|
-
else
|
780
|
-
@lex_state = :expr_beg
|
781
|
-
return :tSTAR2
|
782
|
-
end
|
783
|
-
end
|
784
|
-
|
785
|
-
elsif scan(/\!/)
|
786
|
-
if after_operator?
|
787
|
-
@lex_state = :expr_arg
|
788
|
-
if scan(/@/)
|
789
|
-
return :tBANG, '!'
|
790
|
-
end
|
791
|
-
else
|
792
|
-
@lex_state = :expr_beg
|
793
|
-
end
|
794
|
-
|
795
|
-
if scan(/\=/)
|
796
|
-
return :tNEQ
|
797
|
-
elsif scan(/\~/)
|
798
|
-
return :tNMATCH
|
799
|
-
end
|
800
|
-
|
801
|
-
return :tBANG
|
802
|
-
|
803
|
-
elsif scan(/\=/)
|
804
|
-
if @lex_state == :expr_beg and !@space_seen
|
805
|
-
if scan(/begin/) and space?
|
806
|
-
scan(/(.*)/) # end of line
|
807
|
-
line_count = 0
|
808
|
-
|
809
|
-
while true
|
810
|
-
if scanner.eos?
|
811
|
-
raise "embedded document meets end of file"
|
812
|
-
end
|
813
|
-
|
814
|
-
if scan(/\=end/) and space?
|
815
|
-
@line += line_count
|
816
|
-
return yylex
|
817
|
-
end
|
818
|
-
|
819
|
-
if scan(/\n/)
|
820
|
-
line_count += 1
|
821
|
-
next
|
822
|
-
end
|
823
|
-
|
824
|
-
scan(/(.*)/)
|
825
|
-
end
|
826
|
-
end
|
827
|
-
end
|
828
|
-
|
829
|
-
self.set_arg_state
|
830
|
-
|
831
|
-
if scan(/\=/)
|
832
|
-
if scan(/\=/)
|
833
|
-
return :tEQQ
|
834
|
-
end
|
835
|
-
|
836
|
-
return :tEQ
|
837
|
-
end
|
838
|
-
|
839
|
-
if scan(/\~/)
|
840
|
-
return :tMATCH
|
841
|
-
elsif scan(/\>/)
|
842
|
-
return :tASSOC
|
843
|
-
end
|
844
|
-
|
845
|
-
return :tEQL
|
846
|
-
|
847
|
-
elsif scan(/\"/)
|
848
|
-
self.strterm = new_strterm(STR_DQUOTE, '"', "\0")
|
849
|
-
return :tSTRING_BEG
|
850
|
-
|
851
|
-
elsif scan(/\'/)
|
852
|
-
self.strterm = new_strterm(STR_SQUOTE, "'", "\0")
|
853
|
-
return :tSTRING_BEG
|
854
|
-
|
855
|
-
elsif scan(/\`/)
|
856
|
-
self.strterm = new_strterm(STR_XQUOTE, "`", "\0")
|
857
|
-
return :tXSTRING_BEG
|
858
|
-
|
859
|
-
elsif scan(/\&/)
|
860
|
-
if scan(/\&/)
|
861
|
-
@lex_state = :expr_beg
|
862
|
-
|
863
|
-
if scan(/\=/)
|
864
|
-
return new_op_asgn('&&')
|
865
|
-
end
|
866
|
-
|
867
|
-
return :tANDOP
|
868
|
-
|
869
|
-
elsif scan(/\=/)
|
870
|
-
return new_op_asgn('&')
|
871
|
-
end
|
872
|
-
|
873
|
-
if spcarg?
|
874
|
-
#puts "warning: `&' interpreted as argument prefix"
|
875
|
-
result = :tAMPER
|
876
|
-
elsif beg?
|
877
|
-
result = :tAMPER
|
878
|
-
else
|
879
|
-
#puts "warn_balanced: & argument prefix"
|
880
|
-
result = :tAMPER2
|
881
|
-
end
|
882
|
-
|
883
|
-
self.set_arg_state
|
884
|
-
return result
|
885
|
-
|
886
|
-
elsif scan(/\|/)
|
887
|
-
if scan(/\|/)
|
888
|
-
@lex_state = :expr_beg
|
889
|
-
|
890
|
-
if scan(/\=/)
|
891
|
-
return new_op_asgn('||')
|
892
|
-
end
|
893
|
-
|
894
|
-
return :tOROP
|
895
|
-
|
896
|
-
elsif scan(/\=/)
|
897
|
-
return new_op_asgn('|')
|
898
|
-
end
|
899
|
-
|
900
|
-
self.set_arg_state
|
901
|
-
return :tPIPE
|
902
|
-
|
903
|
-
elsif scan(/\%[QqWwIixrs]/)
|
904
|
-
str_type = scanner.matched[1, 1]
|
905
|
-
paren = term = scan(/./)
|
906
|
-
|
907
|
-
case term
|
908
|
-
when '(' then term = ')'
|
909
|
-
when '[' then term = ']'
|
910
|
-
when '{' then term = '}'
|
911
|
-
when '<' then term = '>'
|
912
|
-
else
|
913
|
-
paren = "\0"
|
914
|
-
end
|
915
|
-
|
916
|
-
token, func = case str_type
|
917
|
-
when 'Q'
|
918
|
-
[:tSTRING_BEG, STR_DQUOTE]
|
919
|
-
when 'q'
|
920
|
-
[:tSTRING_BEG, STR_SQUOTE]
|
921
|
-
when 'W', 'I'
|
922
|
-
skip(/\s*/)
|
923
|
-
[:tWORDS_BEG, STR_DWORD]
|
924
|
-
when 'w', 'i'
|
925
|
-
skip(/\s*/)
|
926
|
-
[:tAWORDS_BEG, STR_SWORD]
|
927
|
-
when 'x'
|
928
|
-
[:tXSTRING_BEG, STR_XQUOTE]
|
929
|
-
when 'r'
|
930
|
-
[:tREGEXP_BEG, STR_REGEXP]
|
931
|
-
when 's'
|
932
|
-
[:tSTRING_BEG, STR_SQUOTE]
|
933
|
-
end
|
934
|
-
|
935
|
-
self.strterm = new_strterm2(func, term, paren)
|
936
|
-
return token
|
937
|
-
|
938
|
-
elsif scan(/\//)
|
939
|
-
if beg?
|
940
|
-
self.strterm = new_strterm(STR_REGEXP, '/', '/')
|
941
|
-
return :tREGEXP_BEG
|
942
|
-
elsif scan(/\=/)
|
943
|
-
return new_op_asgn('/')
|
944
|
-
end
|
945
|
-
|
946
|
-
if arg?
|
947
|
-
if !check(/\s/) && @space_seen
|
948
|
-
self.strterm = new_strterm(STR_REGEXP, '/', '/')
|
949
|
-
return :tREGEXP_BEG
|
950
|
-
end
|
951
|
-
end
|
952
|
-
|
953
|
-
if after_operator?
|
954
|
-
@lex_state = :expr_arg
|
955
|
-
else
|
956
|
-
@lex_state = :expr_beg
|
957
|
-
end
|
958
|
-
|
959
|
-
return :tDIVIDE
|
960
|
-
|
961
|
-
elsif scan(/\%/)
|
962
|
-
if check(/\=/) && @lex_state != :expr_beg
|
963
|
-
scan(/\=/)
|
964
|
-
return new_op_asgn('%')
|
965
|
-
elsif check(/[^\s]/)
|
966
|
-
|
967
|
-
if @lex_state == :expr_beg or
|
968
|
-
@lex_state == :expr_arg && @space_seen or
|
969
|
-
@lex_state == :expr_mid
|
970
|
-
|
971
|
-
paren = term = scan(/./)
|
972
|
-
|
973
|
-
case term
|
974
|
-
when '(' then term = ')'
|
975
|
-
when '[' then term = ']'
|
976
|
-
when '{' then term = '}'
|
977
|
-
when '<' then term = '>'
|
978
|
-
else
|
979
|
-
paren = "\0"
|
980
|
-
end
|
981
|
-
|
982
|
-
self.strterm = new_strterm2(STR_DQUOTE, term, paren)
|
983
|
-
return :tSTRING_BEG
|
984
|
-
end
|
985
|
-
end
|
986
|
-
|
987
|
-
self.set_arg_state
|
988
|
-
|
989
|
-
return :tPERCENT
|
990
|
-
|
991
|
-
elsif scan(/\\/)
|
992
|
-
if scan(/\r?\n/)
|
993
|
-
@space_seen = true
|
994
|
-
next
|
995
|
-
end
|
996
|
-
|
997
|
-
raise SyntaxError, "backslash must appear before newline :#{@file}:#{@line}"
|
998
|
-
|
999
|
-
elsif scan(/\(/)
|
1000
|
-
result = scanner.matched
|
1001
|
-
|
1002
|
-
if beg?
|
1003
|
-
result = :tLPAREN
|
1004
|
-
elsif @space_seen && arg?
|
1005
|
-
@lparen_arg_seen = true
|
1006
|
-
result = :tLPAREN_ARG
|
1007
|
-
else
|
1008
|
-
result = :tLPAREN2
|
1009
|
-
end
|
1010
|
-
|
1011
|
-
@lex_state = :expr_beg
|
1012
|
-
cond_push 0
|
1013
|
-
cmdarg_push 0
|
1014
|
-
@paren_nest += 1
|
1015
|
-
|
1016
|
-
return result
|
1017
|
-
|
1018
|
-
elsif scan(/\)/)
|
1019
|
-
cond_lexpop
|
1020
|
-
cmdarg_lexpop
|
1021
|
-
@paren_nest -= 1
|
1022
|
-
@lex_state = :expr_end
|
1023
|
-
@lparen_arg_seen = false
|
1024
|
-
return :tRPAREN
|
1025
|
-
|
1026
|
-
elsif scan(/\[/)
|
1027
|
-
result = scanner.matched
|
1028
|
-
|
1029
|
-
if after_operator?
|
1030
|
-
@lex_state = :expr_arg
|
1031
|
-
if scan(/\]=/)
|
1032
|
-
return :tASET
|
1033
|
-
elsif scan(/\]/)
|
1034
|
-
return :tAREF
|
1035
|
-
else
|
1036
|
-
raise "Unexpected '[' token"
|
1037
|
-
end
|
1038
|
-
elsif beg?
|
1039
|
-
result = :tLBRACK
|
1040
|
-
elsif arg? && @space_seen
|
1041
|
-
result = :tLBRACK
|
1042
|
-
else
|
1043
|
-
result = :tLBRACK2
|
1044
|
-
end
|
1045
|
-
|
1046
|
-
@lex_state = :expr_beg
|
1047
|
-
cond_push 0
|
1048
|
-
cmdarg_push 0
|
1049
|
-
return result
|
1050
|
-
|
1051
|
-
elsif scan(/\]/)
|
1052
|
-
cond_lexpop
|
1053
|
-
cmdarg_lexpop
|
1054
|
-
@lex_state = :expr_end
|
1055
|
-
return :tRBRACK
|
1056
|
-
|
1057
|
-
elsif scan(/\}/)
|
1058
|
-
cond_lexpop
|
1059
|
-
cmdarg_lexpop
|
1060
|
-
@lex_state = :expr_end
|
1061
|
-
|
1062
|
-
return :tRCURLY
|
1063
|
-
|
1064
|
-
elsif scan(/\.\.\./)
|
1065
|
-
@lex_state = :expr_beg
|
1066
|
-
return :tDOT3
|
1067
|
-
|
1068
|
-
elsif scan(/\.\./)
|
1069
|
-
@lex_state = :expr_beg
|
1070
|
-
return :tDOT2
|
1071
|
-
|
1072
|
-
elsif @lex_state != :expr_fname && scan(/\.JS\[/)
|
1073
|
-
@lex_state = :expr_beg
|
1074
|
-
cond_push 0
|
1075
|
-
cmdarg_push 0
|
1076
|
-
return :tJSLBRACK
|
1077
|
-
|
1078
|
-
elsif @lex_state != :expr_fname && scan(/\.JS\./)
|
1079
|
-
@lex_state = :expr_dot
|
1080
|
-
return :tJSDOT
|
1081
|
-
|
1082
|
-
elsif scan(/\./)
|
1083
|
-
@lex_state = :expr_dot unless @lex_state == :expr_fname
|
1084
|
-
return :tDOT
|
1085
|
-
|
1086
|
-
elsif scan(/\:\:/)
|
1087
|
-
if beg?
|
1088
|
-
@lex_state = :expr_beg
|
1089
|
-
return :tCOLON3
|
1090
|
-
elsif spcarg?
|
1091
|
-
@lex_state = :expr_beg
|
1092
|
-
return :tCOLON3
|
1093
|
-
end
|
1094
|
-
|
1095
|
-
@lex_state = :expr_dot
|
1096
|
-
return :tCOLON2
|
1097
|
-
|
1098
|
-
elsif scan(/\:/)
|
1099
|
-
if end? || check(/\s/)
|
1100
|
-
unless check(/\w/)
|
1101
|
-
@lex_state = :expr_beg
|
1102
|
-
return :tCOLON
|
1103
|
-
end
|
1104
|
-
|
1105
|
-
@lex_state = :expr_fname
|
1106
|
-
return :tSYMBEG
|
1107
|
-
end
|
1108
|
-
|
1109
|
-
if scan(/\'/)
|
1110
|
-
self.strterm = new_strterm(STR_SSYM, "'", "\0")
|
1111
|
-
elsif scan(/\"/)
|
1112
|
-
self.strterm = new_strterm(STR_DSYM, '"', "\0")
|
1113
|
-
end
|
1114
|
-
|
1115
|
-
@lex_state = :expr_fname
|
1116
|
-
return :tSYMBEG
|
1117
|
-
|
1118
|
-
elsif scan(/\^\=/)
|
1119
|
-
return new_op_asgn('^')
|
1120
|
-
|
1121
|
-
elsif scan(/\^/)
|
1122
|
-
self.set_arg_state
|
1123
|
-
return :tCARET
|
1124
|
-
|
1125
|
-
elsif check(/</)
|
1126
|
-
if scan(/<<\=/)
|
1127
|
-
return new_op_asgn('<<')
|
1128
|
-
|
1129
|
-
elsif scan(/<</)
|
1130
|
-
if after_operator?
|
1131
|
-
@lex_state = :expr_arg
|
1132
|
-
return :tLSHFT
|
1133
|
-
elsif !after_operator? && !end? && (!arg? || @space_seen) && @lex_state != :expr_class
|
1134
|
-
if token = heredoc_identifier
|
1135
|
-
return token
|
1136
|
-
end
|
1137
|
-
|
1138
|
-
@lex_state = :expr_beg
|
1139
|
-
return :tLSHFT
|
1140
|
-
end
|
1141
|
-
@lex_state = :expr_beg
|
1142
|
-
return :tLSHFT
|
1143
|
-
elsif scan(/<\=\>/)
|
1144
|
-
if after_operator?
|
1145
|
-
@lex_state = :expr_arg
|
1146
|
-
else
|
1147
|
-
if @lex_state == :expr_class
|
1148
|
-
cmd_start = true
|
1149
|
-
end
|
1150
|
-
|
1151
|
-
@lex_state = :expr_beg
|
1152
|
-
end
|
1153
|
-
|
1154
|
-
return :tCMP
|
1155
|
-
elsif scan(/<\=/)
|
1156
|
-
self.set_arg_state
|
1157
|
-
return :tLEQ
|
1158
|
-
|
1159
|
-
elsif scan(/</)
|
1160
|
-
self.set_arg_state
|
1161
|
-
return :tLT
|
1162
|
-
end
|
1163
|
-
|
1164
|
-
elsif check(/\>/)
|
1165
|
-
if scan(/\>\>\=/)
|
1166
|
-
return new_op_asgn('>>')
|
1167
|
-
|
1168
|
-
elsif scan(/\>\>/)
|
1169
|
-
self.set_arg_state
|
1170
|
-
return :tRSHFT
|
1171
|
-
|
1172
|
-
elsif scan(/\>\=/)
|
1173
|
-
self.set_arg_state
|
1174
|
-
return :tGEQ
|
1175
|
-
|
1176
|
-
elsif scan(/\>/)
|
1177
|
-
self.set_arg_state
|
1178
|
-
return :tGT
|
1179
|
-
end
|
1180
|
-
|
1181
|
-
elsif scan(/->/)
|
1182
|
-
@lex_state = :expr_end
|
1183
|
-
@lambda_stack.push(@paren_nest)
|
1184
|
-
return :tLAMBDA
|
1185
|
-
|
1186
|
-
elsif scan(/[+-]/)
|
1187
|
-
matched = scanner.matched
|
1188
|
-
sign, utype = if matched == '+'
|
1189
|
-
[:tPLUS, :tUPLUS]
|
1190
|
-
else
|
1191
|
-
[:tMINUS, :tUMINUS]
|
1192
|
-
end
|
1193
|
-
|
1194
|
-
if beg?
|
1195
|
-
@lex_state = :expr_mid
|
1196
|
-
self.yylval = matched
|
1197
|
-
if scanner.peek(1) =~ /\d/ and
|
1198
|
-
return utype == :tUMINUS ? '-@NUM' : '+@NUM'
|
1199
|
-
else
|
1200
|
-
return utype
|
1201
|
-
end
|
1202
|
-
elsif after_operator?
|
1203
|
-
@lex_state = :expr_arg
|
1204
|
-
if scan(/@/)
|
1205
|
-
self.yylval = matched + '@'
|
1206
|
-
return :tIDENTIFIER
|
1207
|
-
end
|
1208
|
-
|
1209
|
-
self.yylval = matched
|
1210
|
-
return sign
|
1211
|
-
end
|
1212
|
-
|
1213
|
-
if scan(/\=/)
|
1214
|
-
return new_op_asgn(matched)
|
1215
|
-
end
|
1216
|
-
|
1217
|
-
if spcarg?
|
1218
|
-
@lex_state = :expr_mid
|
1219
|
-
self.yylval = matched
|
1220
|
-
if scanner.peek(1) =~ /\d/ and
|
1221
|
-
return utype == :tUMINUS ? '-@NUM' : '+@NUM'
|
1222
|
-
else
|
1223
|
-
return utype
|
1224
|
-
end
|
1225
|
-
end
|
1226
|
-
|
1227
|
-
@lex_state = :expr_beg
|
1228
|
-
self.yylval = matched
|
1229
|
-
return sign
|
1230
|
-
|
1231
|
-
elsif scan(/\?/)
|
1232
|
-
if end?
|
1233
|
-
@lex_state = :expr_beg
|
1234
|
-
return :tEH
|
1235
|
-
end
|
1236
|
-
|
1237
|
-
if check(/\ |\t|\r|\s/)
|
1238
|
-
@lex_state = :expr_beg
|
1239
|
-
return :tEH
|
1240
|
-
elsif scan(/\\/)
|
1241
|
-
@lex_state = :expr_end
|
1242
|
-
self.yylval = self.read_escape
|
1243
|
-
return :tSTRING
|
1244
|
-
end
|
1245
|
-
|
1246
|
-
@lex_state = :expr_end
|
1247
|
-
self.yylval = scan(/./)
|
1248
|
-
return :tSTRING
|
1249
|
-
|
1250
|
-
elsif scan(/\~/)
|
1251
|
-
self.set_arg_state
|
1252
|
-
return :tTILDE
|
1253
|
-
|
1254
|
-
elsif check(/\$/)
|
1255
|
-
if scan(/\$([1-9]\d*)/)
|
1256
|
-
@lex_state = :expr_end
|
1257
|
-
self.yylval = scanner.matched.sub('$', '')
|
1258
|
-
return :tNTH_REF
|
1259
|
-
|
1260
|
-
elsif scan(/(\$_)(\w+)/)
|
1261
|
-
@lex_state = :expr_end
|
1262
|
-
return :tGVAR
|
1263
|
-
|
1264
|
-
elsif scan(/\$[\+\'\`\&!@\"~*$?\/\\:;=.,<>_]/)
|
1265
|
-
@lex_state = :expr_end
|
1266
|
-
return :tGVAR
|
1267
|
-
elsif scan(/\$\w+/)
|
1268
|
-
@lex_state = :expr_end
|
1269
|
-
return :tGVAR
|
1270
|
-
elsif scan(/\$-[0-9a-zA-Z]/)
|
1271
|
-
@lex_state = :expr_end
|
1272
|
-
return :tGVAR
|
1273
|
-
else
|
1274
|
-
raise "Bad gvar name: #{scanner.peek(5).inspect}"
|
1275
|
-
end
|
1276
|
-
|
1277
|
-
elsif scan(/\$\w+/)
|
1278
|
-
@lex_state = :expr_end
|
1279
|
-
return :tGVAR
|
1280
|
-
|
1281
|
-
elsif scan(/\@\@\w*/)
|
1282
|
-
@lex_state = :expr_end
|
1283
|
-
return :tCVAR
|
1284
|
-
|
1285
|
-
elsif scan(/\@\w*/)
|
1286
|
-
@lex_state = :expr_end
|
1287
|
-
return :tIVAR
|
1288
|
-
|
1289
|
-
elsif scan(/\,/)
|
1290
|
-
@lex_state = :expr_beg
|
1291
|
-
return :tCOMMA
|
1292
|
-
|
1293
|
-
elsif scan(/\{/)
|
1294
|
-
if @lambda_stack.last == @paren_nest
|
1295
|
-
@lambda_stack.pop
|
1296
|
-
@lex_state = :expr_beg
|
1297
|
-
cond_push 0
|
1298
|
-
cmdarg_push 0
|
1299
|
-
return :tLAMBEG
|
1300
|
-
|
1301
|
-
elsif arg? or @lex_state == :expr_end
|
1302
|
-
if @lparen_arg_seen
|
1303
|
-
@lparen_arg_seen = false
|
1304
|
-
result = :tLBRACE_ARG
|
1305
|
-
else
|
1306
|
-
result = :tLCURLY
|
1307
|
-
end
|
1308
|
-
elsif @lex_state == :expr_endarg
|
1309
|
-
result = :tLBRACE_ARG
|
1310
|
-
else
|
1311
|
-
result = :tLBRACE
|
1312
|
-
end
|
1313
|
-
|
1314
|
-
@lex_state = :expr_beg
|
1315
|
-
cond_push 0
|
1316
|
-
cmdarg_push 0
|
1317
|
-
return result
|
1318
|
-
|
1319
|
-
elsif scanner.bol? and skip(/\__END__(\n|$)/)
|
1320
|
-
while true
|
1321
|
-
if scanner.eos?
|
1322
|
-
@eof_content = self.yylval
|
1323
|
-
return false
|
1324
|
-
end
|
1325
|
-
|
1326
|
-
scan(/(.*)/)
|
1327
|
-
scan(/\n/)
|
1328
|
-
end
|
1329
|
-
|
1330
|
-
elsif check(/[0-9]/)
|
1331
|
-
return process_numeric
|
1332
|
-
|
1333
|
-
elsif scan(INLINE_IDENTIFIER_REGEXP)
|
1334
|
-
return process_identifier scanner.matched, cmd_start
|
1335
|
-
end
|
1336
|
-
|
1337
|
-
if scanner.eos?
|
1338
|
-
if @scanner_stack.size == 1 # our main scanner, we cant pop this
|
1339
|
-
self.yylval = false
|
1340
|
-
return false
|
1341
|
-
else # we were probably parsing a heredoc, so pop that parser and continue
|
1342
|
-
@scanner_stack.pop
|
1343
|
-
@scanner = @scanner_stack.last
|
1344
|
-
return yylex
|
1345
|
-
end
|
1346
|
-
end
|
1347
|
-
|
1348
|
-
raise "Unexpected content in parsing stream `#{scanner.peek 5}` :#{@file}:#{@line}"
|
1349
|
-
end
|
1350
|
-
end
|
1351
|
-
end
|
1352
|
-
end
|