Class POParser
-
Field Summary
FieldsModifier 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
ConstructorsConstructorDescriptionPOParser()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 voidDisable tracing.final voidEnable tracing.Generates aParseExceptionthat describes the parsing error that occurred.final TokenRetrieves the nextTokenfrom the input stream.final TokengetToken(int index) Retrieves theTokenat a specific position relative to the current token.static voidTeststatic PreferenceOrder<String> static PreferenceOrder<String> Parses aPreferenceOrderof typeStringfrom a given file path.voidReInit(InputStream stream) Reinitializes the parser with a newInputStream.voidReInit(InputStream stream, String encoding) Reinitializes the parser with a newInputStreamand a specified encoding.voidReinitializes the parser with a newReader.voidReinitializes 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 aPreferenceOrderof typeStringfrom a givenFile.This method creates a
POParserinstance 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 aPreferenceOrderof typeStringfrom a given file path.This method creates a
POParserinstance 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 newInputStreamto initialize the parser with.
-
ReInit
Reinitializes the parser with a newInputStreamand 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 newInputStreamto initialize the parser with.encoding- The encoding to use for the input stream. If the encoding is unsupported, aRuntimeExceptionwill 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 newPOParserTokenManagerto initialize the parser with.
-
getNextToken
Retrieves the nextTokenfrom 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
Tokenin the input stream.
-
getToken
Retrieves theTokenat 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
Tokenat the specified position relative to the current token.
-
generateParseException
Generates aParseExceptionthat describes the parsing error that occurred.This method constructs a
ParseExceptionobject 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
ParseExceptionobject 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.
-