| title | ast |
|---|---|
| categories | debug |
| version | 0.105.0 |
| debug | Print the abstract syntax tree (ast) for a pipeline. |
| usage | Print the abstract syntax tree (ast) for a pipeline. |
| editLink | false |
| contributors | false |
ast for debug
Print the abstract syntax tree (ast) for a pipeline.
> ast {flags} (pipeline)
--json, -j: Serialize to json--minify, -m: Minify the nuon or json output--flatten, -f: An easier to read version of the ast
pipeline: The pipeline to print the ast for.
| input | output |
|---|---|
| nothing | table |
| nothing | record |
| nothing | string |
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 │ │
│ │ │ │ ╰───────┴────╯ │
╰───┴─────────┴────────────────────┴────────────────╯