mfek / feaparser.rlib Goto Github PK
View Code? Open in Web Editor NEWThe beginnings of an Adobe FEA (feature file syntax) parser
License: Apache License 2.0
The beginnings of an Adobe FEA (feature file syntax) parser
License: Apache License 2.0
We all know that FEE's implementation in fontFeatures is very slow.
Does @simoncozens think that feaparser.rlib should also do any FEE-like input transformations? Should it allow people to add Rust callbacks to the parser for arbitrary tag names not in the FEA standard?
Or is fontFeatures, although slow, good enough? Should we instead focus on porting the slow parts of Python fontFeatures to Rust?
Even when reordered to make the test easier, still fails〜
diff --git a/src/lib.rs b/src/lib.rs
index c7ecf89..3d70059 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -37,8 +37,8 @@ mod tests {
# include(te)st); would fail
include (lol);
+ anonymous jjig { test; } jjig;
anonymous jig { @lol = [lol]; {@Q = [Q R S T];} name ";}{"; {}; "}"; } jig;
- anonymous jjig { } jjig;
anonymous jjig {} jjig;
anonymous FIVE { {} {} {} } FIVE;
# This'd be invalid FEA syntax due to tag mismatch. It's up to struct builder to check this! Not possible in a grammar.
running 8 tests
test language::tests::test_languages ... ok
test script::tests::test_scripts ... ok
test tests::test_anchor ... ok
test tests::test_feature_names ... ok
test tests::test_pos_mark ... ok
test tests::test_feaparser ... FAILED
test tests::test_pos_mark_2 ... ok
test tests::test_fonttools_test_suite ... ok
failures:
---- tests::test_feaparser stdout ----
thread 'tests::test_feaparser' panicked at 'called `Result::unwrap()` on an `Err` value: Error { variant: ParsingError { positives: [A_BLOCK, COMMENT], negatives: [] }, location: Pos(141), line_col: Pos((7, 15)), path: None, line: " anonymous jjig { test; } jjig;␊", continued_line: None }', src/lib.rs:139:45
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
failures:
tests::test_feaparser
test result: FAILED. 7 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.05s
Right now this is just a mostly complete grammar which generates an abstract syntax tree (AST).
The default test, test_feaparser
on src/lib.rs
, takes this input:
@lol = [Qol Mol @lol];
languagesystem DFLT dflt;
language DEU required;
include(te\)st);
# include(te)st); would fail
include (lol);
anonymous jig { @lol = [lol]; {@Q = [Q R S T];} name ";}{"; {}; "}"; } jig;
anonymous jjig { } jjig;
anonymous jjig {} jjig;
anonymous FIVE { {} {} {} } FIVE;
# This'd be invalid FEA syntax due to tag mismatch. It's up to struct builder to check this! Not possible in a grammar.
anonymous LAST {
It's the end of the world as we know it
And I feel fine!
} FRST;
anonymous LAST {} LAST;
name 0x3 0x1 0x411;
feature mark {
} mark;
feature liga {
featureNames {
name 0x3 0x1 0x411 "Feature description for MS Platform, script Unicode, language Japanese";
name "b";
};
name "C";
} liga;
table GDEF {
LigatureCaretByPos lol 0;
} GDEF;
table head {
FontRevision 0.0;
} head;
table OS/2 {
FSType 4;
Panose 2 15 0 0 2 2 8 2 9 4;
TypoAscender 800;
TypoDescender -200; # Note that TypoDescender is negative for descent below the baseline.
winAscent 832;
winDescent 321; # Note that winDescent is positive for descent below the baseline.
UnicodeRange
0 # Basic Latin
1 # Latin-1 Supplement
9 # Cyrillic
55 # CJK Compatibility
59 # CJK Unified Ideographs
60 # Private Use Area
;
CodePageRange
1252 # Latin 1
1251 # Cyrillic
932 # JIS/Japan
;
XHeight 400;
CapHeight 600;
WeightClass 800;
WidthClass 3;
Vendor "ADBE";
FamilyClass 0x0805; # Class 8 (Sans-serif), Subclass 5 (Neo-grotesque Gothic)
} OS/2;
feature aalt {
featureNames {
name "Fancy Q's";
};
lookup aalt_1 {
sub Q from [Q.ss01 Q.ss02 Q.ss03];
} aalt_1;
} aalt;
variation rvrn heavy {
lookup symbols_heavy;
lookup letters_heavy;
} rvrn;
anchorDef 120 120 ANCHOR_1;
anchorDef 120 -20 contourpoint 5 ANCHOR_2;
valueRecordDef -10 FIRST_KERN;
valueRecordDef <0 0 20 0> SECOND_KERN;
feature liga {
sub A by B;
sub @A by @B;
sub B by A B C;
sub f f by f_f;
subtable;
sub f i by f_i;
sub f l by f_l;
sub f l' lookup test;
sub f l' by y;
sub Q by NULL;
lookup inside_lu {sub \NULL by NULL;}inside_lu;
} liga;
# comment ça va
#
And makes this enormous tree:
├─ class_definition_statement
│ ├─ class_inner "lol"
│ └─ inline_class
│ ├─ barename "Qol"
│ ├─ barename "Mol"
│ └─ class_inner "lol"
├─ languagesystem_statement
│ ├─ script
│ │ └─ tag "DFLT"
│ └─ language
│ └─ tag "dflt"
├─ language_statement
│ ├─ language
│ │ └─ tag "DEU"
│ └─ required_tag "required"
├─ include_statement
│ └─ include_inner "te\\)st"
├─ COMMENT
│ └─ comment_inner "include(te)st);\ would\ fail"
├─ include_statement
│ └─ include_inner "lol"
├─ anonymous_statement
│ ├─ tag "jig"
│ ├─ anonymous_inner "@lol\ =\ [lol];"
│ ├─ anonymous_inner "{@Q\ =\ [Q\ R\ S\ T];}"
│ ├─ anonymous_inner "name"
│ ├─ anonymous_inner "";}{";"
│ ├─ anonymous_inner "{};"
│ ├─ anonymous_inner ""}";"
│ └─ tag "jig"
├─ anonymous_statement
│ ├─ tag "jjig"
│ └─ tag "jjig"
├─ anonymous_statement
│ ├─ tag "jjig"
│ └─ tag "jjig"
├─ anonymous_statement
│ ├─ tag "FIVE"
│ ├─ anonymous_inner "{}"
│ ├─ anonymous_inner "{}"
│ ├─ anonymous_inner "{}"
│ └─ tag "FIVE"
├─ COMMENT
│ └─ comment_inner "This'd\ be\ invalid\ FEA\ syntax\ due\ to\ tag\ mismatch.\ It's\ up\ to\ struct\ builder\ to\ check\ this!\ Not\ possible\ in\ a\ grammar."
├─ anonymous_statement
│ ├─ tag "LAST"
│ ├─ anonymous_inner "It's\ the\ end\ of\ the\ world\ as\ we\ know\ it\n\ \ \ \ \ \ \ \ And\ I\ feel\ fine!"
│ └─ tag "FRST"
├─ name_statement
│ ├─ fea_integer "0x3"
│ ├─ fea_integer "0x1"
│ └─ fea_integer "0x411"
├─ feature_statement
│ ├─ tag "mark"
│ └─ tag "mark"
├─ feature_statement
│ ├─ tag "liga"
│ ├─ feature_names_statement
│ │ ├─ name_statement
│ │ │ ├─ fea_integer "0x3"
│ │ │ ├─ fea_integer "0x1"
│ │ │ ├─ fea_integer "0x411"
│ │ │ └─ quoted_string
│ │ │ └─ qs_inner "Feature\ description\ for\ MS\ Platform,\ script\ Unicode,\ language\ Japanese"
│ │ └─ name_statement
│ │ └─ quoted_string
│ │ └─ qs_inner "b"
│ ├─ name_statement
│ │ └─ quoted_string
│ │ └─ qs_inner "C"
│ └─ tag "liga"
├─ table_statement
│ └─ table_gdef_statement
│ └─ gdef_block
│ └─ gdef_statement
│ └─ ligaturecaretbypos_gdef_statement
│ ├─ barename "lol"
│ └─ fea_integer "0"
├─ table_statement
│ └─ table_head_statement
│ └─ font_revision_statement
│ └─ version "0.0"
├─ table_statement
│ └─ table_os2_statement
│ └─ os2_block
│ ├─ os2_statement
│ │ └─ os2_single_number
│ │ ├─ os2_single_number_tag "FSType"
│ │ └─ fea_integer "4"
│ ├─ os2_statement
│ │ └─ os2_panose
│ │ ├─ fea_integer "2"
│ │ ├─ fea_integer "15"
│ │ ├─ fea_integer "0"
│ │ ├─ fea_integer "0"
│ │ ├─ fea_integer "2"
│ │ ├─ fea_integer "2"
│ │ ├─ fea_integer "8"
│ │ ├─ fea_integer "2"
│ │ ├─ fea_integer "9"
│ │ └─ fea_integer "4"
│ ├─ os2_statement
│ │ └─ os2_single_number
│ │ ├─ os2_single_number_tag "TypoAscender"
│ │ └─ fea_integer "800"
│ ├─ os2_statement
│ │ └─ os2_single_number
│ │ ├─ os2_single_number_tag "TypoDescender"
│ │ └─ fea_integer "-200"
│ ├─ COMMENT
│ │ └─ comment_inner "Note\ that\ TypoDescender\ is\ negative\ for\ descent\ below\ the\ baseline."
│ ├─ os2_statement
│ │ └─ os2_single_number
│ │ ├─ os2_single_number_tag "winAscent"
│ │ └─ fea_integer "832"
│ ├─ os2_statement
│ │ └─ os2_single_number
│ │ ├─ os2_single_number_tag "winDescent"
│ │ └─ fea_integer "321"
│ ├─ COMMENT
│ │ └─ comment_inner "Note\ that\ winDescent\ is\ positive\ for\ descent\ below\ the\ baseline."
│ ├─ os2_statement
│ │ ├─ os2_range
│ │ │ ├─ os2_range_tag "UnicodeRange"
│ │ │ ├─ fea_integer "0"
│ │ │ ├─ COMMENT
│ │ │ │ └─ comment_inner "Basic\ Latin"
│ │ │ ├─ fea_integer "1"
│ │ │ ├─ COMMENT
│ │ │ │ └─ comment_inner "Latin-1\ Supplement"
│ │ │ ├─ fea_integer "9"
│ │ │ ├─ COMMENT
│ │ │ │ └─ comment_inner "Cyrillic"
│ │ │ ├─ fea_integer "55"
│ │ │ ├─ COMMENT
│ │ │ │ └─ comment_inner "CJK\ Compatibility"
│ │ │ ├─ fea_integer "59"
│ │ │ ├─ COMMENT
│ │ │ │ └─ comment_inner "CJK\ Unified\ Ideographs"
│ │ │ └─ fea_integer "60"
│ │ └─ COMMENT
│ │ └─ comment_inner "Private\ Use\ Area"
│ ├─ os2_statement
│ │ ├─ os2_range
│ │ │ ├─ os2_range_tag "CodePageRange"
│ │ │ ├─ fea_integer "1252"
│ │ │ ├─ COMMENT
│ │ │ │ └─ comment_inner "Latin\ 1"
│ │ │ ├─ fea_integer "1251"
│ │ │ ├─ COMMENT
│ │ │ │ └─ comment_inner "Cyrillic"
│ │ │ └─ fea_integer "932"
│ │ └─ COMMENT
│ │ └─ comment_inner "JIS/Japan"
│ ├─ os2_statement
│ │ └─ os2_single_number
│ │ ├─ os2_single_number_tag "XHeight"
│ │ └─ fea_integer "400"
│ ├─ os2_statement
│ │ └─ os2_single_number
│ │ ├─ os2_single_number_tag "CapHeight"
│ │ └─ fea_integer "600"
│ ├─ os2_statement
│ │ └─ os2_single_number
│ │ ├─ os2_single_number_tag "WeightClass"
│ │ └─ fea_integer "800"
│ ├─ os2_statement
│ │ └─ os2_single_number
│ │ ├─ os2_single_number_tag "WidthClass"
│ │ └─ fea_integer "3"
│ ├─ os2_statement
│ │ └─ os2_vendor
│ │ └─ os2_vendor_id "ADBE"
│ ├─ os2_statement
│ │ └─ os2_single_number
│ │ ├─ os2_single_number_tag "FamilyClass"
│ │ └─ fea_integer "0x0805"
│ └─ COMMENT
│ └─ comment_inner "Class\ 8\ (Sans-serif),\ Subclass\ 5\ (Neo-grotesque\ Gothic)"
├─ feature_statement
│ ├─ tag "aalt"
│ ├─ feature_names_statement
│ │ └─ name_statement
│ │ └─ quoted_string
│ │ └─ qs_inner "Fancy\ Q's"
│ ├─ lookup_statement
│ │ ├─ lookup_tag "lookup"
│ │ ├─ lookup_name "aalt_1"
│ │ ├─ gsub_statement
│ │ │ └─ gsub_3
│ │ │ ├─ sub_tag "sub"
│ │ │ ├─ barename "Q"
│ │ │ ├─ from_tag "from"
│ │ │ └─ inline_class
│ │ │ ├─ barename "Q.ss01"
│ │ │ ├─ barename "Q.ss02"
│ │ │ └─ barename "Q.ss03"
│ │ └─ lookup_name "aalt_1"
│ └─ tag "aalt"
├─ variation_statement
│ ├─ variation_tag "variation"
│ ├─ tag "rvrn"
│ ├─ variation_name "heavy"
│ ├─ variation_block
│ │ ├─ variation_lookup_statement
│ │ │ ├─ lookup_tag "lookup"
│ │ │ └─ lookup_name "symbols_heavy"
│ │ └─ variation_lookup_statement
│ │ ├─ lookup_tag "lookup"
│ │ └─ lookup_name "letters_heavy"
│ └─ tag "rvrn"
├─ anchordef_statement
│ ├─ anchordef_tag "anchorDef"
│ ├─ anchor_coordinates
│ │ ├─ fea_integer "120"
│ │ └─ fea_integer "120"
│ └─ anchor_name
│ └─ name_inner "ANCHOR_1"
├─ anchordef_statement
│ ├─ anchordef_tag "anchorDef"
│ ├─ anchor_coordinates
│ │ ├─ fea_integer "120"
│ │ └─ fea_integer "-20"
│ ├─ contourpoint
│ │ ├─ contourpoint_tag "contourpoint"
│ │ └─ fea_integer "5"
│ └─ anchor_name
│ └─ name_inner "ANCHOR_2"
├─ valuerecorddef_statement
│ ├─ valuerecorddef_tag "valueRecordDef"
│ ├─ valuerecord
│ │ └─ valuerecord1
│ │ └─ fea_integer "-10"
│ └─ valuerecord_name
│ └─ name_inner "FIRST_KERN"
├─ valuerecorddef_statement
│ ├─ valuerecorddef_tag "valueRecordDef"
│ ├─ valuerecord
│ │ └─ valuerecord4
│ │ ├─ fea_integer "0"
│ │ ├─ fea_integer "0"
│ │ ├─ fea_integer "20"
│ │ └─ fea_integer "0"
│ └─ valuerecord_name
│ └─ name_inner "SECOND_KERN"
├─ feature_statement
│ ├─ tag "liga"
│ ├─ gsub_statement
│ │ └─ gsub_1a
│ │ ├─ sub_tag "sub"
│ │ ├─ barename "A"
│ │ ├─ by_tag "by"
│ │ └─ barename "B"
│ ├─ gsub_statement
│ │ └─ gsub_6
│ │ ├─ sub_tag "sub"
│ │ ├─ class_inner "A"
│ │ ├─ by_tag "by"
│ │ └─ class_inner "B"
│ ├─ gsub_statement
│ │ └─ gsub_2a
│ │ ├─ sub_tag "sub"
│ │ ├─ barename "B"
│ │ ├─ by_tag "by"
│ │ └─ gsub_glyph_seq
│ │ ├─ barename "A"
│ │ ├─ barename "B"
│ │ └─ barename "C"
│ ├─ gsub_statement
│ │ └─ gsub_4
│ │ ├─ sub_tag "sub"
│ │ ├─ gsub_glyph_seq
│ │ │ ├─ barename "f"
│ │ │ └─ barename "f"
│ │ ├─ by_tag "by"
│ │ └─ barename "f_f"
│ ├─ subtable_statement "subtable"
│ ├─ gsub_statement
│ │ └─ gsub_4
│ │ ├─ sub_tag "sub"
│ │ ├─ gsub_glyph_seq
│ │ │ ├─ barename "f"
│ │ │ └─ barename "i"
│ │ ├─ by_tag "by"
│ │ └─ barename "f_i"
│ ├─ gsub_statement
│ │ └─ gsub_4
│ │ ├─ sub_tag "sub"
│ │ ├─ gsub_glyph_seq
│ │ │ ├─ barename "f"
│ │ │ └─ barename "l"
│ │ ├─ by_tag "by"
│ │ └─ barename "f_l"
│ ├─ gsub_statement
│ │ └─ gsub_6
│ │ ├─ sub_tag "sub"
│ │ ├─ barename "f"
│ │ ├─ barename "l"
│ │ └─ apply_lookup
│ │ ├─ lookup_tag "lookup"
│ │ └─ lookup_name "test"
│ ├─ gsub_statement
│ │ └─ gsub_6
│ │ ├─ sub_tag "sub"
│ │ ├─ barename "f"
│ │ ├─ barename "l"
│ │ ├─ apply_by "'"
│ │ ├─ by_tag "by"
│ │ └─ barename "y"
│ ├─ gsub_statement
│ │ └─ gsub_2b
│ │ ├─ sub_tag "sub"
│ │ ├─ barename "Q"
│ │ ├─ by_tag "by"
│ │ └─ null_token "NULL"
│ ├─ lookup_statement
│ │ ├─ lookup_tag "lookup"
│ │ ├─ lookup_name "inside_lu"
│ │ ├─ gsub_statement
│ │ │ └─ gsub_2b
│ │ │ ├─ sub_tag "sub"
│ │ │ ├─ barename "\\NULL"
│ │ │ ├─ by_tag "by"
│ │ │ └─ null_token "NULL"
│ │ └─ lookup_name "inside_lu"
│ └─ tag "liga"
├─ COMMENT
│ └─ comment_inner "comment\ ça\ va"
└─ COMMENT "#"
Sorry to make you scroll that much.
The grammar is, as you can see, very far along. But not much else is. @simoncozens knew I was working on this, and was unhappy with wrl/otf-fea-rs. As am I—various issues there, especially wrl/otf-fea-rs#4, show that it's unsuitable for even basic inputs.
So, I uploaded this for him to work on as I'm busy w/other stuff…but I'm still very interested in this problem so am making him issues to close. Basically this is the major one: we need to be generating structs.
The following checks need to be run, which are not run by the parser:
Pinging also @davelab6, who may be interested to know that this project is now public, and likely to replace wrl/otf-fea-rs.
The hope is that fonttools-rs
can be used for this.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.