public void Parse(Document doc, System.Xml.XmlNode node) { foreach (System.Xml.XmlNode subnode in node.ChildNodes) { if (subnode.NodeType == System.Xml.XmlNodeType.Element) { object st = doc.Parse(subnode); if (st is IStatement) { if (subnode.Name == "Positive") { m_positive = (IStatement)st; } else if (subnode.Name == "Negative") { m_negative = (IStatement)st; } else { throw Document.ParseException("{0} should be either Positive or Negative", subnode.Name); } } else if (st is ICondition) { m_condition = (ICondition)st; } else { throw Document.ParseException("{0} is not allowed in a conditional statement", subnode.Name); } } } }
public void Parse(Document doc, System.Xml.XmlNode node) { ParseInner(doc, node, typeof(ICondition)); if (m_children.Count != 1) { throw Document.ParseException("Not elements only accept one child condition"); } m_child = (ICondition)m_children[0]; }
string Resolve(Hashtable seen, string val) { Match match; GroupCollection groups; while (val != null) { match = m_re_Substitution.Match(val); if (match.Success == false) { break; } groups = match.Groups; string pre = groups[1].Value; string var = groups[2].Value; string post = groups[3].Value; match = m_re_TwoOperands.Match(var); if (match.Success) { groups = match.Groups; var = ResolveTwoOperands(seen, groups[1].Value, groups[2].Value, groups[3].Value); } else { if (seen.ContainsKey(var)) { throw Document.ParseException("Infinite recursion resolving '{0}'", var); } seen[var] = true; var varName = var; var = Resolve(seen, GetVariable(var)); if (var == null) { throw Document.ParseException("'{0}' is not defined", varName); } seen.Remove(var); } val = pre + var + post; } return(val); }
string ResolveTwoOperands(Hashtable seen, string val1, string op, string val2) { uint i1 = ResolveOperand(seen, val1); uint i2 = ResolveOperand(seen, val2); if (op == "+") { return(String.Format("0x{0:X}", i1 + i2)); } if (op == "-") { return(String.Format("0x{0:X}", i1 - i2)); } throw Document.ParseException("Unknown operation: '{0}'", op); }
protected void ParseInner(Document doc, System.Xml.XmlNode node, Type type) { foreach (System.Xml.XmlNode subnode in node.ChildNodes) { if (subnode is System.Xml.XmlElement) { object o = doc.Parse(subnode); if (type != null && type.IsInstanceOfType(o) == false) { throw Document.ParseException("{0} is not an instance of {1}", subnode.Name, type.FullName); } m_children.Add(o); } } }
internal string ProcessLine(string line) { Match m; line = line.Trim(); if (line.Length == 0) { return(line); } switch (m_state) { case c_Idle: m = m_re_LoadRegion.Match(line); if (m.Success) { m_state = c_LoadRegionPreamble; GroupCollection groups = m.Groups; return(String.Format(" <LoadRegion Name=\"{0}\" Base=\"{1}\" Options=\"{2}\" Size=\"{3}\">", groups[1], groups[2], groups[4], groups[6])); } break; case c_LoadRegionPreamble: if (line == "{") { m_state = c_LoadRegion; return(""); } break; case c_LoadRegion: if (line == "}") { m_state = c_Idle; return(" </LoadRegion>"); } m = m_re_ExecRegion.Match(line); if (m.Success) { m_state = c_ExecRegionPreamble; GroupCollection groups = m.Groups; return(String.Format(" <ExecRegion Name=\"{0}\" Base=\"{1}\" Options=\"{2}\" Size=\"{3}\">", groups[1], groups[2], groups[4], groups[6])); } break; case c_ExecRegionPreamble: if (line == "{") { m_state = c_ExecRegion; return(""); } break; case c_ExecRegion: if (line == "}") { m_state = c_LoadRegion; return(" </ExecRegion>"); } m = m_re_FileMapping.Match(line); if (m.Success) { GroupCollection groups = m.Groups; return(String.Format(" <FileMapping Name=\"{0}\" Options=\"{1}\" />", groups[1], groups[2])); } break; } throw Document.ParseException("Invalid scatter file input: {0}", line); }