EControl Ltd. Forum Index EControl Ltd.
VCL libraries and software support forum
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How would I tell if a token is of a type or inside range?

 
Post new topic   Reply to topic    EControl Ltd. Forum Index -> EControl Syntax Editor
View previous topic :: View next topic  
Author Message
coder



Joined: 16 Dec 2006
Posts: 2

PostPosted: Fri Dec 29, 2006 9:16 pm    Post subject: How would I tell if a token is of a type or inside range? Reply with quote

Hello,

If I extract a word from the Memo, how would I tell the type of token that word is (I have types defined, ex: function, keyword, string, etc...)

Also, if I have a token inside of a pair of ( ), how would I tell that's it's inside the range (I defined this too) of the ( )?
Back to top
View user's profile Send private message
econtrol
Site Admin


Joined: 09 Jun 2006
Posts: 202

PostPosted: Sat Dec 30, 2006 3:05 pm    Post subject: Reply with quote

Hello,

Example,

// Returns token type at the given position
function SelectedWordType(Memo: TSyntaxMemo; Pos: integer): integer;
var idx: integer;
begin
Result := -1;
if Assigned(Memo.SyntObj) then
begin
idx := Memo.SyntObj.TokenAtPos(Pos);
if idx <> -1 then
Result := Memo.SyntObj.Tags[idx].TokenType;
end;
end;

...

Type_of_selected_word := SelectedWordType(SyntaxMemo1, SyntaxMemo1.SelStart);

Using TSyntaxMemo.SyntObj.Tags[] - you may access all token in the text. Each token has start and end position, rule reference, token type.

Using TSyntaxMemo.SyntObj.Ranges[] - you may access all text ranges in the text.

Using Tags and Ranges properties will very help in code automation (code completion, parameter completion, symbol hints ...)

Michael.
Back to top
View user's profile Send private message Send e-mail
coder



Joined: 16 Dec 2006
Posts: 2

PostPosted: Sun Dec 31, 2006 7:59 am    Post subject: Reply with quote

Thanks for the reply but it doesn't work for my case because I'm not accessing the whole memo component, instead, I'm parsing my text through a function line by line therefore I cannot use memo.selstart.

Is there a way to pass by a token and immediately get its rule display name?

for ex:

pass in: begin
gets back: keyword

pass in: 'testing'
gets back: string

I have already defined the keyword and string rules, now I just need to match them up. The example you gave worked fine for global Memo but I cannot access the tokenatpos function correctly if I'm going line by line.
Back to top
View user's profile Send private message
econtrol
Site Admin


Joined: 09 Jun 2006
Posts: 202

PostPosted: Mon Jan 01, 2007 6:46 pm    Post subject: Reply with quote

You may use

Code:
TSyntAnalyzer.BlockRules[].ConditionList[].TagList : TStrings


to access keywords defined in lexer. Paricular path you may see in "Object Inspector".

Michael.
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    EControl Ltd. Forum Index -> EControl Syntax Editor All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group