Description
I have been thinking about, and working together with a student of mine, on trying to use MF2 with Ruby on Rails. One problematic area I have found is that there are some conflicts between currently used/planned syntax characters in MF2 and in YAML, in particular '#' and '{'.
This raises serious questions, at least for me, whether '{', '{{', and '#', are really good choices for our syntax. I have to admit that I can't propose any alternatives at the moment because I don't know YAML well enough. But I can easily check out other proposals.
TL;DR
Ruby on Rails uses YAML to store resource strings. See https://guides.rubyonrails.org/i18n.html for a general explanation, and e.g. https://github.com/redmine/redmine/blob/master/config/locales for examples.
In YAML, strings can be written bare, without any kinds of quotes,...
(see https://github.com/redmine/redmine/blob/master/config/locales/en.yml#L155).
On the other hand, YAML uses various characters to indicate constructs other than strings.
In particular, '#' introduces comments (as it does in many scripting languages including Python, Ruby, and various shell languages).
Also, '{' starts a hash/map/dictionary, similar again to Python, Ruby, JavaScript, JSON and so on.
Below are examples of some one-liners in YAML (between >>> and <<<) and the resulting objects on the next line (strings in "", which is what we would want; others like hash/map/dictionary (in {}) are not what we want). There are even some cases where an error is produced.
>>>--- foo #cdef<<<
"foo"
>>>--- {abc}<<<
{"abc"=>nil}
>>>--- {{abc}}<<<
{{"abc"=>nil}=>nil}
>>>--- abc {#def} ghi<<<
"abc {#def} ghi"
>>>--- abc #{def} ghi<<<
"abc"
>>>--- abc {$def} ghi<<<
"abc {$def} ghi"
>>>--- {{#match}}<<<
!!!!! This errors out!
And here's the Ruby program that generate the above, just for your reference (with comments for non-Rubyists):
require 'yaml' # use 'yaml' library, based on libyaml
examples = ["--- foo #cdef", # array of YAML examples
"--- {abc}",
"--- {{abc}}",
"--- abc {#def} ghi",
'--- abc #{def} ghi',
'--- abc {$def} ghi',
"--- {{#match}}",
]
examples.each do |ex| # iterate over 'examples' array
puts ('>>>'+ex+'<<<') # print example
begin
s = YAML.load(ex) # parse as YAML
rescue
puts "!!!!! This errors out!" # handle error case
else
puts s.inspect # print resulting object
end
puts # print empty line as separator
end