Beispiel #1
0
static char *
SkipAddress(char *s, int *count)
{
    char *base = s;
    int done;

    if (*count) {
	if (isComma(*s)) {
	    flt_putc(*s++);
	} else {
	    return s;
	}
    }

    if (isdigit(CharOf(*s))) {
	while (isdigit(CharOf(*s)))
	    s++;
	flt_puts(base, (int) (s - base), Number_attr);
    } else if (*s == '$') {
	flt_puts(s++, 1, Literal_attr);
    } else if (isSlash(*s)) {
	if (*s == BACKSLASH) {
	    flt_puts(s++, 1, Action_attr);
	}
	s = SkipPattern(s, &done, 0);
    } else {
	s = SkipError(s);
    }
    *count += 1;
    return s;
}
Beispiel #2
0
static void tokenizeDescriptors(const CharType* attributeStart,
    const CharType*& position,
    const CharType* attributeEnd,
    Vector<DescriptorToken>& descriptors)
{
    DescriptorTokenizerState state = Start;
    const CharType* descriptorsStart = position;
    const CharType* currentDescriptorStart = descriptorsStart;
    while (true) {
        switch (state) {
        case Start:
            if (isEOF(position, attributeEnd)) {
                appendDescriptorAndReset(attributeStart, currentDescriptorStart, attributeEnd, descriptors);
                return;
            }
            if (isComma(*position)) {
                appendDescriptorAndReset(attributeStart, currentDescriptorStart, position, descriptors);
                ++position;
                return;
            }
            if (isHTMLSpace(*position)) {
                appendDescriptorAndReset(attributeStart, currentDescriptorStart, position, descriptors);
                currentDescriptorStart = position + 1;
                state = AfterToken;
            } else if (*position == '(') {
                appendCharacter(currentDescriptorStart, position);
                state = InParenthesis;
            } else {
                appendCharacter(currentDescriptorStart, position);
            }
            break;
        case InParenthesis:
            if (isEOF(position, attributeEnd)) {
                appendDescriptorAndReset(attributeStart, currentDescriptorStart, attributeEnd, descriptors);
                return;
            }
            if (*position == ')') {
                appendCharacter(currentDescriptorStart, position);
                state = Start;
            } else {
                appendCharacter(currentDescriptorStart, position);
            }
            break;
        case AfterToken:
            if (isEOF(position, attributeEnd))
                return;
            if (!isHTMLSpace(*position)) {
                state = Start;
                currentDescriptorStart = position;
                --position;
            }
            break;
        }
        ++position;
    }
}
static void parseImageCandidatesFromSrcsetAttribute(const String& attribute, const CharType* attributeStart, unsigned length, Vector<ImageCandidate>& imageCandidates, Document* document)
{
    const CharType* position = attributeStart;
    const CharType* attributeEnd = position + length;

    while (position < attributeEnd) {
        // 4. Splitting loop: Collect a sequence of characters that are space characters or U+002C COMMA characters.
        skipWhile<CharType, isHTMLSpaceOrComma<CharType>>(position, attributeEnd);
        if (position == attributeEnd) {
            // Contrary to spec language - descriptor parsing happens on each candidate, so when we reach the attributeEnd, we can exit.
            break;
        }
        const CharType* imageURLStart = position;

        // 6. Collect a sequence of characters that are not space characters, and let that be url.
        skipUntil<CharType, isHTMLSpace<CharType>>(position, attributeEnd);
        const CharType* imageURLEnd = position;

        DescriptorParsingResult result;

        // 8. If url ends with a U+002C COMMA character (,)
        if (isComma(*(position - 1))) {
            // Remove all trailing U+002C COMMA characters from url.
            imageURLEnd = position - 1;
            reverseSkipWhile<CharType, isComma>(imageURLEnd, imageURLStart);
            ++imageURLEnd;
            // If url is empty, then jump to the step labeled splitting loop.
            if (imageURLStart == imageURLEnd)
                continue;
        } else {
            skipWhile<CharType, isHTMLSpace<CharType>>(position, attributeEnd);
            Vector<DescriptorToken> descriptorTokens;
            tokenizeDescriptors(attributeStart, position, attributeEnd, descriptorTokens);
            // Contrary to spec language - descriptor parsing happens on each candidate.
            // This is a black-box equivalent, to avoid storing descriptor lists for each candidate.
            if (!parseDescriptors(attribute, descriptorTokens, result, document)) {
                if (document) {
                    UseCounter::count(document, UseCounter::SrcsetDroppedCandidate);
                    if (document->frame())
                        document->frame()->console().addMessage(ConsoleMessage::create(OtherMessageSource, ErrorMessageLevel, String("Dropped srcset candidate ") + String(imageURLStart, imageURLEnd - imageURLStart)));
                }
                continue;
            }
        }

        ASSERT(imageURLEnd > attributeStart);
        unsigned imageURLStartingPosition = imageURLStart - attributeStart;
        ASSERT(imageURLEnd > imageURLStart);
        unsigned imageURLLength = imageURLEnd - imageURLStart;
        imageCandidates.append(ImageCandidate(attribute, imageURLStartingPosition, imageURLLength, result, ImageCandidate::SrcsetOrigin));
        // 11. Return to the step labeled splitting loop.
    }
}
static Vector<ImageCandidate> parseImageCandidatesFromSrcsetAttribute(const CharType* attributeStart, unsigned length)
{
    Vector<ImageCandidate> imageCandidates;

    const CharType* attributeEnd = attributeStart + length;

    for (const CharType* position = attributeStart; position < attributeEnd;) {
        // 4. Splitting loop: Collect a sequence of characters that are space characters or U+002C COMMA characters.
        skipWhile<CharType, isHTMLSpaceOrComma<CharType> >(position, attributeEnd);
        if (position == attributeEnd) {
            // Contrary to spec language - descriptor parsing happens on each candidate, so when we reach the attributeEnd, we can exit.
            break;
        }
        const CharType* imageURLStart = position;
        // 6. Collect a sequence of characters that are not space characters, and let that be url.

        skipUntil<CharType, isHTMLSpace<CharType> >(position, attributeEnd);
        const CharType* imageURLEnd = position;

        DescriptorParsingResult result;

        // 8. If url ends with a U+002C COMMA character (,)
        if (isComma(*(position - 1))) {
            // Remove all trailing U+002C COMMA characters from url.
            imageURLEnd = position - 1;
            reverseSkipWhile<CharType, isComma>(imageURLEnd, imageURLStart);
            ++imageURLEnd;
            // If url is empty, then jump to the step labeled splitting loop.
            if (imageURLStart == imageURLEnd)
                continue;
        } else {
            // Advancing position here (contrary to spec) to avoid an useless extra state machine step.
            // Filed a spec bug: https://github.com/ResponsiveImagesCG/picture-element/issues/189
            ++position;
            Vector<StringView> descriptorTokens;
            tokenizeDescriptors(position, attributeEnd, descriptorTokens);
            // Contrary to spec language - descriptor parsing happens on each candidate.
            // This is a black-box equivalent, to avoid storing descriptor lists for each candidate.
            if (!parseDescriptors(descriptorTokens, result))
                continue;
        }

        ASSERT(imageURLEnd > imageURLStart);
        unsigned imageURLLength = imageURLEnd - imageURLStart;
        imageCandidates.append(ImageCandidate(StringView(imageURLStart, imageURLLength), result, ImageCandidate::SrcsetOrigin));
        // 11. Return to the step labeled splitting loop.
    }
    return imageCandidates;
}
Beispiel #5
0
/* [ <expression> [, <actuals> ]] */
static Actuals *actuals(void) {
  if (isRight())
    return 0;
  Actuals *p = NEW(Actuals);
  p->first = expression();
  p->rest = 0;
  p->n = 1;

  if (isComma()) {
    consume();
    p->rest = actuals();
    p->n = p->rest->n + 1;
  }

  return p;
}
Beispiel #6
0
/* [<id> [, <formals>]] */
static Formals *formals() {
  Formals *p = 0;

  if (isId()) {
    p = NEW(Formals);
    p->first = getId();
    consume();
    p->n = 1;
    p->rest = 0;

    if (isComma()) {
      consume();
      p->rest = formals();
      if (p->rest) {
        p->n = p->rest->n + 1;
      }
    }
  }

  return p;
}
Beispiel #7
0
void Token::print() const {
	if( eol() ) std::cout << "NEWLINE" ;
	else if( eof() ) std::cout << "ENDMARKER" ;
	else if( indent() ) std::cout << "INDENT";
	else if( dedent() ) std::cout << "DEDENT";
	else if( isOpenBrace() ) std::cout << " { ";
	else if( isCloseBrace() ) std::cout << " } ";
	else if( isComma() ) std::cout << " , ";
	else if( isPeriod()) std::cout<< ".";
	else if( isEqual() ) std::cout << " == ";
	else if( isNotEqual() ) std::cout << " != ";
	else if( isLessThan() ) std::cout << " < ";
	else if( isGreaterThan() ) std::cout << " > ";
	else if( isLessThanEqual() ) std::cout << " <= ";
	else if( isGreaterThanEqual() ) std::cout << " >= ";
	else if( isOpenParen() )  std::cout << " ( " ;
	else if( isCloseParen() )  std::cout << " ) " ;
	else if( isAssignmentOperator() )  std::cout << " = ";
	else if( isColon() )  std::cout << " : " ;
	else if( isMultiplicationOperator() )  std::cout << " * " ;
	else if( isAdditionOperator() )  std::cout << " + ";
	else if( isSubtractionOperator() )  std::cout << " - ";
	else if( isModuloOperator() )  std::cout << " % ";
	else if( isDivisionOperator() )  std::cout << " / ";
	else if( isFloorDivision() ) std::cout << " // ";
	else if( isOpenBrack() ) std::cout<< "[";
	else if( isCloseBrack() ) std::cout<< "]";
	else if( isName() )  std::cout << getName();
	else if( isKeyword() ) std::cout << getKeyword();
	else if( isWholeNumber() ) std::cout << getWholeNumber();
	else if( isFloat() ) std::cout << getFloat();
	else if( isString() ) std::cout << getString();
	else if( isCall() ) std::cout << "CALL " << getName();
	else if( isSub() ) std::cout << "ARRAY SUB " << getName();
	else if( isAppend() ) std::cout << "ARRAY APPEND " << getName();
	else if( isPop() ) std::cout << "ARRAY POP " << getName();
	else std::cout << "Uninitialized token.\n";
}
Beispiel #8
0
static int
HaveAddress(char *s)
{
    return (isdigit(CharOf(*s)) || *s == '$' || isSlash(*s) || isComma(*s));
}