LGUI2:Text Types

From Lavish Software Wiki
Jump to navigation Jump to search

Text Types in LavishGUI 2 provide contextual text representation and decoration, based on the content of the text. For example, color codes and syntax highlighting are both supported by this system.

All LavishGUI 2 Text Elements support Text Types. Each LavishGUI 2 Element that contains Text supports Text Types, and can have its own set of options (including colors, brushes and fonts used for the text).


Defining a Text Type

LavishGUI 2 Text Types are defined by a JSON Object enclosed by {}

User-defined Text Types are based on one of four types:

  • plain: A generic string of text, with a set of characters called terminators that specify the end of the text segment
    • character: A specific character of text
    • sequence: A specific sequence of text
  • container: A container for other types of text, specifying sets of character types, sequence types, terminator types that may be contained within


Text Type properties
name The name of the new Text Type
base The base type of the new Text Type. One of plain, character, sequence, or container as described above.
plain
terminators A JSON Array containing a list of single-character JSON strings, each indicating the end of the Text segment
character
character A single-character string specifying the one and only valid character for this Text segment
sequence
sequence A string specifying the one and only valid sequence of characters for this Text segment
container
defaultType The name of the default Text Type, if no more specific type is defined for a character
subOpenType The name of the Text Type that opens a new instance of this container type, if found within. For example, "json_{" would open (start) a new JSON Object
escapeType The name of the Text Type that enables escaping. (Tip: Use the built-in "escape" type.)
terminatorTypes A JSON Object that maps Text Type names to an object containing options for terminating the container with that Text Type, currently specifying "allowedInside" and "escapeable" as True or False
characterTypes A JSON Object that maps single characters (the keys) to Text Types for processing. The specified Text Types must accept the specified characters. For example, it would be invalid to map "{" to "json_[" because the "json_[" type only accepts a "[", but "{" can also be mapped to the container-based "json_object".
sequenceTypes A JSON Object that maps character sequences (the keys) to Text Types (the string values) for processing. The specified Text Types must accept the specified sequences.

Examples

json.json - complete syntax highlighting for JSON
LGUI2:LoadTextElementTypesFile[json.json]
 {
   "json": {
     "base": "container",
     "defaultType":"json_other",
     "characterTypes": {
       "\"": "json_string",
       "{": "json_object",
       "[": "json_array",
       "\r": "crlf",
       "\n": "crlf",
       "}": "json_}",
       "]": "json_]",
       ":": "json_:",
       ",": "json_,",
     }
   },
   "json_{": {
     "base": "character",
     "character": "{"
   },
   "json_}": {
     "base": "character",
     "character": "}"
   },
   "json_[": {
     "base": "character",
     "character": "["
   },
   "json_]": {
     "base": "character",
     "character": "]"
   },
   "json_:": {
     "base": "character",
     "character": ":"
   },
   "json_,": {
     "base": "character",
     "character": ","
   },
   "json_\"": {
     "base": "character",
     "character": "\""
   },
   "json_\\": {
     "base": "character",
     "character": "\\"
   },
   "json_other": {
     "base": "plain",
     "terminators": [ "\r", "\n", "{", "}", "[", "]", ":", ",", "\"" ]
   },
   "json_plain": {
     "base": "plain",
     "terminators": [ "\r", "\n", "\\", "\"" ]
   },
   "json_array": {
     "base": "container",
     "subOpenType": "json_[",
     "defaultType": "json_other",
     "terminatorTypes": {
       "json_]": {  }
     },
     "characterTypes": {
       "\"": "json_string",
       "{": "json_object",
       "[": "json_[",
       "\r": "crlf",
       "\n": "crlf",
       "}": "json_}",
       "]": "json_]",
       ":": "json_:",
       ",": "json_,"
     }
   },
   "json_object": {
     "base": "container",
     "defaultType": "json_other",
     "subOpenType": "json_{",
     "terminatorTypes": {
       "json_}": {  }
     },
     "characterTypes": {
       "\"": "json_string",
       "{": "json_{",
       "[": "json_array",
       "\r": "crlf",
       "\n": "crlf",
       "}": "json_}",
       "]": "json_]",
       ":": "json_:",
       ",": "json_,"
     }
   },
   "json_string": {
     "base": "container",
     "defaultType": "json_plain",
     "escapeType": "escape",
     "terminatorTypes": {
       "json_\"": { },
       "crlf": { "allowedInside": false }
     },
     "characterTypes": {
       "\r": "crlf",
       "\n": "crlf",
       "\"": "json_\"",
       "\\": "escape"
     }
   }
 }

Built-in Text Types

LavishGUI 2 Text Types

Built-in
any - container - crlf - escape - plain
User-defined only
character - sequence

LavishGUI 2 Topics