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.1.tar.gz (28.3 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.1-py3-none-any.whl (19.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: forwhile-1.0.1.tar.gz
  • Upload date:
  • Size: 28.3 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.1.tar.gz
Algorithm Hash digest
SHA256 3a81e5f899047d842314672b8b0afd374474d562a13bcc289726d7c99017f168
MD5 9e0847d52135d6cfd7abc7282df6e23a
BLAKE2b-256 d3b4cfeee1510f698dfacfada666e9d6df5c7eb29619f0a2adecd8d478bc4451

See more details on using hashes here.

File details

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

File metadata

  • Download URL: forwhile-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 19.7 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 05ce028c58f7cb8838605c7c9c6353f1b8e06bb1d5bfd92cef25c78d9f1a9c93
MD5 b2f2ce8abe49822e6f9128009ebd3a59
BLAKE2b-256 9c5b906af911c7d63474b8320db7af171294dc3959f5c78be3e5dca6ac972f0b

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