Skip to main content

A world-building language for young storytellers

Project description

ForWhile

ForWhile CI License: MIT Version

A world-building programming language designed to teach Object-Oriented Programming (OOP) and core simulation concepts to young storytellers through a plain-English, narrative-driven syntax.


๐Ÿ“– Quick Links


๐ŸŒŸ Philosophy

Every feature in ForWhile is designed to serve a world-building and simulation philosophy:

  1. Teaches Real Programming Concepts: Maps directly to classes, objects, traits/properties, composition, methods, constructor methods, loops, and conditions.
  2. Easy to Understand: Reads like plain English narration.
  3. No Developer Jargon: Avoids being "Python with English words" by replacing technical keywords (like def, class, return) with narrative concepts (like creature, action, play scene).
  4. Reinforces World-building: Code reads like a fantasy story or simulation setup.

โš”๏ธ Syntax Comparison

Here is how ForWhile maps common programming paradigms to storytelling:

Programming Concept Traditional Language (e.g., Python) ForWhile Narrative Syntax
Class / Blueprint class Dragon: creature Dragon
Instantiation Ember = Dragon("Ember") bring Ember to life as Dragon with ("Ember")
State Mutation Ember.health = 100 give Ember the trait health to 100
Composition (Mixin) attach Fire to Ember attach Fire to Ember
Method / Action def breathe(self): action breathe
Method Call Ember.breathe() Ember does breathe
Constructor def __init__(self): when born
Conditional Block if condition: ... else: when condition: ... otherwise:
Objects Graph / Edge alice.friend = bob alice knows bob as friend
Plural References [x for x in env if type(x) == Dragon] the world's Dragon creatures
Event Callback observer.on('die', callback) whenever anyone dies
Time-Step Loop for _ in range(10): the world ticks 10 times
Functions / Calls def greet(n): / greet("Bob") scene greet with (n) / play scene greet with ("Bob")
Getter / Computed @property \n def power(self): power is health times 2

๐Ÿ› ๏ธ Installation

ForWhile requires Python 3.8+. Install it from your local package folder:

# Clone the repository
git clone https://github.com/ghanashyam03/ForWhile.git
cd ForWhile

# Install the package in editable development mode
pip install -e .

๐Ÿš€ Usage & CLI Commands

Once installed, the forwhile command is available directly in your terminal. It supports four subcommands:

1. Start the REPL (forwhile start)

Launch the interactive storytelling environment.

forwhile start

Type help inside the REPL to see a visual cheat sheet of commands.

2. Run a Story File (forwhile run <file.fw>)

Bring a .fw story script to life and see the narration.

forwhile run examples/11_story_structure.fw

3. Check a Story File (forwhile check <file.fw>)

Verify a story file for syntax errors or invalid vocabulary without running it.

forwhile check examples/13_trait_kinds.fw

4. Version Check (forwhile --version)

Print the current version of the ForWhile engine.

forwhile --version

๐Ÿ  Project Structure

ForWhile/
โ”œโ”€โ”€ forwhile/              # Core Source Code
โ”‚   โ”œโ”€โ”€ errors.py          # Custom child-friendly errors
โ”‚   โ”œโ”€โ”€ interpreter.py     # Main AST evaluation, CLI, and REPL
โ”‚   โ”œโ”€โ”€ lexer.py           # PLY Lexer (tokenization)
โ”‚   โ””โ”€โ”€ parser.py          # PLY Parser (Abstract Syntax Tree builder)
โ”œโ”€โ”€ tests/                 # Comprehensive Test Suites
โ”‚   โ”œโ”€โ”€ test_basic.py
โ”‚   โ”œโ”€โ”€ test_cli.py
โ”‚   โ”œโ”€โ”€ test_coverage_boost.py
โ”‚   โ”œโ”€โ”€ test_examples.py
โ”‚   โ””โ”€โ”€ ...
โ”œโ”€โ”€ examples/              # Sample Story Scripts
โ”‚   โ”œโ”€โ”€ 01_hello.fw
โ”‚   โ”œโ”€โ”€ 11_story_structure.fw
โ”‚   โ””โ”€โ”€ 15_ecosystem.fw    # Fox/Rabbit/Grass ecosystem simulation
โ”œโ”€โ”€ docs/                  # Documentation
โ”‚   โ”œโ”€โ”€ LANGUAGE_SPEC.md
โ”‚   โ””โ”€โ”€ EDUCATORS_GUIDE.md
โ”œโ”€โ”€ editors/vscode/        # VS Code Extension Support
โ”‚   โ”œโ”€โ”€ package.json       # Extension configuration
โ”‚   โ””โ”€โ”€ syntaxes/          # Syntax highlighting definition
โ”œโ”€โ”€ setup.py               # legacy setuptools installation
โ”œโ”€โ”€ pyproject.toml         # Modern package manifest
โ””โ”€โ”€ LICENSE                # MIT License

๐Ÿงช Development & Testing

We maintain a strict code coverage requirement of $\ge 90%$ on forwhile/interpreter.py.

Install test dependencies and run the tests:

pip install pytest pytest-cov
python -m pytest --cov=forwhile --cov-report=term-missing

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

forwhile-1.0.0.tar.gz (28.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

forwhile-1.0.0-py3-none-any.whl (19.4 kB view details)

Uploaded Python 3

File details

Details for the file forwhile-1.0.0.tar.gz.

File metadata

  • Download URL: forwhile-1.0.0.tar.gz
  • Upload date:
  • Size: 28.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.5

File hashes

Hashes for forwhile-1.0.0.tar.gz
Algorithm Hash digest
SHA256 2b473e28b6e474ec73ecc84040fad6e7763a1531cadde6908867c5faba2694e8
MD5 8c4a7273d54b7f9c3267cf3d2a6acdda
BLAKE2b-256 86e89789e568ec07e7a290f234e7211fe4232e828e80ac7776d2e1483c573c38

See more details on using hashes here.

File details

Details for the file forwhile-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: forwhile-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 19.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.5

File hashes

Hashes for forwhile-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 aad3b788e85f230504ea6e456bfb184c1b006763164296665ae279219b808b3a
MD5 425d00caa5ba93d1ed0877bc7708a52e
BLAKE2b-256 7926a496869250a7c65c1c2405d6f454f2537b9a2f9ccde0908822966b690a4f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page