protected char Peek() { using (LookaheadToken lookahead = Source.BeginLookahead()) { MoveNext(); return(CurrentCharacter); } }
private bool Lookahead(string expected, bool takeIfMatch, bool caseSensitive) { Func <char, char> filter = c => c; if (!caseSensitive) { filter = Char.ToLowerInvariant; } if (expected.Length == 0 || filter(CurrentCharacter) != filter(expected[0])) { return(false); } // Capture the current buffer content in case we have to backtrack string oldBuffer = null; if (takeIfMatch) { Buffer.ToString(); } using (LookaheadToken lookahead = Source.BeginLookahead()) { for (int i = 0; i < expected.Length; i++) { if (filter(CurrentCharacter) != filter(expected[i])) { if (takeIfMatch) { // Clear the buffer and put the old buffer text back Buffer.Clear(); Buffer.Append(oldBuffer); } // Return without accepting lookahead (thus rejecting it) return(false); } if (takeIfMatch) { TakeCurrent(); } else { MoveNext(); } } if (takeIfMatch) { lookahead.Accept(); } } return(true); }
public void After_Accepting_Lookahead_Tokenizer_Returns_Next_Token() { var tokenizer = new HtmlTokenizer(new SeekableTextReader(new StringReader("<foo>"))); using (LookaheadToken lookahead = tokenizer.Source.BeginLookahead()) { Assert.Equal(new HtmlSymbol(0, 0, 0, "<", HtmlSymbolType.OpenAngle), tokenizer.NextSymbol()); Assert.Equal(new HtmlSymbol(1, 0, 1, "foo", HtmlSymbolType.Text), tokenizer.NextSymbol()); lookahead.Accept(); } Assert.Equal(new HtmlSymbol(4, 0, 4, ">", HtmlSymbolType.CloseAngle), tokenizer.NextSymbol()); }
/// <summary> /// consume current token (get next token). </summary> /// <returns> the consumed token (which was the current token when calling this method) </returns> protected internal Scanner.Token ConsumeToken() { Scanner.Token result = token; if (lookahead.Count == 0) { token = scanner.Next(); position = scanner.Position; } else { LookaheadToken next = lookahead[0]; token = next.token; position = next.position; lookahead.RemoveAt(0); } return(result); }
/// <summary> /// consume current token (get next token). </summary> /// <returns> the consumed token (which was the current token when calling this method) </returns> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: protected final org.camunda.bpm.engine.impl.juel.Scanner.Token consumeToken() throws org.camunda.bpm.engine.impl.juel.Scanner.ScanException, ParseException protected internal Token consumeToken() { Token result = token; if (lookahead_Renamed.Count == 0) { token = scanner.next(); position = scanner.Position; } else { LookaheadToken next = lookahead_Renamed.RemoveAt(0); token = next.token; position = next.position; } return(result); }