How to create Rules for 2 Versions

All questions regarding lexer highlighting schemes are discussed here...
Post Reply
Shando
Posts: 13
Joined: 11.10.2018 02:25

How to create Rules for 2 Versions

Post by Shando »

Hi all,

How would I create Rules for the following variations of the same statement:

Code: Select all

if first
    > "First Parameter: ", first
end

if second: > "Second Parameter: ", second
Thanks in advance

Shando
Alexey
Posts: 1633
Joined: 05.10.2012 22:10

Post by Alexey »

Seems, rule-1 will be "if <Id> > ......." with ending rule "end".
and rule-2 will be "if <Id> : > ......" without ending rule.

It's so if "first/second" are Id. If they are expressions, then:
instead of <Id> add "skip tokens" for several token types: <Id> <Symbol> <String> etc.
You need to skip <Symbol> so symbols > and : must be of different name, e.g. <SymbolGreater>, <SymbolColon>
Shando
Posts: 13
Joined: 11.10.2018 02:25

Post by Shando »

Hi Alexey,

Thanks for the reply.

I've tried what you suggested, but must be doing something wrong as I can't get it to work...

Basically, the grammar is as follows:

if <expression> <eol> <statement_list>* <elif_or_else>* <end> <eol>
and
if <expression> <colon> <statement> <eol>

* = can be multiple as per standard if .. else statements

Any further help would be greatly appreciated.

Regards

Shando
Alexey
Posts: 1633
Joined: 05.10.2012 22:10

Post by Alexey »

I will help with ready example of lexer- e.g. small lexer with 2 these rules.
Post Reply