Last active
December 19, 2015 13:39
-
-
Save jlewin/5963447 to your computer and use it in GitHub Desktop.
A node script to collect and process OpenSCAD keywords for improved Ace editor highlighting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var https = require('https'); | |
| var result = [], | |
| output = [], | |
| padding = ' ', | |
| trailingSemicolon = /;$/, | |
| quotes = /"/g, | |
| actionUrl = 'https://raw.github.com/openscad/openscad/master/src/highlighter.cc' | |
| // Fire the http[s] request | |
| https.get(actionUrl, function (response) { | |
| response.setEncoding('utf8'); | |
| response.on('data', function (chunk) { | |
| // Fill results with chunked content | |
| result.push(chunk); | |
| }).on('end', function (hadError) { | |
| // Line-by-line processing | |
| var lines = result.join('').split('\n'), | |
| line, | |
| segments, | |
| tokenType; | |
| // loop over each line | |
| for (var i = 0; i < lines.length; i++) { | |
| line = lines[i]; | |
| if (line.indexOf('tokentypes') != -1) { | |
| segments = line.trim() | |
| .replace(quotes, '') | |
| .replace(trailingSemicolon, '') | |
| .split('<<') | |
| .map(function (s) { return s.trim() }); | |
| tokenType = segments[0]; | |
| // Skip lines that don't start with the expected identifier | |
| if (tokenType.indexOf('tokentypes[') != 0) continue; | |
| // Format and push results to output | |
| output.push('\r\n\r\n' + padding + '// ' + tokenType.substr(11, tokenType.length - 12) + ' tokens \r\n' + | |
| padding + '"' + segments.slice(1).join('|') + '"'); | |
| } | |
| } | |
| // Finally dump the results to the console | |
| console.log(output.join(' + ')); | |
| }); | |
| }).on('error', function (e) { | |
| console.log("Got error: " + e.message); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment