-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
documents and reorganizes the compiler code - part 2
Closes #97
- Loading branch information
Showing
15 changed files
with
1,663 additions
and
1,010 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,52 @@ | ||
# JS Generator # | ||
|
||
TODO | ||
The **jsgenerator** is the third and last step of the compilation process. | ||
It generates the final compiled template as a javascript string, using the syntax tree built previously. | ||
|
||
## Input ## | ||
The syntax tree, e.g.: | ||
``` | ||
{ | ||
"type": "template", | ||
"name": "test", | ||
"args": ["person"], | ||
"content": [ | ||
{type:"element", name:"div", closed:false, attributes:[ | ||
{name:"title", type:"text", value:"Some text"}, | ||
{name:"id", type:"expression", "category": "objectref", "bound": true, "path": [ "person", "id" ]}, | ||
{name:"class", type:"textblock", content:[ | ||
{type:"expression", "category": "objectref", "bound": true, "path": [ "person", "gender" ]}, | ||
{type:"text", value:" "}, | ||
{type:"expression", "category": "objectref", "bound": true, "path": [ "person", "category" ]} | ||
]} | ||
],"content": [ | ||
{ "type": "textblock", "content": [ | ||
{"type": "text","value": "Hello "}, | ||
{"type": "expression", "category": "objectref", "bound": true, "path": [ "person", "name" ]}, | ||
{"type": "text","value": "! "} | ||
]} | ||
]} | ||
] | ||
} | ||
``` | ||
|
||
## Output ## | ||
The compiled template, e.g.: | ||
``` | ||
n.elt( "div", | ||
{e1:[1,2,"person","id"],e2:[1,2,"person","gender"],e3:[1,2,"person","category"]} , | ||
{"title":"Some text","id":["",1],"class":["",2," ",3]}, | ||
0,[ | ||
n.$text({e1:[1,2,"person","name"]},["Hello ",1,"! "]) | ||
] | ||
) | ||
``` | ||
|
||
## Algorithm ## | ||
|
||
The first part of this step is the actual generation. | ||
It is done thanks to the TemplateWalker class (which extend TreeWalker). | ||
It walks the SyntaxTree built previously and manages each node with a processor, depending on its type. | ||
Each processor generates a javascript string for the node and its children. | ||
|
||
Once the generation is done, the resulting javascript string is validated with the *acorn* parser. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.