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 class
private class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
private ISymbolTable
private ContextInferenceManager
private boolean
private String
private boolean
private Program
private String
private IType
private boolean
static final String
static final int
static final String
static final int
static final String
static final int
static final String
static final int
static final char
static final char
static final char
static final char
static final char
static final char
private static ThreadLocal<Stack<TemplateGenerator.RuntimeData>>
static final String
static final String
static final LockingLazyVar<ISymbol>
static final LockingLazyVar<ISymbol>
static final String
static final int
static final String
static final int
static final int
static final String
Fields inherited from interface gw.lang.parser.template.ITemplateGenerator
PRINT_COMPRESSED_METHOD, PRINT_METHOD, PRINT_RANGE_METHOD
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
TemplateGenerator
(Reader reader) WARNING: This will consume the reader and close it! -
Method Summary
Modifier and TypeMethodDescriptionprivate void
addExpression
(StringBuilder strTarget, String strExpression, int iLineNumber) private void
addRefText
(StringBuilder sbTarget, int iStart, int iEnd) private void
addScriptlet
(StringBuilder strTarget, String strScript, int iLineNumber) private void
addStaticSymbols
(ISymbolTable symbolTable, GosuParser parser, IGosuClassInternal supertype) private void
addText
(StringBuilder strTarget, String strText) void
compile
(ISymbolTable symTable) void
compile
(Stack<IScriptPartId> scriptPartIdStack, ISymbolTable symTable, Map<String, List<IFunctionSymbol>> dfsDeclByName, ITypeUsesMap typeUsesMap, Stack<BlockExpression> blocks, ContextInferenceManager ctxInferenceMgr) private Program
compile
(Stack<IScriptPartId> scriptPartIdStack, String strCompiledSource, ISymbolTable symbolTable, Map<String, List<IFunctionSymbol>> dfsDeclByName, ITypeUsesMap typeUsesMap, Stack<BlockExpression> blocks, ContextInferenceManager ctxInferenceMgr) private void
private String
escapeForGosuStringLiteral
(String strText) void
execute
(Writer writer, ISymbolTable symbolTable) void
execute
(Writer writer, StringEscaper escaper, ISymbolTable symTable) private IExternalSymbolMap
extractExternalSymbols
(ISymbolTable compileTimeSymbolTable, ISymbolTable runtimeSymbolTable) static void
generateTemplate
(Reader readerTemplate, Writer writerOut, ISymbolTable symTable) Generates a template of any format having embedded Gosu.static void
generateTemplate
(Reader readerTemplate, Writer writerOut, ISymbolTable symTable, boolean strict) Generates a template of any format having embedded Gosu.private int
getColumnForIndex
(String strSource, int iIndex) private static TemplateGenerator.RuntimeData
static TemplateGenerator
getTemplate
(Reader readerTemplate) static TemplateGenerator
getTemplate
(Reader readerTemplate, String fullyQualifiedName) private int
ignoreTrailingLineSeparator
(String strSource, int iIndex) boolean
boolean
isValid()
private static void
static void
printContent
(String strContent, boolean escape) For internal use only!!static void
printRange
(int iStart, int iEnd) private void
processDirective
(String strScript, int lineNumber, int column, int offset) private static void
private void
putSymbols
(ISymbolTable symTable, HashMap<String, ISymbol> externalSymbolsMap) void
setContextInferenceManager
(ContextInferenceManager ctxInferenceMgr) void
setDisableAlternative
(boolean disableAlternative) void
setForStringLiteral
(boolean bForStringLiteralTemplate) private void
private void
setHasOwnSymbolScope
(boolean hasSymbolScope) void
setUseStudioEditorParser
(boolean useStudioEditorParser) toString()
private String
transformTemplate
(String strSource, List<TemplateParseException> exceptions) void
verify
(IGosuParser parser) private IProgram
verify
(IGosuParser parser, boolean bDoNotThrowParseResultException) void
verify
(IGosuParser parser, Map<String, List<IFunctionSymbol>> dfsDeclByName, ITypeUsesMap typeUsesMap) private IProgram
verify
(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:
getProgram
in interfaceITemplateGenerator
-
getRuntimeData
-
pushRuntimeData
-
popRuntimeData
private static void popRuntimeData() -
execute
- Specified by:
execute
in interfaceITemplateGenerator
- Throws:
TemplateParseException
-
execute
public void execute(Writer writer, StringEscaper escaper, ISymbolTable symTable) throws TemplateParseException - Specified by:
execute
in interfaceITemplateGenerator
- Throws:
TemplateParseException
-
compile
- Specified by:
compile
in 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:
ParseException
ParseResultsException
-
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:
verify
in interfaceITemplateGenerator
- Throws:
ParseResultsException
-
verify
private IProgram verify(IGosuParser parser, boolean bDoNotThrowParseResultException) throws ParseResultsException - Throws:
ParseResultsException
-
getTemplateSyntaxProblems
- Specified by:
getTemplateSyntaxProblems
in 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:
isValid
in interfaceITemplateGenerator
-
setFqn
-
getFullyQualifiedTypeName
- Specified by:
getFullyQualifiedTypeName
in interfaceITemplateGenerator
-
getParameters
- Specified by:
getParameters
in interfaceITemplateGenerator
-
compileIfNotCompiled
private void compileIfNotCompiled() -
getSuperType
- Specified by:
getSuperType
in interfaceITemplateGenerator
-
setUseStudioEditorParser
public void setUseStudioEditorParser(boolean useStudioEditorParser) -
toString
-
getSource
- Specified by:
getSource
in interfaceITemplateGenerator
-
extractExternalSymbols
private IExternalSymbolMap extractExternalSymbols(ISymbolTable compileTimeSymbolTable, ISymbolTable runtimeSymbolTable) -
putSymbols
-