"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/first-mate/README.md" (11 Apr 2017, 4006 Bytes) of package /windows/misc/atom-windows.zip:

As a special service "Fossies" has tried to format the requested source page into HTML format (assuming markdown format). Alternatively you can here view or download the uninterpreted source code file. A member file download can also be achieved by clicking within a package contents listing on the according byte size field.

First Mate Build Status

TextMate helpers


npm install first-mate



{ScopeSelector} = require 'first-mate'
selector = new ScopeSelector('a | b')
selector.matches(['c']) # false
selector.matches(['a']) # true


{GrammarRegistry} = require 'first-mate'
registry = new GrammarRegistry()
grammar = registry.loadGrammarSync('./spec/fixtures/javascript.json')
{line, tags} = grammar.tokenizeLine('var offset = 3;')
# convert compact tags representation into convenient, space-inefficient tokens
tokens = registry.decodeTokens(line, tags)
for {value, scopes} in tokens
  console.log("Token text: '#{value}' with scopes: #{scopes}")

loadGrammar(grammarPath, callback)

Asynchronously load a grammar and add it to the registry.

grammarPath - A string path to the grammar file.

callback - A function to call after the grammar is read and added to the registry. The callback receives (error, grammar) arguments.


Synchronously load a grammar and add it to the registry.

grammarPath - A string path to the grammar file.

Returns a Grammar instance.


Translate an integer representing an open scope tag from a tags array to a scope name.

id - A negative, odd integer.

Returns a scope String.

decodeTokens(line, tags)

Convert a line and a corresponding tags array returned from Grammar::tokenizeLine into an array of token objects.

line - A String representing a line of text.

tags - An Array of integers returned from Grammar::tokenizeLine.

Returns an Array of token objects, each with a value field containing a string of the token's text and a scopes field pointing to an array of every scope name containing the token.


tokenizeLine(line, [ruleStack], [firstLine])

Generate the tokenize for the given line of text.

line - The string text of the line.

ruleStack - An array of Rule objects that was returned from a previous call to this method.

firstLine - true to indicate that the very first line is being tokenized.

Returns an object with a tags key pointing to an array of integers encoding the scope structure of the line, a line key returning the line provided for convenience, and a ruleStack key pointing to an array of rules to pass to this method on future calls for lines proceeding the line that was just tokenized.

The tags array encodes the structure of the line as integers for efficient storage. This can be converted to a more convenient representation if storage is not an issue by passing the line string and tags array to GrammarRegistry::decodeTokens.

Otherwise, the integers can be interpreted as follows:


text - The string text possibly containing newlines.

Returns an object containing a lines key, pointing to an array of tokenized lines and a tags key, pointing to an array of tags arrays described above.