From b42edd9ddf1317dd8289277f70d8699b2b261119 Mon Sep 17 00:00:00 2001 From: Dusty Phillips Date: Mon, 19 Aug 2024 21:10:18 -0300 Subject: [PATCH] Couple missing tests + readme updates now with funny --- README.md | 34 ++++++++++++++++++++++++++++++---- src/generator.gleam | 1 + test/assignment_test.gleam | 16 ++++++++++++++++ test/expression_test.gleam | 13 +++++++++++++ 4 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 test/assignment_test.gleam diff --git a/README.md b/README.md index c28dc26..2325289 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 diff --git a/src/generator.gleam b/src/generator.gleam index 402e521..2d892d2 100644 --- a/src/generator.gleam +++ b/src/generator.gleam @@ -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") } } } diff --git a/test/assignment_test.gleam b/test/assignment_test.gleam new file mode 100644 index 0000000..8ea6a80 --- /dev/null +++ b/test/assignment_test.gleam @@ -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\" + ", + ) +} diff --git a/test/expression_test.gleam b/test/expression_test.gleam index 2697b17..433ce62 100644 --- a/test/expression_test.gleam +++ b/test/expression_test.gleam @@ -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