Class Parser

java.lang.Object
fr.uga.pddl4j.parser.Parser
All Implemented Interfaces:
Callable<Integer>

public final class Parser extends Object implements Callable<Integer>
Implements the Parser of the PDD4L library.

A simple example of how to use the parser:

 public static void main(String[] args) {

  if (args.length == 2 && args[0].equals("-p")) {
      Parser parser = new Parser();
      try {
          parser.parse(args[1]);
        } catch (FileNotFoundException e) {
          System.out.println(e.getMessage());
        }
      if (!parser.getErrorManager().isEmpty()) {
          parser.getErrorManager().printAll();
      }
  } else if (args.length == 4 && args[0].equals("-o") && args[2].equals("-f")) {
    Parser parser = new Parser();
    try {
          parser.parse(args[1], args[3]);
        } catch (FileNotFoundException e) {
          System.out.println(e.getMessage());
        }
      if (!parser.getErrorManager().isEmpty()) {
          parser.mgr.printAll();
        }
    } else {
      System.out.println("\nusage of parser:\n");
      System.out.println("OPTIONS   DESCRIPTIONS\n");
      System.out.println("-p <str>    path for operator and fact file");
      System.out.println("-o <str>    operator file name");
      System.out.println("-f <str>    fact file name\n");
    }
 }

 
To generate the PDDL BNF accepted by the parser use the commande line:
     ./gradlew jjdoc
 
The BNF description is available in build/doc/PDD4J_BNF.
  • Field Details

    • TOTAL_COST

      public static final Symbol<String> TOTAL_COST
      The specific symbol total-costs.
    • TOTAL_TIME

      public static final Symbol<String> TOTAL_TIME
      The specific symbol total-costs.
  • Constructor Details

    • Parser

      public Parser()
      Create a new Parser.
  • Method Details

    • setDomainFile

      public final void setDomainFile(File domain)
      Sets the domain file to parse.
      Parameters:
      domain - the domain file to parse.
    • getDomainFile

      public final File getDomainFile()
      Returns the domain file to parse.
      Returns:
      the domain file to parse.
    • setProblemFile

      public final void setProblemFile(File problem)
      Sets the problem file to parse.
      Parameters:
      problem - the problem file to parse.
    • getProblemFile

      public final File getProblemFile()
      Returns the problem file to parse.
      Returns:
      the problem file to parse.
    • setLogLevel

      public final void setLogLevel(LogLevel log)
      Sets the log level of the planner.
      Parameters:
      log - the log of the planner.
      See Also:
      Level
    • getLogLevel

      public final LogLevel getLogLevel()
      Returns the log of the planner.
      Returns:
      the trace level declared of the planner.
      See Also:
      Level
    • parseDomain

      public ParsedDomain parseDomain(String domain) throws FileNotFoundException
      Parses a planning domain from a specific file path.
      Parameters:
      domain - the path to the domain file.
      Returns:
      a the pddl domain parsed or null if a lexical error or parser error occurred.
      Throws:
      FileNotFoundException - if the specified domain does not exist.
    • parseDomain

      public ParsedDomain parseDomain(File domain) throws FileNotFoundException
      Parses a planning domain from a specific file.
      Parameters:
      domain - the file that contains the planning domain.
      Returns:
      a the pddl domain parsed or null if a lexical error or parser error occurred.
      Throws:
      FileNotFoundException - if the specified domain file does not exist.
    • parseDomain

      public ParsedDomain parseDomain() throws FileNotFoundException
      Parses a planning domain from a specific file.
      Returns:
      the pddl domain parsed or null if a lexical error or parser error occurred.
      Throws:
      FileNotFoundException - if the specified domain file does not exist.
    • parseProblem

      public ParsedProblem parseProblem(String problem) throws FileNotFoundException
      Parses a planning problem from a specific file path.
      Parameters:
      problem - the path to the planning problem.
      Returns:
      a the pddl problem parsed or null if a lexical error or parser error occurred.
      Throws:
      FileNotFoundException - if the specified problem file does not exist.
    • parseProblem

      public ParsedProblem parseProblem(File problem) throws FileNotFoundException
      Parses a planning problem from a specific file.
      Parameters:
      problem - the file that contains the planning problem.
      Returns:
      a the pddl problem parsed or null if a lexical error or parser error occurred.
      Throws:
      FileNotFoundException - if the specified problem file does not exist.
    • parseProblem

      public ParsedProblem parseProblem() throws FileNotFoundException
      Parses a planning problem from a specific file.
      Returns:
      the pddl problem parsed or null if a lexical error or parser error occurred.
      Throws:
      FileNotFoundException - if the specified problem file does not exist.
    • parseDomainAndProblem

      public DefaultParsedProblem parseDomainAndProblem(String domainAndProblem) throws FileNotFoundException
      Parses a planning domain and a planning problem from the specified file path.
      Parameters:
      domainAndProblem - the path to the file that contains the planning domain and problem.
      Returns:
      the problem parsed.
      Throws:
      FileNotFoundException - if the specified file does not exist.
    • parseDomainAndProblem

      public DefaultParsedProblem parseDomainAndProblem(File domainAndProblem) throws FileNotFoundException
      Parses a planning domain and a planning problem from the specified file.
      Parameters:
      domainAndProblem - the file that contains the planning domain and problem.
      Returns:
      the problem parsed.
      Throws:
      FileNotFoundException - if the specified file does not exist.
    • parseFromString

      public void parseFromString(String domainString, String problemString) throws IOException
      Parses a planning domain and a planning problem from their respective string description.
      Parameters:
      domainString - the string that contains the planning domains.
      problemString - the string that contains the planning problem.
      Throws:
      IOException - if an error occurs while parsing.
    • parseFromString

      public void parseFromString(String domainAndProblemString) throws IOException
      Parses a planning domain and a planning problem from their respective string description.
      Parameters:
      domainAndProblemString - the string that contains the domain and planning problem.
      Throws:
      IOException - if an error occurs while parsing.
    • parseFromStream

      public void parseFromStream(InputStream inputDomainAndProblem) throws IOException
      Parses a planning domain and a planning problem from an input stream.
      Parameters:
      inputDomainAndProblem - the stream that contains the domain and planning problem.
      Throws:
      IOException - if an error occurs while parsing.
    • parseFromStream

      public void parseFromStream(InputStream inputDomain, InputStream inputProblem) throws IOException
      Parses a planning domain and a planning problem from two input streams.
      Parameters:
      inputDomain - the stream that contains the domain.
      inputProblem - the stream that contains the planning problem.
      Throws:
      IOException - if an error occurs while parsing.
    • parse

      public void parse(String domainAndProblem) throws FileNotFoundException
      Parses a planning domain and a planning problem from a file path.
      Parameters:
      domainAndProblem - the path of the file that contains the planning domain an problem.
      Throws:
      FileNotFoundException - if the specified domain or problem file does not exist.
    • parse

      public void parse(File domainAndProblem) throws FileNotFoundException
      Parses a planning domain and a planning problem from a file.
      Parameters:
      domainAndProblem - the file that contains the planning domain an problem.
      Throws:
      FileNotFoundException - if the specified domain or problem file does not exist.
    • parse

      public DefaultParsedProblem parse(String domain, String problem) throws FileNotFoundException
      Parses a planning domain and a planning problem from their respective files.
      Parameters:
      domain - the path of the file that contains the planning domains.
      problem - the path of the file that contains the planning problem.
      Returns:
      the problem parsed.
      Throws:
      FileNotFoundException - if the specified domain or problem file does not exist.
    • parse

      public DefaultParsedProblem parse(File domain, File problem) throws FileNotFoundException
      Parses a planning domain and a planning problem from their respective files.
      Parameters:
      domain - the file that contains the planning domains.
      problem - the file that contains the planning problem.
      Returns:
      the problem parsed or null if an error occurred while parsing domain or problem.
      Throws:
      FileNotFoundException - if the specified domain or problem file does not exist.
    • getErrorManager

      public ErrorManager getErrorManager()
      Returns the error manager of the parser.
      Returns:
      the error manager of the parser.
    • main

      public static void main(String[] args)
      The main method of the Parser planner.
      Parameters:
      args - the arguments of the command line.
    • call

      public Integer call()
      This method contains the code called by the main method of the planner when planner are launched from command line.
      Specified by:
      call in interface Callable<Integer>
      Returns:
      the exit return value of the planner: O if every thing is ok; 1 otherwise.