* Replaced all from ...py23 import * with explicit name imports, or removed completely when possible.
* Replaced tounicode() with tostr()
* Changed all BytesIO ans StringIO imports to from io import ..., replaced all UnicodeIO with StringIO.
* Replaced all unichr() with chr()
* Misc minor tweaks and fixes
Refactors feaLib, moving code which builds OpenType lookups into otlLib. Note that this changes feaLib's concept of `location` from a tuple to an object.
This makes the directory to search for included files explicit.
Also use Python 3's FileNotFoundError to catch non-existant files instead of a workaround for Python 2.
In the IncludedFeaNotFound error, pass on the filename token as
it was included in the include statement, so that a client can do their
thing (e.g. issue a warning to suggest the user to write the path
relative to the UFO itself, instead of relative to the feautures.fea
which is inside a UFO).
Also. resolve includes relative to current working directory when the
IncludingLexer' filename is None because it originates from an in-memory stream.
Currently, the feature file parser always resolves included files,
parses their content and inserts it in the resulting AST. The original
`include` statement is lost.
This commit introduces an option to not follow inclusions. Instead, the
output AST will contain an `include` statement. This allows to process a
feature file on its own, and allows to round-trip it.
For example in glyphsLib, when going from a UFO to a .glyphs file, a
UFO feature file will be sliced up into Glyphs.app classes (e.g. a
GSFeaturePrefix with code `include(../family.fea);`) and when going back
from .glyphs to UFO, the feature file will be patched back together.
http://www.adobe.com/devnet/opentype/afdko/topic_feature_file_syntax.html#10
For example, @mhosken is interested in experimenting with inlining
custom syntax (such as Python snippets) into feature files. After this
change, such experiments can be done on top of feaLib because the
Abstract Syntax Tree now contains the tag and content of `anonymous`
blocks.
Since py23 modifies some essential builtins, it's safe to import
everything all the time. At least, that's how it was designed.
It's a bug if importing * breaks some code.
This simplifies the public API to the library. For clients, it does
not matter which exact component was detecting an error. And we will
soon have more components; there would be little point in declaring
CompilerError, TableBuilderError, and so forth.
The OpenType Feature File specification does not specify hex numbers
as explicit token type, but they appear several times in the examples
given by the spec.
When the lexer encounters the "include" keyword, it now enters
a special mode for scanning file names. After having scanned over
the file name, the lexer goes back to normal. The exact format
of file name strings is not defined by the OpenType feature file
specification, so we accept any character that is not a closing
parenthesis.
This simplifies the implementation of the parser for
OpenType feature files, since it can now just keep
token locations returned by the lexer. Before this
change, the parser had to un-pack the location tuples
and build new tuples that included the file path.