Skip to content

Commit

Permalink
Fix errors in imported files
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeapage committed Jun 1, 2012
1 parent 2ce7e39 commit 099503d
Show file tree
Hide file tree
Showing 43 changed files with 452 additions and 336 deletions.
20 changes: 11 additions & 9 deletions src/dotless.Core/Exceptions/ParsingException.cs
@@ -1,24 +1,26 @@
namespace dotless.Core.Exceptions
{
using System;
using dotless.Core.Parser;

public class ParsingException : Exception
{
public int Index { get; set; }
public int Call { get; set; }
public NodeLocation Location { get; set; }
public NodeLocation CallLocation { get; set; }

public ParsingException(string message, int index) : this(message, null, index, 0) {}
public ParsingException(string message, NodeLocation location) : this(message, null, location, null) { }

public ParsingException(string message, int index, int call) : this(message, null, index, call) {}
public ParsingException(string message, NodeLocation location, NodeLocation callLocation) : this(message, null, location, callLocation) { }

public ParsingException(Exception innerException, int index) : this(innerException, index, 0) {}
public ParsingException(Exception innerException, NodeLocation location) : this(innerException, location, null) { }

public ParsingException(Exception innerException, int index, int call) : this(innerException.Message, innerException, index, call) {}
public ParsingException(Exception innerException, NodeLocation location, NodeLocation callLocation) : this(innerException.Message, innerException, location, callLocation) { }

public ParsingException(string message, Exception innerException, int index, int call) : base(message, innerException)
public ParsingException(string message, Exception innerException, NodeLocation location, NodeLocation callLocation)
: base(message, innerException)
{
Index = index;
Call = call;
Location = location;
CallLocation = callLocation;
}
}
}
2 changes: 1 addition & 1 deletion src/dotless.Core/Parser/Functions/AddFunction.cs
Expand Up @@ -10,7 +10,7 @@ public class AddFunction : Function
{
protected override Node Evaluate(Env env)
{
Guard.ExpectAllNodes<Number>(Arguments, this, Index);
Guard.ExpectAllNodes<Number>(Arguments, this, Location);

var value = Arguments.Cast<Number>().Select(d => d.Value).Aggregate(0d, (a, b) => a + b);

Expand Down
4 changes: 2 additions & 2 deletions src/dotless.Core/Parser/Functions/ColorFunction.cs
Expand Up @@ -9,8 +9,8 @@ public class ColorFunction : Function
{
protected override Node Evaluate(Env env)
{
Guard.ExpectNumArguments(1, Arguments.Count, this, Index);
Guard.ExpectNode<TextNode>(Arguments[0], this, Index);
Guard.ExpectNumArguments(1, Arguments.Count, this, Location);
Guard.ExpectNode<TextNode>(Arguments[0], this, Location);

return new Color(((TextNode)Arguments[0]).Value.TrimStart('#'));
}
Expand Down
6 changes: 3 additions & 3 deletions src/dotless.Core/Parser/Functions/ColorFunctionBase.cs
Expand Up @@ -10,14 +10,14 @@ public abstract class ColorFunctionBase : Function
{
protected override Node Evaluate(Env env)
{
Guard.ExpectMinArguments(1, Arguments.Count(), this, Index);
Guard.ExpectNode<Color>(Arguments[0], this, Arguments[0].Index);
Guard.ExpectMinArguments(1, Arguments.Count(), this, Location);
Guard.ExpectNode<Color>(Arguments[0], this, Arguments[0].Location);

var color = Arguments[0] as Color;

if (Arguments.Count == 2)
{
Guard.ExpectNode<Number>(Arguments[1], this, Arguments[1].Index);
Guard.ExpectNode<Number>(Arguments[1], this, Arguments[1].Location);

var number = Arguments[1] as Number;
var edit = EditColor(color, number);
Expand Down
12 changes: 6 additions & 6 deletions src/dotless.Core/Parser/Functions/ContrastFunction.cs
Expand Up @@ -10,18 +10,18 @@ public class ContrastFunction : Function
{
protected override Node Evaluate(Env env)
{
Guard.ExpectMinArguments(1, Arguments.Count, this, Index);
Guard.ExpectMaxArguments(4, Arguments.Count, this, Index);
Guard.ExpectNode<Color>(Arguments[0], this, Index);
Guard.ExpectMinArguments(1, Arguments.Count, this, Location);
Guard.ExpectMaxArguments(4, Arguments.Count, this, Location);
Guard.ExpectNode<Color>(Arguments[0], this, Location);

var color = HslColor.FromRgbColor((Color) Arguments[0]);

if (Arguments.Count > 1)
Guard.ExpectNode<Color>(Arguments[1], this, Index);
Guard.ExpectNode<Color>(Arguments[1], this, Location);
if (Arguments.Count > 2)
Guard.ExpectNode<Color>(Arguments[2], this, Index);
Guard.ExpectNode<Color>(Arguments[2], this, Location);
if (Arguments.Count > 3)
Guard.ExpectNode<Number>(Arguments[3], this, Index);
Guard.ExpectNode<Number>(Arguments[3], this, Location);

WarnNotSupportedByLessJS("contrast(color, color[, color[, percentage]])");

Expand Down
4 changes: 2 additions & 2 deletions src/dotless.Core/Parser/Functions/Function.cs
Expand Up @@ -11,14 +11,14 @@ public abstract class Function
public string Name { get; set; }
protected List<Node> Arguments { get; set; }
public ILogger Logger { get; set; }
public int Index { get; set; }
public NodeLocation Location { get; set; }

public Node Call(Env env, IEnumerable<Node> arguments)
{
Arguments = arguments.ToList();

var node = Evaluate(env);
node.Index = Index;
node.Location = Location;
return node;
}

Expand Down
2 changes: 1 addition & 1 deletion src/dotless.Core/Parser/Functions/HexFunction.cs
Expand Up @@ -12,7 +12,7 @@ protected override Node Eval(Env env, Number number, Node[] args)
WarnNotSupportedByLessJS("hex(number)");

if (!string.IsNullOrEmpty(number.Unit))
throw new ParsingException(string.Format("Expected unitless number in function 'hex', found {0}", number.ToCSS(env)), number.Index);
throw new ParsingException(string.Format("Expected unitless number in function 'hex', found {0}", number.ToCSS(env)), number.Location);

number.Value = Clamp(number.Value, 255, 0);

Expand Down
2 changes: 1 addition & 1 deletion src/dotless.Core/Parser/Functions/HslFunction.cs
Expand Up @@ -9,7 +9,7 @@ public class HslFunction : HslaFunction
{
protected override Node Evaluate(Env env)
{
Guard.ExpectNumArguments(3, Arguments.Count, this, Index);
Guard.ExpectNumArguments(3, Arguments.Count, this, Location);

Arguments.Add(new Number(1d, ""));

Expand Down
4 changes: 2 additions & 2 deletions src/dotless.Core/Parser/Functions/HslaFunction.cs
Expand Up @@ -10,8 +10,8 @@ public class HslaFunction : Function
{
protected override Node Evaluate(Env env)
{
Guard.ExpectNumArguments(4, Arguments.Count, this, Index);
Guard.ExpectAllNodes<Number>(Arguments, this, Index);
Guard.ExpectNumArguments(4, Arguments.Count, this, Location);
Guard.ExpectAllNodes<Number>(Arguments, this, Location);

var args = Arguments.Cast<Number>().ToArray();

Expand Down
2 changes: 1 addition & 1 deletion src/dotless.Core/Parser/Functions/IsFunctions.cs
Expand Up @@ -12,7 +12,7 @@ public abstract class IsFunction : Function
{
protected override Infrastructure.Nodes.Node Evaluate(Infrastructure.Env env)
{
Guard.ExpectNumArguments(1, Arguments.Count, this, Index);
Guard.ExpectNumArguments(1, Arguments.Count, this, Location);

return new Keyword(IsEvaluator(Arguments[0]) ? "true" : "false");
}
Expand Down
8 changes: 4 additions & 4 deletions src/dotless.Core/Parser/Functions/MixFunction.cs
Expand Up @@ -10,14 +10,14 @@ public class MixFunction : Function
{
protected override Node Evaluate(Env env)
{
Guard.ExpectMinArguments(2, Arguments.Count, this, Index);
Guard.ExpectMaxArguments(3, Arguments.Count, this, Index);
Guard.ExpectAllNodes<Color>(Arguments.Take(2), this, Index);
Guard.ExpectMinArguments(2, Arguments.Count, this, Location);
Guard.ExpectMaxArguments(3, Arguments.Count, this, Location);
Guard.ExpectAllNodes<Color>(Arguments.Take(2), this, Location);

double weight = 50;
if (Arguments.Count == 3)
{
Guard.ExpectNode<Number>(Arguments[2], this, Index);
Guard.ExpectNode<Number>(Arguments[2], this, Location);

weight = ((Number) Arguments[2]).Value;
}
Expand Down
4 changes: 2 additions & 2 deletions src/dotless.Core/Parser/Functions/NumberFunctionBase.cs
Expand Up @@ -10,8 +10,8 @@ public abstract class NumberFunctionBase : Function
{
protected override Node Evaluate(Env env)
{
Guard.ExpectMinArguments(1, Arguments.Count, this, Index);
Guard.ExpectNode<Number>(Arguments[0], this, Arguments[0].Index);
Guard.ExpectMinArguments(1, Arguments.Count, this, Location);
Guard.ExpectNode<Number>(Arguments[0], this, Arguments[0].Location);

var number = Arguments[0] as Number;
var args = Arguments.Skip(1).ToArray();
Expand Down
2 changes: 1 addition & 1 deletion src/dotless.Core/Parser/Functions/PercentageFunction.cs
Expand Up @@ -15,7 +15,7 @@ protected override Node Eval(Env env, Number number, Node[] args)
if (string.IsNullOrEmpty(number.Unit))
return new Number(number.Value * 100, "%");

throw new ParsingException(string.Format("Expected unitless number in function 'percentage', found {0}", number.ToCSS(env)), number.Index);
throw new ParsingException(string.Format("Expected unitless number in function 'percentage', found {0}", number.ToCSS(env)), number.Location);
}
}
}
6 changes: 3 additions & 3 deletions src/dotless.Core/Parser/Functions/PowFunction.cs
Expand Up @@ -11,9 +11,9 @@ public class PowFunction : Function
{
protected override Node Evaluate(Env env)
{
Guard.ExpectMinArguments(2, Arguments.Count, this, Index);
Guard.ExpectMaxArguments(2, Arguments.Count, this, Index);
Guard.ExpectAllNodes<Number>(Arguments, this, Index);
Guard.ExpectMinArguments(2, Arguments.Count, this, Location);
Guard.ExpectMaxArguments(2, Arguments.Count, this, Location);
Guard.ExpectAllNodes<Number>(Arguments, this, Location);

WarnNotSupportedByLessJS("pow(number, number)");

Expand Down
2 changes: 1 addition & 1 deletion src/dotless.Core/Parser/Functions/RgbFunction.cs
Expand Up @@ -9,7 +9,7 @@ public class RgbFunction : RgbaFunction
{
protected override Node Evaluate(Env env)
{
Guard.ExpectNumArguments(3, Arguments.Count, this, Index);
Guard.ExpectNumArguments(3, Arguments.Count, this, Location);

Arguments.Add(new Number(1d, ""));

Expand Down
8 changes: 4 additions & 4 deletions src/dotless.Core/Parser/Functions/RgbaFunction.cs
Expand Up @@ -12,14 +12,14 @@ protected override Node Evaluate(Env env)
{
if (Arguments.Count == 2)
{
Guard.ExpectNode<Color>(Arguments[0], this, Index);
Guard.ExpectNode<Number>(Arguments[1], this, Index);
Guard.ExpectNode<Color>(Arguments[0], this, Location);
Guard.ExpectNode<Number>(Arguments[1], this, Location);

return new Color(((Color) Arguments[0]).RGB, ((Number) Arguments[1]).Value);
}

Guard.ExpectNumArguments(4, Arguments.Count, this, Index);
Guard.ExpectAllNodes<Number>(Arguments, this, Index);
Guard.ExpectNumArguments(4, Arguments.Count, this, Location);
Guard.ExpectAllNodes<Number>(Arguments, this, Location);

var args = Arguments.Cast<Number>();

Expand Down
2 changes: 1 addition & 1 deletion src/dotless.Core/Parser/Functions/StringFunctions.cs
Expand Up @@ -13,7 +13,7 @@ public class EFunction : Function
{
protected override Node Evaluate(Env env)
{
Guard.ExpectMaxArguments(1, Arguments.Count, this, Index);
Guard.ExpectMaxArguments(1, Arguments.Count, this, Location);

WarnNotSupportedByLessJS("e(string)", @"~""""");

Expand Down

0 comments on commit 099503d

Please sign in to comment.