Package com.google.caja.parser

Examples of com.google.caja.parser.ParseTreeNode


  @Override
  protected boolean consumeSpecimens(
      List<ParseTreeNode> specimens, Map<String, ParseTreeNode> bindings) {
    if (specimens.isEmpty()) { return false; }
    ParseTreeNode specimen = specimens.get(0);
    if (!(specimen instanceof DirectivePrologue)) { return false; }
    DirectivePrologue usd = ((DirectivePrologue) specimen);
    if (!usd.getDirectives().containsAll(directives)) { return false; }
    specimens.remove(0);
    return true;
View Full Code Here


  protected final ParseTreeNode expand(ParseTreeNode node, Scope scope) {
    boolean debug = false;
    Iterable<Rule> run = debug ? rules.getAllRules() : rules.applicableTo(node);
    for (Rule rule : run) {
      try {
        ParseTreeNode result = rule.fire(node, scope);
        if (result != Rule.NONE) {
          if (debug && !rules.applicableTo(node).contains(rule)) {
            throw new SomethingWidgyHappenedError(
                rule.getName() + " should be applicable to " + node);
          }
          if (logging) { logResults(rule, node, result, null); }
          result.makeImmutable();
          return result;
        }
      } catch (RuntimeException ex) {
        if (logging) { logResults(rule, node, null, ex); }
        throw ex;
View Full Code Here

      Job job = env.job;
      if (job.getType() != ContentType.JS) { continue; }

      URI baseUri = job.getBaseUri();
      Statement s = (Statement) job.getRoot();
      ParseTreeNode result = new ExpressionSanitizerCaja(mgr, baseUri)
          .sanitize(UncajoledModule.of(s));
      if (!(result instanceof CajoledModule)) {
        // Rewriter failed to rewrite so returned its input.
        // There should be details on the message queue.
        it.remove();
View Full Code Here

  private boolean parseInputs(PluginMeta meta, Collection<URI> inputs,
      PluginCompiler pluginc) {
    boolean parsePassed = true;
    for (URI input : inputs) {
      try {
        ParseTreeNode parseTree = new ParserContext(mq)
            .withInput(new InputSource(input))
            .withConfig(meta)
            .withConfig(mc)
            .withSourceMap(originalSources)
            .build();
View Full Code Here

   * The list of parse trees that comprise the plugin after run has been called.
   * Valid after run has been called.
   */
  public List<? extends ParseTreeNode> getOutputs() {
    List<ParseTreeNode> outputs = Lists.newArrayList();
    ParseTreeNode js = getJavascript();
    if (js != null) { outputs.add(js); }
    return outputs;
  }
View Full Code Here

    this.baseUri = baseUri;
  }

  public ParseTreeNode sanitize(ParseTreeNode input) {
    MessageQueue mq = mgr.getMessageQueue();
    ParseTreeNode result = null;
    if (input instanceof UncajoledModule) {
      Block body = ((UncajoledModule) input).getModuleBody();
      if (body.children().size() == 2
          && body.children().get(0) instanceof DirectivePrologue
          && ((DirectivePrologue) body.children().get(0))
              .hasDirective("use strict")
          && body.children().get(1) instanceof TranslatedCode) {
        result = input;
      }
    }
    result = newES53Rewriter(mgr).expand(input);
    if (mq.hasMessageAtLevel(MessageLevel.ERROR)) {
      return null;
    }

    result = new IllegalReferenceCheckRewriter(mq, false).expand(result);
    if (mq.hasMessageAtLevel(MessageLevel.ERROR)) {
      return null;
    }

    result.visitPreOrder(new NonAsciiCheckVisitor(mq));
    if (mq.hasMessageAtLevel(MessageLevel.ERROR)) {
      return null;
    }

    return result;
View Full Code Here

import com.google.caja.parser.js.Statement;
import com.google.caja.parser.quasiliteral.QuasiBuilder;

public final class QuasiUtil {
  public static Statement quasiStmt(String quasi, Object... args) {
    ParseTreeNode n = QuasiBuilder.substV(quasi, args);
    if (n instanceof Expression) {
      return new ExpressionStmt(FilePosition.UNKNOWN, (Expression) n);
    }
    return (Statement) n;
  }
View Full Code Here

    assertTokens("e4.bar", "e4", ".", "bar");
    assertTokens("1e4 .bar", "1e4", ".", "bar");
  }

  public final void testRestrictedSemicolonInsertion() throws Exception {
    ParseTreeNode node = js(fromString(
        ""
        // 0123456789
        + "var x=abcd+\n"
        + "+ef;return 1-\n"
        + "-c;if(b)throw new\n"
        + "Error();break label;do\n"
        + "nothing;while(0);continue top;a-\n"
        + "-b;number=counter++"
        + ";number=counter--"
        + ";number=n-++"
        + "counter"
        ));
    StringBuilder out = new StringBuilder();
    JsMinimalPrinter pp = new JsMinimalPrinter(out);
    pp.setLineLengthLimit(10);
    node.render(new RenderContext(pp));
    pp.noMoreTokens();
    assertEquals(
        "{var x=abcd+"
        + "\n+ef;return 1-"
        + "\n-c;if(b)throw new"
View Full Code Here

        + "\n-b;number=counter++;number=counter--;number=n-++counter}",
        out.toString());
  }

  public final void testNoops() throws ParseException {
    ParseTreeNode b = js(fromString(
        "for (;;) {",
        "  if (foo)",
        "    bar();",
        "  else",
        "    ;",
        "}"));
    StringBuilder out = new StringBuilder();
    JsMinimalPrinter pp = new JsMinimalPrinter(out);
    b.render(new RenderContext(pp));
    pp.noMoreTokens();
    assertEquals(
        "{for(;;){if(foo)bar();else;}}",
        out.toString());
  }
View Full Code Here

  }

  private void assertRendered(String golden, String input) throws Exception {
    JsLexer lex = new JsLexer(fromString(input));
    JsTokenQueue tq = new JsTokenQueue(lex, is);
    ParseTreeNode node = new Parser(tq, mq).parse();
    tq.expectEmpty();

    assertRendered(golden, node);
  }
View Full Code Here

TOP

Related Classes of com.google.caja.parser.ParseTreeNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.