/* Generated by Nim Compiler v2.2.10 */
#define NIM_INTBITS 64

#include "nimbase.h"
#include <string.h>
#undef LANGUAGE_C
#undef MIPSEB
#undef MIPSEL
#undef PPC
#undef R3000
#undef R4000
#undef i386
#undef linux
#undef mips
#undef near
#undef far
#undef powerpc
#undef unix
typedef struct tyObject_TBaseLexer__bW0Cb4KmUu6wcIZW6Cp0nw tyObject_TBaseLexer__bW0Cb4KmUu6wcIZW6Cp0nw;
typedef struct tyObject_TLLStream__FoDsO8lsQbcCVaLehnuOYg tyObject_TLLStream__FoDsO8lsQbcCVaLehnuOYg;
typedef struct RootObj RootObj;
typedef struct TNimTypeV2 TNimTypeV2;
typedef struct NimStrPayload NimStrPayload;
typedef struct NimStringV2 NimStringV2;
struct TNimTypeV2 {
	void* destructor;
	NI size;
	NI16 align;
	NI16 depth;
	NU32* display;
	void* traceImpl;
	void* typeInfoV1;
	NI flags;
	void* vTable[SEQ_DECL_SIZE];
};
struct RootObj {
	TNimTypeV2* m_type;
};
struct NimStrPayload {
	NI cap;
	NIM_CHAR data[SEQ_DECL_SIZE];
};
struct NimStringV2 {
	NI len;
	NimStrPayload* p;
};
struct tyObject_TBaseLexer__bW0Cb4KmUu6wcIZW6Cp0nw {
	RootObj Sup;
	NI bufpos;
	NCSTRING buf;
	NimStringV2 bufStorage;
	NI bufLen;
	tyObject_TLLStream__FoDsO8lsQbcCVaLehnuOYg* stream;
	NI lineNumber;
	NI sentinel;
	NI lineStart;
	NI offsetBase;
};
N_LIB_PRIVATE N_NIMCALL(void, eqsink___system_u2700)(NimStringV2* dest_p0, NimStringV2 src_p1);
N_NIMCALL(NimStringV2, mnewString)(NI len_p0);
static N_INLINE(NCSTRING, nimToCStringConv)(NimStringV2 s_p0);
N_LIB_PRIVATE N_NIMCALL(void, eqcopy___llstream_u115)(tyObject_TLLStream__FoDsO8lsQbcCVaLehnuOYg** dest_p0, tyObject_TLLStream__FoDsO8lsQbcCVaLehnuOYg* src_p1, NIM_BOOL cyclic_p2);
N_LIB_PRIVATE N_NIMCALL(void, fillBuffer__nimlexbase_u46)(tyObject_TBaseLexer__bW0Cb4KmUu6wcIZW6Cp0nw* L_p0);
static N_INLINE(void, moveMem__system_u1746)(void* dest_p0, void* source_p1, NI size_p2);
N_LIB_PRIVATE N_NIMCALL(NI, llStreamRead__llstream_u469)(tyObject_TLLStream__FoDsO8lsQbcCVaLehnuOYg* s_p0, void* buf_p1, NI bufLen_p2);
N_LIB_PRIVATE N_NIMCALL(void, setLengthStrV2)(NimStringV2* s_p0, NI newLen_p1);
static N_INLINE(NIM_BOOL*, nimErrorFlag)(void);
N_LIB_PRIVATE N_NIMCALL(void, skipUTF8BOM__nimlexbase_u113)(tyObject_TBaseLexer__bW0Cb4KmUu6wcIZW6Cp0nw* L_p0);
N_LIB_PRIVATE N_NIMCALL(NI, fillBaseLexer__nimlexbase_u78)(tyObject_TBaseLexer__bW0Cb4KmUu6wcIZW6Cp0nw* L_p0, NI pos_p1);
N_LIB_PRIVATE N_NIMCALL(void, llStreamClose__llstream_u214)(tyObject_TLLStream__FoDsO8lsQbcCVaLehnuOYg* s_p0);
extern NIM_BOOL nimInErrorMode__system_u4146;
static N_INLINE(NCSTRING, nimToCStringConv)(NimStringV2 s_p0) {
	NCSTRING result;
	{
		if (!(s_p0.len == ((NI)0))) goto LA3_;
		result = "";
	}
	goto LA1_;
LA3_: ;
	{
		result = ((NCSTRING) ((*s_p0.p).data));
	}
LA1_: ;
	return result;
}
static N_INLINE(void, moveMem__system_u1746)(void* dest_p0, void* source_p1, NI size_p2) {
	void* T1_;
	T1_ = (void*)0;
	T1_ = memmove(dest_p0, source_p1, ((size_t) (size_p2)));
}
static N_INLINE(NIM_BOOL*, nimErrorFlag)(void) {
	NIM_BOOL* result;
	result = (&nimInErrorMode__system_u4146);
	return result;
}
N_LIB_PRIVATE N_NIMCALL(void, fillBuffer__nimlexbase_u46)(tyObject_TBaseLexer__bW0Cb4KmUu6wcIZW6Cp0nw* L_p0) {
	NI charsRead_1;
	NI toCopy_1;
	NI s_1;
	NI oldBufLen_1;
	tyObject_TLLStream__FoDsO8lsQbcCVaLehnuOYg* T6_;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	charsRead_1 = (NI)0;
	toCopy_1 = (NI)0;
	s_1 = (NI)0;
	oldBufLen_1 = (NI)0;
	toCopy_1 = (NI)((NI)((*L_p0).bufLen - (*L_p0).sentinel) - ((NI)1));
	{
		void* T5_;
		if (!(((NI)0) < toCopy_1)) goto LA3_;
		T5_ = (void*)0;
		T5_ = ((void*) ((&(*L_p0).buf[((NI)0)])));
		moveMem__system_u1746(T5_, ((void*) ((&(*L_p0).buf[(NI)((*L_p0).sentinel + ((NI)1))]))), (toCopy_1));
	}
LA3_: ;
	T6_ = NIM_NIL;
	T6_ = (*L_p0).stream;
	charsRead_1 = llStreamRead__llstream_u469(T6_, ((void*) ((&(*L_p0).buf[toCopy_1]))), (NI)((*L_p0).sentinel + ((NI)1)));
	if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	s_1 = (NI)(toCopy_1 + charsRead_1);
	{
		if (!(charsRead_1 < (NI)((*L_p0).sentinel + ((NI)1)))) goto LA9_;
		(*L_p0).buf[s_1] = 0;
		(*L_p0).sentinel = s_1;
	}
	goto LA7_;
LA9_: ;
	{
		s_1 -= ((NI)1);
		{
			while (1) {
				{
					while (1) {
						NIM_BOOL T16_;
						T16_ = (NIM_BOOL)0;
						T16_ = (((NI)0) <= s_1);
						if (!(T16_)) goto LA17_;
						T16_ = !((((NU8)((*L_p0).buf[s_1])) == ((NU8)(13)) || ((NU8)((*L_p0).buf[s_1])) == ((NU8)(10))));
LA17_: ;
						if (!T16_) goto LA15;
						s_1 -= ((NI)1);
					} LA15: ;
				}
				{
					if (!(((NI)0) <= s_1)) goto LA20_;
					(*L_p0).sentinel = s_1;
					goto LA12;
				}
				goto LA18_;
LA20_: ;
				{
					tyObject_TLLStream__FoDsO8lsQbcCVaLehnuOYg* T23_;
					oldBufLen_1 = (*L_p0).bufLen;
					(*L_p0).bufLen = (NI)((*L_p0).bufLen * ((NI)2));
					setLengthStrV2((&(*L_p0).bufStorage), ((*L_p0).bufLen));
					(*L_p0).buf = nimToCStringConv((*L_p0).bufStorage);
					T23_ = NIM_NIL;
					T23_ = (*L_p0).stream;
					charsRead_1 = llStreamRead__llstream_u469(T23_, ((void*) ((&(*L_p0).buf[oldBufLen_1]))), oldBufLen_1);
					if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
					{
						if (!(charsRead_1 < oldBufLen_1)) goto LA26_;
						(*L_p0).buf[(NI)(oldBufLen_1 + charsRead_1)] = 0;
						(*L_p0).sentinel = (NI)(oldBufLen_1 + charsRead_1);
						goto LA12;
					}
LA26_: ;
					s_1 = (NI)((*L_p0).bufLen - ((NI)1));
				}
LA18_: ;
			}
		} LA12: ;
	}
LA7_: ;
	}BeforeRet_: ;
}
N_LIB_PRIVATE N_NIMCALL(void, skipUTF8BOM__nimlexbase_u113)(tyObject_TBaseLexer__bW0Cb4KmUu6wcIZW6Cp0nw* L_p0) {
	{
		NIM_BOOL T3_;
		NIM_BOOL T4_;
		T3_ = (NIM_BOOL)0;
		T4_ = (NIM_BOOL)0;
		T4_ = ((NU8)((*L_p0).buf[((NI)0)]) == (NU8)(239));
		if (!(T4_)) goto LA5_;
		T4_ = ((NU8)((*L_p0).buf[((NI)1)]) == (NU8)(187));
LA5_: ;
		T3_ = T4_;
		if (!(T3_)) goto LA6_;
		T3_ = ((NU8)((*L_p0).buf[((NI)2)]) == (NU8)(191));
LA6_: ;
		if (!T3_) goto LA7_;
		(*L_p0).bufpos += ((NI)3);
		(*L_p0).lineStart += ((NI)3);
	}
LA7_: ;
}
N_LIB_PRIVATE N_NIMCALL(void, openBaseLexer__nimlexbase_u26)(tyObject_TBaseLexer__bW0Cb4KmUu6wcIZW6Cp0nw* L_p0, tyObject_TLLStream__FoDsO8lsQbcCVaLehnuOYg* inputstream_p1, NI bufLen_p2) {
	NimStringV2 T1_;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	(*L_p0).bufpos = ((NI)0);
	(*L_p0).offsetBase = ((NI)0);
	T1_.len = 0; T1_.p = NIM_NIL;
	T1_ = mnewString((bufLen_p2));
	eqsink___system_u2700((&(*L_p0).bufStorage), T1_);
	(*L_p0).buf = nimToCStringConv((*L_p0).bufStorage);
	(*L_p0).bufLen = bufLen_p2;
	(*L_p0).sentinel = (NI)(bufLen_p2 - ((NI)1));
	(*L_p0).lineStart = ((NI)0);
	(*L_p0).lineNumber = ((NI)1);
	eqcopy___llstream_u115(&(*L_p0).stream, inputstream_p1, NIM_TRUE);
	fillBuffer__nimlexbase_u46(L_p0);
	if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	skipUTF8BOM__nimlexbase_u113(L_p0);
	if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}BeforeRet_: ;
}
N_LIB_PRIVATE N_NIMCALL(NI, getColNumber__nimlexbase_u35)(tyObject_TBaseLexer__bW0Cb4KmUu6wcIZW6Cp0nw* L_p0, NI pos_p1) {
	NI result;
	result = ((NI)(pos_p1 - (*L_p0).lineStart) > 0? ((NI)(pos_p1 - (*L_p0).lineStart)) : -((NI)(pos_p1 - (*L_p0).lineStart)));
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NI, fillBaseLexer__nimlexbase_u78)(tyObject_TBaseLexer__bW0Cb4KmUu6wcIZW6Cp0nw* L_p0, NI pos_p1) {
	NI result;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	result = (NI)0;
	{
		if (!(pos_p1 < (*L_p0).sentinel)) goto LA3_;
		result = (NI)(pos_p1 + ((NI)1));
	}
	goto LA1_;
LA3_: ;
	{
		fillBuffer__nimlexbase_u46(L_p0);
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
		(*L_p0).offsetBase += (NI)(pos_p1 + ((NI)1));
		(*L_p0).bufpos = ((NI)0);
		result = ((NI)0);
	}
LA1_: ;
	(*L_p0).lineStart = result;
	}BeforeRet_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NI, handleCR__nimlexbase_u38)(tyObject_TBaseLexer__bW0Cb4KmUu6wcIZW6Cp0nw* L_p0, NI pos_p1) {
	NI result;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	result = (NI)0;
	(*L_p0).lineNumber += ((NI)1);
	result = fillBaseLexer__nimlexbase_u78(L_p0, pos_p1);
	if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	{
		if (!((NU8)((*L_p0).buf[result]) == (NU8)(10))) goto LA3_;
		result = fillBaseLexer__nimlexbase_u78(L_p0, result);
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}
LA3_: ;
	}BeforeRet_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NI, handleLF__nimlexbase_u41)(tyObject_TBaseLexer__bW0Cb4KmUu6wcIZW6Cp0nw* L_p0, NI pos_p1) {
	NI result;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	result = (NI)0;
	(*L_p0).lineNumber += ((NI)1);
	result = fillBaseLexer__nimlexbase_u78(L_p0, pos_p1);
	if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}BeforeRet_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(void, closeBaseLexer__nimlexbase_u30)(tyObject_TBaseLexer__bW0Cb4KmUu6wcIZW6Cp0nw* L_p0) {
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	llStreamClose__llstream_u214((*L_p0).stream);
	if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}BeforeRet_: ;
}
