Skip to content

pip call operator precedence was fixed #1499

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions jac/jaclang/compiler/jac.lark
Original file line number Diff line number Diff line change
Expand Up @@ -289,17 +289,11 @@ expression: walrus_assign (KW_IF expression KW_ELSE expression)?
| lambda_expr

// Walrus assignments
walrus_assign: (named_ref WALRUS_EQ)? pipe
walrus_assign: (named_ref WALRUS_EQ)? elvis_check

// Lambda expressions
lambda_expr: KW_WITH func_decl_params? (RETURN_HINT expression)? KW_CAN expression

// Pipe expressions
pipe: (pipe PIPE_FWD)? pipe_back

// Pipe back expressions
pipe_back: (pipe_back PIPE_BKWD)? elvis_check

// Elvis expressions
elvis_check: (elvis_check ELVIS_OP)? bitwise_or

Expand Down Expand Up @@ -348,7 +342,13 @@ ds_spawn: (ds_spawn KW_SPAWN)? unpack
unpack: STAR_MUL? ref

// References (unused)
ref: BW_AND? pipe_call
ref: BW_AND? pipe

// Pipe expressions
pipe: (pipe PIPE_FWD)? pipe_back

// Pipe back expressions
pipe_back: (pipe_back PIPE_BKWD)? pipe_call

// Data spatial calls
pipe_call: (PIPE_FWD | A_PIPE_FWD | KW_SPAWN | KW_AWAIT)? atomic_chain
Expand Down
3 changes: 2 additions & 1 deletion jac/jaclang/compiler/passes/tool/jac_formatter_pass.py
Original file line number Diff line number Diff line change
Expand Up @@ -1549,7 +1549,8 @@ def exit_bool_expr(self, node: ast.BoolExpr) -> None:
test_str += f" {node.op.value} "

# Check if line break is needed
if self.is_line_break_needed(test_str):
adjusted_line_length = self.MAX_LINE_LENGTH * 2 - self.indent_size * 2
if self.is_line_break_needed(test_str, max_line_length=adjusted_line_length):
for i in node.values:
if i != end:
self.emit_ln(node, f"{i.gen.jac}")
Expand Down
3 changes: 1 addition & 2 deletions jac/jaclang/compiler/passes/tool/tests/fixtures/corelib.jac
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@ obj JacPlugin {
:obj:Memory:can:get_obj
(caller_id: UUID, item_id: UUID, override: bool=False) -> Element {
ret = item_id |> self.index.get;
if override
or (ret is not None and caller_id |> ret.__is_readable) {
if override or (ret is not None and caller_id |> ret.__is_readable) {
return ret;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,7 @@ obj JacPlugin {
:obj:Memory:can:get_obj
(caller_id: UUID, item_id: UUID, override: bool=False) -> Element {
ret = item_id |> self.index.get;
if override
or (ret is not None and caller_id |> ret.__is_readable) {
if override or (ret is not None and caller_id |> ret.__is_readable) {
return ret;
}
}
Expand Down
7 changes: 7 additions & 0 deletions jac/jaclang/tests/fixtures/pipe_call.jac
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@


with entry {
foo = "foo";
print(foo |> len == 3);
print(1 + foo |> len);
}
9 changes: 9 additions & 0 deletions jac/jaclang/tests/test_language.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,15 @@ def test_multi_dim_arr_slice(self) -> None:
for expected in expected_outputs:
self.assertIn(expected, stdout_value)

def test_pipe_call_percedence(self) -> None:
"""Basic test for pipe call."""
captured_output = io.StringIO()
sys.stdout = captured_output
cli.run(self.fixture_abs_path("pipe_call.jac")) # type: ignore
sys.stdout = sys.__stdout__
stdout_value = captured_output.getvalue()
self.assertEqual("True\n4\n", stdout_value)

def test_chandra_bugs(self) -> None:
"""Parse micro jac file."""
captured_output = io.StringIO()
Expand Down
110 changes: 55 additions & 55 deletions jac/support/jac-lang.org/docs/learn/jac_ref.md
Original file line number Diff line number Diff line change
Expand Up @@ -794,42 +794,6 @@

--8<-- "examples/reference/lambda_expressions.md"

## Pipe expressions
**Code Example**
=== "Jac"
```jac linenums="1"
--8<-- "examples/reference/pipe_expressions.jac"
```
=== "Python"
```python linenums="1"
--8<-- "examples/reference/pipe_expressions.py"
```
??? example "Jac Grammar Snippet"
```yaml linenums="298"
--8<-- "jaclang/compiler/jac.lark:298:298"
```
**Description**

--8<-- "examples/reference/pipe_expressions.md"

## Pipe back expressions
**Code Example**
=== "Jac"
```jac linenums="1"
--8<-- "examples/reference/pipe_back_expressions.jac"
```
=== "Python"
```python linenums="1"
--8<-- "examples/reference/pipe_back_expressions.py"
```
??? example "Jac Grammar Snippet"
```yaml linenums="301"
--8<-- "jaclang/compiler/jac.lark:301:301"
```
**Description**

--8<-- "examples/reference/pipe_back_expressions.md"

## Elvis expressions
**Code Example**
=== "Jac"
Expand All @@ -841,8 +805,8 @@
--8<-- "examples/reference/elvis_expressions.py"
```
??? example "Jac Grammar Snippet"
```yaml linenums="304"
--8<-- "jaclang/compiler/jac.lark:304:304"
```yaml linenums="298"
--8<-- "jaclang/compiler/jac.lark:298:298"
```
**Description**

Expand All @@ -859,8 +823,8 @@
--8<-- "examples/reference/bitwise_expressions.py"
```
??? example "Jac Grammar Snippet"
```yaml linenums="307"
--8<-- "jaclang/compiler/jac.lark:307:310"
```yaml linenums="301"
--8<-- "jaclang/compiler/jac.lark:301:304"
```
**Description**

Expand All @@ -877,8 +841,8 @@
--8<-- "examples/reference/logical_and_compare_expressions.py"
```
??? example "Jac Grammar Snippet"
```yaml linenums="313"
--8<-- "jaclang/compiler/jac.lark:313:327"
```yaml linenums="307"
--8<-- "jaclang/compiler/jac.lark:307:321"
```
**Description**

Expand All @@ -895,8 +859,8 @@
--8<-- "examples/reference/arithmetic_expressions.py"
```
??? example "Jac Grammar Snippet"
```yaml linenums="330"
--8<-- "jaclang/compiler/jac.lark:330:333"
```yaml linenums="324"
--8<-- "jaclang/compiler/jac.lark:324:327"
```
**Description**

Expand All @@ -913,8 +877,8 @@
--8<-- "examples/reference/connect_expressions.py"
```
??? example "Jac Grammar Snippet"
```yaml linenums="336"
--8<-- "jaclang/compiler/jac.lark:336:336"
```yaml linenums="330"
--8<-- "jaclang/compiler/jac.lark:330:330"
```
**Description**

Expand All @@ -931,8 +895,8 @@
--8<-- "examples/reference/atomic_expressions.py"
```
??? example "Jac Grammar Snippet"
```yaml linenums="339"
--8<-- "jaclang/compiler/jac.lark:339:339"
```yaml linenums="333"
--8<-- "jaclang/compiler/jac.lark:333:333"
```
**Description**

Expand All @@ -949,8 +913,8 @@
--8<-- "examples/reference/atomic_pipe_back_expressions.py"
```
??? example "Jac Grammar Snippet"
```yaml linenums="342"
--8<-- "jaclang/compiler/jac.lark:342:342"
```yaml linenums="336"
--8<-- "jaclang/compiler/jac.lark:336:336"
```
**Description**

Expand All @@ -967,8 +931,8 @@
--8<-- "examples/reference/data_spatial_spawn_expressions.py"
```
??? example "Jac Grammar Snippet"
```yaml linenums="345"
--8<-- "jaclang/compiler/jac.lark:345:345"
```yaml linenums="339"
--8<-- "jaclang/compiler/jac.lark:339:339"
```
**Description**

Expand All @@ -985,8 +949,8 @@
--8<-- "examples/reference/unpack_expressions.py"
```
??? example "Jac Grammar Snippet"
```yaml linenums="348"
--8<-- "jaclang/compiler/jac.lark:348:348"
```yaml linenums="342"
--8<-- "jaclang/compiler/jac.lark:342:342"
```
**Description**

Expand All @@ -1002,13 +966,49 @@
```python linenums="1"
--8<-- "examples/reference/references_(unused).py"
```
??? example "Jac Grammar Snippet"
```yaml linenums="345"
--8<-- "jaclang/compiler/jac.lark:345:345"
```
**Description**

--8<-- "examples/reference/references_(unused).md"

## Pipe expressions
**Code Example**
=== "Jac"
```jac linenums="1"
--8<-- "examples/reference/pipe_expressions.jac"
```
=== "Python"
```python linenums="1"
--8<-- "examples/reference/pipe_expressions.py"
```
??? example "Jac Grammar Snippet"
```yaml linenums="348"
--8<-- "jaclang/compiler/jac.lark:348:348"
```
**Description**

--8<-- "examples/reference/pipe_expressions.md"

## Pipe back expressions
**Code Example**
=== "Jac"
```jac linenums="1"
--8<-- "examples/reference/pipe_back_expressions.jac"
```
=== "Python"
```python linenums="1"
--8<-- "examples/reference/pipe_back_expressions.py"
```
??? example "Jac Grammar Snippet"
```yaml linenums="351"
--8<-- "jaclang/compiler/jac.lark:351:351"
```
**Description**

--8<-- "examples/reference/references_(unused).md"
--8<-- "examples/reference/pipe_back_expressions.md"

## Data spatial calls
**Code Example**
Expand Down
Loading