public PegNode(PegNode parent, int id, PegMatch match, PegNode child, PegNode next) { Parent = parent; Id = id; Child = child; Next = next; Match = match; }
private void RestoreTree(PegNode prevCur, PegTree.AddPolicy prevPolicy) { if(_mute) { return; } if(prevCur == null) { Tree.Root = null; } else if(prevPolicy == PegTree.AddPolicy.AddAsChild) { prevCur.Child = null; } else { prevCur.Next = null; } Tree.Cur = prevCur; Tree.Policy = prevPolicy; }
private PegNode CreateNode(CreatorPhase phase, PegNode node, int id) { if(phase == CreatorPhase.Create || phase == CreatorPhase.CreateAndComplete) { return new PegNode(node, id); } else { return null; } }
private void PrintNode(PegNode node, int level, string source) { string tab = ""; for (int i = 0; i < level; ++i) tab += ' '; if (node.Id >= 7 && node.Id <= 10 || node.Id == 2) Console.WriteLine("{0}{1} -> {2}", tab, (ConfigTableEnum)node.Id, node.Match.GetString(source)); else Console.WriteLine("{0}{1}", tab, (ConfigTableEnum)node.Id); if (node.Child != null) PrintNode(node.Child, level + 1, source); if (node.Next != null) PrintNode(node.Next, level, source); }
private object GetObjectValue(PegNode node) { PegNode n = node; List<string> keys = new List<string>(); while(n != null && n.Child != null) { keys.Add(n.Child.Match.GetString(_source)); n = n.Next; } return keys.ToArray(); }
private object GetFlatValue(PegNode node) { if((ConfigTableEnum)node.Id == ConfigTableEnum.String) //string { return node.Match.GetString(_source); } if ((ConfigTableEnum)node.Id == ConfigTableEnum.Bool) { string tmp = node.Match.GetString(_source); if(tmp.Equals("true")) return true; return false; } if ((ConfigTableEnum)node.Id == ConfigTableEnum.Decimal) //long { string tmp = node.Match.GetString(_source); long value = 0; if (Int64.TryParse(tmp, out value)) { return value; } else { throw new Exception("Failed to parse long value."); } } if ((ConfigTableEnum)node.Id == ConfigTableEnum.Number) //double { string tmp = node.Match.GetString(_source); double value = 0; if (Double.TryParse(tmp, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out value)) { return value; } else { throw new Exception("Failed to parse double value."); } } throw new Exception("No valid value type found."); }
private PegNode GetChild(PegNode node, string key) { if (node == null) return null; PegNode k = node.Child; PegNode v = node.Child.Next; if (k.Match.GetString(_source).Equals(key)) { return v; } return null; }
private object GetArrayValue(PegNode node) { PegNode n = node; List<object> objs = new List<object>(); while(n != null) { objs.Add(GetFlatValue(n.Child)); n = n.Next; } return objs.ToArray(); }
private PegNode FindKey(PegNode node, string key) { PegNode n = node; while(n != null) { PegNode child = GetChild(n, key); if(child != null) { return child; } n = n.Next; } return null; }
public PegNode(PegNode parent, int id) : this(parent, id, new PegMatch(), null, null) { }
public PegNode(PegNode parent, int id, PegMatch match) : this(parent, id, match, null, null) { }
public PegNode(PegNode parent, int id, PegMatch match, PegNode child) : this(parent, id, match, child, null) { }