Package Torello.CSS

Class Identifier

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.CharSequence, java.lang.Comparable<java.lang.CharSequence>
    Direct Known Subclasses:
    AtKeyword, Func, Hash

    public class Identifier
    extends CSSToken
    implements java.lang.CharSequence, java.io.Serializable, java.lang.Comparable<java.lang.CharSequence>
    This is a Token Data-Class. It is a descendant of the root CSSToken-Class: CSSToken. Instances of the class are usually are produced by the CSSTokenizer class. Many (but not all) of these subclasses maintain a static-method for building instances of this class named 'build'. Any CSSToken-subclass that is neither a singleton-instance, nor an "Error-Subtype" should have such a builder. Singeton instances do not need builders, and the two Error-Subtype Classes can only be generated by the tokenizer.

    All CSSToken subclasses have a CSSToken.str field which contains the exact character data that was extracted and used to construct instances of this class. All sub-casses also have several "Loop Optimization" methods. These are methods that may or may not be useful in light of some of the newer additions to JDK 17 & 21 including the 'instanceof varName' conditional-expression variable-naming features.

    The algorithms used to write this tokenizer were generated based solely on the CSS Working-Group's Syntax-Documentation. This document may be viewed here: CSS Working-Group CSS-Syntax. There is an external site that maintain all thing CSS located at drafts.csswg.org
    See Also:
    Serialized Form


    • Field Detail

      • serialVersionUID

        🡇     🗕  🗗  🗖
        protected static final long serialVersionUID
        This fulfils the SerialVersion UID requirement for all classes that implement Java's interface java.io.Serializable. Using the Serializable Implementation offered by java is very easy, and can make saving program state when debugging a lot easier. It can also be used in place of more complicated systems like "hibernate" to store data as well.
        See Also:
        Constant Field Values
        Code:
        Exact Field Declaration Expression:
         protected static final long serialVersionUID = 1;
        
      • identifier

        🡅  🡇     🗕  🗗  🗖
        public final java.lang.String identifier
        This contains the unescaped text that that constitutes this identifier. Identifiers are permitted to use Escaped-Unicode Sequences. If any characters were escaped, this String will have the unescaped variant of the String stored here.
    • Method Detail

      • build

        🡅  🡇     🗕  🗗  🗖
        public static Identifier build​(java.lang.String identStr)
        Static-Builder Method for creating an instance of this class. This Static-Method is a substitute for an actual Constructor. Because many of the 'consume(...)' methods in the Token Classe for Torello.CSS actually generate / spit-out more than CSSToken instance, writing publicly available constructors is largely impossible.

        The upside to this approach is that the build methods and the consume methods share identical code. Furthermore this code is (nearly) perfectly based on the Pseudo-Code on the CSS Working-Group Website.
        Parameters:
        identStr - Any Java-String that can be parsed into an instance of Identifier
        Returns:
        An instance of Identifier.

        If the contents of the Input-String parameter 'identStr' cannot be consumed, exactly, by this class' 'consume' method, then an exception shall throw.
        Throws:
        TokenizeException - This exception may be thrown for any number of reasons involving the inability to parse input parameter 'identStr'.
      • startsIdentSequence

        🡅  🡇     🗕  🗗  🗖
        public static boolean startsIdentSequence​(int[] css,
                                                  int sPos)
        Checks whether or not the next token to consume is one of three available identifier-token, classes.

        Tokenizer: Identifier-Name Check Method, Pseudo-Code

        Making use of the CSS Parser DOES NOT require any knowledge of how the underlying Pass 1 Tokenizer actually works. Browser-War people are usually pretty convincing that parsing CSS is a "Moving Target" type of operation, not to be engaged by mere mortals.

        Below is the CSS Working Group's Identifier-Name Pseudo-Code. You may review it if you are at wit's end, and have nothing better to do. There is no need to actually invoke this method, it is here solely for informational purposes.

        These Parsing Pseudo-Code Instructions and Rail-Road Diagrams have been copied from the CSS-Working-Group Web-Site:
        https://drafts.csswg.org/css-syntax/#check-if-three-code-points-would-start-an-ident-sequence

        Check if three code points would start an ident sequence

        This section describes how to check if three code points would start an ident sequence. The algorithm described here can be called explicitly with three code points, or can be called with the input stream itself. In the latter case, the three code points in question are the current input code point and the next two input code points, in that order.

        Note: This algorithm will not consume any additional code points.

        Look at the first code point:

        U+002D HYPHEN-MINUS
        If the second code point is an ident-start code point or a U+002D HYPHEN-MINUS, or the second and third code points are a valid escape, return true. Otherwise, return false.
        ident-start code point
        Return true.
        U+005C REVERSE SOLIDUS (\)
        If the first and second code points are a valid escape, return true. Otherwise, return false.
        anything else
        Return false.
        Parameters:
        css - CSS-String as an array of code-points.
        sPos - The array-index where the tokenizer is to consume its next token
        Returns:
        TRUE if and only if the next token in the array is an identifier
      • consumeIdentSequence

        🡅  🡇     🗕  🗗  🗖
        protected static int consumeIdentSequence​
                    (int[] css,
                     int sPos,
                     ByRef<java.lang.String> identifier)
        
        This is a tokenizer method which "consumes" the next Identifier-Sequence from the input Code-Point Array.

        Tokenizer: Identifier-Sequence Consume Method, Pseudo-Code

        Making use of the CSS Parser DOES NOT require any knowledge of how the underlying Pass 1 Tokenizer actually works. Browser-War people are usually pretty convincing that parsing CSS is a "Moving Target" type of operation, not to be engaged by mere mortals.

        Below is the CSS Working Group's Identifier-Sequence Pseudo-Code. You may review it if you are at wit's end, and have nothing better to do. There is no need to actually invoke this method, it is here solely for informational purposes.

        These Parsing Pseudo-Code Instructions and Rail-Road Diagrams have been copied from the CSS-Working-Group Web-Site:
        https://drafts.csswg.org/css-syntax/#consume-an-ident-sequence

        Consume an ident sequence

        This section describes how to consume an ident sequence from a stream of code points. It returns a string containing the largest name that can be formed from adjacent code points in the stream, starting from the first.

        Note: This algorithm does not do the verification of the first few code points that are necessary to ensure the returned code points would constitute an <ident-token>. If that is the intended use, ensure that the stream starts with an ident sequence before calling this algorithm.

        Let result initially be an empty string.

        Repeatedly consume the next input code point from the stream:

        ident code point
        Append the code point to result.
        the stream starts with a valid escape
        Consume an escaped code point. Append the returned code point to result.
        anything else
        Reconsume the current input code point. Return result.
        <ident-token>
        -- - a-z A-Z _ or non-ASCII escape a-z A-Z 0-9 _ - or non-ASCII escape
      • consumeIdentLikeSequence

        🡅     🗕  🗗  🗖
        protected static void consumeIdentLikeSequence​
                    (int[] css,
                     ByRef<java.lang.Integer> POS,
                     java.util.function.Consumer<CSSToken> returnParsedToken,
                     java.util.function.Consumer<TokenizeError> errorEncountered)
        
        This is a tokenizer method which "consumes" the next Identifier-Token (or Identifier-Token Subclass) from the input Code-Point Array.

        Tokenizer: Identifier-Like-Token Consume Method, Pseudo-Code

        Making use of the CSS Parser DOES NOT require any knowledge of how the underlying Pass 1 Tokenizer actually works. Browser-War people are usually pretty convincing that parsing CSS is a "Moving Target" type of operation, not to be engaged by mere mortals.

        Below is the CSS Working Group's Identifier-Like-Token Pseudo-Code. You may review it if you are at wit's end, and have nothing better to do. There is no need to actually invoke this method, it is here solely for informational purposes.

        These Parsing Pseudo-Code Instructions and Rail-Road Diagrams have been copied from the CSS-Working-Group Web-Site:
        https://drafts.csswg.org/css-syntax/#consume-ident-like-token

        Consume an ident-like token

        This section describes how to consume an ident-like token from a stream of code points. It returns an <ident-token>, <function-token>, <url-token>, or <bad-url-token>.

        Consume an ident sequence, and let string be the result.

        If string’s value is an ASCII case-insensitive match for "url", and the next input code point is U+0028 LEFT PARENTHESIS ((), consume it. While the next two input code points are whitespace, consume the next input code point. If the next one or two input code points are U+0022 QUOTATION MARK ("), U+0027 APOSTROPHE ('), or whitespace followed by U+0022 QUOTATION MARK (") or U+0027 APOSTROPHE ('), then create a <function-token> with its value set to string and return it. Otherwise, consume a url token, and return it.

        Otherwise, if the next input code point is U+0028 LEFT PARENTHESIS ((), consume it. Create a <function-token> with its value set to string and return it.

        Otherwise, create an <ident-token> with its value set to string and return it.