package textmate-language

  1. Overview
  2. Docs

Module TmLanguageSource

Sourcetype t

The collection of TextMate grammars.

Sourcetype grammar

A TextMate grammar.

Sourceexception Error of string

The error message is purely informational and is not to be matched on.

Sourcetype plist = [
  1. | `Bool of bool
  2. | `Data of string
  3. | `Date of float * float option
  4. | `Float of float
  5. | `Int of int
  6. | `String of string
  7. | `Array of plist list
  8. | `Dict of (string * plist) list
]

A plist document. This is the same type as t defined in the plist-xml package (as of version 0.3.0), but is reproduced here as not to depend on plist-xml.

Sourcetype ezjsonm = [
  1. | `Null
  2. | `Bool of bool
  3. | `Float of float
  4. | `String of string
  5. | `A of ezjsonm list
  6. | `O of (string * ezjsonm) list
]

A JSON document. This is the same type as value defined in the ezjsonm package (as of version 1.2.0), but is reproduced here as not to depend on ezjsonm.

Sourcetype yojson = [
  1. | `Null
  2. | `Bool of bool
  3. | `Int of int
  4. | `Float of float
  5. | `String of string
  6. | `Assoc of (string * yojson) list
  7. | `List of yojson list
]

A JSON document. This is the same type as Basic.t defined in the yojson package (as of version 1.7.0), but is reproduced here as not to depend on yojson.

Sourceval create : unit -> t

Creates an empty collection of grammars.

Sourceval add_grammar : t -> grammar -> unit

Adds a grammar to the collection.

Sourceval find_by_name : t -> string -> grammar option

Finds a grammar by its name attribute. Case-insensitive.

Sourceval find_by_scope_name : t -> string -> grammar option

Finds a grammar by its scopeName attribute. Case-sensitive.

Sourceval find_by_filetype : t -> string -> grammar option

Finds a grammar by matching one of the strings in its fileTypes attribute. Case-sensitive.

Sourceval of_plist_exn : plist -> grammar

Reads a TextMate grammar from a PLIST file. Raises Error if the plist does not represent a valid TextMate grammar.

Sourceval of_ezjsonm_exn : ezjsonm -> grammar

Reads a TextMate grammar from a JSON file. Raises Error if the plist does not represent a valid TextMate grammar.

Sourceval of_yojson_exn : yojson -> grammar

Reads a TextMate grammar from a JSON file. Raises Error if the plist does not represent a valid TextMate grammar.

Sourcetype stack

The state of the tokenizer.

Sourceval empty : stack

The initial state of the tokenizer.

Sourcetype token

A token of code.

Sourceval ending : token -> int

One past the index of the last character of the token.

If tok is the first token of the line, tok spans the substring within interval [0, ending tok). If tok succeeds a token prev, tok spans the substring within interval [ending prev, ending tok).

Sourceval scopes : token -> string list

The token's stack of TextMate grammar scopes.

Sourceval tokenize_exn : t -> grammar -> stack -> string -> token list * stack

Usage: let tokens, stack = tokenize_exn t grammar stack line

Tokenizes a line of code. Returns the list of tokens tokens and the updated tokenization state stack.

Precondition:

  • line must be a single line, including the newline character at the end.

Postconditions:

  • tokens is nonempty.
  • The ending positions of tokens are strictly increasing.
  • The ending of the last token in tokens is always String.length line.

Raises Error if it tries to match a malformed end or while regex.

Raises Error if it tries to access a local repository that doesn't exist in the file. Currently, it silently ignores includes of other grammars that don't exist in t.