Skip to content

Draft: XML preprocessor#2067

Merged
iakov merged 21 commits intotrikset:masterfrom
MinyazevR:minyazevr-xml-replacer-mvp
Jan 19, 2026
Merged

Draft: XML preprocessor#2067
iakov merged 21 commits intotrikset:masterfrom
MinyazevR:minyazevr-xml-replacer-mvp

Conversation

@MinyazevR
Copy link
Member

@MinyazevR MinyazevR commented Jan 4, 2026

Preprocessor of xml nodes before sending them to the Constraints Parser.
Syntax for defining a template:

<template name="template_name">
    <params>
       <param name="id"/> 
       <param name="param" default="true"/> 
       <param name="trigger">
	    <trigger>
	        <success/>
	     </trigger>
        </param>
    </params>
    <content>
<![CDATA[
    content
]]>
    </content>
</template>
  1. Parameters can have a default value. It can be a valid sequence of xml nodes or set as a text string (via the default attribute). If both are set, the default takes precedence. In parameter declarations, you can use parameters from the initialization list above using the syntax #{}.
  2. The template body must start with CDATA, and each parameter reference is processed using the #{} syntax, which is handled by regular expressions. This means that nested use of the #{} syntax is not allowed, and a separate parser is provided for such cases, which will complain if an undeclared parameter is used in the template body.
    Syntax for using a template:
<use template="templateName">
    <with id="123" param="false"/>
    <with param="trigger">
        <setUp id="my_id/>
    </with>
</use>
  1. Parameters that are xml tags are specified using the with syntax with the param attribute, whose child is a sequence of valid xml nodes. Text parameters are specified using the with tag attributes, and parameters can be grouped in multiple with tags.
  2. There is a simplified syntax that uses text parameters at the same level as the use tag without using with:
<use template="templateName"  id="123" param="false">
    <with param="trigger">
        <setUp id="my_id/>
    </with>
</use>

Templates can reuse other templates, that is, use syntax in their bodies to refer to other templates:

<template name="set-object-warzone">
    <params>
	<param name="regionId"/>
	<param name="objectId"/>
	<param name="message"/>
	<param name="trigger" default=""/>
    </params>
    <content>
<![CDATA[
<event settedUpInitially="true">
    <condition>
        <not>
            <inside objectId="#{objectId}" regionId="#{regionId}" objectPoint="all"/>
        </not>
    </condition>
    <triggers>
        #{trigger}
        <message text="#{message}"/>
        <success/>
    </triggers>
</event>
]]>
    </content>
</template>

<template name="set-robot-warzone">
    <params>
	<param name="regionId"/>
	<param name="message" default="The robot has moved out of a valid region"/>
	<param name="trigger" default=""/>
    </params>
    <content>
<![CDATA[
<use template="set-object-warzone">
    <with regionId="#{regionId}"/>
    <with message="#{message}"/>
    <with objectId="robot1"/>
    <with param="trigger">
        #{trigger}
    </with>
</use>
]]>
    </content>
</template>

Cyclic links between templates are not allowed.
A system template library for typical actions should be supported.
Thus, checking whether an object is in the region boils down to using the template defined above:

<use template="set-object-warzone" regionId="zone1" objectId="skittle" message="Object skittle not inside zone"/>

There is an environment variable TRIK_PREPROCESSOR_XML_OUTPUT, which allows you to get preprocessed xml in Constraint Parser syntax every time you load xml.

@MinyazevR MinyazevR marked this pull request as draft January 4, 2026 14:13
@MinyazevR MinyazevR changed the title Draft for discussion Draft for discussion: xml node replacer Jan 4, 2026
@MinyazevR MinyazevR force-pushed the minyazevr-xml-replacer-mvp branch from 1bb8edc to 94240de Compare January 8, 2026 15:34
@MinyazevR MinyazevR changed the title Draft for discussion: xml node replacer Draft: XML preprocessor Jan 8, 2026
@MinyazevR MinyazevR force-pushed the minyazevr-xml-replacer-mvp branch 3 times, most recently from fcc7054 to 8bd501a Compare January 8, 2026 20:09
@MinyazevR MinyazevR force-pushed the minyazevr-xml-replacer-mvp branch from 8bd501a to a73962f Compare January 9, 2026 12:58
@MinyazevR MinyazevR marked this pull request as ready for review January 12, 2026 12:12
@MinyazevR MinyazevR marked this pull request as draft January 12, 2026 12:24
@MinyazevR MinyazevR marked this pull request as ready for review January 16, 2026 10:37
@MinyazevR MinyazevR force-pushed the minyazevr-xml-replacer-mvp branch from 9ad6bcb to 017c7d0 Compare January 16, 2026 12:28
@iakov iakov added this to the 2025.5 milestone Jan 19, 2026
@iakov iakov merged commit 97540ad into trikset:master Jan 19, 2026
37 of 39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants