Search in sources :

Example 6 with ParseResult

use of com.google.template.soy.SoyFileSetParser.ParseResult in project closure-templates by google.

the class MsgHtmlTagNodeTest method parseMsgHtmlTagNode.

private static MsgHtmlTagNode parseMsgHtmlTagNode(String htmlTag, ErrorReporter errorReporter, String... params) {
    Checkpoint cp = errorReporter.checkpoint();
    ParseResult parse = SoyFileSetParserBuilder.forFileContents(Joiner.on('\n').join("{namespace ns}", "", "{template .t stricthtml=\"false\"}", Joiner.on('\n').join(params), "{msg desc=\"...\"}", htmlTag, "{/msg}", "{/template}")).errorReporter(errorReporter).parse();
    if (errorReporter.errorsSince(cp)) {
        return null;
    }
    MsgFallbackGroupNode child = (MsgFallbackGroupNode) parse.fileSet().getChild(0).getChild(0).getChild(0);
    return (MsgHtmlTagNode) ((MsgPlaceholderNode) child.getChild(0).getChild(0)).getChild(0);
}
Also used : Checkpoint(com.google.template.soy.error.ErrorReporter.Checkpoint) ParseResult(com.google.template.soy.SoyFileSetParser.ParseResult)

Example 7 with ParseResult

use of com.google.template.soy.SoyFileSetParser.ParseResult in project closure-templates by google.

the class SoyFileSet method compileToIncrementalDomSrcFiles.

/**
 * Compiles this Soy file set into JS source code files and writes these JS files to disk.
 *
 * @param outputPathFormat The format string defining how to build the output file path
 *     corresponding to an input file path.
 * @param jsSrcOptions The compilation options for the JS Src output target.
 * @throws SoyCompilationException If compilation fails.
 * @throws IOException If there is an error in opening/reading a message file or opening/writing
 *     an output JS file.
 */
void compileToIncrementalDomSrcFiles(String outputPathFormat, SoyIncrementalDomSrcOptions jsSrcOptions) throws IOException {
    resetErrorReporter();
    disallowExternalCalls();
    ParseResult result = preprocessIncrementalDOMResults();
    new IncrementalDomSrcMain(apiCallScopeProvider, typeRegistry).genJsFiles(result.fileSet(), result.registry(), jsSrcOptions, outputPathFormat, errorReporter);
    throwIfErrorsPresent();
    reportWarnings();
}
Also used : ParseResult(com.google.template.soy.SoyFileSetParser.ParseResult) IncrementalDomSrcMain(com.google.template.soy.incrementaldomsrc.IncrementalDomSrcMain)

Example 8 with ParseResult

use of com.google.template.soy.SoyFileSetParser.ParseResult in project closure-templates by google.

the class SoyFileSet method generateParseInfo.

/**
 * Generates Java classes containing parse info (param names, template names, meta info). There
 * will be one Java class per Soy file.
 *
 * @param javaPackage The Java package for the generated classes.
 * @param javaClassNameSource Source of the generated class names. Must be one of "filename",
 *     "namespace", or "generic".
 * @return A map from generated file name (of the form "<*>SoyInfo.java") to generated file
 *     content.
 * @throws SoyCompilationException If compilation fails.
 */
ImmutableMap<String, String> generateParseInfo(String javaPackage, String javaClassNameSource) {
    resetErrorReporter();
    // TODO(lukes): see if we can enforce that globals are provided at compile time here. given that
    // types have to be, this should be possible.  Currently it is disabled for backwards
    // compatibility
    // N.B. we do not run the optimizer here for 2 reasons:
    // 1. it would just waste time, since we are not running code generation the optimization work
    // doesn't help anything
    // 2. it potentially removes metadata from the tree by precalculating expressions. For example,
    // trivial print nodes are evaluated, which can remove globals from the tree, but the
    // generator requires data about globals to generate accurate proto descriptors.  Also, the
    // ChangeCallsToPassAllData pass will change the params of templates.
    ParseResult result = parse(passManagerBuilder(SyntaxVersion.V2_0).allowUnknownGlobals().optimize(false), typeRegistry, new PluginResolver(// we allow undefined plugins since they typically aren't provided :(
    PluginResolver.Mode.ALLOW_UNDEFINED, printDirectives, soyFunctionMap, errorReporter));
    throwIfErrorsPresent();
    SoyFileSetNode soyTree = result.fileSet();
    TemplateRegistry registry = result.registry();
    // Do renaming of package-relative class names.
    ImmutableMap<String, String> parseInfo = new GenerateParseInfoVisitor(javaPackage, javaClassNameSource, registry).exec(soyTree);
    throwIfErrorsPresent();
    reportWarnings();
    return parseInfo;
}
Also used : TemplateRegistry(com.google.template.soy.soytree.TemplateRegistry) ParseResult(com.google.template.soy.SoyFileSetParser.ParseResult) GenerateParseInfoVisitor(com.google.template.soy.parseinfo.passes.GenerateParseInfoVisitor) SoyFileSetNode(com.google.template.soy.soytree.SoyFileSetNode) PluginResolver(com.google.template.soy.soyparse.PluginResolver)

Example 9 with ParseResult

use of com.google.template.soy.SoyFileSetParser.ParseResult in project closure-templates by google.

the class SoyFileSet method compileForServerRendering.

/**
 * Runs common compiler logic shared by tofu and jbcsrc backends.
 */
private ServerCompilationPrimitives compileForServerRendering() {
    ParseResult result = parse(SyntaxVersion.V2_0);
    throwIfErrorsPresent();
    SoyFileSetNode soyTree = result.fileSet();
    TemplateRegistry registry = result.registry();
    // which case it is pointless.
    if (cache == null) {
        new ClearSoyDocStringsVisitor().exec(soyTree);
    }
    throwIfErrorsPresent();
    return new ServerCompilationPrimitives(registry, soyTree);
}
Also used : TemplateRegistry(com.google.template.soy.soytree.TemplateRegistry) ClearSoyDocStringsVisitor(com.google.template.soy.passes.ClearSoyDocStringsVisitor) ParseResult(com.google.template.soy.SoyFileSetParser.ParseResult) SoyFileSetNode(com.google.template.soy.soytree.SoyFileSetNode)

Example 10 with ParseResult

use of com.google.template.soy.SoyFileSetParser.ParseResult in project closure-templates by google.

the class SoyFileSet method compileToJsSrc.

/**
 * Compiles this Soy file set into JS source code files and returns these JS files as a list of
 * strings, one per file.
 *
 * @param jsSrcOptions The compilation options for the JS Src output target.
 * @param msgBundle The bundle of translated messages, or null to use the messages from the Soy
 *     source.
 * @return A list of strings where each string represents the JS source code that belongs in one
 *     JS file. The generated JS files correspond one-to-one to the original Soy source files.
 * @throws SoyCompilationException If compilation fails.
 */
@SuppressWarnings("deprecation")
public List<String> compileToJsSrc(SoyJsSrcOptions jsSrcOptions, @Nullable SoyMsgBundle msgBundle) {
    ParseResult result = preprocessJsSrcResults(jsSrcOptions);
    TemplateRegistry registry = result.registry();
    SoyFileSetNode fileSet = result.fileSet();
    List<String> generatedSrcs = new JsSrcMain(apiCallScopeProvider, typeRegistry).genJsSrc(fileSet, registry, jsSrcOptions, msgBundle, errorReporter);
    throwIfErrorsPresent();
    reportWarnings();
    return generatedSrcs;
}
Also used : JsSrcMain(com.google.template.soy.jssrc.internal.JsSrcMain) TemplateRegistry(com.google.template.soy.soytree.TemplateRegistry) ParseResult(com.google.template.soy.SoyFileSetParser.ParseResult) SoyFileSetNode(com.google.template.soy.soytree.SoyFileSetNode)

Aggregations

ParseResult (com.google.template.soy.SoyFileSetParser.ParseResult)38 Test (org.junit.Test)21 SoyFileSetNode (com.google.template.soy.soytree.SoyFileSetNode)13 TemplateRegistry (com.google.template.soy.soytree.TemplateRegistry)13 TemplateNode (com.google.template.soy.soytree.TemplateNode)10 TransitiveDepTemplatesInfo (com.google.template.soy.passes.FindTransitiveDepTemplatesVisitor.TransitiveDepTemplatesInfo)8 SoyRecord (com.google.template.soy.data.SoyRecord)2 IncrementalDomSrcMain (com.google.template.soy.incrementaldomsrc.IncrementalDomSrcMain)2 JsSrcMain (com.google.template.soy.jssrc.internal.JsSrcMain)2 SoyMsgBundle (com.google.template.soy.msgs.SoyMsgBundle)2 PluginResolver (com.google.template.soy.soyparse.PluginResolver)2 SoyTypeRegistry (com.google.template.soy.types.SoyTypeRegistry)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Injector (com.google.inject.Injector)1 SoyFileSetParserBuilder (com.google.template.soy.SoyFileSetParserBuilder)1 SoyModule (com.google.template.soy.SoyModule)1 UniqueNameGenerator (com.google.template.soy.base.internal.UniqueNameGenerator)1 CopyState (com.google.template.soy.basetree.CopyState)1 SyntaxVersion (com.google.template.soy.basetree.SyntaxVersion)1