Package gw.internal.gosu.template
Class TemplateGenerator
java.lang.Object
gw.internal.gosu.template.TemplateGenerator
- All Implemented Interfaces:
ITemplateGenerator
A template generator employing Gosu.
Works much like JSP -- uses <% script %> for scriptlets and <%= expr %> for expressions.
Also supports JSP comments like this: <%-- comment here --%>
Templates can be any type e.g., XML, HTML, text, whatever.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classprivate class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanprivate ISymbolTableprivate ContextInferenceManagerprivate booleanprivate Stringprivate booleanprivate Programprivate Stringprivate ITypeprivate booleanstatic final Stringstatic final intstatic final Stringstatic final intstatic final Stringstatic final intstatic final Stringstatic final intstatic final charstatic final charstatic final charstatic final charstatic final charstatic final charprivate static ThreadLocal<Stack<TemplateGenerator.RuntimeData>>static final Stringstatic final Stringstatic final LockingLazyVar<ISymbol>static final LockingLazyVar<ISymbol>static final Stringstatic final intstatic final Stringstatic final intstatic final intstatic final StringFields inherited from interface gw.lang.parser.template.ITemplateGenerator
PRINT_COMPRESSED_METHOD, PRINT_METHOD, PRINT_RANGE_METHOD -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateTemplateGenerator(Reader reader) WARNING: This will consume the reader and close it! -
Method Summary
Modifier and TypeMethodDescriptionprivate voidaddExpression(StringBuilder strTarget, String strExpression, int iLineNumber) private voidaddRefText(StringBuilder sbTarget, int iStart, int iEnd) private voidaddScriptlet(StringBuilder strTarget, String strScript, int iLineNumber) private voidaddStaticSymbols(ISymbolTable symbolTable, GosuParser parser, IGosuClassInternal supertype) private voidaddText(StringBuilder strTarget, String strText) voidcompile(ISymbolTable symTable) voidcompile(Stack<IScriptPartId> scriptPartIdStack, ISymbolTable symTable, Map<String, List<IFunctionSymbol>> dfsDeclByName, ITypeUsesMap typeUsesMap, Stack<BlockExpression> blocks, ContextInferenceManager ctxInferenceMgr) private Programcompile(Stack<IScriptPartId> scriptPartIdStack, String strCompiledSource, ISymbolTable symbolTable, Map<String, List<IFunctionSymbol>> dfsDeclByName, ITypeUsesMap typeUsesMap, Stack<BlockExpression> blocks, ContextInferenceManager ctxInferenceMgr) private voidprivate StringescapeForGosuStringLiteral(String strText) voidexecute(Writer writer, ISymbolTable symbolTable) voidexecute(Writer writer, StringEscaper escaper, ISymbolTable symTable) private IExternalSymbolMapextractExternalSymbols(ISymbolTable compileTimeSymbolTable, ISymbolTable runtimeSymbolTable) static voidgenerateTemplate(Reader readerTemplate, Writer writerOut, ISymbolTable symTable) Generates a template of any format having embedded Gosu.static voidgenerateTemplate(Reader readerTemplate, Writer writerOut, ISymbolTable symTable, boolean strict) Generates a template of any format having embedded Gosu.private intgetColumnForIndex(String strSource, int iIndex) private static TemplateGenerator.RuntimeDatastatic TemplateGeneratorgetTemplate(Reader readerTemplate) static TemplateGeneratorgetTemplate(Reader readerTemplate, String fullyQualifiedName) private intignoreTrailingLineSeparator(String strSource, int iIndex) booleanbooleanisValid()private static voidstatic voidprintContent(String strContent, boolean escape) For internal use only!!static voidprintRange(int iStart, int iEnd) private voidprocessDirective(String strScript, int lineNumber, int column, int offset) private static voidprivate voidputSymbols(ISymbolTable symTable, HashMap<String, ISymbol> externalSymbolsMap) voidsetContextInferenceManager(ContextInferenceManager ctxInferenceMgr) voidsetDisableAlternative(boolean disableAlternative) voidsetForStringLiteral(boolean bForStringLiteralTemplate) private voidprivate voidsetHasOwnSymbolScope(boolean hasSymbolScope) voidsetUseStudioEditorParser(boolean useStudioEditorParser) toString()private StringtransformTemplate(String strSource, List<TemplateParseException> exceptions) voidverify(IGosuParser parser) private IProgramverify(IGosuParser parser, boolean bDoNotThrowParseResultException) voidverify(IGosuParser parser, Map<String, List<IFunctionSymbol>> dfsDeclByName, ITypeUsesMap typeUsesMap) private IProgramverify(IGosuParser parser, Map<String, List<IFunctionSymbol>> dfsDeclByName, ITypeUsesMap typeUsesMap, boolean bDoNotThrowParseResultsException)
-
Field Details
-
GS_TEMPLATE
- See Also:
-
GS_TEMPLATE_PARSED
- See Also:
-
SCRIPTLET_BEGIN
- See Also:
-
SCRIPTLET_END
- See Also:
-
EXPRESSION_SUFFIX
public static final char EXPRESSION_SUFFIX- See Also:
-
DECLARATION_SUFFIX
public static final char DECLARATION_SUFFIX- See Also:
-
DIRECTIVE_SUFFIX
public static final char DIRECTIVE_SUFFIX- See Also:
-
COMMENT_BEGIN
- See Also:
-
COMMENT_END
- See Also:
-
ALTERNATE_EXPRESSION_BEGIN
- See Also:
-
ALTERNATE_EXPRESSION_END
- See Also:
-
ESCAPED_SCRIPTLET_MARKER
public static final char ESCAPED_SCRIPTLET_MARKER- See Also:
-
ESCAPED_SCRIPTLET_BEGIN_CHAR
public static final char ESCAPED_SCRIPTLET_BEGIN_CHAR- See Also:
-
ESCAPED_ALTERNATE_EXPRESSION_BEGIN_CHAR
public static final char ESCAPED_ALTERNATE_EXPRESSION_BEGIN_CHAR- See Also:
-
SCRIPTLET_BEGIN_LEN
public static final int SCRIPTLET_BEGIN_LEN -
SCRIPTLET_END_LEN
public static final int SCRIPTLET_END_LEN -
COMMENT_BEGIN_LEN
public static final int COMMENT_BEGIN_LEN -
COMMENT_END_LEN
public static final int COMMENT_END_LEN -
ALTERNATE_EXPRESSION_BEGIN_LEN
public static final int ALTERNATE_EXPRESSION_BEGIN_LEN -
ALTERNATE_EXPRESSION_END_LEN
public static final int ALTERNATE_EXPRESSION_END_LEN -
PRINT_CONTENT_SYMBOL
-
PRINT_RANGE_SYMBOL
-
TEMPLATE_LINE_NUMBER
- See Also:
-
g_runtimeData
-
SUBSTR_CHUNKSIZE
public static final int SUBSTR_CHUNKSIZE- See Also:
-
_fqn
-
_scriptStr
-
_params
-
_program
-
_compileTimeSymbolTable
-
_supertype
-
_useStudioEditorParser
private boolean _useStudioEditorParser -
_disableAlternative
private boolean _disableAlternative -
_hasOwnSymbolScope
private boolean _hasOwnSymbolScope -
_ctxInferenceMgr
-
_bStringLiteralTemplate
private boolean _bStringLiteralTemplate
-
-
Constructor Details
-
TemplateGenerator
WARNING: This will consume the reader and close it!- Parameters:
reader- the reader containing the template
-
-
Method Details
-
generateTemplate
public static void generateTemplate(Reader readerTemplate, Writer writerOut, ISymbolTable symTable) throws TemplateParseException Generates a template of any format having embedded Gosu.- Parameters:
readerTemplate- The source of the template.writerOut- Where the output should go.symTable- The symbol table to use.- Throws:
TemplateParseException- on execution exception
-
generateTemplate
public static void generateTemplate(Reader readerTemplate, Writer writerOut, ISymbolTable symTable, boolean strict) throws TemplateParseException Generates a template of any format having embedded Gosu.- Parameters:
readerTemplate- The source of the template.writerOut- Where the output should go.symTable- The symbol table to use.strict- whether to allow althernative template- Throws:
TemplateParseException- on execution exception
-
getTemplate
-
getTemplate
-
setHasOwnSymbolScope
private void setHasOwnSymbolScope(boolean hasSymbolScope) -
getProgram
- Specified by:
getProgramin interfaceITemplateGenerator
-
getRuntimeData
-
pushRuntimeData
-
popRuntimeData
private static void popRuntimeData() -
execute
- Specified by:
executein interfaceITemplateGenerator- Throws:
TemplateParseException
-
execute
public void execute(Writer writer, StringEscaper escaper, ISymbolTable symTable) throws TemplateParseException - Specified by:
executein interfaceITemplateGenerator- Throws:
TemplateParseException
-
compile
- Specified by:
compilein interfaceITemplateGenerator- Throws:
TemplateParseException
-
compile
public void compile(Stack<IScriptPartId> scriptPartIdStack, ISymbolTable symTable, Map<String, List<IFunctionSymbol>> dfsDeclByName, ITypeUsesMap typeUsesMap, Stack<BlockExpression> blocks, ContextInferenceManager ctxInferenceMgr) throws TemplateParseException- Throws:
TemplateParseException
-
compile
private Program compile(Stack<IScriptPartId> scriptPartIdStack, String strCompiledSource, ISymbolTable symbolTable, Map<String, List<IFunctionSymbol>> dfsDeclByName, ITypeUsesMap typeUsesMap, Stack<BlockExpression> blocks, ContextInferenceManager ctxInferenceMgr) throws ParseResultsException- Returns:
- the program to execute
- Throws:
ParseExceptionParseResultsException
-
addStaticSymbols
private void addStaticSymbols(ISymbolTable symbolTable, GosuParser parser, IGosuClassInternal supertype) -
verify
public void verify(IGosuParser parser, Map<String, List<IFunctionSymbol>> dfsDeclByName, ITypeUsesMap typeUsesMap) throws ParseResultsException- Throws:
ParseResultsException
-
verify
private IProgram verify(IGosuParser parser, Map<String, List<IFunctionSymbol>> dfsDeclByName, ITypeUsesMap typeUsesMap, boolean bDoNotThrowParseResultsException) throws ParseResultsException- Throws:
ParseResultsException
-
verify
- Specified by:
verifyin interfaceITemplateGenerator- Throws:
ParseResultsException
-
verify
private IProgram verify(IGosuParser parser, boolean bDoNotThrowParseResultException) throws ParseResultsException - Throws:
ParseResultsException
-
getTemplateSyntaxProblems
- Specified by:
getTemplateSyntaxProblemsin interfaceITemplateGenerator
-
transformTemplate
-
ignoreTrailingLineSeparator
-
processDirective
private void processDirective(String strScript, int lineNumber, int column, int offset) throws TemplateParseException - Throws:
TemplateParseException
-
addText
-
addRefText
-
addExpression
-
addScriptlet
-
escapeForGosuStringLiteral
-
getColumnForIndex
-
printContent
For internal use only!! -
printRange
public static void printRange(int iStart, int iEnd) -
setDisableAlternative
public void setDisableAlternative(boolean disableAlternative) -
setContextInferenceManager
-
setForStringLiteral
public void setForStringLiteral(boolean bForStringLiteralTemplate) -
isForStringLiteral
public boolean isForStringLiteral() -
isValid
public boolean isValid()- Specified by:
isValidin interfaceITemplateGenerator
-
setFqn
-
getFullyQualifiedTypeName
- Specified by:
getFullyQualifiedTypeNamein interfaceITemplateGenerator
-
getParameters
- Specified by:
getParametersin interfaceITemplateGenerator
-
compileIfNotCompiled
private void compileIfNotCompiled() -
getSuperType
- Specified by:
getSuperTypein interfaceITemplateGenerator
-
setUseStudioEditorParser
public void setUseStudioEditorParser(boolean useStudioEditorParser) -
toString
-
getSource
- Specified by:
getSourcein interfaceITemplateGenerator
-
extractExternalSymbols
private IExternalSymbolMap extractExternalSymbols(ISymbolTable compileTimeSymbolTable, ISymbolTable runtimeSymbolTable) -
putSymbols
-