Picolab / pico-engine

An implementation of the pico-engine hosted on node.js
http://picolabs.io/
MIT License
43 stars 8 forks source link

relax the rules for semi-colons #73

Open b1conrad opened 7 years ago

b1conrad commented 7 years ago
farskipper commented 7 years ago

available as of krl-parser@0.19.0

0joshuaolson1 commented 7 years ago

Now semicolons can terminate the last expression in functions. ~They can't terminate items in an action block.~

farskipper commented 7 years ago

Available, as of pico-engine 0.12.x

semi-colons can now be used to follow any action, either in a block or by itself.

More details/help here: https://github.com/Picolab/node-pico-engine/blob/master/CHANGELOG.md#0120---may-25-2017

cgrimm013 commented 7 years ago

(EDIT: not a problem anymore) Not sure exactly what's going on, but in a defaction the parser is only allowing me to have a semicolon on the first declaration. Any subsequent declarations containing semi-colons cause a parsing ambiguity error. Example code:


deleteChild = defaction(pico_name){
      ent_children = children().children
      filtered_children = ent_children.collect(function(child){
                                              (child{"name"} ==  pico_name) => "to_delete" | "dont_delete"
                                            })
      child_to_delete = filtered_children{"to_delete"}.head()

      every {
        engine:removePico(child_to_delete.id)
        send_directive("Deleting child", {"message": "Deleting pico with the given name: "+pico_name})
      }
      returns
      {
        "status": true,
        "updated_children": filtered_children.dont_delete,
        "child": child_to_delete.id
      }
    }```
Only "ent_children = children().children" can have a semi-colon
0joshuaolson1 commented 7 years ago

Also, functions now require semicolons after declarations. This is inconsistent with preludes and defactions.

0joshuaolson1 commented 7 years ago

I noted the special case for functions here.

0joshuaolson1 commented 7 years ago

Labelling as blocked until we agree to forbid standalone expressions in functions, which seems to make the grammar ambiguous unless semicolons are used. @windley?

windley commented 6 years ago

Can you give me some clear examples?

0joshuaolson1 commented 6 years ago

farskipper's tests can come up with counterexamples for bad grammars, such as the current grammar modified to not require (semicolon) separators in functions. As for 'standalone expressions' I think we can do without, I mean the second line in the function:

function(a){
  b = function(c){a + c};
  b(0);
  b(1)
}
windley commented 6 years ago

But this isn't valid. A function is a decl block followed by an expression. This has two expressions.

0joshuaolson1 commented 6 years ago

That answers that, then. Thanks.

Also, can we get rid of them in postludes, I wonder...