haxe/src/haxe/format/JsonParser.cs
// Generated by Haxe 4.3.7

#pragma warning disable 109, 114, 219, 429, 168, 162
namespace haxe.format {
	public class JsonParser : global::haxe.lang.HxObject {
		
		public JsonParser(global::haxe.lang.EmptyObject empty) {
		}
		
		
		public JsonParser(string str) {
			global::haxe.format.JsonParser.__hx_ctor_haxe_format_JsonParser(this, str);
		}
		
		
		protected static void __hx_ctor_haxe_format_JsonParser(global::haxe.format.JsonParser __hx_this, string str) {
			__hx_this.str = str;
			__hx_this.pos = 0;
		}
		
		
		public static object parse(string str) {
			return new global::haxe.format.JsonParser(((string) (str) )).doParse();
		}
		
		
		public string str;
		
		public int pos;
		
		public virtual object doParse() {
			unchecked {
				object result = this.parseRec();
				int c = default(int);
				while (true) {
					c = this.nextChar();
					if (global::StringTools.isEof(c)) {
						break;
					}
					
					switch (c) {
						case 9:
						case 10:
						case 13:
						case 32:
						{
							break;
						}
						
						
						default:
						{
							this.invalidChar();
							break;
						}
						
					}
					
				}
				
				return result;
			}
		}
		
		
		public virtual object parseRec() {
			unchecked {
				while (true) {
					int c = this.nextChar();
					switch (c) {
						case 9:
						case 10:
						case 13:
						case 32:
						{
							break;
						}
						
						
						case 34:
						{
							return this.parseString();
						}
						
						
						case 45:
						case 48:
						case 49:
						case 50:
						case 51:
						case 52:
						case 53:
						case 54:
						case 55:
						case 56:
						case 57:
						{
							return this.parseNumber(c);
						}
						
						
						case 91:
						{
							global::Array arr = new global::Array<object>(new object[]{});
							global::haxe.lang.Null<bool> comma = default(global::haxe.lang.Null<bool>);
							while (true) {
								int c1 = this.nextChar();
								switch (c1) {
									case 9:
									case 10:
									case 13:
									case 32:
									{
										break;
									}
									
									
									case 44:
									{
										if (((comma)).@value) {
											comma = new global::haxe.lang.Null<bool>(false, true);
										}
										else {
											this.invalidChar();
										}
										
										break;
									}
									
									
									case 93:
									{
										if (global::haxe.lang.Runtime.eq((comma).toDynamic(), false)) {
											this.invalidChar();
										}
										
										return arr;
									}
									
									
									default:
									{
										if (((comma)).@value) {
											this.invalidChar();
										}
										
										this.pos--;
										int __temp_expr1 = ((int) (global::haxe.lang.Runtime.toInt(global::haxe.lang.Runtime.callField(arr, "push", 1247875546, new object[]{this.parseRec()}))) );
										comma = new global::haxe.lang.Null<bool>(true, true);
										break;
									}
									
								}
								
							}
							
							break;
						}
						
						
						case 102:
						{
							int save = this.pos;
							if (( ( ( ( this.nextChar() != 97 ) || ( this.nextChar() != 108 ) ) || ( this.nextChar() != 115 ) ) || ( this.nextChar() != 101 ) )) {
								this.pos = save;
								this.invalidChar();
							}
							
							return false;
						}
						
						
						case 110:
						{
							int save1 = this.pos;
							if (( ( ( this.nextChar() != 117 ) || ( this.nextChar() != 108 ) ) || ( this.nextChar() != 108 ) )) {
								this.pos = save1;
								this.invalidChar();
							}
							
							return null;
						}
						
						
						case 116:
						{
							int save2 = this.pos;
							if (( ( ( this.nextChar() != 114 ) || ( this.nextChar() != 117 ) ) || ( this.nextChar() != 101 ) )) {
								this.pos = save2;
								this.invalidChar();
							}
							
							return true;
						}
						
						
						case 123:
						{
							object obj = new global::haxe.lang.DynamicObject(new int[]{}, new object[]{}, new int[]{}, new double[]{});
							string field = null;
							global::haxe.lang.Null<bool> comma1 = default(global::haxe.lang.Null<bool>);
							while (true) {
								int c2 = this.nextChar();
								switch (c2) {
									case 9:
									case 10:
									case 13:
									case 32:
									{
										break;
									}
									
									
									case 34:
									{
										if (( ( field != null ) || (comma1).@value )) {
											this.invalidChar();
										}
										
										field = this.parseString();
										break;
									}
									
									
									case 44:
									{
										if (((comma1)).@value) {
											comma1 = new global::haxe.lang.Null<bool>(false, true);
										}
										else {
											this.invalidChar();
										}
										
										break;
									}
									
									
									case 58:
									{
										if (( field == null )) {
											this.invalidChar();
										}
										
										global::Reflect.setField(obj, field, this.parseRec());
										field = null;
										comma1 = new global::haxe.lang.Null<bool>(true, true);
										break;
									}
									
									
									case 125:
									{
										if (( ( field != null ) || global::haxe.lang.Runtime.eq((comma1).toDynamic(), false) )) {
											this.invalidChar();
										}
										
										return obj;
									}
									
									
									default:
									{
										this.invalidChar();
										break;
									}
									
								}
								
							}
							
							break;
						}
						
						
						default:
						{
							this.invalidChar();
							break;
						}
						
					}
					
				}
				
				return null;
			}
		}
		
		
		public virtual string parseString() {
			unchecked {
				int start = this.pos;
				global::StringBuf buf = null;
				int prev = -1;
				while (true) {
					int c = this.nextChar();
					if (( c == 34 )) {
						break;
					}
					
					if (( c == 92 )) {
						if (( buf == null )) {
							buf = new global::StringBuf();
						}
						
						buf.addSub(this.str, start, new global::haxe.lang.Null<int>(( ( this.pos - start ) - 1 ), true));
						c = this.nextChar();
						if (( ( c != 117 ) && ( prev != -1 ) )) {
							buf.addChar(65533);
							prev = -1;
						}
						
						switch (c) {
							case 34:
							case 47:
							case 92:
							{
								buf.addChar(c);
								break;
							}
							
							
							case 98:
							{
								buf.addChar(8);
								break;
							}
							
							
							case 102:
							{
								buf.addChar(12);
								break;
							}
							
							
							case 110:
							{
								buf.addChar(10);
								break;
							}
							
							
							case 114:
							{
								buf.addChar(13);
								break;
							}
							
							
							case 116:
							{
								buf.addChar(9);
								break;
							}
							
							
							case 117:
							{
								int uc = (global::Std.parseInt(global::haxe.lang.Runtime.concat("0x", global::haxe.lang.StringExt.substr(this.str, this.pos, new global::haxe.lang.Null<int>(4, true))))).@value;
								this.pos += 4;
								if (( prev != -1 )) {
									if (( ( uc < 56320 ) || ( uc > 57343 ) )) {
										buf.addChar(65533);
										prev = -1;
									}
									else {
										buf.addChar(( ( (( ( prev - 55296 ) << 10 )) + (( uc - 56320 )) ) + 65536 ));
										prev = -1;
									}
									
								}
								else if (( ( uc >= 55296 ) && ( uc <= 56319 ) )) {
									prev = uc;
								}
								else {
									buf.addChar(uc);
								}
								
								break;
							}
							
							
							default:
							{
								throw ((global::System.Exception) (global::haxe.Exception.thrown(global::haxe.lang.Runtime.concat(global::haxe.lang.Runtime.concat(global::haxe.lang.Runtime.concat("Invalid escape sequence \\", global::haxe.lang.StringExt.fromCharCode(c)), " at position "), global::haxe.lang.Runtime.toString((( this.pos - 1 )))))) );
							}
							
						}
						
						start = this.pos;
					}
					else if (global::StringTools.isEof(c)) {
						throw ((global::System.Exception) (global::haxe.Exception.thrown("Unclosed string")) );
					}
					
				}
				
				if (( prev != -1 )) {
					buf.addChar(65533);
					prev = -1;
				}
				
				if (( buf == null )) {
					return global::haxe.lang.StringExt.substr(this.str, start, new global::haxe.lang.Null<int>(( ( this.pos - start ) - 1 ), true));
				}
				else {
					buf.addSub(this.str, start, new global::haxe.lang.Null<int>(( ( this.pos - start ) - 1 ), true));
					return buf.toString();
				}
				
			}
		}
		
		
		public object parseNumber(int c) {
			unchecked {
				int start = ( this.pos - 1 );
				bool minus = ( c == 45 );
				bool digit =  ! (minus) ;
				bool zero = ( c == 48 );
				bool point = false;
				bool e = false;
				bool pm = false;
				bool end = false;
				do {
					c = this.nextChar();
					switch (c) {
						case 43:
						case 45:
						{
							if ((  ! (e)  || pm )) {
								this.invalidNumber(start);
							}
							
							digit = false;
							pm = true;
							break;
						}
						
						
						case 46:
						{
							if (( ( minus || point ) || e )) {
								this.invalidNumber(start);
							}
							
							digit = false;
							point = true;
							break;
						}
						
						
						case 48:
						{
							if (( zero &&  ! (point)  )) {
								this.invalidNumber(start);
							}
							
							if (minus) {
								minus = false;
								zero = true;
							}
							
							digit = true;
							break;
						}
						
						
						case 49:
						case 50:
						case 51:
						case 52:
						case 53:
						case 54:
						case 55:
						case 56:
						case 57:
						{
							if (( zero &&  ! (point)  )) {
								this.invalidNumber(start);
							}
							
							if (minus) {
								minus = false;
							}
							
							digit = true;
							zero = false;
							break;
						}
						
						
						case 69:
						case 101:
						{
							if (( ( minus || zero ) || e )) {
								this.invalidNumber(start);
							}
							
							digit = false;
							e = true;
							break;
						}
						
						
						default:
						{
							if ( ! (digit) ) {
								this.invalidNumber(start);
							}
							
							this.pos--;
							end = true;
							break;
						}
						
					}
					
				}
				while ( ! (end) );
				double f = global::Std.parseFloat(global::haxe.lang.StringExt.substr(this.str, start, new global::haxe.lang.Null<int>(( this.pos - start ), true)));
				if (point) {
					return f;
				}
				else {
					int i = ((int) (f) );
					if (( i == f )) {
						return i;
					}
					else {
						return f;
					}
					
				}
				
			}
		}
		
		
		public int nextChar() {
			return global::StringTools.fastCodeAt(this.str, this.pos++);
		}
		
		
		public virtual void invalidChar() {
			this.pos--;
			throw ((global::System.Exception) (global::haxe.Exception.thrown(global::haxe.lang.Runtime.concat(global::haxe.lang.Runtime.concat(global::haxe.lang.Runtime.concat("Invalid char ", global::haxe.lang.Runtime.toString(global::StringTools.fastCodeAt(this.str, this.pos))), " at position "), global::haxe.lang.Runtime.toString(this.pos)))) );
		}
		
		
		public virtual void invalidNumber(int start) {
			throw ((global::System.Exception) (global::haxe.Exception.thrown(global::haxe.lang.Runtime.concat(global::haxe.lang.Runtime.concat(global::haxe.lang.Runtime.concat("Invalid number at position ", global::haxe.lang.Runtime.toString(start)), ": "), global::haxe.lang.StringExt.substr(this.str, start, new global::haxe.lang.Null<int>(( this.pos - start ), true))))) );
		}
		
		
		public override double __hx_setField_f(string field, int hash, double @value, bool handleProperties) {
			unchecked {
				switch (hash) {
					case 5594516:
					{
						this.pos = ((int) (@value) );
						return @value;
					}
					
					
					default:
					{
						return base.__hx_setField_f(field, hash, @value, handleProperties);
					}
					
				}
				
			}
		}
		
		
		public override object __hx_setField(string field, int hash, object @value, bool handleProperties) {
			unchecked {
				switch (hash) {
					case 5594516:
					{
						this.pos = ((int) (global::haxe.lang.Runtime.toInt(@value)) );
						return @value;
					}
					
					
					case 5744817:
					{
						this.str = global::haxe.lang.Runtime.toString(@value);
						return @value;
					}
					
					
					default:
					{
						return base.__hx_setField(field, hash, @value, handleProperties);
					}
					
				}
				
			}
		}
		
		
		public override object __hx_getField(string field, int hash, bool throwErrors, bool isCheck, bool handleProperties) {
			unchecked {
				switch (hash) {
					case 652994848:
					{
						return ((global::haxe.lang.Function) (new global::haxe.lang.Closure(this, "invalidNumber", 652994848)) );
					}
					
					
					case 701410669:
					{
						return ((global::haxe.lang.Function) (new global::haxe.lang.Closure(this, "invalidChar", 701410669)) );
					}
					
					
					case 1837892969:
					{
						return ((global::haxe.lang.Function) (new global::haxe.lang.Closure(this, "nextChar", 1837892969)) );
					}
					
					
					case 481768284:
					{
						return ((global::haxe.lang.Function) (new global::haxe.lang.Closure(this, "parseNumber", 481768284)) );
					}
					
					
					case 208459108:
					{
						return ((global::haxe.lang.Function) (new global::haxe.lang.Closure(this, "parseString", 208459108)) );
					}
					
					
					case 1450762973:
					{
						return ((global::haxe.lang.Function) (new global::haxe.lang.Closure(this, "parseRec", 1450762973)) );
					}
					
					
					case 1887596712:
					{
						return ((global::haxe.lang.Function) (new global::haxe.lang.Closure(this, "doParse", 1887596712)) );
					}
					
					
					case 5594516:
					{
						return this.pos;
					}
					
					
					case 5744817:
					{
						return this.str;
					}
					
					
					default:
					{
						return base.__hx_getField(field, hash, throwErrors, isCheck, handleProperties);
					}
					
				}
				
			}
		}
		
		
		public override double __hx_getField_f(string field, int hash, bool throwErrors, bool handleProperties) {
			unchecked {
				switch (hash) {
					case 5594516:
					{
						return ((double) (this.pos) );
					}
					
					
					default:
					{
						return base.__hx_getField_f(field, hash, throwErrors, handleProperties);
					}
					
				}
				
			}
		}
		
		
		public override object __hx_invokeField(string field, int hash, object[] dynargs) {
			unchecked {
				switch (hash) {
					case 652994848:
					{
						this.invalidNumber(((int) (global::haxe.lang.Runtime.toInt(dynargs[0])) ));
						break;
					}
					
					
					case 701410669:
					{
						this.invalidChar();
						break;
					}
					
					
					case 1837892969:
					{
						return this.nextChar();
					}
					
					
					case 481768284:
					{
						return this.parseNumber(((int) (global::haxe.lang.Runtime.toInt(dynargs[0])) ));
					}
					
					
					case 208459108:
					{
						return this.parseString();
					}
					
					
					case 1450762973:
					{
						return this.parseRec();
					}
					
					
					case 1887596712:
					{
						return this.doParse();
					}
					
					
					default:
					{
						return base.__hx_invokeField(field, hash, dynargs);
					}
					
				}
				
				return null;
			}
		}
		
		
		public override void __hx_getFields(global::Array<string> baseArr) {
			baseArr.push("pos");
			baseArr.push("str");
			base.__hx_getFields(baseArr);
		}
		
		
	}
}