parsica-php/parsica
Parsica is a PHP parser combinator library for building custom parsers from small reusable pieces. Compose complex grammars with a fluent API, parse strings into structured results, and handle errors cleanly—ideal for DSLs, config formats, and language tooling.
The order of clauses in an or() matters. If we do the following parser definition, the parser will consume "http", even if the strings starts with "https", leaving "s://..." as the remainder.
<?php
$parser = string('http')->or(string('https'));
$input = "https://parsica.verraes.net";
$result = $parser->tryString($input);
assertEquals("http", $result->output());
assertEquals("s://parsica.verraes.net", $result->remainder());
The solution is to consider the order of or clauses:
<?php
$parser = string('https')->or(string('http'));
$input = "https://parsica.verraes.net";
$result = $parser->tryString($input);
assertEquals("https", $result->output());
assertEquals("://parsica.verraes.net", $result->remainder());
How can I help you explore Laravel packages today?