Rules

⌘K
  1. Home
  2. Translator++
  3. Parser Model Creator
  4. Rules

Rules

Rules” is a set of patterns that can be used to parse a file format.

Rules in Parser Model Creator

This is an outline regarding important things about Rules in Parser Model Creator. 

You can have more than one rule

You can have more than one rule to parse a single file group. For example, you might need more than one step to be able to parse a certain file format. For instance, you need a rule to mask a block of text, while another rule to extract translatable data. For example, let’s say I am creating a parser for a js file.

/*
this is comment block and should not be processed
var charName = "johnson";
*/

var charName = "Alex";

Everything between /* and */ is a comment and will not be processed. So, I will use Rule 0 to create Masking.

Rule 0 with Action set to Mask value to tell the parser to ignore block of texts

In Rule 0 I created a regular expression to capture all text starting from /* to */

After that, I also created another rule. It will be named automatically as Rule 1, I will use this rule to Capture Value to take the actual value of the translatable texts.

Rule 1 with the Action set to Capture Value, to capture the translatable texts from the file

In this example, I capture anything between quote.

Without masking, the parser will capture both ‘johnson’ and ‘Alex’. However, with masking applied, the parser will exclude ‘johnson’ and only capture ‘Alex’.

Rule order does matter!

The parser processes all rules sequentially, so the order of rules is crucial. For example, in the above example involving masking, you must apply masking to the data before capturing it; otherwise, it won’t work as expected. You can rearrange the rule order by dragging them using the mouse.

Rule order does matter, so you can reorder the rule with mouse drag.

Sample tpm file on this article:

There are two option of how to write the rule, as Regular Expression or Javascript function

You can choose how to write rules, with Regular Expression (regex) or with a JavaScript Function.

Was this article helpful to you? No 24 Yes 5

How can we help?