Skip to content

Abort expression formats incorrectly #829

Open
@DylanRJohnston

Description

@DylanRJohnston

Hey all,

I'm currently working on a transpiler from another language into VRL. All other parts of the AST implement Display in a way that is valid syntactically to parse it again i.e. parse <-> display (formatting not withstanding). However the implementation of Display for abort incorrectly places a colon in its output.

https://github.com/vectordotdev/vrl/blame/b6fd5ecf3e4d75ccc5a822dcebe8a0fe7d04ef78/src/parser/ast.rs#L1199

The following kind of test succeeds for all other expressions in VRL.

    #[test]
    fn abort_isomorphism_failure() {
        let expression = r#"abort "error message""#;

        assert_eq!(
            format!("{expression}\n"),
            vrl::parser::parse(expression).unwrap().to_string()
        )
    }

I don't know if this kind of isomorphism via std::fmt::Display is a guarantee the project is looking to provide, but beyond transpilers it's also very useful for pretty printers since printing from the parsed AST canonicalizes the formatting.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions