Skip to content

Instantly share code, notes, and snippets.

@pfgithub
Last active May 16, 2019 00:19
Show Gist options
  • Save pfgithub/feb43360514295d08b48ab60910062f2 to your computer and use it in GitHub Desktop.
Save pfgithub/feb43360514295d08b48ab60910062f2 to your computer and use it in GitHub Desktop.
Convert an ace syntax highlighter generated with iro to a monarch one
let ace = {/*your syntax highlighter here*/}
let tokens = {/*your syntax highlighter tokens and values*/}
console.log(JSON.stringify((() => {
let monarchTokenizer = {}
Object.keys(acerules).forEach(key => {
let value = acerules[key];
monarchTokenizer[key] = [];
value.forEach(m__ => {
m=Object.assign({},m__)
if(m.defaultToken){return;}
let mt = [];
monarchTokenizer[key].push(mt);
m.token = (tokens[m.token] || "aaaaaproblem:"+m.token);
mt.push("####!!" +(new RegExp(m.regex)).toString() + "!!####");
if(m.push){
mt.push({token: m.token, next: "@"+m.push})
return;
}
if(m.next){
mt.push({token: m.token, next: "@"+m.next})
return;
}
mt.push({token: m.token})
});
});
monarchTokenizer.root = [{include: "@start"}];
return monarchTokenizer
})(), null, "\t").replace(/"####!!(.+?)!!####"/g, (_,a) => JSON.parse('"'+a+'"')));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment