2017 © Pedro Peláez
 

library lexer

image

elerium/lexer

  • Saturday, December 28, 2013
  • by Elerium
  • Repository
  • 1 Watchers
  • 0 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Elerium\Lexer Build Status

Lexical analysis tool for PHP., (*1)

Usage

Here is an example usage:, (*2)

$patterns = array(
    'number' => '[0-9]',
);

$lexer = new \Elerium\Lexer\Lexer($patterns);
$lexemes = $lexer->getLexemes('12'); // Returns two lexemes

Patterns

Pattern name should be numeric or non-numeric value. Pattern name should contains named sub patterns, marked with ?P on beginning of pattern or sub pattern, but it's important that the patterns and sub patterns names must be unique. Ignored patterns are marked with ?:., (*3)

Named patterns:, (*4)

$namedPattern = array(
    'address' => '(?P<city>[a-zA-Z]+) (?P<street>[a-zA-Z0-9]+)',
    'name' => '(?P<name>[a-zA-Z]+) (?P<surname>[a-zA-Z]+)' // error: repeating name!
);

Ignored patterns:, (*5)

$ignoredPatterns = array(
    'whitespace' => '?:\s', // lexeme won't be added to list
);

Errors

If there is no pattern exist for input, then Lexer throw Elerium\Lexer\LexerException., (*6)

$lexer = new \Elerium\Lexer\Lexer(array(
    'foo' => 'foo'
));
$lexer->getLexemes('bar'); // Invalid lexeme near 'bar' at line 1.

The Versions

28/12 2013

dev-master

9999999-dev

  Sources   Download

The Requires

  • php >=5.3.3

 

The Development Requires