This section explains what "backward" and "forward" search is.
Users should understand this part before proceeding to read about other UDL 2.0 features.
Users should understand this part before proceeding to read about other UDL 2.0 features.
Introduction to UDL 1.0 internal logic
_
In this picture you can see a set of three keywords. How did UDL 1.0 recognized each one? The simplest explanation would be something like this:
One obvious limitation is that you have to have space around your keywords, otherwise UDL 1.0 won't recognize them. There were some exceptions from this rule, e.g. operators in UDL 1.0 are just one charecter long, so it was possible to test each character directly and detect an operator. But generally, keywords had to be surounded by whitespace to be correctly recognized. I call this aproach "backwards" detection, because keywords are detected in backward direction (e.g. keyword "first" is detected only after UDL reaches position 5) And yes, I do understand what "backwards" means in English, but I am not a native speaker, so bear with me, I mean nothing offensive. |
_
Introduction to UDL 2.0 internal logic
_
What we have here is a combination of two keywords ("first" and "second") connected by a two-character operator ("<<"), and closed with another operator (";") (Note that operators are underlined so you could see them more easily) So, how does UDL 2.0 work then? Again, this is just a simplified description:
So, UDL 2.0 uses a cobmination of "forward" and "backward" search in order to detect keywords that are "glued" together. And all keywords in UDL 2.0 are diveded in two basic groups which I call "backwards" and "forwards" (feel free to suggest a better name for these). |
Complete list of "backwards" and "forwards" keywords
_Backwards:
Keywords 1-8
Folding in comment
Operators2
Forwards:
Folding in code
Comments
Operators1
Delimiters 1-8
Numbers
Keywords 1-8
Folding in comment
Operators2
Forwards:
Folding in code
Comments
Operators1
Delimiters 1-8
Numbers
_More on "forward" and "backward" logic
Understanding dual logic of UDL 2.0 (detecting keyword in both backward and forward direction) is very important. So, before we proceed with details of UDL 2.0, lets first explain why is it important and where things can go wrong.
The simplest way to demonstrate "backward" and "forward" logic is to define two sets of operators:
The simplest way to demonstrate "backward" and "forward" logic is to define two sets of operators:
- C++ style: && || !
- Python style: and or not
Forward search example: C++ boolean operators are special characters. They can never be part of variable name. That's why they can be "glued" to preceding or following keyword. And this is demonstrated in line three. There are no white spaces in line three, but each operator is recognized by UDL 2.0. Lets follow what happens in the background. For example, we'll focus on && operator in line three.
|
Backward search example: Python boolean operators are normal English words and or not, very similar to other Python keywords. Unlike in C++, Python operators can easily be part of other keywords or variable names. So, if we define Python operators as forward search keywords, we end up with more than we asked for. Lets explain first picture (again operators are underlined to be easily recognized):
That's why I defined a two sets of operators: Operators1 and Operators2:
|
To sum up: both forward and backward search logic must be implemented in UDL 2.0 and it is user's job do decide which one should be applied on a given set of keywords. Rule of the thumb is: if your keyword can be "glued" to other keywords, like C++ boolean operators, use forward search, if your keyword must be separated from rest of the source code by white space or special characters, use backward search.
This option is given in case of operators and folding in code keywords. All other keyword sets simply fall into one of two search directions, and are not user selectable. Complete list is given in paragraph above.