/** * @override */ protected function prev_token() { do { $t = parent::prev_token(); } while (is_array($t) && ($t[0] === T_WHITESPACE || $t[0] === T_COMMENT || $t[0] === T_DOC_COMMENT)); return $t; }
/** * Constructor */ function __construct() { // super-construct with Lex and Grammar parent::__construct(new BNFLex(), new BNFGrammar()); // set pre-compiled parse table $this->Table = new BNFParseTable(); // register custom parse nodes ... $this->register_node_class(BNF_RULES, 'BNFRulesNode'); $this->register_node_class(BNF_RULE, 'BNFRuleNode'); $this->register_node_class(BNF_EMPTY_RULE, 'BNFRuleNode'); $this->register_node_class(BNF_EXPRESSION, 'BNFExpressionNode'); $this->register_node_class(BNF_LIST, 'BNFListNode'); $this->register_node_class(BNF_TERM, 'BNFTermNode'); }
/** * Force a semicolon into the token stream before the current token and rewind to that point. * In fact we are only pretending there was a semicolon. as we should not need to rewind. * This is quicker as splicing the input is problematic due to the internal array pointer. * @return bool */ private function insert_semicolon($failtext = null) { // Remember failing token in case we insert a semicolon and it fails again if (isset($failtext) && isset($this->badtoken)) { if (isset($this->asitoken) && $this->asitoken === $this->badtoken) { return parent::fail($failtext); } $this->asitoken = $this->badtoken; } // insert semilcolon after current token $prevtok = $this->prev_token(); if (!$prevtok) { parent::fail($failtext); } // placing semicolon at imaginary column 0 $this->tok = array(';', ';', $prevtok[2], 0); $this->t = ';'; $this->newline = false; return true; }