enterprise/syn-serde/examples/json2rust/json2rust_main.json
2020-02-17 06:09:45 -06:00

1147 lines
34 KiB
JSON

{
"attrs": [
{
"style": "inner",
"path": {
"segments": [
{
"ident": "warn"
}
]
},
"tokens": [
{
"group": {
"delimiter": "parenthesis",
"stream": [
{
"ident": "rust_2018_idioms"
}
]
}
}
]
}
],
"items": [
{
"use": {
"tree": {
"path": {
"ident": "quote",
"tree": {
"ident": "ToTokens"
}
}
}
}
},
{
"use": {
"tree": {
"path": {
"ident": "std",
"tree": {
"group": [
{
"ident": "env"
},
{
"ident": "fs"
},
{
"path": {
"ident": "io",
"tree": {
"group": [
{
"ident": "self"
},
{
"ident": "BufWriter"
},
{
"ident": "Write"
}
]
}
}
},
{
"path": {
"ident": "path",
"tree": {
"ident": "PathBuf"
}
}
},
{
"path": {
"ident": "process",
"tree": {
"group": [
{
"ident": "Command"
},
{
"ident": "Stdio"
}
]
}
}
}
]
}
}
}
}
},
{
"use": {
"tree": {
"path": {
"ident": "syn_serde",
"tree": {
"ident": "json"
}
}
}
}
},
{
"use": {
"tree": {
"path": {
"ident": "tempfile",
"tree": {
"ident": "Builder"
}
}
}
}
},
{
"type": {
"ident": "Result",
"generics": {
"params": [
{
"type": {
"ident": "T"
}
}
]
},
"ty": {
"path": {
"segments": [
{
"ident": "std"
},
{
"ident": "result"
},
{
"ident": "Result",
"arguments": {
"angle_bracketed": {
"args": [
{
"type": {
"path": {
"segments": [
{
"ident": "T"
}
]
}
}
},
{
"type": {
"path": {
"segments": [
{
"ident": "Box",
"arguments": {
"angle_bracketed": {
"args": [
{
"type": {
"trait_object": {
"dyn": true,
"bounds": [
{
"trait": {
"path": {
"segments": [
{
"ident": "std"
},
{
"ident": "error"
},
{
"ident": "Error"
}
]
}
}
}
]
}
}
}
]
}
}
}
]
}
}
}
]
}
}
}
]
}
}
}
},
{
"fn": {
"ident": "main",
"inputs": [],
"output": null,
"stmts": [
{
"expr": {
"if": {
"cond": {
"let": {
"pat": {
"tuple_struct": {
"path": {
"segments": [
{
"ident": "Err"
}
]
},
"pat": {
"elems": [
{
"ident": {
"ident": "e"
}
}
]
}
}
},
"expr": {
"call": {
"func": {
"path": {
"segments": [
{
"ident": "try_main"
}
]
}
},
"args": []
}
}
}
},
"then_branch": [
{
"semi": {
"macro": {
"path": {
"segments": [
{
"ident": "eprintln"
}
]
},
"delimiter": "paren",
"tokens": [
{
"lit": "\"{}\""
},
{
"punct": {
"op": ",",
"spacing": "alone"
}
},
{
"ident": "e"
}
]
}
}
},
{
"semi": {
"call": {
"func": {
"path": {
"segments": [
{
"ident": "std"
},
{
"ident": "process"
},
{
"ident": "exit"
}
]
}
},
"args": [
{
"lit": {
"int": "1"
}
}
]
}
}
}
]
}
}
}
]
}
},
{
"fn": {
"ident": "try_main",
"inputs": [],
"output": {
"path": {
"segments": [
{
"ident": "Result",
"arguments": {
"angle_bracketed": {
"args": [
{
"type": {
"tuple": {
"elems": []
}
}
}
]
}
}
}
]
}
},
"stmts": [
{
"let": {
"pat": {
"ident": {
"mut": true,
"ident": "args"
}
},
"init": {
"call": {
"func": {
"path": {
"segments": [
{
"ident": "env"
},
{
"ident": "args_os"
}
]
}
},
"args": []
}
}
}
},
{
"let": {
"pat": {
"_": {}
},
"init": {
"method_call": {
"receiver": {
"path": {
"segments": [
{
"ident": "args"
}
]
}
},
"method": "next",
"args": []
}
}
}
},
{
"let": {
"pat": {
"ident": {
"ident": "filepath"
}
},
"init": {
"match": {
"expr": {
"tuple": {
"elems": [
{
"method_call": {
"receiver": {
"path": {
"segments": [
{
"ident": "args"
}
]
}
},
"method": "next",
"args": []
}
},
{
"method_call": {
"receiver": {
"path": {
"segments": [
{
"ident": "args"
}
]
}
},
"method": "next",
"args": []
}
}
]
}
},
"arms": [
{
"pat": {
"tuple": {
"elems": [
{
"tuple_struct": {
"path": {
"segments": [
{
"ident": "Some"
}
]
},
"pat": {
"elems": [
{
"ident": {
"ident": "arg1"
}
}
]
}
}
},
{
"ident": {
"ident": "None"
}
}
]
}
},
"body": {
"call": {
"func": {
"path": {
"segments": [
{
"ident": "PathBuf"
},
{
"ident": "from"
}
]
}
},
"args": [
{
"path": {
"segments": [
{
"ident": "arg1"
}
]
}
}
]
}
}
},
{
"pat": {
"_": {}
},
"body": {
"block": {
"stmts": [
{
"semi": {
"macro": {
"path": {
"segments": [
{
"ident": "println"
}
]
},
"delimiter": "paren",
"tokens": [
{
"lit": "\"Usage: rust2json path/to/filename.rs\""
}
]
}
}
},
{
"semi": {
"return": {
"expr": {
"call": {
"func": {
"path": {
"segments": [
{
"ident": "Ok"
}
]
}
},
"args": [
{
"tuple": {
"elems": []
}
}
]
}
}
}
}
}
]
}
}
}
]
}
}
}
},
{
"let": {
"pat": {
"ident": {
"ident": "json"
}
},
"init": {
"try": {
"expr": {
"call": {
"func": {
"path": {
"segments": [
{
"ident": "fs"
},
{
"ident": "read_to_string"
}
]
}
},
"args": [
{
"reference": {
"expr": {
"path": {
"segments": [
{
"ident": "filepath"
}
]
}
}
}
}
]
}
}
}
}
}
},
{
"let": {
"pat": {
"type": {
"pat": {
"ident": {
"ident": "syntax"
}
},
"ty": {
"path": {
"segments": [
{
"ident": "syn"
},
{
"ident": "File"
}
]
}
}
}
},
"init": {
"try": {
"expr": {
"call": {
"func": {
"path": {
"segments": [
{
"ident": "json"
},
{
"ident": "from_str"
}
]
}
},
"args": [
{
"reference": {
"expr": {
"path": {
"segments": [
{
"ident": "json"
}
]
}
}
}
}
]
}
}
}
}
}
},
{
"let": {
"pat": {
"ident": {
"ident": "outdir"
}
},
"init": {
"try": {
"expr": {
"method_call": {
"receiver": {
"method_call": {
"receiver": {
"call": {
"func": {
"path": {
"segments": [
{
"ident": "Builder"
},
{
"ident": "new"
}
]
}
},
"args": []
}
},
"method": "prefix",
"args": [
{
"lit": {
"str": "\"json2rust\""
}
}
]
}
},
"method": "tempdir",
"args": []
}
}
}
}
}
},
{
"let": {
"pat": {
"ident": {
"ident": "outfile_path"
}
},
"init": {
"method_call": {
"receiver": {
"method_call": {
"receiver": {
"path": {
"segments": [
{
"ident": "outdir"
}
]
}
},
"method": "path",
"args": []
}
},
"method": "join",
"args": [
{
"lit": {
"str": "\"expanded\""
}
}
]
}
}
}
},
{
"semi": {
"try": {
"expr": {
"call": {
"func": {
"path": {
"segments": [
{
"ident": "fs"
},
{
"ident": "write"
}
]
}
},
"args": [
{
"reference": {
"expr": {
"path": {
"segments": [
{
"ident": "outfile_path"
}
]
}
}
}
},
{
"method_call": {
"receiver": {
"method_call": {
"receiver": {
"path": {
"segments": [
{
"ident": "syntax"
}
]
}
},
"method": "into_token_stream",
"args": []
}
},
"method": "to_string",
"args": []
}
}
]
}
}
}
}
},
{
"let": {
"pat": {
"ident": {
"ident": "rustfmt_config_path"
}
},
"init": {
"method_call": {
"receiver": {
"method_call": {
"receiver": {
"path": {
"segments": [
{
"ident": "outdir"
}
]
}
},
"method": "path",
"args": []
}
},
"method": "join",
"args": [
{
"lit": {
"str": "\"rustfmt.toml\""
}
}
]
}
}
}
},
{
"semi": {
"try": {
"expr": {
"call": {
"func": {
"path": {
"segments": [
{
"ident": "fs"
},
{
"ident": "write"
}
]
}
},
"args": [
{
"path": {
"segments": [
{
"ident": "rustfmt_config_path"
}
]
}
},
{
"lit": {
"str": "\"normalize_doc_attributes = true\\n\""
}
}
]
}
}
}
}
},
{
"let": {
"pat": {
"ident": {
"ident": "_status"
}
},
"init": {
"method_call": {
"receiver": {
"method_call": {
"receiver": {
"method_call": {
"receiver": {
"call": {
"func": {
"path": {
"segments": [
{
"ident": "Command"
},
{
"ident": "new"
}
]
}
},
"args": [
{
"lit": {
"str": "\"rustfmt\""
}
}
]
}
},
"method": "arg",
"args": [
{
"reference": {
"expr": {
"path": {
"segments": [
{
"ident": "outfile_path"
}
]
}
}
}
}
]
}
},
"method": "stderr",
"args": [
{
"call": {
"func": {
"path": {
"segments": [
{
"ident": "Stdio"
},
{
"ident": "null"
}
]
}
},
"args": []
}
}
]
}
},
"method": "status",
"args": []
}
}
}
},
{
"let": {
"pat": {
"ident": {
"ident": "writer"
}
},
"init": {
"call": {
"func": {
"path": {
"segments": [
{
"ident": "io"
},
{
"ident": "stdout"
}
]
}
},
"args": []
}
}
}
},
{
"let": {
"pat": {
"ident": {
"mut": true,
"ident": "writer"
}
},
"init": {
"call": {
"func": {
"path": {
"segments": [
{
"ident": "BufWriter"
},
{
"ident": "new"
}
]
}
},
"args": [
{
"method_call": {
"receiver": {
"path": {
"segments": [
{
"ident": "writer"
}
]
}
},
"method": "lock",
"args": []
}
}
]
}
}
}
},
{
"semi": {
"try": {
"expr": {
"method_call": {
"receiver": {
"path": {
"segments": [
{
"ident": "writer"
}
]
}
},
"method": "write_all",
"args": [
{
"method_call": {
"receiver": {
"try": {
"expr": {
"call": {
"func": {
"path": {
"segments": [
{
"ident": "fs"
},
{
"ident": "read_to_string"
}
]
}
},
"args": [
{
"reference": {
"expr": {
"path": {
"segments": [
{
"ident": "outfile_path"
}
]
}
}
}
}
]
}
}
}
},
"method": "as_bytes",
"args": []
}
}
]
}
}
}
}
},
{
"semi": {
"try": {
"expr": {
"method_call": {
"receiver": {
"path": {
"segments": [
{
"ident": "writer"
}
]
}
},
"method": "flush",
"args": []
}
}
}
}
},
{
"expr": {
"call": {
"func": {
"path": {
"segments": [
{
"ident": "Ok"
}
]
}
},
"args": [
{
"tuple": {
"elems": []
}
}
]
}
}
}
]
}
}
]
}