public static RCArray <string> MultipartName(string text, char delimeter) { int partStart = 0; RCArray <string> result = new RCArray <string> (4); for (int i = 0; i < text.Length; ++i) { if (i == text.Length - 1) { string partString = text.Substring(partStart); RCName part = GetName(partString); partStart += partString.Length; // Consume the delimeter ++partStart; result.Write(part.Text); } else if (text[i] == delimeter) { string partString = text.Substring(partStart, i - partStart); RCName part = GetName(partString); partStart += partString.Length; // Consume the delimeter ++partStart; result.Write(part.Text); } else if (text[i] == '\'') { int matchingQuote = text.IndexOf('\'', i + 1); if (matchingQuote < 0) { throw new Exception("Unmatched single quote in name: " + text); } else { while (matchingQuote > 0 && text[matchingQuote - 1] == '\\') { matchingQuote = text.IndexOf('\'', matchingQuote + 1); } if (matchingQuote <= 0 || text[matchingQuote] != '\'') { throw new Exception("Unmatched single quote among escaped single quotes in name: " + text); } string partString = text.Substring(partStart, 1 + (matchingQuote - partStart)); RCName part = GetName(partString); partStart += partString.Length; result.Write(part.Text); i = matchingQuote; } } } return(result); }
static RCName() { RCName empty = new RCName("", 0, false); _names.Add("", empty); _index.Write(empty); RCName trueLiteral = new RCName("'true'", 1, true); _names.Add("true", trueLiteral); _index.Write(trueLiteral); RCName falseLiteral = new RCName("'false'", 2, true); _names.Add("false", falseLiteral); _index.Write(falseLiteral); }
public RCBlock(RCBlock previous, string name, RCEvaluator evaluator, RCValue val) { if (val == null) { throw new ArgumentNullException("value"); } Previous = previous != null ? previous : Empty; RCName nameInfo = RCName.GetName(name); Name = nameInfo.Text; EscapeName = nameInfo.Escaped; Evaluator = evaluator; Value = val; _count = Previous.Count + 1; }
public RCBlock GetName(string name) { name = RCName.Get(name); RCBlock current = this; while (current != null && current.Count > 0) { // The empty block has a null name. // This may not be for the best. if (current.Name != null && current.Name.Equals(name)) { return(current); } current = current.Previous; } return(null); }
public void EvalAssert(RCRunner runner, RCClosure closure, RCBoolean right) { for (int i = 0; i < right.Count; ++i) { if (!right[i]) { RCCube target = new RCCube(new RCArray <string> ("S")); Stack <object> names = new Stack <object> (); RCBlock block = new RCBlock("", ":", closure.Code); block.Cubify(target, names); ColumnBase column = target.GetColumn("r"); string expression; if (column != null) { RCArray <string> refNames = (RCArray <string>)column.Array; // Only display the variables whose values are referenced in the assert // expression RCBlock displayVars = RCBlock.Empty; for (int j = 0; j < refNames.Count; ++j) { RCArray <string> nameParts = RCName.MultipartName(refNames[j], '.'); RCValue val = Eval.Resolve(null, closure, nameParts, null, returnNull: true); if (val != null) { displayVars = new RCBlock(displayVars, refNames[j], ":", val); } } expression = string.Format("{0}, {1}", closure.Code.ToString(), displayVars); } else { expression = string.Format("{0}", closure.Code.ToString()); } throw new RCException(closure, RCErrors.Assert, "Failed: " + expression); } } runner.Yield(closure, new RCBoolean(true)); }
public static RCName GetName(string text) { if (text == null) { text = ""; } string name = null; bool escaped = false; RCName result; lock (_lock) { if (!_names.TryGetValue(text, out result)) { if (text[0] == '\'') { if (text.Length == 1 || text[text.Length - 1] != '\'') { throw new Exception("Unmatched single quote in name: " + text); } // Remove quotes if not necessary // They are necessary when the name begins with a number if (text.Length > 1 && text[1] >= '0' && text[1] <= '9') { name = text; escaped = true; } for (int i = 1; i < text.Length - 1; ++i) { if (!RCTokenType.IsIdentifierChar(text[i])) { name = text; escaped = true; break; } } if (name == null) { name = text.Substring(1, text.Length - 2); } } else if (text[0] >= '0' && text[0] <= '9') { name = "'" + text + "'"; escaped = true; } else { for (int i = 0; i < text.Length; ++i) { // add quotes if necessary if (!RCTokenType.IsIdentifierChar(text[i])) { name = "'" + text + "'"; escaped = true; break; } } if (name == null) { name = text; } } if (_names.TryGetValue(name, out result)) { // this makes it a synonym for next time _names.Add(text, result); return(result); } else { result = new RCName(name, _names.Count, escaped); _names.Add(result.Text, result); _index.Write(result); return(result); } } else { return(result); } } }
public RCReference(string name) { Name = name; Parts = RCName.MultipartName(name, '.'); Parts.Lock(); }