Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Abort expression formats incorrectly #829

Open
DylanRJohnston opened this issue May 7, 2024 · 0 comments · May be fixed by #830
Open

Abort expression formats incorrectly #829

DylanRJohnston opened this issue May 7, 2024 · 0 comments · May be fixed by #830

Comments

@DylanRJohnston
Copy link

DylanRJohnston commented May 7, 2024

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.

@DylanRJohnston DylanRJohnston changed the title Abort expression prints incorrectly Abort expression formats incorrectly May 7, 2024
@DylanRJohnston DylanRJohnston linked a pull request May 7, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant