Website Summary Files Commits Branches @commit @diff @stats
path: root / JSImpl / src / Parser.cpp
diff options
context:
space:
mode:
1 files changed, 28 insertions, 19 deletions
-rw-r--r--JSImpl/src/Parser.cpp47
diff --git a/JSImpl/src/Parser.cpp b/JSImpl/src/Parser.cpp
index bc4920f..4bc97ce 100644
--- a/JSImpl/src/Parser.cpp
+++ b/JSImpl/src/Parser.cpp
@@ -23,6 +23,7 @@ private:
bool MatchOneOf(IPLVector<TokenType> types);
bool Match(TokenType type);
+ bool Peek(TokenType type);
ExpressionPtr RegularExpression();
ExpressionPtr ParenthesizedExpression();
ExpressionPtr PrimaryExpression(NormalType a);
@@ -125,6 +126,11 @@ bool Parser::Match(TokenType type)
return false;
}
+bool Parser::Peek(TokenType type)
+{
+ return type == m_Tokens[m_Current].Type;
+}
+
ExpressionPtr Parser::RegularExpression()
{
return nullptr;
@@ -383,23 +389,32 @@ ExpressionPtr Parser::LeftSideExpression(NormalType a)
ExpressionPtr Parser::CallExpression(NormalType a)
{
ExpressionPtr result;
+
auto ss = Snapshot();
- if (result = PrimaryExpression(a))
+ if (auto pe = PrimaryExpression(a))
{
- return result;
+ result = IPLMakeSharePtr<Call>(pe);
}
- Restore(ss);
- if (result = FullNewExpression())
+ else
{
- return result;
+ Restore(ss);
}
-
- if (result = CallExpressionHelper(a))
+ if (auto fne = FullNewExpression())
{
- return result;
+ result = IPLMakeSharePtr<::Call>(fne);
}
- // TODO error
- return nullptr;
+
+ ExpressionPtr right;
+ do
+ {
+ right = CallExpressionHelper(a);
+ if (right)
+ {
+ result = IPLMakeSharePtr<::Call>(result, right);
+ }
+ } while (right);
+
+ return result;
}
ExpressionPtr Parser::CallExpressionHelper(NormalType a)
@@ -420,9 +435,7 @@ ExpressionPtr Parser::CallExpressionHelper(NormalType a)
{
if (Match(TokenType::Identifier))
{
- auto next = CallExpressionHelper(a);
- // return meaningfull expr
- return nullptr;
+ return IPLMakeSharePtr<MemberAccess>(Prev().Lexeme);
}
// TODO error
return nullptr;
@@ -991,10 +1004,8 @@ ExpressionPtr Parser::ContinueStatement()
{
if (Match(TokenType::Continue))
{
- auto type = TokenType::Continue;
ExpressionPtr expr = OptionalLabel();
- bool suffix = true;
- return IPLMakeSharePtr<UnaryExpression>(expr, type, suffix);
+ return IPLMakeSharePtr<Continue>();
}
return nullptr;
}
@@ -1003,10 +1014,8 @@ ExpressionPtr Parser::BreakStatement()
{
if (Match(TokenType::Break))
{
- auto type = TokenType::Break;
ExpressionPtr expr = OptionalLabel();
- bool suffix = true;
- return IPLMakeSharePtr<UnaryExpression>(expr, type, suffix);
+ return IPLMakeSharePtr<Break>();
}
return nullptr;
}