Skip to content

Ivy-Apps/quickcode

Repository files navigation

QuickCode

A simple and elegant language for generating dynamic code templates using {{variables}} and #ifs.

println("Hello, {{name}}!")
#if {{morning}} #then
println("Good morning :)")
#endif

It's designed to be learned at a single glance. Use:

  • {{variableName}} to create a variable for your template.
  • #if {{booleanName}} #then for parts in the template which will appear only if boolName is true.

When you evaluate/execute your template Compose Hammer will ask you to provide values for the defined variables.

Usage

./gradlew run --args="samples/hello.kt.qc samples/hello_input.json"

Syntax

Keywords:

  • {{varName}}: creates a variable. If it's inside an #if condition becomes a boolean.
  • #if: start an if condition.
  • #then: ends an if condition and starts the template that'll appear only if the condition is true.
  • #endif: ends the template that'll appear if the if condition is true.
  • #else: an alternative to #endif for creating if-else statements. Note #else must always end with #endif.
  • #elseif: used to create else-if statements. Its condition must end with #then just like for #if.

If-condition operators:

  • AND: logical AND like && in many languages.
  • OR: logical OR like || in many languages.
  • NOT: logical NOT like !.
  • (): brackets used for operations priority.

That's it! Now you're ready to create your own code templates.

Your only limitation is your imagination!

Note: If there is a variable name conflict (a String and Boolean variable with the same name), Boolean takes precedence and the variable will be considered to be a boolean (true/false).

Demo

For example:

fun main(#if {{args}} #then args: Array<String>#endif) {
#if {{logging}} AND NOT {{prod}} #then
  println("program started.")
#endif

  println("Hello, {{firstName}} {{lastName}}!")
#if {{likeDogs}} #then
  println("Here's a dog.")
#elseif {{likeCats}} #then
  println("Here's a cat.")
#else
  println("No animals for you, sir.")
#endif

#if ({{logging}} AND NOT {{prod}}) OR {{forcedDebug}} #then
  println("program finished.")
#endif
}

When executed with:

{
   "firstName":"John",
   "lastName":"Wick",
   "args":true,
   "logging":true,
   "likeDogs":true
}

Missing variables are interpreted as false or "" (empty string) by default.

Will produce:

fun main(args: Array<String>) {
  println("program started.")

  println("Hello, John Wick!")
  println("Here's a dog.")

  println("program finished.")
}

About

QuickCode is a simple language for generating dynamic code templates using {{variables}} and #ifs.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages