Skip to content

Instantly share code, notes, and snippets.

@Spartee
Last active July 11, 2017 22:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Spartee/c50b458dca097e95c2919a631ddb23ed to your computer and use it in GitHub Desktop.
Save Spartee/c50b458dca097e95c2919a631ddb23ed to your computer and use it in GitHub Desktop.
An interface for the Toml library written in chapel.
/*
Chapel's Library for `Tom's Obvious, Minimal Language (TOML) <https://github.com/toml-lang/toml>`_.
This module provides support for parsing and writing toml files.
Will list a few example use-cases once interface is finalized.
Node is a placeholder name for the data structure that holds the parsed toml.
Could be named something else more related to toml? e.g. -> tomlTable
*/
/*
Receives a channel to a TOML file as a parameter and outputs an associative
array Node.
*/
proc parseToml(input: channel) : Node {}
/*
Receives a string of TOML format as a parameter and outputs an associative
array Node.
*/
proc parseToml(input: string) : Node {}
/*
Receives an output channel and an instance of Node representing an associative
array of the parsed channel. The format for writing into the file is toml.
*/
proc writeToml(arr: Node, output: channel) {}
@ben-albrecht
Copy link

top-level doc string should be something like:

/* 
Chapel's Library for Tom's Obvious, Minimal Language (TOML)  // maybe link TOML spec?

This module provides support for parsing and writing toml files.
*/

@ben-albrecht
Copy link

I think you can drop function names from docs, and simplify them a bit, e.g.

/*
parseTomlStr takes in a string in toml format to be parsed into an associative
array Node. The Node can be written to a channel using the writeToml procedure.
*/

-->

/*
Parse a string of toml format into an associative array of Nodes.
*/

We'll want to document the Node class and the public methods as well (since library users will be interacting with it). It may be best to rename Node to something like TOML or TomlTable... This is something that would be helpful to receive feedback on from team / community.

@ben-albrecht
Copy link

Could we just merge parseToml and parseTomlStr into parseToml with 2 overloads?

@ben-albrecht
Copy link

I think it'd be useful to include some example uses of the library.

2 examples come to mind:

  1. Open a toml file (as a channel), parse it, then write it to a file.
  2. Create a sample string containing toml format, parse it, then rewrite an element in it (e.g. change name = "sam" to name = "ben"), and then write it to stdout.

Open question: Could users call writeln(node) and rely on the writeThis(f) of the Node class to print to the toml contents?

@ben-albrecht
Copy link

TOML Spec -> https://github.com/toml-lang/toml

URL syntax for restructuredText is:

`Tom's Obvious, Minimal Language (TOML)  <https://github.com/toml-lang/toml>`_.

 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment