src/parser/namespace.js
function() {
    const result = this.node("namespace");
    let body;
    this.expect(this.tok.T_NAMESPACE) && this.next();
    if (this.token == "{") {
      this.currentNamespace = [""];
      body = this.next().read_top_statements();
      this.expect("}") && this.next();
      return result([""], body, true);
    } else {
      const name = this.read_namespace_name();
      if (this.token == ";") {
        this.currentNamespace = name;
        body = this.next().read_top_statements();
        this.expect(this.EOF);
        return result(name.name, body, false);
      } else if (this.token == "{") {
        this.currentNamespace = name;
        body = this.next().read_top_statements();
        this.expect("}") && this.next();
        return result(name.name, body, true);
      } else if (this.token === "(") {
        // resolve ambuiguity between namespace & function call
        name.resolution = this.ast.reference.RELATIVE_NAME;
        name.name = name.name.substring(1);
        result.destroy();
        return this.node("call")(name, this.read_function_argument_list());
      } else {
        this.error(["{", ";"]);
        // graceful mode :
        this.currentNamespace = name;
        body = this.read_top_statements();
        this.expect(this.EOF);
        return result(name, body, false);
      }
    }
  }
function() {
    const result = this.node("namespace");
    let body;
    this.expect(this.tok.T_NAMESPACE) && this.next();
    if (this.token == "{") {
      this.currentNamespace = [""];
      body = this.next().read_top_statements();
      this.expect("}") && this.next();
      return result([""], body, true);
    } else {
      const name = this.read_namespace_name();
      if (this.token == ";") {
        this.currentNamespace = name;
        body = this.next().read_top_statements();
        this.expect(this.EOF);
        return result(name.name, body, false);
      } else if (this.token == "{") {
        this.currentNamespace = name;
        body = this.next().read_top_statements();
        this.expect("}") && this.next();
        return result(name.name, body, true);
      } else if (this.token === "(") {
        // resolve ambuiguity between namespace & function call
        name.resolution = this.ast.reference.RELATIVE_NAME;
        name.name = name.name.substring(1);
        result.destroy();
        return this.node("call")(name, this.read_function_argument_list());
      } else {
        this.error(["{", ";"]);
        // graceful mode :
        this.currentNamespace = name;
        body = this.read_top_statements();
        this.expect(this.EOF);
        return result(name, body, false);
      }
    }
  }
function ( ) { const result = this . node ( "namespace" ) ; let body ; this . expect ( this . tok . T_NAMESPACE ) && this . next ( ) ; if ( this . token == "{" ) { this . currentNamespace = [ "" ] ; body = this . next ( ) . read_top_statements ( ) ; this . expect ( "}" ) && this . next ( ) ; return result ( [ "" ] , body , true ) ; } else { const name = this . read_namespace_name ( ) ; if ( this . token == ";" ) { this . currentNamespace = name ; body = this . next ( ) . read_top_statements ( ) ; this . expect ( this . EOF ) ; return result ( name . name , body , false ) ; } else if ( this . token == "{" ) { this . currentNamespace = name ; body = this . next ( ) . read_top_statements ( ) ; this . expect ( "}" ) && this . next ( ) ; return result ( name . name , body , true ) ; } else if ( this . token === "(" ) { // resolve ambuiguity between namespace & function call name . resolution = this . ast . reference . RELATIVE_NAME ; name . name = name . name . substring ( 1 ) ; result . destroy ( ) ; return this . node ( "call" ) ( name , this . read_function_argument_list ( ) ) ; } else { this . error ( [ "{" , ";" ] ) ; // graceful mode : this . currentNamespace = name ; body = this . read_top_statements ( ) ; this . expect ( this . EOF ) ; return result ( name , body , false ) ; } } }
Reads a namespace declaration block
```ebnf
namespace ::= T_NAMESPACE namespace_name? '{'
top_statements
'}'
| T_NAMESPACE namespace_name ';' top_statements
```
@see http://php.net/manual/en/language.namespaces.php
@return {Namespace}
Reads a namespace declaration block ebnf namespace :: = T_NAMESPACE namespace_name? { top_statements } | T_NAMESPACE namespace_name ; top_statements