Attributes Inheritance with Scheme Nesting

Top  Previous  Next

Here described how text styling attrubutes are applied while we enter from outer scheme into inner sub-scheme.


Consider the following text:


blah-blah 12345 “ some string 12345 12345


Consider the following color scheme:


<?xml version="1.0" encoding="UTF-8"?>


    <Token name="default" textColor="#0" />

    <Token name="string" textColor="green" />

    <Token name="number" fontStyle="bold" />        



Consider the following syntax scheme:


<?xml version="1.0" encoding="UTF-8"?>

<SchemeList root='Main'>

    <!--Strings scheme -->

    <Scheme name='String' defaultToken='string'>

        <Regex token0='number'>

            \b [+\-]? \d+ (\. \d+)? ([eE] [+\-]? \d+) \b




    <Scheme name='Main' defaultToken='default'>

        <Regex token0='number'>

            \b [+\-]? \d+ (\. \d+)? ([eE] [+\-]? \d+) \b



        <RegexBlock innerScheme='String' start_token0='string' 

                    end_token0='string' >


            <Start> &quot;  </Start>        

            <End> &quot; </End>        





When we start parse text, we will be in “Main” scheme.

First, we will find text from start till number: “  blah-blah  ”. This text is not acceptable by any scheme’s rule, thus, it will produce “default” token with black text color and no other attributes.

Second, parser will see text acceptable by rule for numbers (12345), and will produce token “number” with bold font attribute. Other attributes for this token will be got from “deafult” scheme attribute. It is black font color.

Third, parser will find quotes and, from first quote, it will go inside “String” scheme. Default token attributes of String scheme (token “string”) are combined with default token attributes of outer Main scheme (“default”), and textColor of “string” overrides textColor of “default”. Thus, default text color in string will be black.

Next, parser will handle “some string” as “default” token for string scheme - they will be green.

Next, parser will find number inside string, and will apply “number” token attributes to it, combining them with default attributes of “String” scheme. Thus, number will be green and bold.

Next, parser will find end expression of “String” scheme - quote, and will produce “string” attribute for it, as given in end_token0 attribute of RegexBlock.

Next, parser will switch back to “Main” scheme, find a number, produce “number” token, and apply text attributes to it, combining them with “default” attributes of “Main” scheme.


Thus, “number” outside string will be black and bold, and “number” inside string will be green and bold.


Another view at this example:


blah-blah            <== [] (no attrs) + [black] (“Main” default attrs)

12345                <== [bold] + [black] = [bold, black]

“ some string       <== [] + [black] + [green] = [green]

                        (“String” default color

                         overrides “Main” default color)

12345               <== [] + [black] + [green] + [bold] = [green, bold]

12345               <== [bold] + [black] = [bold, black]