Skip to content

Commit f38bae6

Browse files
committed
1 parent c6bdfbf commit f38bae6

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

src/parser.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ parser.prototype.parse = function(code) {
216216
if (this.suppressErrors) {
217217
this.graceful(this.suppressErrors);
218218
}
219+
this.currentNamespace = [''];
219220
this.lexer.setInput(code);
220221
this.lexer.comment_tokens = this.extractDoc;
221222
this.length = this.lexer._input.length;

src/parser/namespace.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,25 @@ module.exports = {
1717
this.expect(this.tok.T_NAMESPACE).next();
1818
var result = this.node('namespace');
1919
if (this.token == '{') {
20+
this.currentNamespace = [''];
2021
return result([''], this.read_code_block(true));
2122
} else {
22-
// @fixme should expect {, T_STRING even if not NS_SEP
23-
if(this.token === this.tok.T_NS_SEPARATOR)
24-
this.error(['{', this.tok.T_STRING]);
23+
if(this.token === this.tok.T_NAMESPACE) this.error(['{', this.tok.T_STRING]);
2524
var name = this.read_namespace_name();
2625
if (this.token == ';') {
26+
this.currentNamespace = name;
2727
var body = this.nextWithComments().read_top_statements();
2828
this.expect(this.EOF);
2929
return result(name, body);
3030
} else if (this.token == '{') {
31+
this.currentNamespace = name;
3132
return result(name, this.read_code_block(true));
33+
} else if (this.token === '(') {
34+
// resolve ambuiguity between namespace & function call
35+
return this.node('call')(
36+
['ns', name.slice(1)]
37+
, this.read_function_argument_list()
38+
);
3239
} else {
3340
this.error(['{', ';']);
3441
}
@@ -41,6 +48,9 @@ module.exports = {
4148
* </ebnf>
4249
*/
4350
,read_namespace_name: function() {
51+
if (this.token === this.tok.T_NAMESPACE) {
52+
this.next().expect(this.tok.T_NS_SEPARATOR).next();
53+
}
4454
return this.read_list(this.tok.T_STRING, this.tok.T_NS_SEPARATOR, true);
4555
}
4656
/**

src/parser/scalar.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ module.exports = {
7676
return result(value);
7777

7878
// CONSTANTS
79+
case this.tok.T_NAMESPACE:
7980
case this.tok.T_NS_SEPARATOR:
8081
case this.tok.T_STRING:
8182
var value = this.read_namespace_name();

0 commit comments

Comments
 (0)