Browse Source

Parsing of chord \[: solved bug when parsing \[A]word\[B]

In previous version, chord `B` was included into chord `A`. Now, they
are adjacent, as expected.
pull/58/head
Louis 10 years ago
parent
commit
278acc8438
  1. 15
      patacrep/plastex_chord.py

15
patacrep/plastex_chord.py

@ -76,6 +76,10 @@ def match_egroup(token):
"""Return True if token is of type `egroup` (end of group).""" """Return True if token is of type `egroup` (end of group)."""
return isinstance(token, plasTeX.Base.Text.egroup) #pylint: disable=no-member return isinstance(token, plasTeX.Base.Text.egroup) #pylint: disable=no-member
def match_space_or_chord(token):
"""Return True if token is a space or a chord."""
return match_space(token) or isinstance(token, Chord)
def parse_until(tex, end=lambda x: False): def parse_until(tex, end=lambda x: False):
"""Parse `tex` until condition `end`, or `egroup` is met. """Parse `tex` until condition `end`, or `egroup` is met.
@ -160,11 +164,14 @@ class BeginChordOrDisplayMath(BeginDisplayMath):
return [chord] return [chord]
else: else:
chord.appendChild(token) chord.appendChild(token)
(parsed, last) = parse_until(tex, match_space) (parsed, last) = parse_until(tex, match_space_or_chord)
parsed.append(last)
# pylint: disable=expression-not-assigned # pylint: disable=expression-not-assigned
[chord.appendChild(item) for item in parsed[:-1]] [chord.appendChild(item) for item in parsed]
return [chord] if isinstance(last, Chord):
return [chord, last]
else:
chord.appendChild(last)
return [chord]
else: else:
return super(BeginChordOrDisplayMath, self).invoke(tex) return super(BeginChordOrDisplayMath, self).invoke(tex)

Loading…
Cancel
Save