Skip to content

ASR: add string formatting nodes #1129

Open
@certik

Description

@certik

One way to handle string formatting and printing in a language independent approach is to decouple string formatting form printing. The Print ASR node would just do printing and printing related flags. I think it's pretty much there.

Then we need an expr node like StringFormat, which will handle all string formatting. The string formatting is inherently runtime operation, so the StringFormat would accept the format string (in various styles) and the variables to format, and it would produce formatted string. It is not clear if a single StringFormat can handle all formatting styles. If not, we will introduce StringFormatFortran, StringFormatC, StringFormatPython1 (%s style), StringFormatPython2 (the {} style) etc. (there are also f-strings in Python, it would be nice to generate the original f-string from ASR if possible).

Then in Fortran print "(i0, i0)", a, b will become Print(StringFormatFortran("(i0, i0)", a, b)), and Python's print("%d %d", a, b) would become Print(StringFormatPython1("%d %d", a, b)).

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