Add bitwise operations, rename power operator to "**"
This commit is contained in:
parent
af4239e198
commit
3ae964e033
@ -30,8 +30,11 @@ namespace XNeedle.Parser
|
|||||||
static readonly Parser<ExpressionType> Multiply = Operator("*", ExpressionType.MultiplyChecked);
|
static readonly Parser<ExpressionType> Multiply = Operator("*", ExpressionType.MultiplyChecked);
|
||||||
static readonly Parser<ExpressionType> Divide = Operator("/", ExpressionType.Divide);
|
static readonly Parser<ExpressionType> Divide = Operator("/", ExpressionType.Divide);
|
||||||
static readonly Parser<ExpressionType> Modulo = Operator("%", ExpressionType.Modulo);
|
static readonly Parser<ExpressionType> Modulo = Operator("%", ExpressionType.Modulo);
|
||||||
static readonly Parser<ExpressionType> Power = Operator("^", ExpressionType.Power);
|
static readonly Parser<ExpressionType> Power = Operator("**", ExpressionType.Power);
|
||||||
|
static readonly Parser<ExpressionType> BitwiseXor = Operator("^", ExpressionType.ExclusiveOr);
|
||||||
|
static readonly Parser<ExpressionType> BitwiseAnd = Operator("&", ExpressionType.And);
|
||||||
|
static readonly Parser<ExpressionType> BitwiseOr = Operator("|", ExpressionType.Or);
|
||||||
|
|
||||||
static Parser<Expression> Function(Context ctx)
|
static Parser<Expression> Function(Context ctx)
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
@ -116,7 +119,7 @@ namespace XNeedle.Parser
|
|||||||
|
|
||||||
static Parser<Expression> Term(Context ctx)
|
static Parser<Expression> Term(Context ctx)
|
||||||
{
|
{
|
||||||
return Parse.ChainOperator(Multiply.Or(Divide).Or(Modulo), InnerTerm(ctx), Expression.MakeBinary);
|
return Parse.ChainOperator(Multiply.Or(Divide).Or(Modulo).Or(BitwiseXor).Or(BitwiseAnd).Or(BitwiseOr), InnerTerm(ctx), Expression.MakeBinary);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Parser<Expression> ConcatExpr(Context ctx)
|
static Parser<Expression> ConcatExpr(Context ctx)
|
||||||
|
|||||||
@ -12,7 +12,7 @@ namespace XNeedle.Transformation
|
|||||||
{
|
{
|
||||||
public class ContextFunctions
|
public class ContextFunctions
|
||||||
{
|
{
|
||||||
public static string hexlit(Context ctx, double value)
|
public static string hexlit(Context ctx, int value)
|
||||||
{
|
{
|
||||||
uint v = (uint)value;
|
uint v = (uint)value;
|
||||||
return $"#x{v:x8}";
|
return $"#x{v:x8}";
|
||||||
@ -70,7 +70,7 @@ namespace XNeedle.Transformation
|
|||||||
return reflected;
|
return reflected;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double crc32(Context ctx, int poly = 0x04C11DB7, int init = 0, int xorOut = 0, bool reflected = false)
|
public static int crc32(Context ctx, int poly = 0x04C11DB7, int init = 0, int xorOut = 0, bool reflected = false)
|
||||||
{
|
{
|
||||||
if (ctx.Node is null)
|
if (ctx.Node is null)
|
||||||
return 0;
|
return 0;
|
||||||
@ -88,7 +88,7 @@ namespace XNeedle.Transformation
|
|||||||
byte[] fragBytes = Encoding.UTF8.GetBytes(data);
|
byte[] fragBytes = Encoding.UTF8.GetBytes(data);
|
||||||
|
|
||||||
// Step 3: Digest into CRC32 using parameterized CRC32 - by default MPEG-2
|
// Step 3: Digest into CRC32 using parameterized CRC32 - by default MPEG-2
|
||||||
return (double)ComputeCrc32(fragBytes, (uint)poly, (uint)init, (uint)xorOut, reflected);
|
return (int)ComputeCrc32(fragBytes, (uint)poly, (uint)init, (uint)xorOut, reflected);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string text(Context ctx)
|
public static string text(Context ctx)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user