-
Notifications
You must be signed in to change notification settings - Fork 8
WIP - Reference Validation #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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()); | ||
|
|
@@ -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"){ | ||
| item.values.forEach(function(i){ | ||
| let p = parsePhrase(i); | ||
|
||
| traverse(p); | ||
| }); | ||
| } | ||
| }); | ||
| references.forEach(function(item){ | ||
| if(!phraseBook[item]){ | ||
|
||
| throw new Error(`Cannot find reference to ${item}`); | ||
| } | ||
| }); | ||
|
|
||
| phraseBook['%preamble'] = preamble; | ||
| phraseBook['%imports'] = imports; | ||
| return phraseBook; | ||
|
|
||
There was a problem hiding this comment.
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.