Rules |
Top Previous Next |
Each scheme contains zero or more rules. Rule contains regular expression used to search tokens, or switch into another scheme. Keep in mind, however, that the scope of every regexp is limited to one line. Also, spaces and newlines inside regexp are ignored, thus, to specify space inside regexp, use “\s” construct.
Rule used to search some regexp inside line and split it to tokens, or assign whole match to another scheme.
<Regex token0='attributeValue'> [^ < > " ' = \s ]+ </Regex> <Regex token0='attributeValue' regex='[^ < > " ' = \s ]+' />
Example 1:
<Regex token0='email'> [_a-zA-Z\d\-\.]+ @ ([_ a-z A-Z \d \-]+ (\. [_ a-z A-Z \d \-]+ )+ ) </Regex>
All match will produce one “email” <Token>.
Example 2:
<Regex token1='emailUser' token2='emailAt' token3='emailHost'> ( [_a-zA-Z\d\-\.]+ ) ( @ ) ([_ a-z A-Z \d \-]+ (\. [_ a-z A-Z \d \-]+ )+ ) </Regex>
All match will produce three tokens: “emailUser” , “emailAt”, “emailHost”. If token for group sequence not given, then default scheme token will be produced:
Example 3:
<Regex token3='emailHost'> ( [_a-zA-Z\d\-\.]+ ) ( @ ) ([_ a-z A-Z \d \-]+ (\. [_ a-z A-Z \d \-]+ )+ ) </Regex>
This match will produce two tokens: “default”, “emailHost”. If token given for outer group of some inner group, then token for inner group will not be produced, instead, token will be produced for outer group only.
Example 4:
<Regex token3='emailHost' token4='emailHostEnd'> ( [_a-zA-Z\d\-\.]+ ) ( @ ) ([_ a-z A-Z \d \-]+ (\. [_ a-z A-Z \d \-]+ )+ ) </Regex>
This match will produce two tokens: “default”, “emailHost”. Group4 is inside Group3, so, token for Group4 will not be produced, because it inside token given for outer Group3.
Example 5:
<Regex token0='email' token3='emailHost' token4='emailHostEnd'> ( [_a-zA-Z\d\-\.]+ ) ( @ ) ([_ a-z A-Z \d \-]+ (\. [_ a-z A-Z \d \-]+ )+ ) </Regex>
This match will produce one token: “email” Groups 4 and 3 are inside of Group0 (whole match), so, tokens for Group4 and Group3 will not be produced, because it inside token given for outer Group0 (whole match).
Also, rule can refer any scheme from other SSL document from TLMDEditDocument.SyntaxSchemes collection using syntax like this: innerScheme =”OtherDoc.SomeScheme”; For example:
<!--Strings scheme --> <Scheme name='String' defaultToken='string'> <!—Will highlight emails inside string literals --> <Regex token0='email'> [_a-zA-Z\d\-\.]+ @ ([_ a-z A-Z \d \-]+ (\. [_ a-z A-Z \d \-]+ )+ ) </Regex> </Scheme>
<!—- Text inside two quotes will be parsed by String scheme rules --> <Regex innerScheme='String'> " (.*?\\ " )*? " </Regex>
<!—- Text inside two ‘’ will be parsed by String scheme from other XML document in TLMDEditDocument.SyntaxSchemes collection, named ‘JavaScript’ --> <Regex innerScheme='JavaScript.String'> ' (.*?\\ ' )*? ' </Regex>
<!-- defaultToken='string': all text inside will be green --> <Scheme name='String' inherit='Text' defaultToken='string'> <Regex token0='escaped' regex='\\[a-z " ]' /> <Regex token0='escaped' regex='\\0x[a-fA-F0-9]+' /> </Scheme>
<!-- defaultToken='badString': all text inside will be red --> <Scheme name='BadString' inherit='String' defaultToken='badString'/>
<!—- You can inherit this scheme to highlight C++ string literals --> <Scheme name='StringFind'> <!—- Text started from “ blah-blah .. may be closed or unclosed string literal -->
<!—- First, we will check for good (closed) string. --> <Regex innerScheme='String' priority='10' <!—- Big priority ? > " (.*?\\ " )*? " </Regex>
<!—- Second, we will check for bad (unclosed) string. --> <Regex innerScheme='BadString' <!—- priority=0 (default) ? > " (.*?\\ " )*? .* $ </Regex> </Scheme>
<!-- All preprocessor text will go as one token 'preprocessor', with contents taken from matched group1 --> <Regex innerScheme='Preprocessor' innerContentGroup='1' priority='10' > ^ \s* \# ([a-zA-Z]+) .* $ </Regex>
<!-- We will fold text inside preprocessor if/endif --> <SyntaxBlock capture="true"> <!-- Here: ‘preprocessor’ is token, ‘if’ is token contents --> <Start> [ preprocessor:if preprocessor:ifdef ] </Start> <End> [ preprocessor:ifend preprocessor:endif ] </End> </SyntaxBlock> |