Class orion.styler.TextMateStyler
Extends
orion.styler.AbstractStyler.
orion.styler.TextMateStyler
Defined in: </shared/eclipse/e4/orion/I201106031245/plugins/org.eclipse.orion.client.core/web/orion/editor/textMateStyler.js>.
Constructor Attributes | Constructor Name and Description |
---|---|
orion.styler.TextMateStyler(editor, grammar)
A styler that knows how to apply a limited subset of the TextMate grammar format to style a line.
|
Method Attributes | Method Name and Description |
---|---|
addScope(scopes, fromNode, start, end, scope)
|
|
addScopeForCaptures(scopes, fromNode, start, end, match, captures)
|
|
addStyles(scope)
Adds eclipse.Style objects for scope to our _styles cache.
|
|
addStylesForCaptures(captures)
|
|
afterMatch(match)
|
|
cleanup(repairing, origNode, rs, re, eof, addedCharCount, removedCharCount)
Helper for parse() in the repair case
|
|
copy(grammar)
|
|
exec(regex, text, offset)
Execs regex on text, and returns the match object with its index offset by the given amount.
|
|
getEndMatch(node, text, offset)
|
|
getFirstDamaged(start, end)
|
|
getInitialExpected(node, rs)
Gets the node corresponding to the first match we expect to see in the repair.
|
|
getIntersecting(start, end)
|
|
getNextExpected(expected, event)
Helper for repair() to tell us what kind of event we expect next.
|
|
getNextMatch(model, node, pos, matchRulesOnly)
|
|
Called once when file is first loaded to build the parse tree.
|
|
isDamaged(n, start, end)
|
|
parse(origNode, repairing, rs, addedCharCount, removedCharCount)
Builds tree from some of the buffer content
TODO cleanup params
|
|
prune(node, expected)
Helper for parse() when repairing.
|
|
push(stack, rules)
Pushes rules onto stack so that rules[startFrom] is on top
|
|
removeUnrepairedChildren(node, repairing)
Helper for parse() in the repair case
Removes any children of node that are unrepaired (implies they were deleted)
|
|
styleDirect(scopes, claimedRegions, node, lineStart, lineEnd)
|
|
styleFromMatchRules(scopes, node, start, end)
Styles the region start.
|
|
styleInherited(scopes, node, start, end)
|
|
toStyleRanges(scopeRanges)
Applies the grammar to obtain the eclipse.StyleRange[] for the given line.
|
- Methods borrowed from class orion.styler.AbstractStyler:
- _onDestroy, _onLineStyle, _onModelChanged, _onSelection, destroy, initialize
Class Detail
orion.styler.TextMateStyler(editor, grammar)
A styler that knows how to apply a limited subset of the TextMate grammar format to style a line.
Styling from a grammar:
Each scope name given in the grammar is converted to an array of CSS class names. For example a region of text with scope keyword.control.php will be assigned the CSS classeskeyword, keyword-control, keyword-control-phpA CSS file can give rules matching any of these class names to provide generic or more specific styling. For example,
.keyword { font-color: blue; }colors all keywords blue, while
.keyword-control-php { font-weight: bold; }bolds only PHP control keywords. This is useful when using grammars that adhere to TextMate's scope name conventions, as a single CSS rule can provide consistent styling to similar constructs across different languages.
Supported top-level grammar features:
- fileTypes, patterns, repository (but see below) are supported.
- scopeName, firstLineMatch, foldingStartMarker, foldingStopMarker are not supported.
TODO update this section
Supported grammar rule features:
- match patterns are supported.
- name scope is supported.
- captures is not supported. Any scopes given inside a captures object are not applied.
- begin/end patterns are not supported and are ignored, along with their subrules. Consequently, matched constructs may not span multiple lines.
- contentName, beginCaptures, endCaptures, applyEndPatternLast are not supported.
- include is supported, but only when it references a rule in the current grammar's repository. Including $self, $base, or rule.from.another.grammar is not supported.
- The (?x) option ("extended" regex format) is supported, but only when it appears at the beginning of a regex pattern.
- Matching is done using native JavaScript RegExps. As a result, many Oniguruma features are not supported.
Unsupported features include:
- Named captures
- Setting flags inside groups (eg. (?i:a)b)
- Lookbehind and negative lookbehind
- Subexpression call
- etc.
- Parameters:
- {orion.textview.TextView} editor
- The editor.
- {JSONObject} grammar
- The TextMate grammar as a JSON object. You can use a plist-to-JSON conversion tool to produce this object. Note that some features of TextMate grammars are not supported.
Method Detail
addScope(scopes, fromNode, start, end, scope)
- Parameters:
- scopes
- fromNode
- start
- end
- scope
addScopeForCaptures(scopes, fromNode, start, end, match, captures)
- Parameters:
- scopes
- fromNode
- start
- end
- match
- captures
addStyles(scope)
Adds eclipse.Style objects for scope to our _styles cache.
- Parameters:
- {String} scope
- A scope name, like "constant.character.php".
addStylesForCaptures(captures)
- Parameters:
- {Object} captures
{Number}
afterMatch(match)
- Parameters:
- {RegExp.match} match
- Returns:
- {Number} The position immediately following the match.
cleanup(repairing, origNode, rs, re, eof, addedCharCount, removedCharCount)
Helper for parse() in the repair case
- Parameters:
- repairing
- origNode
- rs
- re
- eof
- addedCharCount
- removedCharCount
copy(grammar)
- Parameters:
- grammar
exec(regex, text, offset)
Execs regex on text, and returns the match object with its index offset by the given amount.
- Parameters:
- {RegExp} regex
- {String} text
- {Number} offset
{RegExp.match}
getEndMatch(node, text, offset)
- Parameters:
- {Node} node
- {String} text
- {Number} offset
- Returns:
- {RegExp.match} If node is a BeginEndNode and its rule's "end" pattern matches the text.
{BeginEndNode|ContainerNode}
getFirstDamaged(start, end)
- Parameters:
- start
- end
- Returns:
- {BeginEndNode|ContainerNode} The result of taking the first (smallest "start" value) node overlapping [start,end] and drilling down to get its deepest damaged descendant (if any).
{Node}
getInitialExpected(node, rs)
Gets the node corresponding to the first match we expect to see in the repair.
- Parameters:
- {BeginEndNode|ContainerNode} node
- The node returned via getFirstDamaged(rs,rs) -- may be the root.
- {Number} rs
- See _onModelChanged() Note that because rs is a line end (or 0, a line start), it will intersect a beginMatch or endMatch either at their 0th character, or not at all. (begin/endMatches can't cross lines). This is the only time we rely on the start/end values from the pre-change tree. After this we only look at node ordering, never use the old indices.
- Returns:
- {Node}
{Node[]}
getIntersecting(start, end)
- Parameters:
- start
- end
- Returns:
- {Node[]} In depth-first order
{Node}
getNextExpected(expected, event)
Helper for repair() to tell us what kind of event we expect next.
- Parameters:
- {Node} expected
- Last value returned by this method.
- {String} event
- "begin" if the last value of expected was matched as "begin", or "end" if it was matched as an end.
- Returns:
- {Node} The next expected node to match, or null.
{Object}
getNextMatch(model, node, pos, matchRulesOnly)
- Parameters:
- model
- {orion.textview.TextModel}
- node
- {Node}
- pos
- {Number}
- matchRulesOnly Optional
- {Boolean} Optional, if true only "match" subrules will be considered.
- Returns:
- {Object} A match info object with properties: {Boolean} isEnd {Boolean} isSub {RegExp.match} match {(Container|Match|BeginEnd)Rule} rule
initialParse()
Called once when file is first loaded to build the parse tree. Tree is updated incrementally thereafter as buffer is modified
isDamaged(n, start, end)
- Parameters:
- {BeginEndNode} n
- start
- end
- Returns:
- true If n overlaps the interval [start,end]
parse(origNode, repairing, rs, addedCharCount, removedCharCount)
Builds tree from some of the buffer content
TODO cleanup params
- Parameters:
- {BeginEndNode|ContainerNode} origNode
- The deepest node that overlaps [rs,rs], or the root.
- {Boolean} repairing
- {Number} rs
- See _onModelChanged()
- {Number} addedCharCount Optional
- Only used for repairing === true
- {Number} removedCharCount Optional
- Only used for repairing === true
preprocess()
prune(node, expected)
Helper for parse() when repairing. Prunes out the unmatched nodes from the tree so we can continue parsing.
- Parameters:
- {BeginEndNode|ContainerNode} node
- {Node} expected
push(stack, rules)
Pushes rules onto stack so that rules[startFrom] is on top
- Parameters:
- {Array} stack
- {Array} rules
removeUnrepairedChildren(node, repairing)
Helper for parse() in the repair case
Removes any children of node that are unrepaired (implies they were deleted)
- Parameters:
- node
- repairing
styleDirect(scopes, claimedRegions, node, lineStart, lineEnd)
- Parameters:
- {Array} scopes
- {Array} claimedRegions
- {BeginEndNode} node
- lineStart
- lineEnd
styleFromMatchRules(scopes, node, start, end)
Styles the region start..end by applying any "match"-subrules of node
- Parameters:
- {Array} scopes
- {BeginEndNode|ContainerNode} node
- start
- end
styleInherited(scopes, node, start, end)
- Parameters:
- {Array} scopes
- {BeginEndNode} node
- start
- end
toStyleRanges(scopeRanges)
Applies the grammar to obtain the eclipse.StyleRange[] for the given line.
- Parameters:
- {ScopeRange[]} scopeRanges
- Returns:
- eclipse.StyleRange[]