Source: ryangjchandler.co.uk

Write a Lexer in PHP with Lexical
I recently released a new PHP package called "Lexical". It provides a set of attributes and objects to build regular expression based lexers in PHP.

As somebody who enjoys experimenting with parsers and text processing, writing lexers has become a somewhat regular task for me.

Lexical provides a set of attributes that can be added to each case in the enumeration: Regex - accepts a single regular expression.

enum TokenType { #[Regex("[0-9]+")] case Number; #[Literal("+")] case Add; #[Literal("-")] case Subtract; #[Literal("*")] case Multiply; #[Literal("/")] case Divide; }
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners