using System.Collections.Generic; namespace TLang.Lexer { public class LexContext { public static LexContext operator+(LexContext left,LexContext right) { List tokens=new List(); tokens.AddRange(left.Tokens); tokens.AddRange(right.Tokens); LexContext ctx=new LexContext(tokens); ctx.Offset = left.Offset; return ctx; } public LexContext(IReadOnlyList tokens) { Tokens = tokens; } public IReadOnlyList Tokens {get;} public int Offset {get;set;} = 0; public LexContext FromOffset(int offset) { return new LexContext(Tokens){Offset = offset}; } public LexContext FromOffset() { return FromOffset(Offset); } public LexToken Next(int i = 0) { if(Offset + i < Tokens.Count) return Tokens[Offset + i]; return new LexToken(); } public void Add(int i=1) { Offset++; } public LexEntryContext NextEntriesNoSpaces(bool consumeIfTrue,params string[] tokenText) { List tokens = new List(); int offset = Offset; if(Offset + tokenText.Length >= Tokens.Count) return new LexEntryContext(tokens,offset,false); for(int i = 0; i tokens = new List(); int offset = Offset; if(Offset + tokenText.Length >= Tokens.Count) return new LexEntryContext(tokens,offset,false); for(int i = 0; i= Tokens.Count) return false; foreach(var item in tokenText) { if(Tokens[Offset].IsDocumentation || Tokens[Offset].IsChar || Tokens[Offset].IsString || Tokens[Offset].Text == item) { token = Tokens[Offset]; if(consumeIfTrue) Offset++; return true; } } return false; } public LexToken NextEntry { get { if(Offset < Tokens.Count) { return Tokens[Offset++]; } return LexToken.Empty; } } public LexToken PeekEntry { get { if(Offset < Tokens.Count) { return Tokens[Offset]; } return LexToken.Empty; } } public LexLineInfo CurrentLineInfo => PeekEntry.Position; public bool MoreTokens => Offset < Tokens.Count; public string PopDocumentation() { if(Offset >= Tokens.Count || !Tokens[Offset].IsDocumentation) return ""; return Tokens[Offset++].Text; } public LexEntryContext NextEntries(bool consumeIfTrue,params LexToken[] tokens) { List _tokens = new List(); int offset = Offset; if(Offset + tokens.Length >= Tokens.Count) return new LexEntryContext(_tokens,offset,false); for(int i = 0; i