Browse Source

Added support for longer ligatures

- Breaking out the ligature substitution rules like this also allows for
 easy logical extensions, to handle edge cases as FiraCode does.
pull/134/head
John Mager 2 years ago
parent
commit
824cd6a9f8
  1. 65
      Scripts/features.py

65
Scripts/features.py

@ -44,36 +44,41 @@ def rule(liga):
[LIG f i] LIG
[ f f i] LIG }
"""
if len(liga) == 2:
return dedent('''\
lookup {0}_{1} {{
ignore sub {0} {0}' {1};
ignore sub {0}' {1} {1};
sub {0}' {1} by LIG;
sub LIG {1}' by {0}_{1}.liga;
}} {0}_{1};
''').format(*liga)
elif len(liga) == 3:
return dedent('''\
lookup {0}_{1}_{2} {{
ignore sub {0} {0}' {1} {2};
ignore sub {0}' {1} {2} {2};
sub {0}' {1} {2} by LIG;
sub LIG {1}' {2} by LIG;
sub LIG LIG {2}' by {0}_{1}_{2}.liga;
}} {0}_{1}_{2};
''').format(*liga)
elif len(liga) == 4:
return dedent('''\
lookup {0}_{1}_{2}_{3} {{
ignore sub {0} {0}' {1} {2} {3};
ignore sub {0}' {1} {2} {3} {3};
sub {0}' {1} {2} {3} by LIG;
sub LIG {1}' {2} {3} by LIG;
sub LIG LIG {2}' {3} by LIG;
sub LIG LIG LIG {3}' by {0}_{1}_{2}_{3}.liga;
}} {0}_{1}_{2}_{3};
''').format(*liga)
# ignores:
# ignore sub {0} {0}' {1};
# ignore sub {0}' {1} {1};
rules = [
ignore(prefix=liga[:1], head=liga[0], suffix=liga[1:]),
ignore(head=liga[0], suffix=(liga[1:] + [liga[-1]])),
]
name = "_".join(liga)
# substitution logic
# sub {0}' {1} by LIG;
# sub LIG {1}' by {0}_{1}.liga;
for i in range(len(liga)):
init = _join(["LIG" for lig in liga[:i]])
tail = _join(liga[i + 1 :])
replace = "LIG" if (i + 1 < len(liga)) else (name + ".liga")
rules.append("sub{0} {1}'{2} by {3};".format(init, liga[i], tail, replace))
# put it all together
lines = (
["lookup " + name + " {"] + [" " + r for r in rules] + ["}} {0};".format(name)]
)
return "\n".join(lines)
def _join(items):
return (" " + " ".join(items)) if items else ""
def ignore(prefix=None, head=None, suffix=None):
""" don't substitute `head` if it's surrounded by `prefix` and `suffix` """
assert head
pref = _join(prefix)
rest = _join(suffix)
return "ignore sub{0} {1}'{2};".format(pref, head, rest)
def indent(text, prefix):

Loading…
Cancel
Save