The class Words implements an efficient way to consult a Gobstones words definition given by an instance of WordsDef with efficiency and readability. It is an auxiliary class for Gobstones lexer. It solves the problem of abstracting away the concrete words recognized by the Gobstones lexer to build tokens while simplifying the access to the definition of those words, given by a WordsDef.

To create one Words the Lexer provides it with an instance of WordsDef with a particular domain, and later use the operations of the class to ask for specific symbols and words defining tokens. The specific operations include:

  • operations to access sigils
  • operations to access specific pragmas
  • operations to access values of language identification elements
  • operations to ask if a words has some property
  • operations to access specific elements
  • operations to ask a character if it is from a specific group

Type Parameters

Hierarchy (view full)

Implements

API: Language identification elements

API: Main

API: Operators operations

API: Pragmas

API: Predicates for chars

API: Predicates for words

API: Sigils

API: Specific elements

Implementation: Auxiliaries

Implementation: State

API: Language identification elements

  • get valueLanguageDomain(): string
  • The concrete string for the Language Domain according to the words definition given at creation.

    Returns string

  • get valueLanguageLocale(): string
  • The concrete string for the Language Locale option according to the words definition given at creation.

    Returns string

  • get valueLanguageVariant(): string
  • The concrete string for the Language Variant name according to the words definition given at creation.

    Returns string

  • get valueLanguageVersion(): string
  • The concrete string for the Language Version name according to the words definition given at creation.

    Returns string

API: Main

API: Operators operations

  • The abstract word used for the op identifier operator.

    PRECONDITION:

    • op is one of the declared identifier operators

    Parameters

    • op: string

    Returns string

  • The symbol of the operator op at the given level.

    PRECONDITION:

    • the operator op is one of the operators at the given level

    Parameters

    • op: string
    • level: number

    Returns string

  • The fixity of the given fixity level in the language words definition.

    Parameters

    • level: number

    Returns Fixity

  • The number of the last fixity level in the language words definition.

    Returns number

  • The fixity of the given fixity level in the language words definition.

    Parameters

    • token: Token
    • level: number

    Returns boolean

API: Pragmas

  • get languagePragmaALLOWRECURSION(): string
  • The concrete string for the ALLOWRECURSION language pragma according to the words definition given at creation.

    Returns string

  • get languagePragmaDESTRUCTURINGFOREACH(): string
  • The concrete string for the DESTRUCTURINGFOREACH language pragma according to the words definition given at creation.

    Returns string

  • get pragmaATTRIBUTE(): string
  • The concrete string for the ATTRIBUTE pragma according to the words definition given at creation.

    Returns string

  • get pragmaBEGINREGION(): string
  • The concrete string for the BEGINREGION pragma according to the words definition given at creation.

    Returns string

  • get pragmaENDREGION(): string
  • The concrete string for the ENDREGION pragma according to the words definition given at creation.

    Returns string

  • get pragmaEXTRASYMBOLS(): string
  • The concrete string for the EXTRASYMBOLS pragma according to the words definition given at creation.

    Returns string

  • get pragmaLANGUAGEDOMAIN(): string
  • The concrete string for the LANGUAGEDOMAIN pragma according to the words definition given at creation.

    Returns string

  • get pragmaLANGUAGELOCALE(): string
  • The concrete string for the LANGUAGELOCALE pragma according to the words definition given at creation.

    Returns string

  • get pragmaLANGUAGEMOD(): string
  • The concrete string for the LANGUAGEMOD pragma according to the words definition given at creation.

    Returns string

  • get pragmaLANGUAGEVARIANT(): string
  • The concrete string for the LANGUAGEVARIANT pragma according to the words definition given at creation.

    Returns string

  • get pragmaLANGUAGEVERSION(): string
  • The concrete string for the LANGUAGEVERSION pragma according to the words definition given at creation.

    Returns string

API: Predicates for chars

  • Indicates if the given character is a digit char according to the words definition given at creation,

    Parameters

    • ch: string

    Returns boolean

  • Indicates if the given character is a line separator char according to the words definition given at creation,

    Parameters

    • ch: string

    Returns boolean

  • Indicates if the given character is an lowercase sigil char according to the words definition given at creation,

    Parameters

    • ch: string

    Returns boolean

  • Indicates if the given character is a punctuation char according to the words definition given at creation,

    Parameters

    • ch: string

    Returns boolean

  • Indicates if the given character is a regular char according to the words definition given at creation,

    Parameters

    • ch: string

    Returns boolean

  • Indicates if the given character is a string delimiter char according to the words definition given at creation,

    Parameters

    • ch: string

    Returns boolean

  • Indicates if the given character is a string escape char according to the words definition given at creation,

    Parameters

    • ch: string

    Returns boolean

  • Indicates if the given character is a string escape sigil char according to the words definition given at creation,

    Parameters

    • ch: string

    Returns boolean

  • Indicates if the given character is an uppercase sigil char according to the words definition given at creation,

    Parameters

    • ch: string

    Returns boolean

  • Indicates if the given character is a whitespace char according to the words definition given at creation,

    Parameters

    • ch: string

    Returns boolean

API: Predicates for words

  • Indicate if the given abstract word is a keyword according to the words definition given at creation.

    Parameters

    • word: symbol

    Returns boolean

  • Indicate if the given abstract word is a language primitive according to the words definition given at creation.

    Parameters

    • word: symbol

    Returns boolean

  • Indicate if the given abstract word is a symbolic keyword according to the words definition given at creation.

    Parameters

    • word: symbol

    Returns boolean

  • Indicate if the given source has as word as its first characters. The word word is supposed to be a concrete one.

    Parameters

    • word: string
    • source: SourceReader

    Returns boolean

  • Indicate if the given concrete word is an identifier operator of the language definition.

    Parameters

    • word: string

    Returns boolean

  • Indicate if the given concrete word is a keyword according to the words definition given at creation.

    Parameters

    • word: string

    Returns boolean

  • Indicate if the given concrete word is a language primitive according to the words definition given at creation.

    Parameters

    • word: string

    Returns boolean

  • Indicate if the given concrete word is a symbolic keyword according to the words definition given at creation.

    Parameters

    • word: string

    Returns boolean

  • Indicates if the given concrete word is a valid number according to the rules of the language.

    Parameters

    • word: string

    Returns boolean

  • Indicate if the given source has as some of the words as its first characters. The words in words are supposed to be a concrete ones.

    Parameters

    • words: string[]
    • source: SourceReader

    Returns boolean

API: Sigils

  • get sigilPragmaCloser(): string
  • The pragma closer sigil according to the words definition given at creation.

    Returns string

  • get sigilPragmaOpener(): string
  • The pragma opener sigil according to the words definition given at creation.

    Returns string

  • get sigilPragmaSeparator(): string
  • The pragma separator sigil according to the words definition given at creation.

    Returns string

  • get sigilsLineCommentOpener(): string[]
  • The line comment opener sigils according to the words definition given at creation.

    Returns string[]

  • get sigilsParCommentCloser(): string[]
  • The paragraph comment closer sigils according to the words definition given at creation.

    Returns string[]

  • get sigilsParCommentOpener(): string[]
  • The paragraph comment opener sigils according to the words definition given at creation.

    Returns string[]

API: Specific elements

  • Return the keyword for the given word according to the words definition given at creation, if the word is a keyword.

    Parameters

    • word: string

    Returns symbol

  • Return the primitive for the given word according to the words definition given at creation, if the word is a language primitive.

    Parameters

    • word: string

    Returns symbol

  • Return the symbolic keyword for the given word according to the words definition given at creation, if the word is a symbolic keyword.

    Parameters

    • word: string

    Returns symbol

  • Return the concrete word in the language words definition for the given abstract keyword.

    Parameters

    • word: symbol

    Returns string

  • Return the concrete word in the language words definition for the given abstract primitive.

    Parameters

    • word: symbol

    Returns string

  • Return the concrete word in the language words definition for the given abstract symbolic keyword.

    Parameters

    • word: symbol

    Returns string

  • Return the concrete word for the given word according to the words definition given at creation, or keep it as it is, if word is not a symbolic keyword, a keyword, or a primitive.

    Parameters

    • tag: symbol

    Returns string

  • Return the index of the string in words that the given source has as its first characters, if there is some, or undefined if it has is none of them.

    Parameters

    • words: string[]
    • source: SourceReader

    Returns number

  • Return the line separator chars according to the words definition given at creation.

    Returns string

  • Determines the pair opener-closer that is initiated in the given source, provided that one of the openers ocurrs at its beginning.

    PRECONDITION:

    • source starts with one of the strings at openers.

    Parameters

    • source: SourceReader
    • openers: string[]
    • closers: string[]

    Returns string[]

    Throws

    GErrors.PreconditionErrorIn when the source does not start with some of the given openers

  • Return the punctuation symbolic keywords according to the words definition given at creation.

    Returns string[]

Implementation: Auxiliaries

  • Private

    Indicates if all characters of the given string satisfy the condition. It is similar to Array.prototype.every, but for strings.

    Parameters

    • str: string
    • cond: ((str) => boolean)
        • (str): boolean
        • Parameters

          • str: any

          Returns boolean

    Returns boolean

  • Private

    Prepares the strings to detect symbol chars in the source. It is meant to be used by the constructor for initial setup.

    PRECONDITION: the field this._langDef is already set.

    Returns void

Implementation: State

_langDef: WordsDef<DSPrims>

The definition of words for the Gobstones language to use for recognition of characters, symbols, and identifiers.

_symbolChars: SymbolChars

A summary of the symbol chars given in the words definition. It's purpose is efficiency and readability, because it contains redundant information.

INVARIANTS:

  • the fields are always the concatenation of the corresponding basic and extra symbol chars in the words definition.
_wordsTables: GWordsTables

The tables with the associations between abstract words and concrete ones, as given by the words definition. It's purpose is efficiency and readability, because it contains redundant information.

INVARIANT: the tables associates the abstract words with the concrete words as given in the words definition.