public class ClojureAdapter extends LanguageAdapterBase
LanguageAdapter
that supports the Clojure language.
Note: Clojure adapters in all LanguageManager
will share the same
runtime instance of Clojure, which is a JVM-wide singleton.
This is important! Even though every execution context gets its own Clojure namespace, all namespaces exist in the same runtime. If one execution context loads code into a namespace, all execution contexts will be able to access it. This means that two contexts cannot use different versions of a library at the same time if the versions have the same namespace.
Note that Program.prepare()
does not actually compile the source
code, but it does parse it, making it quicker to execute later.
Modifier and Type | Field and Description |
---|---|
protected static clojure.lang.Var |
ALLOW_UNRESOLVED_VARS
clojure.core/*allow-unresolved-vars*
|
protected static clojure.lang.Symbol |
CLOJURE_CORE
clojure.core
|
static String |
CLOJURE_NAMESPACE
Namespace attribute.
|
protected static clojure.lang.Var |
IN_NS
(in-ns)
|
static String |
NAMESPACE_PREFIX
Prefix prepended to all namespace names created by this adapter.
|
protected static clojure.lang.Var |
REFER
(clojure.core/refer)
|
DEFAULT_EXTENSION, DEFAULT_TAG, EXTENSIONS, LANGUAGE_NAME, LANGUAGE_VERSION, NAME, TAGS, VERSION
Constructor and Description |
---|
ClojureAdapter()
Constructor.
|
Modifier and Type | Method and Description |
---|---|
static ExecutionException |
createExecutionException(int startLineNumber,
clojure.lang.Compiler.CompilerException x)
Creates an execution exception with a full stack.
|
Program |
createProgram(String sourceCode,
boolean isScriptlet,
int position,
int startLineNumber,
int startColumnNumber,
Executable executable)
Turns source code into a program.
|
Object |
enter(String entryPointName,
Executable executable,
ExecutionContext executionContext,
Object... arguments)
Enters the executable at a stored, named location.
|
static String |
extractExceptionStackFromMessage(String message,
Collection<StackFrame> stack)
Annoyingly, Clojure's CompilerException accepts stack information
(Compiler.SOURCE, Compiler.LINE) in its constructor, but does not store
it directly.
|
static clojure.lang.Namespace |
getClojureNamespace(ExecutionContext executionContext)
Gets a Clojure namespace stored in the execution context, creating it if
it doesn't exist.
|
String |
getSourceCodeForExpressionInclude(String expression,
Executable executable)
Creates source code for including the output of a text-with-scriptlets
document.
|
String |
getSourceCodeForExpressionOutput(String expression,
Executable executable)
Creates source code for outputting a source code expression to standard
output.
|
String |
getSourceCodeForLiteralOutput(String literal,
Executable executable)
Creates source code for outputting literal text to standard output.
|
void |
releaseContext(ExecutionContext executionContext)
Cleans up any resources used for an execution context.
|
static String |
toClojureStyle(String camelCase)
From somethingLikeThis to something-like-this.
|
getAttributes, getLock, getManager, isEphemeral, isThreadSafe, setManager
public static final String CLOJURE_NAMESPACE
public static final String NAMESPACE_PREFIX
protected static final clojure.lang.Symbol CLOJURE_CORE
protected static final clojure.lang.Var IN_NS
protected static final clojure.lang.Var ALLOW_UNRESOLVED_VARS
protected static final clojure.lang.Var REFER
public ClojureAdapter() throws LanguageAdapterException
LanguageAdapterException
- In case of an initialization errorpublic static ExecutionException createExecutionException(int startLineNumber, clojure.lang.Compiler.CompilerException x)
startLineNumber
- The line number in the document for where the program's source
code beginsx
- The Clojure compiler exceptionpublic static String extractExceptionStackFromMessage(String message, Collection<StackFrame> stack)
message
- The exception messagestack
- The stackpublic static clojure.lang.Namespace getClojureNamespace(ExecutionContext executionContext)
executionContext
- The execution contextpublic static String toClojureStyle(String camelCase)
camelCase
- somethingLikeThispublic String getSourceCodeForLiteralOutput(String literal, Executable executable) throws ParsingException
LanguageAdapter
getSourceCodeForLiteralOutput
in interface LanguageAdapter
getSourceCodeForLiteralOutput
in class LanguageAdapterBase
literal
- The literal textexecutable
- The executableParsingException
- In case of a parsing errorpublic String getSourceCodeForExpressionOutput(String expression, Executable executable) throws ParsingException
LanguageAdapter
getSourceCodeForExpressionOutput
in interface LanguageAdapter
getSourceCodeForExpressionOutput
in class LanguageAdapterBase
expression
- The source code expressionexecutable
- The executableParsingException
- In case of a parsing errorpublic String getSourceCodeForExpressionInclude(String expression, Executable executable) throws ParsingException
LanguageAdapter
For this to work, the executable must have been created with a container
that supports an inclusion command named according to the language
manager attribute
LanguageManager.CONTAINER_INCLUDE_COMMAND_ATTRIBUTE
.
getSourceCodeForExpressionInclude
in interface LanguageAdapter
getSourceCodeForExpressionInclude
in class LanguageAdapterBase
expression
- The source code expressionexecutable
- The executableParsingException
- In case of a parsing errorLanguageManager.getAttributes()
public Program createProgram(String sourceCode, boolean isScriptlet, int position, int startLineNumber, int startColumnNumber, Executable executable) throws ParsingException
LanguageAdapter
Program.prepare()
on the program.sourceCode
- The source codeisScriptlet
- Whether the source code is a scriptletposition
- The program's position in the executablestartLineNumber
- The line number in the document for where the program's source
code beginsstartColumnNumber
- The column number in the document for where the program's source
code beginsexecutable
- The executableParsingException
- In case of a parsing errorpublic Object enter(String entryPointName, Executable executable, ExecutionContext executionContext, Object... arguments) throws NoSuchMethodException, ParsingException, ExecutionException
LanguageAdapter
enter
in interface LanguageAdapter
enter
in class LanguageAdapterBase
entryPointName
- The entry point nameexecutable
- The executableexecutionContext
- The executable contextarguments
- Optional state to pass to the entry pointNoSuchMethodException
- In case the entry point does not existParsingException
- In case of a parsing errorExecutionException
- In case of an execution errorpublic void releaseContext(ExecutionContext executionContext)
LanguageAdapter
releaseContext
in interface LanguageAdapter
releaseContext
in class LanguageAdapterBase
executionContext
- The execution contextExecutionContext.getAttributes()
Copyright © 2009-2015 Three Crickets LLC.