Top Description Fields Constructors Methods
nonapi.io.github.classgraph.types

public Class Parser

extends Object
Class Inheritance
Known Direct Subclasses
nonapi.io.github.classgraph.json.JSONParser
Imports
nonapi.io.github.classgraph.json.JSONUtils

A generic PEG parser.

Field Summary

Modifier and TypeField and Description
private int
position

The current position.

private static final int
SHOW_AFTER

How much context to show after the current position.

private static final int
SHOW_BEFORE

How much context to show before the current position.

private Object
state

Extra parsing state.

private final String
string

The string being parsed.

private final StringBuilder
token

The token buffer.

Constructor Summary

AccessConstructor and Description
public
Parser(final String
The string to parse.
string
)

Construct a parser.

Method Summary

Modifier and TypeMethod and Description
public void
advance(final int
The number of character positions to advance.
numChars
)

Advance numChars character positions.

public void
appendToToken(final String
The string to append.
str
)

Append the given string to the token buffer.

public void
appendToToken(final char
The character to append.
c
)

Append the given character to the token buffer.

public String

Returns:

The current token. Resets the current token to empty.
currToken
()

Get the current token, and reset the token to empty.

public void
expect(final char
The expected character.
expectedChar
)

Expect the next character.

public char

Returns:

The next character.
getc
()

Get the next character.

public int

Returns:

the current position.
getPosition
()

Get the current position.

public String

Returns:

A string showing parsing context, for debugging.
getPositionInfo
()

Get the parsing context as a string, for debugging.

public Object

Returns:

The current value of the state object.
getState
()

Get the "state object" from the parser (can be used to parse state between parser functions).

public CharSequence

Returns:

The subsequence.
getSubsequence
(final int
The start position.
startPosition
,
final int
The end position.
endPosition
)

Return a subsequence of the input string.

public String

Returns:

The substring.
getSubstring
(final int
The start position.
startPosition
,
final int
The end position.
endPosition
)

Return a substring of the input string.

public boolean

Returns:

true if the input has not all been consumed.
hasMore
()

Check to see if there are more characters to parse.

public void
next()

Advance one character without returning the value of the character.

public char

Returns:

The next character, or '\0' if at the end of the string.
peek
()

Peek at the next character without reading it.

public void
peekExpect(final char
The expected next character.
expectedChar
)

Get the next character, throwing a ParseException if the next character is not the expected character.

public boolean

Returns:

True if the strMatch matches a substring of the remaining string starting at the current position.
peekMatches
(final String
The string to compare, starting at the current position, as a "peek" operation.
strMatch
)

Peek operator that can look ahead several characters.

public void
setPosition(final int
The position to move to.
position
)

Set the position of the parser within the string.

public Object

Returns:

The old value of the state object.
setState
(final Object
The state object.
state
)

Set the "state object" from the parser (can be used to parse state between parser functions).

public void
skipWhitespace()

Skip whitespace starting at the current position.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

positionback to summary
private int position

The current position.

SHOW_AFTERback to summary
private static final int SHOW_AFTER

How much context to show after the current position.

SHOW_BEFOREback to summary
private static final int SHOW_BEFORE

How much context to show before the current position.

stateback to summary
private Object state

Extra parsing state.

stringback to summary
private final String string

The string being parsed.

tokenback to summary
private final StringBuilder token

The token buffer.

Constructor Detail

Parserback to summary
public Parser(final String string) throws ParseException

Construct a parser.

Parameters
string:String

The string to parse.

Exceptions
ParseException:
If the string was null.

Method Detail

advanceback to summary
public void advance(final int numChars)

Advance numChars character positions.

Parameters
numChars:int

The number of character positions to advance.

Exceptions
IllegalArgumentException:
If there are insufficient characters remaining in the string.
appendToTokenback to summary
public void appendToToken(final String str)

Append the given string to the token buffer.

Parameters
str:String

The string to append.

appendToTokenback to summary
public void appendToToken(final char c)

Append the given character to the token buffer.

Parameters
c:char

The character to append.

currTokenback to summary
public String currToken()

Get the current token, and reset the token to empty.

Returns:String

The current token. Resets the current token to empty.

expectback to summary
public void expect(final char expectedChar) throws ParseException

Expect the next character.

Parameters
expectedChar:char

The expected character.

Exceptions
ParseException:
If the next character was not the expected character.
getcback to summary
public char getc() throws ParseException

Get the next character.

Returns:char

The next character.

Exceptions
ParseException:
If there were no more characters in the string.
getPositionback to summary
public int getPosition()

Get the current position.

Returns:int

the current position.

getPositionInfoback to summary
public String getPositionInfo()

Get the parsing context as a string, for debugging.

Returns:String

A string showing parsing context, for debugging.

getStateback to summary
public Object getState()

Get the "state object" from the parser (can be used to parse state between parser functions).

Returns:Object

The current value of the state object.

getSubsequenceback to summary
public CharSequence getSubsequence(final int startPosition, final int endPosition)

Return a subsequence of the input string.

Parameters
startPosition:int

The start position.

endPosition:int

The end position.

Returns:CharSequence

The subsequence.

getSubstringback to summary
public String getSubstring(final int startPosition, final int endPosition)

Return a substring of the input string.

Parameters
startPosition:int

The start position.

endPosition:int

The end position.

Returns:String

The substring.

hasMoreback to summary
public boolean hasMore()

Check to see if there are more characters to parse.

Returns:boolean

true if the input has not all been consumed.

nextback to summary
public void next()

Advance one character without returning the value of the character.

peekback to summary
public char peek()

Peek at the next character without reading it.

Returns:char

The next character, or '\0' if at the end of the string.

peekExpectback to summary
public void peekExpect(final char expectedChar) throws ParseException

Get the next character, throwing a ParseException if the next character is not the expected character.

Parameters
expectedChar:char

The expected next character.

Exceptions
ParseException:
If the next character is not the expected next character.
peekMatchesback to summary
public boolean peekMatches(final String strMatch)

Peek operator that can look ahead several characters.

Parameters
strMatch:String

The string to compare, starting at the current position, as a "peek" operation.

Returns:boolean

True if the strMatch matches a substring of the remaining string starting at the current position.

setPositionback to summary
public void setPosition(final int position)

Set the position of the parser within the string.

Parameters
position:int

The position to move to.

Exceptions
IllegalArgumentException:
If the position is out of range.
setStateback to summary
public Object setState(final Object state)

Set the "state object" from the parser (can be used to parse state between parser functions).

Parameters
state:Object

The state object.

Returns:Object

The old value of the state object.

skipWhitespaceback to summary
public void skipWhitespace()

Skip whitespace starting at the current position.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override