/// <summary> /// This only really happens with conjunctive operators (ie. +, -, AND, OR..) /// </summary> /// <param name="xoContext.CurrentNode"></param> /// <param name="xoContext.List"></param> public static void HandlePreconsumptionError(ParsingContext xoContext) { // Its good to know whats next SyntaxKind eNextTokenKind = SyntaxKind.UnknownNode; // If we have an arithmatic operator, we know we need the types to match if (SyntaxKindFacts.IsArithmaticOperator(xoContext.CurrentNode.ExpectedType) || SyntaxKindFacts.IsConditionalOperator(xoContext.CurrentNode.ExpectedType)) { // if (SyntaxKindFacts.IsLiteral(xoContext.List.Peek().ExpectedType)) { // Set the return kind eNextTokenKind = xoContext.List.Peek().ExpectedType; } } // Conjunctive or Adjunct will not matter what types we have else if (SyntaxKindFacts.IsAdjunctConditionalOperator(xoContext.CurrentNode.ExpectedType)) { // MUST BE BOOLEAN eNextTokenKind = SyntaxKind.BooleanToken; } // Default to unknown Filler xoContext.CurrentNode.Add( new FillerNode( eNextTokenKind, "Missing (" + SyntaxKindUtilities.GetStringFromKind(eNextTokenKind) + ")")); }
/// <summary> /// This is very unsafe as everything is converted to Upper /// before the conversion (ie. it matches against any case) /// </summary> /// <param name="xoTrivia"></param> /// <returns></returns> private static Boolean ScanTriviaForKeywords( ParsingContext xoContext, SyntaxTrivia xoTrivia, out List <ISyntax> xaoReturnList) { // Initialise the out var xaoReturnList = new List <ISyntax>(); // Exit early if invalid argument passed if (xoTrivia == null) { return(false); } // Break apart the trivia text String[] asTriviaTextTokens = xoTrivia.RawSQLText.Split(); // Start looping through the trivia text for (int iIndex = 0; iIndex < asTriviaTextTokens.Length; iIndex++) { // For each string in the Comment/Trivia String sLoopingVar = asTriviaTextTokens[iIndex]; SyntaxKind ePossibleKind = SyntaxKindUtilities.GetKindFromString(sLoopingVar); // Try and get a kind // If we have a positive match if (ePossibleKind != SyntaxKind.UnknownNode) { // Mayfly SyntaxToken oToken = new SyntaxToken(ePossibleKind, sLoopingVar); // If we can consume this node (it is something we expect) if (xoContext.CurrentNode.CanConsumeNode( new ParsingContext(xoContext.CurrentNode, new SyntaxList(oToken)), false) == CanConsumeResult.Consume) { // Create tokens from everything beyond this Keyword we can use (because they will most likely be // a part of the new keyword) String sRemainingText = String.Join(" ", asTriviaTextTokens.Skip(iIndex)); xoTrivia.RawSQLText = String.Join(" ", asTriviaTextTokens.Take(iIndex)); // Start lexing the rest of the terms SyntaxLexer oLexer = new SyntaxLexer(new SlidingTextWindow(sRemainingText)); // Add the new tokens to our list while (oLexer.HasTokensLeftToProcess()) { xaoReturnList.Add(oLexer.LexNextToken()); } } } } return(xaoReturnList.Count > 0); }
private static Boolean CheckCommentForKeywords(String xsCommentText) { String[] asIndividualTokens = xsCommentText.Split(); for (int iIndex = 0; iIndex < asIndividualTokens.Length; iIndex++) { String sWord = asIndividualTokens[iIndex]; if (SyntaxKindUtilities.ContainsKey(sWord)) { return(true); } } return(false); }
public static Boolean ScanKeywordOrIdentifier(SlidingTextWindow TextWindow, out SyntaxToken xoToken) { // Found some valid identifier if (ScanIdentifier(TextWindow, out xoToken)) { SyntaxKind eNewType = SyntaxKindUtilities.GetKindFromString(xoToken.RawSQLText); //SyntaxKind eNewType = SyntaxKindConverter.ConvertKeywordIntoSyntaxKind(xoToken.RawSQLText); // If it is not a core keyword then presume its an identifier xoToken.ExpectedType = eNewType != SyntaxKind.UnknownNode ? eNewType : SyntaxKind.IdentifierToken; return(true); } // No identifier could be generated return(false); }
/// <summary> /// This only really happens with conjunctive operators (ie. +, -, AND, OR..) /// </summary> /// <param name="xoContext.CurrentNode"></param> /// <param name="xoContext.List"></param> public static void HandleIncompleteNode(ParsingContext xoContext) { // Its good to know whats next SyntaxKind eNextTokenKind = SyntaxKind.UnknownNode; // If we have an arithmatic operator, we know we need the types to match if (SyntaxKindFacts.IsArithmaticOperator(xoContext.CurrentNode.ExpectedType) || SyntaxKindFacts.IsConditionalOperator(xoContext.CurrentNode.ExpectedType)) { // Only when we have children if (xoContext.CurrentNode.Count > 0) { // Set the return kind eNextTokenKind = xoContext.CurrentNode[0].ExpectedType; } } // Boolean else if ( SyntaxKindFacts.IsAdjunctConditionalOperator(xoContext.CurrentNode.ExpectedType) || // Conjunctive or Adjunct must have bool xoContext.CurrentNode.ExpectedType == SyntaxKind.WhereKeyword || // Where must be bool xoContext.CurrentNode.ExpectedType == SyntaxKind.OnKeyword // On must be bool ) { // MUST BE BOOLEAN eNextTokenKind = SyntaxKind.BooleanToken; } // Identifier else if ( xoContext.CurrentNode.ExpectedType == SyntaxKind.FromKeyword // Table Missing ) { // MUST BE Identifier eNextTokenKind = SyntaxKind.IdentifierToken; } // Default to unknown xoContext.CurrentNode.Add( new FillerNode( eNextTokenKind, "Missing (" + SyntaxKindUtilities.GetStringFromKind(eNextTokenKind) + ")")); }