Skip to content

Elerium/Lexer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Elerium\Lexer Build Status

Lexical analysis tool for PHP.

Usage

Here is an example usage:

$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 ?:.

Named patterns:

$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:

$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.

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

About

Lexical analysis tool for PHP

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published