Page 1 of 1

Simple Lexer

Posted: 06.11.2012 15:54
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

Posted: 06.11.2012 16:50
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"

Posted: 07.11.2012 15:36
by FritsBee
Wauw thanks,

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

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

Frits

Posted: 07.11.2012 16:14
by Alexey

Posted: 07.11.2012 17:05
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

Posted: 07.11.2012 19:06
by FritsBee
Man you'r the greatets

Many thanks