Custom Token with spaces

SyntaxEditor for Windows Forms Forum

Posted 14 years ago by Carl Gilbert
Avatar
Hi

I am using the Actipro Syntax Editor and I am trying to define my own language definition.

I want to define a token that can have at least one WordMacro and optionally a space followed by another WordMacro all encapsulated in square brackets.
For example, [something] or [something else] or [something else again]
So, it always contains one word macro but could contain another word macro precedded by space. The token can not finish with a space either.

I have attached my efforts so far where I have made a new token called CarlToken. Could you please take a look my definition to see where I am going wrong?

Note: The example I have attached uses the '@' at the start and end but ideally I would like to use a '[' and ']' but I wasn't too sure about its use within the document.

Regards, Carl Gilbert

<SyntaxLanguage Key="VB.NET" LanguageDefinitionVersion="3.0" Secure="True" xmlns="http://ActiproSoftware/SyntaxEditor/3.0/LanguageDefinition">

    
    <!-- Triggers -->
    <Triggers>
        <KeyPressTrigger Key="VariableListTrigger" Character="@">
            <KeyPressTriggerValidStates>
                <KeyPressTriggerValidState State="DefaultState" />
            </KeyPressTriggerValidStates>
        </KeyPressTrigger>
        <KeyPressTrigger Key="MemberListTrigger" Character=".">
            <KeyPressTriggerValidStates>
                <KeyPressTriggerValidState State="DefaultState" />
            </KeyPressTriggerValidStates>
        </KeyPressTrigger>
    </Triggers>

    <!-- Highlighting Styles -->    
    <Styles>
        <Style Key="CollapsibleTextStyle" Name="Collapsible Text" ForeColor="Gray" BackColor="Default" Bold="False" Italic="False" Underline="False" />
        <Style Key="ReservedWordStyle" ForeColor="Blue" BackColor="Default" Bold="False" Italic="False" Underline="False" />
        <Style Key="NativeTypeStyle" ForeColor="Blue" BackColor="Default" Bold="False" Italic="False" Underline="False" />
        <Style Key="OperatorStyle" ForeColor="Black" BackColor="Default" Bold="False" Italic="False" Underline="False" />
        <Style Key="ReservedWordOperatorStyle" ForeColor="Blue" BackColor="Default" Bold="False" Italic="False" Underline="False" />
        <Style Key="VariableStyle" ForeColor="Purple" BackColor="Default" Bold="False" Italic="False" Underline="False" /> 
        <Style Key="SomethingStyle" ForeColor="Red" BackColor="Default" Bold="False" Italic="False" Underline="False" /> 
        <Style Key="NumberStyle" ForeColor="Black" BackColor="Default" Bold="False" Italic="False" Underline="False" />
        <Style Key="StringDelimiterStyle" ForeColor="Black" BackColor="Default" Bold="False" Italic="False" Underline="False" />
        <Style Key="StringDefaultStyle" ForeColor="Black" BackColor="Default" Bold="False" Italic="False" Underline="False" />
        <Style Key="CommentDelimiterStyle" ForeColor="Green" BackColor="Default" Bold="False" Italic="False" Underline="False" />
        <Style Key="CommentDefaultStyle" ForeColor="Green" BackColor="Default" Bold="False" Italic="False" Underline="False" />
        <Style Key="PreProcessorDirectiveKeywordStyle" Name="Pre-Processor Directive Keyword" ForeColor="Blue" BackColor="Default" Bold="False" Italic="False" Underline="False" />
        <Style Key="PreProcessorDirectiveDefaultStyle" Name="Pre-Processor Directive Default" ForeColor="Black" BackColor="Default" Bold="False" Italic="False" Underline="False" />
    </Styles>
    
    <!-- States -->
    <States>
        <!-- Code -->
        <State Key="DefaultState">
            <!-- Patterns Groups -->
            <PatternGroups>
                <!-- Whitespace -->
                <RegexPatternGroup TokenKey="WhitespaceToken" PatternValue="{WhitespaceMacro}+" IsWhitespace="True" />
                <!-- Line Terminators -->
                <RegexPatternGroup TokenKey="LineTerminatorToken" PatternValue="{LineTerminatorMacro}" IsWhitespace="True" />
                <!-- Brackets -->
                <ExplicitPatternGroup Key="OpenParenthesisPatternGroup" TokenKey="OpenParenthesisToken" PatternValue="(" EndBracket="CloseParenthesisPatternGroup" />
                <ExplicitPatternGroup Key="CloseParenthesisPatternGroup" TokenKey="CloseParenthesisToken" PatternValue=")" StartBracket="OpenParenthesisPatternGroup" />
                <!-- Punctuation -->
                <ExplicitPatternGroup TokenKey="PunctuationToken">
                    <ExplicitPatterns>
                        . ,
                    </ExplicitPatterns>
                </ExplicitPatternGroup>
                <!-- Booleans -->
                <ExplicitPatternGroup TokenKey="BooleanToken" Style="ReservedWordStyle" LookBehind="[^\.]" LookAhead="{NonWordMacro}" CaseSensitivity="AutoCorrect">
                    <ExplicitPatterns>
                        False True
                    </ExplicitPatterns>
                </ExplicitPatternGroup>
                
                <!-- My -->
                <ExplicitPatternGroup TokenKey="MyToken" PatternValue="My" Style="ReservedWordStyle" LookBehind="[^\.]" LookAhead="{NonWordMacro}" CaseSensitivity="AutoCorrect"/>

                <!-- LocalVariablesToken -->
                <ExplicitPatternGroup TokenKey="LocalVariablesToken" PatternValue="LocalVariables" Style="ReservedWordStyle" LookAhead="{NonWordMacro}" CaseSensitivity="AutoCorrect"/>
                <!-- GlobalVariablesToken -->
                <ExplicitPatternGroup TokenKey="GlobalVariablesToken" PatternValue="GlobalVariables" Style="ReservedWordStyle" LookAhead="{NonWordMacro}" CaseSensitivity="AutoCorrect"/>
                <!-- OrganisationToken -->
                <ExplicitPatternGroup TokenKey="OrganisationToken" PatternValue="Organisation" Style="ReservedWordStyle" LookAhead="{NonWordMacro}" CaseSensitivity="AutoCorrect"/>
                <!-- SystemTypesToken -->
                <ExplicitPatternGroup TokenKey="SystemTypesToken" PatternValue="SystemTypes" Style="ReservedWordStyle" LookAhead="{NonWordMacro}" CaseSensitivity="AutoCorrect"/>


                <!-- Reserved Word Operators -->
                <ExplicitPatternGroup TokenKey="ReservedWordOperatorToken" Style="ReservedWordOperatorStyle" LookBehind="[^\.]" LookAhead="{NonWordMacro}" CaseSensitivity="AutoCorrect">
                    <ExplicitPatterns>
                        And Mod Not Or Xor
                    </ExplicitPatterns>
                </ExplicitPatternGroup>
                <!-- Reserved Words -->
                <ExplicitPatternGroup TokenKey="ReservedWordToken" Style="ReservedWordStyle" LookBehind="[^\.]" LookAhead="{NonWordMacro}" CaseSensitivity="AutoCorrect">
                    <ExplicitPatterns>
                        
                    </ExplicitPatterns>
                </ExplicitPatternGroup>
                <!-- Identifier -->
                <RegexPatternGroup TokenKey="IdentifierToken" Style="VariableStyle" PatternValue="(_ | {AlphaMacro})({WordMacro})*" />
                
                <!-- Operators -->
                <ExplicitPatternGroup TokenKey="OperatorToken" Style="OperatorStyle">
                    <ExplicitPatterns>
                        = &lt;&gt; 
                        += -= *= /= \= ^= 
                        + - * / \ ^  
                        &lt;= &lt; &gt;= &gt; 
                    </ExplicitPatterns>
                </ExplicitPatternGroup>

                <!-- CarlToken --> 
                <RegexPatternGroup TokenKey="CarlToken" Style="VariableStyle" PatternValue="@ {WordMacro}+ (\s {WordMacro}) @" LookAhead="{NonWordMacro}" /> 

                <!-- Numbers -->
                <RegexPatternGroup TokenKey="RealNumberToken" Style="NumberStyle" LookAhead="{NonWordMacro}">
                    <RegexPattern Value="{DigitMacro}* \. {DigitMacro}+ ([Ee] [\+\-]? {DigitMacro}+)?" />
                    <RegexPattern Value="{DigitMacro}+ [Ee] [\+\-]? {DigitMacro}+" />
                </RegexPatternGroup>
                <RegexPatternGroup TokenKey="IntegerNumberToken" Style="NumberStyle" PatternValue="{DigitMacro}+" LookAhead="{NonWordMacro}" />
                <RegexPatternGroup TokenKey="HexIntegerNumberToken" Style="NumberStyle" PatternValue="&amp; [hH] {HexDigitMacro}+" LookAhead="{NonWordMacro}" />
            </PatternGroups>
            <!-- Child States -->
            <ChildStates>
                <ChildState Key="StringState" />
                <ChildState Key="CommentState" />
                <ChildState Key="PreProcessorDirectiveState" />
            </ChildStates>
        </State>
        
        <!-- Strings -->
        <State Key="StringState" TokenKey="StringDefaultToken" Style="StringDefaultStyle">
            <!-- Scopes -->
            <Scopes>
                <Scope>
                    <ExplicitPatternGroup Type="StartScope" TokenKey="StringStartToken" Style="StringDelimiterStyle" PatternValue="&quot;" />
                    <RegexPatternGroup Type="EndScope" TokenKey="StringEndToken" Style="StringDelimiterStyle" PatternValue="[\&quot;\n]" />    
                </Scope>
            </Scopes>
            <!-- Patterns Groups -->
            <PatternGroups>
                <ExplicitPatternGroup TokenKey="StringEscapedCharacterToken" PatternValue="&quot;&quot;" />
                <RegexPatternGroup TokenKey="StringDefaultToken2" PatternValue="[^\&quot;\n]+" />
            </PatternGroups>
        </State>

        <!-- Somethings -->
        <State Key="SomethingState" TokenKey="SomethingToken" Style="SomethingStyle">
            <!-- Scopes -->
            <Scopes>
                <Scope>
                    <ExplicitPatternGroup Type="StartScope" TokenKey="SomethingStartToken" Style="SomethingStyle" PatternValue="@" />
                    <RegexPatternGroup Type="EndScope" TokenKey="SomethingEndToken" Style="SomethingStyle" PatternValue="[\@\n]" />    
                </Scope>
            </Scopes>
            <!-- Patterns Groups -->
            <PatternGroups>
                <ExplicitPatternGroup TokenKey="StringEscapedCharacterToken" PatternValue="@@" />
                <RegexPatternGroup TokenKey="StringDefaultToken2" PatternValue="[^\@\n]+" />
            </PatternGroups>
        </State>
        
        <!-- Comments -->
        <State Key="CommentState" TokenKey="CommentDefaultToken" Style="CommentDefaultStyle">
            <!-- Scopes -->
            <Scopes>
                <Scope>
                    <ExplicitPatternGroup Type="StartScope" TokenKey="CommentStartToken" Style="CommentDelimiterStyle" PatternValue="'" />
                    <RegexPatternGroup Type="EndScope" TokenKey="CommentEndToken" Style="CommentDelimiterStyle" PatternValue="{LineTerminatorMacro}" IsWhitespace="True" />    
                </Scope>
            </Scopes>
            <!-- Patterns Groups -->
            <PatternGroups>
                <RegexPatternGroup TokenKey="CommentDefaultToken" PatternValue="{NonLineTerminatorMacro}+" />
            </PatternGroups>
        </State>

        <!-- Pre-Processor Directives -->
        <State Key="PreProcessorDirectiveState" TokenKey="PreProcessorDirectiveDefaultToken" Style="PreProcessorDirectiveDefaultStyle">
            <!-- Patterns Groups -->
            <PatternGroups>
                <RegexPatternGroup TokenKey="PreProcessorDirectiveDefaultToken" PatternValue="{NonLineTerminatorMacro}+" />
            </PatternGroups>
        </State>
    </States>
    
</SyntaxLanguage>

Comments (1)

Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Carl,

Here's what you need it to read... let me know if that gets it right:
<RegexPatternGroup TokenKey="CarlToken" Style="VariableStyle" PatternValue="\[ {WordMacro}+ (\s+ {WordMacro}+)* \]" />


Actipro Software Support

The latest build of this product (v2018.1 build 0341) was released 7 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.