This morning’s hacking

Given:

contacts: (contact, NL*)+ .
contact: name, NL, (email, NL)?, (phone, NL)? .

name: namestart, ~[#a; "@"]* .
email: namestart, namefollower*, "@", namestart, namefollower* .
phone: ["+0123456789()- "]+ .

-namestart: ["_"; L] .
-namefollower: namestart; ["-.·‿⁀"; Nd; Mn] .
-s: (-[Zs]; -#9; -#d)* .
-NL: -#a ; -#d, -#a .

And:

Johh Doe
john@example.com
555-1234

Mary Smith
m.smith@estaff.example.com
+1-222-555-2344

Jane Doe
(512) 555-9999

Nancy Jones
nancy@example.org

You can get:

$ coffeepot -pp -g:examples/contacts.ixml -i:examples/contacts.txt
<contacts>
   <contact>
      <name>Johh Doe</name>
      <email>john@example.com</email>
      <phone>555-1234</phone>
   </contact>
   <contact>
      <name>Mary Smith</name>
      <email>m.smith@estaff.example.com</email>
      <phone>+1-222-555-2344</phone>
   </contact>
   <contact>
      <name>Jane Doe</name>
      <phone>(512) 555-9999</phone>
   </contact>
   <contact>
      <name>Nancy Jones</name>
      <email>nancy@example.org</email>
   </contact>
</contacts>%

or:

$ coffeepot -pp -g:examples/contacts.ixml -i:examples/contacts.txt --format:json | jq .
{
  "contacts": {
    "contact": [
      {
        "name": "Johh Doe",
        "email": "john@example.com",
        "phone": "555-1234"
      },
      {
        "name": "Mary Smith",
        "email": "m.smith@estaff.example.com",
        "phone": "+1-222-555-2344"
      },
      {
        "name": "Jane Doe",
        "phone": "(512) 555-9999"
      },
      {
        "name": "Nancy Jones",
        "email": "nancy@example.org"
      }
    ]
  }
}

(There’s also a “json-tree” view that will represent any XML output, but
it’s long and boring for this example. And it has a bug at the moment.)

Or, finally:

$ coffeepot -pp -g:examples/contacts.ixml -i:examples/contacts.txt --format:csv
"name","email","phone"
"Johh Doe","john@example.com","555-1234"
"Mary Smith","m.smith@estaff.example.com","+1-222-555-2344"
"Jane Doe",,"(512) 555-9999"
"Nancy Jones","nancy@example.org",

                                        Be seeing you,
                                          norm

--
Norm Tovey-Walsh
Saxonica

Received on Thursday, 17 February 2022 09:23:14 UTC