Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* [The "BSD license"]
* Copyright (c) 2011 Terence Parr
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.stringtemplate.v4;
import org.stringtemplate.v4.compiler.CompiledST;
import org.stringtemplate.v4.compiler.FormalArgument;
import org.stringtemplate.v4.debug.AddAttributeEvent;
import org.stringtemplate.v4.debug.ConstructionEvent;
import org.stringtemplate.v4.debug.EvalTemplateEvent;
import org.stringtemplate.v4.debug.InterpEvent;
import org.stringtemplate.v4.gui.STViz;
import org.stringtemplate.v4.misc.Aggregate;
import org.stringtemplate.v4.misc.ErrorBuffer;
import org.stringtemplate.v4.misc.ErrorManager;
import org.stringtemplate.v4.misc.MultiMap;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.StringWriter;
import java.io.Writer;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
/** An instance of the StringTemplate. It consists primarily of
* a {@linkplain ST#impl reference} to its implementation (shared among all
* instances) and a hash table of {@linkplain ST#locals attributes}. Because
* of dynamic scoping, we also need a reference to any enclosing instance. For
* example, in a deeply nested template for an HTML page body, we could still
* reference the title attribute defined in the outermost page template.
*
* To use templates, you create one (usually via {@link STGroup}) and then inject
* attributes using {@link #add}. To render its attacks, use {@link ST#render()}.
*
* TODO: {@link ST#locals} is not actually a hash table like the documentation
* says.
*/
public class ST {
public final static String VERSION = "4.0.7-SNAPSHOT";
/** {@code <@r()>}, {@code <@r>...<@end>}, and {@code @t.r() ::= "..."} defined manually by coder */
public static enum RegionType {
/** {@code <@r()>} */
IMPLICIT,
/** {@code <@r>...<@end>} */
EMBEDDED,
/** {@code @t.r() ::= "..."} */
EXPLICIT
}
/** Events during template hierarchy construction (not evaluation) */
public static class DebugState {
/** Record who made us? {@link ConstructionEvent} creates {@link Exception} to grab stack */
public ConstructionEvent newSTEvent;
/** Track construction-time add attribute "events"; used for ST user-level debugging */
public MultiMap addAttrEvents = new MultiMap();
}
public static final String UNKNOWN_NAME = "anonymous";
public static final Object EMPTY_ATTR = new Object();
/** When there are no formal args for template t and you map t across
* some values, t implicitly gets arg "it". E.g., "$it$"
*/
public static final String IMPLICIT_ARG_NAME = "it";
/** The implementation for this template among all instances of same template . */
public CompiledST impl;
/** Safe to simultaneously write via {@link #add}, which is synchronized.
* Reading during exec is, however, NOT synchronized. So, not thread safe
* to add attributes while it is being evaluated. Initialized to
* {@link #EMPTY_ATTR} to distinguish {@code null} from empty.
*/
protected Object[] locals;
/** Created as instance of which group? We need this to initialize interpreter
* via render. So, we create st and then it needs to know which
* group created it for sake of polymorphism:
*
*
* st = skin1.getInstanceOf("searchbox");
* result = st.render(); // knows skin1 created it
*
*
* Say we have a group {@code g1} with template {@code t} that imports
* templates {@code t} and {@code u} from another group {@code g2}.
* {@code g1.getInstanceOf("u")} finds {@code u} in {@code g2} but remembers
* that {@code g1} created it. If {@code u} includes {@code t}, it should
* create {@code g1.t} not {@code g2.t}.
*
*
* g1 = {t(), u()}
* |
* v
* g2 = {t()}
*
*/
public STGroup groupThatCreatedThisInstance;
/** If {@link STGroup#trackCreationEvents}, track creation and add
* attribute events for each object. Create this object on first use.
*/
public DebugState debugState;
/** Just an alias for {@link ArrayList}, but this way I can track whether a
* list is something ST created or it's an incoming list.
*/
public static final class AttributeList extends ArrayList