Skip to content

MF2 delimiters/sigils and YAML/Ruby on Rails #520

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
duerst opened this issue Nov 9, 2023 · 3 comments
Closed

MF2 delimiters/sigils and YAML/Ruby on Rails #520

duerst opened this issue Nov 9, 2023 · 3 comments
Labels
blocker-candidate The submitter thinks this might be a block for the next release resolve-candidate This issue appears to have been answered or resolved, and may be closed soon. syntax Issues related with syntax or ABNF

Comments

@duerst
Copy link

duerst commented Nov 9, 2023

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

@aphillips aphillips added syntax Issues related with syntax or ABNF blocker-candidate The submitter thinks this might be a block for the next release labels Nov 10, 2023
@aphillips
Copy link
Member

Related to #521

@aphillips
Copy link
Member

The syntax adopted . as the function starter and removed the {{/}} around the message. Does this address this issue?

@aphillips aphillips added the resolve-candidate This issue appears to have been answered or resolved, and may be closed soon. label Nov 20, 2023
@duerst
Copy link
Author

duerst commented Nov 21, 2023

The syntax adopted . as the function starter and removed the {{/}} around the message. Does this address this issue?

Yes. It does. Thanks, closing.

@duerst duerst closed this as completed Nov 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocker-candidate The submitter thinks this might be a block for the next release resolve-candidate This issue appears to have been answered or resolved, and may be closed soon. syntax Issues related with syntax or ABNF
Projects
None yet
Development

No branches or pull requests

2 participants