From 236d42dda5160b88e6d0437cccc13d0853a9001a Mon Sep 17 00:00:00 2001 From: James Godfrey-Kittle Date: Fri, 27 Mar 2015 12:29:51 -0700 Subject: Handle new contextual feature rules. This depends on our own version of feaTools, which is a bit hacky. Ideally we should use something more robust that feaTools (e.g. a full feature syntax compiler). This also adds a message about the feaTools dependency to the readme, which I forgot about before. --- scripts/lib/fontbuild/features.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'scripts') diff --git a/scripts/lib/fontbuild/features.py b/scripts/lib/fontbuild/features.py index 898aa56..1f59801 100755 --- a/scripts/lib/fontbuild/features.py +++ b/scripts/lib/fontbuild/features.py @@ -26,7 +26,7 @@ parser.classContentRE = re.compile( parser.sequenceInlineClassRE = re.compile( "\[" # [ "([\w\d\s_.@']+)" # content - "\]" # ] + "\]'?" # ], optional contextual marking ) # allow apostrophes in the target and replacement of a substitution @@ -76,8 +76,19 @@ class FilterFeatureWriter(FDKSyntaxFeatureWriter): """Use this class for nested expressions e.g. in feature definitions.""" return FilterFeatureWriter(self.refs, name, isFeature) + def _flattenRefs(self, refs): + """Flatten a list of references.""" + flatRefs = [] + for ref in refs: + if type(ref) == list: + flatRefs.extend(self._flattenRefs(ref)) + elif ref != "'": # ignore contextual class markings + flatRefs.append(ref) + return flatRefs + def _checkRefs(self, refs, errorMsg): """Check a list of references found in a sub or pos rule.""" + refs = self._flattenRefs(refs) for ref in refs: # trailing apostrophes should be ignored if ref[-1] == "'": @@ -105,14 +116,12 @@ class FilterFeatureWriter(FDKSyntaxFeatureWriter): def gsubType1(self, target, replacement): """Check a sub rule with one-to-one replacement.""" - if type(target) == str: - target, replacement = [target], [replacement] - if self._checkRefs(target + replacement, self.subErr): + if self._checkRefs([target, replacement], self.subErr): super(FilterFeatureWriter, self).gsubType1(target, replacement) def gsubType4(self, target, replacement): """Check a sub rule with many-to-one replacement.""" - if self._checkRefs(target + [replacement], self.subErr): + if self._checkRefs([target, replacement], self.subErr): super(FilterFeatureWriter, self).gsubType4(target, replacement) def gposType1(self, target, value): -- cgit v1.2.3