A game about forced loneliness, made by TACStudios
1using System; 2using System.Text; 3 4namespace Unity.VisualScripting.Dependencies.NCalc 5{ 6 public abstract class LogicalExpression 7 { 8 public BinaryExpression And(LogicalExpression operand) 9 { 10 return new BinaryExpression(BinaryExpressionType.And, this, operand); 11 } 12 13 public BinaryExpression And(object operand) 14 { 15 return new BinaryExpression(BinaryExpressionType.And, this, new ValueExpression(operand)); 16 } 17 18 public BinaryExpression DividedBy(LogicalExpression operand) 19 { 20 return new BinaryExpression(BinaryExpressionType.Div, this, operand); 21 } 22 23 public BinaryExpression DividedBy(object operand) 24 { 25 return new BinaryExpression(BinaryExpressionType.Div, this, new ValueExpression(operand)); 26 } 27 28 public BinaryExpression EqualsTo(LogicalExpression operand) 29 { 30 return new BinaryExpression(BinaryExpressionType.Equal, this, operand); 31 } 32 33 public BinaryExpression EqualsTo(object operand) 34 { 35 return new BinaryExpression(BinaryExpressionType.Equal, this, new ValueExpression(operand)); 36 } 37 38 public BinaryExpression GreaterThan(LogicalExpression operand) 39 { 40 return new BinaryExpression(BinaryExpressionType.Greater, this, operand); 41 } 42 43 public BinaryExpression GreaterThan(object operand) 44 { 45 return new BinaryExpression(BinaryExpressionType.Greater, this, new ValueExpression(operand)); 46 } 47 48 public BinaryExpression GreaterOrEqualThan(LogicalExpression operand) 49 { 50 return new BinaryExpression(BinaryExpressionType.GreaterOrEqual, this, operand); 51 } 52 53 public BinaryExpression GreaterOrEqualThan(object operand) 54 { 55 return new BinaryExpression(BinaryExpressionType.GreaterOrEqual, this, new ValueExpression(operand)); 56 } 57 58 public BinaryExpression LesserThan(LogicalExpression operand) 59 { 60 return new BinaryExpression(BinaryExpressionType.Lesser, this, operand); 61 } 62 63 public BinaryExpression LesserThan(object operand) 64 { 65 return new BinaryExpression(BinaryExpressionType.Lesser, this, new ValueExpression(operand)); 66 } 67 68 public BinaryExpression LesserOrEqualThan(LogicalExpression operand) 69 { 70 return new BinaryExpression(BinaryExpressionType.LesserOrEqual, this, operand); 71 } 72 73 public BinaryExpression LesserOrEqualThan(object operand) 74 { 75 return new BinaryExpression(BinaryExpressionType.LesserOrEqual, this, new ValueExpression(operand)); 76 } 77 78 public BinaryExpression Minus(LogicalExpression operand) 79 { 80 return new BinaryExpression(BinaryExpressionType.Minus, this, operand); 81 } 82 83 public BinaryExpression Minus(object operand) 84 { 85 return new BinaryExpression(BinaryExpressionType.Minus, this, new ValueExpression(operand)); 86 } 87 88 public BinaryExpression Modulo(LogicalExpression operand) 89 { 90 return new BinaryExpression(BinaryExpressionType.Modulo, this, operand); 91 } 92 93 public BinaryExpression Modulo(object operand) 94 { 95 return new BinaryExpression(BinaryExpressionType.Modulo, this, new ValueExpression(operand)); 96 } 97 98 public BinaryExpression NotEqual(LogicalExpression operand) 99 { 100 return new BinaryExpression(BinaryExpressionType.NotEqual, this, operand); 101 } 102 103 public BinaryExpression NotEqual(object operand) 104 { 105 return new BinaryExpression(BinaryExpressionType.NotEqual, this, new ValueExpression(operand)); 106 } 107 108 public BinaryExpression Or(LogicalExpression operand) 109 { 110 return new BinaryExpression(BinaryExpressionType.Or, this, operand); 111 } 112 113 public BinaryExpression Or(object operand) 114 { 115 return new BinaryExpression(BinaryExpressionType.Or, this, new ValueExpression(operand)); 116 } 117 118 public BinaryExpression Plus(LogicalExpression operand) 119 { 120 return new BinaryExpression(BinaryExpressionType.Plus, this, operand); 121 } 122 123 public BinaryExpression Plus(object operand) 124 { 125 return new BinaryExpression(BinaryExpressionType.Plus, this, new ValueExpression(operand)); 126 } 127 128 public BinaryExpression Mult(LogicalExpression operand) 129 { 130 return new BinaryExpression(BinaryExpressionType.Times, this, operand); 131 } 132 133 public BinaryExpression Mult(object operand) 134 { 135 return new BinaryExpression(BinaryExpressionType.Times, this, new ValueExpression(operand)); 136 } 137 138 public BinaryExpression BitwiseOr(LogicalExpression operand) 139 { 140 return new BinaryExpression(BinaryExpressionType.BitwiseOr, this, operand); 141 } 142 143 public BinaryExpression BitwiseOr(object operand) 144 { 145 return new BinaryExpression(BinaryExpressionType.BitwiseOr, this, new ValueExpression(operand)); 146 } 147 148 public BinaryExpression BitwiseAnd(LogicalExpression operand) 149 { 150 return new BinaryExpression(BinaryExpressionType.BitwiseAnd, this, operand); 151 } 152 153 public BinaryExpression BitwiseAnd(object operand) 154 { 155 return new BinaryExpression(BinaryExpressionType.BitwiseAnd, this, new ValueExpression(operand)); 156 } 157 158 public BinaryExpression BitwiseXOr(LogicalExpression operand) 159 { 160 return new BinaryExpression(BinaryExpressionType.BitwiseXOr, this, operand); 161 } 162 163 public BinaryExpression BitwiseXOr(object operand) 164 { 165 return new BinaryExpression(BinaryExpressionType.BitwiseXOr, this, new ValueExpression(operand)); 166 } 167 168 public BinaryExpression LeftShift(LogicalExpression operand) 169 { 170 return new BinaryExpression(BinaryExpressionType.LeftShift, this, operand); 171 } 172 173 public BinaryExpression LeftShift(object operand) 174 { 175 return new BinaryExpression(BinaryExpressionType.LeftShift, this, new ValueExpression(operand)); 176 } 177 178 public BinaryExpression RightShift(LogicalExpression operand) 179 { 180 return new BinaryExpression(BinaryExpressionType.RightShift, this, operand); 181 } 182 183 public BinaryExpression RightShift(object operand) 184 { 185 return new BinaryExpression(BinaryExpressionType.RightShift, this, new ValueExpression(operand)); 186 } 187 188 public override string ToString() 189 { 190 var serializer = new SerializationVisitor(); 191 192 Accept(serializer); 193 194 return serializer.Result.ToString().TrimEnd(' '); 195 } 196 197 // This method is not just syntactic sugar. 198 // It chooses the proper overload of Visit() based on the current type. 199 public virtual void Accept(LogicalExpressionVisitor visitor) 200 { 201 throw new NotImplementedException(); 202 } 203 204 private const char BS = '\\'; 205 206 private static string ExtractString(string text) 207 { 208 var sb = new StringBuilder(text); 209 var startIndex = 1; // Skip initial quote 210 var slashIndex = -1; 211 212 while ((slashIndex = sb.ToString().IndexOf(BS, startIndex)) != -1) 213 { 214 var escapeType = sb[slashIndex + 1]; 215 216 switch (escapeType) 217 { 218 case 'u': 219 var hcode = String.Concat(sb[slashIndex + 4], sb[slashIndex + 5]); 220 var lcode = String.Concat(sb[slashIndex + 2], sb[slashIndex + 3]); 221 var unicodeChar = Encoding.Unicode.GetChars(new[] { Convert.ToByte(hcode, 16), Convert.ToByte(lcode, 16) })[0]; 222 sb.Remove(slashIndex, 6).Insert(slashIndex, unicodeChar); 223 break; 224 225 case 'n': 226 sb.Remove(slashIndex, 2).Insert(slashIndex, '\n'); 227 break; 228 229 case 'r': 230 sb.Remove(slashIndex, 2).Insert(slashIndex, '\r'); 231 break; 232 233 case 't': 234 sb.Remove(slashIndex, 2).Insert(slashIndex, '\t'); 235 break; 236 237 case '\'': 238 sb.Remove(slashIndex, 2).Insert(slashIndex, '\''); 239 break; 240 241 case '\\': 242 sb.Remove(slashIndex, 2).Insert(slashIndex, '\\'); 243 break; 244 245 default: 246 throw new ApplicationException("Unvalid escape sequence: \\" + escapeType); 247 } 248 249 startIndex = slashIndex + 1; 250 } 251 252 sb.Remove(0, 1); 253 sb.Remove(sb.Length - 1, 1); 254 255 return sb.ToString(); 256 } 257 } 258}