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 . |
||
---|---|---|
.github | ||
.vscode | ||
app | ||
data | ||
docs | ||
editors | ||
example | ||
images | ||
scripts | ||
src | ||
test | ||
tournament | ||
web | ||
.gitignore | ||
.hlint.yaml | ||
.mergify.yml | ||
.restyled.yaml | ||
.stan.toml | ||
cabal.haskell-ci | ||
CHANGELOG.md | ||
CODE_OF_CONDUCT.md | ||
COMMUNITY.md | ||
CONTRIBUTING.md | ||
cspell.json | ||
DESIGN.md | ||
feedback.yaml | ||
fourmolu.yaml | ||
hie.cabal.yaml | ||
hie.stack.yaml | ||
LICENSE | ||
NOTICE | ||
pull_request_template.md | ||
README.md | ||
scenarios | ||
stack.yaml | ||
swarm.cabal |
Swarm
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.
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.
-
Clone the Swarm repository, e.g.
git clone https://github.com/swarm-game/swarm.git
-
If you don't already have the
cabal
tool:-
Get the
ghcup
tool, a handy one-stop utility for managing all the different pieces of a Haskell toolchain. -
Use
ghcup
to install a supported version of GHC:ghcup install ghc 9.6.4
-
Use
ghcup
to installcabal
:ghcup install cabal
-
-
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.) -
Go get a snack while
cabal
downloads and builds all of Swarm's dependencies. -
You might also want to check out the
scripts
directory, which contains an assortment of useful scripts for developers.