Skip to content
Ioan CHIRIAC edited this page Feb 18, 2015 · 3 revisions

This parser looks a token ahead, and each function MUST consume his token.

Main functions

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()
      ];
    }

expect

checks the current token and raise an error if not match

next

eat current token and goes to the next

text

reads token contents (when the token is a T_STRING for example)

read_list

reads a list of tokens separated with a token

Clone this wiki locally