Class: Fontisan::Ufo::Compile::FeatureCompiler

Inherits:
Object
  • Object
show all
Defined in:
lib/fontisan/ufo/compile/feature_compiler.rb

Overview

Minimal Adobe FEA (features.fea) parser. Extracts the two most common feature constructs from UFO sources:

feature liga { sub f i by fi; } liga;    → LigatureSubst
feature kern { pos A V -50; } kern;       → PairPos

Unsupported constructs are collected and surfaced via ParsedFeatures#unsupported so the caller can decide whether to warn or raise. This is the "limited fea subset" approach from TODO #10b — expand as real-world fonts demand.

The parser is deliberately simple: it tokenizes on whitespace and semicolons, recognizes feature <tag> { ... } <tag>; blocks, and dispatches per-statement to registered rule handlers (OCP — new rule kinds are one handler addition).

Examples:

parsed = FeatureCompiler.parse(fea_text)
parsed.ligatures_for("liga")  # => [{sequence: ["f", "i"], result: "fi"}]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.parse(text) ⇒ ParsedFeatures

Parameters:

  • text (String)

    features.fea content

Returns:



28
29
30
# File 'lib/fontisan/ufo/compile/feature_compiler.rb', line 28

def self.parse(text)
  new.parse(text)
end

Instance Method Details

#parse(text) ⇒ ParsedFeatures

Parameters:

  • text (String)

Returns:



34
35
36
37
38
# File 'lib/fontisan/ufo/compile/feature_compiler.rb', line 34

def parse(text)
  @parsed = ParsedFeatures.new
  tokenize_blocks(text || "")
  @parsed
end