// Generated by CoffeeScript 1.10.0 (function() { window.Editor = Backbone.D3View.extend({ namespace: null, tagName: 'div', initialize: function(conf) { var editor_div, wrapper; this.d3el.classed('Editor', true); editor_div = this.d3el.append('div').attr({ "class": 'editor_div' }).style({ position: 'relative' }); wrapper = editor_div.append('div').style({ position: 'absolute', height: '100%', width: '100%' }); this.status_bar = this.d3el.append('div').attr({ "class": 'status_bar' }); this.parser = PEG.buildParser(conf.grammar); this.editor = CodeMirror(wrapper.node(), { lineNumbers: true, lineWrapping: true, keyMap: 'sublime', value: '# indentation is used to build the tree\nFigura\n Triangolo\n Equilatero\n Isoscele\n Scaleno\n Quadrilatero\n Trapezio\n Parallelogramma\n Rettangolo\n Quadrato\n Rombo\n # repeat an identifier to\n # define more than a single\n # parent node\n Quadrato\n\n# it is also possible to define another\n# connected component...\nAnimale\n Gatto\n Cane\n\n# ...or to merge another tree with an\n# existing one\nGatto\n Siamese\n Persiano', extraKeys: { Tab: function(cm) { if (cm.somethingSelected()) { return cm.indentSelection('add'); } else { return cm.replaceSelection(Array(cm.getOption('indentUnit') + 1).join(' '), 'end', '+input'); } } } }); this.editor.on('change', (function(_this) { return function() { return _this.compile(); }; })(this)); return this.compile(); }, render: function() { return this.editor.refresh(); }, compile: function() { var e, error, graph; this.status_bar.text('All ok.'); this.status_bar.classed('error', false); try { graph = this.parser.parse(this.editor.getValue()); this.highlight_code(graph); return this.model.update(graph); } catch (error) { e = error; this.status_bar.text("Line " + e.location.start.line + ": " + e.message); return this.status_bar.classed('error', true); } }, highlight_code: function(graph) { this.editor.getAllMarks().forEach(function(mark) { return mark.clear(); }); graph.nodes.forEach((function(_this) { return function(d) { if (!d.dummy) { return _this.editor.markText({ line: d.code_location.start.line - 1, ch: d.code_location.start.column - 1 }, { line: d.code_location.end.line - 1, ch: d.code_location.end.column - 1 }, { className: 'node_def' }); } }; })(this)); graph.node_refs.forEach((function(_this) { return function(d) { return _this.editor.markText({ line: d.code_location.start.line - 1, ch: d.code_location.start.column - 1 }, { line: d.code_location.end.line - 1, ch: d.code_location.end.column - 1 }, { className: 'node_ref' }); }; })(this)); return graph.comments.forEach((function(_this) { return function(d) { return _this.editor.markText({ line: d.code_location.start.line - 1, ch: d.code_location.start.column - 1 }, { line: d.code_location.end.line - 1, ch: d.code_location.end.column - 1 }, { className: 'comment' }); }; })(this)); } }); }).call(this);