HN Reader

NewTopBestAskShowJob
Show HN: Dragon (programming lang, also known as Dragonlang)
score icon2
comment icon0
14 hours agoby telui
# Dragonlang

Tiny line-based language with a minimal interpreter in `__main__.py`.

## File extension

Source files use the `.dragon` extension. The interpreter also accepts a filename without an extension and will try `<name>.dragon` if it exists.

## Running

File mode:

```bash python __main__.py path/to/program.dragon ```

REPL mode:

```bash python __main__.py ```

Type `exit` or `quit` to leave the REPL.

### File resolution

When a path argument has no extension (no `.` anywhere in the name), the interpreter tries `<path>.dragon` first if it exists.

## Execution model

- The interpreter processes one line at a time. - There is no multi-line syntax, block structure, or statement separator. - Parsing is based on simple substring checks, not tokenization or a grammar.

### Matching order

Lines are checked in this order, and the first match wins:

1. `+` (addition) 2. `-` (subtraction) 3. `print` 4. `on error` 5. exact variable lookup 6. fallback error

This means lines containing `+` or `-` will never reach `print` or `on error` handling, even if those words appear in the line.

## Syntax and behavior (based on `__main__.py`)

Each line is processed independently. Parsing is minimal and based on substring checks, not a formal grammar.

### Print

Print a string literal:

```dragon print "hello" print 'world' ```

If the text after `print` matches a variable name in the interpreter environment, its value is printed instead. (Variables are not yet assignable.)

Notes:

- `print` is detected anywhere in the line, not just at the start. - The interpreter strips `print` and then trims spaces and quotes (`"`, `'`) from both ends. There is no escape handling.

### Integer math

Addition and subtraction are supported with integers:

```dragon 2+3 10-4 ```

Whitespace around operators is allowed.

Notes:

- The interpreter splits on the first `+` or `-` it sees. - Both sides are trimmed and looked up in the environment before parsing. - Non-integer values raise a `ValueError` and are reported as a generic error.

### Variables (read-only)

Variables can be read if they already exist in the interpreter environment. There is currently no syntax to assign new variables. Variables are stored in the `env` dictionary in `__main__.py`.

### "on error"

There is a special line prefix `on error` that is parsed but does not currently produce output. It strips the prefix, looks up the remaining text in the environment if present, and then returns without printing.

## Error behavior

- File mode: any exception in `run()` prints `Error in line: <line>`. - REPL mode: exceptions are caught, but the current code prints the exception class object rather than the actual error message.

## Example program

```dragon print "hello" 2 + 3 10-4 ```

## Current limitations

- No variable assignment yet (the environment is read-only). - No conditionals, loops, or functions. - No comments, string escapes, or multi-line statements. - Errors are reported as `Error in line: <line>`. - The `on error` line is parsed but has no visible effect.

## Reserved words

The following words are used in the interpreter:

- `webcollect` - `list` - `open` - `system` - `shutdown` - `warn` - `go to` - `enter` - `info` - `time` - `pause`

## Using `pause`

```dragon pause <amount> ```

No comments