Skip to content

Commit

Permalink
Merge pull request #3456 from neeels/neels/ttcn3
Browse files Browse the repository at this point in the history
ttcn: add "template" ["(omit)" | "(value)" | "(present)"]
  • Loading branch information
masatake committed Aug 22, 2022
2 parents 35b9c9a + d92a92f commit dfffd3d
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
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

0 comments on commit dfffd3d

Please sign in to comment.