Skip to content

Commit

Permalink
Traktor: Cleanup in script editor module.
Browse files Browse the repository at this point in the history
  • Loading branch information
apistol78 committed May 13, 2024
1 parent cc118dc commit 938f93f
Show file tree
Hide file tree
Showing 15 changed files with 81 additions and 129 deletions.
5 changes: 4 additions & 1 deletion code/Script/Editor/Lexer.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -13,6 +13,9 @@
namespace traktor::script
{

/*! Script outline parser lexer.
* \ingroup Script
*/
class Lexer : public Object
{
T_RTTI_CLASS;
Expand Down
24 changes: 12 additions & 12 deletions code/Script/Editor/ScriptEditorPage.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand Down Expand Up @@ -30,17 +30,19 @@ namespace traktor

class Preprocessor;

namespace editor
{
}

namespace traktor::editor
{

class IDocument;
class IEditor;
class IEditorPageSite;

}
}

namespace ui
{
namespace traktor::ui
{

class IBitmap;
class GridRow;
Expand All @@ -53,10 +55,10 @@ class Tab;
class ToolBar;
class ToolBarButtonClickEvent;

}
}

namespace script
{
namespace traktor::script
{

class IScriptCompiler;
class IScriptContext;
Expand All @@ -73,7 +75,7 @@ class T_DLLCLASS ScriptEditorPage
T_RTTI_CLASS;

public:
ScriptEditorPage(editor::IEditor* editor, editor::IEditorPageSite* site, editor::IDocument* document);
explicit ScriptEditorPage(editor::IEditor* editor, editor::IEditorPageSite* site, editor::IDocument* document);

virtual bool create(ui::Container* parent) override final;

Expand Down Expand Up @@ -153,6 +155,4 @@ class T_DLLCLASS ScriptEditorPage
void eventTimer(ui::TimerEvent* event);
};

}
}

7 changes: 2 additions & 5 deletions code/Script/Editor/ScriptEditorPageFactory.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -12,10 +12,8 @@
#include "Script/Editor/ScriptEditorPageFactory.h"
#include "Ui/Command.h"

namespace traktor
namespace traktor::script
{
namespace script
{

T_IMPLEMENT_RTTI_FACTORY_CLASS(L"traktor.script.ScriptEditorPageFactory", 0, ScriptEditorPageFactory, editor::IEditorPageFactory)

Expand Down Expand Up @@ -47,5 +45,4 @@ Ref< ISerializable > ScriptEditorPageFactory::cloneAsset(const ISerializable* as
return DeepClone(asset).create();
}

}
}
8 changes: 2 additions & 6 deletions code/Script/Editor/ScriptEditorPageFactory.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -18,10 +18,8 @@
# define T_DLLCLASS T_DLLIMPORT
#endif

namespace traktor
namespace traktor::script
{
namespace script
{

class T_DLLCLASS ScriptEditorPageFactory : public editor::IEditorPageFactory
{
Expand All @@ -39,6 +37,4 @@ class T_DLLCLASS ScriptEditorPageFactory : public editor::IEditorPageFactory
virtual Ref< ISerializable > cloneAsset(const ISerializable* asset) const override final;
};

}
}

21 changes: 7 additions & 14 deletions code/Script/Editor/ScriptEditorPlugin.h
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#ifndef traktor_script_ScriptEditorPlugin_H
#define traktor_script_ScriptEditorPlugin_H
#pragma once

#include "Core/Ref.h"
#include "Editor/IEditorPlugin.h"
#include "Script/Editor/IScriptDebuggerSessions.h"

namespace traktor
namespace traktor::editor
{
namespace editor
{

class IEditor;

}
}

namespace script
{
namespace traktor::script
{

class IScriptManager;
class ScriptDebuggerSessions;
Expand All @@ -38,7 +35,7 @@ class ScriptEditorPlugin
T_RTTI_CLASS;

public:
ScriptEditorPlugin(editor::IEditor* editor);
explicit ScriptEditorPlugin(editor::IEditor* editor);

virtual bool create(ui::Widget* parent, editor::IEditorPageSite* site) override final;

Expand Down Expand Up @@ -73,8 +70,4 @@ class ScriptEditorPlugin
Ref< script::ScriptDebuggerSessions > m_debuggerSessions;
};

}
}

#endif // traktor_script_ScriptEditorPlugin_H

32 changes: 14 additions & 18 deletions code/Script/Editor/ScriptOutlineLua.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -19,12 +19,10 @@ void *ParseAlloc(void *(*mallocProc)(size_t));
void ParseFree(void *p, void (*freeProc)(void*));
void Parse(void *yyp, int yymajor, traktor::script::LuaGrammarToken* yyminor, const traktor::script::ScriptOutlineLua* outline);

namespace traktor
namespace traktor::script
{
namespace script
namespace
{
namespace
{

const std::map< wchar_t, int32_t >& getSingles()
{
Expand Down Expand Up @@ -94,53 +92,52 @@ const std::map< std::wstring, int32_t >& getTuples()
return tuples;
}

}
}

T_IMPLEMENT_RTTI_FACTORY_CLASS(L"traktor.script.ScriptOutlineLua", 0, ScriptOutlineLua, IScriptOutline)

Ref< IScriptOutline::Node > ScriptOutlineLua::parse(const std::wstring& text) const
{
Lexer lx(text.c_str(), text.length());
Lexer lx(text.c_str(), (uint32_t)text.length());

void* parser = ParseAlloc(malloc);
if (!parser)
return 0;
return nullptr;

const std::map< wchar_t, int32_t >& single = getSingles();
const std::map< std::wstring, int32_t >& tuples = getTuples();
const auto& single = getSingles();
const auto& tuples = getTuples();

int32_t type;
while ((type = lx.next()) != Lexer::LtEndOfFile)
{
if (type == Lexer::LtWord)
{
std::wstring word = lx.getWord();

std::map< std::wstring, int32_t >::const_iterator it = tuples.find(word);
const std::wstring word = lx.getWord();
const auto it = tuples.find(word);
if (it != tuples.end())
Parse(parser, it->second, 0, this);
else
Parse(parser, TOKEN_NAME, new LuaGrammarToken(word, lx.getLine()), this);
}
else if (type == Lexer::LtString)
{
std::wstring str = lx.getString();
const std::wstring str = lx.getString();
Parse(parser, TOKEN_STRING, new LuaGrammarToken(str, lx.getLine()), this);
}
else if (type == Lexer::LtNumber)
{
double number = lx.getNumber();
const double number = lx.getNumber();
Parse(parser, TOKEN_NUMBER, new LuaGrammarToken(L"", lx.getLine()), this);
}
else
{
std::map< wchar_t, int32_t >::const_iterator it = single.find(type);
const auto it = single.find(type);
if (it != single.end())
Parse(parser, it->second, new LuaGrammarToken(L"", lx.getLine()), this);
}
}

Parse(parser, 0, 0, this);
Parse(parser, 0, nullptr, this);
ParseFree(parser, free);

return m_result;
Expand All @@ -155,5 +152,4 @@ void ScriptOutlineLua::syntaxError() const
{
}

}
}
8 changes: 2 additions & 6 deletions code/Script/Editor/ScriptOutlineLua.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -10,10 +10,8 @@

#include "Script/Editor/IScriptOutline.h"

namespace traktor
namespace traktor::script
{
namespace script
{

/*! LUA script outline parser.
* \ingroup Script
Expand All @@ -33,6 +31,4 @@ class ScriptOutlineLua : public IScriptOutline
mutable Ref< Node > m_result;
};

}
}

11 changes: 4 additions & 7 deletions code/Script/Editor/ScriptPipeline.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand Down Expand Up @@ -31,12 +31,10 @@
#include "Script/Editor/Script.h"
#include "Script/Editor/ScriptPipeline.h"

namespace traktor
namespace traktor::script
{
namespace script
namespace
{
namespace
{

struct ErrorCallback : public IErrorCallback
{
Expand Down Expand Up @@ -111,7 +109,7 @@ bool flattenDependencies(editor::IPipelineBuilder* pipelineBuilder, const std::w
return true;
}

}
}

T_IMPLEMENT_RTTI_FACTORY_CLASS(L"traktor.script.ScriptPipeline", 21, ScriptPipeline, editor::DefaultPipeline)

Expand Down Expand Up @@ -287,5 +285,4 @@ bool ScriptPipeline::buildOutput(
);
}

}
}
Loading

0 comments on commit 938f93f

Please sign in to comment.