Class ParserContext
java.lang.Object
proguard.classfile.attribute.signature.parsing.ParserContext
An object for storing the data of a currently running parsing operation. Wraps the input string
and also stores the current offset that is being parsed.
-
Constructor Summary
ConstructorsConstructorDescriptionParserContext(String input) Initialize a new parser context from the given input string. -
Method Summary
Modifier and TypeMethodDescriptionvoidadvance(int amount) Consume the given number of characters.chopFront(int length) Consume length characters from the input string, return them in a newly constructed string.voidcommit()Drop the last snapshot, use the currently valid parser state.intindexOf(char c) Returns first index of a given character in the remaining part of the input string.charpeekChar(int offset) Look-ahead at the input string.charpeekCharUnchecked(int offset) Same aspeekChar(int), but doesn't check for the end of the string.intvoidrevert()Reverts to the last valid snapshot.voidsnapshot()Take a snapshot of the current state of the parser.booleanstartsWith(String prefix) Tests whether the current state starts with the given string.
-
Constructor Details
-
ParserContext
Initialize a new parser context from the given input string. Used for starting a new parser pass.- Parameters:
input- The input string to parse.
-
-
Method Details
-
snapshot
public void snapshot() -
commit
public void commit()Drop the last snapshot, use the currently valid parser state. -
revert
public void revert()Reverts to the last valid snapshot. -
peekChar
Look-ahead at the input string.- Parameters:
offset- The number of characters that should be skipped. E.g. 0 means look at the currently parsed character.- Returns:
- The character at the proper offset in the input.
- Throws:
EOFException- When the read attempts to read anything past the end of the input string.
-
peekCharUnchecked
public char peekCharUnchecked(int offset) Same aspeekChar(int), but doesn't check for the end of the string. Useful in loops bounded byremainingLength()to avoid the need for a try-catch block.- Parameters:
offset- The offset of the character to look at.- Returns:
- The character at the given position.
-
advance
public void advance(int amount) Consume the given number of characters.- Parameters:
amount- The number of characters to consider parsed.
-
remainingLength
public int remainingLength()- Returns:
- The remaining length of the input string.
-
chopFront
Consume length characters from the input string, return them in a newly constructed string.- Parameters:
length- The number of characters to consume from the beginning. (The method just callsadvance(int)internally with this number.)- Returns:
- A string of length length that appears at the current position in the input.
-
startsWith
Tests whether the current state starts with the given string.- Parameters:
prefix- The prefix we are checking for.- Returns:
- True if the current input at the current offset starts with the given string.
-
indexOf
public int indexOf(char c) Returns first index of a given character in the remaining part of the input string.- Parameters:
c- The character to search for.- Returns:
- The offset of the character from the current position, or -1 if not found.
-