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

ttcn: add "template" ["(omit)" | "(value)" | "(present)"] #3456

Merged
merged 1 commit into from
Aug 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Units/parser-ttcn.r/ttcn-template-restriction.d/args.ctags
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--sort=no
5 changes: 5 additions & 0 deletions Units/parser-ttcn.r/ttcn-template-restriction.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CoffeeTemplates input.ttcn /^module CoffeeTemplates$/;" M
AnyCoffee input.ttcn /^template (present) Coffee AnyCoffee$/;" d
SomeCoffee input.ttcn /^template (value) Coffee SomeCoffee(integer id, charstring description := "")$/;" d
Espresso input.ttcn /^template (omit) Coffee Espresso()$/;" d
Latte input.ttcn /^template (TYPO IN RESTRICTION) Coffee Latte()$/;" d
32 changes: 32 additions & 0 deletions Units/parser-ttcn.r/ttcn-template-restriction.d/input.ttcn
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import from CoffeeTypes all
import from CoffeeConstants all

module CoffeeTemplates
{

template (present) Coffee AnyCoffee
{
id := ?,
description := ?
}

template (value) Coffee SomeCoffee(integer id, charstring description := "")
{
id := id,
description := description
}

template (omit) Coffee Espresso()
{
id := c_espressoId,
description := c_espresso
}

template (TYPO IN RESTRICTION) Coffee Latte()
{
id := c_latteId,
description := c_latte
}

}

18 changes: 17 additions & 1 deletion parsers/ttcn.c
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,21 @@ static int matchExprOperator (void)
return 0;
}

/* Check if next token is one of "(omit)", "(value)", "(present)".
* ETSI ES 201 873-1 V4.14.1
* A.1.6.7 471. TemplateRestriction ::= "(" (OmitKeyword | ValueKeyword | PresentKeyword) ")"
* A.1.6.6 461. OmitKeyword ::= "omit"
* A.1.6.4.2 346. ValueKeyword ::= "value"
* A.1.6.1.3 145.PresentKeyword ::= "present"
*/
static int matchTemplateRestriction (void)
{
/* Simplistic: do not verify the actual "omit"/"value"/"present" keyword, just skip the entire brackets when
* present. This also is tolerant to typos in the keyword. Drawback: would also accept any amount of unrelated
* tokens and punctuation in the braces. */
return matchBrackets(BR_PAR);
}

static int parseExprOperand (void)
{
ttcnToken_t * pTok;
Expand Down Expand Up @@ -950,7 +965,8 @@ static void parseTTCN (void)
parseTypeDefBody();
break;
case T_TEMPLATE:
/* A.1.6.1.3 TemplateDef ::= "template" (Type | Signature) ID ... */
/* A.1.6.1.3 TemplateDef ::= "template" [TemplateRestriction] (Type | Signature) ID ... */
matchTemplateRestriction();
if (parseType() || parseSignature())
parseID(K_TEMPLATE);
break;
Expand Down