org.jruby.Ruby.parse()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(3.8k)|赞(0)|评价(0)|浏览(116)

本文整理了Java中org.jruby.Ruby.parse方法的一些代码示例,展示了Ruby.parse的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Ruby.parse方法的具体详情如下:
包路径:org.jruby.Ruby
类名称:Ruby
方法名:parse

Ruby.parse介绍

[英]Parse the script contained in the given input stream, using the given filename as the name of the script, and return the root Node. This is used to verify that the script syntax is valid, for jruby -c. The current scope (generally the top-level scope) is used as the parent scope for parsing.
[中]使用给定的文件名作为脚本名,解析给定输入流中包含的脚本,并返回根节点。这用于验证jruby-c的脚本语法是否有效。当前作用域(通常是顶级作用域)用作解析的父作用域。

代码示例

代码示例来源:origin: org.jruby/jruby-complete

public static Node buildAST(boolean isCommandLineScript, String arg) {
  Ruby ruby = Ruby.getGlobalRuntime();
  // inline script
  if (isCommandLineScript) return ruby.parse(ByteList.create(arg), "-e", null, 0, false);
  // from file
  FileInputStream fis = null;
  try {
    File file = new File(arg);
    fis = new FileInputStream(file);
    long size = file.length();
    byte[] bytes = new byte[(int)size];
    fis.read(bytes);
    System.out.println("-- processing " + arg + " --");
    return ruby.parse(new ByteList(bytes), arg, null, 0, false);
  } catch (IOException ioe) {
    throw new RuntimeException(ioe);
  } finally {
    try { if (fis != null) fis.close(); } catch(Exception ignored) { }
  }
}

代码示例来源:origin: org.jruby/jruby-complete

parseResult = context.runtime.parse(bytes, filename, scope, lineno, extra_position_info);

代码示例来源:origin: org.jruby/jruby-core

parseResult = context.runtime.parse(bytes, filename, scope, lineno, extra_position_info);

代码示例来源:origin: org.jruby/jruby-core

public static Node buildAST(boolean isCommandLineScript, String arg) {
  Ruby ruby = Ruby.getGlobalRuntime();
  // inline script
  if (isCommandLineScript) return ruby.parse(ByteList.create(arg), "-e", null, 0, false);
  // from file
  FileInputStream fis = null;
  try {
    File file = new File(arg);
    fis = new FileInputStream(file);
    long size = file.length();
    byte[] bytes = new byte[(int)size];
    fis.read(bytes);
    System.out.println("-- processing " + arg + " --");
    return ruby.parse(new ByteList(bytes), arg, null, 0, false);
  } catch (IOException ioe) {
    throw new RuntimeException(ioe);
  } finally {
    try { if (fis != null) fis.close(); } catch(Exception ignored) { }
  }
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

public static Node buildAST(boolean isCommandLineScript, String arg) {
  Ruby ruby = Ruby.getGlobalRuntime();
  // set to IR mode, since we use different scopes, etc for IR
  ruby.getInstanceConfig().setCompileMode(CompileMode.OFFIR);
  // inline script
  if (isCommandLineScript) return ruby.parse(ByteList.create(arg), "-e", null, 0, false);
  // from file
  FileInputStream fis = null;
  try {
    File file = new File(arg);
    fis = new FileInputStream(file);
    long size = file.length();
    byte[] bytes = new byte[(int)size];
    fis.read(bytes);
    System.out.println("-- processing " + arg + " --");
    return ruby.parse(new ByteList(bytes), arg, null, 0, false);
  } catch (IOException ioe) {
    throw new RuntimeException(ioe);
  } finally {
    try { if (fis != null) fis.close(); } catch(Exception e) { }
  }
}

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

public static Node buildAST(boolean isCommandLineScript, String arg) {
  Ruby ruby = Ruby.getGlobalRuntime();
  // set to IR mode, since we use different scopes, etc for IR
  ruby.getInstanceConfig().setCompileMode(CompileMode.OFFIR);
  // inline script
  if (isCommandLineScript) return ruby.parse(ByteList.create(arg), "-e", null, 0, false);
  // from file
  FileInputStream fis = null;
  try {
    File file = new File(arg);
    fis = new FileInputStream(file);
    long size = file.length();
    byte[] bytes = new byte[(int)size];
    fis.read(bytes);
    System.out.println("-- processing " + arg + " --");
    return ruby.parse(new ByteList(bytes), arg, null, 0, false);
  } catch (IOException ioe) {
    throw new RuntimeException(ioe);
  } finally {
    try { if (fis != null) fis.close(); } catch(Exception e) { }
  }
}

代码示例来源:origin: org.hibnet/webpipes-sass-ruby

Node node = runtime.parse(ByteList.create(script), webpipe.getPath(), runtime.getCurrentContext().getCurrentScope(), 0, false);
IRubyObject result = runtime.runNormally(node);
return new WebpipeOutput(result.toString());

相关文章

微信公众号

最新文章

更多

Ruby类方法