Class Identifier
- java.lang.Object
-
- Torello.CSS.CSSToken
-
- Torello.CSS.Identifier
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.CharSequence,java.lang.Comparable<java.lang.CharSequence>
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 theCSSTokenizerclass. Many (but not all) of these subclasses maintain astatic-method for building instances of this class named'build'. AnyCSSToken-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.
AllCSSTokensubclasses have aCSSToken.strfield 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 atdrafts.csswg.org- See Also:
- Serialized Form
Hi-Lited Source-Code:- View Here: Torello/CSS/Identifier.java
- Open New Browser-Tab: Torello/CSS/Identifier.java
File Size: 25,505 Bytes Line Count: 565 '\n' Characters Found
-
-
Field Summary
Serializable ID Modifier and Type Field protected static longserialVersionUIDThis Data-Class' Instance-Fields Modifier and Type Field Stringidentifier
-
Method Summary
Static Builders: Build an Instance of this class Modifier and Type Method static Identifierbuild(String identStr)Verify & Identify: CSS Working-Group Implementation Modifier and Type Method static booleanstartsIdentSequence(int[] css, int sPos)Tokenize CSS: CSS Working-Group Implementation Modifier and Type Method protected static voidconsumeIdentLikeSequence(int[] css, ByRef<Integer> POS, Consumer<CSSToken> returnParsedToken, Consumer<TokenizeError> errorEncountered)protected static intconsumeIdentSequence(int[] css, int sPos, ByRef<String> identifier)Loop-Optimization Methods: 'is' & 'if' Modifier and Type Method IdentifierifIdentifier()booleanisIdentifier()-
Methods inherited from class Torello.CSS.CSSToken
asAtKeyword, asBadStr, asBadURL, asCDC, asCDO, asComment, asDelimiter, asDimension, asEOF, asFunc, asHash, asIdentifier, asNum, asPercentage, asPunct, asStr, asUnicodeRange, asURL, asWhitespace, charAt, compareTo, equals, ifAtKeyword, ifBadStr, ifBadURL, ifCDC, ifCDO, ifComment, ifDelimiter, ifDelimiter, ifDimension, ifEOF, ifFunc, ifHash, ifNum, ifPercentage, ifPunct, ifPunct, ifStr, ifUnicodeRange, ifURL, ifWhitespace, isAtKeyword, isBadStr, isBadURL, isCDC, isCDO, isComment, isDelimiter, isDelimiter, isDimension, isEOF, isFunc, isHash, isNum, isPercentage, isPunct, isPunct, isStr, isUnicodeRange, isURL, isWhitespace, length, subSequence, toString
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
-
-
-
Field Detail
-
serialVersionUID
protected static final long serialVersionUID
This fulfils the SerialVersion UID requirement for all classes that implement Java'sinterface java.io.Serializable. Using theSerializableImplementation 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, thisStringwill have the unescaped variant of theStringstored here.- Code:
- Exact Field Declaration Expression:
public final String identifier;
-
-
Method Detail
-
isIdentifier
public final boolean isIdentifier()
Description copied from class:CSSTokenLoop Optimization: This method only returnsTRUEif this is an actual instance ofIdentifier.- Overrides:
isIdentifierin classCSSToken- Returns:
- This method returns
FALSEfor all instances ofCSSToken, except when'this'instance is actually theIdentifierSubclass.
That class has overridden this method, and returnsTRUE. - See Also:
isIdentifier()
-
ifIdentifier
public final Identifier ifIdentifier()
Description copied from class:CSSTokenLoop Optimization: When this method is invoked on an instance of sub-classIdentifierthis method produces'this'instance.- Overrides:
ifIdentifierin classCSSToken- Returns:
- This method shall return
null, always, except when'this'is an actual instance ofIdentifier. When so, this method simply returns'this'. All other sub-classes of (abstract) classCSSTokeninherit this method, and therefore return null. - See Also:
ifIdentifier()
-
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 forTorello.CSSactually generate / spit-out more thanCSSTokeninstance, writing publicly available constructors is largely impossible.
The upside to this approach is that thebuildmethods and theconsumemethods share identical code. Furthermore this code is (nearly) perfectly based on the Pseudo-Code on the CSS Working-Group Website.- Parameters:
identStr- Any Java-Stringthat can be parsed into an instance ofIdentifier- Returns:
- An instance of
Identifier.
If the contents of the Input-Stringparameter'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.
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 yourself, it is here solely so that users may understand how the Tokenization-Stage operates.
These Parsing Pseudo-Code Instructions and Rail-Road Diagrams have been copied, verbatim, 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-Stringas an array of code-points.sPos- The array-index where the tokenizer is to consume its next token- Returns:
TRUEif 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 nextIdentifier-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.
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 yourself, it is here solely so that users may understand how the Tokenization-Stage operates.
These Parsing Pseudo-Code Instructions and Rail-Road Diagrams have been copied, verbatim, 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.
-
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 nextIdentifier-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.
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 yourself, it is here solely so that users may understand how the Tokenization-Stage operates.
These Parsing Pseudo-Code Instructions and Rail-Road Diagrams have been copied, verbatim, 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.
-
-