Posted 19 years ago by Radventure B.V
Avatar
I have been trying to add support for detecting attributes in the C# language. For that I added the expressions listed below to the CSharp.xml to the existing nodes. This basically works, but isn't completely correct. For example, array indexes are now also marked as attributes.

Does anybody have any tips how to prevent this?


<!-- Highlighting Styles -->
<Styles>
<Style Key="AttributeDelimiterStyle" ForeColor="Purple" BackColor="Default" Bold="False" Italic="True" Underline="False" />
<Style Key="AttributeDefaultStyle" ForeColor="Purple" BackColor="Default" Bold="False" Italic="True" Underline="False" />
</Styles>

<!-- Code -->
<State Key="DefaultState">
<!-- Child States -->
<ChildStates>
<ChildState Key="AttributeState" />
</ChildStates>
</State>


<!-- States -->
<States>
<!-- Attributes -->
<State Key="AttributeState" Token="AttributeDefaultToken" Style="AttributeDefaultStyle">
<!-- Scopes -->
<Scopes>
<Scope BracketHighlight="True">
<ExplicitPatternGroup Type="StartScope" Token="AttributeStartToken" Style="AttributeDelimiterStyle" PatternValue="[" />
<!-- ExplicitPatternGroup Type="EndScope" Token="AttributeEndToken" Style="AttributeDelimiterStyle" PatternValue="]" / -->
<RegexPatternGroup Type="EndScope" Token="AttributeEndToken" Style="AttributeDelimiterStyle" PatternValue="[\]\n]" />
</Scope>
</Scopes>
<!-- Patterns Groups -->
<PatternGroups>
<RegexPatternGroup Token="AttributeWhitespaceToken" PatternValue="{WhitespaceMacro}+" IsWhitespace="True" />
<RegexPatternGroup Token="AttributeLineTerminatorToken" PatternValue="{LineTerminatorMacro}" IsWhitespace="True" />
<RegexPatternGroup Token="AttributeWordToken" PatternValue="\w+" />
<!-- RegexPatternGroup Token="AttributeDefaultToken" PatternValue="{NonLineTerminatorMacro}" / -->
<!-- RegexPatternGroup Token="AttributeDefaultToken" PatternValue="[^*]" / -->
<RegexPatternGroup Token="AttributeDefaultToken" PatternValue="[^\]\n]+" />
</PatternGroups>
</State>
</States>

Comments (7)

Posted 19 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
That's why we don't include attributes in our language def. <IMG SRC="smile.gif" border="0">

The problem is that a lexical parser only recognizes pattern sequences. What you really need to do, is examine the meaning of the tokens produced by the lexical parser (which is semantic parsing) and maybe change the highlighting styles on the fly programmatically in the semantic parsing code. You can override a Token's highlighting style by using the CustomHighlightingStyle property.

So maybe you keep your code but use default highlighting styles. Then in a semantic parser PostParse, look at the modified tokens and if they are attributes, change their highlighting styles to the attribute one.


Actipro Software Support

Posted 19 years ago by Radventure B.V
Avatar
Thanks, for the info.

I have now more or less working language definition with support for detecting attributes by changing the pattern for the StartScope into "^({WhitespaceMacro}*)\[".

In the semantic parser I'm now getting correctly the AttributeStartToken and AttributeEndToken when entering or leaving the attributes.

Erik Pepping
Posted 19 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
The next major version will also have regex zero-width assertion look-behind capabilities for all lexical patterns so that might help in the future as well.


Actipro Software Support

Posted 19 years ago by NSXDavid
Avatar
Sweet... that'll help a lot. BTW, are we also getting the updated approach to token changes? Where we can see the ones removed as well?

-- David
Posted 19 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Yes, the next major version already has a flag on Token that indicates if it was modified during the last parse. And a collection of Tokens is available that indicate the tokens which were deleted during the last lexical parse.


Actipro Software Support

Posted 19 years ago by Radventure B.V
Avatar
Perfect!

Erik Pepping
Posted 19 years ago by NSXDavid
Avatar
As Carl would say... "Awwwsoooome." Master Shake would be proud!

-- David
The latest build of this product (v24.1.0) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.