vsirotin / si-units

Kotlin function and objects for working with SI units like meter, second, as well as currencies and general units like percent.

Home Page:https://vsirotin.github.io/si-units/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Uint Factory

vsirotin opened this issue · comments

Implement Factory-object for creation Units from their string-representation. This functionality will be very useful by load data from CSV, Json, Yaml etc. files

@vsirotin I am looking at implementing this. What did you have in mind for this issue? In terms of the basic layout, I was thinking of creating a factory method createExpression in Parser.kt in a separate eu.sirotin.kotunil.parser package. The implementation will depend on most of kotunil so I was keen to separate it out. In terms of implementation, I was looking at either using ANTLR 4 along the lines of kotlin-antlr or going for simpler but less robust all Kotlin solution. What's your opinion?

@limska Thank you for your interest in this project.
You are, of course, welcome to place your implementation directly in this project. But I don't mind if you do it in a separate, own project as a part of eco-system of KotUniL.
If you decide to implement it within KotUniL, it's worth to implement it in a separate module depending on kotunil-jvm. This lets you keep the kotunil-jvm lean and without dependencies.
If you decide to go this way, I can create a framework for you.
Probably at the beginning of this new module will be "few multiplatform" as kotunil-jvm because of specific API for reading files and formatting on individual platforms.
So, what would you prefer - to implement in this project or in your separate project?

@limska I have experience with ANTLR 4 and I am afraid that this might be too heavy a solution. ANTLR suits better to complicated, very extensive grammars. The data formats like CSV, JSON or YAML are actually very simple.
It might be worthwhile to start with some existing (ready-made) libraries that work with Java/JVM objects (see e.g. https://www.baeldung.com/java-serialization-approaches). KotUniL objects are JVM objects and can (I hope) be serialised/deserialised with the help of such libraries.
Surely there are ready pure Kotlin implementations of serialisation libraries for common data formats.
If you (like me) are interested in the subject of parsing, I will recommend looking in the direction of parsing combinators. I think you know this, however as examples: 1) Project https://github.com/alllex/parsus 2) Example from chapter 9 of the book "Functional Programming with Kotlin".