org.stringtemplate.v4.compiler.FormalArgument Java Examples

The following examples show how to use org.stringtemplate.v4.compiler.FormalArgument. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: STGroup.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void defineTemplateOrRegion(String fullyQualifiedTemplateName, String regionSurroundingTemplateName, Token templateToken, String template, Token nameToken, List<FormalArgument> args) {
    try {
        if ( regionSurroundingTemplateName!=null ) {
            defineRegion(regionSurroundingTemplateName,
                         nameToken,
                         template,
                         templateToken);
        }
        else {
            defineTemplate(fullyQualifiedTemplateName,
                           nameToken,
                           args,
                           template,
                           templateToken);
        }
    }
    catch (STException e) {
        // after getting syntax error in a template, we emit msg
        // and throw exception to blast all the way out to here.
    }
}
 
Example #2
Source File: ST.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/** Remove an attribute value entirely (can't remove attribute definitions). */

    public void remove(String name) {
        if ( impl.formalArguments==null ) {
            if ( impl.hasFormalArgs ) {
                throw new IllegalArgumentException("no such attribute: "+name);
            }
            return;
        }

        FormalArgument arg = impl.formalArguments.get(name);
        if ( arg==null ) {
            throw new IllegalArgumentException("no such attribute: "+name);
        }
        locals[arg.index] = EMPTY_ATTR; // reset value
    }
 
Example #3
Source File: ST.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/** Remove an attribute value entirely (can't remove attribute definitions). */

    public void remove(String name) {
        if ( impl.formalArguments==null ) {
            if ( impl.hasFormalArgs ) {
                throw new IllegalArgumentException("no such attribute: "+name);
            }
            return;
        }

        FormalArgument arg = impl.formalArguments.get(name);
        if ( arg==null ) {
            throw new IllegalArgumentException("no such attribute: "+name);
        }
        locals[arg.index] = EMPTY_ATTR; // reset value
    }
 
Example #4
Source File: STGroup.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public CompiledST defineTemplate(String fullyQualifiedTemplateName, Token nameT, List<FormalArgument> args, String template, Token templateToken) {
        if ( verbose ) System.out.println("defineTemplate(" +
fullyQualifiedTemplateName+")");
        if ( fullyQualifiedTemplateName==null || fullyQualifiedTemplateName.length()==0 ) {
            throw new IllegalArgumentException("empty template name");
        }
        if ( fullyQualifiedTemplateName.indexOf('.')>=0 ) {
            throw new IllegalArgumentException("cannot have '.' in template names");
        }
        template = Misc.trimOneStartingNewline(template);
        template = Misc.trimOneTrailingNewline(template);
        // compile, passing in templateName as enclosing name for any embedded regions
        CompiledST code = compile(getFileName(), fullyQualifiedTemplateName, args, template, templateToken);
        code.name = fullyQualifiedTemplateName;
        rawDefineTemplate(fullyQualifiedTemplateName, code, nameT);
        code.defineArgDefaultValueTemplates(this);
        code.defineImplicitlyDefinedTemplates(this); // define any anonymous subtemplates
        return code;
    }
 
Example #5
Source File: STGroup.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public CompiledST defineTemplate(String fullyQualifiedTemplateName, Token nameT, List<FormalArgument> args, String template, Token templateToken) {
        if ( verbose ) System.out.println("defineTemplate("+
fullyQualifiedTemplateName+")");
        if ( fullyQualifiedTemplateName==null || fullyQualifiedTemplateName.length()==0 ) {
            throw new IllegalArgumentException("empty template name");
        }
        if ( fullyQualifiedTemplateName.indexOf('.')>=0 ) {
            throw new IllegalArgumentException("cannot have '.' in template names");
        }
        template = Misc.trimOneStartingNewline(template);
        template = Misc.trimOneTrailingNewline(template);
        // compile, passing in templateName as enclosing name for any embedded regions
        CompiledST code = compile(getFileName(), fullyQualifiedTemplateName, args, template, templateToken);
        code.name = fullyQualifiedTemplateName;
        rawDefineTemplate(fullyQualifiedTemplateName, code, nameT);
        code.defineArgDefaultValueTemplates(this);
        code.defineImplicitlyDefinedTemplates(this); // define any anonymous subtemplates
        return code;
    }
 
Example #6
Source File: STGroup.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void defineTemplateOrRegion(String fullyQualifiedTemplateName, String regionSurroundingTemplateName, Token templateToken, String template, Token nameToken, List<FormalArgument> args) {
    try {
        if ( regionSurroundingTemplateName!=null ) {
            defineRegion(regionSurroundingTemplateName,
                         nameToken,
                         template,
                         templateToken);
        }
        else {
            defineTemplate(fullyQualifiedTemplateName,
                           nameToken,
                           args,
                           template,
                           templateToken);
        }
    }
    catch (STException e) {
        // after getting syntax error in a template, we emit msg
        // and throw exception to blast all the way out to here.
    }
}
 
Example #7
Source File: STGroup.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public CompiledST defineTemplate(String fullyQualifiedTemplateName, Token nameT, List<FormalArgument> args, String template, Token templateToken) {
        if ( verbose ) System.out.println("defineTemplate(" +
fullyQualifiedTemplateName+")");
        if ( fullyQualifiedTemplateName==null || fullyQualifiedTemplateName.length()==0 ) {
            throw new IllegalArgumentException("empty template name");
        }
        if ( fullyQualifiedTemplateName.indexOf('.')>=0 ) {
            throw new IllegalArgumentException("cannot have '.' in template names");
        }
        template = Misc.trimOneStartingNewline(template);
        template = Misc.trimOneTrailingNewline(template);
        // compile, passing in templateName as enclosing name for any embedded regions
        CompiledST code = compile(getFileName(), fullyQualifiedTemplateName, args, template, templateToken);
        code.name = fullyQualifiedTemplateName;
        rawDefineTemplate(fullyQualifiedTemplateName, code, nameT);
        code.defineArgDefaultValueTemplates(this);
        code.defineImplicitlyDefinedTemplates(this); // define any anonymous subtemplates
        return code;
    }
 
Example #8
Source File: STGroup.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public CompiledST defineTemplate(String fullyQualifiedTemplateName,
                                 Token nameT,
                                 List<FormalArgument> args,
                                 String template, Token templateToken) {
    if ( verbose ) System.out.println("defineTemplate("+fullyQualifiedTemplateName+")");
    if ( fullyQualifiedTemplateName==null || fullyQualifiedTemplateName.length()==0 ) {
        throw new IllegalArgumentException("empty template name");
    }
    if ( fullyQualifiedTemplateName.indexOf('.')>=0 ) {
        throw new IllegalArgumentException("cannot have '.' in template names");
    }
    template = Misc.trimOneStartingNewline(template);
    template = Misc.trimOneTrailingNewline(template);
    // compile, passing in templateName as enclosing name for any embedded regions
    CompiledST code = compile(getFileName(),
                              fullyQualifiedTemplateName,
                              args,
                              template,
                              templateToken);
    code.name = fullyQualifiedTemplateName;
    rawDefineTemplate(fullyQualifiedTemplateName, code, nameT);
    code.defineArgDefaultValueTemplates(this);
    code.defineImplicitlyDefinedTemplates(this); // define any anonymous subtemplates
    return code;
}
 
Example #9
Source File: STGroup.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public CompiledST defineTemplate(String fullyQualifiedTemplateName, Token nameT, List<FormalArgument> args, String template, Token templateToken) {
    if ( verbose ) System.out.println("defineTemplate("+fullyQualifiedTemplateName+")");
    if ( fullyQualifiedTemplateName==null || fullyQualifiedTemplateName.length()==0 ) {
        throw new IllegalArgumentException("empty template name");
    }
    if ( fullyQualifiedTemplateName.indexOf('.')>=0 ) {
        throw new IllegalArgumentException("cannot have '.' in template names");
    }
    template = Misc.trimOneStartingNewline(template);
    template = Misc.trimOneTrailingNewline(template);
    // compile, passing in templateName as enclosing name for any embedded regions
    CompiledST code = compile(getFileName(), fullyQualifiedTemplateName, args, template, templateToken);
    code.name = fullyQualifiedTemplateName;
    rawDefineTemplate(fullyQualifiedTemplateName, code, nameT);
    code.defineArgDefaultValueTemplates(this);
    code.defineImplicitlyDefinedTemplates(this); // define any anonymous subtemplates
    return code;
}
 
Example #10
Source File: STGroup.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void defineTemplateOrRegion(String fullyQualifiedTemplateName, String regionSurroundingTemplateName, Token templateToken, String template, Token nameToken, List<FormalArgument> args) {
    try {
        if ( regionSurroundingTemplateName!=null ) {
            defineRegion(regionSurroundingTemplateName,
                         nameToken,
                         template,
                         templateToken);
        }
        else {
            defineTemplate(fullyQualifiedTemplateName,
                           nameToken,
                           args,
                           template,
                           templateToken);
        }
    }
    catch (STException e) {
        // after getting syntax error in a template, we emit msg
        // and throw exception to blast all the way out to here.
    }
}
 
Example #11
Source File: ST.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/** Remove an attribute value entirely (can't remove attribute definitions). */

    public void remove(String name) {
        if ( impl.formalArguments==null ) {
            if ( impl.hasFormalArgs ) {
                throw new IllegalArgumentException("no such attribute: "+name);
            }
            return;
        }

        FormalArgument arg = impl.formalArguments.get(name);
        if ( arg==null ) {
            throw new IllegalArgumentException("no such attribute: "+name);
        }
        locals[arg.index] = EMPTY_ATTR; // reset value
    }
 
Example #12
Source File: ST.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/** Remove an attribute value entirely (can't remove attribute definitions). */

    public void remove(String name) {
        if ( impl.formalArguments==null ) {
            if ( impl.hasFormalArgs ) {
                throw new IllegalArgumentException("no such attribute: "+name);
            }
            return;
        }

        FormalArgument arg = impl.formalArguments.get(name);
        if ( arg==null ) {
            throw new IllegalArgumentException("no such attribute: "+name);
        }
        locals[arg.index] = EMPTY_ATTR; // reset value
    }
 
Example #13
Source File: ST.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/** Remove an attribute value entirely (can't remove attribute definitions). */

    public void remove(String name) {
        if ( impl.formalArguments==null ) {
            if ( impl.hasFormalArgs ) {
                throw new IllegalArgumentException("no such attribute: "+name);
            }
            return;
        }

        FormalArgument arg = impl.formalArguments.get(name);
        if ( arg==null ) {
            throw new IllegalArgumentException("no such attribute: "+name);
        }
        locals[arg.index] = EMPTY_ATTR; // reset value
    }
 
Example #14
Source File: STGroup.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public CompiledST defineTemplate(String fullyQualifiedTemplateName, Token nameT, List<FormalArgument> args, String template, Token templateToken) {
        if ( verbose ) System.out.println("defineTemplate(" +
fullyQualifiedTemplateName+")");
        if ( fullyQualifiedTemplateName==null || fullyQualifiedTemplateName.length()==0 ) {
            throw new IllegalArgumentException("empty template name");
        }
        if ( fullyQualifiedTemplateName.indexOf('.')>=0 ) {
            throw new IllegalArgumentException("cannot have '.' in template names");
        }
        template = Misc.trimOneStartingNewline(template);
        template = Misc.trimOneTrailingNewline(template);
        // compile, passing in templateName as enclosing name for any embedded regions
        CompiledST code = compile(getFileName(), fullyQualifiedTemplateName, args, template, templateToken);
        code.name = fullyQualifiedTemplateName;
        rawDefineTemplate(fullyQualifiedTemplateName, code, nameT);
        code.defineArgDefaultValueTemplates(this);
        code.defineImplicitlyDefinedTemplates(this); // define any anonymous subtemplates
        return code;
    }
 
Example #15
Source File: ST.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/** Remove an attribute value entirely (can't remove attribute definitions). */

    public void remove(String name) {
        if ( impl.formalArguments==null ) {
            if ( impl.hasFormalArgs ) {
                throw new IllegalArgumentException("no such attribute: "+name);
            }
            return;
        }

        FormalArgument arg = impl.formalArguments.get(name);
        if ( arg==null ) {
            throw new IllegalArgumentException("no such attribute: "+name);
        }
        locals[arg.index] = EMPTY_ATTR; // reset value
    }
 
Example #16
Source File: STGroup.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public CompiledST defineTemplate(String fullyQualifiedTemplateName, Token nameT, List<FormalArgument> args, String template, Token templateToken) {
        if ( verbose ) System.out.println("defineTemplate("+
fullyQualifiedTemplateName+")");
        if ( fullyQualifiedTemplateName==null || fullyQualifiedTemplateName.length()==0 ) {
            throw new IllegalArgumentException("empty template name");
        }
        if ( fullyQualifiedTemplateName.indexOf('.')>=0 ) {
            throw new IllegalArgumentException("cannot have '.' in template names");
        }
        template = Misc.trimOneStartingNewline(template);
        template = Misc.trimOneTrailingNewline(template);
        // compile, passing in templateName as enclosing name for any embedded regions
        CompiledST code = compile(getFileName(), fullyQualifiedTemplateName, args, template, templateToken);
        code.name = fullyQualifiedTemplateName;
        rawDefineTemplate(fullyQualifiedTemplateName, code, nameT);
        code.defineArgDefaultValueTemplates(this);
        code.defineImplicitlyDefinedTemplates(this); // define any anonymous subtemplates
        return code;
    }
 
Example #17
Source File: ST.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/** Remove an attribute value entirely (can't remove attribute definitions). */

    public void remove(String name) {
        if ( impl.formalArguments==null ) {
            if ( impl.hasFormalArgs ) {
                throw new IllegalArgumentException("no such attribute: "+name);
            }
            return;
        }

        FormalArgument arg = impl.formalArguments.get(name);
        if ( arg==null ) {
            throw new IllegalArgumentException("no such attribute: "+name);
        }
        locals[arg.index] = EMPTY_ATTR; // reset value
    }
 
Example #18
Source File: ST.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/** Remove an attribute value entirely (can't remove attribute definitions). */

    public void remove(String name) {
        if ( impl.formalArguments==null ) {
            if ( impl.hasFormalArgs ) {
                throw new IllegalArgumentException("no such attribute: "+name);
            }
            return;
        }

        FormalArgument arg = impl.formalArguments.get(name);
        if ( arg==null ) {
            throw new IllegalArgumentException("no such attribute: "+name);
        }
        locals[arg.index] = EMPTY_ATTR; // reset value
    }
 
Example #19
Source File: STGroup.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public CompiledST defineTemplate(String fullyQualifiedTemplateName,
							 Token nameT,
                                   List<FormalArgument> args,
							 String template,
							 Token templateToken)
  {
if ( verbose ) System.out.println("defineTemplate("+fullyQualifiedTemplateName+")");
if ( fullyQualifiedTemplateName==null || fullyQualifiedTemplateName.length()==0 ) {
	throw new IllegalArgumentException("empty template name");
}
if ( fullyQualifiedTemplateName.indexOf('.')>=0 ) {
	throw new IllegalArgumentException("cannot have '.' in template names");
}
      template = Misc.trimOneStartingNewline(template);
      template = Misc.trimOneTrailingNewline(template);
// compile, passing in templateName as enclosing name for any embedded regions
      CompiledST code = compile(getFileName(), fullyQualifiedTemplateName, args, template, templateToken);
      code.name = fullyQualifiedTemplateName;
      rawDefineTemplate(fullyQualifiedTemplateName, code, nameT);
code.defineArgDefaultValueTemplates(this);
      code.defineImplicitlyDefinedTemplates(this); // define any anonymous subtemplates

      return code;
  }
 
Example #20
Source File: STGroup.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public CompiledST defineTemplate(String fullyQualifiedTemplateName,
                                 Token nameT,
                                 List<FormalArgument> args,
                                 String template, Token templateToken) {
    if ( verbose ) System.out.println("defineTemplate("+fullyQualifiedTemplateName+")");
    if ( fullyQualifiedTemplateName==null || fullyQualifiedTemplateName.length()==0 ) {
        throw new IllegalArgumentException("empty template name");
    }
    if ( fullyQualifiedTemplateName.indexOf('.')>=0 ) {
        throw new IllegalArgumentException("cannot have '.' in template names");
    }
    template = Misc.trimOneStartingNewline(template);
    template = Misc.trimOneTrailingNewline(template);
    // compile, passing in templateName as enclosing name for any embedded regions
    CompiledST code = compile(getFileName(),
                              fullyQualifiedTemplateName,
                              args,
                              template,
                              templateToken);
    code.name = fullyQualifiedTemplateName;
    rawDefineTemplate(fullyQualifiedTemplateName, code, nameT);
    code.defineArgDefaultValueTemplates(this);
    code.defineImplicitlyDefinedTemplates(this); // define any anonymous subtemplates
    return code;
}
 
Example #21
Source File: STGroup.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public CompiledST defineTemplate(String fullyQualifiedTemplateName,
                                 Token nameT,
                                 List<FormalArgument> args,
                                 String template, Token templateToken) {
    if ( verbose ) System.out.println("defineTemplate("+fullyQualifiedTemplateName+")");
    if ( fullyQualifiedTemplateName==null || fullyQualifiedTemplateName.length()==0 ) {
        throw new IllegalArgumentException("empty template name");
    }
    if ( fullyQualifiedTemplateName.indexOf('.')>=0 ) {
        throw new IllegalArgumentException("cannot have '.' in template names");
    }
    template = Misc.trimOneStartingNewline(template);
    template = Misc.trimOneTrailingNewline(template);
    // compile, passing in templateName as enclosing name for any embedded regions
    CompiledST code = compile(getFileName(),
                              fullyQualifiedTemplateName,
                              args,
                              template,
                              templateToken);
    code.name = fullyQualifiedTemplateName;
    rawDefineTemplate(fullyQualifiedTemplateName, code, nameT);
    code.defineArgDefaultValueTemplates(this);
    code.defineImplicitlyDefinedTemplates(this); // define any anonymous subtemplates
    return code;
}
 
Example #22
Source File: ST.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/** Remove an attribute value entirely (can't remove attribute definitions). */

    public void remove(String name) {
        if ( impl.formalArguments==null ) {
            if ( impl.hasFormalArgs ) {
                throw new IllegalArgumentException("no such attribute: "+name);
            }
            return;
        }

        FormalArgument arg = impl.formalArguments.get(name);
        if ( arg==null ) {
            throw new IllegalArgumentException("no such attribute: "+name);
        }
        locals[arg.index] = EMPTY_ATTR; // reset value
    }
 
Example #23
Source File: ST.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Map<String, Object> getAttributes() {
    if ( impl.formalArguments==null ) return null;
    Map<String, Object> attributes = new HashMap<String, Object>();
    for (FormalArgument a : impl.formalArguments.values()) {
        Object o = locals[a.index];
        if ( o==ST.EMPTY_ATTR ) o = null;
        attributes.put(a.name, o);
    }
    return attributes;
}
 
Example #24
Source File: STGroup.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/** Compile a template. */

    public CompiledST compile(String srcName, String name, List<FormalArgument> args, String template, Token templateToken) // for error location {
        //System.out.println("STGroup.compile: "+enclosingTemplateName);
        Compiler c = new Compiler(this);
        return c.compile(srcName, name, args, template, templateToken);
    }
 
Example #25
Source File: ST.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/** Set {@code locals} attribute value when you only know the name, not the
 *  index. This is ultimately invoked by calling {@code ST#add} from
 *  outside so toss an exception to notify them.
 */

protected void rawSetAttribute(String name, Object value) {
    if ( impl.formalArguments==null ) {
        throw new IllegalArgumentException("no such attribute: "+name);
    }

    FormalArgument arg = impl.formalArguments.get(name);
    if ( arg==null ) {
        throw new IllegalArgumentException("no such attribute: "+name);
    }
    locals[arg.index] = value;
}
 
Example #26
Source File: STGroup.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void defineTemplateOrRegion(String fullyQualifiedTemplateName, String regionSurroundingTemplateName, Token templateToken, String template, Token nameToken, List<FormalArgument> args) {
    try {
        if ( regionSurroundingTemplateName!=null ) {
            defineRegion(regionSurroundingTemplateName, nameToken, template, templateToken);
        }
        else {
            defineTemplate(fullyQualifiedTemplateName, nameToken, args, template, templateToken);
        }
    }
    catch (STException e) {
        // after getting syntax error in a template, we emit msg
        // and throw exception to blast all the way out to here.
    }
}
 
Example #27
Source File: STGroup.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/** Compile a template. */

    public CompiledST compile(String srcName, String name, List<FormalArgument> args, String template, Token templateToken) // for error location
    {
        //System.out.println("STGroup.compile: "+enclosingTemplateName);
        Compiler c = new Compiler(this);
        return c.compile(srcName, name, args, template, templateToken);
    }
 
Example #28
Source File: ST.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Map<String, Object> getAttributes() {
    if ( impl.formalArguments==null ) return null;
    Map<String, Object> attributes = new HashMap<String, Object>();
    for (FormalArgument a : impl.formalArguments.values()) {
        Object o = locals[a.index];
        if ( o== ST.EMPTY_ATTR ) o = null;
        attributes.put(a.name, o);
    }
    return attributes;
}
 
Example #29
Source File: ST.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Map<String, Object> getAttributes() {
    if ( impl.formalArguments==null ) return null;
    Map<String, Object> attributes = new HashMap<String, Object>();
    for (FormalArgument a : impl.formalArguments.values()) {
        Object o = locals[a.index];
        if ( o==ST.EMPTY_ATTR ) o = null;
        attributes.put(a.name, o);
    }
    return attributes;
}
 
Example #30
Source File: ST.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/** Find an attribute in this template only. */

    public Object getAttribute(String name) {
        FormalArgument localArg = null;
        if ( impl.formalArguments!=null ) localArg = impl.formalArguments.get(name);
        if ( localArg!=null ) {
            Object o = locals[localArg.index];
            if ( o==ST.EMPTY_ATTR ) o = null;
            return o;
        }
        return null;
    }