Skip to content

Commit

Permalink
fixed #159
Browse files Browse the repository at this point in the history
  • Loading branch information
mistermboy committed Aug 4, 2020
1 parent 560b6a3 commit b2875d0
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 33 deletions.
43 changes: 26 additions & 17 deletions dist/yashe.bundled.min.js

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions src/config/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ YASHE.defaults = $.extend(true, {}, YASHE.defaults, {
/**
* Default shape
*/
value: `PREFIX wd: <http://www.wikidata.org/entity/>
<human>{
wd:a [ wd:Q5 ]
}
value: `PREFIX p: <http://www.wikidata.org/entity/>
PREFIX ps: <http://www.wikidata.org/entity/>
PREFIX xsd: <http://www.wikidata.org/entity/>
<#sequence_assembly> {
( p:P2576 { ps:P2576 xsd:string } |
ps:P4333 {xsd:string p:P4333 } )
}
`,

highlightSelectionMatches: {
Expand Down
5 changes: 2 additions & 3 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,8 @@ const extendCmInstance = function(yashe) {

yashe.prettify = function(){
if(!yashe.hasErrors()){
console.log('e')
prettyUtils.prettify(yashe);
if(yashe.hasErrors())yashe.undo(); //Just in case the prettify fail
//if(yashe.hasErrors())yashe.undo(); //Just in case the prettify fail
}
}

Expand Down Expand Up @@ -394,7 +393,7 @@ root.storeContent = function(yashe) {
root.prettify = function(yashe){
if(!yashe.hasErrors()){
prettyUtils.prettify(yashe);
// if(yashe.hasErrors())yashe.undo(); //Just in case the prettify fail
//if(yashe.hasErrors())yashe.undo(); //Just in case the prettify fail
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/utils/formatUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ var copyLineDown = function(yashe) {
notifyUser(yashe);
yashe.prettify();
let history = disableEditor(yashe);
console.log('dale papi')
for (var l = 0; l < yashe.lineCount(); ++l) {
let lineTokens = getNonWsLineTokens(yashe.getLineTokens(l));
let valueSetSize = getValueSetSizeIfClosed(lineTokens);
Expand Down Expand Up @@ -193,8 +192,9 @@ var copyLineDown = function(yashe) {
if(valueSetSize<0){
let endOfLine = lineTokens[lineTokens.length-1].end
yashe.replaceRange(' # '+comments,{line:l,ch:endOfLine},{line:l,ch:endOfLine})
if(yashe.hasErrors(yashe))yashe.undo();
//For some reason I'm not able to make codemirror scroll methods work, so I'm forcing the scroll with the cursor
yashe.setCursor({line:l+10,ch:token.start});
yashe.setCursor({line:l+10,ch:token.start});
valueSetSize = 0;
comments = '';
}
Expand Down
7 changes: 5 additions & 2 deletions src/utils/pretty/node.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
class Node{

constructor(constraints,triples,comment='',emptyBrackets,afterTriples=[],finalParenthesis=''){
constructor(constraints,triples,comment='',emptyBrackets,afterTriples=[],finalParenthesis='',multiElementOneOf=false){
this.constraints = constraints;
this.triples = triples;
this.comment = comment; //Comment at the end
this.emptyBrackets = emptyBrackets; //ej: schema:name {};
this.afterTriples= afterTriples; // Whatever after {}
this.finalParenthesis = finalParenthesis;
this.hasAleardyAComment = false; //This is used in the methor getSemicolonIfNeeded due not to set the comment again if it has been already seted
this.multiElementOneOf = multiElementOneOf;
}

toString(longest=0,isTriple,indent=1,isLastTriple=false){
Expand Down Expand Up @@ -136,7 +137,9 @@ class Node{
getSemicolonIfNeeded(isTriple,isLastTriple,tripleComment){
let str = EMPTY_STRING;
if(isTriple){
if(!isLastTriple)str+=SEMICOLON;
if(!isLastTriple){
if(!this.multiElementOneOf)str+=SEMICOLON;
}
if(!this.hasAleardyAComment)str+=tripleComment;
}
return str;
Expand Down
12 changes: 9 additions & 3 deletions src/utils/pretty/prettyUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ function prettify(yashe){
let initialDirectivesAndStarts = getInitialDirectivesAndStarts(tokens);
let shapes = getShapes(tokens);

console.log(shapes)

// Strings
let initialDirectivesAndStartsStr = getDirectivesAndStartsStr(initialDirectivesAndStarts);
let shapesStr = getShapesStr(shapes);
Expand Down Expand Up @@ -102,8 +104,8 @@ function getTriples(tokens) {

if(token.skip) return acc; //Is a comment that is part of the previous triple
singleTriple.push(token);

if(isFinishOfTriple(tokens,token,index,finish)){
let multiElementOneOf = isMultiElementOneOf(token);
if(isFinishOfTriple(tokens,token,index,finish) || multiElementOneOf){
if(singleTriple.length>1){
let before = getBeforeTriplesTokens(singleTriple);
let tripleTokens = getTripleTokens(singleTriple);
Expand All @@ -112,7 +114,7 @@ function getTriples(tokens) {
let comment = getComentsAfterToken(token,tokens,index); //We want the tokens after the Triple
let emptyBrackets = start && subTriples.length==0;

acc.push(new Node(before,subTriples,comment,emptyBrackets,after));
acc.push(new Node(before,subTriples,comment,emptyBrackets,after,'',multiElementOneOf));
start=false;
}
singleTriple = [];
Expand All @@ -131,6 +133,10 @@ function getTriples(tokens) {
},[])
}

function isMultiElementOneOf(token){
return token.string == '|';
}

function getAfterTripleTokens(tokens){
let start=false;
let open = 0;
Expand Down

0 comments on commit b2875d0

Please sign in to comment.