Skip to content

Instantly share code, notes, and snippets.

@nikitaeverywhere
Last active December 21, 2015 13:09
Show Gist options
  • Save nikitaeverywhere/6310513 to your computer and use it in GitHub Desktop.
Save nikitaeverywhere/6310513 to your computer and use it in GitHub Desktop.
SuperRegular expression for breaking Caché code to lexical parts. It can be improved! Supports ##class, $Method/$Var, $$MyMethod, $$$Macro, ^Global, ..ClassMethod, %SystemClass, "strings", 016175, {[()]}.
/**
* Function breaks code for parts with span tags and according styles, but skips &*; html-symbol combinations and tag <br>
*
* @param string
* String to parse.
* @returns {string}
* Parsed string.
*/
this.highlightHTML = function(string) {
return string.replace(/(\/\*.*?(?=\*\/)\*\/)|([0-9]+\.?[0-9]+?)|(((<|&|&#)|(\^%?)|\/|\${0,3}|#{0,2}|%|\.|(\.\.))?[A-Za-z0-9]+[;>]?)|[{}\]\[\(\)!_'\\#\?\+\-\*\/=<>,]|("[^"]*")/g,
function(part) {
return "<span class=\"syntax" + somePart_parsing_function(part) + "\">" + part + "</span>";
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment