Esempio n. 1
0
void IoMessage_parseName(IoMessage *self, IoLexer *lexer)
{
	IoToken *token = IoLexer_pop(lexer);

	DATA(self)->name = IOREF(IOSYMBOL(IoToken_name(token)));

	IoMessage_ifPossibleCacheToken_(self, token);
	IoMessage_rawSetLineNumber_(self, IoToken_lineNumber(token));
	IoMessage_rawSetCharNumber_(self, IoToken_charNumber(token));
}
Esempio n. 2
0
IO_METHOD(IoObject, tokensForString)
{
	/*doc Compiler tokensForString(aString)
	Returns a list of token objects lexed from the input string.
*/

	IoSymbol *text = IoMessage_locals_seqArgAt_(m, locals, 0);
	IoList *tokensList = IoList_new(IOSTATE);
	IoLexer *lexer = IoLexer_new();
	IoSymbol *name = IOSYMBOL("name");
	IoSymbol *line = IOSYMBOL("line");
	IoSymbol *character = IOSYMBOL("character");
	IoSymbol *type = IOSYMBOL("type");

	IoLexer_string_(lexer, CSTRING(text));
	IoLexer_lex(lexer);

	if (IoLexer_errorToken(lexer))
	{
		IoSymbol *errorString  = IOSYMBOL(IoLexer_errorDescription(lexer));
		IoLexer_free(lexer);
		IoState_error_(IOSTATE, NULL, "compile error: %s", CSTRING(errorString));
	}
	else
	{
		IoToken *t;

		while ((t = IoLexer_pop(lexer)))
		{
			IoObject *tokenObject = IoObject_new(IOSTATE);

			IoObject_setSlot_to_(tokenObject, name, IOSYMBOL(IoToken_name(t)));
			IoObject_setSlot_to_(tokenObject, line, IONUMBER(IoToken_lineNumber(t)));
			IoObject_setSlot_to_(tokenObject, character, IONUMBER(IoToken_charNumber(t)));
			IoObject_setSlot_to_(tokenObject, type, IOSYMBOL(IoToken_typeName(t)));

			IoList_rawAppend_(tokensList, tokenObject);
		}
	}

	IoLexer_free(lexer);

	return tokensList;
}