View previous topic :: View next topic |
Author |
Message |
coder
Joined: 16 Dec 2006 Posts: 2
|
Posted: Fri Dec 29, 2006 9:16 pm Post subject: How would I tell if a token is of a type or inside range? |
|
|
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 |
|
|
econtrol Site Admin
Joined: 09 Jun 2006 Posts: 202
|
Posted: Sat Dec 30, 2006 3:05 pm Post subject: |
|
|
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 |
|
|
coder
Joined: 16 Dec 2006 Posts: 2
|
Posted: Sun Dec 31, 2006 7:59 am Post subject: |
|
|
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 |
|
|
econtrol Site Admin
Joined: 09 Jun 2006 Posts: 202
|
Posted: Mon Jan 01, 2007 6:46 pm Post subject: |
|
|
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 |
|
|
|