public int CountTokenByType(SymToken.TClass aClass) { int count = 0; // foreach (SymNode n in this) { if (n is SymNodeToken) { bool isSpecial = (n is SymTokenBalancerNode); // if (isSpecial == false) { SymToken t = ((SymNodeToken)n).Token; // if (t.Class == aClass) { ++count; } } } } // return(count); }
protected static int CountTokenByType(SymNode aNodeWithChildren, SymToken.TClass aClass) { int count = 0; // foreach (SymNode n in aNodeWithChildren) { bool isNodeToken = (n is SymNodeToken); // if (isNodeToken) { bool isSpecial = ((n is SymTokenBalancerNode) || (n is SymTokenBalancerNodeEmittedElement)); // if (isSpecial == false) { SymToken t = ((SymNodeToken)n).Token; // if (t.Class == aClass) { ++count; } } } } // return(count); }
private void MergeWithPreviousTwoTokens( SymToken aNewToken, SymToken.TClass aNewClassType ) { System.Diagnostics.Debug.Assert( iCache.Count > 0 ); SymToken previousToken = iCache.PopTail(); // Combine it with the new token... previousToken.Combine( aNewToken ); previousToken.Class = aNewClassType; // And combine any previous previous token MergeWithPreviousToken( previousToken ); }
private static SymToken.TClass CharacterClassType(char aCharacter) { SymToken.TClass ret = SymToken.TClass.EClassSymbol; // if (char.IsWhiteSpace(aCharacter)) { ret = SymToken.TClass.EClassWhiteSpace; } else if (char.IsLetterOrDigit(aCharacter)) { ret = SymToken.TClass.EClassAlphaNumeric; } // return(ret); }
public bool CheckTokensAreOfEitherClass(SymToken.TClass aClass1, SymToken.TClass aClass2, int aStartIndex) { bool tokensAreAllTheSameClass = true; // int count = Count; for (int i = aStartIndex; i < count; i++) { SymToken token = this[i]; // if (!(token.Class == aClass1 || token.Class == aClass2)) { tokensAreAllTheSameClass = false; break; } } // return(tokensAreAllTheSameClass); }
public virtual int CountTokenByType(SymToken.TClass aClass) { int count = 0; // foreach (SymNode n in this) { if (n is SymNodeToken) { SymToken t = ((SymNodeToken)n).Token; // if (t.Class == aClass) { ++count; } } } // return(count); }
public bool CheckTokensAreOfEitherClass(SymToken.TClass aClass1, SymToken.TClass aClass2) { bool tokensAreAllTheSameClass = CheckTokensAreOfEitherClass(aClass1, aClass2, 0); return(tokensAreAllTheSameClass); }
public bool CheckTokensAreOfClass(SymToken.TClass aClass) { bool tokensAreAllTheSameClass = CheckTokensAreOfClass(aClass, 0); return(tokensAreAllTheSameClass); }
public SymParserWorkerConsumer(SymParserWorkerContext aContext, SymToken.TClass aTerminatingClassType, TDyingAction aDyingAction) : base(aContext) { iTerminatingClassType = aTerminatingClassType; iDyingAction = aDyingAction; }
public SymParserWorkerConsumer(SymParserWorkerContext aContext, SymToken.TClass aTerminatingClassType) : this(aContext, aTerminatingClassType, TDyingAction.EWhenDyingTakeNoAction) { }
private void ProcessTokenDuringNormalOperations( SymToken aToken ) { // By default we will just add the input token to the // pending queue (i.e. no combining/grouping) TGroupingAction action = TGroupingAction.ETokenEnqueue; // if ( iCache.Count == 0 ) { #region The cache is empty - enqueue the token. // Starting a new token batch, so just push the token. If // its a quotation, then it will be handled during // the enqueuing. Pragma symbols must appear as the first // item on a line, and will be picked up similarly to quotes. if ( aToken.Class == SymToken.TClass.EClassNewLine ) { // If we're adding a new blank line as the first // token, we just want to flush it out immediately. EnqueueNewOutputToken( aToken ); action = TGroupingAction.ETokenFlushQueue; } else { action = TGroupingAction.ETokenEnqueue; } #endregion } else { #region The cache already has some tokens... SymToken previousToken = PreviousOutputToken; SymToken.TClass previousTokenClass = previousToken.Class; // if ( aToken.Class == SymToken.TClass.EClassNewLine ) { #region New line detected... // Checking for continuations... if ( previousToken.Class == SymToken.TClass.EClassSymbol && previousToken.Value == @"\" ) { // Because of the continuation character, we don't // flush the cache. // Discard new line previousToken.Class = SymToken.TClass.EClassContinuation; action = TGroupingAction.ETokenIgnore; } else { // We never allow new lines to be combined. In fact, // they are the signal that we should flush whatever we have // cached so far. We must add the new line token // first though. EnqueueNewOutputToken( aToken ); action = TGroupingAction.ETokenFlushQueue; } #endregion } else if ( previousTokenClass == aToken.Class ) { #region Tokens are the same class - check for combining // We group almost all tokens, but some are not permitted // to be combined, for example, brackets. bool combiningAllowed = previousToken.CombiningAllowed; if ( combiningAllowed && aToken.CombiningAllowed ) { // Merge the two tokens action = TGroupingAction.ETokenMerge; } else { // Treat it as a separate token. action = TGroupingAction.ETokenEnqueue; } #endregion } else { #region Handling some other type of token... if ( previousTokenClass == SymToken.TClass.EClassSymbol && previousToken.Value == @"\" ) { // If the last token was a single escaped character, and this next // character is not an asterisk or another back slash, then // we can try to combine the two. if ( !(aToken.Value == "*" || aToken.Value == @"\" ) ) { action = TGroupingAction.ETokenMerge; } else { System.Diagnostics.Debug.Assert( false ); } } else { action = TGroupingAction.ETokenEnqueue; } #endregion } #endregion } #region Now perform the action switch( action ) { case TGroupingAction.ETokenEnqueue: EnqueueNewOutputToken( aToken ); break; case TGroupingAction.ETokenMerge: MergeWithPreviousToken( aToken ); break; case TGroupingAction.ETokenFlushQueue: FlushCache(); break; default: case TGroupingAction.ETokenIgnore: break; } #endregion }
private void AddToWord(char aCharacter, SymToken.TClass aClassType) { iCurrentClass = aClassType; iCurrentWord.Append(aCharacter); }