Ejemplo n.º 1
0
 /**
  * Loads the specified CDF file.
  *
  * @param string $filename The CDF file name.
  */
 public function load($filename)
 {
     // If the file has already been loaded, skip the parsing process.
     if (in_array($filename, $this->_loaded)) {
         return;
     }
     $this->_loaded[] = $filename;
     // Initialize the parser and lexer and parse everything.
     $lexer = new Opt_Cdf_Lexer($filename);
     $parser = new Opt_Cdf_Parser($this);
     $this->_definitions = array();
     while ($lexer->yylex()) {
         if ($lexer->token != 'w') {
             $parser->doParse($lexer->token, $lexer->value);
         }
     }
     $parser->doParse(0, 0);
     // Now register everything in the manager
     foreach ($this->_definitions as $definition) {
         foreach ($definition[0] as $group) {
             $last = reset($group);
             array_shift($group);
             // Concatenate the list for the locator
             $fullyQualifiedPath = array();
             foreach ($group as $item) {
                 if ($item[0] !== null && $item[1] !== null) {
                     $fullyQualifiedPath[] = $item[0] . '#' . $item[1];
                 } elseif ($item[0] != null) {
                     $fullyQualifiedPath[] = '#' . $item[1];
                 } else {
                     $fullyQualifiedPath[] = $item[0] . '#';
                 }
             }
             // Add the format definition to the manager
             if (isset($definition[1]['data-format'])) {
                 $this->_manager->addFormat($last[0], $last[1], $definition[1]['data-format'], $fullyQualifiedPath);
             }
         }
     }
 }
Ejemplo n.º 2
0
<?php

require './cdf_parser.php';
require './cdf_lexer.php';
if (sizeof($argv) != 2) {
    die('Please specify the test file name.');
}
try {
    $lexer = new Opt_Cdf_Lexer($argv[1]);
    $parser = new Opt_Cdf_Parser();
    while ($lexer->yylex()) {
        if ($lexer->token != 'w') {
            $parser->doParse($lexer->token, $lexer->value);
        }
    }
    $parser->doParse(0, 0);
    echo "OK\n";
} catch (Exception $e) {
    die('Exception: ' . $e->getMessage() . "\n");
}