| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /* @description     Transformation Style Sheets - Revolutionising PHP templating    * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * @author          Tom Butler [email protected]                                             * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * @copyright       2017 Tom Butler <[email protected]> | https://r.je/                      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * @license         http://www.opensource.org/licenses/bsd-license.php  BSD License * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * @version         1.2                                                             */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | namespace Transphporm\Parser\Tokenizer; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use \Transphporm\Parser\Tokenizer; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use \Transphporm\Parser\Tokens; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 11 |  |  | class BasicChars implements \Transphporm\Parser\Tokenizable { | 
            
                                                                        
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | 	public function tokenize(TokenizedString $str, Tokens $tokens) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | 		$this->newLine($str, $tokens); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | 		$this->whitespace($str, $tokens); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | 		$this->simpleTokens($str, $tokens); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 17 |  |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  | 	public function whitespace(TokenizedString $str, Tokens $tokens) { | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  | 		//Combine whitespace, this increases performance across the board: Anywhere tokens are iterated over, whitespace is only looped once 8 spaces of indentation = 1 iteration | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  | 		$char = $str->identifyChar(); | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  | 		if ($char === Tokenizer::WHITESPACE) { | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  | 			$last = $tokens->end(); | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  | 			if ($last && $last['type'] !== Tokenizer::WHITESPACE) { | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  | 				$tokens->add(['type' => $char]); | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  | 			} | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  | 		} | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | 	private function newLine(TokenizedString $str, Tokens $tokens) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | 		if ($str->identifyChar() == Tokenizer::NEW_LINE) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | 			$tokens->add(['type' => Tokenizer::WHITESPACE, 'line' => $str->newLine()]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | 		} | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 34 |  |  | 	} | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | 	private function simpleTokens($str, $tokens) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | 		$char = $str->identifyChar(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | 		if (in_array($char, [Tokenizer::ARG, Tokenizer::CONCAT, Tokenizer::DOT, Tokenizer::NOT, Tokenizer::EQUALS, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | 			Tokenizer::COLON, Tokenizer::SEMI_COLON, Tokenizer::NUM_SIGN, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | 			Tokenizer::GREATER_THAN, Tokenizer::LOWER_THAN, Tokenizer::AT_SIGN, Tokenizer::SUBTRACT, Tokenizer::MULTIPLY, Tokenizer::DIVIDE])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | 			$tokens->add(['type' => $char, 'line' => $str->lineNo()]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | 		} | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 44 |  |  | 	} | 
            
                                                                        
                                                                
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 46 |  |  | } |