Nushell
Get Nu!
Getting Started
  • The Nushell Book
  • Command Reference
  • Cookbook
  • Language Reference Guide
  • Contributing Guide
Blog
  • English
  • 中文
  • Deutsch
  • Français
  • Español
  • 日本語
  • Português do Brasil
  • Русский язык
GitHub
Get Nu!
Getting Started
  • The Nushell Book
  • Command Reference
  • Cookbook
  • Language Reference Guide
  • Contributing Guide
Blog
  • English
  • 中文
  • Deutsch
  • Français
  • Español
  • 日本語
  • Português do Brasil
  • Русский язык
GitHub
  • Categories

    • Bits
    • Bytes
    • Chart
    • Conversions
    • Core
    • Database
    • Dataframe
    • Dataframe Or Lazyframe
    • Date
    • Debug
    • Default
    • Env
    • Experimental
    • Expression
    • Filesystem
    • Filters
    • Formats
    • Generators
    • Hash
    • History
    • Lazyframe
    • Math
    • Misc
    • Network
    • Path
    • Platform
    • Plugin
    • Prompt
    • Random
    • Removed
    • Shells
    • Strings
    • System
    • Viewers

ast for debug

Print the abstract syntax tree (ast) for a pipeline.

Signature

> ast {flags} (pipeline)

Flags

  • --json, -j: Serialize to json
  • --minify, -m: Minify the nuon or json output
  • --flatten, -f: An easier to read version of the ast

Parameters

  • pipeline: The pipeline to print the ast for.

Input/output types:

inputoutput
nothingtable
nothingrecord
nothingstring

Examples

Print the ast of a string

> ast 'hello'

Print the ast of a pipeline

> ast 'ls | where name =~ README'

Print the ast of a pipeline with an error

> ast 'for x in 1..10 { echo $x '

Print the ast of a pipeline with an error, as json, in a nushell table

> ast 'for x in 1..10 { echo $x ' --json | get block | from json

Print the ast of a pipeline with an error, as json, minified

> ast 'for x in 1..10 { echo $x ' --json --minify

Print the ast of a string flattened

> ast "'hello'" --flatten
╭───┬─────────┬──────────────┬───────────────╮
│ # │ content │    shape     │     span      │
├───┼─────────┼──────────────┼───────────────┤
│ 0 │ 'hello' │ shape_string │ ╭───────┬───╮ │
│   │         │              │ │ start │ 0 │ │
│   │         │              │ │ end   │ 7 │ │
│   │         │              │ ╰───────┴───╯ │
╰───┴─────────┴──────────────┴───────────────╯

Print the ast of a string flattened, as json, minified

> ast "'hello'" --flatten --json --minify
[{"content":"'hello'","shape":"shape_string","span":{"start":0,"end":7}}]

Print the ast of a pipeline flattened

> ast 'ls | sort-by type name -i' --flatten
╭───┬─────────┬────────────────────┬────────────────╮
│ # │ content │       shape        │      span      │
├───┼─────────┼────────────────────┼────────────────┤
│ 0 │ ls      │ shape_external     │ ╭───────┬───╮  │
│   │         │                    │ │ start │ 0 │  │
│   │         │                    │ │ end   │ 2 │  │
│   │         │                    │ ╰───────┴───╯  │
│ 1 │ |       │ shape_pipe         │ ╭───────┬───╮  │
│   │         │                    │ │ start │ 3 │  │
│   │         │                    │ │ end   │ 4 │  │
│   │         │                    │ ╰───────┴───╯  │
│ 2 │ sort-by │ shape_internalcall │ ╭───────┬────╮ │
│   │         │                    │ │ start │ 5  │ │
│   │         │                    │ │ end   │ 12 │ │
│   │         │                    │ ╰───────┴────╯ │
│ 3 │ type    │ shape_string       │ ╭───────┬────╮ │
│   │         │                    │ │ start │ 13 │ │
│   │         │                    │ │ end   │ 17 │ │
│   │         │                    │ ╰───────┴────╯ │
│ 4 │ name    │ shape_string       │ ╭───────┬────╮ │
│   │         │                    │ │ start │ 18 │ │
│   │         │                    │ │ end   │ 22 │ │
│   │         │                    │ ╰───────┴────╯ │
│ 5 │ -i      │ shape_flag         │ ╭───────┬────╮ │
│   │         │                    │ │ start │ 23 │ │
│   │         │                    │ │ end   │ 25 │ │
│   │         │                    │ ╰───────┴────╯ │
╰───┴─────────┴────────────────────┴────────────────╯