Syntax highlight in a specific region

Is it possible to apply syntax highlight only between specific regions of code, say

`Var x
Sub routineName ( temp as Object )
x= temp
End Sub

x = temp`

In the above ‘temp’ should be color-coded/higlighted only in the sub and not on the outside.
The last line ‘temp’ should not be color coded.

A simple code example would be greatly appreciated.

Do you simply want to highlight between SubEnd Sub and no highlighting outside?

If you have a mode that does the highlighting you want inside, the multiplex addon will let you easily create a wrapper mode that delegates to the inner mode only between your delimiters (as long as the delimiters are fixed strings or regexps).

For more examples of using multiplex, see its test https://github.com/codemirror/CodeMirror/blob/master/addon/mode/multiplex_test.js
and quite a few of the builtin modes e.g.
https://codemirror.net/mode/htmlembedded/
https://github.com/codemirror/CodeMirror/blob/master/mode/htmlembedded/htmlembedded.js#L16-L22