Resource gathering + programming game
Go to file
Brent Yorgey 76958a4639
Insert parsed comments back into the AST and pretty-print with comments (#1845)
This PR does three main things:
1. Insert parsed comments into the AST
2. Extend pretty-printing to include comments
3. Extend the `format` subcommand with a few additional options and move the code to `Swarm.Language.Format`.

The pretty-printed code-with-comments is OK but not great.  It does a reasonable job with comments in standard-ish places; for example, it turns
```
// This function increments a number
def incr : int -> int =
  \n. n + 1
end

/* This command does some stuff.  It is super
   cool and important. */
def stuff : cmd unit =
  move;
  move;
  move;  // the third move is important
  move;
end
```
into
```

// This function increments a number
def incr: int -> int = \n. n + 1 end;

/* This command does some stuff.  It is super
   cool and important. */
def stuff: cmd unit =
  move;
  move;
  move // the third move is important
  ;
  move
end
```
which is good other than the fact that it moves the inline comment after `move;` to before the semicolon.

However, it turns this:
```
// This function does a cool math thing
def foo : int -> int =     // This is an optional type signature
  // pre
  \n. n + 1    // add one
end

/* This is a
   block comment which
   spans multiple lines */

def bar : int -> int   // Another type signature, = on the next line
  = \x. foo /* very important to use foo here */ (foo x)   // very cool implementation
end

def baz : cmd unit =
  move;
  move;
  turn left;   // don't forget to turn left!
  move
end

// And one last thing
```
into this:
```

// This function does a cool math thing
def foo: int -> int 
  = \n.
  n + 1 // add one

end // This is an optional type signature
;

/* This is a
   block comment which
   spans multiple lines */
def bar: int -> int 
  = \x.
  foo /* very important to use foo here */ (
    foo x // very cool implementation

  )
end // Another type signature, = on the next line
```
which has several obvious problems.  I think I know what the problem is in most cases; it will just require more engineering and special cases to get the output to look nicer, but I honestly don't really want to spend more time on this right now.  I'm hoping we can merge this as is (since it is still better than the status quo, namely, deleting all comments) and continue to improve it in the future.

The important point is that I ran the code formatter on every single `.sw` file in the repository and then re-ran the test suite; all the tests passed. So at least `swarm format` does not seem to break anything even if the output does not look the best.

Closes #1467 .
2024-05-14 11:32:03 +00:00
.github Support GHC 9.8, bump upper bounds, and update CI (#1828) 2024-05-10 14:43:41 -05:00
.vscode extensible terrain (#1775) 2024-02-29 06:22:21 +00:00
app Insert parsed comments back into the AST and pretty-print with comments (#1845) 2024-05-14 11:32:03 +00:00
data structure placement order (#1833) 2024-05-10 20:27:53 +00:00
docs Update sublibrary graph generation script & cabal description (#1849) 2024-05-13 17:25:00 +00:00
editors volume command (#1747) 2024-01-28 01:02:08 +00:00
example Key input handler (#1214) 2023-04-25 16:39:59 +00:00
images 0.4 release blog post (#1444) 2023-08-22 12:35:05 -05:00
scripts Update sublibrary graph generation script & cabal description (#1849) 2024-05-13 17:25:00 +00:00
src Insert parsed comments back into the AST and pretty-print with comments (#1845) 2024-05-14 11:32:03 +00:00
test Insert parsed comments back into the AST and pretty-print with comments (#1845) 2024-05-14 11:32:03 +00:00
tournament Use sqlite and static binary (#1837) 2024-05-12 20:45:08 +00:00
web Render command matrix (#1658) 2024-01-26 01:02:14 +00:00
.gitignore refactoring towards tournament server (#1801) 2024-04-22 18:55:06 +00:00
.hlint.yaml Upload and parse scenarios (#1798) 2024-04-25 20:11:11 +00:00
.mergify.yml Support GHC 9.8, bump upper bounds, and update CI (#1828) 2024-05-10 14:43:41 -05:00
.restyled.yaml Fourmolu fixup (#1326) 2023-07-12 18:00:23 +00:00
.stan.toml exclude some stan observations 2021-09-15 06:39:21 -05:00
cabal.haskell-ci Support GHC 9.8, bump upper bounds, and update CI (#1828) 2024-05-10 14:43:41 -05:00
CHANGELOG.md 0.5 release (#1606) 2023-11-01 10:18:16 +00:00
CODE_OF_CONDUCT.md Adopt the Contributor Covenant Code of Conduct 2021-09-19 13:38:33 -05:00
COMMUNITY.md some updates to README and COMMUNITY 2022-10-05 17:52:52 -05:00
CONTRIBUTING.md Recommend cabal (#1822) 2024-05-06 00:09:33 +00:00
cspell.json autopopulate spellchecker (#1749) 2024-01-28 01:54:13 +00:00
DESIGN.md More minor edits (#693) 2022-09-18 12:04:33 +00:00
feedback.yaml Parse comments (#1838) 2024-05-12 00:32:21 +00:00
fourmolu.yaml World description DSL (#1376) 2023-08-17 11:08:42 +00:00
hie.cabal.yaml Recommend cabal (#1822) 2024-05-06 00:09:33 +00:00
hie.stack.yaml Recommend cabal (#1822) 2024-05-06 00:09:33 +00:00
LICENSE Update editors (#581) 2022-07-25 00:16:23 +02:00
NOTICE Use a new opaque type for robots instead of strings (#303) 2022-03-02 03:00:44 +00:00
pull_request_template.md Add a pull request template (#1434) 2023-08-20 19:43:27 +00:00
README.md Recommend cabal (#1822) 2024-05-06 00:09:33 +00:00
scenarios Documentation for scenario file format (#612) 2022-07-30 08:02:11 -04:00
stack.yaml Dependency updates (#1765) 2024-02-12 20:04:28 +00:00
swarm.cabal Insert parsed comments back into the AST and pretty-print with comments (#1845) 2024-05-14 11:32:03 +00:00

Swarm

Build Status GitHub release (latest by date) Swarm release on Hackage Contributor Covenant ircchat GitHub Contributors

Swarm is a 2D programming and resource gathering game. Program your robots to explore the world and collect resources, which in turn allows you to build upgraded robots that can run more interesting and complex programs. More info can be found on the Swarm website.

World 0 after scanning a tree and making a log.

Contributing

See CONTRIBUTING.md for information about various ways you can contribute to Swarm development!

Building

If you just want to play the game, head over to the Swarm website for installation instructions. If you want to build Swarm from source (e.g. in order to contribute, or to test out the latest bleeding-edge unreleased features), read on.

  1. Clone the Swarm repository, e.g.

    git clone https://github.com/swarm-game/swarm.git
    
  2. If you don't already have the cabal tool:

    1. Get the ghcup tool, a handy one-stop utility for managing all the different pieces of a Haskell toolchain.

    2. Use ghcup to install a supported version of GHC:

      ghcup install ghc 9.6.4
      
    3. Use ghcup to install cabal:

      ghcup install cabal
      
  3. Now use cabal to build and run Swarm:

    cd /path/to/the/swarm/repo
    cabal run -O0 swarm:exe:swarm
    

    (Note that we recommend turning off optimizations with -O0 since they don't seem to make much difference to the speed of the resulting executable, but they make a big difference in compilation time.)

  4. Go get a snack while cabal downloads and builds all of Swarm's dependencies.

  5. You might also want to check out the scripts directory, which contains an assortment of useful scripts for developers.