Class POParser

java.lang.Object
org.tweetyproject.preferences.io.POParser
All Implemented Interfaces:
POParserConstants

public class POParser extends Object implements POParserConstants
POParser class
  • Field Details

    • token_source

      public POParserTokenManager token_source
      Generated Token Manager.
    • token

      public Token token
      Current token.
    • jj_nt

      public Token jj_nt
      Next token.
  • Constructor Details

    • POParser

      public POParser()
      Constructor
    • POParser

      public POParser(InputStream stream)
      Constructor with InputStream.
      Parameters:
      stream - inputstream
    • POParser

      public POParser(InputStream stream, String encoding)
      Constructor with InputStream and supplied encoding
      Parameters:
      stream - inputstream
      encoding - the encoding
    • POParser

      public POParser(Reader stream)
      Constructor with reader stream.
      Parameters:
      stream - reader
    • POParser

      public POParser(POParserTokenManager tm)
      Constructor with generated Token Manager.
      Parameters:
      tm - token manager
  • Method Details

    • parse

      public static PreferenceOrder<String> parse(File file) throws ParseException, FileNotFoundException
      Parses a PreferenceOrder of type String from a given File.

      This method creates a POParser instance and parses the file to generate a PreferenceOrder<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 a PreferenceOrder of type String from a given file path.

      This method creates a POParser instance and parses the file at the specified file path to generate a PreferenceOrder<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

      public static void main(String[] args)
      Test
      Parameters:
      args - the args
    • StringPreferenceOrder

      public final PreferenceOrder<String> StringPreferenceOrder() throws ParseException
      Get a StringPreferenceOrder
      Returns:
      a PreferenceOrder
      Throws:
      ParseException - error
    • ReInit

      public void ReInit(InputStream stream)
      Reinitializes the parser with a new InputStream.

      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 new InputStream to initialize the parser with.
    • ReInit

      public void ReInit(InputStream stream, String encoding)
      Reinitializes the parser with a new InputStream 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 new InputStream to initialize the parser with.
      encoding - The encoding to use for the input stream. If the encoding is unsupported, a RuntimeException will be thrown.
      Throws:
      RuntimeException - If the provided encoding is unsupported.
    • ReInit

      public void ReInit(Reader stream)
      Reinitializes the parser with a new Reader.

      This method reinitializes the input stream using a Reader and resets the internal state of the parser, allowing for parsing new data from the provided Reader.

      Parameters:
      stream - The new Reader to initialize the parser with.
    • ReInit

      public void ReInit(POParserTokenManager tm)
      Reinitializes the parser with a new POParserTokenManager.

      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 new POParserTokenManager to initialize the parser with.
    • getNextToken

      public final Token getNextToken()
      Retrieves the next Token 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

      public final Token getToken(int index)
      Retrieves the Token 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

      public ParseException generateParseException()
      Generates a ParseException 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.