Skip to content

Commit 7bc7317

Browse files
author
Gary Brown
committed
Simplified the model to only include parts necessary for initial protocol notation. Fixed some issues with running sub-protocol, parsing and projection.
1 parent a143429 commit 7bc7317

File tree

23 files changed

+569
-993
lines changed

23 files changed

+569
-993
lines changed

modules/org.scribble.protocol.conformance/src/main/java/org/scribble/protocol/conformance/impl/BehaviourList.java

+6-134
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ protected BehaviourList(Block defn) {
6262
* @param defn The block
6363
* @param include The model inclusion construct
6464
*/
65-
protected BehaviourList(Block defn, org.scribble.protocol.model.ModelInclude include) {
65+
protected BehaviourList(Block defn, org.scribble.protocol.model.Run include) {
6666
m_block = defn;
6767
m_include = include;
6868

@@ -173,12 +173,12 @@ public java.util.List<Behaviour> getBehaviourList() {
173173
}
174174

175175
/**
176-
* This method returns the optional model include
176+
* This method returns the optional run activity
177177
* associated with the contained behaviour activities.
178178
*
179-
* @return The optional model include
179+
* @return The optional run activity
180180
*/
181-
public ModelInclude getModelInclude() {
181+
public Run getRun() {
182182
return(m_include);
183183
}
184184

@@ -228,7 +228,7 @@ public void visit(Visitor visitor) {
228228
}
229229

230230
private Block m_block=null;
231-
private ModelInclude m_include=null;
231+
private Run m_include=null;
232232
private java.util.Map<String,String> m_nameMap=null;
233233
private java.util.List<Behaviour> m_list=new java.util.Vector<Behaviour>();
234234

@@ -320,7 +320,7 @@ public void visitInteraction(Interaction elem) {
320320

321321
public void visitRun(Run run) {
322322
Protocol defn=
323-
((ModelInclude)run).getProtocol();
323+
((Run)run).getProtocol();
324324

325325
if (defn != null) {
326326
BehaviourList list=null;
@@ -366,133 +366,5 @@ public void visitRun(Run run) {
366366
}
367367
}
368368
}
369-
370-
/*
371-
public boolean visit(ModelObject obj) {
372-
boolean ret=false;
373-
374-
if (obj instanceof MultiPathBehaviour) {
375-
MultiPathBehaviour paths=
376-
(MultiPathBehaviour)obj;
377-
java.util.List<BehaviourList> bllist=
378-
new java.util.Vector<BehaviourList>();
379-
380-
for (int i=0; i < paths.getPaths().size(); i++) {
381-
Block block=paths.getPaths().get(i);
382-
383-
BehaviourList bl=new BehaviourList(block);
384-
385-
//bl.derivedFrom(block);
386-
387-
bl.setNameMap(m_nameMap);
388-
389-
//block.visit(bl);
390-
391-
bllist.add(bl);
392-
}
393-
394-
BehaviourListPaths blpaths=new BehaviourListPaths((Behaviour)obj,
395-
bllist);
396-
397-
if (blpaths.isVisible()) {
398-
addToList(blpaths);
399-
}
400-
401-
} else if (obj instanceof SinglePathBehaviour) {
402-
SinglePathBehaviour path=
403-
(SinglePathBehaviour)obj;
404-
java.util.List<BehaviourList> bllist=
405-
new java.util.Vector<BehaviourList>();
406-
407-
BehaviourList bl=new BehaviourList(path.getBlock());
408-
409-
//bl.derivedFrom(path.getBlock());
410-
411-
bl.setNameMap(m_nameMap);
412-
413-
//path.getBlock().visit(bl);
414-
415-
bllist.add(bl);
416-
417-
BehaviourListPaths blpaths=new BehaviourListPaths((Behaviour)obj,
418-
bllist);
419-
420-
if (blpaths.isVisible()) {
421-
addToList(blpaths);
422-
}
423-
424-
} else if (obj instanceof ModelInclude) {
425-
ModelInclude include=
426-
(ModelInclude)obj;
427-
Protocol defn=
428-
((ModelInclude)obj).getProtocol();
429-
430-
if (defn != null) {
431-
BehaviourList list=null;
432-
433-
// Check if external model - if so, then
434-
// need to supply reference to list, so can be
435-
// used in error reporting
436-
if (include.getReference() != null &&
437-
include.getReference().isInner() == false) {
438-
list = new BehaviourList(defn.getBlock(), include);
439-
} else {
440-
list = new BehaviourList(defn.getBlock());
441-
}
442-
443-
list.setNameMap(getNameMap(include.getBindings()));
444-
445-
// list.derivedFrom(include);
446-
447-
// defn.visit(list);
448-
449-
// Add list, if async (to identify existence of
450-
// async composed conversation), or if the list
451-
// has elements
452-
if (include.isAsynchronous()) {
453-
454-
// If async, then need to add 'behaviour
455-
// list path' to isolate the behaviour
456-
// list, to ensure it does not get merged
457-
// into the outer list (as with the
458-
// sync run)
459-
java.util.List<BehaviourList> bllist=
460-
new java.util.Vector<BehaviourList>();
461-
462-
bllist.add(list);
463-
464-
BehaviourListPaths blpaths=new BehaviourListPaths((Behaviour)obj,
465-
bllist);
466-
467-
addToList(blpaths);
468-
469-
} else if (list.getBehaviourList().size() > 0) {
470-
addToList(list);
471-
}
472-
}
473-
474-
} else if (obj instanceof Block) {
475-
476-
// Iterate through each activity checking its a behaviour
477-
ret = true;
478-
479-
} else if (obj instanceof Behaviour) {
480-
addToList((Behaviour)obj);
481-
482-
// Only recursively check for behaviours
483-
// inside other behaviours. This will ensure
484-
// inner protocols will not be indirectly
485-
// processed - only if invoked as part of
486-
// a run statement.
487-
ret = true;
488-
489-
} else if (obj == m_block) {
490-
// Visiting the main definition, so visit contents
491-
ret = true;
492-
}
493-
494-
return(ret);
495-
}
496-
*/
497369
}
498370
}

modules/org.scribble.protocol.conformance/src/main/java/org/scribble/protocol/conformance/impl/BehaviourListIterator.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
package org.scribble.protocol.conformance.impl;
1818

1919
import org.scribble.protocol.model.Behaviour;
20-
import org.scribble.protocol.model.ModelInclude;
2120
import org.scribble.protocol.model.ModelReference;
21+
import org.scribble.protocol.model.Run;
2222

2323
/**
2424
* This class provides an iterator implementation over a behaviour list.
@@ -90,18 +90,18 @@ public ModelReference getComposedSource() {
9090

9191
if (m_subList != null) {
9292
ret = m_subList.getComposedSource();
93-
} else if (m_list.getModelInclude() != null) {
94-
ret = m_list.getModelInclude().getReference();
93+
} else if (m_list.getRun() != null) {
94+
ret = m_list.getRun().getReference();
9595
}
9696

9797
return(ret);
9898
}
9999

100-
public ModelInclude getModelInclude() {
101-
ModelInclude ret=m_list.getModelInclude();
100+
public Run getRun() {
101+
Run ret=m_list.getRun();
102102

103103
if (ret == null && m_subList != null) {
104-
ret = m_subList.getModelInclude();
104+
ret = m_subList.getRun();
105105
}
106106

107107
return(ret);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
grammar ScribbleProtocol;
2+
3+
options {
4+
output=AST;
5+
}
6+
7+
tokens {
8+
INTERACTION = 'interaction' ;
9+
PLUS = '+' ;
10+
MINUS = '-' ;
11+
MULT = '*' ;
12+
DIV = '/' ;
13+
FULLSTOP = '.' ;
14+
}
15+
16+
@header {
17+
package org.scribble.protocol.parser.antlr;
18+
}
19+
20+
@lexer::header {
21+
package org.scribble.protocol.parser.antlr;
22+
}
23+
24+
@members {
25+
private org.scribble.common.logging.Journal m_journal=null;
26+
27+
public static void main(String[] args) throws Exception {
28+
ScribbleProtocolLexer lex = new ScribbleProtocolLexer(new ANTLRFileStream(args[0]));
29+
CommonTokenStream tokens = new CommonTokenStream(lex);
30+
31+
ScribbleProtocolParser parser = new ScribbleProtocolParser(tokens);
32+
33+
ProtocolTreeAdaptor adaptor=new ProtocolTreeAdaptor();
34+
adaptor.setParser(parser);
35+
36+
parser.setTreeAdaptor(adaptor);
37+
38+
try {
39+
ScribbleProtocolParser.description_return r=parser.description();
40+
41+
//CommonTree t=(CommonTree)r.getTree();
42+
43+
//Tree t=(Tree)r.getTree();
44+
45+
//System.out.println(t.toStringTree());
46+
47+
} catch (RecognitionException e) {
48+
e.printStackTrace();
49+
}
50+
}
51+
52+
public void setJournal(org.scribble.common.logging.Journal journal) {
53+
m_journal = journal;
54+
}
55+
56+
public void emitErrorMessage(String mesg) {
57+
if (m_journal == null) {
58+
super.emitErrorMessage(mesg);
59+
} else {
60+
m_journal.error(mesg, null);
61+
}
62+
}
63+
}
64+
65+
/*------------------------------------------------------------------
66+
* PARSER RULES
67+
*------------------------------------------------------------------*/
68+
69+
description: ( namespaceDeclaration )? ( importStatement )* protocolDef ;
70+
71+
namespaceDeclaration: 'namespace'^ qualifiedName ';'! ;
72+
73+
qualifiedName: ID ( '.' ID )* ;
74+
75+
urlDef: URL ;
76+
77+
importStatement: 'import'^ qualifiedName ( '@' urlDef )? ';'! ;
78+
79+
protocolDef: 'protocol'^ locatedNameDef blockDef ;
80+
81+
locatedNameDef: ID ( '@' participantName )? ;
82+
83+
blockDef: sequenceDef ;
84+
85+
sequenceDef: '{'! activityListDef '}'! ;
86+
87+
activityListDef: ( activityDef )* ;
88+
89+
activityDef: participantListDef | interactionDef |
90+
raiseDef | choiceDef | parallelDef | optionalDef | repeatDef | runDef |
91+
tryEscapeDef | protocolDef ;
92+
93+
participantListDef: 'participant'^ participantDef ( ','! participantDef )* ';'! ;
94+
95+
participantDef: ID ;
96+
97+
participantName: ID ;
98+
99+
typeReferenceDef: qualifiedName ;
100+
101+
interactionSignatureDef: ( typeReferenceDef | ID '('! typeReferenceDef ( ','! typeReferenceDef )* ')'! ) ;
102+
103+
interactionDef: interactionSignatureDef ( 'from' participantName )? ( 'to' participantName )? ';'! ;
104+
105+
choiceDef: 'choice'^ ( 'from' participantName )? ( 'to' participantName )? '{'! ( whenBlockDef )+ '}'! ;
106+
107+
whenBlockDef: 'when'^ interactionSignatureDef sequenceDef ;
108+
109+
repeatDef: 'repeat'^ ( '@' participantName ( ','! participantName )* )? blockDef ;
110+
111+
optionalDef: 'optional'^ ( '@' participantName ( ','! participantName )* )? blockDef ;
112+
113+
runDef: 'run'^ ( inlineProtocolDef | protocolRefDef ( '('! boundParameter ( ','! boundParameter )* ')'! )? ';'! ) ;
114+
115+
protocolRefDef: ID ( '@' participantName )? ;
116+
117+
inlineProtocolDef: 'protocol' ( '@' participantName )? ( '('! boundParameter ( ','! boundParameter )* ')'! )? blockDef ;
118+
119+
declarationName: ID ;
120+
121+
boundParameter: declarationName 'for' declarationName ;
122+
123+
parallelDef: 'parallel'^ blockDef ( 'and' blockDef )* ;
124+
125+
raiseDef: 'raise'^ '@' participantName ( ','! participantName )* typeReferenceDef ';'! ;
126+
127+
tryEscapeDef: 'try'^ blockDef ( catchOrInterruptBlockDef )+ ;
128+
129+
catchOrInterruptBlockDef: catchBlockDef | interruptBlockDef ;
130+
131+
catchBlockDef: 'catch'^ ( '@' participantName ( ',' participantName )* )? typeReferenceDef sequenceDef ;
132+
133+
interruptBlockDef: 'interrupt'^ ( '@' participantName ( ',' participantName )* )? sequenceDef ;
134+
135+
136+
/*-----------------------------------------------
137+
TO DO:
138+
Declaration (variables) possibly - but that may need
139+
lookahead to avoid conflict with interactions.
140+
-------------------------------------------------*/
141+
142+
143+
144+
expr : term ( ( PLUS | MINUS ) term )* ;
145+
146+
term : factor ( ( MULT | DIV ) factor )* ;
147+
148+
factor : NUMBER ;
149+
150+
151+
/*------------------------------------------------------------------
152+
* LEXER RULES
153+
*------------------------------------------------------------------*/
154+
155+
ID : ('a'..'z'|'A'..'Z'|'_')('a'..'z'|'A'..'Z'|'0'..'9'|'_')* ;
156+
157+
URL : (ID|':'|'?'|'/')+ ;
158+
159+
NUMBER : (DIGIT)+ ;
160+
161+
WHITESPACE : ( '\t' | ' ' | '\r' | '\n'| '\u000C' )+ { $channel = HIDDEN; } ;
162+
163+
fragment DIGIT : '0'..'9' ;

modules/org.scribble.protocol.parser/src/main/antlr3/org/scribble/protocol/parser/antlr/ScribbleProtocol.g

+6-3
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,16 @@ repeatDef: 'repeat'^ ( '@' participantName ( ','! participantName )* )? blockDef
110110

111111
optionalDef: 'optional'^ ( '@' participantName ( ','! participantName )* )? blockDef ;
112112

113-
runDef: 'run'^ ( inlineProtocolDef | protocolRefDef ( '('! boundParameter ( ','! boundParameter )* ')'! )? ';'! ) ;
113+
runDef: 'run'^ ( ( ( '@' participantName )? '('! boundParameter ( ','! boundParameter )* ')'! )? inlineProtocolDef |
114+
protocolRefDef ( '('! boundParameter ( ','! boundParameter )* ')'! )? ';'! ) ;
114115

115116
protocolRefDef: ID ( '@' participantName )? ;
116117

117-
inlineProtocolDef: 'protocol' ( '('! boundParameter ( ','! boundParameter )* ')'! )? blockDef ;
118+
inlineProtocolDef: blockDef ;
118119

119-
boundParameter: ID '='! ID ;
120+
declarationName: ID ;
121+
122+
boundParameter: declarationName '=' declarationName ;
120123

121124
parallelDef: 'parallel'^ blockDef ( 'and' blockDef )* ;
122125

0 commit comments

Comments
 (0)