Home | History | Annotate | Download | only in parser
      1 // Copyright 2014 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef MediaQueryTokenizer_h
      6 #define MediaQueryTokenizer_h
      7 
      8 #include "core/css/parser/MediaQueryToken.h"
      9 #include "core/html/parser/InputStreamPreprocessor.h"
     10 #include "wtf/text/WTFString.h"
     11 
     12 #include <climits>
     13 
     14 namespace WebCore {
     15 
     16 class MediaQueryInputStream;
     17 
     18 class MediaQueryTokenizer {
     19     WTF_MAKE_NONCOPYABLE(MediaQueryTokenizer);
     20     WTF_MAKE_FAST_ALLOCATED;
     21 public:
     22     static void tokenize(String, Vector<MediaQueryToken>&);
     23 private:
     24     MediaQueryTokenizer(MediaQueryInputStream&);
     25 
     26     MediaQueryToken nextToken();
     27 
     28     UChar consume();
     29     void consume(unsigned);
     30     void reconsume(UChar);
     31 
     32     MediaQueryToken consumeNumericToken();
     33     MediaQueryToken consumeIdentLikeToken();
     34     MediaQueryToken consumeNumber();
     35     MediaQueryToken consumeStringTokenUntil(UChar);
     36 
     37     void consumeUntilNonWhitespace();
     38     bool consumeUntilCommentEndFound();
     39 
     40     bool consumeIfNext(UChar);
     41     String consumeName();
     42     UChar consumeEscape();
     43 
     44     bool nextTwoCharsAreValidEscape();
     45     bool nextCharsAreNumber(UChar);
     46     bool nextCharsAreNumber();
     47     bool nextCharsAreIdentifier(UChar);
     48     bool nextCharsAreIdentifier();
     49     MediaQueryToken blockStart(MediaQueryTokenType);
     50     MediaQueryToken blockStart(MediaQueryTokenType blockType, MediaQueryTokenType, String);
     51     MediaQueryToken blockEnd(MediaQueryTokenType, MediaQueryTokenType startType);
     52 
     53     typedef MediaQueryToken (MediaQueryTokenizer::*CodePoint)(UChar);
     54 
     55     static const CodePoint codePoints[];
     56     Vector<MediaQueryTokenType> m_blockStack;
     57 
     58     MediaQueryToken whiteSpace(UChar);
     59     MediaQueryToken leftParenthesis(UChar);
     60     MediaQueryToken rightParenthesis(UChar);
     61     MediaQueryToken leftBracket(UChar);
     62     MediaQueryToken rightBracket(UChar);
     63     MediaQueryToken leftBrace(UChar);
     64     MediaQueryToken rightBrace(UChar);
     65     MediaQueryToken plusOrFullStop(UChar);
     66     MediaQueryToken comma(UChar);
     67     MediaQueryToken hyphenMinus(UChar);
     68     MediaQueryToken asterisk(UChar);
     69     MediaQueryToken solidus(UChar);
     70     MediaQueryToken colon(UChar);
     71     MediaQueryToken semiColon(UChar);
     72     MediaQueryToken reverseSolidus(UChar);
     73     MediaQueryToken asciiDigit(UChar);
     74     MediaQueryToken nameStart(UChar);
     75     MediaQueryToken stringStart(UChar);
     76     MediaQueryToken endOfFile(UChar);
     77 
     78     MediaQueryInputStream& m_input;
     79 };
     80 
     81 
     82 
     83 } // namespace WebCore
     84 
     85 #endif // MediaQueryTokenizer_h
     86