
org.jruby.prism.parser.LoaderPrism Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jruby-prism Show documentation
Show all versions of jruby-prism Show documentation
Java portion of JRuby Prism parser support.
The newest version!
package org.jruby.prism.parser;
import org.jcodings.Encoding;
import org.jruby.Ruby;
import org.jruby.util.ByteList;
import org.prism.Loader;
import org.prism.Nodes;
import org.prism.ParseResult;
public class LoaderPrism extends Loader {
private Ruby runtime;
private Encoding encoding = null;
LoaderPrism(Ruby runtime, byte[] serialized, byte[] source) {
super(serialized, source);
this.runtime = runtime;
}
public ParseResult load() {
ParseResult result = super.load();
resolveEncoding();
return result;
}
public org.jruby.RubySymbol bytesToName(byte[] bytes) {
resolveEncoding();
return runtime.newSymbol(new ByteList(bytes, encoding));
}
private void resolveEncoding() {
if (encoding == null) {
encoding = runtime.getEncodingService().findEncodingOrAliasEntry(encodingName.getBytes()).getEncoding();
}
}
public Encoding getEncoding() {
return encoding;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy