Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion js/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1143,7 +1143,7 @@ async function parsePhraseBook(s, loadSketch) {
let o = importSketches[i];
let sketch;
if (importedSketches[o.name]) {
sketch = importedSketches[o.name];
sketch = importedSketches[o.name]; console.log(item);
} else {
let snap = await loadSketch.download(`sketch/${o.name}`);
sketch = Object.assign({}, snap.val());
Expand All @@ -1162,6 +1162,36 @@ async function parsePhraseBook(s, loadSketch) {
phraseBook[phrase.key].parameters = phrase.parameters;
}
}

let references = [];
function traverse(x){
if(x.type === "Concat"){
for(key in x){
if(x[key].type){
traverse(x[key]);
}
}
}
else if(x.type === "Ref"){
if(references.indexOf(x.node.key) === -1){
references[references.length] = x.node.key;
}
}
}
phrases.forEach(function(item){
if(item.key === "root"){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not just 'root', all phrases need to be checked.

item.values.forEach(function(i){
let p = parsePhrase(i);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you calling parsePhrase? The source has already been parsed at this point.

traverse(p);
});
}
});
references.forEach(function(item){
if(!phraseBook[item]){
Copy link
Member

@stebanos stebanos Feb 24, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, a key can also be a reference to something stored in localMemory, like this:

root:
- {{ dosomething(123) }}

dosomething(num):
- I have to do {{ num }} things.

num is also a key but doesn't refer to a phrase, but in your check it will throw an error.

throw new Error(`Cannot find reference to ${item}`);
}
});

phraseBook['%preamble'] = preamble;
phraseBook['%imports'] = imports;
return phraseBook;
Expand Down