Examples of DynamicScope


Examples of org.jruby.runtime.DynamicScope

    private IRubyObject scanIter(ThreadContext context, Regex pattern, Matcher matcher, Encoding enc, Block block, int begin, int range, int tuFlags) {
        Ruby runtime = context.getRuntime();
        byte[]bytes = value.getUnsafeBytes();
        int size = value.getRealSize();
        RubyMatchData match = null;
        DynamicScope scope = context.getCurrentScope();

        int end = 0;
        if (pattern.numberOfCaptures() == 0) {
            while (matcher.search(begin + end, range, Option.NONE) >= 0) {
                end = positionEnd(matcher, enc, begin, range);
                match = RubyRegexp.updateBackRef(context, this, scope, matcher, pattern);
                RubyString substr = makeShared(runtime, matcher.getBegin(), matcher.getEnd() - matcher.getBegin());
                substr.infectBy(tuFlags);
                match.infectBy(tuFlags);
                block.yield(context, substr);
                modifyCheck(bytes, size);
            }
        } else {
            while (matcher.search(begin + end, range, Option.NONE) >= 0) {
                end = positionEnd(matcher, enc, begin, range);
                match = RubyRegexp.updateBackRef(context, this, scope, matcher, pattern);
                match.infectBy(tuFlags);
                block.yield(context, populateCapturesForScan(runtime, matcher, range, tuFlags, false));
                modifyCheck(bytes, size);
            }
        }
        scope.setBackRef(match == null ? runtime.getNil() : match);
        return this;
    }
View Full Code Here

Examples of org.jruby.runtime.DynamicScope

                end = positionEnd(matcher, enc, begin, range);
                ary.append(populateCapturesForScan(runtime, matcher, range, tuFlags, false));
            }
        }

        DynamicScope scope = context.getCurrentScope();
        if (ary.size() > 0) {
            RubyMatchData match = RubyRegexp.updateBackRef(context, this, scope, matcher, pattern);
            match.infectBy(tuFlags);
        } else {
            scope.setBackRef(runtime.getNil());
        }
        return ary;
    }
View Full Code Here

Examples of org.jruby.runtime.DynamicScope

        int begin = value.getBegin();
        int len = value.getRealSize();
        int range = begin + len;
        final Matcher matcher = prepared.matcher(bytes, begin, range);

        DynamicScope scope = context.getCurrentScope();

        int end = 0;
        RubyMatchData match = null;
        if (pattern.numberOfCaptures() == 0) {
            while (matcher.search(begin + end, range, Option.NONE) >= 0) {
                end = positionEnd(matcher, enc, begin, range);
                match = RubyRegexp.updateBackRef19(context, this, scope, matcher, pattern);
                match.regexp = regexp;
                RubyString substr = makeShared19(runtime, matcher.getBegin(), matcher.getEnd() - matcher.getBegin());
                substr.infectBy(tuFlags);
                match.infectBy(tuFlags);
                block.yield(context, substr);
                modifyCheck(bytes, len, enc);
            }
        } else {
            while (matcher.search(begin + end, range, Option.NONE) >= 0) {
                end = positionEnd(matcher, enc, begin, range);
                match = RubyRegexp.updateBackRef19(context, this, scope, matcher, pattern);
                match.regexp = regexp;
                match.infectBy(tuFlags);
                block.yield(context, populateCapturesForScan(runtime, matcher, range, tuFlags, true));
                modifyCheck(bytes, len, enc);
            }
        }
        scope.setBackRef(match == null ? runtime.getNil() : match);
        return this;
    }
View Full Code Here

Examples of org.jruby.runtime.DynamicScope

                end = positionEnd(matcher, enc, begin, range);
                ary.append(populateCapturesForScan(runtime, matcher, range, tuFlags, true));
            }
        }

        DynamicScope scope = context.getCurrentScope();
        if (ary.size() > 0) {
            RubyMatchData match = RubyRegexp.updateBackRef19(context, this, scope, matcher, pattern);
            match.regexp = regexp;
            match.infectBy(tuFlags);
        } else {
            scope.setBackRef(runtime.getNil());
        }
        return ary;
    }
View Full Code Here

Examples of org.jruby.runtime.DynamicScope

     *
     */
    @JRubyMethod(name = "to_c", reads = BACKREF, writes = BACKREF, compat = RUBY1_9)
    public IRubyObject to_c(ThreadContext context) {
        Ruby runtime = context.getRuntime();
        DynamicScope scope = context.getCurrentScope();
        IRubyObject backref = scope.getBackRef(runtime);
        if (backref instanceof RubyMatchData) ((RubyMatchData)backref).use();

        IRubyObject s = RuntimeHelpers.invoke(
                context, this, "gsub",
                RubyRegexp.newDummyRegexp(runtime, Numeric.ComplexPatterns.underscores_pat),
                runtime.newString(new ByteList(new byte[]{'_'})));

        RubyArray a = RubyComplex.str_to_c_internal(context, s);

        scope.setBackRef(backref);

        if (!a.eltInternal(0).isNil()) {
            return a.eltInternal(0);
        } else {
            return RubyComplex.newComplexCanonicalize(context, RubyFixnum.zero(runtime));
View Full Code Here

Examples of org.jruby.runtime.DynamicScope

     *
     */
    @JRubyMethod(name = "to_r", reads = BACKREF, writes = BACKREF, compat = RUBY1_9)
    public IRubyObject to_r(ThreadContext context) {
        Ruby runtime = context.getRuntime();
        DynamicScope scope = context.getCurrentScope();
        IRubyObject backref = scope.getBackRef(runtime);
        if (backref instanceof RubyMatchData) ((RubyMatchData)backref).use();

        IRubyObject s = RuntimeHelpers.invoke(
                context, this, "gsub",
                RubyRegexp.newDummyRegexp(runtime, Numeric.ComplexPatterns.underscores_pat),
                runtime.newString(new ByteList(new byte[]{'_'})));

        RubyArray a = RubyRational.str_to_r_internal(context, s);

        scope.setBackRef(backref);

        if (!a.eltInternal(0).isNil()) {
            return a.eltInternal(0);
        } else {
            return RubyRational.newRationalCanonicalize(context, RubyFixnum.zero(runtime));
View Full Code Here

Examples of org.jruby.runtime.DynamicScope

    private IRubyObject subBangIter(ThreadContext context, Regex pattern, Block block) {
        int range = value.getBegin() + value.getRealSize();
        Matcher matcher = pattern.matcher(value.getUnsafeBytes(), value.getBegin(), range);

        DynamicScope scope = context.getCurrentScope();
        if (matcher.search(value.getBegin(), range, Option.NONE) >= 0) {
            frozenCheck(true);
            byte[] bytes = value.getUnsafeBytes();
            int size = value.getRealSize();
            RubyMatchData match = RubyRegexp.updateBackRef(context, this, scope, matcher, pattern);
            RubyString repl = objAsString(context, block.yield(context,
                    makeShared(context.getRuntime(), matcher.getBegin(), matcher.getEnd() - matcher.getBegin())));
            modifyCheck(bytes, size);
            frozenCheck(true);
            scope.setBackRef(match);
            return subBangCommon(context, pattern, matcher, repl, repl.flags);
        } else {
            return scope.setBackRef(context.getRuntime().getNil());
        }
    }
View Full Code Here

Examples of org.jruby.runtime.DynamicScope

    private IRubyObject subBangNoIter(ThreadContext context, Regex pattern, RubyString repl) {
        int tuFlags = repl.flags;
        int range = value.getBegin() + value.getRealSize();
        Matcher matcher = pattern.matcher(value.getUnsafeBytes(), value.getBegin(), range);

        DynamicScope scope = context.getCurrentScope();
        if (matcher.search(value.getBegin(), range, Option.NONE) >= 0) {
            repl = RubyRegexp.regsub(repl, this, matcher, context.getRuntime().getKCode().getEncoding());
            RubyRegexp.updateBackRef(context, this, scope, matcher, pattern);
            return subBangCommon(context, pattern, matcher, repl, tuFlags);
        } else {
            return scope.setBackRef(context.getRuntime().getNil());
        }
    }
View Full Code Here

Examples of org.jruby.runtime.DynamicScope

        int range = begin + len;
        byte[]bytes = value.getUnsafeBytes();
        Encoding enc = value.getEncoding();
        final Matcher matcher = prepared.matcher(bytes, begin, range);

        DynamicScope scope = context.getCurrentScope();
        if (matcher.search(begin, range, Option.NONE) >= 0) {
            RubyMatchData match = RubyRegexp.updateBackRef19(context, this, scope, matcher, pattern);
            match.regexp = regexp;
            final RubyString repl;
            final int tuFlags;
            IRubyObject subStr = makeShared19(runtime, matcher.getBegin(), matcher.getEnd() - matcher.getBegin());
            if (hash == null) {
                tuFlags = 0;
                repl = objAsString(context, block.yield(context, subStr));
            } else {
                tuFlags = hash.flags;
                repl = objAsString(context, hash.op_aref(context, subStr));
            }

            modifyCheck(bytes, len, enc);
            frozenCheck();
            scope.setBackRef(match);
            return subBangCommon19(context, pattern, matcher, repl, tuFlags | repl.flags);
        } else {
            return scope.setBackRef(runtime.getNil());
        }
    }
View Full Code Here

Examples of org.jruby.runtime.DynamicScope

     * @param binding The binding object under which to perform the evaluation
     * @return An IRubyObject result from the evaluation
     */
    public static IRubyObject evalWithBinding(ThreadContext context, IRubyObject self, IRubyObject src, Binding binding) {
        Ruby runtime = src.getRuntime();
        DynamicScope evalScope = binding.getDynamicScope().getEvalScope();
       
        // FIXME:  This determine module is in a strange location and should somehow be in block
        evalScope.getStaticScope().determineModule();

        Frame lastFrame = context.preEvalWithBinding(binding);
        try {
            // Binding provided for scope, use it
            RubyString source = src.convertToString();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.