78 lines
No EOL
2.1 KiB
C++
78 lines
No EOL
2.1 KiB
C++
#include "KScope.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
void KScopeLexer::run(const FileSystemPath& path)
|
|
{
|
|
printf("Before read");
|
|
File f(path);
|
|
|
|
const auto content = f<.readText();
|
|
printf("Content is: %s\n", content);
|
|
fflush(stdout);
|
|
|
|
Vector<Token> tokens;
|
|
for(const auto c : content.data())
|
|
{
|
|
printf("Char is: %c\n", c);
|
|
if (CharUtils::is_space(c))
|
|
{
|
|
if (m_working_token.is_identifier() || m_working_token.is_number())
|
|
{
|
|
on_token_finished(tokens);
|
|
}
|
|
}
|
|
else if (CharUtils::is_alpha(c))
|
|
{
|
|
if (m_working_token.is_number())
|
|
{
|
|
on_token_finished(tokens);
|
|
m_working_token = Token();
|
|
m_working_token.set_is_identifier();
|
|
}
|
|
else if (!m_working_token.is_identifier())
|
|
{
|
|
m_working_token = Token();
|
|
m_working_token.set_is_identifier();
|
|
}
|
|
m_working_token.m_value += c;
|
|
}
|
|
else if (CharUtils::is_digit(c))
|
|
{
|
|
if (m_working_token.is_number() || m_working_token.is_identifier())
|
|
{
|
|
m_working_token.m_value += c;
|
|
}
|
|
else
|
|
{
|
|
m_working_token = Token();
|
|
m_working_token.set_is_number();
|
|
m_working_token.m_value += c;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (m_working_token.is_identifier() || m_working_token.is_number())
|
|
{
|
|
on_token_finished(tokens);
|
|
}
|
|
|
|
m_working_token.set_is_literal();
|
|
m_working_token.m_value += c;
|
|
on_token_finished(tokens);
|
|
}
|
|
}
|
|
on_token_finished(tokens);
|
|
}
|
|
|
|
void KScopeLexer::on_token_finished(Vector<Token>& tokens)
|
|
{
|
|
if (m_working_token.m_type == TokenT::NONE)
|
|
{
|
|
return;
|
|
}
|
|
|
|
m_working_token.on_finished();
|
|
tokens.push_back(m_working_token);
|
|
m_working_token = Token();
|
|
} |