/**
* Module containing information and strategies to 
* find/open the parse-table to use.
*
* @author Eric Bouwers
*/
module php/parse/tables

strategies
  /**
   * Opens the right parse table for parsing PHP sources.
   */
  php-open-parse-table =
    php-open-parse-table(php-front-find-table)

  /**
   * Uses the given strategy to find the parse that should be 
   * opened. Will memorize the parse table that it opens.
   *
   * @type String -> OpenParseTable
   */
  php-open-parse-table(finder) =
    PhpMemoParseTable
    <+ ?path
       ; finder
       ; tbl := <open-parse-table>
       ; rules(PhpMemoParseTable : path -> tbl)

  /**
   * Will find tha parse table that is needed in order to
   * parse the given start-symbol.
   *
   * @param String The symbol to parse
   * @type _ -> String
   */
  get-parse-table(|symbol) =
    get-base-part => base
    ; get-table-extension(|symbol) => ext
    ; <conc-strings> (base, ext)
    ; log(|Debug(), "Using parse table", <id>)

  /**
   * Constructs the base-part of the parse table to find
   * based on the version to parse.
   * 
   * @type _ -> String
   */
  get-base-part =
    OverrideParseTable
    <+ <get-config> "version"
    <+ !"PHP4"

  /**
   * Constructs the extensions based on the start-symbol to 
   * parse. The extension will be nothing or 'Test'.
   *
   * @strategy _ -> String
   */
  get-table-extension(|symbol) =
    if !symbol => "Document"
    then !".tbl"
    else !"Test.tbl"
    end

  /**
   * Forces a strategy to be evaluated under the assumption of 
   * PHP version 4.
   */
  using-php4(s) =
    {| OverrideParseTable :
      rules(OverrideParseTable : _ -> "PHP4")
      ; s
    |}     
  
  /**
   * Forces a strategy to be evaluated under the assumption of 
   * PHP version 5.
   */
  using-php5(s) =
    {| OverrideParseTable :
      rules(OverrideParseTable : _ -> "PHP5")
      ; s
    |}