mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-20 16:15:43 +00:00
Make SimpleLexer be able to be initialized via constructor and not only via inheritence
This commit is contained in:
parent
c8214f769b
commit
56c35cb030
@ -1,9 +0,0 @@
|
||||
#include "LocalizeFileLexer.h"
|
||||
|
||||
LocalizeFileLexer::LocalizeFileLexer(IParserLineStream* stream)
|
||||
: SimpleLexer(stream)
|
||||
{
|
||||
SetShouldEmitNewLineTokens(true);
|
||||
SetShouldReadNumbers(false);
|
||||
SetShouldReadStrings(true);
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "Parsing/Simple/SimpleLexer.h"
|
||||
|
||||
class LocalizeFileLexer final : public SimpleLexer
|
||||
{
|
||||
public:
|
||||
explicit LocalizeFileLexer(IParserLineStream* stream);
|
||||
};
|
@ -1,6 +1,5 @@
|
||||
#include "LocalizeFileReader.h"
|
||||
|
||||
#include "LocalizeFileLexer.h"
|
||||
#include "LocalizeFileParser.h"
|
||||
#include "Parsing/Impl/CommentRemovingStreamProxy.h"
|
||||
#include "Parsing/Impl/ParserInputStream.h"
|
||||
@ -30,7 +29,7 @@ void LocalizeFileReader::SetupStreamProxies()
|
||||
|
||||
std::vector<LocalizeFileEntry> LocalizeFileReader::ReadLocalizeFile()
|
||||
{
|
||||
const auto lexer = std::make_unique<LocalizeFileLexer>(m_stream);
|
||||
const auto lexer = std::make_unique<SimpleLexer>(m_stream, SimpleLexer::Config{true, true, false});
|
||||
const auto parser = std::make_unique<LocalizeFileParser>(lexer.get(), m_language);
|
||||
|
||||
if (parser->Parse())
|
||||
|
@ -2,33 +2,23 @@
|
||||
|
||||
SimpleLexer::SimpleLexer(IParserLineStream* stream)
|
||||
: AbstractLexer(stream),
|
||||
m_emit_new_line_tokens(false),
|
||||
m_read_strings(true),
|
||||
m_read_numbers(true),
|
||||
m_config{false, true, true},
|
||||
m_last_line(1)
|
||||
{
|
||||
}
|
||||
|
||||
void SimpleLexer::SetShouldEmitNewLineTokens(const bool value)
|
||||
SimpleLexer::SimpleLexer(IParserLineStream* stream, Config config)
|
||||
: AbstractLexer(stream),
|
||||
m_config(config),
|
||||
m_last_line(1)
|
||||
{
|
||||
m_emit_new_line_tokens = value;
|
||||
}
|
||||
|
||||
void SimpleLexer::SetShouldReadStrings(const bool value)
|
||||
{
|
||||
m_read_strings = value;
|
||||
}
|
||||
|
||||
void SimpleLexer::SetShouldReadNumbers(const bool value)
|
||||
{
|
||||
m_read_numbers = value;
|
||||
}
|
||||
|
||||
SimpleParserValue SimpleLexer::GetNextToken()
|
||||
{
|
||||
auto c = PeekChar();
|
||||
const auto nextCharPos = GetNextCharacterPos();
|
||||
if (m_emit_new_line_tokens && nextCharPos.m_line > m_last_line)
|
||||
if (m_config.m_emit_new_line_tokens && nextCharPos.m_line > m_last_line)
|
||||
{
|
||||
m_last_line++;
|
||||
return SimpleParserValue::NewLine(GetPreviousCharacterPos());
|
||||
@ -36,7 +26,7 @@ SimpleParserValue SimpleLexer::GetNextToken()
|
||||
|
||||
while (isspace(c))
|
||||
{
|
||||
if (m_emit_new_line_tokens && c == '\n')
|
||||
if (m_config.m_emit_new_line_tokens && c == '\n')
|
||||
return SimpleParserValue::NewLine(GetPreviousCharacterPos());
|
||||
|
||||
NextChar();
|
||||
@ -44,7 +34,7 @@ SimpleParserValue SimpleLexer::GetNextToken()
|
||||
}
|
||||
|
||||
const auto pos = GetNextCharacterPos();
|
||||
if (m_emit_new_line_tokens && pos.m_line > m_last_line)
|
||||
if (m_config.m_emit_new_line_tokens && pos.m_line > m_last_line)
|
||||
{
|
||||
m_last_line++;
|
||||
return SimpleParserValue::NewLine(GetPreviousCharacterPos());
|
||||
@ -55,10 +45,10 @@ SimpleParserValue SimpleLexer::GetNextToken()
|
||||
if (c == EOF)
|
||||
return SimpleParserValue::EndOfFile(TokenPos());
|
||||
|
||||
if (m_read_strings && c == '\"')
|
||||
if (m_config.m_read_strings && c == '\"')
|
||||
return SimpleParserValue::String(GetPreviousCharacterPos(), new std::string(ReadString()));
|
||||
|
||||
if (m_read_numbers && isdigit(c))
|
||||
if (m_config.m_read_numbers && isdigit(c))
|
||||
{
|
||||
bool isFloatingPointValue;
|
||||
double doubleValue;
|
||||
|
@ -5,18 +5,22 @@
|
||||
|
||||
class SimpleLexer : public AbstractLexer<SimpleParserValue>
|
||||
{
|
||||
public:
|
||||
class Config
|
||||
{
|
||||
public:
|
||||
bool m_emit_new_line_tokens;
|
||||
bool m_read_strings;
|
||||
bool m_read_numbers;
|
||||
};
|
||||
|
||||
Config m_config;
|
||||
int m_last_line;
|
||||
|
||||
protected:
|
||||
SimpleParserValue GetNextToken() override;
|
||||
|
||||
void SetShouldEmitNewLineTokens(bool value);
|
||||
void SetShouldReadStrings(bool value);
|
||||
void SetShouldReadNumbers(bool value);
|
||||
|
||||
public:
|
||||
explicit SimpleLexer(IParserLineStream* stream);
|
||||
SimpleLexer(IParserLineStream* stream, Config config);
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user