public string GetValue(Node node) { string res = null; int hash = node.GetHashCode(); if (NodeValues.TryGetValue(hash, out res)) return res; lock (_lockObj) { try { Node v = node.Evaluate(Env); dotless.Core.Parser.Tree.Color clr = v as dotless.Core.Parser.Tree.Color; if (clr != null) res = clr.ToArgb(); else res = v.ToCSS(Env); } catch (Exception ex) { throw new ParsingException(ex.Message, node.Location.FileName, Zone.GetLineNumber(node.Location)); } NodeValues.Add(hash, res); } return res; }
public CartoElement(Combinator combinator, Node value) : base(combinator, value) { string strValue = value.ToString().Trim(); if (string.IsNullOrEmpty(strValue)) { m_type = ElementType.Unknown; if (strValue != null) Value = "\"\""; } else if (strValue[0] == '#') { Value = strValue.Remove(0, 1); m_type = ElementType.Id; } else if (strValue[0] == '.') { Value = strValue.Remove(0, 1); m_type = ElementType.Class; } else if (strValue.Contains('*')) { m_type = ElementType.Wildchar; } }
public CartoDimension(Node value, string unit, NodeLocation index) : base(value.ToCSS(new Env()), unit) { m_index = index; if ("px".Equals(unit)) Unit = unit.Replace("px", string.Empty); }
public CartoRule(string name, Node value, bool variadic) : base(name, value, variadic) { m_parts = name.Split('/'); Name = m_parts.Last().Trim(); m_instance = m_parts.Length >= 2 ? m_parts[m_parts.Length - 2].Trim() : "__default__"; UpdateID(); }
public CartoFilterElement(Node key, Node op, Node value, Combinator combinator, Env env) : base(combinator, value) { m_key = key; m_op = op; m_value = value; m_id = "[" + m_key.ToString() + "]" + m_op.ToString() + m_value.ToCSS(env).ToString(); }
public override Node Execute(Node node, out bool visitDeeper) { Rule rule = node as Rule; if (rule != null) { visitDeeper = false; string ruleName = (rule.Name ?? "").ToLowerInvariant(); foreach (Prefix prefix in PrefixesToProcess) { if (ruleName.StartsWith(prefix.PrefixString)) { if (!prefix.KeepRule) { return null; } if (prefix.RemovePrefix) { rule.Name = rule.Name.Substring(prefix.PrefixString.Length); } if (prefix.Reverse) { if (rule.Name.IndexOf("right", StringComparison.InvariantCultureIgnoreCase) >= 0) { rule.Name = Replace(rule.Name, "right", "left", StringComparison.InvariantCultureIgnoreCase); return rule; } if (rule.Name.IndexOf("left", StringComparison.InvariantCultureIgnoreCase) >= 0) { rule.Name = Replace(rule.Name, "left", "right", StringComparison.InvariantCultureIgnoreCase); return rule; } if (rule.Name.IndexOf("top", StringComparison.InvariantCultureIgnoreCase) >= 0 || rule.Name.IndexOf("bottom", StringComparison.InvariantCultureIgnoreCase) >= 0) { return rule; } ValuesReverserVisitor reverser = new ValuesReverserVisitor(); return reverser.ReverseRule(rule); } else { return rule; } } } } visitDeeper = true; return node; }
protected override Node Eval(Env env, Node[] list, Node[] args) { Guard.ExpectNumArguments(1, args.Length, this, Location); Guard.ExpectNode<Number>(args[0], this, args[0].Location); var index = (int)(args[0] as Number).Value; // Extract function indecies are 1-based return list[index-1]; }
public Node Operate(Operation op, Node other) { var otherField = other as CartoFieldNode; if (otherField == null) { Quoted otherQuoted = other as Quoted; return new Quoted(this.Value + op.Operator + ConvertUtility.QuoteValue(otherQuoted.Value), otherQuoted.Escaped); } else { return new CartoFieldNode(this.Value + otherField.Value); } }
private static string ToExpressionValue(Node value, CartoReaderContext cntx) { string result = null; Number num = value as Number; if (num != null) result = num.Value.ToString(); else { Quoted quoted = value as Quoted; if (quoted != null) result = QuoteValue(quoted.Value.ToString()); else result = cntx.GetValue(value); } return result; }
private static string ToExpressionValue(Node value) { string result = null; Number num = value as Number; if (num != null) result = num.Value.ToString(); else { Quoted quoted = value as Quoted; if (quoted != null) result = QuoteValue(quoted.Value.ToString()); else result = value.ToString(); } return result; }
private static string ToExpressionOperator(Node op) { string strOp = op.ToString(); switch (strOp) { case "=": return "="; case "!=": return "!="; case ">=": return ">="; case "<=": return "<="; case ">": return ">"; case "<": return "<"; default: return strOp; } }
public Node Operate(Operation op, Node other) { Quoted otherQuoted = other as Quoted; if (otherQuoted != null) { return new Quoted(ConvertUtility.QuoteValue(this.Value) + op.Operator + ConvertUtility.QuoteValue(otherQuoted.Value), this.Escaped); } else { CartoFieldNode fieldNode = other as CartoFieldNode; if (fieldNode != null) { return new Quoted(ConvertUtility.QuoteValue(this.Value) + op.Operator + fieldNode.Value, this.Escaped); } else { throw new Exception(); } } }
public Alpha Alpha(Node value, NodeLocation location) { return new Alpha(value) { Location = location }; }
public Element Element(Combinator combinator, Node value, NodeLocation location) { return new CartoElement(combinator, value) { Location = location }; }
public dotless.Core.Parser.Tree.Rule Rule(string name, Node value, bool variadic, NodeLocation location) { return new CartoRule(name, value, variadic) { Location = location }; }
public Node Attribute(Node key, Node op, Node val, NodeLocation location) { return new Attribute(key, op, val) { Location = location }; }
public CssFunction CssFunction(string name, Node value, NodeLocation location) { return new CssFunction() { Name = name, Value = value, Location = location }; }
public Condition Condition(Node left, string operation, Node right, bool negate, NodeLocation location) { return new Condition(left, operation, right, negate) { Location = location }; }
public RepeatEntity RepeatEntity(Node value, Node repeatCount, int index) { return new RepeatEntity(value, repeatCount) { Location = location }; }
public Assignment Assignment(string key, Node value, NodeLocation location) { return new Assignment(key, value); }
public Paren Paren(Node value, NodeLocation location) { return new Paren(value) { Location = location }; }
public Directive Directive(string name, Node value, NodeLocation location) { return new Directive(name, value) { Location = location }; }
public Operation Operation(string operation, Node left, Node right, NodeLocation location) { return new Operation(operation, left, right) { Location = location }; }
public Attribute(Node name, Node op, Node value) { Name = name; Op = op; Value = value; }
protected override Node Eval(Env env, Node[] list, Node[] args) { return new Number(list.Length); }
public Shorthand Shorthand(Node first, Node second, NodeLocation location) { return new Shorthand(first, second) { Location = location }; }
public new Node Operate(Operation op, Node other) { CartoDimension dim = other as CartoDimension; if ("%".Equals(Unit) && ("%".Equals(dim.Unit))) { //env.Logger.Error("If two operands differ, the first must not be %"); return null; } if (!"%".Equals(Unit) && "%".Equals(dim.Unit)) { if (op.Operator.Equals("*") || op.Operator.Equals("/") || op.Operator.Equals("%")) { //env.Logger.Error("Percent values can only be added or subtracted from other values"); return null; } Operation op2 = new Operation(op.Operator, new Number(Value.ToString(), Unit), new Number((Value * dim.Value * 0.01).ToString(), Unit)); return new CartoDimension(op2, Unit, m_index); } //here the operands are either the same (% or undefined or px), or one is undefined and the other is px Operation op3 = new Operation(op.Operator, new Number(Value.ToString(), Unit), new Number(dim.Value.ToString(), Unit)); return new CartoDimension(op3, Unit ?? dim.Unit, m_index); }
public Node Visit(Node node) { TextNode tn = node as TextNode; if (tn != null) { _textContent.Append(tn.Value); _nodeContent.Add(tn); return node; } Number number = node as Number; if (number != null) { _nodeContent.Add(number); return node; } Keyword keyword = node as Keyword; if (keyword != null) { _nodeContent.Add(keyword); _textContent.Append(keyword.Value); return node; } node.Accept(this); return node; }
public Url Url(Node value, IImporter importer, NodeLocation location) { return new Url(value, importer) { Location = location }; }
public CartoZoomElement(Node comp, Node number, Combinator combinator, Node value):base(combinator, value) { m_comp = comp; m_value = number; }