Confetti Examples

User Settings#

Confetti can be used to store user-specific settings.

Here’s an example with a flat structure:

username JohnDoe
language en-US
theme dark
notifications on

Application Settings#

Confetti can store application specific settings.

application {
    version 1.2.3
    auto-update true
    log-level debug
}

display {
    resolution 1920x1080
    full-screen true
}

Document Markup#

The grammar is flexible enough to create a markup language among other structured documents.

chapter "The Raven"
author "Edgar Allan Poe"
section "First Act" {
  paragraph {
    "Once upon a midnight dreary, while I pondered, weak and weary,"
    "Over many a quaint and " bold{"curious"} " volume of forgotten lore-\"
  }
  paragraph {
    "While I nodded, nearly napping, suddenly there came a tapping,"
    "As of some one " italic{"gently"} " rapping-rapping at my chamber door."
  }
}

Workflow Automation#

The following demonstrates what a task file might look like. It represents various tasks that you could potentially run via the command line.

build {
    description "Compile the source code"
    command "gcc -o program source.c"
}

clean {
    description "Clean the build directory"
    command "rm -rf build/"
}

test {
    description "Run unit tests"
    command "./tests/run.sh"
    depends_on { build }
}

User Interface#

Structured, text-based file formats can use Confetti in interesting ways.

Application {
    VerticalLayout {
        Label {
            text "This application has a single button."
        }

        Button {
            text "Click Me"
            on_click """
function() {
    console.log(`You clicked a button named: ${this.text}`);
}
"""
        }
    }
}

AI Training#

Below is an example of what a JSON configuration file might look like for an AI model, particularly a machine learning model such as a neural network:

model {
    type "neural_network"
    architecture {
      layers {
        layer { type input; size 784 }
        layer { type dense; units 128; activation "relu" }
        layer { type output; units 10; activation "softmax" }
      }
  }

  training {
    data "/path/to/training/data"
    epochs 20
    early_stopping on
  }
}

Material Definitions#

Here material, opacity, pass, diffuse, and blend-mode are interpreted as commands. The application would interpret the material command as the definition of a new material and all subsequent commands as belonging to it. This relationship is not codified by the configuration format itself, but rather by the user’s application.

material water
    opacity 0.5
    pass
        diffuse materials/liquids/water.png
    pass
        diffuse materials/liquids/water2.png
        blend-mode additive

Domain Specific Languages#

You can create domain specific languages

Stack-Based Language#

A simple stack-based language that could be run by a virtual machine.

push 1
push 2
add     # Pop the top two numbers and push their sum.
pop $x  # Pop the sum and store it in $x.
print "1 + 2 ="
print $x

Control Flow#

The grammar is flexible enough to allow conditionals and other program logic:

# Try sending the user a message about their access level.
set $retry-count to 3
for $i in $retry-count {
    if $is_admin {
        print "Access granted"
        send_email "admin@example.com"
        exit 0 # Success!
    }
}
exit 1 # Failed to confirm admin role.

State Machine#

states {
    greet_player {
        look_at $player
        wait 1s # Pause one second before walking towards the player.
        walk_to $player
        say "Good evening traveler."
    }

    last_words {
        say "Tis a cruel world!"
    }
}

events {
    player_spotted {
        goto_state greet_player
    }

    died {
        goto_state last_words
    }
}