Search in sources :

Example 66 with ST

use of edu.princeton.cs.algs4.ST in project bookish by parrt.

the class Tool method legacy_translate.

// legacy single-doc translation
public Pair<Document, String> legacy_translate(Translator trans, String inputDir, String inputFilename) throws IOException {
    Pair<BookishParser.DocumentContext, BookishParser> results = parseChapter(inputDir, inputFilename, 0);
    trans.entities = results.b.entities;
    // get single chapter
    Document doc = (Document) trans.visit(results.a);
    doc.chapter.connectContainerTree();
    ModelConverter converter = new ModelConverter(trans.templates);
    ST outputST = converter.walk(doc);
    return new Pair<>(doc, outputST.render());
}
Also used : ST(org.stringtemplate.v4.ST) Document(us.parr.bookish.model.Document) ModelConverter(us.parr.bookish.translate.ModelConverter) BookishParser(us.parr.bookish.parse.BookishParser) Pair(org.antlr.v4.runtime.misc.Pair)

Example 67 with ST

use of edu.princeton.cs.algs4.ST in project inmemantlr by julianthome.

the class StringCodeGenPipeline method getTokenVocabOutput.

ST getTokenVocabOutput() {
    ST vocabFileST = new ST(CodeGenerator.vocabFilePattern);
    Map<String, Integer> tokens = new LinkedHashMap<>();
    // make constants for the token names
    for (String t : g.tokenNameToTypeMap.keySet()) {
        int tokenType = g.tokenNameToTypeMap.get(t);
        if (tokenType >= Token.MIN_USER_TOKEN_TYPE) {
            tokens.put(t, tokenType);
        }
    }
    vocabFileST.add("tokenvocab", tokens);
    // now dump the strings
    Map<String, Integer> literals = new LinkedHashMap<>();
    for (String literal : g.stringLiteralToTypeMap.keySet()) {
        int tokenType = g.stringLiteralToTypeMap.get(literal);
        if (tokenType >= Token.MIN_USER_TOKEN_TYPE) {
            literals.put(literal, tokenType);
        }
    }
    vocabFileST.add("literals", literals);
    return vocabFileST;
}
Also used : GrammarAST(org.antlr.v4.tool.ast.GrammarAST) ST(org.stringtemplate.v4.ST)

Example 68 with ST

use of edu.princeton.cs.algs4.ST in project jdbi by jdbi.

the class UseStringTemplateSqlLocatorImpl method configureForType.

@Override
public void configureForType(ConfigRegistry registry, Annotation annotation, Class<?> sqlObjectType) {
    SqlLocator locator = (type, method, config) -> {
        String templateName = SqlAnnotations.getAnnotationValue(method, sql -> sql).orElseGet(method::getName);
        STGroup group = findStringTemplateGroup(type);
        if (!group.isDefined(templateName)) {
            throw new IllegalStateException("No StringTemplate group " + templateName + " for class " + sqlObjectType);
        }
        return templateName;
    };
    TemplateEngine templateEngine = (templateName, ctx) -> {
        STGroup group = findStringTemplateGroup(sqlObjectType);
        ST template = group.getInstanceOf(templateName);
        ctx.getAttributes().forEach(template::add);
        return template.render();
    };
    registry.get(SqlObjects.class).setSqlLocator(locator);
    registry.get(SqlStatements.class).setTemplateEngine(templateEngine);
}
Also used : SqlLocator(org.jdbi.v3.sqlobject.locator.SqlLocator) SqlObjects(org.jdbi.v3.sqlobject.SqlObjects) StringTemplateSqlLocator.findStringTemplateGroup(org.jdbi.v3.stringtemplate4.StringTemplateSqlLocator.findStringTemplateGroup) SqlLocator(org.jdbi.v3.sqlobject.locator.SqlLocator) ST(org.stringtemplate.v4.ST) SqlStatements(org.jdbi.v3.core.statement.SqlStatements) STGroup(org.stringtemplate.v4.STGroup) SqlAnnotations(org.jdbi.v3.sqlobject.internal.SqlAnnotations) Annotation(java.lang.annotation.Annotation) TemplateEngine(org.jdbi.v3.core.statement.TemplateEngine) Configurer(org.jdbi.v3.sqlobject.config.Configurer) Method(java.lang.reflect.Method) ConfigRegistry(org.jdbi.v3.core.config.ConfigRegistry) TemplateEngine(org.jdbi.v3.core.statement.TemplateEngine) ST(org.stringtemplate.v4.ST) SqlStatements(org.jdbi.v3.core.statement.SqlStatements) STGroup(org.stringtemplate.v4.STGroup) SqlObjects(org.jdbi.v3.sqlobject.SqlObjects)

Example 69 with ST

use of edu.princeton.cs.algs4.ST in project webcert by sklintyg.

the class ReceiveMedicalCertificateAnswerIT method testCreateAnswerWithInvalidXMLFailsWithApplicationError.

/**
 * Trigger a soapfault by sending a totally nonsense request - Soap faults should get transformed to a valid
 * (application) error response
 */
@Test
public void testCreateAnswerWithInvalidXMLFailsWithApplicationError() {
    ST brokenTemplate = templateGroup.getInstanceOf("brokenrequest");
    given().body(brokenTemplate.render()).when().post(RECEIVE_QUESTION_V1_0).then().statusCode(200).rootPath(BASE).body("result.resultCode", is(ResultCodeType.ERROR.value())).body("result.errorId", is(ErrorIdType.APPLICATION_ERROR.value()));
}
Also used : ST(org.stringtemplate.v4.ST) Test(org.junit.Test)

Example 70 with ST

use of edu.princeton.cs.algs4.ST in project jbpm by kiegroup.

the class WidProcessor method getTemplateData.

public byte[] getTemplateData(String templateResource, Map<String, WidInfo> widInfoMap) throws IOException {
    ST stTemplate = new ST(getTemplateResourceFileAsString(templateResource), '$', '$');
    stTemplate.add("widInfo", widInfoMap);
    stTemplate.add("openbracket", "{");
    stTemplate.add("closebracket", "}");
    return stTemplate.render().getBytes();
}
Also used : ST(org.stringtemplate.v4.ST)

Aggregations

ST (org.stringtemplate.v4.ST)197 GrammarAST (org.antlr.v4.tool.ast.GrammarAST)37 STGroup (org.stringtemplate.v4.STGroup)24 File (java.io.File)19 ArrayList (java.util.ArrayList)16 IOException (java.io.IOException)12 STGroupFile (org.stringtemplate.v4.STGroupFile)12 Path (java.nio.file.Path)10 Test (org.junit.Test)10 ATNFactory (org.antlr.v4.automata.ATNFactory)9 LexerATNFactory (org.antlr.v4.automata.LexerATNFactory)9 ParserATNFactory (org.antlr.v4.automata.ParserATNFactory)9 CodeGenerator (org.antlr.v4.codegen.CodeGenerator)9 SemanticPipeline (org.antlr.v4.semantics.SemanticPipeline)9 Grammar (org.antlr.v4.tool.Grammar)9 LexerGrammar (org.antlr.v4.tool.LexerGrammar)9 STGroupString (org.stringtemplate.v4.STGroupString)9 LinkedHashMap (java.util.LinkedHashMap)7 URL (java.net.URL)6 Map (java.util.Map)6