// Generated by CoffeeScript 1.10.0 (function() { window.Editor = Backbone.D3View.extend({ namespace: null, tagName: 'div', events: { input: 'compile' }, 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); CodeMirror.defineSimpleMode('hl', { start: [ { regex: new RegExp('<[a-zA-Z0-9][_a-zA-Z0-9]*<'), token: 'span_open' }, { regex: new RegExp('<<'), token: 'span_open' }, { regex: new RegExp('>[a-zA-Z0-9][_a-zA-Z0-9]*>'), token: 'span_close' }, { regex: new RegExp('>>'), token: 'span_close' }, { regex: new RegExp('^\\+\\+\\+$'), token: 'triple_section_open', next: 'triple_section' } ], triple_section: [ { regex: new RegExp('^\\+\\+\\+$'), token: 'triple_section_close', next: 'start' }, { regex: new RegExp('(^[^ \t]*)([ \t]+)([^ \t]*)([ \t]+)(".*"$)'), token: ['subject', '', 'predicate', '', 'literal'] }, { regex: new RegExp('(^[^ \t]*)([ \t]+)([^ \t]*)([ \t]+)([^" \t]*$)'), token: ['subject', '', 'predicate', '', 'object'] } ] }); this.editor = CodeMirror(wrapper.node(), { lineWrapping: true, value: 'This is <B>, a language that can be used to select portions of text for <A>.\n\n<1> are allowed>2>, as well as <N>. Moreover, <B> <33> for overlapping spans>4>.\n\nActual <A> are based on RDF triples, and are included in one or more sections like the following one:\n+++\nA foaf:page https://en.wikipedia.org/wiki/Annotation\n+++' }); this.editor.on('change', (function(_this) { return function() { return _this.compile(); }; })(this)); return this.compile(); }, render: function() { return this.editor.refresh(); }, compile: function() { var data, e, error; this.status_bar.text('All ok.'); this.status_bar.classed('error', false); this.editor.getAllMarks().forEach(function(mark) { return mark.clear(); }); this.triple_section_highlight(); try { data = this.parser.parse(this.editor.getValue()); this.spans_highlight(data.spans); return this.model.set('annotations', data.spans); } catch (error) { e = error; this.status_bar.text("Line " + e.location.start.line + ": " + e.message); return this.status_bar.classed('error', true); } }, spans_highlight: function(spans) { return spans.forEach((function(_this) { return function(s) { return _this.editor.markText({ line: s.start_code_location.start.line - 1, ch: s.start_code_location.start.column - 1 }, { line: s.end_code_location.end.line - 1, ch: s.end_code_location.end.column - 1 }, { className: 'span' }); }; })(this)); }, triple_section_highlight: function() { var in_section, line_number; in_section = false; line_number = 0; return this.editor.eachLine((function(_this) { return function(l) { _this.editor.removeLineClass(line_number, 'background'); _this.editor.removeLineClass(line_number, 'text'); if (in_section) { _this.editor.addLineClass(line_number, 'background', 'triple_section'); _this.editor.addLineClass(line_number, 'text', 'triple_section_text'); } if (l.text === '+++' && in_section) { in_section = !in_section; _this.editor.addLineClass(line_number, 'background', 'triple_section_close'); } else if (l.text === '+++') { in_section = !in_section; _this.editor.addLineClass(line_number, 'background', 'triple_section_open'); } line_number++; return false; }; })(this)); } }); }).call(this);