ETSI's Bug Tracker - Ext Pack: Advanced Matching (ES 203 022)
View Issue Details

ID | Project | Category | View Status | Date Submitted | Last Update
0007438 | Ext Pack: Advanced Matching (ES 203 022) | New Feature | public | 31-05-2016 13:55 | 24-12-2016 12:26

Reporter | Jacob Wieland - Spirent |
Assigned To | Jens Grabowski |
Priority | normal | Severity | minor | Reproducibility | have not tried
Status | closed | Resolution | fixed |
Platform |  | OS |  | OS Version |
Product Version |  |
Target Version | v1.1.1 (published 2017-07) | Fixed in Version | v1.1.1 (published 2017-07) |
Clause Reference(s) | Advanced Matching Package
Source (company - Author) | Spirent - Jacob Wieland
TS version |

Summary | 0007438: Templates with variable bindings.

Description

In function languages, it is customary to use patterns of constructed data types to define the parameters of functions. These patterns can contain unbound variables which will be bound if the pattern matches, so that they can be used on the right-hand-side of the definition.
Since TTCN-3 already has a powerful pattern language available, it would be very useful to allow a similar variable binding as a side-effect of matching.
We propose the following syntax:
<matching mechanism> -> <variable>
in all places where in a template body a matching mechanism is allowed at the moment.
For example:
type record Pair { integer a, integer b }
template Pair pair(out integer a, out integer b) := {
a := ? -> a,
b := ? -> b
}
var integer a, b;
var Pair p := ...;
if (match(p, pair(a,b))) { /* do something with a and b */ }
Of course, the assignment syntax could also be used in an inline template, as long as the variables used are declared in the context of the inline template.
if (match(p, Pair:{ ? -> a, ? -> b }) { /* same semantics as above */ }
The variable would be assigned the value that matched the corresponding matching mechanism iff the whole template body matches. The variable needs to be of the correct type, depending on the place of the matching mechanism inside the template body.
For convenience, parameterized templates would be allowed to declare out parameters to be used for variable binding.
A still open question is what should happen if a template has multiple ways of matching the value (as could, for instance, happen with { *, pair(a,b), * } in a record of Pair). As checking this condition can only be done at runtime and is normally much more expensive than searching for the first match, I propose to keep that ambiguous so that the result can be the assignment for ANY match, thus forcing the user to define the templates in a non-ambiguous way.
Alternatively, a construct could be introduced which allows multiply applying the match operation with the same template (e.g. in a template variable) until no new matching is found:
type record of Pair Pairs;
var Pairs p := ...;
var @match template Pairs t := { *, pair(a, b), * }; // this would be kind of a lazy definition
while (match(p, t)) { /* do something with a and b */ }
Of course, these kinds of templates could also be used in receive statements or anywhere else where templates for matching are allowed (i.e. select cases).
If passed as an actual in parameter, the formal parameter should be declared with a @match modifier so that it is clear that this template can only be used for matching. A template variable that is declared with the @match operator can not be used to be assigned to a normal template variable or used as a return template.

Steps To Reproduce |
Additional Information |
Tags | No tags attached.
Relationships |

Attached Files

Template-Inline-Redirect-Ideas-160722.pptx (30,328) 22-07-2016 13:36
http://oldforge.etsi.org/mantis/file_download.php?file_id=3435&type=bug
CR-7438-Templates-with-variable-bindings-V1.docx (30,289) 15-11-2016 13:21
http://oldforge.etsi.org/mantis/file_download.php?file_id=3521&type=bug
CR-7438-Templates-with-variable-bindings-V2.docx (41,461) 15-11-2016 16:39
http://oldforge.etsi.org/mantis/file_download.php?file_id=3526&type=bug
CR-7438-Templates-with-variable-bindings-V3.docx (49,638) 16-11-2016 11:03
http://oldforge.etsi.org/mantis/file_download.php?file_id=3530&type=bug
CR-7438-Templates-with-variable-bindings-V4.docx (49,739) 17-11-2016 10:10
http://oldforge.etsi.org/mantis/file_download.php?file_id=3549&type=bug
CR-7438-Templates-with-variable-bindings-V5.docx (50,836) 18-11-2016 10:09
http://oldforge.etsi.org/mantis/file_download.php?file_id=3565&type=bug

Issue History
Date Modified | Username | Field | Change
31-05-2016 13:55 | Jacob Wieland - Spirent | New Issue |
31-05-2016 13:58 | Jacob Wieland - Spirent | Clause Reference(s) | TBD => Advanced Matching Package
31-05-2016 16:50 | Jacob Wieland - Spirent | Description Updated | bug_revision_view_page.php?rev_id=291#r291
18-07-2016 10:25 | Jens Grabowski | Note Added: 0013974 |
18-07-2016 10:26 | Jens Grabowski | Assigned To | => Jens Grabowski
18-07-2016 10:26 | Jens Grabowski | Status | new => assigned
19-07-2016 16:22 | Jens Grabowski | Project | TTCN-3 Change Requests => Ext Pack: Advanced Matching (ES 203 022)
22-07-2016 13:36 | Jens Grabowski | File Added: Template-Inline-Redirect-Ideas-160722.pptx |
17-08-2016 11:56 | Jacob Wieland - Spirent | Target Version | => v1.1.1 (published 2017-07)
15-11-2016 13:21 | Jens Grabowski | File Added: CR-7438-Templates-with-variable-bindings-V1.docx |
15-11-2016 13:21 | Jens Grabowski | Assigned To | Jens Grabowski => Jacob Wieland - Spirent
15-11-2016 16:39 | Jacob Wieland - Spirent | File Added: CR-7438-Templates-with-variable-bindings-V2.docx |
15-11-2016 16:39 | Jacob Wieland - Spirent | Note Added: 0014254 |
15-11-2016 16:39 | Jacob Wieland - Spirent | Assigned To | Jacob Wieland - Spirent => Axel Rennoch
15-11-2016 16:39 | Jacob Wieland - Spirent | Status | assigned => confirmed
16-11-2016 11:03 | Axel Rennoch | File Added: CR-7438-Templates-with-variable-bindings-V3.docx |
16-11-2016 11:03 | Axel Rennoch | Note Added: 0014260 |
16-11-2016 11:04 | Axel Rennoch | Assigned To | Axel Rennoch => Jacob Wieland - Spirent
16-11-2016 11:04 | Axel Rennoch | Status | confirmed => assigned
16-11-2016 11:05 | Axel Rennoch | Note Added: 0014261 |
16-11-2016 11:05 | Axel Rennoch | Status | assigned => confirmed
17-11-2016 10:10 | Jacob Wieland - Spirent | File Added: CR-7438-Templates-with-variable-bindings-V4.docx |
17-11-2016 10:12 | Jacob Wieland - Spirent | Note Added: 0014294 |
17-11-2016 10:12 | Jacob Wieland - Spirent | Status | confirmed => resolved
17-11-2016 10:12 | Jacob Wieland - Spirent | Fixed in Version | => v1.1.1 (published 2017-07)
17-11-2016 10:12 | Jacob Wieland - Spirent | Resolution | open => fixed
17-11-2016 10:12 | Jacob Wieland - Spirent | Assigned To | Jacob Wieland - Spirent => Jens Grabowski
18-11-2016 09:48 | Jens Grabowski | Note Added: 0014326 |
18-11-2016 09:48 | Jens Grabowski | Assigned To | Jens Grabowski => Jacob Wieland - Spirent
18-11-2016 09:48 | Jens Grabowski | Status | resolved => assigned
18-11-2016 10:09 | Jacob Wieland - Spirent | File Added: CR-7438-Templates-with-variable-bindings-V5.docx |
18-11-2016 10:10 | Jacob Wieland - Spirent | Note Added: 0014328 |
18-11-2016 10:10 | Jacob Wieland - Spirent | Assigned To | Jacob Wieland - Spirent => Jens Grabowski
18-11-2016 10:10 | Jacob Wieland - Spirent | Status | assigned => confirmed
24-12-2016 12:26 | Jens Grabowski | Status | confirmed => closed

Notes

(0013974)
Jens Grabowski
18-07-2016 10:25

Candidate for "Advanced Matching" extension package.

(0014254)
Jacob Wieland - Spirent
15-11-2016 16:39

please do a preliminary review, this is still in the drafting stage, but please check whether everything is understandable

(0014260)
Axel Rennoch
16-11-2016 11:03

some corrections, formatting and text additions

(0014261)
Axel Rennoch
16-11-2016 11:05

please use version 3 for further updates

(0014294)
Jacob Wieland - Spirent
17-11-2016 10:12

I have reviewed again and made some small wording changes to not confuse the match operation with a template match.

(0014326)
Jens Grabowski
18-11-2016 09:48

BNF rules have to be added.

(0014328)
Jacob Wieland - Spirent
18-11-2016 10:10

added missing BNF changes part, please review and resolve