Printing the value of the configuration - kframework

While modifying the toy language SIMPLE from the tutorial, I thought it would be helpful to have a statement that would just print the current configuration so that I could see the internal state of the program as it ran. To that end I added to Stmta printConfig command. In the semantics then I figured all I had to do was rewrite this to a call to print taking the body of the T cell so I added
rule <k> printConfig; => print(cfg); </k>
<T> cfg </T>
The kompiler throws an error saying that there is an unexpected end parenthesis, specifically the one for print(cfg). I'd encountered a similar issue previously and in that case the error turned out to be due to the typing of the components of the two statements I had. I'm wondering then if there is a way to "cast" the value in the T cell as an Exp so I can print it.
If there is a better way I can debug my semantics that does not involve this I am very open to that as well. Thank you!

Well one issue I can see is that you have <k> and <T> cells next to each other in your rule, but they don't have a sibling relationship in the initial configuration.
The SIMPLE configuration looks like this, where the <k> cell is a grandchild of the <T> cell:
configuration <T color="red">
<threads color="orange">
<thread multiplicity="*" color="yellow">
<k color="green"> $PGM:Stmts ~> execute </k>
<control color="cyan">
<fstack color="blue"> .List </fstack>
<xstack color="purple"> .List </xstack>
</control>
<env color="violet"> .Map </env>
<holds color="black"> .Map </holds>
<id color="pink"> 0 </id>
</thread>
</threads>
<genv color="pink"> .Map </genv>
<store color="white"> .Map </store>
<busy color="cyan"> .Set </busy>
<terminated color="red"> .Set </terminated>
<input color="magenta" stream="stdin"> .List </input>
<output color="brown" stream="stdout"> .List </output>
<nextLoc color="gray"> 0 </nextLoc>
</T>
So if you want to write your rule, you at least have to do this:
syntax Stmt ::= "printConfig" ";"
rule <T> ... <k> printConfig; => print(CFG); ... </k> ... </T> #as CFG
Notice that I made three changes here, (1) I used capital letters for the variable CFG (which is conventional in K), (2) I added the ... to the end of the <k> cell, which allows you to use printConfig; anywhere instead of just at the end of a program, and (3) I used an _#as_ pattern to match both the super-term <T> ... </T> as well as the sub-term <k> ... </k> at the same time, giving the name CFG to the super-term.
_#as_ patterns are documented in the Pending Documentation.
Hope that helps!

Related

Go template merging dictionary with a possibly empty source dictionary

In a go template I'm merging labels from project level and application level with
{{ range $k, $v := (merge $project.labels $app.labels) }}
# Do something with $k and $v.
{{end}}
Both $project.labels and $app.labels are dictionaries generated from a yaml file.
Now I want to make app.labels as an optional field, this can be done with some extra with statement but I wonder if there is an elegant way to do this.
Currently if $app.label is not defined in the yaml file I'll get:
wrong type for value; expected map[string]interface {}; got interface {}
Figured it out by adding empty dict as a default:
{{ range $k, $v := (merge $project.labels ($app.labels | default dict)) }}

ATL transformation rules not matching nested BPMN2 elements

I am writing an ATL translation from BPMN2 to another model. The problem is that the code does not detect any nested element.
I have posted the atl code and my input here at: https://github.com/behnaaz/BPMN2ATL.git
You can see from the output that the only executed rule is def2mod which has created a Reo module element in the output.
If I remove the first level element in the input bpmn file then the rule mapProcess is kicked in.
Also in the logs the command BPMN20!Process.allInstances() which should give a list of all the Processes only works in the mapProcess rule.
I think there is some issue with parsing my bpmn model. Help much appreciated!
=== ATL CODE ====
-- #path BPMN20=/atttl/BPMN2/BPMN20.ecore
create OUT: reo from IN: BPMN20;
rule def2mod {
from
b: BPMN20!Definitions
to
m: reo!Module
do {
b.debug('definition to module > ' + BPMN20!Process.allInstances());
}
}
rule mapProcess {
from
proc: BPMN20!Process
to
conn: reo!Connector
do {
proc.debug('process to connector ' + proc.name + proc.flowElements);
proc.debug( BPMN20!Process.allInstances());
}
}
=== BPMN input ===
<?xml version="1.0" encoding="UTF-8"?>
<bpmn2:Definitions xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL-XMI">
<bpmn2:Process id="bpmnid-80c796ae-c11d-42d8-92ae-1d88bab84536" name="Process" isClosed="false" processType="None" xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL-XMI">
<bpmn2:serviceTask id="bpmnid-11047880-09d8-4147-8382-523145eeb8b6" name="Task 1"/>
<bpmn2:serviceTask id="bpmnid-2f925dd9-4ec8-45b7-936c-0c14597319a9" name="Task 2"/>
<bpmn2:serviceTask id="bpmnid-21a0fc44-3c02-4a00-9b6e-aa6c058992d3" name="Task 3"/>
<bpmn2:startEvent id="bpmnid-196c656e-baa2-4306-809b-56ba006057b9" name="Start Event"/>
<bpmn2:endEvent id="bpmnid-5cfcf354-ba3f-4b13-a5bf-bdf27ca70acc" name="End Event"/>
<bpmn2:sequenceFlow id="bpmnid-be0a37d4-8054-4367-82ae-b43430d5fc6f" name="Sequence Flow0" sourceRef="bpmnid-11047880-09d8-4147-8382-523145eeb8b6" targetRef="bpmnid-2f925dd9-4ec8-45b7-936c-0c14597319a9"/>
<bpmn2:sequenceFlow id="bpmnid-01d687a3-66ee-40d7-9e17-97aa5724eef7" name="Sequence Flow" sourceRef="bpmnid-196c656e-baa2-4306-809b-56ba006057b9" targetRef="bpmnid-11047880-09d8-4147-8382-523145eeb8b6"/>
<bpmn2:sequenceFlow id="bpmnid-b687d3ec-b6d7-480a-a1e1-57fbe220e579" name="Sequence Flow2" sourceRef="bpmnid-21a0fc44-3c02-4a00-9b6e-aa6c058992d3" targetRef="bpmnid-5cfcf354-ba3f-4b13-a5bf-bdf27ca70acc"/>
<bpmn2:sequenceFlow id="bpmnid-4596a8fb-f1dc-46b3-bc28-9a2e11c26f96" name="Sequence Flow1" sourceRef="bpmnid-2f925dd9-4ec8-45b7-936c-0c14597319a9" targetRef="bpmnid-21a0fc44-3c02-4a00-9b6e-aa6c058992d3"/>
</bpmn2:Process>
</bpmn2:Definitions>
The problem seems not to lie with the ATL transformation but with the input model. It seems like it's not conform to your metamodel.
E.g. Definitions has a relation "rootElements" to Process. This should in the XMI model look like this:
<bpmn2:Definitions
xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL-XMI">
<rootElements xsi:type="bpmn2:Process" id="bpmnid-80c796ae-c11d-42d8-92ae-1d88bab84536" />
</bpmn2:Definitions>
To quickly get a conform model you can right-click the Definitions element in your ecore metamodel and choose "Create Dynamic Instance". You can then model a quick sample and run your transformation again. I quickly tried it and got following output
<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:reo="http://www.cwi.nl/reo">
<reo:Module/>
<reo:Connector/>
</xmi:XMI>

Problems with multiline extension in nxlog

I have following logformat:
-- New Entry -------------------------
08:03:10 01.04.15 ncjhdnbchjbdc
08:03:10 jnkjsdncksjdnc
xd1: ndkjewnckjdwcndw
xd2: jncxkjdsnkjcndsqckjnc c cw djkcdnc cnd kj nc
08:03:10 dscsdcdsc
-- New Entry -------------------------
08:03:10 01.04.15 ncjhdnbchjbdc
08:03:10 jnkjsdncksjdnc
xd1: ndkjewnckjdwcndw
xd2: jncxkjdsnkjcndsqckjnc c cw djkcdnc cnd kj nc
08:03:10 dscsdcdsc
I want the complete entry in one line so i use the multiline extension:
<Extension multiline>
Module xm_multiline
HeaderLine /^--/
EndLine " "
</Extension>
<Input in>
Module im_file
File "input.txt"
SavePos TRUE
ReadFromLast TRUE
InputType multiline
Exec if $raw_event !~ /^--/ drop();
Exec $raw_event = replace($raw_event, "\r\n", ";");
</Input>
<Output out>
Module om_file
File "output.txt"
</Output>
<Route 1>
Path in => out
</Route>
The multiline extension works as expected for existing entries in the inputfile after start of nxlog. New entries are not correctly written in the output. Only the header will be written in the output.
Has someone an idea of what iam doing wrong?
UPDATE:
The PollInterval of the im_file seems to be the problem. I red following in the documentation of nxlog (section xm_multiline):
Note Until there is a new header read, the previous message is stored in the buffers because the module does not know where the
message ends. The im_file module will forcibly flush this buffer after
the configured PollInterval timeout. If this behaviour is
unacceptable, consider using some kind of an encapsulation method
(JSON, XML, RFC5425, etc) or use an end marker with EndLine if
possible.
So, i use an end marker but it doesn't work. I tried different values for EndLine (regex: /^\s*$/ String: " ")
This line needs to be fixed.
Exec if $raw_event !~ /^--/ drop()
Should be
Exec if $raw_event =~ /^--/ drop()

EL Expression, set var if test condition is true

I have the following code block within my TAG file -
(See comment inside code block for my question)
<c:forEach var="headerTab" items="${KualiForm.headerNavigationTabs}" varStatus="status">
<c:if test="${headerTab.headerTabDisplayName != 'S2S'}">
<c:choose>
<c:when test="${headerTab.headerTabDisplayName == 'Key Personnel'}">
// (Set the value of the var evaluated in the test above here)
// How do I do the following using EL Notation:
// headerTab.headerTabDisplayName = 'Some other string';
</c:when>
</c:choose>
Have you tried using the c:set JSTL Tag? It should be something like this:
<c:set target="headerTab" property="headerTabDisplayName"
value="Some other string"/>

How to set OPT programmatically with MS SAPI

Given the following which can be loaded into MS SAPI 5.1:
<GRAMMAR LANGID="409">
<RULE NAME="top rule" TOPLEVEL="ACTIVE">
<OPT>hello</OPT>
<P>my name is fred</P>
</RULE>
</GRAMMAR>
How can I do the same programmatically, specifically with regard to the optional element.
I would guess it is done here:
state.AddWordTransition(nextState, "hello", " ", SpeechGrammarWordType.SGLexical, s, id, ref propValue, 1F);
...and it is probably the propValue. But what is the syntax (e.g, propValue="OPT=true" - does not work of course)
Thanks!
Optional words need an epsilon (empty) transition to the next state, so add:
state.AddWordTransition(nextState, NULL, NULL, SpeechGrammarWordType.SGLexical, s, id, ref propValue, 1F);
to add the epsilon transition.