Kotidgy aka "Kotlin Text Indexed Data Generator" is an index-based text data generator written in Kotlin.
Write this
kotidgy {
templates {
t { +"Hello" }
t { +"Hi" / "Aloha" + ", man !" }
t { +f { any { 2..100 } } + " apples " + "on the " + "plate" / "table" }
t { +f { all { 2..3 } } + " apples " + "on the " + "plate" / "table" }
}
}
Get that
Hello
Hi, man !
Aloha, man !
2 apples on the plate
3 apples on the plate
2 apples on the table
3 apples on the table
...
... skipped 194 other lines
...
100 apples on the table
100 apples on the table
23 apples on the plate
23 apples on the table
Add dependencies (you can also add other modules that you need):
<dependency>
<groupId>com.meiblorn</groupId>
<artifactId>kotidgy</artifactId>
<version>1.0.0.RELEASE</version>
</dependency>
Add dependencies (you can also add other modules that you need):
Groovy DSL
dependencies {
implementation 'com:meiblorn:kotidgy:1.0.0.RELEASE'
}
Make sure that you have either jcenter()
or mavenCentral()
in the list of repositories:
repository {
jcenter()
}
Add dependencies (you can also add other modules that you need):
dependencies {
implementation("com.meiblorn:kotidgy:1.0.0.RELEASE")
}
Make sure that you have either jcenter()
or mavenCentral()
in the list of repositories.
Kotlin example:
val engine = KotidgyEngine()
val project = kotidgy {
templates {
t { +"Hello" }
t { +"Hi" / "Aloha" }
t { +f { 2..3 } + " apples" }
}
}
val samples = engone.generate(project)
// Assert here is just for an illustration
assert(samples.toList() == listOf(
Sample(IndexId(0), "Hello"),
Sample(IndexId(0), "Hi"),
Sample(IndexId(1), "Aloha"),
Sample(
IndexId(0),
"2",
Sample(IndexId(0), " apples")
),
Sample(
IndexId(1),
"3",
Sample(IndexId(0), " apples")
)
))
for (sample in samples) {
println(sample)
}
Output will be:
Hello
Hi
Aloha
2 apples
3 apples
- Provide jar directly:
java -jar <%path_to%>/kotidgy.jar <%path_to%>/examples/kotlin/script/index.kotidgy.kts
- Or use it via kscript
#!/usr/bin/env kscript
// Declare dependencies
@file:DependsOn("com.meiblorn:kotidgy:1.0.0.RELEASE")
import com.meiblorn.kotidgy.dsl.*
kotidgy {
templates {
t { +"hi" }
t { +"hello" / "aloha" }
}
}
docker run \
-v $(pwd)/examples/kotlin/script:/data \
meiblorn/kotidgy \
/data/index.kotidgy.kts
Project definition:
kotidgy
/project
— kotidgy project definition wrapperstemplates
— templates definitions wrappert
/template
— template definition
Template definition:
- Every template must start from the
+
sign. It is mandatory cast to the Kotlin Type-Safe Builders DSL. - Template operators:
- unary
+
— start of the template - binary
+
— concatenation /
— alternative operatorall
andany
- collection/iterable wrapper operators.any
— converts collection items to alternatives (like it is written using/
operator: e.g.item1 / item2 / ...
)all
— concatenates collection items (e.g.item1.toString() + item2.toString() + ...
)
f
orlambda
orcall
— kotlin call operator.- All return types are accepted
- If
call
operator returns instance oflist
oriterable
types then instance will be automatically converted toany
collection .toString()
is called for the object rendering.
- unary
- Kotlin is a mature programming language
- Kotlin is a type safe language
- Kotlin has a native DSL builder support.
- Writing a new own programming language is a very expensive operation both in time and effort.
- Kotlin can do much more than own language and has less bugs.
- It has an amazing huge community: Java + Kotlin
- Kotlin can be used to write Bash scripts
- Native IDE support and highlighting: Intellij Idea (it is also available for Free)
You are welcome to contribute ! Just submit your PR and become a part of Kotidgy community!
Please read contributing.md for details on our code of conduct, and the process for submitting pull requests to us.
We use SemVer for versioning. For the versions available, see the tags on this repository.
- Vadim Fedorenko - Meiblorn -Initial work
See also the list of authors who participated in this project.
This project is licensed under the MIT License - see the LICENSE.md file for details
- Your questions will appear here. Feel free to ask me.