sparsetech / toml-scala Goto Github PK
View Code? Open in Web Editor NEWTOML parser with codec derivation for the Scala platform
TOML parser with codec derivation for the Scala platform
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.
Would it be possible to add support for Scala.js 1.0?
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.
Will there be native support for Scala 2.12 or 2.13? If so, any idea of timeframe for this? Thanks.
please consider support for round trip codec:
i.e. toml
-> code
-> toml
with high fidelity, including comments
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
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?
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?
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))
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.