public override string ToString() { return(Type switch { ConstantType.TString => StringValue, ConstantType.TNumber => NumberValue.ToString(CultureInfo.InvariantCulture), ConstantType.TNil => "nil", ConstantType.TBoolean => BoolValue ? "true" : "false", ConstantType.THash => $"0x{HashValue & 0xFFFFFFFFFFFFFFF:X}", _ => "NULL" });
public override string ToString() { return(Type switch { LuaJitConstantType.String => StringValue, LuaJitConstantType.Number => NumberValue.ToString(CultureInfo.InvariantCulture), LuaJitConstantType.Nil => "nil", LuaJitConstantType.Boolean => BoolValue ? "true" : "false", LuaJitConstantType.Function => Function.ToString(), LuaJitConstantType.Table => Table.ToString(), //LuaJitConstantType.Hash => $"0x{HashValue & 0xFFFFFFFFFFFFFFF:X}", _ => "NULL" });
private void VerifyNumber() { if (NumberMode) { if (!Text.EndsWith(".")) { decimal result = 0; if (decimal.TryParse(Text, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out result)) { _text = NumberValue.ToString(CultureInfo.InvariantCulture); } } } }
public string GetJsonValue() { switch (Type) { case "String": return("\"" + StringValue.Replace("\"", "\\\"") + "\""); case "Number": return(NumberValue.ToString()); case "Boolean": return(BooleanValue.ToString()); default: return(""); } }
public override string ToString() { if (Type == TokenType.Number) { if (NumberValue < 0) { return($"({NumberValue})"); } else { return(NumberValue.ToString()); } } else { return(OtherValue); } }
public void HandleNumberParam() { var p1 = new NumberValue(18); Assert.AreEqual("18", p1.ToString()); var p2 = NumberValue.Parse("18"); Assert.AreEqual(18M, p2.Value); var p3 = NumberValue.Parse("18.00"); Assert.AreEqual(18.00M, p3.Value); var crit = Criterium.Parse("paramX=18.34"); var p4 = ((UntypedValue)crit.Operand).AsNumberValue(); Assert.AreEqual(18.34M, p4.Value); }
public override string ToString() { if (Type == ConstantType.TString) { return(StringValue); } if (Type == ConstantType.TNumber) { return(NumberValue.ToString(CultureInfo.InvariantCulture)); } if (Type == ConstantType.TNil) { return("nill"); } if (Type == ConstantType.TBoolean) { return(BoolValue ? "true" : "false"); } if (Type == ConstantType.THash) { return($"0x{HashValue & 0xFFFFFFFFFFFFFFF:X}"); } return("NULL"); }
/// <summary> /// Return a formatted string for the MobiusDataType /// </summary> /// <returns></returns> public override string FormatCriteriaForDisplay() { return(NumberValue.ToString()); }
/// <summary> /// Return the internal normalized string version of the MobiusDataType /// </summary> /// <returns></returns> public override string FormatForCriteria() { return(NumberValue.ToString()); }
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { string Property = e.Link.LinkData as string; PropertyInfo info = action.GetType().GetProperty(Property); if (info == null) { MessageBox.Show("Property " + Property + " Does not exist for " + action.GetType().Name); return; } DialogResult result = DialogResult.Cancel; string valueResult = ""; if (info.PropertyType == typeof(NumberValue)) { VariableEditor editor = new VariableEditor(); if (Variables != null) { editor.SetVariable(Variables.Select(x => x.Name)); } else { editor.SetVariable(new string[] { }); } NumberValue val = info.GetMethod.Invoke(action, new object[] { }) as NumberValue; editor.SetDefault(val == null ? "" : val.ToString()); editor.Text = "Variable Editor - " + Property; result = editor.ShowDialog(); if (result == DialogResult.OK) { info.SetMethod.Invoke(action, new object[] { new NumberValue(valueResult) }); } } if (info.PropertyType == typeof(TargetKey)) { TargetKeyEditor editor = new TargetKeyEditor(); editor.SetPresets(ActionContext); editor.VariableList = Variables; TargetKey t = info.GetMethod.Invoke(action, new object[] { }) as TargetKey; if (t == null) { t = new TargetKey(); } editor.Target = t; result = editor.ShowDialog(); if (result == DialogResult.OK) { TargetKey target = editor.Target; info.SetMethod.Invoke(action, new object[] { target }); } } //It's an Enum! if (typeof(Enum).IsAssignableFrom(info.PropertyType)) { Enum enumValue = info.GetMethod.Invoke(action, new object[] { }) as Enum; //Find out if it's a flag and open the flag editor if (info.PropertyType.GetCustomAttribute <FlagsAttribute>() != null) { FlagCheckBoxEditor editor = new FlagCheckBoxEditor(); editor.EnumValue = enumValue; result = editor.ShowDialog(); enumValue = editor.EnumValue; } else { EnumEditor editor = new EnumEditor(); editor.EnumValue = enumValue; result = editor.ShowDialog(); enumValue = editor.EnumValue; } if (result == DialogResult.OK) { info.SetMethod.Invoke(action, new object[] { enumValue }); valueResult = enumValue.ToString(); } } if (typeof(bool) == info.PropertyType) { bool val = (bool)info.GetMethod.Invoke(action, new object[] { }); BoolEditor editor = new BoolEditor(); editor.Value = val; result = editor.ShowDialog(); if (result == DialogResult.OK) { info.SetMethod.Invoke(action, new object[] { editor.Value }); } } if (typeof(string) == info.PropertyType) { string val = (string)info.GetMethod.Invoke(action, new object[] { }); TextPrompt editor = new TextPrompt(); editor.Text = Property; editor.PromptText = val; result = editor.ShowDialog(); if (result == DialogResult.OK) { info.SetMethod.Invoke(action, new object[] { editor.PromptText }); } } if (typeof(ActionCollection) == info.PropertyType) { ActionCollection actions = info.GetMethod.Invoke(action, new object[] { }) as ActionCollection; ActionListEditor editor = new ActionListEditor(); if (actions == null) { actions = new ActionCollection(Property); } editor.ActionContext = ActionContext; editor.Variables = Variables; editor.Actions = actions; result = editor.ShowDialog(); if (result == DialogResult.OK) { info.SetMethod.Invoke(action, new object[] { editor.Actions }); } } if (result == DialogResult.OK) { UpdateLinkTexts(); } if (LinkClicked != null) { LinkClicked.Invoke(this, new LinkClickedEventArgs(e.Link.LinkData as string)); } }
/** * Parses the next token from the input stream of this tokenizer. * The type of the next token is returned in the <code>ttype</code> * field. Additional information about the token may be in the * <code>nval</code> field or the <code>sval</code> field of this * tokenizer. * <p> * Typical clients of this * class first set up the syntax tables and then sit in a loop * calling nextToken to parse successive tokens until TT_EOF * is returned. * * @return the value of the <code>ttype</code> field. */ public int NextToken() { if (_pushedBack) { _pushedBack = false; return(Ttype); } byte[] ct = _characterType; StringValue = null; int c = _peekc; if (c < 0) { c = NeedChar; } if (c == SkipLf) { c = Read(); if (c < 0) { return(Ttype = TtEof); } if (c == '\n') { c = NeedChar; } } if (c == NeedChar) { c = Read(); if (c < 0) { return(Ttype = TtEof); } } Ttype = c; /* Just to be safe */ /* Set peekc so that the next invocation of nextToken will Read * another character unless peekc is reset in this invocation */ _peekc = NeedChar; int ctype = c < 256 ? ct[c] : CtAlpha; while ((ctype & CtWhitespace) != 0) { if (c == '\r') { LineNumber++; if (_eolIsSignificantP) { _peekc = SkipLf; return(Ttype = TtEol); } c = Read(); if (c == '\n') { c = Read(); } } else { if (c == '\n') { LineNumber++; if (_eolIsSignificantP) { return(Ttype = TtEol); } } c = Read(); } if (c < 0) { return(Ttype = TtEof); } ctype = c < 256 ? ct[c] : CtAlpha; } if ((ctype & CtDigit) != 0) { bool neg = false; if (c == '-') { c = Read(); if (c != '.' && (c < '0' || c > '9')) { _peekc = c; return(Ttype = '-'); } neg = true; } double v = 0; int decexp = 0; int seendot = 0; while (true) { if (c == '.' && seendot == 0) { seendot = 1; } else if ('0' <= c && c <= '9') { v = v * 10 + (c - '0'); decexp += seendot; } else { break; } c = Read(); } _peekc = c; if (decexp != 0) { double denom = 10; decexp--; while (decexp > 0) { denom *= 10; decexp--; } /* Do one division of a likely-to-be-more-accurate number */ v = v / denom; } NumberValue = neg ? -v : v; StringValue = NumberValue.ToString(CultureInfo.InvariantCulture); if (seendot == 1 && NumberValue.CompareTo(Math.Abs(NumberValue)) == 0) { StringValue += ".0"; } return(Ttype = TtNumber); } if ((ctype & CtAlpha) != 0) { var buf = new List <char>(); int i = 0; do { //buf[i++] = (char)c; buf.Add((char)c); i++; c = Read(); ctype = c < 0 ? CtWhitespace : c < 256 ? ct[c] : CtAlpha; } while ((ctype & (CtAlpha | CtDigit)) != 0); _peekc = c; StringValue = new string(buf.ToArray(), 0, i); if (_forceLower) { StringValue = StringValue.ToLower(); } return(Ttype = TtWord); } if ((ctype & CtQuote) != 0) { var buf = new List <char>(); Ttype = c; int i = 0; /* Invariants (because \Octal needs a lookahead): * (i) c contains char value * (ii) d contains the lookahead */ int d = Read(); while (d >= 0 && d != Ttype && d != '\n' && d != '\r') { if (d == '\\') { c = Read(); int first = c; /* To allow \377, but not \477 */ if (c >= '0' && c <= '7') { c = c - '0'; int c2 = Read(); if ('0' <= c2 && c2 <= '7') { c = (c << 3) + (c2 - '0'); c2 = Read(); if ('0' <= c2 && c2 <= '7' && first <= '3') { c = (c << 3) + (c2 - '0'); d = Read(); } else { d = c2; } } else { d = c2; } } else { switch (c) { case 'a': c = 0x7; break; case 'b': c = '\b'; break; case 'f': c = 0xC; break; case 'n': c = '\n'; break; case 'r': c = '\r'; break; case 't': c = '\t'; break; case 'v': c = 0xB; break; } d = Read(); } } else { c = d; d = Read(); } //buf[i++] = (char)c; buf.Add((char)c); i++; } /* If we broke out of the loop because we found a matching quote * character then arrange to Read a new character next time * around; otherwise, save the character. */ _peekc = (d == Ttype) ? NeedChar : d; StringValue = new string(buf.ToArray(), 0, i); return(Ttype); } if (c == '/' && (_slashSlashCommentsP || _slashStarCommentsP)) { c = Read(); if (c == '*' && _slashStarCommentsP) { int prevc = 0; while ((c = Read()) != '/' || prevc != '*') { if (c == '\r') { LineNumber++; c = Read(); if (c == '\n') { c = Read(); } } else { if (c == '\n') { LineNumber++; c = Read(); } } if (c < 0) { return(Ttype = TtEof); } prevc = c; } return(NextToken()); } if (c == '/' && _slashSlashCommentsP) { while ((c = Read()) != '\n' && c != '\r' && c >= 0) { } _peekc = c; return(NextToken()); } /* Now see if it is still a single line comment */ if ((ct['/'] & CtComment) != 0) { while ((c = Read()) != '\n' && c != '\r' && c >= 0) { } _peekc = c; return(NextToken()); } _peekc = c; return(Ttype = '/'); } if ((ctype & CtComment) != 0) { while ((c = Read()) != '\n' && c != '\r' && c >= 0) { } _peekc = c; return(NextToken()); } return(Ttype = c); }
public override String Show(int col, int row, int ctxpre, Formats fo) { return(value.ToString()); }