public Lexer(LexerConfig config) { this.blocks = new LexemMatch[] { new LexemMatch (LexemType.BraceBegin, config.BlockBegin), new LexemMatch (LexemType.Pipe, config.BlockContinue), new LexemMatch (LexemType.BraceEnd, config.BlockEnd) }; this.pending = new LexemMatch (LexemType.None, string.Empty); }
private void NextRaw() { ICollection<LexemMatch> branches; StringBuilder buffer; StringBuilder builder; int index; List<LexemMatch> trails; if (this.pending.Type != LexemType.None) { this.current.Reset (this.pending.Type); this.current.Push (this.pending.Content); this.pending = new LexemMatch (LexemType.None, string.Empty); return; } if (this.eof) { this.current.Reset (LexemType.EndOfFile); this.current.Push ("<EOF>"); return; } builder = new StringBuilder (); buffer = new StringBuilder (); while (!this.eof) { branches = this.blocks; index = 0; buffer.Length = 0; do { trails = null; foreach (LexemMatch branch in branches) { if (index < branch.Content.Length && branch.Content[index] == this.last) { if (index + 1 == branch.Content.Length) { if (builder.Length > 0) { this.current.Reset (LexemType.Text); this.current.Push (builder.ToString ()); this.pending = branch; } else { this.current.Reset (branch.Type); this.current.Push (branch.Content); } this.Read (); return; } if (trails == null) trails = new List<LexemMatch> (branches.Count); trails.Add (branch); } } if (this.last != '\\' || this.Read ()) buffer.Append (this.last); branches = trails; ++index; } while (this.Read () && branches != null && branches.Count > 0); builder.Append (buffer.ToString ()); } this.current.Reset (LexemType.Text); this.current.Push (builder.ToString ()); }