---
title: Lexer and parser command reference
outline: deep
---

# Command reference

The `mago ast` command is a powerful inspection tool that tokenizes and parses a single PHP file, giving you insight into its lexical and syntactical structure.

:::tip
For global options that can be used with any command, see the [Command-Line Interface overview](/fundamentals/command-line-interface.md). Remember to specify global options **before** the `ast` command.
:::

```sh
Usage: mago ast [OPTIONS] <FILE>
```

## Arguments

### `<FILE>`

**Required.** The path to the single PHP file you want to inspect.

## Options

### `--tokens`

Display the stream of raw tokens generated by the lexer instead of the parsed AST. This is useful for debugging low-level syntax issues. This can be combined with `--json` for machine-readable output.

### `--json`

Display the output (either the AST or the token stream) in a machine-readable, pretty-printed JSON format. This is ideal for integration with other tools and scripts.

### `--names`

After parsing the AST, this flag runs the name resolver and prints a list of all symbols (classes, functions, etc.) and their fully qualified names. This is useful for debugging namespace and import resolution.

### Shared Reporting Options

The `ast` command uses a shared set of options for reporting parsing errors.

[**See the Shared Reporting and Fixing Options documentation.**](/fundamentals/shared-reporting-options.md)

:::tip
The `ast` command only reports parsing errors. Auto-fixing and baseline features are not applicable to this command.
:::

### Help

| Flag, Alias(es) | Description                             |
| :-------------- | :-------------------------------------- |
| `--help`, `-h`  | Print the help summary for the command. |
