Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Parsica Laravel Package

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.

View on GitHub
Deep Wiki
Context7

title: Looking ahead

notFollowedBy

Say you want to match the print keyword in a programming language. You can express that with the string("print") parser, but it will match more than you'd like:

<?php
$print = string("print");

$result = $print->tryString("print('Hello World');");
assertEquals("print", $result->output());

$result = $print->tryString("printXYZ('Hello World');");
assertEquals("print", $result->output()); // oops!

As you can see, "printXYZ" also results in "print", but it wasn't our intention, because "printXYZ" is not a valid keyword.

We can solve it by using the notFollowedBy combinator.

<?php
$print = keepFirst(string("print"), notFollowedBy(alphaNumChar()));
$result = $print->run(new StringStream("printXYZ('Hello World');"));
assertTrue($result->isFail());

There's a fluent interface as well:

<?php
$print = string("print")->notFollowedBy(alphaNumChar());
$result = $print->run(new StringStream("printXYZ('Hello World');"));
assertTrue($result->isFail());

In practice, we'll have a lot more keywords than just the one. A good habit is to first generalize this to all the keywords in our language. Then, using our new $keyword parser constructor, we can match the exact variations we like:

<?php
$keyword = fn(string $name) => keepFirst(string($name), notFollowedBy(alphaNumChar()));

$parser = choice(
    $keyword('printf'),
    $keyword('print'),
    $keyword('sprintf')
);

$result = $parser->tryString("print('Hello World');");
assertEquals("print", $result->output());

$result = $parser->tryString("printf('Hello %s', 'world');");
assertEquals("printf", $result->output());
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport