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); } }
private void ExtractFromLine(IBraceStacker 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; } MatchBrace(pairs, cp); } this.LastParsedPosition = line.End; }
private void ExtractBraces(IBraceStacker pairs, int startOffset, int endOffset, int state) { braceScanner.Reset(state); int lineNum = Snapshot.GetLineNumberFromPosition(startOffset); while (lineNum < Snapshot.LineCount) { var line = Snapshot.GetLineFromLineNumber(lineNum++); var lineOffset = startOffset > 0 ? startOffset - line.Start : 0; if (line.Length != 0) { ExtractFromLine(pairs, line, lineOffset); } startOffset = 0; this.LastParsedPosition = line.End; if (line.End >= endOffset) { break; } } }
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); } }
private void ExtractFromLine(IBraceStacker 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; MatchBrace(pairs, cp); } this.LastParsedPosition = line.End; }
private void ExtractBraces(IBraceStacker pairs, int startOffset, int endOffset, int state) { braceScanner.Reset(state); int lineNum = Snapshot.GetLineNumberFromPosition(startOffset); while ( lineNum < Snapshot.LineCount ) { var line = Snapshot.GetLineFromLineNumber(lineNum++); var lineOffset = startOffset > 0 ? startOffset - line.Start : 0; if ( line.Length != 0 ) { ExtractFromLine(pairs, line, lineOffset); } startOffset = 0; this.LastParsedPosition = line.End; if ( line.End >= endOffset ) break; } }