use of org.graalvm.polyglot.Language in project graal by oracle.
the class Launcher method printLanguages.
private static void printLanguages(Engine engine, boolean printWhenEmpty) {
if (engine.getLanguages().isEmpty()) {
if (printWhenEmpty) {
System.out.println(" Installed Languages: none");
}
} else {
System.out.println(" Installed Languages:");
List<Language> languages = new ArrayList<>(engine.getLanguages().size());
int nameLength = 0;
for (Language language : engine.getLanguages().values()) {
languages.add(language);
nameLength = max(nameLength, language.getName().length());
}
languages.sort(Comparator.comparing(Language::getId));
String langFormat = " %-" + nameLength + "s%s version %s%n";
for (Language language : languages) {
String host;
host = "";
String version = language.getVersion();
if (version == null || version.length() == 0) {
version = "";
}
System.out.printf(langFormat, language.getName().isEmpty() ? "Unnamed" : language.getName(), host, version);
}
}
}
use of org.graalvm.polyglot.Language in project graal by oracle.
the class PolyglotLauncher method printHelp.
@Override
protected void printHelp(OptionCategory maxCategory) {
Engine engine = Engine.create();
// @formatter:off
printVersion(engine);
System.out.println();
System.out.println("Usage: polyglot [OPTION]... [FILE] [ARGS]...");
List<Language> languages = sortedLanguages(engine);
System.out.print("Available languages: ");
String sep = "";
for (Language language : languages) {
System.out.print(sep);
System.out.print(language.getId());
sep = ", ";
}
System.out.println();
System.out.println("Basic Options:");
printOption("--language <lang>", "Specifies the main language.");
printOption("--file [<lang>:]FILE", "Additional file to execute.");
printOption("--eval [<lang>:]CODE", "Evaluates code snippets, for example, '--eval js:42'.");
printOption("--shell", "Start a multi language shell.");
// @formatter:on
}
use of org.graalvm.polyglot.Language in project graal by oracle.
the class EvalLauncher method printHelp.
private static void printHelp(OptionCategory maxCategory) {
Engine engine = Engine.create();
System.out.println(BASIC_HELP);
System.out.println("Engine options: ");
for (OptionDescriptor descriptor : engine.getOptions()) {
printOption(maxCategory, descriptor);
}
System.out.println("Language options: ");
for (String languageId : engine.getLanguages().keySet()) {
Language language = engine.getLanguage(languageId);
for (OptionDescriptor descriptor : language.getOptions()) {
printOption(maxCategory, descriptor);
}
}
System.out.println("Tool options: ");
for (String instrumentId : engine.getInstruments().keySet()) {
Instrument instrument = engine.getInstrument(instrumentId);
for (OptionDescriptor descriptor : instrument.getOptions()) {
printOption(maxCategory, descriptor);
}
}
}
use of org.graalvm.polyglot.Language in project graal by oracle.
the class AbstractLanguageLauncher method printVersion.
protected void printVersion(Engine engine) {
String languageId = getLanguageId();
Language language = engine.getLanguages().get(languageId);
if (language == null) {
throw abort(String.format("Unknown language: '%s'!", languageId));
}
String implementationName = language.getImplementationName();
if (implementationName == null || implementationName.length() == 0) {
String languageName = language.getName();
if (languageName == null || languageName.length() == 0) {
languageName = languageId;
}
implementationName = "Graal " + languageName;
}
System.out.println(String.format("%s %s (GraalVM %s)", implementationName, language.getVersion(), engine.getVersion()));
}
use of org.graalvm.polyglot.Language in project graal by oracle.
the class PolyglotEngineImpl method requirePublicLanguage.
@Override
public Language requirePublicLanguage(String id) {
checkState();
Language language = idToPublicLanguage.get(id);
if (language == null) {
String misspelledGuess = matchSpellingError(idToPublicLanguage.keySet(), id);
String didYouMean = "";
if (misspelledGuess != null) {
didYouMean = String.format("Did you mean '%s'? ", misspelledGuess);
}
throw new PolyglotIllegalStateException(String.format("A language with id '%s' is not installed. %sInstalled languages are: %s.", id, didYouMean, getLanguages().keySet()));
}
return language;
}
Aggregations