PHP code example of cageis / lexer

1. Go to this page and download the library: Download cageis/lexer library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

cageis / lexer example snippets



$lexer = CageIs\Lexer\LexerFactory::create();
$tokens = $lexer->addTokenPattern(new CageIs\Lexer\TokenPattern('\d+', 'num'))
    ->addTokenPattern(new CageIs\Lexer\TokenPattern('[a-zA-Z]+', 'alpha'))
    ->setWhitespaceIgnore(true)
    ->parse("hello\n123\n^&111111")
    ->toArray();

// The results will be
[
  [
    'name' => "alpha",
    'match' => "hello",
  ],
  [
    'name' => "num",
    'match' => "123",
  ],
  [
    'name' => "Unknown",
    'match' => "^",
  ],
  [
    'name' => "Unknown",
    'match' => "&",
  ],
  [
    'name' => "num",
    'match' => "111111",
  ]
];