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

parser: Update eventHandler parsing for parameters and bare return #70

Merged
merged 4 commits into from
Feb 15, 2023

Conversation

juliaogris
Copy link
Member

@juliaogris juliaogris commented Feb 9, 2023

Update eventHandler parsing for parameters and bare return. Add builtin
eventHandler declarations for known even names and parameters.

In preparation fix for loop variable declaration validation and unify
parameter declaration validation with variable declaration validation.

This is part one of a two part PR. The second Part will add evaluation and
wiring with frontend.

@github-actions
Copy link

github-actions bot commented Feb 9, 2023

firebase-deployment: https://evy-lang--70-nrwpfmke.web.app (63feee0)

Copy link
Contributor

@camh- camh- left a comment

Choose a reason for hiding this comment

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

🍏 LGTM

Sorry it took me so long to get to this.

print "func x"
end
for x := range 10
print "x" x
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: there's a mixture of 4-space indent and tab indent in the evy fragments throughout this file. This change adds more mixture (one of each). Maybe a trivial cleanup of it all later?

Copy link
Contributor

Choose a reason for hiding this comment

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

🍍 Perhaps ignore this for now since it may be painful to restack all your other PRs - this is my only comment and it's just a nit

Add variable validation in for statements. In specific, variable
declared in the as `for VAR :=  range ...` should follow the same
validation rules as other variable declarations. It's been an
oversight.
Use validateVarDecl in parameters rather than duplicating the validation
for the sake of slightly more accurate error messages.
Update eventHandler parsing for parameters and bare return. In follow up
commits we will add valid builtin eventHandler names and signatures and
add evaluation.
Validate eventHandlers against builtin names and parameters, such that
`on unknown_event` errors and eventhandlers with wrong types of
parameters also error. It is valid to drop all parameters in the source
if they aren't used.
@juliaogris juliaogris merged commit aa04208 into master Feb 15, 2023
juliaogris added a commit that referenced this pull request Feb 15, 2023
Wire eventHandler to frontend so that when `on <event>` block appears in
evy code the corresponding frontend event triggers the execution of
that block. Currently implemented events: `down`, `up`, `move`, `key`.

Only `frontend:` and `all:` commits are relevant, the `parser:` commits are
covered in #70

Sample code
https://evy-lang--73-51oq7tbx.web.app#draw

    on down x:num y:num
      print "down" x y
    end

    on up
      print "up"
    end

    on key c:string
       print "key" c
    end

simple drawing tool

    d := false
    width 1

    on down x:num y:num
      d = true
      move x y
    end

    on up
      d = false
    end

    on move x:num y:num
      if d
        line x y
      end
    end

This merges the following commits:
* frontend: Add memToString and stringToMem
* frontend: Unify naming and add comments
* frontend: Optionally load evy source via URL fragment
* frontend: Refactor canvas scale parameters
* all: Implement up, down, move and key events

     frontend/index.js          | 125 ++++++++++++++++++++++++++++++++-----
     frontend/samples/dot.evy   |  18 ++++++
     frontend/samples/draw.evy  |  17 +++++
     pkg/evaluator/evaluator.go |  51 +++++++++++++--
     pkg/evaluator/value.go     |  25 ++++++++
     pkg/parser/parser.go       |   8 +--
     pkg/wasm/main.go           |  78 +++++++++++++++++++++--
     7 files changed, 292 insertions(+), 30 deletions(-)

Pull-Request: #73
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants