-
Notifications
You must be signed in to change notification settings - Fork 73
Initial support for PHP 8.5 Pipe Operator #1164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -119,6 +119,14 @@ module.exports = { | |||||||||||||||
if (this.token === this.tok.T_COALESCE) { | ||||||||||||||||
return result("bin", "??", expr, this.next().read_expr()); | ||||||||||||||||
} | ||||||||||||||||
// extra operations : | ||||||||||||||||
// $a = "Hi" |> strtoupper(...); | ||||||||||||||||
if (this.token === this.tok.T_PIPE) { | ||||||||||||||||
Comment on lines
+122
to
+124
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nitpick] The comment placement is inconsistent with the existing code structure. This comment should be moved to line 124 to directly precede the pipe operator implementation, matching the pattern used for other operators like the coalesce operator.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||||||
if (this.version < 805) { | ||||||||||||||||
this.raiseError("PHP 8.5+ is required to use pipe operator"); | ||||||||||||||||
} | ||||||||||||||||
return result("bin", "|>", expr, this.next().read_expr()); | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
// extra operations : | ||||||||||||||||
// $username = $_GET['user'] ? true : false; | ||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing | ||
|
||
exports[`Parse Pipeline Operator can parse basic pipeline operator task 1`] = ` | ||
Program { | ||
"children": [ | ||
ExpressionStatement { | ||
"expression": Assign { | ||
"kind": "assign", | ||
"left": Variable { | ||
"curly": false, | ||
"kind": "variable", | ||
"name": "c", | ||
}, | ||
"operator": "=", | ||
"right": Bin { | ||
"kind": "bin", | ||
"left": Variable { | ||
"curly": false, | ||
"kind": "variable", | ||
"name": "a", | ||
}, | ||
"right": Closure { | ||
"arguments": [ | ||
Parameter { | ||
"attrGroups": [], | ||
"byref": false, | ||
"flags": 0, | ||
"kind": "parameter", | ||
"name": Identifier { | ||
"kind": "identifier", | ||
"name": "s", | ||
}, | ||
"nullable": false, | ||
"readonly": false, | ||
"type": null, | ||
"value": null, | ||
"variadic": false, | ||
}, | ||
], | ||
"attrGroups": [], | ||
"body": Bin { | ||
"kind": "bin", | ||
"left": Call { | ||
"arguments": [ | ||
String { | ||
"isDoubleQuote": true, | ||
"kind": "string", | ||
"raw": "","", | ||
"unicode": false, | ||
"value": ",", | ||
}, | ||
Variable { | ||
"curly": false, | ||
"kind": "variable", | ||
"name": "s", | ||
}, | ||
], | ||
"kind": "call", | ||
"what": Name { | ||
"kind": "name", | ||
"name": "explode", | ||
"resolution": "uqn", | ||
}, | ||
}, | ||
"right": Bin { | ||
"kind": "bin", | ||
"left": Call { | ||
"arguments": [ | ||
VariadicPlaceholder { | ||
"kind": "variadicplaceholder", | ||
}, | ||
], | ||
"kind": "call", | ||
"what": Name { | ||
"kind": "name", | ||
"name": "array_filter", | ||
"resolution": "uqn", | ||
}, | ||
}, | ||
"right": String { | ||
"isDoubleQuote": false, | ||
"kind": "string", | ||
"raw": "'array_last'", | ||
"unicode": false, | ||
"value": "array_last", | ||
}, | ||
"type": "|>", | ||
}, | ||
"type": "|>", | ||
}, | ||
"byref": false, | ||
"isStatic": false, | ||
"kind": "arrowfunc", | ||
"nullable": false, | ||
"type": null, | ||
}, | ||
"type": "|>", | ||
}, | ||
}, | ||
"kind": "expressionstatement", | ||
}, | ||
], | ||
"errors": [], | ||
"kind": "program", | ||
} | ||
`; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const parser = require("../main"); | ||
|
||
describe("Parse Pipeline Operator", () => { | ||
it("can parse basic pipeline operator task", () => { | ||
const parser8_5 = parser.create({ | ||
parser: { | ||
version: "8.5", | ||
}, | ||
}); | ||
expect( | ||
parser8_5.parseEval(` | ||
$c = $a | ||
|> fn ($s) => explode(",", $s) | ||
|> array_filter(...) |> 'array_last' ; | ||
`), | ||
).toMatchSnapshot(); | ||
}); | ||
}); |
Uh oh!
There was an error while loading. Please reload this page.