Package com.google.caja.lexer

Examples of com.google.caja.lexer.FilePosition


      int i = 0;
      while (i < children.size() && !(children.get(i) instanceof Declaration)) {
        ++i;
      }
      renderCommaGroup(children.subList(0, i), r);
      FilePosition selectorEnd = children.get(i - 1).getFilePosition();
      FilePosition pos = selectorEnd != null && getFilePosition() != null
          ? FilePosition.span(FilePosition.endOf(selectorEnd),
                              FilePosition.endOf(getFilePosition()))
          : null;
      renderStatements(children.subList(i, children.size()), pos, r);
    }
View Full Code Here


  public final String getSnippet(Message msg) {
    StringBuilder snippet = new StringBuilder();
    for (MessagePart mp : msg.getMessageParts()) {
      if (!(mp instanceof FilePosition)) { continue; }
      FilePosition pos = (FilePosition) mp;
      int len = snippet.length();
      if (len != 0) { snippet.append('\n'); }
      int snippetStart = snippet.length();
      try {
        appendSnippet(pos, snippet);
View Full Code Here

   */
  public ParseTreeNode parse(UriFetcher fetcher, MessageQueue mq)
      throws ParseException {
    if (type == null) { return null; // Malformed content
    CharProducer cp = getContent(fetcher);
    FilePosition p = cp.filePositionForOffsets(cp.getOffset(), cp.getLimit());
    switch (type) {
      case JS: {
        Parser parser = finder.makeJsParser(cp, mq);
        if (parser.getTokenQueue().isEmpty()) { return new Block(p); }
        return parser.parse();
View Full Code Here

    } while (true);
    return toks;
  }

  private static boolean emitTokens(Node n, List<Token<HtmlTokenType>> out) {
    FilePosition pos = Nodes.getFilePositionFor(n);
    switch (n.getNodeType()) {
      case Node.TEXT_NODE:
      case Node.CDATA_SECTION_NODE:
        out.add(Token.instance(
            Nodes.encode(n.getNodeValue()), HtmlTokenType.TEXT, pos));
        break;
      case Node.ELEMENT_NODE:
        if (IHTML.isEph(n)) { return false; }
        Element e = (Element) n;
        FilePosition spos = FilePosition.startOf(pos);
        out.add(Token.instance("<" + tagName(e), HtmlTokenType.TAGBEGIN, spos));
        FilePosition cpos = spos;
        for (Attr a : Nodes.attributesOf(e)) {
          emitTokens(a, out);
          cpos = Nodes.getFilePositionForValue(a);
        }
        cpos = FilePosition.endOf(cpos);
View Full Code Here

  }

  private static void emitEndOf(Node n, List<Token<HtmlTokenType>> out) {
    if (n instanceof Element) {
      Element e = (Element) n;
      FilePosition epos = FilePosition.endOf(Nodes.getFilePositionFor(e));
      out.add(Token.instance(
          "</" + tagName(e), HtmlTokenType.TAGBEGIN, epos));
      out.add(Token.instance(">", HtmlTokenType.TAGEND, epos));
    }
  }
View Full Code Here

    if (!scriptsPerNode.containsKey(n)) { return null; }
    Node safe;
    switch (n.getNodeType()) {
      case Node.ELEMENT_NODE:
        Element el = (Element) n;
        FilePosition pos = Nodes.getFilePositionFor(el);
        safe = doc.createElementNS(el.getNamespaceURI(), el.getTagName());
        Nodes.setFilePositionFor(safe, pos);
        bones.add(new NodeBone(src, n, safe));

        for (Node child : Nodes.childrenOf(el)) {
View Full Code Here

    }
  }

  /** Emit an inlined script. */
  private void fleshOutScriptBlock(ScriptBone bone) {
    FilePosition unk = FilePosition.UNKNOWN;

    FilePosition pos = bone.body.getFilePosition();
    String sourcePath = mc.abbreviate(pos.source());
    if (bone.source.fromCache) {
      CajoledModule scriptFromCache = (CajoledModule) bone.body;
      finishBlock();
      this.js.add(new SafeJsChunk(bone.source, scriptFromCache));
    } else {
      Block scriptToWrapAndProcess = (Block) bone.body;
      emitStatement(quasiStmt(
          ""
          + "try {"
          + "  @scriptBody;"
          + "} catch (ex___) {"
          + "  ___./*@synthetic*/ getNewModuleHandler()"
          // getNewModuleHandler is appropriate since there can't be multiple
          // module handlers in play while loadModule is being called, and all
          // these exception handlers are only reachable while control is in
          // loadModule.
          + "      ./*@synthetic*/ handleUncaughtException("
          + "          ex___, onerror, @sourceFile, @line);"
          + "}",
          // TODO(ihab.awad): Will add UncajoledModule wrapper when we no longer
          // "consolidate" all scripts in an HTML file into one Caja module.
          "scriptBody", scriptToWrapAndProcess,
          "sourceFile", StringLiteral.valueOf(unk, sourcePath),
          "line", StringLiteral.valueOf(unk, String.valueOf(pos.startLineNo()))
          ),
          false,
          bone.source);
    }
  }
View Full Code Here

   *     script block.
   */
  private void fleshOutElement(NodeBone bone, boolean splitDom) {
    Element el = (Element) bone.node;
    Element safe = (Element) bone.safeNode;
    FilePosition pos = Nodes.getFilePositionFor(el);
    ElKey elKey = ElKey.forElement(el);

    // If the element is supposed to have a FRAME_TARGET attribute, set that
    // to a safe value (the actual final value of all FRAME_TARGET attributes
    // will be assigned dynamically).
View Full Code Here

    safe.setAttributeNodeNS(safeAttr);
  }

  private void emitDynamicAttr(
      Attr a, Expression dynamicValue, JobEnvelope source) {
    FilePosition pos = Nodes.getFilePositionFor(a);
    String name = a.getName();
    // Emit a statement to attach the dynamic attribute.
    if (dynamicValue instanceof FunctionConstructor) {
      emitStatement(
          quasiStmt(
View Full Code Here

          bestRun = n - runStart;
        }
        positions = positions.subList(bestStart, bestStart + bestRun);
      }

      FilePosition min = positions.get(0), max = min;
      for (FilePosition pos : positions.subList(1, positions.size())) {
        if (min.startCharInFile() > pos.startCharInFile()) {
          min = pos;
        }
        if (max.endCharInFile() < pos.endCharInFile()) {
          max = pos;
        }
      }
      FilePosition span = FilePosition.span(min, max);
      setFilePosition(node, span);
      return Collections.singletonList(span);
    } else {
      return Collections.<FilePosition>emptyList();
    }
View Full Code Here

TOP

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

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.