public String show() { StringBuilder buf = new StringBuilder(); if ( imports.size()!=0 ) buf.append(" : "+imports); for (String name : templates.keySet()) { CompiledST c = rawGetTemplate(name); if ( c.isAnonSubtemplate || c==NOT_FOUND_ST ) continue; int slash = name.lastIndexOf('/'); name = name.substring(slash+1, name.length()); buf.append(name); buf.append('('); if ( c.formalArguments!=null ) buf.append( Misc.join(c.formalArguments.values().iterator(), ",") ); buf.append(')'); buf.append(" ::= <<"+Misc.newline); buf.append(c.template+ Misc.newline); buf.append(">>"+Misc.newline); } return buf.toString(); }
public static String getLexerRuleNameFromLiteral(String literal) { String name = literalToRuleNameMap.get(literal); if ( name!=null ) { return name; } // is it a keyword like true or begin? String strippedLiteral = Misc.strip(literal, 1); if ( Character.isLetter(strippedLiteral.charAt(0)) ) { return strippedLiteral.toUpperCase(); } return "T__"+lexerRuleNameID++; }
public static String getFileNameNoSuffix(String f) { if (f==null) return null; f = getFileName(f); return f.substring(0,f.lastIndexOf('.')); }
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; }
protected CompiledST load(String name) { if ( verbose ) System.out.println("STGroupDir.load("+name+")"); String parent = Misc.getParent(name); // must have parent; it's fully-qualified String prefix = Misc.getPrefix(name); String unqualifiedName = Misc.getFileName(name); return loadTemplateFile(prefix, unqualifiedName+TEMPLATE_FILE_EXTENSION); // load t.st file
public final void keyValuePair(Map<String,Object> mapping) throws RecognitionException { Token STRING10=null; Object keyValue11 =null; try { // org/stringtemplate/v4/compiler/Group.g:338:2: ( STRING ':' keyValue ) // org/stringtemplate/v4/compiler/Group.g:338:4: STRING ':' keyValue { STRING10=(Token)match(input,STRING,FOLLOW_STRING_in_keyValuePair678); match(input,20,FOLLOW_20_in_keyValuePair680); pushFollow(FOLLOW_keyValue_in_keyValuePair682); keyValue11=keyValue(); state._fsp--; mapping.put(Misc.replaceEscapes(Misc.strip((STRING10!=null?STRING10.getText():null), 1)), keyValue11); } } catch (RecognitionException re) { reportError(re); recover(input,re); } finally { // do for sure before leaving } } // $ANTLR end "keyValuePair"
@Override public String getName() { return Misc.getFileNameNoSuffix(fileName); } @Override
public String strings() { StringBuilder buf = new StringBuilder(); int addr = 0; if ( code.strings!=null ) { for (Object o : code.strings) { if ( o instanceof String ) { String s = (String)o; s = Misc.replaceEscapes(s); buf.append( String.format("%04d: \"%s\"\n", addr, s) ); } else { buf.append( String.format("%04d: %s\n", addr, o) ); } addr++; } } return buf.toString(); }
public CompilationState(ErrorManager errMgr, String name, TokenStream tokens) { this.errMgr = errMgr; this.tokens = tokens; impl.name = name; impl.prefix = Misc.getPrefix(name); }
/** Given an IP (code location), get it's range in source template then * return it's template line:col. */ public String getSourceLocation() { if ( ip<0 || self==null || self.impl==null ) return null; Interval I = self.impl.sourceMap[ip]; if ( I==null ) return null; // get left edge and get line/col int i = I.a; Coordinate loc = Misc.getLineCharPosition(self.impl.template, i); return loc.toString(); }
@Override public URL getRootDirURL() { //System.out.println("url of "+fileName+" is "+url.toString()); String parent = Misc.stripLastPathElement(url.toString()); try { return new URL(parent); } catch (MalformedURLException mue) { errMgr.runTimeError(null, null, ErrorType.INVALID_TEMPLATE_NAME, mue, parent); } return null; } }
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; }
protected CompiledST load(String name) { if ( verbose ) System.out.println("STGroupDir.load("+name+")"); String parent = Misc.getParent(name); // must have parent; it's fully-qualified String prefix = Misc.getPrefix(name); String unqualifiedName = Misc.getFileName(name); return loadTemplateFile(prefix, unqualifiedName+TEMPLATE_FILE_EXTENSION); // load t.st file
public final void keyValuePair(Map<String,Object> mapping) throws RecognitionException { Token STRING10=null; Object keyValue11 = null; try { // org/stringtemplate/v4/compiler/Group.g:286:2: ( STRING ':' keyValue ) // org/stringtemplate/v4/compiler/Group.g:286:4: STRING ':' keyValue { STRING10=(Token)match(input,STRING,FOLLOW_STRING_in_keyValuePair608); match(input,17,FOLLOW_17_in_keyValuePair610); pushFollow(FOLLOW_keyValue_in_keyValuePair612); keyValue11=keyValue(); state._fsp--; mapping.put(Misc.replaceEscapes(Misc.strip((STRING10!=null?STRING10.getText():null), 1)), keyValue11); } } catch (RecognitionException re) { reportError(re); recover(input,re); } finally { } return ; } // $ANTLR end "keyValuePair"
@Override public String getName() { return Misc.getFileNameNoSuffix(fileName); } @Override
public String strings() { StringBuilder buf = new StringBuilder(); int addr = 0; if ( code.strings!=null ) { for (Object o : code.strings) { if ( o instanceof String ) { String s = (String)o; s = Misc.replaceEscapes(s); buf.append( String.format("%04d: \"%s\"\n", addr, s) ); } else { buf.append( String.format("%04d: %s\n", addr, o) ); } addr++; } } return buf.toString(); }
public CompilationState(ErrorManager errMgr, String name, TokenStream tokens) { this.errMgr = errMgr; this.tokens = tokens; impl.name = name; impl.prefix = Misc.getPrefix(name); }
/** Given an IP (code location), get it's range in source template then * return it's template line:col. */ public String getSourceLocation() { if ( ip<0 || self.impl==null ) return null; Interval I = self.impl.sourceMap[ip]; if ( I==null ) return null; // get left edge and get line/col int i = I.a; Coordinate loc = Misc.getLineCharPosition(self.impl.template, i); return loc.toString(); }
@Override public URL getRootDirURL() { //System.out.println("url of "+fileName+" is "+url.toString()); String parent = Misc.stripLastPathElement(url.toString()); try { return new URL(parent); } catch (MalformedURLException mue) { errMgr.runTimeError(null, null, ErrorType.INVALID_TEMPLATE_NAME, mue, parent); } return null; } }
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; }