public BracePos Push(CharPos brace) { var pairs = stack[brace.Char]; var bp = brace.AsBrace(pairs.Count); pairs.Push(bp); return bp; }
private void MatchBrace(IBraceStacker pairs, CharPos cp) { if (IsOpeningBrace(cp)) { Add(pairs.Push(cp)); } else if (pairs.Count(cp.Char) > 0) { // check if this is a closing brace matching // the opening on the stack BracePos p = pairs.Peek(cp.Char); if (braceList[p.Brace] == cp.Char) { // it does, add it pairs.Pop(cp.Char); Add(cp.AsBrace(p.Depth)); } else { // it doesn't; it's an error this.braceErrors.Add(cp); } } else { // closing brace has no opening brace this.braceErrors.Add(cp); } }
public BracePos Push(CharPos brace) { var bp = brace.AsBrace(pairs.Count); pairs.Push(bp); return(bp); }
private void ExtractFromLine(Stack <BracePos> pairs, ITextSnapshotLine line, int lineOffset) { var lc = new LineChars(line, lineOffset); CharPos cp = CharPos.Empty; while (!lc.EndOfLine) { if (!this.braceScanner.Extract(lc, ref cp)) { continue; } if (IsOpeningBrace(cp)) { BracePos p = cp.AsBrace(pairs.Count); pairs.Push(p); Add(p); // we don't need to check if it's a closing brace // because the extractor won't return anything else } else if (pairs.Count > 0) { BracePos p = pairs.Peek(); if (braceList[p.Brace] == cp.Char) { // yield closing brace pairs.Pop(); BracePos c = cp.AsBrace(p.Depth); Add(c); } else { // closing brace does not correspond // to opening brace at same depth this.braceErrors.Add(cp); } } else { // closing brace has no opening brace this.braceErrors.Add(cp); } } this.LastParsedPosition = line.End; }