/// <summary> /// Creates a unit and adds it to this physical type. /// </summary> /// <param name="identifier">the unit's identifier</param> /// <param name="factor">the factor</param> /// <param name="baseUnit">the base unit</param> /// <returns>the created unit</returns> public virtual Unit createUnit(string identifier, AbstractLiteral factor, string baseUnit) { Int64 baseUnits = GetBaseUnits(baseUnit); Int64 int_factor = (factor as VHDL.literal.IntegerLiteral).IntegerValue; Unit unit = new Unit(identifier, int_factor, baseUnits * int_factor, baseUnit); units.Add(unit); return(unit); }
private bool ConstructQuery(Term parent, int depth, string txt, bool negated) { if (txt == null || txt.Length == 0) { return(true); } string indent = String.Format("{0," + depth * 2 + "}", " "); //Console.WriteLine (indent + "Have text: {0}", txt); // Match the query the user typed against our regular expression Match match = term_regex.Match(txt); if (!match.Success) { //Console.WriteLine (indent + "Failed to match."); return(false); } bool op_valid = true; string op = String.Empty; // For the moment at least we don't support operator precedence, so we require // that only a single operator is used for any given term unless it is made unambiguous // by using parenthesis. foreach (Capture capture in match.Groups["Ops"].Captures) { if (op == String.Empty) { op = capture.Value; } else if (op != capture.Value) { op_valid = false; break; } } if (!op_valid) { Console.WriteLine(indent + "Ambiguous operator sequence. Use parenthesis to explicitly define evaluation order."); return(false); } if (match.Groups ["Terms"].Captures.Count == 1 && match.Groups["NotTerm"].Captures.Count != 1) { //Console.WriteLine (indent + "Unbreakable term: {0}", match.Groups ["Terms"].Captures [0]); string literal; bool is_negated = false; Tag tag = null; if (match.Groups ["NotTag"].Captures.Count == 1) { literal = match.Groups ["NotTag"].Captures [0].Value; is_negated = true; } else { literal = match.Groups ["Terms"].Captures [0].Value; } is_negated = is_negated || negated; tag = MainWindow.Toplevel.Database.Tags.GetTagByName(literal); // New OR term so we can match against both tag and text search parent = new OrTerm(parent, null); // If the literal is the name of a tag, include it in the OR AbstractLiteral term = null; if (tag != null) { new Literal(parent, tag, null); } // Always include the literal text in the search (path, comment, etc) new TextLiteral(parent, literal); // If the term was negated, negate the OR parent term if (is_negated) { parent = parent.Invert(true); } if (RootTerm == null) { root_term = parent; } return(true); } else { Term us = null; if (op != null && op != String.Empty) { us = Term.TermFromOperator(op, parent, null); if (RootTerm == null) { root_term = us; } } foreach (Capture capture in match.Groups["Term"].Captures) { string subterm = capture.Value.Trim(); if (subterm == null || subterm.Length == 0) { continue; } // Strip leading/trailing parens if (subterm [0] == '(' && subterm [subterm.Length - 1] == ')') { subterm = subterm.Remove(subterm.Length - 1, 1); subterm = subterm.Remove(0, 1); } //Console.WriteLine (indent + "Breaking subterm apart: {0}", subterm); if (!ConstructQuery(us, depth + 1, subterm, negated)) { return(false); } } foreach (Capture capture in match.Groups["NotTerm"].Captures) { string subterm = capture.Value.Trim(); if (subterm == null || subterm.Length == 0) { continue; } // Strip leading/trailing parens if (subterm [0] == '(' && subterm [subterm.Length - 1] == ')') { subterm = subterm.Remove(subterm.Length - 1, 1); subterm = subterm.Remove(0, 1); } //Console.WriteLine (indent + "Breaking not subterm apart: {0}", subterm); if (!ConstructQuery(us, depth + 1, subterm, true)) { return(false); } } if (negated && us != null) { if (us == RootTerm) { root_term = us.Invert(false); } else { us.Invert(false); } } return(true); } }
/// <summary> /// Creates a physical literal. /// </summary> /// <param name="value">the value</param> /// <param name="unit">the unit</param> public PhysicalLiteral(AbstractLiteral @value, string unit, PhysicalType type) { this.value = @value; this.unit = unit; this.parent = type; }