Package com.google.caja.lexer

Examples of com.google.caja.lexer.ParseException


        addIfNotNull(decls, parseDeclaration());
        if (!tq.checkToken(";")) { break; }
      }
      return new CssTree.DeclarationGroup(pos(m), decls);
    } catch (RuntimeException e) {
      throw new ParseException(new Message(MessageType.PARSE_ERROR,
          tq.currentPosition()), e);
    }
  }
View Full Code Here


    if (t.type == CssTokenType.SYMBOL
        && Strings.eqIgnoreCase(
        symbol, (unescape ? unescape(t) : t.text))) {
      return;
    }
    throw new ParseException(
        new Message(
            MessageType.EXPECTED_TOKEN, t.pos,
            MessagePart.Factory.valueOf(symbol),
            MessagePart.Factory.valueOf(t.text)));
  }
View Full Code Here

    Message msg = new Message(t, tolerance, parts);
    if (isTolerant) {
      mq.getMessages().add(msg);
      return null;
    } else {
      throw new ParseException(msg);
    }
  }
View Full Code Here

    FilePosition endPos = FilePosition.endOf(tokens.lastPosition());
    try {
      elementStack.finish(endPos);
    } catch (IllegalDocumentStateException ex) {
      throw new ParseException(ex.getCajaMessage(), ex);
    }

    DocumentFragment root = elementStack.getRootElement();
    Node firstChild = root.getFirstChild();
    if (firstChild == null || firstChild.getNodeType() != Node.ELEMENT_NODE) {
      throw new ParseException(new Message(
          DomParserMessageType.MISSING_DOCUMENT_ELEMENT, endPos));
    }

    // Check that there isn't any extraneous content after the root element.
    for (Node child = firstChild.getNextSibling(); child != null;
         child = child.getNextSibling()) {
      switch (child.getNodeType()) {
        case Node.COMMENT_NODE:
        case Node.DOCUMENT_TYPE_NODE:
          continue;
        case Node.TEXT_NODE:
          if ("".equals(child.getNodeValue().trim())) { continue; }
          break;
        default: break;
      }
      throw new ParseException(new Message(
          DomParserMessageType.MISPLACED_CONTENT,
          Nodes.getFilePositionFor(child)));
    }

    doc.appendChild(firstChild);
View Full Code Here

      endPos = FilePosition.startOfFile(tokens.getInputSource());
    }
    try {
      elementStack.finish(endPos);
    } catch (IllegalDocumentStateException ex) {
      throw new ParseException(ex.getCajaMessage(), ex);
    }

    DocumentFragment fragment = elementStack.getRootElement();
    if (elementStack.needsNamespaceFixup()) {
      fragment = (DocumentFragment) fixup(fragment, ns);
View Full Code Here

              // 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);
View Full Code Here

                      Nodes.getFilePositionFor(attr),
                      MessagePart.Factory.valueOf("'" + qname + "'"));
        el.removeAttributeNode(attr);
        return;
      }
      throw new ParseException(new Message(DomParserMessageType.IGNORING_TOKEN,
          Nodes.getFilePositionFor(attr),
          MessagePart.Factory.valueOf("'" + qname + "'")), e);
    }

    newAttr.setValue(attr.getValue());
View Full Code Here

              end = parseTagAttributes(t.pos, attribs, out);
            }
            try {
              out.processTag(t, end, attribs);
            } catch (IllegalDocumentStateException ex) {
              throw new ParseException(ex.getCajaMessage(), ex);
            }
          }
          return;
        case CDATA:
        case TEXT:
        case UNESCAPED:
          out.processText(t);
          return;
        case COMMENT:
          out.processComment(t);
          return;
        case IE_DR_COMMENT_BEGIN:
        case IE_DR_COMMENT_END:
          out.processComment(t);
          if (!wantsComments()) {
            mq.addMessage(DomParserMessageType
                              .NOT_IGNORING_DOWNLEVEL_REVEALED_COMMENT,
                          t.pos, MessagePart.Factory.valueOf(t.text));
          }
          break;
        default:
          throw new ParseException(new Message(
              MessageType.MALFORMED_XHTML, t.pos,
              MessagePart.Factory.valueOf(t.text)));
      }
    }
  }
View Full Code Here

      throws ParseException {
    Token<HtmlTokenType> last;
    tokloop:
    while (true) {
      if (tokens.isEmpty()) {
        throw new ParseException(
            new Message(DomParserMessageType.UNCLOSED_TAG, start));
      }
      last = tokens.peek();
      switch (last.type) {
      case TAGEND:
        tokens.advance();
        break tokloop;
      case ATTRNAME:
        AttrStub a = parseAttrib(out);
        if (a != null) { attrs.add(a); }
        break;
      default:
        throw new ParseException(new Message(
            MessageType.MALFORMED_XHTML, FilePosition.span(start, last.pos),
            MessagePart.Factory.valueOf(last.text)));
      }
    }
    return last;
View Full Code Here

            FilePosition.span(name.pos, value.pos),
            MessagePart.Factory.valueOf(name.text));
        return null;
      }
      // XML does not allow valueless attributes.
      throw new ParseException(
          new Message(MessageType.MISSING_ATTRIBUTE_VALUE,
                      value.pos, MessagePart.Factory.valueOf(value.text)));
    } else {
      value = Token.instance(name.text, HtmlTokenType.ATTRVALUE, name.pos);
    }
View Full Code Here

TOP

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

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.