Package com.google.caja.lexer

Examples of com.google.caja.lexer.JsTokenQueue


        new InputStreamReader(new FileInputStream(f), Charsets.UTF_8), is);
  }

  private static Parser parser(CharProducer cp, MessageQueue errs) {
    JsLexer lexer = new JsLexer(cp);
    JsTokenQueue tq = new JsTokenQueue(lexer, cp.getCurrentPosition().source());
    return new Parser(tq, errs);
  }
View Full Code Here


  private ParseTreeNode parse() throws ParseException {
    ParseTreeNode input;
    if (ContentType.JS == type) {
      JsLexer lexer = new JsLexer(cp);
      JsTokenQueue tq = new JsTokenQueue(lexer, is);
      if (tq.isEmpty()) { return null; }
      Parser p = new Parser(tq, mq);
      input = p.parse();
      tq.expectEmpty();
    } else if (ContentType.CSS == type) {
      TokenQueue<CssTokenType> tq = CssParser.makeTokenQueue(cp, mq, false);
      if (tq.isEmpty()) { return null; }

      CssParser p = new CssParser(tq, mq, MessageLevel.WARNING);
      input = p.parseStyleSheet();
      tq.expectEmpty();
    } else if (ContentType.HTML == type) {
      DomParser p = new DomParser(new HtmlLexer(cp), false, is, mq);
      //if (p.getTokenQueue().isEmpty()) { return null; }
      input = Dom.transplant(p.parseDocument());
      p.getTokenQueue().expectEmpty();
View Full Code Here

  Parser makeJsParser(CharProducer cp, MessageQueue mq) {
    boolean quasis = shouldAllowJsQuasis();
    FilePosition p = cp.filePositionForOffsets(cp.getOffset(), cp.getLimit());
    JsLexer lexer = new JsLexer(cp, quasis);
    JsTokenQueue tq = new JsTokenQueue(lexer, p.source());
    tq.setInputRange(p);
    Parser parser = new Parser(tq, mq, quasis);
    parser.setRecoverFromFailure(shouldJsRecover());
    return parser;
  }
View Full Code Here

    MessageContext mc = new MessageContext();
    MessageQueue mq = TestUtil.createTestMessageQueue(mc);
    InputSource is = new InputSource(new URI("file:///no/input/source"));
    CharProducer cp = CharProducer.Factory.create(new StringReader(src), is);
    JsLexer lexer = new JsLexer(cp);
    JsTokenQueue tq = new JsTokenQueue(lexer, is, JsTokenQueue.NO_COMMENT);
    Parser p = new Parser(tq, mq);
    Statement stmt = p.parse();
    p.getTokenQueue().expectEmpty();
    return stmt;
  }
View Full Code Here

    // Using a simple regex is possible if we reject anything but 7-bit ASCII.
    // However, this implementation ensures Caja has a single point of truth
    // regarding what constitutes a JS identifier.
    MessageQueue mq = new SimpleMessageQueue();
    Parser parser = new Parser(
        new JsTokenQueue(
            new JsLexer(
                CharProducer.Factory.fromString(
                    "var " + candidate + ";",
                    InputSource.UNKNOWN)),
            InputSource.UNKNOWN),
View Full Code Here

  static final MessageQueue LOUD_MQ = new EchoingMessageQueue(
      new PrintWriter(System.err), new MessageContext(), true);
  static String normJs(String js, MessageQueue mq) throws ParseException {
    JsLexer lexer = new JsLexer(
        CharProducer.Factory.fromString(js, FilePosition.UNKNOWN));
    JsTokenQueue tq = new JsTokenQueue(lexer, InputSource.UNKNOWN);
    Expression e = new Parser(tq, mq).parseExpression(true);
    tq.expectEmpty();
    StringBuilder sb = new StringBuilder(js.length() + 16);
    RenderContext rc = new RenderContext(new JsMinimalPrinter(sb));
    e.render(rc);
    rc.getOut().noMoreTokens();
    return sb.toString();
View Full Code Here

  private ParseTreeNode parse() throws ParseException {
    ParseTreeNode input;
    if (ContentType.JS == type) {
      JsLexer lexer = new JsLexer(cp);
      JsTokenQueue tq = new JsTokenQueue(lexer, is);
      if (tq.isEmpty()) { return null; }
      Parser p = new Parser(tq, mq);
      input = p.parse();
      tq.expectEmpty();
    } else if (ContentType.CSS == type) {
      TokenQueue<CssTokenType> tq = CssParser.makeTokenQueue(cp, mq, false);
      if (tq.isEmpty()) { return null; }

      CssParser p = new CssParser(tq, mq, MessageLevel.WARNING);
      input = p.parseStyleSheet();
      tq.expectEmpty();
    } else if (ContentType.HTML == type) {
      DomParser p = new DomParser(new HtmlLexer(cp), false, is, mq);
      //if (p.getTokenQueue().isEmpty()) { return null; }
      input = new Dom(p.parseFragment());
      p.getTokenQueue().expectEmpty();
View Full Code Here

    return sb.toString();
  }

  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

    return sb.toString();
  }

  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

  protected Block js(
      CharProducer cp, Criterion<Token<JsTokenType>> filt, boolean quasi)
      throws ParseException {
    JsLexer lexer = new JsLexer(cp);
    JsTokenQueue tq = new JsTokenQueue(lexer, sourceOf(cp), filt);
    Parser p = new Parser(tq, mq, quasi);
    Block b = p.parse();
    tq.expectEmpty();
    return b;
  }
View Full Code Here

TOP

Related Classes of com.google.caja.lexer.JsTokenQueue

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.