-
Notifications
You must be signed in to change notification settings - Fork 72
Home
Ioan CHIRIAC edited this page Feb 18, 2015
·
3 revisions
This parser looks a token ahead, and each function MUST consume his token.
A parsing example :
/**
* reading an interface
* <ebnf>
* interface ::= class_scope? T_INTERFACE T_STRING (T_EXTENDS (NAMESPACE_NAME ',')* NAMESPACE_NAME)? '{' INTERFACE_BODY '}'
* </ebnf>
*/
,read_interface: function(flag) {
var name = this.expect(tokens.T_INTERFACE)
.next()
.expect(tokens.T_STRING)
.text()
;
var propExtends = false;
if (this.next().token == tokens.T_EXTENDS) {
propExtends = this.next().read_list(
this.read_namespace_name,
','
);
}
return [
'interface'
, name
, flag
, propExtends
, this.expect('{').next().read_interface_body()
];
}
checks the current token and raise an error if not match
eat current token and goes to the next
reads token contents (when the token is a T_STRING for example)
reads a list of tokens separated with a token
-- PHP-Parser for NodeJS - Released under BSD3 - Ioan CHIRIAC - Wiki Homepage