Spookylang Documentation

repository·master·Indexed 41 days ago

https://github.com/ftripier/spookyc

A procedural, dynamically typed programming language where keywords are emojis and variable names must meet specific 'scariness' criteria defined by regex patterns. Features a Docker-based compilation workflow and a minimalist standard library including functions like print_and_then_scream and spooky_input.

Tokens
1.7K
Snippets
11
Records
12
Agent score
50%

What's inside Spookylang

  1. Understand Spooky-Completeness and String Scariness

    master

    Spookylang is 'Spooky-complete' (isomorphic to Turing completeness). It operates on a core invariant: it takes 'scary' input and produces 'spooky' output.

    • Scariness: The compiler uses a hardcoded list of regular expressions to categorize strings as 'scary' or 'non-scary'.
    • I/O Constraints: The compiler's I/O routines will crash if they are passed 'non-scary' strings.
    • Variable Naming: Variable names must be 'scary' to satisfy the compiler.
  2. Use Spookylang values and types

    master

    Spookylang supports several data types:

    • Numbers: Integers and floats (e.g., 13, 13.666).
    • Booleans: 🌝 for true, 🌚 for false.
    • Strings: Quoted text (e.g., "hello"). Strings can be concatenated using the + operator.
    • Void: Represented by ⚰️.
    • Lists: Defined using 🍫 (Chocolate) to start, 🍬 (Candy) to separate elements, and 🍭 (Lollipop) to end.
    • Dictionaries: Defined using 🍫 to start, 😱 to map keys to values, 🍬 to separate entries, and 🍭 to end.
    # List Example
    🍫 1 🍬 2.5 🍬 "uh oh skeletons" 🍬 🌝 🍬 🌚 🍬 ⚰️ 🍭
    
    # Dictionary Example
    🍫
    "top_level" 😱 🍫
      "scary_key" 😱 "spooky!"🍬
      "list_key" 😱 🍫 8 🍬 "bones" 🍭🍬
    🍭
  3. Compile Spookylang programs using Docker

    master

    The Spookylang compiler is provided via a Docker-based workflow to avoid manual OCaml setup. The script ./docker-compile.sh builds and persists a Docker image named spookybox.

    To compile a specific spooky file, run the script pointing to your file path. Note that the first run will be slow as it builds the spookybox image.

    ./docker-compile.sh examples/hell_world.spooky
  4. Use conditionals (if/else)

    master

    Spookylang provides two branching structures:

    1. if: Delimited by a perturbed emoji 😨 followed by a parameter list 👿 ... 😈 and a statement block 💀 ... ☠️.
    2. else: Delimited by a concerned emoji 😰 followed by a statement block 💀 ... ☠️.

    Example:

    😨 👿 condition 😈 💀
      statement_1 😈🎃
    ☠️ 😰 💀
      statement_2 😈🎃
    ☠️
    😨 👿 skeletons_are_scary 😈 💀
      print_and_then_scream👿 "scary if statement!" 😈🎃
    ☠️ 😰 💀
      print_and_then_scream👿 "ahhhhhhhh it's an else statement!" 😈🎃
    ☠️
  5. Use loops in Spookylang

    master

    Spookylang has only one type of loop. It is initiated by placing a bat 🦇 near an expression and a statement block.

    Syntax: 🦇 👿 expression 😈 💀 ... ☠️

    🤡 scariest_accumulator🎃 
    scariest_accumulator 😱 0🎃
    🦇 👿 scariest_accumulator < 10 😈 💀
      scariest_accumulator 😱 scariest_accumulator + 1🎃
    ☠️
  6. Run spooky tests using Docker Compose

    master

    You can run the project's test suite using Docker Compose. The spooky-tests service builds the environment from the current directory, mounts the local source code to /source inside the container, and executes the test runner cram against the test file tests/examples_output.t.

    docker-compose up
  7. Write a Spookylang Hello World program

    master

    Spookylang is a procedural, mostly dynamically typed language where keywords are emojis and variable names must be 'scary' to pass compilation. Programs are delimited by 👻 (start) and ☠️ (end).

    👻 boo! 👿  😈 💀
      🤡 spooky_list🎃
      spooky_list 😱 🍫 1 🍬 2.5 🍬 "uh oh skeletons" 🍬 🌝 🍬 🌚 🍬 ⚰️ 🍭🎃
      print_and_then_scream👿 spooky_list 😈🎃
      🍬 ⚰️🎃
    ☠️
  8. Define functions in Spookylang

    master

    Spookylang is a procedural language. A function is defined using an identifier and a list of parameters.

    Key Syntax Rules:

    • A function must be named boo! for the program to execute.
    • 👻 (Ghost) indicates the start of a function definition.
    • 👿 (Devil) delimits parameters.
    • 💀 (Skull) delimits the statement block.
    • ☠️ (Skull/Crossbones) terminates the function block.
    • 🎃 (Jack o' lantern) terminates a statement.
    • Spookylang does not support closures.
    • Varargs are technically possible but discouraged.
    👻  my_spooky_function 👿  😈 💀
      🍬 ⚰️🎃
    ☠️
  9. Declare and assign variables

    master

    Variables in Spookylang must have 'scary' names to compile.

    Declaration: Use the scary clown 🤡 to declare a variable. Note that declaration and assignment cannot happen in the same statement.

    Assignment: Use the screaming genderless anthropomorph 😱 between a binding and an expression, delimited by a jack o' lantern 🎃 at the end of the statement.

    Example:

    🤡 my_terrifying_variable_declaration🎃
    my_variable 😱 10🎃
    🤡 my_terrifying_variable_declaration🎃
    assignment_can_be_scary 😱  ⚰️🎃
  10. Use the Standard Library

    master

    The Spookylang standard library is minimalist and includes the following functions:

    • print_and_then_scream👿 expression 😈🎃: Coerces an expression to a string and prints it to stdout. Warning: This will crash the program if the expression fails to match the internal AI regex list.
    • spooky_input🎃: Blocks execution until user input is provided. Returns the input value. Warning: If the input is not 'spooky', the program crashes.
    • scary_length👿 collection 😈🎃: Returns the length of a list or a string.
    • skeleton_keys👿 dictionary 😈🎃: Returns a list of all keys in the provided dictionary.
    # print_and_then_scream
    print_and_then_scream👿"i'm screaming!"😈🎃
    
    # spooky_input
    scariest_accumulator 😱 spooky_input🎃
    
    # scary_length
    scary_length👿 my_length_is_three_and_im_scary😈🎃
    
    # skeleton_keys
    scariest_keys 😱 skeleton_keys👿sample_haunted_object😈🎃
  11. Use operators in Spookylang

    master

    Spookylang supports standard arithmetic and comparison operators:

    • Arithmetic: +, -, *, /.
    • Comparison: ==, != (implied by == ⚡🌚), >, <, >=, <=.
    • Assignment: 😱 for standard assignment, ⚡= for other assignment types (e.g., 🌝 ⚡= 🌚).
    • List/String Operations: + can be used to concatenate lists or strings.
    4 + 5
    4.0 / 2
    2 * 3
    4 - 1
    🌝 == 🌝
    4 > 3
    3 < 4
    4 >= 4
    4 <= 4