<commit_before>/*
 [The "BSD licence"]
 Copyright (c) 2003-2005 <NAME>
 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.antlr.stringtemplate;

import java.io.*;
import java.util.*;
import java.lang.reflect.Constructor;

import org.antlr.stringtemplate.language.*;
import antlr.*;
import antlr.collections.AST;

/** A <TT>StringTemplate</TT> is a "document" with holes in it where you can stick
 *  values.  <TT>StringTemplate</TT> breaks up your template into chunks of text and
 *  attribute expressions, which are by default enclosed in angle brackets:
 * <TT>&lt;</TT><em>attribute-expression</em><TT>&gt;</TT>.  <TT>StringTemplate</TT>
 * ignores everything outside of attribute expressions, treating it as just text to spit
 * out when you call <TT>StringTemplate.toString()</TT>.
 *
 *  <P><TT>StringTemplate</TT> is not a "system" or "engine" or "server"; it's a lib
rary with two classes of interest: <TT>StringTemplate</TT> and <TT>StringTemplat
eGroup</TT>.  You can directly create a <TT>StringTemplate</TT> in Java code or
you can load a template from a file.
<P>
A StringTemplate describes an output pattern/language like an exemplar.
 *  <p>
 *  StringTemplate and associated code is released under the BSD licence.  See
 *  source.  <br><br>
 *  Copyright (c) 2003-2005 <NAME><br><br>

 *  A particular instance of a template may have a set of attributes that
 *  you set programmatically.  A template refers to these single or multi-
 *  valued attributes when writing itself out.  References within a
 *  template conform to a simple language with attribute references and
 *  references to other, embedded, templates.  The references are surrounded
 *  by user-defined start/stop strings (default of <...>, but $...$ works
 *  well when referencing attributes in HTML to distinguish from tags).
 *
 *  <p>StringTemplateGroup is a self-referential group of StringTemplate
 *  objects kind of like a grammar.  It is very useful for keeping a
 *  group of templates together.  For example, jGuru.com's premium and
 *  guest sites are completely separate sets of template files organized
 *  with a StringTemplateGroup.  Changing "skins" is a simple matter of
 *  switching groups.  Groups know where to load templates by either
 *  looking under a rootDir you can specify for the group or by simply
 *  looking for a resource file in the current class path.  If no rootDir
 *  is specified, template files are assumed to be resources.  So, if
 *  you reference template foo() and you have a rootDir, it looks for
 *  file rootDir/foo.st.  If you don't have a rootDir, it looks for
 *  file foo.st in the CLASSPATH.  note that you can use org/antlr/misc/foo()
 *  (qualified template names) as a template ref.
 *
 *  <p>StringTemplateErrorListener is an interface you can implement to
 *  specify where StringTemplate reports errors.  Setting the listener
 *  for a group automatically makes all associated StringTemplate
 *  objects use the same listener.  For example,
 *
 *  <font size=2><pre>
 *  StringTemplateGroup group = new StringTemplateGroup("loutSyndiags");
 *  group.setErrorListener(
 *     new StringTemplateErrorListener() {
 *        public void error(String msg, Exception e) {
 *           System.err.println("StringTemplate error: "+
 *               msg+((e!=null)?": "+e.getMessage():""));
 *        }
 *    }
 *  );
 *  </pre></font>
 *
 *  <p>IMPLEMENTATION
 *
 *  <p>A StringTemplate is both class and instance like in Self.  Given
 *  any StringTemplate (even one with attributes filled in), you can
 *  get a new "blank" instance of it.
 *
 *  <p>When you define a template, the string pattern is parsed and
 *  broken up into chunks of either String or attribute/template actions.
 *  These are typically just attribute references.  If a template is
 *  embedded within another template either via setAttribute or by
 *  implicit inclusion by referencing a template within a template, it
 *  inherits the attribute scope of the enclosing StringTemplate instance.
 *  All StringTemplate instances with the same pattern point to the same
 *  list of chunks since they are immutable there is no reason to have
 *  a copy in every instance of that pattern.  The only thing that differs
 *  is that every StringTemplate Java object can have its own set of
 *  attributes.  Each chunk points back at the original StringTemplate
 *  Java object whence they were constructed.  So, there are multiple
 *  pointers to the list of chunks (one for each instance with that
 *  pattern) and only one back ptr from a chunk to the original pattern
 *  object.  This is used primarily to get the grcoup of that original
 *  so new templates can be loaded into that group.
 *
 *  <p>To write out a template, the chunks are walked in order and asked to
 *  write themselves out.  String chunks are obviously just written out,
 *  but the attribute expressions/actions are evaluated in light of the
 *  attributes in that object and possibly in an enclosing instance.
 */
public class StringTemplate {
    public static final String VERSION = "2.3b4";

	/** <@r()> */
	public static final int REGION_IMPLICIT = 1;
	/** <@r>...<@end> */
	public static final int REGION_EMBEDDED = 2;
	/** @t.r() ::= "..." defined manually by coder */<commit_msg>push to 2.7.6 from main<commit_after>/*
 [The "BSD licence"]
 Copyright (c) 2003-2005 <NAME>
 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.antlr.stringtemplate;

import java.io.*;
import java.util.*;
import java.lang.reflect.Constructor;

import org.antlr.stringtemplate.language.*;
import antlr.*;
import antlr.collections.AST;

/** A <TT>StringTemplate</TT> is a "document" with holes in it where you can stick
 *  values.  <TT>StringTemplate</TT> breaks up your template into chunks of text and
 *  attribute expressions, which are by default enclosed in angle brackets:
 * <TT>&lt;</TT><em>attribute-expression</em><TT>&gt;</TT>.  <TT>StringTemplate</TT>
 * ignores everything outside of attribute expressions, treating it as just text to spit
 * out when you call <TT>StringTemplate.toString()</TT>.
 *
 *  <P><TT>StringTemplate</TT> is not a "system" or "engine" or "server"; it's a lib
rary with two classes of interest: <TT>StringTemplate</TT> and <TT>StringTemplat
eGroup</TT>.  You can directly create a <TT>StringTemplate</TT> in Java code or
you can load a template from a file.
<P>
A StringTemplate describes an output pattern/language like an exemplar.
 *  <p>
 *  StringTemplate and associated code is released under the BSD licence.  See
 *  source.  <br><br>
 *  Copyright (c) 2003-2005 <NAME><br><br>

 *  A particular instance of a template may have a set of attributes that
 *  you set programmatically.  A template refers to these single or multi-
 *  valued attributes when writing itself out.  References within a
 *  template conform to a simple language with attribute references and
 *  references to other, embedded, templates.  The references are surrounded
 *  by user-defined start/stop strings (default of <...>, but $...$ works
 *  well when referencing attributes in HTML to distinguish from tags).
 *
 *  <p>StringTemplateGroup is a self-referential group of StringTemplate
 *  objects kind of like a grammar.  It is very useful for keeping a
 *  group of templates together.  For example, jGuru.com's premium and
 *  guest sites are completely separate sets of template files organized
 *  with a StringTemplateGroup.  Changing "skins" is a simple matter of
 *  switching groups.  Groups know where to load templates by either
 *  looking under a rootDir you can specify for the group or by simply
 *  looking for a resource file in the current class path.  If no rootDir
 *  is specified, template files are assumed to be resources.  So, if
 *  you reference template foo() and you have a rootDir, it looks for
 *  file rootDir/foo.st.  If you don't have a rootDir, it looks for
 *  file foo.st in the CLASSPATH.  note that you can use org/antlr/misc/foo()
 *  (qualified template names) as a template ref.
 *
 *  <p>StringTemplateErrorListener is an interface you can implement to
 *  specify where StringTemplate reports errors.  Setting the listener
 *  for a group automatically makes all associated StringTemplate
 *  objects use the same listener.  For example,
 *
 *  <font size=2><pre>
 *  StringTemplateGroup group = new StringTemplateGroup("loutSyndiags");
 *  group.setErrorListener(
 *     new StringTemplateErrorListener() {
 *        public void error(String msg, Exception e) {
 *           System.err.println("StringTemplate error: "+
 *               msg+((e!=null)?": "+e.getMessage():""));
 *        }
 *    }
 *  );
 *  </pre></font>
 *
 *  <p>IMPLEMENTATION
 *
 *  <p>A StringTemplate is both class and instance like in Self.  Given
 *  any StringTemplate (even one with attributes filled in), you can
 *  get a new "blank" instance of it.
 *
 *  <p>When you define a template, the string pattern is parsed and
 *  broken up into chunks of either String or attribute/template actions.
 *  These are typically just attribute references.  If a template is
 *  embedded within another template either via setAttribute or by
 *  implicit inclusion by referencing a template within a template, it
 *  inherits the attribute scope of the enclosing StringTemplate instance.
 *  All StringTemplate instances with the same pattern point to the same
 *  list of chunks since they are immutable there is no reason to have
 *  a copy in every instance of that pattern.  The only thing that differs
 *  is that every StringTemplate Java object can have its own set of
 *  attributes.  Each chunk points back at the original StringTemplate
 *  Java object whence they were constructed.  So, there are multiple
 *  pointers to the list of chunks (one for each instance with that
 *  pattern) and only one back ptr from a chunk to the original pattern
 *  object.  This is used primarily to get the grcoup of that original
 *  so new templates can be loaded into that group.
 *
 *  <p>To write out a template, the chunks are walked in order and asked to
 *  write themselves out.  String chunks are obviously just written out,
 *  but the attribute expressions/actions are evaluated in light of the
 *  attributes in that object and possibly in an enclosing instance.
 */
public class StringTemplate {
    public static final String VERSION = "2.3b5";

	/** <@r()> */
	public static final int REGION_IMPLICIT = 1;
	/** <@r>...<@end> */
	public static final int REGION_EMBEDDED = 2;
	/** @t.r() ::= "..." defined manually by coder */
{'fraction_non_alphanumeric': 0.07178479673568082, 'fraction_numerical': 0.004004836028411667, 'mean_word_length': 3.8497618175155734, 'pattern_counts': {'":': 2, '<': 93, '<?xml version=': 0, '>': 93, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2360959', 'n_tokens_mistral': 3554, 'n_tokens_neox': 3386, 'n_words': 1768}