“Rules” is a set of patterns that can be used to parse a file format.
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.
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.
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.
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.