Class CssScanner


  • final class CssScanner
    extends java.lang.Object
    A lexical scanner for CSS.

    Lexical errors are stored as attributes on the tokens in which they occurred. The supplied CssErrorHandler is also invoked when a lexical error occurs, so that clients can terminate the scanning by a rethrow.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      (package private) static class  CssScanner.CssEscapeMemoizer
      Memoizer for escapes at forward reader positions.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static com.google.common.base.CharMatcher A  
      private static int[] AND_LL
      The three last characters in the AND token
      private CssToken.TokenBuilder builder  
      private static int[] CDC_LL
      The two last characters in the CDC token
      private static int[] CDO_LL
      The three last characters in the CDO token
      private CssToken.CssTokenConsumer consumer  
      private char cur  
      private boolean debug  
      private CssErrorHandler errHandler  
      private CssScanner.CssEscapeMemoizer escapes  
      (package private) static com.google.common.base.CharMatcher HEXCHAR  
      private java.util.Locale locale  
      private static com.google.common.base.CharMatcher N  
      private static com.google.common.base.CharMatcher NMCHAR
      {nmchar} excluding {escape}
      private static com.google.common.base.CharMatcher NMSTART
      {nmstart} excluding {escape}
      private static int[] NOT_LL
      The three last characters in the NOT token
      private static com.google.common.base.CharMatcher NOT_WHITESPACE  
      private static com.google.common.base.CharMatcher NUM
      {num}
      private static com.google.common.base.CharMatcher NUMEND
      {num} end char cannot be period
      private static com.google.common.base.CharMatcher NUMSTART
      {num} start char can be unary operators
      private static com.google.common.base.CharMatcher O  
      private static int[] ONLY_LL
      The three last characters in the ONLY token
      private static int QNT_TOKEN_MAXLENGTH  
      private static com.google.common.base.CharMatcher QNTSTART
      start of quantities that followed after {num} excluding {escape}
      private static java.util.Map<int[],​CssToken.Type> quantities  
      (package private) static com.google.common.base.CharMatcher QUOTES  
      private CssReader reader  
      (package private) static com.google.common.base.CharMatcher TERMINATOR  
      private static com.google.common.base.CharMatcher U  
      private static com.google.common.base.CharMatcher UNARY  
      private static com.google.common.base.CharMatcher URANGECHAR  
      private static com.google.common.base.CharMatcher URANGESTART  
      private static int[] URI_LL
      The three last characters in the URI start token
      (package private) static com.google.common.base.CharMatcher WHITESPACE  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void _and()  
      private void _atkeyword()
      ATKEYWORD '@'[-]?{nmstart}{nmchar}* nmstart [_a-z]|{nonascii}|{escape} nmchar [_a-z0-9-]|{nonascii}|{escape}
      private void _cdc()  
      private void _cdo()  
      private void _classname()
      CLASSNAME "."{name} This is not part of formal lexical constructs, but seems to be safe to do at scanner level.
      private void _comment()
      Builds a comment token, excluding the leading and trailing comment tokens.
      private void _dashmatch()
      DASHMATCH |=
      private void _function()
      FUNCTION {ident}\(
      private void _hashname()
      HASHNAME "#"{name} name {nmchar}+ [_a-z0-9-]|{nonascii}|{escape}
      private void _ident()
      IDENT ([-]?{nmstart}|[--]){nmchar}*
      private void _important()
      IMPORTANT !{w}important
      private void _includes()
      INCLUDES ~=
      private void _not()  
      private void _num()  
      private void _only()  
      private void _prefixmatch()
      PREFIXMATCH ^=
      private void _quantity()
      With incoming builder containing a valid NUMBER, and next char being a valid QNTSTART, modify the type and append to the builder
      private void _string()
      string1 \"([^\n\r\f\\"]|\\{nl}|{escape})*\" string2 \'([^\n\r\f\\']|\\{nl}|{escape})*\'
      private void _substringmatch()
      SUBSTRINGMATCH *=
      private void _suffixmatch()
      SUFFIXMATCH $=
      private void _urange()
      Builds a UNICODE_RANGE token.
      private void _uri()
      URI url\({w}{string}{w}\) | url\({w}([!#$%&*-\[\]-~]|{nonascii}|{escape})*{w}\)
      private void _ws()
      Whitespace w ::= wc wc ::= #x9 | #xA | #xC | #xD | #x20
      private void append​(com.google.common.base.CharMatcher matcher)
      Parse forward and append to the TokenBuilder field all characters that match matcher, or until the next character is EOF.
      private void append​(com.google.common.base.CharMatcher matcher, CssToken.TokenBuilder builder)
      Parse forward and append to the supplied builder all characters that match matcher, or until the next character is EOF.
      private static boolean equals​(int[] a, int[] b)
      Like Arrays.equals, but does not return true when both are null.
      private static boolean equals​(int[] a, int[] b, boolean ignoreAsciiCase)
      Like Arrays.equals, but does not return true when both are null.
      private boolean forwardMatch​(java.lang.String match, boolean ignoreCase, boolean resetOnTrue)
      Check if a forward scan will equal given match string
      (package private) static int isNewLine​(int[] chars)
      Determine whether a sequence of chars begin with a CSS newline.
      private boolean isNextEscape()
      Returns true if reader next() is the start of a valid escape sequence.
      private static boolean matches​(int ch, com.google.common.base.CharMatcher matcher)
      Return true if ch matches matcher, false if not or if ch represents EOF (-1).
      private static boolean matchesOrEOF​(int ch, com.google.common.base.CharMatcher matcher)
      Return true if ch represents EOF (-1), or if it matches matcher.
      (package private) void scan()  
      private java.lang.String toString​(java.util.List<java.lang.Integer> ints)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • cur

        private char cur
      • locale

        private java.util.Locale locale
      • quantities

        private static final java.util.Map<int[],​CssToken.Type> quantities
      • WHITESPACE

        static final com.google.common.base.CharMatcher WHITESPACE
      • NOT_WHITESPACE

        private static final com.google.common.base.CharMatcher NOT_WHITESPACE
      • QUOTES

        static final com.google.common.base.CharMatcher QUOTES
      • U

        private static final com.google.common.base.CharMatcher U
      • O

        private static final com.google.common.base.CharMatcher O
      • N

        private static final com.google.common.base.CharMatcher N
      • A

        private static final com.google.common.base.CharMatcher A
      • NMSTART

        private static final com.google.common.base.CharMatcher NMSTART
        {nmstart} excluding {escape}
      • NMCHAR

        private static final com.google.common.base.CharMatcher NMCHAR
        {nmchar} excluding {escape}
      • QNTSTART

        private static final com.google.common.base.CharMatcher QNTSTART
        start of quantities that followed after {num} excluding {escape}
      • NUMEND

        private static final com.google.common.base.CharMatcher NUMEND
        {num} end char cannot be period
      • NUM

        private static final com.google.common.base.CharMatcher NUM
        {num}
      • UNARY

        private static final com.google.common.base.CharMatcher UNARY
      • NUMSTART

        private static final com.google.common.base.CharMatcher NUMSTART
        {num} start char can be unary operators
      • HEXCHAR

        static final com.google.common.base.CharMatcher HEXCHAR
      • URANGESTART

        private static final com.google.common.base.CharMatcher URANGESTART
      • URANGECHAR

        private static final com.google.common.base.CharMatcher URANGECHAR
      • TERMINATOR

        static final com.google.common.base.CharMatcher TERMINATOR
      • CDO_LL

        private static final int[] CDO_LL
        The three last characters in the CDO token
      • CDC_LL

        private static final int[] CDC_LL
        The two last characters in the CDC token
      • URI_LL

        private static final int[] URI_LL
        The three last characters in the URI start token
      • ONLY_LL

        private static final int[] ONLY_LL
        The three last characters in the ONLY token
      • NOT_LL

        private static final int[] NOT_LL
        The three last characters in the NOT token
      • AND_LL

        private static final int[] AND_LL
        The three last characters in the AND token
    • Method Detail

      • _function

        private void _function()
                        throws java.io.IOException
        FUNCTION {ident}\(
        Throws:
        java.io.IOException
      • _dashmatch

        private void _dashmatch()
                         throws java.io.IOException
        DASHMATCH |=
        Throws:
        java.io.IOException
      • _includes

        private void _includes()
                        throws java.io.IOException
        INCLUDES ~=
        Throws:
        java.io.IOException
      • _prefixmatch

        private void _prefixmatch()
                           throws java.io.IOException
        PREFIXMATCH ^=
        Throws:
        java.io.IOException
      • _suffixmatch

        private void _suffixmatch()
                           throws java.io.IOException
        SUFFIXMATCH $=
        Throws:
        java.io.IOException
      • _substringmatch

        private void _substringmatch()
                              throws java.io.IOException
        SUBSTRINGMATCH *=
        Throws:
        java.io.IOException
      • _classname

        private void _classname()
                         throws java.io.IOException,
                                CssExceptions.CssException
        CLASSNAME "."{name} This is not part of formal lexical constructs, but seems to be safe to do at scanner level. name {nmchar}+ [_a-z0-9-]|{nonascii}|{escape}
        Throws:
        CssExceptions.CssException
        java.io.IOException
      • _important

        private void _important()
        IMPORTANT !{w}important
      • _cdo

        private void _cdo()
                   throws java.io.IOException
        Throws:
        java.io.IOException
      • _quantity

        private void _quantity()
                        throws java.io.IOException,
                               CssExceptions.CssException
        With incoming builder containing a valid NUMBER, and next char being a valid QNTSTART, modify the type and append to the builder
        Throws:
        java.io.IOException
        CssExceptions.CssException
      • _and

        private void _and()
                   throws java.io.IOException
        Throws:
        java.io.IOException
      • _not

        private void _not()
                   throws java.io.IOException
        Throws:
        java.io.IOException
      • _only

        private void _only()
                    throws java.io.IOException
        Throws:
        java.io.IOException
      • _cdc

        private void _cdc()
                   throws java.io.IOException
        Throws:
        java.io.IOException
      • _ws

        private void _ws()
                  throws java.io.IOException
        Whitespace w ::= wc wc ::= #x9 | #xA | #xC | #xD | #x20
        Throws:
        java.io.IOException
      • isNextEscape

        private boolean isNextEscape()
                              throws java.io.IOException
        Returns true if reader next() is the start of a valid escape sequence.
        Returns:
        whether or not the reader is at the start of a valid escape sequence.
        Throws:
        java.io.IOException
      • append

        private void append​(com.google.common.base.CharMatcher matcher)
                     throws java.io.IOException,
                            CssExceptions.CssException
        Parse forward and append to the TokenBuilder field all characters that match matcher, or until the next character is EOF. Escapes are included verbatim if they don't match matcher, else literal.
        Throws:
        java.io.IOException
        CssExceptions.CssException
      • append

        private void append​(com.google.common.base.CharMatcher matcher,
                            CssToken.TokenBuilder builder)
                     throws java.io.IOException,
                            CssExceptions.CssException
        Parse forward and append to the supplied builder all characters that match matcher, or until the next character is EOF. Escapes are included verbatim if they don't match matcher, else literal.
        Throws:
        java.io.IOException
        CssExceptions.CssException
      • forwardMatch

        private boolean forwardMatch​(java.lang.String match,
                                     boolean ignoreCase,
                                     boolean resetOnTrue)
                              throws java.io.IOException
        Check if a forward scan will equal given match string
        Parameters:
        match - The string to match
        ignoreCase - Whether case should be ignored
        resetOnTrue - Whether the reader should be reset on found match
        Throws:
        java.io.IOException
      • toString

        private java.lang.String toString​(java.util.List<java.lang.Integer> ints)
      • equals

        private static boolean equals​(int[] a,
                                      int[] b)
        Like Arrays.equals, but does not return true when both are null.
      • equals

        private static boolean equals​(int[] a,
                                      int[] b,
                                      boolean ignoreAsciiCase)
        Like Arrays.equals, but does not return true when both are null.
        Parameters:
        ignoreAsciiCase - If true, ascii case differences are ignored.
      • matchesOrEOF

        private static boolean matchesOrEOF​(int ch,
                                            com.google.common.base.CharMatcher matcher)
        Return true if ch represents EOF (-1), or if it matches matcher.
      • matches

        private static boolean matches​(int ch,
                                       com.google.common.base.CharMatcher matcher)
        Return true if ch matches matcher, false if not or if ch represents EOF (-1).
      • isNewLine

        static int isNewLine​(int[] chars)
        Determine whether a sequence of chars begin with a CSS newline.
        Parameters:
        chars - An array with minimum two characters
        Returns:
        0 if there is no newline, else 1 or 2, representing the newline length in characters.