public static bool ParseOutputLine(Dictionary<Symbol, NodeDefinition> mdf, ref NodeDefinition module, String line, int lineNumber) { Debug.Assert(mdf != null); Debug.Assert(module != null); Debug.Assert(line != null); Debug.Assert(lineNumber > 0); Symbol symbol; ParameterDefinition output; List<String> toks = Utils.StringTokenizer(line, ";", new String[] { "" }); if (toks.Count < 3) { ErrorDialog ed = new ErrorDialog(); ed.post("Encountered an erroneous OUTPUT specification on line {0}.", lineNumber); return false; } // Parse the first substring: NAME and optional attributes String iname; int bracketStart = toks[0].IndexOf('['); if (bracketStart >= 0) iname = toks[0].Substring(0, bracketStart); else iname = toks[0]; iname = iname.Trim(); Regex rx = new Regex(@"^([a-zA-Z_][0-9a-zA-Z_]*)$"); Match m = rx.Match(iname); if (!m.Success) { ErrorDialog ed = new ErrorDialog(); ed.post("Invalid output name: {0} line {1}", iname, lineNumber); return false; } symbol = SymbolManager.theSymbolManager.registerSymbol(iname); output = new ParameterDefinition(symbol); output.markAsOutput(); output.setDefaultVisibility(); if (toks[0].Contains("[")) { int begin_att = toks[0].IndexOf('['); int end_att = toks[0].Substring(begin_att).IndexOf(']'); String atts = null; if (end_att > 0) atts = toks[0].Substring(begin_att, end_att); if (atts != null) if (!ParseParameterAttributes(ref output, atts)) { ErrorDialog ed = new ErrorDialog(); ed.post("Unrecognized input attribute(s) ({0}) in MDF line {1}", atts, lineNumber); return false; } } // Parse the second substring: TYPE. if (!ParseMDFTypes(ref output, toks[1], lineNumber)) return false; // Parse the third substring: DESCRIPTION output.setDescription(toks[2]); module.addOutput(output); return true; }
public static bool ParseParameterAttributes(ref ParameterDefinition pd, String attr) { int val = 0; bool v; if (GetIntegerAttribute(attr, "private", ref val)) { v = (val == 1 ? false : true); pd.setViewability(v); if (v) pd.setDefaultVisibility(false); } else if (GetIntegerAttribute(attr, "hidden", ref val)) { v = (val == 1 ? false : true); pd.setDefaultVisibility(v); } if (GetIntegerAttribute(attr, "visible", ref val)) { bool visible = false, viewable = false; if (val == 0) { viewable = true; visible = false; } else if (val == 1) { viewable = true; visible = true; } else if (val == 2) { viewable = false; visible = false; } pd.setViewability(viewable); pd.setDefaultVisibility(visible); } if (GetIntegerAttribute(attr, "cache", ref val)) pd.setDefaultCacheability((Cacheability)val); if (pd.IsInput && GetIntegerAttribute(attr, "reroute", ref val) && (val >= 0)) pd.setRerouteOutput(val + 1); return true; }
public static bool ParseInputLine(Dictionary<Symbol, NodeDefinition> mdf, ref NodeDefinition module, String line, int lineNumber) { Debug.Assert(mdf != null); Debug.Assert(module != null); Debug.Assert(line != null); Debug.Assert(lineNumber > 0); ParameterDefinition input = null; Symbol symbol; List<String> toks = Utils.StringTokenizer(line, ";", new String[] { "" }); if (toks.Count < 3) { ErrorDialog ed = new ErrorDialog(); ed.post("Encountered an erroneous INPUT specification on line {0}.", lineNumber); return false; } // Parse the first substring: NAME and optional attributes String iname; int bracketStart = toks[0].IndexOf('['); if (bracketStart >= 0) iname = toks[0].Substring(0, bracketStart); else iname = toks[0]; iname = iname.Trim(); Regex rx = new Regex(@"^([a-zA-Z_]\w*)$"); Match m = rx.Match(iname); if (!m.Success) { ErrorDialog ed = new ErrorDialog(); ed.post("Invalid input name: {0} line {1}", iname, lineNumber); return false; } symbol = SymbolManager.theSymbolManager.registerSymbol(iname); input = new ParameterDefinition(symbol); input.markAsInput(); input.setDefaultVisibility(); if (toks[0].Contains("[")) { int begin_att = toks[0].IndexOf('['); int end_att = toks[0].Substring(begin_att).IndexOf(']'); String atts = null; if (end_att > 0) atts = toks[0].Substring(begin_att, end_att); if (atts != null) if (!ParseParameterAttributes(ref input, atts)) { ErrorDialog ed = new ErrorDialog(); ed.post("Unrecognized input attribute(s) ({0}) in MDF line {1}", atts, lineNumber); return false; } } // Parse the second substring: TYPE. if (!ParseMDFTypes(ref input, toks[1], lineNumber)) return false; // Parse the third substring: DEFAULT VALUE. // If the value is equal to "(none)", then mark this parameter // as a required parameter. toks[2] = toks[2].Trim(); if (toks[2].StartsWith("(")) { // A descriptive value if (toks[2] == "(none)") input.setRequired(); else input.setNotRequired(); input.setDescriptiveValue(toks[2]); } else if (!input.setDefaultValue(toks[2])) { ErrorDialog ed = new ErrorDialog(); ed.post("Default value given on line {0} not one of given types.", lineNumber); return false; } // Add the fourth substring: DESCRIPTION // Description can be blank if (toks.Count == 3) input.setDescription(""); else input.setDescription(toks[3]); module.addInput(input); return true; }