EControl Syntax Editor SDK
Block rules

Block rules are applied to the array of tokens. Block rules are checked after each token detection. 


Block types 


Block type specifies action after successful conditions check. 

There are four rule types:

  1. Tag detector - sets style of token (with Identifier index)
  2. Line separator - creates line separator
  3. Range start - creates text range
  4. Range end - closes text range.


Indexing in block rules 


Some properties of block rule use indexes. All indexes are back offset from the indexing reference point. 

There two case of reference point: 

1. Start of conditions (index 0 corresponds to the first checked token). 

2. End of conditions (index 0 corresponds to the last checked token). 



Rule "class derived" of LexLib.Pascal:

0. EQUAL        <identifier>
1. EQUAL   )    <symbol>
2. SKIP         <symbol, identifier>
3. EQUAL   (    <symbol>
4. EQUAL class  <identifier>
5. EQUAL   =    <symbol>

TComponent = class ( TPersistent , IInterface , IInterfaceComponentReference )


Conditions start   9  8  7  6  5  4  3  2  1  0
Conditions end     1  0 -1 -2 -3 -4 -5 -6 -7 -8


Due to there is SKIP condition in this rule, we do not know length of token sequence that satisfies this rule. To specify indexing reference point use Relative to end of condition. flag. When it is True indexing reference point - conditions end, otherwise indexing reference point - conditions start. In this example we must set this flag to True. 


Identifier index - back offset of identifier token. In example above identifier index may be 1 (token "TComponent") or -1 (token "class"). 

The default value of the Identifier Index is 0. It is not necessary to specify this property. 


Block offset - back offset of text range start/end. It is used only for "Range start/end" rules. 


Other properties 


Grammar rule - name of grammar rule which is used instead of conditions sequence to test current sequence of tokens. 


Parent block, Strict parent block, Not a parent, Always enabled - are common for all rules, see "Common for Styles and Rules". 


Group index - integer value that is used to filter text ranges by the syntax tree view. Default is 0, i.e. no filtering performed by the syntax tree. 


Change token type - specifies token type which will be assigned to identifier token. This property available only for "Tag detector" rules. 

Line break position - specifies position of the line separator (above or under token with Ident Index). This property available only for "Line separator" rules. 

Range end condition - reference to the block rule that will close text range, reference to the block rule, text range of which will be closed. This property available only for "Range start" rules. 

Range start condition - reference to the block rule text range of that will be closed by this rule. This property available only for "Range end" rules. 


Require same ident - When this flag is True, when closing text range condition checks identifiers of range start and range end. Only for "Range end" rules. 


Cancel next rules - specifies that block rules checking loop must be broken if this rule is successful. 


Text ranges properties 

These properties are applied to created text ranges, i.e. they are used only for rule type "Range start". 


Name format string - is used for formatting text range name that is used in TSyntaxTreeView. If it is empty, Identifier token will be taken as the range name. See Name formatting (for block rules) to understand principles of name formatting. 


Group format string - is used for formatting text range group name that is used in TSyntaxTreeView. If it is empty, there is no group for this text range. If any text ranges within one parent have identical group name, Group node will be created with caption of this group name and all these text ranges will be children of this group node. See Name formatting (for block rules) to understand principles of building name format. 


Collapsed text icon - is used for formatting string which is used to paint collapsed text icon (text displayed when text range is collapsed). When this property is empty collapsed text icon is not displayed (collapsed text range is shown as line separator). 


Close block at end of text - when this Flag is True, opened text range will be closed at end of text. Only for "Range start" rules. 


Self closing range - specifies whether rule should close previously opened text range before opening new text range. 


Initially closed (no end rule) - specifies whether text range should be closed immediately after opening. Text range will occupy tokens that was used when checking conditions or grammar rule. 


Display in syntax tree view - specifies whether text range must be displayed in TSyntaxTreeView control. Only for "Range start" rules. 


Con not be collapsed - specifies whether text range can be collapsed by user. Only for "Range start" rules. 


Draw block staple - specifies whether text ranges of this rule must be pined together by the staple. 


Highlight page 


Style - For "Range start" rule specifies style of all token in the associated text ranges. For "Tag detect" rule specifies style of token with Ident Index. For "Line separator" rule specifies line color of separator. 


Highlight type - specifies highlighting region:  

No highlighting 
Only bounding tokens 
Only bounding tokens will be highlighted 
All tokens without bounds 
All tokens without bounds will be highlighted 
All range 
All tokens in text range will be highlighted 


Highlight lines of block - when this flag is True, all lines of text range will be highlighted (will have the same foregound and background colors) with the specified Style. If style have ftBackGround type only backgound will be highlighted. Only for "Range start" rules. 


Invert colors of selection - available only if "Highlight lines of block" is True. It specifies style of the selection in Syntax Memo. If it is True, inverted style colors will be used to paint selection, else default selection style will be used. Only for "Range start" rules. 


Active highlighting 


Active highlighting specify that text range may be highlighted only when caret is placed in some predefined position. Only for "Range start" rules. 


Caret position - specifies caret position in text range:  

Any position (always) 
range will be always highlighted independently of caret position 
Bounds of the range 
range will be highlighted only when caret at the bounds of the range (two caret position) (for example, highlighting brackets) 
Bounding tokens 
range will be highlighted only when caret at the bounding tokens 
In the range 
range will be highlighted only when caret is anywhere within text range 
Begin of bounding tokens 
Text range is highlighted when caret is at the first charecter of the bounding tokens 


Select minimal range - specifies that only nearest text range of this rule must be selected for active highlighting. For example, when we highlight "begin ... end" block, we want to highlight only nearest block. 


Syntax tree decoration

Here you may specifier styles and image indexes for the tree node associated with text range and group tree node created for this text range. 




Conditions specify current position validation for this rule. If validating is successful corresponded action defined by the block rule type will be performed. There are any number of condition entries. Each condition have next attributes: 


Condition (type) - may be one of the following:  

Token must have token type to be in defined types and token sting must be in key list 
Not equal 
Token must not have token type to be in defined types and token sting must not be in key list 
Token must have token type to be in defined types and token sting must be in key list (with mask) 
Skips all tokens that have specified token type until next condition will be successful 

If key list is empty second part of condition is omitted. 


Token types - is a set of token types to check condition. 


Key list - is an array of strings to check condition. 


Ignore case - specifies whether it compares strings without case sensitive. 

Copyright (c) 2004-2011. All rights reserved.
What do you think about this topic? Send feedback!