static num MapNum(StringTreeNode node) { return(new num() { @string = node.Childs.Where(n => n.Childs.Count == 0).Select(n => n.Fragment.Content).FirstOrDefault(), }); }
static identifier MapIdentifier(StringTreeNode node) { return(new identifier() { @string = node.Childs.Where(n => n.Childs.Count == 0).Select(n => n.Fragment.Content).FirstOrDefault(), }); }
static exprsSeq MapExprsSeq(StringTreeNode node) { return(new exprsSeq() { exprItems = node.Childs.Where(n => n.Rule.Name == "exprItem").Select(n => MapExprItem(n)).ToArray(), }); }
static omitPattern MapOmitPattern(StringTreeNode node) { return(new omitPattern() { @string = node.Childs.Where(n => n.Childs.Count == 0).Select(n => n.Fragment.Content).FirstOrDefault(), }); }
static condition MapCondition(StringTreeNode node) { return(new condition() { _rawTreeNode = node, exprSeq = node.Childs.Where(n => n.Rule.Name == "exprSeq").Select(n => MapExprSeq(n)).FirstOrDefault(), }); }
static errTransition MapErrTransition(StringTreeNode node) { return(new errTransition() { _rawTreeNode = node, @string = node.Childs.Where(n => n.Childs.Count == 0).Select(n => n.Fragment.Content).FirstOrDefault(), }); }
static stateName MapStateName(StringTreeNode node) { return(new stateName() { _rawTreeNode = node, identifier = node.Childs.Where(n => n.Rule.Name == "identifier").Select(n => MapIdentifier(n)).FirstOrDefault(), }); }
static boolOperator MapBoolOperator(StringTreeNode node) { return(new boolOperator() { _rawTreeNode = node, @strings = node.Childs.Where(n => n.Childs.Count == 0).Select(n => n.Fragment.Content).ToArray(), }); }
static group MapGroup(StringTreeNode node) { return(new group() { @strings = node.Childs.Where(n => n.Childs.Count == 0).Select(n => n.Fragment.Content).ToArray(), exprsSeq = node.Childs.Where(n => n.Rule.Name == "exprsSeq").Select(n => MapExprsSeq(n)).FirstOrDefault(), }); }
static quantor MapQuantor(StringTreeNode node) { return(new quantor() { @strings = node.Childs.Where(n => n.Childs.Count == 0).Select(n => n.Fragment.Content).ToArray(), quantorSpec = node.Childs.Where(n => n.Rule.Name == "quantorSpec").Select(n => MapQuantorSpec(n)).FirstOrDefault(), }); }
static altItem MapAltItem(StringTreeNode node) { return(new altItem() { number = node.Childs.Where(n => n.Rule.Name == "number").Select(n => MapNumber(n)).FirstOrDefault(), trivial = node.Childs.Where(n => n.Rule.Name == "trivial").Select(n => MapTrivial(n)).FirstOrDefault(), }); }
static quantorSpec MapQuantorSpec(StringTreeNode node) { return(new quantorSpec() { nums = node.Childs.Where(n => n.Rule.Name == "num").Select(n => MapNum(n)).ToArray(), @strings = node.Childs.Where(n => n.Childs.Count == 0).Select(n => n.Fragment.Content).ToArray(), }); }
static not MapNot(StringTreeNode node) { return(new not() { @string = node.Childs.Where(n => n.Childs.Count == 0).Select(n => n.Fragment.Content).FirstOrDefault(), trivial = node.Childs.Where(n => n.Rule.Name == "trivial").Select(n => MapTrivial(n)).FirstOrDefault(), }); }
static nsName MapNsName(StringTreeNode node) { return(new nsName() { identifiers = node.Childs.Where(n => n.Rule.Name == "identifier").Select(n => MapIdentifier(n)).ToArray(), @strings = node.Childs.Where(n => n.Childs.Count == 0).Select(n => n.Fragment.Content).ToArray(), }); }
public static grammar MapGrammar(StringTreeNode node) { return(new grammar() { header = node.Childs.Where(n => n.Rule.Name == "header").Select(n => MapHeader(n)).FirstOrDefault(), rules = node.Childs.Where(n => n.Rule.Name == "rule").Select(n => MapRule(n)).ToArray(), }); }
static sep MapSep(StringTreeNode node) { return(new sep() { _rawTreeNode = node, @string = node.Childs.Where(n => n.Childs.Count == 0).Select(n => n.Fragment.Content).FirstOrDefault(), }); }
static keyword MapKeyword(StringTreeNode node) { return(new keyword() { _rawTreeNode = node, @strings = node.Childs.Where(n => n.Childs.Count == 0).Select(n => n.Fragment.Content).ToArray(), }); }
static alternatives MapAlternatives(StringTreeNode node) { return(new alternatives() { altItems = node.Childs.Where(n => n.Rule.Name == "altItem").Select(n => MapAltItem(n)).ToArray(), @strings = node.Childs.Where(n => n.Childs.Count == 0).Select(n => n.Fragment.Content).ToArray(), }); }
static number MapNumber(StringTreeNode node) { return(new number() { trivial = node.Childs.Where(n => n.Rule.Name == "trivial").Select(n => MapTrivial(n)).FirstOrDefault(), quantor = node.Childs.Where(n => n.Rule.Name == "quantor").Select(n => MapQuantor(n)).FirstOrDefault(), }); }
static exprSeq MapExprSeq(StringTreeNode node) { return(new exprSeq() { _rawTreeNode = node, exprItems = node.Childs.Where(n => n.Rule.Name == "exprItem").Select(n => MapExprItem(n)).ToArray(), boolOperators = node.Childs.Where(n => n.Rule.Name == "boolOperator").Select(n => MapBoolOperator(n)).ToArray(), }); }
static rule MapRule(StringTreeNode node) { return(new rule() { identifier = node.Childs.Where(n => n.Rule.Name == "identifier").Select(n => MapIdentifier(n)).FirstOrDefault(), @strings = node.Childs.Where(n => n.Childs.Count == 0).Select(n => n.Fragment.Content).ToArray(), exprsSeq = node.Childs.Where(n => n.Rule.Name == "exprsSeq").Select(n => MapExprsSeq(n)).FirstOrDefault(), }); }
static exprItem MapExprItem(StringTreeNode node) { return(new exprItem() { alternatives = node.Childs.Where(n => n.Rule.Name == "alternatives").Select(n => MapAlternatives(n)).FirstOrDefault(), number = node.Childs.Where(n => n.Rule.Name == "number").Select(n => MapNumber(n)).FirstOrDefault(), trivial = node.Childs.Where(n => n.Rule.Name == "trivial").Select(n => MapTrivial(n)).FirstOrDefault(), }); }
static header MapHeader(StringTreeNode node) { return(new header() { @strings = node.Childs.Where(n => n.Childs.Count == 0).Select(n => n.Fragment.Content).ToArray(), nsName = node.Childs.Where(n => n.Rule.Name == "nsName").Select(n => MapNsName(n)).FirstOrDefault(), identifiers = node.Childs.Where(n => n.Rule.Name == "identifier").Select(n => MapIdentifier(n)).ToArray(), }); }
public static automaton MapAutomaton(StringTreeNode node) { return(new automaton() { _rawTreeNode = node, @strings = node.Childs.Where(n => n.Childs.Count == 0).Select(n => n.Fragment.Content).ToArray(), states = node.Childs.Where(n => n.Rule.Name == "state").Select(n => MapState(n)).ToArray(), }); }
static transition MapTransition(StringTreeNode node) { return(new transition() { _rawTreeNode = node, @strings = node.Childs.Where(n => n.Childs.Count == 0).Select(n => n.Fragment.Content).ToArray(), condition = node.Childs.Where(n => n.Rule.Name == "condition").Select(n => MapCondition(n)).FirstOrDefault(), stateName = node.Childs.Where(n => n.Rule.Name == "stateName").Select(n => MapStateName(n)).FirstOrDefault(), }); }
static exprItem MapExprItem(StringTreeNode node) { return(new exprItem() { _rawTreeNode = node, not = node.Childs.Where(n => n.Rule.Name == "not").Select(n => MapNot(n)).FirstOrDefault(), literal = node.Childs.Where(n => n.Rule.Name == "literal").Select(n => MapLiteral(n)).FirstOrDefault(), identifier = node.Childs.Where(n => n.Rule.Name == "identifier").Select(n => MapIdentifier(n)).FirstOrDefault(), exprGroup = node.Childs.Where(n => n.Rule.Name == "exprGroup").Select(n => MapExprGroup(n)).FirstOrDefault(), }); }
static trivial MapTrivial(StringTreeNode node) { return(new trivial() { identifier = node.Childs.Where(n => n.Rule.Name == "identifier").Select(n => MapIdentifier(n)).FirstOrDefault(), regex = node.Childs.Where(n => n.Rule.Name == "regex").Select(n => MapRegex(n)).FirstOrDefault(), chars = node.Childs.Where(n => n.Rule.Name == "chars").Select(n => MapChars(n)).FirstOrDefault(), check = node.Childs.Where(n => n.Rule.Name == "check").Select(n => MapCheck(n)).FirstOrDefault(), not = node.Childs.Where(n => n.Rule.Name == "not").Select(n => MapNot(n)).FirstOrDefault(), group = node.Childs.Where(n => n.Rule.Name == "group").Select(n => MapGroup(n)).FirstOrDefault(), }); }
static state MapState(StringTreeNode node) { return(new state() { _rawTreeNode = node, stateName = node.Childs.Where(n => n.Rule.Name == "stateName").Select(n => MapStateName(n)).FirstOrDefault(), @strings = node.Childs.Where(n => n.Childs.Count == 0).Select(n => n.Fragment.Content).ToArray(), transitions = node.Childs.Where(n => n.Rule.Name == "transition").Select(n => MapTransition(n)).ToArray(), skip = node.Childs.Where(n => n.Rule.Name == "skip").Select(n => MapSkip(n)).FirstOrDefault(), errTransition = node.Childs.Where(n => n.Rule.Name == "errTransition").Select(n => MapErrTransition(n)).FirstOrDefault(), }); }
public string Play(string text) { StringTreeNode node = _wordsDictionary.Find(text); List <StringTreeNode> winningOptions = GetWinningOptions(node); if (winningOptions.Any()) { return(GetRandomOption(text, winningOptions)); } return(GameExtendingLongestOption(text, node)); }
private List <StringTreeNode> GetWinningOptions(StringTreeNode node) { List <StringTreeNode> winningOptions = new List <StringTreeNode>(); foreach (var childNode in node.GetChildren()) { if (childNode.LeadsToASingleWord() && childNode.GetDeepOfChildren() % 2 != 0 && !childNode.IsWord) { winningOptions.Add(childNode); } } return(winningOptions); }