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

Add Newspeak type annotation support and local variable initializer expressions #175

Merged
merged 8 commits into from
Jul 26, 2017

Conversation

smarr
Copy link
Owner

@smarr smarr commented Jul 25, 2017

This PR improves overall compatibility with Newspeak in multiple ways, but the main improvements add support for type annotations and local variable initializer expressions.

  • parse Newspeak language version marker and module category at beginning of the file
  • parse local variable definition with initializer expressions and support definition of immutable local variables
  • add support for comments in more places, for instance around keyword messages, slot definitions, unary selectors
  • add a warning when value of integer literals with radix does not fit into long, big integers are not supported yet
  • allow minus - to be part of operator sequence

Below, some examples for the most noticeable newly supported syntax.

Local Variables with Initializers

Inside of methods, we can now use the slot initializer syntax as in Newspeak:

public bar = (
  | anImmutableInt = 42.
    aMutableInt ::= 43. |
  anImmutableInt:: 4. (* will raise compiler error *)
  aMutableInt:: aMutableInt + 1. (* works as expected *)
)

Type Annotations

Type annotations are supported for slot definitions as well as return types for messages.
These type annotations are currently not checked in anyway, and there are no plans to introduce checks.

For slots, examples are:

public class Foo (|
  public someNumber <Integer> ::= 42.
  public listOfStrings <List[String]> = createList.
  public blockWithValueArg <[:Value]> = [:v | v ].
|)()

For methods, return types can be specified for instance like this:

public class Foo ()(
  public bar ^ <Foo> = (
    ^ self
  )

  public - other ^ <Integer> = (
    ^ 6
  )
  
  public key: a word: b ^ <List[Promise[V, E]]> = (
    ^ List new
  )
)

@smarr smarr added the enhancement Improves the implementation with something noteworthy label Jul 25, 2017
@smarr smarr added this to the v0.5.0 milestone Jul 25, 2017
@coveralls
Copy link

Coverage Status

Coverage remained the same at 80.051% when pulling ca5afbc on ns-compat into d933bf1 on dev.

Repository owner deleted a comment Jul 25, 2017
Repository owner deleted a comment Jul 25, 2017
Repository owner deleted a comment Jul 25, 2017
Repository owner deleted a comment Jul 25, 2017
Repository owner deleted a comment Jul 25, 2017
@coveralls
Copy link

Coverage Status

Coverage increased (+0.05%) to 80.101% when pulling eadd962 on ns-compat into d933bf1 on dev.

Signed-off-by: Stefan Marr <git@stefan-marr.de>
- includes basic tests

Signed-off-by: Stefan Marr <git@stefan-marr.de>
Signed-off-by: Stefan Marr <git@stefan-marr.de>
- includes basic JUnit tests for the parser

Signed-off-by: Stefan Marr <git@stefan-marr.de>
Signed-off-by: Stefan Marr <git@stefan-marr.de>
Signed-off-by: Stefan Marr <git@stefan-marr.de>
Signed-off-by: Stefan Marr <git@stefan-marr.de>
Signed-off-by: Stefan Marr <git@stefan-marr.de>
Repository owner deleted a comment Jul 25, 2017
Repository owner deleted a comment Jul 25, 2017
Repository owner deleted a comment Jul 25, 2017
Repository owner deleted a comment Jul 25, 2017
Repository owner deleted a comment Jul 25, 2017
@coveralls
Copy link

Coverage Status

Coverage increased (+0.05%) to 80.101% when pulling cd369ee on ns-compat into d933bf1 on dev.

@smarr smarr merged commit 00f1fe9 into dev Jul 26, 2017
@smarr smarr deleted the ns-compat branch July 26, 2017 08:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improves the implementation with something noteworthy
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants