Skip to content

Commit

Permalink
Parser
Browse files Browse the repository at this point in the history
- Implemented `obtainDotPath(ref string path, Expression exp)`
  • Loading branch information
deavmi committed May 20, 2024
1 parent add5fcb commit 92ef239
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions source/tlang/compiler/parsing/core.d
Original file line number Diff line number Diff line change
Expand Up @@ -441,10 +441,55 @@ public final class Parser
return assignment;
}

// x.y.z -> [(x.y) . z]
private bool obtainDotPath(ref string path, Expression exp)
{
BinaryOperatorExpression binOp = cast(BinaryOperatorExpression)exp;
IdentExpression ident = cast(IdentExpression)exp;

// Recurse on left-and-right operands
if(binOp && binOp.getOperator() == SymbolType.DOT)
{
string lhsText;
obtainDotPath(lhsText, binOp.getLeftExpression());

string rhsText;
obtainDotPath(rhsText, binOp.getRightExpression());

path ~= lhsText~"."~rhsText;

return true;
}
// Found an ident
else if(ident)
{
path = ident.getName();
return true;
}
// Anything else is invalid
else
{
WARN("Found nothing else");
return false;
}
}

public Statement parseName(SymbolType terminatingSymbol = SymbolType.SEMICOLON)
{
Statement ret;

// TODO: We must do a sort-of greedby lookahead here until
// we hit a `;` or `=`
//
// we either have [<expr>, =]
// or
// [<dotPath> <path> =/;]

// commonality: <expr>
//
// then have a isDotPath(Expression)
// and dependent on that then move to next steo

/* Save the name or type */
string nameTYpe = lexer.getCurrentToken().getToken();
DEBUG("parseName(): Current token: "~lexer.getCurrentToken().toString());
Expand Down

0 comments on commit 92ef239

Please sign in to comment.