Simple Lexer

All questions regarding lexer highlighting schemes are discussed here...
Locked
FritsBee
Posts: 3
Joined: 06.11.2012 15:41

Simple Lexer

Post by FritsBee »

Hi,

I want to make a simple Lexer

Because out program makes text files which every type of line begins with a character.

The first Line is always beginning with a *
The next lines always begins with |
and the last line begins with _

Can someone explain me how I can color the complete line after those characters.

Frits
Matthias
Posts: 10
Joined: 05.10.2012 22:07

Post by Matthias »

This should be simple. First create 3 new "styles" and set your colors for the lines. Then add 3 new objects in "parser" with following content.
first line: ^\*.*$
second line: ^\|.*$
third line: ^_.*$

for every parser object set one of your created "styles" in "token styles"
FritsBee
Posts: 3
Joined: 06.11.2012 15:41

Post by FritsBee »

Wauw thanks,

But Why are there sometimes *.* and sometimes .*

You can see I'm not familiar with this. ;-) :o

Frits
Alexey
Posts: 1633
Joined: 05.10.2012 22:10

Post by Alexey »

Matthias
Posts: 10
Joined: 05.10.2012 22:07

Post by Matthias »

Regex is much powerful but hard to understand. If you're interested, the link from Alex gives a good start into regex knowledge.

Let me explain the 1st regex. "^\*.*$" represents any line that starts with a star "*". now take a closer look on every single regex part:

^ - marks the beginning of any line in text
\* - the symbol * is a reserved char in regex, so we need to escape it with a "\". "\*" stands for the character "*" in text.

with "^\*" we have now defined any line that starts with *. but you want to highlight the whole line and not only the * character at line start. so we need some more code

. - stands for any single character (a letter, number, symbol) that follows the *
* - repeat the "." until another condition follows. ".*" together means any text with mixed letters, numbers, symbols
$ - marks the end of line
FritsBee
Posts: 3
Joined: 06.11.2012 15:41

Post by FritsBee »

Man you'r the greatets

Many thanks
Locked