Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 340669 - [EOL] Implement Map literals
Summary: [EOL] Implement Map literals
Status: CLOSED FIXED
Alias: None
Product: Epsilon
Classification: Modeling
Component: Core (show other bugs)
Version: unspecified   Edit
Hardware: PC Linux
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Antonio Garcia-Dominguez CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-03-22 10:57 EDT by Antonio Garcia-Dominguez CLA
Modified: 2012-08-29 17:34 EDT (History)
2 users (show)

See Also:


Attachments
Patch which implements Map literals (7.59 KB, patch)
2011-03-22 10:58 EDT, Antonio Garcia-Dominguez CLA
dkolovos: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Antonio Garcia-Dominguez CLA 2011-03-22 10:57:41 EDT
We already have literal expressions for Sequences, Bags, OrderedSets and so on, but we don't have one for Map objects. In the upcoming version of EUnit, we currently do something like this:

$with Sequence {"", "A"}
@test
operation etc() {
  -- ...
}

In the $with annotation, we intend to say 'the default model is A', but this meaning is hard to see, as we're using a Sequence instead of a Map. It would be easier to read with a Map literal expression, like this:

$with Map {"" = "A"}
@test
operation etc() {
  -- ...
}

After talking with Dimitris, we'd like to use "=" instead of ":" (à la Python) or "=>" (à la Perl) as key-value separator, in order to stay closer to OCL and its Tuples. However, this may introduce ambiguities in the grammar. How should we interpret "Map { 1 = 2 = 3 }"? Should it have one (false, 3) pair, or one (1, false) pair?
Comment 1 Antonio Garcia-Dominguez CLA 2011-03-22 10:58:06 EDT
Created attachment 191687 [details]
Patch which implements Map literals

Here is a patch which adds Map literals to EOL, including several test cases for the EOL acceptance suite. Please note that:

- To make the patch more readable, it does not include the code generated by ANTLR. After applying the patch, ANTLR will have to be run again in all E*L languages.

- The "a = b = c" ambiguity has been resolved by using additiveExpression for the key, and logicalExpression for the value. Therefore, keys cannot use logical or relational operators unless between parenthesis, and "1 = 2 = 3" will be split into 1 (the key) and 2 = 3 (the value).
Comment 2 Antonio Garcia-Dominguez CLA 2011-05-19 12:24:28 EDT
I have integrated the patch which adds Map literals. I'm not sure about using them in EUnit, though: I think Louis
Comment 3 Antonio Garcia-Dominguez CLA 2011-05-19 12:27:21 EDT
I have integrated the patch. Do you think it would be OK to change $with to use Map literals now, before (hopefully) EUnit starts being more widely used?
Comment 4 Louis Rose CLA 2011-05-19 12:36:21 EDT
(In reply to comment #3)
> I have integrated the patch. Do you think it would be OK to change $with to use
> Map literals now, before (hopefully) EUnit starts being more widely used?

+1 for changing EUnit now. If we choose to change it now, we should also make a note to the update the paper (if it's accepted)!
Comment 5 Antonio Garcia-Dominguez CLA 2011-05-20 05:24:55 EDT
I've changed EUnit so it uses Map literals. I've also updated the tests, examples and the EUnit chapter accordingly.

I'll tackle the "floating point numbers do not allow exponents" issue described in 333740 and then write the section on EOL literals.
Comment 6 Antonio Garcia-Dominguez CLA 2011-06-16 03:54:04 EDT
I have just committed to SVN the section on EOL literals to the book. Marking this as fixed in SVN.
Comment 7 Dimitris Kolovos CLA 2011-07-25 08:17:07 EDT
Fixed in 0.9.1