Newbee Question: Single Line Comment

SyntaxEditor for WPF Forum

Posted 7 years ago by Housi
Version: 13.1.0583
Avatar

Hi,

I have this .langdef file:

<?xml version="1.0" encoding="utf-8"?>
<!--

Actipro Syntax Language Definition (.langdef)
  For use with Actipro SyntaxEditor and related products.
  http://www.actiprosoftware.com

'AGC+' language created by Agathon AG.
  Copyright by Agathon AG

-->
<LanguageDefinition LanguageKey="AGCplus" LanguageDescription="AGC+" Creator="Agathon AG" Copyright="Copyright by Agathon AG" xmlns="http://schemas.actiprosoftware.com/langdef/1.0">
	<!-- Classification types -->
	<LanguageDefinition.ClassificationTypes>
		<ClassificationType Key="Comment" DefaultStyle="#FF008000" />
		<ClassificationType Key="curKeyword" />
		<ClassificationType Key="currCommand" />
		<ClassificationType Key="Delimiter" />
		<ClassificationType Key="Identifier" />
		<ClassificationType Key="Keyword" DefaultStyle="#FF0000FF" />
		<ClassificationType Key="Number" />
		<ClassificationType Key="Operator" />
		<ClassificationType Key="Simulation" DefaultStyle="#FF8000FF" />
		<ClassificationType Key="String" DefaultStyle="#FF851111" />
	</LanguageDefinition.ClassificationTypes>
	<!-- Lexer -->
	<LanguageDefinition.Lexer>
		<DynamicLexer>
			<!-- Default state -->
			<State Id="1" Key="Default">
				<State.ChildStates>
					<StateRef Key="PrimaryString" />
					<StateRef Key="Simulation" />
					<StateRef Key="MultiLineComment" />
				</State.ChildStates>
				<RegexPatternGroup TokenId="2" TokenKey="Whitespace" Pattern="{LineTerminatorWhitespace}+" />
				<ExplicitPatternGroup TokenId="3" TokenKey="CommandEnd" ClassificationTypeKey="Delimiter" Pattern=";" />
				<ExplicitPatternGroup TokenId="4" TokenKey="OpenParenthesis" ClassificationTypeKey="Delimiter" Pattern="(" />
				<ExplicitPatternGroup TokenId="5" TokenKey="CloseParenthesis" ClassificationTypeKey="Delimiter" Pattern=")" />
				<ExplicitPatternGroup TokenId="1" TokenKey="Keyword" ClassificationTypeKey="Keyword" LookAheadPattern="{NonWord}|\z" CaseSensitivity="AutoCorrect">
					<ExplicitPatterns><![CDATA[
						###IP COMMANDS###
					]]></ExplicitPatterns>
				</ExplicitPatternGroup>
				<RegexPatternGroup TokenId="6" TokenKey="Identifier" ClassificationTypeKey="Identifier" Pattern="(_ | {Alpha})({Word})*" />
				<ExplicitPatternGroup TokenId="7" TokenKey="Operator" ClassificationTypeKey="Operator">
					<ExplicitPatterns><![CDATA[
						* + - / <= <> < = >= >
					]]></ExplicitPatterns>
				</ExplicitPatternGroup>
				<RegexPatternGroup TokenId="8" TokenKey="RealNumber" ClassificationTypeKey="Number" Pattern="{Digit}* \. {Digit}+" LookAheadPattern="{NonWord}|\z" />
				<RegexPatternGroup TokenId="9" TokenKey="IntegerNumber" ClassificationTypeKey="Number" Pattern="{Digit}+" LookAheadPattern="{NonWord}|\z" />
			</State>
			<!-- Simulation state -->
			<State Id="2" Key="Simulation" DefaultClassificationTypeKey="Simulation">
				<State.Scopes>
					<Scope>
						<Scope.StartPatternGroup>
							<ExplicitPatternGroup Pattern="[" />
						</Scope.StartPatternGroup>
						<Scope.EndPatternGroup>
							<ExplicitPatternGroup Pattern="]" />
						</Scope.EndPatternGroup>
					</Scope>
				</State.Scopes>
				<State.ChildStates>
					<StateRef Key="MultiLineComment" />
					<StateRef Key="PrimaryString" />
					<StateRef Key="Simulation" />
				</State.ChildStates>
				<ExplicitPatternGroup TokenId="1" TokenKey="Keyword" ClassificationTypeKey="Keyword" Pattern="###XXX IP COMMANDS###" LookAheadPattern="{NonWord}|\z" CaseSensitivity="AutoCorrect" />
			</State>
			<!-- PrimaryString state -->
			<State Id="3" Key="PrimaryString" DefaultTokenId="10" DefaultTokenKey="PrimaryStringText" DefaultClassificationTypeKey="String">
				<State.Scopes>
					<Scope>
						<Scope.StartPatternGroup>
							<ExplicitPatternGroup TokenId="11" TokenKey="PrimaryStringStartDelimiter" Pattern="&quot;" />
						</Scope.StartPatternGroup>
						<Scope.EndPatternGroup>
							<ExplicitPatternGroup TokenId="12" TokenKey="PrimaryStringEndDelimiter" Pattern="&quot;" />
						</Scope.EndPatternGroup>
					</Scope>
				</State.Scopes>
				<State.ChildStates>
					<StateRef Key="MultiLineComment" />
				</State.ChildStates>
				<RegexPatternGroup TokenId="13" TokenKey="PrimaryStringLineTerminator" Pattern="\n" />
				<RegexPatternGroup TokenId="10" TokenKey="PrimaryStringText" Pattern="[^\&quot;\n]+" />
			</State>
			<!-- MultiLineComment state -->
			<State Id="4" Key="MultiLineComment" DefaultClassificationTypeKey="Comment">
				<State.Scopes>
					<Scope>
						<Scope.StartPatternGroup>
							<ExplicitPatternGroup Pattern="(*" />
						</Scope.StartPatternGroup>
						<Scope.EndPatternGroup>
							<ExplicitPatternGroup Pattern="*)" />
						</Scope.EndPatternGroup>
					</Scope>
				</State.Scopes>
				<State.ChildStates>
					<StateRef Key="MultiLineComment" />
				</State.ChildStates>
			</State>
		</DynamicLexer>
	</LanguageDefinition.Lexer>
</LanguageDefinition>

 

What do i have to do to add a new State which marks me a single line starting with % and endig wit newline (\n)?

I tried it with this:

		  <State Id="5" Key="EmbeddedIso" DefaultClassificationTypeKey="Simulation">
		    <State.Scopes>
		      <Scope>
		        <Scope.StartPatternGroup>
		          <ExplicitPatternGroup Pattern="%" />
		        </Scope.StartPatternGroup>
		        <Scope.EndPatternGroup>
		          <ExplicitPatternGroup Pattern="\n" />
		        </Scope.EndPatternGroup>
		      </Scope>
		    </State.Scopes>
		    <State.ChildStates>
		      <StateRef Key="MultiLineComment" />
		      <StateRef Key="PrimaryString" />
		      <StateRef Key="EmbeddedIso" />
		    </State.ChildStates>
		  </State>
   

 and several variations. But im stuck now for two days :(

Thanks for any advice.

[Modified 7 years ago]

Comments (2)

Answer - Posted 7 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

It looks like your end pattern is wrong.  You have an ExplicitPatternGroup which means it's going to look for the two character sequence "\n" instead of a line feed character.  You'd want to use a RegexPatternGroup instead or could do this:

<RegexPatternGroup Pattern="{LineTerminator}" />

[Modified 7 years ago]


Actipro Software Support

Posted 7 years ago by Housi
Avatar

Thanks alot, your answer solved the Problem!

The latest build of this product (v24.1.2) was released 2 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.