ParsingAndRunManager.java

  1. package org.jruby;

  2. import java.io.IOException;
  3. import java.io.InputStream;

  4. import org.jruby.ast.Node;
  5. import org.jruby.runtime.ThreadContext;

  6. public class ParsingAndRunManager {
  7.    
  8.     public void dealWithRunFromMain(Ruby runtime, InputStream inputStream, String filename) {
  9.         Node scriptNode = runtime.parseFromMain(inputStream, filename);

  10.         // done with the stream, shut it down
  11.         try {inputStream.close();} catch (IOException ioe) {}

  12.         ThreadContext context = runtime.getCurrentContext();

  13.         String oldFile = context.getFile();
  14.         int oldLine = context.getLine();
  15.         try {
  16.             if(scriptNode != null) context.setFileAndLine(scriptNode.getPosition());
  17.            
  18.             RubyInstanceConfig config = runtime.getInstanceConfig();
  19.             if (config.isAssumePrinting() || config.isAssumeLoop()) {
  20.                 runtime.runWithGetsLoop(scriptNode, config.isAssumePrinting(), config.isProcessLineEnds(),
  21.                         config.isSplit());
  22.             } else {
  23.                 runtime.runNormally(scriptNode);
  24.             }
  25.         } finally {
  26.             context.setFileAndLine(oldFile, oldLine);
  27.         }
  28.     }

  29. }