Skip to content

Commit

Permalink
Allow loading programUrl in Designer
Browse files Browse the repository at this point in the history
  • Loading branch information
Breck Yunits authored and Breck Yunits committed May 13, 2024
1 parent 844629f commit b3d5251
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 10 deletions.
11 changes: 8 additions & 3 deletions designer/DesignerApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,16 @@ class DesignerApp extends AbstractTreeComponentParser {
this._setGrammarAndCode(grammar.text, sample.text)
}

async fetchAndLoadGrammarFromUrlCommand(url: string) {
async fetchAndLoadGrammarFromUrlCommand(url: string, programUrl: string) {
const willowBrowser = this.willowBrowser
const grammar = await willowBrowser.httpGetUrl(url)
const grammarProgram = new HandGrammarProgram(grammar.text)
const rootNodeDef = grammarProgram.rootParserDefinition
const sample = rootNodeDef.getNode("example").childrenToString()
let sample = rootNodeDef.getNode("example").childrenToString()
if (programUrl) {
sample = await willowBrowser.httpGetUrl(programUrl)
sample = sample.text
}

this._setGrammarAndCode(grammar.text, sample)
}
Expand Down Expand Up @@ -159,13 +163,14 @@ class DesignerApp extends AbstractTreeComponentParser {
const deepLink = new TreeNode(decodeURIComponent(hash.substr(1)))
const standard = deepLink.get("standard")
const fromUrl = deepLink.get("url")
const programUrl = deepLink.get("programUrl")
if (standard) {
console.log("Loading standard from deep link....")
await this.fetchAndLoadJtreeShippedLanguageCommand(standard)
return true
} else if (fromUrl) {
console.log(`Loading grammar from '${fromUrl}'....`)
await this.fetchAndLoadGrammarFromUrlCommand(fromUrl)
await this.fetchAndLoadGrammarFromUrlCommand(fromUrl, programUrl)
return true
} else {
const grammarCode = deepLink.getNode("grammar")
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jtree",
"version": "77.0.0",
"version": "77.1.0",
"description": "Simplify your code with Tree Notation. This jtree package includes a Tree Notation parser, compiler-compiler, and virtual machine for Tree Languages, as well as sample languages, implemented in TypeScript.",
"types": "./built/jtree.node.d.ts",
"main": "./products/TreeNode.js",
Expand Down
11 changes: 8 additions & 3 deletions products/DesignerApp.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,16 @@ class DesignerApp extends AbstractTreeComponentParser {
const sample = await willowBrowser.httpGetUrl(samplePath)
this._setGrammarAndCode(grammar.text, sample.text)
}
async fetchAndLoadGrammarFromUrlCommand(url) {
async fetchAndLoadGrammarFromUrlCommand(url, programUrl) {
const willowBrowser = this.willowBrowser
const grammar = await willowBrowser.httpGetUrl(url)
const grammarProgram = new HandGrammarProgram(grammar.text)
const rootNodeDef = grammarProgram.rootParserDefinition
const sample = rootNodeDef.getNode("example").childrenToString()
let sample = rootNodeDef.getNode("example").childrenToString()
if (programUrl) {
sample = await willowBrowser.httpGetUrl(programUrl)
sample = sample.text
}
this._setGrammarAndCode(grammar.text, sample)
}
// TODO: ADD TESTS!!!!!
Expand Down Expand Up @@ -114,13 +118,14 @@ class DesignerApp extends AbstractTreeComponentParser {
const deepLink = new TreeNode(decodeURIComponent(hash.substr(1)))
const standard = deepLink.get("standard")
const fromUrl = deepLink.get("url")
const programUrl = deepLink.get("programUrl")
if (standard) {
console.log("Loading standard from deep link....")
await this.fetchAndLoadJtreeShippedLanguageCommand(standard)
return true
} else if (fromUrl) {
console.log(`Loading grammar from '${fromUrl}'....`)
await this.fetchAndLoadGrammarFromUrlCommand(fromUrl)
await this.fetchAndLoadGrammarFromUrlCommand(fromUrl, programUrl)
return true
} else {
const grammarCode = deepLink.getNode("grammar")
Expand Down
2 changes: 1 addition & 1 deletion products/TreeNode.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2555,7 +2555,7 @@ TreeNode.iris = `sepal_length,sepal_width,petal_length,petal_width,species
4.9,2.5,4.5,1.7,virginica
5.1,3.5,1.4,0.2,setosa
5,3.4,1.5,0.2,setosa`
TreeNode.getVersion = () => "77.0.0"
TreeNode.getVersion = () => "77.1.0"
class AbstractExtendibleTreeNode extends TreeNode {
_getFromExtended(firstWordPath) {
const hit = this._getNodeFromExtended(firstWordPath)
Expand Down
2 changes: 1 addition & 1 deletion products/TreeNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -2545,7 +2545,7 @@ TreeNode.iris = `sepal_length,sepal_width,petal_length,petal_width,species
4.9,2.5,4.5,1.7,virginica
5.1,3.5,1.4,0.2,setosa
5,3.4,1.5,0.2,setosa`
TreeNode.getVersion = () => "77.0.0"
TreeNode.getVersion = () => "77.1.0"
class AbstractExtendibleTreeNode extends TreeNode {
_getFromExtended(firstWordPath) {
const hit = this._getNodeFromExtended(firstWordPath)
Expand Down
3 changes: 3 additions & 0 deletions releaseNotes.scroll
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ startColumns 4

Here's a list of the notable changes in JTree.

# 77.1.0 2023-5-13
- 🎉 TL Designer can now take a `programUrl` as well.

# 77.0.0 2023-5-08
- 🎉 `assembleFile` (formerly `evaluateImports`) is now faster by stripping Parser Definitions from assembled files, using them only in the returned parsers. (There are still many speed improvements to be had here)
- ⚠️ BREAKING: The `TreeFileSystem.evaluateImports` method is now `TreeFileSystem.assembleFile`, and the interface of the returned object has changed.
Expand Down
2 changes: 1 addition & 1 deletion treeNode/TreeNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3043,7 +3043,7 @@ class TreeNode extends AbstractNode {
return str ? indent + str.replace(/\n/g, indent) : ""
}

static getVersion = () => "77.0.0"
static getVersion = () => "77.1.0"

static fromDisk(path: string): TreeNode {
const format = this._getFileFormat(path)
Expand Down

0 comments on commit b3d5251

Please sign in to comment.