Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Christian Müller
NIWO
Commits
a9050f9d
Commit
a9050f9d
authored
May 15, 2017
by
Christian Müller
Browse files
fix nondet choice parsing and tostrings
parent
083df74b
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/main/scala/de/tum/workflows/Utils.scala
View file @
a9050f9d
...
...
@@ -4,21 +4,26 @@ import de.tum.workflows.blocks._
import
de.tum.workflows.foltl.FOLTL._
object
Utils
{
def
mkString
[
T
](
string
:
Iterable
[
T
],
start
:
String
,
mid
:
String
,
end
:
String
)
=
{
def
mkString
[
T
](
string
:
Iterable
[
T
],
start
:
String
,
mid
:
String
,
end
:
String
)
=
{
if
(
string
.
isEmpty
)
""
else
string
.
mkString
(
start
,
mid
,
end
)
}
def
collectChoices
(
w
:
Block
)
:
List
[
Fun
]
=
{
w
match
{
case
Loop
(
steps
)
=>
steps
.
flatMap
(
collectChoices
_
)
case
ForallMayBlock
(
agents
,
pred
,
_
)
=>
List
(
Fun
(
pred
,
agents
))
case
b
:
ForallBlock
=>
List
()
case
NondetChoice
(
l
,
r
)
=>
l
.
flatMap
(
collectChoices
)
++
r
.
flatMap
(
collectChoices
)
}
}
def
collectChoices
(
w
:
Block
)
:
List
[
Fun
]
=
{
w
match
{
case
Loop
(
steps
)
=>
steps
.
flatMap
(
collectChoices
_
)
case
ForallMayBlock
(
agents
,
pred
,
_
)
=>
List
(
Fun
(
pred
,
agents
))
case
b
:
ForallBlock
=>
List
()
case
NondetChoice
(
l
,
r
)
=>
l
.
flatMap
(
collectChoices
)
++
r
.
flatMap
(
collectChoices
)
}
}
def
allchoices
(
w
:
Workflow
)
=
{
w
.
steps
flatMap
(
collectChoices
_
)
toSet
}
def
indentLines
(
s
:
String
)
=
{
s
.
lines
.
map
(
" "
+
_
).
mkString
(
"\n"
)
}
}
\ No newline at end of file
src/main/scala/de/tum/workflows/WorkflowParser.scala
View file @
a9050f9d
...
...
@@ -150,10 +150,12 @@ object WorkflowParser extends RegexParsers with LazyLogging {
}
},
t
=>
s
"$t is not a valid block (check free variables, duplicate variables, ...)"
)
def
LOOP
=
"loop"
~>
"{"
~>
(
BLOCK
+)
<~
"}"
^^
{
case
bs
=>
Loop
(
bs
)
}
def
NDCHOICE
=
"choose"
~>
"{"
~>
(
(
BLOCK
+)
<~
"}"
<~
"{"
)~
(
BLOCK
+)
<~
"}"
^^
{
case
l
~
r
=>
NondetChoice
(
l
,
r
)
}
def
LOOP
=
"loop"
~>
"{"
~>
BLOCK
LIST
<~
"}"
^^
{
case
bs
=>
Loop
(
bs
)
}
def
NDCHOICE
=
"choose"
~>
"{"
~>
(
BLOCK
LIST
<~
"}"
<~
"{"
)~
(
BLOCK
+)
<~
"}"
^^
{
case
l
~
r
=>
NondetChoice
(
l
,
r
)
}
def
WORKFLOW
=
rep
(
BLOCK
|
LOOP
|
NDCHOICE
)
^?
{
def
BLOCKLIST
:
Parser
[
List
[
Block
]]
=
(
BLOCK
|
LOOP
|
NDCHOICE
)+
def
WORKFLOW
=
BLOCKLIST
^?
{
case
blocks
if
checkSig
(
blocks
)
=>
{
val
choiceblocks
=
addChoicePredicates
(
blocks
)
Workflow
(
buildSig
(
choiceblocks
),
choiceblocks
)
...
...
src/main/scala/de/tum/workflows/blocks/Workflow.scala
View file @
a9050f9d
...
...
@@ -2,6 +2,7 @@ package de.tum.workflows.blocks
import
de.tum.workflows.foltl.FOLTL._
import
com.typesafe.scalalogging.LazyLogging
import
de.tum.workflows.Utils
case
class
Signature
(
oracles
:
Set
[
Fun
],
preds
:
Set
[
Fun
])
object
Signature
{
...
...
@@ -59,33 +60,31 @@ abstract class Statement {
}
case
class
Add
(
guard
:
Term
,
fun
:
String
,
tuple
:
List
[
Var
])
extends
Statement
{
override
def
toString
()
=
guard
+
" → "
+
fun
+
" += "
+
tuple
.
mkString
(
"("
,
","
,
")"
)
override
def
toString
()
=
guard
+
" → "
+
fun
+
" += "
+
tuple
.
mkString
(
"("
,
","
,
")"
)
+
";"
}
case
class
Remove
(
guard
:
Term
,
fun
:
String
,
tuple
:
List
[
Var
])
extends
Statement
{
override
def
toString
()
=
guard
+
" → "
+
fun
+
" -= "
+
tuple
.
mkString
(
"("
,
","
,
")"
)
override
def
toString
()
=
guard
+
" → "
+
fun
+
" -= "
+
tuple
.
mkString
(
"("
,
","
,
")"
)
+
";"
}
case
class
ForallBlock
(
agents
:
List
[
Var
],
steps
:
List
[
Statement
])
extends
SimpleBlock
{
val
may
=
false
override
def
toString
()
=
"forall "
+
agents
.
map
(
_
.
withType
).
mkString
(
","
)
+
steps
.
mkString
(
"\n "
,
"
;
\n "
,
""
)
override
def
toString
()
=
"forall "
+
agents
.
map
(
_
.
withType
).
mkString
(
","
)
+
steps
.
mkString
(
"\n "
,
"\n "
,
""
)
override
def
pred
()
=
None
}
case
class
ForallMayBlock
(
agents
:
List
[
Var
],
choice
:
String
,
steps
:
List
[
Statement
])
extends
SimpleBlock
{
val
may
=
true
override
def
toString
()
=
"forall "
+
agents
.
map
(
_
.
withType
).
mkString
(
","
)
+
" may ("
+
pred
+
")"
+
steps
.
mkString
(
"\n "
,
"
;
\n "
,
""
)
override
def
toString
()
=
"forall "
+
agents
.
map
(
_
.
withType
).
mkString
(
","
)
+
" may ("
+
pred
+
")"
+
steps
.
mkString
(
"\n "
,
"\n "
,
""
)
override
def
pred
()
=
Some
(
choice
)
}
case
class
Loop
(
steps
:
List
[
Block
])
extends
Block
{
override
def
toString
()
=
{
// indentation
val
s
=
steps
.
map
(
_
.
toString
().
lines
.
mkString
(
" "
,
"\n "
,
""
))
"loop(*)\n"
+
s
.
mkString
(
";\n"
)
"loop(*)\n"
+
Utils
.
indentLines
(
steps
.
mkString
(
"\n"
))
}
}
case
class
NondetChoice
(
left
:
List
[
Block
],
right
:
List
[
Block
])
extends
Block
{
override
def
toString
()
=
{
// TODO: indentation
"or\n"
+
left
.
toString
()
+
"\n"
+
right
.
toString
()
+
"\n"
"choose {\n"
+
Utils
.
indentLines
(
left
.
mkString
(
"\n"
))
+
"\n} {\n"
+
Utils
.
indentLines
(
right
.
mkString
(
"\n"
))
+
"\n}\n"
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment