Package com.google.caja.lexer

Examples of com.google.caja.lexer.FilePosition


      if (left.simplifyForSideEffect() == null) { return right; }
    }
    Object lhs = toLiteralValue(left);
    Object rhs = toLiteralValue(right);
    if (lhs != null && rhs != null) {
      FilePosition pos = getFilePosition();
      switch (op) {
        case EQUAL: case STRICTLY_EQUAL:
        case NOT_EQUAL: case STRICTLY_NOT_EQUAL:
          boolean isStrict =  op == Operator.STRICTLY_EQUAL
              || op == Operator.STRICTLY_NOT_EQUAL;
View Full Code Here


      VarInfo<NAME, BINDING> vi = new VarInfo<NAME, BINDING>(
          origName, newName, declSite);
      vars.put(origName, vi);
      return vi;
    } else {
      FilePosition dPos = d.declaredAt;
      throw new RedeclarationException(new Message(
          RewriterMessageType.CANNOT_REDECLARE_VAR, declSite,
          MessagePart.Factory.valueOf(origName.toString()), dPos));
    }
  }
View Full Code Here

      Node node = openNodes.remove(openNodes.size() - 1).n;
      if (needsDebugData) {
        Nodes.setFilePositionFor(
            node, FilePosition.span(Nodes.getFilePositionFor(node), endPos));
        if (openNodes.size() == 1) {
          FilePosition rootPos = Nodes.getFilePositionFor(rootElement);
          if (rootPos.endCharInFile() <= 1) {
            rootPos = Nodes.getFilePositionFor(rootElement.getFirstChild());
          }
          if (rootPos.startCharInFile() <= endPos.startCharInFile()) {
            Nodes.setFilePositionFor(
                rootElement, FilePosition.span(rootPos, endPos));
          }
        }
      }
View Full Code Here

    do {
      parseDom(elementStack);
      skipTopLevelDocIgnorables(false);
    } while (!tokens.isEmpty());

    FilePosition endPos = checkEnd(elementStack);

    DocumentFragment root = elementStack.getRootElement();
    Node firstChild = root.getFirstChild();
    if (firstChild == null || firstChild.getNodeType() != Node.ELEMENT_NODE) {
      throw new ParseException(new Message(
View Full Code Here

    return fragment;
  }

  private FilePosition checkEnd(OpenElementStack elementStack)
      throws ParseException {
    FilePosition endPos = tokens.lastPosition();
    if (endPos != null) {
      endPos = FilePosition.endOf(endPos);
    } else // No lastPosition if the queue was empty.
      endPos = FilePosition.startOfFile(tokens.getInputSource());
    }
View Full Code Here

            // Try lower-casing the name to avoid HTML name fuzziness.
            String lQname = Strings.lower(qname);
            if (lQname != qname && (elNs = ns.forElementName(lQname)) != null) {
              qname = lQname;
            } else {
              FilePosition pos = Nodes.getFilePositionFor(el);
              ns = elNs = AbstractElementStack.unknownNamespace(
                  pos, ns, qname, mq);
            }
          }

          Element replacement;
          try {
            replacement = doc.createElementNS(elNs.uri, qname);
          } catch (DOMException e) {
            FilePosition pos = Nodes.getFilePositionFor(el);
            mq.addMessage(MessageType.INVALID_TAG_NAME, MessageLevel.WARNING,
                          FilePosition.startOf(pos),
                          MessagePart.Factory.valueOf(qname));
            if (!asXml) {
              // Try creating a non namespaced element as most likely so will
              // the browser.
              // At this point, we can be sure that createElement will not fail
              // because Html5ElementStack did not ignore this element.
              replacement = doc.createElement(qname);
            } else {
              throw new ParseException(new Message(
                  DomParserMessageType.IGNORING_TOKEN, pos,
                  MessagePart.Factory.valueOf("'" + qname + "'")), e);
            }
          }
          el.getParentNode().replaceChild(replacement, el);
          for (Node child; (child = el.getFirstChild()) != null; ) {
            replacement.appendChild(child);
          }
          NamedNodeMap attrs = el.getAttributes();
          while (attrs.getLength() != 0) {
            Attr a = (Attr) attrs.item(0);
            el.removeAttributeNode(a);
            replacement.setAttributeNodeNS(a);
          }
          if (needsDebugData) {
            Nodes.setFilePositionFor(replacement, Nodes.getFilePositionFor(el));
          }
          node = el = replacement;  // Return the replacement.
        } else {
          elNs = ns.forUri(el.getNamespaceURI());
          if (elNs == null) {
            FilePosition pos = Nodes.getFilePositionFor(el);
            ns = elNs = AbstractElementStack.unknownNamespace(
                pos, ns, el.getTagName(), mq);
          }
        }
        // And finally, namespace all the attributes.
View Full Code Here

        case DIRECTIVE:
          tokens.pop();
          final Function<DOMImplementation, DocumentType> maker
              = DoctypeMaker.parse(t.text);
          if (maker != null) {
            final FilePosition pos = t.pos;
            doctypeMaker = new Function<DOMImplementation, DocumentType>() {
              public DocumentType apply(DOMImplementation impl) {
                DocumentType t = maker.apply(impl);
                Nodes.setFilePositionFor(t, pos);
                return t;
View Full Code Here

    }
  }

  public static AttrValue fromAttr(
      final Attr a, HTML.Attribute attr, JobEnvelope source) {
    FilePosition pos = a.getValue() != null ?
        Nodes.getFilePositionForValue(a) : FilePosition.UNKNOWN;
    return new AttrValue(source, a, pos, attr) {
      @Override
      Expression getValueExpr() {
        return StringLiteral.valueOf(valuePos, getPlainValue());
View Full Code Here

    }
  }

  public SanitizedAttr sanitizeStringValue(AttrValue attr) {
    Expression dynamicValue = null;
    FilePosition pos = attr.valuePos;
    String value = attr.getPlainValue();
    // There are two cases for name handling.
    // 1. For names that have local scope or names that can't be mangled,
    //    we pass them through unchanged, except we deny the '__' suffix
    //    as reserved for use by the container.
View Full Code Here

  Expression sanitizeFrameTargetValue(AttrValue attr) {
    // If the guest code supplied an attribute value for 'target', we get it
    // in 'attr.src'. Otherwise, TemplateCompiler gives us an 'attr.src' with
    // a value equal to the empty string, which Domado's rewriteTargetAttribute
    // interprets to mean that the guest code did not supply a value.
    FilePosition pos = attr.valuePos;
    boolean unspecified = null !=
        attr.src.getUserData(TemplateCompiler.ATTRIBUTE_VALUE_WAS_UNSPECIFIED);
    Expression value = unspecified
        ? new NullLiteral(pos)
        : new StringLiteral(pos, attr.src.getValue());
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.