Skip to content

Commit

Permalink
v1.11
Browse files Browse the repository at this point in the history
- Improved parsing
- Fixed rare critical bugs
  • Loading branch information
goshante committed Dec 7, 2019
1 parent f837471 commit b50a539
Show file tree
Hide file tree
Showing 9 changed files with 214 additions and 170 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*.sln.docstates
*.ini
*.log
enc_temp_folder

# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Warcraft III Reforged brought us Lua scripting, but still a lot of map makers fo
- Read logs if something goes wrong, this application leaves cjass2lua.log file with all it's actions and possible problems. Everything should be fine if you have no warnings.

### Latest release
- [v1.10](https://github.com/fullmetal-a/cjass2lua/releases/tag/v1.10)
- [v1.11](https://github.com/fullmetal-a/cjass2lua/releases/tag/v1.11)

### Manual
(No TL;DR sections, complicated bullshit or other retarded shit, just exe file with simple interface)
Expand Down
38 changes: 38 additions & 0 deletions cJass2Lua/cJassNodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,35 @@ namespace cJass
return _top;
}

Node* Node::GetAdjacentNode(bool right) const
{
if (_top == nullptr)
return nullptr;

for (size_t i = 0; i < _top->_subnodes.size(); i++)
{
if (_top->_subnodes[i]->Ptr() == this)
{
if (!right)
{
if (i == 0)
return nullptr;
else
return _top->_subnodes[i - 1]->Ptr();
}
else
{
if (i == _top->_subnodes.size() - 1)
return nullptr;
else
return _top->_subnodes[i + 1]->Ptr();
}
}
}

return nullptr;
}

Node* Node::LastSubnode()
{
if (_subnodes.size() == 0)
Expand Down Expand Up @@ -1322,6 +1351,10 @@ namespace cJass
_otype = OpType::NewLine;
break;

case '_':
_otype = OpType::empty;
break;

default:
appLog(Warning) << "OperationObject::InitData: unknown key.";
}
Expand Down Expand Up @@ -1438,6 +1471,11 @@ namespace cJass
return _cType;
}

std::string OperationObject::GetText() const
{
return _opText;
}

OperationObject::OpType OperationObject::GetOpType() const
{
return _otype;
Expand Down
3 changes: 3 additions & 0 deletions cJass2Lua/cJassNodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ namespace cJass
virtual void InitData(const std::vector<std::string>& strings) = 0;
virtual void InsertStringId(const std::string& strId) {}
virtual bool HasStringId(const std::string& strId) const { return false; }
virtual std::string GetText() const { return ""; }
Node* GetAdjacentNode(bool right) const;
};

class RootNode : public Node
Expand Down Expand Up @@ -340,6 +342,7 @@ namespace cJass
void CloseBlock();
bool CheckIsString();
ConstType GetConstType() const;
virtual std::string GetText() const override;
};

class LocalDeclaration : public Node
Expand Down
119 changes: 23 additions & 96 deletions cJass2Lua/cJassParser2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ namespace cJass
if (word == "class" || word == "struct")
return word_t::structure;

if (word == "evaluate")
return word_t::evaluate;

if (word == "endstruct")
return word_t::endstruct;

Expand Down Expand Up @@ -457,8 +460,6 @@ namespace cJass
size_t linesTotal = 0;
std::shared_ptr<std::function<void(int, int)>> notifyLineCallback;
bool useCallback = false;
ranges_t comments;
ranges_t strings;

if (lineProgressHandler)
{
Expand All @@ -473,102 +474,9 @@ namespace cJass
return;
}

size_t r_begin = ~0, r_end = ~0, r_last = ~0;
_text = Utils::FileToString(cjassFileName);

do
{
r_last = _text.find("\"", r_last + 1);
if (r_last == std::string::npos)
break;

if (r_begin == ~0)
r_begin = r_last;
else
{
r_end = r_last;
strings.push_back({ r_begin, r_end });
r_begin = ~0;
r_end = ~0;
}


} while (true);

r_last = ~0;
do
{
if (r_begin == ~0)
{
r_last = _text.find("//", r_last + 1);
if (r_last == std::string::npos)
break;

r_begin = r_last;
}
else
{
r_last = _text.find("\n", r_last + 1);
if (r_last == std::string::npos)
{
comments.push_back({ r_begin, _text.length() - 1 });
break;
}

r_end = r_last;
comments.push_back({ r_begin, r_end });
r_begin = ~0;
r_end = ~0;
}
} while (true);

r_last = ~0;
do
{
if (r_begin == ~0)
{
r_last = _text.find("/*", r_last + 1);
if (r_last == std::string::npos)
break;

r_begin = r_last;
}
else
{
r_last = _text.find("*/", r_last + 1);
if (r_last == std::string::npos)
{
comments.push_back({ r_begin, _text.length() - 1 });
break;
}

r_end = r_last;
comments.push_back({ r_begin, r_end });
r_begin = ~0;
r_end = ~0;
}
} while (true);

auto matches = reu::SearchAll(_text, "\\.evaluate");
for (auto& match : matches)
{
if (RangeCheck(comments, match.Begin()) && RangeCheck(strings, match.Begin()))
match.Replace("");
}

matches = reu::SearchAll(_text, "([^a-zA-Z_0-9\\[\\]])\\.");
for (auto& match : matches)
{
if (RangeCheck(comments, match.Begin()) && RangeCheck(strings, match.Begin()))
match.Replace("$1");
}

matches = reu::SearchAll(_text, "this\\.");
for (auto& match : matches)
{
if (RangeCheck(comments, match.Begin()) && RangeCheck(strings, match.Begin()))
match.Replace("");
}
Utils::StringToFile("debug.txt", _text);

_activeNode = &_rootNode;
_lastAddedNode = _activeNode;
Expand Down Expand Up @@ -1488,6 +1396,13 @@ namespace cJass
bstack_set_top(allowWrappersStack, false);
break;

case word_t::evaluate:
if (_lastAddedNode->GetText() == ".")
{
_lastAddedNode->InitData({ "_" });
break;
}

case word_t::This:
case word_t::id:
if (isLocalTop && !varAddedStack.top())
Expand Down Expand Up @@ -1616,6 +1531,18 @@ namespace cJass
break;

case word_t::dot:
if (_lastAddedNode->GetText() == "this")
{
_lastAddedNode->InitData({ "_" });
break;
}

if (_lastAddedNode->GetType() != Node::Type::OperationObject
&& _lastAddedNode->Ptr<OperationObject>()->GetOpType() != OperationObject::OpType::Id)
{
break;
}

_addNode(Node::Type::OperationObject, { "o", _word });
break;

Expand Down
24 changes: 3 additions & 21 deletions cJass2Lua/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#pragma warning(disable : 4834)


#define APP_VER "1.10"
#define APP_VER "1.11"
#ifdef _WIN64
#define APP_BUILD "x64"
#else
Expand Down Expand Up @@ -107,7 +107,8 @@ namespace cJass
This,
priv,
pub,
Static
Static,
evaluate
};

enum class ParseSpecialSubject
Expand All @@ -122,23 +123,4 @@ namespace cJass
constant,
structure
};

struct range_t
{
size_t begin;
size_t end;
};

using ranges_t = std::vector<range_t>;

inline bool RangeCheck(const ranges_t& ranges, size_t n)
{
for (auto& r : ranges)
{
if (n >= r.begin && n <= r.end)
return false;
}

return true;
}
}
Binary file modified cJass2Lua/resource.rc
Binary file not shown.
Loading

0 comments on commit b50a539

Please sign in to comment.