Configuring the Lexer (parsley.token.descriptions)

The Lexer is configured primarily by providing it a LexicalDesc. This is a structure built up of many substructures that each configure a specific part of the overall functionality available. In general, many parts of this hierarchy have "sensible defaults" in the form of their plain value within their companion objects; these document what choices were made in each individual case. There may also be some values crafted to adhere to some specific language specification; for instance, EscapeDesc.haskell describes escape characters that adhere to the Haskell Report.

This page does not aim to document everything that is configurable within LexicalDesc, but it will outline the general design and how things slot together.

Diagram of Dependencies

The hierarchy of types involved with lexical configuration can be daunting. The following diagram illustrates both the "has-a" and "is-a" relationships between the types. For instance, TextDesc contains an EscapeDesc, and NumericEscape may be implemented by either NumericEscape.Illegal or NumericEscape.Supported.

classDiagram
direction LR

LexicalDesc *-- NumericDesc
LexicalDesc *-- NameDesc
LexicalDesc *-- SpaceDesc
LexicalDesc *-- SymbolDesc
LexicalDesc *-- TextDesc

TextDesc *-- EscapeDesc
EscapeDesc *-- NumericEscape
`NumericEscape.Illegal` --|> NumericEscape
`NumericEscape.Supported` --|> NumericEscape
`NumericEscape.Supported` *-- NumberOfDigits
`NumberOfDigits.AtMost` --|> NumberOfDigits
`NumberOfDigits.Exactly` --|> NumberOfDigits
`NumberOfDigits.Unbounded` --|> NumberOfDigits

ExponentDesc --* NumericDesc
`ExponentDesc.Supported` --|> ExponentDesc
`ExponentDesc.NoExponents` --|> ExponentDesc
NumericDesc *-- BreakCharDesc
`ExponentDesc.Supported` *-- PlusSignPresence

BreakCharDesc <|-- `BreakCharDesc.Supported`
BreakCharDesc <|-- `BreakCharDesc.NoBreakChar`

PlusSignPresence <|-- `PlusSignPresence.Illegal`
PlusSignPresence <|-- `PlusSignPresence.Optional`
PlusSignPresence <|-- `PlusSignPrecense.Required`
NumericDesc *-- PlusSignPresence

The types in the diagram that have alternative implements are as follows: