scriptbox

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

DslToken.class.php (1119B)


      1 <?php
      2 namespace dsl;
      3 
      4 class DslToken
      5 {
      6 
      7 
      8 	const T_NONE   = 0;
      9 	const T_STRING = 1;
     10 	const T_BRACKET_OPEN = 3;
     11 	const T_BRACKET_CLOSE = 4;
     12 	const T_BLOCK_BEGIN = 5;
     13 	const T_BLOCK_END = 6;
     14 	const T_TEXT = 7;
     15 	const T_NUMBER = 8;
     16 	const T_OPERATOR = 9;
     17 	const T_FUNCTION = 10;
     18 	const T_FOR = 11;
     19 	const T_IF = 12;
     20 	const T_ELSE = 13;
     21 	const T_LET = 14;
     22 	const T_RETURN = 15;
     23 	const T_DOT = 16;
     24 	const T_STATEMENT_END = 17;
     25 	const T_NEGATION = 18;
     26 	const T_COMMA = 19;
     27 	const T_NEW = 20;
     28 	const T_THROW = 21;
     29 
     30 	public $lineNumber;
     31 	public $type;
     32 	public $value;
     33 
     34 	/**
     35 	 * DslToken constructor.
     36 	 * @param $lineNumber
     37 	 * @param $type
     38 	 * @param $value
     39 	 */
     40 	public function __construct($lineNumber, $type, $value)
     41 	{
     42 		$this->lineNumber = $lineNumber;
     43 		$this->type = $type;
     44 		$this->value = $value;
     45 	}
     46 
     47 	public function __toString()
     48 	{
     49 		return '#'.$this->lineNumber.':'.$this->type.':"'.$this->value.'"';
     50 	}
     51 
     52 
     53 	/**
     54 	 * @return bool
     55 	 */
     56 	public function isOperator( $value = null ) {
     57 		if   ( ! $value )
     58 			return $this->type == self::T_OPERATOR;
     59 
     60 		return $this->type == self::T_OPERATOR && $this->value == $value;
     61 	}
     62 }