csharp/Actipro/WPF-Controls/Samples/SampleBrowser/ProductSamples/SyntaxEditorSamples/QuickStart/DotNetAddonServerTags/ParentLexer.cs

ParentLexer.cs
using System;
using System.Collections.Generic;
using ActiproSoftware.Text;
using ActiproSoftware.Text.Implementation;
using ActiproSoftware.Text.Lexing;
using ActiproSoftware.Text.Lexing.Implementation;
using ActiproSoftware.Text.RegularExpressions;

namespace ActiproSoftware.ProductSamples.SyntaxEditorSamples.QuickStart.DotNetAddOnServerTags {
	
	/// 
	/// Represents a Parent lexer (lexical astyzer) implementation.
	/// 
	internal clast ParentLexer : MergableLexerBase {

		private LexicalStateCollection	lexicalStates;
		
		/////////////////////////////////////////////////////////////////////////////////////////////////////
		// OBJECT
		/////////////////////////////////////////////////////////////////////////////////////////////////////

		/// 
		/// Initializes a new instance of the ParentLexer clast.
		/// 
		/// The child language.
		public ParentLexer(ISyntaxLanguage childLanguage) {
			// Initialize lexical states
			lexicalStates = new LexicalStateCollection(this);

			ProgrammaticLexicalState defaultState = new ProgrammaticLexicalState(ParentLexicalStateId.Default, "Default");
			lexicalStates.Add(defaultState);
			this.DefaultLexicalStateCore = defaultState;

			ProgrammaticLexicalState childOutputBlockTransitionState = new ProgrammaticLexicalState(ParentLexicalStateId.ChildOutputBlock, "Child output block transition");
			childOutputBlockTransitionState.LexicalScopes.Add(new ProgrammaticLexicalScope(new ProgrammaticLexicalScopeMatch(this.IsChildOutputBlockTransitionStateScopeStart), 
				new ProgrammaticLexicalScopeMatch(this.IsChildOutputBlockTransitionStateScopeEnd)));
			lexicalStates.Add(childOutputBlockTransitionState);
			defaultState.ChildLexicalStates.Add(childOutputBlockTransitionState);

			ProgrammaticLexicalState childCodeBlockTransitionState = new ProgrammaticLexicalState(ParentLexicalStateId.ChildCodeBlock, "Child code block transition");
			childCodeBlockTransitionState.LexicalScopes.Add(new ProgrammaticLexicalScope(new ProgrammaticLexicalScopeMatch(this.IsChildCodeBlockTransitionStateScopeStart), 
				new ProgrammaticLexicalScopeMatch(this.IsChildCodeBlockTransitionStateScopeEnd)));
			lexicalStates.Add(childCodeBlockTransitionState);
			defaultState.ChildLexicalStates.Add(childCodeBlockTransitionState);

			IMergableLexer lexer = childLanguage.GetLexer() as IMergableLexer;
			if (lexer != null) {
				childOutputBlockTransitionState.Transition = new LexicalStateTransition(childLanguage, lexer.DefaultLexicalState, null);
				childCodeBlockTransitionState.Transition = new LexicalStateTransition(childLanguage, lexer.DefaultLexicalState, null);
			}
		}
		
		/////////////////////////////////////////////////////////////////////////////////////////////////////
		// NON-PUBLIC PROCEDURES
		/////////////////////////////////////////////////////////////////////////////////////////////////////
		
		/// 
		/// Represents the method that will handle token matching callbacks.
		/// 
		/// An  that is reading a text source.
		/// The  that specifies the lexical scope to check.
		/// A  indicating the lexer result.
		private MergableLexerResult IsChildCodeBlockTransitionStateScopeEnd(ITextBufferReader reader, ILexicalScope lexicalScope) {
			if (reader.Peek() == '%') {
				reader.Read();
				if (reader.Peek() == '>') {
					reader.Read();
					return new MergableLexerResult(MatchType.ExactMatch, new LexicalScopeTokenData(lexicalScope, ParentTokenId.ChildCodeBlockEnd));
				}
				reader.ReadReverse();
			}
			return MergableLexerResult.NoMatch;
		}

		/// 
		/// Represents the method that will handle token matching callbacks.
		/// 
		/// An  that is reading a text source.
		/// The  that specifies the lexical scope to check.
		/// A  indicating the lexer result.
		private MergableLexerResult IsChildCodeBlockTransitionStateScopeStart(ITextBufferReader reader, ILexicalScope lexicalScope) {
			if (reader.Peek() == '') {
					reader.Read();
					return new MergableLexerResult(MatchType.ExactMatch, new LexicalScopeTokenData(lexicalScope, ParentTokenId.ChildOutputBlockEnd));
				}
				reader.ReadReverse();
			}
			return MergableLexerResult.NoMatch;
		}

		/// 
		/// Represents the method that will handle token matching callbacks.
		/// 
		/// An  that is reading a text source.
		/// The  that specifies the lexical scope to check.
		/// A  indicating the lexer result.
		private MergableLexerResult IsChildOutputBlockTransitionStateScopeStart(ITextBufferReader reader, ILexicalScope lexicalScope) {
			if (reader.Peek() == '