Package com.google.caja.parser

Examples of com.google.caja.parser.ParseTreeNode


    // Parse the javascript
    try {
      StringReader strReader = new StringReader(resp.getContent());
      CharProducer cp = CharProducer.Factory.create(strReader, is);
      JsTokenQueue tq = new JsTokenQueue(new JsLexer(cp), is);
      ParseTreeNode input = new Parser(tq, mq).parse();
      tq.expectEmpty();

      compiler.addInput(AncestorChain.instance(input).node, contextUri.toJavaUri());
    } catch (ParseException e) {
      // Don't bother continuing.
View Full Code Here


  }

  @VisibleForTesting
  static ParseTreeNode parse(InputSource is, CharProducer cp, String mime, MessageQueue mq)
      throws ParseException {
    ParseTreeNode ptn;
    if (mime.contains("javascript")) {
      JsLexer lexer = new JsLexer(cp);
      JsTokenQueue tq = new JsTokenQueue(lexer, is);
      if (tq.isEmpty()) { return null; }
      Parser p = new Parser(tq, mq);
View Full Code Here

      ExternalReference extRef = new ExternalReference(javaUri,
          FilePosition.instance(is, /*lineNo*/ 1, /*charInFile*/ 1, /*charInLine*/ 1));
      // If the fetch fails, a UriFetchException is thrown and serialized as part of the
      // message queue.
      CharProducer cp = fetcher.fetch(extRef, mime).getTextualContent();
      ParseTreeNode ptn = parse(is, cp, mime, mq);
      return rewrite(uri, container, ptn, es53, debug);
    } catch (UnsupportedEncodingException e) {
      LOG.severe("Unexpected inability to recognize mime type: " + mime);
      mq.addMessage(ServiceMessageType.UNEXPECTED_INPUT_MIME_TYPE,
          MessagePart.Factory.valueOf(mime));
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

    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

        "function @a() { @b.@c = @d; @e = @f; }");
    assertTrue(n instanceof SimpleQuasiNode);
  }

  public final void testMultiProps() throws Exception {
    ParseTreeNode n = QuasiBuilder.substV(
        "({ '@k*': @v*, baz: @boo })",
        "k", new ParseTreeNodeContainer(Arrays.asList(
            jsExpr(fromString("'foo'")), jsExpr(fromString("'bar'")))),
        "v", new ParseTreeNodeContainer(Arrays.asList(
            jsExpr(fromString("0")), jsExpr(fromString("1")))),
View Full Code Here

        render(jsExpr(fromString("{ foo: 0, bar: 1, baz: 2 }"))),
        render(n));
  }

  public final void testPropKeys() throws Exception {
    ParseTreeNode n = QuasiBuilder.substV(
        "({ @a: @b, '\\@c': @d })",
        "a", StringLiteral.valueOf(FilePosition.UNKNOWN, "a"),
        "b", StringLiteral.valueOf(FilePosition.UNKNOWN, "b"),
        "c", StringLiteral.valueOf(FilePosition.UNKNOWN, "c"),
        "d", StringLiteral.valueOf(FilePosition.UNKNOWN, "d"));
View Full Code Here

  }

  public final void testIdsWithUnderscores() throws Exception {
    String[] underscoreIds = {"x__", "x\u005f\u005f", "__", "\u005f\u005f" };
    for (String id : underscoreIds) {
      ParseTreeNode specimen = QuasiBuilder.substV(
          "{ var @idWithUnderscore = 1; }",
          "idWithUnderscore", new Identifier(FilePosition.UNKNOWN, id)
      );
      assertTrue("Valid id failed to parse: " + id,
          QuasiBuilder.match("{ var @x__ = 1; }", specimen));
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.