Stream: show and tell

Topic: Roc Parser package


view this post on Zulip Luke Boswell (Oct 02 2023 at 23:47):

I have created a separate package lukewilliamboswell/roc-parser. I copied an adapted this code from the example repository for use with Advent of Code, and have moved into a separate repository to make it easier to use using a URL and also added a couple of examples.

view this post on Zulip Luke Boswell (Jun 03 2024 at 00:29):

Quick announcement -- a new release of roc-parser

This release includes a new module for parsing Xml. Thank you to @Johannes Maas for the original implementation.

As a demonstration here is a simple program that converts HTML to Roc DSL (using the Hasnep/roc-html package).

This app reads input from Stdin, converts the Xml nodes into Html nodes, and then renders Html nodes out to a DSL string.

The example below converts a Twitter Bootstrap Icon that you can copy into a roc module, saving you precious minutes when writing web apps using roc. :smiley:

<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-sort-up" viewBox="0 0 16 16"><path d="M3.5 12.5a.5.5 0 0 1-1 0V3.707L1.354 4.854a.5.5 0 1 1-.708-.708l2-1.999.007-.007a.5.5 0 0 1 .7.006l2 2a.5.5 0 1 1-.707.708L3.5 3.707zm3.5-9a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5M7.5 6a.5.5 0 0 0 0 1h5a.5.5 0 0 0 0-1zm0 3a.5.5 0 0 0 0 1h3a.5.5 0 0 0 0-1zm0 3a.5.5 0 0 0 0 1h1a.5.5 0 0 0 0-1z"/></svg>
$ roc html-converter.roc < icon.txt
svg [
    xmlns "http://www.w3.org/2000/svg",
    width "16",
    height "16",
    fill "currentColor",
    class "bi bi-sort-up",
    viewBox "0 0 16 16"
] [
    path [
        d "M3.5 12.5a.5.5 0 0 1-1 0V3.707L1.354 4.854a.5.5 0 1 1-.708-.708l2-1.999.007-.007a.5.5 0 0 1 .7.006l2 2a.5.5 0 1 1-.707.708L3.5 3.707zm3.5-9a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5M7.5 6a.5.5 0 0 0 0 1h5a.5.5 0 0 0 0-1zm0 3a.5.5 0 0 0 0 1h3a.5.5 0 0 0 0-1zm0 3a.5.5 0 0 0 0 1h1a.5.5 0 0 0 0-1z"
    ] []
]

Last updated: Jul 06 2025 at 12:14 UTC