Code Monkey home page Code Monkey logo

toml-scala's People

Contributors

tindzk avatar vaartis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

toml-scala's Issues

Can't parse float number expressed in scientific notation

Toml-scala can't parse number in floating point expressed in a scientific notation.

Example :

scala> import toml.Toml ; Toml.parse("poly = -45e12")
import toml.Toml
res4: Either[String,toml.Value.Tbl] = Right(Tbl(Map(poly -> Real(-4.5E13))))

scala> import toml.Toml ; Toml.parse("poly = -45.321e12")
import toml.Toml
res5: Either[String,toml.Value.Tbl] = Left(End:1:15 ..."e12")

Let me know if you need more from me.

Include toml-test

toml-test is a language-agnostic test suite for TOML parsers. To increase our test coverage, include the repository as a Git submodule and run its tests.

Feature: support round trip

please consider support for round trip codec:
i.e. toml -> code -> toml with high fidelity, including comments

No boolean codec?

It seems that one cannot translate TOML into a case class with a boolean field.

case class X(v: Boolean) gives me the Codec[X] implicit not defined in scope when i try to use parseAs/parseAsValue

How best to handle key case differences?

I want to parse

BANANA_SMOOTHIE="please, yes"
HEDGEHOGS="always"

into case class Order(bananaSmoothie: String, hedgehogs: String) using a Codec.

Without any special handling, this fails due to the case differences for the keys.

I could define case class Order(BANANA_SMOOTHIE: String, HEDGEHOGS: String), but I'd rather not.

For now I'm using raw parsing, with no Codec. Is it possible to accommodate for different key cases?

parsing toml dateTime

Hi, thank you for creating this library! I realize the toml DateTime values parsed to java.time.OffsetDateTime are not included as a Value, is there a particular reason for this?

Positions for TOML nodes?

Thank you for creating this project! I'm using toml-scala in new configuration library that I'm working on (adaptation of https://github.com/scalameta/metaconfig) and I'm curious if it would be possible to somehow expose position information in the toml.Value._ case classes.

My goal is to be able to report positioned type error messages when decoding TOML into Scala case classes, for example

# config.toml
booleanField = "stringValue"

The reported error would look like this

config.toml:0 error: Type mismatch;
  found    : String
  expected : Boolean
booleanField = "stringValue"
               ^

One way to achieve this with an immutable ADT with minimal boilerplate is to add a private var into the superclass

abstract class Value {
  private var myIndex: Option[Int] = None
  def position: Option[Int] = myIndex
  def withPosition(newIndex: Int): Value = {
    val copy = copyThis()
    copy.myIndex = Some(newIndex)
    copy
  }
  private[this] def copyThis(): Value = this match {
    case Value.Str(value) => Value.Str(value)
    // ...
  }
}

As long as copyThis().myIndex = is the only place where you mutate the var then the class remains effectively immutable. The position field can be added in a backwards compatible way, it doesn't affect Value equality semantics.

The Rules parser can then construct nodes with the Index fastparse parser and construct nodes with something like this (I didn't check if it compiles)

  val basicStr: Parser[Value.Str] =
    P(Index ~ (DoubleQuote.toString ~/ (strChars | escape).rep.! ~ DoubleQuote.toString))
      .map((index, str) => Value.Str(Unescape.unescapeJavaString(str)).withPosition(index))

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.