/* Generated by Nim Compiler v2.2.4 */
#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_BaseLexer__ZspOFmN5MjfhmGOKIrGMRg tyObject_BaseLexer__ZspOFmN5MjfhmGOKIrGMRg;
typedef struct tyObject_StreamObj__nX3kZRlh8Dq3gQ2cC6DE8w tyObject_StreamObj__nX3kZRlh8Dq3gQ2cC6DE8w;
typedef struct RootObj RootObj;
typedef struct TNimTypeV2 TNimTypeV2;
typedef struct NimStrPayload NimStrPayload;
typedef struct NimStringV2 NimStringV2;
typedef struct tyObject_HSlice__OAVyDXS0QPw7LdXClfU2hA tyObject_HSlice__OAVyDXS0QPw7LdXClfU2hA;
typedef NU8 tySet_tyChar__nmiMWKVIe46vacnhAFrQvw[32];
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_BaseLexer__ZspOFmN5MjfhmGOKIrGMRg {
	RootObj Sup;
	NI bufpos;
	NimStringV2 buf;
	tyObject_StreamObj__nX3kZRlh8Dq3gQ2cC6DE8w* input;
	NI lineNumber;
	NI sentinel;
	NI lineStart;
	NI offsetBase;
	tySet_tyChar__nmiMWKVIe46vacnhAFrQvw refillChars;
};
struct tyObject_HSlice__OAVyDXS0QPw7LdXClfU2hA {
	NI a;
	NI b;
};
N_LIB_PRIVATE N_NIMCALL(void, eqcopy___pureZstreams_u676)(tyObject_StreamObj__nX3kZRlh8Dq3gQ2cC6DE8w** dest_p0, tyObject_StreamObj__nX3kZRlh8Dq3gQ2cC6DE8w* src_p1, NIM_BOOL cyclic_p2);
static N_INLINE(void, nimCopyMem)(void* dest_p0, void* source_p1, NI size_p2);
N_LIB_PRIVATE N_NIMCALL(void, eqsink___system_u2636)(NimStringV2* dest_p0, NimStringV2 src_p1);
N_NIMCALL(NimStringV2, mnewString)(NI len_p0);
N_LIB_PRIVATE N_NIMCALL(void, fillBuffer__pureZlexbase_u17)(tyObject_BaseLexer__ZspOFmN5MjfhmGOKIrGMRg* L_p0);
static N_INLINE(void, moveMem__system_u1722)(void* dest_p0, void* source_p1, NI size_p2);
N_LIB_PRIVATE N_NIMCALL(NI, readDataStr__pureZstreams_u85)(tyObject_StreamObj__nX3kZRlh8Dq3gQ2cC6DE8w* s_p0, NimStringV2* buffer_p1, tyObject_HSlice__OAVyDXS0QPw7LdXClfU2hA slice_p2);
static N_INLINE(tyObject_HSlice__OAVyDXS0QPw7LdXClfU2hA, dotdot___stdZstrbasics_u49)(NI a_p0, NI b_p1);
static N_INLINE(void, nimPrepareStrMutationV2)(NimStringV2* s_p0);
N_LIB_PRIVATE N_NIMCALL(void, nimPrepareStrMutationImpl__system_u2378)(NimStringV2* s_p0);
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__pureZlexbase_u119)(tyObject_BaseLexer__ZspOFmN5MjfhmGOKIrGMRg* L_p0);
N_LIB_PRIVATE N_NIMCALL(NI, fillBaseLexer__pureZlexbase_u73)(tyObject_BaseLexer__ZspOFmN5MjfhmGOKIrGMRg* L_p0, NI pos_p1);
N_LIB_PRIVATE N_NIMCALL(void, close__pureZstreams_u58)(tyObject_StreamObj__nX3kZRlh8Dq3gQ2cC6DE8w* s_p0);
extern NIM_BOOL nimInErrorMode__system_u4306;
static N_INLINE(void, nimCopyMem)(void* dest_p0, void* source_p1, NI size_p2) {
	void* T1_;
	T1_ = (void*)0;
	T1_ = memcpy(dest_p0, source_p1, ((size_t) (size_p2)));
}
static N_INLINE(void, moveMem__system_u1722)(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(tyObject_HSlice__OAVyDXS0QPw7LdXClfU2hA, dotdot___stdZstrbasics_u49)(NI a_p0, NI b_p1) {
	tyObject_HSlice__OAVyDXS0QPw7LdXClfU2hA result;
	result.a = a_p0;
	result.b = b_p1;
	return result;
}
static N_INLINE(void, nimPrepareStrMutationV2)(NimStringV2* s_p0) {
	{
		NIM_BOOL T3_;
		T3_ = (NIM_BOOL)0;
		T3_ = !(((*s_p0).p == ((NimStrPayload*) NIM_NIL)));
		if (!(T3_)) goto LA4_;
		T3_ = ((NI)((*(*s_p0).p).cap & ((NI)IL64(4611686018427387904))) == ((NI)IL64(4611686018427387904)));
LA4_: ;
		if (!T3_) goto LA5_;
		nimPrepareStrMutationImpl__system_u2378(s_p0);
	}
LA5_: ;
}
static N_INLINE(NIM_BOOL*, nimErrorFlag)(void) {
	NIM_BOOL* result;
	result = (&nimInErrorMode__system_u4306);
	return result;
}
N_LIB_PRIVATE N_NIMCALL(void, fillBuffer__pureZlexbase_u17)(tyObject_BaseLexer__ZspOFmN5MjfhmGOKIrGMRg* L_p0) {
	NI charsRead_1;
	NI toCopy_1;
	NI s_1;
	NI oldBufLen_1;
	tyObject_StreamObj__nX3kZRlh8Dq3gQ2cC6DE8w* T6_;
	tyObject_HSlice__OAVyDXS0QPw7LdXClfU2hA T7_;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	charsRead_1 = (NI)0;
	toCopy_1 = (NI)0;
	s_1 = (NI)0;
	oldBufLen_1 = (NI)0;
	toCopy_1 = (NI)((*L_p0).buf.len - (NI)((*L_p0).sentinel + ((NI)1)));
	{
		void* T5_;
		if (!(((NI)0) < toCopy_1)) goto LA3_;
		T5_ = (void*)0;
		T5_ = ((void*) ((&(*L_p0).buf.p->data[((NI)0)])));
		moveMem__system_u1722(T5_, ((void*) ((&(*L_p0).buf.p->data[(NI)((*L_p0).sentinel + ((NI)1))]))), (toCopy_1));
	}
LA3_: ;
	T6_ = NIM_NIL;
	T6_ = (*L_p0).input;
	T7_ = dotdot___stdZstrbasics_u49(toCopy_1, (NI)((NI)((NI)(toCopy_1 + (*L_p0).sentinel) + ((NI)1)) - ((NI)1)));
	charsRead_1 = readDataStr__pureZstreams_u85(T6_, (&(*L_p0).buf), T7_);
	if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	s_1 = (NI)(toCopy_1 + charsRead_1);
	{
		if (!(charsRead_1 < (NI)((*L_p0).sentinel + ((NI)1)))) goto LA10_;
		nimPrepareStrMutationV2((&(*L_p0).buf));
		(*L_p0).buf.p->data[s_1] = 0;
		(*L_p0).sentinel = s_1;
	}
	goto LA8_;
LA10_: ;
	{
		s_1 -= ((NI)1);
		{
			while (1) {
				{
					while (1) {
						NIM_BOOL T17_;
						T17_ = (NIM_BOOL)0;
						T17_ = (((NI)0) <= s_1);
						if (!(T17_)) goto LA18_;
						T17_ = !((((*L_p0).refillChars[(NU)((((NU8)((*L_p0).buf.p->data[s_1]))))>>3] &(1U<<((NU)((((NU8)((*L_p0).buf.p->data[s_1]))))&7U)))!=0));
LA18_: ;
						if (!T17_) goto LA16;
						s_1 -= ((NI)1);
					} LA16: ;
				}
				{
					if (!(((NI)0) <= s_1)) goto LA21_;
					(*L_p0).sentinel = s_1;
					goto LA13;
				}
				goto LA19_;
LA21_: ;
				{
					tyObject_StreamObj__nX3kZRlh8Dq3gQ2cC6DE8w* T24_;
					tyObject_HSlice__OAVyDXS0QPw7LdXClfU2hA T25_;
					oldBufLen_1 = (*L_p0).buf.len;
					setLengthStrV2((&(*L_p0).buf), ((NI)((*L_p0).buf.len * ((NI)2))));
					T24_ = NIM_NIL;
					T24_ = (*L_p0).input;
					T25_ = dotdot___stdZstrbasics_u49(oldBufLen_1, (NI)((*L_p0).buf.len - ((NI)1)));
					charsRead_1 = readDataStr__pureZstreams_u85(T24_, (&(*L_p0).buf), T25_);
					if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
					{
						if (!(charsRead_1 < oldBufLen_1)) goto LA28_;
						nimPrepareStrMutationV2((&(*L_p0).buf));
						(*L_p0).buf.p->data[(NI)(oldBufLen_1 + charsRead_1)] = 0;
						(*L_p0).sentinel = (NI)(oldBufLen_1 + charsRead_1);
						goto LA13;
					}
LA28_: ;
					s_1 = (NI)((*L_p0).buf.len - ((NI)1));
				}
LA19_: ;
			}
		} LA13: ;
	}
LA8_: ;
	}BeforeRet_: ;
}
N_LIB_PRIVATE N_NIMCALL(void, skipUtf8Bom__pureZlexbase_u119)(tyObject_BaseLexer__ZspOFmN5MjfhmGOKIrGMRg* L_p0) {
	{
		NIM_BOOL T3_;
		NIM_BOOL T4_;
		T3_ = (NIM_BOOL)0;
		T4_ = (NIM_BOOL)0;
		T4_ = ((NU8)((*L_p0).buf.p->data[((NI)0)]) == (NU8)(239));
		if (!(T4_)) goto LA5_;
		T4_ = ((NU8)((*L_p0).buf.p->data[((NI)1)]) == (NU8)(187));
LA5_: ;
		T3_ = T4_;
		if (!(T3_)) goto LA6_;
		T3_ = ((NU8)((*L_p0).buf.p->data[((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, open__pureZlexbase_u131)(tyObject_BaseLexer__ZspOFmN5MjfhmGOKIrGMRg* L_p0, tyObject_StreamObj__nX3kZRlh8Dq3gQ2cC6DE8w* input_p1, NI bufLen_p2, tySet_tyChar__nmiMWKVIe46vacnhAFrQvw refillChars_p3) {
	NimStringV2 T1_;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	eqcopy___pureZstreams_u676(&(*L_p0).input, input_p1, NIM_TRUE);
	(*L_p0).bufpos = ((NI)0);
	(*L_p0).offsetBase = ((NI)0);
	nimCopyMem((void*)(*L_p0).refillChars, (NIM_CONST void*)refillChars_p3, 32);
	T1_.len = 0; T1_.p = NIM_NIL;
	T1_ = mnewString((bufLen_p2));
	eqsink___system_u2636((&(*L_p0).buf), T1_);
	(*L_p0).sentinel = (NI)(bufLen_p2 - ((NI)1));
	(*L_p0).lineStart = ((NI)0);
	(*L_p0).lineNumber = ((NI)1);
	fillBuffer__pureZlexbase_u17(L_p0);
	if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	skipUtf8Bom__pureZlexbase_u119(L_p0);
	if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}BeforeRet_: ;
}
N_LIB_PRIVATE N_NIMCALL(NI, fillBaseLexer__pureZlexbase_u73)(tyObject_BaseLexer__ZspOFmN5MjfhmGOKIrGMRg* 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__pureZlexbase_u17(L_p0);
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
		(*L_p0).offsetBase += pos_p1;
		(*L_p0).bufpos = ((NI)0);
		result = ((NI)0);
	}
LA1_: ;
	}BeforeRet_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NI, handleCR__pureZlexbase_u84)(tyObject_BaseLexer__ZspOFmN5MjfhmGOKIrGMRg* L_p0, NI pos_p1) {
	NI result;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	result = (NI)0;
	(*L_p0).lineNumber += ((NI)1);
	result = fillBaseLexer__pureZlexbase_u73(L_p0, pos_p1);
	if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	{
		if (!((NU8)((*L_p0).buf.p->data[result]) == (NU8)(10))) goto LA3_;
		result = fillBaseLexer__pureZlexbase_u73(L_p0, result);
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}
LA3_: ;
	(*L_p0).lineStart = result;
	}BeforeRet_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NI, handleLF__pureZlexbase_u96)(tyObject_BaseLexer__ZspOFmN5MjfhmGOKIrGMRg* L_p0, NI pos_p1) {
	NI result;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	result = (NI)0;
	(*L_p0).lineNumber += ((NI)1);
	result = fillBaseLexer__pureZlexbase_u73(L_p0, pos_p1);
	if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	(*L_p0).lineStart = result;
	}BeforeRet_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NI, getColNumber__pureZlexbase_u146)(tyObject_BaseLexer__ZspOFmN5MjfhmGOKIrGMRg* 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(void, close__pureZlexbase_u15)(tyObject_BaseLexer__ZspOFmN5MjfhmGOKIrGMRg* L_p0) {
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	close__pureZstreams_u58((*L_p0).input);
	if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}BeforeRet_: ;
}
