Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Needs to create actual structs, not just a tree #1

Open
ctrlcctrlv opened this issue May 12, 2021 · 0 comments
Open

Needs to create actual structs, not just a tree #1

ctrlcctrlv opened this issue May 12, 2021 · 0 comments

Comments

@ctrlcctrlv
Copy link
Contributor

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:

  • Whether tags match. I can't specify in a grammar that the beginning tag and end tag must equal one another.
  • Whether classes exist before being called. Goes also for anchors.
  • Whether lookups exist before being called.

Pinging also @davelab6, who may be interested to know that this project is now public, and likely to replace wrl/otf-fea-rs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant