You could try this:
| expression2string(String(X)) = X
Question
Say I want to represent a string in my Metalanguage, so I have a string like "String" the following code will do the following for me
I have
repl>"string"
Will output:
\"string\"
I know the problem has to do with toString, from what I have read it converts double quotes to series of backslashes, My question is there a function I can so I can just output the string normally.
Solution
You could try this:
| expression2string(String(X)) = X
OTHER TIPS
I don't know what your parser does, but usually I would expect it to not include the quote characters in the string value, i.e., the x
in String(x)
should only contain the actual content of the string. Then you'd just define
| expression2string(String s) = "\"" ^ String.toString s ^ "\""
This escapes the string content properly (e.g. newlines or inner quotes), but not the surrounding quotes, which are language syntax, not content.