Skip to content

Commit 4c086cf

Browse files
authored
Add support for altstep interleave to the parser (#773)
1 parent 5ea76a9 commit 4c086cf

4 files changed

Lines changed: 80 additions & 29 deletions

File tree

ttcn3/syntax/nodes.go

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -576,11 +576,12 @@ type (
576576

577577
// A BehaviourSpec represents a behaviour type specification.
578578
BehaviourSpec struct {
579-
KindTok Token // TESTCASE, FUNCTION, ALTSTEP
580-
Params *FormalPars // Parameter list or nil
581-
RunsOn *RunsOnSpec // runs on spec or nil
582-
System *SystemSpec // system spec or nil
583-
Return *ReturnSpec // return value spec or nil
579+
KindTok Token // TESTCASE, FUNCTION, ALTSTEP
580+
Interleave Token // INTERLEAVE or nil
581+
Params *FormalPars // Parameter list or nil
582+
RunsOn *RunsOnSpec // runs on spec or nil
583+
System *SystemSpec // system spec or nil
584+
Return *ReturnSpec // return value spec or nil
584585
}
585586
)
586587

@@ -636,18 +637,19 @@ type (
636637

637638
// A FuncDecl represents a behaviour definition.
638639
FuncDecl struct {
639-
External Token // Position of "external" or nil
640-
KindTok Token // TESTCASE, ALTSTEP, FUNCTION
641-
Name *Ident
642-
Modif Token // Position of "@deterministic" or nil
643-
TypePars *FormalPars
644-
Params *FormalPars // Formal parameter list or nil
645-
RunsOn *RunsOnSpec // Optional runs-on-spec
646-
Mtc *MtcSpec // Optional mtc-spec
647-
System *SystemSpec // Optional system-spec
648-
Return *ReturnSpec // Optional return-spec
649-
Body *BlockStmt // Body or nil
650-
With *WithSpec
640+
External Token // Position of "external" or nil
641+
KindTok Token // TESTCASE, ALTSTEP, FUNCTION
642+
Interleave Token // INTERLEAVE or nil
643+
Name *Ident
644+
Modif Token // Position of "@deterministic" or nil
645+
TypePars *FormalPars
646+
Params *FormalPars // Formal parameter list or nil
647+
RunsOn *RunsOnSpec // Optional runs-on-spec
648+
Mtc *MtcSpec // Optional mtc-spec
649+
System *SystemSpec // Optional system-spec
650+
Return *ReturnSpec // Optional return-spec
651+
Body *BlockStmt // Body or nil
652+
With *WithSpec
651653
}
652654

653655
// A ConstructorDecl represents a class constructor definition.
@@ -728,15 +730,16 @@ type (
728730

729731
// A BehaviourTypeDecl represents a named behaviour type.
730732
BehaviourTypeDecl struct {
731-
TypeTok Token // Position of "type"
732-
KindTok Token // TESTCASE, ALTSTEP, FUNCTION
733-
Name *Ident
734-
TypePars *FormalPars
735-
Params *FormalPars // Formal parameter list
736-
RunsOn *RunsOnSpec // Optional runs-on spec
737-
System *SystemSpec // Optional system spec
738-
Return *ReturnSpec // Optional return spec
739-
With *WithSpec
733+
TypeTok Token // Position of "type"
734+
KindTok Token // TESTCASE, ALTSTEP, FUNCTION
735+
Interleave Token // INTERLEAVE or nil
736+
Name *Ident
737+
TypePars *FormalPars
738+
Params *FormalPars // Formal parameter list
739+
RunsOn *RunsOnSpec // Optional runs-on spec
740+
System *SystemSpec // Optional system spec
741+
Return *ReturnSpec // Optional return spec
742+
With *WithSpec
740743
}
741744

742745
PortTypeDecl struct {

ttcn3/syntax/nodes_gen.go

Lines changed: 33 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ttcn3/syntax/parser.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1833,6 +1833,11 @@ func (p *parser) parseBehaviourTypeDecl() *BehaviourTypeDecl {
18331833
x := new(BehaviourTypeDecl)
18341834
x.TypeTok = p.consume()
18351835
x.KindTok = p.consume()
1836+
1837+
if p.tok == INTERLEAVE {
1838+
x.Interleave = p.consume()
1839+
}
1840+
18361841
x.Name = p.parseName()
18371842
if p.tok == LT {
18381843
x.TypePars = p.parseTypeFormalPars()
@@ -2001,6 +2006,11 @@ func (p *parser) parseBehaviourSpec() *BehaviourSpec {
20012006

20022007
x := new(BehaviourSpec)
20032008
x.KindTok = p.consume()
2009+
2010+
if p.tok == INTERLEAVE {
2011+
x.Interleave = p.consume()
2012+
}
2013+
20042014
x.Params = p.parseFormalPars()
20052015

20062016
if p.tok == RUNS {
@@ -2177,6 +2187,10 @@ func (p *parser) parseFuncDecl() *FuncDecl {
21772187

21782188
x := new(FuncDecl)
21792189
x.KindTok = p.consume()
2190+
2191+
if p.tok == INTERLEAVE {
2192+
x.Interleave = p.consume()
2193+
}
21802194
if p.tok == MODIF {
21812195
x.Modif = p.consume()
21822196
}

ttcn3/syntax/parser_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ func TestFuncDecls(t *testing.T) {
105105
{pass, `function f() mtc C {}`},
106106
{pass, `function f() runs on C mtc C system C {}`},
107107
{pass, `altstep as() { var roi[-] a[4][4]; [] receive; [else] {}}`},
108+
{pass, `altstep interleave interleaveStep() { [] p1.receive; [] p2.check{}}`},
108109
{pass, `signature f();`},
109110
{pass, `signature f() exception (integer);`},
110111
{pass, `signature f() return int;`},
@@ -235,6 +236,8 @@ func TestTypes(t *testing.T) {
235236
{pass, `type set s {int a optional }`},
236237
{pass, `type set s {set length(1) of set length(2) of int() f1[-][-] length(3) optional}`},
237238
{pass, `type set s {function () runs on self return template int callback}`},
239+
{pass, `type set s {altstep (integer p_i) runs on self as_callback}`},
240+
{pass, `type set s {altstep interleave(integer p_i) runs on C is_callback}`},
238241
{pass, `type union s {@default set of int f1 optional}`},
239242
{pass, `type union s {enumerated { e(1) } foo}`},
240243
{pass, `type enumerated a {e, e(1), e(1)}`},
@@ -260,6 +263,7 @@ func TestTypes(t *testing.T) {
260263
// Behaviour Types
261264
{pass, `type function fn() runs on self return template int`},
262265
{pass, `type altstep as() runs on self return int`},
266+
{pass, `type altstep interleave iStep() runs on C`},
263267
{pass, `type testcase tc() runs on C system TSI`},
264268

265269
// Class Types

0 commit comments

Comments
 (0)