Skip to content

Commit

Permalink
Fixed whitspace (yet again) breaking parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
HeronErin authored May 8, 2024
1 parent 87f756f commit 53cda6c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
4 changes: 3 additions & 1 deletion source/main.d
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ void main()
// typeFromTokens("".tokenizeText, index);


auto newScope = parseMultilineScope(FUNCTION_SCOPE_PARSE, "foo[bar++];");
auto newScope = parseMultilineScope(FUNCTION_SCOPE_PARSE, "foo(bar)
[2
];");

newScope.tree;
// DeclarationAndAssignment.matchesToken("y=4".tokenizeText).ptr.writeln;
Expand Down
28 changes: 19 additions & 9 deletions source/parsing/treegen/expressionParser.d
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ private AstNode[][] splitNodesAtComma(AstNode[] inputNodes)
public void phaseTwo(ref Array!AstNode nodes)
{
AstNode[] nonWhiteStack;
size_t[] nonWhiteIndexStack;

Array!AstNode newNodesArray;

Expand All @@ -123,12 +124,13 @@ public void phaseTwo(ref Array!AstNode nodes)

if (node.action == AstAction.Expression
&& nonWhiteStack.length
&& nonWhiteStack[$ - 1].action.isCallable
&& nonWhiteStack[nonWhiteIndexStack[$ - 1]].action.isCallable
)
{
AstNode functionCall = new AstNode();
scope (exit)
newNodesArray[$ - 1] = functionCall;

newNodesArray[nonWhiteIndexStack[$ - 1]] = functionCall;
nonWhiteIndexStack ~= newNodesArray.length - 1;
scope (exit)
nonWhiteStack ~= functionCall;

Expand Down Expand Up @@ -184,11 +186,17 @@ public void phaseTwo(ref Array!AstNode nodes)
&& nonWhiteStack.length)
{
AstNode indexNode = new AstNode;

indexNode.action = AstAction.IndexInto;
scope (exit) nonWhiteStack ~= indexNode;
scope (exit) newNodesArray[$-1] = indexNode;

newNodesArray[nonWhiteIndexStack[$ - 1]] = indexNode;

nonWhiteIndexStack ~= newNodesArray.length - 1;
scope (exit)
nonWhiteStack ~= indexNode;



IndexIntoNodeData id;
indexNode.indexIntoNodeData = id;
indexNode.indexIntoNodeData.indexInto = nonWhiteStack[$ - 1];
Expand All @@ -203,13 +211,15 @@ public void phaseTwo(ref Array!AstNode nodes)

indexNode.indexIntoNodeData.index = components[0];



}
else
{
newNodesArray ~= node;
nonWhiteStack ~= node;
if (!node.isWhite)
{
nonWhiteStack ~= node;
nonWhiteIndexStack ~= newNodesArray.length - 1;
}
}

// if (node.action == AstAction.Expression && lastNonWhite != null )
Expand Down

0 comments on commit 53cda6c

Please sign in to comment.