private static Value ParseJsonList(VmGlobals globals, char[] rawValue, int length, Index i) { i.Value++; // '[' SkipWhitespace(rawValue, length, i); List <Value> items = new List <Value>(); while (i.Value < length && rawValue[i.Value] != ']') { if (items.Count > 0) { PopExpected(rawValue, length, i, ","); SkipWhitespace(rawValue, length, i); } Value item = ParseJsonThing(globals, rawValue, length, i); SkipWhitespace(rawValue, length, i); items.Add(item); } if (i.Value < length) { PopExpected(rawValue, length, i, "]"); } return(CrayonWrapper.buildList(items)); }
private static Value ParseJsonIntoValue(VmGlobals globals, char[] rawValue, int length, Index i) { Value output = ParseJsonThing(globals, rawValue, length, i); SkipWhitespace(rawValue, length, i); if (i.Value < length) { throw new JsonParserException(); } return(output); }
public static Value ParseJsonIntoValue(VmGlobals globals, string rawValue) { try { return(ParseJsonIntoValue(globals, rawValue.ToCharArray(), rawValue.Length, new Index() { Value = 0 })); } catch (JsonParserException) { return(null); } }
public static int lib_fileiocommon_textToLinesImpl(VmGlobals globals, string text, ListImpl output) { List <string> stringList = new List <string>(); FileIOCommonHelper.TextToLines(text, stringList); int _len = stringList.Count; int i = 0; while ((i < _len)) { Interpreter.Vm.CrayonWrapper.addToList(output, Interpreter.Vm.CrayonWrapper.buildString(globals, stringList[i])); i += 1; } return(0); }
private static Value ParseJsonNumber(VmGlobals globals, char[] rawValue, int length, Index i) { int sign = 1; char c = rawValue[i.Value]; if (c == '-') { sign = -1; i.Value++; } StringBuilder sb = new StringBuilder(); while (i.Value < length) { c = rawValue[i.Value++]; if (c != '.' && (c < '0' || c > '9')) { i.Value--; break; } else { sb.Append(c); } } string stringValue = sb.ToString(); if (stringValue.Contains('.')) { double value; if (double.TryParse(stringValue, out value)) { return(CrayonWrapper.buildFloat(globals, value * sign)); } } else { int value; if (int.TryParse(stringValue, out value)) { return(CrayonWrapper.buildInteger(globals, value * sign)); } } throw new JsonParserException(); }
public static Value lib_fileiocommon_fileInfo(VmContext vm, Value[] args) { int mask = (int)args[2].internalValue; FileIOCommonHelper.GetFileInfo((string)args[1].internalValue, mask, PST_IntBuffer16, PST_FloatBuffer16); ListImpl outputList = (ListImpl)args[3].internalValue; Interpreter.Vm.CrayonWrapper.clearList(outputList); VmGlobals globals = vm.globals; Interpreter.Vm.CrayonWrapper.addToList(outputList, Interpreter.Vm.CrayonWrapper.buildBoolean(globals, (PST_IntBuffer16[0] > 0))); Interpreter.Vm.CrayonWrapper.addToList(outputList, Interpreter.Vm.CrayonWrapper.buildBoolean(globals, (PST_IntBuffer16[1] > 0))); if (((mask & 1) != 0)) { Interpreter.Vm.CrayonWrapper.addToList(outputList, Interpreter.Vm.CrayonWrapper.buildInteger(globals, PST_IntBuffer16[2])); } else { Interpreter.Vm.CrayonWrapper.addToList(outputList, globals.valueNull); } if (((mask & 2) != 0)) { Interpreter.Vm.CrayonWrapper.addToList(outputList, Interpreter.Vm.CrayonWrapper.buildBoolean(globals, (PST_IntBuffer16[3] > 0))); } else { Interpreter.Vm.CrayonWrapper.addToList(outputList, globals.valueNull); } if (((mask & 4) != 0)) { Interpreter.Vm.CrayonWrapper.addToList(outputList, Interpreter.Vm.CrayonWrapper.buildFloat(globals, PST_FloatBuffer16[0])); } else { Interpreter.Vm.CrayonWrapper.addToList(outputList, globals.valueNull); } if (((mask & 8) != 0)) { Interpreter.Vm.CrayonWrapper.addToList(outputList, Interpreter.Vm.CrayonWrapper.buildFloat(globals, PST_FloatBuffer16[1])); } else { Interpreter.Vm.CrayonWrapper.addToList(outputList, globals.valueNull); } return(args[3]); }
private static Value ParseJsonDictionary(VmGlobals globals, char[] rawValue, int length, Index i) { int stringTypeId = globals.stringEmpty.type; i.Value++; // '{' SkipWhitespace(rawValue, length, i); List <string> keys = new List <string>(); List <Value> values = new List <Value>(); while (i.Value < length && rawValue[i.Value] != '}') { if (keys.Count > 0) { PopExpected(rawValue, length, i, ","); SkipWhitespace(rawValue, length, i); } Value key = ParseJsonThing(globals, rawValue, length, i); if (key.type != stringTypeId) { throw new JsonParserException(); } SkipWhitespace(rawValue, length, i); PopExpected(rawValue, length, i, ":"); SkipWhitespace(rawValue, length, i); Value value = ParseJsonThing(globals, rawValue, length, i); SkipWhitespace(rawValue, length, i); keys.Add((string)key.internalValue); values.Add(value); } if (i.Value < length) { i.Value++; // '}' } else { throw new JsonParserException(); // EOF } return(CrayonWrapper.buildStringDictionary(globals, keys.ToArray(), values.ToArray())); }
private static Value ParseJsonThing(VmGlobals globals, char[] rawValue, int length, Index i) { SkipWhitespace(rawValue, length, i); Value value = null; char c = rawValue[i.Value]; if (c == '{') { value = ParseJsonDictionary(globals, rawValue, length, i); } else if (c == '[') { value = ParseJsonList(globals, rawValue, length, i); } else if (c == '"') { value = ParseJsonString(globals, rawValue, length, i); } else if (c == '.' || c == '-' || (c >= '0' && c <= '9')) { value = ParseJsonNumber(globals, rawValue, length, i); } else if (PopIfPresent(rawValue, length, i, "true")) { value = globals.boolTrue; } else if (PopIfPresent(rawValue, length, i, "false")) { value = globals.boolFalse; } else if (PopIfPresent(rawValue, length, i, "null")) { value = globals.valueNull; } else { throw new JsonParserException(); } return(value); }
private static Value ParseJsonString(VmGlobals globals, char[] rawValue, int length, Index i) { i.Value++; // opening quote StringBuilder sb = new StringBuilder(); while (i.Value < length && rawValue[i.Value] != '"') { char c = rawValue[i.Value++]; if (c == '\\') { switch (rawValue[i.Value++]) { case '\\': c = '\\'; break; case '"': c = '"'; break; case '\'': c = '\''; break; case 'n': c = '\n'; break; case 't': c = '\t'; break; case 'r': c = '\r'; break; case '0': c = '\0'; break; default: throw new JsonParserException(); } } sb.Append(c); } if (i.Value >= length) { throw new JsonParserException(); } i.Value++; // closing quote return(CrayonWrapper.buildString(globals, sb.ToString())); }
public static Value lib_game_pump_events(VmContext vm, Value[] args) { ListImpl output = (ListImpl)args[0].internalValue; List <PlatformRelayObject> eventList = GameWindow.Instance.GetEvents(); VmGlobals globals = vm.globals; Interpreter.Vm.CrayonWrapper.clearList(output); int _len = eventList.Count; if ((_len > 0)) { int i = 0; i = 0; while ((i < _len)) { PlatformRelayObject ev = eventList[i]; Interpreter.Vm.CrayonWrapper.addToList(output, Interpreter.Vm.CrayonWrapper.buildInteger(globals, ev.type)); int t = ev.type; Interpreter.Vm.CrayonWrapper.addToList(output, Interpreter.Vm.CrayonWrapper.buildInteger(globals, ev.iarg1)); if ((t >= 32)) { Interpreter.Vm.CrayonWrapper.addToList(output, Interpreter.Vm.CrayonWrapper.buildInteger(globals, ev.iarg2)); if ((t == 37)) { Interpreter.Vm.CrayonWrapper.addToList(output, Interpreter.Vm.CrayonWrapper.buildFloat(globals, ev.farg1)); } else if (((t >= 64) && (t < 80))) { Interpreter.Vm.CrayonWrapper.addToList(output, Interpreter.Vm.CrayonWrapper.buildInteger(globals, ev.iarg3)); } } i += 1; } } return(args[0]); }
private static Value ParseJsonString(VmGlobals globals, char[] rawValue, int length, Index i) { i.Value++; // opening quote StringBuilder sb = new StringBuilder(); while (i.Value < length && rawValue[i.Value] != '"') { char c = rawValue[i.Value++]; if (c == '\\') { switch (rawValue[i.Value++]) { case '\\': sb.Append('\\'); break; case '"': sb.Append('"'); break; case '\'': sb.Append('\''); break; case 'n': sb.Append('\n'); break; case 't': sb.Append('\t'); break; case 'r': sb.Append('\r'); break; case '0': sb.Append('\0'); break; case 'u': if (i.Value + 4 < length) { char u1 = rawValue[i.Value]; char u2 = rawValue[i.Value + 1]; char u3 = rawValue[i.Value + 2]; char u4 = rawValue[i.Value + 3]; i.Value += 4; string hexValue = "" + u1 + u2 + u3 + u4; int value; if (!int.TryParse(hexValue, System.Globalization.NumberStyles.HexNumber, null, out value)) { throw new JsonParserException(); } sb.Append((char)value); } else { throw new JsonParserException(); } break; default: throw new JsonParserException(); } } else { sb.Append(c); } } if (i.Value >= length) { throw new JsonParserException(); } i.Value++; // closing quote return(CrayonWrapper.buildString(globals, sb.ToString())); }