コード例 #1
0
ファイル: Dojo.php プロジェクト: Rudi9719/lucid
 public static function roll_out($object, $name, &$output)
 {
     if ($type = $object->type()) {
         $output[$name]['type'] = $type;
     }
     $keys = array('summary', 'description', 'returns', 'tags', 'exceptions');
     if ($object instanceof JavaScriptFunction) {
         $comments = new DojoCommentBlock($object->comments(), $keys, array('example'));
         foreach ($object->parameters() as $parameter) {
             $comments->add_key($parameter->name);
             $output[$name]['parameters'][$parameter->name]['name'] = $parameters->name;
             $type = '';
             if (!empty($parameter->comments)) {
                 $type = preg_replace('%(^/\\*\\s*|\\s*\\*/$)%', '', $parameter->comments[0]);
             }
             self::type_modifiers($type, $output[$name]['parameters'][$parameter->name]);
         }
         $returns = empty($output[$name]['returns']) ? array() : explode('|', $output[$name]['returns']);
         $body = new JavaScriptStatements($object->body());
         foreach ($body->prefix('return') as $return) {
             if (($pos = strrpos($return->line, '//')) !== false) {
                 $returns = array_merge($returns, preg_split('%\\s*\\|\\s*%', trim(substr($return->line, $pos + 2))));
             }
         }
         if (!empty($returns)) {
             $output[$name]['returns'] = implode('|', array_unique($returns));
         }
         foreach ($comments->all() as $key => $text) {
             if ($key == 'example') {
                 $output[$name]['examples'] = $text;
             } elseif ($key == 'returns') {
                 $output[$name]['return_summary'] = $text;
             } elseif (in_array($key, $keys)) {
                 $output[$name][$key] = $key == 'summary' ? self::format_summary($text) : $text;
             } elseif (!empty($output[$name]['parameters']) && array_key_exists($key, $output[$name]['parameters'])) {
                 list($type, $summary) = preg_split('%\\s+%', $text, 2);
                 if ($type) {
                     self::type_modifiers($type, $output[$name]['parameters'][$key]);
                     // TODO: tags
                     if ($type != $output[$name]['parameters'][$key]['type']) {
                         $summary = "{$type} {$summary}";
                     } else {
                         $output[$name]['parameters'][$key]['type'] = $type;
                     }
                 }
                 if (!empty($summary)) {
                     $output[$name]['parameters'][$key]['summary'] = self::format_summary($summary);
                 }
             }
         }
     }
 }
コード例 #2
0
ファイル: Dojo.php プロジェクト: pkdevboxy/owf-framework
 public static function roll_out($object, $name, $into_function, &$output, $new_keys = array(), $is_prototype = FALSE)
 {
     if (empty($output[$name])) {
         $output[$name] = array();
     }
     self::set_type($object, $output[$name]);
     $keys = self::$block_keys;
     $this_keys = array();
     if ($object instanceof JavaScriptObject || $object instanceof JavaScriptFunction) {
         if ($object instanceof JavaScriptObject) {
             self::roll_out_object($object, $name, $output, $keys, $is_prototype ? $name : NULL);
         } elseif ($object instanceof JavaScriptFunction) {
             $comments = new DojoCommentBlock($object->comments(), $keys, array('example'));
             $parent = $this_comment = $comments->get('this');
             if (!$parent) {
                 $parent = $name;
             } elseif ($parent == 'namespace') {
                 $parent = implode('.', array_slice(explode('.', $name), 0, -1));
             }
             $body = new JavaScriptStatements($object->body());
             foreach ($body->assignments(FALSE, $into_function) as $variable) {
                 if (substr($variable->name(), 0, 5) == 'this.') {
                     $variable_name = substr($variable->name(), 5);
                     $comments->add_key($variable_name);
                     $this_keys[] = $variable_name;
                     $full_variable_name = $parent . '.' . $variable_name;
                     if (!$this_comment) {
                         $found = FALSE;
                         if (!empty($output[$name]['prototype'])) {
                             $found = TRUE;
                             $full_variable_name = $output[$name]['prototype'] . '.' . $variable_name;
                             $output[$full_variable_name]['prototype'] = $output[$name]['prototype'];
                         }
                         if (!empty($output[$name]['instance'])) {
                             $found = TRUE;
                             $full_variable_name = $output[$name]['instance'] . '.' . $variable_name;
                             $output[$full_variable_name]['instance'] = $output[$name]['instance'];
                         }
                         if (!$found) {
                             $output[$full_variable_name]['instance'] = $name;
                         }
                     }
                     if ($variable_type = $variable->type()) {
                         if ($variable_type == 'Function') {
                             self::roll_out($variable->value(), $full_variable_name, FALSE, $output);
                         }
                         $output[$full_variable_name]['inferred_type'] = $variable_type;
                     }
                 }
             }
             $blocks = $comments->all();
             foreach ($this_keys as $key) {
                 if ($blocks[$key]) {
                     self::property_text($blocks[$key], $output[$parent . '.' . $key]);
                 }
             }
             // TODO: Look for mixins on the same sort of values
             foreach ($object->parameters() as $parameter) {
                 $comments->add_key($parameter->name);
                 $output[$name]['parameters'][$parameter->name]['name'] = $parameter->name;
                 $type = '';
                 if (!empty($parameter->comments)) {
                     $type = preg_replace('%(^/\\*\\s*|\\s*\\*/$)%', '', $parameter->comments[0]);
                 }
                 self::property_text($type, $output[$name]['parameters'][$parameter->name]);
             }
             if ($body->function_calls(TRUE, 'dojo.deprecated')) {
                 $output[$name]['deprecated'] = TRUE;
             }
             $returns = empty($output[$name]['returns']) ? array() : explode('|', $output[$name]['returns']);
             foreach ($body->prefix('return') as $return) {
                 if (($pos = strrpos($return->line, '//')) !== false) {
                     $returns = array_merge($returns, preg_split('%\\s*\\|\\s*%', trim(substr($return->line, $pos + 2))));
                 }
             }
             if (!empty($returns)) {
                 $output[$name]['returns'] = implode('|', array_unique($returns));
             }
             self::roll_out_comments($comments, $name, $keys, array(), $output);
         }
     }
     return $new_keys;
 }
コード例 #3
0
ファイル: parse.php プロジェクト: Rudi9719/lucid
<?php

require_once 'JavaScriptLanguage.php';
require_once 'JavaScriptParser.php';
require_once 'JavaScriptStatements.php';
require_once 'JavaScriptFunction.php';
if (!$argv[1]) {
    die("Enter a file name\n");
}
$parser = new JavaScriptParser(JavaScriptLanguage::tokenize(file_get_contents($argv[1])));
// print_r($parser->statements());
// die();
$package = new JavaScriptStatements($parser->statements());
$output = array();
// Handle dojo.provide calls
foreach ($package->function_calls(TRUE, 'dojo.provide') as $call) {
    if ($module = $call->arguments()->getString(0)) {
        $output['#provides'] = $module;
    }
}
// Handle dojo.require calls
foreach ($package->function_calls(TRUE, 'dojo.require') as $call) {
    if ($module = $call->arguments()->getString(0)) {
        $output['#requires'][] = array('common', $module);
    }
}
foreach ($package->function_calls(TRUE, 'dojo.mixin') as $call) {
    // TODO
}
foreach ($package->function_calls(TRUE, 'dojo.extend') as $call) {
    // TODO