Skip to content

Commit

Permalink
Migrate python operators (#1747)
Browse files Browse the repository at this point in the history
  • Loading branch information
FireChickenProductivity authored Feb 12, 2025
1 parent 77fc22e commit 90b6d2e
Showing 1 changed file with 49 additions and 107 deletions.
156 changes: 49 additions & 107 deletions lang/python/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from talon import Context, Module, actions, settings

from ..tags.operators import Operators

mod = Module()
ctx = Context()
ctx.matches = r"""
Expand Down Expand Up @@ -145,116 +147,56 @@
for exception in exception_list
}

operators = Operators(
# code_operators_array
SUBSCRIPT=lambda: actions.user.insert_between("[", "]"),
# code_operators_assignment
ASSIGNMENT=" = ",
ASSIGNMENT_SUBTRACTION=" -= ",
ASSIGNMENT_ADDITION=" += ",
ASSIGNMENT_MULTIPLICATION=" *= ",
ASSIGNMENT_DIVISION=" /= ",
ASSIGNMENT_MODULO=" %= ",
ASSIGNMENT_INCREMENT="+= 1",
ASSIGNMENT_BITWISE_AND=" &= ",
ASSIGNMENT_BITWISE_OR=" |= ",
ASSIGNMENT_BITWISE_EXCLUSIVE_OR=" ^= ",
ASSIGNMENT_BITWISE_LEFT_SHIFT=" <<= ",
ASSIGNMENT_BITWISE_RIGHT_SHIFT=" >>= ",
# code_operators_bitwise
BITWISE_NOT="~",
BITWISE_AND=" & ",
BITWISE_OR=" | ",
BITWISE_EXCLUSIVE_OR=" ^ ",
BITWISE_LEFT_SHIFT=" << ",
BITWISE_RIGHT_SHIFT=" >> ",
# code_operators_lambda
LAMBDA=lambda: actions.user.insert_between("lambda ", ": "),
# code_operators_math
MATH_SUBTRACT=" - ",
MATH_ADD=" + ",
MATH_MULTIPLY=" * ",
MATH_DIVIDE=" / ",
MATH_MODULO=" % ",
MATH_EXPONENT=" ** ",
MATH_EQUAL=" == ",
MATH_NOT_EQUAL=" != ",
MATH_GREATER_THAN=" > ",
MATH_GREATER_THAN_OR_EQUAL=" >= ",
MATH_LESS_THAN=" < ",
MATH_LESS_THAN_OR_EQUAL=" <= ",
MATH_AND=" and ",
MATH_OR=" or ",
MATH_NOT="not ",
MATH_IN=" in ",
MATH_NOT_IN=" not in ",
)


@ctx.action_class("user")
class UserActions:
def code_operator_lambda():
actions.user.insert_between("lambda ", ": ")

def code_operator_subscript():
actions.user.insert_between("[", "]")

def code_operator_assignment():
actions.auto_insert(" = ")

def code_operator_subtraction():
actions.auto_insert(" - ")

def code_operator_subtraction_assignment():
actions.auto_insert(" -= ")

def code_operator_addition():
actions.auto_insert(" + ")

def code_operator_addition_assignment():
actions.auto_insert(" += ")

def code_operator_multiplication():
actions.auto_insert(" * ")

def code_operator_multiplication_assignment():
actions.auto_insert(" *= ")

def code_operator_exponent():
actions.auto_insert(" ** ")

def code_operator_division():
actions.auto_insert(" / ")

def code_operator_division_assignment():
actions.auto_insert(" /= ")

def code_operator_modulo():
actions.auto_insert(" % ")

def code_operator_modulo_assignment():
actions.auto_insert(" %= ")

def code_operator_equal():
actions.auto_insert(" == ")

def code_operator_not_equal():
actions.auto_insert(" != ")

def code_operator_greater_than():
actions.auto_insert(" > ")

def code_operator_greater_than_or_equal_to():
actions.auto_insert(" >= ")

def code_operator_less_than():
actions.auto_insert(" < ")

def code_operator_less_than_or_equal_to():
actions.auto_insert(" <= ")

def code_operator_and():
actions.auto_insert(" and ")

def code_operator_or():
actions.auto_insert(" or ")

def code_operator_not():
actions.auto_insert("not ")

def code_operator_in():
actions.auto_insert(" in ")

def code_operator_not_in():
actions.auto_insert(" not in ")

def code_operator_bitwise_and():
actions.auto_insert(" & ")

def code_operator_bitwise_and_assignment():
actions.auto_insert(" &= ")

def code_operator_bitwise_or():
actions.auto_insert(" | ")

def code_operator_bitwise_or_assignment():
actions.auto_insert(" |= ")

def code_operator_bitwise_exclusive_or():
actions.auto_insert(" ^ ")

def code_operator_bitwise_exclusive_or_assignment():
actions.auto_insert(" ^= ")

def code_operator_bitwise_not():
actions.auto_insert("~")

def code_operator_bitwise_left_shift():
actions.auto_insert(" << ")

def code_operator_bitwise_left_shift_assignment():
actions.auto_insert(" <<= ")

def code_operator_bitwise_right_shift():
actions.auto_insert(" >> ")

def code_operator_bitwise_right_shift_assignment():
actions.auto_insert(" >>= ")
def code_get_operators() -> Operators:
return operators

def code_self():
actions.auto_insert("self")
Expand Down

0 comments on commit 90b6d2e

Please sign in to comment.