Inheritance: extends Parser
Exemplo n.º 1
0
 public function read()
 {
     $files = $this->getFileNames();
     $this->inArguments('-v', '--version') && (print $this->getVersionContent());
     $this->inArguments('-h', '--help') && (print $this->getHelpContent());
     array_walk($files, function ($file) {
         if (!file_exists($file)) {
             echo "File [{$file}] not found";
             exit(1);
         }
         try {
             $lexer = new Tokenizer(file_get_contents($file));
             $parser = new TokenReader($lexer);
             $parser->parse();
             echo $parser->format();
         } catch (SyntaxError $e) {
             echo $e;
             exit(1);
         }
     });
 }
Exemplo n.º 2
0
function readline_callback($command)
{
    $command = trim($command);
    switch (trim($command)) {
        case ':quit':
        case ':q':
            exit;
        case 'show c':
            print_entire_license();
            goto next;
        case '':
            goto next;
        case ':clear':
            $clear = isPOSIX() ? 'clear' : 'cls';
            system($clear);
            goto next;
    }
    $lexer = new Tokenizer($command);
    $parser = new TokenReader($lexer);
    try {
        $global_scope = new Scope();
        $parser->parse();
        $parser->ast->injectScope($global_scope);
        $parser->ast->runTypeChecker();
        /* when */
        // args_have('-a', '--ast') && var_dump($parser->ast);
        /* when */
        args_have('-f', '--format') && $parser->format();
    } catch (\Exception $e) {
        echo $e;
    }
    next:
    if (isPOSIX()) {
        readline_add_history($command);
    }
    install_stream_handler();
}