exercism / exercism/configlet

sync: consider using a different TOML parser

Open
#187 5 comments 0 reactions 0 assignees View on GitHub
cmd: sync kind: refactor
Dominant language
Nim
Stars
23
Forks
17
Avg merge
13h 57m
Merged PRs (30d)
1

Description

We don't need to support the entire TOML syntax, just the syntax of:
- `#` begins a comment
- `some-uuid = bool` includes/excludes a UUID

Using our own parser would:
- Allow us to remove our largest dependency
- Improve performance
- Reduce binary size
- Possibly make it easier to support maintainer-added (non-generated) documentation comments, if that's something we want to do

---

To illustrate the final point, given a `tests.toml` file:
```toml
# first test description
bc310baa-ceae-4cb5-a656-20b7d2bbf1fe = true

# maintainer-added documentation comment

# second test description
3430d237-1ec8-4889-8f2d-17985d82e809 = false
```

And the Nim program:
```Nim
import pkg/parsetoml

let toml = parseFile("tests.toml")

echo toml # see also `echo toml.repr`
```

The output is:
```
bc310baa-ceae-4cb5-a656-20b7d2bbf1fe = true
3430d237-1ec8-4889-8f2d-17985d82e809 = false
```

That is, as you might expect, the comments aren't available in the end data structure:

```Nim
TomlValueRef = ref TomlValue

TomlValue = object
case kind*: TomlValueKind
of TomlValueKind.None:
nil
of TomlValueKind.Int:
intVal*: int64
of TomlValueKind.Float:
floatVal*: float64
forcedSign*: Sign

of TomlValueKind.Bool:
boolVal*: bool
of TomlValueKind.Datetime:
dateTimeVal*: TomlDateTime
of TomlValueKind.Date:
dateVal*: TomlDate
of TomlValueKind.Time:
timeVal*: TomlTime
of TomlValueKind.String:
stringVal*: string
of TomlValueKind.Array:
arrayVal*: seq[TomlValueRef]
of TomlValueKind.Table:
tableVal*: TomlTableRef
```

See also:
- https://nimparsers.github.io/parsetoml/index.html
- https://github.com/NimParsers/parsetoml

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.