Stylesheet
An AvailProject contains a stylesheet that dictates how an Avail source viewer/editor should render a source region tagged with one or more style classifiers. A stylesheet comprises one or more patterns, each of which encodes (1) whether a region of text should be rendered and (2) how it should be rendered. Patterns are written using a simple domain-specific language (DSL); this DSL is designed to be reminiscent of Cascading Stylesheets (CSS), but, for reasons of simplicity, is not compatible with it. Each pattern compiles down into a rule. A rule is a program, comprising StyleRuleInstructions, whose input is the sequence S of style classifiers attached to some source region R and whose output is a partial rendering context that should be applied to R. The complete collection of rules is organized into a global StyleRuleTree, such that every vertex contains the StyleRuleContexts for those rules that are still live and every edge encodes a possible next style classifier, either as (1) a fixed style classifier mentioned by some active rule in the source vertex or (2) a wildcard that matches any style classifier. The RenderingEngine iteratively feeds S, one style classifier at a time, through the tree, starting at the root. At each vertex, it feeds the current classifier C to each rule therein. Each rule that accepts C generates one or more StyleRuleContexts, each of which is injected into the lazy successor vertex along the edge labeled C; each rule that rejects C is excluded from further consideration; each rule that completes adds itself to the (ordered) solution set. After consuming S entirely, the rules of the solution set are ranked according to specificity, and every rule that ties for highest specificity contributes its rendering effects to the final RenderingContext. Rendering conflicts are resolved by insertion order, with later rules prevailing over earlier ones. For computational efficiency, the final result is memoized (to the sequence S).
Author
Todd L Smith
Parameters
The original style rules to inject into the stylesheet, prior to adding defaults for missing system style classifiers. Should be arranged in declaration order, as this order establishes the override order during reduction of the final rendering context.
Constructors
Construct a Stylesheet from (1) the specified map of source patterns and style attributes and (2) the palette for final color selection.
Construct a new Stylesheet. Supplement the supplied rules with any missing rules required to support the system style classifiers.
Properties
Functions
Given the specified solution set, compute the final rendering solution by overriding the solutions from left to right, i.e., later contexts override earlier context.
Locate the tree that contains the solutions for the specified input text, which is a comma-separated list of style classifiers, such as styleToken produces when classifying regions of source code.
Obtain the correct rendering context for the specified input text, using a cached solution if possible. The input text is a comma-separated list of style classifiers, such as styleToken produces when classifying regions of source code.