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

Mago Laravel Package

carthage-software/mago

Mago is an extremely fast PHP linter, formatter, and static analyzer written in Rust. It brings Rust-inspired speed and reliability to PHP projects with a modern toolchain and great developer experience, plus multiple install options (script, Homebrew, Composer).

View on GitHub
Deep Wiki
Context7

title: Lexer and parser usage

Using Mago's lexer and parser

The primary way to interact with Mago's parser is through the mago ast command. It takes a single PHP file and can output its structure in several different formats.

Let's consider a simple file, example.php:

<?php

echo 'Hello, World!';

Default tree view

By default, mago ast prints a human-readable tree that visualizes the Abstract Syntax Tree (AST).

mago ast example.php

This will produce an output like this, showing the nested structure of the code:

Program
├── Statement
│   └── OpeningTag
│       └── FullOpeningTag
└── Statement
    └── Echo
        ├── Keyword
        ├── Expression
        │   └── Literal
        │       └── LiteralString "Hello, World!"
        └── Terminator ;

Token view

To see the raw token stream from the lexer, use the --tokens flag. This is useful for debugging low-level syntax issues.

mago ast example.php --tokens

This will output a table of all tokens found in the file:

  Kind                      Value                                              Span
  ───────────────────────── ────────────────────────────────────────────────── ────────────────────
  OpenTag                   "<?php"                                            [0..5]
  Whitespace                "\n\n"                                             [7..7]
  Echo                      "echo"                                             [7..11]
  Whitespace                " "                                                [12..12]
  LiteralString             "'Hello, World!'"                                  [12..27]
  Semicolon                 ";"                                                [27..28]
  Whitespace                "\n"                                               [29..29]

JSON output

For machine-readable output, you can combine the --json flag with either the default AST view or the --tokens view. This is perfect for scripting or for other tools to consume Mago's output.

mago ast example.php --json

This will produce a detailed JSON object representing the full AST.

{
  "error": null,
  "program": {
    "file_id": 9370985751100973094,
    "source_text": "<?php\n\necho 'Hello, World!';\n",
    "statements": {
      "nodes": [
        // ...
      ]
    },
    "trivia": {
      "nodes": [
        // ...
      ]
    }
  }
}

For more details on the available command-line options, see the Command Reference.

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