-
Notifications
You must be signed in to change notification settings - Fork 71
The parser framework
Ioan CHIRIAC edited this page Feb 7, 2016
·
2 revisions
This parser looks a token ahead, and each function MUST consume his token.
NOTE : If you do not consume any token, then it will result in an infinite loop (maybe should handle this with a verification?) and if you don't consume the right tokens, it will result in a parse error.
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