Example #1
0
  /**
   * Append property value components to declaration.value, return false if fail with iter.last at
   * the the token which caused the fail.
   */
  private boolean handlePropertyValue(
      CssDeclaration declaration, CssToken start, CssTokenIterator iter, boolean isStyleAttribute) {
    // we dont worry about EOF here, throw to caller
    while (true) {

      if (start.type == CssToken.Type.IMPORTANT) {
        declaration.important = true;
      } else {
        CssConstruct cc =
            CssConstructFactory.create(
                start, iter, MATCH_SEMI_CLOSEBRACE, ContextRestrictions.PROPERTY_VALUE);
        if (cc == null) {
          return false;
        } else {
          declaration.components.add(cc);
        }
      }

      // if isStyleAttribute, then parse as declaration-list grammar,
      // i.e. no braces
      if ((isStyleAttribute && !iter.hasNext())
          || (MATCH_SEMI.apply(iter.peek()))
          || (!isStyleAttribute && MATCH_CLOSEBRACE.apply(iter.peek()))) {
        return declaration.components.size() > 0;
      } else {
        start = iter.next();
      }
    }
  }
Example #2
0
  /**
   * With start token being the first non-ignorable token inside the declaration block, iterate
   * issuing CssDeclaration objects until the block ends.
   */
  private void handleDeclarationBlock(
      CssToken start, CssTokenIterator iter, final CssContentHandler doc, CssErrorHandler err)
      throws CssException {

    while (true) {
      if (MATCH_CLOSEBRACE.apply(start)) {
        return;
      }
      CssDeclaration decl = handleDeclaration(start, iter, doc, err, false);
      try {
        if (decl != null) {
          doc.declaration(decl);
          if (debug) {
            checkState(MATCH_SEMI_CLOSEBRACE.apply(iter.last));
          }

          // continue or return: we may be at "; next decl" or "}" or ";}"
          if (MATCH_CLOSEBRACE.apply(iter.last)) {
            return;
          } else if (MATCH_SEMI.apply(iter.last) && MATCH_CLOSEBRACE.apply(iter.peek())) {
            iter.next();
            return;
          } else {
            if (debug) {
              checkState(MATCH_SEMI.apply(iter.last));
            }
            // we have ';', expect another decl
            start = iter.next(); // first token after ';'
          }

        } else {
          // #handleDeclaration returned null to signal error
          // #handleDeclaration has issued errors, we forward
          start = iter.next(MATCH_SEMI_CLOSEBRACE);
          if (MATCH_SEMI.apply(start)) {
            start = iter.next();
          }
        }
      } catch (NoSuchElementException nse) {
        err.error(
            new CssGrammarException(
                GRAMMAR_PREMATURE_EOF, iter.last.location, "';' " + Messages.get("or") + " '}'"));
        throw new PrematureEOFException();
      }
    }
  }