static void buildRec(NamedNode n) { foreach (var ch in n.children) { buildRec(ch); } n.build(); }
// first in PathUp that matches condition or null public static NamedNode PathUpTo(this NamedNode arg, Func <NamedNode, bool> condition) { foreach (var n in PathUp(arg)) { if (condition(n)) { return(n); } } return(null); }
public static class NamedNodeUtil { // because i want this in unit tests too public static IEnumerable <NamedNode> Flatten(this IEnumerable <NamedNode> arg) { IEnumerable <NamedNode> res = new NamedNode [0]; foreach (var A in arg) { res = res.Concat(new [] { A }); // topo sort order ( for P1 ancester P2 --> index(P1) < index(P2 ) ) res = res.Concat(A.children.Flatten()); } return(res); }
public static ParserComb.NamedNode ScopeAndType(string src, CH_closedScope scopeIN, MG.PI StartProd, Func <ParserComb.NamedNode, TranslationUnit> TRInstantiate) { ParserComb.NamedNode NN = LexxAndParse_incomplete_tolerant(src, StartProd); // TR constructors do not provide a uniform interface because there is no need for it TranslationUnit TR = TRInstantiate(NN); var deltaScope = new preCH_deltaScope(scopeIN); var combinedScope = TR.scope(deltaScope); return(NN); }
/* * yields all matching alternatives, including those that do not fully consume the input */ public static IEnumerable <parse_match> RUN_with_rest(PI startProd, IEnumerable <Token> toks) { foreach (alt it in startProd.iter(toks)) { TaggedPINodeBase start_ast = ( TaggedPINodeBase )it.n; // todo : potentially throws . atm there is no PI subtype to denote "only PIs that yield tagged nodes" NamedNode NN = start_ast.gen(); buildRec(NN); yield return(new parse_match { N = NN, rest = it.toks }); } }
// A -> [ A , ancester(A) , ancester(ancester(A)) , ... ] ; null -> [] public static IEnumerable <NamedNode> PathUp(this NamedNode arg) { if (arg != null) { yield return(arg); } else { yield break; } while (arg.parent != null) { arg = arg.parent; yield return(arg); } }
public static Compilat TranslateFully(string src, GrammarEntry GE, TranslateLHS eval_LHS) { ParserComb.NamedNode NN = LexxAndParse(src, GE.StartProd); var TR = GE.TR_constructor(NN); var deltaScope = new preCH_deltaScope(eval_LHS.scope); preCH_deltaScope combinedScope = TR.scope(deltaScope); var OPs = TR.emit().ToArray(); var VBoxTrs = TR.VBoxTUs; // basic compile sanity // if ( ! ( VBoxTrs.SelectMany ( vbx => vbx.emit()).Count() == OPs.Length ))throw new Exception(); // figgn! ... im allgemeinen stimmt das gar nicht der OPSuiGen ist in keiner VBoxTU enthalten, so wie das im Moment generiert wird // --- return(new Compilat { deltaScope = (CH_deltaScope)combinedScope.instantiate(), OPs = OPs, src = src, VBoxTrs = VBoxTrs }); }
public static IEnumerable <NamedNode> Leafs(this NamedNode arg) { return(new [] { arg }.Leafs()); }