private bool ReadPunctuation(out PunctuationToken token) { token = new PunctuationToken(); int firstChar = this.reader.PeekChar(); if (!this.punctuations.ContainsKey(firstChar)) { return(false); } foreach (var punctuation in this.punctuations[firstChar]) { using (var transaction = new StreamTransaction(this.reader.BaseStream)) { if (punctuation.Value.HasCharacters(this.reader.ReadChars(punctuation.Value.Length))) { token.Value = punctuation.Value; token.SubType = punctuation.SubType; transaction.Commit(); return(true); } } } return(false); }
public bool ExpectPunctuationToken(PunctuationSubType subType, out PunctuationToken token) { token = null; Token t; if (!this.ReadToken(out t)) { this.ScriptError("couldn't read expected token"); return(false); } if (t.Type != TokenType.Punctuation) { this.ScriptError("expected a punctuation, found {0}", t.Value); return(false); } token = t as PunctuationToken; if (subType < 0) { this.ScriptError("BUG: wrong punctuation subtype"); return(false); } if (token.SubType != subType) { // Search the punctuation table for the string representation of the punctuation var punctuation = this.punctuations.Values.SelectMany(a => a.Where(p => p.SubType == subType)).First(); this.ScriptError("expected {0}, found {1}", punctuation.Value, token.Value); return(false); } return(true); }