Class POParser
-
Field Summary
Modifier and TypeFieldDescriptionNext token.Current token.Generated Token Manager.Fields inherited from interface org.tweetyproject.preferences.io.POParserConstants
DEFAULT, ELEMENT, EOF, EOL, LBRA, RBRA, REL, tokenImage
-
Constructor Summary
ConstructorDescriptionPOParser()
ConstructorPOParser
(InputStream stream) Constructor with InputStream.POParser
(InputStream stream, String encoding) Constructor with InputStream and supplied encodingConstructor with reader stream.Constructor with generated Token Manager. -
Method Summary
Modifier and TypeMethodDescriptionfinal void
Disable tracing.final void
Enable tracing.Generates aParseException
that describes the parsing error that occurred.final Token
Retrieves the nextToken
from the input stream.final Token
getToken
(int index) Retrieves theToken
at a specific position relative to the current token.static void
Teststatic PreferenceOrder
<String> static PreferenceOrder
<String> Parses aPreferenceOrder
of typeString
from a given file path.void
ReInit
(InputStream stream) Reinitializes the parser with a newInputStream
.void
ReInit
(InputStream stream, String encoding) Reinitializes the parser with a newInputStream
and a specified encoding.void
Reinitializes the parser with a newReader
.void
Reinitializes the parser with a newPOParserTokenManager
.final PreferenceOrder
<String> Get a StringPreferenceOrder
-
Field Details
-
token_source
Generated Token Manager. -
token
Current token. -
jj_nt
Next token.
-
-
Constructor Details
-
POParser
public POParser()Constructor -
POParser
-
POParser
Constructor with InputStream and supplied encoding- Parameters:
stream
- inputstreamencoding
- the encoding
-
POParser
-
POParser
Constructor with generated Token Manager.- Parameters:
tm
- token manager
-
-
Method Details
-
parse
Parses aPreferenceOrder
of typeString
from a givenFile
.This method creates a
POParser
instance and parses the file to generate aPreferenceOrder<String>
. The file must contain the data in a format understood by the parser.- Parameters:
file
- The file containing the preference order data to be parsed.- Returns:
- A
PreferenceOrder<String>
parsed from the specified file. - Throws:
ParseException
- If there is an error during parsing.FileNotFoundException
- If the specified file is not found.
-
parse
public static PreferenceOrder<String> parse(String filename) throws ParseException, FileNotFoundException Parses aPreferenceOrder
of typeString
from a given file path.This method creates a
POParser
instance and parses the file at the specified file path to generate aPreferenceOrder<String>
. The file must contain the data in a format understood by the parser.- Parameters:
filename
- The file path of the preference order data to be parsed.- Returns:
- A
PreferenceOrder<String>
parsed from the file at the specified path. - Throws:
ParseException
- If there is an error during parsing.FileNotFoundException
- If the file at the specified path is not found.
-
main
-
StringPreferenceOrder
Get a StringPreferenceOrder- Returns:
- a PreferenceOrder
- Throws:
ParseException
- error
-
ReInit
Reinitializes the parser with a newInputStream
.This method reinitializes the input stream with default encoding. The internal state of the parser is reset, preparing it for parsing new data from the provided
InputStream
.- Parameters:
stream
- The newInputStream
to initialize the parser with.
-
ReInit
Reinitializes the parser with a newInputStream
and a specified encoding.This method reinitializes the input stream with the provided encoding, resetting the internal state of the parser to allow for parsing new data from the provided
InputStream
.- Parameters:
stream
- The newInputStream
to initialize the parser with.encoding
- The encoding to use for the input stream. If the encoding is unsupported, aRuntimeException
will be thrown.- Throws:
RuntimeException
- If the provided encoding is unsupported.
-
ReInit
-
ReInit
Reinitializes the parser with a newPOParserTokenManager
.This method reinitializes the token manager used by the parser, resetting the internal state of the parser to prepare it for parsing new data using the provided
POParserTokenManager
.- Parameters:
tm
- The newPOParserTokenManager
to initialize the parser with.
-
getNextToken
Retrieves the nextToken
from the input stream.This method advances the token pointer to the next token in the input stream. If the next token has already been fetched, it is used directly. Otherwise, the method requests the next token from the token source.
Additionally, it updates the state of the parser, including resetting the lookahead token kind (`jj_ntk`) and incrementing the generation counter (`jj_gen`).
- Returns:
- the next
Token
in the input stream.
-
getToken
Retrieves theToken
at a specific position relative to the current token.This method iterates over the token stream starting from the current token and advances until it reaches the specified index. If the required token has already been fetched, it will simply use it. Otherwise, it will request tokens from the token source until the desired token is reached.
- Parameters:
index
- The number of tokens forward from the current token to retrieve. For example, passing 0 will return the current token, passing 1 will return the next token, and so on.- Returns:
- The
Token
at the specified position relative to the current token.
-
generateParseException
Generates aParseException
that describes the parsing error that occurred.This method constructs a
ParseException
object that includes details about the parsing error, such as the token that caused the error, expected token sequences, and the token image for displaying informative error messages.It collects information about the tokens that were expected but not found, and uses this information to construct a detailed exception.
- Returns:
- a
ParseException
object that contains information about the parsing error.
-
enable_tracing
public final void enable_tracing()Enable tracing. -
disable_tracing
public final void disable_tracing()Disable tracing.
-