OK, I’m coming around to the Swiftier and more explicit syntax,
It’ll be more work but by no means impossible and raises a couple of other possibilities not least the default and better error reporting.
The value of the
”NUMBER" command line flag could now be sub-parsed as an expression “as if typed at that point” rather than just a literal, Would this be considered a feature or a bug? - (and it should be constrained to literals only)
Looking at the
#string/dataLiteral proposal, there is definitely a use case to embed resources in a Linux binary (for example), but there is a bit of a flaw in that the swift compiler does not have a model for a project’s layout so would not be able to find
”long_query.sql” on it’s own.
Perhaps this proposal could be extended so that if the name of the parameter was prefixed by
@ it would parse and inject the file pointed to by the parameter’s value rather than the value itself:
let sql = #userLiteral(“@LONG_SQL_FILE")
A decision could be made as to whether such a file referenced by a parameter would be any literal (or perhaps expression) in Swift syntax or always the body of a raw string with encoding utf-8.
Thinking out loud, there isn’t currently a Data literal in the compiler but the following code could be used for base64 encoded resources with only a slight size penalty and run time overhead.
let image = Data(base64Encoded: #userLiteral(“@IMAGE_BASE64_FILE"))