Skip to content

Commit

Permalink
Fixed bug in cast pipe
Browse files Browse the repository at this point in the history
  • Loading branch information
PsychedelicPalimpsest committed May 21, 2024
1 parent 1cf747e commit 63ee2d4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
32 changes: 18 additions & 14 deletions source/fnc/treegen/expression_parser.d
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,12 @@ NameValuePair[] genCommaSeperatedContents(AstNode expressionLike) {
private bool testAndJoinConversionPipe(ref Array!AstNode nodes, size_t nodeIndex) {
size_t startingIndex = nodeIndex;
Nullable!AstNode itemToConvert = nodes.nextNonWhiteNode(nodeIndex);

Nullable!AstNode op1 = nodes.nextNonWhiteNode(nodeIndex);
Nullable!AstNode op2 = nodes.nextNonWhiteNode(nodeIndex);

if (op1 == null || op2 == null || itemToConvert == null)
return false;
handleSingleNodeExpressionTest(itemToConvert.value);
if (op1.value.action != AstAction.TokenHolder || op2.value.action != AstAction.TokenHolder)
return false;
if (op1.value.tokenBeingHeld.tokenVariety != TokenType.Pipe || op2.value
Expand Down Expand Up @@ -254,6 +254,7 @@ private bool testAndJoinIndexingInto(ref Array!AstNode nodes, size_t nodeIndex)
Nullable!AstNode index = nodes.nextNonWhiteNode(nodeIndex);
if (thingBeingIndexed == null || index == null)
return false;

if (index.value.action != AstAction.ArrayGrouping)
return false;

Expand All @@ -275,7 +276,20 @@ private bool testAndJoinIndexingInto(ref Array!AstNode nodes, size_t nodeIndex)
nodes.linearRemove(nodes[startingIndex + 1 .. nodeIndex]);
return true;
}

private void handleSingleNodeExpressionTest(ref AstNode node){
if (node.action == AstAction.Expression) {
Array!AstNode components;
components ~= node.expressionNodeData.components;
phaseTwo(components);
scanAndMergeOperators(components);
assert(components.length == 1, "Expression is invalid");
node = components[0];
}
else if (node.action == AstAction.ArrayGrouping) {
node.arrayNodeData = genCommaSeperatedContents(node);
node.action = AstAction.Array;
}
}
// Handle function calls, arrays, and Generics
void phaseTwo(ref Array!AstNode nodes) {
for (size_t index = 0; index < nodes.length; index++) {
Expand All @@ -284,6 +298,7 @@ void phaseTwo(ref Array!AstNode nodes) {
if (testAndJoin(sepMethod, nodes, index))
goto TOP;
}

if (testAndJoinConversionPipe(nodes, index))
goto TOP;
if (testAndJoinGeneric(nodes, index))
Expand All @@ -292,18 +307,7 @@ void phaseTwo(ref Array!AstNode nodes) {
goto TOP;
if (testAndJoinIndexingInto(nodes, index))
goto TOP;
if (nodes[index].action == AstAction.Expression) {
Array!AstNode components;
components ~= nodes[index].expressionNodeData.components;
phaseTwo(components);
scanAndMergeOperators(components);
assert(components.length == 1, "Expression is invalid");
nodes[index] = components[0];
}
else if (nodes[index].action == AstAction.ArrayGrouping) {
nodes[index].arrayNodeData = genCommaSeperatedContents(nodes[index]);
nodes[index].action = AstAction.Array;
}
handleSingleNodeExpressionTest(nodes[index]);

}
}
Expand Down
2 changes: 1 addition & 1 deletion source/main.d
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void main() {
ScopeData globalScope = parseMultilineScope(GLOBAL_SCOPE_PARSE, "
public module foo.bar;
int main(){
byte c = 1 |> B.c;
byte c = (1 + 5 )|> B.c;
}
");
globalScope.tree;
Expand Down

0 comments on commit 63ee2d4

Please sign in to comment.