示例#1
0
function parseFunction($ast)
{
    assert_ast_type($ast, NodeType::FUNC);
    $data = ast_node_data($ast);
    $name = parseIdentifier(ast_get($data, NodeKey::NAME));
    $args = parseExpressionList(ast_get($data, NodeKey::ARGS));
    $targs = parseTemplateArgs(ast_get($data, NodeKey::TARGS));
    $targs = is_null($targs) ? [] : $targs;
    $source = ast_node_source($ast);
    $arg_types = array_map(function ($item) {
        return $item->type();
    }, $args);
    try {
        $func = lookupFunction($name, $arg_types, $targs);
    } catch (Exception $e) {
        grokit_error('Failed to find function ' . $name . ' called from ' . $source, $e);
    }
    $info = $func->apply($args, $source);
    // If the function is deterministic and all of the expressions were constant,
    // just turn this expression into a constant.
    if ($info->is_const()) {
        $info->makeConstant();
    }
    return $info;
}
示例#2
0
 function parseImport($ast)
 {
     assert_ast_type($ast, NodeType::IMPORT);
     $lib = parseIdentifier(ast_node_data($ast));
     $source = ast_node_source($ast);
     $base_dir = getenv('GROKIT_INSTALLED_LIBRARY_PATH');
     $parts = LibraryManager::SplitNamespace($lib);
     $file = $base_dir . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $parts) . '.php';
     $result = (include_once $file);
     grokit_assert($result !== false, 'Failed to include library ' . $lib . ', no library file ' . $file . ' found ' . $source);
 }