Example #1
0
 /**
  * Constructor.
  *
  * @param array $keywords
  */
 public function __construct(array $keywords)
 {
     $keywords = array_map(function ($keyword) {
         return preg_quote(strtolower($keyword), '/');
     }, $keywords);
     $regex = '/\\b(' . implode('|', array_unique($keywords)) . ')\\b/iA';
     parent::__construct($regex, Token::TYPE_KEYWORD | Token::TYPE_IDENTIFIER);
 }
Example #2
0
 /**
  * Constructor.
  *
  * @param array $constants
  */
 public function __construct(array $constants)
 {
     $constants = array_map(function ($constant) {
         return preg_quote(strtolower($constant), '/');
     }, $constants);
     $regex = '/\\b(' . implode('|', array_unique($constants)) . ')\\b/iA';
     parent::__construct($regex, Token::TYPE_CONSTANT);
 }
Example #3
0
 /**
  * Constructor.
  *
  * @param array $symbols
  */
 public function __construct(array $symbols)
 {
     // Sorts symbols to allow long symbols (e.g. "...") to be parsed before short ones (e.g. ".").
     rsort($symbols);
     $symbols = array_map(function ($symbol) {
         return preg_quote($symbol, '/');
     }, $symbols);
     $regex = '/' . implode('|', array_unique($symbols)) . '/A';
     parent::__construct($regex, Token::TYPE_SYMBOL);
 }
Example #4
0
 /**
  * Constructor.
  */
 public function __construct()
 {
     parent::__construct('/"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"/As', Token::TYPE_STRING | Token::TYPE_DOUBLE_QUOTED);
 }
Example #5
0
 /**
  * Constructor.
  */
 public function __construct()
 {
     parent::__construct('/-?([0-9]*\\.[0-9]+|[0-9]+)/A', Token::TYPE_NUMBER);
 }
Example #6
0
 /**
  * Constructor.
  */
 public function __construct()
 {
     parent::__construct('/`(?:.[^`]*)*`/UAs', Token::TYPE_STRING | Token::TYPE_BACK_QUOTED);
 }
Example #7
0
 /**
  * Constructor.
  */
 public function __construct()
 {
     parent::__construct('/\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\'/As', Token::TYPE_STRING | Token::TYPE_SINGLE_QUOTED);
 }
Example #8
0
 /**
  * Constructor.
  */
 public function __construct()
 {
     parent::__construct('/\\s+/A', Token::TYPE_WHITESPACE);
 }
Example #9
0
 /**
  * Constructor.
  */
 public function __construct()
 {
     parent::__construct('/(\\/\\*(.|\\s)*?\\*\\/)|(--\\s{1}.*)/A', Token::TYPE_COMMENT);
 }
Example #10
0
 /**
  * Constructor.
  */
 public function __construct()
 {
     parent::__construct('/[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*/A', Token::TYPE_IDENTIFIER);
 }