Re: A grammar challange regarding that pesky YAML format

The best way is to specify the non key:value pair suitably: 

 - if it starts with a key, and a colon, then it must not be followed by a space.


I think the following covers all the cases:


     data: array; pairs.
    pairs: (pair, -#a)+.
    array: (element, -#a)+.


  element: -"- ", (string; pair).


     pair: key, -": ", value.
      key: [L]+.
    value: ~[#a]*.


   string: -key, nonvalue?;
           nonkey.


-nonvalue: ":", ~[" "; #a], ~[#a]*;
           ":";
           ~[L; ":"; #a], ~[#a]*.
  -nonkey: ~[L; #a], ~[#a]*.



Steven


On Sunday 01 February 2026 11:34:58 (+01:00), Fredrik Öhrström wrote:


I am experimenting with a YAML grammar for IXML. 


In YAML you can create a document consisting of a single array with strings:
- a 1
- b 2
- c 3


Convert it into json and you get 
[  "a 1",  "b 2",  "c 3" ]
Note the permitted spaces, no need for quotes. Nice.


You can create a document consisting only of key value pairs:
a: 1
b: 2
c: 3


Convert it into json and you get
{  "a": 1,  "b": 2, "c": 3 }
Nice.


However! You can start a new object consisting of key value pairs on the same array line!!! The YAML parser will look for key <no-space> colon <space>, if this is found then a new object i started on the array line. But if there is no space after the colon or if there is space before the colon, then the array line is a string.... :-/


So this document:
- a: 1
- b:2
- c: 3


Translates into:
[
    {
        "a": 1
    },
    "b:2",
    {
        "c": 3
    }
]
 
Have I mentioned that I do not like YAML? Anyway, in IXML you can have a string rule that matches the array line fine, you can have the key value in array line fine.
But clearly the grammar will be ambigous since >>a: 1<< can be a string or a key value pair.


Is there a way to write a string matching IXML rule that matches to the end of line but forbids <letter>:<space>?


//Fredrik

Received on Monday, 2 February 2026 12:40:20 UTC