Package org.jruby.runtime

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


                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

        // FIXME: Ideally we would not need to call backref-sensitive methods here
        context.pushScope(DynamicScope.newDynamicScope(INTERNAL_STATIC_SCOPE));

        try {
            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

        // FIXME: Ideally we would not need to call backref-sensitive methods here
        context.pushScope(DynamicScope.newDynamicScope(INTERNAL_STATIC_SCOPE));

        try {
            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

        if (wrap) {
            staticScope.setModule(RubyModule.newModule(context.runtime));
        } else {
            staticScope.setModule(objectClass);
        }
        DynamicScope scope = DynamicScope.newDynamicScope(staticScope);

        // Each root node has a top-level scope that we need to push
        context.preScopedBody(scope);
        context.preNodeEval(objectClass, topLevel);
    }
View Full Code Here

        }
        return scopeOffsets;
    }

    public static IRubyObject match2AndUpdateScope(IRubyObject receiver, ThreadContext context, IRubyObject value, String scopeOffsets) {
        DynamicScope scope = context.getCurrentScope();
        IRubyObject match = ((RubyRegexp)receiver).op_match(context, value);
        updateScopeWithCaptures(context, scope, decodeCaptureOffsets(scopeOffsets), match);
        return match;
    }
View Full Code Here

        updateScopeWithCaptures(context, scope, decodeCaptureOffsets(scopeOffsets), match);
        return match;
    }

    public static IRubyObject match2AndUpdateScope19(IRubyObject receiver, ThreadContext context, IRubyObject value, String scopeOffsets) {
        DynamicScope scope = context.getCurrentScope();
        IRubyObject match = ((RubyRegexp)receiver).op_match19(context, value);
        updateScopeWithCaptures(context, scope, decodeCaptureOffsets(scopeOffsets), match);
        return match;
    }
View Full Code Here

            String[] names = new String[paramNames.size()];
            paramNames.toArray(names);
            context.preBsfApply(names);

            // Populate values for the parameter names
            DynamicScope scope = context.getCurrentScope();
            for (int i = 0, size = args.size(); i < size; i++) {
                scope.setValue(i, JavaEmbedUtils.javaToRuby(runtime, args.get(i)), 0);
            }

            return JavaEmbedUtils.rubyToJava(evaler.parse(runtime, funcBody.toString(), file, line).run());
        } catch (StackOverflowError soe) {
            throw context.runtime.newSystemStackError("stack level too deep", soe);
View Full Code Here

     * @param script The scriptlet to run
     * @returns The result of the eval
     */
    public IRubyObject evalScriptlet(String script) {
        ThreadContext context = getCurrentContext();
        DynamicScope currentScope = context.getCurrentScope();
        ManyVarsDynamicScope newScope = new ManyVarsDynamicScope(getStaticScopeFactory().newEvalScope(currentScope.getStaticScope()), currentScope);

        return evalScriptlet(script, newScope);
    }
View Full Code Here

            String[] names = new String[paramNames.size()];
            paramNames.toArray(names);
            context.preBsfApply(names);

            // Populate values for the parameter names
            DynamicScope scope = context.getCurrentScope();
            for (int i = 0, size = args.size(); i < size; i++) {
                scope.setValue(i, JavaEmbedUtils.javaToRuby(runtime, args.get(i)), 0);
            }

            return JavaEmbedUtils.rubyToJava(evaler.parse(runtime, funcBody.toString(), file, line).run());
        } catch (StackOverflowError soe) {
            throw context.runtime.newSystemStackError("stack level too deep", soe);
View Full Code Here

TOP

Related Classes of org.jruby.runtime.DynamicScope

Copyright © 2018 www.massapicom. 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.