You've already forked ScriptPreprocessor
mirror of
https://github.com/AxioDL/ScriptPreprocessor.git
synced 2026-07-10 21:18:40 -07:00
* Fix multiline directives
* Add macros * Add operator parsing
This commit is contained in:
@@ -5,30 +5,73 @@
|
||||
#include <stdlib.h>
|
||||
#include <list>
|
||||
|
||||
void printTokenList(CLexer::TokenList& out)
|
||||
{
|
||||
for (const CLexer::Token& token : out)
|
||||
std::cout << token.value;
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
|
||||
void linkInstancePreprocessor(CLexer::TokenList& tokens, CPreprocessor::DefineTable& defineTable)
|
||||
void linkInstancePreprocessor(CLexer::TokenList& tokens, CPreprocessor::DefineTable& defineTable, CPreprocessor::PreprocessorState state)
|
||||
{
|
||||
(void)(defineTable);
|
||||
CPreprocessor::advanceList(tokens);
|
||||
if (tokens.size() == 0)
|
||||
if (tokens.empty())
|
||||
return;
|
||||
|
||||
std::cout << tokens.begin()->value << std::endl;
|
||||
CLexer::Token source = tokens.front();
|
||||
CPreprocessor::advanceList(tokens);
|
||||
if (source.type != CLexer::NUMBER)
|
||||
{
|
||||
std::cout << state.currentFile + ": Degenerate link request, invalid source" << std::endl;
|
||||
return;
|
||||
}
|
||||
if (tokens.empty())
|
||||
{
|
||||
std::cout << state.currentFile + ": Degenerate link request, missing arguments" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
CLexer::Token target = tokens.front();
|
||||
CPreprocessor::advanceList(tokens);
|
||||
if (target.type != CLexer::NUMBER)
|
||||
{
|
||||
std::cout << state.currentFile + ": Degenerate link request, invalid target" << std::endl;
|
||||
return;
|
||||
}
|
||||
if (tokens.empty())
|
||||
{
|
||||
std::cout << state.currentFile + ": Degenerate link request, missing arguments" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
CLexer::Token token = tokens.front();
|
||||
CPreprocessor::advanceList(tokens);
|
||||
|
||||
std::vector<CLexer::Token> args;
|
||||
if (token.type == CLexer::OPEN && token.value == "(")
|
||||
{
|
||||
while (!tokens.empty())
|
||||
{
|
||||
CLexer::Token currentToken = tokens.front();
|
||||
CPreprocessor::advanceList(tokens);
|
||||
if (currentToken.type == CLexer::CLOSE)
|
||||
break;
|
||||
if (currentToken.type == CLexer::COMMA)
|
||||
continue;
|
||||
if (currentToken.type == CLexer::NUMBER)
|
||||
args.push_back(currentToken);
|
||||
}
|
||||
}
|
||||
|
||||
if (args.size() != 2)
|
||||
std::cout << "Unable to link object instances, missing arguments" << std::endl;
|
||||
else
|
||||
std::cout << "Connecting object " << source.value << " to " << target.value << " with " << args.at(0).value << " " << args.at(1).value << std::endl;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
CPreprocessor preprocessor;
|
||||
preprocessor.define("_DEBUG_");
|
||||
preprocessor.registerHook("link_instance", linkInstancePreprocessor);
|
||||
preprocessor.preprocessFile("main.as");
|
||||
std::cout << preprocessor.finalizedSource() << std::endl;
|
||||
if (preprocessor.preprocessFile("main.as"))
|
||||
std::cout << preprocessor.finalizedSource() << std::endl;
|
||||
else
|
||||
std::cout << "Failed to preprocess script source :(" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user