SCLS Documentalist pattern

Pattern system

How works SCLS Documentalist "Agatha" ?

SCLS Documentalist "Agatha" uses a lot of features to perform each operation.

The more important one is the pattern system.
As said in the description, SCLS Documentalist "Agatha" is made to format a text. To format a text, it need a methodology which follows a pattern. You can tell to SCLS Documentalist "Agatha" which pattern should be use to format a text. However, there are no built-in pattern in this part of the library. You have to define one pattern to use it.

Customize a pattern

Some globals parts of the pattern can be defined easily in the pattern.

As in the hierarchy system, you can define a starting value and an ending value in the pattern. Its a simple string which is added at the start and at the end of the pattern.

Moreover, if the pattern is, for example, only comments, you can tell the user to fill the pattern only with comments, or define the default start of a line in the pattern. It represents what should always be at the start of a line in the pattern, if the user enters a multi line text. For example, if the pattern is only comments, you can se this value to "// ", so the user does not have to put it himself.

Customize a pattern with variables

If a pattern only have a fixed text immutable, it is literally useless. To customize a pattern easily, SCLS Documentalist "Agatha" incorporates a system of variables. Indeed, in the text, you can specify to the library that you want to use a user-defined value, a variable. As the text is only a text, the variable type can only be a text ¯\_(ツ)_/¯. However, the variable is quite independant of the pattern, and its only utilisation in a pattern its is definition. It can be weird, but a variable should be extensible to be use in a fully user-defined text, and not be limitated to a pattern behavior. The value of a variable is so putted in the text of a piece, and not in the pattern. The variables are defined between a start and an end part of text, defined by the macros SCLS_DOCUMENTALIST_VARIABLE_END and SCLS_DOCUMENTALIST_VARIABLE_START. However, a badly defined variable may causes undefined behavior.
If you want to force the user to define some variables, the pattern incorporates a system of forced variables. If a forced variable is missing, the pattern and its children are fully ignored.

Some variables may be global for a pattern and its children.

The pattern hierarchy system

Each pattern have their text, corresponding to the skeleton of your pattern, and can also have a parent or children. A parent pattern incorporates the text of its children in its text. However, the children behavior is quite independant of the parent, making it interesting to use, excepting some setting. Moreover, the parent text is independant of the children behavior. You can chose where to place the parent text, before, between or after a child text. You can also decide to use a defined text to separate each children more aesthetically.

Piece system

How to handle a pattern ?

A lonely pattern is quite useless. However, it is absolutely no costumizable. The simplest way to make a pattern fully costumizable is to use a piece of text. It purpose is quite simple : it takes a pattern, the configuration wanted by the user, and assembles the all to make the wanted output. Each pieces are independant between them, making them fully configurable how you want. The content of each variable is incorporates in them, either thant the configuration of each pattern.

Easily configure a pattern

Moreover that configure the variables of a pattern, you can also configure the behavior of the entire pattern.

If you want to document two differents parts of code, with a part containing 3 functions and the other one 8 functions, you need to tell the first part of the piece to repeat 3 time the function pattern, and the second part of the piece to repeat 8 times the function pattern.
This is possible, by defining the nombure of iteration of each pattern in a piece. However, the children functions and variables may change according to the iteration. If it happens, there is a way for each variables to know it. See this part for more informations.

You can also disable or enable a group of pattern easily. If it is disabled, the pattern and its children are fully ignored.

How each kind of variables are handle in a piece.

The variables are defined between a start and an end part of text, defined by the macros SCLS_DOCUMENTALIST_VARIABLE_END and SCLS_DOCUMENTALIST_VARIABLE_START. Obviously, between this two string, there is the name of the variable.
A variable can have a lot of behavior according to its name.

The simplest definition is only the name of the variable, which is very recommended to be alphabet character and some specials characters like '_'. With this way, the variable as the same value wherever is the variable.

If you want that the variable as a different value according to its position, you have to add specials characters at the end of the name of the variable. The "[]" string tells the piece that the variable name change according to the iterations of the parent pattern. To be more precise, the "[]" string is replaced by "[number_of_iteration]". For example, the 5th iteration of the pattern of the variable "age[]" is "age[5]" in the piece.
Moreover, by adding more "[]", you can have the iterations of the parent of the parent pattern. For example, the 5th iteration of the 8th iteration of the patterns of the variable "location[][]" is "location[8][5]" in the piece. By the way, in this case, the variable "age[]" stays "age[5]", because the "[]" the more at the left represents the pattern of the variable.
If you don't want that the variable change according to a certain pattern, use "[.]". For example, the 5th iteration of the 8th iteration of the patterns of the variable "location[.][]" is "location[.][5]" in the piece. The fact that it is the 8th iteration of the parent of the pattern does not change the value of the variable.
This modified part it's called offset of the variable.

How each kind of patterns are handle in a piece.

The pattern can also be impacted by some configuration.

For the "[]" system, the using is exactly the same as in the variable. For example, the 5th iteration of the 8th iteration of the parent pattern of the pattern "information[][]" is "information[8][5]" in the piece.