Java Code Examples for org.stringtemplate.v4.Interpreter

The following examples show how to use org.stringtemplate.v4.Interpreter. These examples are extracted from open source projects. 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 Project: codebuff   Source File: CompilationState.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void refAttr(Token templateToken, CommonTree id) {
    String name = id.getText();
    if ( impl.formalArguments!=null && impl.formalArguments.get(name) !=null ) {
        FormalArgument arg = impl.formalArguments.get(name);
        int index = arg.index;
        emit1(id, Bytecode.INSTR_LOAD_LOCAL, index);
    }
    else {
        if ( Interpreter.predefinedAnonSubtemplateAttributes.contains(name) ) {
            errMgr.compileTimeError(ErrorType.REF_TO_IMPLICIT_ATTRIBUTE_OUT_OF_SCOPE, templateToken, id.token);
            emit(id, Bytecode.INSTR_NULL);
        } else {
            emit1(id, Bytecode.INSTR_LOAD_ATTR, name);
        }
    }
}
 
Example 2
Source Project: codebuff   Source File: CompilationState.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void refAttr(Token templateToken, CommonTree id) {
    String name = id.getText();
    if ( impl.formalArguments!=null && impl.formalArguments.get(name) !=null ) {
        FormalArgument arg = impl.formalArguments.get(name);
        int index = arg.index;
        emit1(id, Bytecode.INSTR_LOAD_LOCAL, index);
    }
    else {
        if ( Interpreter.predefinedAnonSubtemplateAttributes.contains(name) ) {
            errMgr.compileTimeError(ErrorType.REF_TO_IMPLICIT_ATTRIBUTE_OUT_OF_SCOPE, templateToken, id.token);
            emit(id, Bytecode.INSTR_NULL);
        } else {
            emit1(id, Bytecode.INSTR_LOAD_ATTR, name);
        }
    }
}
 
Example 3
Source Project: codebuff   Source File: STRuntimeMessage.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public String toString() {
    StringBuilder buf = new StringBuilder();
    String loc = null;
    if ( self!=null ) {
        loc = getSourceLocation();
        buf.append("context [");
        if ( interp!=null ) {
            buf.append(Interpreter.getEnclosingInstanceStackString(scope));
        }
        buf.append("]");
    }
    if ( loc!=null ) buf.append(" "+loc);
    buf.append(" "+super.toString());
    return buf.toString();
}
 
Example 4
Source Project: codebuff   Source File: STRuntimeMessage.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public String toString() {
    StringBuilder buf = new StringBuilder();
    String loc = null;
    if ( self!=null ) {
        loc = getSourceLocation();
        buf.append("context [");
        if ( interp!=null ) {
            buf.append(Interpreter.getEnclosingInstanceStackString(scope));
        }
        buf.append("]");
    }
    if ( loc!=null ) buf.append(" "+loc);
    buf.append(" "+super.toString());
    return buf.toString();
}
 
Example 5
Source Project: codebuff   Source File: STViz.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
public STViz(ErrorManager errMgr,
			 EvalTemplateEvent root,
			 String output,
			 Interpreter interp,
                List<String> trace,
                List<STMessage> errors)
   {
	this.errMgr = errMgr;
	this.currentEvent = root;
	this.currentScope = root.scope;
	this.output = output;
	this.interp = interp;
       this.allEvents = interp.getEvents();
	this.trace = trace;
       this.errors = errors;
}
 
Example 6
Source Project: codebuff   Source File: CompilationState.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void refAttr(Token templateToken, CommonTree id) {
    String name = id.getText();
    if ( impl.formalArguments!=null && impl.formalArguments.get(name) !=null ) {
        FormalArgument arg = impl.formalArguments.get(name);
        int index = arg.index;
        emit1(id, Bytecode.INSTR_LOAD_LOCAL, index);
    }
    else {
        if ( Interpreter.predefinedAnonSubtemplateAttributes.contains(name) ) {
            errMgr.compileTimeError(ErrorType.REF_TO_IMPLICIT_ATTRIBUTE_OUT_OF_SCOPE, templateToken, id.token);
            emit(id, Bytecode.INSTR_NULL);
        } else {
            emit1(id, Bytecode.INSTR_LOAD_ATTR, name);
        }
    }
}
 
Example 7
Source Project: codebuff   Source File: CompilationState.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void refAttr(Token templateToken, CommonTree id) {
    String name = id.getText();
    if ( impl.formalArguments!=null && impl.formalArguments.get(name) !=null ) {
        FormalArgument arg = impl.formalArguments.get(name);
        int index = arg.index;
        emit1(id, Bytecode.INSTR_LOAD_LOCAL, index);
    }
    else {
        if ( Interpreter.predefinedAnonSubtemplateAttributes.contains(name) ) {
            errMgr.compileTimeError(ErrorType.REF_TO_IMPLICIT_ATTRIBUTE_OUT_OF_SCOPE, templateToken, id.token);
            emit(id, Bytecode.INSTR_NULL);
        } else {
            emit1(id, Bytecode.INSTR_LOAD_ATTR, name);
        }
    }
}
 
Example 8
@Override
public synchronized Object getProperty(Interpreter interp, ST self, Object o, Object property, String propertyName) throws STNoSuchPropertyException {
    if ( o==null ) {
        throw new NullPointerException("o");
    }
    Class<?> c = o.getClass();
    if ( property==null ) {
        return throwNoSuchProperty(c, propertyName, null);
    }
    Member member = findMember(c, propertyName);
    if ( member!=null ) {
        try {
            if ( member instanceof Method ) {
                return ((Method)member).invoke(o);
            }
            else if ( member instanceof Field ) {
                     return ((Field)member).get(o);
            }
        }
        catch (Exception e) {
            throwNoSuchProperty(c, propertyName, e);
        }
    }
    return throwNoSuchProperty(c, propertyName, null);
}
 
Example 9
Source Project: codebuff   Source File: STRuntimeMessage.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
 public String toString() {
     StringBuilder buf = new StringBuilder();
     String loc = null;
     if ( self!=null ) {
         loc = getSourceLocation();
         buf.append("context [");
         if ( interp!=null ) {
	buf.append( Interpreter.getEnclosingInstanceStackString(scope) );
}
         buf.append("]");
     }
     if ( loc!=null ) buf.append(" "+loc);
     buf.append(" "+super.toString());
     return buf.toString();
 }
 
Example 10
@Override
public synchronized Object getProperty(Interpreter interp, ST self, Object o, Object property, String propertyName) throws STNoSuchPropertyException {
    if ( o==null ) {
        throw new NullPointerException("o");
    }
    Class<?> c = o.getClass();
    if ( property==null ) {
        return throwNoSuchProperty(c, propertyName, null);
    }
    Member member = findMember(c, propertyName);
    if ( member!=null ) {
        try {
            if ( member instanceof Method ) {
                return ((Method)member).invoke(o);
            }
            else if ( member instanceof Field ) {
                return ((Field)member).get(o);
            }
        }
        catch (Exception e) {
            throwNoSuchProperty(c, propertyName, e);
        }
    }
    return throwNoSuchProperty(c, propertyName, null);
}
 
Example 11
Source Project: codebuff   Source File: MapModelAdaptor.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public Object getProperty(Interpreter interp, ST self, Object o, Object property, String propertyName) throws STNoSuchPropertyException {
    Object value;
    Map<?, ?> map = (Map<?, ?>)o;
    if ( property==null ) value = map.get(STGroup.DEFAULT_KEY);
    else if ( property.equals("keys") ) value = map.keySet();
    else if ( property.equals("values") ) value = map.values();
    else if ( map.containsKey(property) ) value = map.get(property);
    else if ( map.containsKey(propertyName) ) { // if can't find the key, try toString version
             value = map.get(propertyName);
    }
    else value = map.get(STGroup.DEFAULT_KEY); // not found, use default
    if ( value==STGroup.DICT_KEY ) {
        value = property;
    }
    return value;
}
 
Example 12
Source Project: codebuff   Source File: MapModelAdaptor.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public Object getProperty(Interpreter interp, ST self, Object o, Object property, String propertyName) throws STNoSuchPropertyException {
    Object value;
    Map<?, ?> map = (Map<?, ?>)o;
    if ( property==null ) value = map.get(STGroup.DEFAULT_KEY);
    else if ( property.equals("keys") ) value = map.keySet();
    else if ( property.equals("values") ) value = map.values();
    else if ( map.containsKey(property) ) value = map.get(property);
    else if ( map.containsKey(propertyName) ) { // if can't find the key, try toString version
             value = map.get(propertyName);
    }
    else value = map.get(STGroup.DEFAULT_KEY); // not found, use default
    if ( value==STGroup.DICT_KEY ) {
        value = property;
    }
    return value;
}
 
Example 13
@Override
public synchronized Object getProperty(Interpreter interp, ST self, Object o, Object property, String propertyName) throws STNoSuchPropertyException {
    if ( o==null ) {
        throw new NullPointerException("o");
    }
    Class<?> c = o.getClass();
    if ( property==null ) {
        return throwNoSuchProperty(c, propertyName, null);
    }
    Member member = findMember(c, propertyName);
    if ( member!=null ) {
        try {
            if ( member instanceof Method ) {
                return ((Method)member).invoke(o);
            }
            else if ( member instanceof Field ) {
                     return ((Field)member).get(o);
            }
        }
        catch (Exception e) {
            throwNoSuchProperty(c, propertyName, e);
        }
    }
    return throwNoSuchProperty(c, propertyName, null);
}
 
Example 14
Source Project: codebuff   Source File: STRuntimeMessage.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public String toString() {
    StringBuilder buf = new StringBuilder();
    String loc = null;
    if ( self!=null ) {
        loc = getSourceLocation();
        buf.append("context [");
        if ( interp!=null ) {
            buf.append(Interpreter.getEnclosingInstanceStackString(scope));
        }
        buf.append("]");
    }
    if ( loc!=null ) buf.append(" "+loc);
    buf.append(" "+super.toString());
    return buf.toString();
}
 
Example 15
Source Project: codebuff   Source File: STRuntimeMessage.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
public STRuntimeMessage(Interpreter interp,
                        ErrorType error,
                        int ip,
                        InstanceScope scope,
                        Throwable e,
                        Object arg) {
    this(interp, error, ip, scope, e, arg, null);
}
 
Example 16
Source Project: codebuff   Source File: ErrorManager.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void runTimeError(Interpreter interp,
                         InstanceScope scope,
                         ErrorType error,
                         Object arg,
                         Object arg2, Object arg3) {
    listener.runTimeError(new STRuntimeMessage(interp, error, scope!=null ? scope.ip : 0, scope, null, arg, arg2, arg3));
}
 
Example 17
public JTreeScopeStackModel(InstanceScope scope) {
    root = new StringTree("Scope stack:");
    Set<String> names = new HashSet<String>();
    List<InstanceScope> stack = Interpreter.getScopeStack(scope, false);
    for (InstanceScope s : stack) {
        StringTree templateNode = new StringTree(s.st.getName());
        root.insertChild(0, templateNode);
        addAttributeDescriptions(s.st, templateNode, names);
    }
    //System.out.println(root.toStringTree());
}
 
Example 18
Source Project: codebuff   Source File: STRuntimeMessage.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
public STRuntimeMessage(Interpreter interp,
                        ErrorType error,
                        int ip,
                        InstanceScope scope,
                        Throwable e, Object arg) {
    this(interp, error, ip, scope, e, arg, null);
}
 
Example 19
@Override
public synchronized Object getProperty(Interpreter interp, ST self, Object o, Object property, String propertyName)
	throws STNoSuchPropertyException
{
	if (o == null) {
		throw new NullPointerException("o");
	}

	Class<?> c = o.getClass();

	if ( property==null ) {
		return throwNoSuchProperty(c, propertyName, null);
	}

	Member member = findMember(c, propertyName);
	if ( member!=null ) {
		try {
			if (member instanceof Method) {
				return ((Method)member).invoke(o);
			}
			else if (member instanceof Field) {
				return ((Field)member).get(o);
			}
		}
		catch (Exception e) {
			throwNoSuchProperty(c, propertyName, e);
		}
	}

	return throwNoSuchProperty(c, propertyName, null);
}
 
Example 20
Source Project: codebuff   Source File: STViz.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
public STViz(ErrorManager errMgr, EvalTemplateEvent root, String output, Interpreter interp, List<String> trace, List<STMessage> errors) {
    this.errMgr = errMgr;
    this.currentEvent = root;
    this.currentScope = root.scope;
    this.output = output;
    this.interp = interp;
    this.allEvents = interp.getEvents();
    this.trace = trace;
    this.errors = errors;
}
 
Example 21
Source Project: codebuff   Source File: ErrorManager.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void runTimeError(Interpreter interp,
                         InstanceScope scope,
                         ErrorType error,
                         Object arg,
                         Object arg2,
                         Object arg3) {
    listener.runTimeError(new STRuntimeMessage(interp, error, scope!=null ? scope.ip :0, scope, null, arg, arg2, arg3));
}
 
Example 22
Source Project: codebuff   Source File: STRuntimeMessage.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
public STRuntimeMessage(Interpreter interp,
                        ErrorType error,
                        int ip,
                        InstanceScope scope,
                        Throwable e,
                        Object arg, Object arg2) {
    this(interp, error, ip, scope, e, arg, arg2, null);
}
 
Example 23
Source Project: codebuff   Source File: ErrorManager.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void runTimeError(Interpreter interp,
                         InstanceScope scope,
                         ErrorType error,
                         Object arg,
                         Object arg2, Object arg3) {
    listener.runTimeError(new STRuntimeMessage(interp, error, scope!=null ? scope.ip : 0, scope, null, arg, arg2, arg3));
}
 
Example 24
Source Project: codebuff   Source File: STModelAdaptor.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public Object getProperty(Interpreter interp, ST self, Object o, Object property, String propertyName)
	throws STNoSuchPropertyException
{
	ST st = (ST)o;
	return st.getAttribute(propertyName);
}
 
Example 25
Source Project: codebuff   Source File: ErrorManager.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void runTimeError(Interpreter interp,
                         InstanceScope scope,
                         ErrorType error,
                         Object arg,
                         Object arg2, Object arg3) {
    listener.runTimeError(new STRuntimeMessage(interp, error, scope!=null ? scope.ip : 0, scope, null, arg, arg2, arg3));
}
 
Example 26
public JTreeScopeStackModel(InstanceScope scope) {
	root = new StringTree("Scope stack:");
	Set<String> names = new HashSet<String>();
	List<InstanceScope> stack = Interpreter.getScopeStack(scope, false);
	for (InstanceScope s : stack) {
		StringTree templateNode = new StringTree(s.st.getName());
		root.insertChild(0, templateNode);
		addAttributeDescriptions(s.st, templateNode, names);
	}
	//System.out.println(root.toStringTree());
}
 
Example 27
Source Project: codebuff   Source File: STRuntimeMessage.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
public STRuntimeMessage(Interpreter interp,
                        ErrorType error,
                        int ip,
                        InstanceScope scope,
                        Throwable e,
                        Object arg,
                        Object arg2) {
    this(interp, error, ip, scope, e, arg, arg2, null);
}
 
Example 28
public JTreeScopeStackModel(InstanceScope scope) {
    root = new StringTree("Scope stack:");
    Set<String> names = new HashSet<String>();
    List<InstanceScope> stack = Interpreter.getScopeStack(scope, false);
    for (InstanceScope s : stack) {
        StringTree templateNode = new StringTree(s.st.getName());
        root.insertChild(0, templateNode);
        addAttributeDescriptions(s.st, templateNode, names);
    }
    //System.out.println(root.toStringTree());
}
 
Example 29
Source Project: codebuff   Source File: STRuntimeMessage.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
public STRuntimeMessage(Interpreter interp,
                        ErrorType error,
                        int ip,
                        InstanceScope scope,
                        Throwable e, Object arg) {
    this(interp, error, ip, scope, e, arg, null);
}
 
Example 30
Source Project: codebuff   Source File: STViz.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
public STViz(ErrorManager errMgr, EvalTemplateEvent root, String output, Interpreter interp, List<String> trace, List<STMessage> errors) {
    this.errMgr = errMgr;
    this.currentEvent = root;
    this.currentScope = root.scope;
    this.output = output;
    this.interp = interp;
    this.allEvents = interp.getEvents();
    this.trace = trace;
    this.errors = errors;
}