ats

How do I draw ascii art in ATS?


I’m trying to make an ascii image with this code:

var a: string = “_”

The problem is that the art has a lot of unfinished backslashes, but which give you the error “the string-char format (oct) is incorrect.” I’m wondering, is there any way to get it to ignore the backslashes as normal characters without having to replace everything with \? Similar to R”_” in c++. Thanks for any help


Solution

  • You can define the string using inline C:

    %{
    char* art = R"(
      /\
     /  \
    ------
    )";
    %}
    
    macdef art = $extval(string, "art")
    
    implement main0() = print art
    

    According to this, raw string literals are available in GCC with -std=gnu99 or -std=gnu11.