Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

web api to parse, render, and run code #1142

Merged
merged 6 commits into from
Apr 25, 2023
Merged

web api to parse, render, and run code #1142

merged 6 commits into from
Apr 25, 2023

Conversation

kostmo
Copy link
Member

@kostmo kostmo commented Mar 6, 2023

Closes #625.

Demo

Running code

Start a creative game:

scripts/play.sh --scenario data/scenarios/creative.yaml

In another terminal window:

curl -H "Content-Type: text/plain; charset=utf-8" -i http://localhost:5357/code/run --data "move;"

Observe that the robot has moved, and that the command sent via curl has been added to the REPL history.

Parsing and rendering code

Start swarm:

scripts/play.sh

Run curl:

curl --silent -H "Content-Type: text/plain; charset=utf-8"  -i http://localhost:5357/code/render --data @data/test/language-snippets/warnings/unused-vars/multiple-lambda-first-unused.sw

See output:

HTTP/1.1 200 OK
Transfer-Encoding: chunked
Date: Mon, 06 Mar 2023 10:16:12 GMT
Server: Warp/3.3.23
Content-Type: text/plain;charset=utf-8

def put = \x. \y. place y end
|
`- \x. \y. place y
   |
   `- \y. place y
      |
      `- place y
         |
         +- place
         |
         `- y

src/Swarm/Web.hs Outdated Show resolved Hide resolved
@kostmo kostmo force-pushed the web-parse-code branch 2 times, most recently from f6fc462 to cec96d2 Compare March 18, 2023 06:39
@kostmo kostmo marked this pull request as ready for review March 18, 2023 06:40
@kostmo kostmo changed the title web api to parse and render code web api to parse, render, and run code Mar 18, 2023
Copy link
Member Author

@kostmo kostmo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ready for another look, @byorgey.

src/Swarm/TUI/Controller.hs Show resolved Hide resolved
src/Swarm/Web.hs Outdated
drawTree . fmap prettyString . para Node $ stx
Left x -> x
codeRunHandler contents = do
liftIO $ writeBChan chan $ Web $ RunWebCode contents
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potentially we could do some syntactical validation "client-side" before sending the raw text over the channel. We could even use the GameState from the IORef to parse the code "in context" with processTerm'. However, we would probably want to re-parse it "game-side", because (1) we want to add the raw command text to the REPL history, and (2) possible race condition (as mentioned above w.r.t. replWorking).

But I think that both of these client-side validations could wait until a later PR.

Copy link
Member

@byorgey byorgey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry it took me so long to look at this!

src/Swarm/Web.hs Outdated Show resolved Hide resolved
src/Swarm/TUI/Controller.hs Show resolved Hide resolved
@byorgey
Copy link
Member

byorgey commented Apr 25, 2023

@kostmo are there any other PRs that you'd like feedback on at the moment? I think I'm now caught up but I could very easily have missed some.

@kostmo
Copy link
Member Author

kostmo commented Apr 25, 2023

any other PRs

#974 is blocked on a stale change request, maybe @xsebek can unblock it?

@kostmo kostmo added the merge me Trigger the merge process of the Pull request. label Apr 25, 2023
@mergify mergify bot merged commit eb90bfb into main Apr 25, 2023
@mergify mergify bot deleted the web-parse-code branch April 25, 2023 21:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge me Trigger the merge process of the Pull request.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement run command for the web service
2 participants