var atlasEditor = ace.edit("atlas-config-editor");
atlasEditor.setTheme("ace/theme/monokai");
atlasEditor.session.setMode("ace/mode/text");
atlasEditor.session.setUseWrapMode(true);

var jsonEditor = ace.edit("json-config-editor");
jsonEditor.setTheme("ace/theme/monokai");
jsonEditor.session.setMode("ace/mode/json");

var parser;

$.get('js/atlas.pegjs', function (data) {
    parser = PEG.buildParser(data);
});

ko.applyBindings({});

function fromAtlasToJson() {
    var input = atlasEditor.getValue();
    var output = parser.parse(input);
    jsonEditor.setValue(ko.toJSON(output, null, 2));
}

function fromJsonToAtlas() {
    var input = JSON.parse(jsonEditor.getValue());
    var output = deparseJson(input);
    atlasEditor.setValue(output);
}