/// <summary> /// Returns `true` if no line terminator exists after any encountered /// parameters beyond the specified token offset and the next on the /// `HIDDEN` channel. /// </summary> protected bool noTerminatorAfterParams(int tokenOffset) { BufferedTokenStream stream = (BufferedTokenStream)_input; int leftParams = 1; int rightParams = 0; if (stream.Lt(tokenOffset).Type == L_PAREN) { // Scan past parameters while (leftParams != rightParams) { tokenOffset++; int tokenType = stream.Lt(tokenOffset).Type; if (tokenType == L_PAREN) { leftParams++; } else if (tokenType == R_PAREN) { rightParams++; } } tokenOffset++; return(noTerminatorBetween(tokenOffset)); } return(true); }
/// <summary> /// Returns `true` if no line terminator exists between the specified /// token offset and the prior one on the `HIDDEN` channel. /// </summary> protected bool noTerminatorBetween(int tokenOffset) { BufferedTokenStream stream = (BufferedTokenStream)_input; IList <IToken> tokens = stream.GetHiddenTokensToLeft(stream.Lt(tokenOffset).TokenIndex); if (tokens == null) { return(true); } foreach (IToken token in tokens) { if (token.Text.Contains("\n")) { return(false); } } return(true); }
internal TNode ParseWithStackGuard <TNode>(Func <TNode> parseFunc, Func <TNode> createEmptyNodeFunc) where TNode : CSharpSyntaxNode { // If this value is non-zero then we are nesting calls to ParseWithStackGuard which should not be // happening. It's not a bug but it's inefficient and should be changed. //Debug.Assert(_recursionDepth == 0); #if DEBUG return(parseFunc()); #else try { return(parseFunc()); } // TODO (DevDiv workitem 966425): Replace exception name test with a type test once the type // is available in the PCL catch (Exception ex) when(ex.GetType().Name == "InsufficientExecutionStackException") { return(CreateForGlobalFailure(_lexerTokenStream?.Lt(1)?.StartIndex ?? 0, createEmptyNodeFunc())); } #endif }