/** * This method return a tuple representing the token discovered. * * @access public * @param \Unicity\IO\Reader $reader the reader to be used * @return \Unicity\Lexer\Scanner\Tuple a tuple representing the token * discovered */ public function process(IO\Reader $reader) { $char = $reader->readChar($reader->position(), false); if ($char !== null && $char == $this->delimiter) { $tuple = new Lexer\Scanner\Tuple(Lexer\Scanner\TokenType::delimiter(), new Common\String($char)); $reader->skip(1); return $tuple; } return null; }
/** * This method return a tuple representing the token discovered. * * @access public * @param \Unicity\IO\Reader $reader the reader to be used * @return \Unicity\Lexer\Scanner\Tuple a tuple representing the token * discovered */ public function process(IO\Reader $reader) { $index = $reader->position(); $char = $reader->readChar($index, false); if ($char !== null && $char >= '0' && $char <= '9') { // "integer" token, "real" token, or "hexadecimal" token $type = null; $lookahead = $index; if ($char == '0') { $lookahead++; $next = $reader->readChar($lookahead, false); if ($next == 'x' or $next == 'X') { do { $lookahead++; $next = $reader->readChar($lookahead, false); } while ($next !== null && $next >= '0' && $next <= '9'); $type = Lexer\Scanner\TokenType::hexadecimal(); } else { if ($next == '.') { do { $lookahead++; $next = $reader->readChar($lookahead, false); } while ($next !== null && $next >= '0' && $next <= '9'); $type = Lexer\Scanner\TokenType::real(); } else { $type = Lexer\Scanner\TokenType::integer(); } } } else { $next = null; do { $lookahead++; $next = $reader->readChar($lookahead, false); } while ($next !== null && $next >= '0' && $next <= '9'); if ($next == '.') { do { $lookahead++; $next = $reader->readChar($lookahead, false); } while ($next !== null && $next >= '0' && $next <= '9'); $type = Lexer\Scanner\TokenType::real(); } else { $type = Lexer\Scanner\TokenType::integer(); } } $token = $reader->readRange($index, $lookahead); $tuple = new Lexer\Scanner\Tuple($type, new Common\String($token)); return $tuple; } return null; }
/** * This method return a tuple representing the token discovered. * * @access public * @param \Unicity\IO\Reader $reader the reader to be used * @return \Unicity\Lexer\Scanner\Tuple a tuple representing the token * discovered */ public function process(IO\Reader $reader) { $index = $reader->position(); $char = $reader->readChar($index, false); if ($char !== null && in_array($char, $this->whitespace)) { $lookahead = $index; do { $lookahead++; $next = $reader->readChar($lookahead, false); } while ($next !== null && in_array($next, $this->whitespace)); $token = $reader->readRange($index, $lookahead); $tuple = new Lexer\Scanner\Tuple(Lexer\Scanner\TokenType::whitespace(), new Common\String($token)); return $tuple; } return null; }
/** * This method return a tuple representing the token discovered. * * @access public * @param \Unicity\IO\Reader $reader the reader to be used * @return \Unicity\Lexer\Scanner\Tuple a tuple representing the token * discovered */ public function process(IO\Reader $reader) { $index = $reader->position(); $char = $reader->readChar($index, false); if ($char !== null && !$this->blacklist->hasValue($char)) { $lookahead = $index; do { $lookahead++; $next = $reader->readChar($lookahead, false); } while ($next !== null && !$this->blacklist->hasValue($next)); $token = $reader->readRange($index, $lookahead); $tuple = new Lexer\Scanner\Tuple(Lexer\Scanner\TokenType::keyword(), new Common\String($token)); return $tuple; } return null; }
/** * This method return a tuple representing the token discovered. * * @access public * @param \Unicity\IO\Reader $reader the reader to be used * @return \Unicity\Lexer\Scanner\Tuple a tuple representing the token * discovered */ public function process(IO\Reader $reader) { $index = $reader->position(); $char = $reader->readChar($index, false); if ($char !== null && preg_match('/^[_a-z]$/i', $char)) { $lookahead = $index; do { $lookahead++; $next = $reader->readChar($lookahead, false); } while ($next !== null && preg_match('/^[_a-z0-9]$/i', $next)); $token = $reader->readRange($index, $lookahead); $type = $this->keywords->hasValue($token) ? Lexer\Scanner\TokenType::keyword() : Lexer\Scanner\TokenType::identifier(); $tuple = new Lexer\Scanner\Tuple($type, new Common\String($token)); return $tuple; } return null; }
/** * This method returns the specified processing instruction. * * @access public * @param string $target the target name of the processing * instruction * @param integer $index the index of the processing instruction * @return array the data associated with the target * @throws Throwable\Parse\Exception indicates that an invalid token was * encountered * * @see http://msdn.microsoft.com/en-us/library/ms256173%28v=vs.110%29.aspx * @see http://www.w3schools.com/xsl/el_processing-instruction.asp * @see http://pastebin.com/x25seJPS * @see https://github.com/petertornstrand/tornstrand.com/blob/master/_posts/2008-10-21-reading-xml-processing-instruction-with-php.html * @see http://java2s.com/Tutorials/PHP/XML_Functions/PHP_xml_set_processing_instruction_handler_Function.htm * @see http://www.xml.com/pub/a/2000/09/13/xslt/ */ public function getProcessingInstruction($target, $index = 1) { $document = dom_import_simplexml($this)->ownerDocument; $xpath = new \DOMXPath($document); $instruction = trim($xpath->evaluate("string(//processing-instruction(\"{$target}\")[{$index}])")); $directives = array(); $scanner = new Lexer\Scanner(new IO\StringReader($instruction)); $scanner->addRule(new Lexer\Scanner\TokenRule\Symbol('=')); $scanner->addRule(new Lexer\Scanner\TokenRule\Keyword()); $scanner->addRule(new Lexer\Scanner\TokenRule\Literal('"')); $scanner->addRule(new Lexer\Scanner\TokenRule\Whitespace()); $state = 0; $key = null; while ($scanner->next()) { $tuple = $scanner->current(); if (Lexer\Scanner\TokenType::identifier()->__equals($tuple->type) && $state == 0) { $state = 1; $key = $tuple->token->__toString(); } else { if (Lexer\Scanner\TokenType::symbol()->__equals($tuple->type) && $state == 1) { $state = 2; } else { if (Lexer\Scanner\TokenType::literal()->__equals($tuple->type) && $state == 2) { $state = 3; $directives[$key] = $tuple->token->substring(1, $tuple->token->length() - 1)->__toString(); } else { if (Lexer\Scanner\TokenType::whitespace()->__equals($tuple->type)) { $state = 0; } else { throw new Throwable\Parse\Exception('Unable to parse processing instruction. Invalid token ":token" encountered with type ":type".', array(':token' => $tuple->token, ':type' => $tuple->type)); } } } } } return $directives; }
/** * This method return a tuple representing the token discovered. * * @access public * @param \Unicity\IO\Reader $reader the reader to be used * @return \Unicity\Lexer\Scanner\Tuple a tuple representing the token * discovered */ public function process(IO\Reader $reader) { $index = $reader->position(); $char = $reader->readChar($index, false); if ($char == $this->quotation) { $lookahead = $index + 1; $length = $reader->length() - 1; while ($lookahead <= $length) { if ($reader->readChar($lookahead, false) == $this->quotation) { if ($lookahead == $length || $reader->readChar($lookahead + 1, false) != $this->quotation) { $lookahead++; break; } $lookahead++; } $lookahead++; } $token = $reader->readRange($index, $lookahead); $tuple = new Lexer\Scanner\Tuple(Lexer\Scanner\TokenType::literal(), new Common\String($token)); return $tuple; } return null; }