Skip to content

Commit

Permalink
formatting: minor cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
benoit-pierre committed Apr 4, 2020
1 parent bb87d9b commit e25295a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
4 changes: 2 additions & 2 deletions plover/dictionary/rtfcre_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from plover.steno import normalize_steno
from plover.steno_dictionary import StenoDictionary
# TODO: Move dictionary format somewhere more canonical than formatting.
from plover.formatting import META_RE
from plover.formatting import ATOM_RE


# A regular expression to capture an individual entry in the dictionary.
Expand Down Expand Up @@ -287,7 +287,7 @@ def load_stylesheet(s):
"{\\stylesheet{\\s0 Normal;}}\r\n")

def format_translation(t):
t = ' '.join([x.strip() for x in META_RE.findall(t) if x.strip()])
t = ' '.join([x.strip() for x in ATOM_RE.findall(t) if x.strip()])

t = re.sub(r'{\.}', r'{\\cxp. }', t)
t = re.sub(r'{!}', r'{\\cxp! }', t)
Expand Down
16 changes: 6 additions & 10 deletions plover/formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
META_ESC_START = META_ESCAPE + META_START
META_ESC_END = META_ESCAPE + META_END

META_RE = re.compile(r"""(?:%s%s|%s%s|[^%s%s])+ # One or more of anything
ATOM_RE = re.compile(r"""(?:%s%s|%s%s|[^%s%s])+ # One or more of anything
# other than unescaped { or }
#
| # or
Expand Down Expand Up @@ -107,8 +107,7 @@ def __init__(self, previous_translations):
def iter_last_actions(self):
"""Iterate over past actions (last first)."""
for translation in reversed(self.previous_translations):
for action in reversed(translation.formatting):
yield action
yield from reversed(translation.formatting)

def iter_last_fragments(self):
"""Iterate over last text fragments (last first).
Expand Down Expand Up @@ -136,8 +135,7 @@ def iter_last_fragments(self):
if part:
# Find out new complete fragments.
fragments = self.FRAGMENT_RX.findall(part + current_fragment)
for f in reversed(fragments[1:]):
yield f
yield from reversed(fragments[1:])
current_fragment = fragments[0]
replace += len(action.prev_replace)
next_action = action
Expand Down Expand Up @@ -221,10 +219,8 @@ def translated(self, action):

def iter_last_actions(self):
"""Custom iterator with support for newly translated actions."""
for action in reversed(self.translated_actions):
yield action
for action in super().iter_last_actions():
yield action
yield from reversed(self.translated_actions)
yield from super().iter_last_actions()


class Formatter:
Expand Down Expand Up @@ -628,7 +624,7 @@ def _translation_to_actions(translation, ctx):
atoms = [_glue_translation(translation)]
else:
atoms = filter(None, (
x.strip(' ') for x in META_RE.findall(translation))
x.strip(' ') for x in ATOM_RE.findall(translation))
)
action_list = []
for atom in atoms:
Expand Down

0 comments on commit e25295a

Please sign in to comment.