boson-php/pasm
pasm is a tiny PHP package from boson-php for working with PASM (an assembly-like format). It provides building blocks to parse, represent, and manipulate PASM code for toolchains, compilers, or code generation experiments.
Installation
composer require boson-php/pasm
Add the service provider to config/app.php under providers:
Boson\Pasm\PasmServiceProvider::class,
First Use Case: Basic Query Execution Pasm is a lightweight query builder for working with PASM (PASM Abstract Syntax Model)—likely used for parsing or generating structured queries (e.g., for a custom query language or DSL). Example:
use Boson\Pasm\Pasm;
$query = Pasm::parse('SELECT * FROM users WHERE id = 1');
// $query now contains a structured AST (Abstract Syntax Tree) for manipulation.
Where to Look First
src/Pasm.php: Core class for parsing and manipulating queries.tests/: Example usage and edge cases (if available).README.md or inline PHPDoc comments.Use Pasm to parse raw strings into structured ASTs, then modify or validate them:
$ast = Pasm::parse('UPDATE users SET name = ?', ['John']);
$ast->setField('name', 'Jane'); // Hypothetical method; verify API.
$sql = Pasm::compile($ast); // Reconstruct query.
Extend Eloquent queries by intercepting raw SQL:
// In a model or service:
$query = Pasm::parse($user->toSql());
$modifiedAst = $query->addCondition('active', true);
$user->setRawSql(Pasm::compile($modifiedAst));
Build queries programmatically:
$query = Pasm::select()
->from('users')
->where('id', '=', 1)
->where('status', 'IN', ['active', 'pending']);
$sql = Pasm::compile($query);
Use Pasm to validate user input against a schema:
$input = Pasm::parse($userInput);
if ($input->isValid()) {
// Proceed with safe query.
}
Register custom syntax or keywords:
Pasm::extend('CUSTOM_KEYWORD', function ($parser) {
// Custom logic for parsing.
});
No Official Docs
boson-php/boson, so consult its parent repo for context.var_dump($ast) or Xdebug.AST Structure Assumptions
WHERE might be nested under conditions). Inspect parsed output:
$ast = Pasm::parse('SELECT * FROM users');
print_r($ast->toArray()); // Reverse-engineer structure.
Compilation Quirks
Pasm::compile() might not handle all SQL dialects. Test with your DB (PostgreSQL, MySQL, etc.).?) may require binding separately.Thread Safety
Pasm::debug(true); // Hypothetical; check if supported.
file_put_contents(
'debug_ast.json',
json_encode(Pasm::parse($query)->toArray(), JSON_PRETTY_PRINT)
);
Custom Parsers
Override Pasm::parse() or extend the base parser class (if exposed):
class CustomPasm extends \Boson\Pasm\Pasm {
protected function parseCustomSyntax($input) { ... }
}
Compiler Hooks
If Pasm::compile() is extensible, hook into it:
Pasm::onCompile(function ($ast) {
// Modify AST before compilation.
});
Integration with Boson
Since Pasm is part of the boson-php/boson ecosystem, explore how it fits into Boson’s workflow (e.g., for API query building).
How can I help you explore Laravel packages today?