public ParserResult Parse(ProgressiveList <Token> tokens) { var result = new ParserResult(); var values = new ParserValues(); BeginValues(values); begin: foreach (var p in parsers) { var parser = (MainParser)p.Value; int state = tokens.GetState(); if (parser.Match(tokens)) { parser.Work(tokens, result); result.Include(parser.GetResult()); goto begin; } else { tokens.RestoreState(state); } values.Clear(); } EndValues(); return(result); }
public static ProgressiveList <T> Get(bool andReturn = false, int defSize = 1) { ProgressiveList <T> list; if (pool.Count == 0) { for (int i = 0; i < defSize; i++) { pool.Enqueue(new ProgressiveList <T>(32)); } list = new ProgressiveList <T>(32); } else { list = pool.Dequeue(); } if (andReturn) { pool.Enqueue(list); } list.Clear(); return(list); }
protected void DefWork(ProgressiveList <Token> tokens, ParserResult result) { if (child?.Match(tokens) ?? false) { child?.Work(tokens, result); } }
public ProgressiveList <T> SplitUntil(Predicate <T> predicate, bool includeTruth = true, bool removeSelf = true, int startingIndex = 0) { int count = items.Count; var pl = new ProgressiveList <T>(); for (var i = startingIndex; i < count; i++) { var item = items[i]; bool truth = predicate(item); if (!truth || truth && includeTruth) { pl.Add(item); } if (truth) { break; } } if (removeSelf) { items.RemoveAll(i => pl.items.Contains(i)); } return(pl); }
public override void Work(ProgressiveList <Token> tokens, ParserResult result) { if (Child.Match(tokens)) { Child.Work(tokens, result); } else { tokens.This().Or(tokens.Look_Back()).Error(); } }
public override void Work(ProgressiveList <Token> tokens, ParserResult result) { if (Conditional.Match(tokens)) { var work = onWork(); if (work != null) { if (work.Match(tokens)) { work.Work(tokens, result); } } } Child?.Work(tokens, result); }
public bool VerifyNexts(ProgressiveList <T> nexts) { T def = default(T); bool ret = true; int state = GetState(); T item; while (!Equals(item = nexts.Next(), def)) { var nitem = nexts.Next(); if (Equals(nitem, def) || !Equals(item, nitem)) { ret = false; break; } } RestoreState(state); return(ret); }
public override bool Match(ProgressiveList <Token> tokens) { Token token; bool result; switch (condType) { case TokenConditional.Text: return(tokens.Next().text == text); case TokenConditional.Type: token = tokens.Next(); result = token.Type() == type; if (result && storeOn != null) { Set(storeOn, token.value); } return(result); case TokenConditional.Value: token = tokens.Next(); result = Tokenizer.isValue(token.Type()); if (result && storeOn != null) { Set(storeOn, token.value); } return(result); case TokenConditional.Any: token = tokens.Next(); result = true; if (storeOn != null) { Set(storeOn, token.value); } return(result); } return(false); }
public bool VerifyNexts(ProgressiveList <Token> nexts) { return(tokens.VerifyNexts(nexts)); }
public bool VerifyNexts(ProgressiveList <string> nexts, bool dontWorryAboutOrder = false, Func <Token, Tokens, bool> checker = null) { bool ret = true; int state = GetState(); bool begun = true; if (dontWorryAboutOrder) { begun = false; } Token token; while ((token = tokens.Next()) != null) { var ntoken = nexts.Next(); if (ntoken == null) { if (!begun) { return(false); } return(ret); } if (token.text != ntoken) { if (!begun) { nexts.Back(); continue; } ret = false; break; } else { if (!begun) { if (checker == null) { begun = true; } else if (checker != null) { int prev = GetState(); if (!checker(token, this)) { nexts.Back(); } else { begun = true; return(true); } RestoreState(prev); } } } } RestoreState(state); if (!begun) { ret = false; } return(ret); }
public Tokens(List <Token> tokens) { this.tokens = new ProgressiveList <Token>(tokens); }
public Tokens(ProgressiveList <Token> tokens) { this.tokens = tokens; }
public static void Return(ProgressiveList <T> list) { list.Clear(); pool.Enqueue(list); }
public static void Return <T>(this ProgressiveList <T> array) => ProgressiveLists <T> .Return(array);
public override bool Match(ProgressiveList <Token> tokens) { return(true); }
public override bool Match(ProgressiveList <Token> tokens) { return(Conditional.Match(tokens)); }
public virtual bool Match(ProgressiveList <Token> tokens) { return(false); }
public override void Work(ProgressiveList <Token> tokens, ParserResult result) { DefWork(tokens, result); }
public virtual void Work(ProgressiveList <Token> tokens, ParserResult result) { }