Skip to content

Commit

Permalink
backup
Browse files Browse the repository at this point in the history
  • Loading branch information
bristermitten committed Jul 31, 2023
1 parent 557cb32 commit cedb078
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 2 deletions.
52 changes: 52 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,58 @@ main = do
The `yield` keyword is primarily for functional languages and will often be ignored in imperative languages. It is used to describe the "return value" of the for loop that is added to the list of inputs.
If no `yield` is present, the last expression in the for loop will be implicitly yielded.

### Complex Example
Let's do an example with heavily nested inputs. For this challenge, we have a list of item names and prices, and then a list of people, who all have their own shopping list. We need to find the total cost of all the items on all the shopping lists.


An example input will look like this:
```
5
apple 1
milk 2
bread 2.5
cheese 3
chocolate 4
3
Alice
2
2 apple
1 milk
Bob
4
1 apple
1 milk
3 bread
2 cheese
Charlie
1
1 chocolate
```

We can describe the inputs using Templatespiler like so
```
item_count = readln Integer
items = for item_count as i {
name, price = readln String Float
yield name, price
}
person_count = readln Integer
people = for person_count as i {
name = readln String
shopping_list_count = readln Integer
shopping_list = for shopping_list_count as j {
count = readln Integer
name = readln String
yield count, name
}
yield name, shopping_list
}
println "solution"
```


## Getting Started

*tldr: Install Nix, enable Flakes, open in VSCode and run `just run`.*
Expand Down
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
# See https://github.com/srid/haskell-flake/blob/master/example/flake.nix
haskellProjects.default = {
# The base package set (this value is the default)
# basePackages = pkgs.haskellPackages;
basePackages = pkgs.haskell.packages.ghc92;

# Packages to add on top of `basePackages`
packages = {
Expand Down
2 changes: 1 addition & 1 deletion src/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ main :: IO ()
main = do
Utf8.withUtf8 $ do
contents <- readFileText "test.tmpspl"
case (runParser (parseBlock <* eof) "test.tmpspl" contents) of
case runParser (parseBlock <* eof) "test.tmpspl" contents of
Left err -> putStrLn $ errorBundlePretty err
Right ast -> putStrLn $ shower ast
14 changes: 14 additions & 0 deletions src/Templatespiler/CodeGen.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE DataKinds #-}

module Templatespiler.CodeGen where

import Templatespiler.AST (Block)

class CodeGen (lang :: Language) where
codeGen :: Block -> Text

data Language
= Java
| C
| Haskell
1 change: 1 addition & 0 deletions src/Templatespiler/CodeGen/C.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module Templatespiler.CodeGen.C where
1 change: 1 addition & 0 deletions src/Templatespiler/CodeGen/Haskell.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module Templatespiler.CodeGen.Haskell where
6 changes: 6 additions & 0 deletions src/Templatespiler/CodeGen/Java.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module Templatespiler.CodeGen.Java where

import Templatespiler.CodeGen

instance CodeGen 'Java where
codeGen = undefined

0 comments on commit cedb078

Please sign in to comment.