Skip to content

Commit

Permalink
Couple missing tests + readme updates
Browse files Browse the repository at this point in the history
now with funny
  • Loading branch information
dusty-phillips committed Aug 20, 2024
1 parent ebf3b60 commit b42edd9
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 4 deletions.
34 changes: 30 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,26 @@
# macabre
# Macabre

**macabre** : (adj) _tending to produce horror in a beholder_

Seriously, Just back away slowly. I'm just playing around.

Are you still here? Don't you know there's a monster at the end of this book?

## What have you done?

Nothing, yet. It only "barely" work if we carefully redefine "barely" to "doesn't".

This is an ultra experimental compiler written in Gleam to compile Gleam source code (using
the [glance](https://hexdocs.pm/glance/) package) to Python.

## Why are you doing this?

I have no idea. It's fun and educational. (I'm on a role with this redefining words thing)

## Usage

```sh
gleam run -- some_file.gleam # compile to python
gleam run -- some_very_simple_file.gleam # compile to python
```

## Development
Expand All @@ -10,12 +29,19 @@ gleam run -- some_file.gleam # compile to python
gleam test # Run tests with glacier
```

## Contributing

Are you insane? Sweet, me too. PRs are welcome.

### TODO

- most operators and expressions aren't implemented yet
- flesh out this list
- most expressions aren't implemented yet
- need to print out nice errors when glance fails to parse
- No List or Result custom types yet
- glance doesn't support comments
- glance doesn't fully typecheck (e.g. `2.0 - 1.5` compiles successfully, but should be `2.0 -. 1.5`)
- not currently generating python type hints (e.g. function arguments and return types), but gleam gives us that info so may as well use it
- no concept of a "project", gleam.toml, downloading dependencies
- only compiles one module at a time
- not sure how to account for `/` on two ints.
- eliminate all todos in source code
1 change: 1 addition & 0 deletions src/generator.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ fn generate_statement(statement: python.Statement) -> StringBuilder {
|> string_builder.append(name)
|> string_builder.append(" = ")
|> string_builder.append_builder(generate_expression(value))
|> string_builder.append("\n")
}
}
}
Expand Down
16 changes: 16 additions & 0 deletions test/assignment_test.gleam
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import glacier/should
import macabre

pub fn multi_variant_custom_type_test() {
"pub fn main() {
let a = \"hello world\"
}
"
|> macabre.compile
|> should.be_ok
|> should.equal(
"def main():
a = \"hello world\"
",
)
}
13 changes: 13 additions & 0 deletions test/expression_test.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,19 @@ pub fn false_expression_test() {
)
}

pub fn variable_expression_test() {
"fn main() {
println(a)
}"
|> macabre.compile
|> should.be_ok
|> should.equal(
"def main():
println(a)
",
)
}

pub fn tuple_index_test() {
"fn main() {
#(42, 12.5, \"foo\").1
Expand Down

0 comments on commit b42edd9

Please sign in to comment.