Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/sogaiu/janet-xmlish

Parse XML-ish Strings as Janet Data
https://github.com/sogaiu/janet-xmlish

janet peg xml

Last synced: about 1 month ago
JSON representation

Parse XML-ish Strings as Janet Data

Awesome Lists containing this project

README

        

# janet-xmlish

PEG-based Parsing for XML-ish Data

## Description and Disclaimer

This code provides a single PEG to help parse XML-like strings to
produce Janet data structures. It's not an attempt at a complete /
correct parser, but it seems to have handled some cases tolerably
well.

## Usage

### Command Line

Zero to sample invocation:

```
git clone https://github.com/sogaiu/janet-xmlish
cd janet-xmlish
janet -l ./janet-xmlish/grammar -e '(pp (peg/match xmlish-peg "

hi

"))'
```

Output:

```
@[{:content @["hi"] :tag "h1"}]
```

### From Code

Assuming installation like:

```
jpm install https://github.com/sogaiu/janet-xmlish
```

Code might look like:

```
(import janet-xmlish/grammar :as xmlish)

(peg/match xmlish/xmlish-peg
``link``)
```

Evaluation might yield:
```
@[{:attrs @{"href" "http://127.0.0.1:8000"}
:content @["link"]
:tag "a"}]
```

## More Examples

See `(comment ...)` portions of source files and files in `usages` for examples.