Skip to content

Commit

Permalink
elvis operator was removed.
Browse files Browse the repository at this point in the history
  • Loading branch information
ThakeeNathees committed Jan 1, 2025
1 parent 1942ca1 commit b2bd095
Show file tree
Hide file tree
Showing 10 changed files with 3 additions and 62 deletions.
5 changes: 0 additions & 5 deletions jac/examples/reference/elvis_expressions.jac

This file was deleted.

Empty file.
5 changes: 0 additions & 5 deletions jac/examples/reference/elvis_expressions.py

This file was deleted.

1 change: 0 additions & 1 deletion jac/jaclang/compiler/constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,6 @@ class Tokens(str, Enum):
ABILITY_OP = "ABILITY_OP"
A_PIPE_FWD = "A_PIPE_FWD"
A_PIPE_BKWD = "A_PIPE_BKWD"
ELVIS_OP = "ELVIS_OP"
RETURN_HINT = "RETURN_HINT"
NULL_OK = "NULL_OK"
DECOR_OP = "DECOR_OP"
Expand Down
6 changes: 1 addition & 5 deletions jac/jaclang/compiler/jac.lark
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,7 @@ lambda_expr: KW_WITH func_decl_params? (RETURN_HINT expression)? KW_CAN expressi
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
pipe_back: (pipe_back PIPE_BKWD)? bitwise_or

// Bitwise expressions
bitwise_or: (bitwise_or BW_OR)? bitwise_xor
Expand Down Expand Up @@ -599,7 +596,6 @@ PIPE_BKWD: /<\|/
DOT_FWD: /\.>/
DOT_BKWD: /<\./
RETURN_HINT: /->/
ELVIS_OP: /\?:/
NULL_OK: /\?/
MATMUL_EQ: /@=/
DECOR_OP: /@/
Expand Down
12 changes: 2 additions & 10 deletions jac/jaclang/compiler/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2037,16 +2037,8 @@ def pipe(self, kid: list[ast.AstNode]) -> ast.Expr:
def pipe_back(self, kid: list[ast.AstNode]) -> ast.Expr:
"""Grammar rule.
pipe_back: elvis_check PIPE_BKWD pipe_back
| elvis_check
"""
return self.binary_expr_unwind(kid)

def elvis_check(self, kid: list[ast.AstNode]) -> ast.Expr:
"""Grammar rule.
elvis_check: bitwise_or ELVIS_OP elvis_check
| bitwise_or
pipe_back: bitwise_or PIPE_BKWD pipe_back
| bitwise_or
"""
return self.binary_expr_unwind(kid)

Expand Down
19 changes: 0 additions & 19 deletions jac/jaclang/compiler/passes/main/pyast_gen_pass.py
Original file line number Diff line number Diff line change
Expand Up @@ -2482,25 +2482,6 @@ def translate_jac_bin_op(self, node: ast.BinaryExpr) -> list[ast3.AST]:
return func_node.gen.py_ast
elif node.op.name == Tok.PIPE_FWD and isinstance(node.right, ast.TupleVal):
self.error("Invalid pipe target.")
elif node.op.name == Tok.ELVIS_OP:
self.needs_jac_feature()
return [
self.sync(
ast3.Call(
func=self.sync(
ast3.Attribute(
value=self.sync(
ast3.Name(id=Con.JAC_FEATURE.value, ctx=ast3.Load())
),
attr="elvis",
ctx=ast3.Load(),
)
),
args=[node.left.gen.py_ast[0], node.right.gen.py_ast[0]],
keywords=[],
)
)
]
else:
self.error(
f"Binary operator {node.op.value} not supported in bootstrap Jac"
Expand Down
6 changes: 0 additions & 6 deletions jac/jaclang/plugin/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -888,12 +888,6 @@ def run_test(

return ret_count

@staticmethod
@hookimpl
def elvis(op1: Optional[T], op2: T) -> T:
"""Jac's elvis operator feature."""
return ret if (ret := op1) is not None else op2

@staticmethod
@hookimpl
def has_instance_default(gen_func: Callable[[], T]) -> T:
Expand Down
5 changes: 0 additions & 5 deletions jac/jaclang/plugin/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,11 +375,6 @@ def run_test(
verbose=verbose,
)

@staticmethod
def elvis(op1: Optional[T], op2: T) -> T:
"""Jac's elvis operator feature."""
return plugin_manager.hook.elvis(op1=op1, op2=op2)

@staticmethod
def has_instance_default(gen_func: Callable[[], T]) -> T:
"""Jac's has container default feature."""
Expand Down
6 changes: 0 additions & 6 deletions jac/jaclang/plugin/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,12 +354,6 @@ def run_test(
"""Run the test suite in the specified .jac file."""
raise NotImplementedError

@staticmethod
@hookspec(firstresult=True)
def elvis(op1: Optional[T], op2: T) -> T:
"""Jac's elvis operator feature."""
raise NotImplementedError

@staticmethod
@hookspec(firstresult=True)
def has_instance_default(gen_func: Callable[[], T]) -> T:
Expand Down

0 comments on commit b2bd095

Please sign in to comment.