Function axon_parser::format_comp[][src]

pub fn format_comp(axon: &str, desired_width: usize) -> Result<String, Error>
Expand description

If the axon input represents a comp, parse it and return a String which contains formatted code.

The axon argument to this function should be a string containing the output of running <some comp src>.parseAst.toAxonCode in SkySpark.

Example

use axon_parser::format_comp;

let desired_width = 80;
let axon = r###"{type:"compdef", params:[{name:"cells"}], body:{type:"block", exprs:[{type:"var", name:"in"}]}, cells:{in:{defVal:0}}}"###;
let formatted_code = format_comp(axon, desired_width).unwrap();
let expected_code = "defcomp\n    in: {defVal: 0}\n\n    do\n        in\n    end\nend";
assert_eq!(formatted_code, expected_code);