configlet icon indicating copy to clipboard operation
configlet copied to clipboard

sync: consider using a different TOML parser

Open ee7 opened this issue 4 years ago • 5 comments

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:

# 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:

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:

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

ee7 avatar Feb 21 '21 12:02 ee7