Browse Source

Support simple fetching of remote resources

dev/git-series/gccdum
Matt Godbolt 6 years ago
parent
commit
843b61112c
  1. 3
      bower.json
  2. 34
      static/compiler.js
  3. 3
      static/main.js

3
bower.json

@ -26,6 +26,7 @@
"eventEmitter": "^5.1.0",
"lz-string": "^1.4.4",
"clipboard": "^1.5.12",
"raven-js": "^3.7.0"
"raven-js": "^3.7.0",
"es6-promise": "^4.0.5"
}
}

34
static/compiler.js

@ -33,6 +33,7 @@ define(function (require) {
var Toggles = require('toggles');
var FontScale = require('fontscale');
var output = require('output');
var Promise = require('es6-promise').Promise;
require('asm-mode');
require('selectize');
@ -300,10 +301,39 @@ define(function (require) {
this.eventHub.emit('compileResult', this.id, this.compiler, result);
};
Compiler.prototype.expand = function (source) {
var includeFind = /^\s*#include\s*["<](https?:\/\/[^>"]+)[>"]$/;
var lines = source.split("\n");
var promises = [];
_.each(lines, function (line, lineNumZeroBased) {
var match = line.match(includeFind);
if (match) {
console.log(line, lineNumZeroBased);
promises.push(new Promise(function (resolve, reject) {
var req = $.get(match[1], function (data) {
data = '# 1 "' + match[1] + '"\n' + data + '\n\n# ' +
(lineNumZeroBased + 1) + ' "<stdin>"\n';
lines[lineNumZeroBased] = data;
resolve();
});
req.fail(function () {
resolve();
});
}));
}
});
return Promise.all(promises).then(function () {
return lines.join("\n");
});
};
Compiler.prototype.onEditorChange = function (editor, source) {
if (editor === this.sourceEditorId) {
this.source = source;
this.compile();
this.expand(source).then(_.bind(function (expanded) {
this.source = expanded;
this.compile();
}, this));
}
};

3
static/main.js

@ -35,7 +35,8 @@ require.config({
events: 'ext/eventEmitter/EventEmitter',
lzstring: 'ext/lz-string/libs/lz-string',
clipboard: 'ext/clipboard/dist/clipboard',
'raven-js': 'ext/raven-js/dist/raven'
'raven-js': 'ext/raven-js/dist/raven',
'es6-promise': 'ext/es6-promise/es6-promise'
},
packages: [{
name: "codemirror",

Loading…
Cancel
Save