Skip to content

Commit

Permalink
Remove symbols from code formatters (#1591)
Browse files Browse the repository at this point in the history
Remove all the symbols from the code formatter capture.

Before: `"hammer one plus"` -> `One+`
Now: `"hammer one plus"` -> `OnePlus`

Fixes #1575

---------

Co-authored-by: Nicholas Riley <com-github@sabi.net>
  • Loading branch information
AndreasArvidsson and nriley authored Nov 10, 2024
1 parent b082ac6 commit e52eb18
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions core/text/formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,6 @@ def code_formatters(m) -> str:


@mod.capture(
# Note that if the user speaks something like "snake dot", it will
# insert "dot" - otherwise, they wouldn't be able to insert punctuation
# words directly.
rule="<self.formatters> <user.text> (<user.text> | <user.formatter_immune>)*"
)
def format_text(m) -> str:
Expand All @@ -385,12 +382,10 @@ def format_text(m) -> str:
return out


@mod.capture(
rule="<self.code_formatters> <user.text> (<user.text> | <user.formatter_immune>)*"
)
@mod.capture(rule="<user.code_formatters> <user.text>")
def format_code(m) -> str:
"""Formats code and returns a string"""
return format_text(m)
return format_phrase(m.text, m.code_formatters)


class ImmuneString:
Expand All @@ -401,14 +396,15 @@ def __init__(self, string):


@mod.capture(
# Add anything else into this that you want to be able to speak during a
# formatter.
# Add anything else into this that you want to have inserted when
# using a prose formatter.
rule="(<user.symbol_key> | (numb | numeral) <number>)"
)
def formatter_immune(m) -> ImmuneString:
"""Text that can be interspersed into a formatter, e.g. characters.
"""Symbols and numbers that can be interspersed into a prose formatter
(i.e., not dictated immediately after the name of the formatter)
It will be inserted directly, without being formatted.
They will be inserted directly, without being formatted.
"""
if hasattr(m, "number"):
Expand Down

0 comments on commit e52eb18

Please sign in to comment.