simple-parser-example.rst 2.55 KB

Simple Parser Example

Extend the Doctrine\Common\Lexer\AbstractLexer class and implement the getCatchablePatterns, getNonCatchablePatterns, and getType methods. Here is a very simple example lexer implementation named CharacterTypeLexer. It tokenizes a string to T_UPPER, T_LOWER and``T_NUMBER`` tokens:

Use CharacterTypeLexer to extract an array of upper case characters:

The variable $upperCaseCharacters contains all of the upper case characters:

This is a simple example but it should demonstrate the low level API that can be used to build more complex parsers.